2007-04-24 16:26:40

by Fabio Olive Leite

[permalink] [raw]
Subject: [PATCH] Stale NFS negative dentries caused by u32 jiffy wrap

Hi nfs@,

This patch solves an issue found on 32bit architectures, where jiffies
wrap every 50 days. Since many NFS structures are very long lived and
the code uses jiffies everywhere for timestamp comparisons, there are
many places where old data can be considered newer than something
fresh from the server. This one deals with negative dentries, and I'd
like to have it discussed in the list for sanity checking.

In 32bit architectures the NFS code uses 32bit jiffies for structures
that can very easily remain allocated for several u32 jiffy wraps,
fooling tests made only with time_after[_eq]. One such case is for
negative dentries, that given the correct timing can be considered valid
even after changing their parent dir's attributes.
=

This patch addresses that by using another unused struct dentry field to
store the higher part of the u64 jiffies. It has more comments than code
because the issue is subtle, and is made conditional on long being a
32bit quantity (64bit arches won't exhibit this behavior).

diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index cd34697..a21fb87 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -644,11 +644,26 @@ static int nfs_check_verifier(struct inode *dir, stru=
ct dentry *dentry)
if ((NFS_I(dir)->cache_validity & NFS_INO_INVALID_ATTR) !=3D 0
|| nfs_attribute_timeout(dir))
return 0;
+#if (BITS_PER_LONG < 64)
+ /* In 32bit architectures, also check the cached higher bits of
+ * jiffies64. NFS dentries can sit idle across two sign flips of
+ * 32bit jiffies and fool time_after[_eq].
+ */
+ if ((u32)(dentry->d_cookie) !=3D (u32)(get_jiffies_64() >> 32))
+ return 0;
+#endif
return nfs_verify_change_attribute(dir, (unsigned long)dentry->d_fsdata);
}
=

static inline void nfs_set_verifier(struct dentry * dentry, unsigned long =
verf)
{
+#if (BITS_PER_LONG < 64)
+ /* In 32bit architectures we can have problems with dentries that sit
+ * idle during two flips of the MSB of the u32 jiffies, so we keep
+ * track of the higher bits in d_cookie.
+ */
+ (u32)(dentry->d_cookie) =3D (u32)(get_jiffies_64() >> 32);
+#endif
dentry->d_fsdata =3D (void *)verf;
}
=

@@ -755,8 +770,17 @@ static int nfs_lookup_revalidate(struct dentry * dentr=
y, struct nameidata *nd)
inode =3D dentry->d_inode;
=

if (!inode) {
- if (nfs_neg_need_reval(dir, dentry, nd))
+ if (nfs_neg_need_reval(dir, dentry, nd)) {
+#if (BITS_PER_LONG < 64)
+ dfprintk(VFS, "nfs_lookup_revalidate: expiring neg dentry for %s\n",
+ dentry->d_name.name);
+ dfprintk(VFS, " d_cookie %08x high_jiffies %08x\n",
+ dentry->d_cookie, (u32)(get_jiffies_64() >> 32));
+ dfprintk(VFS, " d_fsdata %08x cache_change_attribute %08x\n",
+ dentry->d_fsdata, NFS_I(dir)->cache_change_attribute);
+#endif
goto out_bad;
+ }
goto out_valid;
}
=


Cheers,
F=E1bio
-- =

ex sed lex awk yacc, e pluribus unix, amem

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs


2007-04-26 03:25:39

by Fabio Olive Leite

[permalink] [raw]
Subject: Re: [PATCH] Stale NFS negative dentries caused by u32 jiffy wrap

On Tue, Apr 24, 2007 at 01:26:45PM -0300, Fabio Olive Leite wrote:
> =

> This patch solves an issue found on 32bit architectures, where jiffies
> wrap every 50 days. Since many NFS structures are very long lived and
> the code uses jiffies everywhere for timestamp comparisons, there are
> many places where old data can be considered newer than something
> fresh from the server. This one deals with negative dentries, and I'd
> like to have it discussed in the list for sanity checking.

Please disregard this email and patch. With extra testing, I found out
that time_after and friends are not suited at all to the type of
long-lived timestamp comparisons that the NFS code does. I'll start a
new thread for that.

Regards,
F=E1bio
-- =

ex sed lex awk yacc, e pluribus unix, amem

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs