From nobody Wed May 14 10:34:34 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 15274601368884.14370975470365; Sun, 27 May 2018 15:28:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B74E431570FF; Sun, 27 May 2018 22:28:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 676D761F5E; Sun, 27 May 2018 22:28:54 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 831E418033F1; Sun, 27 May 2018 22:28:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4RMSpOE015039 for ; Sun, 27 May 2018 18:28:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6EEF69420A; Sun, 27 May 2018 22:28:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6413A92EE4 for ; Sun, 27 May 2018 22:28:49 +0000 (UTC) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F8BDC007604 for ; Sun, 27 May 2018 22:28:37 +0000 (UTC) Received: by mail-wr0-f193.google.com with SMTP id w10-v6so17296401wrk.9 for ; Sun, 27 May 2018 15:28:37 -0700 (PDT) Received: from machado.local ([95.82.135.172]) by smtp.gmail.com with ESMTPSA id h81-v6sm23469897wmd.0.2018.05.27.15.28.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 May 2018 15:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fidencio-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=40nBivKilYljMBrFw4cjjWVTC2BtyO/8yTJc5t26wgQ=; b=pClok3gSjFmKATu248+3/bQMVnTUBwiDapLtAngx/BWn69UXoVWPk4XirtTvz/a9Dl TxCsAVp0OLIZ6TZyQTcQSsWCJx7WJ7y2DyZTt07GGeF3wbTDEW92vuG2hk6Yy3QGBs9Q 41G0EVRxaZB038Lf3apW/9RoaqbniISf09CLjcLQ/eDZ780YjJ/L0N8tb15DJ5Y2FjUu /ZBohMupC2HH8FQOSbUPmUKiHUdK8MOhX90YPO5hO/cQgi9OS7DLqfB30ETu8o++0Gxg BGiSC34xdp6TVsMwrFR7tR/oJilUnXRQlb7QdUmYAatb5G3dtYqsoR4AjoU2alW/S1P1 S8sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=40nBivKilYljMBrFw4cjjWVTC2BtyO/8yTJc5t26wgQ=; b=GzePQ7gssMgqklMiNlFtp9r5QXUuIU7S4Fl7XVDzHk1Hc5mXwrMuDfz8tbNpuRIQUS qdXofOb9ips0QSP1avwux/oyMG6dUZ3Xn+v/MH7NpUJZIkOG1rnUEwTBulPonVprdPYC fcEFGQWj63dlL+0reScRyxrtP48uQrXrC7VYkiGZAl+uJv2xPbV965IHbBPQZIqgViU/ tVlJJ6unKWXP358tMF9BR7Pxs3fNQzPDv7bzaWbBz3/PjLe8SR5sHIKzfGjP0gsaNIcr mopxSDqcWvgWxn9CDo5/dqov1B9HF4b14hpDaP+I2We9oTzQcWQ+NbY1STYD7w5MlLHw LuBA== X-Gm-Message-State: ALKqPwdrNu7vZEVJ/nykppH2BCUKPFC/UOU257Eu81CkE+VpHwFTQnri 3CM4Ryqy6yJ7oqqoh9ubp+vyR/zl X-Google-Smtp-Source: AB8JxZo+ETekWvsxvvS8mKYuLdvE1fWDci+E2mzncZV3eituX35SCnWNkFIyvS/Z+J4cUV5yNxveuQ== X-Received: by 2002:adf:9365:: with SMTP id 92-v6mr9849178wro.283.1527460115591; Sun, 27 May 2018 15:28:35 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Mon, 28 May 2018 00:28:24 +0200 Message-Id: <20180527222826.18525-6-fabiano@fidencio.org> In-Reply-To: <20180527222826.18525-1-fabiano@fidencio.org> References: <20180527222826.18525-1-fabiano@fidencio.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 27 May 2018 22:28:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 27 May 2018 22:28:38 +0000 (UTC) for IP:'209.85.128.193' DOMAIN:'mail-wr0-f193.google.com' HELO:'mail-wr0-f193.google.com' FROM:'fabiano@fidencio.org' RCPT:'' X-RedHat-Spam-Score: -1.597 (DKIM_SIGNED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID) 209.85.128.193 mail-wr0-f193.google.com 209.85.128.193 mail-wr0-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCHv3 5/7] xen_common: Split per-Vfi logic from xenParseVif() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sun, 27 May 2018 22:28:55 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 xenParseVfi() does a lot of stuff and, in order to make things cleaner, let's split it in two new functions: - xenParseVfi(): it's a new function that keeps the old name. It's responsible for the whole per-Vfi logic from the old xenParseVfi(); - xenParseVfiList(): it's basically the old xenParsePCI(), but now it just iterates over the list of Vfis, calling xenParsePCI() per each Vfi. This patch is basically preparing the ground for the future when typesafe virConf acessors will be used. Signed-off-by: Fabiano Fid=C3=AAncio --- src/xenconfig/xen_common.c | 363 ++++++++++++++++++++++++-----------------= ---- 1 file changed, 192 insertions(+), 171 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index fc7b0683b8..45fecbced8 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -846,202 +846,223 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr de= f, const char *nativeFormat) } =20 =20 -static int -xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename) +static virDomainNetDefPtr +xenParseVif(char *entry, const char *vif_typename) { - char *script =3D NULL; virDomainNetDefPtr net =3D NULL; - virConfValuePtr list =3D virConfGetValue(conf, "vif"); + char *script =3D NULL; + char model[10]; + char type[10]; + char ip[128]; + char mac[18]; + char bridge[50]; + char vifname[50]; + char rate[50]; + char *key; + int rc =3D 0; + + bridge[0] =3D '\0'; + mac[0] =3D '\0'; + ip[0] =3D '\0'; + model[0] =3D '\0'; + type[0] =3D '\0'; + vifname[0] =3D '\0'; + rate[0] =3D '\0'; + + key =3D entry; + while (key) { + char *data; + char *nextkey =3D strchr(key, ','); + + if (!(data =3D strchr(key, '=3D'))) + return NULL; + data++; + + if (STRPREFIX(key, "mac=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(mac) - 1; + if (virStrncpy(mac, data, len, sizeof(mac)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("MAC address %s too big for destination"), + data); + return NULL; + } + } else if (STRPREFIX(key, "bridge=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(bridge) - 1; + if (virStrncpy(bridge, data, len, sizeof(bridge)) =3D=3D NULL)= { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Bridge %s too big for destination"), + data); + return NULL; + } + } else if (STRPREFIX(key, "script=3D")) { + int len =3D nextkey ? (nextkey - data) : strlen(data); + VIR_FREE(script); + if (VIR_STRNDUP(script, data, len) < 0) + return NULL; + } else if (STRPREFIX(key, "model=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(model) - 1; + if (virStrncpy(model, data, len, sizeof(model)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Model %s too big for destination"), + data); + return NULL; + } + } else if (STRPREFIX(key, "type=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(type) - 1; + if (virStrncpy(type, data, len, sizeof(type)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Type %s too big for destination"), + data); + return NULL; + } + } else if (STRPREFIX(key, "vifname=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(vifname) - 1; + if (virStrncpy(vifname, data, len, sizeof(vifname)) =3D=3D NUL= L) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Vifname %s too big for destination"), + data); + return NULL; + } + } else if (STRPREFIX(key, "ip=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(ip) - 1; + if (virStrncpy(ip, data, len, sizeof(ip)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("IP %s too big for destination"), data); + return NULL; + } + } else if (STRPREFIX(key, "rate=3D")) { + int len =3D nextkey ? (nextkey - data) : sizeof(rate) - 1; + if (virStrncpy(rate, data, len, sizeof(rate)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("rate %s too big for destination"), data); + return NULL; + } + } =20 - if (list && list->type =3D=3D VIR_CONF_LIST) { - list =3D list->list; - while (list) { - char model[10]; - char type[10]; - char ip[128]; - char mac[18]; - char bridge[50]; - char vifname[50]; - char rate[50]; - char *key; - - bridge[0] =3D '\0'; - mac[0] =3D '\0'; - ip[0] =3D '\0'; - model[0] =3D '\0'; - type[0] =3D '\0'; - vifname[0] =3D '\0'; - rate[0] =3D '\0'; - - if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NUL= L)) - goto skipnic; - - key =3D list->str; - while (key) { - char *data; - char *nextkey =3D strchr(key, ','); + while (nextkey && (nextkey[0] =3D=3D ',' || + nextkey[0] =3D=3D ' ' || + nextkey[0] =3D=3D '\t')) + nextkey++; + key =3D nextkey; + } =20 - if (!(data =3D strchr(key, '=3D'))) - goto skipnic; - data++; - - if (STRPREFIX(key, "mac=3D")) { - int len =3D nextkey ? (nextkey - data) : sizeof(mac) -= 1; - if (virStrncpy(mac, data, len, sizeof(mac)) =3D=3D NUL= L) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("MAC address %s too big for desti= nation"), - data); - goto skipnic; - } - } else if (STRPREFIX(key, "bridge=3D")) { - int len =3D nextkey ? (nextkey - data) : sizeof(bridge= ) - 1; - if (virStrncpy(bridge, data, len, sizeof(bridge)) =3D= =3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Bridge %s too big for destinatio= n"), - data); - goto skipnic; - } - } else if (STRPREFIX(key, "script=3D")) { - int len =3D nextkey ? (nextkey - data) : strlen(data); - VIR_FREE(script); - if (VIR_STRNDUP(script, data, len) < 0) - goto cleanup; - } else if (STRPREFIX(key, "model=3D")) { - int len =3D nextkey ? (nextkey - data) : sizeof(model)= - 1; - if (virStrncpy(model, data, len, sizeof(model)) =3D=3D= NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Model %s too big for destination= "), - data); - goto skipnic; - } - } else if (STRPREFIX(key, "type=3D")) { - int len =3D nextkey ? (nextkey - data) : sizeof(type) = - 1; - if (virStrncpy(type, data, len, sizeof(type)) =3D=3D N= ULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Type %s too big for destination"= ), - data); - goto skipnic; - } - } else if (STRPREFIX(key, "vifname=3D")) { - int len =3D nextkey ? (nextkey - data) : sizeof(vifnam= e) - 1; - if (virStrncpy(vifname, data, len, sizeof(vifname)) = =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Vifname %s too big for destinati= on"), - data); - goto skipnic; - } - } else if (STRPREFIX(key, "ip=3D")) { - int len =3D nextkey ? (nextkey - data) : sizeof(ip) - = 1; - if (virStrncpy(ip, data, len, sizeof(ip)) =3D=3D NULL)= { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("IP %s too big for destination"),= data); - goto skipnic; - } - } else if (STRPREFIX(key, "rate=3D")) { - int len =3D nextkey ? (nextkey - data) : sizeof(rate) = - 1; - if (virStrncpy(rate, data, len, sizeof(rate)) =3D=3D N= ULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("rate %s too big for destination"= ), data); - goto skipnic; - } - } + if (VIR_ALLOC(net) < 0) + goto cleanup; =20 - while (nextkey && (nextkey[0] =3D=3D ',' || - nextkey[0] =3D=3D ' ' || - nextkey[0] =3D=3D '\t')) - nextkey++; - key =3D nextkey; - } + if (mac[0]) { + if (virMacAddrParse(mac, &net->mac) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("malformed mac address '%s'"), mac); + goto cleanup; + } + } =20 - if (VIR_ALLOC(net) < 0) - goto cleanup; + if (bridge[0] || STREQ_NULLABLE(script, "vif-bridge") || + STREQ_NULLABLE(script, "vif-vnic")) { + net->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + } else { + net->type =3D VIR_DOMAIN_NET_TYPE_ETHERNET; + } =20 - if (mac[0]) { - if (virMacAddrParse(mac, &net->mac) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("malformed mac address '%s'"), mac); - goto cleanup; - } - } + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE) { + if (bridge[0] && VIR_STRDUP(net->data.bridge.brname, bridge) < 0) + goto cleanup; + } + if (ip[0]) { + char **ip_list =3D virStringSplit(ip, " ", 0); + size_t i; =20 - if (bridge[0] || STREQ_NULLABLE(script, "vif-bridge") || - STREQ_NULLABLE(script, "vif-vnic")) { - net->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; - } else { - net->type =3D VIR_DOMAIN_NET_TYPE_ETHERNET; - } + if (!ip_list) + goto cleanup; =20 - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE) { - if (bridge[0] && VIR_STRDUP(net->data.bridge.brname, bridg= e) < 0) - goto cleanup; + for (i =3D 0; ip_list[i]; i++) { + if (virDomainNetAppendIPAddress(net, ip_list[i], 0, 0) < 0) { + virStringListFree(ip_list); + goto cleanup; } - if (ip[0]) { - char **ip_list =3D virStringSplit(ip, " ", 0); - size_t i; + } + virStringListFree(ip_list); + } =20 - if (!ip_list) - goto cleanup; + if (script && script[0]) { + rc =3D VIR_STRDUP(net->script, script); + if (rc < 0) + goto cleanup; + } =20 - for (i =3D 0; ip_list[i]; i++) { - if (virDomainNetAppendIPAddress(net, ip_list[i], 0, 0)= < 0) { - virStringListFree(ip_list); - goto cleanup; - } - } - virStringListFree(ip_list); - } + if (model[0]) { + rc =3D VIR_STRDUP(net->model, model); + if (rc < 0) + goto cleanup; + } =20 - if (script && script[0] && - VIR_STRDUP(net->script, script) < 0) - goto cleanup; + if (!model[0] && type[0] && STREQ(type, vif_typename)) { + rc =3D VIR_STRDUP(net->model, "netfront"); + if (rc < 0) + goto cleanup; + } =20 - if (model[0] && - VIR_STRDUP(net->model, model) < 0) - goto cleanup; + if (vifname[0]) { + rc =3D VIR_STRDUP(net->ifname, vifname); + if (rc < 0) + goto cleanup; + } =20 - if (!model[0] && type[0] && STREQ(type, vif_typename) && - VIR_STRDUP(net->model, "netfront") < 0) - goto cleanup; + if (rate[0]) { + virNetDevBandwidthPtr bandwidth; + unsigned long long kbytes_per_sec; =20 - if (vifname[0] && - VIR_STRDUP(net->ifname, vifname) < 0) - goto cleanup; + rc =3D xenParseSxprVifRate(rate, &kbytes_per_sec); + if (rc < 0) + goto cleanup; =20 - if (rate[0]) { - virNetDevBandwidthPtr bandwidth; - unsigned long long kbytes_per_sec; + rc =3D VIR_ALLOC(bandwidth); + if (rc < 0) + goto cleanup; + rc =3D VIR_ALLOC(bandwidth->out); + if (rc < 0) { + VIR_FREE(bandwidth); + goto cleanup; + } =20 - if (xenParseSxprVifRate(rate, &kbytes_per_sec) < 0) - goto cleanup; + bandwidth->out->average =3D kbytes_per_sec; + net->bandwidth =3D bandwidth; + } =20 - if (VIR_ALLOC(bandwidth) < 0) - goto cleanup; - if (VIR_ALLOC(bandwidth->out) < 0) { - VIR_FREE(bandwidth); - goto cleanup; - } + cleanup: + if (rc < 0) + virDomainNetDefFree(net); + VIR_FREE(script); + return net; +} =20 - bandwidth->out->average =3D kbytes_per_sec; - net->bandwidth =3D bandwidth; - } =20 - if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0) - goto cleanup; +static int +xenParseVifList(virConfPtr conf, virDomainDefPtr def, const char *vif_type= name) +{ + virConfValuePtr list =3D virConfGetValue(conf, "vif"); + + if (!list || list->type !=3D VIR_CONF_LIST) + return 0; =20 - skipnic: - list =3D list->next; + for (list =3D list->list; list; list =3D list->next) { + virDomainNetDefPtr net =3D NULL; + int rc; + + if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NULL)) + continue; + + if (!(net =3D xenParseVif(list->str, vif_typename))) + return -1; + + rc =3D VIR_APPEND_ELEMENT(def->nets, def->nnets, net); + if (rc < 0) { virDomainNetDefFree(net); - net =3D NULL; - VIR_FREE(script); + return -1; } } =20 return 0; - - cleanup: - virDomainNetDefFree(net); - VIR_FREE(script); - return -1; } =20 =20 @@ -1126,10 +1147,10 @@ xenParseConfigCommon(virConfPtr conf, return -1; =20 if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XL)) { - if (xenParseVif(conf, def, "vif") < 0) + if (xenParseVifList(conf, def, "vif") < 0) return -1; } else if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) { - if (xenParseVif(conf, def, "netfront") < 0) + if (xenParseVifList(conf, def, "netfront") < 0) return -1; } else { virReportError(VIR_ERR_INVALID_ARG, --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list