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