Whamcloud - gitweb
LU-3409 llite: silence lockdep warning in ll_md_blocking_ast
[fs/lustre-release.git] / lustre / quota / lquota_lib.c
index 51a0c49..f7d2bc4 100644 (file)
@@ -21,7 +21,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2011, 2012, Intel, Inc.
+ * Copyright (c) 2012, 2013, Intel Corporation.
  * Use is subject to license terms.
  *
  * Author: Johann Lombardi <johann.lombardi@intel.com>
 
 #include "lquota_internal.h"
 
+cfs_mem_cache_t *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);
@@ -223,31 +236,153 @@ out:
 }
 EXPORT_SYMBOL(lquotactl_slv);
 
-static int __init init_lquota(void)
+/**
+ * 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)
 {
-       int     rc;
+       __u8     qtype;
+
+       qtype = (quota_type == USRQUOTA) ? LQUOTA_TYPE_USR : LQUOTA_TYPE_GRP;
+
+       fid->f_seq = FID_SEQ_QUOTA_GLB;
+       fid->f_oid = (qtype << 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     tmp;
+       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)
+                       RETURN(-ENOTSUPP);
+
+               *pool_type = tmp;
+       }
+
+       if (quota_type != NULL) {
+               tmp = fid->f_oid >> 24;
+               if (tmp >= LQUOTA_TYPE_MAX)
+                       RETURN(-ENOTSUPP);
+
+               *quota_type = (tmp == LQUOTA_TYPE_USR) ? USRQUOTA : GRPQUOTA;
+       }
+
+       RETURN(0);
+}
 
-       /* call old quota module init function */
-       rc = init_lustre_quota();
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2,7,50,0)
+/* Index features supported by the global index objects.
+ * We actually use one dt_index_features structure for each quota combination
+ * of quota type x [inode, block] to allow the ldiskfs OSD to recognize those
+ * objects and to handle the conversion from the old administrative quota file
+ * format */
+struct dt_index_features dt_quota_iusr_features;
+EXPORT_SYMBOL(dt_quota_iusr_features);
+struct dt_index_features dt_quota_busr_features;
+EXPORT_SYMBOL(dt_quota_busr_features);
+struct dt_index_features dt_quota_igrp_features;
+EXPORT_SYMBOL(dt_quota_igrp_features);
+struct dt_index_features dt_quota_bgrp_features;
+EXPORT_SYMBOL(dt_quota_bgrp_features);
+
+/**
+ * Helper routine returning the right index feature structure to be used
+ * depending on the FID of the global index.
+ */
+const struct dt_index_features *glb_idx_feature(struct lu_fid *fid)
+{
+       int     res_type, quota_type, rc;
+
+       rc = lquota_extract_fid(fid, NULL, &res_type, &quota_type);
        if (rc)
-               return rc;
+               return ERR_PTR(rc);
+
+       if (quota_type == USRQUOTA) {
+               if (res_type == LQUOTA_RES_MD)
+                       return &dt_quota_iusr_features;
+               else
+                       return &dt_quota_busr_features;
+       } else {
+               if (res_type == LQUOTA_RES_MD)
+                       return &dt_quota_igrp_features;
+               else
+                       return &dt_quota_bgrp_features;
+       }
+}
+#else
+#warning "remove old quota compatibility code"
+#endif
+
+static int __init init_lquota(void)
+{
+       int     rc;
+       ENTRY;
 
-       /* new quota initialization */
        lquota_key_init_generic(&lquota_thread_key, NULL);
        lu_context_key_register(&lquota_thread_key);
 
-       return 0;
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2,7,50,0)
+       dt_quota_iusr_features = dt_quota_busr_features = dt_quota_glb_features;
+       dt_quota_igrp_features = dt_quota_bgrp_features = dt_quota_glb_features;
+#else
+#warning "remove old quota compatibility code"
+#endif
+
+       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)
 {
-       /* 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("Intel Corporation <http://www.intel.com/>");
 MODULE_DESCRIPTION("Lustre Quota");
 MODULE_LICENSE("GPL");