Whamcloud - gitweb
LU-16796 quota: Change struct lquota_entry to use kref 54/56454/8
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Fri, 11 Oct 2024 05:36:55 +0000 (01:36 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 22 Jan 2025 18:42:02 +0000 (18:42 +0000)
This patch changes struct lquota_entry to use
kref instead of atomic_t

Test-Parameters: trivial testlist=sanity-quota
Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: I27cb5373872887c3327a4d6dedccd15b02c7a4c9
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56454
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Sergey Cheremencev <scherementsev@ddn.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/quota/lquota_entry.c
lustre/quota/lquota_internal.h
lustre/quota/lquota_lib.c
lustre/quota/qmt_handler.c
lustre/quota/qmt_lock.c
lustre/quota/qmt_pool.c
lustre/quota/qsd_lock.c
lustre/quota/qsd_reint.c

index b4d9545..d4db0fb 100644 (file)
@@ -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);
index c0ea3e5..21e600f 100644 (file)
@@ -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)
index 80544d4..b3a3879 100644 (file)
@@ -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) {
index 6918f65..07bea44 100644 (file)
@@ -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;
index 1959c83..f449b8e 100644 (file)
@@ -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);
index 1592099..ae2466a 100644 (file)
@@ -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) {
index 1332a63..55ee238 100644 (file)
@@ -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;
index 387971f..63781af 100644 (file)
@@ -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;