* GPL HEADER END
*/
/*
- * Copyright (c) 2011, 2012, Intel, Inc.
+ * Copyright (c) 2012, 2015, Intel Corporation.
* Use is subject to license terms.
*
* Author: Johann Lombardi <johann.lombardi@intel.com>
* Author: Niu Yawei <yawei.niu@intel.com>
*/
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
-
#define DEBUG_SUBSYSTEM S_LQUOTA
#include <linux/version.h>
#include "lquota_internal.h"
+struct kmem_cache *lqe_kmem;
+
+struct lu_kmem_descr lquota_caches[] = {
+ {
+ .ckd_cache = &lqe_kmem,
+ .ckd_name = "lqe_kmem",
+ .ckd_size = sizeof(struct lquota_entry)
+ },
+ {
+ .ckd_cache = NULL
+ }
+};
+
/* register lquota key */
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.
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);
RETURN(obj);
if (!dt_object_exists(obj)) {
- lu_object_put(env, &obj->do_lu);
+ dt_object_put(env, obj);
RETURN(ERR_PTR(-ENOENT));
}
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));
}
}
ENTRY;
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_oid = qtype2slv_oid(type);
qti->qti_fid.f_ver = 0;
/* lookup the quota object */
RETURN(obj);
if (!dt_object_exists(obj)) {
- lu_object_put(env, &obj->do_lu);
+ dt_object_put(env, obj);
RETURN(ERR_PTR(-ENOENT));
}
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));
}
}
RETURN(-EOPNOTSUPP);
}
- if (oqctl->qc_type != USRQUOTA && oqctl->qc_type != GRPQUOTA)
+ if (oqctl->qc_type < 0 || oqctl->qc_type >= MAXQUOTAS)
/* no support for directory quota yet */
RETURN(-EOPNOTSUPP);
/* lookup record storing space accounting information for this ID */
rc = dt_lookup(env, obj, (struct dt_rec *)&qti->qti_acct_rec,
- (struct dt_key *)&key, BYPASS_CAPA);
+ (struct dt_key *)&key);
if (rc < 0)
GOTO(out, rc);
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 */
memset(&qti->qti_slv_rec, 0, sizeof(qti->qti_slv_rec));
/* lookup record storing enforcement information for this ID */
rc = dt_lookup(env, obj, (struct dt_rec *)&qti->qti_slv_rec,
- (struct dt_key *)&key, BYPASS_CAPA);
+ (struct dt_key *)&key);
if (rc < 0 && rc != -ENOENT)
GOTO(out, rc = 0);
GOTO(out, rc = 0);
out:
- lu_object_put(env, &obj->do_lu);
- return rc;
+ dt_object_put(env, obj);
+ return rc;
}
EXPORT_SYMBOL(lquotactl_slv);
-static int __init init_lquota(void)
+static inline __u8 qtype2lqtype(int qtype)
{
- int rc;
+ switch (qtype) {
+ case USRQUOTA:
+ return LQUOTA_TYPE_USR;
+ case GRPQUOTA:
+ return LQUOTA_TYPE_GRP;
+ case PRJQUOTA:
+ return LQUOTA_TYPE_PRJ;
+ }
- /* call old quota module init function */
- rc = init_lustre_quota();
- if (rc)
- return rc;
+ 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
+ * the quota type \quota_type.
+ */
+void lquota_generate_fid(struct lu_fid *fid, int pool_id, int pool_type,
+ int quota_type)
+{
+ __u8 lqtype = qtype2lqtype(quota_type);
+
+ fid->f_seq = FID_SEQ_QUOTA_GLB;
+ fid->f_oid = (lqtype << 24) | (pool_type << 16) | (__u16)pool_id;
+ fid->f_ver = 0;
+}
+
+/**
+ * Helper routine used to extract pool ID, 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 *quota_type)
+{
+ unsigned int lqtype;
+ ENTRY;
+
+ if (fid->f_seq != FID_SEQ_QUOTA_GLB)
+ RETURN(-EINVAL);
+
+ if (pool_id != NULL) {
+ lqtype = fid->f_oid & 0xffffU;
+ if (lqtype != 0)
+ /* we only support pool ID 0 for the time being */
+ RETURN(-ENOTSUPP);
+ *pool_id = lqtype;
+ }
+
+ if (pool_type != NULL) {
+ lqtype = (fid->f_oid >> 16) & 0xffU;
+ if (lqtype >= LQUOTA_LAST_RES)
+ RETURN(-ENOTSUPP);
+
+ *pool_type = lqtype;
+ }
+
+ if (quota_type != NULL) {
+ lqtype = fid->f_oid >> 24;
+ if (lqtype >= LQUOTA_TYPE_MAX)
+ RETURN(-ENOTSUPP);
+
+ *quota_type = lqtype2qtype(lqtype);
+ }
+
+ RETURN(0);
+}
+
+static int __init lquota_init(void)
+{
+ int rc;
+ ENTRY;
- /* new quota initialization */
lquota_key_init_generic(&lquota_thread_key, NULL);
lu_context_key_register(&lquota_thread_key);
- return 0;
+ rc = lu_kmem_init(lquota_caches);
+ if (rc)
+ GOTO(out_key, rc);
+
+ rc = qmt_glb_init();
+ if (rc)
+ GOTO(out_caches, rc);
+
+ rc = qsd_glb_init();
+ if (rc)
+ GOTO(out_qmt, rc);
+
+ RETURN(0);
+
+out_qmt:
+ qmt_glb_fini();
+out_caches:
+ lu_kmem_fini(lquota_caches);
+out_key:
+ lu_context_key_degister(&lquota_thread_key);
+ return rc;
}
-static void exit_lquota(void)
+static void __exit lquota_exit(void)
{
- /* call old quota module exit function */
- exit_lustre_quota();
-
+ qsd_glb_fini();
+ qmt_glb_fini();
+ lu_kmem_fini(lquota_caches);
lu_context_key_degister(&lquota_thread_key);
}
-MODULE_AUTHOR("Intel, Inc. <http://www.intel.com/>");
+MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
MODULE_DESCRIPTION("Lustre Quota");
+MODULE_VERSION(LUSTRE_VERSION_STRING);
MODULE_LICENSE("GPL");
-cfs_module(lquota, "2.4.0", init_lquota, exit_lquota);
+module_init(lquota_init);
+module_exit(lquota_exit);