Whamcloud - gitweb
LU-11668 mdd: use mdd_object_fid() instead of mdo2fid()
[fs/lustre-release.git] / lustre / mdd / mdd_object.c
index 22355ab..f01550a 100644 (file)
@@ -243,12 +243,7 @@ int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
 
 struct mdd_thread_info *mdd_env_info(const struct lu_env *env)
 {
-        struct mdd_thread_info *info;
-
-       lu_env_refill((struct lu_env *)env);
-        info = lu_context_key_get(&env->le_ctx, &mdd_thread_key);
-        LASSERT(info != NULL);
-        return info;
+       return lu_env_info(env, &mdd_thread_key);
 }
 
 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len)
@@ -436,7 +431,7 @@ static int mdd_xattr_get(const struct lu_env *env,
                struct thandle *handle;
                int rc2;
 
-               LASSERT(mdo2fid(mdd_obj) != NULL);
+               LASSERT(mdd_object_fid(mdd_obj) != NULL);
 
                handle = mdd_trans_create(env, mdd);
                if (IS_ERR(handle))
@@ -452,8 +447,8 @@ static int mdd_xattr_get(const struct lu_env *env,
                        GOTO(stop, rc2);
 
                rc2 = mdd_changelog_data_store_by_fid(env, mdd, CL_GETXATTR, 0,
-                                                     mdo2fid(mdd_obj), name,
-                                                     handle);
+                                                     mdd_object_fid(mdd_obj),
+                                                     name, handle);
 
 stop:
                rc2 = mdd_trans_stop(env, mdd, rc2, handle);
@@ -637,6 +632,22 @@ int mdd_update_time(const struct lu_env *env, struct mdd_object *obj,
        RETURN(rc);
 }
 
+
+static bool is_project_state_change(const struct lu_attr *oattr,
+                                   struct lu_attr *la)
+{
+       if (la->la_valid & LA_PROJID &&
+           oattr->la_projid != la->la_projid)
+               return true;
+
+       if ((la->la_valid & LA_FLAGS) &&
+           (la->la_flags & LUSTRE_PROJINHERIT_FL) !=
+           (oattr->la_flags & LUSTRE_PROJINHERIT_FL))
+               return true;
+
+       return false;
+}
+
 /*
  * This gives the same functionality as the code between
  * sys_chmod and inode_setattr
@@ -646,10 +657,12 @@ int mdd_update_time(const struct lu_env *env, struct mdd_object *obj,
  */
 static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj,
                        const struct lu_attr *oattr, struct lu_attr *la,
-                       const unsigned long flags)
+                       const struct md_attr *ma)
 {
        struct lu_ucred  *uc;
        int               rc = 0;
+       const unsigned long flags = ma->ma_attr_flags;
+
        ENTRY;
 
        if (!la->la_valid)
@@ -669,6 +682,14 @@ static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj,
        if (uc == NULL)
                RETURN(0);
 
+       if (is_project_state_change(oattr, la)) {
+               if (!md_capable(uc, CFS_CAP_SYS_RESOURCE) &&
+                   !lustre_in_group_p(uc, ma->ma_enable_chprojid_gid) &&
+                   !(ma->ma_enable_chprojid_gid == -1 &&
+                     mdd_permission_internal(env, obj, oattr, MAY_WRITE)))
+                       RETURN(-EPERM);
+       }
+
        if (la->la_valid == LA_CTIME) {
                if (!(flags & MDS_PERM_BYPASS))
                        /* This is only for set ctime when rename's source is
@@ -680,11 +701,19 @@ static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj,
                RETURN(rc);
        }
 
-       if (la->la_valid == LA_ATIME) {
-               /* This is an atime-only attribute update for close RPCs. */
-               if (la->la_atime < (oattr->la_atime +
+       if (flags & MDS_CLOSE_UPDATE_TIMES &&
+           la->la_valid & (LA_ATIME | LA_MTIME | LA_CTIME)) {
+               /* This is an atime/mtime/ctime attribute update for
+                * close RPCs.
+                */
+               if (la->la_valid & LA_ATIME &&
+                   la->la_atime <= (oattr->la_atime +
                                mdd_obj2mdd_dev(obj)->mdd_atime_diff))
                        la->la_valid &= ~LA_ATIME;
+               if (la->la_valid & LA_CTIME && la->la_ctime <= oattr->la_ctime)
+                       la->la_valid &= ~LA_CTIME;
+               if (la->la_valid & LA_MTIME && la->la_mtime <= oattr->la_mtime)
+                       la->la_valid &= ~LA_MTIME;
                RETURN(0);
        }
 
@@ -937,7 +966,8 @@ int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
        }
 
        rc = mdd_changelog_data_store_by_fid(env, mdd, type, clf_flags,
-                                            mdo2fid(mdd_obj), NULL, handle);
+                                            mdd_object_fid(mdd_obj),
+                                            NULL, handle);
        if (rc == 0)
                mdd_obj->mod_cltime = ktime_get();
 
@@ -973,8 +1003,8 @@ int mdd_changelog_data_store_xattr(const struct lu_env *env,
        }
 
        rc = mdd_changelog_data_store_by_fid(env, mdd, type, clf_flags,
-                                            mdo2fid(mdd_obj), xattr_name,
-                                            handle);
+                                            mdd_object_fid(mdd_obj),
+                                            xattr_name, handle);
        if (rc == 0)
                mdd_obj->mod_cltime = ktime_get();
 
@@ -1045,7 +1075,7 @@ static int mdd_attr_set_changelog(const struct lu_env *env,
        bits |= (valid & LA_ATIME) ? 1 << CL_ATIME : 0;
        bits = bits & mdd->mdd_cl.mc_mask;
        /* This is an implementation limit rather than a protocol limit */
-       CLASSERT(CL_LAST <= sizeof(int) * 8);
+       BUILD_BUG_ON(CL_LAST > sizeof(int) * 8);
        if (bits == 0)
                return 0;
 
@@ -1183,15 +1213,16 @@ int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
                RETURN(rc);
 
        *la_copy = ma->ma_attr;
-       rc = mdd_fix_attr(env, mdd_obj, attr, la_copy, ma->ma_attr_flags);
+       rc = mdd_fix_attr(env, mdd_obj, attr, la_copy, ma);
        if (rc)
                RETURN(rc);
 
        /* no need to setattr anymore */
        if (la_copy->la_valid == 0) {
-               CDEBUG(D_INODE, "%s: no valid attribute on "DFID", previous"
-                      "valid is %#llx\n", mdd2obd_dev(mdd)->obd_name,
-                      PFID(mdo2fid(mdd_obj)), la->la_valid);
+               CDEBUG(D_INODE,
+                      "%s: no valid attribute on "DFID", previous was %#llx\n",
+                      mdd_obj_dev_name(mdd_obj),
+                      PFID(mdd_object_fid(mdd_obj)), la->la_valid);
 
                RETURN(0);
        }
@@ -1333,7 +1364,7 @@ static inline bool has_prefix(const char *str, const char *prefix)
  *
  * \param[in]  xattr_name  Full extended attribute name.
  *
- * \return The type of changelog to use, or -1 if no changelog is to be emitted.
+ * \return type of changelog to use, or CL_NONE if no changelog is to be emitted
  */
 static enum changelog_rec_type
 mdd_xattr_changelog_type(const struct lu_env *env, struct mdd_device *mdd,
@@ -1341,8 +1372,8 @@ mdd_xattr_changelog_type(const struct lu_env *env, struct mdd_device *mdd,
 {
        /* Layout changes systematically recorded */
        if (strcmp(XATTR_NAME_LOV, xattr_name) == 0 ||
-           strncmp(XATTR_LUSTRE_LOV, xattr_name,
-                   strlen(XATTR_LUSTRE_LOV)) == 0)
+           strcmp(XATTR_LUSTRE_LOV, xattr_name) == 0 ||
+           allowed_lustre_lov(xattr_name))
                return CL_LAYOUT;
 
        /* HSM information changes systematically recorded */
@@ -1413,7 +1444,8 @@ static int mdd_hsm_update_locked(const struct lu_env *env,
 
        /* Read HSM attrs from disk */
        current_buf = lu_buf_check_and_alloc(&info->mti_xattr_buf,
-                       MIN(mdd_obj2mdd_dev(mdd_obj)->mdd_dt_conf.ddp_max_ea_size,
+                       min_t(unsigned int,
+                             mdd_obj2mdd_dev(mdd_obj)->mdd_dt_conf.ddp_max_ea_size,
                            XATTR_SIZE_MAX));
        rc = mdo_xattr_get(env, mdd_obj, current_buf, XATTR_NAME_HSM);
        rc = lustre_buf2hsm(current_buf->lb_buf, rc, current_mh);
@@ -1500,7 +1532,7 @@ static int mdd_xattr_merge(const struct lu_env *env, struct md_object *md_obj,
        int rc;
        ENTRY;
 
-       rc = lu_fid_cmp(mdo2fid(obj), mdo2fid(vic));
+       rc = lu_fid_cmp(mdd_object_fid(obj), mdd_object_fid(vic));
        if (rc == 0) /* same fid */
                RETURN(-EPERM);
 
@@ -1568,9 +1600,9 @@ out_restore:
                int rc2 = mdo_xattr_set(env, obj, buf, XATTR_NAME_LOV,
                                        LU_XATTR_REPLACE, handle);
                if (rc2)
-                       CERROR("%s: failed to rollback of layout of: "DFID
-                              ": %d, file state unknown\n",
-                              mdd_obj_dev_name(obj), PFID(mdo2fid(obj)), rc2);
+                       CERROR("%s: failed rollback of "DFID" layout: file state unknown: rc = %d\n",
+                              mdd_obj_dev_name(obj),
+                              PFID(mdd_object_fid(obj)), rc2);
        }
 
 out:
@@ -1731,7 +1763,7 @@ static int mdd_xattr_split(const struct lu_env *env, struct md_object *md_obj,
 
        ENTRY;
 
-       rc = lu_fid_cmp(mdo2fid(obj), mdo2fid(vic));
+       rc = lu_fid_cmp(mdd_object_fid(obj), mdd_object_fid(vic));
        if (rc == 0) /* same fid */
                RETURN(-EPERM);
 
@@ -1807,9 +1839,9 @@ out_restore:
                int rc2 = mdo_xattr_set(env, obj, buf_save, XATTR_NAME_LOV,
                                        LU_XATTR_REPLACE, handle);
                if (rc2)
-                       CERROR("%s: failed to rollback of layout of: "DFID
-                              ": %d, file state unkonwn.\n",
-                              mdd_obj_dev_name(obj), PFID(mdo2fid(obj)), rc2);
+                       CERROR("%s: failed rollback "DFID" layout: file state unkonwn: rc = %d\n",
+                              mdd_obj_dev_name(obj),
+                              PFID(mdd_object_fid(obj)), rc2);
        }
 out:
        rc = mdd_trans_stop(env, mdd, rc, handle);
@@ -2117,11 +2149,11 @@ static int mdd_layout_swap_allowed(const struct lu_env *env,
                                   const struct lu_attr *attr2,
                                   __u64 flags)
 {
-       const struct lu_fid     *fid1, *fid2;
+       const struct lu_fid *fid1, *fid2;
        ENTRY;
 
-       fid1 = mdo2fid(o1);
-       fid2 = mdo2fid(o2);
+       fid1 = mdd_object_fid(o1);
+       fid2 = mdd_object_fid(o2);
 
        if (!fid_is_norm(fid1) &&
            (!fid_is_igif(fid1) || IS_ERR(mdd_links_get(env, o1))))
@@ -2262,8 +2294,8 @@ stop:
 out:
        /* Ignore failure but report the error */
        if (rc)
-               CERROR("%s: "DFID" can't truncate DOM inode data, rc = %d\n",
-                      mdd_obj_dev_name(mo), PFID(mdo2fid(mo)), rc);
+               CERROR("%s: can't truncate DOM inode "DFID" data: rc = %d\n",
+                      mdd_obj_dev_name(mo), PFID(mdd_object_fid(mo)), rc);
        return rc;
 }
 
@@ -2294,12 +2326,12 @@ static int mdd_swap_layouts(const struct lu_env *env, struct md_object *obj1,
 
        ENTRY;
 
-       CLASSERT(ARRAY_SIZE(info->mti_buf) >= 4);
+       BUILD_BUG_ON(ARRAY_SIZE(info->mti_buf) < 4);
        memset(info->mti_buf, 0, sizeof(info->mti_buf));
 
        /* we have to sort the 2 obj, so locking will always
         * be in the same order, even in case of 2 concurrent swaps */
-       rc = lu_fid_cmp(mdo2fid(fst_o), mdo2fid(snd_o));
+       rc = lu_fid_cmp(mdd_object_fid(fst_o), mdd_object_fid(snd_o));
        if (rc == 0) /* same fid ? */
                RETURN(-EPERM);
 
@@ -2364,15 +2396,17 @@ static int mdd_swap_layouts(const struct lu_env *env, struct md_object *obj1,
 
        if (domsize_vlt > 0 && domsize_dom == 0) {
                rc = -EOPNOTSUPP;
-               CDEBUG(D_LAYOUT, "cannot swap layout for "DFID": OST to DOM "
-                      "migration is not supported: rc = %d\n",
-                      PFID(mdo2fid(snd_o)), rc);
+               CDEBUG(D_LAYOUT,
+                      "%s: cannot swap "DFID" layout: OST to DOM migration not supported: rc = %d\n",
+                      mdd_obj_dev_name(snd_o),
+                      PFID(mdd_object_fid(snd_o)), rc);
                GOTO(stop, rc);
        } else if (domsize_vlt > 0 && domsize_dom != domsize_vlt) {
                rc = -EOPNOTSUPP;
-               CDEBUG(D_LAYOUT, "cannot swap layout for "DFID": new layout "
-                      "must have the same DoM component size: rc = %d\n",
-                      PFID(mdo2fid(fst_o)), rc);
+               CDEBUG(D_LAYOUT,
+                      "%s: cannot swap "DFID" layout: new layout must have same DoM component size: rc = %d\n",
+                      mdd_obj_dev_name(fst_o),
+                      PFID(mdd_object_fid(fst_o)), rc);
                GOTO(stop, rc);
        } else if (domsize_vlt > 0) {
                /* Migration with the same DOM component size, no need to
@@ -2505,9 +2539,9 @@ static int mdd_swap_layouts(const struct lu_env *env, struct md_object *obj1,
                        rc2 = mdd_xattr_hsm_replace(env, fst_o, fst_hsm_buf,
                                                    handle);
                        if (rc2 < 0)
-                               CERROR("%s: restore "DFID" HSM error: %d/%d\n",
+                               CERROR("%s: HSM error restoring "DFID": rc = %d/%d\n",
                                       mdd_obj_dev_name(fst_o),
-                                      PFID(mdo2fid(fst_o)), rc, rc2);
+                                      PFID(mdd_object_fid(fst_o)), rc, rc2);
                        GOTO(stop, rc);
                }
        }
@@ -2566,10 +2600,10 @@ out_restore:
        do_lbug:
                if (rc2 < 0) {
                        /* very bad day */
-                       CERROR("%s: unable to roll back layout swap. FIDs: "
-                              DFID" and "DFID "error: %d/%d, steps: %d\n",
+                       CERROR("%s: unable to roll back layout swap of "DFID" and "DFID", steps: %d: rc = %d/%d\n",
                               mdd_obj_dev_name(fst_o),
-                              PFID(mdo2fid(snd_o)), PFID(mdo2fid(fst_o)),
+                              PFID(mdd_object_fid(snd_o)),
+                              PFID(mdd_object_fid(fst_o)),
                               rc, rc2, steps);
                        /* a solution to avoid journal commit is to panic,
                         * but it has strong consequences so we use LBUG to
@@ -3144,7 +3178,7 @@ find:
        }
 
        /* FYI, only the bottom 32 bits of open_flags are recorded */
-       mdd_changelog(env, type, open_flags, md_dev, mdo2fid(mdd_obj));
+       mdd_changelog(env, type, open_flags, md_dev, mdd_object_fid(mdd_obj));
 
        EXIT;
 out: