1e7fd4179SDavid Teigland /****************************************************************************** 2e7fd4179SDavid Teigland ******************************************************************************* 3e7fd4179SDavid Teigland ** 4e7fd4179SDavid Teigland ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 5dbcfc347SDavid Teigland ** Copyright (C) 2005-2008 Red Hat, Inc. All rights reserved. 6e7fd4179SDavid Teigland ** 7e7fd4179SDavid Teigland ** This copyrighted material is made available to anyone wishing to use, 8e7fd4179SDavid Teigland ** modify, copy, or redistribute it subject to the terms and conditions 9e7fd4179SDavid Teigland ** of the GNU General Public License v.2. 10e7fd4179SDavid Teigland ** 11e7fd4179SDavid Teigland ******************************************************************************* 12e7fd4179SDavid Teigland ******************************************************************************/ 13e7fd4179SDavid Teigland 14e7fd4179SDavid Teigland #include "dlm_internal.h" 15e7fd4179SDavid Teigland #include "lockspace.h" 16e7fd4179SDavid Teigland #include "member.h" 17e7fd4179SDavid Teigland #include "lowcomms.h" 18e7fd4179SDavid Teigland #include "midcomms.h" 19e7fd4179SDavid Teigland #include "rcom.h" 20e7fd4179SDavid Teigland #include "recover.h" 21e7fd4179SDavid Teigland #include "dir.h" 22e7fd4179SDavid Teigland #include "config.h" 23e7fd4179SDavid Teigland #include "memory.h" 24e7fd4179SDavid Teigland #include "lock.h" 25e7fd4179SDavid Teigland #include "util.h" 26e7fd4179SDavid Teigland 27e7fd4179SDavid Teigland 28e7fd4179SDavid Teigland static int rcom_response(struct dlm_ls *ls) 29e7fd4179SDavid Teigland { 30e7fd4179SDavid Teigland return test_bit(LSFL_RCOM_READY, &ls->ls_flags); 31e7fd4179SDavid Teigland } 32e7fd4179SDavid Teigland 33e7fd4179SDavid Teigland static int create_rcom(struct dlm_ls *ls, int to_nodeid, int type, int len, 34e7fd4179SDavid Teigland struct dlm_rcom **rc_ret, struct dlm_mhandle **mh_ret) 35e7fd4179SDavid Teigland { 36e7fd4179SDavid Teigland struct dlm_rcom *rc; 37e7fd4179SDavid Teigland struct dlm_mhandle *mh; 38e7fd4179SDavid Teigland char *mb; 39e7fd4179SDavid Teigland int mb_len = sizeof(struct dlm_rcom) + len; 40e7fd4179SDavid Teigland 4144f487a5SPatrick Caulfield mh = dlm_lowcomms_get_buffer(to_nodeid, mb_len, ls->ls_allocation, &mb); 42e7fd4179SDavid Teigland if (!mh) { 43e7fd4179SDavid Teigland log_print("create_rcom to %d type %d len %d ENOBUFS", 44e7fd4179SDavid Teigland to_nodeid, type, len); 45e7fd4179SDavid Teigland return -ENOBUFS; 46e7fd4179SDavid Teigland } 47e7fd4179SDavid Teigland memset(mb, 0, mb_len); 48e7fd4179SDavid Teigland 49e7fd4179SDavid Teigland rc = (struct dlm_rcom *) mb; 50e7fd4179SDavid Teigland 51e7fd4179SDavid Teigland rc->rc_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR); 52e7fd4179SDavid Teigland rc->rc_header.h_lockspace = ls->ls_global_id; 53e7fd4179SDavid Teigland rc->rc_header.h_nodeid = dlm_our_nodeid(); 54e7fd4179SDavid Teigland rc->rc_header.h_length = mb_len; 55e7fd4179SDavid Teigland rc->rc_header.h_cmd = DLM_RCOM; 56e7fd4179SDavid Teigland 57e7fd4179SDavid Teigland rc->rc_type = type; 58e7fd4179SDavid Teigland 5938aa8b0cSDavid Teigland spin_lock(&ls->ls_recover_lock); 6038aa8b0cSDavid Teigland rc->rc_seq = ls->ls_recover_seq; 6138aa8b0cSDavid Teigland spin_unlock(&ls->ls_recover_lock); 6238aa8b0cSDavid Teigland 63e7fd4179SDavid Teigland *mh_ret = mh; 64e7fd4179SDavid Teigland *rc_ret = rc; 65e7fd4179SDavid Teigland return 0; 66e7fd4179SDavid Teigland } 67e7fd4179SDavid Teigland 68e7fd4179SDavid Teigland static void send_rcom(struct dlm_ls *ls, struct dlm_mhandle *mh, 69e7fd4179SDavid Teigland struct dlm_rcom *rc) 70e7fd4179SDavid Teigland { 71e7fd4179SDavid Teigland dlm_rcom_out(rc); 72e7fd4179SDavid Teigland dlm_lowcomms_commit_buffer(mh); 73e7fd4179SDavid Teigland } 74e7fd4179SDavid Teigland 75e7fd4179SDavid Teigland /* When replying to a status request, a node also sends back its 76e7fd4179SDavid Teigland configuration values. The requesting node then checks that the remote 77e7fd4179SDavid Teigland node is configured the same way as itself. */ 78e7fd4179SDavid Teigland 79e7fd4179SDavid Teigland static void make_config(struct dlm_ls *ls, struct rcom_config *rf) 80e7fd4179SDavid Teigland { 8193ff2971SAl Viro rf->rf_lvblen = cpu_to_le32(ls->ls_lvblen); 8293ff2971SAl Viro rf->rf_lsflags = cpu_to_le32(ls->ls_exflags); 83e7fd4179SDavid Teigland } 84e7fd4179SDavid Teigland 859e971b71SDavid Teigland static int check_config(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid) 86e7fd4179SDavid Teigland { 879e971b71SDavid Teigland struct rcom_config *rf = (struct rcom_config *) rc->rc_buf; 8802ed16b6SAl Viro size_t conf_size = sizeof(struct dlm_rcom) + sizeof(struct rcom_config); 899e971b71SDavid Teigland 909e971b71SDavid Teigland if ((rc->rc_header.h_version & 0xFFFF0000) != DLM_HEADER_MAJOR) { 919e971b71SDavid Teigland log_error(ls, "version mismatch: %x nodeid %d: %x", 929e971b71SDavid Teigland DLM_HEADER_MAJOR | DLM_HEADER_MINOR, nodeid, 939e971b71SDavid Teigland rc->rc_header.h_version); 948b0e7b2cSDavid Teigland return -EPROTO; 959e971b71SDavid Teigland } 969e971b71SDavid Teigland 9702ed16b6SAl Viro if (rc->rc_header.h_length < conf_size) { 9802ed16b6SAl Viro log_error(ls, "config too short: %d nodeid %d", 9902ed16b6SAl Viro rc->rc_header.h_length, nodeid); 10002ed16b6SAl Viro return -EPROTO; 10102ed16b6SAl Viro } 10202ed16b6SAl Viro 10393ff2971SAl Viro if (le32_to_cpu(rf->rf_lvblen) != ls->ls_lvblen || 10493ff2971SAl Viro le32_to_cpu(rf->rf_lsflags) != ls->ls_exflags) { 105e7fd4179SDavid Teigland log_error(ls, "config mismatch: %d,%x nodeid %d: %d,%x", 10693ff2971SAl Viro ls->ls_lvblen, ls->ls_exflags, nodeid, 10793ff2971SAl Viro le32_to_cpu(rf->rf_lvblen), 10893ff2971SAl Viro le32_to_cpu(rf->rf_lsflags)); 1098b0e7b2cSDavid Teigland return -EPROTO; 110e7fd4179SDavid Teigland } 111e7fd4179SDavid Teigland return 0; 112e7fd4179SDavid Teigland } 113e7fd4179SDavid Teigland 11498f176fbSDavid Teigland static void allow_sync_reply(struct dlm_ls *ls, uint64_t *new_seq) 11598f176fbSDavid Teigland { 11698f176fbSDavid Teigland spin_lock(&ls->ls_rcom_spin); 11798f176fbSDavid Teigland *new_seq = ++ls->ls_rcom_seq; 11898f176fbSDavid Teigland set_bit(LSFL_RCOM_WAIT, &ls->ls_flags); 11998f176fbSDavid Teigland spin_unlock(&ls->ls_rcom_spin); 12098f176fbSDavid Teigland } 12198f176fbSDavid Teigland 12298f176fbSDavid Teigland static void disallow_sync_reply(struct dlm_ls *ls) 12398f176fbSDavid Teigland { 12498f176fbSDavid Teigland spin_lock(&ls->ls_rcom_spin); 12598f176fbSDavid Teigland clear_bit(LSFL_RCOM_WAIT, &ls->ls_flags); 12698f176fbSDavid Teigland clear_bit(LSFL_RCOM_READY, &ls->ls_flags); 12798f176fbSDavid Teigland spin_unlock(&ls->ls_rcom_spin); 12898f176fbSDavid Teigland } 12998f176fbSDavid Teigland 130e7fd4179SDavid Teigland int dlm_rcom_status(struct dlm_ls *ls, int nodeid) 131e7fd4179SDavid Teigland { 132e7fd4179SDavid Teigland struct dlm_rcom *rc; 133e7fd4179SDavid Teigland struct dlm_mhandle *mh; 134e7fd4179SDavid Teigland int error = 0; 135e7fd4179SDavid Teigland 136faa0f267SDavid Teigland ls->ls_recover_nodeid = nodeid; 137e7fd4179SDavid Teigland 138e7fd4179SDavid Teigland if (nodeid == dlm_our_nodeid()) { 1394007685cSAl Viro rc = ls->ls_recover_buf; 140e7fd4179SDavid Teigland rc->rc_result = dlm_recover_status(ls); 141e7fd4179SDavid Teigland goto out; 142e7fd4179SDavid Teigland } 143e7fd4179SDavid Teigland 144e7fd4179SDavid Teigland error = create_rcom(ls, nodeid, DLM_RCOM_STATUS, 0, &rc, &mh); 145e7fd4179SDavid Teigland if (error) 146e7fd4179SDavid Teigland goto out; 14798f176fbSDavid Teigland 14898f176fbSDavid Teigland allow_sync_reply(ls, &rc->rc_id); 14968c817a1SDavid Teigland memset(ls->ls_recover_buf, 0, dlm_config.ci_buffer_size); 150e7fd4179SDavid Teigland 151e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 152e7fd4179SDavid Teigland 153e7fd4179SDavid Teigland error = dlm_wait_function(ls, &rcom_response); 15498f176fbSDavid Teigland disallow_sync_reply(ls); 155e7fd4179SDavid Teigland if (error) 156e7fd4179SDavid Teigland goto out; 157e7fd4179SDavid Teigland 1584007685cSAl Viro rc = ls->ls_recover_buf; 159e7fd4179SDavid Teigland 160e7fd4179SDavid Teigland if (rc->rc_result == -ESRCH) { 161e7fd4179SDavid Teigland /* we pretend the remote lockspace exists with 0 status */ 162e7fd4179SDavid Teigland log_debug(ls, "remote node %d not ready", nodeid); 163e7fd4179SDavid Teigland rc->rc_result = 0; 164e7fd4179SDavid Teigland } else 1659e971b71SDavid Teigland error = check_config(ls, rc, nodeid); 166e7fd4179SDavid Teigland /* the caller looks at rc_result for the remote recovery status */ 167e7fd4179SDavid Teigland out: 168e7fd4179SDavid Teigland return error; 169e7fd4179SDavid Teigland } 170e7fd4179SDavid Teigland 171e7fd4179SDavid Teigland static void receive_rcom_status(struct dlm_ls *ls, struct dlm_rcom *rc_in) 172e7fd4179SDavid Teigland { 173e7fd4179SDavid Teigland struct dlm_rcom *rc; 174e7fd4179SDavid Teigland struct dlm_mhandle *mh; 175e7fd4179SDavid Teigland int error, nodeid = rc_in->rc_header.h_nodeid; 176e7fd4179SDavid Teigland 177e7fd4179SDavid Teigland error = create_rcom(ls, nodeid, DLM_RCOM_STATUS_REPLY, 178e7fd4179SDavid Teigland sizeof(struct rcom_config), &rc, &mh); 179e7fd4179SDavid Teigland if (error) 180e7fd4179SDavid Teigland return; 1814a99c3d9SDavid Teigland rc->rc_id = rc_in->rc_id; 18238aa8b0cSDavid Teigland rc->rc_seq_reply = rc_in->rc_seq; 183e7fd4179SDavid Teigland rc->rc_result = dlm_recover_status(ls); 184e7fd4179SDavid Teigland make_config(ls, (struct rcom_config *) rc->rc_buf); 185e7fd4179SDavid Teigland 186e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 187e7fd4179SDavid Teigland } 188e7fd4179SDavid Teigland 1894a99c3d9SDavid Teigland static void receive_sync_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) 190e7fd4179SDavid Teigland { 19198f176fbSDavid Teigland spin_lock(&ls->ls_rcom_spin); 19298f176fbSDavid Teigland if (!test_bit(LSFL_RCOM_WAIT, &ls->ls_flags) || 19398f176fbSDavid Teigland rc_in->rc_id != ls->ls_rcom_seq) { 19498f176fbSDavid Teigland log_debug(ls, "reject reply %d from %d seq %llx expect %llx", 19598f176fbSDavid Teigland rc_in->rc_type, rc_in->rc_header.h_nodeid, 19657adf7eeSRyusuke Konishi (unsigned long long)rc_in->rc_id, 19757adf7eeSRyusuke Konishi (unsigned long long)ls->ls_rcom_seq); 19898f176fbSDavid Teigland goto out; 1994a99c3d9SDavid Teigland } 200e7fd4179SDavid Teigland memcpy(ls->ls_recover_buf, rc_in, rc_in->rc_header.h_length); 201e7fd4179SDavid Teigland set_bit(LSFL_RCOM_READY, &ls->ls_flags); 20298f176fbSDavid Teigland clear_bit(LSFL_RCOM_WAIT, &ls->ls_flags); 203e7fd4179SDavid Teigland wake_up(&ls->ls_wait_general); 20498f176fbSDavid Teigland out: 20598f176fbSDavid Teigland spin_unlock(&ls->ls_rcom_spin); 206e7fd4179SDavid Teigland } 207e7fd4179SDavid Teigland 208e7fd4179SDavid Teigland int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name, int last_len) 209e7fd4179SDavid Teigland { 210e7fd4179SDavid Teigland struct dlm_rcom *rc; 211e7fd4179SDavid Teigland struct dlm_mhandle *mh; 2124007685cSAl Viro int error = 0; 2134007685cSAl Viro int max_size = dlm_config.ci_buffer_size - sizeof(struct dlm_rcom); 214e7fd4179SDavid Teigland 215faa0f267SDavid Teigland ls->ls_recover_nodeid = nodeid; 216e7fd4179SDavid Teigland 217e7fd4179SDavid Teigland if (nodeid == dlm_our_nodeid()) { 218e7fd4179SDavid Teigland dlm_copy_master_names(ls, last_name, last_len, 2194007685cSAl Viro ls->ls_recover_buf->rc_buf, 2204007685cSAl Viro max_size, nodeid); 221e7fd4179SDavid Teigland goto out; 222e7fd4179SDavid Teigland } 223e7fd4179SDavid Teigland 224e7fd4179SDavid Teigland error = create_rcom(ls, nodeid, DLM_RCOM_NAMES, last_len, &rc, &mh); 225e7fd4179SDavid Teigland if (error) 226e7fd4179SDavid Teigland goto out; 227e7fd4179SDavid Teigland memcpy(rc->rc_buf, last_name, last_len); 22898f176fbSDavid Teigland 22998f176fbSDavid Teigland allow_sync_reply(ls, &rc->rc_id); 23068c817a1SDavid Teigland memset(ls->ls_recover_buf, 0, dlm_config.ci_buffer_size); 231e7fd4179SDavid Teigland 232e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 233e7fd4179SDavid Teigland 234e7fd4179SDavid Teigland error = dlm_wait_function(ls, &rcom_response); 23598f176fbSDavid Teigland disallow_sync_reply(ls); 236e7fd4179SDavid Teigland out: 237e7fd4179SDavid Teigland return error; 238e7fd4179SDavid Teigland } 239e7fd4179SDavid Teigland 240e7fd4179SDavid Teigland static void receive_rcom_names(struct dlm_ls *ls, struct dlm_rcom *rc_in) 241e7fd4179SDavid Teigland { 242e7fd4179SDavid Teigland struct dlm_rcom *rc; 243e7fd4179SDavid Teigland struct dlm_mhandle *mh; 24438aa8b0cSDavid Teigland int error, inlen, outlen, nodeid; 245e7fd4179SDavid Teigland 246e7fd4179SDavid Teigland nodeid = rc_in->rc_header.h_nodeid; 247e7fd4179SDavid Teigland inlen = rc_in->rc_header.h_length - sizeof(struct dlm_rcom); 24868c817a1SDavid Teigland outlen = dlm_config.ci_buffer_size - sizeof(struct dlm_rcom); 249e7fd4179SDavid Teigland 250e7fd4179SDavid Teigland error = create_rcom(ls, nodeid, DLM_RCOM_NAMES_REPLY, outlen, &rc, &mh); 251e7fd4179SDavid Teigland if (error) 252e7fd4179SDavid Teigland return; 2534a99c3d9SDavid Teigland rc->rc_id = rc_in->rc_id; 25438aa8b0cSDavid Teigland rc->rc_seq_reply = rc_in->rc_seq; 255e7fd4179SDavid Teigland 256e7fd4179SDavid Teigland dlm_copy_master_names(ls, rc_in->rc_buf, inlen, rc->rc_buf, outlen, 257e7fd4179SDavid Teigland nodeid); 258e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 259e7fd4179SDavid Teigland } 260e7fd4179SDavid Teigland 261e7fd4179SDavid Teigland int dlm_send_rcom_lookup(struct dlm_rsb *r, int dir_nodeid) 262e7fd4179SDavid Teigland { 263e7fd4179SDavid Teigland struct dlm_rcom *rc; 264e7fd4179SDavid Teigland struct dlm_mhandle *mh; 265e7fd4179SDavid Teigland struct dlm_ls *ls = r->res_ls; 266e7fd4179SDavid Teigland int error; 267e7fd4179SDavid Teigland 268e7fd4179SDavid Teigland error = create_rcom(ls, dir_nodeid, DLM_RCOM_LOOKUP, r->res_length, 269e7fd4179SDavid Teigland &rc, &mh); 270e7fd4179SDavid Teigland if (error) 271e7fd4179SDavid Teigland goto out; 272e7fd4179SDavid Teigland memcpy(rc->rc_buf, r->res_name, r->res_length); 273e7fd4179SDavid Teigland rc->rc_id = (unsigned long) r; 274e7fd4179SDavid Teigland 275e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 276e7fd4179SDavid Teigland out: 277e7fd4179SDavid Teigland return error; 278e7fd4179SDavid Teigland } 279e7fd4179SDavid Teigland 280e7fd4179SDavid Teigland static void receive_rcom_lookup(struct dlm_ls *ls, struct dlm_rcom *rc_in) 281e7fd4179SDavid Teigland { 282e7fd4179SDavid Teigland struct dlm_rcom *rc; 283e7fd4179SDavid Teigland struct dlm_mhandle *mh; 284e7fd4179SDavid Teigland int error, ret_nodeid, nodeid = rc_in->rc_header.h_nodeid; 285e7fd4179SDavid Teigland int len = rc_in->rc_header.h_length - sizeof(struct dlm_rcom); 286e7fd4179SDavid Teigland 287e7fd4179SDavid Teigland error = create_rcom(ls, nodeid, DLM_RCOM_LOOKUP_REPLY, 0, &rc, &mh); 288e7fd4179SDavid Teigland if (error) 289e7fd4179SDavid Teigland return; 290e7fd4179SDavid Teigland 291e7fd4179SDavid Teigland error = dlm_dir_lookup(ls, nodeid, rc_in->rc_buf, len, &ret_nodeid); 292e7fd4179SDavid Teigland if (error) 293e7fd4179SDavid Teigland ret_nodeid = error; 294e7fd4179SDavid Teigland rc->rc_result = ret_nodeid; 295e7fd4179SDavid Teigland rc->rc_id = rc_in->rc_id; 29638aa8b0cSDavid Teigland rc->rc_seq_reply = rc_in->rc_seq; 297e7fd4179SDavid Teigland 298e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 299e7fd4179SDavid Teigland } 300e7fd4179SDavid Teigland 301e7fd4179SDavid Teigland static void receive_rcom_lookup_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) 302e7fd4179SDavid Teigland { 303e7fd4179SDavid Teigland dlm_recover_master_reply(ls, rc_in); 304e7fd4179SDavid Teigland } 305e7fd4179SDavid Teigland 306e7fd4179SDavid Teigland static void pack_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb, 307e7fd4179SDavid Teigland struct rcom_lock *rl) 308e7fd4179SDavid Teigland { 309e7fd4179SDavid Teigland memset(rl, 0, sizeof(*rl)); 310e7fd4179SDavid Teigland 311163a1859SAl Viro rl->rl_ownpid = cpu_to_le32(lkb->lkb_ownpid); 312163a1859SAl Viro rl->rl_lkid = cpu_to_le32(lkb->lkb_id); 313163a1859SAl Viro rl->rl_exflags = cpu_to_le32(lkb->lkb_exflags); 314163a1859SAl Viro rl->rl_flags = cpu_to_le32(lkb->lkb_flags); 315163a1859SAl Viro rl->rl_lvbseq = cpu_to_le32(lkb->lkb_lvbseq); 316e7fd4179SDavid Teigland rl->rl_rqmode = lkb->lkb_rqmode; 317e7fd4179SDavid Teigland rl->rl_grmode = lkb->lkb_grmode; 318e7fd4179SDavid Teigland rl->rl_status = lkb->lkb_status; 319163a1859SAl Viro rl->rl_wait_type = cpu_to_le16(lkb->lkb_wait_type); 320e7fd4179SDavid Teigland 321e7fd4179SDavid Teigland if (lkb->lkb_bastaddr) 322e7fd4179SDavid Teigland rl->rl_asts |= AST_BAST; 323e7fd4179SDavid Teigland if (lkb->lkb_astaddr) 324e7fd4179SDavid Teigland rl->rl_asts |= AST_COMP; 325e7fd4179SDavid Teigland 326163a1859SAl Viro rl->rl_namelen = cpu_to_le16(r->res_length); 327e7fd4179SDavid Teigland memcpy(rl->rl_name, r->res_name, r->res_length); 328e7fd4179SDavid Teigland 329e7fd4179SDavid Teigland /* FIXME: might we have an lvb without DLM_LKF_VALBLK set ? 330e7fd4179SDavid Teigland If so, receive_rcom_lock_args() won't take this copy. */ 331e7fd4179SDavid Teigland 332e7fd4179SDavid Teigland if (lkb->lkb_lvbptr) 333e7fd4179SDavid Teigland memcpy(rl->rl_lvb, lkb->lkb_lvbptr, r->res_ls->ls_lvblen); 334e7fd4179SDavid Teigland } 335e7fd4179SDavid Teigland 336e7fd4179SDavid Teigland int dlm_send_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) 337e7fd4179SDavid Teigland { 338e7fd4179SDavid Teigland struct dlm_ls *ls = r->res_ls; 339e7fd4179SDavid Teigland struct dlm_rcom *rc; 340e7fd4179SDavid Teigland struct dlm_mhandle *mh; 341e7fd4179SDavid Teigland struct rcom_lock *rl; 342e7fd4179SDavid Teigland int error, len = sizeof(struct rcom_lock); 343e7fd4179SDavid Teigland 344e7fd4179SDavid Teigland if (lkb->lkb_lvbptr) 345e7fd4179SDavid Teigland len += ls->ls_lvblen; 346e7fd4179SDavid Teigland 347e7fd4179SDavid Teigland error = create_rcom(ls, r->res_nodeid, DLM_RCOM_LOCK, len, &rc, &mh); 348e7fd4179SDavid Teigland if (error) 349e7fd4179SDavid Teigland goto out; 350e7fd4179SDavid Teigland 351e7fd4179SDavid Teigland rl = (struct rcom_lock *) rc->rc_buf; 352e7fd4179SDavid Teigland pack_rcom_lock(r, lkb, rl); 353e7fd4179SDavid Teigland rc->rc_id = (unsigned long) r; 354e7fd4179SDavid Teigland 355e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 356e7fd4179SDavid Teigland out: 357e7fd4179SDavid Teigland return error; 358e7fd4179SDavid Teigland } 359e7fd4179SDavid Teigland 360*ae773d0bSAl Viro /* needs at least dlm_rcom + rcom_lock */ 361e7fd4179SDavid Teigland static void receive_rcom_lock(struct dlm_ls *ls, struct dlm_rcom *rc_in) 362e7fd4179SDavid Teigland { 363e7fd4179SDavid Teigland struct dlm_rcom *rc; 364e7fd4179SDavid Teigland struct dlm_mhandle *mh; 365e7fd4179SDavid Teigland int error, nodeid = rc_in->rc_header.h_nodeid; 366e7fd4179SDavid Teigland 367e7fd4179SDavid Teigland dlm_recover_master_copy(ls, rc_in); 368e7fd4179SDavid Teigland 369e7fd4179SDavid Teigland error = create_rcom(ls, nodeid, DLM_RCOM_LOCK_REPLY, 370e7fd4179SDavid Teigland sizeof(struct rcom_lock), &rc, &mh); 371e7fd4179SDavid Teigland if (error) 372e7fd4179SDavid Teigland return; 373e7fd4179SDavid Teigland 374e7fd4179SDavid Teigland /* We send back the same rcom_lock struct we received, but 375e7fd4179SDavid Teigland dlm_recover_master_copy() has filled in rl_remid and rl_result */ 376e7fd4179SDavid Teigland 377e7fd4179SDavid Teigland memcpy(rc->rc_buf, rc_in->rc_buf, sizeof(struct rcom_lock)); 378e7fd4179SDavid Teigland rc->rc_id = rc_in->rc_id; 37938aa8b0cSDavid Teigland rc->rc_seq_reply = rc_in->rc_seq; 380e7fd4179SDavid Teigland 381e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 382e7fd4179SDavid Teigland } 383e7fd4179SDavid Teigland 384c36258b5SDavid Teigland /* If the lockspace doesn't exist then still send a status message 385c36258b5SDavid Teigland back; it's possible that it just doesn't have its global_id yet. */ 386c36258b5SDavid Teigland 387c36258b5SDavid Teigland int dlm_send_ls_not_ready(int nodeid, struct dlm_rcom *rc_in) 388e7fd4179SDavid Teigland { 389e7fd4179SDavid Teigland struct dlm_rcom *rc; 3901babdb45SDavid Teigland struct rcom_config *rf; 391e7fd4179SDavid Teigland struct dlm_mhandle *mh; 392e7fd4179SDavid Teigland char *mb; 3931babdb45SDavid Teigland int mb_len = sizeof(struct dlm_rcom) + sizeof(struct rcom_config); 394e7fd4179SDavid Teigland 39541684f95SDavid Teigland mh = dlm_lowcomms_get_buffer(nodeid, mb_len, GFP_NOFS, &mb); 396e7fd4179SDavid Teigland if (!mh) 397e7fd4179SDavid Teigland return -ENOBUFS; 398e7fd4179SDavid Teigland memset(mb, 0, mb_len); 399e7fd4179SDavid Teigland 400e7fd4179SDavid Teigland rc = (struct dlm_rcom *) mb; 401e7fd4179SDavid Teigland 402e7fd4179SDavid Teigland rc->rc_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR); 403e7fd4179SDavid Teigland rc->rc_header.h_lockspace = rc_in->rc_header.h_lockspace; 404e7fd4179SDavid Teigland rc->rc_header.h_nodeid = dlm_our_nodeid(); 405e7fd4179SDavid Teigland rc->rc_header.h_length = mb_len; 406e7fd4179SDavid Teigland rc->rc_header.h_cmd = DLM_RCOM; 407e7fd4179SDavid Teigland 408e7fd4179SDavid Teigland rc->rc_type = DLM_RCOM_STATUS_REPLY; 409f5888750SDavid Teigland rc->rc_id = rc_in->rc_id; 41038aa8b0cSDavid Teigland rc->rc_seq_reply = rc_in->rc_seq; 411e7fd4179SDavid Teigland rc->rc_result = -ESRCH; 412e7fd4179SDavid Teigland 4131babdb45SDavid Teigland rf = (struct rcom_config *) rc->rc_buf; 41493ff2971SAl Viro rf->rf_lvblen = cpu_to_le32(~0U); 4151babdb45SDavid Teigland 416e7fd4179SDavid Teigland dlm_rcom_out(rc); 417e7fd4179SDavid Teigland dlm_lowcomms_commit_buffer(mh); 418e7fd4179SDavid Teigland 419e7fd4179SDavid Teigland return 0; 420e7fd4179SDavid Teigland } 421e7fd4179SDavid Teigland 42238aa8b0cSDavid Teigland static int is_old_reply(struct dlm_ls *ls, struct dlm_rcom *rc) 42338aa8b0cSDavid Teigland { 42438aa8b0cSDavid Teigland uint64_t seq; 42538aa8b0cSDavid Teigland int rv = 0; 42638aa8b0cSDavid Teigland 42738aa8b0cSDavid Teigland switch (rc->rc_type) { 42838aa8b0cSDavid Teigland case DLM_RCOM_STATUS_REPLY: 42938aa8b0cSDavid Teigland case DLM_RCOM_NAMES_REPLY: 43038aa8b0cSDavid Teigland case DLM_RCOM_LOOKUP_REPLY: 43138aa8b0cSDavid Teigland case DLM_RCOM_LOCK_REPLY: 43238aa8b0cSDavid Teigland spin_lock(&ls->ls_recover_lock); 43338aa8b0cSDavid Teigland seq = ls->ls_recover_seq; 43438aa8b0cSDavid Teigland spin_unlock(&ls->ls_recover_lock); 43538aa8b0cSDavid Teigland if (rc->rc_seq_reply != seq) { 4368ec68867SDavid Teigland log_debug(ls, "ignoring old reply %x from %d " 43738aa8b0cSDavid Teigland "seq_reply %llx expect %llx", 43838aa8b0cSDavid Teigland rc->rc_type, rc->rc_header.h_nodeid, 43938aa8b0cSDavid Teigland (unsigned long long)rc->rc_seq_reply, 44038aa8b0cSDavid Teigland (unsigned long long)seq); 44138aa8b0cSDavid Teigland rv = 1; 44238aa8b0cSDavid Teigland } 44338aa8b0cSDavid Teigland } 44438aa8b0cSDavid Teigland return rv; 44538aa8b0cSDavid Teigland } 44638aa8b0cSDavid Teigland 447c36258b5SDavid Teigland /* Called by dlm_recv; corresponds to dlm_receive_message() but special 448e7fd4179SDavid Teigland recovery-only comms are sent through here. */ 449e7fd4179SDavid Teigland 450c36258b5SDavid Teigland void dlm_receive_rcom(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid) 451e7fd4179SDavid Teigland { 452*ae773d0bSAl Viro int lock_size = sizeof(struct dlm_rcom) + sizeof(struct rcom_lock); 453*ae773d0bSAl Viro 454e7fd4179SDavid Teigland if (dlm_recovery_stopped(ls) && (rc->rc_type != DLM_RCOM_STATUS)) { 4558ec68867SDavid Teigland log_debug(ls, "ignoring recovery message %x from %d", 456e7fd4179SDavid Teigland rc->rc_type, nodeid); 457e7fd4179SDavid Teigland goto out; 458e7fd4179SDavid Teigland } 459e7fd4179SDavid Teigland 46038aa8b0cSDavid Teigland if (is_old_reply(ls, rc)) 46138aa8b0cSDavid Teigland goto out; 46238aa8b0cSDavid Teigland 463e7fd4179SDavid Teigland switch (rc->rc_type) { 464e7fd4179SDavid Teigland case DLM_RCOM_STATUS: 465e7fd4179SDavid Teigland receive_rcom_status(ls, rc); 466e7fd4179SDavid Teigland break; 467e7fd4179SDavid Teigland 468e7fd4179SDavid Teigland case DLM_RCOM_NAMES: 469e7fd4179SDavid Teigland receive_rcom_names(ls, rc); 470e7fd4179SDavid Teigland break; 471e7fd4179SDavid Teigland 472e7fd4179SDavid Teigland case DLM_RCOM_LOOKUP: 473e7fd4179SDavid Teigland receive_rcom_lookup(ls, rc); 474e7fd4179SDavid Teigland break; 475e7fd4179SDavid Teigland 476e7fd4179SDavid Teigland case DLM_RCOM_LOCK: 477*ae773d0bSAl Viro if (rc->rc_header.h_length < lock_size) 478*ae773d0bSAl Viro goto Eshort; 479e7fd4179SDavid Teigland receive_rcom_lock(ls, rc); 480e7fd4179SDavid Teigland break; 481e7fd4179SDavid Teigland 482e7fd4179SDavid Teigland case DLM_RCOM_STATUS_REPLY: 483dbcfc347SDavid Teigland receive_sync_reply(ls, rc); 484e7fd4179SDavid Teigland break; 485e7fd4179SDavid Teigland 486e7fd4179SDavid Teigland case DLM_RCOM_NAMES_REPLY: 487dbcfc347SDavid Teigland receive_sync_reply(ls, rc); 488e7fd4179SDavid Teigland break; 489e7fd4179SDavid Teigland 490e7fd4179SDavid Teigland case DLM_RCOM_LOOKUP_REPLY: 491e7fd4179SDavid Teigland receive_rcom_lookup_reply(ls, rc); 492e7fd4179SDavid Teigland break; 493e7fd4179SDavid Teigland 494e7fd4179SDavid Teigland case DLM_RCOM_LOCK_REPLY: 495*ae773d0bSAl Viro if (rc->rc_header.h_length < lock_size) 496*ae773d0bSAl Viro goto Eshort; 497dbcfc347SDavid Teigland dlm_recover_process_copy(ls, rc); 498e7fd4179SDavid Teigland break; 499e7fd4179SDavid Teigland 500e7fd4179SDavid Teigland default: 501dbcfc347SDavid Teigland log_error(ls, "receive_rcom bad type %d", rc->rc_type); 502e7fd4179SDavid Teigland } 503e7fd4179SDavid Teigland out: 504c36258b5SDavid Teigland return; 505*ae773d0bSAl Viro Eshort: 506*ae773d0bSAl Viro log_error(ls, "recovery message %x from %d is too short", 507*ae773d0bSAl Viro rc->rc_type, nodeid); 508e7fd4179SDavid Teigland } 509e7fd4179SDavid Teigland 510