From nobody Sat Apr 27 18:14:36 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 1537450149717326.13719442326783; Thu, 20 Sep 2018 06:29:09 -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 C7D4230832E6; Thu, 20 Sep 2018 13:29:06 +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 592CD5C158; Thu, 20 Sep 2018 13:29:06 +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 DBDFB181A130; Thu, 20 Sep 2018 13:29:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8KDT2n3005072 for ; Thu, 20 Sep 2018 09:29:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 47CB816E5A; Thu, 20 Sep 2018 13:29:02 +0000 (UTC) Received: from dahmer.brq.redhat.com (unknown [10.43.2.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90AF219486; Thu, 20 Sep 2018 13:29:01 +0000 (UTC) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 15:28:47 +0200 Message-Id: <20180920132852.20280-2-fidencio@redhat.com> In-Reply-To: <20180920132852.20280-1-fidencio@redhat.com> References: <20180920132852.20280-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [libvirt PATCH v7 1/6] xen_common: Change xenConfigCopyStringInternal to using virConfGetValueString 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.44]); Thu, 20 Sep 2018 13:29:07 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Signed-off-by: Fabiano Fid=C3=AAncio Reviewed-by: John Ferlan --- src/xenconfig/xen_common.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 36a9d27c80..a35e1aff58 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -145,23 +145,13 @@ 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); + if ((rc =3D virConfGetValueString(conf, name, value)) < 0) 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 (rc =3D=3D 0) { if (allowMissing) return 0; virReportError(VIR_ERR_INTERNAL_ERROR, @@ -169,7 +159,7 @@ xenConfigCopyStringInternal(virConfPtr conf, return -1; } =20 - return VIR_STRDUP(*value, val->str); + return 1; } =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 18:14:36 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 1537450161056933.741351543838; Thu, 20 Sep 2018 06:29:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AAF37308FE91; Thu, 20 Sep 2018 13:29:18 +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 6DE4A58756; Thu, 20 Sep 2018 13:29:18 +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 1E23F4A464; Thu, 20 Sep 2018 13:29:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8KDT3Bp005080 for ; Thu, 20 Sep 2018 09:29:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4BDA016E5A; Thu, 20 Sep 2018 13:29:03 +0000 (UTC) Received: from dahmer.brq.redhat.com (unknown [10.43.2.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97ADC19486; Thu, 20 Sep 2018 13:29:02 +0000 (UTC) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 15:28:48 +0200 Message-Id: <20180920132852.20280-3-fidencio@redhat.com> In-Reply-To: <20180920132852.20280-1-fidencio@redhat.com> References: <20180920132852.20280-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [libvirt PATCH v7 2/6] xen_common: Change xenConfigGetUUID to using virConfGetValueString 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 20 Sep 2018 13:29:19 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Signed-off-by: Fabiano Fid=C3=AAncio Reviewed-by: John Ferlan --- src/xenconfig/xen_common.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index a35e1aff58..587bab2b19 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -183,7 +183,8 @@ xenConfigCopyStringOpt(virConfPtr conf, const char *nam= e, char **value) static int xenConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid) { - virConfValuePtr val; + VIR_AUTOFREE(char *) string =3D NULL; + int rc; =20 if (!uuid || !name || !conf) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -191,7 +192,11 @@ xenConfigGetUUID(virConfPtr conf, const char *name, un= signed char *uuid) return -1; } =20 - if (!(val =3D virConfGetValue(conf, name))) { + + if ((rc =3D virConfGetValueString(conf, name, &string)) < 0) + return -1; + + if (rc =3D=3D 0) { if (virUUIDGenerate(uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to generate UUID")); @@ -201,21 +206,15 @@ 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); return -1; } =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 18:14:36 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 1537450149528709.9078884109197; Thu, 20 Sep 2018 06:29:09 -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 E9ACC3001938; Thu, 20 Sep 2018 13:29:06 +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 0349B1882C; Thu, 20 Sep 2018 13:29:06 +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 1E1C84BB75; Thu, 20 Sep 2018 13:29:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8KDT4N1005088 for ; Thu, 20 Sep 2018 09:29:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5628316E5A; Thu, 20 Sep 2018 13:29:04 +0000 (UTC) Received: from dahmer.brq.redhat.com (unknown [10.43.2.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E54019486; Thu, 20 Sep 2018 13:29:03 +0000 (UTC) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 15:28:49 +0200 Message-Id: <20180920132852.20280-4-fidencio@redhat.com> In-Reply-To: <20180920132852.20280-1-fidencio@redhat.com> References: <20180920132852.20280-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [libvirt PATCH v7 3/6] xen_common: Change xenConfigGetString to using virConfGetValueString 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.47]); Thu, 20 Sep 2018 13:29:07 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 This change actually changes the behaviour of xenConfigGetString() as now it returns a newly-allocated string. Unfortunately, there's not much that can be done in order to avoid that and all the callers have to be changed in order to avoid leaking the return value. Also, as a side-effect of the change above, the function now takes a "char **" argument instead of a "const char **" one. Signed-off-by: Fabiano Fid=C3=AAncio Reviewed-by: John Ferlan --- src/xenconfig/xen_common.c | 84 ++++++++++++++++++++------------------ src/xenconfig/xen_common.h | 2 +- src/xenconfig/xen_xl.c | 10 +++-- src/xenconfig/xen_xm.c | 7 ++-- 4 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 587bab2b19..7b3e5c3b44 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -228,26 +228,28 @@ xenConfigGetUUID(virConfPtr conf, const char *name, u= nsigned char *uuid) int xenConfigGetString(virConfPtr conf, const char *name, - const char **value, + char **value, const char *def) { - virConfValuePtr val; + char *string =3D NULL; + int rc; =20 *value =3D NULL; - if (!(val =3D virConfGetValue(conf, name))) { - *value =3D def; + if ((rc =3D virConfGetValueString(conf, name, &string)) < 0) + return -1; + + if (rc =3D=3D 0) { + if (VIR_STRDUP(*value, def) < 0) + return -1; return 0; } =20 - if (val->type !=3D VIR_CONF_STRING) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("config value %s was malformed"), name); - return -1; + if (!string) { + if (VIR_STRDUP(*value, def) < 0) + return -1; + } else { + *value =3D string; } - if (!val->str) - *value =3D def; - else - *value =3D val->str; return 0; } =20 @@ -345,32 +347,34 @@ xenParseTimeOffset(virConfPtr conf, virDomainDefPtr d= ef) static int xenParseEventsActions(virConfPtr conf, virDomainDefPtr def) { - const char *str =3D NULL; + VIR_AUTOFREE(char *) on_poweroff =3D NULL; + VIR_AUTOFREE(char *) on_reboot =3D NULL; + VIR_AUTOFREE(char *) on_crash =3D NULL; =20 - if (xenConfigGetString(conf, "on_poweroff", &str, "destroy") < 0) + if (xenConfigGetString(conf, "on_poweroff", &on_poweroff, "destroy") <= 0) return -1; =20 - if ((def->onPoweroff =3D virDomainLifecycleActionTypeFromString(str)) = < 0) { + if ((def->onPoweroff =3D virDomainLifecycleActionTypeFromString(on_pow= eroff)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected value %s for on_poweroff"), str); + _("unexpected value %s for on_poweroff"), on_powero= ff); return -1; } =20 - if (xenConfigGetString(conf, "on_reboot", &str, "restart") < 0) + if (xenConfigGetString(conf, "on_reboot", &on_reboot, "restart") < 0) return -1; =20 - if ((def->onReboot =3D virDomainLifecycleActionTypeFromString(str)) < = 0) { + if ((def->onReboot =3D virDomainLifecycleActionTypeFromString(on_reboo= t)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected value %s for on_reboot"), str); + _("unexpected value %s for on_reboot"), on_reboot); return -1; } =20 - if (xenConfigGetString(conf, "on_crash", &str, "restart") < 0) + if (xenConfigGetString(conf, "on_crash", &on_crash, "restart") < 0) return -1; =20 - if ((def->onCrash =3D virDomainLifecycleActionTypeFromString(str)) < 0= ) { + if ((def->onCrash =3D virDomainLifecycleActionTypeFromString(on_crash)= ) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected value %s for on_crash"), str); + _("unexpected value %s for on_crash"), on_crash); return -1; } =20 @@ -488,7 +492,8 @@ xenParseCPUFeatures(virConfPtr conf, virDomainXMLOptionPtr xmlopt) { unsigned long count =3D 0; - const char *str =3D NULL; + VIR_AUTOFREE(char *) cpus =3D NULL; + VIR_AUTOFREE(char *) tsc_mode =3D NULL; int val =3D 0; virDomainTimerDefPtr timer; =20 @@ -509,16 +514,16 @@ xenParseCPUFeatures(virConfPtr conf, return -1; } =20 - if (xenConfigGetString(conf, "cpus", &str, NULL) < 0) + if (xenConfigGetString(conf, "cpus", &cpus, NULL) < 0) return -1; =20 - if (str && (virBitmapParse(str, &def->cpumask, 4096) < 0)) + if (cpus && (virBitmapParse(cpus, &def->cpumask, 4096) < 0)) return -1; =20 - if (xenConfigGetString(conf, "tsc_mode", &str, NULL) < 0) + if (xenConfigGetString(conf, "tsc_mode", &tsc_mode, NULL) < 0) return -1; =20 - if (str) { + if (tsc_mode) { if (VIR_EXPAND_N(def->clock.timers, def->clock.ntimers, 1) < 0 || VIR_ALLOC(timer) < 0) return -1; @@ -528,11 +533,11 @@ xenParseCPUFeatures(virConfPtr conf, timer->tickpolicy =3D -1; timer->mode =3D VIR_DOMAIN_TIMER_MODE_AUTO; timer->track =3D -1; - if (STREQ_NULLABLE(str, "always_emulate")) + if (STREQ_NULLABLE(tsc_mode, "always_emulate")) timer->mode =3D VIR_DOMAIN_TIMER_MODE_EMULATE; - else if (STREQ_NULLABLE(str, "native")) + else if (STREQ_NULLABLE(tsc_mode, "native")) timer->mode =3D VIR_DOMAIN_TIMER_MODE_NATIVE; - else if (STREQ_NULLABLE(str, "native_paravirt")) + else if (STREQ_NULLABLE(tsc_mode, "native_paravirt")) timer->mode =3D VIR_DOMAIN_TIMER_MODE_PARAVIRT; =20 def->clock.timers[def->clock.ntimers - 1] =3D timer; @@ -746,15 +751,15 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) static int xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFo= rmat) { - const char *str; virConfValuePtr value =3D NULL; virDomainChrDefPtr chr =3D NULL; =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { - if (xenConfigGetString(conf, "parallel", &str, NULL) < 0) + VIR_AUTOFREE(char *) parallel =3D NULL; + if (xenConfigGetString(conf, "parallel", ¶llel, NULL) < 0) goto cleanup; - if (str && STRNEQ(str, "none") && - !(chr =3D xenParseSxprChar(str, NULL))) + if (parallel && STRNEQ(parallel, "none") && + !(chr =3D xenParseSxprChar(parallel, NULL))) goto cleanup; if (chr) { if (VIR_ALLOC_N(def->parallels, 1) < 0) @@ -801,11 +806,12 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def,= const char *nativeFormat) value =3D value->next; } } else { + VIR_AUTOFREE(char *) serial =3D NULL; /* If domain is not using multiple serial ports we parse data = old way */ - if (xenConfigGetString(conf, "serial", &str, NULL) < 0) + if (xenConfigGetString(conf, "serial", &serial, NULL) < 0) goto cleanup; - if (str && STRNEQ(str, "none") && - !(chr =3D xenParseSxprChar(str, NULL))) + if (serial && STRNEQ(serial, "none") && + !(chr =3D xenParseSxprChar(serial, NULL))) goto cleanup; if (chr) { if (VIR_ALLOC_N(def->serials, 1) < 0) @@ -1049,7 +1055,7 @@ xenParseVifList(virConfPtr conf, virDomainDefPtr def,= const char *vif_typename) static int xenParseEmulatedDevices(virConfPtr conf, virDomainDefPtr def) { - const char *str; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { if (xenConfigGetString(conf, "soundhw", &str, NULL) < 0) @@ -1068,7 +1074,7 @@ static int xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps) { virCapsDomainDataPtr capsdata =3D NULL; - const char *str; + VIR_AUTOFREE(char *) str =3D NULL; int hvm =3D 0, ret =3D -1; =20 if (xenConfigCopyString(conf, "name", &def->name) < 0) diff --git a/src/xenconfig/xen_common.h b/src/xenconfig/xen_common.h index 3b7a5db4f3..a26c9e60c4 100644 --- a/src/xenconfig/xen_common.h +++ b/src/xenconfig/xen_common.h @@ -33,7 +33,7 @@ =20 int xenConfigGetString(virConfPtr conf, const char *name, - const char **value, + char **value, const char *def); =20 int xenConfigGetBool(virConfPtr conf, const char *name, int *value, int de= f); diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index 19b6604e05..7250e5735d 100644 --- a/src/xenconfig/xen_xl.c +++ b/src/xenconfig/xen_xl.c @@ -65,7 +65,9 @@ extern int xlu_disk_parse(XLU_Config *cfg, static int xenParseCmdline(virConfPtr conf, char **r_cmdline) { char *cmdline =3D NULL; - const char *root, *extra, *buf; + VIR_AUTOFREE(char *) root =3D NULL; + VIR_AUTOFREE(char *) extra =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if (xenConfigGetString(conf, "cmdline", &buf, NULL) < 0) return -1; @@ -104,8 +106,8 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virC= apsPtr caps) size_t i; =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { - const char *bios; - const char *boot; + VIR_AUTOFREE(char *) bios =3D NULL; + VIR_AUTOFREE(char *) boot =3D NULL; int val =3D 0; =20 if (xenConfigGetString(conf, "bios", &bios, NULL) < 0) @@ -255,7 +257,7 @@ xenTranslateCPUFeature(const char *feature_name, bool f= rom_libxl) static int xenParseXLCPUID(virConfPtr conf, virDomainDefPtr def) { - const char *cpuid_str =3D NULL; + VIR_AUTOFREE(char *) cpuid_str =3D NULL; char **cpuid_pairs =3D NULL; char **name_and_value =3D NULL; size_t i; diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c index 7b60f25ec1..909e8fad40 100644 --- a/src/xenconfig/xen_xm.c +++ b/src/xenconfig/xen_xm.c @@ -44,7 +44,7 @@ xenParseXMOS(virConfPtr conf, virDomainDefPtr def) size_t i; =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { - const char *boot; + VIR_AUTOFREE(char *) boot =3D NULL; =20 if (VIR_ALLOC(def->os.loader) < 0 || xenConfigCopyString(conf, "kernel", &def->os.loader->path) < 0) @@ -72,7 +72,8 @@ xenParseXMOS(virConfPtr conf, virDomainDefPtr def) def->os.nBootDevs++; } } else { - const char *extra, *root; + VIR_AUTOFREE(char *) extra =3D NULL; + VIR_AUTOFREE(char *) root =3D NULL; =20 if (xenConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader= ) < 0) return -1; @@ -417,7 +418,7 @@ xenFormatXMDisks(virConfPtr conf, virDomainDefPtr def) static int xenParseXMInputDevs(virConfPtr conf, virDomainDefPtr def) { - const char *str; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { if (xenConfigGetString(conf, "usbdevice", &str, NULL) < 0) --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 18:14:36 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 1537450164515433.6539897916988; Thu, 20 Sep 2018 06:29:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BCA8140F3A; Thu, 20 Sep 2018 13:29: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 8C220308BDAD; Thu, 20 Sep 2018 13:29:22 +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 395554A46E; Thu, 20 Sep 2018 13:29:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8KDT5fq005093 for ; Thu, 20 Sep 2018 09:29:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5DF4016E5A; Thu, 20 Sep 2018 13:29:05 +0000 (UTC) Received: from dahmer.brq.redhat.com (unknown [10.43.2.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id A696F19486; Thu, 20 Sep 2018 13:29:04 +0000 (UTC) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 15:28:50 +0200 Message-Id: <20180920132852.20280-5-fidencio@redhat.com> In-Reply-To: <20180920132852.20280-1-fidencio@redhat.com> References: <20180920132852.20280-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [libvirt PATCH v7 4/6] xen_common: Change xenParsePCIList to using virConfGetValueStringList 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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 20 Sep 2018 13:29:23 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 The `if(!list || list->type !=3D VIR_CONF_LIST)` check couldn't be written in a 100% similar way. Instead, we're just checking whether `virConfGetValueStringList() <=3D 0` and creating a new function to: - return -1 in case virConfGetValueStringList fails either due to some allocation failure or when traversing the list; - resetting the last error and return 0 otherwise; Taking this approach we can have the behaviour with the new code as close as possible to the old one. Signed-off-by: Fabiano Fid=C3=AAncio Reviewed-by: John Ferlan --- src/xenconfig/xen_common.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 7b3e5c3b44..9133998cd7 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -458,22 +458,40 @@ xenParsePCI(char *entry) return hostdev; } =20 +static int +xenHandleConfGetValueStringListErrors(int ret, int errorCode) +{ + if (ret < 0) { + /* It means virConfGetValueStringList() didn't fail because the + * cval->type switch fell through - since we're passing + * @compatString =3D=3D false - assumes failures for memory alloca= tion + * and VIR_CONF_LIST traversal failure should cause -1 to be + * returned to the caller with the error message set. */ + if (errorCode !=3D VIR_ERR_INTERNAL_ERROR) + return -1; + + /* If we did fall through the switch, then ignore and clear the + * last error. */ + virResetLastError(); + } + return 0; +} =20 static int xenParsePCIList(virConfPtr conf, virDomainDefPtr def) { - virConfValuePtr list =3D virConfGetValue(conf, "pci"); + VIR_AUTOPTR(virString) pcis =3D NULL; + virString *entries =3D NULL; + int rc; =20 - if (!list || list->type !=3D VIR_CONF_LIST) - return 0; + if ((rc =3D virConfGetValueStringList(conf, "pci", false, &pcis)) <=3D= 0) + return xenHandleConfGetValueStringListErrors(rc, virGetLastErrorCo= de()); =20 - for (list =3D list->list; list; list =3D list->next) { + for (entries =3D pcis; *entries; entries++) { + virString 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))) + if (!(hostdev =3D xenParsePCI(entry))) return -1; =20 if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0= ) { --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 18:14:36 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 1537450160674206.28615180000565; Thu, 20 Sep 2018 06:29:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA29232B662; Thu, 20 Sep 2018 13:29:18 +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 864733091330; Thu, 20 Sep 2018 13:29:18 +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 3FABD181A13C; Thu, 20 Sep 2018 13:29:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8KDT6ev005104 for ; Thu, 20 Sep 2018 09:29:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 65BCA16E5A; Thu, 20 Sep 2018 13:29:06 +0000 (UTC) Received: from dahmer.brq.redhat.com (unknown [10.43.2.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id B01DD19497; Thu, 20 Sep 2018 13:29:05 +0000 (UTC) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 15:28:51 +0200 Message-Id: <20180920132852.20280-6-fidencio@redhat.com> In-Reply-To: <20180920132852.20280-1-fidencio@redhat.com> References: <20180920132852.20280-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [libvirt PATCH v7 5/6] xen_common: Change xenParseVfbs to using virConfGetValueStringList 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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 20 Sep 2018 13:29:19 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Signed-off-by: Fabiano Fid=C3=AAncio Reviewed-by: John Ferlan --- src/xenconfig/xen_common.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 9133998cd7..058f35825e 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -618,7 +618,6 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) int val; 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) { @@ -674,17 +673,17 @@ 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) { + VIR_AUTOPTR(virString) vfbs =3D NULL; + int rc; + + if ((rc =3D virConfGetValueStringList(conf, "vfb", false, &vfbs)) = =3D=3D 1) { char vfb[MAX_VFB]; char *key =3D vfb; =20 - if (virStrcpyStatic(vfb, list->list->str) < 0) { + if (virStrcpyStatic(vfb, *vfbs) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("VFB %s too big for destination"), - list->list->str); + *vfbs); goto cleanup; } =20 @@ -754,6 +753,11 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) def->graphics[0] =3D graphics; def->ngraphics =3D 1; graphics =3D NULL; + } else { + rc =3D xenHandleConfGetValueStringListErrors(rc, + virGetLastErrorCode= ()); + if (rc < 0) + goto cleanup; } } =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 18:14:36 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 1537450161308572.3328943673056; Thu, 20 Sep 2018 06:29:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CDB7A62E83; Thu, 20 Sep 2018 13:29:18 +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 91E2F309137F; Thu, 20 Sep 2018 13:29:18 +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 456E64A465; Thu, 20 Sep 2018 13:29:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8KDT7hY005116 for ; Thu, 20 Sep 2018 09:29:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6824216E5A; Thu, 20 Sep 2018 13:29:07 +0000 (UTC) Received: from dahmer.brq.redhat.com (unknown [10.43.2.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4FDB19497; Thu, 20 Sep 2018 13:29:06 +0000 (UTC) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 15:28:52 +0200 Message-Id: <20180920132852.20280-7-fidencio@redhat.com> In-Reply-To: <20180920132852.20280-1-fidencio@redhat.com> References: <20180920132852.20280-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [libvirt PATCH v7 6/6] xen_common: Change xenParseCharDev to using virConfGetValueStringList 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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 20 Sep 2018 13:29:19 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Signed-off-by: Fabiano Fid=C3=AAncio Reviewed-by: John Ferlan --- src/xenconfig/xen_common.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 058f35825e..21f1f4a24c 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -773,11 +773,13 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) static int xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFo= rmat) { - virConfValuePtr value =3D NULL; + VIR_AUTOPTR(virString) serials =3D NULL; virDomainChrDefPtr chr =3D NULL; =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { VIR_AUTOFREE(char *) parallel =3D NULL; + int rc; + if (xenConfigGetString(conf, "parallel", ¶llel, NULL) < 0) goto cleanup; if (parallel && STRNEQ(parallel, "none") && @@ -795,8 +797,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 ((rc =3D virConfGetValueStringList(conf, "serial", false, &seri= als)) =3D=3D 1) { + virString *entries; int portnum =3D -1; =20 if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) { @@ -805,18 +807,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++) { + virString 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; @@ -824,11 +820,14 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def,= const char *nativeFormat) chr->target.port =3D portnum; if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) <= 0) goto cleanup; - - value =3D value->next; } } else { VIR_AUTOFREE(char *) serial =3D NULL; + + rc =3D xenHandleConfGetValueStringListErrors(rc, virGetLastErr= orCode()); + if (rc < 0) + goto cleanup; + /* If domain is not using multiple serial ports we parse data = old way */ if (xenConfigGetString(conf, "serial", &serial, NULL) < 0) goto cleanup; --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list