nfsd: clean up readdirplus encoding
[safe/jmp/linux-2.6] / fs / nfsd / nfs3xdr.c
index be515c5..f16184a 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/sunrpc/svc.h>
 #include <linux/nfsd/nfsd.h>
 #include <linux/nfsd/xdr3.h>
+#include "auth.h"
 
 #define NFSDDBG_FACILITY               NFSDDBG_XDR
 
@@ -217,7 +218,7 @@ encode_post_op_attr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp)
                int err;
                struct kstat stat;
 
-               err = vfs_getattr(fhp->fh_export->ex_mnt, dentry, &stat);
+               err = vfs_getattr(fhp->fh_export->ex_path.mnt, dentry, &stat);
                if (!err) {
                        *p++ = xdr_one;         /* attributes follow */
                        lease_get_mtime(dentry->d_inode, &stat.mtime);
@@ -269,8 +270,9 @@ void fill_post_wcc(struct svc_fh *fhp)
        if (fhp->fh_post_saved)
                printk("nfsd: inode locked twice during operation.\n");
 
-       err = vfs_getattr(fhp->fh_export->ex_mnt, fhp->fh_dentry,
+       err = vfs_getattr(fhp->fh_export->ex_path.mnt, fhp->fh_dentry,
                        &fhp->fh_post_attr);
+       fhp->fh_post_change = fhp->fh_dentry->d_inode->i_version;
        if (err)
                fhp->fh_post_saved = 0;
        else
@@ -812,17 +814,6 @@ encode_entry_baggage(struct nfsd3_readdirres *cd, __be32 *p, const char *name,
        return p;
 }
 
-static __be32 *
-encode_entryplus_baggage(struct nfsd3_readdirres *cd, __be32 *p,
-               struct svc_fh *fhp)
-{
-               p = encode_post_op_attr(cd->rqstp, p, fhp);
-               *p++ = xdr_one;                 /* yes, a file handle follows */
-               p = encode_fh(p, fhp);
-               fh_put(fhp);
-               return p;
-}
-
 static int
 compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp,
                const char *name, int namlen)
@@ -841,22 +832,46 @@ compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp,
                        if (dchild == dparent) {
                                /* filesystem root - cannot return filehandle for ".." */
                                dput(dchild);
-                               return 1;
+                               return -ENOENT;
                        }
                } else
                        dchild = dget(dparent);
        } else
                dchild = lookup_one_len(name, dparent, namlen);
        if (IS_ERR(dchild))
-               return 1;
-       if (d_mountpoint(dchild) ||
-           fh_compose(fhp, exp, dchild, &cd->fh) != 0 ||
-           !dchild->d_inode)
-               rv = 1;
+               return -ENOENT;
+       rv = -ENOENT;
+       if (d_mountpoint(dchild))
+               goto out;
+       rv = fh_compose(fhp, exp, dchild, &cd->fh);
+       if (rv)
+               goto out;
+       if (!dchild->d_inode)
+               goto out;
+       rv = 0;
+out:
        dput(dchild);
        return rv;
 }
 
+__be32 *encode_entryplus_baggage(struct nfsd3_readdirres *cd, __be32 *p, const char *name, int namlen)
+{
+       struct svc_fh   fh;
+       int err;
+
+       err = compose_entry_fh(cd, &fh, name, namlen);
+       if (err) {
+               *p++ = 0;
+               *p++ = 0;
+               return p;
+       }
+       p = encode_post_op_attr(cd->rqstp, p, &fh);
+       *p++ = xdr_one;                 /* yes, a file handle follows */
+       p = encode_fh(p, &fh);
+       fh_put(&fh);
+       return p;
+}
+
 /*
  * Encode a directory entry. This one works for both normal readdir
  * and readdirplus.
@@ -927,16 +942,8 @@ encode_entry(struct readdir_cd *ccd, const char *name, int namlen,
 
                p = encode_entry_baggage(cd, p, name, namlen, ino);
 
-               /* throw in readdirplus baggage */
-               if (plus) {
-                       struct svc_fh   fh;
-
-                       if (compose_entry_fh(cd, &fh, name, namlen) > 0) {
-                               *p++ = 0;
-                               *p++ = 0;
-                       } else
-                               p = encode_entryplus_baggage(cd, p, &fh);
-               }
+               if (plus)
+                       p = encode_entryplus_baggage(cd, p, name, namlen);
                num_entry_words = p - cd->buffer;
        } else if (cd->rqstp->rq_respages[pn+1] != NULL) {
                /* temporarily encode entry into next page, then move back to
@@ -949,17 +956,8 @@ encode_entry(struct readdir_cd *ccd, const char *name, int namlen,
 
                p1 = encode_entry_baggage(cd, p1, name, namlen, ino);
 
-               /* throw in readdirplus baggage */
-               if (plus) {
-                       struct svc_fh   fh;
-
-                       if (compose_entry_fh(cd, &fh, name, namlen) > 0) {
-                               /* zero out the filehandle */
-                               *p1++ = 0;
-                               *p1++ = 0;
-                       } else
-                               p1 = encode_entryplus_baggage(cd, p1, &fh);
-               }
+               if (plus)
+                       p = encode_entryplus_baggage(cd, p1, name, namlen);
 
                /* determine entry word length and lengths to go in pages */
                num_entry_words = p1 - tmp;