]> git.proxmox.com Git - pve-container.git/blobdiff - src/lxc-pve-prestart-hook
docs: update mountpoint descriptions
[pve-container.git] / src / lxc-pve-prestart-hook
index 1ba957f63eb8805a9b1e119821433011a8bd64d6..9835b1c6e8f958953a751988383706e5f44ad856 100755 (executable)
@@ -60,52 +60,50 @@ __PACKAGE__->register_method ({
 
        PVE::Cluster::check_cfs_quorum(); # only start if we have quorum
 
-       return undef if ! -f PVE::LXC::config_file($vmid);
+       return undef if ! -f PVE::LXC::Config->config_file($vmid);
 
-       my $conf = PVE::LXC::load_config($vmid);
-       PVE::LXC::check_lock($conf);
+       my $conf = PVE::LXC::Config->load_config($vmid);
+       if (!$ENV{PVE_SKIPLOCK} && !PVE::LXC::Config->has_lock($conf, 'mounted')) {
+           PVE::LXC::Config->check_lock($conf);
+       }
 
        my $storage_cfg = PVE::Storage::config();
 
-       my $vollist = PVE::LXC::get_vm_volumes($conf);
-       my $loopdevlist = PVE::LXC::get_vm_volumes($conf, 'rootfs');
+       my $vollist = PVE::LXC::Config->get_vm_volumes($conf);
+       my $loopdevlist = PVE::LXC::Config->get_vm_volumes($conf, 'rootfs');
 
        PVE::Storage::activate_volumes($storage_cfg, $vollist);
 
        my $rootdir = $param->{rootfs};
 
+       my $devlist_file = "/var/lib/lxc/$vmid/devices";
+       unlink $devlist_file;
+       my $devices = [];
+
        my $setup_mountpoint = sub {
            my ($ms, $mountpoint) = @_;
 
            #return if $ms eq 'rootfs';
-           PVE::LXC::mountpoint_mount($mountpoint, $rootdir, $storage_cfg);
+           my (undef, undef, $dev) = PVE::LXC::mountpoint_mount($mountpoint, $rootdir, $storage_cfg);
+           push @$devices, $dev if $dev && $mountpoint->{quota};
        };
 
-       my $setup_cgroup_device = sub {
-           my ($ms, $mountpoint) = @_;
-
-           my $volid = $mountpoint->{volume};
-           return if !$volid || $volid !~ m|^/dev/.+|;
+       PVE::LXC::Config->foreach_mountpoint($conf, $setup_mountpoint);
 
-           my $path = PVE::LXC::mountpoint_mount_path($mountpoint, $storage_cfg);
+       my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir);
+       $lxc_setup->pre_start_hook();
 
-           my (undef, undef, $mode, undef, undef, undef, $rdev) = stat($path);
-           if ($mode && S_ISBLK($mode) && $rdev) {
+       if (@$devices) {
+           my $devlist = '';
+           foreach my $dev (@$devices) {
+               my ($mode, $rdev) = (stat($dev))[2,6];
+               next if !$mode || !S_ISBLK($mode) || !$rdev;
                my $major = int($rdev / 0x100);
                my $minor = $rdev % 0x100;
-               if ($major != 7) { # must not be a loop device
-                   PVE::Tools::run_command(['mknod', '-m', '666', "$rootdir$path", 'b', $major, $minor]);
-                   PVE::LXC::write_cgroup_value("devices", $vmid, "devices.allow", "b ${major}:${minor} rwm");
-               }
+               $devlist .= "b:$major:$minor:$dev\n";
            }
-       };
-
-       PVE::LXC::foreach_mountpoint($conf, $setup_mountpoint);
-
-       PVE::LXC::foreach_mountpoint($conf, $setup_cgroup_device);
-
-       my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir);
-       $lxc_setup->pre_start_hook();
+           PVE::Tools::file_set_contents($devlist_file, $devlist);
+       }
        return undef;
     }});