blob: d764236072b192d33a0b8eedb3821d7391991067 [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 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
David Howells08e0e7c2007-04-26 15:55:03 -070028/*
29 * CB.CallBack operation type
30 */
31static const struct afs_call_type afs_SRXCBCallBack = {
David Howells00d3b7a2007-04-26 15:57:07 -070032 .name = "CB.CallBack",
David Howells08e0e7c2007-04-26 15:55:03 -070033 .deliver = afs_deliver_cb_callback,
34 .abort_to_error = afs_abort_to_error,
35 .destructor = afs_cm_destructor,
Linus Torvalds1da177e2005-04-16 15:20:36 -070036};
37
David Howells08e0e7c2007-04-26 15:55:03 -070038/*
39 * CB.InitCallBackState operation type
40 */
41static const struct afs_call_type afs_SRXCBInitCallBackState = {
David Howells00d3b7a2007-04-26 15:57:07 -070042 .name = "CB.InitCallBackState",
David Howells08e0e7c2007-04-26 15:55:03 -070043 .deliver = afs_deliver_cb_init_call_back_state,
44 .abort_to_error = afs_abort_to_error,
45 .destructor = afs_cm_destructor,
Linus Torvalds1da177e2005-04-16 15:20:36 -070046};
47
David Howells08e0e7c2007-04-26 15:55:03 -070048/*
David Howellsc35eccb2007-04-26 15:58:49 -070049 * CB.InitCallBackState3 operation type
50 */
51static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
52 .name = "CB.InitCallBackState3",
53 .deliver = afs_deliver_cb_init_call_back_state3,
54 .abort_to_error = afs_abort_to_error,
55 .destructor = afs_cm_destructor,
56};
57
58/*
David Howells08e0e7c2007-04-26 15:55:03 -070059 * CB.Probe operation type
60 */
61static const struct afs_call_type afs_SRXCBProbe = {
David Howells00d3b7a2007-04-26 15:57:07 -070062 .name = "CB.Probe",
David Howells08e0e7c2007-04-26 15:55:03 -070063 .deliver = afs_deliver_cb_probe,
64 .abort_to_error = afs_abort_to_error,
65 .destructor = afs_cm_destructor,
66};
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Linus Torvalds1da177e2005-04-16 15:20:36 -070068/*
David Howells9396d492008-04-29 01:03:22 -070069 * CB.ProbeUuid operation type
70 */
71static const struct afs_call_type afs_SRXCBProbeUuid = {
72 .name = "CB.ProbeUuid",
73 .deliver = afs_deliver_cb_probe_uuid,
74 .abort_to_error = afs_abort_to_error,
75 .destructor = afs_cm_destructor,
76};
77
78/*
David Howells7c80bcc2008-04-29 01:03:21 -070079 * CB.TellMeAboutYourself operation type
David Howellsb908fe62007-04-26 15:58:17 -070080 */
David Howells7c80bcc2008-04-29 01:03:21 -070081static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
82 .name = "CB.TellMeAboutYourself",
83 .deliver = afs_deliver_cb_tell_me_about_yourself,
David Howellsb908fe62007-04-26 15:58:17 -070084 .abort_to_error = afs_abort_to_error,
85 .destructor = afs_cm_destructor,
86};
87
88/*
David Howells08e0e7c2007-04-26 15:55:03 -070089 * route an incoming cache manager call
90 * - return T if supported, F if not
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 */
David Howells08e0e7c2007-04-26 15:55:03 -070092bool afs_cm_incoming_call(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
David Howells50a2c952016-10-13 08:27:10 +010094 _enter("{CB.OP %u}", call->operation_ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
David Howells50a2c952016-10-13 08:27:10 +010096 switch (call->operation_ID) {
David Howells08e0e7c2007-04-26 15:55:03 -070097 case CBCallBack:
98 call->type = &afs_SRXCBCallBack;
99 return true;
100 case CBInitCallBackState:
101 call->type = &afs_SRXCBInitCallBackState;
102 return true;
David Howellsc35eccb2007-04-26 15:58:49 -0700103 case CBInitCallBackState3:
104 call->type = &afs_SRXCBInitCallBackState3;
105 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700106 case CBProbe:
107 call->type = &afs_SRXCBProbe;
108 return true;
David Howells7c80bcc2008-04-29 01:03:21 -0700109 case CBTellMeAboutYourself:
110 call->type = &afs_SRXCBTellMeAboutYourself;
David Howellsb908fe62007-04-26 15:58:17 -0700111 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700112 default:
113 return false;
114 }
David Howellsec268152007-04-26 15:49:28 -0700115}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117/*
David Howells08e0e7c2007-04-26 15:55:03 -0700118 * clean up a cache manager call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 */
David Howells08e0e7c2007-04-26 15:55:03 -0700120static void afs_cm_destructor(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
David Howells08e0e7c2007-04-26 15:55:03 -0700122 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
David Howells6c67c7c2014-05-21 14:48:05 +0100124 /* Break the callbacks here so that we do it after the final ACK is
125 * received. The step number here must match the final number in
126 * afs_deliver_cb_callback().
127 */
David Howellsd0016482016-08-30 20:42:14 +0100128 if (call->unmarshall == 5) {
David Howells6c67c7c2014-05-21 14:48:05 +0100129 ASSERT(call->server && call->count && call->request);
130 afs_break_callbacks(call->server, call->count, call->request);
131 }
132
David Howells08e0e7c2007-04-26 15:55:03 -0700133 afs_put_server(call->server);
134 call->server = NULL;
135 kfree(call->buffer);
136 call->buffer = NULL;
David Howellsec268152007-04-26 15:49:28 -0700137}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139/*
David Howells08e0e7c2007-04-26 15:55:03 -0700140 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 */
David Howells08e0e7c2007-04-26 15:55:03 -0700142static void SRXAFSCB_CallBack(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
David Howells08e0e7c2007-04-26 15:55:03 -0700144 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
David Howells08e0e7c2007-04-26 15:55:03 -0700146 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
David Howells08e0e7c2007-04-26 15:55:03 -0700148 /* be sure to send the reply *before* attempting to spam the AFS server
149 * with FSFetchStatus requests on the vnodes with broken callbacks lest
150 * the AFS server get into a vicious cycle of trying to break further
151 * callbacks because it hadn't received completion of the CBCallBack op
152 * yet */
153 afs_send_empty_reply(call);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
David Howells08e0e7c2007-04-26 15:55:03 -0700155 afs_break_callbacks(call->server, call->count, call->request);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700157}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159/*
David Howells08e0e7c2007-04-26 15:55:03 -0700160 * deliver request data to a CB.CallBack call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 */
David Howellsd0016482016-08-30 20:42:14 +0100162static int afs_deliver_cb_callback(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
David Howells8324f0b2016-08-30 09:49:29 +0100164 struct sockaddr_rxrpc srx;
David Howells08e0e7c2007-04-26 15:55:03 -0700165 struct afs_callback *cb;
166 struct afs_server *server;
David Howells08e0e7c2007-04-26 15:55:03 -0700167 __be32 *bp;
168 u32 tmp;
169 int ret, loop;
170
David Howellsd0016482016-08-30 20:42:14 +0100171 _enter("{%u}", call->unmarshall);
David Howells08e0e7c2007-04-26 15:55:03 -0700172
173 switch (call->unmarshall) {
174 case 0:
David Howells8324f0b2016-08-30 09:49:29 +0100175 rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
David Howells08e0e7c2007-04-26 15:55:03 -0700176 call->offset = 0;
177 call->unmarshall++;
178
179 /* extract the FID array and its count in two steps */
180 case 1:
181 _debug("extract FID count");
David Howellsd0016482016-08-30 20:42:14 +0100182 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +0100183 if (ret < 0)
184 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700185
186 call->count = ntohl(call->tmp);
187 _debug("FID count: %u", call->count);
188 if (call->count > AFSCBMAX)
189 return -EBADMSG;
190
191 call->buffer = kmalloc(call->count * 3 * 4, GFP_KERNEL);
192 if (!call->buffer)
193 return -ENOMEM;
194 call->offset = 0;
195 call->unmarshall++;
196
197 case 2:
198 _debug("extract FID array");
David Howellsd0016482016-08-30 20:42:14 +0100199 ret = afs_extract_data(call, call->buffer,
200 call->count * 3 * 4, true);
David Howells372ee162016-08-03 14:11:40 +0100201 if (ret < 0)
202 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700203
204 _debug("unmarshall FID array");
205 call->request = kcalloc(call->count,
206 sizeof(struct afs_callback),
207 GFP_KERNEL);
208 if (!call->request)
209 return -ENOMEM;
210
211 cb = call->request;
212 bp = call->buffer;
213 for (loop = call->count; loop > 0; loop--, cb++) {
214 cb->fid.vid = ntohl(*bp++);
215 cb->fid.vnode = ntohl(*bp++);
216 cb->fid.unique = ntohl(*bp++);
217 cb->type = AFSCM_CB_UNTYPED;
218 }
219
220 call->offset = 0;
221 call->unmarshall++;
222
223 /* extract the callback array and its count in two steps */
224 case 3:
225 _debug("extract CB count");
David Howellsd0016482016-08-30 20:42:14 +0100226 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +0100227 if (ret < 0)
228 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700229
230 tmp = ntohl(call->tmp);
231 _debug("CB count: %u", tmp);
232 if (tmp != call->count && tmp != 0)
233 return -EBADMSG;
234 call->offset = 0;
235 call->unmarshall++;
David Howells08e0e7c2007-04-26 15:55:03 -0700236
237 case 4:
238 _debug("extract CB array");
David Howellsd0016482016-08-30 20:42:14 +0100239 ret = afs_extract_data(call, call->buffer,
240 call->count * 3 * 4, false);
David Howells372ee162016-08-03 14:11:40 +0100241 if (ret < 0)
242 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700243
244 _debug("unmarshall CB array");
245 cb = call->request;
246 bp = call->buffer;
247 for (loop = call->count; loop > 0; loop--, cb++) {
248 cb->version = ntohl(*bp++);
249 cb->expiry = ntohl(*bp++);
250 cb->type = ntohl(*bp++);
251 }
252
David Howells08e0e7c2007-04-26 15:55:03 -0700253 call->offset = 0;
254 call->unmarshall++;
255
David Howells6c67c7c2014-05-21 14:48:05 +0100256 /* Record that the message was unmarshalled successfully so
257 * that the call destructor can know do the callback breaking
258 * work, even if the final ACK isn't received.
259 *
260 * If the step number changes, then afs_cm_destructor() must be
261 * updated also.
262 */
263 call->unmarshall++;
David Howellsd0016482016-08-30 20:42:14 +0100264 case 5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 break;
266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
David Howells08e0e7c2007-04-26 15:55:03 -0700268 call->state = AFS_CALL_REPLYING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
David Howells08e0e7c2007-04-26 15:55:03 -0700270 /* we'll need the file server record as that tells us which set of
271 * vnodes to operate upon */
David Howells8324f0b2016-08-30 09:49:29 +0100272 server = afs_find_server(&srx);
David Howells08e0e7c2007-04-26 15:55:03 -0700273 if (!server)
274 return -ENOTCONN;
275 call->server = server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
David Howells08e0e7c2007-04-26 15:55:03 -0700277 INIT_WORK(&call->work, SRXAFSCB_CallBack);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000278 queue_work(afs_wq, &call->work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 return 0;
David Howellsec268152007-04-26 15:49:28 -0700280}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282/*
David Howells08e0e7c2007-04-26 15:55:03 -0700283 * allow the fileserver to request callback state (re-)initialisation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 */
David Howells08e0e7c2007-04-26 15:55:03 -0700285static void SRXAFSCB_InitCallBackState(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
David Howells08e0e7c2007-04-26 15:55:03 -0700287 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
David Howells08e0e7c2007-04-26 15:55:03 -0700289 _enter("{%p}", call->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
David Howells08e0e7c2007-04-26 15:55:03 -0700291 afs_init_callback_state(call->server);
292 afs_send_empty_reply(call);
293 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700294}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296/*
David Howells08e0e7c2007-04-26 15:55:03 -0700297 * deliver request data to a CB.InitCallBackState call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 */
David Howellsd0016482016-08-30 20:42:14 +0100299static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
David Howells8324f0b2016-08-30 09:49:29 +0100301 struct sockaddr_rxrpc srx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 struct afs_server *server;
David Howells372ee162016-08-03 14:11:40 +0100303 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
David Howellsd0016482016-08-30 20:42:14 +0100305 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
David Howells8324f0b2016-08-30 09:49:29 +0100307 rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
308
David Howellsd0016482016-08-30 20:42:14 +0100309 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100310 if (ret < 0)
311 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
David Howells08e0e7c2007-04-26 15:55:03 -0700313 /* no unmarshalling required */
314 call->state = AFS_CALL_REPLYING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
David Howells08e0e7c2007-04-26 15:55:03 -0700316 /* we'll need the file server record as that tells us which set of
317 * vnodes to operate upon */
David Howells8324f0b2016-08-30 09:49:29 +0100318 server = afs_find_server(&srx);
David Howells08e0e7c2007-04-26 15:55:03 -0700319 if (!server)
320 return -ENOTCONN;
321 call->server = server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
David Howells08e0e7c2007-04-26 15:55:03 -0700323 INIT_WORK(&call->work, SRXAFSCB_InitCallBackState);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000324 queue_work(afs_wq, &call->work);
David Howells08e0e7c2007-04-26 15:55:03 -0700325 return 0;
David Howellsec268152007-04-26 15:49:28 -0700326}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328/*
David Howellsc35eccb2007-04-26 15:58:49 -0700329 * deliver request data to a CB.InitCallBackState3 call
330 */
David Howellsd0016482016-08-30 20:42:14 +0100331static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
David Howellsc35eccb2007-04-26 15:58:49 -0700332{
David Howells8324f0b2016-08-30 09:49:29 +0100333 struct sockaddr_rxrpc srx;
David Howellsc35eccb2007-04-26 15:58:49 -0700334 struct afs_server *server;
David Howellsd0016482016-08-30 20:42:14 +0100335 struct afs_uuid *r;
336 unsigned loop;
337 __be32 *b;
338 int ret;
David Howellsc35eccb2007-04-26 15:58:49 -0700339
David Howellsd0016482016-08-30 20:42:14 +0100340 _enter("");
David Howellsc35eccb2007-04-26 15:58:49 -0700341
David Howells8324f0b2016-08-30 09:49:29 +0100342 rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
343
David Howellsd0016482016-08-30 20:42:14 +0100344 _enter("{%u}", call->unmarshall);
345
346 switch (call->unmarshall) {
347 case 0:
348 call->offset = 0;
349 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
350 if (!call->buffer)
351 return -ENOMEM;
352 call->unmarshall++;
353
354 case 1:
355 _debug("extract UUID");
356 ret = afs_extract_data(call, call->buffer,
357 11 * sizeof(__be32), false);
358 switch (ret) {
359 case 0: break;
360 case -EAGAIN: return 0;
361 default: return ret;
362 }
363
364 _debug("unmarshall UUID");
365 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
366 if (!call->request)
367 return -ENOMEM;
368
369 b = call->buffer;
370 r = call->request;
371 r->time_low = ntohl(b[0]);
372 r->time_mid = ntohl(b[1]);
373 r->time_hi_and_version = ntohl(b[2]);
374 r->clock_seq_hi_and_reserved = ntohl(b[3]);
375 r->clock_seq_low = ntohl(b[4]);
376
377 for (loop = 0; loop < 6; loop++)
378 r->node[loop] = ntohl(b[loop + 5]);
379
380 call->offset = 0;
381 call->unmarshall++;
382
383 case 2:
384 break;
385 }
David Howellsc35eccb2007-04-26 15:58:49 -0700386
387 /* no unmarshalling required */
388 call->state = AFS_CALL_REPLYING;
389
390 /* we'll need the file server record as that tells us which set of
391 * vnodes to operate upon */
David Howells8324f0b2016-08-30 09:49:29 +0100392 server = afs_find_server(&srx);
David Howellsc35eccb2007-04-26 15:58:49 -0700393 if (!server)
394 return -ENOTCONN;
395 call->server = server;
396
397 INIT_WORK(&call->work, SRXAFSCB_InitCallBackState);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000398 queue_work(afs_wq, &call->work);
David Howellsc35eccb2007-04-26 15:58:49 -0700399 return 0;
400}
401
402/*
David Howells08e0e7c2007-04-26 15:55:03 -0700403 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 */
David Howells08e0e7c2007-04-26 15:55:03 -0700405static void SRXAFSCB_Probe(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
David Howells08e0e7c2007-04-26 15:55:03 -0700407 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
David Howells08e0e7c2007-04-26 15:55:03 -0700409 _enter("");
410 afs_send_empty_reply(call);
411 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700412}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414/*
David Howells08e0e7c2007-04-26 15:55:03 -0700415 * deliver request data to a CB.Probe call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 */
David Howellsd0016482016-08-30 20:42:14 +0100417static int afs_deliver_cb_probe(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
David Howells372ee162016-08-03 14:11:40 +0100419 int ret;
420
David Howellsd0016482016-08-30 20:42:14 +0100421 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
David Howellsd0016482016-08-30 20:42:14 +0100423 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100424 if (ret < 0)
425 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
David Howells08e0e7c2007-04-26 15:55:03 -0700427 /* no unmarshalling required */
428 call->state = AFS_CALL_REPLYING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
David Howells08e0e7c2007-04-26 15:55:03 -0700430 INIT_WORK(&call->work, SRXAFSCB_Probe);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000431 queue_work(afs_wq, &call->work);
David Howells08e0e7c2007-04-26 15:55:03 -0700432 return 0;
David Howellsec268152007-04-26 15:49:28 -0700433}
David Howellsb908fe62007-04-26 15:58:17 -0700434
435/*
David Howells9396d492008-04-29 01:03:22 -0700436 * allow the fileserver to quickly find out if the fileserver has been rebooted
437 */
438static void SRXAFSCB_ProbeUuid(struct work_struct *work)
439{
440 struct afs_call *call = container_of(work, struct afs_call, work);
441 struct afs_uuid *r = call->request;
442
443 struct {
444 __be32 match;
445 } reply;
446
447 _enter("");
448
David Howells9396d492008-04-29 01:03:22 -0700449 if (memcmp(r, &afs_uuid, sizeof(afs_uuid)) == 0)
450 reply.match = htonl(0);
451 else
452 reply.match = htonl(1);
453
454 afs_send_simple_reply(call, &reply, sizeof(reply));
455 _leave("");
456}
457
458/*
459 * deliver request data to a CB.ProbeUuid call
460 */
David Howellsd0016482016-08-30 20:42:14 +0100461static int afs_deliver_cb_probe_uuid(struct afs_call *call)
David Howells9396d492008-04-29 01:03:22 -0700462{
463 struct afs_uuid *r;
464 unsigned loop;
465 __be32 *b;
466 int ret;
467
David Howellsd0016482016-08-30 20:42:14 +0100468 _enter("{%u}", call->unmarshall);
David Howells9396d492008-04-29 01:03:22 -0700469
470 switch (call->unmarshall) {
471 case 0:
472 call->offset = 0;
473 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
474 if (!call->buffer)
475 return -ENOMEM;
476 call->unmarshall++;
477
478 case 1:
479 _debug("extract UUID");
David Howellsd0016482016-08-30 20:42:14 +0100480 ret = afs_extract_data(call, call->buffer,
481 11 * sizeof(__be32), false);
David Howells9396d492008-04-29 01:03:22 -0700482 switch (ret) {
483 case 0: break;
484 case -EAGAIN: return 0;
485 default: return ret;
486 }
487
488 _debug("unmarshall UUID");
489 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
490 if (!call->request)
491 return -ENOMEM;
492
493 b = call->buffer;
494 r = call->request;
495 r->time_low = ntohl(b[0]);
496 r->time_mid = ntohl(b[1]);
497 r->time_hi_and_version = ntohl(b[2]);
498 r->clock_seq_hi_and_reserved = ntohl(b[3]);
499 r->clock_seq_low = ntohl(b[4]);
500
501 for (loop = 0; loop < 6; loop++)
502 r->node[loop] = ntohl(b[loop + 5]);
503
504 call->offset = 0;
505 call->unmarshall++;
506
507 case 2:
David Howells9396d492008-04-29 01:03:22 -0700508 break;
509 }
510
David Howells9396d492008-04-29 01:03:22 -0700511 call->state = AFS_CALL_REPLYING;
512
513 INIT_WORK(&call->work, SRXAFSCB_ProbeUuid);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000514 queue_work(afs_wq, &call->work);
David Howells9396d492008-04-29 01:03:22 -0700515 return 0;
516}
517
518/*
David Howellsb908fe62007-04-26 15:58:17 -0700519 * allow the fileserver to ask about the cache manager's capabilities
520 */
David Howells7c80bcc2008-04-29 01:03:21 -0700521static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
David Howellsb908fe62007-04-26 15:58:17 -0700522{
523 struct afs_interface *ifs;
524 struct afs_call *call = container_of(work, struct afs_call, work);
525 int loop, nifs;
526
527 struct {
528 struct /* InterfaceAddr */ {
529 __be32 nifs;
530 __be32 uuid[11];
531 __be32 ifaddr[32];
532 __be32 netmask[32];
533 __be32 mtu[32];
534 } ia;
535 struct /* Capabilities */ {
536 __be32 capcount;
537 __be32 caps[1];
538 } cap;
539 } reply;
540
541 _enter("");
542
543 nifs = 0;
544 ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL);
545 if (ifs) {
546 nifs = afs_get_ipv4_interfaces(ifs, 32, false);
547 if (nifs < 0) {
548 kfree(ifs);
549 ifs = NULL;
550 nifs = 0;
551 }
552 }
553
554 memset(&reply, 0, sizeof(reply));
555 reply.ia.nifs = htonl(nifs);
556
557 reply.ia.uuid[0] = htonl(afs_uuid.time_low);
558 reply.ia.uuid[1] = htonl(afs_uuid.time_mid);
559 reply.ia.uuid[2] = htonl(afs_uuid.time_hi_and_version);
560 reply.ia.uuid[3] = htonl((s8) afs_uuid.clock_seq_hi_and_reserved);
561 reply.ia.uuid[4] = htonl((s8) afs_uuid.clock_seq_low);
562 for (loop = 0; loop < 6; loop++)
563 reply.ia.uuid[loop + 5] = htonl((s8) afs_uuid.node[loop]);
564
565 if (ifs) {
566 for (loop = 0; loop < nifs; loop++) {
567 reply.ia.ifaddr[loop] = ifs[loop].address.s_addr;
568 reply.ia.netmask[loop] = ifs[loop].netmask.s_addr;
569 reply.ia.mtu[loop] = htonl(ifs[loop].mtu);
570 }
Patrick McHardy5b35fad2007-05-03 03:27:39 -0700571 kfree(ifs);
David Howellsb908fe62007-04-26 15:58:17 -0700572 }
573
574 reply.cap.capcount = htonl(1);
575 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
576 afs_send_simple_reply(call, &reply, sizeof(reply));
577
578 _leave("");
579}
580
581/*
David Howells7c80bcc2008-04-29 01:03:21 -0700582 * deliver request data to a CB.TellMeAboutYourself call
David Howellsb908fe62007-04-26 15:58:17 -0700583 */
David Howellsd0016482016-08-30 20:42:14 +0100584static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
David Howellsb908fe62007-04-26 15:58:17 -0700585{
David Howells372ee162016-08-03 14:11:40 +0100586 int ret;
587
David Howellsd0016482016-08-30 20:42:14 +0100588 _enter("");
David Howellsb908fe62007-04-26 15:58:17 -0700589
David Howellsd0016482016-08-30 20:42:14 +0100590 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100591 if (ret < 0)
592 return ret;
David Howellsb908fe62007-04-26 15:58:17 -0700593
594 /* no unmarshalling required */
595 call->state = AFS_CALL_REPLYING;
596
David Howells7c80bcc2008-04-29 01:03:21 -0700597 INIT_WORK(&call->work, SRXAFSCB_TellMeAboutYourself);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000598 queue_work(afs_wq, &call->work);
David Howellsb908fe62007-04-26 15:58:17 -0700599 return 0;
600}