in commit 370608b, bitmap of in-used macvtap devices was introduced. if there is already macvtap device created not by libvirt, virNetDevMacVLanCreateWithVPortProfile will failed after try MACVLAN_MAX_ID times call virNetDevMacVLanReleaseID Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1321546 Signed-off-by: Shanzhi Yu <shyu@xxxxxxxxxx> --- src/util/virnetdevmacvlan.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index 2409113..973363e 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -988,7 +988,8 @@ virNetDevMacVLanCreateWithVPortProfile(const char *ifnameRequested, MACVTAP_NAME_PREFIX : MACVLAN_NAME_PREFIX; const char *pattern = (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) ? MACVTAP_NAME_PATTERN : MACVLAN_NAME_PATTERN; - int rc, reservedID = -1; + int rc = -1; + int reservedID = 0; char ifname[IFNAMSIZ]; int retries, do_retry = 0; uint32_t macvtapMode; @@ -1072,16 +1073,17 @@ virNetDevMacVLanCreateWithVPortProfile(const char *ifnameRequested, retries = MACVLAN_MAX_ID; while (!ifnameCreated && retries) { virMutexLock(&virNetDevMacVLanCreateMutex); - reservedID = virNetDevMacVLanReserveID(reservedID, flags, false, true); - if (reservedID < 0) { - virMutexUnlock(&virNetDevMacVLanCreateMutex); - return -1; - } snprintf(ifname, sizeof(ifname), pattern, reservedID); rc = virNetDevMacVLanCreate(ifname, type, macaddress, linkdev, macvtapMode, &do_retry); if (rc < 0) { - virNetDevMacVLanReleaseID(reservedID, flags); + reservedID++; + reservedID = virNetDevMacVLanReserveID(reservedID, flags, false, true); + if (reservedID < 0) { + virMutexUnlock(&virNetDevMacVLanCreateMutex); + return -1; + } + virMutexUnlock(&virNetDevMacVLanCreateMutex); if (!do_retry) return -1; -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list