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>
#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_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
}
};
-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)
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;
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:
struct dt_object *root, *parent = NULL, *admin = NULL;
dt_obj_version_t version;
char *fname;
- bool isblk;
+ bool isblk, converted = false;
int rc;
ENTRY;
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) {
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);
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;
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,