[pve-devel] applied: Re: [PATCH common 1/1] sync_mountpoint: open path so that sync works

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Sep 18 12:01:03 CEST 2020


On 9/17/20 9:17 PM, Stoiko Ivanov wrote:
> 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 at proxmox.com>
> ---
>  src/PVE/Tools.pm | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
>

applied, thanks! Followed up with a change in error propagation, after checking
the call sites (which is only one).

diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 7eb1197..7d33683 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -1434,9 +1434,12 @@ sub fsync($) {
 sub sync_mountpoint {
     my ($path) = @_;
     sysopen my $fd, $path, O_RDONLY|O_CLOEXEC or die "failed to open $path: $!\n";
-    my $result = syncfs(fileno($fd));
+    my $syncfs_err;
+    if (!syncfs(fileno($fd))) {
+       $syncfs_err = "$!";
+    }
     close($fd);
-    return $result;
+    die "syncfs '$path' failed - $syncfs_err\n" if defined $syncfs_err;
 }
 
 # support sending multi-part mail messages with a text and or a HTML part





More information about the pve-devel mailing list