]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
port allocator: remove range on manual port reserving
authorNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Tue, 6 Feb 2018 09:09:07 +0000 (12:09 +0300)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 22 Feb 2018 12:52:45 +0000 (13:52 +0100)
Range check in virPortAllocatorSetUsed is not useful anymore
when we manage ports for entire unsigned short range values.

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 5e309c3a29a69361c5b72610ca084ad6b1f68c08..3442fe73c0975e0fdeb0c5c88d19a313bb5dbc2c 100644 (file)
@@ -409,9 +409,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
                     return -1;
                 graphics->data.vnc.port = port;
             } else {
-                if (virPortAllocatorSetUsed(driver->remotePorts,
-                                            graphics->data.vnc.port,
-                                            true) < 0)
+                if (virPortAllocatorSetUsed(graphics->data.vnc.port, true) < 0)
                     VIR_WARN("Failed to mark VNC port '%d' as used by '%s'",
                              graphics->data.vnc.port, def->name);
             }
index 5076246aac1add390ee9118d660445782e570419..e215f6a8dcde5b1c8c00eb0c36189cdd56277c8e 100644 (file)
@@ -425,9 +425,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(data->driver->remotePorts,
-                                             vnc_port,
-                                             true) < 0) {
+                 if (virPortAllocatorSetUsed(vnc_port, true) < 0) {
                      VIR_WARN("Failed to mark VNC port '%d' as used by '%s'",
                               vnc_port, vm->def->name);
                  }
index dc33eb7bcd2d7519c6c599b07a2640b4aeb83142..132606669c3ee80eaf53000240b20f4df8679f91 100644 (file)
@@ -4226,8 +4226,7 @@ qemuProcessStartHook(virQEMUDriverPtr driver,
 
 
 static int
-qemuProcessGraphicsReservePorts(virQEMUDriverPtr driver,
-                                virDomainGraphicsDefPtr graphics,
+qemuProcessGraphicsReservePorts(virDomainGraphicsDefPtr graphics,
                                 bool reconnect)
 {
     virDomainGraphicsListenDefPtr glisten;
@@ -4245,16 +4244,12 @@ qemuProcessGraphicsReservePorts(virQEMUDriverPtr driver,
     case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
         if (!graphics->data.vnc.autoport ||
             reconnect) {
-            if (virPortAllocatorSetUsed(driver->remotePorts,
-                                        graphics->data.vnc.port,
-                                        true) < 0)
+            if (virPortAllocatorSetUsed(graphics->data.vnc.port, true) < 0)
                 return -1;
             graphics->data.vnc.portReserved = true;
         }
         if (graphics->data.vnc.websocket > 0 &&
-            virPortAllocatorSetUsed(driver->remotePorts,
-                                    graphics->data.vnc.websocket,
-                                    true) < 0)
+            virPortAllocatorSetUsed(graphics->data.vnc.websocket, true) < 0)
             return -1;
         break;
 
@@ -4263,17 +4258,13 @@ qemuProcessGraphicsReservePorts(virQEMUDriverPtr driver,
             return 0;
 
         if (graphics->data.spice.port > 0) {
-            if (virPortAllocatorSetUsed(driver->remotePorts,
-                                        graphics->data.spice.port,
-                                        true) < 0)
+            if (virPortAllocatorSetUsed(graphics->data.spice.port, true) < 0)
                 return -1;
             graphics->data.spice.portReserved = true;
         }
 
         if (graphics->data.spice.tlsPort > 0) {
-            if (virPortAllocatorSetUsed(driver->remotePorts,
-                                        graphics->data.spice.tlsPort,
-                                        true) < 0)
+            if (virPortAllocatorSetUsed(graphics->data.spice.tlsPort, true) < 0)
                 return -1;
             graphics->data.spice.tlsPortReserved = true;
         }
@@ -4553,7 +4544,7 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver,
         for (i = 0; i < vm->def->ngraphics; i++) {
             graphics = vm->def->graphics[i];
 
-            if (qemuProcessGraphicsReservePorts(driver, graphics, false) < 0)
+            if (qemuProcessGraphicsReservePorts(graphics, false) < 0)
                 goto cleanup;
         }
     }
@@ -6741,9 +6732,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
                 virPortAllocatorRelease(driver->remotePorts,
                                         graphics->data.vnc.port);
             } else if (graphics->data.vnc.portReserved) {
-                virPortAllocatorSetUsed(driver->remotePorts,
-                                        graphics->data.spice.port,
-                                        false);
+                virPortAllocatorSetUsed(graphics->data.spice.port, false);
                 graphics->data.vnc.portReserved = false;
             }
             if (graphics->data.vnc.websocketGenerated) {
@@ -6752,9 +6741,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
                 graphics->data.vnc.websocketGenerated = false;
                 graphics->data.vnc.websocket = -1;
             } else if (graphics->data.vnc.websocket) {
-                virPortAllocatorSetUsed(driver->remotePorts,
-                                        graphics->data.vnc.websocket,
-                                        false);
+                virPortAllocatorSetUsed(graphics->data.vnc.websocket, false);
             }
         }
         if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
@@ -6765,16 +6752,12 @@ void qemuProcessStop(virQEMUDriverPtr driver,
                                         graphics->data.spice.tlsPort);
             } else {
                 if (graphics->data.spice.portReserved) {
-                    virPortAllocatorSetUsed(driver->remotePorts,
-                                            graphics->data.spice.port,
-                                            false);
+                    virPortAllocatorSetUsed(graphics->data.spice.port, false);
                     graphics->data.spice.portReserved = false;
                 }
 
                 if (graphics->data.spice.tlsPortReserved) {
-                    virPortAllocatorSetUsed(driver->remotePorts,
-                                            graphics->data.spice.tlsPort,
-                                            false);
+                    virPortAllocatorSetUsed(graphics->data.spice.tlsPort, false);
                     graphics->data.spice.tlsPortReserved = false;
                 }
             }
@@ -7365,9 +7348,7 @@ qemuProcessReconnect(void *opaque)
     }
 
     for (i = 0; i < obj->def->ngraphics; i++) {
-        if (qemuProcessGraphicsReservePorts(driver,
-                                            obj->def->graphics[i],
-                                            true) < 0)
+        if (qemuProcessGraphicsReservePorts(obj->def->graphics[i], true) < 0)
             goto error;
     }
 
index be29e97e1afcd4da03fb523436cd45bbc565734f..23c7af1755f36b5594ae2e3c602262a206b18070 100644 (file)
@@ -301,8 +301,7 @@ virPortAllocatorRelease(virPortAllocatorRangePtr range,
 }
 
 int
-virPortAllocatorSetUsed(virPortAllocatorRangePtr range,
-                        unsigned short port,
+virPortAllocatorSetUsed(unsigned short port,
                         bool value)
 {
     int ret = -1;
@@ -313,12 +312,6 @@ virPortAllocatorSetUsed(virPortAllocatorRangePtr range,
 
     virObjectLock(pa);
 
-    if (port < range->start ||
-        port > range->end) {
-        ret = 0;
-        goto cleanup;
-    }
-
     if (value) {
         if (virBitmapIsBitSet(pa->bitmap, port) ||
             virBitmapSetBit(pa->bitmap, port) < 0) {
index fb38c3318c5add6e79a72db9bffbd631affc6ff6..ea816bc9710f8be2fa72135be898287987459164 100644 (file)
@@ -46,8 +46,6 @@ int virPortAllocatorAcquire(virPortAllocatorRangePtr range,
 int virPortAllocatorRelease(virPortAllocatorRangePtr range,
                             unsigned short port);
 
-int virPortAllocatorSetUsed(virPortAllocatorRangePtr range,
-                            unsigned short port,
-                            bool value);
+int virPortAllocatorSetUsed(unsigned short port, bool value);
 
 #endif /* __VIR_PORT_ALLOCATOR_H__ */
index 47ea85bd39848ec3c776284379b37e68f7e35af4..e8089b8700a1ea01cf649daf28d222eb30c182aa 100644 (file)
@@ -97,7 +97,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
         if (vmdef->graphics[0]->data.vnc.autoport)
             virPortAllocatorRelease(gports, vmdef->graphics[0]->data.vnc.port);
         else
-            virPortAllocatorSetUsed(gports, vmdef->graphics[0]->data.vnc.port, false);
+            virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, false);
     }
 
     VIR_FREE(actualargv);
index 465edf09242d845da377b7e19252b9b616034485..bfe742b81926ae85d642186fa741c870db3eea7d 100644 (file)
@@ -118,7 +118,7 @@ testCompareXMLToDomConfig(const char *xmlfile,
         if (vmdef->graphics[0]->data.vnc.autoport)
             virPortAllocatorRelease(gports, vmdef->graphics[0]->data.vnc.port);
         else
-            virPortAllocatorSetUsed(gports, vmdef->graphics[0]->data.vnc.port, false);
+            virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, false);
     }
 
     VIR_FREE(expectjson);