bug-tar
[Top][All Lists]
Advanced

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

[Bug-tar] [patch] O_NOATIME support


From: Ian Turner
Subject: [Bug-tar] [patch] O_NOATIME support
Date: Mon, 19 Sep 2005 17:28:38 -0700
User-agent: Mozilla Thunderbird 1.0.6-1.1.fc3 (X11/20050720)

Hello all,

Attached is a patch to add O_NOATIME support to GNU tar. This allows one to make backups without changing atime, mtime, or ctime on regular files. O_NOATIME requires kernel 2.6.8 or greater, along with appropriate system headers, but this patch will still compile without those things.

O_NOATIME doesn't work if you aren't the owner of the file in question (or root), if the file is on an unsupported filesystem (like NFS), or if the file is a symlink.

Because of these limitations, and because of the very different side-effects, I have added a new option --no-atime, rather than extend the existing --preserve-atime option. The option exists (as a no-op), even if configure did not find required system headers. --no-atime does not at present interact with --preserve-atime (though you can use them both); it might be useful to do the "best thing" if the user specifies both, but at present it is impossible to know if O_NOATIME is actually working, at least under certain circumstances.

Comments are appreciated. Let me know if you have any criticisms, or if there is something else I must to do get this patch into the distribution.

Cheers,

--Ian Turner
diff -aur --exclude='*~' --exclude=aclocal.m4 --exclude=config.hin 
--exclude=configure --exclude=Makefile.in tar-1.15.1/configure.ac 
tar-1.15.1-noatime/configure.ac
--- tar-1.15.1/configure.ac     2004-12-21 05:29:02.000000000 -0800
+++ tar-1.15.1-noatime/configure.ac     2005-09-19 15:15:34.000000000 -0700
@@ -114,6 +114,16 @@
 AC_CHECK_DECLS([getpwuid],,, [#include <pwd.h>])
 AC_CHECK_DECLS([time],,, [#include <time.h>])
 
+# Check for O_NOATIME
+AC_CHECK_DECL(O_NOATIME,
+             [AC_DEFINE([HAVE_O_NOATIME], [], [Existence of fcntl.h])],
+              [AC_DEFINE([O_NOATIME], [(0)],
+                         [Substitute for missung system O_NOATIME])],
+[#if HAVE_FCNTL_H
+#  include <fcntl.h>
+# endif
+])
+
 # Set LIB_SETSOCKOPT to -lnsl -lsocket if necessary.
 tar_save_LIBS=$LIBS
   LIB_SETSOCKOPT=
diff -aur --exclude='*~' --exclude=aclocal.m4 --exclude=config.hin 
--exclude=configure --exclude=Makefile.in tar-1.15.1/doc/tar.texi 
tar-1.15.1-noatime/doc/tar.texi
--- tar-1.15.1/doc/tar.texi     2004-12-18 11:20:19.000000000 -0800
+++ tar-1.15.1-noatime/doc/tar.texi     2005-09-19 14:34:18.000000000 -0700
@@ -306,6 +306,11 @@
 @set xref-newer-mtime @xref{after}
 @set pxref-newer-mtime @pxref{after}
 
address@hidden op-no-atime @kbd{--no-atime}
address@hidden ref-no-atime @ref{Attributes}
address@hidden xref-no-atime @xref{Attributes}
address@hidden pxref-no-atime @pxref{Attributes}
+
 @set op-no-recursion @kbd{--no-recursion}
 @set ref-no-recursion @ref{recurse}
 @set xref-no-recursion @xref{recurse}
@@ -2672,6 +2677,9 @@
 unless you're root.
 @FIXME-xref{}
 
+See also the @value{op-no-atime} option, which can avoid all these
+problems, but only with proper operating system support.
+
 @item address@hidden
 
 Rather than deleting files from the file system, @command{tar} will
@@ -2953,6 +2961,16 @@
 An exclude pattern can match any subsequence of the name's components.
 @FIXME-xref{}
 
address@hidden --no-atime
+
+If the operating system supports it, open files with the O_NOATIME flag,
+such that tar will not affect the atime of a dumped file. Does nothing
+on some platforms (Linux before 2.6.8), filesystems (NFS), or file
+types (symlinks).
+
+Compare with --atime-preserve, which modifies files' ctime, and
+creates a race condition with other readers.
+
 @item --no-ignore-case
 Use case-sensitive matching when excluding files.
 @FIXME-xref{}
@@ -7392,21 +7410,25 @@
 @UNREVISED
 
 When @command{tar} reads files, this causes them to have the access
-times updated.  To have @command{tar} attempt to set the access times
-back to what they were before they were read, use the
address@hidden option.
+times updated. To avoid this, use the @value{op-atime-preserve} or
address@hidden options, which respectively reset the atime
+retroactively or avoid changing it in the first place.
 
 Handling of file attributes
 
 @table @kbd
 @item --atime-preserve
-Preserve access times on files that are read.
+Reset access times on files that are read.
 This doesn't work for files that
-you don't own, unless you're root, and it doesn't interact with
+you don't own, unless you're root, and it resets the ctime instead --
+therefore it also doesn't interact with
 incremental dumps nicely (@pxref{Backups}), and it can set access or
 modification times incorrectly if other programs access the file while
 @command{tar} is running; but it is good enough for some purposes.
 
+See also the @value{op-no-atime} option, which avoids changing the
+atime in the first place, provided proper operating system support.
+
 @item -m
 @itemx --touch
 Do not extract file modified time.
diff -aur --exclude='*~' --exclude=aclocal.m4 --exclude=config.hin 
--exclude=configure --exclude=Makefile.in tar-1.15.1/src/common.h 
tar-1.15.1-noatime/src/common.h
--- tar-1.15.1/src/common.h     2004-12-21 06:31:58.000000000 -0800
+++ tar-1.15.1-noatime/src/common.h     2005-09-16 12:28:32.000000000 -0700
@@ -221,6 +221,9 @@
 
 GLOBAL bool numeric_owner_option;
 
+/* Should we open files with Linux's O_NOATIME option? */
+GLOBAL bool no_atime_option;
+
 GLOBAL bool one_file_system_option;
 
 /* Specified value to be put into tar file in place of stat () results, or
diff -aur --exclude='*~' --exclude=aclocal.m4 --exclude=config.hin 
--exclude=configure --exclude=Makefile.in tar-1.15.1/src/compare.c 
tar-1.15.1-noatime/src/compare.c
--- tar-1.15.1/src/compare.c    2004-09-06 04:30:29.000000000 -0700
+++ tar-1.15.1-noatime/src/compare.c    2005-09-16 12:27:53.000000000 -0700
@@ -263,7 +263,9 @@
          goto quit;
        }
 
-      diff_handle = open (current_stat_info.file_name, O_RDONLY | O_BINARY);
+      diff_handle = open (current_stat_info.file_name,
+                         O_RDONLY | O_BINARY |
+                         (no_atime_option ? O_NOATIME : 0));
 
       if (diff_handle < 0)
        {
diff -aur --exclude='*~' --exclude=aclocal.m4 --exclude=config.hin 
--exclude=configure --exclude=Makefile.in tar-1.15.1/src/create.c 
tar-1.15.1-noatime/src/create.c
--- tar-1.15.1/src/create.c     2004-10-04 02:21:31.000000000 -0700
+++ tar-1.15.1-noatime/src/create.c     2005-09-19 14:59:34.000000000 -0700
@@ -1423,7 +1423,8 @@
          if (file_dumpable_p (st))
            {
              fd = open (st->orig_file_name,
-                        O_RDONLY | O_BINARY);
+                        O_RDONLY | O_BINARY |
+                        ( no_atime_option ? O_NOATIME : 0));
              if (fd < 0)
                {
                  if (!top_level && errno == ENOENT)
diff -aur --exclude='*~' --exclude=aclocal.m4 --exclude=config.hin 
--exclude=configure --exclude=Makefile.in tar-1.15.1/src/tar.c 
tar-1.15.1-noatime/src/tar.c
--- tar-1.15.1/src/tar.c        2004-12-21 06:11:26.000000000 -0800
+++ tar-1.15.1-noatime/src/tar.c        2005-09-19 15:00:10.000000000 -0700
@@ -198,6 +198,7 @@
   MODE_OPTION,
   NEWER_MTIME_OPTION,
   NO_ANCHORED_OPTION,
+  NO_ATIME_OPTION,
   NO_IGNORE_CASE_OPTION,
   NO_OVERWRITE_DIR_OPTION,
   NO_RECURSION_OPTION,
@@ -333,11 +334,13 @@
   {"mode", MODE_OPTION, N_("CHANGES"), 0,
    N_("force (symbolic) mode CHANGES for added files"), 31 },
   {"atime-preserve", ATIME_PRESERVE_OPTION, 0, 0,
-   N_("don't change access times on dumped files"), 31 },
+   N_("reset access times on dumped files"), 31 },
   {"touch", 'm', 0, 0,
    N_("don't extract file modified time"), 31 },
   {"same-owner", SAME_OWNER_OPTION, 0, 0,
    N_("try extracting files with the same ownership"), 31 },
+  {"no-atime", ATIME_PRESERVE_OPTION, 0, 0,
+   N_("don't change access times on dumped files"), 31 },
   {"no-same-owner", NO_SAME_OWNER_OPTION, 0, 0,
    N_("extract files as yourself"), 31 },
   {"numeric-owner", NUMERIC_OWNER_OPTION, 0, 0,
@@ -996,6 +999,10 @@
       args->exclude_options &= ~ EXCLUDE_ANCHORED;
       break;
       
+    case NO_ATIME_OPTION:
+      no_atime_option = true;
+      break;
+
     case NO_IGNORE_CASE_OPTION:
       args->exclude_options &= ~ FNM_CASEFOLD;
       break;

reply via email to

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