xref: /openbmc/linux/fs/dlm/rcom.c (revision 1babdb453138f17b8ed3d1d5711089c4e2fa5ace)
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);
100faa0f267SDavid 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;
1114a99c3d9SDavid Teigland 	rc->rc_id = ++ls->ls_rcom_seq;
112e7fd4179SDavid Teigland 
113e7fd4179SDavid Teigland 	send_rcom(ls, mh, rc);
114e7fd4179SDavid Teigland 
115e7fd4179SDavid Teigland 	error = dlm_wait_function(ls, &rcom_response);
116e7fd4179SDavid Teigland 	clear_bit(LSFL_RCOM_READY, &ls->ls_flags);
117e7fd4179SDavid Teigland 	if (error)
118e7fd4179SDavid Teigland 		goto out;
119e7fd4179SDavid Teigland 
120e7fd4179SDavid Teigland 	rc = (struct dlm_rcom *) ls->ls_recover_buf;
121e7fd4179SDavid Teigland 
122e7fd4179SDavid Teigland 	if (rc->rc_result == -ESRCH) {
123e7fd4179SDavid Teigland 		/* we pretend the remote lockspace exists with 0 status */
124e7fd4179SDavid Teigland 		log_debug(ls, "remote node %d not ready", nodeid);
125e7fd4179SDavid Teigland 		rc->rc_result = 0;
126e7fd4179SDavid Teigland 	} else
127e7fd4179SDavid Teigland 		error = check_config(ls, (struct rcom_config *) rc->rc_buf,
128e7fd4179SDavid Teigland 				     nodeid);
129e7fd4179SDavid Teigland 	/* the caller looks at rc_result for the remote recovery status */
130e7fd4179SDavid Teigland  out:
131e7fd4179SDavid Teigland 	return error;
132e7fd4179SDavid Teigland }
133e7fd4179SDavid Teigland 
134e7fd4179SDavid Teigland static void receive_rcom_status(struct dlm_ls *ls, struct dlm_rcom *rc_in)
135e7fd4179SDavid Teigland {
136e7fd4179SDavid Teigland 	struct dlm_rcom *rc;
137e7fd4179SDavid Teigland 	struct dlm_mhandle *mh;
138e7fd4179SDavid Teigland 	int error, nodeid = rc_in->rc_header.h_nodeid;
139e7fd4179SDavid Teigland 
140e7fd4179SDavid Teigland 	error = create_rcom(ls, nodeid, DLM_RCOM_STATUS_REPLY,
141e7fd4179SDavid Teigland 			    sizeof(struct rcom_config), &rc, &mh);
142e7fd4179SDavid Teigland 	if (error)
143e7fd4179SDavid Teigland 		return;
1444a99c3d9SDavid Teigland 	rc->rc_id = rc_in->rc_id;
145e7fd4179SDavid Teigland 	rc->rc_result = dlm_recover_status(ls);
146e7fd4179SDavid Teigland 	make_config(ls, (struct rcom_config *) rc->rc_buf);
147e7fd4179SDavid Teigland 
148e7fd4179SDavid Teigland 	send_rcom(ls, mh, rc);
149e7fd4179SDavid Teigland }
150e7fd4179SDavid Teigland 
1514a99c3d9SDavid Teigland static void receive_sync_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in)
152e7fd4179SDavid Teigland {
1534a99c3d9SDavid Teigland 	if (rc_in->rc_id != ls->ls_rcom_seq) {
1544a99c3d9SDavid Teigland 		log_debug(ls, "reject old reply %d got %llx wanted %llx",
1554a99c3d9SDavid Teigland 			  rc_in->rc_type, rc_in->rc_id, ls->ls_rcom_seq);
1564a99c3d9SDavid Teigland 		return;
1574a99c3d9SDavid Teigland 	}
158e7fd4179SDavid Teigland 	memcpy(ls->ls_recover_buf, rc_in, rc_in->rc_header.h_length);
159e7fd4179SDavid Teigland 	set_bit(LSFL_RCOM_READY, &ls->ls_flags);
160e7fd4179SDavid Teigland 	wake_up(&ls->ls_wait_general);
161e7fd4179SDavid Teigland }
162e7fd4179SDavid Teigland 
1634a99c3d9SDavid Teigland static void receive_rcom_status_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in)
1644a99c3d9SDavid Teigland {
1654a99c3d9SDavid Teigland 	receive_sync_reply(ls, rc_in);
1664a99c3d9SDavid Teigland }
1674a99c3d9SDavid Teigland 
168e7fd4179SDavid Teigland int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name, int last_len)
169e7fd4179SDavid Teigland {
170e7fd4179SDavid Teigland 	struct dlm_rcom *rc;
171e7fd4179SDavid Teigland 	struct dlm_mhandle *mh;
172e7fd4179SDavid Teigland 	int error = 0, len = sizeof(struct dlm_rcom);
173e7fd4179SDavid Teigland 
174e7fd4179SDavid Teigland 	memset(ls->ls_recover_buf, 0, dlm_config.buffer_size);
175faa0f267SDavid Teigland 	ls->ls_recover_nodeid = nodeid;
176e7fd4179SDavid Teigland 
177e7fd4179SDavid Teigland 	if (nodeid == dlm_our_nodeid()) {
178e7fd4179SDavid Teigland 		dlm_copy_master_names(ls, last_name, last_len,
179e7fd4179SDavid Teigland 		                      ls->ls_recover_buf + len,
180e7fd4179SDavid Teigland 		                      dlm_config.buffer_size - len, nodeid);
181e7fd4179SDavid Teigland 		goto out;
182e7fd4179SDavid Teigland 	}
183e7fd4179SDavid Teigland 
184e7fd4179SDavid Teigland 	error = create_rcom(ls, nodeid, DLM_RCOM_NAMES, last_len, &rc, &mh);
185e7fd4179SDavid Teigland 	if (error)
186e7fd4179SDavid Teigland 		goto out;
187e7fd4179SDavid Teigland 	memcpy(rc->rc_buf, last_name, last_len);
1884a99c3d9SDavid Teigland 	rc->rc_id = ++ls->ls_rcom_seq;
189e7fd4179SDavid Teigland 
190e7fd4179SDavid Teigland 	send_rcom(ls, mh, rc);
191e7fd4179SDavid Teigland 
192e7fd4179SDavid Teigland 	error = dlm_wait_function(ls, &rcom_response);
193e7fd4179SDavid Teigland 	clear_bit(LSFL_RCOM_READY, &ls->ls_flags);
194e7fd4179SDavid Teigland  out:
195e7fd4179SDavid Teigland 	return error;
196e7fd4179SDavid Teigland }
197e7fd4179SDavid Teigland 
198e7fd4179SDavid Teigland static void receive_rcom_names(struct dlm_ls *ls, struct dlm_rcom *rc_in)
199e7fd4179SDavid Teigland {
200e7fd4179SDavid Teigland 	struct dlm_rcom *rc;
201e7fd4179SDavid Teigland 	struct dlm_mhandle *mh;
202e7fd4179SDavid Teigland 	int error, inlen, outlen;
203e7fd4179SDavid Teigland 	int nodeid = rc_in->rc_header.h_nodeid;
204e7fd4179SDavid Teigland 	uint32_t status = dlm_recover_status(ls);
205e7fd4179SDavid Teigland 
206e7fd4179SDavid Teigland 	/*
207e7fd4179SDavid Teigland 	 * We can't run dlm_dir_rebuild_send (which uses ls_nodes) while
208e7fd4179SDavid Teigland 	 * dlm_recoverd is running ls_nodes_reconfig (which changes ls_nodes).
209e7fd4179SDavid Teigland 	 * It could only happen in rare cases where we get a late NAMES
210e7fd4179SDavid Teigland 	 * message from a previous instance of recovery.
211e7fd4179SDavid Teigland 	 */
212e7fd4179SDavid Teigland 
213e7fd4179SDavid Teigland 	if (!(status & DLM_RS_NODES)) {
214e7fd4179SDavid Teigland 		log_debug(ls, "ignoring RCOM_NAMES from %u", nodeid);
215e7fd4179SDavid Teigland 		return;
216e7fd4179SDavid Teigland 	}
217e7fd4179SDavid Teigland 
218e7fd4179SDavid Teigland 	nodeid = rc_in->rc_header.h_nodeid;
219e7fd4179SDavid Teigland 	inlen = rc_in->rc_header.h_length - sizeof(struct dlm_rcom);
220e7fd4179SDavid Teigland 	outlen = dlm_config.buffer_size - sizeof(struct dlm_rcom);
221e7fd4179SDavid Teigland 
222e7fd4179SDavid Teigland 	error = create_rcom(ls, nodeid, DLM_RCOM_NAMES_REPLY, outlen, &rc, &mh);
223e7fd4179SDavid Teigland 	if (error)
224e7fd4179SDavid Teigland 		return;
2254a99c3d9SDavid Teigland 	rc->rc_id = rc_in->rc_id;
226e7fd4179SDavid Teigland 
227e7fd4179SDavid Teigland 	dlm_copy_master_names(ls, rc_in->rc_buf, inlen, rc->rc_buf, outlen,
228e7fd4179SDavid Teigland 			      nodeid);
229e7fd4179SDavid Teigland 	send_rcom(ls, mh, rc);
230e7fd4179SDavid Teigland }
231e7fd4179SDavid Teigland 
232e7fd4179SDavid Teigland static void receive_rcom_names_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in)
233e7fd4179SDavid Teigland {
2344a99c3d9SDavid Teigland 	receive_sync_reply(ls, rc_in);
235e7fd4179SDavid Teigland }
236e7fd4179SDavid Teigland 
237e7fd4179SDavid Teigland int dlm_send_rcom_lookup(struct dlm_rsb *r, int dir_nodeid)
238e7fd4179SDavid Teigland {
239e7fd4179SDavid Teigland 	struct dlm_rcom *rc;
240e7fd4179SDavid Teigland 	struct dlm_mhandle *mh;
241e7fd4179SDavid Teigland 	struct dlm_ls *ls = r->res_ls;
242e7fd4179SDavid Teigland 	int error;
243e7fd4179SDavid Teigland 
244e7fd4179SDavid Teigland 	error = create_rcom(ls, dir_nodeid, DLM_RCOM_LOOKUP, r->res_length,
245e7fd4179SDavid Teigland 			    &rc, &mh);
246e7fd4179SDavid Teigland 	if (error)
247e7fd4179SDavid Teigland 		goto out;
248e7fd4179SDavid Teigland 	memcpy(rc->rc_buf, r->res_name, r->res_length);
249e7fd4179SDavid Teigland 	rc->rc_id = (unsigned long) r;
250e7fd4179SDavid Teigland 
251e7fd4179SDavid Teigland 	send_rcom(ls, mh, rc);
252e7fd4179SDavid Teigland  out:
253e7fd4179SDavid Teigland 	return error;
254e7fd4179SDavid Teigland }
255e7fd4179SDavid Teigland 
256e7fd4179SDavid Teigland static void receive_rcom_lookup(struct dlm_ls *ls, struct dlm_rcom *rc_in)
257e7fd4179SDavid Teigland {
258e7fd4179SDavid Teigland 	struct dlm_rcom *rc;
259e7fd4179SDavid Teigland 	struct dlm_mhandle *mh;
260e7fd4179SDavid Teigland 	int error, ret_nodeid, nodeid = rc_in->rc_header.h_nodeid;
261e7fd4179SDavid Teigland 	int len = rc_in->rc_header.h_length - sizeof(struct dlm_rcom);
262e7fd4179SDavid Teigland 
263e7fd4179SDavid Teigland 	error = create_rcom(ls, nodeid, DLM_RCOM_LOOKUP_REPLY, 0, &rc, &mh);
264e7fd4179SDavid Teigland 	if (error)
265e7fd4179SDavid Teigland 		return;
266e7fd4179SDavid Teigland 
267e7fd4179SDavid Teigland 	error = dlm_dir_lookup(ls, nodeid, rc_in->rc_buf, len, &ret_nodeid);
268e7fd4179SDavid Teigland 	if (error)
269e7fd4179SDavid Teigland 		ret_nodeid = error;
270e7fd4179SDavid Teigland 	rc->rc_result = ret_nodeid;
271e7fd4179SDavid Teigland 	rc->rc_id = rc_in->rc_id;
272e7fd4179SDavid Teigland 
273e7fd4179SDavid Teigland 	send_rcom(ls, mh, rc);
274e7fd4179SDavid Teigland }
275e7fd4179SDavid Teigland 
276e7fd4179SDavid Teigland static void receive_rcom_lookup_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in)
277e7fd4179SDavid Teigland {
278e7fd4179SDavid Teigland 	dlm_recover_master_reply(ls, rc_in);
279e7fd4179SDavid Teigland }
280e7fd4179SDavid Teigland 
281e7fd4179SDavid Teigland static void pack_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb,
282e7fd4179SDavid Teigland 			   struct rcom_lock *rl)
283e7fd4179SDavid Teigland {
284e7fd4179SDavid Teigland 	memset(rl, 0, sizeof(*rl));
285e7fd4179SDavid Teigland 
286e7fd4179SDavid Teigland 	rl->rl_ownpid = lkb->lkb_ownpid;
287e7fd4179SDavid Teigland 	rl->rl_lkid = lkb->lkb_id;
288e7fd4179SDavid Teigland 	rl->rl_exflags = lkb->lkb_exflags;
289e7fd4179SDavid Teigland 	rl->rl_flags = lkb->lkb_flags;
290e7fd4179SDavid Teigland 	rl->rl_lvbseq = lkb->lkb_lvbseq;
291e7fd4179SDavid Teigland 	rl->rl_rqmode = lkb->lkb_rqmode;
292e7fd4179SDavid Teigland 	rl->rl_grmode = lkb->lkb_grmode;
293e7fd4179SDavid Teigland 	rl->rl_status = lkb->lkb_status;
294e7fd4179SDavid Teigland 	rl->rl_wait_type = lkb->lkb_wait_type;
295e7fd4179SDavid Teigland 
296e7fd4179SDavid Teigland 	if (lkb->lkb_bastaddr)
297e7fd4179SDavid Teigland 		rl->rl_asts |= AST_BAST;
298e7fd4179SDavid Teigland 	if (lkb->lkb_astaddr)
299e7fd4179SDavid Teigland 		rl->rl_asts |= AST_COMP;
300e7fd4179SDavid Teigland 
301e7fd4179SDavid Teigland 	rl->rl_namelen = r->res_length;
302e7fd4179SDavid Teigland 	memcpy(rl->rl_name, r->res_name, r->res_length);
303e7fd4179SDavid Teigland 
304e7fd4179SDavid Teigland 	/* FIXME: might we have an lvb without DLM_LKF_VALBLK set ?
305e7fd4179SDavid Teigland 	   If so, receive_rcom_lock_args() won't take this copy. */
306e7fd4179SDavid Teigland 
307e7fd4179SDavid Teigland 	if (lkb->lkb_lvbptr)
308e7fd4179SDavid Teigland 		memcpy(rl->rl_lvb, lkb->lkb_lvbptr, r->res_ls->ls_lvblen);
309e7fd4179SDavid Teigland }
310e7fd4179SDavid Teigland 
311e7fd4179SDavid Teigland int dlm_send_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb)
312e7fd4179SDavid Teigland {
313e7fd4179SDavid Teigland 	struct dlm_ls *ls = r->res_ls;
314e7fd4179SDavid Teigland 	struct dlm_rcom *rc;
315e7fd4179SDavid Teigland 	struct dlm_mhandle *mh;
316e7fd4179SDavid Teigland 	struct rcom_lock *rl;
317e7fd4179SDavid Teigland 	int error, len = sizeof(struct rcom_lock);
318e7fd4179SDavid Teigland 
319e7fd4179SDavid Teigland 	if (lkb->lkb_lvbptr)
320e7fd4179SDavid Teigland 		len += ls->ls_lvblen;
321e7fd4179SDavid Teigland 
322e7fd4179SDavid Teigland 	error = create_rcom(ls, r->res_nodeid, DLM_RCOM_LOCK, len, &rc, &mh);
323e7fd4179SDavid Teigland 	if (error)
324e7fd4179SDavid Teigland 		goto out;
325e7fd4179SDavid Teigland 
326e7fd4179SDavid Teigland 	rl = (struct rcom_lock *) rc->rc_buf;
327e7fd4179SDavid Teigland 	pack_rcom_lock(r, lkb, rl);
328e7fd4179SDavid Teigland 	rc->rc_id = (unsigned long) r;
329e7fd4179SDavid Teigland 
330e7fd4179SDavid Teigland 	send_rcom(ls, mh, rc);
331e7fd4179SDavid Teigland  out:
332e7fd4179SDavid Teigland 	return error;
333e7fd4179SDavid Teigland }
334e7fd4179SDavid Teigland 
335e7fd4179SDavid Teigland static void receive_rcom_lock(struct dlm_ls *ls, struct dlm_rcom *rc_in)
336e7fd4179SDavid Teigland {
337e7fd4179SDavid Teigland 	struct dlm_rcom *rc;
338e7fd4179SDavid Teigland 	struct dlm_mhandle *mh;
339e7fd4179SDavid Teigland 	int error, nodeid = rc_in->rc_header.h_nodeid;
340e7fd4179SDavid Teigland 
341e7fd4179SDavid Teigland 	dlm_recover_master_copy(ls, rc_in);
342e7fd4179SDavid Teigland 
343e7fd4179SDavid Teigland 	error = create_rcom(ls, nodeid, DLM_RCOM_LOCK_REPLY,
344e7fd4179SDavid Teigland 			    sizeof(struct rcom_lock), &rc, &mh);
345e7fd4179SDavid Teigland 	if (error)
346e7fd4179SDavid Teigland 		return;
347e7fd4179SDavid Teigland 
348e7fd4179SDavid Teigland 	/* We send back the same rcom_lock struct we received, but
349e7fd4179SDavid Teigland 	   dlm_recover_master_copy() has filled in rl_remid and rl_result */
350e7fd4179SDavid Teigland 
351e7fd4179SDavid Teigland 	memcpy(rc->rc_buf, rc_in->rc_buf, sizeof(struct rcom_lock));
352e7fd4179SDavid Teigland 	rc->rc_id = rc_in->rc_id;
353e7fd4179SDavid Teigland 
354e7fd4179SDavid Teigland 	send_rcom(ls, mh, rc);
355e7fd4179SDavid Teigland }
356e7fd4179SDavid Teigland 
357e7fd4179SDavid Teigland static void receive_rcom_lock_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in)
358e7fd4179SDavid Teigland {
359e7fd4179SDavid Teigland 	uint32_t status = dlm_recover_status(ls);
360e7fd4179SDavid Teigland 
361e7fd4179SDavid Teigland 	if (!(status & DLM_RS_DIR)) {
362e7fd4179SDavid Teigland 		log_debug(ls, "ignoring RCOM_LOCK_REPLY from %u",
363e7fd4179SDavid Teigland 			  rc_in->rc_header.h_nodeid);
364e7fd4179SDavid Teigland 		return;
365e7fd4179SDavid Teigland 	}
366e7fd4179SDavid Teigland 
367e7fd4179SDavid Teigland 	dlm_recover_process_copy(ls, rc_in);
368e7fd4179SDavid Teigland }
369e7fd4179SDavid Teigland 
370e7fd4179SDavid Teigland static int send_ls_not_ready(int nodeid, struct dlm_rcom *rc_in)
371e7fd4179SDavid Teigland {
372e7fd4179SDavid Teigland 	struct dlm_rcom *rc;
373*1babdb45SDavid Teigland 	struct rcom_config *rf;
374e7fd4179SDavid Teigland 	struct dlm_mhandle *mh;
375e7fd4179SDavid Teigland 	char *mb;
376*1babdb45SDavid Teigland 	int mb_len = sizeof(struct dlm_rcom) + sizeof(struct rcom_config);
377e7fd4179SDavid Teigland 
378e7fd4179SDavid Teigland 	mh = dlm_lowcomms_get_buffer(nodeid, mb_len, GFP_KERNEL, &mb);
379e7fd4179SDavid Teigland 	if (!mh)
380e7fd4179SDavid Teigland 		return -ENOBUFS;
381e7fd4179SDavid Teigland 	memset(mb, 0, mb_len);
382e7fd4179SDavid Teigland 
383e7fd4179SDavid Teigland 	rc = (struct dlm_rcom *) mb;
384e7fd4179SDavid Teigland 
385e7fd4179SDavid Teigland 	rc->rc_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR);
386e7fd4179SDavid Teigland 	rc->rc_header.h_lockspace = rc_in->rc_header.h_lockspace;
387e7fd4179SDavid Teigland 	rc->rc_header.h_nodeid = dlm_our_nodeid();
388e7fd4179SDavid Teigland 	rc->rc_header.h_length = mb_len;
389e7fd4179SDavid Teigland 	rc->rc_header.h_cmd = DLM_RCOM;
390e7fd4179SDavid Teigland 
391e7fd4179SDavid Teigland 	rc->rc_type = DLM_RCOM_STATUS_REPLY;
392f5888750SDavid Teigland 	rc->rc_id = rc_in->rc_id;
393e7fd4179SDavid Teigland 	rc->rc_result = -ESRCH;
394e7fd4179SDavid Teigland 
395*1babdb45SDavid Teigland 	rf = (struct rcom_config *) rc->rc_buf;
396*1babdb45SDavid Teigland 	rf->rf_lvblen = -1;
397*1babdb45SDavid Teigland 
398e7fd4179SDavid Teigland 	dlm_rcom_out(rc);
399e7fd4179SDavid Teigland 	dlm_lowcomms_commit_buffer(mh);
400e7fd4179SDavid Teigland 
401e7fd4179SDavid Teigland 	return 0;
402e7fd4179SDavid Teigland }
403e7fd4179SDavid Teigland 
404e7fd4179SDavid Teigland /* Called by dlm_recvd; corresponds to dlm_receive_message() but special
405e7fd4179SDavid Teigland    recovery-only comms are sent through here. */
406e7fd4179SDavid Teigland 
407e7fd4179SDavid Teigland void dlm_receive_rcom(struct dlm_header *hd, int nodeid)
408e7fd4179SDavid Teigland {
409e7fd4179SDavid Teigland 	struct dlm_rcom *rc = (struct dlm_rcom *) hd;
410e7fd4179SDavid Teigland 	struct dlm_ls *ls;
411e7fd4179SDavid Teigland 
412e7fd4179SDavid Teigland 	dlm_rcom_in(rc);
413e7fd4179SDavid Teigland 
414e7fd4179SDavid Teigland 	/* If the lockspace doesn't exist then still send a status message
415e7fd4179SDavid Teigland 	   back; it's possible that it just doesn't have its global_id yet. */
416e7fd4179SDavid Teigland 
417e7fd4179SDavid Teigland 	ls = dlm_find_lockspace_global(hd->h_lockspace);
418e7fd4179SDavid Teigland 	if (!ls) {
419435618b7SDavid Teigland 		log_print("lockspace %x from %d type %x not found",
420435618b7SDavid Teigland 			  hd->h_lockspace, nodeid, rc->rc_type);
421435618b7SDavid Teigland 		if (rc->rc_type == DLM_RCOM_STATUS)
422e7fd4179SDavid Teigland 			send_ls_not_ready(nodeid, rc);
423e7fd4179SDavid Teigland 		return;
424e7fd4179SDavid Teigland 	}
425e7fd4179SDavid Teigland 
426e7fd4179SDavid Teigland 	if (dlm_recovery_stopped(ls) && (rc->rc_type != DLM_RCOM_STATUS)) {
427e7fd4179SDavid Teigland 		log_error(ls, "ignoring recovery message %x from %d",
428e7fd4179SDavid Teigland 			  rc->rc_type, nodeid);
429e7fd4179SDavid Teigland 		goto out;
430e7fd4179SDavid Teigland 	}
431e7fd4179SDavid Teigland 
432e7fd4179SDavid Teigland 	if (nodeid != rc->rc_header.h_nodeid) {
433e7fd4179SDavid Teigland 		log_error(ls, "bad rcom nodeid %d from %d",
434e7fd4179SDavid Teigland 			  rc->rc_header.h_nodeid, nodeid);
435e7fd4179SDavid Teigland 		goto out;
436e7fd4179SDavid Teigland 	}
437e7fd4179SDavid Teigland 
438e7fd4179SDavid Teigland 	switch (rc->rc_type) {
439e7fd4179SDavid Teigland 	case DLM_RCOM_STATUS:
440e7fd4179SDavid Teigland 		receive_rcom_status(ls, rc);
441e7fd4179SDavid Teigland 		break;
442e7fd4179SDavid Teigland 
443e7fd4179SDavid Teigland 	case DLM_RCOM_NAMES:
444e7fd4179SDavid Teigland 		receive_rcom_names(ls, rc);
445e7fd4179SDavid Teigland 		break;
446e7fd4179SDavid Teigland 
447e7fd4179SDavid Teigland 	case DLM_RCOM_LOOKUP:
448e7fd4179SDavid Teigland 		receive_rcom_lookup(ls, rc);
449e7fd4179SDavid Teigland 		break;
450e7fd4179SDavid Teigland 
451e7fd4179SDavid Teigland 	case DLM_RCOM_LOCK:
452e7fd4179SDavid Teigland 		receive_rcom_lock(ls, rc);
453e7fd4179SDavid Teigland 		break;
454e7fd4179SDavid Teigland 
455e7fd4179SDavid Teigland 	case DLM_RCOM_STATUS_REPLY:
456e7fd4179SDavid Teigland 		receive_rcom_status_reply(ls, rc);
457e7fd4179SDavid Teigland 		break;
458e7fd4179SDavid Teigland 
459e7fd4179SDavid Teigland 	case DLM_RCOM_NAMES_REPLY:
460e7fd4179SDavid Teigland 		receive_rcom_names_reply(ls, rc);
461e7fd4179SDavid Teigland 		break;
462e7fd4179SDavid Teigland 
463e7fd4179SDavid Teigland 	case DLM_RCOM_LOOKUP_REPLY:
464e7fd4179SDavid Teigland 		receive_rcom_lookup_reply(ls, rc);
465e7fd4179SDavid Teigland 		break;
466e7fd4179SDavid Teigland 
467e7fd4179SDavid Teigland 	case DLM_RCOM_LOCK_REPLY:
468e7fd4179SDavid Teigland 		receive_rcom_lock_reply(ls, rc);
469e7fd4179SDavid Teigland 		break;
470e7fd4179SDavid Teigland 
471e7fd4179SDavid Teigland 	default:
472e7fd4179SDavid Teigland 		DLM_ASSERT(0, printk("rc_type=%x\n", rc->rc_type););
473e7fd4179SDavid Teigland 	}
474e7fd4179SDavid Teigland  out:
475e7fd4179SDavid Teigland 	dlm_put_lockspace(ls);
476e7fd4179SDavid Teigland }
477e7fd4179SDavid Teigland 
478