bug-tar
[Top][All Lists]
Advanced

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

Re: [Bug-tar] Re: [patch] O_NOATIME support


From: Ian Turner
Subject: Re: [Bug-tar] Re: [patch] O_NOATIME support
Date: Tue, 18 Oct 2005 09:25:00 -0700
User-agent: KMail/1.7.1

On Tuesday 18 October 2005 06:28, Joerg Schilling wrote:

> Well, then I will probably do something like:

>

> #ifdef __linux__

> #ifdef O_NOATIME

> flags = fcntl(f, F_GETFL, 0);

> fcntl(f, F_SETFL, flags | O_NOATIME);

> #endif

> #endif

>

> and people who run the prokern kernel will fail.

Yes, that is how you can test if you have a kernel that understands O_NOATIME. But that's it; it doesn't tell you if O_NOATIME actually works on the file in question. On current kernels, the fcntl test will succeed even on NFS. In the last analysis, the code should look something like:

int flags = -1, fd = -1;

enum atime_preserve file_atime_mode = atime_preserve_option;

#ifndef HAVE_O_NOATIME

if (file_atime_mode == BEST_ATIME_PRESERVE)

file_atime_mode = REPLACE_ATIME_PRESERVE;

#else

if (file_atime_mode == SYSTEM_ATIME_PRESERVE ||

file_atime_mode == BEST_ATIME_PRESERVE) {

fd = open(filename, O_NOATIME | ...);

int noatime_success = 1;

if (fd < 0) {

if (errno == EINVAL) {

noatime_success = 0;

} else {

/* Whatever you do if open fails. */

}

}

#ifdef __linux__

flags = fcntl(f, F_GETFL, 0);

if (!(flags | O_NOATIME))

noatime_success = 0;

#endif

if (!noatime_success) {

if (file_atime_mode == BEST_ATIME_PRESERVE) {

file_atime_mode = REPLACE_ATIME_PRESERVE;

} else /* SYSTEM_ATIME_PRESERVE */ {

file_atime_mode = DONT_ATIME_PRESERVE;

/* Throw an error message here? */

}

}

}

#endif

if (fd < 0) {

fd = open(filename, ...);

if (fd < 0) {

/* whatever you do if open fails. */

}

}

This correctly captures all the cases, except for the (buggy) kernels between 2.6.8 and (maybe) 2.6.20. For those kernels only, tar will use O_NOATIME even on filesystems where it doesn't work. But figuring out where it does work on those kernels is a huge can of worms, not really reliable, and so not really worth the effort.

Cheers,

--Ian


reply via email to

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