Skip to content

Commit d44e0fc

Browse files
committed
dlm: recover nodes that are removed and re-added
If a node is removed from a lockspace, and then added back before the dlm is notified of the removal, the dlm will not detect the removal and won't clear the old state from the node. This is fixed by using a list of added nodes so the membership recovery can detect when a newly added node is already in the member list. Signed-off-by: David Teigland <teigland@redhat.com>
1 parent 761b9d3 commit d44e0fc

5 files changed

Lines changed: 74 additions & 16 deletions

File tree

‎fs/dlm/config.c‎

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ struct node {
284284
struct list_head list; /* space->members */
285285
int nodeid;
286286
int weight;
287+
int new;
287288
};
288289

289290
static struct configfs_group_operations clusters_ops = {
@@ -565,6 +566,7 @@ static struct config_item *make_node(struct config_group *g, const char *name)
565566
config_item_init_type_name(&nd->item, name, &node_type);
566567
nd->nodeid = -1;
567568
nd->weight = 1; /* default weight of 1 if none is set */
569+
nd->new = 1; /* set to 0 once it's been read by dlm_nodeid_list() */
568570

569571
mutex_lock(&sp->members_lock);
570572
list_add(&nd->list, &sp->members);
@@ -805,36 +807,64 @@ static void put_comm(struct comm *cm)
805807
}
806808

807809
/* caller must free mem */
808-
int dlm_nodeid_list(char *lsname, int **ids_out)
810+
int dlm_nodeid_list(char *lsname, int **ids_out, int *ids_count_out,
811+
int **new_out, int *new_count_out)
809812
{
810813
struct space *sp;
811814
struct node *nd;
812-
int i = 0, rv = 0;
813-
int *ids;
815+
int i = 0, rv = 0, ids_count = 0, new_count = 0;
816+
int *ids, *new;
814817

815818
sp = get_space(lsname);
816819
if (!sp)
817820
return -EEXIST;
818821

819822
mutex_lock(&sp->members_lock);
820823
if (!sp->members_count) {
821-
rv = 0;
824+
rv = -EINVAL;
825+
printk(KERN_ERR "dlm: zero members_count\n");
822826
goto out;
823827
}
824828

825-
ids = kcalloc(sp->members_count, sizeof(int), GFP_KERNEL);
829+
ids_count = sp->members_count;
830+
831+
ids = kcalloc(ids_count, sizeof(int), GFP_KERNEL);
826832
if (!ids) {
827833
rv = -ENOMEM;
828834
goto out;
829835
}
830836

831-
rv = sp->members_count;
832-
list_for_each_entry(nd, &sp->members, list)
837+
list_for_each_entry(nd, &sp->members, list) {
833838
ids[i++] = nd->nodeid;
839+
if (nd->new)
840+
new_count++;
841+
}
842+
843+
if (ids_count != i)
844+
printk(KERN_ERR "dlm: bad nodeid count %d %d\n", ids_count, i);
845+
846+
if (!new_count)
847+
goto out_ids;
848+
849+
new = kcalloc(new_count, sizeof(int), GFP_KERNEL);
850+
if (!new) {
851+
kfree(ids);
852+
rv = -ENOMEM;
853+
goto out;
854+
}
834855

835-
if (rv != i)
836-
printk("bad nodeid count %d %d\n", rv, i);
856+
i = 0;
857+
list_for_each_entry(nd, &sp->members, list) {
858+
if (nd->new) {
859+
new[i++] = nd->nodeid;
860+
nd->new = 0;
861+
}
862+
}
863+
*new_count_out = new_count;
864+
*new_out = new;
837865

866+
out_ids:
867+
*ids_count_out = ids_count;
838868
*ids_out = ids;
839869
out:
840870
mutex_unlock(&sp->members_lock);

‎fs/dlm/config.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ extern struct dlm_config_info dlm_config;
3535
int dlm_config_init(void);
3636
void dlm_config_exit(void);
3737
int dlm_node_weight(char *lsname, int nodeid);
38-
int dlm_nodeid_list(char *lsname, int **ids_out);
38+
int dlm_nodeid_list(char *lsname, int **ids_out, int *ids_count_out,
39+
int **new_out, int *new_count_out);
3940
int dlm_nodeid_to_addr(int nodeid, struct sockaddr_storage *addr);
4041
int dlm_addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid);
4142
int dlm_our_nodeid(void);

‎fs/dlm/dlm_internal.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ struct dlm_member {
133133

134134
struct dlm_recover {
135135
struct list_head list;
136-
int *nodeids;
136+
int *nodeids; /* nodeids of all members */
137137
int node_count;
138+
int *new; /* nodeids of new members */
139+
int new_count;
138140
uint64_t seq;
139141
};
140142

‎fs/dlm/member.c‎

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,23 @@ int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out)
210210
}
211211
}
212212

213+
/* Add an entry to ls_nodes_gone for members that were removed and
214+
then added again, so that previous state for these nodes will be
215+
cleared during recovery. */
216+
217+
for (i = 0; i < rv->new_count; i++) {
218+
if (!dlm_is_member(ls, rv->new[i]))
219+
continue;
220+
log_debug(ls, "new nodeid %d is a re-added member", rv->new[i]);
221+
222+
memb = kzalloc(sizeof(struct dlm_member), GFP_KERNEL);
223+
if (!memb)
224+
return -ENOMEM;
225+
memb->nodeid = rv->new[i];
226+
list_add_tail(&memb->list, &ls->ls_nodes_gone);
227+
neg++;
228+
}
229+
213230
/* add new members to ls_nodes */
214231

215232
for (i = 0; i < rv->node_count; i++) {
@@ -314,15 +331,16 @@ int dlm_ls_stop(struct dlm_ls *ls)
314331
int dlm_ls_start(struct dlm_ls *ls)
315332
{
316333
struct dlm_recover *rv = NULL, *rv_old;
317-
int *ids = NULL;
318-
int error, count;
334+
int *ids = NULL, *new = NULL;
335+
int error, ids_count = 0, new_count = 0;
319336

320337
rv = kzalloc(sizeof(struct dlm_recover), GFP_KERNEL);
321338
if (!rv)
322339
return -ENOMEM;
323340

324-
error = count = dlm_nodeid_list(ls->ls_name, &ids);
325-
if (error <= 0)
341+
error = dlm_nodeid_list(ls->ls_name, &ids, &ids_count,
342+
&new, &new_count);
343+
if (error < 0)
326344
goto fail;
327345

328346
spin_lock(&ls->ls_recover_lock);
@@ -337,14 +355,19 @@ int dlm_ls_start(struct dlm_ls *ls)
337355
}
338356

339357
rv->nodeids = ids;
340-
rv->node_count = count;
358+
rv->node_count = ids_count;
359+
rv->new = new;
360+
rv->new_count = new_count;
341361
rv->seq = ++ls->ls_recover_seq;
342362
rv_old = ls->ls_recover_args;
343363
ls->ls_recover_args = rv;
344364
spin_unlock(&ls->ls_recover_lock);
345365

346366
if (rv_old) {
367+
log_error(ls, "unused recovery %llx %d",
368+
(unsigned long long)rv_old->seq, rv_old->node_count);
347369
kfree(rv_old->nodeids);
370+
kfree(rv_old->new);
348371
kfree(rv_old);
349372
}
350373

@@ -354,6 +377,7 @@ int dlm_ls_start(struct dlm_ls *ls)
354377
fail:
355378
kfree(rv);
356379
kfree(ids);
380+
kfree(new);
357381
return error;
358382
}
359383

‎fs/dlm/recoverd.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ static void do_ls_recovery(struct dlm_ls *ls)
257257
if (rv) {
258258
ls_recover(ls, rv);
259259
kfree(rv->nodeids);
260+
kfree(rv->new);
260261
kfree(rv);
261262
}
262263
}

0 commit comments

Comments
 (0)