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