From nobody Thu May 2 13:15:45 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 1528952451575504.9060884701629; Wed, 13 Jun 2018 22:00:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E2FFC057FA8; Thu, 14 Jun 2018 05:00:49 +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 36BD82C6C0; Thu, 14 Jun 2018 05:00:49 +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 AD1B01800539; Thu, 14 Jun 2018 05:00:48 +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 w5E50EQY016137 for ; Thu, 14 Jun 2018 01:00:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 222B484630; Thu, 14 Jun 2018 05:00:14 +0000 (UTC) Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1993A84633 for ; Thu, 14 Jun 2018 05:00:11 +0000 (UTC) Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) (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 C77AD3082129 for ; Thu, 14 Jun 2018 04:59:59 +0000 (UTC) Received: by mail-wr0-f196.google.com with SMTP id x4-v6so4876180wro.11 for ; Wed, 13 Jun 2018 21:59:59 -0700 (PDT) Received: from machado.local ([83.240.61.28]) by smtp.gmail.com with ESMTPSA id u11-v6sm4578387wrq.68.2018.06.13.21.59.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Jun 2018 21:59:57 -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=1B9NahpyGYxu+cwk/Oi25ajKreyNjcjN3olcn0E4/p8=; b=vrC20WGNno/M0JlVVy4cZdsOweKujJweGMmnSK9fRPdd15AtNqlukQM6MZYoQymjDv 34+Vp/GU5g1gTNYo0auxAmVZSCVuAT5Bg/NC5tG40cirl9LZqYj+3Mj3chj+rJmmD3l+ SwUKRpwN5U6bbuaqW4bR2GUnSabuwQrAii1p+XLwJgE0TzNZEeGIiho7GJ5Go1ECs4vz ezlDdl1O22g9KP5xEAC8Xp3auip8r1navEaRJVnFFzGT0PIYasSYhzZ/xGCkIwlztnXd DbrwPk0UofetclaU7Xi2NFK1mbJkFFkcticjfODMWL8dMyItnoRu2QjO7C2UJCSbMqPP 6iRA== 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=1B9NahpyGYxu+cwk/Oi25ajKreyNjcjN3olcn0E4/p8=; b=P6PfdXh6OORnu9MFbcuuecFbz2Hl7ZQFAau2jmVbiFhircLFCbRhAVXBN4OiKsqsDE KbCHqit3JDdBrIv+Ku7tWrKOGcJS6/G4nZdYMurx11AVl+s0DJa2yU1WqjgZbwmlne4v QMVwAfZepkxvkNZ0tS6M/QM4THc+XlQHa7BkgFUyx/Vfgk1VITb5UErCr+tY1vIfH7/F 7nxdx+JzdLNnEpAhjPprAKXtfADrPJixvhUWZOEYXr1J3VmmYaCIB32DL0S/vbPKazRy olaJ+jViOKXQocrFNYfQ+N1r0nDWfPgQ2EPE65vHpKYKqcWSnk9ASZSqk2rmx1WkRX/j SAow== X-Gm-Message-State: APt69E0VJyQWaMLOifpYsu1hOyf/eEeKhBx/K6A+2Hssw8AhLIDXJcGF BZSXwnGUZbOgOUQqSAZ/NqMHwJ6b X-Google-Smtp-Source: ADUXVKJOE3CQD11zCv7GFoDns3cOpNjWZJHprqSk/MUWNMrUb/HBx4+/YfoQl3EgxRSglZ5lJ7D8nw== X-Received: by 2002:adf:ef4f:: with SMTP id c15-v6mr629227wrp.182.1528952398192; Wed, 13 Jun 2018 21:59:58 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Thu, 14 Jun 2018 06:59:52 +0200 Message-Id: <20180614045953.26164-2-fabiano@fidencio.org> In-Reply-To: <20180614045953.26164-1-fabiano@fidencio.org> References: <20180614045953.26164-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.42]); Thu, 14 Jun 2018 05:00:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 14 Jun 2018 05:00:00 +0000 (UTC) for IP:'209.85.128.196' DOMAIN:'mail-wr0-f196.google.com' HELO:'mail-wr0-f196.google.com' FROM:'fabiano@fidencio.org' RCPT:'' X-RedHat-Spam-Score: 0.099 (DKIM_SIGNED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID) 209.85.128.196 mail-wr0-f196.google.com 209.85.128.196 mail-wr0-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 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] [PATCH v4 1/2] xen_common: Split per-Vif 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 14 Jun 2018 05:00:50 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 xenParseVif() does a lot of stuff and, in order to make things cleaner, let's split it in two new functions: - xenParseVif(): it's a new function that keeps the old name. It's responsible for the whole per-Vif logic from the old xenParseVif(); - xenParseVifList(): it's basically the old xenParsePCI(), but now it just iterates over the list of Vifs, calling xenParsePCI() per each Vif. 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 | 358 +++++++++++++++++++++++------------------= ---- 1 file changed, 187 insertions(+), 171 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index fc7b0683b8..02765c540b 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -846,202 +846,218 @@ 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"); + virDomainNetDefPtr ret =3D NULL; + 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; + + 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]) { + if (VIR_STRDUP(net->script, script) < 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]) { + if (VIR_STRDUP(net->model, model) < 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)) { + if (VIR_STRDUP(net->model, "netfront") < 0) + goto cleanup; + } =20 - if (model[0] && - VIR_STRDUP(net->model, model) < 0) - goto cleanup; + if (vifname[0]) { + if (VIR_STRDUP(net->ifname, vifname) < 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; + if (xenParseSxprVifRate(rate, &kbytes_per_sec) < 0) + goto cleanup; =20 - if (rate[0]) { - virNetDevBandwidthPtr bandwidth; - unsigned long long kbytes_per_sec; + if (VIR_ALLOC(bandwidth) < 0) + goto cleanup; =20 - if (xenParseSxprVifRate(rate, &kbytes_per_sec) < 0) - goto cleanup; + if (VIR_ALLOC(bandwidth->out) < 0) { + VIR_FREE(bandwidth); + goto cleanup; + } =20 - 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; + } =20 - bandwidth->out->average =3D kbytes_per_sec; - net->bandwidth =3D bandwidth; - } + VIR_STEAL_PTR(ret, net); =20 - if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0) - goto cleanup; + cleanup: + virDomainNetDefFree(net); + VIR_FREE(script); + return ret; +} + + +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 +1142,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 Thu May 2 13:15:45 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 1528952450168177.68554502274617; Wed, 13 Jun 2018 22:00:50 -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 8960830C1109; Thu, 14 Jun 2018 05:00:48 +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 5077F4532; Thu, 14 Jun 2018 05:00:48 +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 E145C180053A; Thu, 14 Jun 2018 05:00:47 +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 w5E50E2J016136 for ; Thu, 14 Jun 2018 01:00:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1FE778462E; Thu, 14 Jun 2018 05:00:14 +0000 (UTC) Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1876C84630 for ; Thu, 14 Jun 2018 05:00:12 +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 B92003082126 for ; Thu, 14 Jun 2018 05:00:00 +0000 (UTC) Received: by mail-wr0-f193.google.com with SMTP id e18-v6so4899414wrs.5 for ; Wed, 13 Jun 2018 22:00:00 -0700 (PDT) Received: from machado.local ([83.240.61.28]) by smtp.gmail.com with ESMTPSA id u11-v6sm4578387wrq.68.2018.06.13.21.59.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Jun 2018 21:59:58 -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=zhQN+f1G12CrlIMzyntvkkRD8zDMsaumcf6sUTfygDo=; b=0Rbb4evLZ85s5Sa4XhEXbBadfVuojk42Q+hcxyHfxhnYRJvH2sCk6m7UeF3pOeLYdO QAcP8ry6RBJu96NgXNmwMXgP/7O5plEPz/AZf6E+AF1B4wby7yEP3fWqmDpNOUAi2AYJ H5ytHqrXOQIwWvKBI+p1MrPQDs+10ZIcrVT/1oq+nmFe7AUWNY6EuwxE2+9GuqaGAIcW m4DD6QCZ9sSbFRVY4lhlpBqW/8qFD8fyqE4jCx3hwGnJgDSXYRmXedP+msGPN7/c1gQW nRfbhnAwsVZTsvWwxqjYyuDnUz4F6F56VqzkS4slsUntxr+Wp4+47/hKFyWvC7zYZd99 yiTw== 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=zhQN+f1G12CrlIMzyntvkkRD8zDMsaumcf6sUTfygDo=; b=a+eH28SDl9JbYJE+FRxnuTg0I+yXpdpeYWm9amxp/dyYF1AiKPeF+7Rk1oWm4hbmLx 6PjvA768I4QuD4xnUWGnxvaVD0K1Y29K6s7NFnUKRgeeid5hAxWCys5fUxywKKfHKtJX RnOalZaOHjppDlJ+QLZj7RlC1xrzbl9QnxCBLLuDdA5Jcl2gK1DVt6bZgiVqSuTJLqTx SNRIDPVi6xTqBWvLMy8Y8bV/8dNunUsd7K7NVjCjSntQNR5EBon4A0myiH8HqQolMbZz wGr376MkfH+0Ko9JA1lw2VickF/CLeSG31E+WpYEitINyiODqPH4jG9GnHGWQFu+M8yR gmhw== X-Gm-Message-State: APt69E0h2eSwQ9VmrmiLNTxSBNilI48VYV7UZ3y72hUU/i7pc4Ypu+ib VP2vZls9ordpM5XKr+Hjxn70JRhj X-Google-Smtp-Source: ADUXVKIMoNH4lzrNQBCnn2CkUO/MWR9I6lfMOpqpxHUEYPst6x/9f5+pe82iqfhkpHHmxfztBtrZGw== X-Received: by 2002:a5d:4503:: with SMTP id s3-v6mr674477wrq.191.1528952399133; Wed, 13 Jun 2018 21:59:59 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Thu, 14 Jun 2018 06:59:53 +0200 Message-Id: <20180614045953.26164-3-fabiano@fidencio.org> In-Reply-To: <20180614045953.26164-1-fabiano@fidencio.org> References: <20180614045953.26164-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.42]); Thu, 14 Jun 2018 05:00:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 14 Jun 2018 05:00:01 +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: 0.099 (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.84 on 10.5.110.42 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] [PATCH v4 2/2] 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 14 Jun 2018 05:00:49 +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 02765c540b..2dc5e62a9e 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 @@ -1035,29 +1027,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