Whamcloud - gitweb
LU-5823 clio: add coo_obd_info_get and coo_data_version
[fs/lustre-release.git] / lustre / llite / file.c
index 349df65..f835a85 100644 (file)
@@ -1696,43 +1696,34 @@ out:
 /**
  * Get size for inode for which FIEMAP mapping is requested.
  * Make the FIEMAP get_info call and returns the result.
+ * \param fiemap       kernel buffer to hold extens
+ * \param num_bytes    kernel buffer size
  */
-static int ll_do_fiemap(struct inode *inode, struct ll_user_fiemap *fiemap,
+static int ll_do_fiemap(struct inode *inode, struct fiemap *fiemap,
                        size_t num_bytes)
 {
-       struct obd_export *exp = ll_i2dtexp(inode);
-       struct lov_stripe_md *lsm = NULL;
-        struct ll_fiemap_info_key fm_key = { .name = KEY_FIEMAP, };
-       __u32 vallen = num_bytes;
-        int rc;
-        ENTRY;
-
-        /* Checks for fiemap flags */
-        if (fiemap->fm_flags & ~LUSTRE_FIEMAP_FLAGS_COMPAT) {
-                fiemap->fm_flags &= ~LUSTRE_FIEMAP_FLAGS_COMPAT;
-                return -EBADR;
-        }
-
-        /* Check for FIEMAP_FLAG_SYNC */
-        if (fiemap->fm_flags & FIEMAP_FLAG_SYNC) {
-                rc = filemap_fdatawrite(inode->i_mapping);
-                if (rc)
-                        return rc;
-        }
+       struct lu_env                   *env;
+       int                             refcheck;
+       int                             rc = 0;
+       struct ll_fiemap_info_key       fmkey = { .name = KEY_FIEMAP, };
+       ENTRY;
 
-       lsm = ccc_inode_lsm_get(inode);
-       if (lsm == NULL)
-               return -ENOENT;
+       /* Checks for fiemap flags */
+       if (fiemap->fm_flags & ~LUSTRE_FIEMAP_FLAGS_COMPAT) {
+               fiemap->fm_flags &= ~LUSTRE_FIEMAP_FLAGS_COMPAT;
+               return -EBADR;
+       }
 
-       /* If the stripe_count > 1 and the application does not understand
-        * DEVICE_ORDER flag, then it cannot interpret the extents correctly.
-        */
-       if (lsm->lsm_stripe_count > 1 &&
-           !(fiemap->fm_flags & FIEMAP_FLAG_DEVICE_ORDER))
-               GOTO(out, rc = -EOPNOTSUPP);
+       /* Check for FIEMAP_FLAG_SYNC */
+       if (fiemap->fm_flags & FIEMAP_FLAG_SYNC) {
+               rc = filemap_fdatawrite(inode->i_mapping);
+               if (rc)
+                       return rc;
+       }
 
-       fm_key.oa.o_oi = lsm->lsm_oi;
-        fm_key.oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
+       env = cl_env_get(&refcheck);
+       if (IS_ERR(env))
+               RETURN(PTR_ERR(env));
 
        if (i_size_read(inode) == 0) {
                rc = ll_glimpse_size(inode);
@@ -1740,23 +1731,22 @@ static int ll_do_fiemap(struct inode *inode, struct ll_user_fiemap *fiemap,
                        GOTO(out, rc);
        }
 
-        obdo_from_inode(&fm_key.oa, inode, OBD_MD_FLSIZE);
-        obdo_set_parent_fid(&fm_key.oa, &ll_i2info(inode)->lli_fid);
-        /* If filesize is 0, then there would be no objects for mapping */
-        if (fm_key.oa.o_size == 0) {
-                fiemap->fm_mapped_extents = 0;
-               GOTO(out, rc = 0);
-        }
+       fmkey.oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
+       obdo_from_inode(&fmkey.oa, inode, OBD_MD_FLSIZE);
+       obdo_set_parent_fid(&fmkey.oa, &ll_i2info(inode)->lli_fid);
 
-        memcpy(&fm_key.fiemap, fiemap, sizeof(*fiemap));
+       /* If filesize is 0, then there would be no objects for mapping */
+       if (fmkey.oa.o_size == 0) {
+               fiemap->fm_mapped_extents = 0;
+               GOTO(out, rc = 0);
+       }
 
-        rc = obd_get_info(NULL, exp, sizeof(fm_key), &fm_key, &vallen,
-                          fiemap, lsm);
-        if (rc)
-                CERROR("obd_get_info failed: rc = %d\n", rc);
+       fmkey.fiemap = *fiemap;
 
+       rc = cl_object_fiemap(env, ll_i2info(inode)->lli_clob,
+                             &fmkey, fiemap, &num_bytes);
 out:
-       ccc_inode_lsm_put(inode, lsm);
+       cl_env_put(env, &refcheck);
        RETURN(rc);
 }
 
@@ -1803,60 +1793,59 @@ gf_free:
        RETURN(rc);
 }
 
-static int ll_ioctl_fiemap(struct inode *inode, unsigned long arg)
+static int ll_ioctl_fiemap(struct inode *inode, struct fiemap __user *arg)
 {
-        struct ll_user_fiemap *fiemap_s;
-        size_t num_bytes, ret_bytes;
-        unsigned int extent_count;
-        int rc = 0;
+       struct fiemap   *fiemap;
+       size_t          num_bytes;
+       size_t          ret_bytes;
+       __u32           extent_count;
+       int             rc = 0;
 
-        /* Get the extent count so we can calculate the size of
-         * required fiemap buffer */
-        if (get_user(extent_count,
-            &((struct ll_user_fiemap __user *)arg)->fm_extent_count))
-                RETURN(-EFAULT);
+       /* Get the extent count so we can calculate the size of
+        * required fiemap buffer */
+       if (get_user(extent_count, &arg->fm_extent_count))
+               RETURN(-EFAULT);
 
        if (extent_count >=
-           (SIZE_MAX - sizeof(*fiemap_s)) / sizeof(struct ll_fiemap_extent))
+           (SIZE_MAX - sizeof(*fiemap)) / sizeof(struct ll_fiemap_extent))
                RETURN(-EINVAL);
-        num_bytes = sizeof(*fiemap_s) + (extent_count *
-                                         sizeof(struct ll_fiemap_extent));
+       num_bytes = sizeof(*fiemap) + (extent_count *
+                                      sizeof(struct ll_fiemap_extent));
 
-        OBD_ALLOC_LARGE(fiemap_s, num_bytes);
-        if (fiemap_s == NULL)
-                RETURN(-ENOMEM);
+       OBD_ALLOC_LARGE(fiemap, num_bytes);
+       if (fiemap == NULL)
+               RETURN(-ENOMEM);
 
        /* get the fiemap value */
-       if (copy_from_user(fiemap_s, (struct ll_user_fiemap __user *)arg,
-                          sizeof(*fiemap_s)))
+       if (copy_from_user(fiemap, arg, sizeof(*fiemap)))
                GOTO(error, rc = -EFAULT);
 
-        /* If fm_extent_count is non-zero, read the first extent since
-         * it is used to calculate end_offset and device from previous
-         * fiemap call. */
-        if (extent_count) {
-                if (copy_from_user(&fiemap_s->fm_extents[0],
-                    (char __user *)arg + sizeof(*fiemap_s),
-                    sizeof(struct ll_fiemap_extent)))
-                        GOTO(error, rc = -EFAULT);
-        }
+       /* If fm_extent_count is non-zero, read the first extent since
+        * it is used to calculate end_offset and device from previous
+        * fiemap call. */
+       if (extent_count != 0) {
+               if (copy_from_user(&fiemap->fm_extents[0],
+                                  (char __user *)arg + sizeof(*fiemap),
+                                  sizeof(struct ll_fiemap_extent)))
+                       GOTO(error, rc = -EFAULT);
+       }
 
-        rc = ll_do_fiemap(inode, fiemap_s, num_bytes);
-        if (rc)
-                GOTO(error, rc);
+       rc = ll_do_fiemap(inode, fiemap, num_bytes);
+       if (rc)
+               GOTO(error, rc);
 
-        ret_bytes = sizeof(struct ll_user_fiemap);
+       ret_bytes = sizeof(struct fiemap);
 
-        if (extent_count != 0)
-                ret_bytes += (fiemap_s->fm_mapped_extents *
-                                 sizeof(struct ll_fiemap_extent));
+       if (extent_count != 0)
+               ret_bytes += (fiemap->fm_mapped_extents *
+                                sizeof(struct ll_fiemap_extent));
 
-       if (copy_to_user((void __user *)arg, fiemap_s, ret_bytes))
+       if (copy_to_user((void __user *)arg, fiemap, ret_bytes))
                rc = -EFAULT;
 
 error:
-        OBD_FREE_LARGE(fiemap_s, num_bytes);
-        RETURN(rc);
+       OBD_FREE_LARGE(fiemap, num_bytes);
+       RETURN(rc);
 }
 
 /*
@@ -1865,43 +1854,31 @@ error:
  * This value is computed using stripe object version on OST.
  * Version is computed using server side locking.
  *
- * @param sync if do sync on the OST side;
+ * @param flags if do sync on the OST side;
  *             0: no sync
  *             LL_DV_RD_FLUSH: flush dirty pages, LCK_PR on OSTs
  *             LL_DV_WR_FLUSH: drop all caching pages, LCK_PW on OSTs
  */
 int ll_data_version(struct inode *inode, __u64 *data_version, int flags)
 {
-       struct lov_stripe_md    *lsm = NULL;
-       struct ll_sb_info       *sbi = ll_i2sbi(inode);
-       struct obdo             *obdo = NULL;
-       int                      rc;
+       struct lu_env   *env;
+       int             refcheck;
+       int             rc;
        ENTRY;
 
-       /* If no stripe, we consider version is 0. */
-       lsm = ccc_inode_lsm_get(inode);
-       if (!lsm_has_objects(lsm)) {
+       /* If no file object initialized, we consider its version is 0. */
+       if (ll_i2info(inode)->lli_clob == NULL) {
                *data_version = 0;
-               CDEBUG(D_INODE, "No object for inode\n");
-               GOTO(out, rc = 0);
+               RETURN(0);
        }
 
-       OBD_ALLOC_PTR(obdo);
-       if (obdo == NULL)
-               GOTO(out, rc = -ENOMEM);
-
-       rc = ll_lsm_getattr(lsm, sbi->ll_dt_exp, NULL, obdo, flags);
-       if (rc == 0) {
-               if (!(obdo->o_valid & OBD_MD_FLDATAVERSION))
-                       rc = -EOPNOTSUPP;
-               else
-                       *data_version = obdo->o_data_version;
-       }
+       env = cl_env_get(&refcheck);
+       if (IS_ERR(env))
+               RETURN(PTR_ERR(env));
 
-       OBD_FREE_PTR(obdo);
-       EXIT;
-out:
-       ccc_inode_lsm_put(inode, lsm);
+       rc = cl_object_data_version(env, ll_i2info(inode)->lli_clob,
+                                   data_version, flags);
+       cl_env_put(env, &refcheck);
        RETURN(rc);
 }
 
@@ -2117,6 +2094,11 @@ static int ll_hsm_state_set(struct inode *inode, struct hsm_state_set *hss)
 {
        struct md_op_data       *op_data;
        int                      rc;
+       ENTRY;
+
+       /* Detect out-of range masks */
+       if ((hss->hss_setmask | hss->hss_clearmask) & ~HSM_FLAGS_MASK)
+               RETURN(-EINVAL);
 
        /* Non-root users are forbidden to set or clear flags which are
         * NOT defined in HSM_USER_MASK. */
@@ -2124,6 +2106,11 @@ static int ll_hsm_state_set(struct inode *inode, struct hsm_state_set *hss)
            !cfs_capable(CFS_CAP_SYS_ADMIN))
                RETURN(-EPERM);
 
+       /* Detect out-of range archive id */
+       if ((hss->hss_valid & HSS_ARCHIVE_ID) &&
+           (hss->hss_archive_id > LL_HSM_MAX_ARCHIVE))
+               RETURN(-EINVAL);
+
        op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
                                     LUSTRE_OPC_ANY, hss);
        if (IS_ERR(op_data))
@@ -2273,8 +2260,8 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        case LL_IOC_LOV_GETSTRIPE:
                RETURN(ll_file_getstripe(inode,
                                         (struct lov_user_md __user *)arg));
-        case FSFILT_IOC_FIEMAP:
-                RETURN(ll_ioctl_fiemap(inode, arg));
+       case FSFILT_IOC_FIEMAP:
+               RETURN(ll_ioctl_fiemap(inode, (struct fiemap __user *)arg));
         case FSFILT_IOC_GETFLAGS:
         case FSFILT_IOC_SETFLAGS:
                 RETURN(ll_iocontrol(inode, file, cmd, arg));