Whamcloud - gitweb
LU-2346 quota: set default grace time
authorNiu Yawei <niu@whamcloud.com>
Fri, 16 Nov 2012 13:45:48 +0000 (08:45 -0500)
committerOleg Drokin <green@whamcloud.com>
Mon, 17 Dec 2012 06:37:59 +0000 (01:37 -0500)
Set default grace time as MAX_IQ_TIME or MAX_DQ_TIME.

Signed-off-by: Niu Yawei <niu@whamcloud.com>
Change-Id: I8f57e5483cdf0948532d3185fdf43c6efec73233
Reviewed-on: http://review.whamcloud.com/4598
Tested-by: Hudson
Reviewed-by: Johann Lombardi <johann.lombardi@intel.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Fan Yong <fan.yong@intel.com>
lustre/include/lustre_quota.h
lustre/osd-ldiskfs/osd_quota.c
lustre/quota/lquota_disk.c
lustre/quota/qmt_pool.c

index 8925380..8777ed5 100644 (file)
 #include <lustre_fid.h>
 #include <lustre_dlm.h>
 
 #include <lustre_fid.h>
 #include <lustre_dlm.h>
 
+#ifndef MAX_IQ_TIME
+#define MAX_IQ_TIME  604800     /* (7*24*60*60) 1 week */
+#endif
+
+#ifndef MAX_DQ_TIME
+#define MAX_DQ_TIME  604800     /* (7*24*60*60) 1 week */
+#endif
+
 struct lquota_id_info;
 struct lquota_trans;
 
 struct lquota_id_info;
 struct lquota_trans;
 
@@ -177,6 +185,10 @@ void qsd_op_end(const struct lu_env *, struct qsd_instance *,
                struct lquota_trans *);
 void qsd_op_adjust(const struct lu_env *, struct qsd_instance *,
                   union lquota_id *, int);
                struct lquota_trans *);
 void qsd_op_adjust(const struct lu_env *, struct qsd_instance *,
                   union lquota_id *, int);
+/* This is exported for the ldiskfs quota migration only,
+ * see convert_quota_file() */
+int lquota_disk_write_glb(const struct lu_env *, struct dt_object *,
+                         __u64, struct lquota_glb_rec *);
 
 /*
  * Quota information attached to a transaction
 
 /*
  * Quota information attached to a transaction
index 2bf0b5d..804f045 100644 (file)
@@ -723,63 +723,6 @@ const struct dt_index_operations osd_admin_index_ops = {
        }
 };
 
        }
 };
 
-static int write_quota_rec(const struct lu_env *env, struct dt_object *dt,
-                          __u64 id, struct lquota_glb_rec *rec)
-{
-       struct osd_device       *osd = osd_obj2dev(osd_dt_obj(dt));
-       struct thandle          *th;
-       struct dt_key           *key = (struct dt_key *)&id;
-       int                      rc;
-       ENTRY;
-
-       th = dt_trans_create(env, &osd->od_dt_dev);
-       if (IS_ERR(th))
-               RETURN(PTR_ERR(th));
-
-       /* the entry with 0 key can always be found in IAM file. */
-       if (id == 0) {
-               rc = dt_declare_delete(env, dt, key, th);
-               if (rc)
-                       GOTO(out, rc);
-       }
-
-       rc = dt_declare_insert(env, dt, (struct dt_rec *)rec, key, th);
-       if (rc)
-               GOTO(out, rc);
-
-       rc = dt_trans_start_local(env, &osd->od_dt_dev, th);
-       if (rc)
-               GOTO(out, rc);
-
-       dt_write_lock(env, dt, 0);
-
-       if (id == 0) {
-               struct lquota_glb_rec *tmp;
-
-               OBD_ALLOC_PTR(tmp);
-               if (tmp == NULL)
-                       GOTO(out_lock, rc = -ENOMEM);
-
-               rc = dt_lookup(env, dt, (struct dt_rec *)tmp, key,
-                              BYPASS_CAPA);
-
-               OBD_FREE_PTR(tmp);
-               if (rc == 0) {
-                       rc = dt_delete(env, dt, key, th, BYPASS_CAPA);
-                       if (rc)
-                               GOTO(out_lock, rc);
-               }
-               rc = 0;
-       }
-
-       rc = dt_insert(env, dt, (struct dt_rec *)rec, key, th, BYPASS_CAPA, 1);
-out_lock:
-       dt_write_unlock(env, dt);
-out:
-       dt_trans_stop(env, &osd->od_dt_dev, th);
-       RETURN(rc);
-}
-
 static int convert_quota_file(const struct lu_env *env,
                              struct dt_object *old, struct dt_object *new,
                              bool isblk)
 static int convert_quota_file(const struct lu_env *env,
                              struct dt_object *old, struct dt_object *new,
                              bool isblk)
@@ -829,7 +772,7 @@ static int convert_quota_file(const struct lu_env *env,
        grace = isblk ? dqinfo->dqi_bgrace : dqinfo->dqi_igrace;
        if (grace != 0) {
                glb_rec->qbr_time = grace;
        grace = isblk ? dqinfo->dqi_bgrace : dqinfo->dqi_igrace;
        if (grace != 0) {
                glb_rec->qbr_time = grace;
-               rc = write_quota_rec(env, new, 0, glb_rec);
+               rc = lquota_disk_write_glb(env, new, 0, glb_rec);
                if (rc)
                        GOTO(out, rc);
                glb_rec->qbr_time = 0;
                if (rc)
                        GOTO(out, rc);
                glb_rec->qbr_time = 0;
@@ -866,7 +809,7 @@ static int convert_quota_file(const struct lu_env *env,
                glb_rec->qbr_softlimit = isblk ? dqblk->dqb_bsoftlimit :
                                                 dqblk->dqb_isoftlimit;
 
                glb_rec->qbr_softlimit = isblk ? dqblk->dqb_bsoftlimit :
                                                 dqblk->dqb_isoftlimit;
 
-               rc = write_quota_rec(env, new, *((__u64 *)key), glb_rec);
+               rc = lquota_disk_write_glb(env, new, *((__u64 *)key), glb_rec);
                if (rc)
                        GOTO(out_it, rc);
 next:
                if (rc)
                        GOTO(out_it, rc);
 next:
@@ -1001,7 +944,7 @@ int osd_quota_migration(const struct lu_env *env, struct dt_object *dt,
        struct dt_object        *root, *parent = NULL, *admin = NULL;
        dt_obj_version_t         version;
        char                    *fname;
        struct dt_object        *root, *parent = NULL, *admin = NULL;
        dt_obj_version_t         version;
        char                    *fname;
-       bool                     isblk;
+       bool                     isblk, converted = false;
        int                      rc;
        ENTRY;
 
        int                      rc;
        ENTRY;
 
@@ -1103,7 +1046,24 @@ int osd_quota_migration(const struct lu_env *env, struct dt_object *dt,
        if (rc)
                CERROR("%s: Migrate old admin quota file(%s) failed, rc:%d\n",
                       osd->od_svname, fname, rc);
        if (rc)
                CERROR("%s: Migrate old admin quota file(%s) failed, rc:%d\n",
                       osd->od_svname, fname, rc);
+       converted = true;
 out:
 out:
+       /* if no migration happen, we need to set the default grace time. */
+       if (!converted && rc == 0) {
+               struct lquota_glb_rec *rec = &oti->oti_quota_rec.lqr_glb_rec;
+
+               rec->qbr_hardlimit = 0;
+               rec->qbr_softlimit = 0;
+               rec->qbr_granted = 0;
+               rec->qbr_time = isblk ? MAX_DQ_TIME : MAX_IQ_TIME;
+
+               rc = lquota_disk_write_glb(env, dt, 0, rec);
+               if (rc)
+                       CERROR("%s: Failed to set default grace time for "
+                              "index("DFID"), rc:%d\n", osd->od_svname,
+                              PFID(lu_object_fid(&dt->do_lu)), rc);
+       }
+
        /* bump index version to 1, so the migration will be skipped
         * next time. */
        if (rc == 0) {
        /* bump index version to 1, so the migration will be skipped
         * next time. */
        if (rc == 0) {
index 2b037e8..5f8c439 100644 (file)
@@ -741,3 +741,69 @@ out:
        dt_trans_stop(env, dev, th);
        return rc;
 }
        dt_trans_stop(env, dev, th);
        return rc;
 }
+
+/*
+ * Write a global record
+ *
+ * \param env - is the environment passed by the caller
+ * \param obj - is the on-disk global index to be updated
+ * \param id  - index to be updated
+ * \param rec - record to be written
+ */
+int lquota_disk_write_glb(const struct lu_env *env, struct dt_object *obj,
+                         __u64 id, struct lquota_glb_rec *rec)
+{
+       struct dt_device        *dev = lu2dt_dev(obj->do_lu.lo_dev);
+       struct thandle          *th;
+       struct dt_key           *key = (struct dt_key *)&id;
+       int                      rc;
+       ENTRY;
+
+       th = dt_trans_create(env, dev);
+       if (IS_ERR(th))
+               RETURN(PTR_ERR(th));
+
+       /* the entry with 0 key can always be found in IAM file. */
+       if (id == 0) {
+               rc = dt_declare_delete(env, obj, key, th);
+               if (rc)
+                       GOTO(out, rc);
+       }
+
+       rc = dt_declare_insert(env, obj, (struct dt_rec *)rec, key, th);
+       if (rc)
+               GOTO(out, rc);
+
+       rc = dt_trans_start_local(env, dev, th);
+       if (rc)
+               GOTO(out, rc);
+
+       dt_write_lock(env, obj, 0);
+
+       if (id == 0) {
+               struct lquota_glb_rec *tmp;
+
+               OBD_ALLOC_PTR(tmp);
+               if (tmp == NULL)
+                       GOTO(out_lock, rc = -ENOMEM);
+
+               rc = dt_lookup(env, obj, (struct dt_rec *)tmp, key,
+                              BYPASS_CAPA);
+
+               OBD_FREE_PTR(tmp);
+               if (rc == 0) {
+                       rc = dt_delete(env, obj, key, th, BYPASS_CAPA);
+                       if (rc)
+                               GOTO(out_lock, rc);
+               }
+               rc = 0;
+       }
+
+       rc = dt_insert(env, obj, (struct dt_rec *)rec, key, th, BYPASS_CAPA, 1);
+out_lock:
+       dt_write_unlock(env, obj);
+out:
+       dt_trans_stop(env, dev, th);
+       RETURN(rc);
+}
+EXPORT_SYMBOL(lquota_disk_write_glb);
index c1f8b72..ad9e478 100644 (file)
@@ -453,8 +453,10 @@ int qmt_pool_prepare(const struct lu_env *env, struct qmt_device *qmt,
                     struct dt_object *qmt_root)
 {
        struct qmt_thread_info  *qti = qmt_info(env);
                     struct dt_object *qmt_root)
 {
        struct qmt_thread_info  *qti = qmt_info(env);
+       struct lquota_glb_rec   *rec = &qti->qti_glb_rec;
        struct qmt_pool_info    *pool;
        struct dt_device        *dev = NULL;
        struct qmt_pool_info    *pool;
        struct dt_device        *dev = NULL;
+       dt_obj_version_t         version;
        cfs_list_t              *pos;
        int                      rc = 0, qtype;
        ENTRY;
        cfs_list_t              *pos;
        int                      rc = 0, qtype;
        ENTRY;
@@ -505,6 +507,34 @@ int qmt_pool_prepare(const struct lu_env *env, struct qmt_device *qmt,
 
                        pool->qpi_glb_obj[qtype] = obj;
 
 
                        pool->qpi_glb_obj[qtype] = obj;
 
+                       version = dt_version_get(env, obj);
+                       /* set default grace time for newly created index */
+                       if (version == 0) {
+                               rec->qbr_hardlimit = 0;
+                               rec->qbr_softlimit = 0;
+                               rec->qbr_granted = 0;
+                               rec->qbr_time = pool_type == LQUOTA_RES_MD ?
+                                       MAX_IQ_TIME : MAX_DQ_TIME;
+
+                               rc = lquota_disk_write_glb(env, obj, 0, rec);
+                               if (rc) {
+                                       CERROR("%s: failed to set default "
+                                              "grace time for %s type (%d)\n",
+                                              qmt->qmt_svname,
+                                              QTYPE_NAME(qtype), rc);
+                                       RETURN(rc);
+                               }
+
+                               rc = lquota_disk_update_ver(env, dev, obj, 1);
+                               if (rc) {
+                                       CERROR("%s: failed to set initial "
+                                              "version for %s type (%d)\n",
+                                              qmt->qmt_svname,
+                                              QTYPE_NAME(qtype), rc);
+                                       RETURN(rc);
+                               }
+                       }
+
                        /* create quota entry site for this quota type */
                        pool->qpi_site[qtype] = lquota_site_alloc(env, pool,
                                                                  true, qtype,
                        /* create quota entry site for this quota type */
                        pool->qpi_site[qtype] = lquota_site_alloc(env, pool,
                                                                  true, qtype,