In virDomainVirtioSerialAddrNext, add another controller
if we've exhausted all ports of the existing controllers.
https://bugzilla.redhat.com/show_bug.cgi?id=1076708
---
src/conf/domain_addr.c | 47 +++++++++++++++++++---
src/conf/domain_addr.h | 10 +++--
src/qemu/qemu_command.c | 4 +-
src/qemu/qemu_hotplug.c | 3 +-
.../qemuxml2argv-channel-virtio-autoadd.args | 33 +++++++++++++++
.../qemuxml2argv-channel-virtio-autoadd.xml | 45 +++++++++++++++++++++
tests/qemuxml2argvtest.c | 2 +
7 files changed, 132 insertions(+), 12 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-autoadd.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-autoadd.xml
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index 49d28be..27a237d 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -878,7 +878,28 @@ virDomainVirtioSerialAddrSetFree(virDomainVirtioSerialAddrSetPtr
addrs)
}
static int
-virDomainVirtioSerialAddrNext(virDomainVirtioSerialAddrSetPtr addrs,
+virDomainVirtioSerialAddrSetAutoaddController(virDomainDefPtr def,
+ virDomainVirtioSerialAddrSetPtr addrs,
+ unsigned int idx)
+{
+ int contidx;
+
+ if (virDomainDefMaybeAddController(def,
+ VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL,
+ idx, -1) < 0)
+ return -1;
+
+ contidx = virDomainControllerFind(def, VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL,
idx);
+
+ if (virDomainVirtioSerialAddrSetAddController(addrs, def->controllers[contidx])
< 0)
+ return -1;
+
+ return 0;
+}
+
+static int
+virDomainVirtioSerialAddrNext(virDomainDefPtr def,
+ virDomainVirtioSerialAddrSetPtr addrs,
virDomainDeviceVirtioSerialAddress *addr,
bool allowZero)
{
@@ -905,6 +926,20 @@ virDomainVirtioSerialAddrNext(virDomainVirtioSerialAddrSetPtr addrs,
}
}
+ if (def) {
+ for (i = 0; i < INT_MAX; i++) {
+ int idx = virDomainControllerFind(def,
VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL, i);
+
+ if (idx == -1) {
+ if (virDomainVirtioSerialAddrSetAutoaddController(def, addrs, i) < 0)
+ goto cleanup;
+ controller = i;
+ port = startPort + 1;
+ goto success;
+ }
+ }
+ }
+
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Unable to find a free virtio-serial port"));
@@ -958,7 +993,8 @@
virDomainVirtioSerialAddrNextFromController(virDomainVirtioSerialAddrSetPtr addr
* or assign a virtio serial address to the device
*/
int
-virDomainVirtioSerialAddrAutoAssign(virDomainVirtioSerialAddrSetPtr addrs,
+virDomainVirtioSerialAddrAutoAssign(virDomainDefPtr def,
+ virDomainVirtioSerialAddrSetPtr addrs,
virDomainDeviceInfoPtr info,
bool allowZero)
{
@@ -967,12 +1003,13 @@ virDomainVirtioSerialAddrAutoAssign(virDomainVirtioSerialAddrSetPtr
addrs,
info->addr.vioserial.port)
return virDomainVirtioSerialAddrReserve(NULL, NULL, info, addrs);
else
- return virDomainVirtioSerialAddrAssign(addrs, info, allowZero, portOnly);
+ return virDomainVirtioSerialAddrAssign(def, addrs, info, allowZero, portOnly);
}
int
-virDomainVirtioSerialAddrAssign(virDomainVirtioSerialAddrSetPtr addrs,
+virDomainVirtioSerialAddrAssign(virDomainDefPtr def,
+ virDomainVirtioSerialAddrSetPtr addrs,
virDomainDeviceInfoPtr info,
bool allowZero,
bool portOnly)
@@ -988,7 +1025,7 @@ virDomainVirtioSerialAddrAssign(virDomainVirtioSerialAddrSetPtr
addrs,
&ptr->addr.vioserial) <
0)
goto cleanup;
} else {
- if (virDomainVirtioSerialAddrNext(addrs, &ptr->addr.vioserial,
+ if (virDomainVirtioSerialAddrNext(def, addrs, &ptr->addr.vioserial,
allowZero) < 0)
goto cleanup;
}
diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h
index 14ffd17..c18e130 100644
--- a/src/conf/domain_addr.h
+++ b/src/conf/domain_addr.h
@@ -208,17 +208,19 @@ virDomainVirtioSerialAddrSetFree(virDomainVirtioSerialAddrSetPtr
addrs);
bool
virDomainVirtioSerialAddrIsComplete(virDomainDeviceInfoPtr info);
int
-virDomainVirtioSerialAddrAutoAssign(virDomainVirtioSerialAddrSetPtr addrs,
+virDomainVirtioSerialAddrAutoAssign(virDomainDefPtr def,
+ virDomainVirtioSerialAddrSetPtr addrs,
virDomainDeviceInfoPtr info,
bool allowZero)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+ ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
int
-virDomainVirtioSerialAddrAssign(virDomainVirtioSerialAddrSetPtr addrs,
+virDomainVirtioSerialAddrAssign(virDomainDefPtr def,
+ virDomainVirtioSerialAddrSetPtr addrs,
virDomainDeviceInfoPtr info,
bool allowZero,
bool portOnly)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+ ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
int
virDomainVirtioSerialAddrReserve(virDomainDefPtr def,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2af5dbf..c339088 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1433,7 +1433,7 @@ qemuDomainAssignVirtioSerialAddresses(virDomainDefPtr def,
if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO &&
!virDomainVirtioSerialAddrIsComplete(&chr->info) &&
- virDomainVirtioSerialAddrAutoAssign(addrs, &chr->info, true) < 0)
+ virDomainVirtioSerialAddrAutoAssign(def, addrs, &chr->info, true) <
0)
goto cleanup;
}
@@ -1442,7 +1442,7 @@ qemuDomainAssignVirtioSerialAddresses(virDomainDefPtr def,
if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO &&
!virDomainVirtioSerialAddrIsComplete(&chr->info) &&
- virDomainVirtioSerialAddrAutoAssign(addrs, &chr->info, false) < 0)
+ virDomainVirtioSerialAddrAutoAssign(def, addrs, &chr->info, false)
< 0)
goto cleanup;
}
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 560a164..2f0549e 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1557,7 +1557,8 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO)
allowZero = true;
- if (virDomainVirtioSerialAddrAutoAssign(priv->vioserialaddrs,
+ if (virDomainVirtioSerialAddrAutoAssign(NULL,
+ priv->vioserialaddrs,
&chr->info,
allowZero) < 0)
goto cleanup;
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-autoadd.args
b/tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-autoadd.args
new file mode 100644
index 0000000..9aae58a
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-autoadd.args
@@ -0,0 +1,33 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu -S -M pc -m 214 -smp 1 \
+-nographic -nodefconfig -nodefaults \
+-chardev socket,id=charmonitor,path=/tmp/test-monitor,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=readline \
+-no-acpi -boot c \
+-device virtio-serial-pci,id=virtio-serial0,max_ports=4,vectors=4,bus=pci.0,addr=0x3 \
+-device virtio-serial-pci,id=virtio-serial1,bus=pci.0,addr=0x4 \
+-usb -hda /dev/HostVG/QEMUGuest1 \
+-chardev pty,id=charchannel0 \
+-device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,\
+id=channel0,name=org.linux-kvm.port.0 \
+-chardev pty,id=charchannel1 \
+-device virtserialport,bus=virtio-serial0.0,nr=2,chardev=charchannel1,\
+id=channel1,name=org.linux-kvm.port.foo \
+-chardev pty,id=charchannel2 \
+-device virtserialport,bus=virtio-serial0.0,nr=3,chardev=charchannel2,\
+id=channel2,name=org.linux-kvm.port.bar \
+-chardev pty,id=charchannel3 \
+-device virtserialport,bus=virtio-serial1.0,nr=1,chardev=charchannel3,\
+id=channel3,name=org.linux-kvm.port.wizz \
+-chardev pty,id=charchannel4 \
+-device virtserialport,bus=virtio-serial1.0,nr=2,chardev=charchannel4,\
+id=channel4,name=org.linux-kvm.port.ooh \
+-chardev pty,id=charchannel5 \
+-device virtserialport,bus=virtio-serial1.0,nr=3,chardev=charchannel5,\
+id=channel5,name=org.linux-kvm.port.lla \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-autoadd.xml
b/tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-autoadd.xml
new file mode 100644
index 0000000..0da2492
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-autoadd.xml
@@ -0,0 +1,45 @@
+<domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219100</memory>
+ <currentMemory unit='KiB'>219100</currentMemory>
+ <vcpu placement='static' cpuset='1-4,8-20,525'>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu</emulator>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <target dev='hda' bus='ide'/>
+ <address type='drive' controller='0' bus='0'
target='0' unit='0'/>
+ </disk>
+ <controller type='usb' index='0'/>
+ <controller type='ide' index='0'/>
+ <controller type='virtio-serial' index='0' ports='4'
vectors='4'/>
+ <channel type='pty'>
+ <target type='virtio' name='org.linux-kvm.port.0'/>
+ </channel>
+ <channel type='pty'>
+ <target type='virtio' name='org.linux-kvm.port.foo'/>
+ </channel>
+ <channel type='pty'>
+ <target type='virtio' name='org.linux-kvm.port.bar'/>
+ </channel>
+ <channel type='pty'>
+ <target type='virtio' name='org.linux-kvm.port.wizz'/>
+ </channel>
+ <channel type='pty'>
+ <target type='virtio' name='org.linux-kvm.port.ooh'/>
+ </channel>
+ <channel type='pty'>
+ <target type='virtio' name='org.linux-kvm.port.lla'/>
+ </channel>
+ <memballoon model='virtio'/>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 00e608c..ff8b37a 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1072,6 +1072,8 @@ mymain(void)
QEMU_CAPS_DEVICE, QEMU_CAPS_CHARDEV, QEMU_CAPS_NODEFCONFIG);
DO_TEST("channel-virtio-autoassign",
QEMU_CAPS_DEVICE, QEMU_CAPS_CHARDEV, QEMU_CAPS_NODEFCONFIG);
+ DO_TEST("channel-virtio-autoadd",
+ QEMU_CAPS_DEVICE, QEMU_CAPS_CHARDEV, QEMU_CAPS_NODEFCONFIG);
DO_TEST("console-virtio",
QEMU_CAPS_DEVICE, QEMU_CAPS_CHARDEV, QEMU_CAPS_NODEFCONFIG);
DO_TEST("console-virtio-many",
--
2.0.5