All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] make "noac" and "actimeo=0" work correctly
@ 2008-06-10 20:52 Peter Staubach
  2008-07-08 16:08 ` [PATCH V2] " Peter Staubach
  0 siblings, 1 reply; 12+ messages in thread
From: Peter Staubach @ 2008-06-10 20:52 UTC (permalink / raw)
  To: NFS list; +Cc: Trond Myklebust

[-- Attachment #1: Type: text/plain, Size: 1275 bytes --]

Hi.

I've been looking at a bugzilla which describes a problem where
a customer was advised to use either the "noac" or "actimeo=0"
mount options to solve a consistency problem that they were
seeing in the file attributes.  It turned out that this solution
did not work reliably for them because sometimes, the local
attribute cache was believed to be valid and not timed out.
(With an attribute cache timeout of 0, the cache should always
appear to be timed out.)

In looking at this situation, it appears to me that the problem
is that the attribute cache timeout code has an off-by-one
error in it.  It is assuming that the cache is valid in the
region, [read_cache_jiffies, read_cache_jiffies + attrtimeo].  The
cache should be considered valid only in the region,
[read_cache_jiffies, read_cache_jiffies + attrtimeo).  With this
change, the options, "noac" and "actimeo=0", work as originally
expected.

While I was there, I addressed a problem with the jiffies
overflowing on 32 bit systems.  When overflow occurs, the
value of read_cache_jiffies + attrtimeo can be less then the
value of read_cache_jiffies.  This would cause an unnecessary
GETATTR over the wire.

Thoughts and/or comments?

   Thanx...

      ps

Signed-off-by: Peter Staubach <staubach@redhat.com>


[-- Attachment #2: attrtimeo.f-9 --]
[-- Type: text/plain, Size: 2516 bytes --]

--- linux-2.6.25.i686/fs/nfs/inode.c.org
+++ linux-2.6.25.i686/fs/nfs/inode.c
@@ -703,7 +714,7 @@ int nfs_attribute_timeout(struct inode *
 
 	if (nfs_have_delegation(inode, FMODE_READ))
 		return 0;
-	return !time_in_range(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->attrtimeo);
+	return !nfs_time_in_range_open(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->attrtimeo);
 }
 
 /**
@@ -1088,7 +1113,7 @@ static int nfs_update_inode(struct inode
 		nfsi->attrtimeo_timestamp = now;
 		nfsi->last_updated = now;
 	} else {
-		if (!time_in_range(now, nfsi->attrtimeo_timestamp, nfsi->attrtimeo_timestamp + nfsi->attrtimeo)) {
+		if (!nfs_time_in_range_open(now, nfsi->attrtimeo_timestamp, nfsi->attrtimeo_timestamp + nfsi->attrtimeo)) {
 			if ((nfsi->attrtimeo <<= 1) > NFS_MAXATTRTIMEO(inode))
 				nfsi->attrtimeo = NFS_MAXATTRTIMEO(inode);
 			nfsi->attrtimeo_timestamp = now;
--- linux-2.6.25.i686/fs/nfs/dir.c.org
+++ linux-2.6.25.i686/fs/nfs/dir.c
@@ -1807,7 +1830,7 @@ static int nfs_access_get_cached(struct 
 	cache = nfs_access_search_rbtree(inode, cred);
 	if (cache == NULL)
 		goto out;
-	if (!time_in_range(jiffies, cache->jiffies, cache->jiffies + nfsi->attrtimeo))
+	if (!nfs_time_in_range_open(jiffies, cache->jiffies, cache->jiffies + nfsi->attrtimeo))
 		goto out_stale;
 	res->jiffies = cache->jiffies;
 	res->cred = cache->cred;
--- linux-2.6.25.i686/include/linux/nfs_fs.h.org
+++ linux-2.6.25.i686/include/linux/nfs_fs.h
@@ -121,7 +121,7 @@ struct nfs_inode {
 	 *
 	 * We need to revalidate the cached attrs for this inode if
 	 *
-	 *	jiffies - read_cache_jiffies > attrtimeo
+	 *	jiffies - read_cache_jiffies >= attrtimeo
 	 */
 	unsigned long		read_cache_jiffies;
 	unsigned long		attrtimeo;
@@ -244,6 +244,22 @@ static inline unsigned NFS_MAXATTRTIMEO(
 	return S_ISDIR(inode->i_mode) ? nfss->acdirmax : nfss->acregmax;
 }
 
+static inline int nfs_time_in_range_open(unsigned long a,
+				unsigned long b, unsigned long c)
+{
+	/*
+	 * If c is less then b, then the jiffies have wrapped.
+	 * If so, then check to see if a is between b and the
+	 * max jiffies value or between 0 and the value of c.
+	 * This is the range between b and c.
+	 *
+	 * Otherwise, just check to see whether a is in [b, c).
+	 */
+	if (c < b)
+		return time_after_eq(a, b) || time_before(a, c);
+	return time_after_eq(a, b) && time_before(a, c);
+}
+
 static inline int NFS_STALE(const struct inode *inode)
 {
 	return test_bit(NFS_INO_STALE, &NFS_I(inode)->flags);

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-12-05 21:37 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-10 20:52 [PATCH] make "noac" and "actimeo=0" work correctly Peter Staubach
2008-07-08 16:08 ` [PATCH V2] " Peter Staubach
2008-07-10 15:58   ` Chuck Lever
     [not found]     ` <76bd70e30807100858g58fbf454uc9331035a2bbf264-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-10 17:41       ` Peter Staubach
2008-07-10 18:55         ` Chuck Lever
     [not found]           ` <76bd70e30807101155l226c1cceh24ca17157cb454bf-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-10 19:23             ` Peter Staubach
2008-07-10 19:31               ` Chuck Lever
2008-07-10 19:29         ` Trond Myklebust
2008-07-11 20:14           ` Peter Staubach
2008-07-11 20:19             ` Trond Myklebust
2008-07-11 20:24               ` Peter Staubach
2008-12-05 21:37                 ` [PATCH V3] optimize attribute timeouts for "noac" and "actimeo=0" Peter Staubach

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.