[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [RFC PATCH 3/3] assign free controller to virtio-serial port



When no <address> element is explicitly given, the virtio-serial port is
automatically assigned a controller which is known to have a free port
available.
---
 src/conf/domain_conf.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index bfb3a81..dbf7685 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12243,10 +12243,35 @@ virDomainDefParseXML(xmlDocPtr xml,
 
         def->channels[def->nchannels++] = chr;
 
+        /* assign to next controller with free port */
         if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
             chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO &&
-            chr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
+            chr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+            size_t j;
+            int found = 0;
+            int maxctlrindex = -1;
+            for (j = 0; j < def->ncontrollers && !found; j++) {
+                if (def->controllers[j]->type == VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL) {
+                    int ports = (def->controllers[j]->opts.vioserial.ports != -1)
+                              ?  def->controllers[j]->opts.vioserial.ports : 31;
+                    int maxport = virDomainGetVirtioSerialMaxPort
+                                    (def, def->controllers[j]->idx);
+                    if (maxport < ports-1) { /* free port? */
+                        chr->info.addr.vioserial.controller = def->controllers[j]->idx;
+                        found = 1;
+                    }
+                    if ((int)def->controllers[j]->idx > maxctlrindex)
+                        maxctlrindex = def->controllers[j]->idx;
+                }
+            }
+            if (!found) {
+                maxctlrindex++; /* assign to next implicit controller with free ports */
+                while (virDomainGetVirtioSerialMaxPort(def, maxctlrindex) >= 31-1)
+                    maxctlrindex++;
+                chr->info.addr.vioserial.controller = maxctlrindex;
+            }
             chr->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL;
+        }
 
         /* assign next port available on controller */
         if (chr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL &&
-- 
1.8.3.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]