mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
dlm: fix variable key length lookup
Before commit6c648035cb("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:6c648035cb("dlm: switch to use rhashtable for rsbs") Signed-off-by: Alexander Aring <aahringo@redhat.com> Signed-off-by: David Teigland <teigland@redhat.com>
This commit is contained in:
parent
19982c99a3
commit
b4e6ae7ba7
|
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user