blob: 168f2a4d1180dff1a835121cc54f869bb2130fb2 [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 Howells15b17522017-11-02 15:27:48 +0000109 case CBProbeUuid:
110 call->type = &afs_SRXCBProbeUuid;
111 return true;
David Howells7c80bcc2008-04-29 01:03:21 -0700112 case CBTellMeAboutYourself:
113 call->type = &afs_SRXCBTellMeAboutYourself;
David Howellsb908fe62007-04-26 15:58:17 -0700114 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700115 default:
116 return false;
117 }
David Howellsec268152007-04-26 15:49:28 -0700118}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120/*
David Howells08e0e7c2007-04-26 15:55:03 -0700121 * clean up a cache manager call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 */
David Howells08e0e7c2007-04-26 15:55:03 -0700123static void afs_cm_destructor(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
David Howells08e0e7c2007-04-26 15:55:03 -0700125 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
David Howells6c67c7c2014-05-21 14:48:05 +0100127 /* Break the callbacks here so that we do it after the final ACK is
128 * received. The step number here must match the final number in
129 * afs_deliver_cb_callback().
130 */
David Howellsd0016482016-08-30 20:42:14 +0100131 if (call->unmarshall == 5) {
David Howells6c67c7c2014-05-21 14:48:05 +0100132 ASSERT(call->server && call->count && call->request);
133 afs_break_callbacks(call->server, call->count, call->request);
134 }
135
David Howells08e0e7c2007-04-26 15:55:03 -0700136 afs_put_server(call->server);
137 call->server = NULL;
138 kfree(call->buffer);
139 call->buffer = NULL;
David Howellsec268152007-04-26 15:49:28 -0700140}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142/*
David Howells08e0e7c2007-04-26 15:55:03 -0700143 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 */
David Howells08e0e7c2007-04-26 15:55:03 -0700145static void SRXAFSCB_CallBack(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
David Howells08e0e7c2007-04-26 15:55:03 -0700147 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
David Howells08e0e7c2007-04-26 15:55:03 -0700149 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
David Howells08e0e7c2007-04-26 15:55:03 -0700151 /* be sure to send the reply *before* attempting to spam the AFS server
152 * with FSFetchStatus requests on the vnodes with broken callbacks lest
153 * the AFS server get into a vicious cycle of trying to break further
154 * callbacks because it hadn't received completion of the CBCallBack op
155 * yet */
156 afs_send_empty_reply(call);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
David Howells08e0e7c2007-04-26 15:55:03 -0700158 afs_break_callbacks(call->server, call->count, call->request);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700160}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162/*
David Howells08e0e7c2007-04-26 15:55:03 -0700163 * deliver request data to a CB.CallBack call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 */
David Howellsd0016482016-08-30 20:42:14 +0100165static int afs_deliver_cb_callback(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
David Howells8324f0b2016-08-30 09:49:29 +0100167 struct sockaddr_rxrpc srx;
David Howells08e0e7c2007-04-26 15:55:03 -0700168 struct afs_callback *cb;
169 struct afs_server *server;
David Howells08e0e7c2007-04-26 15:55:03 -0700170 __be32 *bp;
David Howells08e0e7c2007-04-26 15:55:03 -0700171 int ret, loop;
172
David Howellsd0016482016-08-30 20:42:14 +0100173 _enter("{%u}", call->unmarshall);
David Howells08e0e7c2007-04-26 15:55:03 -0700174
175 switch (call->unmarshall) {
176 case 0:
David Howells8324f0b2016-08-30 09:49:29 +0100177 rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
David Howells08e0e7c2007-04-26 15:55:03 -0700178 call->offset = 0;
179 call->unmarshall++;
180
181 /* extract the FID array and its count in two steps */
182 case 1:
183 _debug("extract FID count");
David Howellsd0016482016-08-30 20:42:14 +0100184 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +0100185 if (ret < 0)
186 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700187
188 call->count = ntohl(call->tmp);
189 _debug("FID count: %u", call->count);
190 if (call->count > AFSCBMAX)
191 return -EBADMSG;
192
193 call->buffer = kmalloc(call->count * 3 * 4, GFP_KERNEL);
194 if (!call->buffer)
195 return -ENOMEM;
196 call->offset = 0;
197 call->unmarshall++;
198
199 case 2:
200 _debug("extract FID array");
David Howellsd0016482016-08-30 20:42:14 +0100201 ret = afs_extract_data(call, call->buffer,
202 call->count * 3 * 4, true);
David Howells372ee162016-08-03 14:11:40 +0100203 if (ret < 0)
204 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700205
206 _debug("unmarshall FID array");
207 call->request = kcalloc(call->count,
208 sizeof(struct afs_callback),
209 GFP_KERNEL);
210 if (!call->request)
211 return -ENOMEM;
212
213 cb = call->request;
214 bp = call->buffer;
215 for (loop = call->count; loop > 0; loop--, cb++) {
216 cb->fid.vid = ntohl(*bp++);
217 cb->fid.vnode = ntohl(*bp++);
218 cb->fid.unique = ntohl(*bp++);
219 cb->type = AFSCM_CB_UNTYPED;
220 }
221
222 call->offset = 0;
223 call->unmarshall++;
224
225 /* extract the callback array and its count in two steps */
226 case 3:
227 _debug("extract CB count");
David Howellsd0016482016-08-30 20:42:14 +0100228 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +0100229 if (ret < 0)
230 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700231
Marc Dionneeaaad762017-03-16 16:27:44 +0000232 call->count2 = ntohl(call->tmp);
233 _debug("CB count: %u", call->count2);
234 if (call->count2 != call->count && call->count2 != 0)
David Howells08e0e7c2007-04-26 15:55:03 -0700235 return -EBADMSG;
236 call->offset = 0;
237 call->unmarshall++;
David Howells08e0e7c2007-04-26 15:55:03 -0700238
239 case 4:
240 _debug("extract CB array");
David Howellsd0016482016-08-30 20:42:14 +0100241 ret = afs_extract_data(call, call->buffer,
Marc Dionneeaaad762017-03-16 16:27:44 +0000242 call->count2 * 3 * 4, false);
David Howells372ee162016-08-03 14:11:40 +0100243 if (ret < 0)
244 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700245
246 _debug("unmarshall CB array");
247 cb = call->request;
248 bp = call->buffer;
Marc Dionneeaaad762017-03-16 16:27:44 +0000249 for (loop = call->count2; loop > 0; loop--, cb++) {
David Howells08e0e7c2007-04-26 15:55:03 -0700250 cb->version = ntohl(*bp++);
251 cb->expiry = ntohl(*bp++);
252 cb->type = ntohl(*bp++);
253 }
254
David Howells08e0e7c2007-04-26 15:55:03 -0700255 call->offset = 0;
256 call->unmarshall++;
257
David Howells6c67c7c2014-05-21 14:48:05 +0100258 /* Record that the message was unmarshalled successfully so
259 * that the call destructor can know do the callback breaking
260 * work, even if the final ACK isn't received.
261 *
262 * If the step number changes, then afs_cm_destructor() must be
263 * updated also.
264 */
265 call->unmarshall++;
David Howellsd0016482016-08-30 20:42:14 +0100266 case 5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 break;
268 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
David Howells08e0e7c2007-04-26 15:55:03 -0700270 call->state = AFS_CALL_REPLYING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
David Howells08e0e7c2007-04-26 15:55:03 -0700272 /* we'll need the file server record as that tells us which set of
273 * vnodes to operate upon */
David Howells8324f0b2016-08-30 09:49:29 +0100274 server = afs_find_server(&srx);
David Howells08e0e7c2007-04-26 15:55:03 -0700275 if (!server)
276 return -ENOTCONN;
277 call->server = server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
David Howells08e0e7c2007-04-26 15:55:03 -0700279 INIT_WORK(&call->work, SRXAFSCB_CallBack);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000280 queue_work(afs_wq, &call->work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 return 0;
David Howellsec268152007-04-26 15:49:28 -0700282}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284/*
David Howells08e0e7c2007-04-26 15:55:03 -0700285 * allow the fileserver to request callback state (re-)initialisation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 */
David Howells08e0e7c2007-04-26 15:55:03 -0700287static void SRXAFSCB_InitCallBackState(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
David Howells08e0e7c2007-04-26 15:55:03 -0700289 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
David Howells08e0e7c2007-04-26 15:55:03 -0700291 _enter("{%p}", call->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
David Howells08e0e7c2007-04-26 15:55:03 -0700293 afs_init_callback_state(call->server);
294 afs_send_empty_reply(call);
295 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700296}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298/*
David Howells08e0e7c2007-04-26 15:55:03 -0700299 * deliver request data to a CB.InitCallBackState call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 */
David Howellsd0016482016-08-30 20:42:14 +0100301static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
David Howells8324f0b2016-08-30 09:49:29 +0100303 struct sockaddr_rxrpc srx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 struct afs_server *server;
David Howells372ee162016-08-03 14:11:40 +0100305 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
David Howellsd0016482016-08-30 20:42:14 +0100307 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
David Howells8324f0b2016-08-30 09:49:29 +0100309 rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
310
David Howellsd0016482016-08-30 20:42:14 +0100311 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100312 if (ret < 0)
313 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
David Howells08e0e7c2007-04-26 15:55:03 -0700315 /* no unmarshalling required */
316 call->state = AFS_CALL_REPLYING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
David Howells08e0e7c2007-04-26 15:55:03 -0700318 /* we'll need the file server record as that tells us which set of
319 * vnodes to operate upon */
David Howells8324f0b2016-08-30 09:49:29 +0100320 server = afs_find_server(&srx);
David Howells08e0e7c2007-04-26 15:55:03 -0700321 if (!server)
322 return -ENOTCONN;
323 call->server = server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
David Howells08e0e7c2007-04-26 15:55:03 -0700325 INIT_WORK(&call->work, SRXAFSCB_InitCallBackState);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000326 queue_work(afs_wq, &call->work);
David Howells08e0e7c2007-04-26 15:55:03 -0700327 return 0;
David Howellsec268152007-04-26 15:49:28 -0700328}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330/*
David Howellsc35eccb2007-04-26 15:58:49 -0700331 * deliver request data to a CB.InitCallBackState3 call
332 */
David Howellsd0016482016-08-30 20:42:14 +0100333static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
David Howellsc35eccb2007-04-26 15:58:49 -0700334{
David Howells8324f0b2016-08-30 09:49:29 +0100335 struct sockaddr_rxrpc srx;
David Howellsc35eccb2007-04-26 15:58:49 -0700336 struct afs_server *server;
David Howellsd0016482016-08-30 20:42:14 +0100337 struct afs_uuid *r;
338 unsigned loop;
339 __be32 *b;
340 int ret;
David Howellsc35eccb2007-04-26 15:58:49 -0700341
David Howellsd0016482016-08-30 20:42:14 +0100342 _enter("");
David Howellsc35eccb2007-04-26 15:58:49 -0700343
David Howells8324f0b2016-08-30 09:49:29 +0100344 rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
345
David Howellsd0016482016-08-30 20:42:14 +0100346 _enter("{%u}", call->unmarshall);
347
348 switch (call->unmarshall) {
349 case 0:
350 call->offset = 0;
351 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
352 if (!call->buffer)
353 return -ENOMEM;
354 call->unmarshall++;
355
356 case 1:
357 _debug("extract UUID");
358 ret = afs_extract_data(call, call->buffer,
359 11 * sizeof(__be32), false);
360 switch (ret) {
361 case 0: break;
362 case -EAGAIN: return 0;
363 default: return ret;
364 }
365
366 _debug("unmarshall UUID");
367 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
368 if (!call->request)
369 return -ENOMEM;
370
371 b = call->buffer;
372 r = call->request;
373 r->time_low = ntohl(b[0]);
374 r->time_mid = ntohl(b[1]);
375 r->time_hi_and_version = ntohl(b[2]);
376 r->clock_seq_hi_and_reserved = ntohl(b[3]);
377 r->clock_seq_low = ntohl(b[4]);
378
379 for (loop = 0; loop < 6; loop++)
380 r->node[loop] = ntohl(b[loop + 5]);
381
382 call->offset = 0;
383 call->unmarshall++;
384
385 case 2:
386 break;
387 }
David Howellsc35eccb2007-04-26 15:58:49 -0700388
389 /* no unmarshalling required */
390 call->state = AFS_CALL_REPLYING;
391
392 /* we'll need the file server record as that tells us which set of
393 * vnodes to operate upon */
David Howells8324f0b2016-08-30 09:49:29 +0100394 server = afs_find_server(&srx);
David Howellsc35eccb2007-04-26 15:58:49 -0700395 if (!server)
396 return -ENOTCONN;
397 call->server = server;
398
399 INIT_WORK(&call->work, SRXAFSCB_InitCallBackState);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000400 queue_work(afs_wq, &call->work);
David Howellsc35eccb2007-04-26 15:58:49 -0700401 return 0;
402}
403
404/*
David Howells08e0e7c2007-04-26 15:55:03 -0700405 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 */
David Howells08e0e7c2007-04-26 15:55:03 -0700407static void SRXAFSCB_Probe(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408{
David Howells08e0e7c2007-04-26 15:55:03 -0700409 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
David Howells08e0e7c2007-04-26 15:55:03 -0700411 _enter("");
412 afs_send_empty_reply(call);
413 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700414}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416/*
David Howells08e0e7c2007-04-26 15:55:03 -0700417 * deliver request data to a CB.Probe call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 */
David Howellsd0016482016-08-30 20:42:14 +0100419static int afs_deliver_cb_probe(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420{
David Howells372ee162016-08-03 14:11:40 +0100421 int ret;
422
David Howellsd0016482016-08-30 20:42:14 +0100423 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
David Howellsd0016482016-08-30 20:42:14 +0100425 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100426 if (ret < 0)
427 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
David Howells08e0e7c2007-04-26 15:55:03 -0700429 /* no unmarshalling required */
430 call->state = AFS_CALL_REPLYING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
David Howells08e0e7c2007-04-26 15:55:03 -0700432 INIT_WORK(&call->work, SRXAFSCB_Probe);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000433 queue_work(afs_wq, &call->work);
David Howells08e0e7c2007-04-26 15:55:03 -0700434 return 0;
David Howellsec268152007-04-26 15:49:28 -0700435}
David Howellsb908fe62007-04-26 15:58:17 -0700436
437/*
David Howells9396d492008-04-29 01:03:22 -0700438 * allow the fileserver to quickly find out if the fileserver has been rebooted
439 */
440static void SRXAFSCB_ProbeUuid(struct work_struct *work)
441{
442 struct afs_call *call = container_of(work, struct afs_call, work);
443 struct afs_uuid *r = call->request;
444
445 struct {
446 __be32 match;
447 } reply;
448
449 _enter("");
450
David Howells9396d492008-04-29 01:03:22 -0700451 if (memcmp(r, &afs_uuid, sizeof(afs_uuid)) == 0)
452 reply.match = htonl(0);
453 else
454 reply.match = htonl(1);
455
456 afs_send_simple_reply(call, &reply, sizeof(reply));
457 _leave("");
458}
459
460/*
461 * deliver request data to a CB.ProbeUuid call
462 */
David Howellsd0016482016-08-30 20:42:14 +0100463static int afs_deliver_cb_probe_uuid(struct afs_call *call)
David Howells9396d492008-04-29 01:03:22 -0700464{
465 struct afs_uuid *r;
466 unsigned loop;
467 __be32 *b;
468 int ret;
469
David Howellsd0016482016-08-30 20:42:14 +0100470 _enter("{%u}", call->unmarshall);
David Howells9396d492008-04-29 01:03:22 -0700471
472 switch (call->unmarshall) {
473 case 0:
474 call->offset = 0;
475 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
476 if (!call->buffer)
477 return -ENOMEM;
478 call->unmarshall++;
479
480 case 1:
481 _debug("extract UUID");
David Howellsd0016482016-08-30 20:42:14 +0100482 ret = afs_extract_data(call, call->buffer,
483 11 * sizeof(__be32), false);
David Howells9396d492008-04-29 01:03:22 -0700484 switch (ret) {
485 case 0: break;
486 case -EAGAIN: return 0;
487 default: return ret;
488 }
489
490 _debug("unmarshall UUID");
491 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
492 if (!call->request)
493 return -ENOMEM;
494
495 b = call->buffer;
496 r = call->request;
497 r->time_low = ntohl(b[0]);
498 r->time_mid = ntohl(b[1]);
499 r->time_hi_and_version = ntohl(b[2]);
500 r->clock_seq_hi_and_reserved = ntohl(b[3]);
501 r->clock_seq_low = ntohl(b[4]);
502
503 for (loop = 0; loop < 6; loop++)
504 r->node[loop] = ntohl(b[loop + 5]);
505
506 call->offset = 0;
507 call->unmarshall++;
508
509 case 2:
David Howells9396d492008-04-29 01:03:22 -0700510 break;
511 }
512
David Howells9396d492008-04-29 01:03:22 -0700513 call->state = AFS_CALL_REPLYING;
514
515 INIT_WORK(&call->work, SRXAFSCB_ProbeUuid);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000516 queue_work(afs_wq, &call->work);
David Howells9396d492008-04-29 01:03:22 -0700517 return 0;
518}
519
520/*
David Howellsb908fe62007-04-26 15:58:17 -0700521 * allow the fileserver to ask about the cache manager's capabilities
522 */
David Howells7c80bcc2008-04-29 01:03:21 -0700523static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
David Howellsb908fe62007-04-26 15:58:17 -0700524{
525 struct afs_interface *ifs;
526 struct afs_call *call = container_of(work, struct afs_call, work);
527 int loop, nifs;
528
529 struct {
530 struct /* InterfaceAddr */ {
531 __be32 nifs;
532 __be32 uuid[11];
533 __be32 ifaddr[32];
534 __be32 netmask[32];
535 __be32 mtu[32];
536 } ia;
537 struct /* Capabilities */ {
538 __be32 capcount;
539 __be32 caps[1];
540 } cap;
541 } reply;
542
543 _enter("");
544
545 nifs = 0;
546 ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL);
547 if (ifs) {
548 nifs = afs_get_ipv4_interfaces(ifs, 32, false);
549 if (nifs < 0) {
550 kfree(ifs);
551 ifs = NULL;
552 nifs = 0;
553 }
554 }
555
556 memset(&reply, 0, sizeof(reply));
557 reply.ia.nifs = htonl(nifs);
558
559 reply.ia.uuid[0] = htonl(afs_uuid.time_low);
560 reply.ia.uuid[1] = htonl(afs_uuid.time_mid);
561 reply.ia.uuid[2] = htonl(afs_uuid.time_hi_and_version);
562 reply.ia.uuid[3] = htonl((s8) afs_uuid.clock_seq_hi_and_reserved);
563 reply.ia.uuid[4] = htonl((s8) afs_uuid.clock_seq_low);
564 for (loop = 0; loop < 6; loop++)
565 reply.ia.uuid[loop + 5] = htonl((s8) afs_uuid.node[loop]);
566
567 if (ifs) {
568 for (loop = 0; loop < nifs; loop++) {
569 reply.ia.ifaddr[loop] = ifs[loop].address.s_addr;
570 reply.ia.netmask[loop] = ifs[loop].netmask.s_addr;
571 reply.ia.mtu[loop] = htonl(ifs[loop].mtu);
572 }
Patrick McHardy5b35fad2007-05-03 03:27:39 -0700573 kfree(ifs);
David Howellsb908fe62007-04-26 15:58:17 -0700574 }
575
576 reply.cap.capcount = htonl(1);
577 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
578 afs_send_simple_reply(call, &reply, sizeof(reply));
579
580 _leave("");
581}
582
583/*
David Howells7c80bcc2008-04-29 01:03:21 -0700584 * deliver request data to a CB.TellMeAboutYourself call
David Howellsb908fe62007-04-26 15:58:17 -0700585 */
David Howellsd0016482016-08-30 20:42:14 +0100586static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
David Howellsb908fe62007-04-26 15:58:17 -0700587{
David Howells372ee162016-08-03 14:11:40 +0100588 int ret;
589
David Howellsd0016482016-08-30 20:42:14 +0100590 _enter("");
David Howellsb908fe62007-04-26 15:58:17 -0700591
David Howellsd0016482016-08-30 20:42:14 +0100592 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100593 if (ret < 0)
594 return ret;
David Howellsb908fe62007-04-26 15:58:17 -0700595
596 /* no unmarshalling required */
597 call->state = AFS_CALL_REPLYING;
598
David Howells7c80bcc2008-04-29 01:03:21 -0700599 INIT_WORK(&call->work, SRXAFSCB_TellMeAboutYourself);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000600 queue_work(afs_wq, &call->work);
David Howellsb908fe62007-04-26 15:58:17 -0700601 return 0;
602}