Whamcloud - gitweb
LU-11868 mdc: Improve xattr buffer allocations
[fs/lustre-release.git] / lustre / mdd / mdd_object.c
index c04c685..ea8f1b7 100644 (file)
@@ -1099,6 +1099,7 @@ static int mdd_declare_attr_set(const struct lu_env *env,
 
 /*
  * LU-3671
+ * LU-7239
  *
  * permission changes may require sync operation, to mitigate performance
  * impact, only do this for dir and when permission is reduced.
@@ -1113,17 +1114,24 @@ static inline bool permission_needs_sync(const struct lu_attr *old,
        if (!S_ISDIR(old->la_mode))
                return false;
 
-       if (new->la_valid & (LA_UID | LA_GID))
+       if (new->la_valid & LA_UID && old->la_uid != new->la_uid)
                return true;
 
-       if (new->la_valid & LA_MODE &&
-           new->la_mode & (S_ISUID | S_ISGID | S_ISVTX))
+       if (new->la_valid & LA_GID && old->la_gid != new->la_gid)
                return true;
 
-       if ((new->la_valid & LA_MODE) &&
-           ((new->la_mode & old->la_mode) & S_IRWXUGO) !=
-            (old->la_mode & S_IRWXUGO))
-               return true;
+       if (new->la_valid & LA_MODE) {
+               /* turned on sticky bit */
+               if (!(old->la_mode & S_ISVTX) && (new->la_mode & S_ISVTX))
+                       return true;
+
+               /* set-GID has no impact on what is allowed, not checked */
+
+               /* turned off setuid bit, or one of rwx for someone */
+               if (((new->la_mode & old->la_mode) & (0777 | S_ISUID)) !=
+                    (old->la_mode & (0777 | S_ISUID)))
+                       return true;
+       }
 
        return false;
 }
@@ -1163,6 +1171,7 @@ int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
        struct lu_attr *attr = MDD_ENV_VAR(env, cattr);
        const struct lu_attr *la = &ma->ma_attr;
        struct lu_ucred  *uc;
+       bool chrgrp_by_unprivileged_user = false;
        int rc;
        ENTRY;
 
@@ -1194,15 +1203,23 @@ int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
        uc = lu_ucred_check(env);
        if (S_ISREG(attr->la_mode) && la->la_valid & LA_GID &&
            la->la_gid != attr->la_gid && uc != NULL && uc->uc_fsuid != 0) {
+               /* LU-10048: disable synchronous chgrp operation for it will
+                * cause deadlock between MDT and OST.
                la_copy->la_valid |= LA_FLAGS;
                la_copy->la_flags |= LUSTRE_SET_SYNC_FL;
+                */
+               chrgrp_by_unprivileged_user = true;
 
-               /* Flush the possible existing sync requests to OSTs to
-                * keep the order of sync for the current setattr operation
+               /* Flush the possible existing client setattr requests to OSTs
+                * to keep the order with the current setattr operation that
                 * will be sent directly to OSTs. see LU-5152 */
+               /* LU-11303 disable sync as this is too heavyweight.
+                * This should be replaced with a sync only for the object
+                * being modified here, not the whole filesystem.
                rc = dt_sync(env, mdd->mdd_child);
                if (rc)
                        GOTO(out, rc);
+                */
        }
 
        handle = mdd_trans_create(env, mdd);
@@ -1221,7 +1238,8 @@ int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
        if (rc)
                GOTO(out, rc);
 
-       if (mdd->mdd_sync_permission && permission_needs_sync(attr, la))
+       if (!chrgrp_by_unprivileged_user && mdd->mdd_sync_permission &&
+           permission_needs_sync(attr, la))
                handle->th_sync = 1;
 
        if (la->la_valid & (LA_MTIME | LA_CTIME))
@@ -1396,7 +1414,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,
-                               mdo2mdd(obj)->mdd_dt_conf.ddp_max_ea_size);
+                       MIN(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);
        if (rc < 0 && rc != -ENODATA)
@@ -3129,7 +3148,7 @@ static int mdd_close(const struct lu_env *env, struct md_object *obj,
        int is_orphan = 0;
        int rc;
        bool blocked = false;
-       int last_close_by_uid = 0;
+       bool last_close_by_uid = false;
        const struct lu_ucred *uc = lu_ucred(env);
        ENTRY;
 
@@ -3211,8 +3230,9 @@ cont:
        mdd_obj->mod_count--; /*release open count */
 
        /* under mdd write lock */
-       /* If recording, see if we need to remove UID from list */
-       if (mdd_changelog_enabled(env, mdd, CL_OPEN)) {
+       /* If recording, see if we need to remove UID from list. uc is not
+        * initialized if the client has been evicted. */
+       if (mdd_changelog_enabled(env, mdd, CL_OPEN) && uc) {
                struct mdd_object_user *mou;
 
                /* look for UID in list */
@@ -3226,7 +3246,7 @@ cont:
                        mou->mou_opencount--;
                        if (mou->mou_opencount == 0) {
                                mdd_obj_user_remove(mdd_obj, mou);
-                               last_close_by_uid = 1;
+                               last_close_by_uid = true;
                        }
                }
        }