]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
NFS: Simplify ->decode_dirent() calling sequence
authorChuck Lever <chuck.lever@oracle.com>
Tue, 14 Dec 2010 14:58:11 +0000 (14:58 +0000)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Thu, 16 Dec 2010 17:37:24 +0000 (12:37 -0500)
Clean up.

The pointer returned by ->decode_dirent() is no longer used as a
pointer.  The only call site (xdr_decode() in fs/nfs/dir.c) simply
extracts the errno value encoded in the pointer.  Replace the
returned pointer with a standard integer errno return value.

Also, pass the "server" argument as part of the nfs_entry instead of
as a separate parameter.  It's faster to derive "server" in
nfs_readdir_xdr_to_array() since we already have the directory's inode
handy.  "server" ought to be invariant for a set of entries in the
same directory, right?

The legacy versions of decode_dirent() don't use "server" anyway, so
it's wasted work for them to derive and pass "server" for each entry.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Tested-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
fs/nfs/dir.c
fs/nfs/internal.h
fs/nfs/nfs2xdr.c
fs/nfs/nfs3xdr.c
fs/nfs/nfs4_fs.h
fs/nfs/nfs4xdr.c
include/linux/nfs_xdr.h

index 996dd8989a9135203cab110f57e7c1f8df49e200..3e2123fe79f55fa5b6ec302bfd7b6d6682e20284 100644 (file)
@@ -172,7 +172,7 @@ struct nfs_cache_array {
        struct nfs_cache_array_entry array[0];
 };
 
-typedef __be32 * (*decode_dirent_t)(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int);
+typedef int (*decode_dirent_t)(struct xdr_stream *, struct nfs_entry *, int);
 typedef struct {
        struct file     *file;
        struct page     *page;
@@ -378,14 +378,14 @@ error:
        return error;
 }
 
-/* Fill in an entry based on the xdr code stored in desc->page */
-static
-int xdr_decode(nfs_readdir_descriptor_t *desc, struct nfs_entry *entry, struct xdr_stream *stream)
+static int xdr_decode(nfs_readdir_descriptor_t *desc,
+                     struct nfs_entry *entry, struct xdr_stream *xdr)
 {
-       __be32 *p = desc->decode(stream, entry, NFS_SERVER(desc->file->f_path.dentry->d_inode), desc->plus);
-       if (IS_ERR(p))
-               return PTR_ERR(p);
+       int error;
 
+       error = desc->decode(xdr, entry, desc->plus);
+       if (error)
+               return error;
        entry->fattr->time_start = desc->timestamp;
        entry->fattr->gencount = desc->gencount;
        return 0;
@@ -566,6 +566,7 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page,
        entry.eof = 0;
        entry.fh = nfs_alloc_fhandle();
        entry.fattr = nfs_alloc_fattr();
+       entry.server = NFS_SERVER(inode);
        if (entry.fh == NULL || entry.fattr == NULL)
                goto out;
 
index 6c6a9955bae977630558d10a55cb4180271e2593..435eae3666bd5fe263c4825cb015f658284bd610 100644 (file)
@@ -187,15 +187,18 @@ extern void nfs_destroy_directcache(void);
 /* nfs2xdr.c */
 extern int nfs_stat_to_errno(enum nfs_stat);
 extern struct rpc_procinfo nfs_procedures[];
-extern __be32 *nfs2_decode_dirent(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int);
+extern int nfs2_decode_dirent(struct xdr_stream *,
+                               struct nfs_entry *, int);
 
 /* nfs3xdr.c */
 extern struct rpc_procinfo nfs3_procedures[];
-extern __be32 *nfs3_decode_dirent(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int);
+extern int nfs3_decode_dirent(struct xdr_stream *,
+                               struct nfs_entry *, int);
 
 /* nfs4xdr.c */
 #ifdef CONFIG_NFS_V4
-extern __be32 *nfs4_decode_dirent(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int);
+extern int nfs4_decode_dirent(struct xdr_stream *,
+                               struct nfs_entry *, int);
 #endif
 #ifdef CONFIG_NFS_V4_1
 extern const u32 nfs41_maxread_overhead;
index 0343175fe6c0fab584741ec2604af4abba6d5003..a9b848edbd2e714d09382e3601d987058d9f8bca 100644 (file)
@@ -936,10 +936,10 @@ static int nfs2_xdr_dec_writeres(struct rpc_rqst *req, __be32 *p,
  *                      the local page cache.
  * @xdr: XDR stream where entry resides
  * @entry: buffer to fill in with entry data
- * @server: nfs_server data for this directory
  * @plus: boolean indicating whether this should be a readdirplus entry
  *
- * Returns the position of the next item in the buffer, or an ERR_PTR.
+ * Returns zero if successful, otherwise a negative errno value is
+ * returned.
  *
  * This function is not invoked during READDIR reply decoding, but
  * rather whenever an application invokes the getdents(2) system call
@@ -954,8 +954,8 @@ static int nfs2_xdr_dec_writeres(struct rpc_rqst *req, __be32 *p,
  *             entry           *nextentry;
  *     };
  */
-__be32 *nfs2_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
-                          struct nfs_server *server, int plus)
+int nfs2_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
+                      int plus)
 {
        __be32 *p;
        int error;
@@ -968,9 +968,9 @@ __be32 *nfs2_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
                if (unlikely(p == NULL))
                        goto out_overflow;
                if (*p++ == xdr_zero)
-                       return ERR_PTR(-EAGAIN);
+                       return -EAGAIN;
                entry->eof = 1;
-               return ERR_PTR(-EBADCOOKIE);
+               return -EBADCOOKIE;
        }
 
        p = xdr_inline_decode(xdr, 4);
@@ -980,7 +980,7 @@ __be32 *nfs2_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
 
        error = decode_filename_inline(xdr, &entry->name, &entry->len);
        if (unlikely(error))
-               return ERR_PTR(error);
+               return error;
 
        /*
         * The type (size and byte order) of nfscookie isn't defined in
@@ -999,11 +999,11 @@ __be32 *nfs2_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
        entry->eof = 0;
        if (p != NULL)
                entry->eof = (p[0] == xdr_zero) && (p[1] != xdr_zero);
-       return p;
+       return 0;
 
 out_overflow:
        print_overflow_msg(__func__, xdr);
-       return ERR_PTR(-EAGAIN);
+       return -EAGAIN;
 }
 
 /*
index c97d00fe849a826b93b226122580d7d086046298..15c93ccd90c574aae4059534dc372ae84b5dc2b5 100644 (file)
@@ -1970,10 +1970,10 @@ out_status:
  *                     the local page cache
  * @xdr: XDR stream where entry resides
  * @entry: buffer to fill in with entry data
- * @server: nfs_server data for this directory
  * @plus: boolean indicating whether this should be a readdirplus entry
  *
- * Returns the position of the next item in the buffer, or an ERR_PTR.
+ * Returns zero if successful, otherwise a negative errno value is
+ * returned.
  *
  * This function is not invoked during READDIR reply decoding, but
  * rather whenever an application invokes the getdents(2) system call
@@ -2000,8 +2000,8 @@ out_status:
  *             entryplus3      *nextentry;
  *     };
  */
-__be32 *nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
-                          struct nfs_server *server, int plus)
+int nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
+                      int plus)
 {
        struct nfs_entry old = *entry;
        __be32 *p;
@@ -2015,23 +2015,23 @@ __be32 *nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
                if (unlikely(p == NULL))
                        goto out_overflow;
                if (*p == xdr_zero)
-                       return ERR_PTR(-EAGAIN);
+                       return -EAGAIN;
                entry->eof = 1;
-               return ERR_PTR(-EBADCOOKIE);
+               return -EBADCOOKIE;
        }
 
        error = decode_fileid3(xdr, &entry->ino);
        if (unlikely(error))
-               return ERR_PTR(error);
+               return error;
 
        error = decode_inline_filename3(xdr, &entry->name, &entry->len);
        if (unlikely(error))
-               return ERR_PTR(error);
+               return error;
 
        entry->prev_cookie = entry->cookie;
        error = decode_cookie3(xdr, &entry->cookie);
        if (unlikely(error))
-               return ERR_PTR(error);
+               return error;
 
        entry->d_type = DT_UNKNOWN;
 
@@ -2039,7 +2039,7 @@ __be32 *nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
                entry->fattr->valid = 0;
                error = decode_post_op_attr(xdr, entry->fattr);
                if (unlikely(error))
-                       return ERR_PTR(error);
+                       return error;
                if (entry->fattr->valid & NFS_ATTR_FATTR_V3)
                        entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
 
@@ -2052,7 +2052,7 @@ __be32 *nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
                        if (unlikely(error)) {
                                if (error == -E2BIG)
                                        goto out_truncated;
-                               return ERR_PTR(error);
+                               return error;
                        }
                } else
                        zero_nfs_fh3(entry->fh);
@@ -2063,15 +2063,15 @@ __be32 *nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
        entry->eof = 0;
        if (p != NULL)
                entry->eof = (p[0] == xdr_zero) && (p[1] != xdr_zero);
-       return p;
+       return 0;
 
 out_overflow:
        print_overflow_msg(__func__, xdr);
-       return ERR_PTR(-EAGAIN);
+       return -EAGAIN;
 out_truncated:
        dprintk("NFS: directory entry contains invalid file handle\n");
        *entry = old;
-       return ERR_PTR(-EAGAIN);
+       return -EAGAIN;
 }
 
 /*
index 9fa496387fdfec9a61aa45213c2a99b93982b30b..7a6eecffcaeb14021b287b72c800932ab74ada8b 100644 (file)
@@ -331,7 +331,6 @@ extern void nfs_free_seqid(struct nfs_seqid *seqid);
 extern const nfs4_stateid zero_stateid;
 
 /* nfs4xdr.c */
-extern __be32 *nfs4_decode_dirent(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int);
 extern struct rpc_procinfo nfs4_procedures[];
 
 struct nfs4_mount_data;
index 868815c55450948e60e359816167a27b65122c4d..be9f00ab0d1804f44f8a5ee8370e7b4f63efe8da 100644 (file)
@@ -6159,8 +6159,22 @@ out:
 }
 #endif /* CONFIG_NFS_V4_1 */
 
-__be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
-                          struct nfs_server *server, int plus)
+/**
+ * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
+ *                      the local page cache.
+ * @xdr: XDR stream where entry resides
+ * @entry: buffer to fill in with entry data
+ * @plus: boolean indicating whether this should be a readdirplus entry
+ *
+ * Returns zero if successful, otherwise a negative errno value is
+ * returned.
+ *
+ * This function is not invoked during READDIR reply decoding, but
+ * rather whenever an application invokes the getdents(2) system call
+ * on a directory already in our cache.
+ */
+int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
+                      int plus)
 {
        uint32_t bitmap[2] = {0};
        uint32_t len;
@@ -6172,9 +6186,9 @@ __be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
                if (unlikely(!p))
                        goto out_overflow;
                if (!ntohl(*p++))
-                       return ERR_PTR(-EAGAIN);
+                       return -EAGAIN;
                entry->eof = 1;
-               return ERR_PTR(-EBADCOOKIE);
+               return -EBADCOOKIE;
        }
 
        p = xdr_inline_decode(xdr, 12);
@@ -6203,7 +6217,8 @@ __be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
        if (decode_attr_length(xdr, &len, &p) < 0)
                goto out_overflow;
 
-       if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, server, 1) < 0)
+       if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
+                                       entry->server, 1) < 0)
                goto out_overflow;
        if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
                entry->ino = entry->fattr->fileid;
@@ -6221,11 +6236,11 @@ __be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
        else
                entry->eof = 0;
 
-       return p;
+       return 0;
 
 out_overflow:
        print_overflow_msg(__func__, xdr);
-       return ERR_PTR(-EAGAIN);
+       return -EAGAIN;
 }
 
 /*
index 80f07198a31a682814684d7946915cedd1df5d56..236e7e4b99a001d0071331c04481d65d57d57369 100644 (file)
@@ -484,6 +484,7 @@ struct nfs_entry {
        struct nfs_fh *         fh;
        struct nfs_fattr *      fattr;
        unsigned char           d_type;
+       struct nfs_server *     server;
 };
 
 /*
@@ -1089,7 +1090,7 @@ struct nfs_rpc_ops {
        int     (*pathconf) (struct nfs_server *, struct nfs_fh *,
                             struct nfs_pathconf *);
        int     (*set_capabilities)(struct nfs_server *, struct nfs_fh *);
-       __be32 *(*decode_dirent)(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int plus);
+       int     (*decode_dirent)(struct xdr_stream *, struct nfs_entry *, int);
        void    (*read_setup)   (struct nfs_read_data *, struct rpc_message *);
        int     (*read_done)  (struct rpc_task *, struct nfs_read_data *);
        void    (*write_setup)  (struct nfs_write_data *, struct rpc_message *);