Whamcloud - gitweb
LU-5837 llite: ll_getparent cleanup 27/12527/6
authorHenri Doreau <henri.doreau@cea.fr>
Fri, 31 Oct 2014 23:04:19 +0000 (00:04 +0100)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 9 Dec 2014 08:14:42 +0000 (08:14 +0000)
Avoid unneeded allocation. Get read-only attributes from the user
getparent structure and write the modified attributes only, instead
of populating a whole structure in kernel and copying it back.

Signed-off-by: Henri Doreau <henri.doreau@cea.fr>
Change-Id: Ifc0632870f80733194384d02d1b4962cdcd75658
Reviewed-on: http://review.whamcloud.com/12527
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: frank zago <fzago@cray.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/llite/file.c
lustre/llite/llite_lib.c
lustre/utils/liblustreapi.c

index 57bee66..723bf92 100644 (file)
@@ -2357,7 +2357,7 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                RETURN(0);
        }
        case LL_IOC_GETPARENT:
-               RETURN(ll_getparent(file, (void __user *)arg));
+               RETURN(ll_getparent(file, (struct getparent __user *)arg));
 
        case OBD_IOC_FID2PATH:
                RETURN(ll_fid2path(inode, (void __user *)arg));
index 09aa53c..1ec69d4 100644 (file)
@@ -2790,20 +2790,18 @@ void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
 /**
  * Parse linkea content to extract information about a given hardlink
  *
- * \param[in]  ldata  - Initialized linkea data
- * \param[in]  linkno - Link identifier
- * \param[out] gpout  - Destination structure to fill with linkno,
- *                      parent FID and entry name
- * \param[in]  size   - Size of the gp_name buffer in gpout
+ * \param[in]   ldata      - Initialized linkea data
+ * \param[in]   linkno     - Link identifier
+ * \param[out]  parent_fid - The entry's parent FID
+ * \param[out]  ln         - Entry name destination buffer
  *
  * \retval 0 on success
  * \retval Appropriate negative error code on failure
  */
 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
-                           struct getparent *gpout, size_t name_size)
+                           struct lu_fid *parent_fid, struct lu_name *ln)
 {
        unsigned int    idx;
-       struct lu_name  ln;
        int             rc;
        ENTRY;
 
@@ -2816,25 +2814,18 @@ static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
                RETURN(-ENODATA);
 
        linkea_first_entry(ldata);
-       idx = 0;
-       while (ldata->ld_lee != NULL) {
-               linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, &ln,
-                                   &gpout->gp_fid);
+       for (idx = 0; ldata->ld_lee != NULL; idx++) {
+               linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
+                                   parent_fid);
                if (idx == linkno)
                        break;
 
                linkea_next_entry(ldata);
-               idx++;
        }
 
        if (idx < linkno)
                RETURN(-ENODATA);
 
-       if (ln.ln_namelen >= name_size)
-               RETURN(-EOVERFLOW);
-
-       gpout->gp_linkno = linkno;
-       strlcpy(gpout->gp_name, ln.ln_name, name_size);
        RETURN(0);
 }
 
@@ -2857,10 +2848,10 @@ int ll_getparent(struct file *file, struct getparent __user *arg)
        struct inode            *inode = file->f_dentry->d_inode;
        struct linkea_data      *ldata;
        struct lu_buf            buf = LU_BUF_NULL;
-       struct getparent        *gpout;
+       struct lu_name           ln;
+       struct lu_fid            parent_fid;
        __u32                    linkno;
        __u32                    name_size;
-       size_t                   out_size;
        int                      rc;
 
        ENTRY;
@@ -2886,27 +2877,26 @@ int ll_getparent(struct file *file, struct getparent __user *arg)
        if (rc < 0)
                GOTO(ldata_free, rc);
 
-       out_size = sizeof(*gpout) + name_size;
-       OBD_ALLOC(gpout, out_size);
-       if (gpout == NULL)
-               GOTO(lb_free, rc = -ENOMEM);
-
-       if (copy_from_user(gpout, arg, sizeof(*gpout)))
-               GOTO(gp_free, rc = -EFAULT);
-
        rc = ll_getxattr(dentry, XATTR_NAME_LINK, buf.lb_buf, buf.lb_len);
        if (rc < 0)
-               GOTO(gp_free, rc);
+               GOTO(lb_free, rc);
 
-       rc = ll_linkea_decode(ldata, linkno, gpout, name_size);
+       rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
        if (rc < 0)
-               GOTO(gp_free, rc);
+               GOTO(lb_free, rc);
+
+       if (ln.ln_namelen >= name_size)
+               GOTO(lb_free, rc = -EOVERFLOW);
+
+       if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
+               GOTO(lb_free, rc = -EFAULT);
+
+       if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
+               GOTO(lb_free, rc = -EFAULT);
 
-       if (copy_to_user(arg, gpout, out_size))
-               GOTO(gp_free, rc = -EFAULT);
+       if (put_user('\0', arg->gp_name + ln.ln_namelen))
+               GOTO(lb_free, rc = -EFAULT);
 
-gp_free:
-       OBD_FREE(gpout, out_size);
 lb_free:
        lu_buf_free(&buf);
 ldata_free:
index e8c92a2..3f4e370 100644 (file)
@@ -4521,7 +4521,6 @@ int llapi_fd2parent(int fd, unsigned int linkno, lustre_fid *parent_fid,
        if (gp == NULL)
                return -ENOMEM;
 
-       memset(gp, 0, sizeof(*gp) + name_size);
        gp->gp_linkno = linkno;
        gp->gp_name_size = name_size;
 
@@ -4531,12 +4530,8 @@ int llapi_fd2parent(int fd, unsigned int linkno, lustre_fid *parent_fid,
                goto err_free;
        }
 
-       if (gp->gp_name_size > name_size) {
-               rc = -EOVERFLOW;
-               goto err_free;
-       }
-
        *parent_fid = gp->gp_fid;
+
        strncpy(name, gp->gp_name, name_size);
        name[name_size - 1] = '\0';