]> git.proxmox.com Git - pve-container.git/commitdiff
Move volume activation to vm_start
authorStoiko Ivanov <s.ivanov@proxmox.com>
Tue, 14 Jul 2020 17:50:18 +0000 (19:50 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Tue, 4 Aug 2020 11:49:54 +0000 (13:49 +0200)
currently all volumes for a container are activated in the pre-start hook,
which runs in a separate mount namespace (lxc.monitor.unshare is set to 1
in our container config). This leads to problems with ZFS:
* if a pool is imported by this call the filesystems are mounted only inside
  the containers mount namespace

by running the volume activation inside vm_start, right before starting the
container via systemctl the volume activation happens before the unshare.

The other site where a container is started via systemctl is in
'pve-container-stop-wrapper' when a container is rebooted from the inside:
By activating the volumes in 'lxc-pve-poststop-hook' we avoid to try starting
a container with an inactive volume (LVM, kRBD), occuring when having a
mp-addtion pending during such a reboot

Starting a container manually using lxc-start is usually done for obtaining
debug-logs (after starting failed with our tooling) - so the potential for
regression in that case should also be small.

The $loopdevlist variable is not used anywhere in our codebase since 2015
(da6298481ea4dfe7d894f42fa105cda015ebe5ce).

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
src/PVE/LXC.pm
src/lxc-pve-poststop-hook
src/lxc-pve-prestart-hook

index f3aca7a2b871a2dacb31a5045835b95acbe35e2d..db5b8ca6ce82d9d40dbca1045b5afcb12da1a89e 100644 (file)
@@ -2186,6 +2186,11 @@ sub vm_start {
        close($fh);
     }
 
+    my $storage_cfg = PVE::Storage::config();
+    my $vollist = PVE::LXC::Config->get_vm_volumes($conf);
+
+    PVE::Storage::activate_volumes($storage_cfg, $vollist);
+
     my $cmd = ['systemctl', 'start', "pve-container\@$vmid"];
 
     PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'pre-start', 1);
index 2683ae2d1361fc011038a58d064f57e14c7a1176..0fdd49ea4482a749083f99ca4ba801142c40a98a 100755 (executable)
@@ -75,6 +75,12 @@ PVE::LXC::Tools::lxc_hook('post-stop', 'lxc', sub {
        open(my $fh, '>', "/var/lib/lxc/$vmid/reboot")
            or die "failed to create reboot trigger file: $!\n";
        close($fh);
+
+       # activate all volumes of the container in case pending changes added
+       # a not yet activated volume
+       my $vollist = PVE::LXC::Config->get_vm_volumes($conf);
+       PVE::Storage::activate_volumes($storage_cfg, $vollist);
+
        # cause lxc to stop instead of rebooting
        exit(1);
     }
index ed25aa4170931323bc081ec44e30258b893f3059..8823cadb766d9e72bf8d4adcd3f9d0fb85970d25 100755 (executable)
@@ -38,11 +38,6 @@ PVE::LXC::Tools::lxc_hook('pre-start', 'lxc', sub {
 
     my $storage_cfg = PVE::Storage::config();
 
-    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 = $vars->{ROOTFS_PATH};
 
     # Delete any leftover reboot-trigger file