From nobody Fri Jul 4 08:16:18 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 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