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/sched.h>
20 struct workqueue_struct *afs_cm_workqueue;
23 static int afs_deliver_cb_init_call_back_state(struct afs_call *,
24 struct sk_buff *, bool);
25 static int afs_deliver_cb_init_call_back_state3(struct afs_call *,
26 struct sk_buff *, bool);
27 static int afs_deliver_cb_probe(struct afs_call *, struct sk_buff *, bool);
28 static int afs_deliver_cb_callback(struct afs_call *, struct sk_buff *, bool);
29 static int afs_deliver_cb_probe_uuid(struct afs_call *, struct sk_buff *, bool);
30 static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *,
31 struct sk_buff *, bool);
32 static void afs_cm_destructor(struct afs_call *);
35 * CB.CallBack operation type
37 static const struct afs_call_type afs_SRXCBCallBack = {
38 .name = "CB.CallBack",
39 .deliver = afs_deliver_cb_callback,
40 .abort_to_error = afs_abort_to_error,
41 .destructor = afs_cm_destructor,
45 * CB.InitCallBackState operation type
47 static const struct afs_call_type afs_SRXCBInitCallBackState = {
48 .name = "CB.InitCallBackState",
49 .deliver = afs_deliver_cb_init_call_back_state,
50 .abort_to_error = afs_abort_to_error,
51 .destructor = afs_cm_destructor,
55 * CB.InitCallBackState3 operation type
57 static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
58 .name = "CB.InitCallBackState3",
59 .deliver = afs_deliver_cb_init_call_back_state3,
60 .abort_to_error = afs_abort_to_error,
61 .destructor = afs_cm_destructor,
65 * CB.Probe operation type
67 static const struct afs_call_type afs_SRXCBProbe = {
69 .deliver = afs_deliver_cb_probe,
70 .abort_to_error = afs_abort_to_error,
71 .destructor = afs_cm_destructor,
75 * CB.ProbeUuid operation type
77 static const struct afs_call_type afs_SRXCBProbeUuid = {
78 .name = "CB.ProbeUuid",
79 .deliver = afs_deliver_cb_probe_uuid,
80 .abort_to_error = afs_abort_to_error,
81 .destructor = afs_cm_destructor,
85 * CB.TellMeAboutYourself operation type
87 static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
88 .name = "CB.TellMeAboutYourself",
89 .deliver = afs_deliver_cb_tell_me_about_yourself,
90 .abort_to_error = afs_abort_to_error,
91 .destructor = afs_cm_destructor,
95 * route an incoming cache manager call
96 * - return T if supported, F if not
98 bool afs_cm_incoming_call(struct afs_call *call)
100 u32 operation_id = ntohl(call->operation_ID);
102 _enter("{CB.OP %u}", operation_id);
104 switch (operation_id) {
106 call->type = &afs_SRXCBCallBack;
108 case CBInitCallBackState:
109 call->type = &afs_SRXCBInitCallBackState;
111 case CBInitCallBackState3:
112 call->type = &afs_SRXCBInitCallBackState3;
115 call->type = &afs_SRXCBProbe;
117 case CBTellMeAboutYourself:
118 call->type = &afs_SRXCBTellMeAboutYourself;
126 * clean up a cache manager call
128 static void afs_cm_destructor(struct afs_call *call)
132 afs_put_server(call->server);
139 * allow the fileserver to see if the cache manager is still alive
141 static void SRXAFSCB_CallBack(struct work_struct *work)
143 struct afs_call *call = container_of(work, struct afs_call, work);
147 /* be sure to send the reply *before* attempting to spam the AFS server
148 * with FSFetchStatus requests on the vnodes with broken callbacks lest
149 * the AFS server get into a vicious cycle of trying to break further
150 * callbacks because it hadn't received completion of the CBCallBack op
152 afs_send_empty_reply(call);
154 afs_break_callbacks(call->server, call->count, call->request);
159 * deliver request data to a CB.CallBack call
161 static int afs_deliver_cb_callback(struct afs_call *call, struct sk_buff *skb,
164 struct afs_callback *cb;
165 struct afs_server *server;
171 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
173 switch (call->unmarshall) {
178 /* extract the FID array and its count in two steps */
180 _debug("extract FID count");
181 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
184 case -EAGAIN: return 0;
188 call->count = ntohl(call->tmp);
189 _debug("FID count: %u", call->count);
190 if (call->count > AFSCBMAX)
193 call->buffer = kmalloc(call->count * 3 * 4, GFP_KERNEL);
200 _debug("extract FID array");
201 ret = afs_extract_data(call, skb, last, call->buffer,
202 call->count * 3 * 4);
205 case -EAGAIN: return 0;
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);
234 case -EAGAIN: return 0;
238 tmp = ntohl(call->tmp);
239 _debug("CB count: %u", tmp);
240 if (tmp != call->count && tmp != 0)
248 _debug("extract CB array");
249 ret = afs_extract_data(call, skb, last, call->request,
250 call->count * 3 * 4);
253 case -EAGAIN: return 0;
257 _debug("unmarshall CB array");
260 for (loop = call->count; loop > 0; loop--, cb++) {
261 cb->version = ntohl(*bp++);
262 cb->expiry = ntohl(*bp++);
263 cb->type = ntohl(*bp++);
280 call->state = AFS_CALL_REPLYING;
282 /* we'll need the file server record as that tells us which set of
283 * vnodes to operate upon */
284 memcpy(&addr, &ip_hdr(skb)->saddr, 4);
285 server = afs_find_server(&addr);
288 call->server = server;
290 INIT_WORK(&call->work, SRXAFSCB_CallBack);
291 schedule_work(&call->work);
296 * allow the fileserver to request callback state (re-)initialisation
298 static void SRXAFSCB_InitCallBackState(struct work_struct *work)
300 struct afs_call *call = container_of(work, struct afs_call, work);
302 _enter("{%p}", call->server);
304 afs_init_callback_state(call->server);
305 afs_send_empty_reply(call);
310 * deliver request data to a CB.InitCallBackState call
312 static int afs_deliver_cb_init_call_back_state(struct afs_call *call,
316 struct afs_server *server;
319 _enter(",{%u},%d", skb->len, last);
326 /* no unmarshalling required */
327 call->state = AFS_CALL_REPLYING;
329 /* we'll need the file server record as that tells us which set of
330 * vnodes to operate upon */
331 memcpy(&addr, &ip_hdr(skb)->saddr, 4);
332 server = afs_find_server(&addr);
335 call->server = server;
337 INIT_WORK(&call->work, SRXAFSCB_InitCallBackState);
338 schedule_work(&call->work);
343 * deliver request data to a CB.InitCallBackState3 call
345 static int afs_deliver_cb_init_call_back_state3(struct afs_call *call,
349 struct afs_server *server;
352 _enter(",{%u},%d", skb->len, last);
357 /* no unmarshalling required */
358 call->state = AFS_CALL_REPLYING;
360 /* we'll need the file server record as that tells us which set of
361 * vnodes to operate upon */
362 memcpy(&addr, &ip_hdr(skb)->saddr, 4);
363 server = afs_find_server(&addr);
366 call->server = server;
368 INIT_WORK(&call->work, SRXAFSCB_InitCallBackState);
369 schedule_work(&call->work);
374 * allow the fileserver to see if the cache manager is still alive
376 static void SRXAFSCB_Probe(struct work_struct *work)
378 struct afs_call *call = container_of(work, struct afs_call, work);
381 afs_send_empty_reply(call);
386 * deliver request data to a CB.Probe call
388 static int afs_deliver_cb_probe(struct afs_call *call, struct sk_buff *skb,
391 _enter(",{%u},%d", skb->len, last);
398 /* no unmarshalling required */
399 call->state = AFS_CALL_REPLYING;
401 INIT_WORK(&call->work, SRXAFSCB_Probe);
402 schedule_work(&call->work);
407 * allow the fileserver to quickly find out if the fileserver has been rebooted
409 static void SRXAFSCB_ProbeUuid(struct work_struct *work)
411 struct afs_call *call = container_of(work, struct afs_call, work);
412 struct afs_uuid *r = call->request;
421 if (memcmp(r, &afs_uuid, sizeof(afs_uuid)) == 0)
422 reply.match = htonl(0);
424 reply.match = htonl(1);
426 afs_send_simple_reply(call, &reply, sizeof(reply));
431 * deliver request data to a CB.ProbeUuid call
433 static int afs_deliver_cb_probe_uuid(struct afs_call *call, struct sk_buff *skb,
441 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
448 switch (call->unmarshall) {
451 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
457 _debug("extract UUID");
458 ret = afs_extract_data(call, skb, last, call->buffer,
459 11 * sizeof(__be32));
462 case -EAGAIN: return 0;
466 _debug("unmarshall UUID");
467 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
473 r->time_low = ntohl(b[0]);
474 r->time_mid = ntohl(b[1]);
475 r->time_hi_and_version = ntohl(b[2]);
476 r->clock_seq_hi_and_reserved = ntohl(b[3]);
477 r->clock_seq_low = ntohl(b[4]);
479 for (loop = 0; loop < 6; loop++)
480 r->node[loop] = ntohl(b[loop + 5]);
495 call->state = AFS_CALL_REPLYING;
497 INIT_WORK(&call->work, SRXAFSCB_ProbeUuid);
498 schedule_work(&call->work);
503 * allow the fileserver to ask about the cache manager's capabilities
505 static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
507 struct afs_interface *ifs;
508 struct afs_call *call = container_of(work, struct afs_call, work);
512 struct /* InterfaceAddr */ {
519 struct /* Capabilities */ {
528 ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL);
530 nifs = afs_get_ipv4_interfaces(ifs, 32, false);
538 memset(&reply, 0, sizeof(reply));
539 reply.ia.nifs = htonl(nifs);
541 reply.ia.uuid[0] = htonl(afs_uuid.time_low);
542 reply.ia.uuid[1] = htonl(afs_uuid.time_mid);
543 reply.ia.uuid[2] = htonl(afs_uuid.time_hi_and_version);
544 reply.ia.uuid[3] = htonl((s8) afs_uuid.clock_seq_hi_and_reserved);
545 reply.ia.uuid[4] = htonl((s8) afs_uuid.clock_seq_low);
546 for (loop = 0; loop < 6; loop++)
547 reply.ia.uuid[loop + 5] = htonl((s8) afs_uuid.node[loop]);
550 for (loop = 0; loop < nifs; loop++) {
551 reply.ia.ifaddr[loop] = ifs[loop].address.s_addr;
552 reply.ia.netmask[loop] = ifs[loop].netmask.s_addr;
553 reply.ia.mtu[loop] = htonl(ifs[loop].mtu);
558 reply.cap.capcount = htonl(1);
559 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
560 afs_send_simple_reply(call, &reply, sizeof(reply));
566 * deliver request data to a CB.TellMeAboutYourself call
568 static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call,
569 struct sk_buff *skb, bool last)
571 _enter(",{%u},%d", skb->len, last);
578 /* no unmarshalling required */
579 call->state = AFS_CALL_REPLYING;
581 INIT_WORK(&call->work, SRXAFSCB_TellMeAboutYourself);
582 schedule_work(&call->work);