]> git.proxmox.com Git - pve-container.git/blobdiff - src/PVE/LXC/Tools.pm
Add device passthrough
[pve-container.git] / src / PVE / LXC / Tools.pm
index 0ff56e8e0e1ce95161e8f8e72dd8ec6f8f9e7f38..f96756dc3b12b92943c7e3f454efd4ad424efb00 100644 (file)
@@ -81,10 +81,9 @@ sub lxc_hook($$&) {
     $code->($ct_name, $common_vars, $namespaces, $args);
 }
 
-sub for_current_devices($&) {
-    my ($vmid, $code) = @_;
+sub for_devices {
+    my ($devlist_file, $vmid, $code) = @_;
 
-    my $devlist_file = "/var/lib/lxc/$vmid/devices";
     my $fd;
 
     if (! open $fd, '<', $devlist_file) {
@@ -93,8 +92,8 @@ sub for_current_devices($&) {
     }
 
     while (defined(my $line = <$fd>)) {
-       if ($line !~ m@^(b):(\d+):(\d+):/dev/(\S+)\s*$@) {
-           warn "invalid .pve-devices entry: $line\n";
+       if ($line !~ m@^(b|c):(\d+):(\d+):/dev/(\S+)\s*$@) {
+           warn "invalid $devlist_file entry: $line\n";
            next;
        }
 
@@ -117,6 +116,27 @@ sub for_current_devices($&) {
     close $fd;
 }
 
+sub for_current_passthrough_mounts($&) {
+    my ($vmid, $code) = @_;
+
+    my $devlist_file = "/var/lib/lxc/$vmid/passthrough/mounts";
+
+    if (-e $devlist_file) {
+       for_devices($devlist_file, $vmid, $code);
+    } else {
+       # Fallback to the old device list file in case a package upgrade
+       # occurs between lxc-pve-prestart-hook and now.
+       for_devices("/var/lib/lxc/$vmid/devices", $vmid, $code);
+    }
+}
+
+sub for_current_passthrough_devices($&) {
+    my ($vmid, $code) = @_;
+
+    my $passthrough_devlist_file = "/var/lib/lxc/$vmid/passthrough/devices";
+    for_devices($passthrough_devlist_file, $vmid, $code);
+}
+
 sub cgroup_do_write($$) {
     my ($path, $value) = @_;
     my $fd;