blob: 85737e96ab8b5a3d242f50dbf59a8f81c332e4dd [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
Adrian Bunkc1206a22007-10-16 23:26:41 -070020#if 0
David Howells08e0e7c2007-04-26 15:55:03 -070021struct workqueue_struct *afs_cm_workqueue;
Adrian Bunkc1206a22007-10-16 23:26:41 -070022#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
David Howells08e0e7c2007-04-26 15:55:03 -070024static int afs_deliver_cb_init_call_back_state(struct afs_call *,
25 struct sk_buff *, bool);
David Howellsc35eccb2007-04-26 15:58:49 -070026static int afs_deliver_cb_init_call_back_state3(struct afs_call *,
27 struct sk_buff *, bool);
David Howells08e0e7c2007-04-26 15:55:03 -070028static int afs_deliver_cb_probe(struct afs_call *, struct sk_buff *, bool);
29static int afs_deliver_cb_callback(struct afs_call *, struct sk_buff *, bool);
David Howells9396d492008-04-29 01:03:22 -070030static int afs_deliver_cb_probe_uuid(struct afs_call *, struct sk_buff *, bool);
David Howells7c80bcc2008-04-29 01:03:21 -070031static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *,
32 struct sk_buff *, bool);
David Howells08e0e7c2007-04-26 15:55:03 -070033static void afs_cm_destructor(struct afs_call *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
David Howells08e0e7c2007-04-26 15:55:03 -070035/*
36 * CB.CallBack operation type
37 */
38static const struct afs_call_type afs_SRXCBCallBack = {
David Howells00d3b7a2007-04-26 15:57:07 -070039 .name = "CB.CallBack",
David Howells08e0e7c2007-04-26 15:55:03 -070040 .deliver = afs_deliver_cb_callback,
41 .abort_to_error = afs_abort_to_error,
42 .destructor = afs_cm_destructor,
Linus Torvalds1da177e2005-04-16 15:20:36 -070043};
44
David Howells08e0e7c2007-04-26 15:55:03 -070045/*
46 * CB.InitCallBackState operation type
47 */
48static const struct afs_call_type afs_SRXCBInitCallBackState = {
David Howells00d3b7a2007-04-26 15:57:07 -070049 .name = "CB.InitCallBackState",
David Howells08e0e7c2007-04-26 15:55:03 -070050 .deliver = afs_deliver_cb_init_call_back_state,
51 .abort_to_error = afs_abort_to_error,
52 .destructor = afs_cm_destructor,
Linus Torvalds1da177e2005-04-16 15:20:36 -070053};
54
David Howells08e0e7c2007-04-26 15:55:03 -070055/*
David Howellsc35eccb2007-04-26 15:58:49 -070056 * CB.InitCallBackState3 operation type
57 */
58static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
59 .name = "CB.InitCallBackState3",
60 .deliver = afs_deliver_cb_init_call_back_state3,
61 .abort_to_error = afs_abort_to_error,
62 .destructor = afs_cm_destructor,
63};
64
65/*
David Howells08e0e7c2007-04-26 15:55:03 -070066 * CB.Probe operation type
67 */
68static const struct afs_call_type afs_SRXCBProbe = {
David Howells00d3b7a2007-04-26 15:57:07 -070069 .name = "CB.Probe",
David Howells08e0e7c2007-04-26 15:55:03 -070070 .deliver = afs_deliver_cb_probe,
71 .abort_to_error = afs_abort_to_error,
72 .destructor = afs_cm_destructor,
73};
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075/*
David Howells9396d492008-04-29 01:03:22 -070076 * CB.ProbeUuid operation type
77 */
78static const struct afs_call_type afs_SRXCBProbeUuid = {
79 .name = "CB.ProbeUuid",
80 .deliver = afs_deliver_cb_probe_uuid,
81 .abort_to_error = afs_abort_to_error,
82 .destructor = afs_cm_destructor,
83};
84
85/*
David Howells7c80bcc2008-04-29 01:03:21 -070086 * CB.TellMeAboutYourself operation type
David Howellsb908fe62007-04-26 15:58:17 -070087 */
David Howells7c80bcc2008-04-29 01:03:21 -070088static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
89 .name = "CB.TellMeAboutYourself",
90 .deliver = afs_deliver_cb_tell_me_about_yourself,
David Howellsb908fe62007-04-26 15:58:17 -070091 .abort_to_error = afs_abort_to_error,
92 .destructor = afs_cm_destructor,
93};
94
95/*
David Howells08e0e7c2007-04-26 15:55:03 -070096 * route an incoming cache manager call
97 * - return T if supported, F if not
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 */
David Howells08e0e7c2007-04-26 15:55:03 -070099bool afs_cm_incoming_call(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
David Howells08e0e7c2007-04-26 15:55:03 -0700101 u32 operation_id = ntohl(call->operation_ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
David Howells08e0e7c2007-04-26 15:55:03 -0700103 _enter("{CB.OP %u}", operation_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
David Howells08e0e7c2007-04-26 15:55:03 -0700105 switch (operation_id) {
106 case CBCallBack:
107 call->type = &afs_SRXCBCallBack;
108 return true;
109 case CBInitCallBackState:
110 call->type = &afs_SRXCBInitCallBackState;
111 return true;
David Howellsc35eccb2007-04-26 15:58:49 -0700112 case CBInitCallBackState3:
113 call->type = &afs_SRXCBInitCallBackState3;
114 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700115 case CBProbe:
116 call->type = &afs_SRXCBProbe;
117 return true;
David Howells7c80bcc2008-04-29 01:03:21 -0700118 case CBTellMeAboutYourself:
119 call->type = &afs_SRXCBTellMeAboutYourself;
David Howellsb908fe62007-04-26 15:58:17 -0700120 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700121 default:
122 return false;
123 }
David Howellsec268152007-04-26 15:49:28 -0700124}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126/*
David Howells08e0e7c2007-04-26 15:55:03 -0700127 * clean up a cache manager call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 */
David Howells08e0e7c2007-04-26 15:55:03 -0700129static void afs_cm_destructor(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
David Howells08e0e7c2007-04-26 15:55:03 -0700131 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
David Howells6c67c7c2014-05-21 14:48:05 +0100133 /* Break the callbacks here so that we do it after the final ACK is
134 * received. The step number here must match the final number in
135 * afs_deliver_cb_callback().
136 */
137 if (call->unmarshall == 6) {
138 ASSERT(call->server && call->count && call->request);
139 afs_break_callbacks(call->server, call->count, call->request);
140 }
141
David Howells08e0e7c2007-04-26 15:55:03 -0700142 afs_put_server(call->server);
143 call->server = NULL;
144 kfree(call->buffer);
145 call->buffer = NULL;
David Howellsec268152007-04-26 15:49:28 -0700146}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148/*
David Howells08e0e7c2007-04-26 15:55:03 -0700149 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 */
David Howells08e0e7c2007-04-26 15:55:03 -0700151static void SRXAFSCB_CallBack(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
David Howells08e0e7c2007-04-26 15:55:03 -0700153 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
David Howells08e0e7c2007-04-26 15:55:03 -0700155 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
David Howells08e0e7c2007-04-26 15:55:03 -0700157 /* be sure to send the reply *before* attempting to spam the AFS server
158 * with FSFetchStatus requests on the vnodes with broken callbacks lest
159 * the AFS server get into a vicious cycle of trying to break further
160 * callbacks because it hadn't received completion of the CBCallBack op
161 * yet */
162 afs_send_empty_reply(call);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
David Howells08e0e7c2007-04-26 15:55:03 -0700164 afs_break_callbacks(call->server, call->count, call->request);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700166}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168/*
David Howells08e0e7c2007-04-26 15:55:03 -0700169 * deliver request data to a CB.CallBack call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 */
David Howells08e0e7c2007-04-26 15:55:03 -0700171static int afs_deliver_cb_callback(struct afs_call *call, struct sk_buff *skb,
172 bool last)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
David Howells08e0e7c2007-04-26 15:55:03 -0700174 struct afs_callback *cb;
175 struct afs_server *server;
176 struct in_addr addr;
177 __be32 *bp;
178 u32 tmp;
179 int ret, loop;
180
181 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
182
183 switch (call->unmarshall) {
184 case 0:
185 call->offset = 0;
186 call->unmarshall++;
187
188 /* extract the FID array and its count in two steps */
189 case 1:
190 _debug("extract FID count");
191 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
David Howells372ee162016-08-03 14:11:40 +0100192 if (ret < 0)
193 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700194
195 call->count = ntohl(call->tmp);
196 _debug("FID count: %u", call->count);
197 if (call->count > AFSCBMAX)
198 return -EBADMSG;
199
200 call->buffer = kmalloc(call->count * 3 * 4, GFP_KERNEL);
201 if (!call->buffer)
202 return -ENOMEM;
203 call->offset = 0;
204 call->unmarshall++;
205
206 case 2:
207 _debug("extract FID array");
208 ret = afs_extract_data(call, skb, last, call->buffer,
209 call->count * 3 * 4);
David Howells372ee162016-08-03 14:11:40 +0100210 if (ret < 0)
211 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700212
213 _debug("unmarshall FID array");
214 call->request = kcalloc(call->count,
215 sizeof(struct afs_callback),
216 GFP_KERNEL);
217 if (!call->request)
218 return -ENOMEM;
219
220 cb = call->request;
221 bp = call->buffer;
222 for (loop = call->count; loop > 0; loop--, cb++) {
223 cb->fid.vid = ntohl(*bp++);
224 cb->fid.vnode = ntohl(*bp++);
225 cb->fid.unique = ntohl(*bp++);
226 cb->type = AFSCM_CB_UNTYPED;
227 }
228
229 call->offset = 0;
230 call->unmarshall++;
231
232 /* extract the callback array and its count in two steps */
233 case 3:
234 _debug("extract CB count");
235 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
David Howells372ee162016-08-03 14:11:40 +0100236 if (ret < 0)
237 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700238
239 tmp = ntohl(call->tmp);
240 _debug("CB count: %u", tmp);
241 if (tmp != call->count && tmp != 0)
242 return -EBADMSG;
243 call->offset = 0;
244 call->unmarshall++;
245 if (tmp == 0)
246 goto empty_cb_array;
247
248 case 4:
249 _debug("extract CB array");
250 ret = afs_extract_data(call, skb, last, call->request,
251 call->count * 3 * 4);
David Howells372ee162016-08-03 14:11:40 +0100252 if (ret < 0)
253 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700254
255 _debug("unmarshall CB array");
256 cb = call->request;
257 bp = call->buffer;
258 for (loop = call->count; loop > 0; loop--, cb++) {
259 cb->version = ntohl(*bp++);
260 cb->expiry = ntohl(*bp++);
261 cb->type = ntohl(*bp++);
262 }
263
264 empty_cb_array:
265 call->offset = 0;
266 call->unmarshall++;
267
268 case 5:
David Howells372ee162016-08-03 14:11:40 +0100269 ret = afs_data_complete(call, skb, last);
270 if (ret < 0)
271 return ret;
David Howells6c67c7c2014-05-21 14:48:05 +0100272
273 /* Record that the message was unmarshalled successfully so
274 * that the call destructor can know do the callback breaking
275 * work, even if the final ACK isn't received.
276 *
277 * If the step number changes, then afs_cm_destructor() must be
278 * updated also.
279 */
280 call->unmarshall++;
281 case 6:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 break;
283 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
David Howells08e0e7c2007-04-26 15:55:03 -0700286 call->state = AFS_CALL_REPLYING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
David Howells08e0e7c2007-04-26 15:55:03 -0700288 /* we'll need the file server record as that tells us which set of
289 * vnodes to operate upon */
290 memcpy(&addr, &ip_hdr(skb)->saddr, 4);
291 server = afs_find_server(&addr);
292 if (!server)
293 return -ENOTCONN;
294 call->server = server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
David Howells08e0e7c2007-04-26 15:55:03 -0700296 INIT_WORK(&call->work, SRXAFSCB_CallBack);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000297 queue_work(afs_wq, &call->work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 return 0;
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);
312 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700313}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315/*
David Howells08e0e7c2007-04-26 15:55:03 -0700316 * deliver request data to a CB.InitCallBackState call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 */
David Howells08e0e7c2007-04-26 15:55:03 -0700318static int afs_deliver_cb_init_call_back_state(struct afs_call *call,
319 struct sk_buff *skb,
320 bool last)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
322 struct afs_server *server;
David Howells08e0e7c2007-04-26 15:55:03 -0700323 struct in_addr addr;
David Howells372ee162016-08-03 14:11:40 +0100324 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
David Howells08e0e7c2007-04-26 15:55:03 -0700326 _enter(",{%u},%d", skb->len, last);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
David Howells372ee162016-08-03 14:11:40 +0100328 ret = afs_data_complete(call, skb, last);
329 if (ret < 0)
330 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
David Howells08e0e7c2007-04-26 15:55:03 -0700332 /* no unmarshalling required */
333 call->state = AFS_CALL_REPLYING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
David Howells08e0e7c2007-04-26 15:55:03 -0700335 /* we'll need the file server record as that tells us which set of
336 * vnodes to operate upon */
337 memcpy(&addr, &ip_hdr(skb)->saddr, 4);
338 server = afs_find_server(&addr);
339 if (!server)
340 return -ENOTCONN;
341 call->server = server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
David Howells08e0e7c2007-04-26 15:55:03 -0700343 INIT_WORK(&call->work, SRXAFSCB_InitCallBackState);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000344 queue_work(afs_wq, &call->work);
David Howells08e0e7c2007-04-26 15:55:03 -0700345 return 0;
David Howellsec268152007-04-26 15:49:28 -0700346}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348/*
David Howellsc35eccb2007-04-26 15:58:49 -0700349 * deliver request data to a CB.InitCallBackState3 call
350 */
351static int afs_deliver_cb_init_call_back_state3(struct afs_call *call,
352 struct sk_buff *skb,
353 bool last)
354{
355 struct afs_server *server;
356 struct in_addr addr;
357
358 _enter(",{%u},%d", skb->len, last);
359
David Howells372ee162016-08-03 14:11:40 +0100360 /* There are some arguments that we ignore */
361 afs_data_consumed(call, skb);
David Howellsc35eccb2007-04-26 15:58:49 -0700362 if (!last)
David Howells372ee162016-08-03 14:11:40 +0100363 return -EAGAIN;
David Howellsc35eccb2007-04-26 15:58:49 -0700364
365 /* no unmarshalling required */
366 call->state = AFS_CALL_REPLYING;
367
368 /* we'll need the file server record as that tells us which set of
369 * vnodes to operate upon */
370 memcpy(&addr, &ip_hdr(skb)->saddr, 4);
371 server = afs_find_server(&addr);
372 if (!server)
373 return -ENOTCONN;
374 call->server = server;
375
376 INIT_WORK(&call->work, SRXAFSCB_InitCallBackState);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000377 queue_work(afs_wq, &call->work);
David Howellsc35eccb2007-04-26 15:58:49 -0700378 return 0;
379}
380
381/*
David Howells08e0e7c2007-04-26 15:55:03 -0700382 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 */
David Howells08e0e7c2007-04-26 15:55:03 -0700384static void SRXAFSCB_Probe(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
David Howells08e0e7c2007-04-26 15:55:03 -0700386 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
David Howells08e0e7c2007-04-26 15:55:03 -0700388 _enter("");
389 afs_send_empty_reply(call);
390 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700391}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393/*
David Howells08e0e7c2007-04-26 15:55:03 -0700394 * deliver request data to a CB.Probe call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 */
David Howells08e0e7c2007-04-26 15:55:03 -0700396static int afs_deliver_cb_probe(struct afs_call *call, struct sk_buff *skb,
397 bool last)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
David Howells372ee162016-08-03 14:11:40 +0100399 int ret;
400
David Howells08e0e7c2007-04-26 15:55:03 -0700401 _enter(",{%u},%d", skb->len, last);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
David Howells372ee162016-08-03 14:11:40 +0100403 ret = afs_data_complete(call, skb, last);
404 if (ret < 0)
405 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
David Howells08e0e7c2007-04-26 15:55:03 -0700407 /* no unmarshalling required */
408 call->state = AFS_CALL_REPLYING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
David Howells08e0e7c2007-04-26 15:55:03 -0700410 INIT_WORK(&call->work, SRXAFSCB_Probe);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000411 queue_work(afs_wq, &call->work);
David Howells08e0e7c2007-04-26 15:55:03 -0700412 return 0;
David Howellsec268152007-04-26 15:49:28 -0700413}
David Howellsb908fe62007-04-26 15:58:17 -0700414
415/*
David Howells9396d492008-04-29 01:03:22 -0700416 * allow the fileserver to quickly find out if the fileserver has been rebooted
417 */
418static void SRXAFSCB_ProbeUuid(struct work_struct *work)
419{
420 struct afs_call *call = container_of(work, struct afs_call, work);
421 struct afs_uuid *r = call->request;
422
423 struct {
424 __be32 match;
425 } reply;
426
427 _enter("");
428
429
430 if (memcmp(r, &afs_uuid, sizeof(afs_uuid)) == 0)
431 reply.match = htonl(0);
432 else
433 reply.match = htonl(1);
434
435 afs_send_simple_reply(call, &reply, sizeof(reply));
436 _leave("");
437}
438
439/*
440 * deliver request data to a CB.ProbeUuid call
441 */
442static int afs_deliver_cb_probe_uuid(struct afs_call *call, struct sk_buff *skb,
443 bool last)
444{
445 struct afs_uuid *r;
446 unsigned loop;
447 __be32 *b;
448 int ret;
449
450 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
451
David Howells372ee162016-08-03 14:11:40 +0100452 ret = afs_data_complete(call, skb, last);
453 if (ret < 0)
454 return ret;
David Howells9396d492008-04-29 01:03:22 -0700455
456 switch (call->unmarshall) {
457 case 0:
458 call->offset = 0;
459 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
460 if (!call->buffer)
461 return -ENOMEM;
462 call->unmarshall++;
463
464 case 1:
465 _debug("extract UUID");
466 ret = afs_extract_data(call, skb, last, call->buffer,
467 11 * sizeof(__be32));
468 switch (ret) {
469 case 0: break;
470 case -EAGAIN: return 0;
471 default: return ret;
472 }
473
474 _debug("unmarshall UUID");
475 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
476 if (!call->request)
477 return -ENOMEM;
478
479 b = call->buffer;
480 r = call->request;
481 r->time_low = ntohl(b[0]);
482 r->time_mid = ntohl(b[1]);
483 r->time_hi_and_version = ntohl(b[2]);
484 r->clock_seq_hi_and_reserved = ntohl(b[3]);
485 r->clock_seq_low = ntohl(b[4]);
486
487 for (loop = 0; loop < 6; loop++)
488 r->node[loop] = ntohl(b[loop + 5]);
489
490 call->offset = 0;
491 call->unmarshall++;
492
493 case 2:
494 _debug("trailer");
495 if (skb->len != 0)
496 return -EBADMSG;
497 break;
498 }
499
David Howells372ee162016-08-03 14:11:40 +0100500 ret = afs_data_complete(call, skb, last);
501 if (ret < 0)
502 return ret;
David Howells9396d492008-04-29 01:03:22 -0700503
504 call->state = AFS_CALL_REPLYING;
505
506 INIT_WORK(&call->work, SRXAFSCB_ProbeUuid);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000507 queue_work(afs_wq, &call->work);
David Howells9396d492008-04-29 01:03:22 -0700508 return 0;
509}
510
511/*
David Howellsb908fe62007-04-26 15:58:17 -0700512 * allow the fileserver to ask about the cache manager's capabilities
513 */
David Howells7c80bcc2008-04-29 01:03:21 -0700514static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
David Howellsb908fe62007-04-26 15:58:17 -0700515{
516 struct afs_interface *ifs;
517 struct afs_call *call = container_of(work, struct afs_call, work);
518 int loop, nifs;
519
520 struct {
521 struct /* InterfaceAddr */ {
522 __be32 nifs;
523 __be32 uuid[11];
524 __be32 ifaddr[32];
525 __be32 netmask[32];
526 __be32 mtu[32];
527 } ia;
528 struct /* Capabilities */ {
529 __be32 capcount;
530 __be32 caps[1];
531 } cap;
532 } reply;
533
534 _enter("");
535
536 nifs = 0;
537 ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL);
538 if (ifs) {
539 nifs = afs_get_ipv4_interfaces(ifs, 32, false);
540 if (nifs < 0) {
541 kfree(ifs);
542 ifs = NULL;
543 nifs = 0;
544 }
545 }
546
547 memset(&reply, 0, sizeof(reply));
548 reply.ia.nifs = htonl(nifs);
549
550 reply.ia.uuid[0] = htonl(afs_uuid.time_low);
551 reply.ia.uuid[1] = htonl(afs_uuid.time_mid);
552 reply.ia.uuid[2] = htonl(afs_uuid.time_hi_and_version);
553 reply.ia.uuid[3] = htonl((s8) afs_uuid.clock_seq_hi_and_reserved);
554 reply.ia.uuid[4] = htonl((s8) afs_uuid.clock_seq_low);
555 for (loop = 0; loop < 6; loop++)
556 reply.ia.uuid[loop + 5] = htonl((s8) afs_uuid.node[loop]);
557
558 if (ifs) {
559 for (loop = 0; loop < nifs; loop++) {
560 reply.ia.ifaddr[loop] = ifs[loop].address.s_addr;
561 reply.ia.netmask[loop] = ifs[loop].netmask.s_addr;
562 reply.ia.mtu[loop] = htonl(ifs[loop].mtu);
563 }
Patrick McHardy5b35fad2007-05-03 03:27:39 -0700564 kfree(ifs);
David Howellsb908fe62007-04-26 15:58:17 -0700565 }
566
567 reply.cap.capcount = htonl(1);
568 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
569 afs_send_simple_reply(call, &reply, sizeof(reply));
570
571 _leave("");
572}
573
574/*
David Howells7c80bcc2008-04-29 01:03:21 -0700575 * deliver request data to a CB.TellMeAboutYourself call
David Howellsb908fe62007-04-26 15:58:17 -0700576 */
David Howells7c80bcc2008-04-29 01:03:21 -0700577static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call,
578 struct sk_buff *skb, bool last)
David Howellsb908fe62007-04-26 15:58:17 -0700579{
David Howells372ee162016-08-03 14:11:40 +0100580 int ret;
581
David Howellsb908fe62007-04-26 15:58:17 -0700582 _enter(",{%u},%d", skb->len, last);
583
David Howells372ee162016-08-03 14:11:40 +0100584 ret = afs_data_complete(call, skb, last);
585 if (ret < 0)
586 return ret;
David Howellsb908fe62007-04-26 15:58:17 -0700587
588 /* no unmarshalling required */
589 call->state = AFS_CALL_REPLYING;
590
David Howells7c80bcc2008-04-29 01:03:21 -0700591 INIT_WORK(&call->work, SRXAFSCB_TellMeAboutYourself);
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000592 queue_work(afs_wq, &call->work);
David Howellsb908fe62007-04-26 15:58:17 -0700593 return 0;
594}