linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* question about copy_file_range() between btrfs filesystem.
@ 2023-01-11  8:45 Wang Yugui
  2023-01-20 18:49 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Wang Yugui @ 2023-01-11  8:45 UTC (permalink / raw)
  To: linux-btrfs

[-- Attachment #1: Type: text/plain, Size: 576 bytes --]

Hi,

question about copy_file_range() between btrfs filesystem.

test progam:
	attachment file(copy directly from 'man copy_file_range')

test result:
kernel: 6.1.4
1)in/out files in single btrfs subvol: OK

2)in/out files in single btrfs filesystem, but different subvols: OK

3)in/out files in different btrfs filesystems: ERROR Invalid cross-device link
   but as a compare, in/out files in different nfs filesystems(in same server): OK.
Question: 
Should we support copy_file_range() between btrfs filesystem?

Best Regards
Wang Yugui (wangyugui@e16-tech.com)
2023/01/11


[-- Attachment #2: copy_file_range.c --]
[-- Type: application/octet-stream, Size: 1570 bytes --]



#define _GNU_SOURCE
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <unistd.h>

/* On versions of glibc before 2.27, we must invoke copy_file_range()
       using syscall(2) */
static loff_t
copy_file_range(int fd_in, loff_t *off_in, int fd_out,
                     loff_t *off_out, size_t len, unsigned int flags)
{
       return syscall(__NR_copy_file_range, fd_in, off_in, fd_out,
                     off_out, len, flags);
}

int
main(int argc, char **argv)
{
       int fd_in, fd_out;
       struct stat stat;
       loff_t len, ret;

       if (argc != 3) {
              fprintf(stderr, "Usage: %s <source> <destination>\n", argv[0]);
              exit(EXIT_FAILURE);
       }

       fd_in = open(argv[1], O_RDONLY);
       if (fd_in == -1) {
              perror("open (argv[1])");
              exit(EXIT_FAILURE);
       }

       if (fstat(fd_in, &stat) == -1) {
              perror("fstat");
              exit(EXIT_FAILURE);
       }

       len = stat.st_size;

       fd_out = open(argv[2], O_CREAT | O_WRONLY | O_TRUNC, 0644);
       if (fd_out == -1) {
              perror("open (argv[2])");
              exit(EXIT_FAILURE);
       }

       do {
              ret = copy_file_range(fd_in, NULL, fd_out, NULL, len, 0);
              if (ret == -1) {
              perror("copy_file_range");
              exit(EXIT_FAILURE);
              }

              len -= ret;
       } while (len > 0 && ret > 0);

       close(fd_in);
       close(fd_out);
       exit(EXIT_SUCCESS);
}


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: question about copy_file_range() between btrfs filesystem.
  2023-01-11  8:45 question about copy_file_range() between btrfs filesystem Wang Yugui
@ 2023-01-20 18:49 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2023-01-20 18:49 UTC (permalink / raw)
  To: Wang Yugui; +Cc: linux-btrfs

On Wed, Jan 11, 2023 at 04:45:14PM +0800, Wang Yugui wrote:
> Hi,
> 
> question about copy_file_range() between btrfs filesystem.
> 
> test progam:
> 	attachment file(copy directly from 'man copy_file_range')
> 
> test result:
> kernel: 6.1.4
> 1)in/out files in single btrfs subvol: OK
> 
> 2)in/out files in single btrfs filesystem, but different subvols: OK
> 
> 3)in/out files in different btrfs filesystems: ERROR Invalid cross-device link
>    but as a compare, in/out files in different nfs filesystems(in same server): OK.
> Question: 
> Should we support copy_file_range() between btrfs filesystem?

I think NFS has some fallback if the source and target files are not on
the same underlying filesystem. There's and article about the semantics
of copy_file_range https://lwn.net/Articles/846403/ .

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-20 18:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-11  8:45 question about copy_file_range() between btrfs filesystem Wang Yugui
2023-01-20 18:49 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).