Merge to Fedora kernel-2.6.18-1.2257_FC5 patched with stable patch-2.6.18.5-vs2.0...
[linux-2.6.git] / fs / nfsd / nfsfh.c
index 077ff84..501d838 100644 (file)
@@ -41,7 +41,7 @@ extern struct export_operations export_op_default;
  * if not, require that we can walk up to exp->ex_dentry
  * doing some checks on the 'x' bits
  */
-int nfsd_acceptable(void *expv, struct dentry *dentry)
+static int nfsd_acceptable(void *expv, struct dentry *dentry)
 {
        struct svc_export *exp = expv;
        int rv;
@@ -71,6 +71,35 @@ int nfsd_acceptable(void *expv, struct dentry *dentry)
        return rv;
 }
 
+/* Type check. The correct error return for type mismatches does not seem to be
+ * generally agreed upon. SunOS seems to use EISDIR if file isn't S_IFREG; a
+ * comment in the NFSv3 spec says this is incorrect (implementation notes for
+ * the write call).
+ */
+static inline int
+nfsd_mode_check(struct svc_rqst *rqstp, umode_t mode, int type)
+{
+       /* Type can be negative when creating hardlinks - not to a dir */
+       if (type > 0 && (mode & S_IFMT) != type) {
+               if (rqstp->rq_vers == 4 && (mode & S_IFMT) == S_IFLNK)
+                       return nfserr_symlink;
+               else if (type == S_IFDIR)
+                       return nfserr_notdir;
+               else if ((mode & S_IFMT) == S_IFDIR)
+                       return nfserr_isdir;
+               else
+                       return nfserr_inval;
+       }
+       if (type < 0 && (mode & S_IFMT) == -type) {
+               if (rqstp->rq_vers == 4 && (mode & S_IFMT) == S_IFLNK)
+                       return nfserr_symlink;
+               else if (type == -S_IFDIR)
+                       return nfserr_isdir;
+               else
+                       return nfserr_notdir;
+       }
+       return 0;
+}
 
 /*
  * Perform sanity checks on the dentry in a client's file handle.
@@ -87,7 +116,6 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
        struct knfsd_fh *fh = &fhp->fh_handle;
        struct svc_export *exp = NULL;
        struct dentry   *dentry;
-       struct inode    *inode;
        u32             error = 0;
 
        dprintk("nfsd: fh_verify(%s)\n", SVCFH_fmt(fhp));
@@ -142,15 +170,13 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
                }
 
                error = nfserr_dropit;
-               if (IS_ERR(exp) && PTR_ERR(exp) == -EAGAIN) {
-                       dprintk("nfsd: fh_verify failed: nfserr_dropit\n");
+               if (IS_ERR(exp) && PTR_ERR(exp) == -EAGAIN)
                        goto out;
-               }
+
                error = nfserr_stale; 
-               if (!exp || IS_ERR(exp)) {
-                       dprintk("nfsd: fh_verify failed: nfserr_stale\n");
+               if (!exp || IS_ERR(exp))
                        goto out;
-               }
+
                /* Check if the request originated from a secure port. */
                error = nfserr_perm;
                if (!rqstp->rq_secure && EX_SECURE(exp)) {
@@ -162,12 +188,9 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
                }
 
                /* Set user creds for this exportpoint */
-               error = nfsd_setuser(rqstp, exp);
-               if (error) {
-                       dprintk("nfsd: nfsd_setuser failed: %d\n", error);
-                       error = nfserrno(error);
+               error = nfserrno(nfsd_setuser(rqstp, exp));
+               if (error)
                        goto out;
-               }
 
                /*
                 * Look up the dentry using the NFS file handle.
@@ -201,7 +224,6 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
                if (dentry == NULL)
                        goto out;
                if (IS_ERR(dentry)) {
-                       dprintk("nfsd: CALL(nop,decode_fh) failed: %ld\n", PTR_ERR(dentry));
                        if (PTR_ERR(dentry) != -EINVAL)
                                error = nfserrno(PTR_ERR(dentry));
                        goto out;
@@ -224,42 +246,21 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
                dprintk("nfsd: fh_verify - just checking\n");
                dentry = fhp->fh_dentry;
                exp = fhp->fh_export;
+               /* Set user creds for this exportpoint; necessary even
+                * in the "just checking" case because this may be a
+                * filehandle that was created by fh_compose, and that
+                * is about to be used in another nfsv4 compound
+                * operation */
+               error = nfserrno(nfsd_setuser(rqstp, exp));
+               if (error)
+                       goto out;
        }
        cache_get(&exp->h);
 
-       inode = dentry->d_inode;
-
-
-       /* Type check. The correct error return for type mismatches
-        * does not seem to be generally agreed upon. SunOS seems to
-        * use EISDIR if file isn't S_IFREG; a comment in the NFSv3
-        * spec says this is incorrect (implementation notes for the
-        * write call).
-        */
 
-       /* Type can be negative when creating hardlinks - not to a dir */
-       if (type > 0 && (inode->i_mode & S_IFMT) != type) {
-               if (rqstp->rq_vers == 4 && (inode->i_mode & S_IFMT) == S_IFLNK)
-                       error = nfserr_symlink;
-               else if (type == S_IFDIR)
-                       error = nfserr_notdir;
-               else if ((inode->i_mode & S_IFMT) == S_IFDIR)
-                       error = nfserr_isdir;
-               else
-                       error = nfserr_inval;
-               dprintk("nfsd: bad type: %d\n", ntohl(error));
+       error = nfsd_mode_check(rqstp, dentry->d_inode->i_mode, type);
+       if (error)
                goto out;
-       }
-       if (type < 0 && (inode->i_mode & S_IFMT) == -type) {
-               if (rqstp->rq_vers == 4 && (inode->i_mode & S_IFMT) == S_IFLNK)
-                       error = nfserr_symlink;
-               else if (type == -S_IFDIR)
-                       error = nfserr_isdir;
-               else
-                       error = nfserr_notdir;
-               dprintk("nfsd: bad type2: %d\n", ntohl(error));
-               goto out;
-       }
 
        /* Finally, check access permissions. */
        error = nfsd_permission(exp, dentry, access);
@@ -286,8 +287,8 @@ out:
  * an inode.  In this case a call to fh_update should be made
  * before the fh goes out on the wire ...
  */
-inline int _fh_update(struct dentry *dentry, struct svc_export *exp,
-                     __u32 *datap, int *maxsize)
+static inline int _fh_update(struct dentry *dentry, struct svc_export *exp,
+                            __u32 *datap, int *maxsize)
 {
        struct export_operations *nop = exp->ex_mnt->mnt_sb->s_export_op;
        
@@ -303,8 +304,9 @@ inline int _fh_update(struct dentry *dentry, struct svc_export *exp,
 /*
  * for composing old style file handles
  */
-inline void _fh_update_old(struct dentry *dentry, struct svc_export *exp,
-                          struct knfsd_fh *fh)
+static inline void _fh_update_old(struct dentry *dentry,
+                                 struct svc_export *exp,
+                                 struct knfsd_fh *fh)
 {
        fh->ofh_ino = ino_t_to_u32(dentry->d_inode->i_ino);
        fh->ofh_generation = dentry->d_inode->i_generation;
@@ -317,8 +319,8 @@ int
 fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, struct svc_fh *ref_fh)
 {
        /* ref_fh is a reference file handle.
-        * if it is non-null, then we should compose a filehandle which is
-        * of the same version, where possible.
+        * if it is non-null and for the same filesystem, then we should compose
+        * a filehandle which is of the same version, where possible.
         * Currently, that means that if ref_fh->fh_handle.fh_version == 0xca
         * Then create a 32byte filehandle using nfs_fhbase_old
         *
@@ -337,7 +339,7 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, st
                parent->d_name.name, dentry->d_name.name,
                (inode ? inode->i_ino : 0));
 
-       if (ref_fh) {
+       if (ref_fh && ref_fh->fh_export == exp) {
                ref_fh_version = ref_fh->fh_handle.fh_version;
                if (ref_fh_version == 0xca)
                        ref_fh_fsid_type = 0;
@@ -466,7 +468,7 @@ fh_update(struct svc_fh *fhp)
        } else {
                int size;
                if (fhp->fh_handle.fh_fileid_type != 0)
-                       goto out_uptodate;
+                       goto out;
                datap = fhp->fh_handle.fh_auth+
                        fhp->fh_handle.fh_size/4 -1;
                size = (fhp->fh_maxsize - fhp->fh_handle.fh_size)/4;
@@ -486,10 +488,6 @@ out_negative:
        printk(KERN_ERR "fh_update: %s/%s still negative!\n",
                dentry->d_parent->d_name.name, dentry->d_name.name);
        goto out;
-out_uptodate:
-       printk(KERN_ERR "fh_update: %s/%s already up-to-date!\n",
-               dentry->d_parent->d_name.name, dentry->d_name.name);
-       goto out;
 }
 
 /*
@@ -511,7 +509,7 @@ fh_put(struct svc_fh *fhp)
                nfsd_nr_put++;
        }
        if (exp) {
-               svc_export_put(&exp->h, &svc_export_cache);
+               cache_put(&exp->h, &svc_export_cache);
                fhp->fh_export = NULL;
        }
        return;