David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | ******************************************************************************* |
| 3 | ** |
| 4 | ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
| 5 | ** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. |
| 6 | ** |
| 7 | ** This copyrighted material is made available to anyone wishing to use, |
| 8 | ** modify, copy, or redistribute it subject to the terms and conditions |
| 9 | ** of the GNU General Public License v.2. |
| 10 | ** |
| 11 | ******************************************************************************* |
| 12 | ******************************************************************************/ |
| 13 | |
| 14 | #include "dlm_internal.h" |
| 15 | #include "lockspace.h" |
| 16 | #include "dir.h" |
| 17 | #include "config.h" |
| 18 | #include "ast.h" |
| 19 | #include "memory.h" |
| 20 | #include "rcom.h" |
| 21 | #include "lock.h" |
| 22 | #include "lowcomms.h" |
| 23 | #include "member.h" |
| 24 | #include "recover.h" |
| 25 | |
| 26 | |
| 27 | /* |
| 28 | * Recovery waiting routines: these functions wait for a particular reply from |
| 29 | * a remote node, or for the remote node to report a certain status. They need |
| 30 | * to abort if the lockspace is stopped indicating a node has failed (perhaps |
| 31 | * the one being waited for). |
| 32 | */ |
| 33 | |
| 34 | /* |
| 35 | * Wait until given function returns non-zero or lockspace is stopped |
| 36 | * (LS_RECOVERY_STOP set due to failure of a node in ls_nodes). When another |
| 37 | * function thinks it could have completed the waited-on task, they should wake |
| 38 | * up ls_wait_general to get an immediate response rather than waiting for the |
| 39 | * timer to detect the result. A timer wakes us up periodically while waiting |
| 40 | * to see if we should abort due to a node failure. This should only be called |
| 41 | * by the dlm_recoverd thread. |
| 42 | */ |
| 43 | |
| 44 | static void dlm_wait_timer_fn(unsigned long data) |
| 45 | { |
| 46 | struct dlm_ls *ls = (struct dlm_ls *) data; |
David Teigland | 68c817a | 2007-01-09 09:41:48 -0600 | [diff] [blame] | 47 | mod_timer(&ls->ls_timer, jiffies + (dlm_config.ci_recover_timer * HZ)); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 48 | wake_up(&ls->ls_wait_general); |
| 49 | } |
| 50 | |
| 51 | int dlm_wait_function(struct dlm_ls *ls, int (*testfn) (struct dlm_ls *ls)) |
| 52 | { |
| 53 | int error = 0; |
| 54 | |
| 55 | init_timer(&ls->ls_timer); |
| 56 | ls->ls_timer.function = dlm_wait_timer_fn; |
| 57 | ls->ls_timer.data = (long) ls; |
David Teigland | 68c817a | 2007-01-09 09:41:48 -0600 | [diff] [blame] | 58 | ls->ls_timer.expires = jiffies + (dlm_config.ci_recover_timer * HZ); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 59 | add_timer(&ls->ls_timer); |
| 60 | |
| 61 | wait_event(ls->ls_wait_general, testfn(ls) || dlm_recovery_stopped(ls)); |
| 62 | del_timer_sync(&ls->ls_timer); |
| 63 | |
| 64 | if (dlm_recovery_stopped(ls)) { |
| 65 | log_debug(ls, "dlm_wait_function aborted"); |
| 66 | error = -EINTR; |
| 67 | } |
| 68 | return error; |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * An efficient way for all nodes to wait for all others to have a certain |
| 73 | * status. The node with the lowest nodeid polls all the others for their |
| 74 | * status (wait_status_all) and all the others poll the node with the low id |
| 75 | * for its accumulated result (wait_status_low). When all nodes have set |
| 76 | * status flag X, then status flag X_ALL will be set on the low nodeid. |
| 77 | */ |
| 78 | |
| 79 | uint32_t dlm_recover_status(struct dlm_ls *ls) |
| 80 | { |
| 81 | uint32_t status; |
| 82 | spin_lock(&ls->ls_recover_lock); |
| 83 | status = ls->ls_recover_status; |
| 84 | spin_unlock(&ls->ls_recover_lock); |
| 85 | return status; |
| 86 | } |
| 87 | |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 88 | static void _set_recover_status(struct dlm_ls *ls, uint32_t status) |
| 89 | { |
| 90 | ls->ls_recover_status |= status; |
| 91 | } |
| 92 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 93 | void dlm_set_recover_status(struct dlm_ls *ls, uint32_t status) |
| 94 | { |
| 95 | spin_lock(&ls->ls_recover_lock); |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 96 | _set_recover_status(ls, status); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 97 | spin_unlock(&ls->ls_recover_lock); |
| 98 | } |
| 99 | |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 100 | static int wait_status_all(struct dlm_ls *ls, uint32_t wait_status, |
| 101 | int save_slots) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 102 | { |
Al Viro | 4007685 | 2008-01-25 03:01:51 -0500 | [diff] [blame] | 103 | struct dlm_rcom *rc = ls->ls_recover_buf; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 104 | struct dlm_member *memb; |
| 105 | int error = 0, delay; |
| 106 | |
| 107 | list_for_each_entry(memb, &ls->ls_nodes, list) { |
| 108 | delay = 0; |
| 109 | for (;;) { |
| 110 | if (dlm_recovery_stopped(ls)) { |
| 111 | error = -EINTR; |
| 112 | goto out; |
| 113 | } |
| 114 | |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 115 | error = dlm_rcom_status(ls, memb->nodeid, 0); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 116 | if (error) |
| 117 | goto out; |
| 118 | |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 119 | if (save_slots) |
| 120 | dlm_slot_save(ls, rc, memb); |
| 121 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 122 | if (rc->rc_result & wait_status) |
| 123 | break; |
| 124 | if (delay < 1000) |
| 125 | delay += 20; |
| 126 | msleep(delay); |
| 127 | } |
| 128 | } |
| 129 | out: |
| 130 | return error; |
| 131 | } |
| 132 | |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 133 | static int wait_status_low(struct dlm_ls *ls, uint32_t wait_status, |
| 134 | uint32_t status_flags) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 135 | { |
Al Viro | 4007685 | 2008-01-25 03:01:51 -0500 | [diff] [blame] | 136 | struct dlm_rcom *rc = ls->ls_recover_buf; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 137 | int error = 0, delay = 0, nodeid = ls->ls_low_nodeid; |
| 138 | |
| 139 | for (;;) { |
| 140 | if (dlm_recovery_stopped(ls)) { |
| 141 | error = -EINTR; |
| 142 | goto out; |
| 143 | } |
| 144 | |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 145 | error = dlm_rcom_status(ls, nodeid, status_flags); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 146 | if (error) |
| 147 | break; |
| 148 | |
| 149 | if (rc->rc_result & wait_status) |
| 150 | break; |
| 151 | if (delay < 1000) |
| 152 | delay += 20; |
| 153 | msleep(delay); |
| 154 | } |
| 155 | out: |
| 156 | return error; |
| 157 | } |
| 158 | |
| 159 | static int wait_status(struct dlm_ls *ls, uint32_t status) |
| 160 | { |
| 161 | uint32_t status_all = status << 1; |
| 162 | int error; |
| 163 | |
| 164 | if (ls->ls_low_nodeid == dlm_our_nodeid()) { |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 165 | error = wait_status_all(ls, status, 0); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 166 | if (!error) |
| 167 | dlm_set_recover_status(ls, status_all); |
| 168 | } else |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 169 | error = wait_status_low(ls, status_all, 0); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 170 | |
| 171 | return error; |
| 172 | } |
| 173 | |
| 174 | int dlm_recover_members_wait(struct dlm_ls *ls) |
| 175 | { |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 176 | struct dlm_member *memb; |
| 177 | struct dlm_slot *slots; |
| 178 | int num_slots, slots_size; |
| 179 | int error, rv; |
| 180 | uint32_t gen; |
| 181 | |
| 182 | list_for_each_entry(memb, &ls->ls_nodes, list) { |
| 183 | memb->slot = -1; |
| 184 | memb->generation = 0; |
| 185 | } |
| 186 | |
| 187 | if (ls->ls_low_nodeid == dlm_our_nodeid()) { |
| 188 | error = wait_status_all(ls, DLM_RS_NODES, 1); |
| 189 | if (error) |
| 190 | goto out; |
| 191 | |
| 192 | /* slots array is sparse, slots_size may be > num_slots */ |
| 193 | |
| 194 | rv = dlm_slots_assign(ls, &num_slots, &slots_size, &slots, &gen); |
| 195 | if (!rv) { |
| 196 | spin_lock(&ls->ls_recover_lock); |
| 197 | _set_recover_status(ls, DLM_RS_NODES_ALL); |
| 198 | ls->ls_num_slots = num_slots; |
| 199 | ls->ls_slots_size = slots_size; |
| 200 | ls->ls_slots = slots; |
| 201 | ls->ls_generation = gen; |
| 202 | spin_unlock(&ls->ls_recover_lock); |
| 203 | } else { |
| 204 | dlm_set_recover_status(ls, DLM_RS_NODES_ALL); |
| 205 | } |
| 206 | } else { |
| 207 | error = wait_status_low(ls, DLM_RS_NODES_ALL, DLM_RSF_NEED_SLOTS); |
| 208 | if (error) |
| 209 | goto out; |
| 210 | |
| 211 | dlm_slots_copy_in(ls); |
| 212 | } |
| 213 | out: |
| 214 | return error; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | int dlm_recover_directory_wait(struct dlm_ls *ls) |
| 218 | { |
| 219 | return wait_status(ls, DLM_RS_DIR); |
| 220 | } |
| 221 | |
| 222 | int dlm_recover_locks_wait(struct dlm_ls *ls) |
| 223 | { |
| 224 | return wait_status(ls, DLM_RS_LOCKS); |
| 225 | } |
| 226 | |
| 227 | int dlm_recover_done_wait(struct dlm_ls *ls) |
| 228 | { |
| 229 | return wait_status(ls, DLM_RS_DONE); |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * The recover_list contains all the rsb's for which we've requested the new |
| 234 | * master nodeid. As replies are returned from the resource directories the |
| 235 | * rsb's are removed from the list. When the list is empty we're done. |
| 236 | * |
| 237 | * The recover_list is later similarly used for all rsb's for which we've sent |
| 238 | * new lkb's and need to receive new corresponding lkid's. |
| 239 | * |
| 240 | * We use the address of the rsb struct as a simple local identifier for the |
| 241 | * rsb so we can match an rcom reply with the rsb it was sent for. |
| 242 | */ |
| 243 | |
| 244 | static int recover_list_empty(struct dlm_ls *ls) |
| 245 | { |
| 246 | int empty; |
| 247 | |
| 248 | spin_lock(&ls->ls_recover_list_lock); |
| 249 | empty = list_empty(&ls->ls_recover_list); |
| 250 | spin_unlock(&ls->ls_recover_list_lock); |
| 251 | |
| 252 | return empty; |
| 253 | } |
| 254 | |
| 255 | static void recover_list_add(struct dlm_rsb *r) |
| 256 | { |
| 257 | struct dlm_ls *ls = r->res_ls; |
| 258 | |
| 259 | spin_lock(&ls->ls_recover_list_lock); |
| 260 | if (list_empty(&r->res_recover_list)) { |
| 261 | list_add_tail(&r->res_recover_list, &ls->ls_recover_list); |
| 262 | ls->ls_recover_list_count++; |
| 263 | dlm_hold_rsb(r); |
| 264 | } |
| 265 | spin_unlock(&ls->ls_recover_list_lock); |
| 266 | } |
| 267 | |
| 268 | static void recover_list_del(struct dlm_rsb *r) |
| 269 | { |
| 270 | struct dlm_ls *ls = r->res_ls; |
| 271 | |
| 272 | spin_lock(&ls->ls_recover_list_lock); |
| 273 | list_del_init(&r->res_recover_list); |
| 274 | ls->ls_recover_list_count--; |
| 275 | spin_unlock(&ls->ls_recover_list_lock); |
| 276 | |
| 277 | dlm_put_rsb(r); |
| 278 | } |
| 279 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 280 | static void recover_list_clear(struct dlm_ls *ls) |
| 281 | { |
| 282 | struct dlm_rsb *r, *s; |
| 283 | |
| 284 | spin_lock(&ls->ls_recover_list_lock); |
| 285 | list_for_each_entry_safe(r, s, &ls->ls_recover_list, res_recover_list) { |
| 286 | list_del_init(&r->res_recover_list); |
David Teigland | 5206980 | 2006-11-02 09:49:02 -0600 | [diff] [blame] | 287 | r->res_recover_locks_count = 0; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 288 | dlm_put_rsb(r); |
| 289 | ls->ls_recover_list_count--; |
| 290 | } |
| 291 | |
| 292 | if (ls->ls_recover_list_count != 0) { |
| 293 | log_error(ls, "warning: recover_list_count %d", |
| 294 | ls->ls_recover_list_count); |
| 295 | ls->ls_recover_list_count = 0; |
| 296 | } |
| 297 | spin_unlock(&ls->ls_recover_list_lock); |
| 298 | } |
| 299 | |
David Teigland | 1d7c484 | 2012-05-15 16:07:49 -0500 | [diff] [blame^] | 300 | static int recover_idr_empty(struct dlm_ls *ls) |
| 301 | { |
| 302 | int empty = 1; |
| 303 | |
| 304 | spin_lock(&ls->ls_recover_idr_lock); |
| 305 | if (ls->ls_recover_list_count) |
| 306 | empty = 0; |
| 307 | spin_unlock(&ls->ls_recover_idr_lock); |
| 308 | |
| 309 | return empty; |
| 310 | } |
| 311 | |
| 312 | static int recover_idr_add(struct dlm_rsb *r) |
| 313 | { |
| 314 | struct dlm_ls *ls = r->res_ls; |
| 315 | int rv, id; |
| 316 | |
| 317 | rv = idr_pre_get(&ls->ls_recover_idr, GFP_NOFS); |
| 318 | if (!rv) |
| 319 | return -ENOMEM; |
| 320 | |
| 321 | spin_lock(&ls->ls_recover_idr_lock); |
| 322 | if (r->res_id) { |
| 323 | spin_unlock(&ls->ls_recover_idr_lock); |
| 324 | return -1; |
| 325 | } |
| 326 | rv = idr_get_new_above(&ls->ls_recover_idr, r, 1, &id); |
| 327 | if (rv) { |
| 328 | spin_unlock(&ls->ls_recover_idr_lock); |
| 329 | return rv; |
| 330 | } |
| 331 | r->res_id = id; |
| 332 | ls->ls_recover_list_count++; |
| 333 | dlm_hold_rsb(r); |
| 334 | spin_unlock(&ls->ls_recover_idr_lock); |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | static void recover_idr_del(struct dlm_rsb *r) |
| 339 | { |
| 340 | struct dlm_ls *ls = r->res_ls; |
| 341 | |
| 342 | spin_lock(&ls->ls_recover_idr_lock); |
| 343 | idr_remove(&ls->ls_recover_idr, r->res_id); |
| 344 | r->res_id = 0; |
| 345 | ls->ls_recover_list_count--; |
| 346 | spin_unlock(&ls->ls_recover_idr_lock); |
| 347 | |
| 348 | dlm_put_rsb(r); |
| 349 | } |
| 350 | |
| 351 | static struct dlm_rsb *recover_idr_find(struct dlm_ls *ls, uint64_t id) |
| 352 | { |
| 353 | struct dlm_rsb *r; |
| 354 | |
| 355 | spin_lock(&ls->ls_recover_idr_lock); |
| 356 | r = idr_find(&ls->ls_recover_idr, (int)id); |
| 357 | spin_unlock(&ls->ls_recover_idr_lock); |
| 358 | return r; |
| 359 | } |
| 360 | |
| 361 | static int recover_idr_clear_rsb(int id, void *p, void *data) |
| 362 | { |
| 363 | struct dlm_ls *ls = data; |
| 364 | struct dlm_rsb *r = p; |
| 365 | |
| 366 | r->res_id = 0; |
| 367 | r->res_recover_locks_count = 0; |
| 368 | ls->ls_recover_list_count--; |
| 369 | |
| 370 | dlm_put_rsb(r); |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | static void recover_idr_clear(struct dlm_ls *ls) |
| 375 | { |
| 376 | spin_lock(&ls->ls_recover_idr_lock); |
| 377 | idr_for_each(&ls->ls_recover_idr, recover_idr_clear_rsb, ls); |
| 378 | idr_remove_all(&ls->ls_recover_idr); |
| 379 | |
| 380 | if (ls->ls_recover_list_count != 0) { |
| 381 | log_error(ls, "warning: recover_list_count %d", |
| 382 | ls->ls_recover_list_count); |
| 383 | ls->ls_recover_list_count = 0; |
| 384 | } |
| 385 | spin_unlock(&ls->ls_recover_idr_lock); |
| 386 | } |
| 387 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 388 | |
| 389 | /* Master recovery: find new master node for rsb's that were |
| 390 | mastered on nodes that have been removed. |
| 391 | |
| 392 | dlm_recover_masters |
| 393 | recover_master |
| 394 | dlm_send_rcom_lookup -> receive_rcom_lookup |
| 395 | dlm_dir_lookup |
| 396 | receive_rcom_lookup_reply <- |
| 397 | dlm_recover_master_reply |
| 398 | set_new_master |
| 399 | set_master_lkbs |
| 400 | set_lock_master |
| 401 | */ |
| 402 | |
| 403 | /* |
| 404 | * Set the lock master for all LKBs in a lock queue |
| 405 | * If we are the new master of the rsb, we may have received new |
| 406 | * MSTCPY locks from other nodes already which we need to ignore |
| 407 | * when setting the new nodeid. |
| 408 | */ |
| 409 | |
| 410 | static void set_lock_master(struct list_head *queue, int nodeid) |
| 411 | { |
| 412 | struct dlm_lkb *lkb; |
| 413 | |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 414 | list_for_each_entry(lkb, queue, lkb_statequeue) { |
| 415 | if (!(lkb->lkb_flags & DLM_IFL_MSTCPY)) { |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 416 | lkb->lkb_nodeid = nodeid; |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 417 | lkb->lkb_remid = 0; |
| 418 | } |
| 419 | } |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | static void set_master_lkbs(struct dlm_rsb *r) |
| 423 | { |
| 424 | set_lock_master(&r->res_grantqueue, r->res_nodeid); |
| 425 | set_lock_master(&r->res_convertqueue, r->res_nodeid); |
| 426 | set_lock_master(&r->res_waitqueue, r->res_nodeid); |
| 427 | } |
| 428 | |
| 429 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 430 | * Propagate the new master nodeid to locks |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 431 | * The NEW_MASTER flag tells dlm_recover_locks() which rsb's to consider. |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 432 | * The NEW_MASTER2 flag tells recover_lvb() and recover_grant() which |
David Teigland | f7da790 | 2006-07-25 13:53:33 -0500 | [diff] [blame] | 433 | * rsb's to consider. |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 434 | */ |
| 435 | |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 436 | static void set_new_master(struct dlm_rsb *r) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 437 | { |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 438 | set_master_lkbs(r); |
| 439 | rsb_set_flag(r, RSB_NEW_MASTER); |
| 440 | rsb_set_flag(r, RSB_NEW_MASTER2); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | /* |
| 444 | * We do async lookups on rsb's that need new masters. The rsb's |
| 445 | * waiting for a lookup reply are kept on the recover_list. |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 446 | * |
| 447 | * Another node recovering the master may have sent us a rcom lookup, |
| 448 | * and our dlm_master_lookup() set it as the new master, along with |
| 449 | * NEW_MASTER so that we'll recover it here (this implies dir_nodeid |
| 450 | * equals our_nodeid below). |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 451 | */ |
| 452 | |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 453 | static int recover_master(struct dlm_rsb *r, unsigned int *count) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 454 | { |
| 455 | struct dlm_ls *ls = r->res_ls; |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 456 | int our_nodeid, dir_nodeid; |
| 457 | int is_removed = 0; |
| 458 | int error; |
| 459 | |
| 460 | if (is_master(r)) |
| 461 | return 0; |
| 462 | |
| 463 | is_removed = dlm_is_removed(ls, r->res_nodeid); |
| 464 | |
| 465 | if (!is_removed && !rsb_flag(r, RSB_NEW_MASTER)) |
| 466 | return 0; |
| 467 | |
| 468 | our_nodeid = dlm_our_nodeid(); |
| 469 | dir_nodeid = dlm_dir_nodeid(r); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 470 | |
| 471 | if (dir_nodeid == our_nodeid) { |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 472 | if (is_removed) { |
| 473 | r->res_master_nodeid = our_nodeid; |
| 474 | r->res_nodeid = 0; |
| 475 | } |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 476 | |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 477 | /* set master of lkbs to ourself when is_removed, or to |
| 478 | another new master which we set along with NEW_MASTER |
| 479 | in dlm_master_lookup */ |
| 480 | set_new_master(r); |
| 481 | error = 0; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 482 | } else { |
David Teigland | 1d7c484 | 2012-05-15 16:07:49 -0500 | [diff] [blame^] | 483 | recover_idr_add(r); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 484 | error = dlm_send_rcom_lookup(r, dir_nodeid); |
| 485 | } |
| 486 | |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 487 | (*count)++; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 488 | return error; |
| 489 | } |
| 490 | |
| 491 | /* |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 492 | * All MSTCPY locks are purged and rebuilt, even if the master stayed the same. |
| 493 | * This is necessary because recovery can be started, aborted and restarted, |
| 494 | * causing the master nodeid to briefly change during the aborted recovery, and |
| 495 | * change back to the original value in the second recovery. The MSTCPY locks |
| 496 | * may or may not have been purged during the aborted recovery. Another node |
| 497 | * with an outstanding request in waiters list and a request reply saved in the |
| 498 | * requestqueue, cannot know whether it should ignore the reply and resend the |
| 499 | * request, or accept the reply and complete the request. It must do the |
| 500 | * former if the remote node purged MSTCPY locks, and it must do the later if |
| 501 | * the remote node did not. This is solved by always purging MSTCPY locks, in |
| 502 | * which case, the request reply would always be ignored and the request |
| 503 | * resent. |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 504 | */ |
| 505 | |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 506 | static int recover_master_static(struct dlm_rsb *r, unsigned int *count) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 507 | { |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 508 | int dir_nodeid = dlm_dir_nodeid(r); |
| 509 | int new_master = dir_nodeid; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 510 | |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 511 | if (dir_nodeid == dlm_our_nodeid()) |
| 512 | new_master = 0; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 513 | |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 514 | dlm_purge_mstcpy_locks(r); |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 515 | r->res_master_nodeid = dir_nodeid; |
| 516 | r->res_nodeid = new_master; |
| 517 | set_new_master(r); |
| 518 | (*count)++; |
| 519 | return 0; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | /* |
| 523 | * Go through local root resources and for each rsb which has a master which |
| 524 | * has departed, get the new master nodeid from the directory. The dir will |
| 525 | * assign mastery to the first node to look up the new master. That means |
| 526 | * we'll discover in this lookup if we're the new master of any rsb's. |
| 527 | * |
| 528 | * We fire off all the dir lookup requests individually and asynchronously to |
| 529 | * the correct dir node. |
| 530 | */ |
| 531 | |
| 532 | int dlm_recover_masters(struct dlm_ls *ls) |
| 533 | { |
| 534 | struct dlm_rsb *r; |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 535 | unsigned int total = 0; |
| 536 | unsigned int count = 0; |
| 537 | int nodir = dlm_no_directory(ls); |
| 538 | int error; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 539 | |
| 540 | log_debug(ls, "dlm_recover_masters"); |
| 541 | |
| 542 | down_read(&ls->ls_root_sem); |
| 543 | list_for_each_entry(r, &ls->ls_root_list, res_root_list) { |
| 544 | if (dlm_recovery_stopped(ls)) { |
| 545 | up_read(&ls->ls_root_sem); |
| 546 | error = -EINTR; |
| 547 | goto out; |
| 548 | } |
| 549 | |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 550 | lock_rsb(r); |
| 551 | if (nodir) |
| 552 | error = recover_master_static(r, &count); |
| 553 | else |
| 554 | error = recover_master(r, &count); |
| 555 | unlock_rsb(r); |
| 556 | cond_resched(); |
| 557 | total++; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 558 | |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 559 | if (error) { |
| 560 | up_read(&ls->ls_root_sem); |
| 561 | goto out; |
| 562 | } |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 563 | } |
| 564 | up_read(&ls->ls_root_sem); |
| 565 | |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 566 | log_debug(ls, "dlm_recover_masters %u of %u", count, total); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 567 | |
David Teigland | 1d7c484 | 2012-05-15 16:07:49 -0500 | [diff] [blame^] | 568 | error = dlm_wait_function(ls, &recover_idr_empty); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 569 | out: |
| 570 | if (error) |
David Teigland | 1d7c484 | 2012-05-15 16:07:49 -0500 | [diff] [blame^] | 571 | recover_idr_clear(ls); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 572 | return error; |
| 573 | } |
| 574 | |
| 575 | int dlm_recover_master_reply(struct dlm_ls *ls, struct dlm_rcom *rc) |
| 576 | { |
| 577 | struct dlm_rsb *r; |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 578 | int ret_nodeid, new_master; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 579 | |
David Teigland | 1d7c484 | 2012-05-15 16:07:49 -0500 | [diff] [blame^] | 580 | r = recover_idr_find(ls, rc->rc_id); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 581 | if (!r) { |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 582 | log_error(ls, "dlm_recover_master_reply no id %llx", |
David Teigland | 9229f01 | 2006-05-24 09:21:30 -0400 | [diff] [blame] | 583 | (unsigned long long)rc->rc_id); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 584 | goto out; |
| 585 | } |
| 586 | |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 587 | ret_nodeid = rc->rc_result; |
| 588 | |
| 589 | if (ret_nodeid == dlm_our_nodeid()) |
| 590 | new_master = 0; |
| 591 | else |
| 592 | new_master = ret_nodeid; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 593 | |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 594 | lock_rsb(r); |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 595 | r->res_master_nodeid = ret_nodeid; |
| 596 | r->res_nodeid = new_master; |
| 597 | set_new_master(r); |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 598 | unlock_rsb(r); |
David Teigland | 1d7c484 | 2012-05-15 16:07:49 -0500 | [diff] [blame^] | 599 | recover_idr_del(r); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 600 | |
David Teigland | 1d7c484 | 2012-05-15 16:07:49 -0500 | [diff] [blame^] | 601 | if (recover_idr_empty(ls)) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 602 | wake_up(&ls->ls_wait_general); |
| 603 | out: |
| 604 | return 0; |
| 605 | } |
| 606 | |
| 607 | |
| 608 | /* Lock recovery: rebuild the process-copy locks we hold on a |
| 609 | remastered rsb on the new rsb master. |
| 610 | |
| 611 | dlm_recover_locks |
| 612 | recover_locks |
| 613 | recover_locks_queue |
| 614 | dlm_send_rcom_lock -> receive_rcom_lock |
| 615 | dlm_recover_master_copy |
| 616 | receive_rcom_lock_reply <- |
| 617 | dlm_recover_process_copy |
| 618 | */ |
| 619 | |
| 620 | |
| 621 | /* |
| 622 | * keep a count of the number of lkb's we send to the new master; when we get |
| 623 | * an equal number of replies then recovery for the rsb is done |
| 624 | */ |
| 625 | |
| 626 | static int recover_locks_queue(struct dlm_rsb *r, struct list_head *head) |
| 627 | { |
| 628 | struct dlm_lkb *lkb; |
| 629 | int error = 0; |
| 630 | |
| 631 | list_for_each_entry(lkb, head, lkb_statequeue) { |
| 632 | error = dlm_send_rcom_lock(r, lkb); |
| 633 | if (error) |
| 634 | break; |
| 635 | r->res_recover_locks_count++; |
| 636 | } |
| 637 | |
| 638 | return error; |
| 639 | } |
| 640 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 641 | static int recover_locks(struct dlm_rsb *r) |
| 642 | { |
| 643 | int error = 0; |
| 644 | |
| 645 | lock_rsb(r); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 646 | |
David Teigland | a345da3 | 2006-08-18 11:54:25 -0500 | [diff] [blame] | 647 | DLM_ASSERT(!r->res_recover_locks_count, dlm_dump_rsb(r);); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 648 | |
| 649 | error = recover_locks_queue(r, &r->res_grantqueue); |
| 650 | if (error) |
| 651 | goto out; |
| 652 | error = recover_locks_queue(r, &r->res_convertqueue); |
| 653 | if (error) |
| 654 | goto out; |
| 655 | error = recover_locks_queue(r, &r->res_waitqueue); |
| 656 | if (error) |
| 657 | goto out; |
| 658 | |
| 659 | if (r->res_recover_locks_count) |
| 660 | recover_list_add(r); |
| 661 | else |
| 662 | rsb_clear_flag(r, RSB_NEW_MASTER); |
| 663 | out: |
| 664 | unlock_rsb(r); |
| 665 | return error; |
| 666 | } |
| 667 | |
| 668 | int dlm_recover_locks(struct dlm_ls *ls) |
| 669 | { |
| 670 | struct dlm_rsb *r; |
| 671 | int error, count = 0; |
| 672 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 673 | down_read(&ls->ls_root_sem); |
| 674 | list_for_each_entry(r, &ls->ls_root_list, res_root_list) { |
| 675 | if (is_master(r)) { |
| 676 | rsb_clear_flag(r, RSB_NEW_MASTER); |
| 677 | continue; |
| 678 | } |
| 679 | |
| 680 | if (!rsb_flag(r, RSB_NEW_MASTER)) |
| 681 | continue; |
| 682 | |
| 683 | if (dlm_recovery_stopped(ls)) { |
| 684 | error = -EINTR; |
| 685 | up_read(&ls->ls_root_sem); |
| 686 | goto out; |
| 687 | } |
| 688 | |
| 689 | error = recover_locks(r); |
| 690 | if (error) { |
| 691 | up_read(&ls->ls_root_sem); |
| 692 | goto out; |
| 693 | } |
| 694 | |
| 695 | count += r->res_recover_locks_count; |
| 696 | } |
| 697 | up_read(&ls->ls_root_sem); |
| 698 | |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 699 | log_debug(ls, "dlm_recover_locks %d out", count); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 700 | |
| 701 | error = dlm_wait_function(ls, &recover_list_empty); |
| 702 | out: |
| 703 | if (error) |
| 704 | recover_list_clear(ls); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 705 | return error; |
| 706 | } |
| 707 | |
| 708 | void dlm_recovered_lock(struct dlm_rsb *r) |
| 709 | { |
David Teigland | a345da3 | 2006-08-18 11:54:25 -0500 | [diff] [blame] | 710 | DLM_ASSERT(rsb_flag(r, RSB_NEW_MASTER), dlm_dump_rsb(r);); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 711 | |
| 712 | r->res_recover_locks_count--; |
| 713 | if (!r->res_recover_locks_count) { |
| 714 | rsb_clear_flag(r, RSB_NEW_MASTER); |
| 715 | recover_list_del(r); |
| 716 | } |
| 717 | |
| 718 | if (recover_list_empty(r->res_ls)) |
| 719 | wake_up(&r->res_ls->ls_wait_general); |
| 720 | } |
| 721 | |
| 722 | /* |
| 723 | * The lvb needs to be recovered on all master rsb's. This includes setting |
| 724 | * the VALNOTVALID flag if necessary, and determining the correct lvb contents |
| 725 | * based on the lvb's of the locks held on the rsb. |
| 726 | * |
| 727 | * RSB_VALNOTVALID is set if there are only NL/CR locks on the rsb. If it |
| 728 | * was already set prior to recovery, it's not cleared, regardless of locks. |
| 729 | * |
| 730 | * The LVB contents are only considered for changing when this is a new master |
| 731 | * of the rsb (NEW_MASTER2). Then, the rsb's lvb is taken from any lkb with |
| 732 | * mode > CR. If no lkb's exist with mode above CR, the lvb contents are taken |
| 733 | * from the lkb with the largest lvb sequence number. |
| 734 | */ |
| 735 | |
| 736 | static void recover_lvb(struct dlm_rsb *r) |
| 737 | { |
| 738 | struct dlm_lkb *lkb, *high_lkb = NULL; |
| 739 | uint32_t high_seq = 0; |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 740 | int lock_lvb_exists = 0; |
| 741 | int big_lock_exists = 0; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 742 | int lvblen = r->res_ls->ls_lvblen; |
| 743 | |
| 744 | list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) { |
| 745 | if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) |
| 746 | continue; |
| 747 | |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 748 | lock_lvb_exists = 1; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 749 | |
| 750 | if (lkb->lkb_grmode > DLM_LOCK_CR) { |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 751 | big_lock_exists = 1; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 752 | goto setflag; |
| 753 | } |
| 754 | |
| 755 | if (((int)lkb->lkb_lvbseq - (int)high_seq) >= 0) { |
| 756 | high_lkb = lkb; |
| 757 | high_seq = lkb->lkb_lvbseq; |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) { |
| 762 | if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) |
| 763 | continue; |
| 764 | |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 765 | lock_lvb_exists = 1; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 766 | |
| 767 | if (lkb->lkb_grmode > DLM_LOCK_CR) { |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 768 | big_lock_exists = 1; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 769 | goto setflag; |
| 770 | } |
| 771 | |
| 772 | if (((int)lkb->lkb_lvbseq - (int)high_seq) >= 0) { |
| 773 | high_lkb = lkb; |
| 774 | high_seq = lkb->lkb_lvbseq; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | setflag: |
| 779 | if (!lock_lvb_exists) |
| 780 | goto out; |
| 781 | |
| 782 | if (!big_lock_exists) |
| 783 | rsb_set_flag(r, RSB_VALNOTVALID); |
| 784 | |
| 785 | /* don't mess with the lvb unless we're the new master */ |
| 786 | if (!rsb_flag(r, RSB_NEW_MASTER2)) |
| 787 | goto out; |
| 788 | |
| 789 | if (!r->res_lvbptr) { |
David Teigland | 52bda2b | 2007-11-07 09:06:49 -0600 | [diff] [blame] | 790 | r->res_lvbptr = dlm_allocate_lvb(r->res_ls); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 791 | if (!r->res_lvbptr) |
| 792 | goto out; |
| 793 | } |
| 794 | |
| 795 | if (big_lock_exists) { |
| 796 | r->res_lvbseq = lkb->lkb_lvbseq; |
| 797 | memcpy(r->res_lvbptr, lkb->lkb_lvbptr, lvblen); |
| 798 | } else if (high_lkb) { |
| 799 | r->res_lvbseq = high_lkb->lkb_lvbseq; |
| 800 | memcpy(r->res_lvbptr, high_lkb->lkb_lvbptr, lvblen); |
| 801 | } else { |
| 802 | r->res_lvbseq = 0; |
| 803 | memset(r->res_lvbptr, 0, lvblen); |
| 804 | } |
| 805 | out: |
| 806 | return; |
| 807 | } |
| 808 | |
| 809 | /* All master rsb's flagged RECOVER_CONVERT need to be looked at. The locks |
| 810 | converting PR->CW or CW->PR need to have their lkb_grmode set. */ |
| 811 | |
| 812 | static void recover_conversion(struct dlm_rsb *r) |
| 813 | { |
| 814 | struct dlm_lkb *lkb; |
| 815 | int grmode = -1; |
| 816 | |
| 817 | list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) { |
| 818 | if (lkb->lkb_grmode == DLM_LOCK_PR || |
| 819 | lkb->lkb_grmode == DLM_LOCK_CW) { |
| 820 | grmode = lkb->lkb_grmode; |
| 821 | break; |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) { |
| 826 | if (lkb->lkb_grmode != DLM_LOCK_IV) |
| 827 | continue; |
| 828 | if (grmode == -1) |
| 829 | lkb->lkb_grmode = lkb->lkb_rqmode; |
| 830 | else |
| 831 | lkb->lkb_grmode = grmode; |
| 832 | } |
| 833 | } |
| 834 | |
David Teigland | f7da790 | 2006-07-25 13:53:33 -0500 | [diff] [blame] | 835 | /* We've become the new master for this rsb and waiting/converting locks may |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 836 | need to be granted in dlm_recover_grant() due to locks that may have |
David Teigland | f7da790 | 2006-07-25 13:53:33 -0500 | [diff] [blame] | 837 | existed from a removed node. */ |
| 838 | |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 839 | static void recover_grant(struct dlm_rsb *r) |
David Teigland | f7da790 | 2006-07-25 13:53:33 -0500 | [diff] [blame] | 840 | { |
| 841 | if (!list_empty(&r->res_waitqueue) || !list_empty(&r->res_convertqueue)) |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 842 | rsb_set_flag(r, RSB_RECOVER_GRANT); |
David Teigland | f7da790 | 2006-07-25 13:53:33 -0500 | [diff] [blame] | 843 | } |
| 844 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 845 | void dlm_recover_rsbs(struct dlm_ls *ls) |
| 846 | { |
| 847 | struct dlm_rsb *r; |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 848 | unsigned int count = 0; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 849 | |
| 850 | down_read(&ls->ls_root_sem); |
| 851 | list_for_each_entry(r, &ls->ls_root_list, res_root_list) { |
| 852 | lock_rsb(r); |
| 853 | if (is_master(r)) { |
| 854 | if (rsb_flag(r, RSB_RECOVER_CONVERT)) |
| 855 | recover_conversion(r); |
David Teigland | f7da790 | 2006-07-25 13:53:33 -0500 | [diff] [blame] | 856 | if (rsb_flag(r, RSB_NEW_MASTER2)) |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 857 | recover_grant(r); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 858 | recover_lvb(r); |
| 859 | count++; |
| 860 | } |
| 861 | rsb_clear_flag(r, RSB_RECOVER_CONVERT); |
David Teigland | f7da790 | 2006-07-25 13:53:33 -0500 | [diff] [blame] | 862 | rsb_clear_flag(r, RSB_NEW_MASTER2); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 863 | unlock_rsb(r); |
| 864 | } |
| 865 | up_read(&ls->ls_root_sem); |
| 866 | |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 867 | if (count) |
| 868 | log_debug(ls, "dlm_recover_rsbs %d done", count); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | /* Create a single list of all root rsb's to be used during recovery */ |
| 872 | |
| 873 | int dlm_create_root_list(struct dlm_ls *ls) |
| 874 | { |
Bob Peterson | 9beb3bf | 2011-10-26 15:24:55 -0500 | [diff] [blame] | 875 | struct rb_node *n; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 876 | struct dlm_rsb *r; |
| 877 | int i, error = 0; |
| 878 | |
| 879 | down_write(&ls->ls_root_sem); |
| 880 | if (!list_empty(&ls->ls_root_list)) { |
| 881 | log_error(ls, "root list not empty"); |
| 882 | error = -EINVAL; |
| 883 | goto out; |
| 884 | } |
| 885 | |
| 886 | for (i = 0; i < ls->ls_rsbtbl_size; i++) { |
David Teigland | c7be761 | 2009-01-07 16:50:41 -0600 | [diff] [blame] | 887 | spin_lock(&ls->ls_rsbtbl[i].lock); |
Bob Peterson | 9beb3bf | 2011-10-26 15:24:55 -0500 | [diff] [blame] | 888 | for (n = rb_first(&ls->ls_rsbtbl[i].keep); n; n = rb_next(n)) { |
| 889 | r = rb_entry(n, struct dlm_rsb, res_hashnode); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 890 | list_add(&r->res_root_list, &ls->ls_root_list); |
| 891 | dlm_hold_rsb(r); |
| 892 | } |
David Teigland | 85f0379 | 2008-01-16 13:02:31 -0600 | [diff] [blame] | 893 | |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 894 | if (!RB_EMPTY_ROOT(&ls->ls_rsbtbl[i].toss)) |
| 895 | log_error(ls, "dlm_create_root_list toss not empty"); |
David Teigland | c7be761 | 2009-01-07 16:50:41 -0600 | [diff] [blame] | 896 | spin_unlock(&ls->ls_rsbtbl[i].lock); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 897 | } |
| 898 | out: |
| 899 | up_write(&ls->ls_root_sem); |
| 900 | return error; |
| 901 | } |
| 902 | |
| 903 | void dlm_release_root_list(struct dlm_ls *ls) |
| 904 | { |
| 905 | struct dlm_rsb *r, *safe; |
| 906 | |
| 907 | down_write(&ls->ls_root_sem); |
| 908 | list_for_each_entry_safe(r, safe, &ls->ls_root_list, res_root_list) { |
| 909 | list_del_init(&r->res_root_list); |
| 910 | dlm_put_rsb(r); |
| 911 | } |
| 912 | up_write(&ls->ls_root_sem); |
| 913 | } |
| 914 | |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 915 | void dlm_clear_toss(struct dlm_ls *ls) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 916 | { |
Bob Peterson | 9beb3bf | 2011-10-26 15:24:55 -0500 | [diff] [blame] | 917 | struct rb_node *n, *next; |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 918 | struct dlm_rsb *r; |
| 919 | unsigned int count = 0; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 920 | int i; |
| 921 | |
| 922 | for (i = 0; i < ls->ls_rsbtbl_size; i++) { |
David Teigland | c7be761 | 2009-01-07 16:50:41 -0600 | [diff] [blame] | 923 | spin_lock(&ls->ls_rsbtbl[i].lock); |
Bob Peterson | 9beb3bf | 2011-10-26 15:24:55 -0500 | [diff] [blame] | 924 | for (n = rb_first(&ls->ls_rsbtbl[i].toss); n; n = next) { |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 925 | next = rb_next(n); |
| 926 | r = rb_entry(n, struct dlm_rsb, res_hashnode); |
| 927 | rb_erase(n, &ls->ls_rsbtbl[i].toss); |
| 928 | dlm_free_rsb(r); |
| 929 | count++; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 930 | } |
David Teigland | c7be761 | 2009-01-07 16:50:41 -0600 | [diff] [blame] | 931 | spin_unlock(&ls->ls_rsbtbl[i].lock); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 932 | } |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 933 | |
| 934 | if (count) |
| 935 | log_debug(ls, "dlm_clear_toss %u done", count); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 936 | } |
| 937 | |