From nobody Wed May 14 10:55:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527368484569966.5249166656693; Sat, 26 May 2018 14:01:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 61AB91B3A82; Sat, 26 May 2018 21:01:22 +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 1D44E1690D; Sat, 26 May 2018 21:01: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 B6A244CA81; Sat, 26 May 2018 21:01:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4QL0lKo031708 for ; Sat, 26 May 2018 17:00:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 086B35D750; Sat, 26 May 2018 21:00:47 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F23C15D6A8 for ; Sat, 26 May 2018 21:00:46 +0000 (UTC) Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) (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 78A7E30CA2DF for ; Sat, 26 May 2018 21:00:34 +0000 (UTC) Received: by mail-wm0-f52.google.com with SMTP id x2-v6so15474685wmh.5 for ; Sat, 26 May 2018 14:00:34 -0700 (PDT) Received: from machado.local ([95.82.135.172]) by smtp.gmail.com with ESMTPSA id u89-v6sm10748062wma.4.2018.05.26.14.00.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 May 2018 14:00: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=0IzQrF4yjKVWMAlfROYQb4R1zmCyK2yROy3jK4ogIAA=; b=QkCxw06pp5u0MLswInNMyvQmJhbNL5xh6xOyoA1bMj2whP86VVW4FzHSsY2Nu9dR+7 rjXItA0SaA2It+zEqeJl2/yKoW8L65OI+frmqJDgqY24WwbkhH2EJ1uFpZLT5CPyKd9J K9UfXaQALLlzPjGoDShOzi388b4OqAFkvlStzrsVhB2azI6Owr+6Eci7w9Et0gEqddWN qupBZzR9Uyn3atf5lBLw41He8cX5hRzy9wQOCUxJmI+SjsLnfGzbQC9cZmbWGB+VsTZV TNFoY4oUa5haQFFGQs154HlvCWNkl8sQ4bSfv/5oOp8H/X0ElrJXxdMO774bWKpEZYM4 hRSQ== 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=0IzQrF4yjKVWMAlfROYQb4R1zmCyK2yROy3jK4ogIAA=; b=svP8F6Zth9mUSLbkwwRSTb4X/blN/eIX9FC/M7y5HFIezHCXlTFa0TdB0uXsMkDn4C tkEXH+Vqy4U8nS8qSDRu4etWvhKcT3HdJGyTwQklDUd4snGVeroyiBu0cHKH7mn9JoEY gPRy0oPhqI738MbXHLQoFpq2mfidptI8qq0mA4rcfPVPB+1SIFfPtGofPTtSKL9oaamO RjHn2qj8vtv095v5keQN7RKCyfXyupsdqH/irkfdKHMU+s8+cSt7iL0v1uUIvZA+wciE 4jpTXqFz3x3ZSENsiEtuN3QhN2smRYuxEdkRZLHt1Zx2EBCFCFyDwNpQersWQNa8Przi VwWg== X-Gm-Message-State: ALKqPweq5J7mb3+ENadcQ4MiYtxd2ZNZLgO6zLSoMcdwIAyfLlm8w6x0 AK3JMkcWf5VM0S5vAjyNoN4eQpQc X-Google-Smtp-Source: ADUXVKKTAEVZNeHBCDFFUu7fHWBUcgEwWr+SCnHR2haHn6A8mI1QyeG2Tuy+EaXyKG2CAcCiSHqoNQ== X-Received: by 2002:a1c:d046:: with SMTP id h67-v6mr4836928wmg.80.1527368432630; Sat, 26 May 2018 14:00:32 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Sat, 26 May 2018 23:00:27 +0200 Message-Id: <20180526210027.12066-4-fabiano@fidencio.org> In-Reply-To: <20180526210027.12066-1-fabiano@fidencio.org> References: <20180526210027.12066-1-fabiano@fidencio.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Sat, 26 May 2018 21:00:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Sat, 26 May 2018 21:00:35 +0000 (UTC) for IP:'74.125.82.52' DOMAIN:'mail-wm0-f52.google.com' HELO:'mail-wm0-f52.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.52 mail-wm0-f52.google.com 74.125.82.52 mail-wm0-f52.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= , =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCHv2 3/3] xen_common: 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 26 May 2018 21:01:23 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 From: Fabiano Fid=C3=AAncio There are still some places using virConfGetValue() and then checking the specific type of the pointers and so on. Those place are not going to be changed as: - Directly using virConfGetValue*() would trigger virReportError() on their current code - Expanding virConfGetValue*() to support strings as other types (as boolean or long) doesn't seem to be the safest path to take. Signed-off-by: Fabiano Fid=C3=AAncio --- src/xenconfig/xen_common.c | 637 ++++++++++++++++++++++-------------------= ---- 1 file changed, 307 insertions(+), 330 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index a2b0708ee3..2e8e95f720 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 result; =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; - } + result =3D virConfGetValueString(conf, name, value); + if (result =3D=3D 1 && *value !=3D NULL) + return 0; + + if (allowMissing) + return 0; =20 - return VIR_STRDUP(*value, val->str); + return -1; } =20 =20 @@ -193,7 +180,8 @@ xenConfigCopyStringOpt(virConfPtr conf, const char *nam= e, char **value) static int xenConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid) { - virConfValuePtr val; + char *string =3D NULL; + int result; =20 if (!uuid || !name || !conf) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -201,35 +189,35 @@ xenConfigGetUUID(virConfPtr conf, const char *name, u= nsigned char *uuid) return -1; } =20 - if (!(val =3D virConfGetValue(conf, name))) { - if (virUUIDGenerate(uuid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("Failed to generate UUID")); - return -1; - } else { - return 0; - } - } - - if (val->type !=3D VIR_CONF_STRING) { - virReportError(VIR_ERR_CONF_SYNTAX, - _("config value %s not a string"), name); + if (virConfGetValueString(conf, name, &string) < 0) return -1; - } =20 - if (!val->str) { + if (!string) { virReportError(VIR_ERR_CONF_SYNTAX, _("%s can't be empty"), name); return -1; } =20 - if (virUUIDParse(val->str, uuid) < 0) { + if (virUUIDGenerate(uuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("Failed to generate UUID")); + result =3D -1; + goto cleanup; + } + + if (virUUIDParse(string, uuid) < 0) { virReportError(VIR_ERR_CONF_SYNTAX, - _("%s not parseable"), val->str); - return -1; + _("%s not parseable"), string); + result =3D -1; + goto cleanup; } =20 - return 0; + result =3D 1; + + cleanup: + VIR_FREE(string); + + return result; } =20 =20 @@ -242,23 +230,15 @@ 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))) { + if (virConfGetValueString(conf, name, &string) < 0) { *value =3D def; - return 0; - } - - if (val->type !=3D VIR_CONF_STRING) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("config value %s was malformed"), name); return -1; } - if (!val->str) - *value =3D def; - else - *value =3D val->str; + + *value =3D string !=3D NULL ? string : def; + return 0; } =20 @@ -392,93 +372,92 @@ xenParseEventsActions(virConfPtr conf, virDomainDefPt= r def) static int xenParsePCI(virConfPtr conf, virDomainDefPtr def) { - virConfValuePtr list =3D virConfGetValue(conf, "pci"); virDomainHostdevDefPtr hostdev =3D NULL; + char **pcis =3D NULL, **entries; =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'; - - 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, ':'))) - 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 (!(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 (virConfGetValueStringList(conf, "pci", false, &pcis) <=3D 0) + return 0; =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; - } + for (entries =3D pcis; *entries; entries++) { + 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 *entries; + + /* pci=3D['0000:00:1b.0','0000:00:13.0'] */ + if (!(nextkey =3D strchr(key, ':'))) + continue; + if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) =3D=3D= NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Domain %s too big for destination"), key); + continue; + } + + key =3D nextkey + 1; + if (!(nextkey =3D strchr(key, ':'))) + continue; + if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) =3D=3D NULL)= { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Bus %s too big for destination"), key); + continue; + } + + key =3D nextkey + 1; + if (!(nextkey =3D strchr(key, '.'))) + continue; + if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) =3D=3D NUL= L) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Slot %s too big for destination"), key); + continue; + } + + key =3D nextkey + 1; + if (strlen(key) !=3D 1) + continue; + if (virStrncpy(func, key, 1, sizeof(func)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Function %s too big for destination"), key); + continue; + } + + if (virStrToLong_i(domain, NULL, 16, &domainID) < 0) + continue; + if (virStrToLong_i(bus, NULL, 16, &busID) < 0) + continue; + if (virStrToLong_i(slot, NULL, 16, &slotID) < 0) + continue; + if (virStrToLong_i(func, NULL, 16, &funcID) < 0) + continue; + if (!(hostdev =3D virDomainHostdevDefNew())) + goto cleanup; =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; - } + if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0)= { + virDomainHostdevDefFree(hostdev); + goto cleanup; + } } =20 + virStringListFree(pcis); return 0; + + cleanup: + virStringListFree(pcis); + return -1; } =20 =20 @@ -593,9 +572,9 @@ static int xenParseVfb(virConfPtr conf, virDomainDefPtr def) { int val; + char **vfbs =3D NULL, **entries; 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) { @@ -651,17 +630,18 @@ 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) { + if (virConfGetValueStringList(conf, "vfb", false, &vfbs) <=3D 0) + return 0; + + 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 @@ -734,11 +714,13 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) } } =20 + virStringListFree(vfbs); return 0; =20 cleanup: virDomainGraphicsDefFree(graphics); VIR_FREE(listenAddr); + virStringListFree(vfbs); return -1; } =20 @@ -746,11 +728,14 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) static int xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFo= rmat) { + char **serials =3D NULL, **entries; const char *str; virConfValuePtr value =3D NULL; virDomainChrDefPtr chr =3D NULL; =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { + int portnum =3D -1; + if (xenConfigGetString(conf, "parallel", &str, NULL) < 0) goto cleanup; if (str && STRNEQ(str, "none") && @@ -768,39 +753,7 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, = const 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) { - int portnum =3D -1; - - if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Multiple serial devices are not supporte= d by xen-xm")); - goto cleanup; - } - - value =3D value->list; - while (value) { - char *port =3D NULL; - - 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; - continue; - } - - 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) - goto cleanup; - - value =3D value->next; - } - } else { + if (virConfGetValueStringList(conf, "serial", false, &serials) <= =3D 0) { /* If domain is not using multiple serial ports we parse data = old way */ if (xenConfigGetString(conf, "serial", &str, NULL) < 0) goto cleanup; @@ -815,7 +768,33 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, = const char *nativeFormat) def->serials[0] =3D chr; def->nserials++; } + + return 0; + } + + if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Multiple serial devices are not supported by= xen-xm")); + goto cleanup; + } + + for (entries =3D serials; *entries; entries++) { + char *port =3D *entries; + + portnum++; + if (STREQ(port, "none")) { + value =3D value->next; + continue; + } + + 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) + goto cleanup; } + virStringListFree(serials); } else { if (VIR_ALLOC_N(def->consoles, 1) < 0) goto cleanup; @@ -831,6 +810,7 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, c= onst char *nativeFormat) =20 cleanup: virDomainChrDefFree(chr); + virStringListFree(serials); return -1; } =20 @@ -838,197 +818,194 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr de= f, const char *nativeFormat) static int xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename) { + char **vifs =3D NULL, **entries; char *script =3D NULL; virDomainNetDefPtr net =3D NULL; - virConfValuePtr list =3D virConfGetValue(conf, "vif"); - - 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; =20 - key =3D list->str; - while (key) { - char *data; - char *nextkey =3D strchr(key, ','); + if (virConfGetValueStringList(conf, "vif", false, &vifs) <=3D 0) + return 0; =20 - if (!(data =3D strchr(key, '=3D'))) + for (entries =3D vifs; *entries; entries++) { + char model[10]; + char type[10]; + char ip[128]; + char mac[18]; + char bridge[50]; + char vifname[50]; + char rate[50]; + char *key =3D *entries; + + 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'; + + while (key) { + char *data; + char *nextkey =3D strchr(key, ','); + + 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 NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("MAC address %s too big for destinati= on"), + data); 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; - } } - - while (nextkey && (nextkey[0] =3D=3D ',' || - nextkey[0] =3D=3D ' ' || - nextkey[0] =3D=3D '\t')) - nextkey++; - key =3D nextkey; - } - - if (VIR_ALLOC(net) < 0) - goto cleanup; - - if (mac[0]) { - if (virMacAddrParse(mac, &net->mac) < 0) { + } else if (STRPREFIX(key, "bridge=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(bridge) - = 1; + if (virStrncpy(bridge, data, len, sizeof(bridge)) =3D=3D N= ULL) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("malformed mac address '%s'"), mac); + _("Bridge %s too big for destination"), + 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 NUL= L) { + 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 NULL)= { + 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(vifname) -= 1; + if (virStrncpy(vifname, data, len, sizeof(vifname)) =3D=3D= NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Vifname %s too big for destination"), + 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"), dat= a); + 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 NULL)= { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("rate %s too big for destination"), d= ata); + goto skipnic; } } =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 (net->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE) { - if (bridge[0] && VIR_STRDUP(net->data.bridge.brname, bridg= e) < 0) - goto cleanup; - } - if (ip[0]) { - char **ip_list =3D virStringSplit(ip, " ", 0); - size_t i; + while (nextkey && (nextkey[0] =3D=3D ',' || + nextkey[0] =3D=3D ' ' || + nextkey[0] =3D=3D '\t')) + nextkey++; + key =3D nextkey; + } =20 - if (!ip_list) - goto cleanup; + if (VIR_ALLOC(net) < 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 (mac[0]) { + if (virMacAddrParse(mac, &net->mac) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("malformed mac address '%s'"), mac); + goto cleanup; } + } =20 - if (script && script[0] && - VIR_STRDUP(net->script, script) < 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 (model[0] && - VIR_STRDUP(net->model, model) < 0) + 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 (!model[0] && type[0] && STREQ(type, vif_typename) && - VIR_STRDUP(net->model, "netfront") < 0) + if (!ip_list) goto cleanup; =20 - if (vifname[0] && - VIR_STRDUP(net->ifname, vifname) < 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; + } + } + virStringListFree(ip_list); + } =20 - if (rate[0]) { - virNetDevBandwidthPtr bandwidth; - unsigned long long kbytes_per_sec; + if (script && script[0] && + VIR_STRDUP(net->script, script) < 0) + goto cleanup; =20 - if (xenParseSxprVifRate(rate, &kbytes_per_sec) < 0) - goto cleanup; + if (model[0] && + VIR_STRDUP(net->model, model) < 0) + goto cleanup; =20 - if (VIR_ALLOC(bandwidth) < 0) - goto cleanup; - if (VIR_ALLOC(bandwidth->out) < 0) { - VIR_FREE(bandwidth); - goto cleanup; - } + if (!model[0] && type[0] && STREQ(type, vif_typename) && + VIR_STRDUP(net->model, "netfront") < 0) + goto cleanup; =20 - bandwidth->out->average =3D kbytes_per_sec; - net->bandwidth =3D bandwidth; - } + if (vifname[0] && + VIR_STRDUP(net->ifname, vifname) < 0) + goto cleanup; =20 - if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0) + if (rate[0]) { + virNetDevBandwidthPtr bandwidth; + unsigned long long kbytes_per_sec; + + if (xenParseSxprVifRate(rate, &kbytes_per_sec) < 0) goto cleanup; =20 - skipnic: - list =3D list->next; - virDomainNetDefFree(net); - net =3D NULL; - VIR_FREE(script); + if (VIR_ALLOC(bandwidth) < 0) + goto cleanup; + if (VIR_ALLOC(bandwidth->out) < 0) { + VIR_FREE(bandwidth); + goto cleanup; + } + + bandwidth->out->average =3D kbytes_per_sec; + net->bandwidth =3D bandwidth; } + + if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0) + goto cleanup; + + skipnic: + virDomainNetDefFree(net); + net =3D NULL; + VIR_FREE(script); } =20 + virStringListFree(vifs); return 0; =20 cleanup: virDomainNetDefFree(net); + virStringListFree(vifs); VIR_FREE(script); return -1; } --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list