From: Alexander Aring <aahringo@redhat.com>
To: teigland@redhat.com
Cc: gfs2@lists.linux.dev
Subject: [PATCH v6.9-rc1 04/10] dlm: put lkbs instead of force free
Date: Thu, 28 Mar 2024 11:48:36 -0400 [thread overview]
Message-ID: <20240328154842.1099288-4-aahringo@redhat.com> (raw)
In-Reply-To: <20240328154842.1099288-1-aahringo@redhat.com>
This patch converts a force free of the lkb idr and switch to use the
lkbs put functionality. If there are still references hold due the lkb
programming logic and its state it will be drop before. Instead of force
freeing the lkbs of the idr using the refcounters makes sure we using
the reference counters correctly. If we do that, then no rsb should be
left on the lockspace keep hash bucket which is an additonally check
added to this patch. All rsbs on the toss list should have a reference
counter of 1.
Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
fs/dlm/lock.c | 2 +-
fs/dlm/lock.h | 1 +
fs/dlm/lockspace.c | 33 +++++++++++++++++++++++----------
3 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c
index fd752dd03896..a39c2c49bff8 100644
--- a/fs/dlm/lock.c
+++ b/fs/dlm/lock.c
@@ -1368,7 +1368,7 @@ static void add_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb, int status)
}
}
-static void del_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb)
+void del_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb)
{
lkb->lkb_status = 0;
list_del(&lkb->lkb_statequeue);
diff --git a/fs/dlm/lock.h b/fs/dlm/lock.h
index b54e2cbbe6e2..853c3d3dc49d 100644
--- a/fs/dlm/lock.h
+++ b/fs/dlm/lock.h
@@ -60,6 +60,7 @@ int dlm_debug_add_lkb(struct dlm_ls *ls, uint32_t lkb_id, char *name, int len,
int lkb_nodeid, unsigned int lkb_flags, int lkb_status);
int dlm_debug_add_lkb_to_waiters(struct dlm_ls *ls, uint32_t lkb_id,
int mstype, int to_nodeid);
+void del_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb);
static inline int is_master(struct dlm_rsb *r)
{
diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index 0455dddb0797..0f9d7b498602 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -737,14 +737,30 @@ static int lkb_idr_is_any(int id, void *p, void *data)
return 1;
}
-static int lkb_idr_free(int id, void *p, void *data)
+/*
+ * No locking required, lockspace usage should be synchronized
+ * to have any activity anymore.
+ */
+static int lkb_idr_put(int id, void *p, void *data)
{
struct dlm_lkb *lkb = p;
- if (lkb->lkb_lvbptr && test_bit(DLM_IFL_MSTCPY_BIT, &lkb->lkb_iflags))
- dlm_free_lvb(lkb->lkb_lvbptr);
+ if (lkb->lkb_status)
+ del_lkb(lkb->lkb_resource, lkb);
- dlm_free_lkb(lkb);
+ /*
+ * Forcibly reset wait_count and associated refcount. The
+ * wait_count will almost always be 1, but in case of an
+ * overlapping unlock/cancel it could be 2: see where
+ * add_to_waiters() finds the lkb is already on the waiters
+ * list and does lkb_wait_count++; hold_lkb().
+ */
+ while (lkb->lkb_wait_count) {
+ lkb->lkb_wait_count--;
+ dlm_put_lkb(lkb);
+ }
+
+ WARN_ON_ONCE(!dlm_put_lkb(lkb));
return 0;
}
@@ -826,7 +842,7 @@ static int release_lockspace(struct dlm_ls *ls, int force)
* Free all lkb's in idr
*/
- idr_for_each(&ls->ls_lkbidr, lkb_idr_free, ls);
+ idr_for_each(&ls->ls_lkbidr, lkb_idr_put, ls);
idr_destroy(&ls->ls_lkbidr);
/*
@@ -834,15 +850,12 @@ static int release_lockspace(struct dlm_ls *ls, int force)
*/
for (i = 0; i < ls->ls_rsbtbl_size; i++) {
- while ((n = rb_first(&ls->ls_rsbtbl[i].keep))) {
- rsb = rb_entry(n, struct dlm_rsb, res_hashnode);
- rb_erase(n, &ls->ls_rsbtbl[i].keep);
- dlm_free_rsb(rsb);
- }
+ WARN_ON_ONCE(!RB_EMPTY_ROOT(&ls->ls_rsbtbl[i].keep));
while ((n = rb_first(&ls->ls_rsbtbl[i].toss))) {
rsb = rb_entry(n, struct dlm_rsb, res_hashnode);
rb_erase(n, &ls->ls_rsbtbl[i].toss);
+ WARN_ON_ONCE(kref_read(&rsb->res_ref) != 1);
dlm_free_rsb(rsb);
}
}
--
2.43.0
next prev parent reply other threads:[~2024-03-28 15:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-28 15:48 [PATCH v6.9-rc1 01/10] dlm: fix user space lock decision to copy lvb Alexander Aring
2024-03-28 15:48 ` [PATCH v6.9-rc1 02/10] fs: dlm: Simplify the allocation of slab caches in dlm_midcomms_cache_create Alexander Aring
2024-03-28 15:48 ` [PATCH v6.9-rc1 03/10] fs: dlm: Simplify the allocation of slab caches in dlm_lowcomms_msg_cache_create Alexander Aring
2024-03-28 15:48 ` Alexander Aring [this message]
2024-03-28 15:48 ` [PATCH v6.9-rc1 05/10] dlm: remove lkb from ast bast tracepoints Alexander Aring
2024-03-28 15:48 ` [PATCH v6.9-rc1 06/10] dlm: remove callback queue debugfs functionality Alexander Aring
2024-03-28 15:48 ` [PATCH v6.9-rc1 07/10] dlm: move lkb debug information out of callback Alexander Aring
2024-03-28 15:48 ` [PATCH v6.9-rc1 08/10] dlm: combine switch case fail and default statements Alexander Aring
2024-03-28 15:48 ` [PATCH v6.9-rc1 09/10] dlm: fix race between final callback and remove Alexander Aring
2024-03-28 15:48 ` [PATCH v6.9-rc1 10/10] dlm: remove callback reference counting Alexander Aring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240328154842.1099288-4-aahringo@redhat.com \
--to=aahringo@redhat.com \
--cc=gfs2@lists.linux.dev \
--cc=teigland@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox