mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 09:17:52 +03:00
Auto add virtio-serial controllers
In virDomainVirtioSerialAddrNext, add another controller if we've exhausted all ports of the existing controllers. https://bugzilla.redhat.com/show_bug.cgi?id=1076708
This commit is contained in:
parent
89e991a2aa
commit
1371ea92f0
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
@ -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>
|
@ -1074,6 +1074,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",
|
||||
|
Loading…
Reference in New Issue
Block a user