From b58ba5d4494c2816805e02f8feba1594b7c2d4a5 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 31 May 2022 13:52:27 +0200 Subject: [PATCH] drop old mount code Signed-off-by: Wolfgang Bumiller --- src/PVE/LXC.pm | 12 +---- src/PVE/LXC/Config.pm | 4 -- src/PVE/LXC/Tools.pm | 18 ------- src/lxc-pve-prestart-hook | 111 ++++++++++++++++---------------------- 4 files changed, 48 insertions(+), 97 deletions(-) diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 1e9af0f..c9b5ba7 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -4,7 +4,7 @@ use strict; use warnings; use Cwd qw(); -use Errno qw(ELOOP ENOTDIR EROFS ECONNREFUSED ENOSYS EEXIST); +use Errno qw(ELOOP ENOTDIR EROFS ECONNREFUSED EEXIST); use Fcntl qw(O_RDONLY O_WRONLY O_NOFOLLOW O_DIRECTORY); use File::Path; use File::Spec; @@ -1681,7 +1681,6 @@ sub mountpoint_stage { __mountpoint_mount($mountpoint, $stage_dir, $storage_cfg, $snapname, $rootuid, $rootgid, 1); if (!defined($path)) { - return undef if $! == ENOSYS; die "failed to mount subvolume: $!\n"; } @@ -1716,16 +1715,9 @@ sub mountpoint_insert_staged { # Use $stage_mount, $rootdir is treated as a temporary path to "stage" the file system. The user # can then open a file descriptor to it which can be used with the `move_mount` syscall. -# Note that if the kernel does not support the new mount API, this will not perform any action -# and return `undef` with $! = ENOSYS. sub __mountpoint_mount { my ($mountpoint, $rootdir, $storage_cfg, $snapname, $rootuid, $rootgid, $stage_mount) = @_; - if (defined($stage_mount) && !PVE::LXC::Tools::can_use_new_mount_api()) { - $! = ENOSYS; - return undef; - } - # When staging mount points we always mount to $rootdir directly (iow. as if `mp=/`). # This is required since __mount_prepare_rootdir() will return handles to the parent directory # which we use in __bindmount_verify()! @@ -1933,7 +1925,7 @@ sub get_staging_mount_path($) { return $target; } -# Mount /run/pve/mountpoints as tmpfs +# Mount tmpfs for mount point staging and return the path. sub get_staging_tempfs() { # We choose a path in /var/lib/lxc/ here because the lxc-start apparmor profile restricts most # mounts to that. diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm index 2dd57e2..56e1f10 100644 --- a/src/PVE/LXC/Config.pm +++ b/src/PVE/LXC/Config.pm @@ -1415,10 +1415,6 @@ sub vmconfig_hotplug_pending { $hotplug_memory->($conf->{pending}->{memory}, $conf->{pending}->{swap}); } } elsif ($opt =~ m/^mp(\d+)$/) { - if (!PVE::LXC::Tools::can_use_new_mount_api()) { - die "skip\n"; - } - if (exists($conf->{$opt})) { die "skip\n"; # don't try to hotplug over existing mp } diff --git a/src/PVE/LXC/Tools.pm b/src/PVE/LXC/Tools.pm index 1d83768..62cdbc1 100644 --- a/src/PVE/LXC/Tools.pm +++ b/src/PVE/LXC/Tools.pm @@ -4,8 +4,6 @@ package PVE::LXC::Tools; use strict; use warnings; -use Errno qw(ENOSYS); - use PVE::SafeSyslog; # LXC introduced an `lxc.hook.version` property which allows hooks to be executed in different @@ -134,20 +132,4 @@ sub cgroup_do_write($$) { return 1; } -# Check whether the kernel supports the new mount api. This is used in the pre-start hook and in -# the hotplugging code. -my $cached_can_use_new_mount_api = undef; -sub can_use_new_mount_api() { - if (!defined($cached_can_use_new_mount_api)) { - if (PVE::Tools::move_mount(-1, 0, -1, 0, 0)) { - # This should not be possible... - die "kernel behaved unexpectedly: move_mount(-1, NULL, -1, NULL) did not fail!\n"; - } - # On older kernels the syscall doesn't exist and we get ENOSYS. (For newer kernels this call - # will fail with EFAULT instead, since we pass in a NULL pointer as file system name.) - $cached_can_use_new_mount_api = ($! != ENOSYS); - } - return $cached_can_use_new_mount_api; -} - 1; diff --git a/src/lxc-pve-prestart-hook b/src/lxc-pve-prestart-hook index 3bdf7e4..936d0bf 100755 --- a/src/lxc-pve-prestart-hook +++ b/src/lxc-pve-prestart-hook @@ -69,71 +69,52 @@ PVE::LXC::Tools::lxc_hook('pre-start', 'lxc', sub { PVE::Tools::run_command(['umount', '--recursive', $rootdir], outfunc => sub {}, errfunc => sub {}); }; - my $setup_mountpoint; - if (!PVE::LXC::Tools::can_use_new_mount_api()) { - # Legacy mode for old kernels: - $setup_mountpoint = sub { - my ($opt, $mountpoint) = @_; - - my (undef, undef, $dev) = PVE::LXC::mountpoint_mount( - $mountpoint, - $rootdir, - $storage_cfg, - undef, - $rootuid, - $rootgid, - ); - push @$devices, $dev if $dev && $mountpoint->{quota}; - }; - } else { - # With newer kernels we stage mount points and then use move_mount(). - my $rootdir_fd = undef; - $setup_mountpoint = sub { - my ($opt, $mountpoint) = @_; - - my $dir = PVE::LXC::get_staging_mount_path($opt); - my (undef, undef, $dev, $mount_fd) = PVE::LXC::mountpoint_stage( - $mountpoint, - $dir, - $storage_cfg, - undef, - $rootuid, - $rootgid, - ); - - my ($dest_dir, $dest_base_fd); - if ($rootdir_fd) { - # Mount relative to the rootdir fd. - $dest_base_fd = $rootdir_fd; - $dest_dir = './' . $mountpoint->{mp}; - } else { - # Assert that 'rootfs' is the first one: - die "foreach_mount() error\n" if $opt ne 'rootfs'; - - # Mount the rootfs absolutely. - # $rootdir is not controlled by the container, so this is fine. - sysopen($dest_base_fd, '/', O_PATH | O_DIRECTORY) - or die "failed to open '.': $!\n"; - $dest_dir = $rootdir; - } - - PVE::LXC::mountpoint_insert_staged( - $mount_fd, - $dest_base_fd, - $dest_dir, - $opt, - $rootuid, - $rootgid, - ); - - # From now on we mount inside our rootfs: - if (!$rootdir_fd) { - $rootdir_fd = $mount_fd; - } - - push @$devices, $dev if $dev && $mountpoint->{quota}; - }; - } + my $rootdir_fd = undef; + my $setup_mountpoint = sub { + my ($opt, $mountpoint) = @_; + + my $dir = PVE::LXC::get_staging_mount_path($opt); + my (undef, undef, $dev, $mount_fd) = PVE::LXC::mountpoint_stage( + $mountpoint, + $dir, + $storage_cfg, + undef, + $rootuid, + $rootgid, + ); + + my ($dest_dir, $dest_base_fd); + if ($rootdir_fd) { + # Mount relative to the rootdir fd. + $dest_base_fd = $rootdir_fd; + $dest_dir = './' . $mountpoint->{mp}; + } else { + # Assert that 'rootfs' is the first one: + die "foreach_mount() error\n" if $opt ne 'rootfs'; + + # Mount the rootfs absolutely. + # $rootdir is not controlled by the container, so this is fine. + sysopen($dest_base_fd, '/', O_PATH | O_DIRECTORY) + or die "failed to open '.': $!\n"; + $dest_dir = $rootdir; + } + + PVE::LXC::mountpoint_insert_staged( + $mount_fd, + $dest_base_fd, + $dest_dir, + $opt, + $rootuid, + $rootgid, + ); + + # From now on we mount inside our rootfs: + if (!$rootdir_fd) { + $rootdir_fd = $mount_fd; + } + + push @$devices, $dev if $dev && $mountpoint->{quota}; + }; PVE::LXC::Config->foreach_volume($conf, $setup_mountpoint); -- 2.39.5