Whamcloud - gitweb
LU-5152 quota: enforce block quota for chgrp
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_handler.c
index 118bec0..ad77d4d 100644 (file)
@@ -2479,7 +2479,7 @@ static int osd_declare_attr_qid(const struct lu_env *env,
                                struct osd_object *obj,
                                struct osd_thandle *oh, long long bspace,
                                qid_t old_id, qid_t new_id, bool enforce,
-                               unsigned type)
+                               unsigned type, bool ignore_edquot)
 {
        int rc;
        struct osd_thread_info *info = osd_oti_get(env);
@@ -2494,7 +2494,7 @@ static int osd_declare_attr_qid(const struct lu_env *env,
        qi->lqi_space      = 1;
        /* Reserve credits for the new id */
        rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
-       if (rc == -EDQUOT || rc == -EINPROGRESS)
+       if (ignore_edquot && (rc == -EDQUOT || rc == -EINPROGRESS))
                rc = 0;
        if (rc)
                RETURN(rc);
@@ -2503,7 +2503,7 @@ static int osd_declare_attr_qid(const struct lu_env *env,
        qi->lqi_id.qid_uid = old_id;
        qi->lqi_space      = -1;
        rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
-       if (rc == -EDQUOT || rc == -EINPROGRESS)
+       if (ignore_edquot && (rc == -EDQUOT || rc == -EINPROGRESS))
                rc = 0;
        if (rc)
                RETURN(rc);
@@ -2519,7 +2519,7 @@ static int osd_declare_attr_qid(const struct lu_env *env,
         * to save credit reservation.
         */
        rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
-       if (rc == -EDQUOT || rc == -EINPROGRESS)
+       if (ignore_edquot && (rc == -EDQUOT || rc == -EINPROGRESS))
                rc = 0;
        if (rc)
                RETURN(rc);
@@ -2528,7 +2528,7 @@ static int osd_declare_attr_qid(const struct lu_env *env,
        qi->lqi_id.qid_uid = old_id;
        qi->lqi_space      = -bspace;
        rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
-       if (rc == -EDQUOT || rc == -EINPROGRESS)
+       if (ignore_edquot && (rc == -EDQUOT || rc == -EINPROGRESS))
                rc = 0;
 
        RETURN(rc);
@@ -2566,22 +2566,30 @@ static int osd_declare_attr_set(const struct lu_env *env,
        if (attr == NULL || obj->oo_inode == NULL)
                RETURN(rc);
 
-       bspace   = obj->oo_inode->i_blocks;
-       bspace <<= obj->oo_inode->i_sb->s_blocksize_bits;
+       bspace   = obj->oo_inode->i_blocks << 9;
        bspace   = toqb(bspace);
 
        /* Changing ownership is always preformed by super user, it should not
-        * fail with EDQUOT.
+        * fail with EDQUOT unless required explicitly.
         *
         * We still need to call the osd_declare_qid() to calculate the journal
         * credits for updating quota accounting files and to trigger quota
         * space adjustment once the operation is completed.*/
        if (attr->la_valid & LA_UID || attr->la_valid & LA_GID) {
+               bool ignore_edquot = !(attr->la_flags & LUSTRE_SET_SYNC_FL);
+
+               if (!ignore_edquot)
+                       CDEBUG(D_QUOTA, "%s: enforce quota on UID %u, GID %u"
+                              "(the quota space is %lld)\n",
+                              obj->oo_inode->i_sb->s_id, attr->la_uid,
+                              attr->la_gid, bspace);
+
                /* USERQUOTA */
                uid = i_uid_read(obj->oo_inode);
                enforce = (attr->la_valid & LA_UID) && (attr->la_uid != uid);
                rc = osd_declare_attr_qid(env, obj, oh, bspace, uid,
-                                         attr->la_uid, enforce, USRQUOTA);
+                                         attr->la_uid, enforce, USRQUOTA,
+                                         true);
                if (rc)
                        RETURN(rc);
 
@@ -2589,7 +2597,8 @@ static int osd_declare_attr_set(const struct lu_env *env,
                enforce = (attr->la_valid & LA_GID) && (attr->la_gid != gid);
                rc = osd_declare_attr_qid(env, obj, oh, bspace,
                                          i_gid_read(obj->oo_inode),
-                                         attr->la_gid, enforce, GRPQUOTA);
+                                         attr->la_gid, enforce, GRPQUOTA,
+                                         ignore_edquot);
                if (rc)
                        RETURN(rc);
 
@@ -2601,7 +2610,7 @@ static int osd_declare_attr_set(const struct lu_env *env,
                                        (attr->la_projid != projid);
                rc = osd_declare_attr_qid(env, obj, oh, bspace,
                                          (qid_t)projid, (qid_t)attr->la_projid,
-                                         enforce, PRJQUOTA);
+                                         enforce, PRJQUOTA, true);
                if (rc)
                        RETURN(rc);
        }
@@ -5618,7 +5627,7 @@ static int osd_index_declare_ea_insert(const struct lu_env *env,
                    i_projid_read(inode) != 0)
                        rc = osd_declare_attr_qid(env, osd_dt_obj(dt), oh,
                                                  0, i_projid_read(inode),
-                                                 0, false, PRJQUOTA);
+                                                 0, false, PRJQUOTA, true);
 #endif
        }