From b260d4e320a5e2961247de9f3db7c60293627936 Mon Sep 17 00:00:00 2001 From: Stoiko Ivanov Date: Thu, 17 Sep 2020 21:17:00 +0200 Subject: [PATCH] sync_mountpoint: open path so that sync works sync_mountpoint takes a path, gets an open filedescriptor and calls syncfs(2) on it. by opening with O_PATH the syncfs call fails with EBADF (see open(2)). found by running: ``` pkill -f 'pvedaemon worker'; strace -yyttT -s 512 -o /tmp/trace -fp $(pgrep -f pvedaemon$) ``` Signed-off-by: Stoiko Ivanov --- src/PVE/Tools.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index e04b504..7eb1197 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -94,6 +94,7 @@ use constant {CLONE_NEWNS => 0x00020000, CLONE_NEWNET => 0x40000000}; use constant {O_PATH => 0x00200000, + O_CLOEXEC => 0x00080000, O_TMPFILE => 0x00410000}; # This includes O_DIRECTORY use constant {AT_EMPTY_PATH => 0x1000, @@ -1432,7 +1433,7 @@ sub fsync($) { sub sync_mountpoint { my ($path) = @_; - sysopen my $fd, $path, O_PATH or die "failed to open $path: $!\n"; + sysopen my $fd, $path, O_RDONLY|O_CLOEXEC or die "failed to open $path: $!\n"; my $result = syncfs(fileno($fd)); close($fd); return $result; -- 2.39.2