Whamcloud - gitweb
LU-5734 lnet: improve clean up code and API
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_quota.c
index 4051640..753562d 100644 (file)
@@ -21,7 +21,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2012, 2013, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  * Use is subject to license terms.
  *
  * Author: Johann Lombardi <johann@whamcloud.com>
@@ -166,7 +166,15 @@ static struct dt_it *osd_it_acct_init(const struct lu_env *env,
        if (info == NULL)
                RETURN(ERR_PTR(-ENOMEM));
 
-       it = &info->oti_it_quota;
+       if (info->oti_it_inline) {
+               OBD_ALLOC_PTR(it);
+               if (it == NULL)
+                       RETURN(ERR_PTR(-ENOMEM));
+       } else {
+               it = &info->oti_it_quota;
+               info->oti_it_inline = 1;
+       }
+
        memset(it, 0, sizeof(*it));
        lu_object_get(lo);
        it->oiq_obj = obj;
@@ -188,6 +196,7 @@ static struct dt_it *osd_it_acct_init(const struct lu_env *env,
  */
 static void osd_it_acct_fini(const struct lu_env *env, struct dt_it *di)
 {
+       struct osd_thread_info *info = osd_oti_get(env);
        struct osd_it_quota *it = (struct osd_it_quota *)di;
        struct osd_quota_leaf *leaf, *tmp;
        ENTRY;
@@ -198,6 +207,12 @@ static void osd_it_acct_fini(const struct lu_env *env, struct dt_it *di)
                list_del_init(&leaf->oql_link);
                OBD_FREE_PTR(leaf);
        }
+
+       if (it != &info->oti_it_quota)
+               OBD_FREE_PTR(it);
+       else
+               info->oti_it_inline = 0;
+
        EXIT;
 }
 
@@ -512,7 +527,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;
-       int                      i, rc = 0;
+       int                      i, rc = 0, crd;
        bool                     found = false;
        ENTRY;
 
@@ -537,11 +552,26 @@ int osd_declare_qid(const struct lu_env *env, struct osd_thandle *oh,
 
                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);
@@ -736,7 +766,7 @@ static int osd_it_admin_next(const struct lu_env *env, struct dt_it *di)
        RETURN(rc);
 }
 
-const struct dt_index_operations osd_admin_index_ops = {
+static const struct dt_index_operations osd_admin_index_ops = {
        .dio_lookup     = osd_acct_index_lookup,
        .dio_it         = {
                .init     = osd_it_acct_init,