Whamcloud - gitweb
LU-5777 quota: reserve enough credits for setattr 61/12361/3
authorNiu Yawei <yawei.niu@intel.com>
Tue, 21 Oct 2014 11:07:30 +0000 (07:07 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 29 Oct 2014 14:42:11 +0000 (14:42 +0000)
On chown/chgrp operation, the file to be changed could be the
last file of owner/group, and the user/group ID entry could be
removed from the quota file in this setattr operation. We'd
reserve enough journal credits for such case.

Signed-off-by: Niu Yawei <yawei.niu@intel.com>
Change-Id: Ida22092739a6380cca0d6eccc45e1f06f5e82adb
Reviewed-on: http://review.whamcloud.com/12361
Tested-by: Jenkins
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Bobi Jam <bobijam@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/osd-ldiskfs/osd_quota.c

index 4051640..38cf125 100644 (file)
@@ -512,7 +512,7 @@ int osd_declare_qid(const struct lu_env *env, struct osd_thandle *oh,
        struct osd_device       *dev = info->oti_dev;
        struct qsd_instance     *qsd = dev->od_quota_slave;
        struct inode            *inode = NULL;
        struct osd_device       *dev = info->oti_dev;
        struct qsd_instance     *qsd = dev->od_quota_slave;
        struct inode            *inode = NULL;
-       int                      i, rc = 0;
+       int                      i, rc = 0, crd;
        bool                     found = false;
        ENTRY;
 
        bool                     found = false;
        ENTRY;
 
@@ -537,11 +537,26 @@ int osd_declare_qid(const struct lu_env *env, struct osd_thandle *oh,
 
                if (obj != NULL)
                        inode = obj->oo_inode;
 
                if (obj != NULL)
                        inode = obj->oo_inode;
-               osd_trans_declare_op(env, oh, OSD_OT_QUOTA,
-                                    (qi->lqi_id.qid_uid == 0 ||
-                                     (inode != NULL &&
-                                      inode->i_dquot[qi->lqi_type] != NULL)) ?
-                                    1: LDISKFS_QUOTA_INIT_BLOCKS(osd_sb(dev)));
+
+               /* root ID entry should be always present in the quota file */
+               if (qi->lqi_id.qid_uid == 0) {
+                       crd = 1;
+               } else {
+                       /* used space for this ID could be dropped to zero,
+                        * reserve extra credits for removing ID entry from
+                        * the quota file */
+                       if (qi->lqi_space < 0)
+                               crd = LDISKFS_QUOTA_DEL_BLOCKS(osd_sb(dev));
+                       /* reserve credits for adding ID entry to the quota
+                        * file if the i_dquot isn't initialized yet. */
+                       else if (inode == NULL ||
+                                inode->i_dquot[qi->lqi_type] == NULL)
+                               crd = LDISKFS_QUOTA_INIT_BLOCKS(osd_sb(dev));
+                       else
+                               crd = 1;
+               }
+
+               osd_trans_declare_op(env, oh, OSD_OT_QUOTA, crd);
 
                oh->ot_id_array[i] = qi->lqi_id.qid_uid;
                osd_qid_set_type(oh, i, qi->lqi_type);
 
                oh->ot_id_array[i] = qi->lqi_id.qid_uid;
                osd_qid_set_type(oh, i, qi->lqi_type);