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>
20 static int afs_deliver_cb_init_call_back_state(struct afs_call
*);
21 static int afs_deliver_cb_init_call_back_state3(struct afs_call
*);
22 static int afs_deliver_cb_probe(struct afs_call
*);
23 static int afs_deliver_cb_callback(struct afs_call
*);
24 static int afs_deliver_cb_probe_uuid(struct afs_call
*);
25 static int afs_deliver_cb_tell_me_about_yourself(struct afs_call
*);
26 static void afs_cm_destructor(struct afs_call
*);
27 static void SRXAFSCB_CallBack(struct work_struct
*);
28 static void SRXAFSCB_InitCallBackState(struct work_struct
*);
29 static void SRXAFSCB_Probe(struct work_struct
*);
30 static void SRXAFSCB_ProbeUuid(struct work_struct
*);
31 static void SRXAFSCB_TellMeAboutYourself(struct work_struct
*);
33 #define CM_NAME(name) \
34 const char afs_SRXCB##name##_name[] __tracepoint_string = \
38 * CB.CallBack operation type
40 static CM_NAME(CallBack
);
41 static const struct afs_call_type afs_SRXCBCallBack
= {
42 .name
= afs_SRXCBCallBack_name
,
43 .deliver
= afs_deliver_cb_callback
,
44 .abort_to_error
= afs_abort_to_error
,
45 .destructor
= afs_cm_destructor
,
46 .work
= SRXAFSCB_CallBack
,
50 * CB.InitCallBackState operation type
52 static CM_NAME(InitCallBackState
);
53 static const struct afs_call_type afs_SRXCBInitCallBackState
= {
54 .name
= afs_SRXCBInitCallBackState_name
,
55 .deliver
= afs_deliver_cb_init_call_back_state
,
56 .abort_to_error
= afs_abort_to_error
,
57 .destructor
= afs_cm_destructor
,
58 .work
= SRXAFSCB_InitCallBackState
,
62 * CB.InitCallBackState3 operation type
64 static CM_NAME(InitCallBackState3
);
65 static const struct afs_call_type afs_SRXCBInitCallBackState3
= {
66 .name
= afs_SRXCBInitCallBackState3_name
,
67 .deliver
= afs_deliver_cb_init_call_back_state3
,
68 .abort_to_error
= afs_abort_to_error
,
69 .destructor
= afs_cm_destructor
,
70 .work
= SRXAFSCB_InitCallBackState
,
74 * CB.Probe operation type
76 static CM_NAME(Probe
);
77 static const struct afs_call_type afs_SRXCBProbe
= {
78 .name
= afs_SRXCBProbe_name
,
79 .deliver
= afs_deliver_cb_probe
,
80 .abort_to_error
= afs_abort_to_error
,
81 .destructor
= afs_cm_destructor
,
82 .work
= SRXAFSCB_Probe
,
86 * CB.ProbeUuid operation type
88 static CM_NAME(ProbeUuid
);
89 static const struct afs_call_type afs_SRXCBProbeUuid
= {
90 .name
= afs_SRXCBProbeUuid_name
,
91 .deliver
= afs_deliver_cb_probe_uuid
,
92 .abort_to_error
= afs_abort_to_error
,
93 .destructor
= afs_cm_destructor
,
94 .work
= SRXAFSCB_ProbeUuid
,
98 * CB.TellMeAboutYourself operation type
100 static CM_NAME(TellMeAboutYourself
);
101 static const struct afs_call_type afs_SRXCBTellMeAboutYourself
= {
102 .name
= afs_SRXCBTellMeAboutYourself_name
,
103 .deliver
= afs_deliver_cb_tell_me_about_yourself
,
104 .abort_to_error
= afs_abort_to_error
,
105 .destructor
= afs_cm_destructor
,
106 .work
= SRXAFSCB_TellMeAboutYourself
,
110 * route an incoming cache manager call
111 * - return T if supported, F if not
113 bool afs_cm_incoming_call(struct afs_call
*call
)
115 _enter("{CB.OP %u}", call
->operation_ID
);
117 switch (call
->operation_ID
) {
119 call
->type
= &afs_SRXCBCallBack
;
121 case CBInitCallBackState
:
122 call
->type
= &afs_SRXCBInitCallBackState
;
124 case CBInitCallBackState3
:
125 call
->type
= &afs_SRXCBInitCallBackState3
;
128 call
->type
= &afs_SRXCBProbe
;
131 call
->type
= &afs_SRXCBProbeUuid
;
133 case CBTellMeAboutYourself
:
134 call
->type
= &afs_SRXCBTellMeAboutYourself
;
142 * clean up a cache manager call
144 static void afs_cm_destructor(struct afs_call
*call
)
148 /* Break the callbacks here so that we do it after the final ACK is
149 * received. The step number here must match the final number in
150 * afs_deliver_cb_callback().
152 if (call
->unmarshall
== 5) {
153 ASSERT(call
->server
&& call
->count
&& call
->request
);
154 afs_break_callbacks(call
->server
, call
->count
, call
->request
);
157 afs_put_server(call
->server
);
164 * allow the fileserver to see if the cache manager is still alive
166 static void SRXAFSCB_CallBack(struct work_struct
*work
)
168 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
172 /* be sure to send the reply *before* attempting to spam the AFS server
173 * with FSFetchStatus requests on the vnodes with broken callbacks lest
174 * the AFS server get into a vicious cycle of trying to break further
175 * callbacks because it hadn't received completion of the CBCallBack op
177 afs_send_empty_reply(call
);
179 afs_break_callbacks(call
->server
, call
->count
, call
->request
);
185 * deliver request data to a CB.CallBack call
187 static int afs_deliver_cb_callback(struct afs_call
*call
)
189 struct sockaddr_rxrpc srx
;
190 struct afs_callback
*cb
;
191 struct afs_server
*server
;
195 _enter("{%u}", call
->unmarshall
);
197 switch (call
->unmarshall
) {
199 rxrpc_kernel_get_peer(afs_socket
, call
->rxcall
, &srx
);
203 /* extract the FID array and its count in two steps */
205 _debug("extract FID count");
206 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
210 call
->count
= ntohl(call
->tmp
);
211 _debug("FID count: %u", call
->count
);
212 if (call
->count
> AFSCBMAX
)
215 call
->buffer
= kmalloc(call
->count
* 3 * 4, GFP_KERNEL
);
222 _debug("extract FID array");
223 ret
= afs_extract_data(call
, call
->buffer
,
224 call
->count
* 3 * 4, true);
228 _debug("unmarshall FID array");
229 call
->request
= kcalloc(call
->count
,
230 sizeof(struct afs_callback
),
237 for (loop
= call
->count
; loop
> 0; loop
--, cb
++) {
238 cb
->fid
.vid
= ntohl(*bp
++);
239 cb
->fid
.vnode
= ntohl(*bp
++);
240 cb
->fid
.unique
= ntohl(*bp
++);
241 cb
->type
= AFSCM_CB_UNTYPED
;
247 /* extract the callback array and its count in two steps */
249 _debug("extract CB count");
250 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
254 call
->count2
= ntohl(call
->tmp
);
255 _debug("CB count: %u", call
->count2
);
256 if (call
->count2
!= call
->count
&& call
->count2
!= 0)
262 _debug("extract CB array");
263 ret
= afs_extract_data(call
, call
->buffer
,
264 call
->count2
* 3 * 4, false);
268 _debug("unmarshall CB array");
271 for (loop
= call
->count2
; loop
> 0; loop
--, cb
++) {
272 cb
->version
= ntohl(*bp
++);
273 cb
->expiry
= ntohl(*bp
++);
274 cb
->type
= ntohl(*bp
++);
280 /* Record that the message was unmarshalled successfully so
281 * that the call destructor can know do the callback breaking
282 * work, even if the final ACK isn't received.
284 * If the step number changes, then afs_cm_destructor() must be
292 call
->state
= AFS_CALL_REPLYING
;
294 /* we'll need the file server record as that tells us which set of
295 * vnodes to operate upon */
296 server
= afs_find_server(&srx
);
299 call
->server
= server
;
301 return afs_queue_call_work(call
);
305 * allow the fileserver to request callback state (re-)initialisation
307 static void SRXAFSCB_InitCallBackState(struct work_struct
*work
)
309 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
311 _enter("{%p}", call
->server
);
313 afs_init_callback_state(call
->server
);
314 afs_send_empty_reply(call
);
320 * deliver request data to a CB.InitCallBackState call
322 static int afs_deliver_cb_init_call_back_state(struct afs_call
*call
)
324 struct sockaddr_rxrpc srx
;
325 struct afs_server
*server
;
330 rxrpc_kernel_get_peer(afs_socket
, call
->rxcall
, &srx
);
332 ret
= afs_extract_data(call
, NULL
, 0, false);
336 /* no unmarshalling required */
337 call
->state
= AFS_CALL_REPLYING
;
339 /* we'll need the file server record as that tells us which set of
340 * vnodes to operate upon */
341 server
= afs_find_server(&srx
);
344 call
->server
= server
;
346 return afs_queue_call_work(call
);
350 * deliver request data to a CB.InitCallBackState3 call
352 static int afs_deliver_cb_init_call_back_state3(struct afs_call
*call
)
354 struct sockaddr_rxrpc srx
;
355 struct afs_server
*server
;
363 rxrpc_kernel_get_peer(afs_socket
, call
->rxcall
, &srx
);
365 _enter("{%u}", call
->unmarshall
);
367 switch (call
->unmarshall
) {
370 call
->buffer
= kmalloc(11 * sizeof(__be32
), GFP_KERNEL
);
376 _debug("extract UUID");
377 ret
= afs_extract_data(call
, call
->buffer
,
378 11 * sizeof(__be32
), false);
381 case -EAGAIN
: return 0;
385 _debug("unmarshall UUID");
386 call
->request
= kmalloc(sizeof(struct afs_uuid
), GFP_KERNEL
);
393 r
->time_mid
= htons(ntohl(b
[1]));
394 r
->time_hi_and_version
= htons(ntohl(b
[2]));
395 r
->clock_seq_hi_and_reserved
= ntohl(b
[3]);
396 r
->clock_seq_low
= ntohl(b
[4]);
398 for (loop
= 0; loop
< 6; loop
++)
399 r
->node
[loop
] = ntohl(b
[loop
+ 5]);
408 /* no unmarshalling required */
409 call
->state
= AFS_CALL_REPLYING
;
411 /* we'll need the file server record as that tells us which set of
412 * vnodes to operate upon */
413 server
= afs_find_server(&srx
);
416 call
->server
= server
;
418 return afs_queue_call_work(call
);
422 * allow the fileserver to see if the cache manager is still alive
424 static void SRXAFSCB_Probe(struct work_struct
*work
)
426 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
429 afs_send_empty_reply(call
);
435 * deliver request data to a CB.Probe call
437 static int afs_deliver_cb_probe(struct afs_call
*call
)
443 ret
= afs_extract_data(call
, NULL
, 0, false);
447 /* no unmarshalling required */
448 call
->state
= AFS_CALL_REPLYING
;
450 return afs_queue_call_work(call
);
454 * allow the fileserver to quickly find out if the fileserver has been rebooted
456 static void SRXAFSCB_ProbeUuid(struct work_struct
*work
)
458 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
459 struct afs_uuid
*r
= call
->request
;
467 if (memcmp(r
, &afs_uuid
, sizeof(afs_uuid
)) == 0)
468 reply
.match
= htonl(0);
470 reply
.match
= htonl(1);
472 afs_send_simple_reply(call
, &reply
, sizeof(reply
));
478 * deliver request data to a CB.ProbeUuid call
480 static int afs_deliver_cb_probe_uuid(struct afs_call
*call
)
487 _enter("{%u}", call
->unmarshall
);
489 switch (call
->unmarshall
) {
492 call
->buffer
= kmalloc(11 * sizeof(__be32
), GFP_KERNEL
);
498 _debug("extract UUID");
499 ret
= afs_extract_data(call
, call
->buffer
,
500 11 * sizeof(__be32
), false);
503 case -EAGAIN
: return 0;
507 _debug("unmarshall UUID");
508 call
->request
= kmalloc(sizeof(struct afs_uuid
), GFP_KERNEL
);
514 r
->time_low
= ntohl(b
[0]);
515 r
->time_mid
= ntohl(b
[1]);
516 r
->time_hi_and_version
= ntohl(b
[2]);
517 r
->clock_seq_hi_and_reserved
= ntohl(b
[3]);
518 r
->clock_seq_low
= ntohl(b
[4]);
520 for (loop
= 0; loop
< 6; loop
++)
521 r
->node
[loop
] = ntohl(b
[loop
+ 5]);
530 call
->state
= AFS_CALL_REPLYING
;
532 return afs_queue_call_work(call
);
536 * allow the fileserver to ask about the cache manager's capabilities
538 static void SRXAFSCB_TellMeAboutYourself(struct work_struct
*work
)
540 struct afs_interface
*ifs
;
541 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
545 struct /* InterfaceAddr */ {
552 struct /* Capabilities */ {
561 ifs
= kcalloc(32, sizeof(*ifs
), GFP_KERNEL
);
563 nifs
= afs_get_ipv4_interfaces(ifs
, 32, false);
571 memset(&reply
, 0, sizeof(reply
));
572 reply
.ia
.nifs
= htonl(nifs
);
574 reply
.ia
.uuid
[0] = afs_uuid
.time_low
;
575 reply
.ia
.uuid
[1] = htonl(ntohs(afs_uuid
.time_mid
));
576 reply
.ia
.uuid
[2] = htonl(ntohs(afs_uuid
.time_hi_and_version
));
577 reply
.ia
.uuid
[3] = htonl((s8
) afs_uuid
.clock_seq_hi_and_reserved
);
578 reply
.ia
.uuid
[4] = htonl((s8
) afs_uuid
.clock_seq_low
);
579 for (loop
= 0; loop
< 6; loop
++)
580 reply
.ia
.uuid
[loop
+ 5] = htonl((s8
) afs_uuid
.node
[loop
]);
583 for (loop
= 0; loop
< nifs
; loop
++) {
584 reply
.ia
.ifaddr
[loop
] = ifs
[loop
].address
.s_addr
;
585 reply
.ia
.netmask
[loop
] = ifs
[loop
].netmask
.s_addr
;
586 reply
.ia
.mtu
[loop
] = htonl(ifs
[loop
].mtu
);
591 reply
.cap
.capcount
= htonl(1);
592 reply
.cap
.caps
[0] = htonl(AFS_CAP_ERROR_TRANSLATION
);
593 afs_send_simple_reply(call
, &reply
, sizeof(reply
));
599 * deliver request data to a CB.TellMeAboutYourself call
601 static int afs_deliver_cb_tell_me_about_yourself(struct afs_call
*call
)
607 ret
= afs_extract_data(call
, NULL
, 0, false);
611 /* no unmarshalling required */
612 call
->state
= AFS_CALL_REPLYING
;
614 return afs_queue_call_work(call
);