David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | ******************************************************************************* |
| 3 | ** |
| 4 | ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
| 5 | ** Copyright (C) 2005 Red Hat, Inc. All rights reserved. |
| 6 | ** |
| 7 | ** This copyrighted material is made available to anyone wishing to use, |
| 8 | ** modify, copy, or redistribute it subject to the terms and conditions |
| 9 | ** of the GNU General Public License v.2. |
| 10 | ** |
| 11 | ******************************************************************************* |
| 12 | ******************************************************************************/ |
| 13 | |
| 14 | #include "dlm_internal.h" |
| 15 | #include "lockspace.h" |
| 16 | #include "member.h" |
| 17 | #include "lowcomms.h" |
| 18 | #include "midcomms.h" |
| 19 | #include "rcom.h" |
| 20 | #include "recover.h" |
| 21 | #include "dir.h" |
| 22 | #include "config.h" |
| 23 | #include "memory.h" |
| 24 | #include "lock.h" |
| 25 | #include "util.h" |
| 26 | |
| 27 | |
| 28 | static int rcom_response(struct dlm_ls *ls) |
| 29 | { |
| 30 | return test_bit(LSFL_RCOM_READY, &ls->ls_flags); |
| 31 | } |
| 32 | |
| 33 | static int create_rcom(struct dlm_ls *ls, int to_nodeid, int type, int len, |
| 34 | struct dlm_rcom **rc_ret, struct dlm_mhandle **mh_ret) |
| 35 | { |
| 36 | struct dlm_rcom *rc; |
| 37 | struct dlm_mhandle *mh; |
| 38 | char *mb; |
| 39 | int mb_len = sizeof(struct dlm_rcom) + len; |
| 40 | |
Patrick Caulfield | 44f487a | 2007-06-06 09:21:22 -0500 | [diff] [blame] | 41 | mh = dlm_lowcomms_get_buffer(to_nodeid, mb_len, ls->ls_allocation, &mb); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 42 | if (!mh) { |
| 43 | log_print("create_rcom to %d type %d len %d ENOBUFS", |
| 44 | to_nodeid, type, len); |
| 45 | return -ENOBUFS; |
| 46 | } |
| 47 | memset(mb, 0, mb_len); |
| 48 | |
| 49 | rc = (struct dlm_rcom *) mb; |
| 50 | |
| 51 | rc->rc_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR); |
| 52 | rc->rc_header.h_lockspace = ls->ls_global_id; |
| 53 | rc->rc_header.h_nodeid = dlm_our_nodeid(); |
| 54 | rc->rc_header.h_length = mb_len; |
| 55 | rc->rc_header.h_cmd = DLM_RCOM; |
| 56 | |
| 57 | rc->rc_type = type; |
| 58 | |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 59 | spin_lock(&ls->ls_recover_lock); |
| 60 | rc->rc_seq = ls->ls_recover_seq; |
| 61 | spin_unlock(&ls->ls_recover_lock); |
| 62 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 63 | *mh_ret = mh; |
| 64 | *rc_ret = rc; |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static void send_rcom(struct dlm_ls *ls, struct dlm_mhandle *mh, |
| 69 | struct dlm_rcom *rc) |
| 70 | { |
| 71 | dlm_rcom_out(rc); |
| 72 | dlm_lowcomms_commit_buffer(mh); |
| 73 | } |
| 74 | |
| 75 | /* When replying to a status request, a node also sends back its |
| 76 | configuration values. The requesting node then checks that the remote |
| 77 | node is configured the same way as itself. */ |
| 78 | |
| 79 | static void make_config(struct dlm_ls *ls, struct rcom_config *rf) |
| 80 | { |
| 81 | rf->rf_lvblen = ls->ls_lvblen; |
| 82 | rf->rf_lsflags = ls->ls_exflags; |
| 83 | } |
| 84 | |
David Teigland | 9e971b7 | 2006-12-13 10:37:55 -0600 | [diff] [blame] | 85 | static int check_config(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 86 | { |
David Teigland | 9e971b7 | 2006-12-13 10:37:55 -0600 | [diff] [blame] | 87 | struct rcom_config *rf = (struct rcom_config *) rc->rc_buf; |
| 88 | |
| 89 | if ((rc->rc_header.h_version & 0xFFFF0000) != DLM_HEADER_MAJOR) { |
| 90 | log_error(ls, "version mismatch: %x nodeid %d: %x", |
| 91 | DLM_HEADER_MAJOR | DLM_HEADER_MINOR, nodeid, |
| 92 | rc->rc_header.h_version); |
David Teigland | 8b0e7b2 | 2007-05-18 09:03:35 -0500 | [diff] [blame] | 93 | return -EPROTO; |
David Teigland | 9e971b7 | 2006-12-13 10:37:55 -0600 | [diff] [blame] | 94 | } |
| 95 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 96 | if (rf->rf_lvblen != ls->ls_lvblen || |
| 97 | rf->rf_lsflags != ls->ls_exflags) { |
| 98 | log_error(ls, "config mismatch: %d,%x nodeid %d: %d,%x", |
| 99 | ls->ls_lvblen, ls->ls_exflags, |
| 100 | nodeid, rf->rf_lvblen, rf->rf_lsflags); |
David Teigland | 8b0e7b2 | 2007-05-18 09:03:35 -0500 | [diff] [blame] | 101 | return -EPROTO; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 102 | } |
| 103 | return 0; |
| 104 | } |
| 105 | |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 106 | static void allow_sync_reply(struct dlm_ls *ls, uint64_t *new_seq) |
| 107 | { |
| 108 | spin_lock(&ls->ls_rcom_spin); |
| 109 | *new_seq = ++ls->ls_rcom_seq; |
| 110 | set_bit(LSFL_RCOM_WAIT, &ls->ls_flags); |
| 111 | spin_unlock(&ls->ls_rcom_spin); |
| 112 | } |
| 113 | |
| 114 | static void disallow_sync_reply(struct dlm_ls *ls) |
| 115 | { |
| 116 | spin_lock(&ls->ls_rcom_spin); |
| 117 | clear_bit(LSFL_RCOM_WAIT, &ls->ls_flags); |
| 118 | clear_bit(LSFL_RCOM_READY, &ls->ls_flags); |
| 119 | spin_unlock(&ls->ls_rcom_spin); |
| 120 | } |
| 121 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 122 | int dlm_rcom_status(struct dlm_ls *ls, int nodeid) |
| 123 | { |
| 124 | struct dlm_rcom *rc; |
| 125 | struct dlm_mhandle *mh; |
| 126 | int error = 0; |
| 127 | |
David Teigland | faa0f26 | 2006-08-08 17:08:42 -0500 | [diff] [blame] | 128 | ls->ls_recover_nodeid = nodeid; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 129 | |
| 130 | if (nodeid == dlm_our_nodeid()) { |
| 131 | rc = (struct dlm_rcom *) ls->ls_recover_buf; |
| 132 | rc->rc_result = dlm_recover_status(ls); |
| 133 | goto out; |
| 134 | } |
| 135 | |
| 136 | error = create_rcom(ls, nodeid, DLM_RCOM_STATUS, 0, &rc, &mh); |
| 137 | if (error) |
| 138 | goto out; |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 139 | |
| 140 | allow_sync_reply(ls, &rc->rc_id); |
David Teigland | 68c817a | 2007-01-09 09:41:48 -0600 | [diff] [blame] | 141 | memset(ls->ls_recover_buf, 0, dlm_config.ci_buffer_size); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 142 | |
| 143 | send_rcom(ls, mh, rc); |
| 144 | |
| 145 | error = dlm_wait_function(ls, &rcom_response); |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 146 | disallow_sync_reply(ls); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 147 | if (error) |
| 148 | goto out; |
| 149 | |
| 150 | rc = (struct dlm_rcom *) ls->ls_recover_buf; |
| 151 | |
| 152 | if (rc->rc_result == -ESRCH) { |
| 153 | /* we pretend the remote lockspace exists with 0 status */ |
| 154 | log_debug(ls, "remote node %d not ready", nodeid); |
| 155 | rc->rc_result = 0; |
| 156 | } else |
David Teigland | 9e971b7 | 2006-12-13 10:37:55 -0600 | [diff] [blame] | 157 | error = check_config(ls, rc, nodeid); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 158 | /* the caller looks at rc_result for the remote recovery status */ |
| 159 | out: |
| 160 | return error; |
| 161 | } |
| 162 | |
| 163 | static void receive_rcom_status(struct dlm_ls *ls, struct dlm_rcom *rc_in) |
| 164 | { |
| 165 | struct dlm_rcom *rc; |
| 166 | struct dlm_mhandle *mh; |
| 167 | int error, nodeid = rc_in->rc_header.h_nodeid; |
| 168 | |
| 169 | error = create_rcom(ls, nodeid, DLM_RCOM_STATUS_REPLY, |
| 170 | sizeof(struct rcom_config), &rc, &mh); |
| 171 | if (error) |
| 172 | return; |
David Teigland | 4a99c3d | 2006-08-09 11:20:15 -0500 | [diff] [blame] | 173 | rc->rc_id = rc_in->rc_id; |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 174 | rc->rc_seq_reply = rc_in->rc_seq; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 175 | rc->rc_result = dlm_recover_status(ls); |
| 176 | make_config(ls, (struct rcom_config *) rc->rc_buf); |
| 177 | |
| 178 | send_rcom(ls, mh, rc); |
| 179 | } |
| 180 | |
David Teigland | 4a99c3d | 2006-08-09 11:20:15 -0500 | [diff] [blame] | 181 | static void receive_sync_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 182 | { |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 183 | spin_lock(&ls->ls_rcom_spin); |
| 184 | if (!test_bit(LSFL_RCOM_WAIT, &ls->ls_flags) || |
| 185 | rc_in->rc_id != ls->ls_rcom_seq) { |
| 186 | log_debug(ls, "reject reply %d from %d seq %llx expect %llx", |
| 187 | rc_in->rc_type, rc_in->rc_header.h_nodeid, |
Ryusuke Konishi | 57adf7e | 2006-11-29 09:33:48 -0500 | [diff] [blame] | 188 | (unsigned long long)rc_in->rc_id, |
| 189 | (unsigned long long)ls->ls_rcom_seq); |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 190 | goto out; |
David Teigland | 4a99c3d | 2006-08-09 11:20:15 -0500 | [diff] [blame] | 191 | } |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 192 | memcpy(ls->ls_recover_buf, rc_in, rc_in->rc_header.h_length); |
| 193 | set_bit(LSFL_RCOM_READY, &ls->ls_flags); |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 194 | clear_bit(LSFL_RCOM_WAIT, &ls->ls_flags); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 195 | wake_up(&ls->ls_wait_general); |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 196 | out: |
| 197 | spin_unlock(&ls->ls_rcom_spin); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 198 | } |
| 199 | |
David Teigland | 4a99c3d | 2006-08-09 11:20:15 -0500 | [diff] [blame] | 200 | static void receive_rcom_status_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) |
| 201 | { |
| 202 | receive_sync_reply(ls, rc_in); |
| 203 | } |
| 204 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 205 | int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name, int last_len) |
| 206 | { |
| 207 | struct dlm_rcom *rc; |
| 208 | struct dlm_mhandle *mh; |
| 209 | int error = 0, len = sizeof(struct dlm_rcom); |
| 210 | |
David Teigland | faa0f26 | 2006-08-08 17:08:42 -0500 | [diff] [blame] | 211 | ls->ls_recover_nodeid = nodeid; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 212 | |
| 213 | if (nodeid == dlm_our_nodeid()) { |
| 214 | dlm_copy_master_names(ls, last_name, last_len, |
| 215 | ls->ls_recover_buf + len, |
David Teigland | 68c817a | 2007-01-09 09:41:48 -0600 | [diff] [blame] | 216 | dlm_config.ci_buffer_size - len, nodeid); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 217 | goto out; |
| 218 | } |
| 219 | |
| 220 | error = create_rcom(ls, nodeid, DLM_RCOM_NAMES, last_len, &rc, &mh); |
| 221 | if (error) |
| 222 | goto out; |
| 223 | memcpy(rc->rc_buf, last_name, last_len); |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 224 | |
| 225 | allow_sync_reply(ls, &rc->rc_id); |
David Teigland | 68c817a | 2007-01-09 09:41:48 -0600 | [diff] [blame] | 226 | memset(ls->ls_recover_buf, 0, dlm_config.ci_buffer_size); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 227 | |
| 228 | send_rcom(ls, mh, rc); |
| 229 | |
| 230 | error = dlm_wait_function(ls, &rcom_response); |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 231 | disallow_sync_reply(ls); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 232 | out: |
| 233 | return error; |
| 234 | } |
| 235 | |
| 236 | static void receive_rcom_names(struct dlm_ls *ls, struct dlm_rcom *rc_in) |
| 237 | { |
| 238 | struct dlm_rcom *rc; |
| 239 | struct dlm_mhandle *mh; |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 240 | int error, inlen, outlen, nodeid; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 241 | |
| 242 | nodeid = rc_in->rc_header.h_nodeid; |
| 243 | inlen = rc_in->rc_header.h_length - sizeof(struct dlm_rcom); |
David Teigland | 68c817a | 2007-01-09 09:41:48 -0600 | [diff] [blame] | 244 | outlen = dlm_config.ci_buffer_size - sizeof(struct dlm_rcom); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 245 | |
| 246 | error = create_rcom(ls, nodeid, DLM_RCOM_NAMES_REPLY, outlen, &rc, &mh); |
| 247 | if (error) |
| 248 | return; |
David Teigland | 4a99c3d | 2006-08-09 11:20:15 -0500 | [diff] [blame] | 249 | rc->rc_id = rc_in->rc_id; |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 250 | rc->rc_seq_reply = rc_in->rc_seq; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 251 | |
| 252 | dlm_copy_master_names(ls, rc_in->rc_buf, inlen, rc->rc_buf, outlen, |
| 253 | nodeid); |
| 254 | send_rcom(ls, mh, rc); |
| 255 | } |
| 256 | |
| 257 | static void receive_rcom_names_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) |
| 258 | { |
David Teigland | 4a99c3d | 2006-08-09 11:20:15 -0500 | [diff] [blame] | 259 | receive_sync_reply(ls, rc_in); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | int dlm_send_rcom_lookup(struct dlm_rsb *r, int dir_nodeid) |
| 263 | { |
| 264 | struct dlm_rcom *rc; |
| 265 | struct dlm_mhandle *mh; |
| 266 | struct dlm_ls *ls = r->res_ls; |
| 267 | int error; |
| 268 | |
| 269 | error = create_rcom(ls, dir_nodeid, DLM_RCOM_LOOKUP, r->res_length, |
| 270 | &rc, &mh); |
| 271 | if (error) |
| 272 | goto out; |
| 273 | memcpy(rc->rc_buf, r->res_name, r->res_length); |
| 274 | rc->rc_id = (unsigned long) r; |
| 275 | |
| 276 | send_rcom(ls, mh, rc); |
| 277 | out: |
| 278 | return error; |
| 279 | } |
| 280 | |
| 281 | static void receive_rcom_lookup(struct dlm_ls *ls, struct dlm_rcom *rc_in) |
| 282 | { |
| 283 | struct dlm_rcom *rc; |
| 284 | struct dlm_mhandle *mh; |
| 285 | int error, ret_nodeid, nodeid = rc_in->rc_header.h_nodeid; |
| 286 | int len = rc_in->rc_header.h_length - sizeof(struct dlm_rcom); |
| 287 | |
| 288 | error = create_rcom(ls, nodeid, DLM_RCOM_LOOKUP_REPLY, 0, &rc, &mh); |
| 289 | if (error) |
| 290 | return; |
| 291 | |
| 292 | error = dlm_dir_lookup(ls, nodeid, rc_in->rc_buf, len, &ret_nodeid); |
| 293 | if (error) |
| 294 | ret_nodeid = error; |
| 295 | rc->rc_result = ret_nodeid; |
| 296 | rc->rc_id = rc_in->rc_id; |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 297 | rc->rc_seq_reply = rc_in->rc_seq; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 298 | |
| 299 | send_rcom(ls, mh, rc); |
| 300 | } |
| 301 | |
| 302 | static void receive_rcom_lookup_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) |
| 303 | { |
| 304 | dlm_recover_master_reply(ls, rc_in); |
| 305 | } |
| 306 | |
| 307 | static void pack_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb, |
| 308 | struct rcom_lock *rl) |
| 309 | { |
| 310 | memset(rl, 0, sizeof(*rl)); |
| 311 | |
| 312 | rl->rl_ownpid = lkb->lkb_ownpid; |
| 313 | rl->rl_lkid = lkb->lkb_id; |
| 314 | rl->rl_exflags = lkb->lkb_exflags; |
| 315 | rl->rl_flags = lkb->lkb_flags; |
| 316 | rl->rl_lvbseq = lkb->lkb_lvbseq; |
| 317 | rl->rl_rqmode = lkb->lkb_rqmode; |
| 318 | rl->rl_grmode = lkb->lkb_grmode; |
| 319 | rl->rl_status = lkb->lkb_status; |
| 320 | rl->rl_wait_type = lkb->lkb_wait_type; |
| 321 | |
| 322 | if (lkb->lkb_bastaddr) |
| 323 | rl->rl_asts |= AST_BAST; |
| 324 | if (lkb->lkb_astaddr) |
| 325 | rl->rl_asts |= AST_COMP; |
| 326 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 327 | rl->rl_namelen = r->res_length; |
| 328 | memcpy(rl->rl_name, r->res_name, r->res_length); |
| 329 | |
| 330 | /* FIXME: might we have an lvb without DLM_LKF_VALBLK set ? |
| 331 | If so, receive_rcom_lock_args() won't take this copy. */ |
| 332 | |
| 333 | if (lkb->lkb_lvbptr) |
| 334 | memcpy(rl->rl_lvb, lkb->lkb_lvbptr, r->res_ls->ls_lvblen); |
| 335 | } |
| 336 | |
| 337 | int dlm_send_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) |
| 338 | { |
| 339 | struct dlm_ls *ls = r->res_ls; |
| 340 | struct dlm_rcom *rc; |
| 341 | struct dlm_mhandle *mh; |
| 342 | struct rcom_lock *rl; |
| 343 | int error, len = sizeof(struct rcom_lock); |
| 344 | |
| 345 | if (lkb->lkb_lvbptr) |
| 346 | len += ls->ls_lvblen; |
| 347 | |
| 348 | error = create_rcom(ls, r->res_nodeid, DLM_RCOM_LOCK, len, &rc, &mh); |
| 349 | if (error) |
| 350 | goto out; |
| 351 | |
| 352 | rl = (struct rcom_lock *) rc->rc_buf; |
| 353 | pack_rcom_lock(r, lkb, rl); |
| 354 | rc->rc_id = (unsigned long) r; |
| 355 | |
| 356 | send_rcom(ls, mh, rc); |
| 357 | out: |
| 358 | return error; |
| 359 | } |
| 360 | |
| 361 | static void receive_rcom_lock(struct dlm_ls *ls, struct dlm_rcom *rc_in) |
| 362 | { |
| 363 | struct dlm_rcom *rc; |
| 364 | struct dlm_mhandle *mh; |
| 365 | int error, nodeid = rc_in->rc_header.h_nodeid; |
| 366 | |
| 367 | dlm_recover_master_copy(ls, rc_in); |
| 368 | |
| 369 | error = create_rcom(ls, nodeid, DLM_RCOM_LOCK_REPLY, |
| 370 | sizeof(struct rcom_lock), &rc, &mh); |
| 371 | if (error) |
| 372 | return; |
| 373 | |
| 374 | /* We send back the same rcom_lock struct we received, but |
| 375 | dlm_recover_master_copy() has filled in rl_remid and rl_result */ |
| 376 | |
| 377 | memcpy(rc->rc_buf, rc_in->rc_buf, sizeof(struct rcom_lock)); |
| 378 | rc->rc_id = rc_in->rc_id; |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 379 | rc->rc_seq_reply = rc_in->rc_seq; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 380 | |
| 381 | send_rcom(ls, mh, rc); |
| 382 | } |
| 383 | |
| 384 | static void receive_rcom_lock_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) |
| 385 | { |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 386 | dlm_recover_process_copy(ls, rc_in); |
| 387 | } |
| 388 | |
Patrick Caulfield | 44f487a | 2007-06-06 09:21:22 -0500 | [diff] [blame] | 389 | static int send_ls_not_ready(struct dlm_ls *ls, int nodeid, |
| 390 | struct dlm_rcom *rc_in) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 391 | { |
| 392 | struct dlm_rcom *rc; |
David Teigland | 1babdb4 | 2006-11-27 13:18:41 -0600 | [diff] [blame] | 393 | struct rcom_config *rf; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 394 | struct dlm_mhandle *mh; |
| 395 | char *mb; |
David Teigland | 1babdb4 | 2006-11-27 13:18:41 -0600 | [diff] [blame] | 396 | int mb_len = sizeof(struct dlm_rcom) + sizeof(struct rcom_config); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 397 | |
Patrick Caulfield | 44f487a | 2007-06-06 09:21:22 -0500 | [diff] [blame] | 398 | mh = dlm_lowcomms_get_buffer(nodeid, mb_len, ls->ls_allocation, &mb); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 399 | if (!mh) |
| 400 | return -ENOBUFS; |
| 401 | memset(mb, 0, mb_len); |
| 402 | |
| 403 | rc = (struct dlm_rcom *) mb; |
| 404 | |
| 405 | rc->rc_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR); |
| 406 | rc->rc_header.h_lockspace = rc_in->rc_header.h_lockspace; |
| 407 | rc->rc_header.h_nodeid = dlm_our_nodeid(); |
| 408 | rc->rc_header.h_length = mb_len; |
| 409 | rc->rc_header.h_cmd = DLM_RCOM; |
| 410 | |
| 411 | rc->rc_type = DLM_RCOM_STATUS_REPLY; |
David Teigland | f588875 | 2006-08-23 12:50:54 -0500 | [diff] [blame] | 412 | rc->rc_id = rc_in->rc_id; |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 413 | rc->rc_seq_reply = rc_in->rc_seq; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 414 | rc->rc_result = -ESRCH; |
| 415 | |
David Teigland | 1babdb4 | 2006-11-27 13:18:41 -0600 | [diff] [blame] | 416 | rf = (struct rcom_config *) rc->rc_buf; |
| 417 | rf->rf_lvblen = -1; |
| 418 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 419 | dlm_rcom_out(rc); |
| 420 | dlm_lowcomms_commit_buffer(mh); |
| 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 425 | static int is_old_reply(struct dlm_ls *ls, struct dlm_rcom *rc) |
| 426 | { |
| 427 | uint64_t seq; |
| 428 | int rv = 0; |
| 429 | |
| 430 | switch (rc->rc_type) { |
| 431 | case DLM_RCOM_STATUS_REPLY: |
| 432 | case DLM_RCOM_NAMES_REPLY: |
| 433 | case DLM_RCOM_LOOKUP_REPLY: |
| 434 | case DLM_RCOM_LOCK_REPLY: |
| 435 | spin_lock(&ls->ls_recover_lock); |
| 436 | seq = ls->ls_recover_seq; |
| 437 | spin_unlock(&ls->ls_recover_lock); |
| 438 | if (rc->rc_seq_reply != seq) { |
David Teigland | 8ec6886 | 2007-01-09 09:38:39 -0600 | [diff] [blame] | 439 | log_debug(ls, "ignoring old reply %x from %d " |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 440 | "seq_reply %llx expect %llx", |
| 441 | rc->rc_type, rc->rc_header.h_nodeid, |
| 442 | (unsigned long long)rc->rc_seq_reply, |
| 443 | (unsigned long long)seq); |
| 444 | rv = 1; |
| 445 | } |
| 446 | } |
| 447 | return rv; |
| 448 | } |
| 449 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 450 | /* Called by dlm_recvd; corresponds to dlm_receive_message() but special |
| 451 | recovery-only comms are sent through here. */ |
| 452 | |
| 453 | void dlm_receive_rcom(struct dlm_header *hd, int nodeid) |
| 454 | { |
| 455 | struct dlm_rcom *rc = (struct dlm_rcom *) hd; |
| 456 | struct dlm_ls *ls; |
| 457 | |
| 458 | dlm_rcom_in(rc); |
| 459 | |
| 460 | /* If the lockspace doesn't exist then still send a status message |
| 461 | back; it's possible that it just doesn't have its global_id yet. */ |
| 462 | |
| 463 | ls = dlm_find_lockspace_global(hd->h_lockspace); |
| 464 | if (!ls) { |
David Teigland | 435618b | 2006-11-02 09:45:56 -0600 | [diff] [blame] | 465 | log_print("lockspace %x from %d type %x not found", |
| 466 | hd->h_lockspace, nodeid, rc->rc_type); |
| 467 | if (rc->rc_type == DLM_RCOM_STATUS) |
Patrick Caulfield | 44f487a | 2007-06-06 09:21:22 -0500 | [diff] [blame] | 468 | send_ls_not_ready(ls, nodeid, rc); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 469 | return; |
| 470 | } |
| 471 | |
| 472 | if (dlm_recovery_stopped(ls) && (rc->rc_type != DLM_RCOM_STATUS)) { |
David Teigland | 8ec6886 | 2007-01-09 09:38:39 -0600 | [diff] [blame] | 473 | log_debug(ls, "ignoring recovery message %x from %d", |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 474 | rc->rc_type, nodeid); |
| 475 | goto out; |
| 476 | } |
| 477 | |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 478 | if (is_old_reply(ls, rc)) |
| 479 | goto out; |
| 480 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 481 | if (nodeid != rc->rc_header.h_nodeid) { |
| 482 | log_error(ls, "bad rcom nodeid %d from %d", |
| 483 | rc->rc_header.h_nodeid, nodeid); |
| 484 | goto out; |
| 485 | } |
| 486 | |
| 487 | switch (rc->rc_type) { |
| 488 | case DLM_RCOM_STATUS: |
| 489 | receive_rcom_status(ls, rc); |
| 490 | break; |
| 491 | |
| 492 | case DLM_RCOM_NAMES: |
| 493 | receive_rcom_names(ls, rc); |
| 494 | break; |
| 495 | |
| 496 | case DLM_RCOM_LOOKUP: |
| 497 | receive_rcom_lookup(ls, rc); |
| 498 | break; |
| 499 | |
| 500 | case DLM_RCOM_LOCK: |
| 501 | receive_rcom_lock(ls, rc); |
| 502 | break; |
| 503 | |
| 504 | case DLM_RCOM_STATUS_REPLY: |
| 505 | receive_rcom_status_reply(ls, rc); |
| 506 | break; |
| 507 | |
| 508 | case DLM_RCOM_NAMES_REPLY: |
| 509 | receive_rcom_names_reply(ls, rc); |
| 510 | break; |
| 511 | |
| 512 | case DLM_RCOM_LOOKUP_REPLY: |
| 513 | receive_rcom_lookup_reply(ls, rc); |
| 514 | break; |
| 515 | |
| 516 | case DLM_RCOM_LOCK_REPLY: |
| 517 | receive_rcom_lock_reply(ls, rc); |
| 518 | break; |
| 519 | |
| 520 | default: |
| 521 | DLM_ASSERT(0, printk("rc_type=%x\n", rc->rc_type);); |
| 522 | } |
| 523 | out: |
| 524 | dlm_put_lockspace(ls); |
| 525 | } |
| 526 | |