X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fquota%2Flquota_lib.c;h=8bbc58b3591979237561a860481c30265fdf895f;hb=416e67222b769df490a8be034ef987a596dd8dff;hp=9f3f3242d7db01824bf86e722fa4919890406303;hpb=0754bc8f2623bea184111af216f7567608db35b6;p=fs%2Flustre-release.git diff --git a/lustre/quota/lquota_lib.c b/lustre/quota/lquota_lib.c index 9f3f324..8bbc58b 100644 --- a/lustre/quota/lquota_lib.c +++ b/lustre/quota/lquota_lib.c @@ -21,7 +21,7 @@ * GPL HEADER END */ /* - * Copyright (c) 2012, 2015, Intel Corporation. + * Copyright (c) 2012, 2017, Intel Corporation. * Use is subject to license terms. * * Author: Johann Lombardi @@ -54,6 +54,20 @@ LU_KEY_INIT_FINI(lquota, struct lquota_thread_info); LU_CONTEXT_KEY_DEFINE(lquota, LCT_MD_THREAD | LCT_DT_THREAD | LCT_LOCAL); LU_KEY_INIT_GENERIC(lquota); +static inline __u32 qtype2acct_oid(int qtype) +{ + switch (qtype) { + case USRQUOTA: + return ACCT_USER_OID; + case GRPQUOTA: + return ACCT_GROUP_OID; + case PRJQUOTA: + return ACCT_PROJECT_OID; + } + + return ACCT_GROUP_OID; +} + /** * Look-up accounting object to collect space usage information for user * or group. @@ -69,8 +83,7 @@ struct dt_object *acct_obj_lookup(const struct lu_env *env, struct dt_object *obj = NULL; ENTRY; - lu_local_obj_fid(&qti->qti_fid, - type == USRQUOTA ? ACCT_USER_OID : ACCT_GROUP_OID); + lu_local_obj_fid(&qti->qti_fid, qtype2acct_oid(type)); /* lookup the accounting object */ obj = dt_locate(env, dev, &qti->qti_fid); @@ -78,7 +91,7 @@ struct dt_object *acct_obj_lookup(const struct lu_env *env, RETURN(obj); if (!dt_object_exists(obj)) { - lu_object_put(env, &obj->do_lu); + dt_object_put(env, obj); RETURN(ERR_PTR(-ENOENT)); } @@ -91,8 +104,8 @@ struct dt_object *acct_obj_lookup(const struct lu_env *env, CERROR("%s: failed to set up indexing operations for %s" " acct object rc:%d\n", dev->dd_lu_dev.ld_obd->obd_name, - QTYPE_NAME(type), rc); - lu_object_put(env, &obj->do_lu); + qtype_name(type), rc); + dt_object_put(env, obj); RETURN(ERR_PTR(rc)); } } @@ -104,17 +117,26 @@ struct dt_object *acct_obj_lookup(const struct lu_env *env, * * \param env - is the environment passed by the caller * \param dev - is the dt_device storing the slave index object + * \param pool - is the pool type, either LQUOTA_RES_MD or LQUOTA_RES_DT * \param type - is the quota type, either USRQUOTA or GRPQUOTA */ static struct dt_object *quota_obj_lookup(const struct lu_env *env, - struct dt_device *dev, int type) + struct dt_device *dev, int pool, + int type) { struct lquota_thread_info *qti = lquota_info(env); struct dt_object *obj = NULL; + int is_md; ENTRY; + is_md = lu_device_is_md(dev->dd_lu_dev.ld_site->ls_top_dev); + if ((is_md && pool == LQUOTA_RES_MD) || + (!is_md && pool == LQUOTA_RES_DT)) + qti->qti_fid.f_oid = qtype2slv_oid(type); + else + qti->qti_fid.f_oid = pool << 16 | qtype2slv_oid(type); + qti->qti_fid.f_seq = FID_SEQ_QUOTA; - qti->qti_fid.f_oid = type == USRQUOTA ? LQUOTA_USR_OID : LQUOTA_GRP_OID; qti->qti_fid.f_ver = 0; /* lookup the quota object */ @@ -123,7 +145,7 @@ static struct dt_object *quota_obj_lookup(const struct lu_env *env, RETURN(obj); if (!dt_object_exists(obj)) { - lu_object_put(env, &obj->do_lu); + dt_object_put(env, obj); RETURN(ERR_PTR(-ENOENT)); } @@ -137,8 +159,8 @@ static struct dt_object *quota_obj_lookup(const struct lu_env *env, CERROR("%s: failed to set up indexing operations for %s" " slave index object rc:%d\n", dev->dd_lu_dev.ld_obd->obd_name, - QTYPE_NAME(type), rc); - lu_object_put(env, &obj->do_lu); + qtype_name(type), rc); + dt_object_put(env, obj); RETURN(ERR_PTR(rc)); } } @@ -160,7 +182,7 @@ int lquotactl_slv(const struct lu_env *env, struct dt_device *dev, { struct lquota_thread_info *qti = lquota_info(env); __u64 key; - struct dt_object *obj; + struct dt_object *obj, *obj_aux = NULL; struct obd_dqblk *dqblk = &oqctl->qc_dqblk; int rc; ENTRY; @@ -173,8 +195,7 @@ int lquotactl_slv(const struct lu_env *env, struct dt_device *dev, RETURN(-EOPNOTSUPP); } - if (oqctl->qc_type != USRQUOTA && oqctl->qc_type != GRPQUOTA) - /* no support for directory quota yet */ + if (oqctl->qc_type < 0 || oqctl->qc_type >= LL_MAXQUOTAS) RETURN(-EOPNOTSUPP); /* qc_id is a 32-bit field while a key has 64 bits */ @@ -199,11 +220,15 @@ int lquotactl_slv(const struct lu_env *env, struct dt_device *dev, dqblk->dqb_curinodes = qti->qti_acct_rec.ispace; dqblk->dqb_valid = QIF_USAGE; - lu_object_put(env, &obj->do_lu); + dt_object_put(env, obj); /* Step 2: collect enforcement information */ - obj = quota_obj_lookup(env, dev, oqctl->qc_type); + if (lu_device_is_md(dev->dd_lu_dev.ld_site->ls_top_dev)) + obj = quota_obj_lookup(env, dev, LQUOTA_RES_MD, oqctl->qc_type); + else + obj = quota_obj_lookup(env, dev, LQUOTA_RES_DT, oqctl->qc_type); + if (IS_ERR(obj)) RETURN(0); if (obj->do_index_ops == NULL) @@ -219,6 +244,24 @@ int lquotactl_slv(const struct lu_env *env, struct dt_device *dev, if (lu_device_is_md(dev->dd_lu_dev.ld_site->ls_top_dev)) { dqblk->dqb_ihardlimit = qti->qti_slv_rec.qsr_granted; dqblk->dqb_bhardlimit = 0; + + obj_aux = quota_obj_lookup(env, dev, LQUOTA_RES_DT, + oqctl->qc_type); + if (IS_ERR(obj_aux)) { + obj_aux = NULL; + GOTO(out, rc = 0); + } + + if (obj_aux->do_index_ops == NULL) + GOTO(out, rc = 0); + + memset(&qti->qti_slv_rec, 0, sizeof(qti->qti_slv_rec)); + rc = dt_lookup(env, obj_aux, (struct dt_rec *)&qti->qti_slv_rec, + (struct dt_key *)&key); + if (rc < 0 && rc != -ENOENT) + GOTO(out, rc = 0); + + dqblk->dqb_bhardlimit = qti->qti_slv_rec.qsr_granted; } else { dqblk->dqb_ihardlimit = 0; dqblk->dqb_bhardlimit = qti->qti_slv_rec.qsr_granted; @@ -227,69 +270,88 @@ int lquotactl_slv(const struct lu_env *env, struct dt_device *dev, GOTO(out, rc = 0); out: - lu_object_put(env, &obj->do_lu); - return rc; + dt_object_put(env, obj); + if (obj_aux != NULL) + dt_object_put(env, obj_aux); + return rc; } EXPORT_SYMBOL(lquotactl_slv); +static inline __u8 qtype2lqtype(int qtype) +{ + switch (qtype) { + case USRQUOTA: + return LQUOTA_TYPE_USR; + case GRPQUOTA: + return LQUOTA_TYPE_GRP; + case PRJQUOTA: + return LQUOTA_TYPE_PRJ; + } + + return LQUOTA_TYPE_GRP; +} + +static inline int lqtype2qtype(int lqtype) +{ + switch (lqtype) { + case LQUOTA_TYPE_USR: + return USRQUOTA; + case LQUOTA_TYPE_GRP: + return GRPQUOTA; + case LQUOTA_TYPE_PRJ: + return PRJQUOTA; + } + + return GRPQUOTA; +} + /** * Helper routine returning the FID associated with the global index storing - * quota settings for the storage pool \pool_id, resource type \pool_type and + * quota settings for default storage pool, resource type \pool_type and * the quota type \quota_type. */ -void lquota_generate_fid(struct lu_fid *fid, int pool_id, int pool_type, - int quota_type) +void lquota_generate_fid(struct lu_fid *fid, int pool_type, int quota_type) { - __u8 qtype; - - qtype = (quota_type == USRQUOTA) ? LQUOTA_TYPE_USR : LQUOTA_TYPE_GRP; + __u8 lqtype = qtype2lqtype(quota_type); fid->f_seq = FID_SEQ_QUOTA_GLB; - fid->f_oid = (qtype << 24) | (pool_type << 16) | (__u16)pool_id; + fid->f_oid = (lqtype << 24) | (pool_type << 16); fid->f_ver = 0; } /** - * Helper routine used to extract pool ID, pool type and quota type from a + * Helper routine used to extract pool type and quota type from a * given FID. */ -int lquota_extract_fid(const struct lu_fid *fid, int *pool_id, int *pool_type, +int lquota_extract_fid(const struct lu_fid *fid, int *pool_type, int *quota_type) { - unsigned int tmp; + unsigned int lqtype; ENTRY; if (fid->f_seq != FID_SEQ_QUOTA_GLB) RETURN(-EINVAL); - if (pool_id != NULL) { - tmp = fid->f_oid & 0xffffU; - if (tmp != 0) - /* we only support pool ID 0 for the time being */ - RETURN(-ENOTSUPP); - *pool_id = tmp; - } - if (pool_type != NULL) { - tmp = (fid->f_oid >> 16) & 0xffU; - if (tmp >= LQUOTA_LAST_RES) + lqtype = (fid->f_oid >> 16) & 0xffU; + if (lqtype >= LQUOTA_LAST_RES) RETURN(-ENOTSUPP); - *pool_type = tmp; + *pool_type = lqtype; } if (quota_type != NULL) { - tmp = fid->f_oid >> 24; - if (tmp >= LQUOTA_TYPE_MAX) + lqtype = fid->f_oid >> 24; + if (lqtype >= LQUOTA_TYPE_MAX) RETURN(-ENOTSUPP); - *quota_type = (tmp == LQUOTA_TYPE_USR) ? USRQUOTA : GRPQUOTA; + *quota_type = lqtype2qtype(lqtype); } RETURN(0); } -static int __init init_lquota(void) +static int __init lquota_init(void) { int rc; ENTRY; @@ -320,7 +382,7 @@ out_key: return rc; } -static void exit_lquota(void) +static void __exit lquota_exit(void) { qsd_glb_fini(); qmt_glb_fini(); @@ -333,5 +395,5 @@ MODULE_DESCRIPTION("Lustre Quota"); MODULE_VERSION(LUSTRE_VERSION_STRING); MODULE_LICENSE("GPL"); -module_init(init_lquota); -module_exit(exit_lquota); +module_init(lquota_init); +module_exit(lquota_exit);