X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fquota%2Flquota_entry.c;h=ae495d8348eba6dee735e4358831b6b14151cb20;hp=830e9cf4a28da0b8dd3c203f554c3e17a0acceb5;hb=72617588ac8cb2e3e5a7b8e5ebc201cab524d938;hpb=c40c7939c0110ca53151c47249d85e56a6e0f24d diff --git a/lustre/quota/lquota_entry.c b/lustre/quota/lquota_entry.c index 830e9cf..ae495d8 100644 --- a/lustre/quota/lquota_entry.c +++ b/lustre/quota/lquota_entry.c @@ -20,17 +20,13 @@ * GPL HEADER END */ /* - * Copyright (c) 2011, 2012, Intel, Inc. + * Copyright (c) 2012, 2015, Intel Corporation. * Use is subject to license terms. * * Author: Johann Lombardi * Author: Niu Yawei */ -#ifndef EXPORT_SYMTAB -# define EXPORT_SYMTAB -#endif - #define DEBUG_SUBSYSTEM S_LQUOTA #include @@ -39,56 +35,56 @@ #include "lquota_internal.h" static int hash_lqs_cur_bits = HASH_LQE_CUR_BITS; -CFS_MODULE_PARM(hash_lqs_cur_bits, "i", int, 0444, - "the current bits of lqe hash"); -cfs_mem_cache_t *lqe_kmem; +module_param(hash_lqs_cur_bits, int, 0444); +MODULE_PARM_DESC(hash_lqs_cur_bits, "the current bits of lqe hash"); -static unsigned lqe64_hash_hash(cfs_hash_t *hs, const void *key, unsigned mask) +static unsigned +lqe64_hash_hash(struct cfs_hash *hs, const void *key, unsigned mask) { return cfs_hash_u64_hash(*((__u64 *)key), mask); } -static void *lqe64_hash_key(cfs_hlist_node_t *hnode) +static void *lqe64_hash_key(struct hlist_node *hnode) { struct lquota_entry *lqe; - lqe = cfs_hlist_entry(hnode, struct lquota_entry, lqe_hash); + lqe = hlist_entry(hnode, struct lquota_entry, lqe_hash); return &lqe->lqe_id.qid_uid; } -static int lqe64_hash_keycmp(const void *key, cfs_hlist_node_t *hnode) +static int lqe64_hash_keycmp(const void *key, struct hlist_node *hnode) { struct lquota_entry *lqe; - lqe = cfs_hlist_entry(hnode, struct lquota_entry, lqe_hash); + lqe = hlist_entry(hnode, struct lquota_entry, lqe_hash); return (lqe->lqe_id.qid_uid == *((__u64*)key)); } -static void *lqe_hash_object(cfs_hlist_node_t *hnode) +static void *lqe_hash_object(struct hlist_node *hnode) { - return cfs_hlist_entry(hnode, struct lquota_entry, lqe_hash); + return hlist_entry(hnode, struct lquota_entry, lqe_hash); } -static void lqe_hash_get(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +static void lqe_hash_get(struct cfs_hash *hs, struct hlist_node *hnode) { struct lquota_entry *lqe; - lqe = cfs_hlist_entry(hnode, struct lquota_entry, lqe_hash); + lqe = hlist_entry(hnode, struct lquota_entry, lqe_hash); lqe_getref(lqe); } -static void lqe_hash_put_locked(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +static void lqe_hash_put_locked(struct cfs_hash *hs, struct hlist_node *hnode) { struct lquota_entry *lqe; - lqe = cfs_hlist_entry(hnode, struct lquota_entry, lqe_hash); + lqe = hlist_entry(hnode, struct lquota_entry, lqe_hash); lqe_putref(lqe); } -static void lqe_hash_exit(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +static void lqe_hash_exit(struct cfs_hash *hs, struct hlist_node *hnode) { CERROR("Should not have any item left!\n"); } /* lqe hash methods for 64-bit uid/gid, new hash functions would have to be * defined for per-directory quota relying on a 128-bit FID */ -static cfs_hash_ops_t lqe64_hash_ops = { +static struct cfs_hash_ops lqe64_hash_ops = { .hs_hash = lqe64_hash_hash, .hs_key = lqe64_hash_key, .hs_keycmp = lqe64_hash_keycmp, @@ -104,12 +100,15 @@ void lquota_lqe_debug0(struct lquota_entry *lqe, const char *fmt, ...) { struct lquota_site *site = lqe->lqe_site; + struct va_format vaf; va_list args; LASSERT(site->lqs_ops->lqe_debug != NULL); va_start(args, fmt); - site->lqs_ops->lqe_debug(lqe, site->lqs_parent, msgdata, fmt, args); + vaf.fmt = fmt; + vaf.va = &args; + site->lqs_ops->lqe_debug(lqe, site->lqs_parent, msgdata, &vaf); va_end(args); } @@ -119,13 +118,13 @@ struct lqe_iter_data { bool lid_free_all; }; -static int lqe_iter_cb(cfs_hash_t *hs, cfs_hash_bd_t *bd, - cfs_hlist_node_t *hnode, void *data) +static int lqe_iter_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd, + struct hlist_node *hnode, void *data) { struct lqe_iter_data *d = (struct lqe_iter_data *)data; struct lquota_entry *lqe; - lqe = cfs_hlist_entry(hnode, struct lquota_entry, lqe_hash); + lqe = hlist_entry(hnode, struct lquota_entry, lqe_hash); LASSERT(atomic_read(&lqe->lqe_ref) > 0); /* Only one reference held by hash table, and nobody else can @@ -156,7 +155,7 @@ static int lqe_iter_cb(cfs_hash_t *hs, cfs_hash_bd_t *bd, * \param free_all - free all entries or only free the entries * without quota enforce ? */ -static void lqe_cleanup(cfs_hash_t *hash, bool free_all) +static void lqe_cleanup(struct cfs_hash *hash, bool free_all) { struct lqe_iter_data d; int repeat = 0; @@ -177,8 +176,7 @@ retry: "freed:%lu, repeat:%u\n", hash, d.lid_inuse, d.lid_freed, repeat); repeat++; - cfs_schedule_timeout_and_set_state(CFS_TASK_INTERRUPTIBLE, - cfs_time_seconds(1)); + schedule_timeout_interruptible(cfs_time_seconds(1)); goto retry; } EXIT; @@ -207,7 +205,8 @@ struct lquota_site *lquota_site_alloc(const struct lu_env *env, void *parent, char hashname[15]; ENTRY; - LASSERT(qtype < MAXQUOTAS); + if (qtype >= LL_MAXQUOTAS) + RETURN(ERR_PTR(-ENOTSUPP)); OBD_ALLOC_PTR(site); if (site == NULL) @@ -221,14 +220,18 @@ struct lquota_site *lquota_site_alloc(const struct lu_env *env, void *parent, /* allocate hash table */ memset(hashname, 0, sizeof(hashname)); - sprintf(hashname, "LQUOTA_HASH%u", qtype); + snprintf(hashname, sizeof(hashname), "LQUOTA_HASH%hu", qtype); site->lqs_hash= cfs_hash_create(hashname, hash_lqs_cur_bits, HASH_LQE_MAX_BITS, min(hash_lqs_cur_bits, HASH_LQE_BKT_BITS), 0, CFS_HASH_MIN_THETA, CFS_HASH_MAX_THETA, &lqe64_hash_ops, - CFS_HASH_DEFAULT|CFS_HASH_BIGNAME); + CFS_HASH_RW_SEM_BKTLOCK | + CFS_HASH_COUNTER | + CFS_HASH_REHASH | + CFS_HASH_BIGNAME); + if (site->lqs_hash == NULL) { OBD_FREE_PTR(site); RETURN(ERR_PTR(-ENOMEM)); @@ -282,8 +285,10 @@ static void lqe_init(struct lquota_entry *lqe) * * \param env - the environment passed by the caller * \param lqe - is the quota entry to refresh + * \param find - don't create entry on disk if true */ -static int lqe_read(const struct lu_env *env, struct lquota_entry *lqe) +static int lqe_read(const struct lu_env *env, + struct lquota_entry *lqe, bool find) { struct lquota_site *site; int rc; @@ -296,7 +301,7 @@ static int lqe_read(const struct lu_env *env, struct lquota_entry *lqe) LQUOTA_DEBUG(lqe, "read"); - rc = site->lqs_ops->lqe_read(env, lqe, site->lqs_parent); + rc = site->lqs_ops->lqe_read(env, lqe, site->lqs_parent, find); if (rc == 0) /* mark the entry as up-to-date */ lqe->lqe_uptodate = true; @@ -310,12 +315,15 @@ static int lqe_read(const struct lu_env *env, struct lquota_entry *lqe) * \param env - the environment passed by the caller * \param site - lquota site which stores quota entries in a hash table * \param qid - is the quota ID to be found/created + * \param find - don't create lqe on disk in case of ENOENT if true * * \retval 0 - success * \retval -ve - failure */ -struct lquota_entry *lqe_locate(const struct lu_env *env, - struct lquota_site *site, union lquota_id *qid) +struct lquota_entry *lqe_locate_find(const struct lu_env *env, + struct lquota_site *site, + union lquota_id *qid, + bool find) { struct lquota_entry *lqe, *new = NULL; int rc = 0; @@ -327,9 +335,9 @@ struct lquota_entry *lqe_locate(const struct lu_env *env, RETURN(lqe); } - OBD_SLAB_ALLOC_PTR_GFP(new, lqe_kmem, CFS_ALLOC_IO); + OBD_SLAB_ALLOC_PTR_GFP(new, lqe_kmem, GFP_NOFS); if (new == NULL) { - CERROR("Fail to allocate lqe for id:"LPU64", " + CERROR("Fail to allocate lqe for id:%llu, " "hash:%s\n", qid->qid_uid, site->lqs_hash->hs_name); RETURN(ERR_PTR(-ENOMEM)); } @@ -337,7 +345,7 @@ struct lquota_entry *lqe_locate(const struct lu_env *env, atomic_set(&new->lqe_ref, 1); /* hold 1 for caller */ new->lqe_id = *qid; new->lqe_site = site; - CFS_INIT_LIST_HEAD(&new->lqe_link); + INIT_LIST_HEAD(&new->lqe_link); /* quota settings need to be updated from disk, that's why * lqe->lqe_uptodate isn't set yet */ @@ -347,7 +355,7 @@ struct lquota_entry *lqe_locate(const struct lu_env *env, lqe_init(new); /* read quota settings from disk and mark lqe as up-to-date */ - rc = lqe_read(env, new); + rc = lqe_read(env, new, find); if (rc) GOTO(out, lqe = ERR_PTR(rc));