[pve-devel] [PATCH 11/11] hostpci rework

Derumier Alexandre aderumier at odiso.com
Wed Sep 7 15:34:46 CEST 2011


-add MAX_HOSTPCI_DEVICES=2 (can be tuned later)

-change code to support 1 line by device
hostpci0: ...
hostpci1: ...

-add device id.

Need be be fixed:
- check iommu support before adding devices
- unmap device from host kernel driver before add

http://www.linux-kvm.org/page/How_to_assign_devices_with_VT-d_in_KVM

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

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 07bc7f1..6db8305 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -302,22 +302,6 @@ EODESC
 	description => "Enable/disable Balloon device.",
 	default => 1,
     },
-    hostpci => {
-	optional => 1,
-        type => 'string', format => 'pve-qm-hostpci',
-	typetext => "HOSTPCIDEVICE { , HOSTPCIDEVICE }",
-	description => <<EODESCR,
-Map host pci devices. HOSTPCIDEVICE syntax is:
-
-'bus:dev.func' (hexadecimal numbers)
-
-You can us the 'lspci' command to list existing pci devices.
-
-Note: This option allows direct access to host hardware. So it is no longer possible to migrate such machines - use with special care.
-
-Experimental: user reported problems with this option.
-EODESCR
-    },
     serial => {
 	optional => 1,
 	type => 'string', format => 'pve-qm-serial',
@@ -421,6 +405,7 @@ my $MAX_VIRTIO_DISKS = 6;
 my $MAX_USB_DEVICES = 5;
 my $MAX_NETS = 6;
 my $MAX_UNUSED_DISKS = 8;
+my $MAX_HOSTPCI_DEVICES = 2;
 
 my $nic_model_list = ['rtl8139', 'ne2k_pci', 'e1000',  'pcnet',  'virtio',
 		      'ne2k_isa', 'i82551', 'i82557b', 'i82559er'];
@@ -459,6 +444,29 @@ for (my $i = 0; $i < $MAX_NETS; $i++)  {
     $confdesc->{"net$i"} = $netdesc;
 }
 
+my $hostpcidesc = {
+	optional => 1,
+        type => 'string', format => 'pve-qm-hostpci',
+	typetext => "HOSTPCIDEVICE { , HOSTPCIDEVICE }",
+	description => <<EODESCR,
+Map host pci devices. HOSTPCIDEVICE syntax is:
+
+'bus:dev.func' (hexadecimal numbers)
+
+You can us the 'lspci' command to list existing pci devices.
+
+Note: This option allows direct access to host hardware. So it is no longer possible to migrate such machines - use with special care.
+
+Experimental: user reported problems with this option.
+EODESCR
+};
+PVE::JSONSchema::register_standard_option("pve-qm-hostpci", $hostpcidesc);
+
+for (my $i = 0; $i < $MAX_HOSTPCI_DEVICES; $i++)  {
+    $confdesc->{"hostpci$i"} = $hostpcidesc;
+}
+
+
 my $drivename_hash;
     
 my $idedesc = {
@@ -1043,13 +1051,10 @@ PVE::JSONSchema::register_format('pve-qm-hostpci', \&verify_hostpci);
 sub verify_hostpci {
     my ($value, $noerr) = @_;
 
-    my @dl = split (/,/, $value);
-    foreach my $v (@dl) {
-	if ($v !~ m/^[a-f0-9]{2}:[a-f0-9]{2}\.[a-f0-9]$/i) {
+	if ($value !~ m/^[a-f0-9]{2}:[a-f0-9]{2}\.[a-f0-9]$/i) {
 	    return undef if $noerr;
 	    die "unable to parse pci id\n";
 	}
-    }
     return $value;
 }
 
@@ -1918,11 +1923,11 @@ sub config_to_command {
     push @$cmd, '-device', 'usb-tablet,bus=ehci.0,port=6' if $tablet;
 
     # host pci devices
-    if (my $pcidl = $conf->{hostpci}) {
-	my @dl = split (/,/, $pcidl);
-	foreach my $dev (@dl) {
-	    push @$cmd, '-device', "pci-assign,host=$dev" if $dev;
-	}
+    #fixme : need to check IOMMU support
+    #http://www.linux-kvm.org/page/How_to_assign_devices_with_VT-d_in_KVM
+    for (my $i = 0; $i < $MAX_HOSTPCI_DEVICES; $i++)  {
+	    #fixme : unbind device from host kernel driver before add to guest
+	    push @$cmd, '-device', "pci-assign,host=$conf->{\"hostpci$i\"},id=hostpci$i";
     }
 
     # usb devices
-- 
1.7.2.5



More information about the pve-devel mailing list