]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
dlm: remove callback reference counting
authorAlexander Aring <aahringo@redhat.com>
Thu, 28 Mar 2024 15:48:42 +0000 (11:48 -0400)
committerDavid Teigland <teigland@redhat.com>
Mon, 1 Apr 2024 18:31:13 +0000 (13:31 -0500)
Get rid of the unnecessary refcounting on callback structs.
Copy interesting callback info into the lkb struct rather
than maintaining pointers to callback structs from the lkb.
This goes back to the way things were done prior to
commit 61bed0baa4db ("fs: dlm: use a non-static queue for callbacks").

Signed-off-by: Alexander Aring <aahringo@redhat.com>
Signed-off-by: David Teigland <teigland@redhat.com>
fs/dlm/ast.c
fs/dlm/ast.h
fs/dlm/debug_fs.c
fs/dlm/dlm_internal.h
fs/dlm/lock.c
fs/dlm/memory.c
fs/dlm/user.c

index e9da812352b4c89e28b682d27750b63fb79451b9..03879c94fadb5bd688deb5162f0ed66b519c9686 100644 (file)
 #include "user.h"
 #include "ast.h"
 
-void dlm_release_callback(struct kref *ref)
-{
-       struct dlm_callback *cb = container_of(ref, struct dlm_callback, ref);
-
-       dlm_free_cb(cb);
-}
-
-void dlm_callback_set_last_ptr(struct dlm_callback **from,
-                              struct dlm_callback *to)
-{
-       if (*from)
-               kref_put(&(*from)->ref, dlm_release_callback);
-
-       if (to)
-               kref_get(&to->ref);
-
-       *from = to;
-}
-
 static void dlm_callback_work(struct work_struct *work)
 {
        struct dlm_callback *cb = container_of(work, struct dlm_callback, work);
@@ -53,7 +34,7 @@ static void dlm_callback_work(struct work_struct *work)
                cb->astfn(cb->astparam);
        }
 
-       kref_put(&cb->ref, dlm_release_callback);
+       dlm_free_cb(cb);
 }
 
 int dlm_queue_lkb_callback(struct dlm_lkb *lkb, uint32_t flags, int mode,
@@ -70,11 +51,11 @@ int dlm_queue_lkb_callback(struct dlm_lkb *lkb, uint32_t flags, int mode,
                /* if cb is a bast, it should be skipped if the blocking mode is
                 * compatible with the last granted mode
                 */
-               if (lkb->lkb_last_cast) {
-                       if (dlm_modes_compat(mode, lkb->lkb_last_cast->mode)) {
+               if (lkb->lkb_last_cast_cb_mode != -1) {
+                       if (dlm_modes_compat(mode, lkb->lkb_last_cast_cb_mode)) {
                                log_debug(ls, "skip %x bast mode %d for cast mode %d",
                                          lkb->lkb_id, mode,
-                                         lkb->lkb_last_cast->mode);
+                                         lkb->lkb_last_cast_cb_mode);
                                goto out;
                        }
                }
@@ -85,8 +66,9 @@ int dlm_queue_lkb_callback(struct dlm_lkb *lkb, uint32_t flags, int mode,
                 * is a bast for the same mode or a more restrictive mode.
                 * (the addional > PR check is needed for PR/CW inversion)
                 */
-               if (lkb->lkb_last_cb && lkb->lkb_last_cb->flags & DLM_CB_BAST) {
-                       prev_mode = lkb->lkb_last_cb->mode;
+               if (lkb->lkb_last_cb_mode != -1 &&
+                   lkb->lkb_last_cb_flags & DLM_CB_BAST) {
+                       prev_mode = lkb->lkb_last_cb_mode;
 
                        if ((prev_mode == mode) ||
                            (prev_mode > mode && prev_mode > DLM_LOCK_PR)) {
@@ -95,19 +77,25 @@ int dlm_queue_lkb_callback(struct dlm_lkb *lkb, uint32_t flags, int mode,
                                goto out;
                        }
                }
+
+               lkb->lkb_last_bast_time = ktime_get();
+               lkb->lkb_last_bast_cb_mode = mode;
        } else if (flags & DLM_CB_CAST) {
                if (test_bit(DLM_DFL_USER_BIT, &lkb->lkb_dflags)) {
-                       if (lkb->lkb_last_cast)
-                               prev_mode = lkb->lkb_last_cb->mode;
-                       else
-                               prev_mode = -1;
+                       prev_mode = lkb->lkb_last_cast_cb_mode;
 
                        if (!status && lkb->lkb_lksb->sb_lvbptr &&
                            dlm_lvb_operations[prev_mode + 1][mode + 1])
                                copy_lvb = 1;
                }
+
+               lkb->lkb_last_cast_cb_mode = mode;
+               lkb->lkb_last_cast_time = ktime_get();
        }
 
+       lkb->lkb_last_cb_mode = mode;
+       lkb->lkb_last_cb_flags = flags;
+
        *cb = dlm_allocate_cb();
        if (!*cb) {
                rv = DLM_ENQUEUE_CALLBACK_FAILURE;
@@ -126,17 +114,7 @@ int dlm_queue_lkb_callback(struct dlm_lkb *lkb, uint32_t flags, int mode,
        (*cb)->sb_flags = (sbflags & 0x000000FF);
        (*cb)->copy_lvb = copy_lvb;
        (*cb)->lkb_lksb = lkb->lkb_lksb;
-       kref_init(&(*cb)->ref);
-
-       if (flags & DLM_CB_BAST) {
-               lkb->lkb_last_bast_time = ktime_get();
-               lkb->lkb_last_bast_mode = mode;
-       } else if (flags & DLM_CB_CAST) {
-               dlm_callback_set_last_ptr(&lkb->lkb_last_cast, *cb);
-               lkb->lkb_last_cast_time = ktime_get();
-       }
 
-       dlm_callback_set_last_ptr(&lkb->lkb_last_cb, *cb);
        rv = DLM_ENQUEUE_CALLBACK_NEED_SCHED;
 
 out:
index 9bd12409e1ee73688dc0e05ffd2aa2741064696d..9093ff043bee91b6d749c0eb4b209af7c620573b 100644 (file)
@@ -19,10 +19,7 @@ int dlm_queue_lkb_callback(struct dlm_lkb *lkb, uint32_t flags, int mode,
                           struct dlm_callback **cb);
 void dlm_add_cb(struct dlm_lkb *lkb, uint32_t flags, int mode, int status,
                 uint32_t sbflags);
-void dlm_callback_set_last_ptr(struct dlm_callback **from,
-                              struct dlm_callback *to);
 
-void dlm_release_callback(struct kref *ref);
 int dlm_callback_start(struct dlm_ls *ls);
 void dlm_callback_stop(struct dlm_ls *ls);
 void dlm_callback_suspend(struct dlm_ls *ls);
index 289d959c77008a7bed45ad977cd67231d648e0c6..19cdedd56629dd87266c018a2eee0535f29f3951 100644 (file)
@@ -247,7 +247,7 @@ static void print_format3_lock(struct seq_file *s, struct dlm_lkb *lkb,
                   lkb->lkb_status,
                   lkb->lkb_grmode,
                   lkb->lkb_rqmode,
-                  lkb->lkb_last_bast_mode,
+                  lkb->lkb_last_bast_cb_mode,
                   rsb_lookup,
                   lkb->lkb_wait_type,
                   lkb->lkb_lvbseq,
index cda1526fd15b1f6cc828c07c4deabc63f0e75897..1d2ee5c2d23dacbb70a3aa7f964d04d76fea984b 100644 (file)
@@ -258,7 +258,6 @@ struct dlm_callback {
        uint32_t                lkb_id;
 
        struct list_head        list;
-       struct kref             ref;
 };
 
 struct dlm_lkb {
@@ -289,9 +288,10 @@ struct dlm_lkb {
        struct list_head        lkb_ownqueue;   /* list of locks for a process */
        ktime_t                 lkb_timestamp;
 
-       struct dlm_callback     *lkb_last_cast;
-       struct dlm_callback     *lkb_last_cb;
-       int                     lkb_last_bast_mode;
+       int8_t                  lkb_last_cast_cb_mode;
+       int8_t                  lkb_last_bast_cb_mode;
+       int8_t                  lkb_last_cb_mode;
+       uint8_t                 lkb_last_cb_flags;
        ktime_t                 lkb_last_cast_time;     /* for debugging */
        ktime_t                 lkb_last_bast_time;     /* for debugging */
 
index 198672446dcdddb4936809a9a92abebef9096635..c8426f6f518ca3d7872e95808d23f22eb092e34f 100644 (file)
@@ -1197,7 +1197,9 @@ static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret,
        if (!lkb)
                return -ENOMEM;
 
-       lkb->lkb_last_bast_mode = -1;
+       lkb->lkb_last_bast_cb_mode = DLM_LOCK_IV;
+       lkb->lkb_last_cast_cb_mode = DLM_LOCK_IV;
+       lkb->lkb_last_cb_mode = DLM_LOCK_IV;
        lkb->lkb_nodeid = -1;
        lkb->lkb_grmode = DLM_LOCK_IV;
        kref_init(&lkb->lkb_ref);
@@ -6031,7 +6033,7 @@ void dlm_clear_proc_locks(struct dlm_ls *ls, struct dlm_user_proc *proc)
 
        list_for_each_entry_safe(cb, cb_safe, &proc->asts, list) {
                list_del(&cb->list);
-               kref_put(&cb->ref, dlm_release_callback);
+               dlm_free_cb(cb);
        }
 
        spin_unlock(&ls->ls_clear_proc_locks);
@@ -6072,7 +6074,7 @@ static void purge_proc_locks(struct dlm_ls *ls, struct dlm_user_proc *proc)
        spin_lock(&proc->asts_spin);
        list_for_each_entry_safe(cb, cb_safe, &proc->asts, list) {
                list_del(&cb->list);
-               kref_put(&cb->ref, dlm_release_callback);
+               dlm_free_cb(cb);
        }
        spin_unlock(&proc->asts_spin);
 }
index 64f212a066cff180052dc8c5aa42f77ceb8f2669..be9398ddf3578e8905b74235220a88ede6a83c60 100644 (file)
@@ -127,10 +127,6 @@ void dlm_free_lkb(struct dlm_lkb *lkb)
                }
        }
 
-       /* drop references if they are set */
-       dlm_callback_set_last_ptr(&lkb->lkb_last_cast, NULL);
-       dlm_callback_set_last_ptr(&lkb->lkb_last_cb, NULL);
-
        kmem_cache_free(lkb_cache, lkb);
 }
 
index 334a6d64d413fe48511532368e78dfdb0eac5375..b4971ba4bdd6dcf71eed11db4549e9192cbea942 100644 (file)
@@ -864,7 +864,7 @@ static ssize_t device_read(struct file *file, char __user *buf, size_t count,
        ret = copy_result_to_user(&cb->ua,
                                  test_bit(DLM_PROC_FLAGS_COMPAT, &proc->flags),
                                  cb->flags, cb->mode, cb->copy_lvb, buf, count);
-       kref_put(&cb->ref, dlm_release_callback);
+       dlm_free_cb(cb);
        return ret;
 }