blob: 41e277f57b20f5e03833abc42aaacea75aff2f73 [file] [log] [blame]
David Howellsec268152007-04-26 15:49:28 -07001/* AFS Cache Manager Service
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/sched.h>
David Howells08e0e7c2007-04-26 15:55:03 -070016#include <linux/ip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include "internal.h"
David Howells08e0e7c2007-04-26 15:55:03 -070018#include "afs_cm.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
David Howellsd0016482016-08-30 20:42:14 +010020static int afs_deliver_cb_init_call_back_state(struct afs_call *);
21static int afs_deliver_cb_init_call_back_state3(struct afs_call *);
22static int afs_deliver_cb_probe(struct afs_call *);
23static int afs_deliver_cb_callback(struct afs_call *);
24static int afs_deliver_cb_probe_uuid(struct afs_call *);
25static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *);
David Howells08e0e7c2007-04-26 15:55:03 -070026static void afs_cm_destructor(struct afs_call *);
David Howells341f7412017-01-05 10:38:36 +000027static void SRXAFSCB_CallBack(struct work_struct *);
28static void SRXAFSCB_InitCallBackState(struct work_struct *);
29static void SRXAFSCB_Probe(struct work_struct *);
30static void SRXAFSCB_ProbeUuid(struct work_struct *);
31static void SRXAFSCB_TellMeAboutYourself(struct work_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
David Howells8e8d7f12017-01-05 10:38:34 +000033#define CM_NAME(name) \
34 const char afs_SRXCB##name##_name[] __tracepoint_string = \
35 "CB." #name
36
David Howells08e0e7c2007-04-26 15:55:03 -070037/*
38 * CB.CallBack operation type
39 */
David Howells8e8d7f12017-01-05 10:38:34 +000040static CM_NAME(CallBack);
David Howells08e0e7c2007-04-26 15:55:03 -070041static const struct afs_call_type afs_SRXCBCallBack = {
David Howells8e8d7f12017-01-05 10:38:34 +000042 .name = afs_SRXCBCallBack_name,
David Howells08e0e7c2007-04-26 15:55:03 -070043 .deliver = afs_deliver_cb_callback,
David Howells08e0e7c2007-04-26 15:55:03 -070044 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000045 .work = SRXAFSCB_CallBack,
Linus Torvalds1da177e2005-04-16 15:20:36 -070046};
47
David Howells08e0e7c2007-04-26 15:55:03 -070048/*
49 * CB.InitCallBackState operation type
50 */
David Howells8e8d7f12017-01-05 10:38:34 +000051static CM_NAME(InitCallBackState);
David Howells08e0e7c2007-04-26 15:55:03 -070052static const struct afs_call_type afs_SRXCBInitCallBackState = {
David Howells8e8d7f12017-01-05 10:38:34 +000053 .name = afs_SRXCBInitCallBackState_name,
David Howells08e0e7c2007-04-26 15:55:03 -070054 .deliver = afs_deliver_cb_init_call_back_state,
David Howells08e0e7c2007-04-26 15:55:03 -070055 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000056 .work = SRXAFSCB_InitCallBackState,
Linus Torvalds1da177e2005-04-16 15:20:36 -070057};
58
David Howells08e0e7c2007-04-26 15:55:03 -070059/*
David Howellsc35eccb2007-04-26 15:58:49 -070060 * CB.InitCallBackState3 operation type
61 */
David Howells8e8d7f12017-01-05 10:38:34 +000062static CM_NAME(InitCallBackState3);
David Howellsc35eccb2007-04-26 15:58:49 -070063static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
David Howells8e8d7f12017-01-05 10:38:34 +000064 .name = afs_SRXCBInitCallBackState3_name,
David Howellsc35eccb2007-04-26 15:58:49 -070065 .deliver = afs_deliver_cb_init_call_back_state3,
David Howellsc35eccb2007-04-26 15:58:49 -070066 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000067 .work = SRXAFSCB_InitCallBackState,
David Howellsc35eccb2007-04-26 15:58:49 -070068};
69
70/*
David Howells08e0e7c2007-04-26 15:55:03 -070071 * CB.Probe operation type
72 */
David Howells8e8d7f12017-01-05 10:38:34 +000073static CM_NAME(Probe);
David Howells08e0e7c2007-04-26 15:55:03 -070074static const struct afs_call_type afs_SRXCBProbe = {
David Howells8e8d7f12017-01-05 10:38:34 +000075 .name = afs_SRXCBProbe_name,
David Howells08e0e7c2007-04-26 15:55:03 -070076 .deliver = afs_deliver_cb_probe,
David Howells08e0e7c2007-04-26 15:55:03 -070077 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000078 .work = SRXAFSCB_Probe,
David Howells08e0e7c2007-04-26 15:55:03 -070079};
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081/*
David Howells9396d492008-04-29 01:03:22 -070082 * CB.ProbeUuid operation type
83 */
David Howells8e8d7f12017-01-05 10:38:34 +000084static CM_NAME(ProbeUuid);
David Howells9396d492008-04-29 01:03:22 -070085static const struct afs_call_type afs_SRXCBProbeUuid = {
David Howells8e8d7f12017-01-05 10:38:34 +000086 .name = afs_SRXCBProbeUuid_name,
David Howells9396d492008-04-29 01:03:22 -070087 .deliver = afs_deliver_cb_probe_uuid,
David Howells9396d492008-04-29 01:03:22 -070088 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000089 .work = SRXAFSCB_ProbeUuid,
David Howells9396d492008-04-29 01:03:22 -070090};
91
92/*
David Howells7c80bcc2008-04-29 01:03:21 -070093 * CB.TellMeAboutYourself operation type
David Howellsb908fe62007-04-26 15:58:17 -070094 */
David Howells8e8d7f12017-01-05 10:38:34 +000095static CM_NAME(TellMeAboutYourself);
David Howells7c80bcc2008-04-29 01:03:21 -070096static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
David Howells8e8d7f12017-01-05 10:38:34 +000097 .name = afs_SRXCBTellMeAboutYourself_name,
David Howells7c80bcc2008-04-29 01:03:21 -070098 .deliver = afs_deliver_cb_tell_me_about_yourself,
David Howellsb908fe62007-04-26 15:58:17 -070099 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +0000100 .work = SRXAFSCB_TellMeAboutYourself,
David Howellsb908fe62007-04-26 15:58:17 -0700101};
102
103/*
David Howells08e0e7c2007-04-26 15:55:03 -0700104 * route an incoming cache manager call
105 * - return T if supported, F if not
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 */
David Howells08e0e7c2007-04-26 15:55:03 -0700107bool afs_cm_incoming_call(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
David Howells50a2c952016-10-13 08:27:10 +0100109 _enter("{CB.OP %u}", call->operation_ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
David Howells50a2c952016-10-13 08:27:10 +0100111 switch (call->operation_ID) {
David Howells08e0e7c2007-04-26 15:55:03 -0700112 case CBCallBack:
113 call->type = &afs_SRXCBCallBack;
114 return true;
115 case CBInitCallBackState:
116 call->type = &afs_SRXCBInitCallBackState;
117 return true;
David Howellsc35eccb2007-04-26 15:58:49 -0700118 case CBInitCallBackState3:
119 call->type = &afs_SRXCBInitCallBackState3;
120 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700121 case CBProbe:
122 call->type = &afs_SRXCBProbe;
123 return true;
David Howellsf4b35262017-11-02 15:27:48 +0000124 case CBProbeUuid:
125 call->type = &afs_SRXCBProbeUuid;
126 return true;
David Howells7c80bcc2008-04-29 01:03:21 -0700127 case CBTellMeAboutYourself:
128 call->type = &afs_SRXCBTellMeAboutYourself;
David Howellsb908fe62007-04-26 15:58:17 -0700129 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700130 default:
131 return false;
132 }
David Howellsec268152007-04-26 15:49:28 -0700133}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135/*
David Howells08e0e7c2007-04-26 15:55:03 -0700136 * clean up a cache manager call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 */
David Howells08e0e7c2007-04-26 15:55:03 -0700138static void afs_cm_destructor(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
David Howells08e0e7c2007-04-26 15:55:03 -0700140 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
David Howells6c67c7c2014-05-21 14:48:05 +0100142 /* Break the callbacks here so that we do it after the final ACK is
143 * received. The step number here must match the final number in
144 * afs_deliver_cb_callback().
145 */
David Howellsd0016482016-08-30 20:42:14 +0100146 if (call->unmarshall == 5) {
David Howellsd0676a12017-11-02 15:27:49 +0000147 ASSERT(call->cm_server && call->count && call->request);
148 afs_break_callbacks(call->cm_server, call->count, call->request);
David Howells6c67c7c2014-05-21 14:48:05 +0100149 }
150
David Howells08e0e7c2007-04-26 15:55:03 -0700151 kfree(call->buffer);
152 call->buffer = NULL;
David Howellsec268152007-04-26 15:49:28 -0700153}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155/*
David Howellsc435ee32017-11-02 15:27:49 +0000156 * The server supplied a list of callbacks that it wanted to break.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 */
David Howells08e0e7c2007-04-26 15:55:03 -0700158static void SRXAFSCB_CallBack(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
David Howells08e0e7c2007-04-26 15:55:03 -0700160 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
David Howells08e0e7c2007-04-26 15:55:03 -0700162 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
David Howells08e0e7c2007-04-26 15:55:03 -0700164 /* be sure to send the reply *before* attempting to spam the AFS server
165 * with FSFetchStatus requests on the vnodes with broken callbacks lest
166 * the AFS server get into a vicious cycle of trying to break further
167 * callbacks because it hadn't received completion of the CBCallBack op
168 * yet */
169 afs_send_empty_reply(call);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
David Howellsd0676a12017-11-02 15:27:49 +0000171 afs_break_callbacks(call->cm_server, call->count, call->request);
David Howells341f7412017-01-05 10:38:36 +0000172 afs_put_call(call);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700174}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176/*
David Howells08e0e7c2007-04-26 15:55:03 -0700177 * deliver request data to a CB.CallBack call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 */
David Howellsd0016482016-08-30 20:42:14 +0100179static int afs_deliver_cb_callback(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
David Howells8324f0b2016-08-30 09:49:29 +0100181 struct sockaddr_rxrpc srx;
David Howells08e0e7c2007-04-26 15:55:03 -0700182 struct afs_callback *cb;
183 struct afs_server *server;
David Howells08e0e7c2007-04-26 15:55:03 -0700184 __be32 *bp;
David Howells08e0e7c2007-04-26 15:55:03 -0700185 int ret, loop;
186
David Howellsd0016482016-08-30 20:42:14 +0100187 _enter("{%u}", call->unmarshall);
David Howells08e0e7c2007-04-26 15:55:03 -0700188
189 switch (call->unmarshall) {
190 case 0:
191 call->offset = 0;
192 call->unmarshall++;
193
194 /* extract the FID array and its count in two steps */
195 case 1:
196 _debug("extract FID count");
David Howellsd0016482016-08-30 20:42:14 +0100197 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +0100198 if (ret < 0)
199 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700200
201 call->count = ntohl(call->tmp);
202 _debug("FID count: %u", call->count);
203 if (call->count > AFSCBMAX)
204 return -EBADMSG;
205
206 call->buffer = kmalloc(call->count * 3 * 4, GFP_KERNEL);
207 if (!call->buffer)
208 return -ENOMEM;
209 call->offset = 0;
210 call->unmarshall++;
211
212 case 2:
213 _debug("extract FID array");
David Howellsd0016482016-08-30 20:42:14 +0100214 ret = afs_extract_data(call, call->buffer,
215 call->count * 3 * 4, true);
David Howells372ee162016-08-03 14:11:40 +0100216 if (ret < 0)
217 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700218
219 _debug("unmarshall FID array");
220 call->request = kcalloc(call->count,
221 sizeof(struct afs_callback),
222 GFP_KERNEL);
223 if (!call->request)
224 return -ENOMEM;
225
226 cb = call->request;
227 bp = call->buffer;
228 for (loop = call->count; loop > 0; loop--, cb++) {
229 cb->fid.vid = ntohl(*bp++);
230 cb->fid.vnode = ntohl(*bp++);
231 cb->fid.unique = ntohl(*bp++);
232 cb->type = AFSCM_CB_UNTYPED;
233 }
234
235 call->offset = 0;
236 call->unmarshall++;
237
238 /* extract the callback array and its count in two steps */
239 case 3:
240 _debug("extract CB count");
David Howellsd0016482016-08-30 20:42:14 +0100241 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +0100242 if (ret < 0)
243 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700244
Marc Dionnebcd89272017-03-16 16:27:44 +0000245 call->count2 = ntohl(call->tmp);
246 _debug("CB count: %u", call->count2);
247 if (call->count2 != call->count && call->count2 != 0)
David Howells08e0e7c2007-04-26 15:55:03 -0700248 return -EBADMSG;
249 call->offset = 0;
250 call->unmarshall++;
David Howells08e0e7c2007-04-26 15:55:03 -0700251
252 case 4:
253 _debug("extract CB array");
David Howellsd0016482016-08-30 20:42:14 +0100254 ret = afs_extract_data(call, call->buffer,
Marc Dionnebcd89272017-03-16 16:27:44 +0000255 call->count2 * 3 * 4, false);
David Howells372ee162016-08-03 14:11:40 +0100256 if (ret < 0)
257 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700258
259 _debug("unmarshall CB array");
260 cb = call->request;
261 bp = call->buffer;
Marc Dionnebcd89272017-03-16 16:27:44 +0000262 for (loop = call->count2; loop > 0; loop--, cb++) {
David Howells08e0e7c2007-04-26 15:55:03 -0700263 cb->version = ntohl(*bp++);
264 cb->expiry = ntohl(*bp++);
265 cb->type = ntohl(*bp++);
266 }
267
David Howells08e0e7c2007-04-26 15:55:03 -0700268 call->offset = 0;
269 call->unmarshall++;
270
David Howells6c67c7c2014-05-21 14:48:05 +0100271 /* Record that the message was unmarshalled successfully so
272 * that the call destructor can know do the callback breaking
273 * work, even if the final ACK isn't received.
274 *
275 * If the step number changes, then afs_cm_destructor() must be
276 * updated also.
277 */
278 call->unmarshall++;
David Howellsd0016482016-08-30 20:42:14 +0100279 case 5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 break;
281 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
David Howells98bf40c2017-11-02 15:27:53 +0000283 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
284 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
David Howells08e0e7c2007-04-26 15:55:03 -0700286 /* we'll need the file server record as that tells us which set of
287 * vnodes to operate upon */
David Howells98bf40c2017-11-02 15:27:53 +0000288 rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
David Howellsf044c882017-11-02 15:27:45 +0000289 server = afs_find_server(call->net, &srx);
David Howells08e0e7c2007-04-26 15:55:03 -0700290 if (!server)
291 return -ENOTCONN;
David Howellsd0676a12017-11-02 15:27:49 +0000292 call->cm_server = server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
David Howells341f7412017-01-05 10:38:36 +0000294 return afs_queue_call_work(call);
David Howellsec268152007-04-26 15:49:28 -0700295}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297/*
David Howells08e0e7c2007-04-26 15:55:03 -0700298 * allow the fileserver to request callback state (re-)initialisation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 */
David Howells08e0e7c2007-04-26 15:55:03 -0700300static void SRXAFSCB_InitCallBackState(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
David Howells08e0e7c2007-04-26 15:55:03 -0700302 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
David Howellsd0676a12017-11-02 15:27:49 +0000304 _enter("{%p}", call->cm_server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
David Howellsd0676a12017-11-02 15:27:49 +0000306 afs_init_callback_state(call->cm_server);
David Howells08e0e7c2007-04-26 15:55:03 -0700307 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000308 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700309 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700310}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312/*
David Howells08e0e7c2007-04-26 15:55:03 -0700313 * deliver request data to a CB.InitCallBackState call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 */
David Howellsd0016482016-08-30 20:42:14 +0100315static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
David Howells8324f0b2016-08-30 09:49:29 +0100317 struct sockaddr_rxrpc srx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 struct afs_server *server;
David Howells372ee162016-08-03 14:11:40 +0100319 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
David Howellsd0016482016-08-30 20:42:14 +0100321 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
David Howellsf044c882017-11-02 15:27:45 +0000323 rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
David Howells8324f0b2016-08-30 09:49:29 +0100324
David Howellsd0016482016-08-30 20:42:14 +0100325 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100326 if (ret < 0)
327 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
David Howells08e0e7c2007-04-26 15:55:03 -0700329 /* we'll need the file server record as that tells us which set of
330 * vnodes to operate upon */
David Howellsf044c882017-11-02 15:27:45 +0000331 server = afs_find_server(call->net, &srx);
David Howells08e0e7c2007-04-26 15:55:03 -0700332 if (!server)
333 return -ENOTCONN;
David Howellsd0676a12017-11-02 15:27:49 +0000334 call->cm_server = server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
David Howells341f7412017-01-05 10:38:36 +0000336 return afs_queue_call_work(call);
David Howellsec268152007-04-26 15:49:28 -0700337}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339/*
David Howellsc35eccb2007-04-26 15:58:49 -0700340 * deliver request data to a CB.InitCallBackState3 call
341 */
David Howellsd0016482016-08-30 20:42:14 +0100342static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
David Howellsc35eccb2007-04-26 15:58:49 -0700343{
David Howells8324f0b2016-08-30 09:49:29 +0100344 struct sockaddr_rxrpc srx;
David Howellsc35eccb2007-04-26 15:58:49 -0700345 struct afs_server *server;
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300346 struct afs_uuid *r;
David Howellsd0016482016-08-30 20:42:14 +0100347 unsigned loop;
348 __be32 *b;
349 int ret;
David Howellsc35eccb2007-04-26 15:58:49 -0700350
David Howellsd0016482016-08-30 20:42:14 +0100351 _enter("");
David Howellsc35eccb2007-04-26 15:58:49 -0700352
David Howellsd0016482016-08-30 20:42:14 +0100353 _enter("{%u}", call->unmarshall);
354
355 switch (call->unmarshall) {
356 case 0:
357 call->offset = 0;
358 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
359 if (!call->buffer)
360 return -ENOMEM;
361 call->unmarshall++;
362
363 case 1:
364 _debug("extract UUID");
365 ret = afs_extract_data(call, call->buffer,
366 11 * sizeof(__be32), false);
367 switch (ret) {
368 case 0: break;
369 case -EAGAIN: return 0;
370 default: return ret;
371 }
372
373 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300374 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100375 if (!call->request)
376 return -ENOMEM;
377
378 b = call->buffer;
379 r = call->request;
David Howellsff548772017-02-10 16:34:07 +0000380 r->time_low = b[0];
381 r->time_mid = htons(ntohl(b[1]));
382 r->time_hi_and_version = htons(ntohl(b[2]));
David Howellsd0016482016-08-30 20:42:14 +0100383 r->clock_seq_hi_and_reserved = ntohl(b[3]);
384 r->clock_seq_low = ntohl(b[4]);
385
386 for (loop = 0; loop < 6; loop++)
387 r->node[loop] = ntohl(b[loop + 5]);
388
389 call->offset = 0;
390 call->unmarshall++;
391
392 case 2:
393 break;
394 }
David Howellsc35eccb2007-04-26 15:58:49 -0700395
David Howells98bf40c2017-11-02 15:27:53 +0000396 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
397 return -EIO;
David Howellsc35eccb2007-04-26 15:58:49 -0700398
399 /* we'll need the file server record as that tells us which set of
400 * vnodes to operate upon */
David Howells98bf40c2017-11-02 15:27:53 +0000401 rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
David Howellsf044c882017-11-02 15:27:45 +0000402 server = afs_find_server(call->net, &srx);
David Howellsc35eccb2007-04-26 15:58:49 -0700403 if (!server)
404 return -ENOTCONN;
David Howellsd0676a12017-11-02 15:27:49 +0000405 call->cm_server = server;
David Howellsc35eccb2007-04-26 15:58:49 -0700406
David Howells341f7412017-01-05 10:38:36 +0000407 return afs_queue_call_work(call);
David Howellsc35eccb2007-04-26 15:58:49 -0700408}
409
410/*
David Howells08e0e7c2007-04-26 15:55:03 -0700411 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 */
David Howells08e0e7c2007-04-26 15:55:03 -0700413static void SRXAFSCB_Probe(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
David Howells08e0e7c2007-04-26 15:55:03 -0700415 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
David Howells08e0e7c2007-04-26 15:55:03 -0700417 _enter("");
418 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000419 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700420 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700421}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423/*
David Howells08e0e7c2007-04-26 15:55:03 -0700424 * deliver request data to a CB.Probe call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 */
David Howellsd0016482016-08-30 20:42:14 +0100426static int afs_deliver_cb_probe(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
David Howells372ee162016-08-03 14:11:40 +0100428 int ret;
429
David Howellsd0016482016-08-30 20:42:14 +0100430 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
David Howellsd0016482016-08-30 20:42:14 +0100432 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100433 if (ret < 0)
434 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
David Howells98bf40c2017-11-02 15:27:53 +0000436 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
437 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
David Howells341f7412017-01-05 10:38:36 +0000439 return afs_queue_call_work(call);
David Howellsec268152007-04-26 15:49:28 -0700440}
David Howellsb908fe62007-04-26 15:58:17 -0700441
442/*
David Howells9396d492008-04-29 01:03:22 -0700443 * allow the fileserver to quickly find out if the fileserver has been rebooted
444 */
445static void SRXAFSCB_ProbeUuid(struct work_struct *work)
446{
447 struct afs_call *call = container_of(work, struct afs_call, work);
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300448 struct afs_uuid *r = call->request;
David Howells9396d492008-04-29 01:03:22 -0700449
450 struct {
451 __be32 match;
452 } reply;
453
454 _enter("");
455
David Howellsf044c882017-11-02 15:27:45 +0000456 if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0)
David Howells9396d492008-04-29 01:03:22 -0700457 reply.match = htonl(0);
458 else
459 reply.match = htonl(1);
460
461 afs_send_simple_reply(call, &reply, sizeof(reply));
David Howells341f7412017-01-05 10:38:36 +0000462 afs_put_call(call);
David Howells9396d492008-04-29 01:03:22 -0700463 _leave("");
464}
465
466/*
467 * deliver request data to a CB.ProbeUuid call
468 */
David Howellsd0016482016-08-30 20:42:14 +0100469static int afs_deliver_cb_probe_uuid(struct afs_call *call)
David Howells9396d492008-04-29 01:03:22 -0700470{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300471 struct afs_uuid *r;
David Howells9396d492008-04-29 01:03:22 -0700472 unsigned loop;
473 __be32 *b;
474 int ret;
475
David Howellsd0016482016-08-30 20:42:14 +0100476 _enter("{%u}", call->unmarshall);
David Howells9396d492008-04-29 01:03:22 -0700477
478 switch (call->unmarshall) {
479 case 0:
480 call->offset = 0;
481 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
482 if (!call->buffer)
483 return -ENOMEM;
484 call->unmarshall++;
485
486 case 1:
487 _debug("extract UUID");
David Howellsd0016482016-08-30 20:42:14 +0100488 ret = afs_extract_data(call, call->buffer,
489 11 * sizeof(__be32), false);
David Howells9396d492008-04-29 01:03:22 -0700490 switch (ret) {
491 case 0: break;
492 case -EAGAIN: return 0;
493 default: return ret;
494 }
495
496 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300497 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700498 if (!call->request)
499 return -ENOMEM;
500
501 b = call->buffer;
502 r = call->request;
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300503 r->time_low = ntohl(b[0]);
504 r->time_mid = ntohl(b[1]);
505 r->time_hi_and_version = ntohl(b[2]);
David Howells9396d492008-04-29 01:03:22 -0700506 r->clock_seq_hi_and_reserved = ntohl(b[3]);
507 r->clock_seq_low = ntohl(b[4]);
508
509 for (loop = 0; loop < 6; loop++)
510 r->node[loop] = ntohl(b[loop + 5]);
511
512 call->offset = 0;
513 call->unmarshall++;
514
515 case 2:
David Howells9396d492008-04-29 01:03:22 -0700516 break;
517 }
518
David Howells98bf40c2017-11-02 15:27:53 +0000519 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
520 return -EIO;
David Howells9396d492008-04-29 01:03:22 -0700521
David Howells341f7412017-01-05 10:38:36 +0000522 return afs_queue_call_work(call);
David Howells9396d492008-04-29 01:03:22 -0700523}
524
525/*
David Howellsb908fe62007-04-26 15:58:17 -0700526 * allow the fileserver to ask about the cache manager's capabilities
527 */
David Howells7c80bcc2008-04-29 01:03:21 -0700528static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
David Howellsb908fe62007-04-26 15:58:17 -0700529{
530 struct afs_interface *ifs;
531 struct afs_call *call = container_of(work, struct afs_call, work);
532 int loop, nifs;
533
534 struct {
535 struct /* InterfaceAddr */ {
536 __be32 nifs;
537 __be32 uuid[11];
538 __be32 ifaddr[32];
539 __be32 netmask[32];
540 __be32 mtu[32];
541 } ia;
542 struct /* Capabilities */ {
543 __be32 capcount;
544 __be32 caps[1];
545 } cap;
546 } reply;
547
548 _enter("");
549
550 nifs = 0;
551 ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL);
552 if (ifs) {
553 nifs = afs_get_ipv4_interfaces(ifs, 32, false);
554 if (nifs < 0) {
555 kfree(ifs);
556 ifs = NULL;
557 nifs = 0;
558 }
559 }
560
561 memset(&reply, 0, sizeof(reply));
562 reply.ia.nifs = htonl(nifs);
563
David Howellsf044c882017-11-02 15:27:45 +0000564 reply.ia.uuid[0] = call->net->uuid.time_low;
565 reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid));
566 reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version));
567 reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved);
568 reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low);
David Howellsb908fe62007-04-26 15:58:17 -0700569 for (loop = 0; loop < 6; loop++)
David Howellsf044c882017-11-02 15:27:45 +0000570 reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]);
David Howellsb908fe62007-04-26 15:58:17 -0700571
572 if (ifs) {
573 for (loop = 0; loop < nifs; loop++) {
574 reply.ia.ifaddr[loop] = ifs[loop].address.s_addr;
575 reply.ia.netmask[loop] = ifs[loop].netmask.s_addr;
576 reply.ia.mtu[loop] = htonl(ifs[loop].mtu);
577 }
Patrick McHardy5b35fad2007-05-03 03:27:39 -0700578 kfree(ifs);
David Howellsb908fe62007-04-26 15:58:17 -0700579 }
580
581 reply.cap.capcount = htonl(1);
582 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
583 afs_send_simple_reply(call, &reply, sizeof(reply));
David Howells341f7412017-01-05 10:38:36 +0000584 afs_put_call(call);
David Howellsb908fe62007-04-26 15:58:17 -0700585 _leave("");
586}
587
588/*
David Howells7c80bcc2008-04-29 01:03:21 -0700589 * deliver request data to a CB.TellMeAboutYourself call
David Howellsb908fe62007-04-26 15:58:17 -0700590 */
David Howellsd0016482016-08-30 20:42:14 +0100591static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
David Howellsb908fe62007-04-26 15:58:17 -0700592{
David Howells372ee162016-08-03 14:11:40 +0100593 int ret;
594
David Howellsd0016482016-08-30 20:42:14 +0100595 _enter("");
David Howellsb908fe62007-04-26 15:58:17 -0700596
David Howellsd0016482016-08-30 20:42:14 +0100597 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100598 if (ret < 0)
599 return ret;
David Howellsb908fe62007-04-26 15:58:17 -0700600
David Howells98bf40c2017-11-02 15:27:53 +0000601 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
602 return -EIO;
David Howellsb908fe62007-04-26 15:58:17 -0700603
David Howells341f7412017-01-05 10:38:36 +0000604 return afs_queue_call_work(call);
David Howellsb908fe62007-04-26 15:58:17 -0700605}