]> git.proxmox.com Git - pve-common.git/commitdiff
sync_mountpoint: open path so that sync works
authorStoiko Ivanov <s.ivanov@proxmox.com>
Thu, 17 Sep 2020 19:17:00 +0000 (21:17 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Sep 2020 09:53:50 +0000 (11:53 +0200)
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 <s.ivanov@proxmox.com>
src/PVE/Tools.pm

index e04b504617388fdc5b7f4b8b086df48af7d2a141..7eb1197e2b4090e6a6de765a0024c93b8693dd21 100644 (file)
@@ -94,6 +94,7 @@ use constant {CLONE_NEWNS   => 0x00020000,
               CLONE_NEWNET  => 0x40000000};
 
 use constant {O_PATH    => 0x00200000,
               CLONE_NEWNET  => 0x40000000};
 
 use constant {O_PATH    => 0x00200000,
+              O_CLOEXEC => 0x00080000,
               O_TMPFILE => 0x00410000}; # This includes O_DIRECTORY
 
 use constant {AT_EMPTY_PATH => 0x1000,
               O_TMPFILE => 0x00410000}; # This includes O_DIRECTORY
 
 use constant {AT_EMPTY_PATH => 0x1000,
@@ -1432,7 +1433,7 @@ sub fsync($) {
 
 sub sync_mountpoint {
     my ($path) = @_;
 
 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;
     my $result = syncfs(fileno($fd));
     close($fd);
     return $result;