blob: 3062cceb5c2aebcc4a15e3c52d1b26ecea82f20d [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,
44 .abort_to_error = afs_abort_to_error,
45 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000046 .work = SRXAFSCB_CallBack,
Linus Torvalds1da177e2005-04-16 15:20:36 -070047};
48
David Howells08e0e7c2007-04-26 15:55:03 -070049/*
50 * CB.InitCallBackState operation type
51 */
David Howells8e8d7f12017-01-05 10:38:34 +000052static CM_NAME(InitCallBackState);
David Howells08e0e7c2007-04-26 15:55:03 -070053static const struct afs_call_type afs_SRXCBInitCallBackState = {
David Howells8e8d7f12017-01-05 10:38:34 +000054 .name = afs_SRXCBInitCallBackState_name,
David Howells08e0e7c2007-04-26 15:55:03 -070055 .deliver = afs_deliver_cb_init_call_back_state,
56 .abort_to_error = afs_abort_to_error,
57 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000058 .work = SRXAFSCB_InitCallBackState,
Linus Torvalds1da177e2005-04-16 15:20:36 -070059};
60
David Howells08e0e7c2007-04-26 15:55:03 -070061/*
David Howellsc35eccb2007-04-26 15:58:49 -070062 * CB.InitCallBackState3 operation type
63 */
David Howells8e8d7f12017-01-05 10:38:34 +000064static CM_NAME(InitCallBackState3);
David Howellsc35eccb2007-04-26 15:58:49 -070065static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
David Howells8e8d7f12017-01-05 10:38:34 +000066 .name = afs_SRXCBInitCallBackState3_name,
David Howellsc35eccb2007-04-26 15:58:49 -070067 .deliver = afs_deliver_cb_init_call_back_state3,
68 .abort_to_error = afs_abort_to_error,
69 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000070 .work = SRXAFSCB_InitCallBackState,
David Howellsc35eccb2007-04-26 15:58:49 -070071};
72
73/*
David Howells08e0e7c2007-04-26 15:55:03 -070074 * CB.Probe operation type
75 */
David Howells8e8d7f12017-01-05 10:38:34 +000076static CM_NAME(Probe);
David Howells08e0e7c2007-04-26 15:55:03 -070077static const struct afs_call_type afs_SRXCBProbe = {
David Howells8e8d7f12017-01-05 10:38:34 +000078 .name = afs_SRXCBProbe_name,
David Howells08e0e7c2007-04-26 15:55:03 -070079 .deliver = afs_deliver_cb_probe,
80 .abort_to_error = afs_abort_to_error,
81 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000082 .work = SRXAFSCB_Probe,
David Howells08e0e7c2007-04-26 15:55:03 -070083};
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085/*
David Howells9396d492008-04-29 01:03:22 -070086 * CB.ProbeUuid operation type
87 */
David Howells8e8d7f12017-01-05 10:38:34 +000088static CM_NAME(ProbeUuid);
David Howells9396d492008-04-29 01:03:22 -070089static const struct afs_call_type afs_SRXCBProbeUuid = {
David Howells8e8d7f12017-01-05 10:38:34 +000090 .name = afs_SRXCBProbeUuid_name,
David Howells9396d492008-04-29 01:03:22 -070091 .deliver = afs_deliver_cb_probe_uuid,
92 .abort_to_error = afs_abort_to_error,
93 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000094 .work = SRXAFSCB_ProbeUuid,
David Howells9396d492008-04-29 01:03:22 -070095};
96
97/*
David Howells7c80bcc2008-04-29 01:03:21 -070098 * CB.TellMeAboutYourself operation type
David Howellsb908fe62007-04-26 15:58:17 -070099 */
David Howells8e8d7f12017-01-05 10:38:34 +0000100static CM_NAME(TellMeAboutYourself);
David Howells7c80bcc2008-04-29 01:03:21 -0700101static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
David Howells8e8d7f12017-01-05 10:38:34 +0000102 .name = afs_SRXCBTellMeAboutYourself_name,
David Howells7c80bcc2008-04-29 01:03:21 -0700103 .deliver = afs_deliver_cb_tell_me_about_yourself,
David Howellsb908fe62007-04-26 15:58:17 -0700104 .abort_to_error = afs_abort_to_error,
105 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +0000106 .work = SRXAFSCB_TellMeAboutYourself,
David Howellsb908fe62007-04-26 15:58:17 -0700107};
108
109/*
David Howells08e0e7c2007-04-26 15:55:03 -0700110 * route an incoming cache manager call
111 * - return T if supported, F if not
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 */
David Howells08e0e7c2007-04-26 15:55:03 -0700113bool afs_cm_incoming_call(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
David Howells50a2c952016-10-13 08:27:10 +0100115 _enter("{CB.OP %u}", call->operation_ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
David Howells50a2c952016-10-13 08:27:10 +0100117 switch (call->operation_ID) {
David Howells08e0e7c2007-04-26 15:55:03 -0700118 case CBCallBack:
119 call->type = &afs_SRXCBCallBack;
120 return true;
121 case CBInitCallBackState:
122 call->type = &afs_SRXCBInitCallBackState;
123 return true;
David Howellsc35eccb2007-04-26 15:58:49 -0700124 case CBInitCallBackState3:
125 call->type = &afs_SRXCBInitCallBackState3;
126 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700127 case CBProbe:
128 call->type = &afs_SRXCBProbe;
129 return true;
David Howells7c80bcc2008-04-29 01:03:21 -0700130 case CBTellMeAboutYourself:
131 call->type = &afs_SRXCBTellMeAboutYourself;
David Howellsb908fe62007-04-26 15:58:17 -0700132 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700133 default:
134 return false;
135 }
David Howellsec268152007-04-26 15:49:28 -0700136}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/*
David Howells08e0e7c2007-04-26 15:55:03 -0700139 * clean up a cache manager call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 */
David Howells08e0e7c2007-04-26 15:55:03 -0700141static void afs_cm_destructor(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
David Howells08e0e7c2007-04-26 15:55:03 -0700143 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
David Howells6c67c7c2014-05-21 14:48:05 +0100145 /* Break the callbacks here so that we do it after the final ACK is
146 * received. The step number here must match the final number in
147 * afs_deliver_cb_callback().
148 */
David Howellsd0016482016-08-30 20:42:14 +0100149 if (call->unmarshall == 5) {
David Howells6c67c7c2014-05-21 14:48:05 +0100150 ASSERT(call->server && call->count && call->request);
151 afs_break_callbacks(call->server, call->count, call->request);
152 }
153
David Howells08e0e7c2007-04-26 15:55:03 -0700154 afs_put_server(call->server);
155 call->server = NULL;
156 kfree(call->buffer);
157 call->buffer = NULL;
David Howellsec268152007-04-26 15:49:28 -0700158}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160/*
David Howells08e0e7c2007-04-26 15:55:03 -0700161 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 */
David Howells08e0e7c2007-04-26 15:55:03 -0700163static void SRXAFSCB_CallBack(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
David Howells08e0e7c2007-04-26 15:55:03 -0700165 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
David Howells08e0e7c2007-04-26 15:55:03 -0700167 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
David Howells08e0e7c2007-04-26 15:55:03 -0700169 /* be sure to send the reply *before* attempting to spam the AFS server
170 * with FSFetchStatus requests on the vnodes with broken callbacks lest
171 * the AFS server get into a vicious cycle of trying to break further
172 * callbacks because it hadn't received completion of the CBCallBack op
173 * yet */
174 afs_send_empty_reply(call);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
David Howells08e0e7c2007-04-26 15:55:03 -0700176 afs_break_callbacks(call->server, call->count, call->request);
David Howells341f7412017-01-05 10:38:36 +0000177 afs_put_call(call);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700179}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181/*
David Howells08e0e7c2007-04-26 15:55:03 -0700182 * deliver request data to a CB.CallBack call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 */
David Howellsd0016482016-08-30 20:42:14 +0100184static int afs_deliver_cb_callback(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
David Howells8324f0b2016-08-30 09:49:29 +0100186 struct sockaddr_rxrpc srx;
David Howells08e0e7c2007-04-26 15:55:03 -0700187 struct afs_callback *cb;
188 struct afs_server *server;
David Howells08e0e7c2007-04-26 15:55:03 -0700189 __be32 *bp;
David Howells08e0e7c2007-04-26 15:55:03 -0700190 int ret, loop;
191
David Howellsd0016482016-08-30 20:42:14 +0100192 _enter("{%u}", call->unmarshall);
David Howells08e0e7c2007-04-26 15:55:03 -0700193
194 switch (call->unmarshall) {
195 case 0:
David Howells8324f0b2016-08-30 09:49:29 +0100196 rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
David Howells08e0e7c2007-04-26 15:55:03 -0700197 call->offset = 0;
198 call->unmarshall++;
199
200 /* extract the FID array and its count in two steps */
201 case 1:
202 _debug("extract FID count");
David Howellsd0016482016-08-30 20:42:14 +0100203 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +0100204 if (ret < 0)
205 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700206
207 call->count = ntohl(call->tmp);
208 _debug("FID count: %u", call->count);
209 if (call->count > AFSCBMAX)
210 return -EBADMSG;
211
212 call->buffer = kmalloc(call->count * 3 * 4, GFP_KERNEL);
213 if (!call->buffer)
214 return -ENOMEM;
215 call->offset = 0;
216 call->unmarshall++;
217
218 case 2:
219 _debug("extract FID array");
David Howellsd0016482016-08-30 20:42:14 +0100220 ret = afs_extract_data(call, call->buffer,
221 call->count * 3 * 4, true);
David Howells372ee162016-08-03 14:11:40 +0100222 if (ret < 0)
223 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700224
225 _debug("unmarshall FID array");
226 call->request = kcalloc(call->count,
227 sizeof(struct afs_callback),
228 GFP_KERNEL);
229 if (!call->request)
230 return -ENOMEM;
231
232 cb = call->request;
233 bp = call->buffer;
234 for (loop = call->count; loop > 0; loop--, cb++) {
235 cb->fid.vid = ntohl(*bp++);
236 cb->fid.vnode = ntohl(*bp++);
237 cb->fid.unique = ntohl(*bp++);
238 cb->type = AFSCM_CB_UNTYPED;
239 }
240
241 call->offset = 0;
242 call->unmarshall++;
243
244 /* extract the callback array and its count in two steps */
245 case 3:
246 _debug("extract CB count");
David Howellsd0016482016-08-30 20:42:14 +0100247 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +0100248 if (ret < 0)
249 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700250
Marc Dionnebcd89272017-03-16 16:27:44 +0000251 call->count2 = ntohl(call->tmp);
252 _debug("CB count: %u", call->count2);
253 if (call->count2 != call->count && call->count2 != 0)
David Howells08e0e7c2007-04-26 15:55:03 -0700254 return -EBADMSG;
255 call->offset = 0;
256 call->unmarshall++;
David Howells08e0e7c2007-04-26 15:55:03 -0700257
258 case 4:
259 _debug("extract CB array");
David Howellsd0016482016-08-30 20:42:14 +0100260 ret = afs_extract_data(call, call->buffer,
Marc Dionnebcd89272017-03-16 16:27:44 +0000261 call->count2 * 3 * 4, false);
David Howells372ee162016-08-03 14:11:40 +0100262 if (ret < 0)
263 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700264
265 _debug("unmarshall CB array");
266 cb = call->request;
267 bp = call->buffer;
Marc Dionnebcd89272017-03-16 16:27:44 +0000268 for (loop = call->count2; loop > 0; loop--, cb++) {
David Howells08e0e7c2007-04-26 15:55:03 -0700269 cb->version = ntohl(*bp++);
270 cb->expiry = ntohl(*bp++);
271 cb->type = ntohl(*bp++);
272 }
273
David Howells08e0e7c2007-04-26 15:55:03 -0700274 call->offset = 0;
275 call->unmarshall++;
276
David Howells6c67c7c2014-05-21 14:48:05 +0100277 /* Record that the message was unmarshalled successfully so
278 * that the call destructor can know do the callback breaking
279 * work, even if the final ACK isn't received.
280 *
281 * If the step number changes, then afs_cm_destructor() must be
282 * updated also.
283 */
284 call->unmarshall++;
David Howellsd0016482016-08-30 20:42:14 +0100285 case 5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 break;
287 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
David Howells08e0e7c2007-04-26 15:55:03 -0700289 call->state = AFS_CALL_REPLYING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
David Howells08e0e7c2007-04-26 15:55:03 -0700291 /* we'll need the file server record as that tells us which set of
292 * vnodes to operate upon */
David Howells8324f0b2016-08-30 09:49:29 +0100293 server = afs_find_server(&srx);
David Howells08e0e7c2007-04-26 15:55:03 -0700294 if (!server)
295 return -ENOTCONN;
296 call->server = server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
David Howells341f7412017-01-05 10:38:36 +0000298 return afs_queue_call_work(call);
David Howellsec268152007-04-26 15:49:28 -0700299}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301/*
David Howells08e0e7c2007-04-26 15:55:03 -0700302 * allow the fileserver to request callback state (re-)initialisation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 */
David Howells08e0e7c2007-04-26 15:55:03 -0700304static void SRXAFSCB_InitCallBackState(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
David Howells08e0e7c2007-04-26 15:55:03 -0700306 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
David Howells08e0e7c2007-04-26 15:55:03 -0700308 _enter("{%p}", call->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
David Howells08e0e7c2007-04-26 15:55:03 -0700310 afs_init_callback_state(call->server);
311 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000312 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700313 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700314}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316/*
David Howells08e0e7c2007-04-26 15:55:03 -0700317 * deliver request data to a CB.InitCallBackState call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 */
David Howellsd0016482016-08-30 20:42:14 +0100319static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
David Howells8324f0b2016-08-30 09:49:29 +0100321 struct sockaddr_rxrpc srx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 struct afs_server *server;
David Howells372ee162016-08-03 14:11:40 +0100323 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
David Howellsd0016482016-08-30 20:42:14 +0100325 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
David Howells8324f0b2016-08-30 09:49:29 +0100327 rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
328
David Howellsd0016482016-08-30 20:42:14 +0100329 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100330 if (ret < 0)
331 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
David Howells08e0e7c2007-04-26 15:55:03 -0700333 /* no unmarshalling required */
334 call->state = AFS_CALL_REPLYING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
David Howells08e0e7c2007-04-26 15:55:03 -0700336 /* we'll need the file server record as that tells us which set of
337 * vnodes to operate upon */
David Howells8324f0b2016-08-30 09:49:29 +0100338 server = afs_find_server(&srx);
David Howells08e0e7c2007-04-26 15:55:03 -0700339 if (!server)
340 return -ENOTCONN;
341 call->server = server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
David Howells341f7412017-01-05 10:38:36 +0000343 return afs_queue_call_work(call);
David Howellsec268152007-04-26 15:49:28 -0700344}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346/*
David Howellsc35eccb2007-04-26 15:58:49 -0700347 * deliver request data to a CB.InitCallBackState3 call
348 */
David Howellsd0016482016-08-30 20:42:14 +0100349static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
David Howellsc35eccb2007-04-26 15:58:49 -0700350{
David Howells8324f0b2016-08-30 09:49:29 +0100351 struct sockaddr_rxrpc srx;
David Howellsc35eccb2007-04-26 15:58:49 -0700352 struct afs_server *server;
David Howellsff548772017-02-10 16:34:07 +0000353 struct uuid_v1 *r;
David Howellsd0016482016-08-30 20:42:14 +0100354 unsigned loop;
355 __be32 *b;
356 int ret;
David Howellsc35eccb2007-04-26 15:58:49 -0700357
David Howellsd0016482016-08-30 20:42:14 +0100358 _enter("");
David Howellsc35eccb2007-04-26 15:58:49 -0700359
David Howells8324f0b2016-08-30 09:49:29 +0100360 rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
361
David Howellsd0016482016-08-30 20:42:14 +0100362 _enter("{%u}", call->unmarshall);
363
364 switch (call->unmarshall) {
365 case 0:
366 call->offset = 0;
367 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
368 if (!call->buffer)
369 return -ENOMEM;
370 call->unmarshall++;
371
372 case 1:
373 _debug("extract UUID");
374 ret = afs_extract_data(call, call->buffer,
375 11 * sizeof(__be32), false);
376 switch (ret) {
377 case 0: break;
378 case -EAGAIN: return 0;
379 default: return ret;
380 }
381
382 _debug("unmarshall UUID");
David Howellsff548772017-02-10 16:34:07 +0000383 call->request = kmalloc(sizeof(struct uuid_v1), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100384 if (!call->request)
385 return -ENOMEM;
386
387 b = call->buffer;
388 r = call->request;
David Howellsff548772017-02-10 16:34:07 +0000389 r->time_low = b[0];
390 r->time_mid = htons(ntohl(b[1]));
391 r->time_hi_and_version = htons(ntohl(b[2]));
David Howellsd0016482016-08-30 20:42:14 +0100392 r->clock_seq_hi_and_reserved = ntohl(b[3]);
393 r->clock_seq_low = ntohl(b[4]);
394
395 for (loop = 0; loop < 6; loop++)
396 r->node[loop] = ntohl(b[loop + 5]);
397
398 call->offset = 0;
399 call->unmarshall++;
400
401 case 2:
402 break;
403 }
David Howellsc35eccb2007-04-26 15:58:49 -0700404
405 /* no unmarshalling required */
406 call->state = AFS_CALL_REPLYING;
407
408 /* we'll need the file server record as that tells us which set of
409 * vnodes to operate upon */
David Howells8324f0b2016-08-30 09:49:29 +0100410 server = afs_find_server(&srx);
David Howellsc35eccb2007-04-26 15:58:49 -0700411 if (!server)
412 return -ENOTCONN;
413 call->server = server;
414
David Howells341f7412017-01-05 10:38:36 +0000415 return afs_queue_call_work(call);
David Howellsc35eccb2007-04-26 15:58:49 -0700416}
417
418/*
David Howells08e0e7c2007-04-26 15:55:03 -0700419 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 */
David Howells08e0e7c2007-04-26 15:55:03 -0700421static void SRXAFSCB_Probe(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422{
David Howells08e0e7c2007-04-26 15:55:03 -0700423 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
David Howells08e0e7c2007-04-26 15:55:03 -0700425 _enter("");
426 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000427 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700428 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700429}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431/*
David Howells08e0e7c2007-04-26 15:55:03 -0700432 * deliver request data to a CB.Probe call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 */
David Howellsd0016482016-08-30 20:42:14 +0100434static int afs_deliver_cb_probe(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
David Howells372ee162016-08-03 14:11:40 +0100436 int ret;
437
David Howellsd0016482016-08-30 20:42:14 +0100438 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
David Howellsd0016482016-08-30 20:42:14 +0100440 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100441 if (ret < 0)
442 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
David Howells08e0e7c2007-04-26 15:55:03 -0700444 /* no unmarshalling required */
445 call->state = AFS_CALL_REPLYING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
David Howells341f7412017-01-05 10:38:36 +0000447 return afs_queue_call_work(call);
David Howellsec268152007-04-26 15:49:28 -0700448}
David Howellsb908fe62007-04-26 15:58:17 -0700449
450/*
David Howells9396d492008-04-29 01:03:22 -0700451 * allow the fileserver to quickly find out if the fileserver has been rebooted
452 */
453static void SRXAFSCB_ProbeUuid(struct work_struct *work)
454{
455 struct afs_call *call = container_of(work, struct afs_call, work);
David Howellsff548772017-02-10 16:34:07 +0000456 struct uuid_v1 *r = call->request;
David Howells9396d492008-04-29 01:03:22 -0700457
458 struct {
459 __be32 match;
460 } reply;
461
462 _enter("");
463
David Howells9396d492008-04-29 01:03:22 -0700464 if (memcmp(r, &afs_uuid, sizeof(afs_uuid)) == 0)
465 reply.match = htonl(0);
466 else
467 reply.match = htonl(1);
468
469 afs_send_simple_reply(call, &reply, sizeof(reply));
David Howells341f7412017-01-05 10:38:36 +0000470 afs_put_call(call);
David Howells9396d492008-04-29 01:03:22 -0700471 _leave("");
472}
473
474/*
475 * deliver request data to a CB.ProbeUuid call
476 */
David Howellsd0016482016-08-30 20:42:14 +0100477static int afs_deliver_cb_probe_uuid(struct afs_call *call)
David Howells9396d492008-04-29 01:03:22 -0700478{
David Howellsff548772017-02-10 16:34:07 +0000479 struct uuid_v1 *r;
David Howells9396d492008-04-29 01:03:22 -0700480 unsigned loop;
481 __be32 *b;
482 int ret;
483
David Howellsd0016482016-08-30 20:42:14 +0100484 _enter("{%u}", call->unmarshall);
David Howells9396d492008-04-29 01:03:22 -0700485
486 switch (call->unmarshall) {
487 case 0:
488 call->offset = 0;
489 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
490 if (!call->buffer)
491 return -ENOMEM;
492 call->unmarshall++;
493
494 case 1:
495 _debug("extract UUID");
David Howellsd0016482016-08-30 20:42:14 +0100496 ret = afs_extract_data(call, call->buffer,
497 11 * sizeof(__be32), false);
David Howells9396d492008-04-29 01:03:22 -0700498 switch (ret) {
499 case 0: break;
500 case -EAGAIN: return 0;
501 default: return ret;
502 }
503
504 _debug("unmarshall UUID");
David Howellsff548772017-02-10 16:34:07 +0000505 call->request = kmalloc(sizeof(struct uuid_v1), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700506 if (!call->request)
507 return -ENOMEM;
508
509 b = call->buffer;
510 r = call->request;
David Howellsff548772017-02-10 16:34:07 +0000511 r->time_low = b[0];
512 r->time_mid = htons(ntohl(b[1]));
513 r->time_hi_and_version = htons(ntohl(b[2]));
David Howells9396d492008-04-29 01:03:22 -0700514 r->clock_seq_hi_and_reserved = ntohl(b[3]);
515 r->clock_seq_low = ntohl(b[4]);
516
517 for (loop = 0; loop < 6; loop++)
518 r->node[loop] = ntohl(b[loop + 5]);
519
520 call->offset = 0;
521 call->unmarshall++;
522
523 case 2:
David Howells9396d492008-04-29 01:03:22 -0700524 break;
525 }
526
David Howells9396d492008-04-29 01:03:22 -0700527 call->state = AFS_CALL_REPLYING;
528
David Howells341f7412017-01-05 10:38:36 +0000529 return afs_queue_call_work(call);
David Howells9396d492008-04-29 01:03:22 -0700530}
531
532/*
David Howellsb908fe62007-04-26 15:58:17 -0700533 * allow the fileserver to ask about the cache manager's capabilities
534 */
David Howells7c80bcc2008-04-29 01:03:21 -0700535static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
David Howellsb908fe62007-04-26 15:58:17 -0700536{
537 struct afs_interface *ifs;
538 struct afs_call *call = container_of(work, struct afs_call, work);
539 int loop, nifs;
540
541 struct {
542 struct /* InterfaceAddr */ {
543 __be32 nifs;
544 __be32 uuid[11];
545 __be32 ifaddr[32];
546 __be32 netmask[32];
547 __be32 mtu[32];
548 } ia;
549 struct /* Capabilities */ {
550 __be32 capcount;
551 __be32 caps[1];
552 } cap;
553 } reply;
554
555 _enter("");
556
557 nifs = 0;
558 ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL);
559 if (ifs) {
560 nifs = afs_get_ipv4_interfaces(ifs, 32, false);
561 if (nifs < 0) {
562 kfree(ifs);
563 ifs = NULL;
564 nifs = 0;
565 }
566 }
567
568 memset(&reply, 0, sizeof(reply));
569 reply.ia.nifs = htonl(nifs);
570
David Howellsff548772017-02-10 16:34:07 +0000571 reply.ia.uuid[0] = afs_uuid.time_low;
572 reply.ia.uuid[1] = htonl(ntohs(afs_uuid.time_mid));
573 reply.ia.uuid[2] = htonl(ntohs(afs_uuid.time_hi_and_version));
David Howellsb908fe62007-04-26 15:58:17 -0700574 reply.ia.uuid[3] = htonl((s8) afs_uuid.clock_seq_hi_and_reserved);
575 reply.ia.uuid[4] = htonl((s8) afs_uuid.clock_seq_low);
576 for (loop = 0; loop < 6; loop++)
577 reply.ia.uuid[loop + 5] = htonl((s8) afs_uuid.node[loop]);
578
579 if (ifs) {
580 for (loop = 0; loop < nifs; loop++) {
581 reply.ia.ifaddr[loop] = ifs[loop].address.s_addr;
582 reply.ia.netmask[loop] = ifs[loop].netmask.s_addr;
583 reply.ia.mtu[loop] = htonl(ifs[loop].mtu);
584 }
Patrick McHardy5b35fad2007-05-03 03:27:39 -0700585 kfree(ifs);
David Howellsb908fe62007-04-26 15:58:17 -0700586 }
587
588 reply.cap.capcount = htonl(1);
589 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
590 afs_send_simple_reply(call, &reply, sizeof(reply));
David Howells341f7412017-01-05 10:38:36 +0000591 afs_put_call(call);
David Howellsb908fe62007-04-26 15:58:17 -0700592 _leave("");
593}
594
595/*
David Howells7c80bcc2008-04-29 01:03:21 -0700596 * deliver request data to a CB.TellMeAboutYourself call
David Howellsb908fe62007-04-26 15:58:17 -0700597 */
David Howellsd0016482016-08-30 20:42:14 +0100598static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
David Howellsb908fe62007-04-26 15:58:17 -0700599{
David Howells372ee162016-08-03 14:11:40 +0100600 int ret;
601
David Howellsd0016482016-08-30 20:42:14 +0100602 _enter("");
David Howellsb908fe62007-04-26 15:58:17 -0700603
David Howellsd0016482016-08-30 20:42:14 +0100604 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100605 if (ret < 0)
606 return ret;
David Howellsb908fe62007-04-26 15:58:17 -0700607
608 /* no unmarshalling required */
609 call->state = AFS_CALL_REPLYING;
610
David Howells341f7412017-01-05 10:38:36 +0000611 return afs_queue_call_work(call);
David Howellsb908fe62007-04-26 15:58:17 -0700612}