]> git.proxmox.com Git - pve-common.git/commitdiff
Syscalls/Tools: add renameat2
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 9 Jun 2021 13:18:45 +0000 (15:18 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 15 Jun 2021 12:35:26 +0000 (14:35 +0200)
Mostly for the ability to atomically swap files.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/PVE/Syscall.pm
src/PVE/Tools.pm

index 2d5019f347263a8201db9320ae8cd87145884b0c..10e185d1831fbb566e010fdfa052c0c83f195f29 100644 (file)
@@ -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...
index b4caf5440f26fcbcfccdaaf3e22ba2173bc1f78f..8d6734d2024eb7d9dbbf9e56078f550a557d785c 100644 (file)
@@ -105,6 +105,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) = @_;
 
@@ -1462,6 +1467,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";