rcom.c (de4fb176622d54a82ea3ceb7362392aaf5ff0b5a) rcom.c (3428785a65dabf05bc899b6c5334984e98286184)
1// SPDX-License-Identifier: GPL-2.0-only
2/******************************************************************************
3*******************************************************************************
4**
5** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
6** Copyright (C) 2005-2008 Red Hat, Inc. All rights reserved.
7**
8**

--- 20 unchanged lines hidden (view full) ---

29
30static void _create_rcom(struct dlm_ls *ls, int to_nodeid, int type, int len,
31 struct dlm_rcom **rc_ret, char *mb, int mb_len)
32{
33 struct dlm_rcom *rc;
34
35 rc = (struct dlm_rcom *) mb;
36
1// SPDX-License-Identifier: GPL-2.0-only
2/******************************************************************************
3*******************************************************************************
4**
5** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
6** Copyright (C) 2005-2008 Red Hat, Inc. All rights reserved.
7**
8**

--- 20 unchanged lines hidden (view full) ---

29
30static void _create_rcom(struct dlm_ls *ls, int to_nodeid, int type, int len,
31 struct dlm_rcom **rc_ret, char *mb, int mb_len)
32{
33 struct dlm_rcom *rc;
34
35 rc = (struct dlm_rcom *) mb;
36
37 rc->rc_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR);
38 rc->rc_header.u.h_lockspace = ls->ls_global_id;
39 rc->rc_header.h_nodeid = dlm_our_nodeid();
40 rc->rc_header.h_length = mb_len;
37 rc->rc_header.h_version = cpu_to_le32(DLM_HEADER_MAJOR | DLM_HEADER_MINOR);
38 rc->rc_header.u.h_lockspace = cpu_to_le32(ls->ls_global_id);
39 rc->rc_header.h_nodeid = cpu_to_le32(dlm_our_nodeid());
40 rc->rc_header.h_length = cpu_to_le16(mb_len);
41 rc->rc_header.h_cmd = DLM_RCOM;
42
43 rc->rc_type = type;
44
45 spin_lock(&ls->ls_recover_lock);
46 rc->rc_seq = ls->ls_recover_seq;
47 spin_unlock(&ls->ls_recover_lock);
48

--- 73 unchanged lines hidden (view full) ---

122 rf->rf_num_slots = cpu_to_le16(num_slots);
123 rf->rf_generation = cpu_to_le32(ls->ls_generation);
124}
125
126static int check_rcom_config(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid)
127{
128 struct rcom_config *rf = (struct rcom_config *) rc->rc_buf;
129
41 rc->rc_header.h_cmd = DLM_RCOM;
42
43 rc->rc_type = type;
44
45 spin_lock(&ls->ls_recover_lock);
46 rc->rc_seq = ls->ls_recover_seq;
47 spin_unlock(&ls->ls_recover_lock);
48

--- 73 unchanged lines hidden (view full) ---

122 rf->rf_num_slots = cpu_to_le16(num_slots);
123 rf->rf_generation = cpu_to_le32(ls->ls_generation);
124}
125
126static int check_rcom_config(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid)
127{
128 struct rcom_config *rf = (struct rcom_config *) rc->rc_buf;
129
130 if ((rc->rc_header.h_version & 0xFFFF0000) != DLM_HEADER_MAJOR) {
130 if ((le32_to_cpu(rc->rc_header.h_version) & 0xFFFF0000) != DLM_HEADER_MAJOR) {
131 log_error(ls, "version mismatch: %x nodeid %d: %x",
132 DLM_HEADER_MAJOR | DLM_HEADER_MINOR, nodeid,
131 log_error(ls, "version mismatch: %x nodeid %d: %x",
132 DLM_HEADER_MAJOR | DLM_HEADER_MINOR, nodeid,
133 rc->rc_header.h_version);
133 le32_to_cpu(rc->rc_header.h_version));
134 return -EPROTO;
135 }
136
137 if (le32_to_cpu(rf->rf_lvblen) != ls->ls_lvblen ||
138 le32_to_cpu(rf->rf_lsflags) != ls->ls_exflags) {
139 log_error(ls, "config mismatch: %d,%x nodeid %d: %d,%x",
140 ls->ls_lvblen, ls->ls_exflags, nodeid,
141 le32_to_cpu(rf->rf_lvblen),

--- 80 unchanged lines hidden (view full) ---

222 return error;
223}
224
225static void receive_rcom_status(struct dlm_ls *ls, struct dlm_rcom *rc_in)
226{
227 struct dlm_rcom *rc;
228 struct rcom_status *rs;
229 uint32_t status;
134 return -EPROTO;
135 }
136
137 if (le32_to_cpu(rf->rf_lvblen) != ls->ls_lvblen ||
138 le32_to_cpu(rf->rf_lsflags) != ls->ls_exflags) {
139 log_error(ls, "config mismatch: %d,%x nodeid %d: %d,%x",
140 ls->ls_lvblen, ls->ls_exflags, nodeid,
141 le32_to_cpu(rf->rf_lvblen),

--- 80 unchanged lines hidden (view full) ---

222 return error;
223}
224
225static void receive_rcom_status(struct dlm_ls *ls, struct dlm_rcom *rc_in)
226{
227 struct dlm_rcom *rc;
228 struct rcom_status *rs;
229 uint32_t status;
230 int nodeid = rc_in->rc_header.h_nodeid;
230 int nodeid = le32_to_cpu(rc_in->rc_header.h_nodeid);
231 int len = sizeof(struct rcom_config);
232 struct dlm_msg *msg;
233 int num_slots = 0;
234 int error;
235
236 if (!dlm_slots_version(&rc_in->rc_header)) {
237 status = dlm_recover_status(ls);
238 goto do_create;

--- 45 unchanged lines hidden (view full) ---

284}
285
286static void receive_sync_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in)
287{
288 spin_lock(&ls->ls_rcom_spin);
289 if (!test_bit(LSFL_RCOM_WAIT, &ls->ls_flags) ||
290 rc_in->rc_id != ls->ls_rcom_seq) {
291 log_debug(ls, "reject reply %d from %d seq %llx expect %llx",
231 int len = sizeof(struct rcom_config);
232 struct dlm_msg *msg;
233 int num_slots = 0;
234 int error;
235
236 if (!dlm_slots_version(&rc_in->rc_header)) {
237 status = dlm_recover_status(ls);
238 goto do_create;

--- 45 unchanged lines hidden (view full) ---

284}
285
286static void receive_sync_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in)
287{
288 spin_lock(&ls->ls_rcom_spin);
289 if (!test_bit(LSFL_RCOM_WAIT, &ls->ls_flags) ||
290 rc_in->rc_id != ls->ls_rcom_seq) {
291 log_debug(ls, "reject reply %d from %d seq %llx expect %llx",
292 rc_in->rc_type, rc_in->rc_header.h_nodeid,
292 rc_in->rc_type,
293 le32_to_cpu(rc_in->rc_header.h_nodeid),
293 (unsigned long long)rc_in->rc_id,
294 (unsigned long long)ls->ls_rcom_seq);
295 goto out;
296 }
294 (unsigned long long)rc_in->rc_id,
295 (unsigned long long)ls->ls_rcom_seq);
296 goto out;
297 }
297 memcpy(ls->ls_recover_buf, rc_in, rc_in->rc_header.h_length);
298 memcpy(ls->ls_recover_buf, rc_in,
299 le16_to_cpu(rc_in->rc_header.h_length));
298 set_bit(LSFL_RCOM_READY, &ls->ls_flags);
299 clear_bit(LSFL_RCOM_WAIT, &ls->ls_flags);
300 wake_up(&ls->ls_wait_general);
301 out:
302 spin_unlock(&ls->ls_rcom_spin);
303}
304
305int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name, int last_len)

--- 25 unchanged lines hidden (view full) ---

331}
332
333static void receive_rcom_names(struct dlm_ls *ls, struct dlm_rcom *rc_in)
334{
335 struct dlm_rcom *rc;
336 int error, inlen, outlen, nodeid;
337 struct dlm_msg *msg;
338
300 set_bit(LSFL_RCOM_READY, &ls->ls_flags);
301 clear_bit(LSFL_RCOM_WAIT, &ls->ls_flags);
302 wake_up(&ls->ls_wait_general);
303 out:
304 spin_unlock(&ls->ls_rcom_spin);
305}
306
307int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name, int last_len)

--- 25 unchanged lines hidden (view full) ---

333}
334
335static void receive_rcom_names(struct dlm_ls *ls, struct dlm_rcom *rc_in)
336{
337 struct dlm_rcom *rc;
338 int error, inlen, outlen, nodeid;
339 struct dlm_msg *msg;
340
339 nodeid = rc_in->rc_header.h_nodeid;
340 inlen = rc_in->rc_header.h_length - sizeof(struct dlm_rcom);
341 nodeid = le32_to_cpu(rc_in->rc_header.h_nodeid);
342 inlen = le16_to_cpu(rc_in->rc_header.h_length) -
343 sizeof(struct dlm_rcom);
341 outlen = DLM_MAX_APP_BUFSIZE - sizeof(struct dlm_rcom);
342
343 error = create_rcom_stateless(ls, nodeid, DLM_RCOM_NAMES_REPLY, outlen,
344 &rc, &msg);
345 if (error)
346 return;
347 rc->rc_id = rc_in->rc_id;
348 rc->rc_seq_reply = rc_in->rc_seq;

--- 21 unchanged lines hidden (view full) ---

370 out:
371 return error;
372}
373
374static void receive_rcom_lookup(struct dlm_ls *ls, struct dlm_rcom *rc_in)
375{
376 struct dlm_rcom *rc;
377 struct dlm_mhandle *mh;
344 outlen = DLM_MAX_APP_BUFSIZE - sizeof(struct dlm_rcom);
345
346 error = create_rcom_stateless(ls, nodeid, DLM_RCOM_NAMES_REPLY, outlen,
347 &rc, &msg);
348 if (error)
349 return;
350 rc->rc_id = rc_in->rc_id;
351 rc->rc_seq_reply = rc_in->rc_seq;

--- 21 unchanged lines hidden (view full) ---

373 out:
374 return error;
375}
376
377static void receive_rcom_lookup(struct dlm_ls *ls, struct dlm_rcom *rc_in)
378{
379 struct dlm_rcom *rc;
380 struct dlm_mhandle *mh;
378 int error, ret_nodeid, nodeid = rc_in->rc_header.h_nodeid;
379 int len = rc_in->rc_header.h_length - sizeof(struct dlm_rcom);
381 int error, ret_nodeid, nodeid = le32_to_cpu(rc_in->rc_header.h_nodeid);
382 int len = le16_to_cpu(rc_in->rc_header.h_length) -
383 sizeof(struct dlm_rcom);
380
381 /* Old code would send this special id to trigger a debug dump. */
382 if (rc_in->rc_id == 0xFFFFFFFF) {
383 log_error(ls, "receive_rcom_lookup dump from %d", nodeid);
384 dlm_dump_rsb_name(ls, rc_in->rc_buf, len);
385 return;
386 }
387

--- 71 unchanged lines hidden (view full) ---

459 return error;
460}
461
462/* needs at least dlm_rcom + rcom_lock */
463static void receive_rcom_lock(struct dlm_ls *ls, struct dlm_rcom *rc_in)
464{
465 struct dlm_rcom *rc;
466 struct dlm_mhandle *mh;
384
385 /* Old code would send this special id to trigger a debug dump. */
386 if (rc_in->rc_id == 0xFFFFFFFF) {
387 log_error(ls, "receive_rcom_lookup dump from %d", nodeid);
388 dlm_dump_rsb_name(ls, rc_in->rc_buf, len);
389 return;
390 }
391

--- 71 unchanged lines hidden (view full) ---

463 return error;
464}
465
466/* needs at least dlm_rcom + rcom_lock */
467static void receive_rcom_lock(struct dlm_ls *ls, struct dlm_rcom *rc_in)
468{
469 struct dlm_rcom *rc;
470 struct dlm_mhandle *mh;
467 int error, nodeid = rc_in->rc_header.h_nodeid;
471 int error, nodeid = le32_to_cpu(rc_in->rc_header.h_nodeid);
468
469 dlm_recover_master_copy(ls, rc_in);
470
471 error = create_rcom(ls, nodeid, DLM_RCOM_LOCK_REPLY,
472 sizeof(struct rcom_lock), &rc, &mh);
473 if (error)
474 return;
475

--- 19 unchanged lines hidden (view full) ---

495 int mb_len = sizeof(struct dlm_rcom) + sizeof(struct rcom_config);
496
497 mh = dlm_midcomms_get_mhandle(nodeid, mb_len, GFP_NOFS, &mb);
498 if (!mh)
499 return -ENOBUFS;
500
501 rc = (struct dlm_rcom *) mb;
502
472
473 dlm_recover_master_copy(ls, rc_in);
474
475 error = create_rcom(ls, nodeid, DLM_RCOM_LOCK_REPLY,
476 sizeof(struct rcom_lock), &rc, &mh);
477 if (error)
478 return;
479

--- 19 unchanged lines hidden (view full) ---

499 int mb_len = sizeof(struct dlm_rcom) + sizeof(struct rcom_config);
500
501 mh = dlm_midcomms_get_mhandle(nodeid, mb_len, GFP_NOFS, &mb);
502 if (!mh)
503 return -ENOBUFS;
504
505 rc = (struct dlm_rcom *) mb;
506
503 rc->rc_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR);
507 rc->rc_header.h_version = cpu_to_le32(DLM_HEADER_MAJOR | DLM_HEADER_MINOR);
504 rc->rc_header.u.h_lockspace = rc_in->rc_header.u.h_lockspace;
508 rc->rc_header.u.h_lockspace = rc_in->rc_header.u.h_lockspace;
505 rc->rc_header.h_nodeid = dlm_our_nodeid();
506 rc->rc_header.h_length = mb_len;
509 rc->rc_header.h_nodeid = cpu_to_le32(dlm_our_nodeid());
510 rc->rc_header.h_length = cpu_to_le16(mb_len);
507 rc->rc_header.h_cmd = DLM_RCOM;
508
509 rc->rc_type = DLM_RCOM_STATUS_REPLY;
510 rc->rc_id = rc_in->rc_id;
511 rc->rc_seq_reply = rc_in->rc_seq;
512 rc->rc_result = -ESRCH;
513
514 rf = (struct rcom_config *) rc->rc_buf;

--- 111 unchanged lines hidden (view full) ---

626 receive_rcom_names(ls, rc);
627 break;
628
629 case DLM_RCOM_LOOKUP:
630 receive_rcom_lookup(ls, rc);
631 break;
632
633 case DLM_RCOM_LOCK:
511 rc->rc_header.h_cmd = DLM_RCOM;
512
513 rc->rc_type = DLM_RCOM_STATUS_REPLY;
514 rc->rc_id = rc_in->rc_id;
515 rc->rc_seq_reply = rc_in->rc_seq;
516 rc->rc_result = -ESRCH;
517
518 rf = (struct rcom_config *) rc->rc_buf;

--- 111 unchanged lines hidden (view full) ---

630 receive_rcom_names(ls, rc);
631 break;
632
633 case DLM_RCOM_LOOKUP:
634 receive_rcom_lookup(ls, rc);
635 break;
636
637 case DLM_RCOM_LOCK:
634 if (rc->rc_header.h_length < lock_size)
638 if (le16_to_cpu(rc->rc_header.h_length) < lock_size)
635 goto Eshort;
636 receive_rcom_lock(ls, rc);
637 break;
638
639 case DLM_RCOM_STATUS_REPLY:
640 receive_sync_reply(ls, rc);
641 break;
642
643 case DLM_RCOM_NAMES_REPLY:
644 receive_sync_reply(ls, rc);
645 break;
646
647 case DLM_RCOM_LOOKUP_REPLY:
648 receive_rcom_lookup_reply(ls, rc);
649 break;
650
651 case DLM_RCOM_LOCK_REPLY:
639 goto Eshort;
640 receive_rcom_lock(ls, rc);
641 break;
642
643 case DLM_RCOM_STATUS_REPLY:
644 receive_sync_reply(ls, rc);
645 break;
646
647 case DLM_RCOM_NAMES_REPLY:
648 receive_sync_reply(ls, rc);
649 break;
650
651 case DLM_RCOM_LOOKUP_REPLY:
652 receive_rcom_lookup_reply(ls, rc);
653 break;
654
655 case DLM_RCOM_LOCK_REPLY:
652 if (rc->rc_header.h_length < lock_size)
656 if (le16_to_cpu(rc->rc_header.h_length) < lock_size)
653 goto Eshort;
654 dlm_recover_process_copy(ls, rc);
655 break;
656
657 default:
658 log_error(ls, "receive_rcom bad type %d", rc->rc_type);
659 }
660 return;

--- 16 unchanged lines hidden ---
657 goto Eshort;
658 dlm_recover_process_copy(ls, rc);
659 break;
660
661 default:
662 log_error(ls, "receive_rcom bad type %d", rc->rc_type);
663 }
664 return;

--- 16 unchanged lines hidden ---