linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] xfsprogs: copy_range don't truncate dstfile
@ 2019-09-05  5:31 Jianhong.Yin
  2019-09-05  5:31 ` [PATCH 2/2] xfsprogs: copy_range: let = (src_size - src_offset) if len omitted Jianhong.Yin
  0 siblings, 1 reply; 7+ messages in thread
From: Jianhong.Yin @ 2019-09-05  5:31 UTC (permalink / raw)
  To: linux-xfs; +Cc: jiyin, Jianhong.Yin

now if we do copy_range from srcfile to dstfile without any option
will truncate the dstfile, and not any document indicate this default
action. that's unexpected and confuse people.

'''
$ ./xfs_io -f -c 'copy_range copy_file_range.c'  testfile
$ ll testfile
-rw-rw-r--. 1 yjh yjh 3534 Sep  5 07:15 testfile
$ ./xfs_io -c 'copy_range testfile'  testfile
$ ll testfile
-rw-rw-r--. 1 yjh yjh 3534 Sep  5 07:16 testfile
$ ./xfs_io -c 'copy_range testfile -l 3534 -d 3534' testfile
$ ll testfile
-rw-rw-r--. 1 yjh yjh 7068 Sep  5 07:17 testfile
$ ./xfs_io -c 'copy_range copy_file_range.c'  testfile
$ ll testfile
-rw-rw-r--. 1 yjh yjh 7068 Sep  5 07:18 testfile
$ cmp -n 3534 copy_file_range.c testfile
$ cmp -i 0:3534 copy_file_range.c testfile
'''

Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
---
 io/copy_file_range.c | 15 ---------------
 1 file changed, 15 deletions(-)

diff --git a/io/copy_file_range.c b/io/copy_file_range.c
index b7b9fd88..283f5094 100644
--- a/io/copy_file_range.c
+++ b/io/copy_file_range.c
@@ -66,15 +66,6 @@ copy_src_filesize(int fd)
 	return st.st_size;
 }
 
-static int
-copy_dst_truncate(void)
-{
-	int ret = ftruncate(file->fd, 0);
-	if (ret < 0)
-		perror("ftruncate");
-	return ret;
-}
-
 static int
 copy_range_f(int argc, char **argv)
 {
@@ -146,12 +137,6 @@ copy_range_f(int argc, char **argv)
 			goto out;
 		}
 		len = sz;
-
-		ret = copy_dst_truncate();
-		if (ret < 0) {
-			ret = 1;
-			goto out;
-		}
 	}
 
 	ret = copy_file_range_cmd(fd, &src, &dst, len);
-- 
2.21.0


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

* [PATCH 2/2] xfsprogs: copy_range: let = (src_size - src_offset) if len omitted
  2019-09-05  5:31 [PATCH 1/2] xfsprogs: copy_range don't truncate dstfile Jianhong.Yin
@ 2019-09-05  5:31 ` Jianhong.Yin
  2019-09-05  6:01   ` Zorro Lang
  0 siblings, 1 reply; 7+ messages in thread
From: Jianhong.Yin @ 2019-09-05  5:31 UTC (permalink / raw)
  To: linux-xfs; +Cc: jiyin, Jianhong.Yin

add update man page.

Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
---
 io/copy_file_range.c | 7 +++++--
 man/man8/xfs_io.8    | 9 +++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/io/copy_file_range.c b/io/copy_file_range.c
index 283f5094..02d50e53 100644
--- a/io/copy_file_range.c
+++ b/io/copy_file_range.c
@@ -72,6 +72,7 @@ copy_range_f(int argc, char **argv)
 	long long src = 0;
 	long long dst = 0;
 	size_t len = 0;
+	int len_ommited = 1;
 	int opt;
 	int ret;
 	int fd;
@@ -103,6 +104,7 @@ copy_range_f(int argc, char **argv)
 				printf(_("invalid length -- %s\n"), optarg);
 				return 0;
 			}
+			len_ommited = 0;
 			break;
 		case 'f':
 			src_file_nr = atoi(argv[1]);
@@ -128,7 +130,7 @@ copy_range_f(int argc, char **argv)
 		fd = filetable[src_file_nr].fd;
 	}
 
-	if (src == 0 && dst == 0 && len == 0) {
+	if (len_ommited) {
 		off64_t	sz;
 
 		sz = copy_src_filesize(fd);
@@ -136,7 +138,8 @@ copy_range_f(int argc, char **argv)
 			ret = 1;
 			goto out;
 		}
-		len = sz;
+		if (sz > src)
+			len = sz - src;
 	}
 
 	ret = copy_file_range_cmd(fd, &src, &dst, len);
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index 6e064bdd..f5f1c4fc 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -669,13 +669,10 @@ The source must be specified either by path
 or as another open file
 .RB ( \-f ).
 If
-.I src_file
-.IR src_offset ,
-.IR dst_offset ,
-and
 .I length
-are omitted the contents of src_file will be copied to the beginning of the
-open file, overwriting any data already there.
+is omitted will use
+.I src_file 
+(file size - src_offset) instead.
 .RS 1.0i
 .PD 0
 .TP 0.4i
-- 
2.21.0


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

* Re: [PATCH 2/2] xfsprogs: copy_range: let = (src_size - src_offset) if len omitted
  2019-09-05  5:31 ` [PATCH 2/2] xfsprogs: copy_range: let = (src_size - src_offset) if len omitted Jianhong.Yin
@ 2019-09-05  6:01   ` Zorro Lang
  2019-09-05  6:04     ` Jianhong Yin
  0 siblings, 1 reply; 7+ messages in thread
From: Zorro Lang @ 2019-09-05  6:01 UTC (permalink / raw)
  To: Jianhong.Yin; +Cc: linux-xfs, jiyin

On Thu, Sep 05, 2019 at 01:31:52PM +0800, Jianhong.Yin wrote:
> add update man page.
> 
> Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
> ---

I think these can be in one patch, but anyway...

>  io/copy_file_range.c | 7 +++++--
>  man/man8/xfs_io.8    | 9 +++------
>  2 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/io/copy_file_range.c b/io/copy_file_range.c
> index 283f5094..02d50e53 100644
> --- a/io/copy_file_range.c
> +++ b/io/copy_file_range.c
> @@ -72,6 +72,7 @@ copy_range_f(int argc, char **argv)
>  	long long src = 0;
>  	long long dst = 0;
>  	size_t len = 0;
> +	int len_ommited = 1;
>  	int opt;
>  	int ret;
>  	int fd;
> @@ -103,6 +104,7 @@ copy_range_f(int argc, char **argv)
>  				printf(_("invalid length -- %s\n"), optarg);
>  				return 0;
>  			}
> +			len_ommited = 0;
>  			break;
>  		case 'f':
>  			src_file_nr = atoi(argv[1]);
> @@ -128,7 +130,7 @@ copy_range_f(int argc, char **argv)
>  		fd = filetable[src_file_nr].fd;
>  	}
>  
> -	if (src == 0 && dst == 0 && len == 0) {
> +	if (len_ommited) {
>  		off64_t	sz;
>  
>  		sz = copy_src_filesize(fd);
> @@ -136,7 +138,8 @@ copy_range_f(int argc, char **argv)
>  			ret = 1;
>  			goto out;
>  		}
> -		len = sz;
> +		if (sz > src)
> +			len = sz - src;

What about file size < offset?

Maybe we can do like this?:

    sz = copy_src_filesize(fd);
    if (sz < 0 || (unsigned long long)sz > SIZE_MAX || sz < src) {
        ret = 1;
        goto out;
    }
    len = sz - src;

Thanks,
Zorro

>  	}
>  
>  	ret = copy_file_range_cmd(fd, &src, &dst, len);
> diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
> index 6e064bdd..f5f1c4fc 100644
> --- a/man/man8/xfs_io.8
> +++ b/man/man8/xfs_io.8
> @@ -669,13 +669,10 @@ The source must be specified either by path
>  or as another open file
>  .RB ( \-f ).
>  If
> -.I src_file
> -.IR src_offset ,
> -.IR dst_offset ,
> -and
>  .I length
> -are omitted the contents of src_file will be copied to the beginning of the
> -open file, overwriting any data already there.
> +is omitted will use
> +.I src_file 
> +(file size - src_offset) instead.
>  .RS 1.0i
>  .PD 0
>  .TP 0.4i
> -- 
> 2.21.0
> 

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

* Re: [PATCH 2/2] xfsprogs: copy_range: let = (src_size - src_offset) if len omitted
  2019-09-05  6:01   ` Zorro Lang
@ 2019-09-05  6:04     ` Jianhong Yin
  2019-09-05  8:13       ` Zorro Lang
  0 siblings, 1 reply; 7+ messages in thread
From: Jianhong Yin @ 2019-09-05  6:04 UTC (permalink / raw)
  To: Zorro Lang; +Cc: Jianhong.Yin, linux-xfs



----- 原始邮件 -----
> 发件人: "Zorro Lang" <zlang@redhat.com>
> 收件人: "Jianhong.Yin" <yin-jianhong@163.com>
> 抄送: linux-xfs@vger.kernel.org, jiyin@redhat.com
> 发送时间: 星期四, 2019年 9 月 05日 下午 2:01:32
> 主题: Re: [PATCH 2/2] xfsprogs: copy_range: let = (src_size - src_offset) if len omitted
> 
> On Thu, Sep 05, 2019 at 01:31:52PM +0800, Jianhong.Yin wrote:
> > add update man page.
> > 
> > Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
> > ---
> 
> I think these can be in one patch, but anyway...
> 
> >  io/copy_file_range.c | 7 +++++--
> >  man/man8/xfs_io.8    | 9 +++------
> >  2 files changed, 8 insertions(+), 8 deletions(-)
> > 
> > diff --git a/io/copy_file_range.c b/io/copy_file_range.c
> > index 283f5094..02d50e53 100644
> > --- a/io/copy_file_range.c
> > +++ b/io/copy_file_range.c
> > @@ -72,6 +72,7 @@ copy_range_f(int argc, char **argv)
> >  	long long src = 0;
> >  	long long dst = 0;
> >  	size_t len = 0;
> > +	int len_ommited = 1;
> >  	int opt;
> >  	int ret;
> >  	int fd;
> > @@ -103,6 +104,7 @@ copy_range_f(int argc, char **argv)
> >  				printf(_("invalid length -- %s\n"), optarg);
> >  				return 0;
> >  			}
> > +			len_ommited = 0;
> >  			break;
> >  		case 'f':
> >  			src_file_nr = atoi(argv[1]);
> > @@ -128,7 +130,7 @@ copy_range_f(int argc, char **argv)
> >  		fd = filetable[src_file_nr].fd;
> >  	}
> >  
> > -	if (src == 0 && dst == 0 && len == 0) {
> > +	if (len_ommited) {
> >  		off64_t	sz;
> >  
> >  		sz = copy_src_filesize(fd);
> > @@ -136,7 +138,8 @@ copy_range_f(int argc, char **argv)
> >  			ret = 1;
> >  			goto out;
> >  		}
> > -		len = sz;
> > +		if (sz > src)
> > +			len = sz - src;
> 
> What about file size < offset?
just keep the default value 0,

because QE/tester might want to see what happen
when give an offset(> fsize) to copy_file_range()
  #note: This tool was made for test/debug copy_file_range()

Jianhong

> 
> Maybe we can do like this?:
> 
>     sz = copy_src_filesize(fd);
>     if (sz < 0 || (unsigned long long)sz > SIZE_MAX || sz < src) {
>         ret = 1;
>         goto out;
>     }
>     len = sz - src;
> 
> Thanks,
> Zorro
> 
> >  	}
> >  
> >  	ret = copy_file_range_cmd(fd, &src, &dst, len);
> > diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
> > index 6e064bdd..f5f1c4fc 100644
> > --- a/man/man8/xfs_io.8
> > +++ b/man/man8/xfs_io.8
> > @@ -669,13 +669,10 @@ The source must be specified either by path
> >  or as another open file
> >  .RB ( \-f ).
> >  If
> > -.I src_file
> > -.IR src_offset ,
> > -.IR dst_offset ,
> > -and
> >  .I length
> > -are omitted the contents of src_file will be copied to the beginning of
> > the
> > -open file, overwriting any data already there.
> > +is omitted will use
> > +.I src_file
> > +(file size - src_offset) instead.
> >  .RS 1.0i
> >  .PD 0
> >  .TP 0.4i
> > --
> > 2.21.0
> > 
> 

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

* Re: [PATCH 2/2] xfsprogs: copy_range: let = (src_size - src_offset) if len omitted
  2019-09-05  6:04     ` Jianhong Yin
@ 2019-09-05  8:13       ` Zorro Lang
  2019-09-06  0:53         ` Zorro Lang
  0 siblings, 1 reply; 7+ messages in thread
From: Zorro Lang @ 2019-09-05  8:13 UTC (permalink / raw)
  To: Jianhong Yin; +Cc: Jianhong.Yin, linux-xfs

On Thu, Sep 05, 2019 at 02:04:31AM -0400, Jianhong Yin wrote:
> 
> 
> ----- 原始邮件 -----
> > 发件人: "Zorro Lang" <zlang@redhat.com>
> > 收件人: "Jianhong.Yin" <yin-jianhong@163.com>
> > 抄送: linux-xfs@vger.kernel.org, jiyin@redhat.com
> > 发送时间: 星期四, 2019年 9 月 05日 下午 2:01:32
> > 主题: Re: [PATCH 2/2] xfsprogs: copy_range: let = (src_size - src_offset) if len omitted
> > 
> > On Thu, Sep 05, 2019 at 01:31:52PM +0800, Jianhong.Yin wrote:
> > > add update man page.
> > > 
> > > Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
> > > ---
> > 
> > I think these can be in one patch, but anyway...
> > 
> > >  io/copy_file_range.c | 7 +++++--
> > >  man/man8/xfs_io.8    | 9 +++------
> > >  2 files changed, 8 insertions(+), 8 deletions(-)
> > > 
> > > diff --git a/io/copy_file_range.c b/io/copy_file_range.c
> > > index 283f5094..02d50e53 100644
> > > --- a/io/copy_file_range.c
> > > +++ b/io/copy_file_range.c
> > > @@ -72,6 +72,7 @@ copy_range_f(int argc, char **argv)
> > >  	long long src = 0;
> > >  	long long dst = 0;
> > >  	size_t len = 0;
> > > +	int len_ommited = 1;
> > >  	int opt;
> > >  	int ret;
> > >  	int fd;
> > > @@ -103,6 +104,7 @@ copy_range_f(int argc, char **argv)
> > >  				printf(_("invalid length -- %s\n"), optarg);
> > >  				return 0;
> > >  			}
> > > +			len_ommited = 0;
> > >  			break;
> > >  		case 'f':
> > >  			src_file_nr = atoi(argv[1]);
> > > @@ -128,7 +130,7 @@ copy_range_f(int argc, char **argv)
> > >  		fd = filetable[src_file_nr].fd;
> > >  	}
> > >  
> > > -	if (src == 0 && dst == 0 && len == 0) {
> > > +	if (len_ommited) {
> > >  		off64_t	sz;
> > >  
> > >  		sz = copy_src_filesize(fd);
> > > @@ -136,7 +138,8 @@ copy_range_f(int argc, char **argv)
> > >  			ret = 1;
> > >  			goto out;
> > >  		}
> > > -		len = sz;
> > > +		if (sz > src)
> > > +			len = sz - src;
> > 
> > What about file size < offset?
> just keep the default value 0,
> 
> because QE/tester might want to see what happen
> when give an offset(> fsize) to copy_file_range()
>   #note: This tool was made for test/debug copy_file_range()

Hmm, that's a good reason:)

> 
> Jianhong
> 
> > 
> > Maybe we can do like this?:
> > 
> >     sz = copy_src_filesize(fd);
> >     if (sz < 0 || (unsigned long long)sz > SIZE_MAX || sz < src) {
> >         ret = 1;
> >         goto out;
> >     }
> >     len = sz - src;
> > 
> > Thanks,
> > Zorro
> > 
> > >  	}
> > >  
> > >  	ret = copy_file_range_cmd(fd, &src, &dst, len);
> > > diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
> > > index 6e064bdd..f5f1c4fc 100644
> > > --- a/man/man8/xfs_io.8
> > > +++ b/man/man8/xfs_io.8
> > > @@ -669,13 +669,10 @@ The source must be specified either by path
> > >  or as another open file
> > >  .RB ( \-f ).
> > >  If
> > > -.I src_file
> > > -.IR src_offset ,
> > > -.IR dst_offset ,
> > > -and
> > >  .I length
> > > -are omitted the contents of src_file will be copied to the beginning of
> > > the
> > > -open file, overwriting any data already there.
> > > +is omitted will use
> > > +.I src_file
> > > +(file size - src_offset) instead.
> > >  .RS 1.0i
> > >  .PD 0
> > >  .TP 0.4i
> > > --
> > > 2.21.0
> > > 
> > 

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

* Re: [PATCH 2/2] xfsprogs: copy_range: let = (src_size - src_offset) if len omitted
  2019-09-05  8:13       ` Zorro Lang
@ 2019-09-06  0:53         ` Zorro Lang
  2019-09-06  2:18           ` Jianhong Yin
  0 siblings, 1 reply; 7+ messages in thread
From: Zorro Lang @ 2019-09-06  0:53 UTC (permalink / raw)
  To: Jianhong Yin; +Cc: Jianhong.Yin, linux-xfs

On Thu, Sep 05, 2019 at 04:13:15PM +0800, Zorro Lang wrote:
> On Thu, Sep 05, 2019 at 02:04:31AM -0400, Jianhong Yin wrote:
> > 
> > 
> > ----- 原始邮件 -----
> > > 发件人: "Zorro Lang" <zlang@redhat.com>
> > > 收件人: "Jianhong.Yin" <yin-jianhong@163.com>
> > > 抄送: linux-xfs@vger.kernel.org, jiyin@redhat.com
> > > 发送时间: 星期四, 2019年 9 月 05日 下午 2:01:32
> > > 主题: Re: [PATCH 2/2] xfsprogs: copy_range: let = (src_size - src_offset) if len omitted
> > > 
> > > On Thu, Sep 05, 2019 at 01:31:52PM +0800, Jianhong.Yin wrote:
> > > > add update man page.
> > > > 
> > > > Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
> > > > ---
> > > 
> > > I think these can be in one patch, but anyway...
> > > 
> > > >  io/copy_file_range.c | 7 +++++--
> > > >  man/man8/xfs_io.8    | 9 +++------
> > > >  2 files changed, 8 insertions(+), 8 deletions(-)
> > > > 
> > > > diff --git a/io/copy_file_range.c b/io/copy_file_range.c
> > > > index 283f5094..02d50e53 100644
> > > > --- a/io/copy_file_range.c
> > > > +++ b/io/copy_file_range.c
> > > > @@ -72,6 +72,7 @@ copy_range_f(int argc, char **argv)
> > > >  	long long src = 0;
> > > >  	long long dst = 0;
> > > >  	size_t len = 0;
> > > > +	int len_ommited = 1;
> > > >  	int opt;
> > > >  	int ret;
> > > >  	int fd;
> > > > @@ -103,6 +104,7 @@ copy_range_f(int argc, char **argv)
> > > >  				printf(_("invalid length -- %s\n"), optarg);
> > > >  				return 0;
> > > >  			}
> > > > +			len_ommited = 0;
> > > >  			break;
> > > >  		case 'f':
> > > >  			src_file_nr = atoi(argv[1]);
> > > > @@ -128,7 +130,7 @@ copy_range_f(int argc, char **argv)
> > > >  		fd = filetable[src_file_nr].fd;
> > > >  	}
> > > >  
> > > > -	if (src == 0 && dst == 0 && len == 0) {
> > > > +	if (len_ommited) {
> > > >  		off64_t	sz;
> > > >  
> > > >  		sz = copy_src_filesize(fd);
> > > > @@ -136,7 +138,8 @@ copy_range_f(int argc, char **argv)
> > > >  			ret = 1;
> > > >  			goto out;
> > > >  		}
> > > > -		len = sz;
> > > > +		if (sz > src)
> > > > +			len = sz - src;
> > > 
> > > What about file size < offset?
> > just keep the default value 0,
> > 
> > because QE/tester might want to see what happen
> > when give an offset(> fsize) to copy_file_range()
> >   #note: This tool was made for test/debug copy_file_range()
> 
> Hmm, that's a good reason:)
> 
> > 
> > Jianhong
> > 
> > > 
> > > Maybe we can do like this?:
> > > 
> > >     sz = copy_src_filesize(fd);
> > >     if (sz < 0 || (unsigned long long)sz > SIZE_MAX || sz < src) {
> > >         ret = 1;
> > >         goto out;
> > >     }
> > >     len = sz - src;
> > > 
> > > Thanks,
> > > Zorro
> > > 
> > > >  	}
> > > >  
> > > >  	ret = copy_file_range_cmd(fd, &src, &dst, len);
> > > > diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
> > > > index 6e064bdd..f5f1c4fc 100644
> > > > --- a/man/man8/xfs_io.8
> > > > +++ b/man/man8/xfs_io.8
> > > > @@ -669,13 +669,10 @@ The source must be specified either by path
> > > >  or as another open file
> > > >  .RB ( \-f ).
> > > >  If
> > > > -.I src_file
> > > > -.IR src_offset ,
> > > > -.IR dst_offset ,
> > > > -and
> > > >  .I length
> > > > -are omitted the contents of src_file will be copied to the beginning of
> > > > the
> > > > -open file, overwriting any data already there.
> > > > +is omitted will use
> > > > +.I src_file
> > > > +(file size - src_offset) instead.

BTW, When I tried to merge this patch, I got below warning:

  Applying: xfsprogs: copy_range: let = (src_size - src_offset) if len omitted
  .git/rebase-apply/patch:61: trailing whitespace.
  .I src_file 
  warning: 1 line adds whitespace errors.

Thanks,
Zorro

> > > >  .RS 1.0i
> > > >  .PD 0
> > > >  .TP 0.4i
> > > > --
> > > > 2.21.0
> > > > 
> > > 

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

* Re: [PATCH 2/2] xfsprogs: copy_range: let = (src_size - src_offset) if len omitted
  2019-09-06  0:53         ` Zorro Lang
@ 2019-09-06  2:18           ` Jianhong Yin
  0 siblings, 0 replies; 7+ messages in thread
From: Jianhong Yin @ 2019-09-06  2:18 UTC (permalink / raw)
  To: Zorro Lang; +Cc: Jianhong.Yin, linux-xfs


----- 原始邮件 -----
> 发件人: "Zorro Lang" <zlang@redhat.com>
> 收件人: "Jianhong Yin" <jiyin@redhat.com>
> 抄送: "Jianhong.Yin" <yin-jianhong@163.com>, linux-xfs@vger.kernel.org
> 发送时间: 星期五, 2019年 9 月 06日 上午 8:53:56
> 主题: Re: [PATCH 2/2] xfsprogs: copy_range: let = (src_size - src_offset) if len omitted
> 
> On Thu, Sep 05, 2019 at 04:13:15PM +0800, Zorro Lang wrote:
> > On Thu, Sep 05, 2019 at 02:04:31AM -0400, Jianhong Yin wrote:
> > > 
> > > 
> > > ----- 原始邮件 -----
> > > > 发件人: "Zorro Lang" <zlang@redhat.com>
> > > > 收件人: "Jianhong.Yin" <yin-jianhong@163.com>
> > > > 抄送: linux-xfs@vger.kernel.org, jiyin@redhat.com
> > > > 发送时间: 星期四, 2019年 9 月 05日 下午 2:01:32
> > > > 主题: Re: [PATCH 2/2] xfsprogs: copy_range: let = (src_size - src_offset)
> > > > if len omitted
> > > > 
> > > > On Thu, Sep 05, 2019 at 01:31:52PM +0800, Jianhong.Yin wrote:
> > > > > add update man page.
> > > > > 
> > > > > Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
> > > > > ---
> > > > 
> > > > I think these can be in one patch, but anyway...
> > > > 
> > > > >  io/copy_file_range.c | 7 +++++--
> > > > >  man/man8/xfs_io.8    | 9 +++------
> > > > >  2 files changed, 8 insertions(+), 8 deletions(-)
> > > > > 
> > > > > diff --git a/io/copy_file_range.c b/io/copy_file_range.c
> > > > > index 283f5094..02d50e53 100644
> > > > > --- a/io/copy_file_range.c
> > > > > +++ b/io/copy_file_range.c
> > > > > @@ -72,6 +72,7 @@ copy_range_f(int argc, char **argv)
> > > > >  	long long src = 0;
> > > > >  	long long dst = 0;
> > > > >  	size_t len = 0;
> > > > > +	int len_ommited = 1;
> > > > >  	int opt;
> > > > >  	int ret;
> > > > >  	int fd;
> > > > > @@ -103,6 +104,7 @@ copy_range_f(int argc, char **argv)
> > > > >  				printf(_("invalid length -- %s\n"), optarg);
> > > > >  				return 0;
> > > > >  			}
> > > > > +			len_ommited = 0;
> > > > >  			break;
> > > > >  		case 'f':
> > > > >  			src_file_nr = atoi(argv[1]);
> > > > > @@ -128,7 +130,7 @@ copy_range_f(int argc, char **argv)
> > > > >  		fd = filetable[src_file_nr].fd;
> > > > >  	}
> > > > >  
> > > > > -	if (src == 0 && dst == 0 && len == 0) {
> > > > > +	if (len_ommited) {
> > > > >  		off64_t	sz;
> > > > >  
> > > > >  		sz = copy_src_filesize(fd);
> > > > > @@ -136,7 +138,8 @@ copy_range_f(int argc, char **argv)
> > > > >  			ret = 1;
> > > > >  			goto out;
> > > > >  		}
> > > > > -		len = sz;
> > > > > +		if (sz > src)
> > > > > +			len = sz - src;
> > > > 
> > > > What about file size < offset?
> > > just keep the default value 0,
> > > 
> > > because QE/tester might want to see what happen
> > > when give an offset(> fsize) to copy_file_range()
> > >   #note: This tool was made for test/debug copy_file_range()
> > 
> > Hmm, that's a good reason:)
> > 
> > > 
> > > Jianhong
> > > 
> > > > 
> > > > Maybe we can do like this?:
> > > > 
> > > >     sz = copy_src_filesize(fd);
> > > >     if (sz < 0 || (unsigned long long)sz > SIZE_MAX || sz < src) {
> > > >         ret = 1;
> > > >         goto out;
> > > >     }
> > > >     len = sz - src;
> > > > 
> > > > Thanks,
> > > > Zorro
> > > > 
> > > > >  	}
> > > > >  
> > > > >  	ret = copy_file_range_cmd(fd, &src, &dst, len);
> > > > > diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
> > > > > index 6e064bdd..f5f1c4fc 100644
> > > > > --- a/man/man8/xfs_io.8
> > > > > +++ b/man/man8/xfs_io.8
> > > > > @@ -669,13 +669,10 @@ The source must be specified either by path
> > > > >  or as another open file
> > > > >  .RB ( \-f ).
> > > > >  If
> > > > > -.I src_file
> > > > > -.IR src_offset ,
> > > > > -.IR dst_offset ,
> > > > > -and
> > > > >  .I length
> > > > > -are omitted the contents of src_file will be copied to the beginning
> > > > > of
> > > > > the
> > > > > -open file, overwriting any data already there.
> > > > > +is omitted will use
> > > > > +.I src_file
> > > > > +(file size - src_offset) instead.
> 
> BTW, When I tried to merge this patch, I got below warning:
> 
>   Applying: xfsprogs: copy_range: let = (src_size - src_offset) if len
>   omitted
>   .git/rebase-apply/patch:61: trailing whitespace.
>   .I src_file
>   warning: 1 line adds whitespace errors.

Thanks Zorro, will fix it.

Jianhong

> 
> Thanks,
> Zorro
> 
> > > > >  .RS 1.0i
> > > > >  .PD 0
> > > > >  .TP 0.4i
> > > > > --
> > > > > 2.21.0
> > > > > 
> > > > 
> 

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

end of thread, other threads:[~2019-09-06  2:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-05  5:31 [PATCH 1/2] xfsprogs: copy_range don't truncate dstfile Jianhong.Yin
2019-09-05  5:31 ` [PATCH 2/2] xfsprogs: copy_range: let = (src_size - src_offset) if len omitted Jianhong.Yin
2019-09-05  6:01   ` Zorro Lang
2019-09-05  6:04     ` Jianhong Yin
2019-09-05  8:13       ` Zorro Lang
2019-09-06  0:53         ` Zorro Lang
2019-09-06  2:18           ` Jianhong Yin

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).