]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: Add RWF_DONTCACHE support to pwritev2
authorRitesh Harjani (IBM) <ritesh.list@gmail.com>
Sat, 15 Mar 2025 08:20:12 +0000 (13:50 +0530)
committerAndrey Albershteyn <aalbersh@kernel.org>
Mon, 31 Mar 2025 08:03:56 +0000 (10:03 +0200)
Add per-io RWF_DONTCACHE support flag to pwritev2().
This enables xfs_io to perform uncached buffered-io writes.

e.g. xfs_io -fc "pwrite -U -V 1 0 16K" /mnt/f1

Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Reviewed-by: Jens Axboe <axboe@kernel.dk>
include/linux.h
io/pwrite.c
man/man8/xfs_io.8

index b3516d54c51b175325645e88ea26b13d01b48673..6e83e073aa2eb4c8c907a0d20a0596d5d9f4629b 100644 (file)
@@ -237,6 +237,11 @@ struct fsxattr {
 #define RWF_ATOMIC     ((__kernel_rwf_t)0x00000040)
 #endif
 
+/* buffered IO that drops the cache after reading or writing data */
+#ifndef RWF_DONTCACHE
+#define RWF_DONTCACHE  ((__kernel_rwf_t)0x00000080)
+#endif
+
 /*
  * Reminder: anything added to this file will be compiled into downstream
  * userspace projects!
index fab59be40a4d24e4db9f00cf3d32683205abbc56..7df71e235d102f33469637f68dc675d90c3a93b1 100644 (file)
@@ -45,6 +45,7 @@ pwrite_help(void)
 " -N   -- Perform the pwritev2() with RWF_NOWAIT\n"
 " -D   -- Perform the pwritev2() with RWF_DSYNC\n"
 " -A   -- Perform the pwritev2() with RWF_ATOMIC\n"
+" -U   -- Perform the pwritev2() with RWF_DONTCACHE\n"
 #endif
 "\n"));
 }
@@ -285,7 +286,7 @@ pwrite_f(
        init_cvtnum(&fsblocksize, &fssectsize);
        bsize = fsblocksize;
 
-       while ((c = getopt(argc, argv, "Ab:BCdDf:Fi:NqRs:OS:uV:wWZ:")) != EOF) {
+       while ((c = getopt(argc, argv, "Ab:BCdDf:Fi:NqRs:OS:uUV:wWZ:")) != EOF) {
                switch (c) {
                case 'b':
                        tmp = cvtnum(fsblocksize, fssectsize, optarg);
@@ -328,6 +329,9 @@ pwrite_f(
                case 'A':
                        pwritev2_flags |= RWF_ATOMIC;
                        break;
+               case 'U':
+                       pwritev2_flags |= RWF_DONTCACHE;
+                       break;
 #endif
                case 's':
                        skip = cvtnum(fsblocksize, fssectsize, optarg);
@@ -392,6 +396,12 @@ pwrite_f(
                exitcode = 1;
                return command_usage(&pwrite_cmd);
        }
+       if (pwritev2_flags != 0 && vectors == 0) {
+               printf(_("pwritev2 flags require vectored I/O (-V)\n"));
+               exitcode = 1;
+               return command_usage(&pwrite_cmd);
+       }
+
        offset = cvtnum(fsblocksize, fssectsize, argv[optind]);
        if (offset < 0) {
                printf(_("non-numeric offset argument -- %s\n"), argv[optind]);
@@ -480,7 +490,7 @@ pwrite_init(void)
        pwrite_cmd.argmax = -1;
        pwrite_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
        pwrite_cmd.args =
-_("[-i infile [-qAdDwNOW] [-s skip]] [-b bs] [-S seed] [-FBR [-Z N]] [-V N] off len");
+_("[-i infile [-qAdDwNOUW] [-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 59d5ddc54dcc6674ac9da50d2b26eb909197648c..47af523256999ea16b7ddb2fa1b62f680b04984a 100644 (file)
@@ -244,7 +244,7 @@ See the
 .B pread
 command.
 .TP
-.BI "pwrite [ \-i " file " ] [ \-qAdDwNOW ] [ \-s " skip " ] [ \-b " size " ] [ \-S " seed " ] [ \-FBR [ \-Z " zeed " ] ] [ \-V " vectors " ] " "offset length"
+.BI "pwrite [ \-i " file " ] [ \-qAdDwNOUW ] [ \-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
@@ -287,6 +287,12 @@ Perform the
 call with
 .IR RWF_ATOMIC .
 .TP
+.B \-U
+Perform the
+.BR pwritev2 (2)
+call with
+.IR RWF_DONTCACHE .
+.TP
 .B \-O
 perform pwrite once and return the (maybe partial) bytes written.
 .TP