* [PATCH v2] xfsprogs: io/copy_range: cover corner case (fd_in == fd_out)
@ 2019-09-03 11:19 Jianhong.Yin
2019-09-03 17:54 ` Eric Sandeen
0 siblings, 1 reply; 3+ messages in thread
From: Jianhong.Yin @ 2019-09-03 11:19 UTC (permalink / raw)
To: linux-xfs, linux-fsdevel
Cc: lsahlber, alexander198961, fengxiaoli0714, dchinner, sandeen,
Jianhong.Yin
Related bug:
copy_file_range return "Invalid argument" when copy in the same file
https://bugzilla.kernel.org/show_bug.cgi?id=202935
if argument of option -f is "-", use current file->fd as fd_in
Usage:
xfs_io -c 'copy_range -f -' some_file
Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
---
io/copy_file_range.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/io/copy_file_range.c b/io/copy_file_range.c
index b7b9fd88..2dde8a31 100644
--- a/io/copy_file_range.c
+++ b/io/copy_file_range.c
@@ -28,6 +28,7 @@ copy_range_help(void)
at position 0\n\
'copy_range -f 2' - copies all bytes from open file 2 into the current open file\n\
at position 0\n\
+ 'copy_range -f -' - copies all bytes from current open file append the current open file\n\
"));
}
@@ -114,11 +115,15 @@ copy_range_f(int argc, char **argv)
}
break;
case 'f':
- src_file_nr = atoi(argv[1]);
- if (src_file_nr < 0 || src_file_nr >= filecount) {
- printf(_("file value %d is out of range (0-%d)\n"),
- src_file_nr, filecount - 1);
- return 0;
+ if (strcmp(argv[1], "-") == 0)
+ src_file_nr = (file - &filetable[0]) / sizeof(fileio_t);
+ else {
+ src_file_nr = atoi(argv[1]);
+ if (src_file_nr < 0 || src_file_nr >= filecount) {
+ printf(_("file value %d is out of range (0-%d)\n"),
+ src_file_nr, filecount - 1);
+ return 0;
+ }
}
/* Expect no src_path arg */
src_path_arg = 0;
@@ -147,10 +152,14 @@ copy_range_f(int argc, char **argv)
}
len = sz;
- ret = copy_dst_truncate();
- if (ret < 0) {
- ret = 1;
- goto out;
+ if (fd != file->fd) {
+ ret = copy_dst_truncate();
+ if (ret < 0) {
+ ret = 1;
+ goto out;
+ }
+ } else {
+ dst = sz;
}
}
--
2.17.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] xfsprogs: io/copy_range: cover corner case (fd_in == fd_out)
2019-09-03 11:19 [PATCH v2] xfsprogs: io/copy_range: cover corner case (fd_in == fd_out) Jianhong.Yin
@ 2019-09-03 17:54 ` Eric Sandeen
2019-09-04 3:24 ` 尹剑虹
0 siblings, 1 reply; 3+ messages in thread
From: Eric Sandeen @ 2019-09-03 17:54 UTC (permalink / raw)
To: Jianhong.Yin, linux-xfs, linux-fsdevel
Cc: lsahlber, alexander198961, fengxiaoli0714, dchinner
On 9/3/19 6:19 AM, Jianhong.Yin wrote:
> Related bug:
> copy_file_range return "Invalid argument" when copy in the same file
> https://bugzilla.kernel.org/show_bug.cgi?id=202935
that's a CIFS bug though, not related to how xfs_io operates, correct?
What is the failing xfs_io case? Because this seems to work fine here:
# fallocate -l 128m testfile
# strace -eopen,copy_file_range xfs_io -c "copy_range -s 1m -d 8m -l 2m testfile" testfile
...
open("testfile", O_RDWR) = 3
...
open("testfile", O_RDONLY) = 4
copy_file_range(4, [1048576], 3, [8388608], 2097152, 0) = 2097152
+++ exited with 0 +++
this works too:
# strace -eopen,copy_file_range xfs_io -c "copy_range testfile" testfile
...
open("testfile", O_RDWR) = 3
...
open("testfile", O_RDONLY) = 4
copy_file_range(4, [0], 3, [0], 134217728, 0) = 0
+++ exited with 0 +++
so can you help me understand what bug you're fixing?
-Eric
> if argument of option -f is "-", use current file->fd as fd_in
>
> Usage:
> xfs_io -c 'copy_range -f -' some_file
>
> Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
> ---
> io/copy_file_range.c | 27 ++++++++++++++++++---------
> 1 file changed, 18 insertions(+), 9 deletions(-)
>
> diff --git a/io/copy_file_range.c b/io/copy_file_range.c
> index b7b9fd88..2dde8a31 100644
> --- a/io/copy_file_range.c
> +++ b/io/copy_file_range.c
> @@ -28,6 +28,7 @@ copy_range_help(void)
> at position 0\n\
> 'copy_range -f 2' - copies all bytes from open file 2 into the current open file\n\
> at position 0\n\
> + 'copy_range -f -' - copies all bytes from current open file append the current open file\n\
> "));
> }
>
> @@ -114,11 +115,15 @@ copy_range_f(int argc, char **argv)
> }
> break;
> case 'f':
> - src_file_nr = atoi(argv[1]);
> - if (src_file_nr < 0 || src_file_nr >= filecount) {
> - printf(_("file value %d is out of range (0-%d)\n"),
> - src_file_nr, filecount - 1);
> - return 0;
> + if (strcmp(argv[1], "-") == 0)
> + src_file_nr = (file - &filetable[0]) / sizeof(fileio_t);
> + else {
> + src_file_nr = atoi(argv[1]);
> + if (src_file_nr < 0 || src_file_nr >= filecount) {
> + printf(_("file value %d is out of range (0-%d)\n"),
> + src_file_nr, filecount - 1);
> + return 0;
> + }
> }
> /* Expect no src_path arg */
> src_path_arg = 0;
> @@ -147,10 +152,14 @@ copy_range_f(int argc, char **argv)
> }
> len = sz;
>
> - ret = copy_dst_truncate();
> - if (ret < 0) {
> - ret = 1;
> - goto out;
> + if (fd != file->fd) {
> + ret = copy_dst_truncate();
> + if (ret < 0) {
> + ret = 1;
> + goto out;
> + }
> + } else {
> + dst = sz;
> }
> }
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re:Re: [PATCH v2] xfsprogs: io/copy_range: cover corner case (fd_in == fd_out)
2019-09-03 17:54 ` Eric Sandeen
@ 2019-09-04 3:24 ` 尹剑虹
0 siblings, 0 replies; 3+ messages in thread
From: 尹剑虹 @ 2019-09-04 3:24 UTC (permalink / raw)
To: Eric Sandeen
Cc: linux-xfs, linux-fsdevel, lsahlber, alexander198961,
fengxiaoli0714, dchinner
At 2019-09-04 01:54:21, "Eric Sandeen" <sandeen@redhat.com> wrote:
>On 9/3/19 6:19 AM, Jianhong.Yin wrote:
>> Related bug:
>> copy_file_range return "Invalid argument" when copy in the same file
>> https://bugzilla.kernel.org/show_bug.cgi?id=202935
>
>that's a CIFS bug though, not related to how xfs_io operates, correct?
Hi Eric
that's right, I thought that the condition to reproduce the bug must be fd_in == fd_out.
but now I know that's not correct. src_file == dst_file is enough.
but there's a little problem, if exec follow command , will truncate src_file
# xfs_io -c "copy_range testfile" testfile
it's not expected, will send new patch to fix it. if you agree
Jianhong
>
>What is the failing xfs_io case? Because this seems to work fine here:
>
># fallocate -l 128m testfile
># strace -eopen,copy_file_range xfs_io -c "copy_range -s 1m -d 8m -l 2m testfile" testfile
>...
>open("testfile", O_RDWR) = 3
>...
>open("testfile", O_RDONLY) = 4
>copy_file_range(4, [1048576], 3, [8388608], 2097152, 0) = 2097152
>+++ exited with 0 +++
>
>this works too:
>
># strace -eopen,copy_file_range xfs_io -c "copy_range testfile" testfile
>...
>open("testfile", O_RDWR) = 3
>...
>open("testfile", O_RDONLY) = 4
>copy_file_range(4, [0], 3, [0], 134217728, 0) = 0
>+++ exited with 0 +++
>
>so can you help me understand what bug you're fixing?
>
>-Eric
>
>> if argument of option -f is "-", use current file->fd as fd_in
>>
>> Usage:
>> xfs_io -c 'copy_range -f -' some_file
>>
>> Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
>> ---
>> io/copy_file_range.c | 27 ++++++++++++++++++---------
>> 1 file changed, 18 insertions(+), 9 deletions(-)
>>
>> diff --git a/io/copy_file_range.c b/io/copy_file_range.c
>> index b7b9fd88..2dde8a31 100644
>> --- a/io/copy_file_range.c
>> +++ b/io/copy_file_range.c
>> @@ -28,6 +28,7 @@ copy_range_help(void)
>> at position 0\n\
>> 'copy_range -f 2' - copies all bytes from open file 2 into the current open file\n\
>> at position 0\n\
>> + 'copy_range -f -' - copies all bytes from current open file append the current open file\n\
>> "));
>> }
>>
>> @@ -114,11 +115,15 @@ copy_range_f(int argc, char **argv)
>> }
>> break;
>> case 'f':
>> - src_file_nr = atoi(argv[1]);
>> - if (src_file_nr < 0 || src_file_nr >= filecount) {
>> - printf(_("file value %d is out of range (0-%d)\n"),
>> - src_file_nr, filecount - 1);
>> - return 0;
>> + if (strcmp(argv[1], "-") == 0)
>> + src_file_nr = (file - &filetable[0]) / sizeof(fileio_t);
>> + else {
>> + src_file_nr = atoi(argv[1]);
>> + if (src_file_nr < 0 || src_file_nr >= filecount) {
>> + printf(_("file value %d is out of range (0-%d)\n"),
>> + src_file_nr, filecount - 1);
>> + return 0;
>> + }
>> }
>> /* Expect no src_path arg */
>> src_path_arg = 0;
>> @@ -147,10 +152,14 @@ copy_range_f(int argc, char **argv)
>> }
>> len = sz;
>>
>> - ret = copy_dst_truncate();
>> - if (ret < 0) {
>> - ret = 1;
>> - goto out;
>> + if (fd != file->fd) {
>> + ret = copy_dst_truncate();
>> + if (ret < 0) {
>> + ret = 1;
>> + goto out;
>> + }
>> + } else {
>> + dst = sz;
>> }
>> }
>>
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-09-04 3:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-03 11:19 [PATCH v2] xfsprogs: io/copy_range: cover corner case (fd_in == fd_out) Jianhong.Yin
2019-09-03 17:54 ` Eric Sandeen
2019-09-04 3:24 ` 尹剑虹
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).