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 struct sk_buff *, bool);
22 static int afs_deliver_cb_init_call_back_state3(struct afs_call *,
23 struct sk_buff *, bool);
24 static int afs_deliver_cb_probe(struct afs_call *, struct sk_buff *, bool);
25 static int afs_deliver_cb_callback(struct afs_call *, struct sk_buff *, bool);
26 static int afs_deliver_cb_probe_uuid(struct afs_call *, struct sk_buff *, bool);
27 static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *,
28 struct sk_buff *, bool);
29 static void afs_cm_destructor(struct afs_call *);
32 * CB.CallBack operation type
34 static const struct afs_call_type afs_SRXCBCallBack = {
35 .name = "CB.CallBack",
36 .deliver = afs_deliver_cb_callback,
37 .abort_to_error = afs_abort_to_error,
38 .destructor = afs_cm_destructor,
42 * CB.InitCallBackState operation type
44 static const struct afs_call_type afs_SRXCBInitCallBackState = {
45 .name = "CB.InitCallBackState",
46 .deliver = afs_deliver_cb_init_call_back_state,
47 .abort_to_error = afs_abort_to_error,
48 .destructor = afs_cm_destructor,
52 * CB.InitCallBackState3 operation type
54 static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
55 .name = "CB.InitCallBackState3",
56 .deliver = afs_deliver_cb_init_call_back_state3,
57 .abort_to_error = afs_abort_to_error,
58 .destructor = afs_cm_destructor,
62 * CB.Probe operation type
64 static const struct afs_call_type afs_SRXCBProbe = {
66 .deliver = afs_deliver_cb_probe,
67 .abort_to_error = afs_abort_to_error,
68 .destructor = afs_cm_destructor,
72 * CB.ProbeUuid operation type
74 static const struct afs_call_type afs_SRXCBProbeUuid = {
75 .name = "CB.ProbeUuid",
76 .deliver = afs_deliver_cb_probe_uuid,
77 .abort_to_error = afs_abort_to_error,
78 .destructor = afs_cm_destructor,
82 * CB.TellMeAboutYourself operation type
84 static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
85 .name = "CB.TellMeAboutYourself",
86 .deliver = afs_deliver_cb_tell_me_about_yourself,
87 .abort_to_error = afs_abort_to_error,
88 .destructor = afs_cm_destructor,
92 * route an incoming cache manager call
93 * - return T if supported, F if not
95 bool afs_cm_incoming_call(struct afs_call *call)
97 u32 operation_id = ntohl(call->operation_ID);
99 _enter("{CB.OP %u}", operation_id);
101 switch (operation_id) {
103 call->type = &afs_SRXCBCallBack;
105 case CBInitCallBackState:
106 call->type = &afs_SRXCBInitCallBackState;
108 case CBInitCallBackState3:
109 call->type = &afs_SRXCBInitCallBackState3;
112 call->type = &afs_SRXCBProbe;
114 case CBTellMeAboutYourself:
115 call->type = &afs_SRXCBTellMeAboutYourself;
123 * clean up a cache manager call
125 static void afs_cm_destructor(struct afs_call *call)
129 /* Break the callbacks here so that we do it after the final ACK is
130 * received. The step number here must match the final number in
131 * afs_deliver_cb_callback().
133 if (call->unmarshall == 6) {
134 ASSERT(call->server && call->count && call->request);
135 afs_break_callbacks(call->server, call->count, call->request);
138 afs_put_server(call->server);
145 * allow the fileserver to see if the cache manager is still alive
147 static void SRXAFSCB_CallBack(struct work_struct *work)
149 struct afs_call *call = container_of(work, struct afs_call, work);
153 /* be sure to send the reply *before* attempting to spam the AFS server
154 * with FSFetchStatus requests on the vnodes with broken callbacks lest
155 * the AFS server get into a vicious cycle of trying to break further
156 * callbacks because it hadn't received completion of the CBCallBack op
158 afs_send_empty_reply(call);
160 afs_break_callbacks(call->server, call->count, call->request);
165 * deliver request data to a CB.CallBack call
167 static int afs_deliver_cb_callback(struct afs_call *call, struct sk_buff *skb,
170 struct afs_callback *cb;
171 struct afs_server *server;
177 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
179 switch (call->unmarshall) {
184 /* extract the FID array and its count in two steps */
186 _debug("extract FID count");
187 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
191 call->count = ntohl(call->tmp);
192 _debug("FID count: %u", call->count);
193 if (call->count > AFSCBMAX)
196 call->buffer = kmalloc(call->count * 3 * 4, GFP_KERNEL);
203 _debug("extract FID array");
204 ret = afs_extract_data(call, skb, last, call->buffer,
205 call->count * 3 * 4);
209 _debug("unmarshall FID array");
210 call->request = kcalloc(call->count,
211 sizeof(struct afs_callback),
218 for (loop = call->count; loop > 0; loop--, cb++) {
219 cb->fid.vid = ntohl(*bp++);
220 cb->fid.vnode = ntohl(*bp++);
221 cb->fid.unique = ntohl(*bp++);
222 cb->type = AFSCM_CB_UNTYPED;
228 /* extract the callback array and its count in two steps */
230 _debug("extract CB count");
231 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
235 tmp = ntohl(call->tmp);
236 _debug("CB count: %u", tmp);
237 if (tmp != call->count && tmp != 0)
245 _debug("extract CB array");
246 ret = afs_extract_data(call, skb, last, call->request,
247 call->count * 3 * 4);
251 _debug("unmarshall CB array");
254 for (loop = call->count; loop > 0; loop--, cb++) {
255 cb->version = ntohl(*bp++);
256 cb->expiry = ntohl(*bp++);
257 cb->type = ntohl(*bp++);
265 ret = afs_data_complete(call, skb, last);
269 /* Record that the message was unmarshalled successfully so
270 * that the call destructor can know do the callback breaking
271 * work, even if the final ACK isn't received.
273 * If the step number changes, then afs_cm_destructor() must be
281 call->state = AFS_CALL_REPLYING;
283 /* we'll need the file server record as that tells us which set of
284 * vnodes to operate upon */
285 memcpy(&addr, &ip_hdr(skb)->saddr, 4);
286 server = afs_find_server(&addr);
289 call->server = server;
291 INIT_WORK(&call->work, SRXAFSCB_CallBack);
292 queue_work(afs_wq, &call->work);
297 * allow the fileserver to request callback state (re-)initialisation
299 static void SRXAFSCB_InitCallBackState(struct work_struct *work)
301 struct afs_call *call = container_of(work, struct afs_call, work);
303 _enter("{%p}", call->server);
305 afs_init_callback_state(call->server);
306 afs_send_empty_reply(call);
311 * deliver request data to a CB.InitCallBackState call
313 static int afs_deliver_cb_init_call_back_state(struct afs_call *call,
317 struct afs_server *server;
321 _enter(",{%u},%d", skb->len, last);
323 ret = afs_data_complete(call, skb, last);
327 /* no unmarshalling required */
328 call->state = AFS_CALL_REPLYING;
330 /* we'll need the file server record as that tells us which set of
331 * vnodes to operate upon */
332 memcpy(&addr, &ip_hdr(skb)->saddr, 4);
333 server = afs_find_server(&addr);
336 call->server = server;
338 INIT_WORK(&call->work, SRXAFSCB_InitCallBackState);
339 queue_work(afs_wq, &call->work);
344 * deliver request data to a CB.InitCallBackState3 call
346 static int afs_deliver_cb_init_call_back_state3(struct afs_call *call,
350 struct afs_server *server;
353 _enter(",{%u},%d", skb->len, last);
355 /* There are some arguments that we ignore */
356 afs_data_consumed(call, skb);
360 /* no unmarshalling required */
361 call->state = AFS_CALL_REPLYING;
363 /* we'll need the file server record as that tells us which set of
364 * vnodes to operate upon */
365 memcpy(&addr, &ip_hdr(skb)->saddr, 4);
366 server = afs_find_server(&addr);
369 call->server = server;
371 INIT_WORK(&call->work, SRXAFSCB_InitCallBackState);
372 queue_work(afs_wq, &call->work);
377 * allow the fileserver to see if the cache manager is still alive
379 static void SRXAFSCB_Probe(struct work_struct *work)
381 struct afs_call *call = container_of(work, struct afs_call, work);
384 afs_send_empty_reply(call);
389 * deliver request data to a CB.Probe call
391 static int afs_deliver_cb_probe(struct afs_call *call, struct sk_buff *skb,
396 _enter(",{%u},%d", skb->len, last);
398 ret = afs_data_complete(call, skb, last);
402 /* no unmarshalling required */
403 call->state = AFS_CALL_REPLYING;
405 INIT_WORK(&call->work, SRXAFSCB_Probe);
406 queue_work(afs_wq, &call->work);
411 * allow the fileserver to quickly find out if the fileserver has been rebooted
413 static void SRXAFSCB_ProbeUuid(struct work_struct *work)
415 struct afs_call *call = container_of(work, struct afs_call, work);
416 struct afs_uuid *r = call->request;
424 if (memcmp(r, &afs_uuid, sizeof(afs_uuid)) == 0)
425 reply.match = htonl(0);
427 reply.match = htonl(1);
429 afs_send_simple_reply(call, &reply, sizeof(reply));
434 * deliver request data to a CB.ProbeUuid call
436 static int afs_deliver_cb_probe_uuid(struct afs_call *call, struct sk_buff *skb,
444 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
446 ret = afs_data_complete(call, skb, last);
450 switch (call->unmarshall) {
453 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
459 _debug("extract UUID");
460 ret = afs_extract_data(call, skb, last, call->buffer,
461 11 * sizeof(__be32));
464 case -EAGAIN: return 0;
468 _debug("unmarshall UUID");
469 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
475 r->time_low = ntohl(b[0]);
476 r->time_mid = ntohl(b[1]);
477 r->time_hi_and_version = ntohl(b[2]);
478 r->clock_seq_hi_and_reserved = ntohl(b[3]);
479 r->clock_seq_low = ntohl(b[4]);
481 for (loop = 0; loop < 6; loop++)
482 r->node[loop] = ntohl(b[loop + 5]);
494 ret = afs_data_complete(call, skb, last);
498 call->state = AFS_CALL_REPLYING;
500 INIT_WORK(&call->work, SRXAFSCB_ProbeUuid);
501 queue_work(afs_wq, &call->work);
506 * allow the fileserver to ask about the cache manager's capabilities
508 static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
510 struct afs_interface *ifs;
511 struct afs_call *call = container_of(work, struct afs_call, work);
515 struct /* InterfaceAddr */ {
522 struct /* Capabilities */ {
531 ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL);
533 nifs = afs_get_ipv4_interfaces(ifs, 32, false);
541 memset(&reply, 0, sizeof(reply));
542 reply.ia.nifs = htonl(nifs);
544 reply.ia.uuid[0] = htonl(afs_uuid.time_low);
545 reply.ia.uuid[1] = htonl(afs_uuid.time_mid);
546 reply.ia.uuid[2] = htonl(afs_uuid.time_hi_and_version);
547 reply.ia.uuid[3] = htonl((s8) afs_uuid.clock_seq_hi_and_reserved);
548 reply.ia.uuid[4] = htonl((s8) afs_uuid.clock_seq_low);
549 for (loop = 0; loop < 6; loop++)
550 reply.ia.uuid[loop + 5] = htonl((s8) afs_uuid.node[loop]);
553 for (loop = 0; loop < nifs; loop++) {
554 reply.ia.ifaddr[loop] = ifs[loop].address.s_addr;
555 reply.ia.netmask[loop] = ifs[loop].netmask.s_addr;
556 reply.ia.mtu[loop] = htonl(ifs[loop].mtu);
561 reply.cap.capcount = htonl(1);
562 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
563 afs_send_simple_reply(call, &reply, sizeof(reply));
569 * deliver request data to a CB.TellMeAboutYourself call
571 static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call,
572 struct sk_buff *skb, bool last)
576 _enter(",{%u},%d", skb->len, last);
578 ret = afs_data_complete(call, skb, last);
582 /* no unmarshalling required */
583 call->state = AFS_CALL_REPLYING;
585 INIT_WORK(&call->work, SRXAFSCB_TellMeAboutYourself);
586 queue_work(afs_wq, &call->work);