Thomas Gleixner | 2522fe4 | 2019-05-28 09:57:20 -0700 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | ******************************************************************************* |
| 4 | ** |
| 5 | ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
David Teigland | dbcfc34 | 2008-01-29 14:52:10 -0600 | [diff] [blame] | 6 | ** Copyright (C) 2005-2008 Red Hat, Inc. All rights reserved. |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 7 | ** |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 8 | ** |
| 9 | ******************************************************************************* |
| 10 | ******************************************************************************/ |
| 11 | |
| 12 | #include "dlm_internal.h" |
| 13 | #include "lockspace.h" |
| 14 | #include "member.h" |
| 15 | #include "lowcomms.h" |
| 16 | #include "midcomms.h" |
| 17 | #include "rcom.h" |
| 18 | #include "recover.h" |
| 19 | #include "dir.h" |
| 20 | #include "config.h" |
| 21 | #include "memory.h" |
| 22 | #include "lock.h" |
| 23 | #include "util.h" |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 24 | |
| 25 | static int rcom_response(struct dlm_ls *ls) |
| 26 | { |
| 27 | return test_bit(LSFL_RCOM_READY, &ls->ls_flags); |
| 28 | } |
| 29 | |
| 30 | static int create_rcom(struct dlm_ls *ls, int to_nodeid, int type, int len, |
| 31 | struct dlm_rcom **rc_ret, struct dlm_mhandle **mh_ret) |
| 32 | { |
| 33 | struct dlm_rcom *rc; |
| 34 | struct dlm_mhandle *mh; |
| 35 | char *mb; |
| 36 | int mb_len = sizeof(struct dlm_rcom) + len; |
| 37 | |
David Teigland | 573c24c | 2009-11-30 16:34:43 -0600 | [diff] [blame] | 38 | mh = dlm_lowcomms_get_buffer(to_nodeid, mb_len, GFP_NOFS, &mb); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 39 | if (!mh) { |
| 40 | log_print("create_rcom to %d type %d len %d ENOBUFS", |
| 41 | to_nodeid, type, len); |
| 42 | return -ENOBUFS; |
| 43 | } |
| 44 | memset(mb, 0, mb_len); |
| 45 | |
| 46 | rc = (struct dlm_rcom *) mb; |
| 47 | |
| 48 | rc->rc_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR); |
| 49 | rc->rc_header.h_lockspace = ls->ls_global_id; |
| 50 | rc->rc_header.h_nodeid = dlm_our_nodeid(); |
| 51 | rc->rc_header.h_length = mb_len; |
| 52 | rc->rc_header.h_cmd = DLM_RCOM; |
| 53 | |
| 54 | rc->rc_type = type; |
| 55 | |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 56 | spin_lock(&ls->ls_recover_lock); |
| 57 | rc->rc_seq = ls->ls_recover_seq; |
| 58 | spin_unlock(&ls->ls_recover_lock); |
| 59 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 60 | *mh_ret = mh; |
| 61 | *rc_ret = rc; |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static void send_rcom(struct dlm_ls *ls, struct dlm_mhandle *mh, |
| 66 | struct dlm_rcom *rc) |
| 67 | { |
| 68 | dlm_rcom_out(rc); |
| 69 | dlm_lowcomms_commit_buffer(mh); |
| 70 | } |
| 71 | |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 72 | static void set_rcom_status(struct dlm_ls *ls, struct rcom_status *rs, |
| 73 | uint32_t flags) |
| 74 | { |
| 75 | rs->rs_flags = cpu_to_le32(flags); |
| 76 | } |
| 77 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 78 | /* When replying to a status request, a node also sends back its |
| 79 | configuration values. The requesting node then checks that the remote |
| 80 | node is configured the same way as itself. */ |
| 81 | |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 82 | static void set_rcom_config(struct dlm_ls *ls, struct rcom_config *rf, |
| 83 | uint32_t num_slots) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 84 | { |
Al Viro | 93ff297 | 2008-01-25 02:34:00 -0500 | [diff] [blame] | 85 | rf->rf_lvblen = cpu_to_le32(ls->ls_lvblen); |
| 86 | rf->rf_lsflags = cpu_to_le32(ls->ls_exflags); |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 87 | |
| 88 | rf->rf_our_slot = cpu_to_le16(ls->ls_slot); |
| 89 | rf->rf_num_slots = cpu_to_le16(num_slots); |
| 90 | rf->rf_generation = cpu_to_le32(ls->ls_generation); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 91 | } |
| 92 | |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 93 | static int check_rcom_config(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 94 | { |
David Teigland | 9e971b7 | 2006-12-13 10:37:55 -0600 | [diff] [blame] | 95 | struct rcom_config *rf = (struct rcom_config *) rc->rc_buf; |
| 96 | |
| 97 | if ((rc->rc_header.h_version & 0xFFFF0000) != DLM_HEADER_MAJOR) { |
| 98 | log_error(ls, "version mismatch: %x nodeid %d: %x", |
| 99 | DLM_HEADER_MAJOR | DLM_HEADER_MINOR, nodeid, |
| 100 | rc->rc_header.h_version); |
David Teigland | 8b0e7b2 | 2007-05-18 09:03:35 -0500 | [diff] [blame] | 101 | return -EPROTO; |
David Teigland | 9e971b7 | 2006-12-13 10:37:55 -0600 | [diff] [blame] | 102 | } |
| 103 | |
Al Viro | 93ff297 | 2008-01-25 02:34:00 -0500 | [diff] [blame] | 104 | if (le32_to_cpu(rf->rf_lvblen) != ls->ls_lvblen || |
| 105 | le32_to_cpu(rf->rf_lsflags) != ls->ls_exflags) { |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 106 | log_error(ls, "config mismatch: %d,%x nodeid %d: %d,%x", |
Al Viro | 93ff297 | 2008-01-25 02:34:00 -0500 | [diff] [blame] | 107 | ls->ls_lvblen, ls->ls_exflags, nodeid, |
| 108 | le32_to_cpu(rf->rf_lvblen), |
| 109 | le32_to_cpu(rf->rf_lsflags)); |
David Teigland | 8b0e7b2 | 2007-05-18 09:03:35 -0500 | [diff] [blame] | 110 | return -EPROTO; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 111 | } |
| 112 | return 0; |
| 113 | } |
| 114 | |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 115 | static void allow_sync_reply(struct dlm_ls *ls, uint64_t *new_seq) |
| 116 | { |
| 117 | spin_lock(&ls->ls_rcom_spin); |
| 118 | *new_seq = ++ls->ls_rcom_seq; |
| 119 | set_bit(LSFL_RCOM_WAIT, &ls->ls_flags); |
| 120 | spin_unlock(&ls->ls_rcom_spin); |
| 121 | } |
| 122 | |
| 123 | static void disallow_sync_reply(struct dlm_ls *ls) |
| 124 | { |
| 125 | spin_lock(&ls->ls_rcom_spin); |
| 126 | clear_bit(LSFL_RCOM_WAIT, &ls->ls_flags); |
| 127 | clear_bit(LSFL_RCOM_READY, &ls->ls_flags); |
| 128 | spin_unlock(&ls->ls_rcom_spin); |
| 129 | } |
| 130 | |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 131 | /* |
| 132 | * low nodeid gathers one slot value at a time from each node. |
| 133 | * it sets need_slots=0, and saves rf_our_slot returned from each |
| 134 | * rcom_config. |
| 135 | * |
| 136 | * other nodes gather all slot values at once from the low nodeid. |
| 137 | * they set need_slots=1, and ignore the rf_our_slot returned from each |
| 138 | * rcom_config. they use the rf_num_slots returned from the low |
| 139 | * node's rcom_config. |
| 140 | */ |
| 141 | |
| 142 | int dlm_rcom_status(struct dlm_ls *ls, int nodeid, uint32_t status_flags) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 143 | { |
| 144 | struct dlm_rcom *rc; |
| 145 | struct dlm_mhandle *mh; |
| 146 | int error = 0; |
| 147 | |
David Teigland | faa0f26 | 2006-08-08 17:08:42 -0500 | [diff] [blame] | 148 | ls->ls_recover_nodeid = nodeid; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 149 | |
| 150 | if (nodeid == dlm_our_nodeid()) { |
Al Viro | 4007685 | 2008-01-25 03:01:51 -0500 | [diff] [blame] | 151 | rc = ls->ls_recover_buf; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 152 | rc->rc_result = dlm_recover_status(ls); |
| 153 | goto out; |
| 154 | } |
| 155 | |
tsutomu.owa@toshiba.co.jp | 5966121 | 2017-09-12 08:56:08 +0000 | [diff] [blame] | 156 | retry: |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 157 | error = create_rcom(ls, nodeid, DLM_RCOM_STATUS, |
| 158 | sizeof(struct rcom_status), &rc, &mh); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 159 | if (error) |
| 160 | goto out; |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 161 | |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 162 | set_rcom_status(ls, (struct rcom_status *)rc->rc_buf, status_flags); |
| 163 | |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 164 | allow_sync_reply(ls, &rc->rc_id); |
David Teigland | 68c817a | 2007-01-09 09:41:48 -0600 | [diff] [blame] | 165 | memset(ls->ls_recover_buf, 0, dlm_config.ci_buffer_size); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 166 | |
| 167 | send_rcom(ls, mh, rc); |
| 168 | |
| 169 | error = dlm_wait_function(ls, &rcom_response); |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 170 | disallow_sync_reply(ls); |
tsutomu.owa@toshiba.co.jp | 5966121 | 2017-09-12 08:56:08 +0000 | [diff] [blame] | 171 | if (error == -ETIMEDOUT) |
| 172 | goto retry; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 173 | if (error) |
| 174 | goto out; |
| 175 | |
Al Viro | 4007685 | 2008-01-25 03:01:51 -0500 | [diff] [blame] | 176 | rc = ls->ls_recover_buf; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 177 | |
| 178 | if (rc->rc_result == -ESRCH) { |
| 179 | /* we pretend the remote lockspace exists with 0 status */ |
| 180 | log_debug(ls, "remote node %d not ready", nodeid); |
| 181 | rc->rc_result = 0; |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 182 | error = 0; |
| 183 | } else { |
| 184 | error = check_rcom_config(ls, rc, nodeid); |
| 185 | } |
| 186 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 187 | /* the caller looks at rc_result for the remote recovery status */ |
| 188 | out: |
| 189 | return error; |
| 190 | } |
| 191 | |
| 192 | static void receive_rcom_status(struct dlm_ls *ls, struct dlm_rcom *rc_in) |
| 193 | { |
| 194 | struct dlm_rcom *rc; |
| 195 | struct dlm_mhandle *mh; |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 196 | struct rcom_status *rs; |
| 197 | uint32_t status; |
| 198 | int nodeid = rc_in->rc_header.h_nodeid; |
| 199 | int len = sizeof(struct rcom_config); |
| 200 | int num_slots = 0; |
| 201 | int error; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 202 | |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 203 | if (!dlm_slots_version(&rc_in->rc_header)) { |
| 204 | status = dlm_recover_status(ls); |
| 205 | goto do_create; |
| 206 | } |
| 207 | |
| 208 | rs = (struct rcom_status *)rc_in->rc_buf; |
| 209 | |
Neale Ferguson | c07127b | 2014-10-14 15:10:48 -0500 | [diff] [blame] | 210 | if (!(le32_to_cpu(rs->rs_flags) & DLM_RSF_NEED_SLOTS)) { |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 211 | status = dlm_recover_status(ls); |
| 212 | goto do_create; |
| 213 | } |
| 214 | |
| 215 | spin_lock(&ls->ls_recover_lock); |
| 216 | status = ls->ls_recover_status; |
| 217 | num_slots = ls->ls_num_slots; |
| 218 | spin_unlock(&ls->ls_recover_lock); |
| 219 | len += num_slots * sizeof(struct rcom_slot); |
| 220 | |
| 221 | do_create: |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 222 | error = create_rcom(ls, nodeid, DLM_RCOM_STATUS_REPLY, |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 223 | len, &rc, &mh); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 224 | if (error) |
| 225 | return; |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 226 | |
David Teigland | 4a99c3d | 2006-08-09 11:20:15 -0500 | [diff] [blame] | 227 | rc->rc_id = rc_in->rc_id; |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 228 | rc->rc_seq_reply = rc_in->rc_seq; |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 229 | rc->rc_result = status; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 230 | |
David Teigland | 757a427 | 2011-10-20 13:26:28 -0500 | [diff] [blame] | 231 | set_rcom_config(ls, (struct rcom_config *)rc->rc_buf, num_slots); |
| 232 | |
| 233 | if (!num_slots) |
| 234 | goto do_send; |
| 235 | |
| 236 | spin_lock(&ls->ls_recover_lock); |
| 237 | if (ls->ls_num_slots != num_slots) { |
| 238 | spin_unlock(&ls->ls_recover_lock); |
| 239 | log_debug(ls, "receive_rcom_status num_slots %d to %d", |
| 240 | num_slots, ls->ls_num_slots); |
| 241 | rc->rc_result = 0; |
| 242 | set_rcom_config(ls, (struct rcom_config *)rc->rc_buf, 0); |
| 243 | goto do_send; |
| 244 | } |
| 245 | |
| 246 | dlm_slots_copy_out(ls, rc); |
| 247 | spin_unlock(&ls->ls_recover_lock); |
| 248 | |
| 249 | do_send: |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 250 | send_rcom(ls, mh, rc); |
| 251 | } |
| 252 | |
David Teigland | 4a99c3d | 2006-08-09 11:20:15 -0500 | [diff] [blame] | 253 | 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] | 254 | { |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 255 | spin_lock(&ls->ls_rcom_spin); |
| 256 | if (!test_bit(LSFL_RCOM_WAIT, &ls->ls_flags) || |
| 257 | rc_in->rc_id != ls->ls_rcom_seq) { |
| 258 | log_debug(ls, "reject reply %d from %d seq %llx expect %llx", |
| 259 | rc_in->rc_type, rc_in->rc_header.h_nodeid, |
Ryusuke Konishi | 57adf7e | 2006-11-29 09:33:48 -0500 | [diff] [blame] | 260 | (unsigned long long)rc_in->rc_id, |
| 261 | (unsigned long long)ls->ls_rcom_seq); |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 262 | goto out; |
David Teigland | 4a99c3d | 2006-08-09 11:20:15 -0500 | [diff] [blame] | 263 | } |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 264 | memcpy(ls->ls_recover_buf, rc_in, rc_in->rc_header.h_length); |
| 265 | set_bit(LSFL_RCOM_READY, &ls->ls_flags); |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 266 | clear_bit(LSFL_RCOM_WAIT, &ls->ls_flags); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 267 | wake_up(&ls->ls_wait_general); |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 268 | out: |
| 269 | spin_unlock(&ls->ls_rcom_spin); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name, int last_len) |
| 273 | { |
| 274 | struct dlm_rcom *rc; |
| 275 | struct dlm_mhandle *mh; |
Al Viro | 4007685 | 2008-01-25 03:01:51 -0500 | [diff] [blame] | 276 | int error = 0; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 277 | |
David Teigland | faa0f26 | 2006-08-08 17:08:42 -0500 | [diff] [blame] | 278 | ls->ls_recover_nodeid = nodeid; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 279 | |
tsutomu.owa@toshiba.co.jp | 5966121 | 2017-09-12 08:56:08 +0000 | [diff] [blame] | 280 | retry: |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 281 | error = create_rcom(ls, nodeid, DLM_RCOM_NAMES, last_len, &rc, &mh); |
| 282 | if (error) |
| 283 | goto out; |
| 284 | memcpy(rc->rc_buf, last_name, last_len); |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 285 | |
| 286 | allow_sync_reply(ls, &rc->rc_id); |
David Teigland | 68c817a | 2007-01-09 09:41:48 -0600 | [diff] [blame] | 287 | memset(ls->ls_recover_buf, 0, dlm_config.ci_buffer_size); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 288 | |
| 289 | send_rcom(ls, mh, rc); |
| 290 | |
| 291 | error = dlm_wait_function(ls, &rcom_response); |
David Teigland | 98f176f | 2006-11-27 13:19:28 -0600 | [diff] [blame] | 292 | disallow_sync_reply(ls); |
tsutomu.owa@toshiba.co.jp | 5966121 | 2017-09-12 08:56:08 +0000 | [diff] [blame] | 293 | if (error == -ETIMEDOUT) |
| 294 | goto retry; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 295 | out: |
| 296 | return error; |
| 297 | } |
| 298 | |
| 299 | static void receive_rcom_names(struct dlm_ls *ls, struct dlm_rcom *rc_in) |
| 300 | { |
| 301 | struct dlm_rcom *rc; |
| 302 | struct dlm_mhandle *mh; |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 303 | int error, inlen, outlen, nodeid; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 304 | |
| 305 | nodeid = rc_in->rc_header.h_nodeid; |
| 306 | inlen = rc_in->rc_header.h_length - sizeof(struct dlm_rcom); |
David Teigland | 68c817a | 2007-01-09 09:41:48 -0600 | [diff] [blame] | 307 | outlen = dlm_config.ci_buffer_size - sizeof(struct dlm_rcom); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 308 | |
| 309 | error = create_rcom(ls, nodeid, DLM_RCOM_NAMES_REPLY, outlen, &rc, &mh); |
| 310 | if (error) |
| 311 | return; |
David Teigland | 4a99c3d | 2006-08-09 11:20:15 -0500 | [diff] [blame] | 312 | rc->rc_id = rc_in->rc_id; |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 313 | rc->rc_seq_reply = rc_in->rc_seq; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 314 | |
| 315 | dlm_copy_master_names(ls, rc_in->rc_buf, inlen, rc->rc_buf, outlen, |
| 316 | nodeid); |
| 317 | send_rcom(ls, mh, rc); |
| 318 | } |
| 319 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 320 | int dlm_send_rcom_lookup(struct dlm_rsb *r, int dir_nodeid) |
| 321 | { |
| 322 | struct dlm_rcom *rc; |
| 323 | struct dlm_mhandle *mh; |
| 324 | struct dlm_ls *ls = r->res_ls; |
| 325 | int error; |
| 326 | |
| 327 | error = create_rcom(ls, dir_nodeid, DLM_RCOM_LOOKUP, r->res_length, |
| 328 | &rc, &mh); |
| 329 | if (error) |
| 330 | goto out; |
| 331 | memcpy(rc->rc_buf, r->res_name, r->res_length); |
David Teigland | 1d7c484 | 2012-05-15 16:07:49 -0500 | [diff] [blame] | 332 | rc->rc_id = (unsigned long) r->res_id; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 333 | |
| 334 | send_rcom(ls, mh, rc); |
| 335 | out: |
| 336 | return error; |
| 337 | } |
| 338 | |
| 339 | static void receive_rcom_lookup(struct dlm_ls *ls, struct dlm_rcom *rc_in) |
| 340 | { |
| 341 | struct dlm_rcom *rc; |
| 342 | struct dlm_mhandle *mh; |
| 343 | int error, ret_nodeid, nodeid = rc_in->rc_header.h_nodeid; |
| 344 | int len = rc_in->rc_header.h_length - sizeof(struct dlm_rcom); |
| 345 | |
| 346 | error = create_rcom(ls, nodeid, DLM_RCOM_LOOKUP_REPLY, 0, &rc, &mh); |
| 347 | if (error) |
| 348 | return; |
| 349 | |
David Teigland | 9250e52 | 2017-10-09 09:29:31 -0500 | [diff] [blame] | 350 | /* Old code would send this special id to trigger a debug dump. */ |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 351 | if (rc_in->rc_id == 0xFFFFFFFF) { |
| 352 | log_error(ls, "receive_rcom_lookup dump from %d", nodeid); |
| 353 | dlm_dump_rsb_name(ls, rc_in->rc_buf, len); |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | error = dlm_master_lookup(ls, nodeid, rc_in->rc_buf, len, |
| 358 | DLM_LU_RECOVER_MASTER, &ret_nodeid, NULL); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 359 | if (error) |
| 360 | ret_nodeid = error; |
| 361 | rc->rc_result = ret_nodeid; |
| 362 | rc->rc_id = rc_in->rc_id; |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 363 | rc->rc_seq_reply = rc_in->rc_seq; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 364 | |
| 365 | send_rcom(ls, mh, rc); |
| 366 | } |
| 367 | |
| 368 | static void receive_rcom_lookup_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) |
| 369 | { |
| 370 | dlm_recover_master_reply(ls, rc_in); |
| 371 | } |
| 372 | |
| 373 | static void pack_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb, |
| 374 | struct rcom_lock *rl) |
| 375 | { |
| 376 | memset(rl, 0, sizeof(*rl)); |
| 377 | |
Al Viro | 163a185 | 2008-01-25 02:08:26 -0500 | [diff] [blame] | 378 | rl->rl_ownpid = cpu_to_le32(lkb->lkb_ownpid); |
| 379 | rl->rl_lkid = cpu_to_le32(lkb->lkb_id); |
| 380 | rl->rl_exflags = cpu_to_le32(lkb->lkb_exflags); |
| 381 | rl->rl_flags = cpu_to_le32(lkb->lkb_flags); |
| 382 | rl->rl_lvbseq = cpu_to_le32(lkb->lkb_lvbseq); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 383 | rl->rl_rqmode = lkb->lkb_rqmode; |
| 384 | rl->rl_grmode = lkb->lkb_grmode; |
| 385 | rl->rl_status = lkb->lkb_status; |
Al Viro | 163a185 | 2008-01-25 02:08:26 -0500 | [diff] [blame] | 386 | rl->rl_wait_type = cpu_to_le16(lkb->lkb_wait_type); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 387 | |
David Teigland | e5dae54 | 2008-02-06 00:35:45 -0600 | [diff] [blame] | 388 | if (lkb->lkb_bastfn) |
David Teigland | 8304d6f | 2011-02-21 14:58:21 -0600 | [diff] [blame] | 389 | rl->rl_asts |= DLM_CB_BAST; |
David Teigland | e5dae54 | 2008-02-06 00:35:45 -0600 | [diff] [blame] | 390 | if (lkb->lkb_astfn) |
David Teigland | 8304d6f | 2011-02-21 14:58:21 -0600 | [diff] [blame] | 391 | rl->rl_asts |= DLM_CB_CAST; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 392 | |
Al Viro | 163a185 | 2008-01-25 02:08:26 -0500 | [diff] [blame] | 393 | rl->rl_namelen = cpu_to_le16(r->res_length); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 394 | memcpy(rl->rl_name, r->res_name, r->res_length); |
| 395 | |
| 396 | /* FIXME: might we have an lvb without DLM_LKF_VALBLK set ? |
| 397 | If so, receive_rcom_lock_args() won't take this copy. */ |
| 398 | |
| 399 | if (lkb->lkb_lvbptr) |
| 400 | memcpy(rl->rl_lvb, lkb->lkb_lvbptr, r->res_ls->ls_lvblen); |
| 401 | } |
| 402 | |
| 403 | int dlm_send_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) |
| 404 | { |
| 405 | struct dlm_ls *ls = r->res_ls; |
| 406 | struct dlm_rcom *rc; |
| 407 | struct dlm_mhandle *mh; |
| 408 | struct rcom_lock *rl; |
| 409 | int error, len = sizeof(struct rcom_lock); |
| 410 | |
| 411 | if (lkb->lkb_lvbptr) |
| 412 | len += ls->ls_lvblen; |
| 413 | |
| 414 | error = create_rcom(ls, r->res_nodeid, DLM_RCOM_LOCK, len, &rc, &mh); |
| 415 | if (error) |
| 416 | goto out; |
| 417 | |
| 418 | rl = (struct rcom_lock *) rc->rc_buf; |
| 419 | pack_rcom_lock(r, lkb, rl); |
| 420 | rc->rc_id = (unsigned long) r; |
| 421 | |
| 422 | send_rcom(ls, mh, rc); |
| 423 | out: |
| 424 | return error; |
| 425 | } |
| 426 | |
Al Viro | ae773d0 | 2008-01-25 19:55:09 -0500 | [diff] [blame] | 427 | /* needs at least dlm_rcom + rcom_lock */ |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 428 | static void receive_rcom_lock(struct dlm_ls *ls, struct dlm_rcom *rc_in) |
| 429 | { |
| 430 | struct dlm_rcom *rc; |
| 431 | struct dlm_mhandle *mh; |
| 432 | int error, nodeid = rc_in->rc_header.h_nodeid; |
| 433 | |
| 434 | dlm_recover_master_copy(ls, rc_in); |
| 435 | |
| 436 | error = create_rcom(ls, nodeid, DLM_RCOM_LOCK_REPLY, |
| 437 | sizeof(struct rcom_lock), &rc, &mh); |
| 438 | if (error) |
| 439 | return; |
| 440 | |
| 441 | /* We send back the same rcom_lock struct we received, but |
| 442 | dlm_recover_master_copy() has filled in rl_remid and rl_result */ |
| 443 | |
| 444 | memcpy(rc->rc_buf, rc_in->rc_buf, sizeof(struct rcom_lock)); |
| 445 | rc->rc_id = rc_in->rc_id; |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 446 | rc->rc_seq_reply = rc_in->rc_seq; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 447 | |
| 448 | send_rcom(ls, mh, rc); |
| 449 | } |
| 450 | |
David Teigland | c36258b | 2007-09-27 15:53:38 -0500 | [diff] [blame] | 451 | /* If the lockspace doesn't exist then still send a status message |
| 452 | back; it's possible that it just doesn't have its global_id yet. */ |
| 453 | |
| 454 | int dlm_send_ls_not_ready(int nodeid, struct dlm_rcom *rc_in) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 455 | { |
| 456 | struct dlm_rcom *rc; |
David Teigland | 1babdb4 | 2006-11-27 13:18:41 -0600 | [diff] [blame] | 457 | struct rcom_config *rf; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 458 | struct dlm_mhandle *mh; |
| 459 | char *mb; |
David Teigland | 1babdb4 | 2006-11-27 13:18:41 -0600 | [diff] [blame] | 460 | int mb_len = sizeof(struct dlm_rcom) + sizeof(struct rcom_config); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 461 | |
David Teigland | 41684f9 | 2007-07-13 14:49:06 -0500 | [diff] [blame] | 462 | mh = dlm_lowcomms_get_buffer(nodeid, mb_len, GFP_NOFS, &mb); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 463 | if (!mh) |
| 464 | return -ENOBUFS; |
| 465 | memset(mb, 0, mb_len); |
| 466 | |
| 467 | rc = (struct dlm_rcom *) mb; |
| 468 | |
| 469 | rc->rc_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR); |
| 470 | rc->rc_header.h_lockspace = rc_in->rc_header.h_lockspace; |
| 471 | rc->rc_header.h_nodeid = dlm_our_nodeid(); |
| 472 | rc->rc_header.h_length = mb_len; |
| 473 | rc->rc_header.h_cmd = DLM_RCOM; |
| 474 | |
| 475 | rc->rc_type = DLM_RCOM_STATUS_REPLY; |
David Teigland | f588875 | 2006-08-23 12:50:54 -0500 | [diff] [blame] | 476 | rc->rc_id = rc_in->rc_id; |
David Teigland | 38aa8b0 | 2006-12-13 10:37:16 -0600 | [diff] [blame] | 477 | rc->rc_seq_reply = rc_in->rc_seq; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 478 | rc->rc_result = -ESRCH; |
| 479 | |
David Teigland | 1babdb4 | 2006-11-27 13:18:41 -0600 | [diff] [blame] | 480 | rf = (struct rcom_config *) rc->rc_buf; |
Al Viro | 93ff297 | 2008-01-25 02:34:00 -0500 | [diff] [blame] | 481 | rf->rf_lvblen = cpu_to_le32(~0U); |
David Teigland | 1babdb4 | 2006-11-27 13:18:41 -0600 | [diff] [blame] | 482 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 483 | dlm_rcom_out(rc); |
| 484 | dlm_lowcomms_commit_buffer(mh); |
| 485 | |
| 486 | return 0; |
| 487 | } |
| 488 | |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 489 | /* |
| 490 | * Ignore messages for stage Y before we set |
| 491 | * recover_status bit for stage X: |
| 492 | * |
| 493 | * recover_status = 0 |
| 494 | * |
| 495 | * dlm_recover_members() |
| 496 | * - send nothing |
| 497 | * - recv nothing |
| 498 | * - ignore NAMES, NAMES_REPLY |
| 499 | * - ignore LOOKUP, LOOKUP_REPLY |
| 500 | * - ignore LOCK, LOCK_REPLY |
| 501 | * |
| 502 | * recover_status |= NODES |
| 503 | * |
| 504 | * dlm_recover_members_wait() |
| 505 | * |
| 506 | * dlm_recover_directory() |
| 507 | * - send NAMES |
| 508 | * - recv NAMES_REPLY |
| 509 | * - ignore LOOKUP, LOOKUP_REPLY |
| 510 | * - ignore LOCK, LOCK_REPLY |
| 511 | * |
| 512 | * recover_status |= DIR |
| 513 | * |
| 514 | * dlm_recover_directory_wait() |
| 515 | * |
| 516 | * dlm_recover_masters() |
| 517 | * - send LOOKUP |
| 518 | * - recv LOOKUP_REPLY |
| 519 | * |
| 520 | * dlm_recover_locks() |
| 521 | * - send LOCKS |
| 522 | * - recv LOCKS_REPLY |
| 523 | * |
| 524 | * recover_status |= LOCKS |
| 525 | * |
| 526 | * dlm_recover_locks_wait() |
| 527 | * |
| 528 | * recover_status |= DONE |
| 529 | */ |
| 530 | |
David Teigland | c36258b | 2007-09-27 15:53:38 -0500 | [diff] [blame] | 531 | /* Called by dlm_recv; corresponds to dlm_receive_message() but special |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 532 | recovery-only comms are sent through here. */ |
| 533 | |
David Teigland | c36258b | 2007-09-27 15:53:38 -0500 | [diff] [blame] | 534 | void dlm_receive_rcom(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 535 | { |
Al Viro | ae773d0 | 2008-01-25 19:55:09 -0500 | [diff] [blame] | 536 | int lock_size = sizeof(struct dlm_rcom) + sizeof(struct rcom_lock); |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 537 | int stop, reply = 0, names = 0, lookup = 0, lock = 0; |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 538 | uint32_t status; |
David Teigland | d6e2478 | 2012-04-23 13:58:42 -0500 | [diff] [blame] | 539 | uint64_t seq; |
Al Viro | ae773d0 | 2008-01-25 19:55:09 -0500 | [diff] [blame] | 540 | |
David Teigland | d6e2478 | 2012-04-23 13:58:42 -0500 | [diff] [blame] | 541 | switch (rc->rc_type) { |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 542 | case DLM_RCOM_STATUS_REPLY: |
| 543 | reply = 1; |
| 544 | break; |
| 545 | case DLM_RCOM_NAMES: |
| 546 | names = 1; |
| 547 | break; |
| 548 | case DLM_RCOM_NAMES_REPLY: |
| 549 | names = 1; |
| 550 | reply = 1; |
| 551 | break; |
| 552 | case DLM_RCOM_LOOKUP: |
| 553 | lookup = 1; |
| 554 | break; |
| 555 | case DLM_RCOM_LOOKUP_REPLY: |
| 556 | lookup = 1; |
| 557 | reply = 1; |
| 558 | break; |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 559 | case DLM_RCOM_LOCK: |
| 560 | lock = 1; |
| 561 | break; |
| 562 | case DLM_RCOM_LOCK_REPLY: |
| 563 | lock = 1; |
| 564 | reply = 1; |
| 565 | break; |
David Teigland | d6e2478 | 2012-04-23 13:58:42 -0500 | [diff] [blame] | 566 | }; |
| 567 | |
| 568 | spin_lock(&ls->ls_recover_lock); |
David Teigland | 4875647 | 2012-04-26 15:54:29 -0500 | [diff] [blame] | 569 | status = ls->ls_recover_status; |
David Teigland | 475f230 | 2012-08-02 11:08:21 -0500 | [diff] [blame] | 570 | stop = test_bit(LSFL_RECOVER_STOP, &ls->ls_flags); |
David Teigland | d6e2478 | 2012-04-23 13:58:42 -0500 | [diff] [blame] | 571 | seq = ls->ls_recover_seq; |
| 572 | spin_unlock(&ls->ls_recover_lock); |
| 573 | |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 574 | if (stop && (rc->rc_type != DLM_RCOM_STATUS)) |
| 575 | goto ignore; |
| 576 | |
| 577 | if (reply && (rc->rc_seq_reply != seq)) |
| 578 | goto ignore; |
| 579 | |
| 580 | if (!(status & DLM_RS_NODES) && (names || lookup || lock)) |
| 581 | goto ignore; |
| 582 | |
| 583 | if (!(status & DLM_RS_DIR) && (lookup || lock)) |
| 584 | goto ignore; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 585 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 586 | switch (rc->rc_type) { |
| 587 | case DLM_RCOM_STATUS: |
| 588 | receive_rcom_status(ls, rc); |
| 589 | break; |
| 590 | |
| 591 | case DLM_RCOM_NAMES: |
| 592 | receive_rcom_names(ls, rc); |
| 593 | break; |
| 594 | |
| 595 | case DLM_RCOM_LOOKUP: |
| 596 | receive_rcom_lookup(ls, rc); |
| 597 | break; |
| 598 | |
| 599 | case DLM_RCOM_LOCK: |
Al Viro | ae773d0 | 2008-01-25 19:55:09 -0500 | [diff] [blame] | 600 | if (rc->rc_header.h_length < lock_size) |
| 601 | goto Eshort; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 602 | receive_rcom_lock(ls, rc); |
| 603 | break; |
| 604 | |
| 605 | case DLM_RCOM_STATUS_REPLY: |
David Teigland | dbcfc34 | 2008-01-29 14:52:10 -0600 | [diff] [blame] | 606 | receive_sync_reply(ls, rc); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 607 | break; |
| 608 | |
| 609 | case DLM_RCOM_NAMES_REPLY: |
David Teigland | dbcfc34 | 2008-01-29 14:52:10 -0600 | [diff] [blame] | 610 | receive_sync_reply(ls, rc); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 611 | break; |
| 612 | |
| 613 | case DLM_RCOM_LOOKUP_REPLY: |
| 614 | receive_rcom_lookup_reply(ls, rc); |
| 615 | break; |
| 616 | |
| 617 | case DLM_RCOM_LOCK_REPLY: |
Al Viro | ae773d0 | 2008-01-25 19:55:09 -0500 | [diff] [blame] | 618 | if (rc->rc_header.h_length < lock_size) |
| 619 | goto Eshort; |
David Teigland | dbcfc34 | 2008-01-29 14:52:10 -0600 | [diff] [blame] | 620 | dlm_recover_process_copy(ls, rc); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 621 | break; |
| 622 | |
| 623 | default: |
David Teigland | dbcfc34 | 2008-01-29 14:52:10 -0600 | [diff] [blame] | 624 | log_error(ls, "receive_rcom bad type %d", rc->rc_type); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 625 | } |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 626 | return; |
| 627 | |
| 628 | ignore: |
| 629 | log_limit(ls, "dlm_receive_rcom ignore msg %d " |
| 630 | "from %d %llu %llu recover seq %llu sts %x gen %u", |
| 631 | rc->rc_type, |
| 632 | nodeid, |
| 633 | (unsigned long long)rc->rc_seq, |
| 634 | (unsigned long long)rc->rc_seq_reply, |
| 635 | (unsigned long long)seq, |
| 636 | status, ls->ls_generation); |
David Teigland | c36258b | 2007-09-27 15:53:38 -0500 | [diff] [blame] | 637 | return; |
Al Viro | ae773d0 | 2008-01-25 19:55:09 -0500 | [diff] [blame] | 638 | Eshort: |
David Teigland | c04fecb | 2012-05-10 10:18:07 -0500 | [diff] [blame] | 639 | log_error(ls, "recovery message %d from %d is too short", |
| 640 | rc->rc_type, nodeid); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 641 | } |
| 642 | |