[pve-devel] [PATCH qemu-server 3/3] PCI.pm: implement get_mdev_types

Dominik Csapak d.csapak at proxmox.com
Thu Nov 15 15:30:46 CET 2018


this will be used for the mdev api call for the gui

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/QemuServer/PCI.pm | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/PVE/QemuServer/PCI.pm b/PVE/QemuServer/PCI.pm
index 52bffe5..3cee8a0 100644
--- a/PVE/QemuServer/PCI.pm
+++ b/PVE/QemuServer/PCI.pm
@@ -248,6 +248,39 @@ sub lspci {
     return $devices;
 }
 
+sub get_mdev_types {
+    my ($id) = @_;
+
+    my $fullid = $id;
+    if ($id !~ m/^[0-9a-fA-f]{4}:/) {
+	$fullid = "0000:$id";
+    }
+
+    my $types = [];
+
+    my $mdev_path = "$pcisysfs/devices/$fullid/mdev_supported_types";
+    if (!-d $mdev_path) {
+	return $types;
+    }
+
+    dir_glob_foreach($mdev_path, '[^\.].*', sub {
+	my ($type) = @_;
+
+	my $type_path = "$mdev_path/$type";
+
+	my $available = int(PVE::Tools::file_read_firstline("$type_path/available_instances"));
+	my $description = PVE::Tools::file_get_contents("$type_path/description");
+
+	push @$types, {
+	    type => $type,
+	    description => $description,
+	    available => $available,
+	};
+    });
+
+    return $types;
+}
+
 sub check_iommu_support{
     # iommu support if there is anything in /sys/class/iommu besides . or ..
     return PVE::Tools::dir_glob_regex('/sys/class/iommu/', "[^\.].*");
-- 
2.11.0





More information about the pve-devel mailing list