Whamcloud - gitweb
LU-5389: optimize ll_fid2path() 67/11167/7
authorFrank Zago <fzago@cray.com>
Sat, 19 Jul 2014 18:55:09 +0000 (13:55 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 25 Jul 2014 03:25:14 +0000 (03:25 +0000)
The only parameter from userspace that matters is the length of the
buffer. We don't need to allocate then import the whole structure. By
importing only that length, we can save a memory allocation.

Add sparse annotations to that function.

Change-Id: I4baa941f0128f9bcc19fade112915f3c52cd5b8b
Signed-off-by: frank zago <fzago@cray.com>
Reviewed-on: http://review.whamcloud.com/11167
Tested-by: Jenkins
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
lustre/llite/file.c
lustre/llite/llite_internal.h

index 6582be3..0457867 100644 (file)
@@ -1893,38 +1893,36 @@ out:
        RETURN(rc);
 }
 
-int ll_fid2path(struct inode *inode, void *arg)
+int ll_fid2path(struct inode *inode, void __user *arg)
 {
        struct obd_export       *exp = ll_i2mdexp(inode);
-       struct getinfo_fid2path *gfout, *gfin;
-       int                      outsize, rc;
+       const struct getinfo_fid2path __user *gfin = arg;
+       __u32                    pathlen;
+       struct getinfo_fid2path *gfout;
+       size_t                   outsize;
+       int                      rc;
+
        ENTRY;
 
        if (!cfs_capable(CFS_CAP_DAC_READ_SEARCH) &&
            !(ll_i2sbi(inode)->ll_flags & LL_SBI_USER_FID2PATH))
                RETURN(-EPERM);
 
-       /* Need to get the buflen */
-       OBD_ALLOC_PTR(gfin);
-       if (gfin == NULL)
-               RETURN(-ENOMEM);
-       if (copy_from_user(gfin, arg, sizeof(*gfin))) {
-               OBD_FREE_PTR(gfin);
+       /* Only need to get the buflen */
+       if (get_user(pathlen, &gfin->gf_pathlen))
                RETURN(-EFAULT);
-       }
 
-       outsize = sizeof(*gfout) + gfin->gf_pathlen;
+       outsize = sizeof(*gfout) + pathlen;
        OBD_ALLOC(gfout, outsize);
-       if (gfout == NULL) {
-               OBD_FREE_PTR(gfin);
+       if (gfout == NULL)
                RETURN(-ENOMEM);
-       }
-       memcpy(gfout, gfin, sizeof(*gfout));
-       OBD_FREE_PTR(gfin);
+
+       if (copy_from_user(gfout, arg, sizeof(*gfout)))
+               GOTO(gf_free, rc = -EFAULT);
 
        /* Call mdc_iocontrol */
        rc = obd_iocontrol(OBD_IOC_FID2PATH, exp, outsize, gfout, NULL);
-       if (rc)
+       if (rc != 0)
                GOTO(gf_free, rc);
 
        if (copy_to_user(arg, gfout, outsize))
index f7d8a4c..3e117c6 100644 (file)
@@ -828,7 +828,7 @@ int ll_fsync(struct file *file, int data);
 int ll_fsync(struct file *file, struct dentry *dentry, int data);
 #endif
 int ll_merge_lvb(const struct lu_env *env, struct inode *inode);
-int ll_fid2path(struct inode *inode, void *arg);
+int ll_fid2path(struct inode *inode, void __user *arg);
 int ll_data_version(struct inode *inode, __u64 *data_version, int flags);
 int ll_hsm_release(struct inode *inode);