From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:33203) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S65Uo-0000hB-Q2 for qemu-devel@nongnu.org; Fri, 09 Mar 2012 14:29:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S65Um-00049F-RL for qemu-devel@nongnu.org; Fri, 09 Mar 2012 14:28:58 -0500 Received: from e38.co.us.ibm.com ([32.97.110.159]:42740) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S65Um-00043U-KT for qemu-devel@nongnu.org; Fri, 09 Mar 2012 14:28:56 -0500 Received: from /spool/local by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Mar 2012 12:28:51 -0700 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 42E113E40048 for ; Fri, 9 Mar 2012 12:28:49 -0700 (MST) Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q29JSZcX077882 for ; Fri, 9 Mar 2012 12:28:35 -0700 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q29JSYsC020508 for ; Fri, 9 Mar 2012 12:28:34 -0700 Message-ID: <4F5A59D7.2080300@us.ibm.com> Date: Fri, 09 Mar 2012 13:28:23 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <1331308936-30042-1-git-send-email-vianac@linux.vnet.ibm.com> <1331308936-30042-2-git-send-email-vianac@linux.vnet.ibm.com> In-Reply-To: <1331308936-30042-2-git-send-email-vianac@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 1/2] QEmu: support disk filenames with comma List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?ISO-8859-1?Q?Cr=EDstian_Viana?= Cc: qemu-devel@nongnu.org, agl@us.ibm.com On 03/09/2012 10:02 AM, Crístian Viana wrote: > If there is a disk file with a comma in the name, QEmu expects a double > comma instead of a single one (e.g., the file "virtual,disk.img" needs > to be specified as "virtual,,disk.img" in QEmu's command line). This > patch fixes libvirt to work with that feature. Fix RHBZ #801036. I think you meant to send this to libvir-devel. Regards, Anthony Liguori > > diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c > index de2d4a1..685a278 100644 > --- a/src/qemu/qemu_command.c > +++ b/src/qemu/qemu_command.c > @@ -1628,6 +1628,48 @@ qemuSafeSerialParamValue(const char *value) > return 0; > } > > +static const char * > +qemuEscapeCommas(const char *name) > +{ > + const char *name_ptr = name; > + char *escaped_name, *escaped_name_ptr; > + size_t escaped_name_max_size = (strlen(name) * 2) + 1; > + > + /* If there is no comma in the string, return a copy of the original one. */ > + if (!strchr(name, ',')) { > + if (!(escaped_name = strdup(name))) { > + virReportOOMError(); > + return NULL; > + } > + return escaped_name; > + } > + > + /* In the worst case the string will have a sequence of only commas, > + * which will require double the space for the escaped string. */ > + if (VIR_ALLOC_N(escaped_name, escaped_name_max_size)< 0) { > + virReportOOMError(); > + return NULL; > + } > + > + /* Insert a comma after each comma in the string. */ > + escaped_name_ptr = escaped_name; > + while (*name_ptr != '\0') { > + if (*name_ptr == ',') { > + *escaped_name_ptr++ = ','; > + } > + > + *escaped_name_ptr++ = *name_ptr++; > + } > + > + escaped_name_ptr = '\0'; > + > + /* Reduce the string memory size to its current length. */ > + VIR_SHRINK_N(escaped_name, escaped_name_max_size, > + strlen(escaped_name) - strlen(name)); > + > + return escaped_name; > +} > + > static int > qemuBuildRBDString(virConnectPtr conn, > virDomainDiskDefPtr disk, > @@ -1638,7 +1680,7 @@ qemuBuildRBDString(virConnectPtr conn, > char *secret = NULL; > size_t secret_size; > > - virBufferAsprintf(opt, "rbd:%s", disk->src); > + virBufferAsprintf(opt, "rbd:%s", qemuEscapeCommas(disk->src)); > if (disk->auth.username) { > virBufferEscape(opt, ":", ":id=%s", disk->auth.username); > /* look up secret */ > @@ -1922,9 +1964,9 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED, > goto error; > } > if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) > - virBufferAsprintf(&opt, "file=fat:floppy:%s,", disk->src); > + virBufferAsprintf(&opt, "file=fat:floppy:%s,", qemuEscapeCommas(disk->src)); > else > - virBufferAsprintf(&opt, "file=fat:%s,", disk->src); > + virBufferAsprintf(&opt, "file=fat:%s,", qemuEscapeCommas(disk->src)); > } else if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) { > switch (disk->protocol) { > case VIR_DOMAIN_DISK_PROTOCOL_NBD: > @@ -1944,16 +1986,16 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED, > break; > case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG: > if (disk->nhosts == 0) > - virBufferAsprintf(&opt, "file=sheepdog:%s,", disk->src); > + virBufferAsprintf(&opt, "file=sheepdog:%s,", qemuEscapeCommas(disk->src)); > else > /* only one host is supported now */ > virBufferAsprintf(&opt, "file=sheepdog:%s:%s:%s,", > disk->hosts->name, disk->hosts->port, > - disk->src); > + qemuEscapeCommas(disk->src)); > break; > } > } else { > - virBufferAsprintf(&opt, "file=%s,", disk->src); > + virBufferAsprintf(&opt, "file=%s,", qemuEscapeCommas(disk->src)); > } > } > if (qemuCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) > @@ -2134,7 +2176,6 @@ error: > return NULL; > } > > - > char * > qemuBuildDriveDevStr(virDomainDefPtr def, > virDomainDiskDefPtr disk,