From nobody Mon May 6 12:55:51 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153667080593567.89742791366325; Tue, 11 Sep 2018 06:00:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C2B21305B891; Tue, 11 Sep 2018 13:00:03 +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 5F2912015AC5; Tue, 11 Sep 2018 13:00:03 +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 234F44BB7F; Tue, 11 Sep 2018 13:00:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8BCxxZk005633 for ; Tue, 11 Sep 2018 08:59:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1497AB27B4; Tue, 11 Sep 2018 12:59:59 +0000 (UTC) Received: from dahmer.brq.redhat.com (unknown [10.43.2.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 886436353B; Tue, 11 Sep 2018 12:59:58 +0000 (UTC) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Tue, 11 Sep 2018 14:59:49 +0200 Message-Id: <20180911125949.9966-2-fidencio@redhat.com> In-Reply-To: <20180911125949.9966-1-fidencio@redhat.com> References: <20180911125949.9966-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [libvirt PATCH v5 1/1] 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.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 11 Sep 2018 13:00:05 +0000 (UTC) X-ZohoMail: RDMRC_0 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. However, 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 neither the safest nor the preferential path to take. Signed-off-by: Fabiano Fid=C3=AAncio --- src/xenconfig/xen_common.c | 163 +++++++++++++++++-------------------- 1 file changed, 75 insertions(+), 88 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index fdca9845aa..c31ebfb270 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -145,31 +145,19 @@ 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; - } + rc =3D virConfGetValueString(conf, name, value); + if (rc =3D=3D 1 && *value) + return 0; =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; - } + if (allowMissing) + return 0; =20 - return VIR_STRDUP(*value, val->str); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("config value %s was missing"), name); + return -1; } =20 =20 @@ -193,7 +181,7 @@ 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; =20 if (!uuid || !name || !conf) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -201,7 +189,7 @@ xenConfigGetUUID(virConfPtr conf, const char *name, uns= igned char *uuid) return -1; } =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")); @@ -211,24 +199,20 @@ xenConfigGetUUID(virConfPtr conf, const char *name, u= nsigned char *uuid) } } =20 - if (val->type !=3D VIR_CONF_STRING) { - virReportError(VIR_ERR_CONF_SYNTAX, - _("config value %s not a string"), name); - return -1; - } - - 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 (virUUIDParse(string, uuid) < 0) { virReportError(VIR_ERR_CONF_SYNTAX, - _("%s not parseable"), val->str); + _("%s not parseable"), string); + VIR_FREE(string); return -1; } =20 + VIR_FREE(string); return 0; } =20 @@ -242,23 +226,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))) { + 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) + if (!string) *value =3D def; else - *value =3D val->str; + *value =3D string; return 0; } =20 @@ -469,27 +446,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 +583,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 +643,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) < 0) { + if (virStrcpyStatic(vfb, entry) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("VFB %s too big for destination"), - list->list->str); + entry); goto cleanup; } =20 @@ -745,21 +733,23 @@ 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) @@ -779,8 +769,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,18 +779,12 @@ 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; @@ -808,8 +792,6 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, c= onst char *nativeFormat) chr->target.port =3D portnum; if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) <= 0) goto cleanup; - - value =3D value->next; } } else { /* If domain is not using multiple serial ports we parse data = old way */ @@ -825,6 +807,7 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, c= onst char *nativeFormat) chr->target.port =3D 0; def->serials[0] =3D chr; def->nserials++; + chr =3D NULL; } } } else { @@ -838,11 +821,12 @@ 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 @@ -1031,29 +1015,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.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list