[pve-devel] [PATCH 5/9] implement virtio iothread hotplug

Alexandre Derumier aderumier at odiso.com
Fri Jan 16 11:00:57 CET 2015


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm |   37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 028b211..927e79c 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3175,6 +3175,8 @@ sub vm_deviceplug {
 
     } elsif ($deviceid =~ m/^(virtio)(\d+)$/) {
 
+	qemu_iothread_add($vmid, $deviceid, $device);
+
         qemu_driveadd($storecfg, $vmid, $device);
         my $devicefull = print_drivedevice_full($storecfg, $conf, $vmid, $device);
 
@@ -3256,7 +3258,8 @@ sub vm_deviceunplug {
         qemu_devicedel($vmid, $deviceid);
         qemu_devicedelverify($vmid, $deviceid);
         qemu_drivedel($vmid, $deviceid);
-   
+	qemu_iothread_del($conf, $vmid, $deviceid);
+
     } elsif ($deviceid =~ m/^(scsihw)(\d+)$/) {
     
 	qemu_devicedel($vmid, $deviceid);
@@ -3296,6 +3299,25 @@ sub qemu_devicedel {
     my $ret = vm_mon_cmd($vmid, "device_del", id => $deviceid);
 }
 
+sub qemu_iothread_add {
+    my($vmid, $deviceid, $device) = @_;
+
+    if ($device->{iothread}) {
+	my $iothreads = vm_iothreads_list($vmid);
+	qemu_objectadd($vmid, "iothread-$deviceid", "iothread") if !$iothreads->{"iothread-$deviceid"};
+    }
+}
+
+sub qemu_iothread_del {
+    my($conf, $vmid, $deviceid) = @_;
+
+    my $device = parse_drive($deviceid, $conf->{$deviceid});
+    if ($device->{iothread}) {
+	my $iothreads = vm_iothreads_list($vmid);
+	qemu_objectdel($vmid, "iothread-$deviceid") if $iothreads->{"iothread-$deviceid"};
+    }
+}
+
 sub qemu_objectadd {
     my($vmid, $objectid, $qomtype) = @_;
 
@@ -5976,4 +5998,17 @@ sub lspci {
     return $devices;
 }
 
+sub vm_iothreads_list {
+    my ($vmid) = @_;
+
+    my $res = vm_mon_cmd($vmid, 'query-iothreads');
+
+    my $iothreads = {};
+    foreach my $iothread (@$res) {
+	$iothreads->{ $iothread->{id} } = $iothread->{"thread-id"};
+    }
+
+    return $iothreads;
+}
+
 1;
-- 
1.7.10.4



More information about the pve-devel mailing list