| 1 | |
| 2 | |
| 3 | *******************************************************************************
|
| 4 | **
|
| 5 | ** Copyright (C) 2005-2011 Red Hat, Inc. All rights reserved.
|
| 6 | **
|
| 7 | **
|
| 8 | *******************************************************************************
|
| 9 | *****************************************************************************
|
| 10 |
|
| 11 | #include "dlm_internal.h"
|
| 12 | #include "lockspace.h"
|
| 13 | #include "member.h"
|
| 14 | #include "recoverd.h"
|
| 15 | #include "recover.h"
|
| 16 | #include "rcom.h"
|
| 17 | #include "config.h"
|
| 18 | #include "midcomms.h"
|
| 19 | #include "lowcomms.h"
|
| 20 |
|
| 21 | int dlm_slots_version(const struct dlm_header *h)
|
| 22 | {
|
| 23 | if ((le32_to_cpu(h->h_version) & 0x0000FFFF) < DLM_HEADER_SLOTS)
|
| 24 | return 0;
|
| 25 | return 1;
|
| 26 | }
|
| 27 |
|
| 28 | void dlm_slot_save(struct dlm_ls *ls, struct dlm_rcom *rc,
|
| 29 | struct dlm_member *memb)
|
| 30 | {
|
| 31 | struct rcom_config *rf = (struct rcom_config *)rc->rc_buf;
|
| 32 |
|
| 33 | if (!dlm_slots_version(&rc->rc_header))
|
| 34 | return;
|
| 35 |
|
| 36 | memb->slot = le16_to_cpu(rf->rf_our_slot);
|
| 37 | memb->generation = le32_to_cpu(rf->rf_generation);
|
| 38 | }
|
| 39 |
|
| 40 | void dlm_slots_copy_out(struct dlm_ls *ls, struct dlm_rcom *rc)
|
| 41 | {
|
| 42 | struct dlm_slot *slot;
|
| 43 | struct rcom_slot *ro;
|
| 44 | int i;
|
| 45 |
|
| 46 | ro = (struct rcom_slot *)(rc->rc_buf + sizeof(struct rcom_config));
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 | for (i = 0; i < ls->ls_slots_size; i++) {
|
| 51 | slot = &ls->ls_slots[i];
|
| 52 | if (!slot->nodeid)
|
| 53 | continue;
|
| 54 | ro->ro_nodeid = cpu_to_le32(slot->nodeid);
|
| 55 | ro->ro_slot = cpu_to_le16(slot->slot);
|
| 56 | ro++;
|
| 57 | }
|
| 58 | }
|
| 59 |
|
| 60 | #define SLOT_DEBUG_LINE 128
|
| 61 |
|
| 62 | static void log_slots(struct dlm_ls *ls, uint32_t gen, int num_slots,
|
| 63 | struct rcom_slot *ro0, struct dlm_slot *array,
|
| 64 | int array_size)
|
| 65 | {
|
| 66 | char line[SLOT_DEBUG_LINE];
|
| 67 | int len = SLOT_DEBUG_LINE - 1;
|
| 68 | int pos = 0;
|
| 69 | int ret, i;
|
| 70 |
|
| 71 | memset(line, 0, sizeof(line));
|
| 72 |
|
| 73 | if (array) {
|
| 74 | for (i = 0; i < array_size; i++) {
|
| 75 | if (!array[i].nodeid)
|
| 76 | continue;
|
| 77 |
|
| 78 | ret = snprintf(line + pos, len - pos, " %d:%d",
|
| 79 | array[i].slot, array[i].nodeid);
|
| 80 | if (ret >= len - pos)
|
| 81 | break;
|
| 82 | pos += ret;
|
| 83 | }
|
| 84 | } else if (ro0) {
|
| 85 | for (i = 0; i < num_slots; i++) {
|
| 86 | ret = snprintf(line + pos, len - pos, " %d:%d",
|
| 87 | ro0[i].ro_slot, ro0[i].ro_nodeid);
|
| 88 | if (ret >= len - pos)
|
| 89 | break;
|
| 90 | pos += ret;
|
| 91 | }
|
| 92 | }
|
| 93 |
|
| 94 | log_rinfo(ls, "generation %u slots %d%s", gen, num_slots, line);
|
| 95 | }
|
| 96 |
|
| 97 | int dlm_slots_copy_in(struct dlm_ls *ls)
|
| 98 | {
|
| 99 | struct dlm_member *memb;
|
| 100 | struct dlm_rcom *rc = ls->ls_recover_buf;
|
| 101 | struct rcom_config *rf = (struct rcom_config *)rc->rc_buf;
|
| 102 | struct rcom_slot *ro0, *ro;
|
| 103 | int our_nodeid = dlm_our_nodeid();
|
| 104 | int i, num_slots;
|
| 105 | uint32_t gen;
|
| 106 |
|
| 107 | if (!dlm_slots_version(&rc->rc_header))
|
| 108 | return -1;
|
| 109 |
|
| 110 | gen = le32_to_cpu(rf->rf_generation);
|
| 111 | if (gen <= ls->ls_generation) {
|
| 112 | log_error(ls, "dlm_slots_copy_in gen %u old %u",
|
| 113 | gen, ls->ls_generation);
|
| 114 | }
|
| 115 | ls->ls_generation = gen;
|
| 116 |
|
| 117 | num_slots = le16_to_cpu(rf->rf_num_slots);
|
| 118 | if (!num_slots)
|
| 119 | return -1;
|
| 120 |
|
| 121 | ro0 = (struct rcom_slot *)(rc->rc_buf + sizeof(struct rcom_config));
|
| 122 |
|
| 123 | log_slots(ls, gen, num_slots, ro0, NULL, 0);
|
| 124 |
|
| 125 | list_for_each_entry(memb, &ls->ls_nodes, list) {
|
| 126 | for (i = 0, ro = ro0; i < num_slots; i++, ro++) {
|
| 127 | if (le32_to_cpu(ro->ro_nodeid) != memb->nodeid)
|
| 128 | continue;
|
| 129 | memb->slot = le16_to_cpu(ro->ro_slot);
|
| 130 | memb->slot_prev = memb->slot;
|
| 131 | break;
|
| 132 | }
|
| 133 |
|
| 134 | if (memb->nodeid == our_nodeid) {
|
| 135 | if (ls->ls_slot && ls->ls_slot != memb->slot) {
|
| 136 | log_error(ls, "dlm_slots_copy_in our slot "
|
| 137 | "changed %d %d", ls->ls_slot,
|
| 138 | memb->slot);
|
| 139 | return -1;
|
| 140 | }
|
| 141 |
|
| 142 | if (!ls->ls_slot)
|
| 143 | ls->ls_slot = memb->slot;
|
| 144 | }
|
| 145 |
|
| 146 | if (!memb->slot) {
|
| 147 | log_error(ls, "dlm_slots_copy_in nodeid %d no slot",
|
| 148 | memb->nodeid);
|
| 149 | return -1;
|
| 150 | }
|
| 151 | }
|
| 152 |
|
| 153 | return 0;
|
| 154 | }
|
| 155 |
|
| 156 | |
| 157 | in wait_status_all(), so memb->slot will remain -1, and we will not
|
| 158 | assign slots or set ls_num_slots here
|
| 159 |
|
| 160 | int dlm_slots_assign(struct dlm_ls *ls, int *num_slots, int *slots_size,
|
| 161 | struct dlm_slot **slots_out, uint32_t *gen_out)
|
| 162 | {
|
| 163 | struct dlm_member *memb;
|
| 164 | struct dlm_slot *array;
|
| 165 | int our_nodeid = dlm_our_nodeid();
|
| 166 | int array_size, max_slots, i;
|
| 167 | int need = 0;
|
| 168 | int max = 0;
|
| 169 | int num = 0;
|
| 170 | uint32_t gen = 0;
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 | list_for_each_entry(memb, &ls->ls_nodes, list) {
|
| 175 | if (memb->nodeid == our_nodeid) {
|
| 176 | memb->slot = ls->ls_slot;
|
| 177 | memb->generation = ls->ls_generation;
|
| 178 | break;
|
| 179 | }
|
| 180 | }
|
| 181 |
|
| 182 | list_for_each_entry(memb, &ls->ls_nodes, list) {
|
| 183 | if (memb->generation > gen)
|
| 184 | gen = memb->generation;
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 | if (memb->slot == -1)
|
| 189 | return -1;
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 | if (!memb->slot)
|
| 194 | need++;
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 | num++;
|
| 199 |
|
| 200 | if (!max || max < memb->slot)
|
| 201 | max = memb->slot;
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 | if (memb->slot_prev && memb->slot && memb->slot_prev != memb->slot) {
|
| 206 | log_error(ls, "nodeid %d slot changed %d %d",
|
| 207 | memb->nodeid, memb->slot_prev, memb->slot);
|
| 208 | return -1;
|
| 209 | }
|
| 210 | memb->slot_prev = memb->slot;
|
| 211 | }
|
| 212 |
|
| 213 | array_size = max + need;
|
| 214 | array = kzalloc_objs(*array, array_size, GFP_NOFS);
|
| 215 | if (!array)
|
| 216 | return -ENOMEM;
|
| 217 |
|
| 218 | num = 0;
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 | list_for_each_entry(memb, &ls->ls_nodes, list) {
|
| 223 | if (!memb->slot)
|
| 224 | continue;
|
| 225 |
|
| 226 | if (memb->slot > array_size) {
|
| 227 | log_error(ls, "invalid slot number %d", memb->slot);
|
| 228 | kfree(array);
|
| 229 | return -1;
|
| 230 | }
|
| 231 |
|
| 232 | array[memb->slot - 1].nodeid = memb->nodeid;
|
| 233 | array[memb->slot - 1].slot = memb->slot;
|
| 234 | num++;
|
| 235 | }
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 | list_for_each_entry(memb, &ls->ls_nodes, list) {
|
| 240 | if (memb->slot)
|
| 241 | continue;
|
| 242 |
|
| 243 | for (i = 0; i < array_size; i++) {
|
| 244 | if (array[i].nodeid)
|
| 245 | continue;
|
| 246 |
|
| 247 | memb->slot = i + 1;
|
| 248 | memb->slot_prev = memb->slot;
|
| 249 | array[i].nodeid = memb->nodeid;
|
| 250 | array[i].slot = memb->slot;
|
| 251 | num++;
|
| 252 |
|
| 253 | if (!ls->ls_slot && memb->nodeid == our_nodeid)
|
| 254 | ls->ls_slot = memb->slot;
|
| 255 | break;
|
| 256 | }
|
| 257 |
|
| 258 | if (!memb->slot) {
|
| 259 | log_error(ls, "no free slot found");
|
| 260 | kfree(array);
|
| 261 | return -1;
|
| 262 | }
|
| 263 | }
|
| 264 |
|
| 265 | gen++;
|
| 266 |
|
| 267 | log_slots(ls, gen, num, NULL, array, array_size);
|
| 268 |
|
| 269 | max_slots = (DLM_MAX_APP_BUFSIZE - sizeof(struct dlm_rcom) -
|
| 270 | sizeof(struct rcom_config)) / sizeof(struct rcom_slot);
|
| 271 |
|
| 272 | if (num > max_slots) {
|
| 273 | log_error(ls, "num_slots %d exceeds max_slots %d",
|
| 274 | num, max_slots);
|
| 275 | kfree(array);
|
| 276 | return -1;
|
| 277 | }
|
| 278 |
|
| 279 | *gen_out = gen;
|
| 280 | *slots_out = array;
|
| 281 | *slots_size = array_size;
|
| 282 | *num_slots = num;
|
| 283 | return 0;
|
| 284 | }
|
| 285 |
|
| 286 | static void add_ordered_member(struct dlm_ls *ls, struct dlm_member *new)
|
| 287 | {
|
| 288 | struct dlm_member *memb = NULL;
|
| 289 | struct list_head *tmp;
|
| 290 | struct list_head *newlist = &new->list;
|
| 291 | struct list_head *head = &ls->ls_nodes;
|
| 292 |
|
| 293 | list_for_each(tmp, head) {
|
| 294 | memb = list_entry(tmp, struct dlm_member, list);
|
| 295 | if (new->nodeid < memb->nodeid)
|
| 296 | break;
|
| 297 | }
|
| 298 |
|
| 299 | if (!memb)
|
| 300 | list_add_tail(newlist, head);
|
| 301 | else {
|
| 302 | list_add_tail(newlist, tmp);
|
| 303 | }
|
| 304 | }
|
| 305 |
|
| 306 | static int add_remote_member(int nodeid)
|
| 307 | {
|
| 308 | int error;
|
| 309 |
|
| 310 | if (nodeid == dlm_our_nodeid())
|
| 311 | return 0;
|
| 312 |
|
| 313 | error = dlm_lowcomms_connect_node(nodeid);
|
| 314 | if (error < 0)
|
| 315 | return error;
|
| 316 |
|
| 317 | dlm_midcomms_add_member(nodeid);
|
| 318 | return 0;
|
| 319 | }
|
| 320 |
|
| 321 | static int dlm_add_member(struct dlm_ls *ls, struct dlm_config_node *node)
|
| 322 | {
|
| 323 | struct dlm_member *memb;
|
| 324 | int error;
|
| 325 |
|
| 326 | memb = kzalloc_obj(*memb, GFP_NOFS);
|
| 327 | if (!memb)
|
| 328 | return -ENOMEM;
|
| 329 |
|
| 330 | memb->nodeid = node->nodeid;
|
| 331 | memb->weight = node->weight;
|
| 332 | memb->comm_seq = node->comm_seq;
|
| 333 |
|
| 334 | error = add_remote_member(node->nodeid);
|
| 335 | if (error < 0) {
|
| 336 | kfree(memb);
|
| 337 | return error;
|
| 338 | }
|
| 339 |
|
| 340 | add_ordered_member(ls, memb);
|
| 341 | ls->ls_num_nodes++;
|
| 342 | return 0;
|
| 343 | }
|
| 344 |
|
| 345 | static struct dlm_member *find_memb(struct list_head *head, int nodeid)
|
| 346 | {
|
| 347 | struct dlm_member *memb;
|
| 348 |
|
| 349 | list_for_each_entry(memb, head, list) {
|
| 350 | if (memb->nodeid == nodeid)
|
| 351 | return memb;
|
| 352 | }
|
| 353 | return NULL;
|
| 354 | }
|
| 355 |
|
| 356 | int dlm_is_member(struct dlm_ls *ls, int nodeid)
|
| 357 | {
|
| 358 | if (find_memb(&ls->ls_nodes, nodeid))
|
| 359 | return 1;
|
| 360 | return 0;
|
| 361 | }
|
| 362 |
|
| 363 | int dlm_is_removed(struct dlm_ls *ls, int nodeid)
|
| 364 | {
|
| 365 | WARN_ON_ONCE(!nodeid || nodeid == -1);
|
| 366 |
|
| 367 | if (find_memb(&ls->ls_nodes_gone, nodeid))
|
| 368 | return 1;
|
| 369 | return 0;
|
| 370 | }
|
| 371 |
|
| 372 | static void clear_memb_list(struct list_head *head,
|
| 373 | void (*after_del)(int nodeid))
|
| 374 | {
|
| 375 | struct dlm_member *memb;
|
| 376 |
|
| 377 | while (!list_empty(head)) {
|
| 378 | memb = list_entry(head->next, struct dlm_member, list);
|
| 379 | list_del(&memb->list);
|
| 380 | if (after_del)
|
| 381 | after_del(memb->nodeid);
|
| 382 | kfree(memb);
|
| 383 | }
|
| 384 | }
|
| 385 |
|
| 386 | static void remove_remote_member(int nodeid)
|
| 387 | {
|
| 388 | if (nodeid == dlm_our_nodeid())
|
| 389 | return;
|
| 390 |
|
| 391 | dlm_midcomms_remove_member(nodeid);
|
| 392 | }
|
| 393 |
|
| 394 | void dlm_clear_members(struct dlm_ls *ls)
|
| 395 | {
|
| 396 | clear_memb_list(&ls->ls_nodes, remove_remote_member);
|
| 397 | ls->ls_num_nodes = 0;
|
| 398 | }
|
| 399 |
|
| 400 | void dlm_clear_members_gone(struct dlm_ls *ls)
|
| 401 | {
|
| 402 | clear_memb_list(&ls->ls_nodes_gone, NULL);
|
| 403 | }
|
| 404 |
|
| 405 | static int make_member_array(struct dlm_ls *ls)
|
| 406 | {
|
| 407 | struct dlm_member *memb;
|
| 408 | int i, w, x = 0, total = 0, all_zero = 0, *array;
|
| 409 |
|
| 410 | kfree(ls->ls_node_array);
|
| 411 | ls->ls_node_array = NULL;
|
| 412 |
|
| 413 | list_for_each_entry(memb, &ls->ls_nodes, list) {
|
| 414 | if (check_add_overflow(total, memb->weight, &total))
|
| 415 | return -EOVERFLOW;
|
| 416 | }
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 | if (!total) {
|
| 421 | total = ls->ls_num_nodes;
|
| 422 | all_zero = 1;
|
| 423 | }
|
| 424 |
|
| 425 | array = kmalloc_objs(*array, total, GFP_NOFS);
|
| 426 | if (!array)
|
| 427 | return -ENOMEM;
|
| 428 |
|
| 429 | list_for_each_entry(memb, &ls->ls_nodes, list) {
|
| 430 | if (!all_zero && !memb->weight)
|
| 431 | continue;
|
| 432 |
|
| 433 | if (all_zero)
|
| 434 | w = 1;
|
| 435 | else
|
| 436 | w = memb->weight;
|
| 437 |
|
| 438 | DLM_ASSERT(x < total, printk("total %d x %d\n", total, x););
|
| 439 |
|
| 440 | for (i = 0; i < w; i++)
|
| 441 | array[x++] = memb->nodeid;
|
| 442 | }
|
| 443 |
|
| 444 | ls->ls_total_weight = total;
|
| 445 | ls->ls_node_array = array;
|
| 446 |
|
| 447 | return 0;
|
| 448 | }
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 | static int ping_members(struct dlm_ls *ls, uint64_t seq)
|
| 453 | {
|
| 454 | struct dlm_member *memb;
|
| 455 | int error = 0;
|
| 456 |
|
| 457 | list_for_each_entry(memb, &ls->ls_nodes, list) {
|
| 458 | if (dlm_recovery_stopped(ls)) {
|
| 459 | error = -EINTR;
|
| 460 | break;
|
| 461 | }
|
| 462 | error = dlm_rcom_status(ls, memb->nodeid, 0, seq);
|
| 463 | if (error)
|
| 464 | break;
|
| 465 | }
|
| 466 | if (error)
|
| 467 | log_rinfo(ls, "ping_members aborted %d last nodeid %d",
|
| 468 | error, ls->ls_recover_nodeid);
|
| 469 | return error;
|
| 470 | }
|
| 471 |
|
| 472 | static void dlm_lsop_recover_prep(struct dlm_ls *ls)
|
| 473 | {
|
| 474 | if (!ls->ls_ops || !ls->ls_ops->recover_prep)
|
| 475 | return;
|
| 476 | ls->ls_ops->recover_prep(ls->ls_ops_arg);
|
| 477 | }
|
| 478 |
|
| 479 | static void dlm_lsop_recover_slot(struct dlm_ls *ls, struct dlm_member *memb,
|
| 480 | unsigned int release_recover)
|
| 481 | {
|
| 482 | struct dlm_slot slot;
|
| 483 | uint32_t seq;
|
| 484 | int error;
|
| 485 |
|
| 486 | if (!ls->ls_ops || !ls->ls_ops->recover_slot)
|
| 487 | return;
|
| 488 |
|
| 489 | |
| 490 | or the present comms connection is newer
|
| 491 | than the one when this member was added, then
|
| 492 | we consider the node to have failed (versus
|
| 493 | being removed due to dlm_release_lockspace)
|
| 494 |
|
| 495 | error = dlm_comm_seq(memb->nodeid, &seq, false);
|
| 496 |
|
| 497 | if (!release_recover && !error && seq == memb->comm_seq)
|
| 498 | return;
|
| 499 |
|
| 500 | slot.nodeid = memb->nodeid;
|
| 501 | slot.slot = memb->slot;
|
| 502 |
|
| 503 | ls->ls_ops->recover_slot(ls->ls_ops_arg, &slot);
|
| 504 | }
|
| 505 |
|
| 506 | void dlm_lsop_recover_done(struct dlm_ls *ls)
|
| 507 | {
|
| 508 | struct dlm_member *memb;
|
| 509 | struct dlm_slot *slots;
|
| 510 | int i, num;
|
| 511 |
|
| 512 | if (!ls->ls_ops || !ls->ls_ops->recover_done)
|
| 513 | return;
|
| 514 |
|
| 515 | num = ls->ls_num_nodes;
|
| 516 | slots = kzalloc_objs(*slots, num);
|
| 517 | if (!slots)
|
| 518 | return;
|
| 519 |
|
| 520 | i = 0;
|
| 521 | list_for_each_entry(memb, &ls->ls_nodes, list) {
|
| 522 | if (i == num) {
|
| 523 | log_error(ls, "dlm_lsop_recover_done bad num %d", num);
|
| 524 | goto out;
|
| 525 | }
|
| 526 | slots[i].nodeid = memb->nodeid;
|
| 527 | slots[i].slot = memb->slot;
|
| 528 | i++;
|
| 529 | }
|
| 530 |
|
| 531 | ls->ls_ops->recover_done(ls->ls_ops_arg, slots, num,
|
| 532 | ls->ls_slot, ls->ls_generation);
|
| 533 | out:
|
| 534 | kfree(slots);
|
| 535 | }
|
| 536 |
|
| 537 | static struct dlm_config_node *find_config_node(struct dlm_recover *rv,
|
| 538 | int nodeid)
|
| 539 | {
|
| 540 | int i;
|
| 541 |
|
| 542 | for (i = 0; i < rv->nodes_count; i++) {
|
| 543 | if (rv->nodes[i].nodeid == nodeid)
|
| 544 | return &rv->nodes[i];
|
| 545 | }
|
| 546 | return NULL;
|
| 547 | }
|
| 548 |
|
| 549 | int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out)
|
| 550 | {
|
| 551 | struct dlm_member *memb, *safe;
|
| 552 | struct dlm_config_node *node;
|
| 553 | int i, error, neg = 0, low = -1;
|
| 554 | unsigned int release_recover;
|
| 555 |
|
| 556 | |
| 557 | * count as a negative change so the "neg" recovery steps will happen
|
| 558 | *
|
| 559 | * This functionality must report all member changes to lsops or
|
| 560 | * midcomms layer and must never return before.
|
| 561 |
|
| 562 |
|
| 563 | list_for_each_entry(memb, &ls->ls_nodes_gone, list) {
|
| 564 | log_rinfo(ls, "prev removed member %d", memb->nodeid);
|
| 565 | neg++;
|
| 566 | }
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 | list_for_each_entry_safe(memb, safe, &ls->ls_nodes, list) {
|
| 571 | node = find_config_node(rv, memb->nodeid);
|
| 572 | if (!node) {
|
| 573 | log_error(ls, "remove member %d invalid",
|
| 574 | memb->nodeid);
|
| 575 | return -EFAULT;
|
| 576 | }
|
| 577 |
|
| 578 | if (!node->new && !node->gone)
|
| 579 | continue;
|
| 580 |
|
| 581 | release_recover = 0;
|
| 582 |
|
| 583 | if (node->gone) {
|
| 584 | release_recover = node->release_recover;
|
| 585 | log_rinfo(ls, "remove member %d%s", memb->nodeid,
|
| 586 | release_recover ? " (release_recover)" : "");
|
| 587 | } else {
|
| 588 |
|
| 589 | log_rinfo(ls, "remove member %d comm_seq %u %u",
|
| 590 | memb->nodeid, memb->comm_seq, node->comm_seq);
|
| 591 | }
|
| 592 |
|
| 593 | neg++;
|
| 594 | list_move(&memb->list, &ls->ls_nodes_gone);
|
| 595 | remove_remote_member(memb->nodeid);
|
| 596 | ls->ls_num_nodes--;
|
| 597 | dlm_lsop_recover_slot(ls, memb, release_recover);
|
| 598 | }
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 | for (i = 0; i < rv->nodes_count; i++) {
|
| 603 | node = &rv->nodes[i];
|
| 604 | if (node->gone)
|
| 605 | continue;
|
| 606 |
|
| 607 | if (dlm_is_member(ls, node->nodeid))
|
| 608 | continue;
|
| 609 | error = dlm_add_member(ls, node);
|
| 610 | if (error)
|
| 611 | return error;
|
| 612 |
|
| 613 | log_rinfo(ls, "add member %d", node->nodeid);
|
| 614 | }
|
| 615 |
|
| 616 | list_for_each_entry(memb, &ls->ls_nodes, list) {
|
| 617 | if (low == -1 || memb->nodeid < low)
|
| 618 | low = memb->nodeid;
|
| 619 | }
|
| 620 | ls->ls_low_nodeid = low;
|
| 621 |
|
| 622 | error = make_member_array(ls);
|
| 623 | if (error)
|
| 624 | return error;
|
| 625 |
|
| 626 | *neg_out = neg;
|
| 627 |
|
| 628 | error = ping_members(ls, rv->seq);
|
| 629 | log_rinfo(ls, "dlm_recover_members %d nodes", ls->ls_num_nodes);
|
| 630 | return error;
|
| 631 | }
|
| 632 |
|
| 633 | |
| 634 | dlm_ls_start() is called on any of them to start the new recovery.
|
| 635 |
|
| 636 | int dlm_ls_stop(struct dlm_ls *ls)
|
| 637 | {
|
| 638 | int new;
|
| 639 |
|
| 640 | |
| 641 | * Prevent dlm_recv from being in the middle of something when we do
|
| 642 | * the stop. This includes ensuring dlm_recv isn't processing a
|
| 643 | * recovery message (rcom), while dlm_recoverd is aborting and
|
| 644 | * resetting things from an in-progress recovery. i.e. we want
|
| 645 | * dlm_recoverd to abort its recovery without worrying about dlm_recv
|
| 646 | * processing an rcom at the same time. Stopping dlm_recv also makes
|
| 647 | * it easy for dlm_receive_message() to check locking stopped and add a
|
| 648 | * message to the requestqueue without races.
|
| 649 |
|
| 650 |
|
| 651 | write_lock_bh(&ls->ls_recv_active);
|
| 652 |
|
| 653 | |
| 654 | * Abort any recovery that's in progress (see RECOVER_STOP,
|
| 655 | * dlm_recovery_stopped()) and tell any other threads running in the
|
| 656 | * dlm to quit any processing (see RUNNING, dlm_locking_stopped()).
|
| 657 |
|
| 658 |
|
| 659 | spin_lock_bh(&ls->ls_recover_lock);
|
| 660 | set_bit(LSFL_RECOVER_STOP, &ls->ls_flags);
|
| 661 | new = test_and_clear_bit(LSFL_RUNNING, &ls->ls_flags);
|
| 662 | if (new)
|
| 663 | timer_delete_sync(&ls->ls_scan_timer);
|
| 664 | ls->ls_recover_seq++;
|
| 665 |
|
| 666 |
|
| 667 | write_lock_bh(&ls->ls_requestqueue_lock);
|
| 668 | set_bit(LSFL_RECV_MSG_BLOCKED, &ls->ls_flags);
|
| 669 | write_unlock_bh(&ls->ls_requestqueue_lock);
|
| 670 | spin_unlock_bh(&ls->ls_recover_lock);
|
| 671 |
|
| 672 | |
| 673 | * Let dlm_recv run again, now any normal messages will be saved on the
|
| 674 | * requestqueue for later.
|
| 675 |
|
| 676 |
|
| 677 | write_unlock_bh(&ls->ls_recv_active);
|
| 678 |
|
| 679 | |
| 680 | * This in_recovery lock does two things:
|
| 681 | * 1) Keeps this function from returning until all threads are out
|
| 682 | * of locking routines and locking is truly stopped.
|
| 683 | * 2) Keeps any new requests from being processed until it's unlocked
|
| 684 | * when recovery is complete.
|
| 685 |
|
| 686 |
|
| 687 | if (new) {
|
| 688 | set_bit(LSFL_RECOVER_DOWN, &ls->ls_flags);
|
| 689 | wake_up_process(ls->ls_recoverd_task);
|
| 690 | wait_event(ls->ls_recover_lock_wait,
|
| 691 | test_bit(LSFL_RECOVER_LOCK, &ls->ls_flags));
|
| 692 | }
|
| 693 |
|
| 694 | |
| 695 | * The recoverd suspend/resume makes sure that dlm_recoverd (if
|
| 696 | * running) has noticed RECOVER_STOP above and quit processing the
|
| 697 | * previous recovery.
|
| 698 |
|
| 699 |
|
| 700 | dlm_recoverd_suspend(ls);
|
| 701 |
|
| 702 | spin_lock_bh(&ls->ls_recover_lock);
|
| 703 | kfree(ls->ls_slots);
|
| 704 | ls->ls_slots = NULL;
|
| 705 | ls->ls_num_slots = 0;
|
| 706 | ls->ls_slots_size = 0;
|
| 707 | ls->ls_recover_status = 0;
|
| 708 | spin_unlock_bh(&ls->ls_recover_lock);
|
| 709 |
|
| 710 | dlm_recoverd_resume(ls);
|
| 711 |
|
| 712 | if (!ls->ls_recover_begin)
|
| 713 | ls->ls_recover_begin = jiffies;
|
| 714 |
|
| 715 | |
| 716 | * for each possible dlm_ls_stop() when recovery is already
|
| 717 | * stopped.
|
| 718 | *
|
| 719 | * If we successful was able to clear LSFL_RUNNING bit and
|
| 720 | * it was set we know it is the first dlm_ls_stop() call.
|
| 721 |
|
| 722 | if (new)
|
| 723 | dlm_lsop_recover_prep(ls);
|
| 724 |
|
| 725 | return 0;
|
| 726 | }
|
| 727 |
|
| 728 | int dlm_ls_start(struct dlm_ls *ls)
|
| 729 | {
|
| 730 | struct dlm_recover *rv, *rv_old;
|
| 731 | struct dlm_config_node *nodes = NULL;
|
| 732 | int error, count;
|
| 733 |
|
| 734 | rv = kzalloc_obj(*rv, GFP_NOFS);
|
| 735 | if (!rv)
|
| 736 | return -ENOMEM;
|
| 737 |
|
| 738 | error = dlm_config_nodes(ls->ls_name, &nodes, &count);
|
| 739 | if (error < 0)
|
| 740 | goto fail_rv;
|
| 741 |
|
| 742 | spin_lock_bh(&ls->ls_recover_lock);
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 | if (!dlm_locking_stopped(ls)) {
|
| 747 | spin_unlock_bh(&ls->ls_recover_lock);
|
| 748 | log_error(ls, "start ignored: lockspace running");
|
| 749 | error = -EINVAL;
|
| 750 | goto fail;
|
| 751 | }
|
| 752 |
|
| 753 | rv->nodes = nodes;
|
| 754 | rv->nodes_count = count;
|
| 755 | rv->seq = ++ls->ls_recover_seq;
|
| 756 | rv_old = ls->ls_recover_args;
|
| 757 | ls->ls_recover_args = rv;
|
| 758 | spin_unlock_bh(&ls->ls_recover_lock);
|
| 759 |
|
| 760 | if (rv_old) {
|
| 761 | log_error(ls, "unused recovery %llx %d",
|
| 762 | (unsigned long long)rv_old->seq, rv_old->nodes_count);
|
| 763 | kfree(rv_old->nodes);
|
| 764 | kfree(rv_old);
|
| 765 | }
|
| 766 |
|
| 767 | set_bit(LSFL_RECOVER_WORK, &ls->ls_flags);
|
| 768 | wake_up_process(ls->ls_recoverd_task);
|
| 769 | return 0;
|
| 770 |
|
| 771 | fail:
|
| 772 | kfree(nodes);
|
| 773 | fail_rv:
|
| 774 | kfree(rv);
|
| 775 | return error;
|
| 776 | }
|
| 777 |
|