1 /* AFS Cache Manager Service
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/slab.h>
15 #include <linux/sched.h>
21 static int afs_deliver_cb_init_call_back_state(struct afs_call
*,
22 struct sk_buff
*, bool);
23 static int afs_deliver_cb_init_call_back_state3(struct afs_call
*,
24 struct sk_buff
*, bool);
25 static int afs_deliver_cb_probe(struct afs_call
*, struct sk_buff
*, bool);
26 static int afs_deliver_cb_callback(struct afs_call
*, struct sk_buff
*, bool);
27 static int afs_deliver_cb_probe_uuid(struct afs_call
*, struct sk_buff
*, bool);
28 static int afs_deliver_cb_tell_me_about_yourself(struct afs_call
*,
29 struct sk_buff
*, bool);
30 static void afs_cm_destructor(struct afs_call
*);
33 * CB.CallBack operation type
35 static const struct afs_call_type afs_SRXCBCallBack
= {
36 .name
= "CB.CallBack",
37 .deliver
= afs_deliver_cb_callback
,
38 .abort_to_error
= afs_abort_to_error
,
39 .destructor
= afs_cm_destructor
,
43 * CB.InitCallBackState operation type
45 static const struct afs_call_type afs_SRXCBInitCallBackState
= {
46 .name
= "CB.InitCallBackState",
47 .deliver
= afs_deliver_cb_init_call_back_state
,
48 .abort_to_error
= afs_abort_to_error
,
49 .destructor
= afs_cm_destructor
,
53 * CB.InitCallBackState3 operation type
55 static const struct afs_call_type afs_SRXCBInitCallBackState3
= {
56 .name
= "CB.InitCallBackState3",
57 .deliver
= afs_deliver_cb_init_call_back_state3
,
58 .abort_to_error
= afs_abort_to_error
,
59 .destructor
= afs_cm_destructor
,
63 * CB.Probe operation type
65 static const struct afs_call_type afs_SRXCBProbe
= {
67 .deliver
= afs_deliver_cb_probe
,
68 .abort_to_error
= afs_abort_to_error
,
69 .destructor
= afs_cm_destructor
,
73 * CB.ProbeUuid operation type
75 static const struct afs_call_type afs_SRXCBProbeUuid
= {
76 .name
= "CB.ProbeUuid",
77 .deliver
= afs_deliver_cb_probe_uuid
,
78 .abort_to_error
= afs_abort_to_error
,
79 .destructor
= afs_cm_destructor
,
83 * CB.TellMeAboutYourself operation type
85 static const struct afs_call_type afs_SRXCBTellMeAboutYourself
= {
86 .name
= "CB.TellMeAboutYourself",
87 .deliver
= afs_deliver_cb_tell_me_about_yourself
,
88 .abort_to_error
= afs_abort_to_error
,
89 .destructor
= afs_cm_destructor
,
93 * route an incoming cache manager call
94 * - return T if supported, F if not
96 bool afs_cm_incoming_call(struct afs_call
*call
)
98 u32 operation_id
= ntohl(call
->operation_ID
);
100 _enter("{CB.OP %u}", operation_id
);
102 switch (operation_id
) {
104 call
->type
= &afs_SRXCBCallBack
;
106 case CBInitCallBackState
:
107 call
->type
= &afs_SRXCBInitCallBackState
;
109 case CBInitCallBackState3
:
110 call
->type
= &afs_SRXCBInitCallBackState3
;
113 call
->type
= &afs_SRXCBProbe
;
115 case CBTellMeAboutYourself
:
116 call
->type
= &afs_SRXCBTellMeAboutYourself
;
124 * clean up a cache manager call
126 static void afs_cm_destructor(struct afs_call
*call
)
130 afs_put_server(call
->server
);
137 * allow the fileserver to see if the cache manager is still alive
139 static void SRXAFSCB_CallBack(struct work_struct
*work
)
141 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
145 /* be sure to send the reply *before* attempting to spam the AFS server
146 * with FSFetchStatus requests on the vnodes with broken callbacks lest
147 * the AFS server get into a vicious cycle of trying to break further
148 * callbacks because it hadn't received completion of the CBCallBack op
150 afs_send_empty_reply(call
);
152 afs_break_callbacks(call
->server
, call
->count
, call
->request
);
157 * deliver request data to a CB.CallBack call
159 static int afs_deliver_cb_callback(struct afs_call
*call
, struct sk_buff
*skb
,
162 struct afs_callback
*cb
;
163 struct afs_server
*server
;
169 _enter("{%u},{%u},%d", call
->unmarshall
, skb
->len
, last
);
171 switch (call
->unmarshall
) {
176 /* extract the FID array and its count in two steps */
178 _debug("extract FID count");
179 ret
= afs_extract_data(call
, skb
, last
, &call
->tmp
, 4);
182 case -EAGAIN
: return 0;
186 call
->count
= ntohl(call
->tmp
);
187 _debug("FID count: %u", call
->count
);
188 if (call
->count
> AFSCBMAX
)
191 call
->buffer
= kmalloc(call
->count
* 3 * 4, GFP_KERNEL
);
198 _debug("extract FID array");
199 ret
= afs_extract_data(call
, skb
, last
, call
->buffer
,
200 call
->count
* 3 * 4);
203 case -EAGAIN
: return 0;
207 _debug("unmarshall FID array");
208 call
->request
= kcalloc(call
->count
,
209 sizeof(struct afs_callback
),
216 for (loop
= call
->count
; loop
> 0; loop
--, cb
++) {
217 cb
->fid
.vid
= ntohl(*bp
++);
218 cb
->fid
.vnode
= ntohl(*bp
++);
219 cb
->fid
.unique
= ntohl(*bp
++);
220 cb
->type
= AFSCM_CB_UNTYPED
;
226 /* extract the callback array and its count in two steps */
228 _debug("extract CB count");
229 ret
= afs_extract_data(call
, skb
, last
, &call
->tmp
, 4);
232 case -EAGAIN
: return 0;
236 tmp
= ntohl(call
->tmp
);
237 _debug("CB count: %u", tmp
);
238 if (tmp
!= call
->count
&& tmp
!= 0)
246 _debug("extract CB array");
247 ret
= afs_extract_data(call
, skb
, last
, call
->request
,
248 call
->count
* 3 * 4);
251 case -EAGAIN
: return 0;
255 _debug("unmarshall CB array");
258 for (loop
= call
->count
; loop
> 0; loop
--, cb
++) {
259 cb
->version
= ntohl(*bp
++);
260 cb
->expiry
= ntohl(*bp
++);
261 cb
->type
= ntohl(*bp
++);
278 call
->state
= AFS_CALL_REPLYING
;
280 /* we'll need the file server record as that tells us which set of
281 * vnodes to operate upon */
282 memcpy(&addr
, &ip_hdr(skb
)->saddr
, 4);
283 server
= afs_find_server(&addr
);
286 call
->server
= server
;
288 INIT_WORK(&call
->work
, SRXAFSCB_CallBack
);
289 schedule_work(&call
->work
);
294 * allow the fileserver to request callback state (re-)initialisation
296 static void SRXAFSCB_InitCallBackState(struct work_struct
*work
)
298 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
300 _enter("{%p}", call
->server
);
302 afs_init_callback_state(call
->server
);
303 afs_send_empty_reply(call
);
308 * deliver request data to a CB.InitCallBackState call
310 static int afs_deliver_cb_init_call_back_state(struct afs_call
*call
,
314 struct afs_server
*server
;
317 _enter(",{%u},%d", skb
->len
, last
);
324 /* no unmarshalling required */
325 call
->state
= AFS_CALL_REPLYING
;
327 /* we'll need the file server record as that tells us which set of
328 * vnodes to operate upon */
329 memcpy(&addr
, &ip_hdr(skb
)->saddr
, 4);
330 server
= afs_find_server(&addr
);
333 call
->server
= server
;
335 INIT_WORK(&call
->work
, SRXAFSCB_InitCallBackState
);
336 schedule_work(&call
->work
);
341 * deliver request data to a CB.InitCallBackState3 call
343 static int afs_deliver_cb_init_call_back_state3(struct afs_call
*call
,
347 struct afs_server
*server
;
350 _enter(",{%u},%d", skb
->len
, last
);
355 /* no unmarshalling required */
356 call
->state
= AFS_CALL_REPLYING
;
358 /* we'll need the file server record as that tells us which set of
359 * vnodes to operate upon */
360 memcpy(&addr
, &ip_hdr(skb
)->saddr
, 4);
361 server
= afs_find_server(&addr
);
364 call
->server
= server
;
366 INIT_WORK(&call
->work
, SRXAFSCB_InitCallBackState
);
367 schedule_work(&call
->work
);
372 * allow the fileserver to see if the cache manager is still alive
374 static void SRXAFSCB_Probe(struct work_struct
*work
)
376 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
379 afs_send_empty_reply(call
);
384 * deliver request data to a CB.Probe call
386 static int afs_deliver_cb_probe(struct afs_call
*call
, struct sk_buff
*skb
,
389 _enter(",{%u},%d", skb
->len
, last
);
396 /* no unmarshalling required */
397 call
->state
= AFS_CALL_REPLYING
;
399 INIT_WORK(&call
->work
, SRXAFSCB_Probe
);
400 schedule_work(&call
->work
);
405 * allow the fileserver to quickly find out if the fileserver has been rebooted
407 static void SRXAFSCB_ProbeUuid(struct work_struct
*work
)
409 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
410 struct afs_uuid
*r
= call
->request
;
419 if (memcmp(r
, &afs_uuid
, sizeof(afs_uuid
)) == 0)
420 reply
.match
= htonl(0);
422 reply
.match
= htonl(1);
424 afs_send_simple_reply(call
, &reply
, sizeof(reply
));
429 * deliver request data to a CB.ProbeUuid call
431 static int afs_deliver_cb_probe_uuid(struct afs_call
*call
, struct sk_buff
*skb
,
439 _enter("{%u},{%u},%d", call
->unmarshall
, skb
->len
, last
);
446 switch (call
->unmarshall
) {
449 call
->buffer
= kmalloc(11 * sizeof(__be32
), GFP_KERNEL
);
455 _debug("extract UUID");
456 ret
= afs_extract_data(call
, skb
, last
, call
->buffer
,
457 11 * sizeof(__be32
));
460 case -EAGAIN
: return 0;
464 _debug("unmarshall UUID");
465 call
->request
= kmalloc(sizeof(struct afs_uuid
), GFP_KERNEL
);
471 r
->time_low
= ntohl(b
[0]);
472 r
->time_mid
= ntohl(b
[1]);
473 r
->time_hi_and_version
= ntohl(b
[2]);
474 r
->clock_seq_hi_and_reserved
= ntohl(b
[3]);
475 r
->clock_seq_low
= ntohl(b
[4]);
477 for (loop
= 0; loop
< 6; loop
++)
478 r
->node
[loop
] = ntohl(b
[loop
+ 5]);
493 call
->state
= AFS_CALL_REPLYING
;
495 INIT_WORK(&call
->work
, SRXAFSCB_ProbeUuid
);
496 schedule_work(&call
->work
);
501 * allow the fileserver to ask about the cache manager's capabilities
503 static void SRXAFSCB_TellMeAboutYourself(struct work_struct
*work
)
505 struct afs_interface
*ifs
;
506 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
510 struct /* InterfaceAddr */ {
517 struct /* Capabilities */ {
526 ifs
= kcalloc(32, sizeof(*ifs
), GFP_KERNEL
);
528 nifs
= afs_get_ipv4_interfaces(ifs
, 32, false);
536 memset(&reply
, 0, sizeof(reply
));
537 reply
.ia
.nifs
= htonl(nifs
);
539 reply
.ia
.uuid
[0] = htonl(afs_uuid
.time_low
);
540 reply
.ia
.uuid
[1] = htonl(afs_uuid
.time_mid
);
541 reply
.ia
.uuid
[2] = htonl(afs_uuid
.time_hi_and_version
);
542 reply
.ia
.uuid
[3] = htonl((s8
) afs_uuid
.clock_seq_hi_and_reserved
);
543 reply
.ia
.uuid
[4] = htonl((s8
) afs_uuid
.clock_seq_low
);
544 for (loop
= 0; loop
< 6; loop
++)
545 reply
.ia
.uuid
[loop
+ 5] = htonl((s8
) afs_uuid
.node
[loop
]);
548 for (loop
= 0; loop
< nifs
; loop
++) {
549 reply
.ia
.ifaddr
[loop
] = ifs
[loop
].address
.s_addr
;
550 reply
.ia
.netmask
[loop
] = ifs
[loop
].netmask
.s_addr
;
551 reply
.ia
.mtu
[loop
] = htonl(ifs
[loop
].mtu
);
556 reply
.cap
.capcount
= htonl(1);
557 reply
.cap
.caps
[0] = htonl(AFS_CAP_ERROR_TRANSLATION
);
558 afs_send_simple_reply(call
, &reply
, sizeof(reply
));
564 * deliver request data to a CB.TellMeAboutYourself call
566 static int afs_deliver_cb_tell_me_about_yourself(struct afs_call
*call
,
567 struct sk_buff
*skb
, bool last
)
569 _enter(",{%u},%d", skb
->len
, last
);
576 /* no unmarshalling required */
577 call
->state
= AFS_CALL_REPLYING
;
579 INIT_WORK(&call
->work
, SRXAFSCB_TellMeAboutYourself
);
580 schedule_work(&call
->work
);