nfsd: fix spurious EACCESS in reconnect_path()
[safe/jmp/linux-2.6] / fs / nfsd / nfs4xdr.c
index bf1e792..9547ab6 100644 (file)
@@ -376,20 +376,6 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, struct iattr *ia
                        goto xdr_error;
                }
        }
-       if (bmval[1] & FATTR4_WORD1_TIME_METADATA) {
-               /* We require the high 32 bits of 'seconds' to be 0, and we ignore
-                  all 32 bits of 'nseconds'. */
-               READ_BUF(12);
-               len += 12;
-               READ32(dummy32);
-               if (dummy32)
-                       return nfserr_inval;
-               READ32(iattr->ia_ctime.tv_sec);
-               READ32(iattr->ia_ctime.tv_nsec);
-               if (iattr->ia_ctime.tv_nsec >= (u32)1000000000)
-                       return nfserr_inval;
-               iattr->ia_valid |= ATTR_CTIME;
-       }
        if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
                READ_BUF(4);
                len += 4;
@@ -1215,7 +1201,7 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
        *p++ = htonl((u32)((n) >> 32));                         \
        *p++ = htonl((u32)(n));                                 \
 } while (0)
-#define WRITEMEM(ptr,nbytes)     do {                          \
+#define WRITEMEM(ptr,nbytes)     do if (nbytes > 0) {          \
        *(p + XDR_QUADLEN(nbytes) -1) = 0;                      \
        memcpy(p, ptr, nbytes);                                 \
        p += XDR_QUADLEN(nbytes);                               \
@@ -1330,9 +1316,9 @@ static char *nfsd4_path(struct svc_rqst *rqstp, struct svc_export *exp, __be32 *
        *stat = exp_pseudoroot(rqstp, &tmp_fh);
        if (*stat)
                return NULL;
-       rootpath = tmp_fh.fh_export->ex_path;
+       rootpath = tmp_fh.fh_export->ex_pathname;
 
-       path = exp->ex_path;
+       path = exp->ex_pathname;
 
        if (strncmp(path, rootpath, strlen(rootpath))) {
                dprintk("nfsd: fs_locations failed;"
@@ -1453,7 +1439,7 @@ static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *rdattr_err)
 __be32
 nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
                struct dentry *dentry, __be32 *buffer, int *countp, u32 *bmval,
-               struct svc_rqst *rqstp)
+               struct svc_rqst *rqstp, int ignore_crossmnt)
 {
        u32 bmval0 = bmval[0];
        u32 bmval1 = bmval[1];
@@ -1481,7 +1467,7 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
                        goto out;
        }
 
-       err = vfs_getattr(exp->ex_mnt, dentry, &stat);
+       err = vfs_getattr(exp->ex_path.mnt, dentry, &stat);
        if (err)
                goto out_nfserr;
        if ((bmval0 & (FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL |
@@ -1833,9 +1819,14 @@ out_acl:
        if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) {
                if ((buflen -= 8) < 0)
                        goto out_resource;
-               if (exp->ex_mnt->mnt_root->d_inode == dentry->d_inode) {
-                       err = vfs_getattr(exp->ex_mnt->mnt_parent,
-                               exp->ex_mnt->mnt_mountpoint, &stat);
+               /*
+                * Get parent's attributes if not ignoring crossmount
+                * and this is the root of a cross-mounted filesystem.
+                */
+               if (ignore_crossmnt == 0 &&
+                   exp->ex_path.mnt->mnt_root->d_inode == dentry->d_inode) {
+                       err = vfs_getattr(exp->ex_path.mnt->mnt_parent,
+                               exp->ex_path.mnt->mnt_mountpoint, &stat);
                        if (err)
                                goto out_nfserr;
                }
@@ -1862,6 +1853,15 @@ out_serverfault:
        goto out;
 }
 
+static inline int attributes_need_mount(u32 *bmval)
+{
+       if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME))
+               return 1;
+       if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID)
+               return 1;
+       return 0;
+}
+
 static __be32
 nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd,
                const char *name, int namlen, __be32 *p, int *buflen)
@@ -1869,13 +1869,23 @@ nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd,
        struct svc_export *exp = cd->rd_fhp->fh_export;
        struct dentry *dentry;
        __be32 nfserr;
+       int ignore_crossmnt = 0;
 
        dentry = lookup_one_len(name, cd->rd_fhp->fh_dentry, namlen);
        if (IS_ERR(dentry))
                return nfserrno(PTR_ERR(dentry));
 
        exp_get(exp);
-       if (d_mountpoint(dentry)) {
+       /*
+        * In the case of a mountpoint, the client may be asking for
+        * attributes that are only properties of the underlying filesystem
+        * as opposed to the cross-mounted file system. In such a case,
+        * we will not follow the cross mount and will fill the attribtutes
+        * directly from the mountpoint dentry.
+        */
+       if (d_mountpoint(dentry) && !attributes_need_mount(cd->rd_bmval))
+               ignore_crossmnt = 1;
+       else if (d_mountpoint(dentry)) {
                int err;
 
                /*
@@ -1894,7 +1904,7 @@ nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd,
 
        }
        nfserr = nfsd4_encode_fattr(NULL, exp, dentry, p, buflen, cd->rd_bmval,
-                                       cd->rd_rqstp);
+                                       cd->rd_rqstp, ignore_crossmnt);
 out_put:
        dput(dentry);
        exp_put(exp);
@@ -2048,7 +2058,7 @@ nfsd4_encode_getattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
        buflen = resp->end - resp->p - (COMPOUND_ERR_SLACK_SPACE >> 2);
        nfserr = nfsd4_encode_fattr(fhp, fhp->fh_export, fhp->fh_dentry,
                                    resp->p, &buflen, getattr->ga_bmval,
-                                   resp->rqstp);
+                                   resp->rqstp, 0);
        if (!nfserr)
                resp->p += buflen;
        return nfserr;