]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
port allocator: remove release functionality from set used
authorNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Tue, 6 Feb 2018 09:09:10 +0000 (12:09 +0300)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 22 Feb 2018 12:52:45 +0000 (13:52 +0100)
Let's use virPortAllocatorRelease instead of virPortAllocatorSetUsed(false).

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
src/bhyve/bhyve_command.c
src/bhyve/bhyve_process.c
src/qemu/qemu_process.c
src/util/virportallocator.c
src/util/virportallocator.h
tests/bhyvexml2argvtest.c
tests/libxlxml2domconfigtest.c

index 3442fe73c0975e0fdeb0c5c88d19a313bb5dbc2c..ec5d240121bcf9f0776c30787797d1769a84ad09 100644 (file)
@@ -409,7 +409,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
                     return -1;
                 graphics->data.vnc.port = port;
             } else {
-                if (virPortAllocatorSetUsed(graphics->data.vnc.port, true) < 0)
+                if (virPortAllocatorSetUsed(graphics->data.vnc.port) < 0)
                     VIR_WARN("Failed to mark VNC port '%d' as used by '%s'",
                              graphics->data.vnc.port, def->name);
             }
index 5e682faad663a673198ab397583376ab276d49a3..4ff6257f8409b54e7715f3920bba37b90f888ea7 100644 (file)
@@ -424,7 +424,7 @@ virBhyveProcessReconnect(virDomainObjPtr vm,
              if (vm->def->ngraphics == 1 &&
                  vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
                  int vnc_port = vm->def->graphics[0]->data.vnc.port;
-                 if (virPortAllocatorSetUsed(vnc_port, true) < 0) {
+                 if (virPortAllocatorSetUsed(vnc_port) < 0) {
                      VIR_WARN("Failed to mark VNC port '%d' as used by '%s'",
                               vnc_port, vm->def->name);
                  }
index 2053f8ead134b774ccd6bca220eacfea02ace901..1923c8e359c924a4e08f09b4a02fefa1f206f2e9 100644 (file)
@@ -4244,12 +4244,12 @@ qemuProcessGraphicsReservePorts(virDomainGraphicsDefPtr graphics,
     case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
         if (!graphics->data.vnc.autoport ||
             reconnect) {
-            if (virPortAllocatorSetUsed(graphics->data.vnc.port, true) < 0)
+            if (virPortAllocatorSetUsed(graphics->data.vnc.port) < 0)
                 return -1;
             graphics->data.vnc.portReserved = true;
         }
         if (graphics->data.vnc.websocket > 0 &&
-            virPortAllocatorSetUsed(graphics->data.vnc.websocket, true) < 0)
+            virPortAllocatorSetUsed(graphics->data.vnc.websocket) < 0)
             return -1;
         break;
 
@@ -4258,13 +4258,13 @@ qemuProcessGraphicsReservePorts(virDomainGraphicsDefPtr graphics,
             return 0;
 
         if (graphics->data.spice.port > 0) {
-            if (virPortAllocatorSetUsed(graphics->data.spice.port, true) < 0)
+            if (virPortAllocatorSetUsed(graphics->data.spice.port) < 0)
                 return -1;
             graphics->data.spice.portReserved = true;
         }
 
         if (graphics->data.spice.tlsPort > 0) {
-            if (virPortAllocatorSetUsed(graphics->data.spice.tlsPort, true) < 0)
+            if (virPortAllocatorSetUsed(graphics->data.spice.tlsPort) < 0)
                 return -1;
             graphics->data.spice.tlsPortReserved = true;
         }
@@ -6731,7 +6731,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
             if (graphics->data.vnc.autoport) {
                 virPortAllocatorRelease(graphics->data.vnc.port);
             } else if (graphics->data.vnc.portReserved) {
-                virPortAllocatorSetUsed(graphics->data.spice.port, false);
+                virPortAllocatorRelease(graphics->data.spice.port);
                 graphics->data.vnc.portReserved = false;
             }
             if (graphics->data.vnc.websocketGenerated) {
@@ -6739,7 +6739,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
                 graphics->data.vnc.websocketGenerated = false;
                 graphics->data.vnc.websocket = -1;
             } else if (graphics->data.vnc.websocket) {
-                virPortAllocatorSetUsed(graphics->data.vnc.websocket, false);
+                virPortAllocatorRelease(graphics->data.vnc.websocket);
             }
         }
         if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
@@ -6748,12 +6748,12 @@ void qemuProcessStop(virQEMUDriverPtr driver,
                 virPortAllocatorRelease(graphics->data.spice.tlsPort);
             } else {
                 if (graphics->data.spice.portReserved) {
-                    virPortAllocatorSetUsed(graphics->data.spice.port, false);
+                    virPortAllocatorRelease(graphics->data.spice.port);
                     graphics->data.spice.portReserved = false;
                 }
 
                 if (graphics->data.spice.tlsPortReserved) {
-                    virPortAllocatorSetUsed(graphics->data.spice.tlsPort, false);
+                    virPortAllocatorRelease(graphics->data.spice.tlsPort);
                     graphics->data.spice.tlsPortReserved = false;
                 }
             }
index d800fdfd41265684bb0e30b7371859d23d5a78ec..8620372676895f770bffe701776abe678d6cc491 100644 (file)
@@ -287,8 +287,7 @@ virPortAllocatorRelease(unsigned short port)
 }
 
 int
-virPortAllocatorSetUsed(unsigned short port,
-                        bool value)
+virPortAllocatorSetUsed(unsigned short port)
 {
     int ret = -1;
     virPortAllocatorPtr pa = virPortAllocatorGet();
@@ -298,20 +297,11 @@ virPortAllocatorSetUsed(unsigned short port,
 
     virObjectLock(pa);
 
-    if (value) {
-        if (virBitmapIsBitSet(pa->bitmap, port) ||
-            virBitmapSetBit(pa->bitmap, port) < 0) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Failed to reserve port %d"), port);
-            goto cleanup;
-        }
-    } else {
-        if (virBitmapClearBit(pa->bitmap, port) < 0) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Failed to release port %d"),
-                           port);
-            goto cleanup;
-        }
+    if (virBitmapIsBitSet(pa->bitmap, port) ||
+        virBitmapSetBit(pa->bitmap, port) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to reserve port %d"), port);
+        goto cleanup;
     }
 
     ret = 0;
index 1d7505fcf8f0c06382870837bbe3386ba13d4ffd..11696b786571a270013f86d768e6dbf7781a9945 100644 (file)
@@ -40,6 +40,6 @@ int virPortAllocatorAcquire(virPortAllocatorRangePtr range,
 
 int virPortAllocatorRelease(unsigned short port);
 
-int virPortAllocatorSetUsed(unsigned short port, bool value);
+int virPortAllocatorSetUsed(unsigned short port);
 
 #endif /* __VIR_PORT_ALLOCATOR_H__ */
index eb0f548f17e17477f11905fb10206b4f0e0dbf83..6f3b0c2ebf6eaf92bdd02d6b01c68339415f1804 100644 (file)
@@ -93,12 +93,8 @@ static int testCompareXMLToArgvFiles(const char *xml,
  out:
     if (vmdef &&
         vmdef->ngraphics == 1 &&
-        vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
-        if (vmdef->graphics[0]->data.vnc.autoport)
-            virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port);
-        else
-            virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, false);
-    }
+        vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC)
+        virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port);
 
     VIR_FREE(actualargv);
     VIR_FREE(actualld);
index 1f7411c57c3e0b094377b2cc4590086cdb361e63..ea3d2884ef674be7073bfb4be06712e2c5f70525 100644 (file)
@@ -113,12 +113,8 @@ testCompareXMLToDomConfig(const char *xmlfile,
  cleanup:
     if (vmdef &&
         vmdef->ngraphics == 1 &&
-        vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
-        if (vmdef->graphics[0]->data.vnc.autoport)
-            virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port);
-        else
-            virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, false);
-    }
+        vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC)
+        virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port);
 
     VIR_FREE(expectjson);
     VIR_FREE(actualjson);