From 2a42554850e92ef1aa515269e7d2a4020403c12d Mon Sep 17 00:00:00 2001 From: Niu Yawei Date: Fri, 16 Nov 2012 08:45:48 -0500 Subject: [PATCH] LU-2346 quota: set default grace time Set default grace time as MAX_IQ_TIME or MAX_DQ_TIME. Signed-off-by: Niu Yawei Change-Id: I8f57e5483cdf0948532d3185fdf43c6efec73233 Reviewed-on: http://review.whamcloud.com/4598 Tested-by: Hudson Reviewed-by: Johann Lombardi Tested-by: Maloo Reviewed-by: Fan Yong --- lustre/include/lustre_quota.h | 12 +++++++ lustre/osd-ldiskfs/osd_quota.c | 80 +++++++++++------------------------------- lustre/quota/lquota_disk.c | 66 ++++++++++++++++++++++++++++++++++ lustre/quota/qmt_pool.c | 30 ++++++++++++++++ 4 files changed, 128 insertions(+), 60 deletions(-) diff --git a/lustre/include/lustre_quota.h b/lustre/include/lustre_quota.h index 8925380..8777ed5 100644 --- a/lustre/include/lustre_quota.h +++ b/lustre/include/lustre_quota.h @@ -45,6 +45,14 @@ #include #include +#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; @@ -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); +/* 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 diff --git a/lustre/osd-ldiskfs/osd_quota.c b/lustre/osd-ldiskfs/osd_quota.c index 2bf0b5d..804f045 100644 --- a/lustre/osd-ldiskfs/osd_quota.c +++ b/lustre/osd-ldiskfs/osd_quota.c @@ -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) @@ -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; - 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; @@ -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; - 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: @@ -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; - bool isblk; + bool isblk, converted = false; 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); + converted = true; 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) { diff --git a/lustre/quota/lquota_disk.c b/lustre/quota/lquota_disk.c index 2b037e8..5f8c439 100644 --- a/lustre/quota/lquota_disk.c +++ b/lustre/quota/lquota_disk.c @@ -741,3 +741,69 @@ out: 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); diff --git a/lustre/quota/qmt_pool.c b/lustre/quota/qmt_pool.c index c1f8b72..ad9e478 100644 --- a/lustre/quota/qmt_pool.c +++ b/lustre/quota/qmt_pool.c @@ -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 lquota_glb_rec *rec = &qti->qti_glb_rec; struct qmt_pool_info *pool; struct dt_device *dev = NULL; + dt_obj_version_t version; 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; + 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, -- 1.8.3.1