From: Wolfgang Bumiller Date: Thu, 11 Feb 2016 08:26:29 +0000 (+0100) Subject: added syncfs syscall and sync_mountpoint helper X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=44acb12c2714f7289e60ad3b9c5e0a36ee4dab59 added syncfs syscall and sync_mountpoint helper --- diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 60ba8aa..6303d20 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -75,6 +75,8 @@ use constant {CLONE_NEWNS => 0x00020000, CLONE_NEWPID => 0x20000000, CLONE_NEWNET => 0x40000000}; +use constant O_PATH => 0x10000000; + sub run_with_timeout { my ($timeout, $code, @param) = @_; @@ -1195,4 +1197,17 @@ sub setns($$) { return 0 == syscall(308, $fileno, $nstype); } +sub syncfs($) { + my ($fileno) = @_; + return 0 == syscall(306, $fileno); +} + +sub sync_mountpoint { + my ($path) = @_; + sysopen my $fd, $path, O_PATH or die "failed to open $path: $!\n"; + my $result = syncfs(fileno($fd)); + close($fd); + return $result; +} + 1;