GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / fs / afs / cmservice.c
blob5a3533fef6c7eec17f186967e0ad61bf219a8e34
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>
16 #include <linux/ip.h>
17 #include "internal.h"
18 #include "afs_cm.h"
21 static int afs_deliver_cb_init_call_back_state(struct afs_call *,
22 struct sk_buff *, bool);
23 static int afs_deliver_cb_init_call_back_state3(struct afs_call *,
24 struct sk_buff *, bool);
25 static int afs_deliver_cb_probe(struct afs_call *, struct sk_buff *, bool);
26 static int afs_deliver_cb_callback(struct afs_call *, struct sk_buff *, bool);
27 static int afs_deliver_cb_probe_uuid(struct afs_call *, struct sk_buff *, bool);
28 static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *,
29 struct sk_buff *, bool);
30 static void afs_cm_destructor(struct afs_call *);
33 * CB.CallBack operation type
35 static const struct afs_call_type afs_SRXCBCallBack = {
36 .name = "CB.CallBack",
37 .deliver = afs_deliver_cb_callback,
38 .abort_to_error = afs_abort_to_error,
39 .destructor = afs_cm_destructor,
43 * CB.InitCallBackState operation type
45 static const struct afs_call_type afs_SRXCBInitCallBackState = {
46 .name = "CB.InitCallBackState",
47 .deliver = afs_deliver_cb_init_call_back_state,
48 .abort_to_error = afs_abort_to_error,
49 .destructor = afs_cm_destructor,
53 * CB.InitCallBackState3 operation type
55 static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
56 .name = "CB.InitCallBackState3",
57 .deliver = afs_deliver_cb_init_call_back_state3,
58 .abort_to_error = afs_abort_to_error,
59 .destructor = afs_cm_destructor,
63 * CB.Probe operation type
65 static const struct afs_call_type afs_SRXCBProbe = {
66 .name = "CB.Probe",
67 .deliver = afs_deliver_cb_probe,
68 .abort_to_error = afs_abort_to_error,
69 .destructor = afs_cm_destructor,
73 * CB.ProbeUuid operation type
75 static const struct afs_call_type afs_SRXCBProbeUuid = {
76 .name = "CB.ProbeUuid",
77 .deliver = afs_deliver_cb_probe_uuid,
78 .abort_to_error = afs_abort_to_error,
79 .destructor = afs_cm_destructor,
83 * CB.TellMeAboutYourself operation type
85 static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
86 .name = "CB.TellMeAboutYourself",
87 .deliver = afs_deliver_cb_tell_me_about_yourself,
88 .abort_to_error = afs_abort_to_error,
89 .destructor = afs_cm_destructor,
93 * route an incoming cache manager call
94 * - return T if supported, F if not
96 bool afs_cm_incoming_call(struct afs_call *call)
98 u32 operation_id = ntohl(call->operation_ID);
100 _enter("{CB.OP %u}", operation_id);
102 switch (operation_id) {
103 case CBCallBack:
104 call->type = &afs_SRXCBCallBack;
105 return true;
106 case CBInitCallBackState:
107 call->type = &afs_SRXCBInitCallBackState;
108 return true;
109 case CBInitCallBackState3:
110 call->type = &afs_SRXCBInitCallBackState3;
111 return true;
112 case CBProbe:
113 call->type = &afs_SRXCBProbe;
114 return true;
115 case CBTellMeAboutYourself:
116 call->type = &afs_SRXCBTellMeAboutYourself;
117 return true;
118 default:
119 return false;
124 * clean up a cache manager call
126 static void afs_cm_destructor(struct afs_call *call)
128 _enter("");
130 afs_put_server(call->server);
131 call->server = NULL;
132 kfree(call->buffer);
133 call->buffer = NULL;
137 * allow the fileserver to see if the cache manager is still alive
139 static void SRXAFSCB_CallBack(struct work_struct *work)
141 struct afs_call *call = container_of(work, struct afs_call, work);
143 _enter("");
145 /* be sure to send the reply *before* attempting to spam the AFS server
146 * with FSFetchStatus requests on the vnodes with broken callbacks lest
147 * the AFS server get into a vicious cycle of trying to break further
148 * callbacks because it hadn't received completion of the CBCallBack op
149 * yet */
150 afs_send_empty_reply(call);
152 afs_break_callbacks(call->server, call->count, call->request);
153 _leave("");
157 * deliver request data to a CB.CallBack call
159 static int afs_deliver_cb_callback(struct afs_call *call, struct sk_buff *skb,
160 bool last)
162 struct afs_callback *cb;
163 struct afs_server *server;
164 struct in_addr addr;
165 __be32 *bp;
166 u32 tmp;
167 int ret, loop;
169 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
171 switch (call->unmarshall) {
172 case 0:
173 call->offset = 0;
174 call->unmarshall++;
176 /* extract the FID array and its count in two steps */
177 case 1:
178 _debug("extract FID count");
179 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
180 switch (ret) {
181 case 0: break;
182 case -EAGAIN: return 0;
183 default: return ret;
186 call->count = ntohl(call->tmp);
187 _debug("FID count: %u", call->count);
188 if (call->count > AFSCBMAX)
189 return -EBADMSG;
191 call->buffer = kmalloc(call->count * 3 * 4, GFP_KERNEL);
192 if (!call->buffer)
193 return -ENOMEM;
194 call->offset = 0;
195 call->unmarshall++;
197 case 2:
198 _debug("extract FID array");
199 ret = afs_extract_data(call, skb, last, call->buffer,
200 call->count * 3 * 4);
201 switch (ret) {
202 case 0: break;
203 case -EAGAIN: return 0;
204 default: return ret;
207 _debug("unmarshall FID array");
208 call->request = kcalloc(call->count,
209 sizeof(struct afs_callback),
210 GFP_KERNEL);
211 if (!call->request)
212 return -ENOMEM;
214 cb = call->request;
215 bp = call->buffer;
216 for (loop = call->count; loop > 0; loop--, cb++) {
217 cb->fid.vid = ntohl(*bp++);
218 cb->fid.vnode = ntohl(*bp++);
219 cb->fid.unique = ntohl(*bp++);
220 cb->type = AFSCM_CB_UNTYPED;
223 call->offset = 0;
224 call->unmarshall++;
226 /* extract the callback array and its count in two steps */
227 case 3:
228 _debug("extract CB count");
229 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
230 switch (ret) {
231 case 0: break;
232 case -EAGAIN: return 0;
233 default: return ret;
236 tmp = ntohl(call->tmp);
237 _debug("CB count: %u", tmp);
238 if (tmp != call->count && tmp != 0)
239 return -EBADMSG;
240 call->offset = 0;
241 call->unmarshall++;
242 if (tmp == 0)
243 goto empty_cb_array;
245 case 4:
246 _debug("extract CB array");
247 ret = afs_extract_data(call, skb, last, call->request,
248 call->count * 3 * 4);
249 switch (ret) {
250 case 0: break;
251 case -EAGAIN: return 0;
252 default: return ret;
255 _debug("unmarshall CB array");
256 cb = call->request;
257 bp = call->buffer;
258 for (loop = call->count; loop > 0; loop--, cb++) {
259 cb->version = ntohl(*bp++);
260 cb->expiry = ntohl(*bp++);
261 cb->type = ntohl(*bp++);
264 empty_cb_array:
265 call->offset = 0;
266 call->unmarshall++;
268 case 5:
269 _debug("trailer");
270 if (skb->len != 0)
271 return -EBADMSG;
272 break;
275 if (!last)
276 return 0;
278 call->state = AFS_CALL_REPLYING;
280 /* we'll need the file server record as that tells us which set of
281 * vnodes to operate upon */
282 memcpy(&addr, &ip_hdr(skb)->saddr, 4);
283 server = afs_find_server(&addr);
284 if (!server)
285 return -ENOTCONN;
286 call->server = server;
288 INIT_WORK(&call->work, SRXAFSCB_CallBack);
289 schedule_work(&call->work);
290 return 0;
294 * allow the fileserver to request callback state (re-)initialisation
296 static void SRXAFSCB_InitCallBackState(struct work_struct *work)
298 struct afs_call *call = container_of(work, struct afs_call, work);
300 _enter("{%p}", call->server);
302 afs_init_callback_state(call->server);
303 afs_send_empty_reply(call);
304 _leave("");
308 * deliver request data to a CB.InitCallBackState call
310 static int afs_deliver_cb_init_call_back_state(struct afs_call *call,
311 struct sk_buff *skb,
312 bool last)
314 struct afs_server *server;
315 struct in_addr addr;
317 _enter(",{%u},%d", skb->len, last);
319 if (skb->len > 0)
320 return -EBADMSG;
321 if (!last)
322 return 0;
324 /* no unmarshalling required */
325 call->state = AFS_CALL_REPLYING;
327 /* we'll need the file server record as that tells us which set of
328 * vnodes to operate upon */
329 memcpy(&addr, &ip_hdr(skb)->saddr, 4);
330 server = afs_find_server(&addr);
331 if (!server)
332 return -ENOTCONN;
333 call->server = server;
335 INIT_WORK(&call->work, SRXAFSCB_InitCallBackState);
336 schedule_work(&call->work);
337 return 0;
341 * deliver request data to a CB.InitCallBackState3 call
343 static int afs_deliver_cb_init_call_back_state3(struct afs_call *call,
344 struct sk_buff *skb,
345 bool last)
347 struct afs_server *server;
348 struct in_addr addr;
350 _enter(",{%u},%d", skb->len, last);
352 if (!last)
353 return 0;
355 /* no unmarshalling required */
356 call->state = AFS_CALL_REPLYING;
358 /* we'll need the file server record as that tells us which set of
359 * vnodes to operate upon */
360 memcpy(&addr, &ip_hdr(skb)->saddr, 4);
361 server = afs_find_server(&addr);
362 if (!server)
363 return -ENOTCONN;
364 call->server = server;
366 INIT_WORK(&call->work, SRXAFSCB_InitCallBackState);
367 schedule_work(&call->work);
368 return 0;
372 * allow the fileserver to see if the cache manager is still alive
374 static void SRXAFSCB_Probe(struct work_struct *work)
376 struct afs_call *call = container_of(work, struct afs_call, work);
378 _enter("");
379 afs_send_empty_reply(call);
380 _leave("");
384 * deliver request data to a CB.Probe call
386 static int afs_deliver_cb_probe(struct afs_call *call, struct sk_buff *skb,
387 bool last)
389 _enter(",{%u},%d", skb->len, last);
391 if (skb->len > 0)
392 return -EBADMSG;
393 if (!last)
394 return 0;
396 /* no unmarshalling required */
397 call->state = AFS_CALL_REPLYING;
399 INIT_WORK(&call->work, SRXAFSCB_Probe);
400 schedule_work(&call->work);
401 return 0;
405 * allow the fileserver to quickly find out if the fileserver has been rebooted
407 static void SRXAFSCB_ProbeUuid(struct work_struct *work)
409 struct afs_call *call = container_of(work, struct afs_call, work);
410 struct afs_uuid *r = call->request;
412 struct {
413 __be32 match;
414 } reply;
416 _enter("");
419 if (memcmp(r, &afs_uuid, sizeof(afs_uuid)) == 0)
420 reply.match = htonl(0);
421 else
422 reply.match = htonl(1);
424 afs_send_simple_reply(call, &reply, sizeof(reply));
425 _leave("");
429 * deliver request data to a CB.ProbeUuid call
431 static int afs_deliver_cb_probe_uuid(struct afs_call *call, struct sk_buff *skb,
432 bool last)
434 struct afs_uuid *r;
435 unsigned loop;
436 __be32 *b;
437 int ret;
439 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
441 if (skb->len > 0)
442 return -EBADMSG;
443 if (!last)
444 return 0;
446 switch (call->unmarshall) {
447 case 0:
448 call->offset = 0;
449 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
450 if (!call->buffer)
451 return -ENOMEM;
452 call->unmarshall++;
454 case 1:
455 _debug("extract UUID");
456 ret = afs_extract_data(call, skb, last, call->buffer,
457 11 * sizeof(__be32));
458 switch (ret) {
459 case 0: break;
460 case -EAGAIN: return 0;
461 default: return ret;
464 _debug("unmarshall UUID");
465 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
466 if (!call->request)
467 return -ENOMEM;
469 b = call->buffer;
470 r = call->request;
471 r->time_low = ntohl(b[0]);
472 r->time_mid = ntohl(b[1]);
473 r->time_hi_and_version = ntohl(b[2]);
474 r->clock_seq_hi_and_reserved = ntohl(b[3]);
475 r->clock_seq_low = ntohl(b[4]);
477 for (loop = 0; loop < 6; loop++)
478 r->node[loop] = ntohl(b[loop + 5]);
480 call->offset = 0;
481 call->unmarshall++;
483 case 2:
484 _debug("trailer");
485 if (skb->len != 0)
486 return -EBADMSG;
487 break;
490 if (!last)
491 return 0;
493 call->state = AFS_CALL_REPLYING;
495 INIT_WORK(&call->work, SRXAFSCB_ProbeUuid);
496 schedule_work(&call->work);
497 return 0;
501 * allow the fileserver to ask about the cache manager's capabilities
503 static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
505 struct afs_interface *ifs;
506 struct afs_call *call = container_of(work, struct afs_call, work);
507 int loop, nifs;
509 struct {
510 struct /* InterfaceAddr */ {
511 __be32 nifs;
512 __be32 uuid[11];
513 __be32 ifaddr[32];
514 __be32 netmask[32];
515 __be32 mtu[32];
516 } ia;
517 struct /* Capabilities */ {
518 __be32 capcount;
519 __be32 caps[1];
520 } cap;
521 } reply;
523 _enter("");
525 nifs = 0;
526 ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL);
527 if (ifs) {
528 nifs = afs_get_ipv4_interfaces(ifs, 32, false);
529 if (nifs < 0) {
530 kfree(ifs);
531 ifs = NULL;
532 nifs = 0;
536 memset(&reply, 0, sizeof(reply));
537 reply.ia.nifs = htonl(nifs);
539 reply.ia.uuid[0] = htonl(afs_uuid.time_low);
540 reply.ia.uuid[1] = htonl(afs_uuid.time_mid);
541 reply.ia.uuid[2] = htonl(afs_uuid.time_hi_and_version);
542 reply.ia.uuid[3] = htonl((s8) afs_uuid.clock_seq_hi_and_reserved);
543 reply.ia.uuid[4] = htonl((s8) afs_uuid.clock_seq_low);
544 for (loop = 0; loop < 6; loop++)
545 reply.ia.uuid[loop + 5] = htonl((s8) afs_uuid.node[loop]);
547 if (ifs) {
548 for (loop = 0; loop < nifs; loop++) {
549 reply.ia.ifaddr[loop] = ifs[loop].address.s_addr;
550 reply.ia.netmask[loop] = ifs[loop].netmask.s_addr;
551 reply.ia.mtu[loop] = htonl(ifs[loop].mtu);
553 kfree(ifs);
556 reply.cap.capcount = htonl(1);
557 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
558 afs_send_simple_reply(call, &reply, sizeof(reply));
560 _leave("");
564 * deliver request data to a CB.TellMeAboutYourself call
566 static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call,
567 struct sk_buff *skb, bool last)
569 _enter(",{%u},%d", skb->len, last);
571 if (skb->len > 0)
572 return -EBADMSG;
573 if (!last)
574 return 0;
576 /* no unmarshalling required */
577 call->state = AFS_CALL_REPLYING;
579 INIT_WORK(&call->work, SRXAFSCB_TellMeAboutYourself);
580 schedule_work(&call->work);
581 return 0;