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