From nobody Wed May 14 10:27:11 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 1527460154216441.8561625229636; Sun, 27 May 2018 15:29:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D3BB390DA5; Sun, 27 May 2018 22:29:12 +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 085635DD6B; Sun, 27 May 2018 22:29:12 +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 AD59D4CA82; Sun, 27 May 2018 22:29:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4RMSlLi015005 for ; Sun, 27 May 2018 18:28:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 569B76E50F; Sun, 27 May 2018 22:28:47 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4DC6E6E510 for ; Sun, 27 May 2018 22:28:44 +0000 (UTC) Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) (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 5ACBE3A9EB for ; Sun, 27 May 2018 22:28:33 +0000 (UTC) Received: by mail-wm0-f43.google.com with SMTP id j4-v6so27398715wme.1 for ; Sun, 27 May 2018 15:28:33 -0700 (PDT) Received: from machado.local ([95.82.135.172]) by smtp.gmail.com with ESMTPSA id h81-v6sm23469897wmd.0.2018.05.27.15.28.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 May 2018 15:28:31 -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=ZeIBbVbhT0SAABl8XcrNGGaVNBc8ZRc9wXD7qdy/AV0=; b=EyjF0IUv2+M+T49d+mIdozm23E8ZSiJiHzxJpXhmBymsE/drgL/HwsjArxjgzmlAc0 r3uWoCY/s0VFIZLxJcrYlANVhW52DgB3ZQY0VnlzT9Djq6VfVqOeozDFVpiXNNTULXi+ gtL2di3YlzkLrTetFxf0DXO3dNgvjcQgbhDWdAiKw82DDk8uHH3ASSLbsZ1Ywxwbb0KI Uv/H9KK9SwWtnji6GzQBR6GmBL02ZixUhOxt6O3UKIF4z/JZKCeUoZLewLxPCi2M33QQ BXaKQfCFhl+7R7QDhN0AP2gbFQHPBYIIJGdb6aw4VFOXWUBLQae17Dbn4Od7hQa/3j14 4E8w== 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=ZeIBbVbhT0SAABl8XcrNGGaVNBc8ZRc9wXD7qdy/AV0=; b=dnJ26x+SywXKNa5IBq2NMxIb5Y6oYQ8/aLJmRZYPUYXJAz5H/jvVpD/t+/LucPXT04 VRsZ+l0Oi8v/aiihZWXHYeicBR1pHd98WL5tA9Pwh+B72V7tJWsNsV7R22Fv4QXpFzys o1wGIpqT6GzQElA+Gu0mIH5ys84/XO2yndG9eqvTfS8DR+2ahho9XcJBxTEt2o57Vuyr 8TnBtWn9b+NPKVAx4+F3hw0jaQurKUYXPCPAHm/DVMQKPyvskgYqz+GZhZlVsFRASuRH DVUtFuu9FROF85cKLl/v5L83Xfx2Zzof4J/5mkJ6cDXJyYJAQ0on39e+7YUfmkF3xUo6 zP2w== X-Gm-Message-State: ALKqPwfww2TkBt6eKCbZ8X525AzjtPsbDY1kA13k8FXzl36QwzWA7tdo FuSiQa9jnK6jrgqYNfKGabj2mbOg X-Google-Smtp-Source: ADUXVKLJGxJGDWoSIX2rrm6pbtxbGYQ8P4klZZ4OFML5nSuu3022NvBD0kOBBVfPnzw8JHK1ijJAzg== X-Received: by 2002:a1c:443:: with SMTP id 64-v6mr8304031wme.140.1527460111615; Sun, 27 May 2018 15:28:31 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Mon, 28 May 2018 00:28:20 +0200 Message-Id: <20180527222826.18525-2-fabiano@fidencio.org> In-Reply-To: <20180527222826.18525-1-fabiano@fidencio.org> References: <20180527222826.18525-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.38]); Sun, 27 May 2018 22:28:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sun, 27 May 2018 22:28:33 +0000 (UTC) for IP:'74.125.82.43' DOMAIN:'mail-wm0-f43.google.com' HELO:'mail-wm0-f43.google.com' FROM:'fabiano@fidencio.org' RCPT:'' X-RedHat-Spam-Score: 0.08 (DKIM_SIGNED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID) 74.125.82.43 mail-wm0-f43.google.com 74.125.82.43 mail-wm0-f43.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCHv3 1/7] xen_xm: Split the per-disk logic from xenParseXMDisk() 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.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sun, 27 May 2018 22:29:12 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 xenParseXMDisk() does a lot of stuff and, in order to make things cleaner, let's split it in two new functions: - xenParseXMDisk(): it's a new function that keeps the old name. It's responsible for the whole per-disk logic from the old xenParseXMDisk(); - xenParseXMDiskList(): it's basically the old xenParseXMDisk(), but now it just iterates over the list of disks, calling xenParseXMDisk() per each disk. This patch is basically preparing the ground for the future when typesafe virConf acessors will be used. Signed-off-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/xenconfig/xen_xm.c | 304 +++++++++++++++++++++++++--------------------= ---- 1 file changed, 156 insertions(+), 148 deletions(-) diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c index 4becb40b4c..be50a13909 100644 --- a/src/xenconfig/xen_xm.c +++ b/src/xenconfig/xen_xm.c @@ -107,179 +107,187 @@ xenParseXMOS(virConfPtr conf, virDomainDefPtr def) } =20 =20 -static int -xenParseXMDisk(virConfPtr conf, virDomainDefPtr def) +static virDomainDiskDefPtr +xenParseXMDisk(char *entry, int hvm) { virDomainDiskDefPtr disk =3D NULL; - int hvm =3D def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM; - virConfValuePtr list =3D virConfGetValue(conf, "disk"); + char *head; + char *offset; + char *tmp; + const char *src; =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 (!(disk =3D virDomainDiskDefNew(NULL))) + return NULL; =20 - if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NUL= L)) - goto skipdisk; + head =3D entry; + /* + * 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 error; + + 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 error; =20 - head =3D list->str; - if (!(disk =3D virDomainDiskDefNew(NULL))) - return -1; + if (virDomainDiskSetSource(disk, tmp) < 0) { + VIR_FREE(tmp); + goto error; + } + 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) - goto cleanup; - - if (virDomainDiskSetSource(disk, tmp) < 0) { - VIR_FREE(tmp); - goto cleanup; - } + 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 error; + + if (VIR_ALLOC_N(disk->dst, (offset - head) + 1) < 0) + goto error; + + 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 error; + } + + 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 error; + + if (virDomainDiskSetDriver(disk, tmp) < 0) { VIR_FREE(tmp); + goto error; } + VIR_FREE(tmp); =20 - head =3D offset + 1; - /* Remove legacy ioemu: junk */ - if (STRPREFIX(head, "ioemu:")) - head =3D head + 6; + /* Strip the prefix we found off the source file name */ + if (virDomainDiskSetSource(disk, src + len + 1) < 0) + goto error; =20 - /* Extract the dest device name */ - if (!(offset =3D strchr(head, ','))) - goto skipdisk; + src =3D virDomainDiskGetSource(disk); + } =20 - if (VIR_ALLOC_N(disk->dst, (offset - head) + 1) < 0) - goto cleanup; + /* And the sub-type for tap:XXX: type */ + if (STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap") || + STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap2")) { + char *driverType; =20 - if (virStrncpy(disk->dst, head, offset - head, - (offset - head) + 1) =3D=3D NULL) { + if (!(tmp =3D strchr(src, ':'))) + goto error; + len =3D tmp - src; + + if (VIR_STRNDUP(driverType, src, len) < 0) + goto error; + + if (STREQ(driverType, "aio")) + virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW); + else + virDomainDiskSetFormat(disk, + virStorageFileFormatTypeFromString(= driverType)); + VIR_FREE(driverType); + if (virDomainDiskGetFormat(disk) <=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Dest file %s too big for destination"), = head); - goto cleanup; + _("Unknown driver type %s"), + src); + goto error; } =20 - head =3D offset + 1; - /* Extract source driver type */ + /* Strip the prefix we found off the source file name */ + if (virDomainDiskSetSource(disk, src + len + 1) < 0) + goto error; 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); - - /* Strip the prefix we found off the source file name = */ - if (virDomainDiskSetSource(disk, src + len + 1) < 0) - goto cleanup; - - src =3D virDomainDiskGetSource(disk); - } + } + } =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); - } - } + /* No source, or driver name, so fix to phy: */ + if (!virDomainDiskGetDriver(disk) && + virDomainDiskSetDriver(disk, "phy") < 0) + goto error; + + /* 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 - /* No source, or driver name, so fix to phy: */ - if (!virDomainDiskGetDriver(disk) && - virDomainDiskSetDriver(disk, "phy") < 0) - goto cleanup; + 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 - /* 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'; - } + 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 - 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; - } + return disk; =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; + error: + virDomainDiskDefFree(disk); + return NULL; +} =20 - /* Maintain list in sorted order according to target device na= me */ - if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0) - goto cleanup; =20 - skipdisk: - list =3D list->next; - virDomainDiskDefFree(disk); - disk =3D NULL; - } +static int +xenParseXMDiskList(virConfPtr conf, virDomainDefPtr def) +{ + int hvm =3D def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM; + virConfValuePtr list =3D virConfGetValue(conf, "disk"); + + if (!list || list->type !=3D VIR_CONF_LIST) + return 0; + + for (list =3D list->list; list; list =3D list->next) { + virDomainDiskDefPtr disk; + int rc; + + if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NULL)) + continue; + + if (!(disk =3D xenParseXMDisk(list->str, hvm))) + continue; + + /* Maintain list in sorted order according to target device name */ + rc =3D VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk); + virDomainDiskDefFree(disk); + + if (rc < 0) + return -1; } =20 return 0; - - cleanup: - virDomainDiskDefFree(disk); - return -1; } =20 =20 @@ -457,7 +465,7 @@ xenParseXM(virConfPtr conf, if (xenParseXMOS(conf, def) < 0) goto cleanup; =20 - if (xenParseXMDisk(conf, def) < 0) + if (xenParseXMDiskList(conf, def) < 0) goto cleanup; =20 if (xenParseXMInputDevs(conf, def) < 0) --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list