return 0;
}
+
static int
qemuBuildRBDString(virConnectPtr conn,
virDomainDiskDefPtr disk,
char *secret = NULL;
size_t secret_size;
- virBufferAsprintf(opt, "rbd:%s", disk->src);
+ virBufferEscape(opt, ',', ",", "rbd:%s", disk->src);
if (disk->auth.username) {
- virBufferEscape(opt, ":", ":id=%s", disk->auth.username);
+ virBufferEscape(opt, '\\', ":", ":id=%s", disk->auth.username);
/* look up secret */
switch (disk->auth.secretType) {
case VIR_DOMAIN_DISK_SECRET_TYPE_UUID:
virReportOOMError();
goto error;
}
- virBufferEscape(opt, ":", ":key=%s:auth_supported=cephx none",
+ virBufferEscape(opt, '\\', ":",
+ ":key=%s:auth_supported=cephx none",
base64);
VIR_FREE(base64);
} else {
goto error;
}
if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
- virBufferAsprintf(&opt, "file=fat:floppy:%s,", disk->src);
+ virBufferEscape(&opt, ',', ",", "file=fat:floppy:%s,",
+ disk->src);
else
- virBufferAsprintf(&opt, "file=fat:%s,", disk->src);
+ virBufferEscape(&opt, ',', ",", "file=fat:%s,", disk->src);
} else if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) {
switch (disk->protocol) {
case VIR_DOMAIN_DISK_PROTOCOL_NBD:
virBufferAddChar(&opt, ',');
break;
case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG:
- if (disk->nhosts == 0)
- virBufferAsprintf(&opt, "file=sheepdog:%s,", disk->src);
- else
+ if (disk->nhosts == 0) {
+ virBufferEscape(&opt, ',', ",", "file=sheepdog:%s,",
+ disk->src);
+ } else {
/* only one host is supported now */
- virBufferAsprintf(&opt, "file=sheepdog:%s:%s:%s,",
- disk->hosts->name, disk->hosts->port,
- disk->src);
+ virBufferAsprintf(&opt, "file=sheepdog:%s:%s:",
+ disk->hosts->name, disk->hosts->port);
+ virBufferEscape(&opt, ',', ",", "%s,", disk->src);
+ }
break;
}
} else {
- virBufferAsprintf(&opt, "file=%s,", disk->src);
+ virBufferEscape(&opt, ',', ",", "file=%s,", disk->src);
}
}
if (qemuCapsGet(qemuCaps, QEMU_CAPS_DEVICE))
return NULL;
}
-
char *
qemuBuildDriveDevStr(virDomainDefPtr def,
virDomainDiskDefPtr disk,
char *keyword;
char *value = NULL;
- if (!(endmark = strchr(start, ',')))
+ endmark = start;
+ do {
+ /* Qemu accepts ',,' as an escape for a literal comma;
+ * skip past those here while searching for the end of the
+ * value, then strip them down below */
+ endmark = strchr(endmark, ',');
+ } while (endmark && endmark[1] == ',' && (endmark += 2));
+ if (!endmark)
endmark = end;
if (!(separator = strchr(start, '=')))
separator = end;
VIR_FREE(keyword);
goto no_memory;
}
+ if (strchr(value, ',')) {
+ char *p = strchr(value, ',') + 1;
+ char *q = p + 1;
+ while (*q) {
+ if (*q == ',')
+ q++;
+ *p++ = *q++;
+ }
+ *p = '\0';
+ }
}
if (keywordAlloc == keywordCount) {
/*
* buf.c: buffers for libvirt
*
- * Copyright (C) 2005-2008, 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2005-2008, 2010-2012 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
const char *format,
const char *str)
{
- virBufferEscape(buf, "\\'", format, str);
+ virBufferEscape(buf, '\\', "\\'", format, str);
}
/**
* virBufferEscape:
* @buf: the buffer to append to
+ * @escape: the escape character to inject
* @toescape: NUL-terminated list of characters to escape
* @format: a printf like format string but with only one %s parameter
* @str: the string argument which needs to be escaped
*
* Do a formatted print with a single string to a buffer. Any characters
- * in the provided list are escaped with a preceeding \. Auto indentation
+ * in the provided list are escaped with the given escape. Auto indentation
* may be applied.
*/
void
-virBufferEscape(virBufferPtr buf, const char *toescape,
+virBufferEscape(virBufferPtr buf, char escape, const char *toescape,
const char *format, const char *str)
{
int len;
*/
char needle[2] = { *cur, 0 };
if (strstr(toescape, needle))
- *out++ = '\\';
+ *out++ = escape;
*out++ = *cur;
cur++;
}
/*
* buf.h: buffers for libvirt
*
- * Copyright (C) 2005-2008, 2011 Red Hat, Inc.
+ * Copyright (C) 2005-2008, 2011, 2012 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
ATTRIBUTE_FMT_PRINTF(2, 0);
void virBufferStrcat(virBufferPtr buf, ...)
ATTRIBUTE_SENTINEL;
-void virBufferEscape(virBufferPtr buf, const char *toescape,
+void virBufferEscape(virBufferPtr buf, char escape, const char *toescape,
const char *format, const char *str);
void virBufferEscapeString(virBufferPtr buf, const char *format,
const char *str);