From nobody Sat May 4 05:24:14 2024 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 From nobody Sat May 4 05:24:14 2024 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 1527460158643504.2116123399255; Sun, 27 May 2018 15:29:18 -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 E0743C9B0F; Sun, 27 May 2018 22:29:16 +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 9A0379420E; Sun, 27 May 2018 22:29:16 +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 143F74CA89; Sun, 27 May 2018 22:29:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4RMSmfo015013 for ; Sun, 27 May 2018 18:28:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id C569E1001949; Sun, 27 May 2018 22:28:48 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC8A31001942 for ; Sun, 27 May 2018 22:28:45 +0000 (UTC) Received: from mail-wr0-f172.google.com (mail-wr0-f172.google.com [209.85.128.172]) (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 5FEAC19D2AA for ; Sun, 27 May 2018 22:28:34 +0000 (UTC) Received: by mail-wr0-f172.google.com with SMTP id i12-v6so17316579wrc.4 for ; Sun, 27 May 2018 15:28:34 -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.31 (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=4YjG/3F2OD9z08UX3T04I9w1iMbR2aIThBn/F1Ptpd4=; b=cAcmFfsjGKnwJ+12kjthIEgrrPEVHFbGDuJ2JpUqNru9VhsT3knMo+6pvyhcwqRCK3 DMVF+srpHoO8iipM2D1YnH35FwVj3RTIo2mvojMCemZXGvHIw3pLId/7gQjJhxG+/867 OVEbvey1J0JlYdV8tjXHiQ2TPrpfGoHenH2D4wsNFVAkBnmhwpf62M6sRT+YvqI11kba imus3nzKn7LgBGLRigDYX7JxkCdNFDRgSj+GvVVq76TnUvG3EpyPQpJi6wTDm/IWThb7 YoXSUGDtjqOcqiuqcmN2Z8ykaCbGrKqRqZzMY1fBX6xtdZFLDcgAtLD63dHOYC+2HQB5 D1mg== 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=4YjG/3F2OD9z08UX3T04I9w1iMbR2aIThBn/F1Ptpd4=; b=V/rbwRyFgynmqPwQnqp0BLxx6Mif2iy02bSqwqvOaLSPjy8ZGeVk1dm9tTOa15cNQR PzMLqN3NP8nTWii98Utb37YI6lCQ700zMGi6TBzcJqE92Y1rL52QDdXIxO9H85F7GWKC vnzE6NmmQQMO42+600hRmdJk7bKNSASFm99GVBUJWrSABh7Go/Zz90P7H2tj4Z/A0Nma XXaMP+kKanXj0//xpPJJHAcLtzGuSjDevGq+9zrMpddHoQRPqYnkAQwvpaCYZvjjF5eC DsjRzHjYwnT1FOINRDmms/erjQ+rqCrAjfZRtm32ARSfH13a8mzRIBYOGm8PsFB6jfBX 3ASA== X-Gm-Message-State: ALKqPwdiVvoOyLpLkNZSiX8jADO1Ty4RZiJp039J7e5ZF4vspeJ+Nn0M jNP9yWahOcnGR/aP+QEFqwJod2Cs X-Google-Smtp-Source: AB8JxZoV4LIPfp1okzq2fF9hEdnTcxRpfMsQ58ueZEnrsAvKEUfgd0ltLNw5Mr4Fr42x/0VKa6soeA== X-Received: by 2002:adf:cd08:: with SMTP id w8-v6mr9430857wrm.187.1527460112805; Sun, 27 May 2018 15:28:32 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Mon, 28 May 2018 00:28:21 +0200 Message-Id: <20180527222826.18525-3-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.39]); Sun, 27 May 2018 22:28:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sun, 27 May 2018 22:28:34 +0000 (UTC) for IP:'209.85.128.172' DOMAIN:'mail-wr0-f172.google.com' HELO:'mail-wr0-f172.google.com' FROM:'fabiano@fidencio.org' RCPT:'' X-RedHat-Spam-Score: 0.1 (DKIM_SIGNED, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID) 209.85.128.172 mail-wr0-f172.google.com 209.85.128.172 mail-wr0-f172.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCHv3 2/7] 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.26]); Sun, 27 May 2018 22:29:17 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Signed-off-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/xenconfig/xen_xm.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c index be50a13909..ef52cf4250 100644 --- a/src/xenconfig/xen_xm.c +++ b/src/xenconfig/xen_xm.c @@ -263,20 +263,20 @@ xenParseXMDisk(char *entry, int hvm) static int xenParseXMDiskList(virConfPtr conf, virDomainDefPtr def) { + char **disks =3D NULL, **entries; int hvm =3D def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM; - virConfValuePtr list =3D virConfGetValue(conf, "disk"); + int ret =3D -1; + int rc; =20 - if (!list || list->type !=3D VIR_CONF_LIST) - return 0; + rc =3D virConfGetValueStringList(conf, "disk", false, &disks); + if (rc <=3D 0) + return rc; =20 - for (list =3D list->list; list; list =3D list->next) { + for (entries =3D disks; *entries; entries++) { virDomainDiskDefPtr disk; - int rc; + char *entry =3D *entries; =20 - if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NULL)) - continue; - - if (!(disk =3D xenParseXMDisk(list->str, hvm))) + if (!(disk =3D xenParseXMDisk(entry, hvm))) continue; =20 /* Maintain list in sorted order according to target device name */ @@ -284,10 +284,14 @@ xenParseXMDiskList(virConfPtr conf, virDomainDefPtr d= ef) virDomainDiskDefFree(disk); =20 if (rc < 0) - return -1; + goto cleanup; } =20 - return 0; + ret =3D 0; + + cleanup: + virStringListFree(disks); + return ret; } =20 =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 05:24:14 2024 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 152746013661888.67198235674061; Sun, 27 May 2018 15:28:56 -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 2FB2930CADC5; Sun, 27 May 2018 22:28:55 +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 D2D075DD6B; Sun, 27 May 2018 22:28:54 +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 77C8E4CA81; Sun, 27 May 2018 22:28:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4RMSnw2015025 for ; Sun, 27 May 2018 18:28:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id C07992010CF0; Sun, 27 May 2018 22:28:49 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B8EEF2010CEE for ; Sun, 27 May 2018 22:28:46 +0000 (UTC) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) (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 61F58CD4CD for ; Sun, 27 May 2018 22:28:35 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id v131-v6so8142030wma.1 for ; Sun, 27 May 2018 15:28:35 -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.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 May 2018 15:28:33 -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=KwDjwry99t46Fp6itpoRnYNn6oam+HVsTPoxKSvkapE=; b=zx+z5nUfPTnN3iFgAf0RPRAf76gaWkMk4BwyjWiyG9R4Z05tQXXPHnFUwpvt/q6OU2 zLa3KT/mHWzHHztHACIW06sZudWx8YhyK7lerM/EtYk0bHmRnu7GDG0z+rGR7STRSk9e drK/0lljN3PhbuQ0ugbpokCUEfBlyONHIT0kli5BJziQxeF79FoszRtK643Pz9TZO6fZ DmsVBNr7bUdkHP17WC8qD51NijtfoHb8hx7a8KY+orA73EXFLg1xygPxTXGLxf7PGeFH 8PSsGTf7DgOEj6/I+day+tw4giYbekNiz8cc2idGKerM1TPVoEXtF3jNEFKTcbd48RuK BOdQ== 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=KwDjwry99t46Fp6itpoRnYNn6oam+HVsTPoxKSvkapE=; b=CtIcOzM0RhN5p7pyqH9O6UcMxt0LDC4yTq9ZCdPReHphLi4F9zx5my+l2vGG/xBwat 7gU0i0XGobRbRADRFB5fhZt+eoreEVzj0RijAgaWiZRmqgKjyKWvtUfQjyBNE+ES7kfR epSNHE03a+ec4ZDWjBAui54rjQqlZzfNBp5KPxxVSFranHFynB+DGkwpaI3OQS8agPUn M3GwMqO2Kk1Svl8H4TJg35sI67B517/tTQ5OaBG6wAFw3pFnUFBqOdooRus14RQSxmk/ RODKBINmOkQufbkPuXvW9uXJXwTL58dAiObkIQ4coDDbJMPC92eWoOr9KQ2c7LJmVjWU EV9A== X-Gm-Message-State: ALKqPwf8S2V9Ss7fc+PkW8eyzPiWmOCeSneexR3V7kH809gYXlfWjRKc nVOjhtb2VUT2/UdLlf91UHdPw/Qk X-Google-Smtp-Source: ADUXVKIQRrEgns/S2xZjUgbmIbjE5dZlJMlOcivdjnbZF74dy1A49nzP6IwIalXoZhQvCLJeeQAoFg== X-Received: by 2002:a1c:9595:: with SMTP id x143-v6mr8186260wmd.146.1527460113864; Sun, 27 May 2018 15:28:33 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Mon, 28 May 2018 00:28:22 +0200 Message-Id: <20180527222826.18525-4-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.25]); Sun, 27 May 2018 22:28:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sun, 27 May 2018 22:28:35 +0000 (UTC) for IP:'74.125.82.66' DOMAIN:'mail-wm0-f66.google.com' HELO:'mail-wm0-f66.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.66 mail-wm0-f66.google.com 74.125.82.66 mail-wm0-f66.google.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCHv3 3/7] vmx: 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.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.46]); Sun, 27 May 2018 22:28:55 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Signed-off-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/vmx/vmx.c | 194 +++++++++++++++++++++---------------------------------= ---- 1 file changed, 70 insertions(+), 124 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index df6a58a474..b6df257144 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -722,39 +722,36 @@ virVMXConvertToUTF8(const char *encoding, const char = *string) =20 =20 static int -virVMXGetConfigString(virConfPtr conf, const char *name, char **string, - bool optional) +virVMXGetConfigStringHelper(virConfPtr conf, const char *name, char **stri= ng, + bool optional) { - virConfValuePtr value; - + int rc; *string =3D NULL; - value =3D virConfGetValue(conf, name); =20 - if (value =3D=3D NULL) { - if (optional) - return 0; + rc =3D virConfGetValueString(conf, name, string); + if (rc =3D=3D 1 && *string !=3D NULL) + return 1; =20 - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), name); - return -1; - } + if (optional) + return 0; =20 - if (value->type !=3D VIR_CONF_STRING) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Config entry '%s' must be a string"), name); - return -1; - } + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Missing essential config entry '%s'"), name); + return -1; +} =20 - if (value->str =3D=3D NULL) { - if (optional) - return 0; =20 - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), name); + +static int +virVMXGetConfigString(virConfPtr conf, const char *name, char **string, + bool optional) +{ + *string =3D NULL; + + if (virVMXGetConfigStringHelper(conf, name, string, optional) < 0) return -1; - } =20 - return VIR_STRDUP(*string, value->str); + return 0; } =20 =20 @@ -763,43 +760,26 @@ static int virVMXGetConfigUUID(virConfPtr conf, const char *name, unsigned char *uuid, bool optional) { - virConfValuePtr value; - - value =3D virConfGetValue(conf, name); + char *string =3D NULL; + int ret =3D -1; + int rc; =20 - if (value =3D=3D NULL) { - if (optional) { - return 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), name); - return -1; - } - } + rc =3D virVMXGetConfigStringHelper(conf, name, &string, optional); + if (rc <=3D 0) + return rc; =20 - if (value->type !=3D VIR_CONF_STRING) { + rc =3D virUUIDParse(string, uuid); + if (rc < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Config entry '%s' must be a string"), name); - return -1; - } - - if (value->str =3D=3D NULL) { - if (optional) { - return 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), name); - return -1; - } + _("Could not parse UUID from string '%s'"), string); + goto cleanup; } =20 - if (virUUIDParse(value->str, uuid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not parse UUID from string '%s'"), value->= str); - return -1; - } + ret =3D 0; =20 - return 0; + cleanup: + VIR_FREE(string); + return ret; } =20 =20 @@ -808,47 +788,30 @@ static int virVMXGetConfigLong(virConfPtr conf, const char *name, long long *number, long long default_, bool optional) { - virConfValuePtr value; + char *string =3D NULL; + int ret =3D -1; + int rc; =20 *number =3D default_; - value =3D virConfGetValue(conf, name); =20 - if (value =3D=3D NULL) { - if (optional) { - return 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), name); - return -1; - } - } - - if (value->type =3D=3D VIR_CONF_STRING) { - if (value->str =3D=3D NULL) { - if (optional) { - return 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), n= ame); - return -1; - } - } + rc =3D virVMXGetConfigStringHelper(conf, name, &string, optional); + if (rc <=3D 0) + return rc; =20 - if (STRCASEEQ(value->str, "unlimited")) { - *number =3D -1; - } else if (virStrToLong_ll(value->str, NULL, 10, number) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Config entry '%s' must represent an integer = value"), - name); - return -1; - } - } else { + if (STRCASEEQ(string, "unlimited")) { + *number =3D -1; + } else if (virStrToLong_ll(string, NULL, 10, number) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Config entry '%s' must be a string"), name); - return -1; + _("Config entry '%s' must represent an integer value"), + name); + goto cleanup; } =20 - return 0; + ret =3D 0; + + cleanup: + VIR_FREE(string); + return ret; } =20 =20 @@ -857,49 +820,32 @@ static int virVMXGetConfigBoolean(virConfPtr conf, const char *name, bool *boolean_, bool default_, bool optional) { - virConfValuePtr value; + char *string =3D NULL; + int ret =3D -1; + int rc; =20 *boolean_ =3D default_; - value =3D virConfGetValue(conf, name); =20 - if (value =3D=3D NULL) { - if (optional) { - return 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), name); - return -1; - } - } - - if (value->type =3D=3D VIR_CONF_STRING) { - if (value->str =3D=3D NULL) { - if (optional) { - return 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), n= ame); - return -1; - } - } + rc =3D virVMXGetConfigStringHelper(conf, name, &string, optional); + if (rc <=3D 0) + return rc; =20 - if (STRCASEEQ(value->str, "true")) { - *boolean_ =3D 1; - } else if (STRCASEEQ(value->str, "false")) { - *boolean_ =3D 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Config entry '%s' must represent a boolean v= alue " - "(true|false)"), name); - return -1; - } + if (STRCASEEQ(string, "true")) { + *boolean_ =3D 1; + } else if (STRCASEEQ(string, "false")) { + *boolean_ =3D 0; } else { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Config entry '%s' must be a string"), name); - return -1; + _("Config entry '%s' must represent a boolean value= " + "(true|false)"), name); + goto cleanup; } =20 - return 0; + ret =3D 0; + + cleanup: + VIR_FREE(string); + return ret; } =20 =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 05:24:14 2024 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 1527460162644781.4753883085534; Sun, 27 May 2018 15:29:22 -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 508463157116; Sun, 27 May 2018 22:29:21 +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 1DF149420A; Sun, 27 May 2018 22:29:21 +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 B5C7A4CA89; Sun, 27 May 2018 22:29:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4RMSnme015020 for ; Sun, 27 May 2018 18:28:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id AA83B17D25; Sun, 27 May 2018 22:28:49 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A34115DD6B for ; Sun, 27 May 2018 22:28:47 +0000 (UTC) Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) (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 551BB19D2BB for ; Sun, 27 May 2018 22:28:36 +0000 (UTC) Received: by mail-wr0-f195.google.com with SMTP id i12-v6so17316638wrc.4 for ; Sun, 27 May 2018 15:28:36 -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.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 May 2018 15:28:34 -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=OIa2uaM/OVZ5pXxcqRPqKOZQDp/vcFn4O6HXcdaxUH4=; b=WADrTKtsDCKJtU54NdJAfzRDoacJ87W58SoJF8HutJdZCC1Z8nghH75RfNe6a5NxL0 SaaIW9tiEQ945+4NJBYTDFLGa6fVOVN0WA+hY3FwsKuzEZwHaDrICgSCKcEVIv0V8C+y NbFqqA+9PTUyIiote8K3GWRANsaiDXMDhivqmxzIfxG5pgzxOhAnK02uodRC3gtP/Ka0 tFplFpCrbC1f9jAmPSFTHvn7zRS4aqR7Pyq5tfgfif7uJ3q48u81B2yJ+uqCap+5VTrg xM/jHtm7xVIg8Q6w6XthwTlMTz5rlFSHxbJkSLmxX+ypcoCaNcPR7t2Ac3sWZkoP+z4t Nf9w== 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=OIa2uaM/OVZ5pXxcqRPqKOZQDp/vcFn4O6HXcdaxUH4=; b=q4vL5ELHNHV3oVJxRFYgox2aWwmm384Ni0LfL9SKz+JvZL7KJ5sfo3Lpo5l+0z/Ayk Ts8AdIkO0fuKIJoWpDDkcCQdVT9uYOn5NwlKgbfPWvOjBWCKM5FrERp4s4/otpqP6JY0 SXHR9BEE/wyzvH54TDA/YnWT6Jt8/uos6pU25lygyc0YEPbdrOSDA1juyTDTgnjjqyCB v6YYwAt3UJp8SgL7GWd/0ru6SHCmu9+TBpcTqmux+fLkJoKorA4NzYEeWVBpfJx56Iut yJUdWPIxlkO/a4iSj2Ci4ihZFeYE8jyw1lkdsuEjgyBRz9JI+oTPSmulBe3Pp5NVn1Ep aMbw== X-Gm-Message-State: ALKqPwfNOpP2A14MDMT/XbzTSXKFuCUVNZ/sbUff6kBI/QMlmib3/laA k66zx0SUQE4Ktfr1AQTDuOJNcQe0 X-Google-Smtp-Source: AB8JxZrmrkDolFIDrozO5qasExxPd1zxo4m6cYes963AkZphjCU7c+mg99geVzXhEqCaGTdBfz7J9g== X-Received: by 2002:adf:e70d:: with SMTP id c13-v6mr9485736wrm.203.1527460114698; Sun, 27 May 2018 15:28:34 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Mon, 28 May 2018 00:28:23 +0200 Message-Id: <20180527222826.18525-5-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.39]); Sun, 27 May 2018 22:28:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sun, 27 May 2018 22:28:36 +0000 (UTC) for IP:'209.85.128.195' DOMAIN:'mail-wr0-f195.google.com' HELO:'mail-wr0-f195.google.com' FROM:'fabiano@fidencio.org' RCPT:'' X-RedHat-Spam-Score: -1.597 (DKIM_SIGNED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID) 209.85.128.195 mail-wr0-f195.google.com 209.85.128.195 mail-wr0-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCHv3 4/7] xen_common: Split per-PCI logic from xenParsePCI() 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.49]); Sun, 27 May 2018 22:29:21 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 xenParsePCI() does a lot of stuff and, in order to make things cleaner, let's split it in two new functions: - xenParsePCI(): it's a new function that keeps the old name. It's responsible for the whole per-PCI logic from the old xenParsePCI(); - xenParsePCIList(): it's basically the old xenParsePCI(), but now it just iterates over the list of PCIs, calling xenParsePCI() per each PCI. 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_common.c | 167 ++++++++++++++++++++++++-----------------= ---- 1 file changed, 89 insertions(+), 78 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index a2b0708ee3..fc7b0683b8 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -389,92 +389,103 @@ xenParseEventsActions(virConfPtr conf, virDomainDefP= tr def) } =20 =20 -static int -xenParsePCI(virConfPtr conf, virDomainDefPtr def) +static virDomainHostdevDefPtr +xenParsePCI(char *entry) { - virConfValuePtr list =3D virConfGetValue(conf, "pci"); virDomainHostdevDefPtr hostdev =3D NULL; + char domain[5]; + char bus[3]; + char slot[3]; + char func[2]; + char *key, *nextkey; + int domainID; + int busID; + int slotID; + int funcID; + + domain[0] =3D bus[0] =3D slot[0] =3D func[0] =3D '\0'; + + /* pci=3D['0000:00:1b.0','0000:00:13.0'] */ + if (!(key =3D entry)) + return NULL; + if (!(nextkey =3D strchr(key, ':'))) + return NULL; + if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) =3D=3D NU= LL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Domain %s too big for destination"), key); + return NULL; + } =20 - if (list && list->type =3D=3D VIR_CONF_LIST) { - list =3D list->list; - while (list) { - char domain[5]; - char bus[3]; - char slot[3]; - char func[2]; - char *key, *nextkey; - int domainID; - int busID; - int slotID; - int funcID; - - domain[0] =3D bus[0] =3D slot[0] =3D func[0] =3D '\0'; + key =3D nextkey + 1; + if (!(nextkey =3D strchr(key, ':'))) + return NULL; + if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Bus %s too big for destination"), key); + return NULL; + } =20 - if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NUL= L)) - goto skippci; - /* pci=3D['0000:00:1b.0','0000:00:13.0'] */ - if (!(key =3D list->str)) - goto skippci; - if (!(nextkey =3D strchr(key, ':'))) - goto skippci; - if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) = =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Domain %s too big for destination"), key= ); - goto skippci; - } + key =3D nextkey + 1; + if (!(nextkey =3D strchr(key, '.'))) + return NULL; + if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Slot %s too big for destination"), key); + return NULL; + } =20 - key =3D nextkey + 1; - if (!(nextkey =3D strchr(key, ':'))) - goto skippci; - if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) =3D=3D = NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Bus %s too big for destination"), key); - goto skippci; - } + key =3D nextkey + 1; + if (strlen(key) !=3D 1) + return NULL; + if (virStrncpy(func, key, 1, sizeof(func)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Function %s too big for destination"), key); + return NULL; + } =20 - key =3D nextkey + 1; - if (!(nextkey =3D strchr(key, '.'))) - goto skippci; - if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) =3D= =3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Slot %s too big for destination"), key); - goto skippci; - } + if (virStrToLong_i(domain, NULL, 16, &domainID) < 0) + return NULL; + if (virStrToLong_i(bus, NULL, 16, &busID) < 0) + return NULL; + if (virStrToLong_i(slot, NULL, 16, &slotID) < 0) + return NULL; + if (virStrToLong_i(func, NULL, 16, &funcID) < 0) + return NULL; =20 - key =3D nextkey + 1; - if (strlen(key) !=3D 1) - goto skippci; - if (virStrncpy(func, key, 1, sizeof(func)) =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Function %s too big for destination"), k= ey); - goto skippci; - } + if (!(hostdev =3D virDomainHostdevDefNew())) + return NULL; =20 - if (virStrToLong_i(domain, NULL, 16, &domainID) < 0) - goto skippci; - if (virStrToLong_i(bus, NULL, 16, &busID) < 0) - goto skippci; - if (virStrToLong_i(slot, NULL, 16, &slotID) < 0) - goto skippci; - if (virStrToLong_i(func, NULL, 16, &funcID) < 0) - goto skippci; - if (!(hostdev =3D virDomainHostdevDefNew())) - return -1; - - hostdev->managed =3D false; - hostdev->source.subsys.type =3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE= _PCI; - hostdev->source.subsys.u.pci.addr.domain =3D domainID; - hostdev->source.subsys.u.pci.addr.bus =3D busID; - hostdev->source.subsys.u.pci.addr.slot =3D slotID; - hostdev->source.subsys.u.pci.addr.function =3D funcID; - - if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev)= < 0) { - virDomainHostdevDefFree(hostdev); - return -1; - } + hostdev->managed =3D false; + hostdev->source.subsys.type =3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI; + hostdev->source.subsys.u.pci.addr.domain =3D domainID; + hostdev->source.subsys.u.pci.addr.bus =3D busID; + hostdev->source.subsys.u.pci.addr.slot =3D slotID; + hostdev->source.subsys.u.pci.addr.function =3D funcID; =20 - skippci: - list =3D list->next; + return hostdev; +} + + +static int +xenParsePCIList(virConfPtr conf, virDomainDefPtr def) +{ + virConfValuePtr list =3D virConfGetValue(conf, "pci"); + + if (!list || list->type !=3D VIR_CONF_LIST) + return 0; + + for (list =3D list->list; list; list =3D list->next) { + virDomainHostdevDefPtr hostdev; + + if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NULL)) + continue; + + if (!(hostdev =3D xenParsePCI(list->str))) + return -1; + + if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0= ) { + virDomainHostdevDefFree(hostdev); + return -1; } } =20 @@ -1126,7 +1137,7 @@ xenParseConfigCommon(virConfPtr conf, return -1; } =20 - if (xenParsePCI(conf, def) < 0) + if (xenParsePCIList(conf, def) < 0) return -1; =20 if (xenParseEmulatedDevices(conf, def) < 0) --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 05:24:14 2024 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 15274601368884.14370975470365; Sun, 27 May 2018 15:28:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B74E431570FF; Sun, 27 May 2018 22:28:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 676D761F5E; Sun, 27 May 2018 22:28:54 +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 831E418033F1; Sun, 27 May 2018 22:28:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4RMSpOE015039 for ; Sun, 27 May 2018 18:28:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6EEF69420A; Sun, 27 May 2018 22:28:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6413A92EE4 for ; Sun, 27 May 2018 22:28:49 +0000 (UTC) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) (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 9F8BDC007604 for ; Sun, 27 May 2018 22:28:37 +0000 (UTC) Received: by mail-wr0-f193.google.com with SMTP id w10-v6so17296401wrk.9 for ; Sun, 27 May 2018 15:28:37 -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.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 May 2018 15:28:35 -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=40nBivKilYljMBrFw4cjjWVTC2BtyO/8yTJc5t26wgQ=; b=pClok3gSjFmKATu248+3/bQMVnTUBwiDapLtAngx/BWn69UXoVWPk4XirtTvz/a9Dl TxCsAVp0OLIZ6TZyQTcQSsWCJx7WJ7y2DyZTt07GGeF3wbTDEW92vuG2hk6Yy3QGBs9Q 41G0EVRxaZB038Lf3apW/9RoaqbniISf09CLjcLQ/eDZ780YjJ/L0N8tb15DJ5Y2FjUu /ZBohMupC2HH8FQOSbUPmUKiHUdK8MOhX90YPO5hO/cQgi9OS7DLqfB30ETu8o++0Gxg BGiSC34xdp6TVsMwrFR7tR/oJilUnXRQlb7QdUmYAatb5G3dtYqsoR4AjoU2alW/S1P1 S8sw== 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=40nBivKilYljMBrFw4cjjWVTC2BtyO/8yTJc5t26wgQ=; b=GzePQ7gssMgqklMiNlFtp9r5QXUuIU7S4Fl7XVDzHk1Hc5mXwrMuDfz8tbNpuRIQUS qdXofOb9ips0QSP1avwux/oyMG6dUZ3Xn+v/MH7NpUJZIkOG1rnUEwTBulPonVprdPYC fcEFGQWj63dlL+0reScRyxrtP48uQrXrC7VYkiGZAl+uJv2xPbV965IHbBPQZIqgViU/ tVlJJ6unKWXP358tMF9BR7Pxs3fNQzPDv7bzaWbBz3/PjLe8SR5sHIKzfGjP0gsaNIcr mopxSDqcWvgWxn9CDo5/dqov1B9HF4b14hpDaP+I2We9oTzQcWQ+NbY1STYD7w5MlLHw LuBA== X-Gm-Message-State: ALKqPwdrNu7vZEVJ/nykppH2BCUKPFC/UOU257Eu81CkE+VpHwFTQnri 3CM4Ryqy6yJ7oqqoh9ubp+vyR/zl X-Google-Smtp-Source: AB8JxZo+ETekWvsxvvS8mKYuLdvE1fWDci+E2mzncZV3eituX35SCnWNkFIyvS/Z+J4cUV5yNxveuQ== X-Received: by 2002:adf:9365:: with SMTP id 92-v6mr9849178wro.283.1527460115591; Sun, 27 May 2018 15:28:35 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Mon, 28 May 2018 00:28:24 +0200 Message-Id: <20180527222826.18525-6-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.32]); Sun, 27 May 2018 22:28:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 27 May 2018 22:28:38 +0000 (UTC) for IP:'209.85.128.193' DOMAIN:'mail-wr0-f193.google.com' HELO:'mail-wr0-f193.google.com' FROM:'fabiano@fidencio.org' RCPT:'' X-RedHat-Spam-Score: -1.597 (DKIM_SIGNED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID) 209.85.128.193 mail-wr0-f193.google.com 209.85.128.193 mail-wr0-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCHv3 5/7] xen_common: Split per-Vfi logic from xenParseVif() 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sun, 27 May 2018 22:28:55 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 xenParseVfi() does a lot of stuff and, in order to make things cleaner, let's split it in two new functions: - xenParseVfi(): it's a new function that keeps the old name. It's responsible for the whole per-Vfi logic from the old xenParseVfi(); - xenParseVfiList(): it's basically the old xenParsePCI(), but now it just iterates over the list of Vfis, calling xenParsePCI() per each Vfi. This patch is basically preparing the ground for the future when typesafe virConf acessors will be used. Signed-off-by: Fabiano Fid=C3=AAncio --- src/xenconfig/xen_common.c | 363 ++++++++++++++++++++++++-----------------= ---- 1 file changed, 192 insertions(+), 171 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index fc7b0683b8..45fecbced8 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -846,202 +846,223 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr de= f, const char *nativeFormat) } =20 =20 -static int -xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename) +static virDomainNetDefPtr +xenParseVif(char *entry, const char *vif_typename) { - char *script =3D NULL; virDomainNetDefPtr net =3D NULL; - virConfValuePtr list =3D virConfGetValue(conf, "vif"); + char *script =3D NULL; + char model[10]; + char type[10]; + char ip[128]; + char mac[18]; + char bridge[50]; + char vifname[50]; + char rate[50]; + char *key; + int rc =3D 0; + + bridge[0] =3D '\0'; + mac[0] =3D '\0'; + ip[0] =3D '\0'; + model[0] =3D '\0'; + type[0] =3D '\0'; + vifname[0] =3D '\0'; + rate[0] =3D '\0'; + + key =3D entry; + while (key) { + char *data; + char *nextkey =3D strchr(key, ','); + + if (!(data =3D strchr(key, '=3D'))) + return NULL; + data++; + + if (STRPREFIX(key, "mac=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(mac) - 1; + if (virStrncpy(mac, data, len, sizeof(mac)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("MAC address %s too big for destination"), + data); + return NULL; + } + } else if (STRPREFIX(key, "bridge=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(bridge) - 1; + if (virStrncpy(bridge, data, len, sizeof(bridge)) =3D=3D NULL)= { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Bridge %s too big for destination"), + data); + return NULL; + } + } else if (STRPREFIX(key, "script=3D")) { + int len =3D nextkey ? (nextkey - data) : strlen(data); + VIR_FREE(script); + if (VIR_STRNDUP(script, data, len) < 0) + return NULL; + } else if (STRPREFIX(key, "model=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(model) - 1; + if (virStrncpy(model, data, len, sizeof(model)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Model %s too big for destination"), + data); + return NULL; + } + } else if (STRPREFIX(key, "type=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(type) - 1; + if (virStrncpy(type, data, len, sizeof(type)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Type %s too big for destination"), + data); + return NULL; + } + } else if (STRPREFIX(key, "vifname=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(vifname) - 1; + if (virStrncpy(vifname, data, len, sizeof(vifname)) =3D=3D NUL= L) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Vifname %s too big for destination"), + data); + return NULL; + } + } else if (STRPREFIX(key, "ip=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(ip) - 1; + if (virStrncpy(ip, data, len, sizeof(ip)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("IP %s too big for destination"), data); + return NULL; + } + } else if (STRPREFIX(key, "rate=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(rate) - 1; + if (virStrncpy(rate, data, len, sizeof(rate)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("rate %s too big for destination"), data); + return NULL; + } + } =20 - if (list && list->type =3D=3D VIR_CONF_LIST) { - list =3D list->list; - while (list) { - char model[10]; - char type[10]; - char ip[128]; - char mac[18]; - char bridge[50]; - char vifname[50]; - char rate[50]; - char *key; - - bridge[0] =3D '\0'; - mac[0] =3D '\0'; - ip[0] =3D '\0'; - model[0] =3D '\0'; - type[0] =3D '\0'; - vifname[0] =3D '\0'; - rate[0] =3D '\0'; - - if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NUL= L)) - goto skipnic; - - key =3D list->str; - while (key) { - char *data; - char *nextkey =3D strchr(key, ','); + while (nextkey && (nextkey[0] =3D=3D ',' || + nextkey[0] =3D=3D ' ' || + nextkey[0] =3D=3D '\t')) + nextkey++; + key =3D nextkey; + } =20 - if (!(data =3D strchr(key, '=3D'))) - goto skipnic; - data++; - - if (STRPREFIX(key, "mac=3D")) { - int len =3D nextkey ? (nextkey - data) : sizeof(mac) -= 1; - if (virStrncpy(mac, data, len, sizeof(mac)) =3D=3D NUL= L) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("MAC address %s too big for desti= nation"), - data); - goto skipnic; - } - } else if (STRPREFIX(key, "bridge=3D")) { - int len =3D nextkey ? (nextkey - data) : sizeof(bridge= ) - 1; - if (virStrncpy(bridge, data, len, sizeof(bridge)) =3D= =3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Bridge %s too big for destinatio= n"), - data); - goto skipnic; - } - } else if (STRPREFIX(key, "script=3D")) { - int len =3D nextkey ? (nextkey - data) : strlen(data); - VIR_FREE(script); - if (VIR_STRNDUP(script, data, len) < 0) - goto cleanup; - } else if (STRPREFIX(key, "model=3D")) { - int len =3D nextkey ? (nextkey - data) : sizeof(model)= - 1; - if (virStrncpy(model, data, len, sizeof(model)) =3D=3D= NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Model %s too big for destination= "), - data); - goto skipnic; - } - } else if (STRPREFIX(key, "type=3D")) { - int len =3D nextkey ? (nextkey - data) : sizeof(type) = - 1; - if (virStrncpy(type, data, len, sizeof(type)) =3D=3D N= ULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Type %s too big for destination"= ), - data); - goto skipnic; - } - } else if (STRPREFIX(key, "vifname=3D")) { - int len =3D nextkey ? (nextkey - data) : sizeof(vifnam= e) - 1; - if (virStrncpy(vifname, data, len, sizeof(vifname)) = =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Vifname %s too big for destinati= on"), - data); - goto skipnic; - } - } else if (STRPREFIX(key, "ip=3D")) { - int len =3D nextkey ? (nextkey - data) : sizeof(ip) - = 1; - if (virStrncpy(ip, data, len, sizeof(ip)) =3D=3D NULL)= { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("IP %s too big for destination"),= data); - goto skipnic; - } - } else if (STRPREFIX(key, "rate=3D")) { - int len =3D nextkey ? (nextkey - data) : sizeof(rate) = - 1; - if (virStrncpy(rate, data, len, sizeof(rate)) =3D=3D N= ULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("rate %s too big for destination"= ), data); - goto skipnic; - } - } + if (VIR_ALLOC(net) < 0) + goto cleanup; =20 - while (nextkey && (nextkey[0] =3D=3D ',' || - nextkey[0] =3D=3D ' ' || - nextkey[0] =3D=3D '\t')) - nextkey++; - key =3D nextkey; - } + if (mac[0]) { + if (virMacAddrParse(mac, &net->mac) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("malformed mac address '%s'"), mac); + goto cleanup; + } + } =20 - if (VIR_ALLOC(net) < 0) - goto cleanup; + if (bridge[0] || STREQ_NULLABLE(script, "vif-bridge") || + STREQ_NULLABLE(script, "vif-vnic")) { + net->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + } else { + net->type =3D VIR_DOMAIN_NET_TYPE_ETHERNET; + } =20 - if (mac[0]) { - if (virMacAddrParse(mac, &net->mac) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("malformed mac address '%s'"), mac); - goto cleanup; - } - } + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE) { + if (bridge[0] && VIR_STRDUP(net->data.bridge.brname, bridge) < 0) + goto cleanup; + } + if (ip[0]) { + char **ip_list =3D virStringSplit(ip, " ", 0); + size_t i; =20 - if (bridge[0] || STREQ_NULLABLE(script, "vif-bridge") || - STREQ_NULLABLE(script, "vif-vnic")) { - net->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; - } else { - net->type =3D VIR_DOMAIN_NET_TYPE_ETHERNET; - } + if (!ip_list) + goto cleanup; =20 - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE) { - if (bridge[0] && VIR_STRDUP(net->data.bridge.brname, bridg= e) < 0) - goto cleanup; + for (i =3D 0; ip_list[i]; i++) { + if (virDomainNetAppendIPAddress(net, ip_list[i], 0, 0) < 0) { + virStringListFree(ip_list); + goto cleanup; } - if (ip[0]) { - char **ip_list =3D virStringSplit(ip, " ", 0); - size_t i; + } + virStringListFree(ip_list); + } =20 - if (!ip_list) - goto cleanup; + if (script && script[0]) { + rc =3D VIR_STRDUP(net->script, script); + if (rc < 0) + goto cleanup; + } =20 - for (i =3D 0; ip_list[i]; i++) { - if (virDomainNetAppendIPAddress(net, ip_list[i], 0, 0)= < 0) { - virStringListFree(ip_list); - goto cleanup; - } - } - virStringListFree(ip_list); - } + if (model[0]) { + rc =3D VIR_STRDUP(net->model, model); + if (rc < 0) + goto cleanup; + } =20 - if (script && script[0] && - VIR_STRDUP(net->script, script) < 0) - goto cleanup; + if (!model[0] && type[0] && STREQ(type, vif_typename)) { + rc =3D VIR_STRDUP(net->model, "netfront"); + if (rc < 0) + goto cleanup; + } =20 - if (model[0] && - VIR_STRDUP(net->model, model) < 0) - goto cleanup; + if (vifname[0]) { + rc =3D VIR_STRDUP(net->ifname, vifname); + if (rc < 0) + goto cleanup; + } =20 - if (!model[0] && type[0] && STREQ(type, vif_typename) && - VIR_STRDUP(net->model, "netfront") < 0) - goto cleanup; + if (rate[0]) { + virNetDevBandwidthPtr bandwidth; + unsigned long long kbytes_per_sec; =20 - if (vifname[0] && - VIR_STRDUP(net->ifname, vifname) < 0) - goto cleanup; + rc =3D xenParseSxprVifRate(rate, &kbytes_per_sec); + if (rc < 0) + goto cleanup; =20 - if (rate[0]) { - virNetDevBandwidthPtr bandwidth; - unsigned long long kbytes_per_sec; + rc =3D VIR_ALLOC(bandwidth); + if (rc < 0) + goto cleanup; + rc =3D VIR_ALLOC(bandwidth->out); + if (rc < 0) { + VIR_FREE(bandwidth); + goto cleanup; + } =20 - if (xenParseSxprVifRate(rate, &kbytes_per_sec) < 0) - goto cleanup; + bandwidth->out->average =3D kbytes_per_sec; + net->bandwidth =3D bandwidth; + } =20 - if (VIR_ALLOC(bandwidth) < 0) - goto cleanup; - if (VIR_ALLOC(bandwidth->out) < 0) { - VIR_FREE(bandwidth); - goto cleanup; - } + cleanup: + if (rc < 0) + virDomainNetDefFree(net); + VIR_FREE(script); + return net; +} =20 - bandwidth->out->average =3D kbytes_per_sec; - net->bandwidth =3D bandwidth; - } =20 - if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0) - goto cleanup; +static int +xenParseVifList(virConfPtr conf, virDomainDefPtr def, const char *vif_type= name) +{ + virConfValuePtr list =3D virConfGetValue(conf, "vif"); + + if (!list || list->type !=3D VIR_CONF_LIST) + return 0; =20 - skipnic: - list =3D list->next; + for (list =3D list->list; list; list =3D list->next) { + virDomainNetDefPtr net =3D NULL; + int rc; + + if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NULL)) + continue; + + if (!(net =3D xenParseVif(list->str, vif_typename))) + return -1; + + rc =3D VIR_APPEND_ELEMENT(def->nets, def->nnets, net); + if (rc < 0) { virDomainNetDefFree(net); - net =3D NULL; - VIR_FREE(script); + return -1; } } =20 return 0; - - cleanup: - virDomainNetDefFree(net); - VIR_FREE(script); - return -1; } =20 =20 @@ -1126,10 +1147,10 @@ xenParseConfigCommon(virConfPtr conf, return -1; =20 if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XL)) { - if (xenParseVif(conf, def, "vif") < 0) + if (xenParseVifList(conf, def, "vif") < 0) return -1; } else if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) { - if (xenParseVif(conf, def, "netfront") < 0) + if (xenParseVifList(conf, def, "netfront") < 0) return -1; } else { virReportError(VIR_ERR_INVALID_ARG, --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 05:24:14 2024 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 1527460153866635.4573991396894; Sun, 27 May 2018 15:29:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3F80ACD4CD; 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 081F25D6B5; 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 B25064CA85; Sun, 27 May 2018 22:29:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4RMSq8Z015050 for ; Sun, 27 May 2018 18:28:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 96A33171BE; Sun, 27 May 2018 22:28:52 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8CBAE5E1CD for ; Sun, 27 May 2018 22:28:49 +0000 (UTC) Received: from mail-wr0-f182.google.com (mail-wr0-f182.google.com [209.85.128.182]) (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 EED80C945B for ; Sun, 27 May 2018 22:28:37 +0000 (UTC) Received: by mail-wr0-f182.google.com with SMTP id d2-v6so1829607wrm.10 for ; Sun, 27 May 2018 15:28:37 -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.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 May 2018 15:28:35 -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=8HqwWyFbbGJGyOS3emfMZmhbIX1+h7VaQZ7B1YdM8LI=; b=p1L/DchE/YV7PX07zupU4zGUAlp9tvVZd+eXalZtzuvdWf2BFxDT9ogov4Hvx3K0GC vghmIRVoTU96SPYZsD+1cIxtqGpTpzZ8E4Ubg380fk732c6muzpb+MxWqe6BaWpKiSf1 YZzhAVKbdCGmFyxRpxpm/wSm5itC7wJGmF1y8XSp0l5eYHSD5z5UGJv6sSMn2ej+6naU AC5nwxrL21E2+nKeCdKZ4FecxoOkACbFzZRLpdcdCWAlL6EL+ujTlRq7GkYaBUJsIYzA YEhhPI5HX7bgzs2kCX6pfB8Xb1bBFGLkP7LtuLFKImPH0I8MVasxS/Fg54+3yQBkee2R 11bg== 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=8HqwWyFbbGJGyOS3emfMZmhbIX1+h7VaQZ7B1YdM8LI=; b=d0k8w42SFe4AaxfFDBf3t1g4Z6Q8dqwmk3cn3ysVBgpZpDAON19FOoIpsHQNHoGfP6 hG5Lxf6PeW2TY7zPKU+01cwn6fQixd6wJWyVqrcVQMkN8snkRFyhPPA3vbtQXBPFweBL qWFiZ77QjgMTd7Dcx6R9PVP3onNHLdhY0H8Fkn20Vn41ZcTawpTt98HlX+aHwE0gqaEt XEJapwm4cjSB40byGlRtmsVS20CzklkxqI9kYDYUA66733i8jvBqQdJToC/WTm+AzQ6L 0/2xvOV2z0ZNeO5OuXGfTyIIEND4t4CwGRbH/tErUKtT4+37qVJIKId47kalkD1iHbh6 eX9w== X-Gm-Message-State: ALKqPwe4XJg0rCa092JuRRgTJx23QuNgSfXzwoPqeaIxtreEuUm3wr3j p1WpMChIU3RBnd+mh4yUSceNx16I X-Google-Smtp-Source: AB8JxZpr05dnVbh5oddD/tR+phS4cGHJm7Z0tvjlwOe98mNJ7VVPHYwtEuaLyCRKYmSpSe3mKAsVSQ== X-Received: by 2002:adf:e843:: with SMTP id d3-v6mr9608797wrn.146.1527460116377; Sun, 27 May 2018 15:28:36 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Mon, 28 May 2018 00:28:25 +0200 Message-Id: <20180527222826.18525-7-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.26]); Sun, 27 May 2018 22:28:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 27 May 2018 22:28:38 +0000 (UTC) for IP:'209.85.128.182' DOMAIN:'mail-wr0-f182.google.com' HELO:'mail-wr0-f182.google.com' FROM:'fabiano@fidencio.org' RCPT:'' X-RedHat-Spam-Score: -1.597 (DKIM_SIGNED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID) 209.85.128.182 mail-wr0-f182.google.com 209.85.128.182 mail-wr0-f182.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCHv3 6/7] xen_common: convert to typesafe virConf acessors 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); 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 There are still a few places using virConfGetValue(), checking for the specific type of the pointers and so on. Those places are not going to be converted as: - Using virConfGetValue*() would trigger virReportError() in the current code, which would cause, at least, some misleading messages for whoever has to debug this code path; - Expanding virConfValue*() to support strings as other types (for instance, as boolean or long) does not seem to be the safest path to take. Signed-off-by: Fabiano Fid=C3=AAncio --- src/xenconfig/xen_common.c | 197 ++++++++++++++++++++++-------------------= ---- 1 file changed, 96 insertions(+), 101 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 45fecbced8..2ba1a19c39 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -145,31 +145,18 @@ xenConfigCopyStringInternal(virConfPtr conf, char **value, int allowMissing) { - virConfValuePtr val; + int rc; =20 *value =3D NULL; - if (!(val =3D virConfGetValue(conf, name))) { - if (allowMissing) - return 0; - virReportError(VIR_ERR_INTERNAL_ERROR, - _("config value %s was missing"), name); - return -1; - } =20 - if (val->type !=3D VIR_CONF_STRING) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("config value %s was not a string"), name); - return -1; - } - if (!val->str) { - if (allowMissing) - return 0; - virReportError(VIR_ERR_INTERNAL_ERROR, - _("config value %s was missing"), name); - return -1; - } + rc =3D virConfGetValueString(conf, name, value); + if (rc =3D=3D 1 && *value) + return 0; =20 - return VIR_STRDUP(*value, val->str); + if (allowMissing) + return 0; + + return -1; } =20 =20 @@ -193,43 +180,43 @@ xenConfigCopyStringOpt(virConfPtr conf, const char *n= ame, char **value) static int xenConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid) { - virConfValuePtr val; + char *string =3D NULL; + int ret =3D -1; =20 if (!uuid || !name || !conf) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Arguments must be non null")); - return -1; + goto cleanup; } =20 - if (!(val =3D virConfGetValue(conf, name))) { + if (virConfGetValueString(conf, name, &string) < 0) { if (virUUIDGenerate(uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to generate UUID")); - return -1; - } else { - return 0; + goto cleanup; } - } =20 - if (val->type !=3D VIR_CONF_STRING) { - virReportError(VIR_ERR_CONF_SYNTAX, - _("config value %s not a string"), name); - return -1; + ret =3D 0; + goto cleanup; } =20 - if (!val->str) { + if (!string) { virReportError(VIR_ERR_CONF_SYNTAX, _("%s can't be empty"), name); - return -1; + goto cleanup; } =20 - if (virUUIDParse(val->str, uuid) < 0) { + if (virUUIDParse(string, uuid) < 0) { virReportError(VIR_ERR_CONF_SYNTAX, - _("%s not parseable"), val->str); - return -1; + _("%s not parseable"), string); + goto cleanup; } =20 - return 0; + ret =3D 0; + + cleanup: + VIR_FREE(string); + return ret; } =20 =20 @@ -242,23 +229,16 @@ xenConfigGetString(virConfPtr conf, const char **value, const char *def) { - virConfValuePtr val; + char *string =3D NULL; =20 - *value =3D NULL; - if (!(val =3D virConfGetValue(conf, name))) { - *value =3D def; - return 0; - } + *value =3D def; =20 - if (val->type !=3D VIR_CONF_STRING) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("config value %s was malformed"), name); + if (virConfGetValueString(conf, name, &string) < 0) return -1; - } - if (!val->str) - *value =3D def; - else - *value =3D val->str; + + if (string) + *value =3D string; + return 0; } =20 @@ -469,27 +449,30 @@ xenParsePCI(char *entry) static int xenParsePCIList(virConfPtr conf, virDomainDefPtr def) { - virConfValuePtr list =3D virConfGetValue(conf, "pci"); + char **pcis =3D NULL, **entries; + int ret =3D -1; =20 - if (!list || list->type !=3D VIR_CONF_LIST) + if (virConfGetValueStringList(conf, "pci", false, &pcis) <=3D 0) return 0; =20 - for (list =3D list->list; list; list =3D list->next) { + for (entries =3D pcis; *entries; entries++) { + char *entry =3D *entries; virDomainHostdevDefPtr hostdev; =20 - if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NULL)) - continue; - - if (!(hostdev =3D xenParsePCI(list->str))) - return -1; + if (!(hostdev =3D xenParsePCI(entry))) + goto cleanup; =20 if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0= ) { virDomainHostdevDefFree(hostdev); - return -1; + goto cleanup; } } =20 - return 0; + ret =3D 0; + + cleanup: + virStringListFree(pcis); + return ret; } =20 =20 @@ -603,10 +586,11 @@ xenParseCPUFeatures(virConfPtr conf, static int xenParseVfb(virConfPtr conf, virDomainDefPtr def) { + int ret =3D -1; int val; + char **vfbs =3D NULL; char *listenAddr =3D NULL; int hvm =3D def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM; - virConfValuePtr list; virDomainGraphicsDefPtr graphics =3D NULL; =20 if (hvm) { @@ -662,17 +646,24 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) } =20 if (!hvm && def->graphics =3D=3D NULL) { /* New PV guests use this for= mat */ - list =3D virConfGetValue(conf, "vfb"); - if (list && list->type =3D=3D VIR_CONF_LIST && - list->list && list->list->type =3D=3D VIR_CONF_STRING && - list->list->str) { + char **entries; + int rc; + + rc =3D virConfGetValueStringList(conf, "vfb", false, &vfbs); + if (rc <=3D 0) { + ret =3D 0; + goto cleanup; + } + + for (entries =3D vfbs; *entries; entries++) { char vfb[MAX_VFB]; char *key =3D vfb; + char *entry =3D *entries; =20 - if (virStrcpyStatic(vfb, list->list->str) =3D=3D NULL) { + if (virStrcpyStatic(vfb, entry) =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, _("VFB %s too big for destination"), - list->list->str); + entry); goto cleanup; } =20 @@ -745,21 +736,24 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) } } =20 - return 0; + ret =3D 0; =20 cleanup: virDomainGraphicsDefFree(graphics); VIR_FREE(listenAddr); - return -1; + virStringListFree(vfbs); + return ret; } =20 =20 static int xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFo= rmat) { + + char **serials =3D NULL; const char *str; - virConfValuePtr value =3D NULL; virDomainChrDefPtr chr =3D NULL; + int ret =3D -1; =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { if (xenConfigGetString(conf, "parallel", &str, NULL) < 0) @@ -768,8 +762,10 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, = const char *nativeFormat) !(chr =3D xenParseSxprChar(str, NULL))) goto cleanup; if (chr) { - if (VIR_ALLOC_N(def->parallels, 1) < 0) + if (VIR_ALLOC_N(def->parallels, 1) < 0) { + virDomainChrDefFree(chr); goto cleanup; + } =20 chr->deviceType =3D VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL; chr->target.port =3D 0; @@ -779,8 +775,8 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, c= onst char *nativeFormat) } =20 /* Try to get the list of values to support multiple serial ports = */ - value =3D virConfGetValue(conf, "serial"); - if (value && value->type =3D=3D VIR_CONF_LIST) { + if (virConfGetValueStringList(conf, "serial", false, &serials) =3D= =3D 1) { + char **entries; int portnum =3D -1; =20 if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) { @@ -789,27 +785,21 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def,= const char *nativeFormat) goto cleanup; } =20 - value =3D value->list; - while (value) { - char *port =3D NULL; + for (entries =3D serials; *entries; entries++) { + char *port =3D *entries; =20 - if ((value->type !=3D VIR_CONF_STRING) || (value->str =3D= =3D NULL)) - goto cleanup; - port =3D value->str; portnum++; - if (STREQ(port, "none")) { - value =3D value->next; + if (STREQ(port, "none")) continue; - } =20 if (!(chr =3D xenParseSxprChar(port, NULL))) goto cleanup; chr->deviceType =3D VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; chr->target.port =3D portnum; - if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) <= 0) + if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) <= 0) { + virDomainChrDefFree(chr); goto cleanup; - - value =3D value->next; + } } } else { /* If domain is not using multiple serial ports we parse data = old way */ @@ -819,8 +809,10 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, = const char *nativeFormat) !(chr =3D xenParseSxprChar(str, NULL))) goto cleanup; if (chr) { - if (VIR_ALLOC_N(def->serials, 1) < 0) + if (VIR_ALLOC_N(def->serials, 1) < 0) { + virDomainChrDefFree(chr); goto cleanup; + } chr->deviceType =3D VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; chr->target.port =3D 0; def->serials[0] =3D chr; @@ -838,11 +830,11 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def,= const char *nativeFormat) def->consoles[0]->targetType =3D VIR_DOMAIN_CHR_CONSOLE_TARGET_TYP= E_XEN; } =20 - return 0; + ret =3D 0; =20 cleanup: - virDomainChrDefFree(chr); - return -1; + virStringListFree(serials); + return ret; } =20 =20 @@ -1040,29 +1032,32 @@ xenParseVif(char *entry, const char *vif_typename) static int xenParseVifList(virConfPtr conf, virDomainDefPtr def, const char *vif_type= name) { - virConfValuePtr list =3D virConfGetValue(conf, "vif"); + char **vifs =3D NULL, **entries; + int ret =3D -1; =20 - if (!list || list->type !=3D VIR_CONF_LIST) + if (virConfGetValueStringList(conf, "vif", false, &vifs) <=3D 0) return 0; =20 - for (list =3D list->list; list; list =3D list->next) { + for (entries =3D vifs; *entries; entries++) { virDomainNetDefPtr net =3D NULL; + char *entry =3D *entries; int rc; =20 - if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NULL)) - continue; - - if (!(net =3D xenParseVif(list->str, vif_typename))) - return -1; + if (!(net =3D xenParseVif(entry, vif_typename))) + goto cleanup; =20 rc =3D VIR_APPEND_ELEMENT(def->nets, def->nnets, net); if (rc < 0) { virDomainNetDefFree(net); - return -1; + goto cleanup; } } =20 - return 0; + ret =3D 0; + + cleanup: + virStringListFree(vifs); + return ret; } =20 =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 05:24:14 2024 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 1527460153830882.5838625977874; Sun, 27 May 2018 15:29:13 -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 3B3F530BF440; Sun, 27 May 2018 22:29:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 069BC9420A; 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 ADF8F18033F0; Sun, 27 May 2018 22:29:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4RMSptp015038 for ; Sun, 27 May 2018 18:28:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6E763941E0; Sun, 27 May 2018 22:28:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 651DE93DBC for ; Sun, 27 May 2018 22:28:49 +0000 (UTC) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) (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 BC972315710A for ; Sun, 27 May 2018 22:28:38 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id v131-v6so8142177wma.1 for ; Sun, 27 May 2018 15:28:38 -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.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 May 2018 15:28:36 -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=3pPCwMtFj7Tbbxhkkwdz8JbICFko3VWleZvbfTPvIuc=; b=EfjI7eX/XsjHE43Nk4BYF2+i3elk4gKmuUAhrr6KbH027lgqdwx7N75s9KZLF0cpHT Gw+UdE3JVNX7lsGzxSCVL9bV8byN4IPgjOJcr93HUj6Vyvky1gJzBIYyphfCASmZ6rSt fqqL+tHdaqbB1Po1NQSX3hFuDNoIiB9Lx5EjyFL9ccuXeGQqb25Cb40h63CaB7DItMOc /vS7YHFZrd+OrZjnKbfoTw8F3dvLyQzfkVzZVK3CqQldMkgnjtEKrTrmlZoOE9tv0grD RmbbFzZQGGpVlVgWdgiYScm8R0TW55XQQZu9DL01YdNnteXsBEJrCOK6wxL+gm8mh3r3 vSsQ== 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=3pPCwMtFj7Tbbxhkkwdz8JbICFko3VWleZvbfTPvIuc=; b=M1aiEz3JsM9waS41x+DOgp97cml6kvZBurR+LUxqNcfWPlZ/cdXNcwhToUOD4oz+h7 c5rfEONjAp2I8Jkoh86G/0aekGMcV9/DP1WYEoqpzQmjSwO+bQsI3dobKrPk9a5nmWd1 E/9On/7kiVilCBjCkffpiX1zQSGTwC+DUfBNDuTTHYqYqVcndiaZNTZRQf7z5i/F9MHt HqcBLtQmeAJLDIZ76TGug6oz/aKHxDLYmhcBuAEk1H95mKZrd5KmoIzJ/jCrTnIWp1O2 zEDTZcJB5oazIWKwgInSfmskg6lxJFL+iASV1Utug+FiopkYkcKOSf4VGDbFQJdnlFTo szCg== X-Gm-Message-State: ALKqPwfOA467ZsGBFUfZtqu+VTHz7sn/yfDo4vzmO6+/h1mAZHTdKKUq sgoGn2GaGNcSUYd2/a2ahl9KNiEU X-Google-Smtp-Source: ADUXVKIAo5+T91PX5rIl3jhJEmhXdE9+P9rjiWwMjvffbUXAcQXbJEGFNW8AthArqwRZ+9QHiBEY1Q== X-Received: by 2002:a1c:6803:: with SMTP id d3-v6mr8209324wmc.70.1527460117188; Sun, 27 May 2018 15:28:37 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Mon, 28 May 2018 00:28:26 +0200 Message-Id: <20180527222826.18525-8-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.49]); Sun, 27 May 2018 22:28:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sun, 27 May 2018 22:28:39 +0000 (UTC) for IP:'74.125.82.66' DOMAIN:'mail-wm0-f66.google.com' HELO:'mail-wm0-f66.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.66 mail-wm0-f66.google.com 74.125.82.66 mail-wm0-f66.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCHv3 7/7] xen_common: Fix a few memory leaks 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.48]); 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 While converting the functions of xen_common to use typesafe virConf acessors, I've spotted a few memory leaks, which are fixed in this patch. Signed-off-by: Fabiano Fid=C3=AAncio --- src/xenconfig/xen_common.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 2ba1a19c39..6d9ce9bd66 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -458,14 +458,16 @@ xenParsePCIList(virConfPtr conf, virDomainDefPtr def) for (entries =3D pcis; *entries; entries++) { char *entry =3D *entries; virDomainHostdevDefPtr hostdev; + int rc; =20 if (!(hostdev =3D xenParsePCI(entry))) goto cleanup; =20 - if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0= ) { - virDomainHostdevDefFree(hostdev); + rc =3D VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev); + virDomainHostdevDefFree(hostdev); + + if (rc < 0) goto cleanup; - } } =20 ret =3D 0; @@ -787,6 +789,7 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, c= onst char *nativeFormat) =20 for (entries =3D serials; *entries; entries++) { char *port =3D *entries; + int rc; =20 portnum++; if (STREQ(port, "none")) @@ -796,10 +799,11 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def,= const char *nativeFormat) goto cleanup; chr->deviceType =3D VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; chr->target.port =3D portnum; - if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) <= 0) { - virDomainChrDefFree(chr); + rc =3D VIR_APPEND_ELEMENT(def->serials, def->nserials, chr= ); + virDomainChrDefFree(chr); + + if (rc < 0) goto cleanup; - } } } else { /* If domain is not using multiple serial ports we parse data = old way */ @@ -1047,10 +1051,10 @@ xenParseVifList(virConfPtr conf, virDomainDefPtr de= f, const char *vif_typename) goto cleanup; =20 rc =3D VIR_APPEND_ELEMENT(def->nets, def->nnets, net); - if (rc < 0) { - virDomainNetDefFree(net); + virDomainNetDefFree(net); + + if (rc < 0) goto cleanup; - } } =20 ret =3D 0; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list