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 struct workqueue_struct
*afs_cm_workqueue
;
24 static int afs_deliver_cb_init_call_back_state(struct afs_call
*,
25 struct sk_buff
*, bool);
26 static int afs_deliver_cb_init_call_back_state3(struct afs_call
*,
27 struct sk_buff
*, bool);
28 static int afs_deliver_cb_probe(struct afs_call
*, struct sk_buff
*, bool);
29 static int afs_deliver_cb_callback(struct afs_call
*, struct sk_buff
*, bool);
30 static int afs_deliver_cb_probe_uuid(struct afs_call
*, struct sk_buff
*, bool);
31 static int afs_deliver_cb_tell_me_about_yourself(struct afs_call
*,
32 struct sk_buff
*, bool);
33 static void afs_cm_destructor(struct afs_call
*);
36 * CB.CallBack operation type
38 static const struct afs_call_type afs_SRXCBCallBack
= {
39 .name
= "CB.CallBack",
40 .deliver
= afs_deliver_cb_callback
,
41 .abort_to_error
= afs_abort_to_error
,
42 .destructor
= afs_cm_destructor
,
46 * CB.InitCallBackState operation type
48 static const struct afs_call_type afs_SRXCBInitCallBackState
= {
49 .name
= "CB.InitCallBackState",
50 .deliver
= afs_deliver_cb_init_call_back_state
,
51 .abort_to_error
= afs_abort_to_error
,
52 .destructor
= afs_cm_destructor
,
56 * CB.InitCallBackState3 operation type
58 static 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
,
66 * CB.Probe operation type
68 static const struct afs_call_type afs_SRXCBProbe
= {
70 .deliver
= afs_deliver_cb_probe
,
71 .abort_to_error
= afs_abort_to_error
,
72 .destructor
= afs_cm_destructor
,
76 * CB.ProbeUuid operation type
78 static 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
,
86 * CB.TellMeAboutYourself operation type
88 static const struct afs_call_type afs_SRXCBTellMeAboutYourself
= {
89 .name
= "CB.TellMeAboutYourself",
90 .deliver
= afs_deliver_cb_tell_me_about_yourself
,
91 .abort_to_error
= afs_abort_to_error
,
92 .destructor
= afs_cm_destructor
,
96 * route an incoming cache manager call
97 * - return T if supported, F if not
99 bool afs_cm_incoming_call(struct afs_call
*call
)
101 u32 operation_id
= ntohl(call
->operation_ID
);
103 _enter("{CB.OP %u}", operation_id
);
105 switch (operation_id
) {
107 call
->type
= &afs_SRXCBCallBack
;
109 case CBInitCallBackState
:
110 call
->type
= &afs_SRXCBInitCallBackState
;
112 case CBInitCallBackState3
:
113 call
->type
= &afs_SRXCBInitCallBackState3
;
116 call
->type
= &afs_SRXCBProbe
;
118 case CBTellMeAboutYourself
:
119 call
->type
= &afs_SRXCBTellMeAboutYourself
;
127 * clean up a cache manager call
129 static void afs_cm_destructor(struct afs_call
*call
)
133 /* 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().
137 if (call
->unmarshall
== 6) {
138 ASSERT(call
->server
&& call
->count
&& call
->request
);
139 afs_break_callbacks(call
->server
, call
->count
, call
->request
);
142 afs_put_server(call
->server
);
149 * allow the fileserver to see if the cache manager is still alive
151 static void SRXAFSCB_CallBack(struct work_struct
*work
)
153 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
157 /* 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
162 afs_send_empty_reply(call
);
164 afs_break_callbacks(call
->server
, call
->count
, call
->request
);
169 * deliver request data to a CB.CallBack call
171 static int afs_deliver_cb_callback(struct afs_call
*call
, struct sk_buff
*skb
,
174 struct afs_callback
*cb
;
175 struct afs_server
*server
;
181 _enter("{%u},{%u},%d", call
->unmarshall
, skb
->len
, last
);
183 switch (call
->unmarshall
) {
188 /* extract the FID array and its count in two steps */
190 _debug("extract FID count");
191 ret
= afs_extract_data(call
, skb
, last
, &call
->tmp
, 4);
195 call
->count
= ntohl(call
->tmp
);
196 _debug("FID count: %u", call
->count
);
197 if (call
->count
> AFSCBMAX
)
200 call
->buffer
= kmalloc(call
->count
* 3 * 4, GFP_KERNEL
);
207 _debug("extract FID array");
208 ret
= afs_extract_data(call
, skb
, last
, call
->buffer
,
209 call
->count
* 3 * 4);
213 _debug("unmarshall FID array");
214 call
->request
= kcalloc(call
->count
,
215 sizeof(struct afs_callback
),
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
;
232 /* extract the callback array and its count in two steps */
234 _debug("extract CB count");
235 ret
= afs_extract_data(call
, skb
, last
, &call
->tmp
, 4);
239 tmp
= ntohl(call
->tmp
);
240 _debug("CB count: %u", tmp
);
241 if (tmp
!= call
->count
&& tmp
!= 0)
249 _debug("extract CB array");
250 ret
= afs_extract_data(call
, skb
, last
, call
->request
,
251 call
->count
* 3 * 4);
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
++);
269 ret
= afs_data_complete(call
, skb
, last
);
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.
277 * If the step number changes, then afs_cm_destructor() must be
286 call
->state
= AFS_CALL_REPLYING
;
288 /* 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
);
294 call
->server
= server
;
296 INIT_WORK(&call
->work
, SRXAFSCB_CallBack
);
297 queue_work(afs_wq
, &call
->work
);
302 * allow the fileserver to request callback state (re-)initialisation
304 static void SRXAFSCB_InitCallBackState(struct work_struct
*work
)
306 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
308 _enter("{%p}", call
->server
);
310 afs_init_callback_state(call
->server
);
311 afs_send_empty_reply(call
);
316 * deliver request data to a CB.InitCallBackState call
318 static int afs_deliver_cb_init_call_back_state(struct afs_call
*call
,
322 struct afs_server
*server
;
326 _enter(",{%u},%d", skb
->len
, last
);
328 ret
= afs_data_complete(call
, skb
, last
);
332 /* no unmarshalling required */
333 call
->state
= AFS_CALL_REPLYING
;
335 /* 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
);
341 call
->server
= server
;
343 INIT_WORK(&call
->work
, SRXAFSCB_InitCallBackState
);
344 queue_work(afs_wq
, &call
->work
);
349 * deliver request data to a CB.InitCallBackState3 call
351 static int afs_deliver_cb_init_call_back_state3(struct afs_call
*call
,
355 struct afs_server
*server
;
358 _enter(",{%u},%d", skb
->len
, last
);
360 /* There are some arguments that we ignore */
361 afs_data_consumed(call
, skb
);
365 /* no unmarshalling required */
366 call
->state
= AFS_CALL_REPLYING
;
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
);
374 call
->server
= server
;
376 INIT_WORK(&call
->work
, SRXAFSCB_InitCallBackState
);
377 queue_work(afs_wq
, &call
->work
);
382 * allow the fileserver to see if the cache manager is still alive
384 static void SRXAFSCB_Probe(struct work_struct
*work
)
386 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
389 afs_send_empty_reply(call
);
394 * deliver request data to a CB.Probe call
396 static int afs_deliver_cb_probe(struct afs_call
*call
, struct sk_buff
*skb
,
401 _enter(",{%u},%d", skb
->len
, last
);
403 ret
= afs_data_complete(call
, skb
, last
);
407 /* no unmarshalling required */
408 call
->state
= AFS_CALL_REPLYING
;
410 INIT_WORK(&call
->work
, SRXAFSCB_Probe
);
411 queue_work(afs_wq
, &call
->work
);
416 * allow the fileserver to quickly find out if the fileserver has been rebooted
418 static void SRXAFSCB_ProbeUuid(struct work_struct
*work
)
420 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
421 struct afs_uuid
*r
= call
->request
;
430 if (memcmp(r
, &afs_uuid
, sizeof(afs_uuid
)) == 0)
431 reply
.match
= htonl(0);
433 reply
.match
= htonl(1);
435 afs_send_simple_reply(call
, &reply
, sizeof(reply
));
440 * deliver request data to a CB.ProbeUuid call
442 static int afs_deliver_cb_probe_uuid(struct afs_call
*call
, struct sk_buff
*skb
,
450 _enter("{%u},{%u},%d", call
->unmarshall
, skb
->len
, last
);
452 ret
= afs_data_complete(call
, skb
, last
);
456 switch (call
->unmarshall
) {
459 call
->buffer
= kmalloc(11 * sizeof(__be32
), GFP_KERNEL
);
465 _debug("extract UUID");
466 ret
= afs_extract_data(call
, skb
, last
, call
->buffer
,
467 11 * sizeof(__be32
));
470 case -EAGAIN
: return 0;
474 _debug("unmarshall UUID");
475 call
->request
= kmalloc(sizeof(struct afs_uuid
), GFP_KERNEL
);
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]);
487 for (loop
= 0; loop
< 6; loop
++)
488 r
->node
[loop
] = ntohl(b
[loop
+ 5]);
500 ret
= afs_data_complete(call
, skb
, last
);
504 call
->state
= AFS_CALL_REPLYING
;
506 INIT_WORK(&call
->work
, SRXAFSCB_ProbeUuid
);
507 queue_work(afs_wq
, &call
->work
);
512 * allow the fileserver to ask about the cache manager's capabilities
514 static void SRXAFSCB_TellMeAboutYourself(struct work_struct
*work
)
516 struct afs_interface
*ifs
;
517 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
521 struct /* InterfaceAddr */ {
528 struct /* Capabilities */ {
537 ifs
= kcalloc(32, sizeof(*ifs
), GFP_KERNEL
);
539 nifs
= afs_get_ipv4_interfaces(ifs
, 32, false);
547 memset(&reply
, 0, sizeof(reply
));
548 reply
.ia
.nifs
= htonl(nifs
);
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
]);
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
);
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
));
575 * deliver request data to a CB.TellMeAboutYourself call
577 static int afs_deliver_cb_tell_me_about_yourself(struct afs_call
*call
,
578 struct sk_buff
*skb
, bool last
)
582 _enter(",{%u},%d", skb
->len
, last
);
584 ret
= afs_data_complete(call
, skb
, last
);
588 /* no unmarshalling required */
589 call
->state
= AFS_CALL_REPLYING
;
591 INIT_WORK(&call
->work
, SRXAFSCB_TellMeAboutYourself
);
592 queue_work(afs_wq
, &call
->work
);