From 01d10c84ad64bfbfe60c45267e9ac9b441191025 Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Fri, 11 Oct 2024 01:36:55 -0400 Subject: [PATCH] LU-16796 quota: Change struct lquota_entry to use kref This patch changes struct lquota_entry to use kref instead of atomic_t Test-Parameters: trivial testlist=sanity-quota Signed-off-by: Arshad Hussain Change-Id: I27cb5373872887c3327a4d6dedccd15b02c7a4c9 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56454 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Sergey Cheremencev Reviewed-by: Timothy Day Reviewed-by: Oleg Drokin --- lustre/quota/lquota_entry.c | 6 +++--- lustre/quota/lquota_internal.h | 12 +++++++----- lustre/quota/lquota_lib.c | 8 ++++++++ lustre/quota/qmt_handler.c | 2 +- lustre/quota/qmt_lock.c | 2 +- lustre/quota/qmt_pool.c | 4 ++-- lustre/quota/qsd_lock.c | 2 +- lustre/quota/qsd_reint.c | 2 +- 8 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lustre/quota/lquota_entry.c b/lustre/quota/lquota_entry.c index b4d9545..d4db0fb 100644 --- a/lustre/quota/lquota_entry.c +++ b/lustre/quota/lquota_entry.c @@ -108,12 +108,12 @@ static int lqe_iter_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd, struct lquota_entry *lqe; lqe = hlist_entry(hnode, struct lquota_entry, lqe_hash); - LASSERT(atomic_read(&lqe->lqe_ref) > 0); + LASSERT(kref_read(&lqe->lqe_ref) > 0); /* Only one reference held by hash table, and nobody else can * grab the entry at this moment, it's safe to remove it from * the hash and free it. */ - if (atomic_read(&lqe->lqe_ref) == 1) { + if (kref_read(&lqe->lqe_ref) == 1) { if (!lqe_is_master(lqe)) { LASSERT(lqe->lqe_pending_write == 0); LASSERT(lqe->lqe_pending_req == 0); @@ -325,7 +325,7 @@ struct lquota_entry *lqe_locate_find(const struct lu_env *env, RETURN(ERR_PTR(-ENOMEM)); } - atomic_set(&new->lqe_ref, 1); /* hold 1 for caller */ + kref_init(&new->lqe_ref); /* hold 1 for caller */ new->lqe_id = *qid; new->lqe_site = site; INIT_LIST_HEAD(&new->lqe_link); diff --git a/lustre/quota/lquota_internal.h b/lustre/quota/lquota_internal.h index c0ea3e5..21e600f 100644 --- a/lustre/quota/lquota_internal.h +++ b/lustre/quota/lquota_internal.h @@ -143,7 +143,7 @@ struct lquota_entry { struct lquota_site *lqe_site; /* reference counter */ - atomic_t lqe_ref; + struct kref lqe_ref; /* linked to list of lqes which: * - need quota space adjustment on slave @@ -250,19 +250,21 @@ struct lquota_site { extern struct kmem_cache *lqe_kmem; +/* lquota_lib.c */ +void lqe_ref_free(struct kref *kref); + /* helper routine to get/put reference on lquota_entry */ static inline void lqe_getref(struct lquota_entry *lqe) { LASSERT(lqe != NULL); - atomic_inc(&lqe->lqe_ref); + kref_get(&lqe->lqe_ref); } static inline void lqe_putref(struct lquota_entry *lqe) { LASSERT(lqe != NULL); - LASSERT(atomic_read(&lqe->lqe_ref) > 0); - if (atomic_dec_and_test(&lqe->lqe_ref)) - OBD_SLAB_FREE_PTR(lqe, lqe_kmem); + LASSERT(kref_read(&lqe->lqe_ref) > 0); + kref_put(&lqe->lqe_ref, lqe_ref_free); } static inline int lqe_is_master(struct lquota_entry *lqe) diff --git a/lustre/quota/lquota_lib.c b/lustre/quota/lquota_lib.c index 80544d4..b3a3879 100644 --- a/lustre/quota/lquota_lib.c +++ b/lustre/quota/lquota_lib.c @@ -36,6 +36,14 @@ 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); +void lqe_ref_free(struct kref *kref) +{ + struct lquota_entry *lqe = container_of(kref, struct lquota_entry, + lqe_ref); + + OBD_SLAB_FREE_PTR(lqe, lqe_kmem); +} + static inline __u32 qtype2acct_oid(int qtype) { switch (qtype) { diff --git a/lustre/quota/qmt_handler.c b/lustre/quota/qmt_handler.c index 6918f65..07bea44 100644 --- a/lustre/quota/qmt_handler.c +++ b/lustre/quota/qmt_handler.c @@ -77,7 +77,7 @@ static int qmt_entry_iter_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd, struct lquota_entry *lqe; lqe = hlist_entry(hnode, struct lquota_entry, lqe_hash); - LASSERT(atomic_read(&lqe->lqe_ref) > 0); + LASSERT(kref_read(&lqe->lqe_ref) > 0); if (lqe->lqe_id.qid_uid == 0 || !lqe->lqe_is_default) return 0; diff --git a/lustre/quota/qmt_lock.c b/lustre/quota/qmt_lock.c index 1959c83..f449b8e 100644 --- a/lustre/quota/qmt_lock.c +++ b/lustre/quota/qmt_lock.c @@ -1059,7 +1059,7 @@ static int qmt_reba_thread(void *_args) * so no need to send glimpse callbacks. */ if (!kthread_should_stop() && - atomic_read(&lqe->lqe_ref) > 1) + kref_read(&lqe->lqe_ref) > 1) qmt_id_lock_glimpse(env, qmt, lqe, NULL); lqe_putref(lqe); diff --git a/lustre/quota/qmt_pool.c b/lustre/quota/qmt_pool.c index 1592099..ae2466a 100644 --- a/lustre/quota/qmt_pool.c +++ b/lustre/quota/qmt_pool.c @@ -687,7 +687,7 @@ static int qmt_lgd_extend_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd, int old_num = 0, rc; lqe = hlist_entry(hnode, struct lquota_entry, lqe_hash); - LASSERT(atomic_read(&lqe->lqe_ref) > 0); + LASSERT(kref_read(&lqe->lqe_ref) > 0); rc = 0; CDEBUG(D_QUOTA, "lgd %px\n", lqe->lqe_glbl_data); @@ -1177,7 +1177,7 @@ static int qmt_site_recalc_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd, struct lu_env *env = data; lqe = hlist_entry(hnode, struct lquota_entry, lqe_hash); - LASSERT(atomic_read(&lqe->lqe_ref) > 0); + LASSERT(kref_read(&lqe->lqe_ref) > 0); lqe_write_lock(lqe); if (lqe->lqe_granted != lqe->lqe_recalc_granted) { diff --git a/lustre/quota/qsd_lock.c b/lustre/quota/qsd_lock.c index 1332a63..55ee238 100644 --- a/lustre/quota/qsd_lock.c +++ b/lustre/quota/qsd_lock.c @@ -223,7 +223,7 @@ static int qsd_entry_def_iter_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd, struct lquota_entry *lqe; lqe = hlist_entry(hnode, struct lquota_entry, lqe_hash); - LASSERT(atomic_read(&lqe->lqe_ref) > 0); + LASSERT(kref_read(&lqe->lqe_ref) > 0); if (lqe->lqe_id.qid_uid == 0 || !lqe->lqe_is_default) return 0; diff --git a/lustre/quota/qsd_reint.c b/lustre/quota/qsd_reint.c index 387971f..63781af 100644 --- a/lustre/quota/qsd_reint.c +++ b/lustre/quota/qsd_reint.c @@ -548,7 +548,7 @@ static int qsd_entry_iter_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd, int *pending = (int *)data; lqe = hlist_entry(hnode, struct lquota_entry, lqe_hash); - LASSERT(atomic_read(&lqe->lqe_ref) > 0); + LASSERT(kref_read(&lqe->lqe_ref) > 0); lqe_read_lock(lqe); *pending += lqe->lqe_pending_req; -- 1.8.3.1