[pve-devel] [PATCH 2/6] add vm_devices_list sub

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


parse qemu "info pci" result

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

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index f5b5103..14635ae 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2244,6 +2244,32 @@ sub next_migrate_port {
     die "unable to find free migration port";
 }
 
+sub vm_devices_list {
+    my ($vmid) = @_;
+
+        my $res = vm_monitor_command ($vmid, "info pci", 1);
+
+        my @lines = split ("\n", $res);
+        my $devices;
+        my $bus;
+        my $addr;
+        my $id;
+        foreach my $line (@lines) {
+            $line =~ s/^\s+//;
+          if ($line =~ m/^Bus  (\d+), device   (\d+), function (\d+):$/) {
+           $bus=$1;
+           $addr=$2;
+          }
+          if ($line =~ m/^id "([a-z][a-z_\-]*\d*)"$/) {
+            $id=$1;
+            $devices->{$id}->{bus}=$bus;
+            $devices->{$id}->{addr}=$addr;
+          }
+        }
+
+return $devices;
+}
+
 sub vm_start {
     my ($storecfg, $vmid, $statefile, $skiplock) = @_;
 
-- 
1.7.2.5




More information about the pve-devel mailing list