From 40cd2e8941bebd8c0e56c1eed3b0435d6f3207b1 Mon Sep 17 00:00:00 2001 From: Stoiko Ivanov Date: Fri, 6 Nov 2020 15:19:41 +0100 Subject: [PATCH] add fsfreeze helper: fsfreeze_mountpoint issues the same ioctls as fsfreeze(8) on the provided directory (the $thaw parameter deciding between '--freeze' and '--unfreeze') This is used for container backups on RBD, where snapshots on containers, which are heavy on IO, are not mountable readonly, because the ext4 is not consistent. Needed to fix #2991 and #2528. The ioctl numbers were found via strace -X verbose (and verified with the kernel documentation). Signed-off-by: Stoiko Ivanov --- src/PVE/LXC/Config.pm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm index 49f599b..0528d51 100644 --- a/src/PVE/LXC/Config.pm +++ b/src/PVE/LXC/Config.pm @@ -13,6 +13,9 @@ use PVE::Tools; use base qw(PVE::AbstractConfig); +use constant {FIFREEZE => 0xc0045877, + FITHAW => 0xc0045878}; + my $nodename = PVE::INotify::nodename(); my $lock_handles = {}; my $lockdir = "/run/lock/lxc"; @@ -109,6 +112,22 @@ sub __snapshot_check_freeze_needed { return ($ret, $ret); } +# implements similar functionality to fsfreeze(8) +sub fsfreeze_mountpoint { + my ($path, $thaw) = @_; + + my $op = $thaw ? 'thaw' : 'freeze'; + my $ioctl = $thaw ? FITHAW : FIFREEZE; + + sysopen my $fd, $path, O_RDONLY or die "failed to open $path: $!\n"; + my $ioctl_err; + if (!ioctl($fd, $ioctl, 0)) { + $ioctl_err = "$!"; + } + close($fd); + die "fs$op '$path' failed - $ioctl_err\n" if defined $ioctl_err; +} + sub __snapshot_freeze { my ($class, $vmid, $unfreeze) = @_; -- 2.39.2