Since commit 282d135ddbb the parser for <interface> has cleared out any interface name from the input XML that used the macvtap/macvlan name as a prefix. Along with that, the switch to use the new virNetDevGenerateName() function for auto-generating macvtap/macvlan device names (commit 9b5d741a9), has realized two facts: 1) virNetDevGenerateName() can be called with a name already filled in, and in that case it is an effective NOP. 2) because virNetDevGenerate() will always find an unused name, there is no need to retry device creation in a loop - if it fails the first time, it would fail any subsequent time as well. that, combined with the aforementioned parser change allow us to simplify virNetDevMacVLanCreateWithVPortProfile() - we no longer need any extra code to determine if a template "AutoName" was requested, and don't need a separate code path for creating the device in the case that a specific name was given in the XML - all we need to do is log any requested name, and then call exactly the same code as we would if no name was given. Signed-off-by: Laine Stump <laine@xxxxxxxxxx> --- src/util/virnetdevmacvlan.c | 64 ++++++------------------------------- 1 file changed, 10 insertions(+), 54 deletions(-) diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index a4ad698335..2deefe6589 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -673,6 +673,7 @@ virNetDevMacVLanCreateWithVPortProfile(const char *ifnameRequested, uint32_t macvtapMode; int vf = -1; bool vnet_hdr = flags & VIR_NETDEV_MACVLAN_VNET_HDR; + virNetDevGenNameType type; macvtapMode = modeMap[mode]; @@ -706,66 +707,21 @@ virNetDevMacVLanCreateWithVPortProfile(const char *ifnameRequested, } if (ifnameRequested) { - int rc; - bool isAutoName - = (STRPREFIX(ifnameRequested, VIR_NET_GENERATED_MACVTAP_PREFIX) || - STRPREFIX(ifnameRequested, VIR_NET_GENERATED_MACVLAN_PREFIX)); - VIR_INFO("Requested macvtap device name: %s", ifnameRequested); - - if ((rc = virNetDevExists(ifnameRequested)) < 0) - return -1; - - if (rc) { - /* ifnameRequested is already being used */ - - if (!isAutoName) { - virReportSystemError(EEXIST, - _("Unable to create device '%s'"), - ifnameRequested); - return -1; - } - } else { - - /* ifnameRequested is available. try to open it */ - - virNetDevReserveName(ifnameRequested); - - if (virNetDevMacVLanCreate(ifnameRequested, macaddress, - linkdev, macvtapMode, flags) == 0) { - - /* virNetDevMacVLanCreate() was successful - use this name */ - ifname = g_strdup(ifnameRequested); - - } else if (!isAutoName) { - /* couldn't open ifnameRequested, but it wasn't an - * autogenerated named, so there is nothing else to - * try - fail and return. - */ - return -1; - } - } + ifname = g_strdup(ifnameRequested); } - if (!ifname) { - /* ifnameRequested was NULL, or it was an already in use - * autogenerated name, so now we look for an unused - * autogenerated name. - */ - virNetDevGenNameType type; - if (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) - type = VIR_NET_DEV_GEN_NAME_MACVTAP; - else - type = VIR_NET_DEV_GEN_NAME_MACVLAN; + if (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) + type = VIR_NET_DEV_GEN_NAME_MACVTAP; + else + type = VIR_NET_DEV_GEN_NAME_MACVLAN; - if (virNetDevGenerateName(&ifname, type) < 0 || - virNetDevMacVLanCreate(ifname, macaddress, - linkdev, macvtapMode, flags) < 0) - return -1; + if (virNetDevGenerateName(&ifname, type) < 0 || + virNetDevMacVLanCreate(ifname, macaddress, + linkdev, macvtapMode, flags) < 0) { + return -1; } - /* all done creating the device */ - if (virNetDevVPortProfileAssociate(ifname, virtPortProfile, macaddress, -- 2.28.0