Whamcloud - gitweb
LU-9679 general: add missing spaces to folded strings.
[fs/lustre-release.git] / lustre / mdd / mdd_object.c
index e4357ec..21eae5d 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)
@@ -605,7 +600,7 @@ int mdd_attr_set_internal(const struct lu_env *env, struct mdd_object *obj,
        ENTRY;
 
        rc = mdo_attr_set(env, obj, attr, handle);
-#ifdef CONFIG_FS_POSIX_ACL
+#ifdef CONFIG_LUSTRE_FS_POSIX_ACL
        if (!rc && (attr->la_valid & LA_MODE) && needacl)
                rc = mdd_acl_chmod(env, obj, attr->la_mode, handle);
 #endif
@@ -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);
        }
 
@@ -1045,7 +1074,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;
 
@@ -1069,7 +1098,7 @@ static int mdd_declare_attr_set(const struct lu_env *env,
         if (rc)
                 return rc;
 
-#ifdef CONFIG_FS_POSIX_ACL
+#ifdef CONFIG_LUSTRE_FS_POSIX_ACL
        if (attr->la_valid & LA_MODE) {
                mdd_read_lock(env, obj, DT_TGT_CHILD);
                rc = mdo_xattr_get(env, obj, &LU_BUF_NULL,
@@ -1183,14 +1212,15 @@ 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,
+               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);
 
                RETURN(0);
@@ -1333,7 +1363,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 +1371,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 */
@@ -2294,7 +2324,7 @@ 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
@@ -2970,6 +3000,7 @@ void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
                          struct dt_allocation_hint *hint)
 {
        struct dt_object *np = parent ?  mdd_object_child(parent) : NULL;
+       struct mdd_device *mdd = mdd_obj2mdd_dev(child);
        struct dt_object *nc = mdd_object_child(child);
 
        memset(hint, 0, sizeof(*hint));
@@ -2983,6 +3014,19 @@ void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
        } else {
                hint->dah_eadata = NULL;
                hint->dah_eadata_len = 0;
+               if (spec->sp_cr_flags & MDS_OPEN_APPEND) {
+                       if (mdd->mdd_append_stripe_count != 0 ||
+                           mdd->mdd_append_pool[0])
+                               CDEBUG(D_INFO,
+                                      "using O_APPEND file striping\n");
+                       if (mdd->mdd_append_stripe_count)
+                               hint->dah_append_stripes =
+                                       mdd->mdd_append_stripe_count;
+                       if (mdd->mdd_append_pool[0])
+                               hint->dah_append_pool = mdd->mdd_append_pool;
+               } else {
+                       hint->dah_append_stripes = 0;
+               }
        }
 
        CDEBUG(D_INFO, DFID" eadata %p len %d\n", PFID(mdd_object_fid(child)),