]> git.hungrycats.org Git - linux/commitdiff
NFS: While the storage container for NFS file handles must be able to
authorTrond Myklebust <trond.myklebust@fys.uio.no>
Mon, 23 Aug 2004 14:15:49 +0000 (10:15 -0400)
committerTrond Myklebust <trond.myklebust@fys.uio.no>
Mon, 23 Aug 2004 14:15:49 +0000 (10:15 -0400)
   store 128 bytes, usually NFS servers don't use file handles that
   are more than 32 bytes in size.  This patch creates an efficient
   mechanism for comparing file handles that ignores the unused bytes
   in a file handle.

Signed-off-by: Chuck Lever <cel@netapp.com>
Signed-off-by: Trond Myklebust <trond.myklebust@fys.uio.no>
fs/lockd/svcsubs.c
fs/nfs/dir.c
fs/nfs/inode.c
include/linux/nfs.h

index 4d37124b928943c453607b5a882758d6706ad2d5..de7536358c7ce30651ea0b620d331ddf8be87175 100644 (file)
@@ -67,7 +67,7 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,
        down(&nlm_file_sema);
 
        for (file = nlm_files[hash]; file; file = file->f_next)
-               if (!memcmp(&file->f_handle, f, sizeof(*f)))
+               if (!nfs_compare_fh(&file->f_handle, f))
                        goto found;
 
        dprintk("lockd: creating file for (%08x %08x %08x %08x %08x %08x)\n",
index 36366f6b1d8700d97839002ec09bd8124ce4f95d..59f88f6ee2fb4ea5cb96f74a421737b0c31cfc1d 100644 (file)
@@ -610,7 +610,7 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
        verifier = nfs_save_change_attribute(dir);
        error = nfs_cached_lookup(dir, dentry, &fhandle, &fattr);
        if (!error) {
-               if (memcmp(NFS_FH(inode), &fhandle, sizeof(struct nfs_fh))!= 0)
+               if (nfs_compare_fh(NFS_FH(inode), &fhandle))
                        goto out_bad;
                if (nfs_lookup_verify_inode(inode, isopen))
                        goto out_zap_parent;
@@ -623,7 +623,7 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
        error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, &fhandle, &fattr);
        if (error)
                goto out_bad;
-       if (memcmp(NFS_FH(inode), &fhandle, sizeof(struct nfs_fh))!= 0)
+       if (nfs_compare_fh(NFS_FH(inode), &fhandle))
                goto out_bad;
        if ((error = nfs_refresh_inode(inode, &fattr)) != 0)
                goto out_bad;
index cbbfb4b82196f8c4d0cfd7dea16d336e8cc99d40..919776250e8cc6dc317b53a70ecc3b5ee3f94357 100644 (file)
@@ -596,7 +596,7 @@ nfs_find_actor(struct inode *inode, void *opaque)
 
        if (NFS_FILEID(inode) != fattr->fileid)
                return 0;
-       if (memcmp(NFS_FH(inode), fh, sizeof(struct nfs_fh)) != 0)
+       if (nfs_compare_fh(NFS_FH(inode), fh))
                return 0;
        if (is_bad_inode(inode))
                return 0;
@@ -1259,7 +1259,7 @@ static int nfs_compare_super(struct super_block *sb, void *data)
                return 0;
        if (old->addr.sin_port != server->addr.sin_port)
                return 0;
-       return !memcmp(&old->fh, &server->fh, sizeof(struct nfs_fh));
+       return !nfs_compare_fh(&old->fh, &server->fh);
 }
 
 static struct super_block *nfs_get_sb(struct file_system_type *fs_type,
index b30265f03e00282c39d2a9cf288f55093d2062a9..11a05d8a1f24a2aeafef3cc51f2d29f807bd44e8 100644 (file)
@@ -8,6 +8,7 @@
 #define _LINUX_NFS_H
 
 #include <linux/sunrpc/msg_prot.h>
+#include <linux/string.h>
 
 #define NFS_PROGRAM    100003
 #define NFS_PORT       2049
@@ -138,6 +139,16 @@ struct nfs_fh {
        unsigned char           data[NFS_MAXFHSIZE];
 };
 
+/*
+ * Returns a zero iff the size and data fields match.
+ * Checks only "size" bytes in the data field.
+ */
+static inline int nfs_compare_fh(const struct nfs_fh *a, const struct nfs_fh *b)
+{
+       return a->size != b->size || memcmp(a->data, b->data, a->size) != 0;
+}
+
+
 /*
  * This is really a general kernel constant, but since nothing like
  * this is defined in the kernel headers, I have to do it here.