]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: Allow partial writes
authorGoldwyn Rodrigues <rgoldwyn@suse.com>
Thu, 9 Nov 2017 20:56:29 +0000 (14:56 -0600)
committerEric Sandeen <sandeen@redhat.com>
Thu, 9 Nov 2017 20:56:29 +0000 (14:56 -0600)
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 <rgoldwyn@suse.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
[sandeen@sandeen.net: add O to short help]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
io/io.h
io/pwrite.c
man/man8/xfs_io.8

diff --git a/io/io.h b/io/io.h
index 6a0fe657b24dd397e0f2b8b2a2f16f58baa7dc8d..3862985fc337089658723952a42833aa112bb23c 100644 (file)
--- a/io/io.h
+++ b/io/io.h
@@ -25,6 +25,7 @@
 #define IO_RANDOM      ( 0)
 #define IO_FORWARD     ( 1)
 #define IO_BACKWARD    (-1)
+#define IO_ONCE                ( 2)
 
 /*
  * File descriptor options
index c36a661a87c5646daa8d3958c3ae042068e8e374..26f79579e668eebc99fab075e9f25c1eea18e2e6 100644 (file)
@@ -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"
@@ -261,6 +262,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,
@@ -282,7 +299,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);
@@ -304,6 +321,9 @@ pwrite_f(
                case 'R':
                        direction = IO_RANDOM;
                        break;
+               case 'O':
+                       direction = IO_ONCE;
+                       break;
                case 'd':
                        dflag = 1;
                        break;
@@ -405,6 +425,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);
@@ -446,7 +469,7 @@ pwrite_init(void)
        pwrite_cmd.argmax = -1;
        pwrite_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
        pwrite_cmd.args =
-_("[-i infile [-dwNW] [-s skip]] [-b bs] [-S seed] [-FBR [-Z N]] [-V N] off len");
+_("[-i infile [-dwNOW] [-s skip]] [-b bs] [-S seed] [-FBR [-Z N]] [-V N] off len");
        pwrite_cmd.oneline =
                _("writes a number of bytes at a specified offset");
        pwrite_cmd.help = pwrite_help;
index c2fe6aae7537b898033919c80b09fd2f1e02530c..9bf1a4783c4f26db12b6ede2aa7f1cd47e4dc826 100644 (file)
@@ -222,7 +222,7 @@ See the
 .B pread
 command.
 .TP
-.BI "pwrite [ \-i " file " ] [ \-dwNW ] [ \-s " skip " ] [ \-b " size " ] [ \-S " seed " ] [ \-FBR [ \-Z " zeed " ] ] [ \-V " vectors " ] " "offset length"
+.BI "pwrite [ \-i " file " ] [ \-dwNOW ] [ \-s " skip " ] [ \-b " size " ] [ \-S " seed " ] [ \-FBR [ \-Z " zeed " ] ] [ \-V " vectors " ] " "offset length"
 Writes a range of bytes in a specified blocksize from the given
 .IR offset .
 The bytes written can be either a set pattern or read in from another
@@ -250,6 +250,9 @@ Perform the
 call with
 .I RWF_NOWAIT.
 .TP
+.B \-O
+perform pwrite once and return the (maybe partial) bytes written.
+.TP
 .B \-W
 call
 .BR fsync (2)