From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: "Jianhong.Yin" <yin-jianhong@163.com>
Cc: linux-xfs@vger.kernel.org, jiyin@redhat.com
Subject: Re: [PATCH] xfsprogs: copy_range don't truncate dstfile if same with srcfile
Date: Wed, 4 Sep 2019 10:27:36 -0700 [thread overview]
Message-ID: <20190904172736.GD5354@magnolia> (raw)
In-Reply-To: <20190904063222.21253-1-yin-jianhong@163.com>
On Wed, Sep 04, 2019 at 02:32:22PM +0800, Jianhong.Yin wrote:
> now if we do copy_range in same file without any extra option
> will truncate the file, and not any document indicate this default
> action. that's risky to users.
>
> '''
> $ LANG=C ll testfile
> -rw-rw-r--. 1 yjh yjh 4054 Sep 4 14:22 testfile
> $ ./xfs_io -c 'copy_range testfile' testfile
> $ LANG=C ll testfile
> -rw-rw-r--. 1 yjh yjh 4054 Sep 4 14:23 testfile
> '''
>
> Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
> ---
> io/copy_file_range.c | 23 +++++++++++++++++++----
> 1 file changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/io/copy_file_range.c b/io/copy_file_range.c
> index b7b9fd88..487041c0 100644
> --- a/io/copy_file_range.c
> +++ b/io/copy_file_range.c
> @@ -75,6 +75,19 @@ copy_dst_truncate(void)
> return ret;
> }
>
> +int is_same_file(int fd1, int fd2) {
> + struct stat stat1, stat2;
> + if (fstat(fd1, &stat1) < 0) {
> + perror("fstat");
> + return -1;
> + }
> + if (fstat(fd2, &stat2) < 0) {
> + perror("fstat");
> + return -1;
> + }
> + return (stat1.st_dev == stat2.st_dev) && (stat1.st_ino == stat2.st_ino);
> +}
> +
> static int
> copy_range_f(int argc, char **argv)
> {
> @@ -147,10 +160,12 @@ copy_range_f(int argc, char **argv)
> }
> len = sz;
>
> - ret = copy_dst_truncate();
> - if (ret < 0) {
> - ret = 1;
> - goto out;
> + if (!is_same_file(fd, file->fd)) {
Uggggh, why does xfs_io copy_range have this weird behavior? It should
be a simple wrapper for copy_file_range (the syscall) and nothing else.
The code patch looks fine for solving this edge case, but we really
shouldn't have this "extra" functionality in a debugging tool that
should be athin wrapper around the syscall for xfstests purposes.
--D
> + ret = copy_dst_truncate();
> + if (ret < 0) {
> + ret = 1;
> + goto out;
> + }
> }
> }
>
> --
> 2.17.2
>
next prev parent reply other threads:[~2019-09-04 17:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-04 6:32 [PATCH] xfsprogs: copy_range don't truncate dstfile if same with srcfile Jianhong.Yin
2019-09-04 17:27 ` Darrick J. Wong [this message]
2019-09-04 23:34 ` Jianhong Yin
2019-09-05 5:02 ` Zorro Lang
2019-09-05 5:23 ` Jianhong Yin
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=20190904172736.GD5354@magnolia \
--to=darrick.wong@oracle.com \
--cc=jiyin@redhat.com \
--cc=linux-xfs@vger.kernel.org \
--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