xfs_io: Add support for pwritev2()
PATCH v2 1/3 xfs_io: Add support for pwritev2()
From: Goldwyn Rodrigues <[email protected]>
--- configure.ac | 1 + include/builddefs.in | 1 + io/Makefile | 4 ++++ io/pwrite.c | 39 ++++++++++++++++++++++++++------------- m4/package_libcdev.m4 | 16 ++++++++++++++++ 5 files changed, 48 insertions(+), 13 deletions(-)
configure.ac +1 -0
@@ -132,6 +132,7 @@ AC_HAVE_GETMNTENT AC_HAVE_GETMNTINFO AC_HAVE_FALLOCATE AC_HAVE_FIEMAP +AC_HAVE_PWRITEV2 AC_HAVE_PREADV AC_HAVE_COPY_FILE_RANGE AC_HAVE_SYNC_FILE_RANGE
include/builddefs.in +1 -0
@@ -103,6 +103,7 @@ HAVE_GETMNTINFO = @have_getmntinfo@ HAVE_FALLOCATE = @have_fallocate@ HAVE_FIEMAP = @have_fiemap@ HAVE_PREADV = @have_preadv@ +HAVE_PWRITEV2 = @have_pwritev2@ HAVE_COPY_FILE_RANGE = @have_copy_file_range@ HAVE_SYNC_FILE_RANGE = @have_sync_file_range@ HAVE_SYNCFS = @have_syncfs@
io/Makefile +4 -0
@@ -90,6 +90,10 @@ ifeq ($(HAVE_PREADV),yes) LCFLAGS += -DHAVE_PREADV -DHAVE_PWRITEV endif +ifeq ($(HAVE_PWRITEV2),yes) +LCFLAGS += -DHAVE_PWRITEV2 +endif + ifeq ($(HAVE_READDIR),yes) CFILES += readdir.c LCFLAGS += -DHAVE_READDIR
io/pwrite.c +26 -13
@@ -62,7 +62,8 @@ do_pwritev(int fd, off64_t offset, ssize_t count, - ssize_t buffer_size) + ssize_t buffer_size, + int pwritev2_flags) { int vecs = 0;ssize_t oldlen =0 ;
@@ -81,7 +82,14 @@ do_pwritev( }else { vecs = vectors; } +#ifdef HAVE_PWRITEV2 +if (pwritev2_flags) + bytes =pwritev2 (fd, iov, vectors, offset, pwritev2_flags); +else + bytes =pwritev (fd, iov, vectors, offset); +#else bytes =pwritev (fd, iov, vectors, offset); +#endif /* restore trimmed iov */ if (oldlen)
@@ -98,12 +106,13 @@ do_pwrite(int fd, off64_t offset, ssize_t count, - ssize_t buffer_size) + ssize_t buffer_size, + int pwritev2_flags) { if (!vectors) return pwrite(fd, buffer, min(count, buffer_size), offset); -return do_pwritev (fd, offset, count, buffer_size); +return do_pwritev (fd, offset, count, buffer_size, pwritev2_flags); } static int
@@ -111,7 +120,8 @@ write_random(off64_t offset, long long count, unsigned int seed, - long long *total) + long long *total, + int pwritev2_flags) { off64_t off, range;ssize_t bytes;
@@ -133,7 +143,7 @@ write_random( buffersize; else off = offset; - bytes =do_pwrite (file->fd, off, buffersize, buffersize); + bytes =do_pwrite (file->fd, off, buffersize, buffersize, pwritev2_flags);if (bytes ==0 )break ;if (bytes <0 ) {
@@ -153,7 +163,8 @@ static intwrite_backward ( off64_t offset, long long *count, - long long *total) + long long *total, + int pwritev2_flags) { off64_t end, off = offset;ssize_t bytes =0 , bytes_requested;
@@ -171,7 +182,7 @@ write_backward(if ((bytes_requested = (off % buffersize))) { bytes_requested =min (cnt, bytes_requested); off -= bytes_requested; - bytes =do_pwrite (file->fd, off, bytes_requested, buffersize); + bytes =do_pwrite (file->fd, off, bytes_requested, buffersize, pwritev2_flags);if (bytes ==0 )return ops;if (bytes <0 ) {
@@ -189,7 +200,7 @@ write_backward(while (cnt > end) { bytes_requested =min (cnt, buffersize); off -= bytes_requested; - bytes =do_pwrite (file->fd, off, cnt, buffersize); + bytes =do_pwrite (file->fd, off, cnt, buffersize, pwritev2_flags);if (bytes ==0 )break ;if (bytes <0 ) {
@@ -212,7 +223,8 @@ write_buffer(size_t bs, int fd, off64_t skip, - long long *total) + long long *total, + int pwritev2_flags) { ssize_t bytes;long long bar =min (bs, count);
@@ -224,7 +236,7 @@ write_buffer(if (read_buffer (fd, skip + *total, bs, &bar,0 ,1 ) <0 )break ; } - bytes =do_pwrite (file->fd, offset, count, bar); + bytes =do_pwrite (file->fd, offset, count, bar, pwritev2_flags);if (bytes ==0 )break ;if (bytes <0 ) {
@@ -258,6 +270,7 @@ pwrite_f(int Cflag, qflag, uflag, dflag, wflag, Wflag;int direction =IO_FORWARD ;int c, fd =-1 ; +int pwritev2_flags =0 ; Cflag = qflag = uflag = dflag = wflag = Wflag =0 ;init_cvtnum (&fsblocksize, &fssectsize);
@@ -365,13 +378,13 @@ pwrite_f(case IO_RANDOM :if (!zeed)/* srandom seed */ zeed =time (NULL ); - c =write_random (offset, count, zeed, &total); + c =write_random (offset, count, zeed, &total, pwritev2_flags);break ;case IO_FORWARD : - c =write_buffer (offset, count, bsize, fd, skip, &total); + c =write_buffer (offset, count, bsize, fd, skip, &total, pwritev2_flags);break ;case IO_BACKWARD : - c =write_backward (offset, &count, &total); + c =write_backward (offset, &count, &total, pwritev2_flags);break ;default : total =0 ;
m4/package_libcdev.m4 +16 -0
@@ -146,6 +146,22 @@ AC_DEFUN([AC_HAVE_PREADV], AC_SUBST(have_preadv) ]) +# +# Check if we have a pwritev2 libc call (Linux) +# +AC_DEFUN([AC_HAVE_PWRITEV2], + [ AC_MSG_CHECKING([for pwritev2]) + AC_TRY_LINK([ +#define _BSD_SOURCE +#include <sys/uio.h> + ], [ + pwritev2(0, 0, 0, 0, 0); + ], have_pwritev2=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_pwritev2) + ]) + # # Check if we have a copy_file_range system call (Linux) #
Signature · 1 line
2.14.1
PATCH v2 2/3 xfs_io: Add RWF_NOWAIT to pwritev2()
From: Goldwyn Rodrigues <[email protected]>
This allows to make pwritev2() calls with RWF_NOWAIT, which would fail in case the call blocks.
--- io/pwrite.c | 8 +++++++- man/man8/xfs_io.8 | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-)
io/pwrite.c +7 -1
@@ -52,6 +52,9 @@ pwrite_help(void)" (heh, zorry, the -s/-S arguments were already in use in pwrite)\n" #ifdef HAVE_PWRITEV" -V N -- use vectored IO with N iovecs of blocksize each (pwritev)\n" +#ifdef HAVE_PWRITEV2 +" -N -- Perform the pwritev2() with RWF_NOWAIT\n" +#endif #endif "\n")); }
@@ -276,7 +279,7 @@ pwrite_f(init_cvtnum (&fsblocksize, &fssectsize); bsize = fsblocksize; -while ((c =getopt (argc, argv,"b:BCdf:Fi:qRs:S:uV:wWZ:" )) !=EOF ) { +while ((c =getopt (argc, argv,"b:BCdf:Fi:NqRs:S:uV:wWZ:" )) !=EOF ) {switch (c) {case 'b' : tmp =cvtnum (fsblocksize, fssectsize, optarg);
@@ -305,6 +308,9 @@ pwrite_f(case 'i' : infile = optarg;break ; +case 'N' : + pwritev2_flags |=RWF_NOWAIT ; +break ;case 's' : skip =cvtnum (fsblocksize, fssectsize, optarg);if (skip <0 ) {
man/man8/xfs_io.8 +6 -0
@@ -282,6 +282,12 @@ Use the vectored IO write syscall with a number of blocksize length iovecs. The number of iovecs is set by the .I vectors parameter. +.TP +.B \-N +Perform the +.BR pwritev2 (2) +call with +.I RWF_NOWAIT. .RE .PD .TP
Signature · 1 line
2.14.1
Re: [PATCH v2 2/3] xfs_io: Add RWF_NOWAIT to pwritev2()
Quoted 35 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
This allows to make
pwritev2()calls withRWF_NOWAIT, which would fail in case the call blocks.Signed-off-by Goldwyn Rodrigues <[email protected]>--- io/pwrite.c | 8 +++++++- man/man8/xfs_io.8 | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-)io/pwrite.c +4
-1@@ -52,6 +52,9 @@ pwrite_help(void)" (heh, zorry, the -s/-S arguments were already in use in pwrite)\n" #ifdef HAVE_PWRITEV" -V N -- use vectored IO with N iovecs of blocksize each (pwritev)\n" +#ifdef HAVE_PWRITEV2 +" -N -- Perform the pwritev2() with RWF_NOWAIT\n" +#endif #endif "\n")); }@@ -276,7 +279,7 @@ pwrite_f(init_cvtnum (&fsblocksize, &fssectsize); bsize = fsblocksize; -while ((c =getopt (argc, argv,"b:BCdf:Fi:qRs:S:uV:wWZ:" )) !=EOF ) { +while ((c =getopt (argc, argv,"b:BCdf:Fi:NqRs:S:uV:wWZ:" )) !=EOF ) {switch (c) {case 'b' : tmp =cvtnum (fsblocksize, fssectsize, optarg);
io/pwrite.c pwrite_f( · line 312
Quoted 5 lines
io/pwrite.c +2
-0@@ -305,6 +308,9 @@ pwrite_f(case 'i' : infile = optarg;break ; +case 'N' : + pwritev2_flags |=RWF_NOWAIT ;
This causes a build failure on my local machine due to lack of RWF_NOWAIT. #ifdef HAVE_PWRITEV2 around this case? Otherwise the code looks Ok.
Brian
Quoted 28 lines
io/pwrite.c +1
-0+break ;case 's' : skip =cvtnum (fsblocksize, fssectsize, optarg);if (skip <0 ) {man/man8/xfs_io.8 +6
-0@@ -282,6 +282,12 @@ Use the vectored IO write syscall with a number of blocksize length iovecs. The number of iovecs is set by the .I vectors parameter. +.TP +.B \-N +Perform the +.BR pwritev2 (2) +call with +.I RWF_NOWAIT. .RE .PD .TPSignature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 2/3] xfs_io: Add RWF_NOWAIT to pwritev2()
In reply to Goldwyn RodriguesQuoted 16 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
This allows to make
pwritev2()calls withRWF_NOWAIT, which would fail in case the call blocks.Signed-off-by Goldwyn Rodrigues <[email protected]>--- io/pwrite.c | 8 +++++++- man/man8/xfs_io.8 | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-)io/pwrite.c +0
-0
io/pwrite.c pwrite_help(void) · line 57
Quoted 6 lines
io/pwrite.c +3
-0@@ -52,6 +52,9 @@ pwrite_help(void)" (heh, zorry, the -s/-S arguments were already in use in pwrite)\n" #ifdef HAVE_PWRITEV" -V N -- use vectored IO with N iovecs of blocksize each (pwritev)\n" +#ifdef HAVE_PWRITEV2 +" -N -- Perform the pwritev2() with RWF_NOWAIT\n" +#endif
Separate these two? i.e.
#ifdef HAVE_PWRITEV
" -V N..."
#endif
#ifdef HAVE_PWRITEV2
" -N ..."
#endif
They're tested separately in configure, so the ifdefs needn't be nested.
Quoted 13 lines
io/pwrite.c +1
-1#endif "\n")); }@@ -276,7 +279,7 @@ pwrite_f(init_cvtnum (&fsblocksize, &fssectsize); bsize = fsblocksize; -while ((c =getopt (argc, argv,"b:BCdf:Fi:qRs:S:uV:wWZ:" )) !=EOF ) { +while ((c =getopt (argc, argv,"b:BCdf:Fi:NqRs:S:uV:wWZ:" )) !=EOF ) {switch (c) {case 'b' : tmp =cvtnum (fsblocksize, fssectsize, optarg);
io/pwrite.c pwrite_f( · line 313
Quoted 6 lines
io/pwrite.c +3
-0@@ -305,6 +308,9 @@ pwrite_f(case 'i' : infile = optarg;break ; +case 'N' : + pwritev2_flags |=RWF_NOWAIT ; +break ;
Needs #ifdef HAVE_PWRITEV2.
If you feel the need to be extra cautious, you could also put:
#ifndef HAVE_PWRITEV2 assert(pwritev2_flags == 0);
#endif
...just after the getopt parsing to make sure that we never silently drop RWF_* flags due to code bugs.
--D
Quoted 27 lines
io/pwrite.c +0
-0case 's' : skip =cvtnum (fsblocksize, fssectsize, optarg);if (skip <0 ) {man/man8/xfs_io.8 +6
-0@@ -282,6 +282,12 @@ Use the vectored IO write syscall with a number of blocksize length iovecs. The number of iovecs is set by the .I vectors parameter. +.TP +.B \-N +Perform the +.BR pwritev2 (2) +call with +.I RWF_NOWAIT. .RE .PD .TPSignature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 2/3] xfs_io: Add RWF_NOWAIT to pwritev2()
Quoted 57 lines · Darrick J. Wong
Quoted 16 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
This allows to make
pwritev2()calls withRWF_NOWAIT, which would fail in case the call blocks.Signed-off-by Goldwyn Rodrigues <[email protected]>--- io/pwrite.c | 8 +++++++- man/man8/xfs_io.8 | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-)io/pwrite.c +0
-0io/pwrite.c pwrite_help(void) · line 57
Quoted 6 lines
io/pwrite.c +3
-0@@ -52,6 +52,9 @@ pwrite_help(void)" (heh, zorry, the -s/-S arguments were already in use in pwrite)\n" #ifdef HAVE_PWRITEV" -V N -- use vectored IO with N iovecs of blocksize each (pwritev)\n" +#ifdef HAVE_PWRITEV2 +" -N -- Perform the pwritev2() with RWF_NOWAIT\n" +#endifSeparate these two? i.e.
#ifdef
HAVE_PWRITEV
" -V N..."
#endif
#ifdefHAVE_PWRITEV2
" -N ..."
#endifThey're tested separately in configure, so the ifdefs needn't be nested.
Quoted 13 lines
io/pwrite.c +1
-1#endif "\n")); }@@ -276,7 +279,7 @@ pwrite_f(init_cvtnum (&fsblocksize, &fssectsize); bsize = fsblocksize; -while ((c =getopt (argc, argv,"b:BCdf:Fi:qRs:S:uV:wWZ:" )) !=EOF ) { +while ((c =getopt (argc, argv,"b:BCdf:Fi:NqRs:S:uV:wWZ:" )) !=EOF ) {switch (c) {case 'b' : tmp =cvtnum (fsblocksize, fssectsize, optarg);io/pwrite.c pwrite_f( · line 313
Quoted 6 lines
io/pwrite.c +3
-0@@ -305,6 +308,9 @@ pwrite_f(case 'i' : infile = optarg;break ; +case 'N' : + pwritev2_flags |=RWF_NOWAIT ; +break ;Needs #ifdef
HAVE_PWRITEV2.
Quoted 9 lines
If you feel the need to be extra cautious, you could also put:
#ifndef HAVE_PWRITEV2 assert(pwritev2_flags == 0);#endif
...just after the getopt parsing to make sure that we never silently drop RWF_* flags due to code bugs.
Instead I am planning to put an #else to #ifdef in the case 'N' to make sure that people who do not have pwritev2() get the proper message instead of the command failing without reason.
+ case 'N':
+#ifdef HAVE_PWRITEV2
+ pwritev2_flags |= RWF_NOWAIT;
+ break;
+#else
+ printf(_("-N: Kernel does not support
pwritev2()\n"));
+ return 0;
+#endif
Quoted 29 lines
--D
Quoted 27 lines
io/pwrite.c +0
-0case 's' : skip =cvtnum (fsblocksize, fssectsize, optarg);if (skip <0 ) {man/man8/xfs_io.8 +6
-0@@ -282,6 +282,12 @@ Use the vectored IO write syscall with a number of blocksize length iovecs. The number of iovecs is set by the .I vectors parameter. +.TP +.B \-N +Perform the +.BR pwritev2 (2) +call with +.I RWF_NOWAIT. .RE .PD .TPSignature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Goldwyn
Re: [PATCH v2 2/3] xfs_io: Add RWF_NOWAIT to pwritev2()
Quoted 81 lines · Goldwyn Rodrigues
Quoted 57 lines · Darrick J. Wong
Quoted 16 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
This allows to make
pwritev2()calls withRWF_NOWAIT, which would fail in case the call blocks.Signed-off-by Goldwyn Rodrigues <[email protected]>--- io/pwrite.c | 8 +++++++- man/man8/xfs_io.8 | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-)io/pwrite.c +0
-0io/pwrite.c pwrite_help(void) · line 57
Quoted 6 lines
io/pwrite.c +3
-0@@ -52,6 +52,9 @@ pwrite_help(void)" (heh, zorry, the -s/-S arguments were already in use in pwrite)\n" #ifdef HAVE_PWRITEV" -V N -- use vectored IO with N iovecs of blocksize each (pwritev)\n" +#ifdef HAVE_PWRITEV2 +" -N -- Perform the pwritev2() with RWF_NOWAIT\n" +#endifSeparate these two? i.e.
#ifdef
HAVE_PWRITEV
" -V N..."
#endif
#ifdefHAVE_PWRITEV2
" -N ..."
#endifThey're tested separately in configure, so the ifdefs needn't be nested.
Quoted 13 lines
io/pwrite.c +1
-1#endif "\n")); }@@ -276,7 +279,7 @@ pwrite_f(init_cvtnum (&fsblocksize, &fssectsize); bsize = fsblocksize; -while ((c =getopt (argc, argv,"b:BCdf:Fi:qRs:S:uV:wWZ:" )) !=EOF ) { +while ((c =getopt (argc, argv,"b:BCdf:Fi:NqRs:S:uV:wWZ:" )) !=EOF ) {switch (c) {case 'b' : tmp =cvtnum (fsblocksize, fssectsize, optarg);io/pwrite.c pwrite_f( · line 313
Quoted 6 lines
io/pwrite.c +3
-0@@ -305,6 +308,9 @@ pwrite_f(case 'i' : infile = optarg;break ; +case 'N' : + pwritev2_flags |=RWF_NOWAIT ; +break ;Needs #ifdef
HAVE_PWRITEV2.Quoted 9 lines
If you feel the need to be extra cautious, you could also put:
#ifndef HAVE_PWRITEV2 assert(pwritev2_flags == 0);#endif
...just after the getopt parsing to make sure that we never silently drop RWF_* flags due to code bugs.
Instead I am planning to put an #else to #ifdef in the case 'N' to make sure that people who do not have
pwritev2()get the proper message instead of the command failing without reason.io/pwrite.c +6
-0+case 'N' : +#ifdef HAVE_PWRITEV2 + pwritev2_flags |=RWF_NOWAIT ; +break ; +#else + printf(_("-N: Kernel does not supportpwritev2()\n"));
Review
Quoted 2 lines
(quoted diff) +2
-0+ return 0; +#endif
Why add support for a command only to say "command not supported"? The error message is also incorrect - the build environment didn't support pwritev2, not the kernel the xfs_io binary is currently running on.
As it is, I really don't like this sort of ifdef pattern because it means over time we'll end up with an ifdef mess in the option parsing as more flags are added. Just make the default case say "command -%c not supported", and that removes the need for any of these else cases.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH v2 2/3] xfs_io: Add RWF_NOWAIT to pwritev2()
Quoted 90 lines · Dave Chinner
Quoted 81 lines · Goldwyn Rodrigues
Quoted 57 lines · Darrick J. Wong
Quoted 16 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
This allows to make
pwritev2()calls withRWF_NOWAIT, which would fail in case the call blocks.Signed-off-by Goldwyn Rodrigues <[email protected]>--- io/pwrite.c | 8 +++++++- man/man8/xfs_io.8 | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-)io/pwrite.c +0
-0io/pwrite.c pwrite_help(void) · line 57
Quoted 6 lines
io/pwrite.c +3
-0@@ -52,6 +52,9 @@ pwrite_help(void)" (heh, zorry, the -s/-S arguments were already in use in pwrite)\n" #ifdef HAVE_PWRITEV" -V N -- use vectored IO with N iovecs of blocksize each (pwritev)\n" +#ifdef HAVE_PWRITEV2 +" -N -- Perform the pwritev2() with RWF_NOWAIT\n" +#endifSeparate these two? i.e.
#ifdef
HAVE_PWRITEV
" -V N..."
#endif
#ifdefHAVE_PWRITEV2
" -N ..."
#endifThey're tested separately in configure, so the ifdefs needn't be nested.
Quoted 13 lines
io/pwrite.c +1
-1#endif "\n")); }@@ -276,7 +279,7 @@ pwrite_f(init_cvtnum (&fsblocksize, &fssectsize); bsize = fsblocksize; -while ((c =getopt (argc, argv,"b:BCdf:Fi:qRs:S:uV:wWZ:" )) !=EOF ) { +while ((c =getopt (argc, argv,"b:BCdf:Fi:NqRs:S:uV:wWZ:" )) !=EOF ) {switch (c) {case 'b' : tmp =cvtnum (fsblocksize, fssectsize, optarg);io/pwrite.c pwrite_f( · line 313
Quoted 6 lines
io/pwrite.c +3
-0@@ -305,6 +308,9 @@ pwrite_f(case 'i' : infile = optarg;break ; +case 'N' : + pwritev2_flags |=RWF_NOWAIT ; +break ;Needs #ifdef
HAVE_PWRITEV2.Quoted 9 lines
If you feel the need to be extra cautious, you could also put:
#ifndef HAVE_PWRITEV2 assert(pwritev2_flags == 0);#endif
...just after the getopt parsing to make sure that we never silently drop RWF_* flags due to code bugs.
Instead I am planning to put an #else to #ifdef in the case 'N' to make sure that people who do not have
pwritev2()get the proper message instead of the command failing without reason.io/pwrite.c +6
-0+case 'N' : +#ifdef HAVE_PWRITEV2 + pwritev2_flags |=RWF_NOWAIT ; +break ; +#else + printf(_("-N: Kernel does not supportpwritev2()\n"));
Review
Quoted 2 lines
(quoted diff) +2
-0+ return 0; +#endifWhy add support for a command only to say "command not supported"? The error message is also incorrect - the build environment didn't support pwritev2, not the kernel the
xfs_iobinary is currently running on.
Quoted 6 lines
As it is, I really don't like this sort of ifdef pattern because it means over time we'll end up with an ifdef mess in the option parsing as more flags are added. Just make the default case say "command -%c not supported", and that removes the need for any of these else cases.
In that case, it would go to "default" which will print the command_usage. I am fine with that as long as the user understands why -N is not working.
Signature · 1 line
Goldwyn
PATCH v2 3/3 xfs_io: Allow partial writes
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Partial writes are performed when there is an error midway while performing the I/O. Perform the write exactly once and return the number of bytes written so far, until the error.
--- io/io.h | 1 + io/pwrite.c | 25 ++++++++++++++++++++++++- man/man8/xfs_io.8 | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-)
io/io.h +1 -0
@@ -25,6 +25,7 @@#define IO_RANDOM ( 0)#define IO_FORWARD ( 1)#define IO_BACKWARD (-1) +#define IO_ONCE ( 2)/* * File descriptor options
io/pwrite.c +24 -1
@@ -47,6 +47,7 @@ pwrite_help(void)" -W -- call fsync(2) at the end (included in timing results)\n" " -B -- write backwards through the range from offset (backwards N bytes)\n" " -F -- write forwards through the range of bytes from offset (default)\n" +" -O -- perform pwrite call once and return (maybe partial) bytes written\n" " -R -- write at random offsets in the specified range of bytes\n" " -Z N -- zeed the random number generator (used when writing randomly)\n" " (heh, zorry, the -s/-S arguments were already in use in pwrite)\n"
@@ -258,6 +259,22 @@ write_buffer(return ops; } +static int +write_once ( +off64_t offset, +long long count, +long long *total, +int pwritev2_flags) +{ +size_t bytes; + bytes =do_pwrite (file->fd, offset, count, count, pwritev2_flags); +if (bytes <0 ) +return -1 ; + *total = bytes; +return 1 ; +} + + static int pwrite_f( int argc,
@@ -279,7 +296,7 @@ pwrite_f(init_cvtnum (&fsblocksize, &fssectsize); bsize = fsblocksize; -while ((c =getopt (argc, argv,"b:BCdf:Fi:NqRs:S:uV:wWZ:" )) !=EOF ) { +while ((c =getopt (argc, argv,"b:BCdf:Fi:NqRs:OS:uV:wWZ:" )) !=EOF ) {switch (c) {case 'b' : tmp =cvtnum (fsblocksize, fssectsize, optarg);
@@ -301,6 +318,9 @@ pwrite_f(case 'R' : direction =IO_RANDOM ;break ; +case 'O' : + direction =IO_ONCE ; +break ;case 'd' : dflag =1 ;break ;
@@ -392,6 +412,9 @@ pwrite_f(case IO_BACKWARD : c =write_backward (offset, &count, &total, pwritev2_flags);break ; +case IO_ONCE : + c =write_once (offset, count, &total, pwritev2_flags); +break ;default : total =0 ;ASSERT (0 );
man/man8/xfs_io.8 +3 -0
@@ -263,6 +263,9 @@ write the buffers in a reserve sequential direction. .B \-R write the buffers in the give range in a random order. .TP +.B \-O +perform pwrite once and return the (maybe partial) bytes written. +.TP .B \-Z seed specify the random number seed used for random write .TP
Signature · 1 line
2.14.1
Re: [PATCH v2 3/3] xfs_io: Allow partial writes
Quoted 8 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Partial writes are performed when there is an error midway while performing the I/O. Perform the write exactly once and return the number of bytes written so far, until the error.
Signed-off-by Goldwyn Rodrigues <[email protected]>---
Quoted 102 lines
io/io.h | 1 + io/pwrite.c | 25 ++++++++++++++++++++++++- man/man8/xfs_io.8 | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-)io/io.h +1
-0@@ -25,6 +25,7 @@#define IO_RANDOM ( 0)#define IO_FORWARD ( 1)#define IO_BACKWARD (-1) +#define IO_ONCE ( 2)/* * File descriptor options io/pwrite.c +24
-1@@ -47,6 +47,7 @@ pwrite_help(void)" -W -- call fsync(2) at the end (included in timing results)\n" " -B -- write backwards through the range from offset (backwards N bytes)\n" " -F -- write forwards through the range of bytes from offset (default)\n" +" -O -- perform pwrite call once and return (maybe partial) bytes written\n" " -R -- write at random offsets in the specified range of bytes\n" " -Z N -- zeed the random number generator (used when writing randomly)\n" " (heh, zorry, the -s/-S arguments were already in use in pwrite)\n" @@ -258,6 +259,22 @@ write_buffer(return ops; } +static int +write_once ( +off64_t offset, +long long count, +long long *total, +int pwritev2_flags) +{ +size_t bytes; + bytes =do_pwrite (file->fd, offset, count, count, pwritev2_flags); +if (bytes <0 ) +return -1 ; + *total = bytes; +return 1 ; +} + + static int pwrite_f( int argc,@@ -279,7 +296,7 @@ pwrite_f(init_cvtnum (&fsblocksize, &fssectsize); bsize = fsblocksize; -while ((c =getopt (argc, argv,"b:BCdf:Fi:NqRs:S:uV:wWZ:" )) !=EOF ) { +while ((c =getopt (argc, argv,"b:BCdf:Fi:NqRs:OS:uV:wWZ:" )) !=EOF ) {switch (c) {case 'b' : tmp =cvtnum (fsblocksize, fssectsize, optarg);@@ -301,6 +318,9 @@ pwrite_f(case 'R' : direction =IO_RANDOM ;break ; +case 'O' : + direction =IO_ONCE ; +break ;case 'd' : dflag =1 ;break ;@@ -392,6 +412,9 @@ pwrite_f(case IO_BACKWARD : c =write_backward (offset, &count, &total, pwritev2_flags);break ; +case IO_ONCE : + c =write_once (offset, count, &total, pwritev2_flags); +break ;default : total =0 ;ASSERT (0 );man/man8/xfs_io.8 +3
-0@@ -263,6 +263,9 @@ write the buffers in a reserve sequential direction. .B \-R write the buffers in the give range in a random order. .TP +.B \-O +perform pwrite once and return the (maybe partial) bytes written. +.TP .B \-Z seed specify the random number seed used for random write .TPSignature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 3/3] xfs_io: Allow partial writes
In reply to Goldwyn RodriguesQuoted 7 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Partial writes are performed when there is an error midway while performing the I/O. Perform the write exactly once and return the number of bytes written so far, until the error.
Signed-off-by Goldwyn Rodrigues <[email protected]>
Looks ok,
Quoted 103 lines
--- io/io.h | 1 + io/pwrite.c | 25 ++++++++++++++++++++++++- man/man8/xfs_io.8 | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-)io/io.h +1
-0@@ -25,6 +25,7 @@#define IO_RANDOM ( 0)#define IO_FORWARD ( 1)#define IO_BACKWARD (-1) +#define IO_ONCE ( 2)/* * File descriptor options io/pwrite.c +24
-1@@ -47,6 +47,7 @@ pwrite_help(void)" -W -- call fsync(2) at the end (included in timing results)\n" " -B -- write backwards through the range from offset (backwards N bytes)\n" " -F -- write forwards through the range of bytes from offset (default)\n" +" -O -- perform pwrite call once and return (maybe partial) bytes written\n" " -R -- write at random offsets in the specified range of bytes\n" " -Z N -- zeed the random number generator (used when writing randomly)\n" " (heh, zorry, the -s/-S arguments were already in use in pwrite)\n" @@ -258,6 +259,22 @@ write_buffer(return ops; } +static int +write_once ( +off64_t offset, +long long count, +long long *total, +int pwritev2_flags) +{ +size_t bytes; + bytes =do_pwrite (file->fd, offset, count, count, pwritev2_flags); +if (bytes <0 ) +return -1 ; + *total = bytes; +return 1 ; +} + + static int pwrite_f( int argc,@@ -279,7 +296,7 @@ pwrite_f(init_cvtnum (&fsblocksize, &fssectsize); bsize = fsblocksize; -while ((c =getopt (argc, argv,"b:BCdf:Fi:NqRs:S:uV:wWZ:" )) !=EOF ) { +while ((c =getopt (argc, argv,"b:BCdf:Fi:NqRs:OS:uV:wWZ:" )) !=EOF ) {switch (c) {case 'b' : tmp =cvtnum (fsblocksize, fssectsize, optarg);@@ -301,6 +318,9 @@ pwrite_f(case 'R' : direction =IO_RANDOM ;break ; +case 'O' : + direction =IO_ONCE ; +break ;case 'd' : dflag =1 ;break ;@@ -392,6 +412,9 @@ pwrite_f(case IO_BACKWARD : c =write_backward (offset, &count, &total, pwritev2_flags);break ; +case IO_ONCE : + c =write_once (offset, count, &total, pwritev2_flags); +break ;default : total =0 ;ASSERT (0 );man/man8/xfs_io.8 +3
-0@@ -263,6 +263,9 @@ write the buffers in a reserve sequential direction. .B \-R write the buffers in the give range in a random order. .TP +.B \-O +perform pwrite once and return the (maybe partial) bytes written. +.TP .B \-Z seed specify the random number seed used for random write .TPSignature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi,
Any response/review comments to these patches?
I have two fstests waiting for these patches to be incorporated.
Signature · 1 line
Goldwyn
Quoted 214 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Signed-off-by Goldwyn Rodrigues <[email protected]>--- configure.ac | 1 + include/builddefs.in | 1 + io/Makefile | 4 ++++ io/pwrite.c | 39 ++++++++++++++++++++++++++------------- m4/package_libcdev.m4 | 16 ++++++++++++++++ 5 files changed, 48 insertions(+), 13 deletions(-)configure.ac +1
-0@@ -132,6 +132,7 @@ AC_HAVE_GETMNTENT AC_HAVE_GETMNTINFO AC_HAVE_FALLOCATE AC_HAVE_FIEMAP +AC_HAVE_PWRITEV2 AC_HAVE_PREADV AC_HAVE_COPY_FILE_RANGE AC_HAVE_SYNC_FILE_RANGEinclude/builddefs.in +1
-0@@ -103,6 +103,7 @@ HAVE_GETMNTINFO = @have_getmntinfo@ HAVE_FALLOCATE = @have_fallocate@ HAVE_FIEMAP = @have_fiemap@ HAVE_PREADV = @have_preadv@ +HAVE_PWRITEV2 = @have_pwritev2@ HAVE_COPY_FILE_RANGE = @have_copy_file_range@ HAVE_SYNC_FILE_RANGE = @have_sync_file_range@ HAVE_SYNCFS = @have_syncfs@io/Makefile +4
-0@@ -90,6 +90,10 @@ ifeq ($(HAVE_PREADV),yes) LCFLAGS += -DHAVE_PREADV -DHAVE_PWRITEV endif +ifeq ($(HAVE_PWRITEV2),yes) +LCFLAGS += -DHAVE_PWRITEV2 +endif + ifeq ($(HAVE_READDIR),yes) CFILES += readdir.c LCFLAGS += -DHAVE_READDIRio/pwrite.c +26
-13@@ -62,7 +62,8 @@ do_pwritev(int fd, off64_t offset, ssize_t count, - ssize_t buffer_size) + ssize_t buffer_size, + int pwritev2_flags) { int vecs = 0;ssize_t oldlen =0 ;@@ -81,7 +82,14 @@ do_pwritev( }else { vecs = vectors; } +#ifdef HAVE_PWRITEV2 +if (pwritev2_flags) + bytes =pwritev2 (fd, iov, vectors, offset, pwritev2_flags); +else + bytes =pwritev (fd, iov, vectors, offset); +#else bytes =pwritev (fd, iov, vectors, offset); +#endif /* restore trimmed iov */ if (oldlen)@@ -98,12 +106,13 @@ do_pwrite(int fd, off64_t offset, ssize_t count, - ssize_t buffer_size) + ssize_t buffer_size, + int pwritev2_flags) { if (!vectors) return pwrite(fd, buffer, min(count, buffer_size), offset); -return do_pwritev (fd, offset, count, buffer_size); +return do_pwritev (fd, offset, count, buffer_size, pwritev2_flags); } static int@@ -111,7 +120,8 @@ write_random(off64_t offset, long long count, unsigned int seed, - long long *total) + long long *total, + int pwritev2_flags) { off64_t off, range;ssize_t bytes;@@ -133,7 +143,7 @@ write_random( buffersize; else off = offset; - bytes =do_pwrite (file->fd, off, buffersize, buffersize); + bytes =do_pwrite (file->fd, off, buffersize, buffersize, pwritev2_flags);if (bytes ==0 )break ;if (bytes <0 ) {@@ -153,7 +163,8 @@ static intwrite_backward ( off64_t offset, long long *count, - long long *total) + long long *total, + int pwritev2_flags) { off64_t end, off = offset;ssize_t bytes =0 , bytes_requested;@@ -171,7 +182,7 @@ write_backward(if ((bytes_requested = (off % buffersize))) { bytes_requested =min (cnt, bytes_requested); off -= bytes_requested; - bytes =do_pwrite (file->fd, off, bytes_requested, buffersize); + bytes =do_pwrite (file->fd, off, bytes_requested, buffersize, pwritev2_flags);if (bytes ==0 )return ops;if (bytes <0 ) {@@ -189,7 +200,7 @@ write_backward(while (cnt > end) { bytes_requested =min (cnt, buffersize); off -= bytes_requested; - bytes =do_pwrite (file->fd, off, cnt, buffersize); + bytes =do_pwrite (file->fd, off, cnt, buffersize, pwritev2_flags);if (bytes ==0 )break ;if (bytes <0 ) {@@ -212,7 +223,8 @@ write_buffer(size_t bs, int fd, off64_t skip, - long long *total) + long long *total, + int pwritev2_flags) { ssize_t bytes;long long bar =min (bs, count);@@ -224,7 +236,7 @@ write_buffer(if (read_buffer (fd, skip + *total, bs, &bar,0 ,1 ) <0 )break ; } - bytes =do_pwrite (file->fd, offset, count, bar); + bytes =do_pwrite (file->fd, offset, count, bar, pwritev2_flags);if (bytes ==0 )break ;if (bytes <0 ) {@@ -258,6 +270,7 @@ pwrite_f(int Cflag, qflag, uflag, dflag, wflag, Wflag;int direction =IO_FORWARD ;int c, fd =-1 ; +int pwritev2_flags =0 ; Cflag = qflag = uflag = dflag = wflag = Wflag =0 ;init_cvtnum (&fsblocksize, &fssectsize);@@ -365,13 +378,13 @@ pwrite_f(case IO_RANDOM :if (!zeed)/* srandom seed */ zeed =time (NULL ); - c =write_random (offset, count, zeed, &total); + c =write_random (offset, count, zeed, &total, pwritev2_flags);break ;case IO_FORWARD : - c =write_buffer (offset, count, bsize, fd, skip, &total); + c =write_buffer (offset, count, bsize, fd, skip, &total, pwritev2_flags);break ;case IO_BACKWARD : - c =write_backward (offset, &count, &total); + c =write_backward (offset, &count, &total, pwritev2_flags);break ;default : total =0 ;m4/package_libcdev.m4 +16
-0@@ -146,6 +146,22 @@ AC_DEFUN([AC_HAVE_PREADV], AC_SUBST(have_preadv) ]) +# +# Check if we have a pwritev2 libc call (Linux) +# +AC_DEFUN([AC_HAVE_PWRITEV2], + [ AC_MSG_CHECKING([for pwritev2]) + AC_TRY_LINK([ +#define _BSD_SOURCE +#include <sys/uio.h> + ], [ + pwritev2(0, 0, 0, 0, 0); + ], have_pwritev2=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_pwritev2) + ]) + # # Check if we have a copy_file_range system call (Linux) #
Signature · 1 line
Goldwyn
Quoted 11 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Signed-off-by Goldwyn Rodrigues <[email protected]>--- configure.ac | 1 + include/builddefs.in | 1 + io/Makefile | 4 ++++ io/pwrite.c | 39 ++++++++++++++++++++++++++------------- m4/package_libcdev.m4 | 16 ++++++++++++++++ 5 files changed, 48 insertions(+), 13 deletions(-)
...
Quoted 4 lines
io/pwrite.c +0
-0
...
Quoted 11 lines
io/pwrite.c +2
-1@@ -111,7 +120,8 @@ write_random(off64_t offset, long long count, unsigned int seed, - long long *total) + long long *total, + int pwritev2_flags) { off64_t off, range;ssize_t bytes;
io/pwrite.c write_random( · line 146
Quoted 5 lines
io/pwrite.c +1
-1@@ -133,7 +143,7 @@ write_random( buffersize; else off = offset; - bytes =do_pwrite (file->fd, off, buffersize, buffersize); + bytes =do_pwrite (file->fd, off, buffersize, buffersize, pwritev2_flags);
Looks like a couple or so long lines here and below. We usually wrap lines at 80 chars. Otherwise this seems fine to me.
Brian
Quoted 109 lines
io/pwrite.c +11
-8if (bytes ==0 )break ;if (bytes <0 ) {@@ -153,7 +163,8 @@ static intwrite_backward ( off64_t offset, long long *count, - long long *total) + long long *total, + int pwritev2_flags) { off64_t end, off = offset;ssize_t bytes =0 , bytes_requested;@@ -171,7 +182,7 @@ write_backward(if ((bytes_requested = (off % buffersize))) { bytes_requested =min (cnt, bytes_requested); off -= bytes_requested; - bytes =do_pwrite (file->fd, off, bytes_requested, buffersize); + bytes =do_pwrite (file->fd, off, bytes_requested, buffersize, pwritev2_flags);if (bytes ==0 )return ops;if (bytes <0 ) {@@ -189,7 +200,7 @@ write_backward(while (cnt > end) { bytes_requested =min (cnt, buffersize); off -= bytes_requested; - bytes =do_pwrite (file->fd, off, cnt, buffersize); + bytes =do_pwrite (file->fd, off, cnt, buffersize, pwritev2_flags);if (bytes ==0 )break ;if (bytes <0 ) {@@ -212,7 +223,8 @@ write_buffer(size_t bs, int fd, off64_t skip, - long long *total) + long long *total, + int pwritev2_flags) { ssize_t bytes;long long bar =min (bs, count);@@ -224,7 +236,7 @@ write_buffer(if (read_buffer (fd, skip + *total, bs, &bar,0 ,1 ) <0 )break ; } - bytes =do_pwrite (file->fd, offset, count, bar); + bytes =do_pwrite (file->fd, offset, count, bar, pwritev2_flags);if (bytes ==0 )break ;if (bytes <0 ) {@@ -258,6 +270,7 @@ pwrite_f(int Cflag, qflag, uflag, dflag, wflag, Wflag;int direction =IO_FORWARD ;int c, fd =-1 ; +int pwritev2_flags =0 ; Cflag = qflag = uflag = dflag = wflag = Wflag =0 ;init_cvtnum (&fsblocksize, &fssectsize);@@ -365,13 +378,13 @@ pwrite_f(case IO_RANDOM :if (!zeed)/* srandom seed */ zeed =time (NULL ); - c =write_random (offset, count, zeed, &total); + c =write_random (offset, count, zeed, &total, pwritev2_flags);break ;case IO_FORWARD : - c =write_buffer (offset, count, bsize, fd, skip, &total); + c =write_buffer (offset, count, bsize, fd, skip, &total, pwritev2_flags);break ;case IO_BACKWARD : - c =write_backward (offset, &count, &total); + c =write_backward (offset, &count, &total, pwritev2_flags);break ;default : total =0 ;m4/package_libcdev.m4 +16
-0@@ -146,6 +146,22 @@ AC_DEFUN([AC_HAVE_PREADV], AC_SUBST(have_preadv) ]) +# +# Check if we have a pwritev2 libc call (Linux) +# +AC_DEFUN([AC_HAVE_PWRITEV2], + [ AC_MSG_CHECKING([for pwritev2]) + AC_TRY_LINK([ +#define _BSD_SOURCE +#include <sys/uio.h> + ], [ + pwritev2(0, 0, 0, 0, 0); + ], have_pwritev2=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_pwritev2) + ]) + # # Check if we have a copy_file_range system call (Linux) #Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html