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" 26757a4271SDavid Teigland #include "member.h" 27e7fd4179SDavid Teigland 28e7fd4179SDavid Teigland 29e7fd4179SDavid Teigland static int rcom_response(struct dlm_ls *ls) 30e7fd4179SDavid Teigland { 31e7fd4179SDavid Teigland return test_bit(LSFL_RCOM_READY, &ls->ls_flags); 32e7fd4179SDavid Teigland } 33e7fd4179SDavid Teigland 34e7fd4179SDavid Teigland static int create_rcom(struct dlm_ls *ls, int to_nodeid, int type, int len, 35e7fd4179SDavid Teigland struct dlm_rcom **rc_ret, struct dlm_mhandle **mh_ret) 36e7fd4179SDavid Teigland { 37e7fd4179SDavid Teigland struct dlm_rcom *rc; 38e7fd4179SDavid Teigland struct dlm_mhandle *mh; 39e7fd4179SDavid Teigland char *mb; 40e7fd4179SDavid Teigland int mb_len = sizeof(struct dlm_rcom) + len; 41e7fd4179SDavid Teigland 42573c24c4SDavid Teigland mh = dlm_lowcomms_get_buffer(to_nodeid, mb_len, GFP_NOFS, &mb); 43e7fd4179SDavid Teigland if (!mh) { 44e7fd4179SDavid Teigland log_print("create_rcom to %d type %d len %d ENOBUFS", 45e7fd4179SDavid Teigland to_nodeid, type, len); 46e7fd4179SDavid Teigland return -ENOBUFS; 47e7fd4179SDavid Teigland } 48e7fd4179SDavid Teigland memset(mb, 0, mb_len); 49e7fd4179SDavid Teigland 50e7fd4179SDavid Teigland rc = (struct dlm_rcom *) mb; 51e7fd4179SDavid Teigland 52e7fd4179SDavid Teigland rc->rc_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR); 53e7fd4179SDavid Teigland rc->rc_header.h_lockspace = ls->ls_global_id; 54e7fd4179SDavid Teigland rc->rc_header.h_nodeid = dlm_our_nodeid(); 55e7fd4179SDavid Teigland rc->rc_header.h_length = mb_len; 56e7fd4179SDavid Teigland rc->rc_header.h_cmd = DLM_RCOM; 57e7fd4179SDavid Teigland 58e7fd4179SDavid Teigland rc->rc_type = type; 59e7fd4179SDavid Teigland 6038aa8b0cSDavid Teigland spin_lock(&ls->ls_recover_lock); 6138aa8b0cSDavid Teigland rc->rc_seq = ls->ls_recover_seq; 6238aa8b0cSDavid Teigland spin_unlock(&ls->ls_recover_lock); 6338aa8b0cSDavid Teigland 64e7fd4179SDavid Teigland *mh_ret = mh; 65e7fd4179SDavid Teigland *rc_ret = rc; 66e7fd4179SDavid Teigland return 0; 67e7fd4179SDavid Teigland } 68e7fd4179SDavid Teigland 69e7fd4179SDavid Teigland static void send_rcom(struct dlm_ls *ls, struct dlm_mhandle *mh, 70e7fd4179SDavid Teigland struct dlm_rcom *rc) 71e7fd4179SDavid Teigland { 72e7fd4179SDavid Teigland dlm_rcom_out(rc); 73e7fd4179SDavid Teigland dlm_lowcomms_commit_buffer(mh); 74e7fd4179SDavid Teigland } 75e7fd4179SDavid Teigland 76757a4271SDavid Teigland static void set_rcom_status(struct dlm_ls *ls, struct rcom_status *rs, 77757a4271SDavid Teigland uint32_t flags) 78757a4271SDavid Teigland { 79757a4271SDavid Teigland rs->rs_flags = cpu_to_le32(flags); 80757a4271SDavid Teigland } 81757a4271SDavid Teigland 82e7fd4179SDavid Teigland /* When replying to a status request, a node also sends back its 83e7fd4179SDavid Teigland configuration values. The requesting node then checks that the remote 84e7fd4179SDavid Teigland node is configured the same way as itself. */ 85e7fd4179SDavid Teigland 86757a4271SDavid Teigland static void set_rcom_config(struct dlm_ls *ls, struct rcom_config *rf, 87757a4271SDavid Teigland uint32_t num_slots) 88e7fd4179SDavid Teigland { 8993ff2971SAl Viro rf->rf_lvblen = cpu_to_le32(ls->ls_lvblen); 9093ff2971SAl Viro rf->rf_lsflags = cpu_to_le32(ls->ls_exflags); 91757a4271SDavid Teigland 92757a4271SDavid Teigland rf->rf_our_slot = cpu_to_le16(ls->ls_slot); 93757a4271SDavid Teigland rf->rf_num_slots = cpu_to_le16(num_slots); 94757a4271SDavid Teigland rf->rf_generation = cpu_to_le32(ls->ls_generation); 95e7fd4179SDavid Teigland } 96e7fd4179SDavid Teigland 97757a4271SDavid Teigland static int check_rcom_config(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid) 98e7fd4179SDavid Teigland { 999e971b71SDavid Teigland struct rcom_config *rf = (struct rcom_config *) rc->rc_buf; 1009e971b71SDavid Teigland 1019e971b71SDavid Teigland if ((rc->rc_header.h_version & 0xFFFF0000) != DLM_HEADER_MAJOR) { 1029e971b71SDavid Teigland log_error(ls, "version mismatch: %x nodeid %d: %x", 1039e971b71SDavid Teigland DLM_HEADER_MAJOR | DLM_HEADER_MINOR, nodeid, 1049e971b71SDavid Teigland rc->rc_header.h_version); 1058b0e7b2cSDavid Teigland return -EPROTO; 1069e971b71SDavid Teigland } 1079e971b71SDavid Teigland 10893ff2971SAl Viro if (le32_to_cpu(rf->rf_lvblen) != ls->ls_lvblen || 10993ff2971SAl Viro le32_to_cpu(rf->rf_lsflags) != ls->ls_exflags) { 110e7fd4179SDavid Teigland log_error(ls, "config mismatch: %d,%x nodeid %d: %d,%x", 11193ff2971SAl Viro ls->ls_lvblen, ls->ls_exflags, nodeid, 11293ff2971SAl Viro le32_to_cpu(rf->rf_lvblen), 11393ff2971SAl Viro le32_to_cpu(rf->rf_lsflags)); 1148b0e7b2cSDavid Teigland return -EPROTO; 115e7fd4179SDavid Teigland } 116e7fd4179SDavid Teigland return 0; 117e7fd4179SDavid Teigland } 118e7fd4179SDavid Teigland 11998f176fbSDavid Teigland static void allow_sync_reply(struct dlm_ls *ls, uint64_t *new_seq) 12098f176fbSDavid Teigland { 12198f176fbSDavid Teigland spin_lock(&ls->ls_rcom_spin); 12298f176fbSDavid Teigland *new_seq = ++ls->ls_rcom_seq; 12398f176fbSDavid Teigland set_bit(LSFL_RCOM_WAIT, &ls->ls_flags); 12498f176fbSDavid Teigland spin_unlock(&ls->ls_rcom_spin); 12598f176fbSDavid Teigland } 12698f176fbSDavid Teigland 12798f176fbSDavid Teigland static void disallow_sync_reply(struct dlm_ls *ls) 12898f176fbSDavid Teigland { 12998f176fbSDavid Teigland spin_lock(&ls->ls_rcom_spin); 13098f176fbSDavid Teigland clear_bit(LSFL_RCOM_WAIT, &ls->ls_flags); 13198f176fbSDavid Teigland clear_bit(LSFL_RCOM_READY, &ls->ls_flags); 13298f176fbSDavid Teigland spin_unlock(&ls->ls_rcom_spin); 13398f176fbSDavid Teigland } 13498f176fbSDavid Teigland 135757a4271SDavid Teigland /* 136757a4271SDavid Teigland * low nodeid gathers one slot value at a time from each node. 137757a4271SDavid Teigland * it sets need_slots=0, and saves rf_our_slot returned from each 138757a4271SDavid Teigland * rcom_config. 139757a4271SDavid Teigland * 140757a4271SDavid Teigland * other nodes gather all slot values at once from the low nodeid. 141757a4271SDavid Teigland * they set need_slots=1, and ignore the rf_our_slot returned from each 142757a4271SDavid Teigland * rcom_config. they use the rf_num_slots returned from the low 143757a4271SDavid Teigland * node's rcom_config. 144757a4271SDavid Teigland */ 145757a4271SDavid Teigland 146757a4271SDavid Teigland int dlm_rcom_status(struct dlm_ls *ls, int nodeid, uint32_t status_flags) 147e7fd4179SDavid Teigland { 148e7fd4179SDavid Teigland struct dlm_rcom *rc; 149e7fd4179SDavid Teigland struct dlm_mhandle *mh; 150e7fd4179SDavid Teigland int error = 0; 151e7fd4179SDavid Teigland 152faa0f267SDavid Teigland ls->ls_recover_nodeid = nodeid; 153e7fd4179SDavid Teigland 154e7fd4179SDavid Teigland if (nodeid == dlm_our_nodeid()) { 1554007685cSAl Viro rc = ls->ls_recover_buf; 156e7fd4179SDavid Teigland rc->rc_result = dlm_recover_status(ls); 157e7fd4179SDavid Teigland goto out; 158e7fd4179SDavid Teigland } 159e7fd4179SDavid Teigland 160757a4271SDavid Teigland error = create_rcom(ls, nodeid, DLM_RCOM_STATUS, 161757a4271SDavid Teigland sizeof(struct rcom_status), &rc, &mh); 162e7fd4179SDavid Teigland if (error) 163e7fd4179SDavid Teigland goto out; 16498f176fbSDavid Teigland 165757a4271SDavid Teigland set_rcom_status(ls, (struct rcom_status *)rc->rc_buf, status_flags); 166757a4271SDavid Teigland 16798f176fbSDavid Teigland allow_sync_reply(ls, &rc->rc_id); 16868c817a1SDavid Teigland memset(ls->ls_recover_buf, 0, dlm_config.ci_buffer_size); 169e7fd4179SDavid Teigland 170e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 171e7fd4179SDavid Teigland 172e7fd4179SDavid Teigland error = dlm_wait_function(ls, &rcom_response); 17398f176fbSDavid Teigland disallow_sync_reply(ls); 174e7fd4179SDavid Teigland if (error) 175e7fd4179SDavid Teigland goto out; 176e7fd4179SDavid Teigland 1774007685cSAl Viro rc = ls->ls_recover_buf; 178e7fd4179SDavid Teigland 179e7fd4179SDavid Teigland if (rc->rc_result == -ESRCH) { 180e7fd4179SDavid Teigland /* we pretend the remote lockspace exists with 0 status */ 181e7fd4179SDavid Teigland log_debug(ls, "remote node %d not ready", nodeid); 182e7fd4179SDavid Teigland rc->rc_result = 0; 183757a4271SDavid Teigland error = 0; 184757a4271SDavid Teigland } else { 185757a4271SDavid Teigland error = check_rcom_config(ls, rc, nodeid); 186757a4271SDavid Teigland } 187757a4271SDavid Teigland 188e7fd4179SDavid Teigland /* the caller looks at rc_result for the remote recovery status */ 189e7fd4179SDavid Teigland out: 190e7fd4179SDavid Teigland return error; 191e7fd4179SDavid Teigland } 192e7fd4179SDavid Teigland 193e7fd4179SDavid Teigland static void receive_rcom_status(struct dlm_ls *ls, struct dlm_rcom *rc_in) 194e7fd4179SDavid Teigland { 195e7fd4179SDavid Teigland struct dlm_rcom *rc; 196e7fd4179SDavid Teigland struct dlm_mhandle *mh; 197757a4271SDavid Teigland struct rcom_status *rs; 198757a4271SDavid Teigland uint32_t status; 199757a4271SDavid Teigland int nodeid = rc_in->rc_header.h_nodeid; 200757a4271SDavid Teigland int len = sizeof(struct rcom_config); 201757a4271SDavid Teigland int num_slots = 0; 202757a4271SDavid Teigland int error; 203e7fd4179SDavid Teigland 204757a4271SDavid Teigland if (!dlm_slots_version(&rc_in->rc_header)) { 205757a4271SDavid Teigland status = dlm_recover_status(ls); 206757a4271SDavid Teigland goto do_create; 207757a4271SDavid Teigland } 208757a4271SDavid Teigland 209757a4271SDavid Teigland rs = (struct rcom_status *)rc_in->rc_buf; 210757a4271SDavid Teigland 211757a4271SDavid Teigland if (!(rs->rs_flags & DLM_RSF_NEED_SLOTS)) { 212757a4271SDavid Teigland status = dlm_recover_status(ls); 213757a4271SDavid Teigland goto do_create; 214757a4271SDavid Teigland } 215757a4271SDavid Teigland 216757a4271SDavid Teigland spin_lock(&ls->ls_recover_lock); 217757a4271SDavid Teigland status = ls->ls_recover_status; 218757a4271SDavid Teigland num_slots = ls->ls_num_slots; 219757a4271SDavid Teigland spin_unlock(&ls->ls_recover_lock); 220757a4271SDavid Teigland len += num_slots * sizeof(struct rcom_slot); 221757a4271SDavid Teigland 222757a4271SDavid Teigland do_create: 223e7fd4179SDavid Teigland error = create_rcom(ls, nodeid, DLM_RCOM_STATUS_REPLY, 224757a4271SDavid Teigland len, &rc, &mh); 225e7fd4179SDavid Teigland if (error) 226e7fd4179SDavid Teigland return; 227757a4271SDavid Teigland 2284a99c3d9SDavid Teigland rc->rc_id = rc_in->rc_id; 22938aa8b0cSDavid Teigland rc->rc_seq_reply = rc_in->rc_seq; 230757a4271SDavid Teigland rc->rc_result = status; 231e7fd4179SDavid Teigland 232757a4271SDavid Teigland set_rcom_config(ls, (struct rcom_config *)rc->rc_buf, num_slots); 233757a4271SDavid Teigland 234757a4271SDavid Teigland if (!num_slots) 235757a4271SDavid Teigland goto do_send; 236757a4271SDavid Teigland 237757a4271SDavid Teigland spin_lock(&ls->ls_recover_lock); 238757a4271SDavid Teigland if (ls->ls_num_slots != num_slots) { 239757a4271SDavid Teigland spin_unlock(&ls->ls_recover_lock); 240757a4271SDavid Teigland log_debug(ls, "receive_rcom_status num_slots %d to %d", 241757a4271SDavid Teigland num_slots, ls->ls_num_slots); 242757a4271SDavid Teigland rc->rc_result = 0; 243757a4271SDavid Teigland set_rcom_config(ls, (struct rcom_config *)rc->rc_buf, 0); 244757a4271SDavid Teigland goto do_send; 245757a4271SDavid Teigland } 246757a4271SDavid Teigland 247757a4271SDavid Teigland dlm_slots_copy_out(ls, rc); 248757a4271SDavid Teigland spin_unlock(&ls->ls_recover_lock); 249757a4271SDavid Teigland 250757a4271SDavid Teigland do_send: 251e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 252e7fd4179SDavid Teigland } 253e7fd4179SDavid Teigland 2544a99c3d9SDavid Teigland static void receive_sync_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) 255e7fd4179SDavid Teigland { 25698f176fbSDavid Teigland spin_lock(&ls->ls_rcom_spin); 25798f176fbSDavid Teigland if (!test_bit(LSFL_RCOM_WAIT, &ls->ls_flags) || 25898f176fbSDavid Teigland rc_in->rc_id != ls->ls_rcom_seq) { 25998f176fbSDavid Teigland log_debug(ls, "reject reply %d from %d seq %llx expect %llx", 26098f176fbSDavid Teigland rc_in->rc_type, rc_in->rc_header.h_nodeid, 26157adf7eeSRyusuke Konishi (unsigned long long)rc_in->rc_id, 26257adf7eeSRyusuke Konishi (unsigned long long)ls->ls_rcom_seq); 26398f176fbSDavid Teigland goto out; 2644a99c3d9SDavid Teigland } 265e7fd4179SDavid Teigland memcpy(ls->ls_recover_buf, rc_in, rc_in->rc_header.h_length); 266e7fd4179SDavid Teigland set_bit(LSFL_RCOM_READY, &ls->ls_flags); 26798f176fbSDavid Teigland clear_bit(LSFL_RCOM_WAIT, &ls->ls_flags); 268e7fd4179SDavid Teigland wake_up(&ls->ls_wait_general); 26998f176fbSDavid Teigland out: 27098f176fbSDavid Teigland spin_unlock(&ls->ls_rcom_spin); 271e7fd4179SDavid Teigland } 272e7fd4179SDavid Teigland 273e7fd4179SDavid Teigland int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name, int last_len) 274e7fd4179SDavid Teigland { 275e7fd4179SDavid Teigland struct dlm_rcom *rc; 276e7fd4179SDavid Teigland struct dlm_mhandle *mh; 2774007685cSAl Viro int error = 0; 2784007685cSAl Viro int max_size = dlm_config.ci_buffer_size - sizeof(struct dlm_rcom); 279e7fd4179SDavid Teigland 280faa0f267SDavid Teigland ls->ls_recover_nodeid = nodeid; 281e7fd4179SDavid Teigland 282e7fd4179SDavid Teigland if (nodeid == dlm_our_nodeid()) { 283599e0f58SDavid Teigland ls->ls_recover_buf->rc_header.h_length = 284599e0f58SDavid Teigland dlm_config.ci_buffer_size; 285e7fd4179SDavid Teigland dlm_copy_master_names(ls, last_name, last_len, 2864007685cSAl Viro ls->ls_recover_buf->rc_buf, 2874007685cSAl Viro max_size, nodeid); 288e7fd4179SDavid Teigland goto out; 289e7fd4179SDavid Teigland } 290e7fd4179SDavid Teigland 291e7fd4179SDavid Teigland error = create_rcom(ls, nodeid, DLM_RCOM_NAMES, last_len, &rc, &mh); 292e7fd4179SDavid Teigland if (error) 293e7fd4179SDavid Teigland goto out; 294e7fd4179SDavid Teigland memcpy(rc->rc_buf, last_name, last_len); 29598f176fbSDavid Teigland 29698f176fbSDavid Teigland allow_sync_reply(ls, &rc->rc_id); 29768c817a1SDavid Teigland memset(ls->ls_recover_buf, 0, dlm_config.ci_buffer_size); 298e7fd4179SDavid Teigland 299e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 300e7fd4179SDavid Teigland 301e7fd4179SDavid Teigland error = dlm_wait_function(ls, &rcom_response); 30298f176fbSDavid Teigland disallow_sync_reply(ls); 303e7fd4179SDavid Teigland out: 304e7fd4179SDavid Teigland return error; 305e7fd4179SDavid Teigland } 306e7fd4179SDavid Teigland 307e7fd4179SDavid Teigland static void receive_rcom_names(struct dlm_ls *ls, struct dlm_rcom *rc_in) 308e7fd4179SDavid Teigland { 309e7fd4179SDavid Teigland struct dlm_rcom *rc; 310e7fd4179SDavid Teigland struct dlm_mhandle *mh; 31138aa8b0cSDavid Teigland int error, inlen, outlen, nodeid; 312e7fd4179SDavid Teigland 313e7fd4179SDavid Teigland nodeid = rc_in->rc_header.h_nodeid; 314e7fd4179SDavid Teigland inlen = rc_in->rc_header.h_length - sizeof(struct dlm_rcom); 31568c817a1SDavid Teigland outlen = dlm_config.ci_buffer_size - sizeof(struct dlm_rcom); 316e7fd4179SDavid Teigland 317e7fd4179SDavid Teigland error = create_rcom(ls, nodeid, DLM_RCOM_NAMES_REPLY, outlen, &rc, &mh); 318e7fd4179SDavid Teigland if (error) 319e7fd4179SDavid Teigland return; 3204a99c3d9SDavid Teigland rc->rc_id = rc_in->rc_id; 32138aa8b0cSDavid Teigland rc->rc_seq_reply = rc_in->rc_seq; 322e7fd4179SDavid Teigland 323e7fd4179SDavid Teigland dlm_copy_master_names(ls, rc_in->rc_buf, inlen, rc->rc_buf, outlen, 324e7fd4179SDavid Teigland nodeid); 325e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 326e7fd4179SDavid Teigland } 327e7fd4179SDavid Teigland 328e7fd4179SDavid Teigland int dlm_send_rcom_lookup(struct dlm_rsb *r, int dir_nodeid) 329e7fd4179SDavid Teigland { 330e7fd4179SDavid Teigland struct dlm_rcom *rc; 331e7fd4179SDavid Teigland struct dlm_mhandle *mh; 332e7fd4179SDavid Teigland struct dlm_ls *ls = r->res_ls; 333e7fd4179SDavid Teigland int error; 334e7fd4179SDavid Teigland 335e7fd4179SDavid Teigland error = create_rcom(ls, dir_nodeid, DLM_RCOM_LOOKUP, r->res_length, 336e7fd4179SDavid Teigland &rc, &mh); 337e7fd4179SDavid Teigland if (error) 338e7fd4179SDavid Teigland goto out; 339e7fd4179SDavid Teigland memcpy(rc->rc_buf, r->res_name, r->res_length); 340e7fd4179SDavid Teigland rc->rc_id = (unsigned long) r; 341e7fd4179SDavid Teigland 342e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 343e7fd4179SDavid Teigland out: 344e7fd4179SDavid Teigland return error; 345e7fd4179SDavid Teigland } 346e7fd4179SDavid Teigland 347e7fd4179SDavid Teigland static void receive_rcom_lookup(struct dlm_ls *ls, struct dlm_rcom *rc_in) 348e7fd4179SDavid Teigland { 349e7fd4179SDavid Teigland struct dlm_rcom *rc; 350e7fd4179SDavid Teigland struct dlm_mhandle *mh; 351e7fd4179SDavid Teigland int error, ret_nodeid, nodeid = rc_in->rc_header.h_nodeid; 352e7fd4179SDavid Teigland int len = rc_in->rc_header.h_length - sizeof(struct dlm_rcom); 353e7fd4179SDavid Teigland 354e7fd4179SDavid Teigland error = create_rcom(ls, nodeid, DLM_RCOM_LOOKUP_REPLY, 0, &rc, &mh); 355e7fd4179SDavid Teigland if (error) 356e7fd4179SDavid Teigland return; 357e7fd4179SDavid Teigland 358e7fd4179SDavid Teigland error = dlm_dir_lookup(ls, nodeid, rc_in->rc_buf, len, &ret_nodeid); 359e7fd4179SDavid Teigland if (error) 360e7fd4179SDavid Teigland ret_nodeid = error; 361e7fd4179SDavid Teigland rc->rc_result = ret_nodeid; 362e7fd4179SDavid Teigland rc->rc_id = rc_in->rc_id; 36338aa8b0cSDavid Teigland rc->rc_seq_reply = rc_in->rc_seq; 364e7fd4179SDavid Teigland 365e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 366e7fd4179SDavid Teigland } 367e7fd4179SDavid Teigland 368e7fd4179SDavid Teigland static void receive_rcom_lookup_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) 369e7fd4179SDavid Teigland { 370e7fd4179SDavid Teigland dlm_recover_master_reply(ls, rc_in); 371e7fd4179SDavid Teigland } 372e7fd4179SDavid Teigland 373e7fd4179SDavid Teigland static void pack_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb, 374e7fd4179SDavid Teigland struct rcom_lock *rl) 375e7fd4179SDavid Teigland { 376e7fd4179SDavid Teigland memset(rl, 0, sizeof(*rl)); 377e7fd4179SDavid Teigland 378163a1859SAl Viro rl->rl_ownpid = cpu_to_le32(lkb->lkb_ownpid); 379163a1859SAl Viro rl->rl_lkid = cpu_to_le32(lkb->lkb_id); 380163a1859SAl Viro rl->rl_exflags = cpu_to_le32(lkb->lkb_exflags); 381163a1859SAl Viro rl->rl_flags = cpu_to_le32(lkb->lkb_flags); 382163a1859SAl Viro rl->rl_lvbseq = cpu_to_le32(lkb->lkb_lvbseq); 383e7fd4179SDavid Teigland rl->rl_rqmode = lkb->lkb_rqmode; 384e7fd4179SDavid Teigland rl->rl_grmode = lkb->lkb_grmode; 385e7fd4179SDavid Teigland rl->rl_status = lkb->lkb_status; 386163a1859SAl Viro rl->rl_wait_type = cpu_to_le16(lkb->lkb_wait_type); 387e7fd4179SDavid Teigland 388e5dae548SDavid Teigland if (lkb->lkb_bastfn) 3898304d6f2SDavid Teigland rl->rl_asts |= DLM_CB_BAST; 390e5dae548SDavid Teigland if (lkb->lkb_astfn) 3918304d6f2SDavid Teigland rl->rl_asts |= DLM_CB_CAST; 392e7fd4179SDavid Teigland 393163a1859SAl Viro rl->rl_namelen = cpu_to_le16(r->res_length); 394e7fd4179SDavid Teigland memcpy(rl->rl_name, r->res_name, r->res_length); 395e7fd4179SDavid Teigland 396e7fd4179SDavid Teigland /* FIXME: might we have an lvb without DLM_LKF_VALBLK set ? 397e7fd4179SDavid Teigland If so, receive_rcom_lock_args() won't take this copy. */ 398e7fd4179SDavid Teigland 399e7fd4179SDavid Teigland if (lkb->lkb_lvbptr) 400e7fd4179SDavid Teigland memcpy(rl->rl_lvb, lkb->lkb_lvbptr, r->res_ls->ls_lvblen); 401e7fd4179SDavid Teigland } 402e7fd4179SDavid Teigland 403e7fd4179SDavid Teigland int dlm_send_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) 404e7fd4179SDavid Teigland { 405e7fd4179SDavid Teigland struct dlm_ls *ls = r->res_ls; 406e7fd4179SDavid Teigland struct dlm_rcom *rc; 407e7fd4179SDavid Teigland struct dlm_mhandle *mh; 408e7fd4179SDavid Teigland struct rcom_lock *rl; 409e7fd4179SDavid Teigland int error, len = sizeof(struct rcom_lock); 410e7fd4179SDavid Teigland 411e7fd4179SDavid Teigland if (lkb->lkb_lvbptr) 412e7fd4179SDavid Teigland len += ls->ls_lvblen; 413e7fd4179SDavid Teigland 414e7fd4179SDavid Teigland error = create_rcom(ls, r->res_nodeid, DLM_RCOM_LOCK, len, &rc, &mh); 415e7fd4179SDavid Teigland if (error) 416e7fd4179SDavid Teigland goto out; 417e7fd4179SDavid Teigland 418e7fd4179SDavid Teigland rl = (struct rcom_lock *) rc->rc_buf; 419e7fd4179SDavid Teigland pack_rcom_lock(r, lkb, rl); 420e7fd4179SDavid Teigland rc->rc_id = (unsigned long) r; 421e7fd4179SDavid Teigland 422e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 423e7fd4179SDavid Teigland out: 424e7fd4179SDavid Teigland return error; 425e7fd4179SDavid Teigland } 426e7fd4179SDavid Teigland 427ae773d0bSAl Viro /* needs at least dlm_rcom + rcom_lock */ 428e7fd4179SDavid Teigland static void receive_rcom_lock(struct dlm_ls *ls, struct dlm_rcom *rc_in) 429e7fd4179SDavid Teigland { 430e7fd4179SDavid Teigland struct dlm_rcom *rc; 431e7fd4179SDavid Teigland struct dlm_mhandle *mh; 432e7fd4179SDavid Teigland int error, nodeid = rc_in->rc_header.h_nodeid; 433e7fd4179SDavid Teigland 434e7fd4179SDavid Teigland dlm_recover_master_copy(ls, rc_in); 435e7fd4179SDavid Teigland 436e7fd4179SDavid Teigland error = create_rcom(ls, nodeid, DLM_RCOM_LOCK_REPLY, 437e7fd4179SDavid Teigland sizeof(struct rcom_lock), &rc, &mh); 438e7fd4179SDavid Teigland if (error) 439e7fd4179SDavid Teigland return; 440e7fd4179SDavid Teigland 441e7fd4179SDavid Teigland /* We send back the same rcom_lock struct we received, but 442e7fd4179SDavid Teigland dlm_recover_master_copy() has filled in rl_remid and rl_result */ 443e7fd4179SDavid Teigland 444e7fd4179SDavid Teigland memcpy(rc->rc_buf, rc_in->rc_buf, sizeof(struct rcom_lock)); 445e7fd4179SDavid Teigland rc->rc_id = rc_in->rc_id; 44638aa8b0cSDavid Teigland rc->rc_seq_reply = rc_in->rc_seq; 447e7fd4179SDavid Teigland 448e7fd4179SDavid Teigland send_rcom(ls, mh, rc); 449e7fd4179SDavid Teigland } 450e7fd4179SDavid Teigland 451c36258b5SDavid Teigland /* If the lockspace doesn't exist then still send a status message 452c36258b5SDavid Teigland back; it's possible that it just doesn't have its global_id yet. */ 453c36258b5SDavid Teigland 454c36258b5SDavid Teigland int dlm_send_ls_not_ready(int nodeid, struct dlm_rcom *rc_in) 455e7fd4179SDavid Teigland { 456e7fd4179SDavid Teigland struct dlm_rcom *rc; 4571babdb45SDavid Teigland struct rcom_config *rf; 458e7fd4179SDavid Teigland struct dlm_mhandle *mh; 459e7fd4179SDavid Teigland char *mb; 4601babdb45SDavid Teigland int mb_len = sizeof(struct dlm_rcom) + sizeof(struct rcom_config); 461e7fd4179SDavid Teigland 46241684f95SDavid Teigland mh = dlm_lowcomms_get_buffer(nodeid, mb_len, GFP_NOFS, &mb); 463e7fd4179SDavid Teigland if (!mh) 464e7fd4179SDavid Teigland return -ENOBUFS; 465e7fd4179SDavid Teigland memset(mb, 0, mb_len); 466e7fd4179SDavid Teigland 467e7fd4179SDavid Teigland rc = (struct dlm_rcom *) mb; 468e7fd4179SDavid Teigland 469e7fd4179SDavid Teigland rc->rc_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR); 470e7fd4179SDavid Teigland rc->rc_header.h_lockspace = rc_in->rc_header.h_lockspace; 471e7fd4179SDavid Teigland rc->rc_header.h_nodeid = dlm_our_nodeid(); 472e7fd4179SDavid Teigland rc->rc_header.h_length = mb_len; 473e7fd4179SDavid Teigland rc->rc_header.h_cmd = DLM_RCOM; 474e7fd4179SDavid Teigland 475e7fd4179SDavid Teigland rc->rc_type = DLM_RCOM_STATUS_REPLY; 476f5888750SDavid Teigland rc->rc_id = rc_in->rc_id; 47738aa8b0cSDavid Teigland rc->rc_seq_reply = rc_in->rc_seq; 478e7fd4179SDavid Teigland rc->rc_result = -ESRCH; 479e7fd4179SDavid Teigland 4801babdb45SDavid Teigland rf = (struct rcom_config *) rc->rc_buf; 48193ff2971SAl Viro rf->rf_lvblen = cpu_to_le32(~0U); 4821babdb45SDavid Teigland 483e7fd4179SDavid Teigland dlm_rcom_out(rc); 484e7fd4179SDavid Teigland dlm_lowcomms_commit_buffer(mh); 485e7fd4179SDavid Teigland 486e7fd4179SDavid Teigland return 0; 487e7fd4179SDavid Teigland } 488e7fd4179SDavid Teigland 489c36258b5SDavid Teigland /* Called by dlm_recv; corresponds to dlm_receive_message() but special 490e7fd4179SDavid Teigland recovery-only comms are sent through here. */ 491e7fd4179SDavid Teigland 492c36258b5SDavid Teigland void dlm_receive_rcom(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid) 493e7fd4179SDavid Teigland { 494ae773d0bSAl Viro int lock_size = sizeof(struct dlm_rcom) + sizeof(struct rcom_lock); 495*4875647aSDavid Teigland int stop, reply = 0, lock = 0; 496*4875647aSDavid Teigland uint32_t status; 497d6e24788SDavid Teigland uint64_t seq; 498ae773d0bSAl Viro 499d6e24788SDavid Teigland switch (rc->rc_type) { 500*4875647aSDavid Teigland case DLM_RCOM_LOCK: 501*4875647aSDavid Teigland lock = 1; 502*4875647aSDavid Teigland break; 503*4875647aSDavid Teigland case DLM_RCOM_LOCK_REPLY: 504*4875647aSDavid Teigland lock = 1; 505*4875647aSDavid Teigland reply = 1; 506*4875647aSDavid Teigland break; 507d6e24788SDavid Teigland case DLM_RCOM_STATUS_REPLY: 508d6e24788SDavid Teigland case DLM_RCOM_NAMES_REPLY: 509d6e24788SDavid Teigland case DLM_RCOM_LOOKUP_REPLY: 510d6e24788SDavid Teigland reply = 1; 511d6e24788SDavid Teigland }; 512d6e24788SDavid Teigland 513d6e24788SDavid Teigland spin_lock(&ls->ls_recover_lock); 514*4875647aSDavid Teigland status = ls->ls_recover_status; 515d6e24788SDavid Teigland stop = test_bit(LSFL_RECOVERY_STOP, &ls->ls_flags); 516d6e24788SDavid Teigland seq = ls->ls_recover_seq; 517d6e24788SDavid Teigland spin_unlock(&ls->ls_recover_lock); 518d6e24788SDavid Teigland 519d6e24788SDavid Teigland if ((stop && (rc->rc_type != DLM_RCOM_STATUS)) || 520*4875647aSDavid Teigland (reply && (rc->rc_seq_reply != seq)) || 521*4875647aSDavid Teigland (lock && !(status & DLM_RS_DIR))) { 522d6e24788SDavid Teigland log_limit(ls, "dlm_receive_rcom ignore msg %d " 523*4875647aSDavid Teigland "from %d %llu %llu recover seq %llu sts %x gen %u", 524*4875647aSDavid Teigland rc->rc_type, 525*4875647aSDavid Teigland nodeid, 526d6e24788SDavid Teigland (unsigned long long)rc->rc_seq, 527d6e24788SDavid Teigland (unsigned long long)rc->rc_seq_reply, 528*4875647aSDavid Teigland (unsigned long long)seq, 529*4875647aSDavid Teigland status, ls->ls_generation); 530e7fd4179SDavid Teigland goto out; 531e7fd4179SDavid Teigland } 532e7fd4179SDavid Teigland 533e7fd4179SDavid Teigland switch (rc->rc_type) { 534e7fd4179SDavid Teigland case DLM_RCOM_STATUS: 535e7fd4179SDavid Teigland receive_rcom_status(ls, rc); 536e7fd4179SDavid Teigland break; 537e7fd4179SDavid Teigland 538e7fd4179SDavid Teigland case DLM_RCOM_NAMES: 539e7fd4179SDavid Teigland receive_rcom_names(ls, rc); 540e7fd4179SDavid Teigland break; 541e7fd4179SDavid Teigland 542e7fd4179SDavid Teigland case DLM_RCOM_LOOKUP: 543e7fd4179SDavid Teigland receive_rcom_lookup(ls, rc); 544e7fd4179SDavid Teigland break; 545e7fd4179SDavid Teigland 546e7fd4179SDavid Teigland case DLM_RCOM_LOCK: 547ae773d0bSAl Viro if (rc->rc_header.h_length < lock_size) 548ae773d0bSAl Viro goto Eshort; 549e7fd4179SDavid Teigland receive_rcom_lock(ls, rc); 550e7fd4179SDavid Teigland break; 551e7fd4179SDavid Teigland 552e7fd4179SDavid Teigland case DLM_RCOM_STATUS_REPLY: 553dbcfc347SDavid Teigland receive_sync_reply(ls, rc); 554e7fd4179SDavid Teigland break; 555e7fd4179SDavid Teigland 556e7fd4179SDavid Teigland case DLM_RCOM_NAMES_REPLY: 557dbcfc347SDavid Teigland receive_sync_reply(ls, rc); 558e7fd4179SDavid Teigland break; 559e7fd4179SDavid Teigland 560e7fd4179SDavid Teigland case DLM_RCOM_LOOKUP_REPLY: 561e7fd4179SDavid Teigland receive_rcom_lookup_reply(ls, rc); 562e7fd4179SDavid Teigland break; 563e7fd4179SDavid Teigland 564e7fd4179SDavid Teigland case DLM_RCOM_LOCK_REPLY: 565ae773d0bSAl Viro if (rc->rc_header.h_length < lock_size) 566ae773d0bSAl Viro goto Eshort; 567dbcfc347SDavid Teigland dlm_recover_process_copy(ls, rc); 568e7fd4179SDavid Teigland break; 569e7fd4179SDavid Teigland 570e7fd4179SDavid Teigland default: 571dbcfc347SDavid Teigland log_error(ls, "receive_rcom bad type %d", rc->rc_type); 572e7fd4179SDavid Teigland } 573e7fd4179SDavid Teigland out: 574c36258b5SDavid Teigland return; 575ae773d0bSAl Viro Eshort: 576ae773d0bSAl Viro log_error(ls, "recovery message %x from %d is too short", 577ae773d0bSAl Viro rc->rc_type, nodeid); 578e7fd4179SDavid Teigland } 579e7fd4179SDavid Teigland 580