coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 4/4] stat: support statx DONT_SYNC and FORCE_SYNC flags


From: Jeff Layton
Subject: [PATCH v2 4/4] stat: support statx DONT_SYNC and FORCE_SYNC flags
Date: Sat, 13 Apr 2019 08:50:15 -0400

Add two new command-line options that set the appropriate hint flags in
the statx call. These are primarily used with network filesystems to
indicate what level of cache coherency the application can tolerate.
The new options are only implemented when built with HAVE_STATX.

* NEWS: mention the enhancements
* src/stat.c: add new options to control synchronization with server
---
 NEWS       |  8 ++++++++
 src/stat.c | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/NEWS b/NEWS
index 6844228bef9f..f8de29a397ab 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,14 @@ GNU coreutils NEWS                                    -*- 
outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** New Features
+
+   stat now uses the statx() system call to do its bidding when it is
+   available. It will craft a statx mask with only the needed attributes.
+   When built with statx support, it also supports new command line
+   options to control synchronization with the server on network
+   filesytems.
+
 ** Bug fixes
 
   factor again outputs immediately when stdout is a tty but stdin is not.
diff --git a/src/stat.c b/src/stat.c
index cfa78f256968..86e44bde5898 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -201,6 +201,10 @@ static struct option const long_options[] =
   {"format", required_argument, NULL, 'c'},
   {"printf", required_argument, NULL, PRINTF_OPTION},
   {"terse", no_argument, NULL, 't'},
+#if HAVE_STATX && defined STATX_INO
+  {"dont-sync", no_argument, NULL, 'D' },
+  {"force-sync", no_argument, NULL, 'F' },
+#endif
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
   {NULL, 0, NULL, 0}
@@ -1200,6 +1204,12 @@ do_statfs (char const *filename, char const *format)
 }
 
 #if HAVE_STATX && defined STATX_INO
+/* Ask statx to avoid syncing? */
+static bool dont_sync;
+
+/* Ask statx to force sync? */
+static bool force_sync;
+
 struct printarg {
   struct statx *stx;
   struct stat *st;
@@ -1471,6 +1481,11 @@ do_stat (char const *filename, char const *format, char 
const *format2)
       flags = AT_SYMLINK_NOFOLLOW;
     }
 
+  if (dont_sync)
+    flags |= AT_STATX_DONT_SYNC;
+  else if (force_sync)
+    flags |= AT_STATX_FORCE_SYNC;
+
   fd = statx(fd, filename, flags, format_to_mask(format), &stx);
   if (fd < 0)
     {
@@ -1799,6 +1814,12 @@ Display file or file system status.\n\
   -L, --dereference     follow links\n\
   -f, --file-system     display file system status instead of file status\n\
 "), stdout);
+#if HAVE_STATX && defined STATX_INO
+      fputs (_("\
+  -D, --dont-sync      don't synchronize with server (for network fs')\n\
+  -F, --force-sync     force synchronization with server (for network fs')\n\
+"), stdout);
+#endif
       fputs (_("\
   -c  --format=FORMAT   use the specified FORMAT instead of the default;\n\
                           output a newline after each use of FORMAT\n\
@@ -1931,6 +1952,26 @@ main (int argc, char *argv[])
           trailing_delim = "\n";
           break;
 
+#if HAVE_STATX && defined STATX_INO
+       case 'D':
+         if (force_sync)
+            {
+              error (0, 0, _("--dont-sync and --force-sync are mutually 
exclusive"));
+              usage (EXIT_FAILURE);
+            }
+         dont_sync = true;
+         break;
+
+       case 'F':
+         if (dont_sync)
+            {
+              error (0, 0, _("--dont-sync and --force-sync are mutually 
exclusive"));
+              usage (EXIT_FAILURE);
+            }
+         force_sync = true;
+         break;
+#endif
+
         case 'L':
           follow_links = true;
           break;
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]