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