bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] fts: introduce FTS_NOATIME


From: Eric Blake
Subject: [PATCH] fts: introduce FTS_NOATIME
Date: Thu, 7 Jul 2011 11:41:29 -0600

This gives clients the option to try a non-invasive traversal,
where merely visiting a directory does not update its timestamp,
where such is supported by the kernel.

Note that whiteout support and O_NOATIME support are orthogonal:
there is no way to get O_NOATIME behavior when using __opendir2
to visit whiteouts on BSD systems.

* lib/fts_.h (FTS_NOATIME): New bit flag.
(FTS_OPTIONMASK): Adjust.
* lib/fts.c (diropen, fts_open, fts_build): Honor it.
(fd_ring_check): Debug code unconditionally uses O_NOATIME.
Needed for findutils bug http://savannah.gnu.org/bugs/?33724

Signed-off-by: Eric Blake <address@hidden>
---

Does this look correct?

 ChangeLog  |    6 ++++++
 lib/fts.c  |   17 ++++++++++-------
 lib/fts_.h |    4 +++-
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index dbf0bea..1dfa2b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2011-07-07  Eric Blake  <address@hidden>

+       fts: introduce FTS_NOATIME
+       * lib/fts_.h (FTS_NOATIME): New bit flag.
+       (FTS_OPTIONMASK): Adjust.
+       * lib/fts.c (diropen, fts_open, fts_build): Honor it.
+       (fd_ring_check): Debug code unconditionally uses O_NOATIME.
+
        getopt: avoid compiler warning during configure
        * m4/getopt.m4 (gl_GETOPT_CHECK_HEADRS): Avoid problems with
        assigning string literals to non-const pointer.
diff --git a/lib/fts.c b/lib/fts.c
index d3ad1cd..7210c1b 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -349,7 +349,8 @@ internal_function
 diropen (FTS const *sp, char const *dir)
 {
   int open_flags = (O_SEARCH | O_DIRECTORY | O_NOCTTY | O_NONBLOCK
-                    | (ISSET (FTS_PHYSICAL) ? O_NOFOLLOW : 0));
+                    | (ISSET (FTS_PHYSICAL) ? O_NOFOLLOW : 0)
+                    | (ISSET (FTS_NOATIME) ? O_NOATIME : 0));

   int fd = (ISSET (FTS_CWDFD)
             ? openat (sp->fts_cwd_fd, dir, open_flags)
@@ -406,7 +407,8 @@ fts_open (char * const *argv,
                early, doing it here saves us the trouble of ensuring
                later (where it'd be messier) that "." can in fact
                be opened.  If not, revert to FTS_NOCHDIR mode.  */
-            int fd = open (".", O_SEARCH);
+            int fd = open (".",
+                           O_SEARCH | (ISSET (FTS_NOATIME) ? O_NOATIME : 0));
             if (fd < 0)
               {
                 /* Even if `.' is unreadable, don't revert to FTS_NOCHDIR mode
@@ -1241,10 +1243,11 @@ fts_build (register FTS *sp, int type)
         opendirat((! ISSET(FTS_NOCHDIR) && ISSET(FTS_CWDFD)     \
                    ? sp->fts_cwd_fd : AT_FDCWD),                \
                   file,                                         \
-                  ((ISSET(FTS_PHYSICAL)                         \
-                    && ! (ISSET(FTS_COMFOLLOW)                  \
-                          && cur->fts_level == FTS_ROOTLEVEL))  \
-                   ? O_NOFOLLOW : 0),                           \
+                  (((ISSET(FTS_PHYSICAL)                        \
+                     && ! (ISSET(FTS_COMFOLLOW)                 \
+                           && cur->fts_level == FTS_ROOTLEVEL)) \
+                    ? O_NOFOLLOW : 0)                           \
+                   | (ISSET (FTS_NOATIME) ? O_NOATIME : 0)),    \
                   &dir_fd)
 #endif
        if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) {
@@ -1653,7 +1656,7 @@ fd_ring_check (FTS const *sp)
       int fd = i_ring_pop (&fd_w);
       if (0 <= fd)
         {
-          int parent_fd = openat (cwd_fd, "..", O_SEARCH);
+          int parent_fd = openat (cwd_fd, "..", O_SEARCH | O_NOATIME);
           if (parent_fd < 0)
             {
               // Warn?
diff --git a/lib/fts_.h b/lib/fts_.h
index 6a22bec..fe92cfd 100644
--- a/lib/fts_.h
+++ b/lib/fts_.h
@@ -142,7 +142,9 @@ typedef struct {
      dirent.d_type data.  */
 # define FTS_DEFER_STAT         0x0400

-# define FTS_OPTIONMASK 0x07ff          /* valid user option mask */
+# define FTS_NOATIME    0x0800          /* use O_NOATIME during traversal */
+
+# define FTS_OPTIONMASK 0x0fff          /* valid user option mask */

 # define FTS_NAMEONLY   0x1000          /* (private) child names only */
 # define FTS_STOP       0x2000          /* (private) unrecoverable error */
-- 
1.7.4.4




reply via email to

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