Skip to content

Commit d47b822

Browse files
Alexander Aringteigland
authored andcommitted
dlm: warn about invalid nodeid comparsions
This patch adds a warn on if is_master() and dlm_is_removed() checks on invalid nodeid states that are probably not what the caller wants to do here. The is_master() function checking on r->res_nodeid is invalid when it is set to -1, whereas the dlm_is_removed() has a different meaning as "nodeid member" and also 0 is invalid. We run into these cases and this patch changes those cases as we never will run into them. There should be no functional changes as the condition should return the same result. However this patch signals now on caller level that there might be an "extra" case to handle here. Signed-off-by: Alexander Aring <[email protected]> Signed-off-by: David Teigland <[email protected]>
1 parent 90ad918 commit d47b822

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

fs/dlm/lock.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ static void __dlm_master_lookup(struct dlm_ls *ls, struct dlm_rsb *r, int our_no
11511151
r->res_dir_nodeid = our_nodeid;
11521152
}
11531153

1154-
if (fix_master && dlm_is_removed(ls, r->res_master_nodeid)) {
1154+
if (fix_master && r->res_master_nodeid && dlm_is_removed(ls, r->res_master_nodeid)) {
11551155
/* Recovery uses this function to set a new master when
11561156
* the previous master failed. Setting NEW_MASTER will
11571157
* force dlm_recover_masters to call recover_master on this
@@ -5283,7 +5283,7 @@ int dlm_recover_waiters_post(struct dlm_ls *ls)
52835283
case DLM_MSG_LOOKUP:
52845284
case DLM_MSG_REQUEST:
52855285
_request_lock(r, lkb);
5286-
if (is_master(r))
5286+
if (r->res_nodeid != -1 && is_master(r))
52875287
confirm_master(r, 0);
52885288
break;
52895289
case DLM_MSG_CONVERT:
@@ -5396,7 +5396,7 @@ void dlm_recover_purge(struct dlm_ls *ls, const struct list_head *root_list)
53965396

53975397
list_for_each_entry(r, root_list, res_root_list) {
53985398
lock_rsb(r);
5399-
if (is_master(r)) {
5399+
if (r->res_nodeid != -1 && is_master(r)) {
54005400
purge_dead_list(ls, r, &r->res_grantqueue,
54015401
nodeid_gone, &lkb_count);
54025402
purge_dead_list(ls, r, &r->res_convertqueue,

fs/dlm/lock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ int dlm_debug_add_lkb_to_waiters(struct dlm_ls *ls, uint32_t lkb_id,
6666

6767
static inline int is_master(struct dlm_rsb *r)
6868
{
69+
WARN_ON_ONCE(r->res_nodeid == -1);
70+
6971
return !r->res_nodeid;
7072
}
7173

fs/dlm/member.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ int dlm_is_member(struct dlm_ls *ls, int nodeid)
366366

367367
int dlm_is_removed(struct dlm_ls *ls, int nodeid)
368368
{
369+
WARN_ON_ONCE(!nodeid || nodeid == -1);
370+
369371
if (find_memb(&ls->ls_nodes_gone, nodeid))
370372
return 1;
371373
return 0;

fs/dlm/recover.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,11 @@ static int recover_master(struct dlm_rsb *r, unsigned int *count, uint64_t seq)
452452
int is_removed = 0;
453453
int error;
454454

455-
if (is_master(r))
455+
if (r->res_nodeid != -1 && is_master(r))
456456
return 0;
457457

458-
is_removed = dlm_is_removed(ls, r->res_nodeid);
458+
if (r->res_nodeid != -1)
459+
is_removed = dlm_is_removed(ls, r->res_nodeid);
459460

460461
if (!is_removed && !rsb_flag(r, RSB_NEW_MASTER))
461462
return 0;
@@ -664,7 +665,7 @@ int dlm_recover_locks(struct dlm_ls *ls, uint64_t seq,
664665
int error, count = 0;
665666

666667
list_for_each_entry(r, root_list, res_root_list) {
667-
if (is_master(r)) {
668+
if (r->res_nodeid != -1 && is_master(r)) {
668669
rsb_clear_flag(r, RSB_NEW_MASTER);
669670
continue;
670671
}
@@ -858,7 +859,7 @@ void dlm_recover_rsbs(struct dlm_ls *ls, const struct list_head *root_list)
858859

859860
list_for_each_entry(r, root_list, res_root_list) {
860861
lock_rsb(r);
861-
if (is_master(r)) {
862+
if (r->res_nodeid != -1 && is_master(r)) {
862863
if (rsb_flag(r, RSB_RECOVER_CONVERT))
863864
recover_conversion(r);
864865

0 commit comments

Comments
 (0)