[pve-devel] [PATCH common] Syscalls/Tools: add renameat2
Wolfgang Bumiller
w.bumiller at proxmox.com
Wed Jun 9 15:18:45 CEST 2021
Mostly for the ability to atomically swap files.
Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
src/PVE/Syscall.pm | 1 +
src/PVE/Tools.pm | 10 ++++++++++
2 files changed, 11 insertions(+)
diff --git a/src/PVE/Syscall.pm b/src/PVE/Syscall.pm
index 2d5019f..10e185d 100644
--- a/src/PVE/Syscall.pm
+++ b/src/PVE/Syscall.pm
@@ -17,6 +17,7 @@ BEGIN {
setresuid => &SYS_setresuid,
fchownat => &SYS_fchownat,
mount => &SYS_mount,
+ renameat2 => &SYS_renameat2,
# These use asm-generic, so they're the same across (sane) architectures. We use numbers
# since they're not in perl's syscall.ph yet...
diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 16ae3d2..63bf075 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -104,6 +104,11 @@ use constant {O_PATH => 0x00200000,
use constant {AT_EMPTY_PATH => 0x1000,
AT_FDCWD => -100};
+# from <linux/fs.h>
+use constant {RENAME_NOREPLACE => (1 << 0),
+ RENAME_EXCHANGE => (1 << 1),
+ RENAME_WHITEOUT => (1 << 2)};
+
sub run_with_timeout {
my ($timeout, $code, @param) = @_;
@@ -1461,6 +1466,11 @@ sub fsync($) {
return 0 == syscall(PVE::Syscall::fsync, $fileno);
}
+sub renameat2($$$$$) {
+ my ($olddirfd, $oldpath, $newdirfd, $newpath, $flags) = @_;
+ return 0 == syscall(PVE::Syscall::renameat2, $olddirfd, $oldpath, $newdirfd, $newpath, $flags);
+}
+
sub sync_mountpoint {
my ($path) = @_;
sysopen my $fd, $path, O_RDONLY|O_CLOEXEC or die "failed to open $path: $!\n";
--
2.30.2
More information about the pve-devel
mailing list