]> git.proxmox.com Git - pve-container.git/blob - src/lxc-pve-autodev-hook
added quota flag to mountpoints
[pve-container.git] / src / lxc-pve-autodev-hook
1 #!/usr/bin/perl
2
3 package lxc_pve_autodev_hook;
4
5 use strict;
6 use warnings;
7
8 exit 0 if $ENV{LXC_NAME} && $ENV{LXC_NAME} !~ /^\d+$/;
9
10 use PVE::Tools;
11
12 my $vmid = $ENV{LXC_NAME};
13 my $root = $ENV{LXC_ROOTFS_MOUNT};
14
15 if (@ARGV != 3 || $ARGV[1] ne 'lxc' || $ARGV[2] ne 'autodev') {
16 die "invalid usage, this is an LXC autodev hook\n";
17 }
18
19 if ($vmid ne $ARGV[0]) {
20 die "got wrong name: $ARGV[0] while LXC_NAME=$vmid\n";
21 }
22
23 my $devlist_file = "/var/lib/lxc/$vmid/devices";
24
25 open my $fd, '<', $devlist_file;
26 if (!$fd) {
27 exit 0 if $!{ENOENT}; # If the list is empty the file might not exist.
28 die "failed to open device list: $!\n";
29 }
30
31 while (defined(my $line = <$fd>)) {
32 if ($line !~ m@^(b):(\d+):(\d+):/dev/(\S+)\s*$@) {
33 warn "invalid .pve-devices entry: $line\n";
34 }
35 my ($type, $major, $minor, $dev) = ($1, $2, $3, $4);
36
37 # Don't break out of $root/dev/
38 if ($dev =~ /\.\./) {
39 warn "skipping illegal device node entry: $dev\n";
40 next;
41 }
42
43 # Never expose /dev/loop-control
44 if ($major == 10 && $minor == 237) {
45 warn "skipping illegal device entry (loop-control) for: $dev\n";
46 next;
47 }
48
49 PVE::Tools::run_command(['mknod', '-m', '666', "$root/dev/$dev",
50 $type, $major, $minor]);
51 }
52 close $fd;