From nobody Wed May 14 10:55:02 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; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527368460635201.4004739514868; Sat, 26 May 2018 14:01:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD17FC0EF9B5; Sat, 26 May 2018 21:00:52 +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 C90C32010CA0; Sat, 26 May 2018 21:00:50 +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 237444CA80; Sat, 26 May 2018 21:00:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4QL0jij031690 for ; Sat, 26 May 2018 17:00:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id C0A3A17B22; Sat, 26 May 2018 21:00:45 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B9B2617786 for ; Sat, 26 May 2018 21:00:44 +0000 (UTC) Received: from mail-wr0-f181.google.com (mail-wr0-f181.google.com [209.85.128.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 506D338C361 for ; Sat, 26 May 2018 21:00:32 +0000 (UTC) Received: by mail-wr0-f181.google.com with SMTP id u12-v6so14428051wrn.8 for ; Sat, 26 May 2018 14:00:32 -0700 (PDT) Received: from machado.local ([95.82.135.172]) by smtp.gmail.com with ESMTPSA id u89-v6sm10748062wma.4.2018.05.26.14.00.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 May 2018 14:00:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fidencio-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TJp6QaXAMgd/kaIKn/XzPX/0T3RLSweKJ9amRQfOuH4=; b=DDWKgJIOwGYw7zLZXJr5d9GJkucmpwIwX0n5v97gw0rkrfyBqi4dhYminN8d+gmRmv MsuZnQKMhkTE35K10lgXu0kc56O2fw4sNXJ3wBHdBXa1GIfv/tGfXAJOSw7ejoIkATpc cRra0XLCX1IiLet3ten5chRmOwCnyrT7VItwad8mEupA5D/dFp9vR0fHv7GEQOWd3Duv /zm30sOC8qL/brbEDDHHKuxk9iuSCUOgtabQhapitkWeEmoaJhMqdbb7zfe1t7G7o3ZP W5SreClD7PEl0V7OVmwRedRkDBayJEAca44sHVtC7P8Ea3TzZt7VdmjdgyogIMMQUd55 xsPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TJp6QaXAMgd/kaIKn/XzPX/0T3RLSweKJ9amRQfOuH4=; b=uC7zMqASbM4rk/kC1bUYHiUfeADM+RekGU0oC04jcMekBYEpQadjdOyS3eSboaebuJ wCYNFXdgabi91EWiVQ+a+5bbFWRce0uI8i31oELeTzSRxow9PgVxrJFFld0MNZ8V0R0J 1toWOrEesMGRLPeUxjs3C9n/Jq3a8CQgv8xX1vY5HZ8W9fVBFpfp1LC8tdilhKizGncq tT1mnlSWc5ho2BGv8oiUAr095m+pIF1ib6ksHJ+Knda+zPQmmJqm4VcVIp/Ieo/nqehw AimKNyBHK2rVozdqa/0x7PorT8qdsGauMDHvy1KSd5lZ/lSmjHqpgFgngHykS6SFLgFU HPMQ== X-Gm-Message-State: ALKqPwc4HVdpApeEXe1xt2MLkel53LPxxc+XkW4Q1Q9GVtdNWyw7RQLL 6Ik95i316GLR/71ijbY3M47vwyHM X-Google-Smtp-Source: AB8JxZoqgp6xtoFadUVgt11C6jbRNYnGz6Dlf6qJz/U5hTZH26U3MEGnJcv3S8nb0opVbWJcH74+nw== X-Received: by 2002:adf:c848:: with SMTP id e8-v6mr5876377wrh.236.1527368430715; Sat, 26 May 2018 14:00:30 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Sat, 26 May 2018 23:00:25 +0200 Message-Id: <20180526210027.12066-2-fabiano@fidencio.org> In-Reply-To: <20180526210027.12066-1-fabiano@fidencio.org> References: <20180526210027.12066-1-fabiano@fidencio.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 26 May 2018 21:00:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 26 May 2018 21:00:32 +0000 (UTC) for IP:'209.85.128.181' DOMAIN:'mail-wr0-f181.google.com' HELO:'mail-wr0-f181.google.com' FROM:'fabiano@fidencio.org' RCPT:'' X-RedHat-Spam-Score: -1.699 (DKIM_SIGNED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID) 209.85.128.181 mail-wr0-f181.google.com 209.85.128.181 mail-wr0-f181.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= , =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCHv2 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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 26 May 2018 21:00:59 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 From: Fabiano Fid=C3=AAncio 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 4becb40b4c..fc88ac8238 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.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list