From: Zorro Lang <zlang@redhat.com>
To: "Jianhong.Yin" <yin-jianhong@163.com>
Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
lsahlber@redhat.com, alexander198961@gmail.com,
fengxiaoli0714@gmail.com, dchinner@redhat.com,
sandeen@redhat.com
Subject: Re: [PATCH] xfsprogs: io/copy_range: cover corner case (fd_in == fd_out)
Date: Tue, 3 Sep 2019 21:19:29 +0800 [thread overview]
Message-ID: <20190903131928.GV7239@dhcp-12-102.nay.redhat.com> (raw)
In-Reply-To: <20190903115943.GU7239@dhcp-12-102.nay.redhat.com>
On Tue, Sep 03, 2019 at 07:59:43PM +0800, Zorro Lang wrote:
> On Tue, Sep 03, 2019 at 06:56:32PM +0800, 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
> >
> > 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>
> > ---
>
> Hi,
>
> Actually, I'm thinking about if you need same 'fd' or same file path?
> If you just need same file path, I think
>
> # xfs_io -c "copy_range testfile" testfile
>
> already can help that. The only one problem stop you doing that is
> "copy_dst_truncate()".
>
> If all above I suppose is right, we can turn to talk about if that
> copy_dst_truncate() is necessary, or how can we skip it.
I just checked, the copy_dst_truncate() is only called when:
if (src == 0 && dst == 0 && len == 0) {
So if you can give your reproducer a "length"(or offset), likes:
# xfs_io -c "copy_range -l 64k testfile" testfile
You can avoid the copy_dst_truncate() too.
Is that helpful?
Thanks,
Zorro
>
> Thanks,
> Zorro
>
> > 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], "-"))
> > + 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
> >
next prev parent reply other threads:[~2019-09-03 13:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-03 10:56 [PATCH] xfsprogs: io/copy_range: cover corner case (fd_in == fd_out) Jianhong.Yin
2019-09-03 11:59 ` Zorro Lang
2019-09-03 13:19 ` Zorro Lang [this message]
[not found] ` <7689497e.d24e.16cf7f750d6.Coremail.yin-jianhong@163.com>
2019-09-04 2:03 ` Zorro Lang
2019-09-04 3:30 ` 尹剑虹
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=20190903131928.GV7239@dhcp-12-102.nay.redhat.com \
--to=zlang@redhat.com \
--cc=alexander198961@gmail.com \
--cc=dchinner@redhat.com \
--cc=fengxiaoli0714@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=lsahlber@redhat.com \
--cc=sandeen@redhat.com \
--cc=yin-jianhong@163.com \
/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;
as well as URLs for NNTP newsgroup(s).