From: Wang Yugui <wangyugui@e16-tech.com>
To: linux-btrfs@vger.kernel.org
Subject: question about copy_file_range() between btrfs filesystem.
Date: Wed, 11 Jan 2023 16:45:14 +0800 [thread overview]
Message-ID: <20230111164513.85BA.409509F4@e16-tech.com> (raw)
[-- 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);
}
next reply other threads:[~2023-01-11 8:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-11 8:45 Wang Yugui [this message]
2023-01-20 18:49 ` question about copy_file_range() between btrfs filesystem David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230111164513.85BA.409509F4@e16-tech.com \
--to=wangyugui@e16-tech.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox