[pve-devel] [PATCH 3/6] add vm_deviceadd sub

Derumier Alexandre aderumier at odiso.com
Mon Oct 10 16:46:55 CEST 2011


use qm monitor to hotplug pci device

currently only virtio disk

Signed-off-by: Derumier Alexandre <aderumier at odiso.com>
---
 PVE/QemuServer.pm |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 14635ae..4e41e2a 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -900,7 +900,7 @@ sub print_drivedevice_full {
 
     if ($drive->{interface} eq 'virtio') {
       my $pciaddr = print_pci_addr("$drive->{interface}$drive->{index}");
-      $device = "virtio-blk-pci,drive=drive-$drive->{interface}$drive->{index},id=device-$drive->{interface}$drive->{index}$pciaddr";
+      $device = "virtio-blk-pci,drive=drive-$drive->{interface}$drive->{index},id=$drive->{interface}$drive->{index}$pciaddr";
     }
 
     elsif ($drive->{interface} eq 'scsi') {
@@ -2270,6 +2270,29 @@ sub vm_devices_list {
 return $devices;
 }
 
+sub vm_deviceadd {
+    my ($storecfg,$vmid, $deviceid,$device) = @_;
+
+    my $cfspath = cfs_config_path($vmid);
+    my $conf = PVE::Cluster::cfs_read_file($cfspath) || {};
+
+    return if !check_running ($vmid) || $conf->{hotplug} != 1 ; # do nothing if vm is running or hotplug option not set to 1
+
+    if($deviceid =~ m/^(virtio)(\d+)$/) {
+
+        my $drive = print_drive_full ($storecfg,$vmid, $device);
+        vm_monitor_command ($vmid, "drive_add auto $drive", 1);
+        my $devicefull = print_drivedevice_full ($storecfg,$vmid, $device);
+        vm_monitor_command ($vmid, "device_add $devicefull", 1);
+    }
+
+    #verification
+    sleep 2; #give a litlle time to os to add the device
+    my $devices_list = vm_devices_list($vmid);
+    die "error on hotplug device" if(! defined($devices_list->{$deviceid}));
+
+}
+
 sub vm_start {
     my ($storecfg, $vmid, $statefile, $skiplock) = @_;
 
-- 
1.7.2.5




More information about the pve-devel mailing list