Uploaded image for project: 'Lustre'
  1. Lustre
  2. LU-11557

Implement renameat2() with RENAME_EXCHANGE

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • Lustre 2.10.5, Lustre 2.12.2
    • CentOS 7
    • 9223372036854775807

      It would be nice to have support for renameat2()'s Linux specific flags RENAME_EXCHANGE, which improves rename safety and efficiency of tools like mv that always try to use renameat2(..., RENAME_EXCHANGE) first.

      For example, the code snippet below works on ext4 and xfs but not on Lustre:

      #include <errno.h>
      #include <fcntl.h>
      #include <stdio.h>
      #include <unistd.h>
      #include <linux/fs.h>
      #include <sys/syscall.h>
      
      int main(int argc, char *argv[])
      {
        int ret;
      
        ret = syscall(SYS_renameat2, AT_FDCWD, argv[1], AT_FDCWD, argv[2], RENAME_EXCHANGE);
        if (ret != 0)
          fprintf(stderr, "renameat2(%s, %s) ret=%d, errno=%d\n", argv[1], argv[2], ret, errno);
        return ret;
      }
      
      $ renameat2 file1 file2
      renameat2(file1, file2) ret=-1 errno=22 
      

       

      Example on ext4:

      $ echo file1 > file1
      $ echo file2 > file2
      $ ./renameat2 file1 file2
      renameat2 ret=0 errno=0
      $ cat file1
      file2
      $ cat file2
      file1
      

       

      Thanks!
      Stephane

       

            timday Tim Day
            sthiell Stephane Thiell
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated: