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 .destructor
= afs_cm_destructor
,
45 .work
= SRXAFSCB_CallBack
,
49 * CB.InitCallBackState operation type
51 static CM_NAME(InitCallBackState
);
52 static const struct afs_call_type afs_SRXCBInitCallBackState
= {
53 .name
= afs_SRXCBInitCallBackState_name
,
54 .deliver
= afs_deliver_cb_init_call_back_state
,
55 .destructor
= afs_cm_destructor
,
56 .work
= SRXAFSCB_InitCallBackState
,
60 * CB.InitCallBackState3 operation type
62 static CM_NAME(InitCallBackState3
);
63 static const struct afs_call_type afs_SRXCBInitCallBackState3
= {
64 .name
= afs_SRXCBInitCallBackState3_name
,
65 .deliver
= afs_deliver_cb_init_call_back_state3
,
66 .destructor
= afs_cm_destructor
,
67 .work
= SRXAFSCB_InitCallBackState
,
71 * CB.Probe operation type
73 static CM_NAME(Probe
);
74 static const struct afs_call_type afs_SRXCBProbe
= {
75 .name
= afs_SRXCBProbe_name
,
76 .deliver
= afs_deliver_cb_probe
,
77 .destructor
= afs_cm_destructor
,
78 .work
= SRXAFSCB_Probe
,
82 * CB.ProbeUuid operation type
84 static CM_NAME(ProbeUuid
);
85 static const struct afs_call_type afs_SRXCBProbeUuid
= {
86 .name
= afs_SRXCBProbeUuid_name
,
87 .deliver
= afs_deliver_cb_probe_uuid
,
88 .destructor
= afs_cm_destructor
,
89 .work
= SRXAFSCB_ProbeUuid
,
93 * CB.TellMeAboutYourself operation type
95 static CM_NAME(TellMeAboutYourself
);
96 static const struct afs_call_type afs_SRXCBTellMeAboutYourself
= {
97 .name
= afs_SRXCBTellMeAboutYourself_name
,
98 .deliver
= afs_deliver_cb_tell_me_about_yourself
,
99 .destructor
= afs_cm_destructor
,
100 .work
= SRXAFSCB_TellMeAboutYourself
,
104 * route an incoming cache manager call
105 * - return T if supported, F if not
107 bool afs_cm_incoming_call(struct afs_call
*call
)
109 _enter("{CB.OP %u}", call
->operation_ID
);
111 switch (call
->operation_ID
) {
113 call
->type
= &afs_SRXCBCallBack
;
115 case CBInitCallBackState
:
116 call
->type
= &afs_SRXCBInitCallBackState
;
118 case CBInitCallBackState3
:
119 call
->type
= &afs_SRXCBInitCallBackState3
;
122 call
->type
= &afs_SRXCBProbe
;
125 call
->type
= &afs_SRXCBProbeUuid
;
127 case CBTellMeAboutYourself
:
128 call
->type
= &afs_SRXCBTellMeAboutYourself
;
136 * clean up a cache manager call
138 static void afs_cm_destructor(struct afs_call
*call
)
142 /* Break the callbacks here so that we do it after the final ACK is
143 * received. The step number here must match the final number in
144 * afs_deliver_cb_callback().
146 if (call
->unmarshall
== 5) {
147 ASSERT(call
->cm_server
&& call
->count
&& call
->request
);
148 afs_break_callbacks(call
->cm_server
, call
->count
, call
->request
);
156 * The server supplied a list of callbacks that it wanted to break.
158 static void SRXAFSCB_CallBack(struct work_struct
*work
)
160 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
164 /* be sure to send the reply *before* attempting to spam the AFS server
165 * with FSFetchStatus requests on the vnodes with broken callbacks lest
166 * the AFS server get into a vicious cycle of trying to break further
167 * callbacks because it hadn't received completion of the CBCallBack op
169 afs_send_empty_reply(call
);
171 afs_break_callbacks(call
->cm_server
, call
->count
, call
->request
);
177 * deliver request data to a CB.CallBack call
179 static int afs_deliver_cb_callback(struct afs_call
*call
)
181 struct sockaddr_rxrpc srx
;
182 struct afs_callback
*cb
;
183 struct afs_server
*server
;
187 _enter("{%u}", call
->unmarshall
);
189 switch (call
->unmarshall
) {
194 /* extract the FID array and its count in two steps */
196 _debug("extract FID count");
197 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
201 call
->count
= ntohl(call
->tmp
);
202 _debug("FID count: %u", call
->count
);
203 if (call
->count
> AFSCBMAX
)
206 call
->buffer
= kmalloc(call
->count
* 3 * 4, GFP_KERNEL
);
213 _debug("extract FID array");
214 ret
= afs_extract_data(call
, call
->buffer
,
215 call
->count
* 3 * 4, true);
219 _debug("unmarshall FID array");
220 call
->request
= kcalloc(call
->count
,
221 sizeof(struct afs_callback
),
228 for (loop
= call
->count
; loop
> 0; loop
--, cb
++) {
229 cb
->fid
.vid
= ntohl(*bp
++);
230 cb
->fid
.vnode
= ntohl(*bp
++);
231 cb
->fid
.unique
= ntohl(*bp
++);
232 cb
->type
= AFSCM_CB_UNTYPED
;
238 /* extract the callback array and its count in two steps */
240 _debug("extract CB count");
241 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
245 call
->count2
= ntohl(call
->tmp
);
246 _debug("CB count: %u", call
->count2
);
247 if (call
->count2
!= call
->count
&& call
->count2
!= 0)
253 _debug("extract CB array");
254 ret
= afs_extract_data(call
, call
->buffer
,
255 call
->count2
* 3 * 4, false);
259 _debug("unmarshall CB array");
262 for (loop
= call
->count2
; loop
> 0; loop
--, cb
++) {
263 cb
->version
= ntohl(*bp
++);
264 cb
->expiry
= ntohl(*bp
++);
265 cb
->type
= ntohl(*bp
++);
271 /* Record that the message was unmarshalled successfully so
272 * that the call destructor can know do the callback breaking
273 * work, even if the final ACK isn't received.
275 * If the step number changes, then afs_cm_destructor() must be
283 if (!afs_check_call_state(call
, AFS_CALL_SV_REPLYING
))
286 /* we'll need the file server record as that tells us which set of
287 * vnodes to operate upon */
288 rxrpc_kernel_get_peer(call
->net
->socket
, call
->rxcall
, &srx
);
289 server
= afs_find_server(call
->net
, &srx
);
292 call
->cm_server
= server
;
294 return afs_queue_call_work(call
);
298 * allow the fileserver to request callback state (re-)initialisation
300 static void SRXAFSCB_InitCallBackState(struct work_struct
*work
)
302 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
304 _enter("{%p}", call
->cm_server
);
306 afs_init_callback_state(call
->cm_server
);
307 afs_send_empty_reply(call
);
313 * deliver request data to a CB.InitCallBackState call
315 static int afs_deliver_cb_init_call_back_state(struct afs_call
*call
)
317 struct sockaddr_rxrpc srx
;
318 struct afs_server
*server
;
323 rxrpc_kernel_get_peer(call
->net
->socket
, call
->rxcall
, &srx
);
325 ret
= afs_extract_data(call
, NULL
, 0, false);
329 /* we'll need the file server record as that tells us which set of
330 * vnodes to operate upon */
331 server
= afs_find_server(call
->net
, &srx
);
334 call
->cm_server
= server
;
336 return afs_queue_call_work(call
);
340 * deliver request data to a CB.InitCallBackState3 call
342 static int afs_deliver_cb_init_call_back_state3(struct afs_call
*call
)
344 struct sockaddr_rxrpc srx
;
345 struct afs_server
*server
;
353 _enter("{%u}", call
->unmarshall
);
355 switch (call
->unmarshall
) {
358 call
->buffer
= kmalloc(11 * sizeof(__be32
), GFP_KERNEL
);
364 _debug("extract UUID");
365 ret
= afs_extract_data(call
, call
->buffer
,
366 11 * sizeof(__be32
), false);
369 case -EAGAIN
: return 0;
373 _debug("unmarshall UUID");
374 call
->request
= kmalloc(sizeof(struct afs_uuid
), GFP_KERNEL
);
381 r
->time_mid
= htons(ntohl(b
[1]));
382 r
->time_hi_and_version
= htons(ntohl(b
[2]));
383 r
->clock_seq_hi_and_reserved
= ntohl(b
[3]);
384 r
->clock_seq_low
= ntohl(b
[4]);
386 for (loop
= 0; loop
< 6; loop
++)
387 r
->node
[loop
] = ntohl(b
[loop
+ 5]);
396 if (!afs_check_call_state(call
, AFS_CALL_SV_REPLYING
))
399 /* we'll need the file server record as that tells us which set of
400 * vnodes to operate upon */
401 rxrpc_kernel_get_peer(call
->net
->socket
, call
->rxcall
, &srx
);
402 server
= afs_find_server(call
->net
, &srx
);
405 call
->cm_server
= server
;
407 return afs_queue_call_work(call
);
411 * allow the fileserver to see if the cache manager is still alive
413 static void SRXAFSCB_Probe(struct work_struct
*work
)
415 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
418 afs_send_empty_reply(call
);
424 * deliver request data to a CB.Probe call
426 static int afs_deliver_cb_probe(struct afs_call
*call
)
432 ret
= afs_extract_data(call
, NULL
, 0, false);
436 if (!afs_check_call_state(call
, AFS_CALL_SV_REPLYING
))
439 return afs_queue_call_work(call
);
443 * allow the fileserver to quickly find out if the fileserver has been rebooted
445 static void SRXAFSCB_ProbeUuid(struct work_struct
*work
)
447 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
448 struct afs_uuid
*r
= call
->request
;
456 if (memcmp(r
, &call
->net
->uuid
, sizeof(call
->net
->uuid
)) == 0)
457 reply
.match
= htonl(0);
459 reply
.match
= htonl(1);
461 afs_send_simple_reply(call
, &reply
, sizeof(reply
));
467 * deliver request data to a CB.ProbeUuid call
469 static int afs_deliver_cb_probe_uuid(struct afs_call
*call
)
476 _enter("{%u}", call
->unmarshall
);
478 switch (call
->unmarshall
) {
481 call
->buffer
= kmalloc(11 * sizeof(__be32
), GFP_KERNEL
);
487 _debug("extract UUID");
488 ret
= afs_extract_data(call
, call
->buffer
,
489 11 * sizeof(__be32
), false);
492 case -EAGAIN
: return 0;
496 _debug("unmarshall UUID");
497 call
->request
= kmalloc(sizeof(struct afs_uuid
), GFP_KERNEL
);
503 r
->time_low
= ntohl(b
[0]);
504 r
->time_mid
= ntohl(b
[1]);
505 r
->time_hi_and_version
= ntohl(b
[2]);
506 r
->clock_seq_hi_and_reserved
= ntohl(b
[3]);
507 r
->clock_seq_low
= ntohl(b
[4]);
509 for (loop
= 0; loop
< 6; loop
++)
510 r
->node
[loop
] = ntohl(b
[loop
+ 5]);
519 if (!afs_check_call_state(call
, AFS_CALL_SV_REPLYING
))
522 return afs_queue_call_work(call
);
526 * allow the fileserver to ask about the cache manager's capabilities
528 static void SRXAFSCB_TellMeAboutYourself(struct work_struct
*work
)
530 struct afs_interface
*ifs
;
531 struct afs_call
*call
= container_of(work
, struct afs_call
, work
);
535 struct /* InterfaceAddr */ {
542 struct /* Capabilities */ {
551 ifs
= kcalloc(32, sizeof(*ifs
), GFP_KERNEL
);
553 nifs
= afs_get_ipv4_interfaces(ifs
, 32, false);
561 memset(&reply
, 0, sizeof(reply
));
562 reply
.ia
.nifs
= htonl(nifs
);
564 reply
.ia
.uuid
[0] = call
->net
->uuid
.time_low
;
565 reply
.ia
.uuid
[1] = htonl(ntohs(call
->net
->uuid
.time_mid
));
566 reply
.ia
.uuid
[2] = htonl(ntohs(call
->net
->uuid
.time_hi_and_version
));
567 reply
.ia
.uuid
[3] = htonl((s8
) call
->net
->uuid
.clock_seq_hi_and_reserved
);
568 reply
.ia
.uuid
[4] = htonl((s8
) call
->net
->uuid
.clock_seq_low
);
569 for (loop
= 0; loop
< 6; loop
++)
570 reply
.ia
.uuid
[loop
+ 5] = htonl((s8
) call
->net
->uuid
.node
[loop
]);
573 for (loop
= 0; loop
< nifs
; loop
++) {
574 reply
.ia
.ifaddr
[loop
] = ifs
[loop
].address
.s_addr
;
575 reply
.ia
.netmask
[loop
] = ifs
[loop
].netmask
.s_addr
;
576 reply
.ia
.mtu
[loop
] = htonl(ifs
[loop
].mtu
);
581 reply
.cap
.capcount
= htonl(1);
582 reply
.cap
.caps
[0] = htonl(AFS_CAP_ERROR_TRANSLATION
);
583 afs_send_simple_reply(call
, &reply
, sizeof(reply
));
589 * deliver request data to a CB.TellMeAboutYourself call
591 static int afs_deliver_cb_tell_me_about_yourself(struct afs_call
*call
)
597 ret
= afs_extract_data(call
, NULL
, 0, false);
601 if (!afs_check_call_state(call
, AFS_CALL_SV_REPLYING
))
604 return afs_queue_call_work(call
);