[pve-devel] [PATCH 4/8] create qemu_deviceadd, qemu_devicedel, qemu_driveadd, qemu_drivedel, qemu_deviceaddverify, qemu_devicedelverify from previous patch code removal
Derumier Alexandre
aderumier at odiso.com
Fri Dec 23 08:09:44 CET 2011
Signed-off-by: Derumier Alexandre <aderumier at odiso.com>
---
PVE/QemuServer.pm | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 684701c..c0ef80d 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2293,6 +2293,77 @@ sub vm_deviceunplug {
}
+
+sub qemu_deviceadd {
+ my($vmid,$devicefull) = @_;
+
+ my $ret = vm_monitor_command($vmid, "device_add $devicefull");
+ $ret =~ s/^\s+//;
+ # Otherwise, if the command succeeds, no output is sent. So any non-empty string shows an error
+ die "error on hotplug device : $ret" if $ret ne "";
+
+}
+
+sub qemu_devicedel {
+ my($vmid, $deviceid) = @_;
+
+ my $ret = vm_monitor_command($vmid, "device_del $deviceid");
+ $ret =~ s/^\s+//;
+ die "detaching device $deviceid failed : $ret" if $ret ne "";
+
+}
+
+
+sub qemu_driveadd {
+ my($storecfg, $vmid, $device) = @_;
+
+ my $drive = print_drive_full($storecfg, $vmid, $device);
+ my $ret = vm_monitor_command($vmid, "drive_add auto $drive");
+ # If the command succeeds qemu prints: "OK"
+ if ($ret !~ m/OK/s) {
+ die "adding drive failed: $ret";
+ }
+}
+
+sub qemu_drivedel {
+ my($vmid, $deviceid) = @_;
+
+ my $ret = vm_monitor_command($vmid, "drive_del drive-$deviceid");
+ $ret =~ s/^\s+//;
+ if ($ret =~ m/Device \'.*?\' not found/s) {
+ # NB: device not found errors mean the drive was auto-deleted and we ignore the error
+ }
+ elsif ($ret ne "") {
+ die "deleting drive $deviceid failed : $ret";
+ }
+
+}
+
+
+sub qemu_deviceaddverify {
+ my ($vmid,$deviceid) = @_;
+
+ for (my $i = 0; $i <= 5; $i++) {
+ my $devices_list = vm_devices_list($vmid);
+ return if defined($devices_list->{$deviceid});
+ sleep 1;
+ }
+ die "error on hotplug device $deviceid";
+}
+
+
+sub qemu_devicedelverify {
+ my ($vmid,$deviceid) = @_;
+
+ #need to verify the device is correctly remove as device_del is async and empty return is not reliable
+ for (my $i = 0; $i <= 5; $i++) {
+ my $devices_list = vm_devices_list($vmid);
+ return if !defined($devices_list->{$deviceid});
+ sleep 1;
+ }
+ die "error on hot-unplugging device $deviceid";
+}
+
sub vm_start {
my ($storecfg, $vmid, $statefile, $skiplock) = @_;
--
1.7.2.5
More information about the pve-devel
mailing list