From nobody Wed May 14 19:23:19 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152725485082179.56315293587215; Fri, 25 May 2018 06:27:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C5F72C2360C3; Fri, 25 May 2018 13:27:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 28C779D7C1; Fri, 25 May 2018 13:27:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 86FFA4CA84; Fri, 25 May 2018 13:27:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4PDRPWQ023577 for ; Fri, 25 May 2018 09:27:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 829B62023488; Fri, 25 May 2018 13:27:25 +0000 (UTC) Received: from pessoa.redhat.com (unknown [10.40.205.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 381522023487; Fri, 25 May 2018 13:27:24 +0000 (UTC) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Fri, 25 May 2018 15:27:15 +0200 Message-Id: <20180525132717.17628-2-fidencio@redhat.com> In-Reply-To: <20180525132717.17628-1-fidencio@redhat.com> References: <20180525132717.17628-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= , =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCH 1/3] xen_vm: convert to typesafe virConf accessors X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 25 May 2018 13:27:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Signed-off-by: Fabiano Fid=C3=AAncio --- src/xenconfig/xen_xm.c | 268 ++++++++++++++++++++--------------------- 1 file changed, 132 insertions(+), 136 deletions(-) diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c index 4becb40b4..fc88ac823 100644 --- a/src/xenconfig/xen_xm.c +++ b/src/xenconfig/xen_xm.c @@ -112,172 +112,168 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def) { virDomainDiskDefPtr disk =3D NULL; int hvm =3D def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM; - virConfValuePtr list =3D virConfGetValue(conf, "disk"); + char **disks =3D NULL, **entries; =20 - if (list && list->type =3D=3D VIR_CONF_LIST) { - list =3D list->list; - while (list) { - char *head; - char *offset; - char *tmp; - const char *src; + if (virConfGetValueStringList(conf, "disk", false, &disks) < 0) + goto cleanup; =20 - if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NUL= L)) - goto skipdisk; + for (entries =3D disks; *entries; entries++) { + char *head =3D *entries; + char *offset; + char *tmp; + const char *src; =20 - head =3D list->str; - if (!(disk =3D virDomainDiskDefNew(NULL))) - return -1; + if (!(disk =3D virDomainDiskDefNew(NULL))) + return -1; + + /* + * Disks have 3 components, SOURCE,DEST-DEVICE,MODE + * eg, phy:/dev/HostVG/XenGuest1,xvda,w + * The SOURCE is usually prefixed with a driver type, + * and optionally driver sub-type + * The DEST-DEVICE is optionally post-fixed with disk type + */ + + /* Extract the source file path*/ + if (!(offset =3D strchr(head, ','))) + goto skipdisk; + + if (offset =3D=3D head) { + /* No source file given, eg CDROM with no media */ + ignore_value(virDomainDiskSetSource(disk, NULL)); + } else { + if (VIR_STRNDUP(tmp, head, offset - head) < 0) + goto cleanup; + + if (virDomainDiskSetSource(disk, tmp) < 0) { + VIR_FREE(tmp); + goto cleanup; + } + VIR_FREE(tmp); + } =20 - /* - * Disks have 3 components, SOURCE,DEST-DEVICE,MODE - * eg, phy:/dev/HostVG/XenGuest1,xvda,w - * The SOURCE is usually prefixed with a driver type, - * and optionally driver sub-type - * The DEST-DEVICE is optionally post-fixed with disk type - */ - - /* Extract the source file path*/ - if (!(offset =3D strchr(head, ','))) - goto skipdisk; - - if (offset =3D=3D head) { - /* No source file given, eg CDROM with no media */ - ignore_value(virDomainDiskSetSource(disk, NULL)); - } else { - if (VIR_STRNDUP(tmp, head, offset - head) < 0) + head =3D offset + 1; + /* Remove legacy ioemu: junk */ + if (STRPREFIX(head, "ioemu:")) + head =3D head + 6; + + /* Extract the dest device name */ + if (!(offset =3D strchr(head, ','))) + goto skipdisk; + + if (VIR_ALLOC_N(disk->dst, (offset - head) + 1) < 0) + goto cleanup; + + if (virStrncpy(disk->dst, head, offset - head, + (offset - head) + 1) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Dest file %s too big for destination"), head= ); + goto cleanup; + } + + head =3D offset + 1; + /* Extract source driver type */ + src =3D virDomainDiskGetSource(disk); + if (src) { + size_t len; + /* The main type phy:, file:, tap: ... */ + if ((tmp =3D strchr(src, ':')) !=3D NULL) { + len =3D tmp - src; + if (VIR_STRNDUP(tmp, src, len) < 0) goto cleanup; =20 - if (virDomainDiskSetSource(disk, tmp) < 0) { + if (virDomainDiskSetDriver(disk, tmp) < 0) { VIR_FREE(tmp); goto cleanup; } VIR_FREE(tmp); - } - - head =3D offset + 1; - /* Remove legacy ioemu: junk */ - if (STRPREFIX(head, "ioemu:")) - head =3D head + 6; - - /* Extract the dest device name */ - if (!(offset =3D strchr(head, ','))) - goto skipdisk; =20 - if (VIR_ALLOC_N(disk->dst, (offset - head) + 1) < 0) - goto cleanup; + /* Strip the prefix we found off the source file name */ + if (virDomainDiskSetSource(disk, src + len + 1) < 0) + goto cleanup; =20 - if (virStrncpy(disk->dst, head, offset - head, - (offset - head) + 1) =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Dest file %s too big for destination"), = head); - goto cleanup; + src =3D virDomainDiskGetSource(disk); } =20 - head =3D offset + 1; - /* Extract source driver type */ - src =3D virDomainDiskGetSource(disk); - if (src) { - size_t len; - /* The main type phy:, file:, tap: ... */ - if ((tmp =3D strchr(src, ':')) !=3D NULL) { - len =3D tmp - src; - if (VIR_STRNDUP(tmp, src, len) < 0) - goto cleanup; - - if (virDomainDiskSetDriver(disk, tmp) < 0) { - VIR_FREE(tmp); - goto cleanup; - } - VIR_FREE(tmp); + /* And the sub-type for tap:XXX: type */ + if (STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap") || + STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap2")) { + char *driverType; =20 - /* Strip the prefix we found off the source file name = */ - if (virDomainDiskSetSource(disk, src + len + 1) < 0) - goto cleanup; + if (!(tmp =3D strchr(src, ':'))) + goto skipdisk; + len =3D tmp - src; =20 - src =3D virDomainDiskGetSource(disk); - } + if (VIR_STRNDUP(driverType, src, len) < 0) + goto cleanup; =20 - /* And the sub-type for tap:XXX: type */ - if (STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap") || - STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap2")) { - char *driverType; - - if (!(tmp =3D strchr(src, ':'))) - goto skipdisk; - len =3D tmp - src; - - if (VIR_STRNDUP(driverType, src, len) < 0) - goto cleanup; - - if (STREQ(driverType, "aio")) - virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW); - else - virDomainDiskSetFormat(disk, - virStorageFileFormatTypeFro= mString(driverType)); - VIR_FREE(driverType); - if (virDomainDiskGetFormat(disk) <=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown driver type %s"), - src); - goto cleanup; - } - - /* Strip the prefix we found off the source file name = */ - if (virDomainDiskSetSource(disk, src + len + 1) < 0) - goto cleanup; - src =3D virDomainDiskGetSource(disk); + if (STREQ(driverType, "aio")) + virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW); + else + virDomainDiskSetFormat(disk, + virStorageFileFormatTypeFromStr= ing(driverType)); + VIR_FREE(driverType); + if (virDomainDiskGetFormat(disk) <=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown driver type %s"), + src); + goto cleanup; } + + /* Strip the prefix we found off the source file name */ + if (virDomainDiskSetSource(disk, src + len + 1) < 0) + goto cleanup; + src =3D virDomainDiskGetSource(disk); } + } =20 - /* No source, or driver name, so fix to phy: */ - if (!virDomainDiskGetDriver(disk) && - virDomainDiskSetDriver(disk, "phy") < 0) - goto cleanup; + /* No source, or driver name, so fix to phy: */ + if (!virDomainDiskGetDriver(disk) && + virDomainDiskSetDriver(disk, "phy") < 0) + goto cleanup; =20 - /* phy: type indicates a block device */ - virDomainDiskSetType(disk, - STREQ(virDomainDiskGetDriver(disk), "phy"= ) ? - VIR_STORAGE_TYPE_BLOCK : - VIR_STORAGE_TYPE_FILE); - - /* Check for a :cdrom/:disk postfix */ - disk->device =3D VIR_DOMAIN_DISK_DEVICE_DISK; - if ((tmp =3D strchr(disk->dst, ':')) !=3D NULL) { - if (STREQ(tmp, ":cdrom")) - disk->device =3D VIR_DOMAIN_DISK_DEVICE_CDROM; - tmp[0] =3D '\0'; - } + /* phy: type indicates a block device */ + virDomainDiskSetType(disk, + STREQ(virDomainDiskGetDriver(disk), "phy") ? + VIR_STORAGE_TYPE_BLOCK : + VIR_STORAGE_TYPE_FILE); + + /* Check for a :cdrom/:disk postfix */ + disk->device =3D VIR_DOMAIN_DISK_DEVICE_DISK; + if ((tmp =3D strchr(disk->dst, ':')) !=3D NULL) { + if (STREQ(tmp, ":cdrom")) + disk->device =3D VIR_DOMAIN_DISK_DEVICE_CDROM; + tmp[0] =3D '\0'; + } =20 - if (STRPREFIX(disk->dst, "xvd") || !hvm) { - disk->bus =3D VIR_DOMAIN_DISK_BUS_XEN; - } else if (STRPREFIX(disk->dst, "sd")) { - disk->bus =3D VIR_DOMAIN_DISK_BUS_SCSI; - } else { - disk->bus =3D VIR_DOMAIN_DISK_BUS_IDE; - } + if (STRPREFIX(disk->dst, "xvd") || !hvm) { + disk->bus =3D VIR_DOMAIN_DISK_BUS_XEN; + } else if (STRPREFIX(disk->dst, "sd")) { + disk->bus =3D VIR_DOMAIN_DISK_BUS_SCSI; + } else { + disk->bus =3D VIR_DOMAIN_DISK_BUS_IDE; + } =20 - if (STREQ(head, "r") || - STREQ(head, "ro")) - disk->src->readonly =3D true; - else if ((STREQ(head, "w!")) || - (STREQ(head, "!"))) - disk->src->shared =3D true; + if (STREQ(head, "r") || + STREQ(head, "ro")) + disk->src->readonly =3D true; + else if ((STREQ(head, "w!")) || + (STREQ(head, "!"))) + disk->src->shared =3D true; =20 - /* Maintain list in sorted order according to target device na= me */ - if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0) - goto cleanup; + /* Maintain list in sorted order according to target device name */ + if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0) + goto cleanup; =20 - skipdisk: - list =3D list->next; - virDomainDiskDefFree(disk); - disk =3D NULL; - } + skipdisk: + virDomainDiskDefFree(disk); + disk =3D NULL; } =20 return 0; =20 cleanup: + virStringListFree(disks); virDomainDiskDefFree(disk); return -1; } --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list