From nobody Sun Feb 8 21:06:22 2026 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 154785276123080.27014515445035; Fri, 18 Jan 2019 15:06:01 -0800 (PST) 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 2B6A983F44; Fri, 18 Jan 2019 23:05:59 +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 E1C15508E2; Fri, 18 Jan 2019 23:05:58 +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 990443F603; Fri, 18 Jan 2019 23:05:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0IN5ZCU008652 for ; Fri, 18 Jan 2019 18:05:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id A049D600D6; Fri, 18 Jan 2019 23:05:35 +0000 (UTC) Received: from worklaptop.redhat.com (ovpn-125-139.rdu2.redhat.com [10.10.125.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id 35F74600C2; Fri, 18 Jan 2019 23:05:35 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 18 Jan 2019 18:05:22 -0500 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/10] conf: net: Add model enum, and netfront value 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-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.27]); Fri, 18 Jan 2019 23:06:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This adds a network model enum. The virDomainNetDef property is named 'model' like most other devices. When the XML parser or a driver calls NetSetModelString, if the passed string is in the enum, we will set net->model, otherwise we copy the string into net->modelstr Add a single example for the 'netfront' xen model, and wire that up, just to verify it's all working Signed-off-by: Cole Robinson --- src/conf/domain_conf.c | 56 +++++++++++++++++++++++++++----------- src/conf/domain_conf.h | 10 +++++++ src/libvirt_private.syms | 2 ++ src/libxl/libxl_conf.c | 4 +-- src/qemu/qemu_hotplug.c | 8 ++++++ src/xenconfig/xen_common.c | 16 +++++------ src/xenconfig/xen_sxpr.c | 15 +++++----- 7 files changed, 78 insertions(+), 33 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 25fbf6f64b..129e16bd0b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -436,6 +436,10 @@ VIR_ENUM_IMPL(virDomainNet, VIR_DOMAIN_NET_TYPE_LAST, "hostdev", "udp") =20 +VIR_ENUM_IMPL(virDomainNetModel, VIR_DOMAIN_NET_MODEL_LAST, + "unknown", + "netfront") + VIR_ENUM_IMPL(virDomainNetBackend, VIR_DOMAIN_NET_BACKEND_TYPE_LAST, "default", "qemu", @@ -2121,6 +2125,7 @@ virDomainNetDefClear(virDomainNetDefPtr def) return; =20 VIR_FREE(def->modelstr); + def->model =3D VIR_DOMAIN_NET_MODEL_UNKNOWN; =20 switch (def->type) { case VIR_DOMAIN_NET_TYPE_VHOSTUSER: @@ -11390,21 +11395,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlo= pt, goto error; } =20 - /* NIC model (see -net nic,model=3D?). We only check that it looks - * reasonable, not that it is a supported NIC type. FWIW kvm - * supports these types as of April 2008: - * i82551 i82557b i82559er ne2k_pci pcnet rtl8139 e1000 virtio - * QEMU PPC64 supports spapr-vlan - */ - if (model !=3D NULL) { - if (strspn(model, NET_MODEL_CHARS) < strlen(model)) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("Model name contains invalid characters")); - goto error; - } - def->modelstr =3D model; - model =3D NULL; - } + if (model !=3D NULL && + virDomainNetSetModelString(def, model) < 0) + goto error; =20 switch (def->type) { case VIR_DOMAIN_NET_TYPE_NETWORK: @@ -21978,6 +21971,14 @@ virDomainNetDefCheckABIStability(virDomainNetDefPt= r src, return false; } =20 + if (src->model !=3D dst->model) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target network card model %s does not match sour= ce %s"), + virDomainNetModelTypeToString(dst->model), + virDomainNetModelTypeToString(src->model)); + return false; + } + if (src->mtu !=3D dst->mtu) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Target network card MTU %d does not match source= %d"), @@ -29841,6 +29842,8 @@ virDomainNetGetActualTrustGuestRxFilters(virDomainN= etDefPtr iface) const char * virDomainNetGetModelString(const virDomainNetDef *iface) { + if (iface->model) + return virDomainNetModelTypeToString(iface->model); return iface->modelstr; } =20 @@ -29848,13 +29851,31 @@ int virDomainNetSetModelString(virDomainNetDefPtr iface, const char *model) { - return VIR_STRDUP(iface->modelstr, model); + VIR_FREE(iface->modelstr); + if ((iface->model =3D virDomainNetModelTypeFromString(model)) >=3D 0) + return 0; + + iface->model =3D VIR_DOMAIN_NET_MODEL_UNKNOWN; + if (!model) + return 0; + + if (strspn(model, NET_MODEL_CHARS) < strlen(model)) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("Model name contains invalid characters")); + return -1; + } + + if (VIR_STRDUP(iface->modelstr, model) < 0) + return -1; + return 0; } =20 int virDomainNetStreqModelString(const virDomainNetDef *iface, const char *model) { + if (iface->model) + return iface->model =3D=3D virDomainNetModelTypeFromString(model); return STREQ_NULLABLE(iface->modelstr, model); } =20 @@ -29862,6 +29883,9 @@ int virDomainNetStrcaseeqModelString(const virDomainNetDef *iface, const char *model) { + if (iface->model) + return STRCASEEQ(virDomainNetModelTypeToString(iface->model), + model); return iface->modelstr && STRCASEEQ(iface->modelstr, model); } =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 5400deda4c..e26b885508 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -960,6 +960,14 @@ typedef enum { VIR_DOMAIN_NET_TYPE_LAST } virDomainNetType; =20 +/* network model types */ +typedef enum { + VIR_DOMAIN_NET_MODEL_UNKNOWN, + VIR_DOMAIN_NET_MODEL_NETFRONT, + + VIR_DOMAIN_NET_MODEL_LAST +} virDomainNetModelType; + /* the backend driver used for virtio interfaces */ typedef enum { VIR_DOMAIN_NET_BACKEND_TYPE_DEFAULT, /* prefer kernel, fall back to us= er */ @@ -1021,6 +1029,7 @@ struct _virDomainNetDef { virDomainNetType type; virMacAddr mac; bool mac_generated; /* true if mac was *just now* auto-generated by li= bvirt */ + int model; /* virDomainNetModelType */ char *modelstr; union { struct { @@ -3493,6 +3502,7 @@ VIR_ENUM_DECL(virDomainNet) VIR_ENUM_DECL(virDomainNetBackend) VIR_ENUM_DECL(virDomainNetVirtioTxMode) VIR_ENUM_DECL(virDomainNetInterfaceLinkState) +VIR_ENUM_DECL(virDomainNetModel) VIR_ENUM_DECL(virDomainChrDevice) VIR_ENUM_DECL(virDomainChrChannelTarget) VIR_ENUM_DECL(virDomainChrConsoleTarget) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index afb5975352..d802535fa0 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -475,6 +475,8 @@ virDomainNetGetActualVlan; virDomainNetGetModelString; virDomainNetHasVirtioModel; virDomainNetInsert; +virDomainNetModelTypeFromString; +virDomainNetModelTypeToString; virDomainNetNotifyActualDevice; virDomainNetReleaseActualDevice; virDomainNetRemove; diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 29aa04583c..ebb38ba7e8 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1269,7 +1269,7 @@ libxlMakeNic(virDomainDefPtr def, if (virDomainNetGetModelString(l_nic)) { if ((def->os.type =3D=3D VIR_DOMAIN_OSTYPE_XEN || def->os.type =3D=3D VIR_DOMAIN_OSTYPE_XENPVH) && - !virDomainNetStreqModelString(l_nic, "netfront")) { + l_nic->model !=3D VIR_DOMAIN_NET_MODEL_NETFRONT) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("only model 'netfront' is supported for " "Xen PV(H) domains")); @@ -1277,7 +1277,7 @@ libxlMakeNic(virDomainDefPtr def, } if (VIR_STRDUP(x_nic->model, virDomainNetGetModelString(l_nic)) < = 0) goto cleanup; - if (virDomainNetStreqModelString(l_nic, "netfront")) + if (l_nic->model =3D=3D VIR_DOMAIN_NET_MODEL_NETFRONT) x_nic->nictype =3D LIBXL_NIC_TYPE_VIF; else x_nic->nictype =3D LIBXL_NIC_TYPE_VIF_IOEMU; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index b0a99ed853..168b391f0e 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3711,6 +3711,14 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, goto cleanup; } =20 + if (olddev->model !=3D newdev->model) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("cannot modify network device model from %s to %s= "), + virDomainNetModelTypeToString(olddev->model), + virDomainNetModelTypeToString(newdev->model)); + goto cleanup; + } + if (virDomainNetHasVirtioModel(olddev) && (olddev->driver.virtio.name !=3D newdev->driver.virtio.name || olddev->driver.virtio.txmode !=3D newdev->driver.virtio.txmode || diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 74ce8dcc69..dfe240a949 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -1068,13 +1068,13 @@ xenParseVif(char *entry, const char *vif_typename) VIR_STRDUP(net->script, script) < 0) goto cleanup; =20 - if (model[0] && - virDomainNetSetModelString(net, model) < 0) - goto cleanup; - - if (!model[0] && type[0] && STREQ(type, vif_typename) && - virDomainNetSetModelString(net, "netfront") < 0) - goto cleanup; + if (model[0]) { + if (virDomainNetSetModelString(net, model) < 0) + goto cleanup; + } else { + if (type[0] && STREQ(type, vif_typename)) + net->model =3D VIR_DOMAIN_NET_MODEL_NETFRONT; + } =20 if (vifname[0] && VIR_STRDUP(net->ifname, vifname) < 0) @@ -1427,7 +1427,7 @@ xenFormatNet(virConnectPtr conn, virBufferAsprintf(&buf, ",model=3D%s", virDomainNetGetModelString(net)); } else { - if (virDomainNetStreqModelString(net, "netfront")) + if (net->model =3D=3D VIR_DOMAIN_NET_MODEL_NETFRONT) virBufferAsprintf(&buf, ",type=3D%s", vif_typename); else virBufferAsprintf(&buf, ",model=3D%s", diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c index b3bbce4e86..071949bff5 100644 --- a/src/xenconfig/xen_sxpr.c +++ b/src/xenconfig/xen_sxpr.c @@ -642,12 +642,13 @@ xenParseSxprNets(virDomainDefPtr def, } } =20 - if (virDomainNetSetModelString(net, model) < 0) - goto cleanup; - - if (!model && type && STREQ(type, "netfront") && - virDomainNetSetModelString(net, "netfront") < 0) - goto cleanup; + if (model) { + if (virDomainNetSetModelString(net, model) < 0) + goto cleanup; + } else { + if (type && STREQ(type, "netfront")) + net->model =3D VIR_DOMAIN_NET_MODEL_NETFRONT; + } =20 tmp =3D sexpr_node(node, "device/vif/rate"); if (tmp) { @@ -1940,7 +1941,7 @@ xenFormatSxprNet(virConnectPtr conn, virBufferEscapeSexpr(buf, "(model '%s')", virDomainNetGetModelString(def)); } else { - if (virDomainNetStreqModelString(def, "netfront")) + if (def->model =3D=3D VIR_DOMAIN_NET_MODEL_NETFRONT) virBufferAddLit(buf, "(type netfront)"); else virBufferEscapeSexpr(buf, "(model '%s')", --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list