To ease converting the net->model value to an enum, add the wrapper functions: virDomainNetGetModelString virDomainNetSetModelString virDomainNetStreqModelString virDomainNetStrcaseeqModelString Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx> --- src/bhyve/bhyve_command.c | 8 ++++---- src/bhyve/bhyve_parse_command.c | 2 +- src/conf/domain_conf.c | 36 ++++++++++++++++++++++++++++----- src/conf/domain_conf.h | 7 +++++++ src/libvirt_private.syms | 4 ++++ src/libxl/libxl_conf.c | 8 ++++---- src/qemu/qemu_command.c | 11 +++++----- src/qemu/qemu_domain.c | 4 ++-- src/qemu/qemu_domain_address.c | 14 ++++++------- src/qemu/qemu_driver.c | 14 ++++++++++--- src/qemu/qemu_hotplug.c | 7 ++++--- src/qemu/qemu_parse_command.c | 5 +++-- src/vbox/vbox_common.c | 18 ++++++++--------- src/vmx/vmx.c | 31 ++++++++++++++-------------- src/vz/vz_driver.c | 4 ++-- src/vz/vz_sdk.c | 14 ++++++------- src/xenconfig/xen_common.c | 21 ++++++++++--------- src/xenconfig/xen_sxpr.c | 21 ++++++++++--------- 18 files changed, 138 insertions(+), 91 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 84fda08943..78f8a88290 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -56,16 +56,16 @@ bhyveBuildNetArgStr(virConnectPtr conn, int ret = -1; virDomainNetType actualType = virDomainNetGetActualType(net); - if (net->model == NULL) { + if (!virDomainNetGetModelString(net)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("NIC model must be specified")); return -1; } - if (STREQ(net->model, "virtio")) { + if (virDomainNetStreqModelString(net, "virtio")) { if (VIR_STRDUP(nic_model, "virtio-net") < 0) return -1; - } else if (STREQ(net->model, "e1000")) { + } else if (virDomainNetStreqModelString(net, "e1000")) { if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_NET_E1000) != 0) { if (VIR_STRDUP(nic_model, "e1000") < 0) return -1; @@ -78,7 +78,7 @@ bhyveBuildNetArgStr(virConnectPtr conn, } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("NIC model '%s' is not supported"), - net->model); + virDomainNetGetModelString(net)); return -1; } diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c index 1c9191fb96..cf0b2db30a 100644 --- a/src/bhyve/bhyve_parse_command.c +++ b/src/bhyve/bhyve_parse_command.c @@ -513,7 +513,7 @@ bhyveParsePCINet(virDomainDefPtr def, if (VIR_STRDUP(net->data.bridge.brname, "virbr0") < 0) goto error; - if (VIR_STRDUP(net->model, model) < 0) + if (virDomainNetSetModelString(net, model) < 0) goto error; net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 46fbc0befc..778b842979 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -25565,9 +25565,9 @@ virDomainNetDefFormat(virBufferPtr buf, virBufferEscapeString(buf, " actual='%s'", def->ifname_guest_actual); virBufferAddLit(buf, "/>\n"); } - if (def->model) { + if (virDomainNetGetModelString(def)) { virBufferEscapeString(buf, "<model type='%s'/>\n", - def->model); + virDomainNetGetModelString(def)); if (virDomainNetHasVirtioModel(def)) { char *str = NULL, *gueststr = NULL, *hoststr = NULL; int rc = 0; @@ -29838,13 +29838,39 @@ virDomainNetGetActualTrustGuestRxFilters(virDomainNetDefPtr iface) return iface->trustGuestRxFilters == VIR_TRISTATE_BOOL_YES; } +const char * +virDomainNetGetModelString(const virDomainNetDef *iface) +{ + return iface->model; +} + +int +virDomainNetSetModelString(virDomainNetDefPtr iface, + const char *model) +{ + return VIR_STRDUP(iface->model, model); +} + +int +virDomainNetStreqModelString(const virDomainNetDef *iface, + const char *model) +{ + return STREQ_NULLABLE(iface->model, model); +} + +int +virDomainNetStrcaseeqModelString(const virDomainNetDef *iface, + const char *model) +{ + return iface->model && STRCASEEQ(iface->model, model); +} bool virDomainNetHasVirtioModel(const virDomainNetDef *iface) { - return (STREQ_NULLABLE(iface->model, "virtio") || - STREQ_NULLABLE(iface->model, "virtio-transitional") || - STREQ_NULLABLE(iface->model, "virtio-non-transitional")); + return (virDomainNetStreqModelString(iface, "virtio") || + virDomainNetStreqModelString(iface, "virtio-transitional") || + virDomainNetStreqModelString(iface, "virtio-non-transitional")); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 0d801b0d6d..8f856c2d14 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3271,6 +3271,13 @@ virNetDevBandwidthPtr virDomainNetGetActualBandwidth(virDomainNetDefPtr iface); virNetDevVlanPtr virDomainNetGetActualVlan(virDomainNetDefPtr iface); bool virDomainNetGetActualTrustGuestRxFilters(virDomainNetDefPtr iface); +const char *virDomainNetGetModelString(const virDomainNetDef *iface); +int virDomainNetSetModelString(virDomainNetDefPtr iface, + const char *model); +int virDomainNetStreqModelString(const virDomainNetDef *iface, + const char *model); +int virDomainNetStrcaseeqModelString(const virDomainNetDef *iface, + const char *model); bool virDomainNetHasVirtioModel(const virDomainNetDef *iface); int virDomainNetAppendIPAddress(virDomainNetDefPtr def, const char *address, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 60a193450b..afb5975352 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -472,6 +472,7 @@ virDomainNetGetActualTrustGuestRxFilters; virDomainNetGetActualType; virDomainNetGetActualVirtPortProfile; virDomainNetGetActualVlan; +virDomainNetGetModelString; virDomainNetHasVirtioModel; virDomainNetInsert; virDomainNetNotifyActualDevice; @@ -480,6 +481,9 @@ virDomainNetRemove; virDomainNetRemoveHostdev; virDomainNetResolveActualType; virDomainNetSetDeviceImpl; +virDomainNetSetModelString; +virDomainNetStrcaseeqModelString; +virDomainNetStreqModelString; virDomainNetTypeFromString; virDomainNetTypeSharesHostView; virDomainNetTypeToString; diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 4102a940b9..29aa04583c 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1266,18 +1266,18 @@ libxlMakeNic(virDomainDefPtr def, * xen commit 32e9d0f ("libxl: nic type defaults to vif in hotplug for * hvm guest"). */ - if (l_nic->model) { + if (virDomainNetGetModelString(l_nic)) { if ((def->os.type == VIR_DOMAIN_OSTYPE_XEN || def->os.type == VIR_DOMAIN_OSTYPE_XENPVH) && - STRNEQ(l_nic->model, "netfront")) { + !virDomainNetStreqModelString(l_nic, "netfront")) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("only model 'netfront' is supported for " "Xen PV(H) domains")); return -1; } - if (VIR_STRDUP(x_nic->model, l_nic->model) < 0) + if (VIR_STRDUP(x_nic->model, virDomainNetGetModelString(l_nic)) < 0) goto cleanup; - if (STREQ(l_nic->model, "netfront")) + if (virDomainNetStreqModelString(l_nic, "netfront")) x_nic->nictype = LIBXL_NIC_TYPE_VIF; else x_nic->nictype = LIBXL_NIC_TYPE_VIF_IOEMU; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 940d55b1b1..83222dd0be 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3779,13 +3779,14 @@ qemuBuildLegacyNicStr(virDomainNetDefPtr net) { char *str; char macaddr[VIR_MAC_STRING_BUFLEN]; + const char *netmodel = virDomainNetGetModelString(net); ignore_value(virAsprintf(&str, "nic,macaddr=%s,netdev=host%s%s%s%s%s", virMacAddrFormat(&net->mac, macaddr), net->info.alias, - (net->model ? ",model=" : ""), - (net->model ? net->model : ""), + (netmodel ? ",model=" : ""), + (netmodel ? netmodel : ""), (net->info.alias ? ",id=" : ""), (net->info.alias ? net->info.alias : ""))); return str; @@ -3805,14 +3806,14 @@ qemuBuildNicDevStr(virDomainDefPtr def, if (virDomainNetHasVirtioModel(net)) { if (qemuBuildVirtioTransitional(&buf, "virtio-net", qemuCaps, - net->info.type, - 0, net->model, + net->info.type, 0, + virDomainNetGetModelString(net), VIR_DOMAIN_DEVICE_NET) < 0) goto error; usingVirtio = true; } else { - virBufferAddStr(&buf, net->model); + virBufferAddStr(&buf, virDomainNetGetModelString(net)); } if (usingVirtio && net->driver.virtio.txmode) { diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 85f7b6a4c8..38e86b8ad1 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -6565,8 +6565,8 @@ qemuDomainDeviceNetDefPostParse(virDomainNetDefPtr net, virQEMUCapsPtr qemuCaps) { if (net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV && - !net->model) { - if (VIR_STRDUP(net->model, + !virDomainNetGetModelString(net)) { + if (virDomainNetSetModelString(net, qemuDomainDefaultNetModel(def, qemuCaps)) < 0) return -1; } diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 50cc47b7b3..c0843bdad6 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -230,10 +230,8 @@ qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def) for (i = 0; i < def->nnets; i++) { virDomainNetDefPtr net = def->nets[i]; - if (net->model && - STREQ(net->model, "spapr-vlan")) { + if (virDomainNetStreqModelString(net, "spapr-vlan")) net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO; - } if (qemuDomainAssignSpaprVIOAddress(def, &net->info, VIO_ADDR_NET) < 0) goto cleanup; @@ -696,18 +694,18 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev, * addresses for other hostdev devices. */ if (net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV || - STREQ(net->model, "usb-net")) { + virDomainNetStreqModelString(net, "usb-net")) { return 0; } - if (STREQ(net->model, "virtio") || - STREQ(net->model, "virtio-non-transitional")) + if (virDomainNetStreqModelString(net, "virtio") || + virDomainNetStreqModelString(net, "virtio-non-transitional")) return virtioFlags; - if (STREQ(net->model, "virtio-transitional")) + if (virDomainNetStreqModelString(net, "virtio-transitional")) return pciFlags; - if (STREQ(net->model, "e1000e")) + if (virDomainNetStreqModelString(net, "e1000e")) return pcieFlags; return pciFlags; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 949c09aba4..ba8b7d13a8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7449,20 +7449,28 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, for (i = 0; i < vm->def->nnets; i++) { virDomainNetDefPtr net = vm->def->nets[i]; unsigned int bootIndex = net->info.bootIndex; - char *model = net->model; + char *model; virMacAddr mac = net->mac; char *script = net->script; - net->model = NULL; + if (virDomainNetGetModelString(net) && + VIR_STRDUP(model, virDomainNetGetModelString(net)) < 0) + goto cleanup; + net->script = NULL; virDomainNetDefClear(net); net->type = VIR_DOMAIN_NET_TYPE_ETHERNET; net->info.bootIndex = bootIndex; - net->model = model; net->mac = mac; net->script = script; + + if (model && virDomainNetSetModelString(net, model) < 0) { + VIR_FREE(model); + goto cleanup; + } + VIR_FREE(model); } if (!(cmd = qemuProcessCreatePretendCmd(driver, vm, NULL, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 2fdc71d07b..b0a99ed853 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3702,11 +3702,12 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, goto cleanup; } - if (STRNEQ_NULLABLE(olddev->model, newdev->model)) { + if (STRNEQ_NULLABLE(virDomainNetGetModelString(olddev), + virDomainNetGetModelString(newdev))) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("cannot modify network device model from %s to %s"), - olddev->model ? olddev->model : "(default)", - newdev->model ? newdev->model : "(default)"); + NULLSTR(virDomainNetGetModelString(olddev)), + NULLSTR(virDomainNetGetModelString(newdev))); goto cleanup; } diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c index c4650f01e0..0a080f3ece 100644 --- a/src/qemu/qemu_parse_command.c +++ b/src/qemu/qemu_parse_command.c @@ -1111,8 +1111,9 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt, goto error; } } else if (STREQ(keywords[i], "model")) { - def->model = values[i]; - values[i] = NULL; + if (virDomainNetSetModelString(def, values[i]) < 0) + goto error; + VIR_FREE(values[i]); } else if (STREQ(keywords[i], "vhost")) { if ((values[i] == NULL) || STREQ(values[i], "on")) { def->driver.virtio.name = VIR_DOMAIN_NET_BACKEND_TYPE_VHOST; diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 00d43d9a83..fa8d899fec 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -1309,7 +1309,7 @@ vboxAttachNetwork(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine) macaddrvbox[VIR_MAC_STRING_BUFLEN - 6] = '\0'; VIR_DEBUG("NIC(%zu): Type: %d", i, def->nets[i]->type); - VIR_DEBUG("NIC(%zu): Model: %s", i, def->nets[i]->model); + VIR_DEBUG("NIC(%zu): Model: %s", i, virDomainNetGetModelString(def->nets[i])); VIR_DEBUG("NIC(%zu): Mac: %s", i, macaddr); VIR_DEBUG("NIC(%zu): ifname: %s", i, def->nets[i]->ifname); if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_NETWORK) { @@ -1338,19 +1338,19 @@ vboxAttachNetwork(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine) gVBoxAPI.UINetworkAdapter.SetEnabled(adapter, 1); - if (def->nets[i]->model) { - if (STRCASEEQ(def->nets[i]->model, "Am79C970A")) { + if (virDomainNetGetModelString(def->nets[i])) { + if (virDomainNetStrcaseeqModelString(def->nets[i], "Am79C970A")) { adapterType = NetworkAdapterType_Am79C970A; - } else if (STRCASEEQ(def->nets[i]->model, "Am79C973")) { + } else if (virDomainNetStrcaseeqModelString(def->nets[i], "Am79C973")) { adapterType = NetworkAdapterType_Am79C973; - } else if (STRCASEEQ(def->nets[i]->model, "82540EM")) { + } else if (virDomainNetStrcaseeqModelString(def->nets[i], "82540EM")) { adapterType = NetworkAdapterType_I82540EM; - } else if (STRCASEEQ(def->nets[i]->model, "82545EM")) { + } else if (virDomainNetStrcaseeqModelString(def->nets[i], "82545EM")) { adapterType = NetworkAdapterType_I82545EM; - } else if (STRCASEEQ(def->nets[i]->model, "82543GC")) { + } else if (virDomainNetStrcaseeqModelString(def->nets[i], "82543GC")) { adapterType = NetworkAdapterType_I82543GC; } else if (gVBoxAPI.APIVersion >= 3000051 && - STRCASEEQ(def->nets[i]->model, "virtio")) { + virDomainNetStrcaseeqModelString(def->nets[i], "virtio")) { /* Only vbox 3.1 and later support NetworkAdapterType_Virto */ adapterType = NetworkAdapterType_Virtio; } @@ -3762,7 +3762,7 @@ vboxDumpNetwork(vboxDriverPtr data, INetworkAdapter *adapter) model = "virtio"; break; } - if (VIR_STRDUP(net->model, model) < 0) + if (virDomainNetSetModelString(net, model) < 0) goto error; gVBoxAPI.UINetworkAdapter.GetMACAddress(adapter, &utf16); diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index a853c05e86..7f8357211c 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -2670,10 +2670,8 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) /* Setup virDomainNetDef */ if (connectionType == NULL || STRCASEEQ(connectionType, "bridged")) { (*def)->type = VIR_DOMAIN_NET_TYPE_BRIDGE; - (*def)->model = virtualDev; (*def)->data.bridge.brname = networkName; - virtualDev = NULL; networkName = NULL; } else if (STRCASEEQ(connectionType, "hostonly")) { /* FIXME */ @@ -2683,16 +2681,12 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) goto cleanup; } else if (STRCASEEQ(connectionType, "nat")) { (*def)->type = VIR_DOMAIN_NET_TYPE_USER; - (*def)->model = virtualDev; - virtualDev = NULL; } else if (STRCASEEQ(connectionType, "custom")) { (*def)->type = VIR_DOMAIN_NET_TYPE_BRIDGE; - (*def)->model = virtualDev; (*def)->data.bridge.brname = networkName; (*def)->ifname = vnet; - virtualDev = NULL; networkName = NULL; vnet = NULL; } else { @@ -2702,6 +2696,10 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) goto cleanup; } + if (virDomainNetSetModelString((*def), virtualDev) < 0) + goto cleanup; + VIR_FREE(virtualDev); + result = 0; cleanup: @@ -3739,28 +3737,29 @@ virVMXFormatEthernet(virDomainNetDefPtr def, int controller, virBufferAsprintf(buffer, "ethernet%d.present = \"true\"\n", controller); /* def:model -> vmx:virtualDev, vmx:features */ - if (def->model != NULL) { - if (STRCASENEQ(def->model, "vlance") && - STRCASENEQ(def->model, "vmxnet") && - STRCASENEQ(def->model, "vmxnet2") && - STRCASENEQ(def->model, "vmxnet3") && - STRCASENEQ(def->model, "e1000") && - STRCASENEQ(def->model, "e1000e")) { + if (virDomainNetGetModelString(def)) { + if (!virDomainNetStrcaseeqModelString(def, "vlance") && + !virDomainNetStrcaseeqModelString(def, "vmxnet") && + !virDomainNetStrcaseeqModelString(def, "vmxnet2") && + !virDomainNetStrcaseeqModelString(def, "vmxnet3") && + !virDomainNetStrcaseeqModelString(def, "e1000") && + !virDomainNetStrcaseeqModelString(def, "e1000e")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Expecting domain XML entry 'devices/interface/model' " "to be 'vlance' or 'vmxnet' or 'vmxnet2' or 'vmxnet3' " - "or 'e1000' or 'e1000e' but found '%s'"), def->model); + "or 'e1000' or 'e1000e' but found '%s'"), + virDomainNetGetModelString(def)); return -1; } - if (STRCASEEQ(def->model, "vmxnet2")) { + if (virDomainNetStrcaseeqModelString(def, "vmxnet2")) { virBufferAsprintf(buffer, "ethernet%d.virtualDev = \"vmxnet\"\n", controller); virBufferAsprintf(buffer, "ethernet%d.features = \"15\"\n", controller); } else { virBufferAsprintf(buffer, "ethernet%d.virtualDev = \"%s\"\n", - controller, def->model); + controller, virDomainNetGetModelString(def)); } } diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 7e9ef932dc..eab2953759 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -269,9 +269,9 @@ vzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, if (dev->type == VIR_DOMAIN_DEVICE_NET && (dev->data.net->type == VIR_DOMAIN_NET_TYPE_NETWORK || dev->data.net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) && - !dev->data.net->model && + !virDomainNetGetModelString(dev->data.net) && def->os.type == VIR_DOMAIN_OSTYPE_HVM && - VIR_STRDUP(dev->data.net->model, "e1000") < 0) + virDomainNetSetModelString(dev->data.net, "e1000") < 0) return -1; return 0; diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 63d013deac..60681591c6 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -1105,15 +1105,15 @@ prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt) switch ((int)type) { case PNT_RTL: - if (VIR_STRDUP(net->model, "rtl8139") < 0) + if (virDomainNetSetModelString(net, "rtl8139") < 0) goto cleanup; break; case PNT_E1000: - if (VIR_STRDUP(net->model, "e1000") < 0) + if (virDomainNetSetModelString(net, "e1000") < 0) goto cleanup; break; case PNT_VIRTIO: - if (VIR_STRDUP(net->model, "virtio") < 0) + if (virDomainNetSetModelString(net, "virtio") < 0) goto cleanup; break; default: @@ -3378,15 +3378,15 @@ static int prlsdkConfigureNet(vzDriverPtr driver ATTRIBUTE_UNUSED, goto cleanup; if (isCt) { - if (net->model) + if (virDomainNetGetModelString(net)) VIR_WARN("Setting network adapter for containers is not " "supported by vz driver."); } else { - if (STREQ(net->model, "rtl8139")) { + if (virDomainNetStreqModelString(net, "rtl8139")) { pret = PrlVmDevNet_SetAdapterType(sdknet, PNT_RTL); - } else if (STREQ(net->model, "e1000")) { + } else if (virDomainNetStreqModelString(net, "e1000")) { pret = PrlVmDevNet_SetAdapterType(sdknet, PNT_E1000); - } else if (STREQ(net->model, "virtio")) { + } else if (virDomainNetStreqModelString(net, "virtio")) { pret = PrlVmDevNet_SetAdapterType(sdknet, PNT_VIRTIO); } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 94e0703cf3..74ce8dcc69 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -1069,11 +1069,11 @@ xenParseVif(char *entry, const char *vif_typename) goto cleanup; if (model[0] && - VIR_STRDUP(net->model, model) < 0) + virDomainNetSetModelString(net, model) < 0) goto cleanup; if (!model[0] && type[0] && STREQ(type, vif_typename) && - VIR_STRDUP(net->model, "netfront") < 0) + virDomainNetSetModelString(net, "netfront") < 0) goto cleanup; if (vifname[0] && @@ -1422,15 +1422,16 @@ xenFormatNet(virConnectPtr conn, goto cleanup; } - if (!hvm) { - if (net->model != NULL) - virBufferAsprintf(&buf, ",model=%s", net->model); - } else { - if (net->model != NULL && STREQ(net->model, "netfront")) { - virBufferAsprintf(&buf, ",type=%s", vif_typename); + if (virDomainNetGetModelString(net)) { + if (!hvm) { + virBufferAsprintf(&buf, ",model=%s", + virDomainNetGetModelString(net)); } else { - if (net->model != NULL) - virBufferAsprintf(&buf, ",model=%s", net->model); + if (virDomainNetStreqModelString(net, "netfront")) + virBufferAsprintf(&buf, ",type=%s", vif_typename); + else + virBufferAsprintf(&buf, ",model=%s", + virDomainNetGetModelString(net)); } } diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c index 11af3e747a..b3bbce4e86 100644 --- a/src/xenconfig/xen_sxpr.c +++ b/src/xenconfig/xen_sxpr.c @@ -642,11 +642,11 @@ xenParseSxprNets(virDomainDefPtr def, } } - if (VIR_STRDUP(net->model, model) < 0) + if (virDomainNetSetModelString(net, model) < 0) goto cleanup; if (!model && type && STREQ(type, "netfront") && - VIR_STRDUP(net->model, "netfront") < 0) + virDomainNetSetModelString(net, "netfront") < 0) goto cleanup; tmp = sexpr_node(node, "device/vif/rate"); @@ -1935,15 +1935,16 @@ xenFormatSxprNet(virConnectPtr conn, !STRPREFIX(def->ifname, "vif")) virBufferEscapeSexpr(buf, "(vifname '%s')", def->ifname); - if (!hvm) { - if (def->model != NULL) - virBufferEscapeSexpr(buf, "(model '%s')", def->model); - } else { - if (def->model != NULL && STREQ(def->model, "netfront")) { - virBufferAddLit(buf, "(type netfront)"); + if (virDomainNetGetModelString(def)) { + if (!hvm) { + virBufferEscapeSexpr(buf, "(model '%s')", + virDomainNetGetModelString(def)); } else { - if (def->model != NULL) - virBufferEscapeSexpr(buf, "(model '%s')", def->model); + if (virDomainNetStreqModelString(def, "netfront")) + virBufferAddLit(buf, "(type netfront)"); + else + virBufferEscapeSexpr(buf, "(model '%s')", + virDomainNetGetModelString(def)); } } -- 2.20.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list