From: Alexander Aring <aahringo@redhat.com>
To: teigland@redhat.com
Cc: aahringo@redhat.com, gfs2@lists.linux.dev
Subject: [PATCH RESEND dlm/next 8/8] dlm: fix variable key length lookup
Date: Tue, 1 Sep 2026 13:47:15 -0400 [thread overview]
Message-ID: <20260901174715.3825582-9-aahringo@redhat.com> (raw)
In-Reply-To: <20260901174715.3825582-1-aahringo@redhat.com>
Before commit 6c648035cbe7 ("dlm: switch to use rhashtable for rsbs")
the rsb hashtable was dynamic key length. Accidentally it was changed to
switch to static key length which can end in different results. We
fixing this back to the original behaviour by adding the necessary
functionality to rhashtable to handle the objects and lookups as dynamic
key lengths.
Fixes: 6c648035cbe7 ("dlm: switch to use rhashtable for rsbs")
Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
fs/dlm/config.c | 30 ++++++++++++++++++++++++++++--
fs/dlm/dlm_internal.h | 5 +++++
fs/dlm/lock.c | 6 ++++--
3 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/fs/dlm/config.c b/fs/dlm/config.c
index 53cd332930423..6c5c3f049b33a 100644
--- a/fs/dlm/config.c
+++ b/fs/dlm/config.c
@@ -64,11 +64,37 @@ static void release_node(struct config_item *);
static struct configfs_attribute *comm_attrs[];
static struct configfs_attribute *node_attrs[];
+static u32 rsb_hashfn(const void *data, u32 len, u32 seed)
+{
+ const struct dlm_rsb_key *key = data;
+
+ return jhash(key->name, key->len, 0);
+}
+
+static u32 rsb_obj_hashfn(const void *data, u32 len, u32 seed)
+{
+ const struct dlm_rsb *r = data;
+
+ return r->res_hash;
+}
+
+static int rsb_obj_cmpfn(struct rhashtable_compare_arg *arg, const void *obj)
+{
+ const struct dlm_rsb_key *key = arg->key;
+ const struct dlm_rsb *r = obj;
+
+ if (key->len != r->res_length)
+ return -1;
+
+ return memcmp(&r->res_name, key->name, key->len);
+}
+
const struct rhashtable_params dlm_rhash_rsb_params = {
.nelem_hint = 3, /* start small */
- .key_len = DLM_RESNAME_MAXLEN,
- .key_offset = offsetof(struct dlm_rsb, res_name),
.head_offset = offsetof(struct dlm_rsb, res_node),
+ .hashfn = rsb_hashfn,
+ .obj_hashfn = rsb_obj_hashfn,
+ .obj_cmpfn = rsb_obj_cmpfn,
.automatic_shrinking = true,
};
diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h
index 9df842421ae06..74c2e77d1b553 100644
--- a/fs/dlm/dlm_internal.h
+++ b/fs/dlm/dlm_internal.h
@@ -340,6 +340,11 @@ struct dlm_rsb {
char res_name[DLM_RESNAME_MAXLEN+1];
};
+struct dlm_rsb_key {
+ char name[DLM_RESNAME_MAXLEN];
+ size_t len;
+};
+
/* dlm_master_lookup() flags */
#define DLM_LU_RECOVER_DIR 1
diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c
index d73c4aed1f8ac..2609e4fdeba84 100644
--- a/fs/dlm/lock.c
+++ b/fs/dlm/lock.c
@@ -625,12 +625,14 @@ static int get_rsb_struct(struct dlm_ls *ls, const void *name, int len,
int dlm_search_rsb_tree(struct rhashtable *rhash, const void *name,
unsigned int len, struct dlm_rsb **r_ret)
{
- char key[DLM_RESNAME_MAXLEN] = {};
+ struct dlm_rsb_key key = {
+ .len = len,
+ };
if (len > DLM_RESNAME_MAXLEN)
return -EINVAL;
- memcpy(key, name, len);
+ memcpy(key.name, name, len);
*r_ret = rhashtable_lookup_fast(rhash, &key, dlm_rhash_rsb_params);
if (*r_ret)
return 0;
--
2.43.0
prev parent reply other threads:[~2026-09-01 17:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 17:47 [PATCH RESEND dlm/next 0/8] dlm: pending fixes based on v7.3-rc1 Alexander Aring
2026-09-01 17:47 ` [PATCH RESEND dlm/next 1/8] dlm: gate dlm_plock device on CAP_SYS_ADMIN Alexander Aring
2026-09-01 17:47 ` [PATCH RESEND dlm/next 2/8] dlm: require CAP_SYS_ADMIN for dlm-monitor device Alexander Aring
2026-09-01 17:47 ` [PATCH RESEND dlm/next 3/8] dlm: validate userspace lock resource name length Alexander Aring
2026-09-01 17:47 ` [PATCH RESEND dlm/next 4/8] dlm: fix buffer overflow from negative len in dlm_search_rsb_tree Alexander Aring
2026-09-01 17:47 ` [PATCH RESEND dlm/next 5/8] dlm: validate lock modes in recovery messages Alexander Aring
2026-09-01 17:47 ` [PATCH RESEND dlm/next 6/8] dlm: fix NULL pointer dereference in dlm_dump_rsb_name() Alexander Aring
2026-09-01 17:47 ` [PATCH RESEND dlm/next 7/8] dlm: wait for outstanding SRCU callbacks to complete in exit paths Alexander Aring
2026-09-01 17:47 ` Alexander Aring [this message]
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=20260901174715.3825582-9-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