defconfig: exynos9610: Re-add dropped Wi-Fi AP options lost
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] / fs / afs / cmservice.c
CommitLineData
ec26815a 1/* AFS Cache Manager Service
1da177e4
LT
2 *
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
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.
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
5a0e3ad6 14#include <linux/slab.h>
1da177e4 15#include <linux/sched.h>
08e0e7c8 16#include <linux/ip.h>
1da177e4 17#include "internal.h"
08e0e7c8 18#include "afs_cm.h"
1da177e4 19
d001648e
DH
20static int afs_deliver_cb_init_call_back_state(struct afs_call *);
21static int afs_deliver_cb_init_call_back_state3(struct afs_call *);
22static int afs_deliver_cb_probe(struct afs_call *);
23static int afs_deliver_cb_callback(struct afs_call *);
24static int afs_deliver_cb_probe_uuid(struct afs_call *);
25static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *);
08e0e7c8 26static void afs_cm_destructor(struct afs_call *);
341f741f
DH
27static void SRXAFSCB_CallBack(struct work_struct *);
28static void SRXAFSCB_InitCallBackState(struct work_struct *);
29static void SRXAFSCB_Probe(struct work_struct *);
30static void SRXAFSCB_ProbeUuid(struct work_struct *);
31static void SRXAFSCB_TellMeAboutYourself(struct work_struct *);
1da177e4 32
8e8d7f13
DH
33#define CM_NAME(name) \
34 const char afs_SRXCB##name##_name[] __tracepoint_string = \
35 "CB." #name
36
1da177e4 37/*
08e0e7c8 38 * CB.CallBack operation type
1da177e4 39 */
8e8d7f13 40static CM_NAME(CallBack);
08e0e7c8 41static const struct afs_call_type afs_SRXCBCallBack = {
8e8d7f13 42 .name = afs_SRXCBCallBack_name,
08e0e7c8
DH
43 .deliver = afs_deliver_cb_callback,
44 .abort_to_error = afs_abort_to_error,
45 .destructor = afs_cm_destructor,
341f741f 46 .work = SRXAFSCB_CallBack,
08e0e7c8 47};
1da177e4 48
1da177e4 49/*
08e0e7c8 50 * CB.InitCallBackState operation type
1da177e4 51 */
8e8d7f13 52static CM_NAME(InitCallBackState);
08e0e7c8 53static const struct afs_call_type afs_SRXCBInitCallBackState = {
8e8d7f13 54 .name = afs_SRXCBInitCallBackState_name,
08e0e7c8
DH
55 .deliver = afs_deliver_cb_init_call_back_state,
56 .abort_to_error = afs_abort_to_error,
57 .destructor = afs_cm_destructor,
341f741f 58 .work = SRXAFSCB_InitCallBackState,
08e0e7c8 59};
1da177e4 60
c35eccb1
DH
61/*
62 * CB.InitCallBackState3 operation type
63 */
8e8d7f13 64static CM_NAME(InitCallBackState3);
c35eccb1 65static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
8e8d7f13 66 .name = afs_SRXCBInitCallBackState3_name,
c35eccb1
DH
67 .deliver = afs_deliver_cb_init_call_back_state3,
68 .abort_to_error = afs_abort_to_error,
69 .destructor = afs_cm_destructor,
341f741f 70 .work = SRXAFSCB_InitCallBackState,
c35eccb1
DH
71};
72
1da177e4 73/*
08e0e7c8 74 * CB.Probe operation type
1da177e4 75 */
8e8d7f13 76static CM_NAME(Probe);
08e0e7c8 77static const struct afs_call_type afs_SRXCBProbe = {
8e8d7f13 78 .name = afs_SRXCBProbe_name,
08e0e7c8
DH
79 .deliver = afs_deliver_cb_probe,
80 .abort_to_error = afs_abort_to_error,
81 .destructor = afs_cm_destructor,
341f741f 82 .work = SRXAFSCB_Probe,
08e0e7c8 83};
1da177e4 84
9396d496
DH
85/*
86 * CB.ProbeUuid operation type
87 */
8e8d7f13 88static CM_NAME(ProbeUuid);
9396d496 89static const struct afs_call_type afs_SRXCBProbeUuid = {
8e8d7f13 90 .name = afs_SRXCBProbeUuid_name,
9396d496
DH
91 .deliver = afs_deliver_cb_probe_uuid,
92 .abort_to_error = afs_abort_to_error,
93 .destructor = afs_cm_destructor,
341f741f 94 .work = SRXAFSCB_ProbeUuid,
9396d496
DH
95};
96
b908fe6b 97/*
7c80bcce 98 * CB.TellMeAboutYourself operation type
b908fe6b 99 */
8e8d7f13 100static CM_NAME(TellMeAboutYourself);
7c80bcce 101static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
8e8d7f13 102 .name = afs_SRXCBTellMeAboutYourself_name,
7c80bcce 103 .deliver = afs_deliver_cb_tell_me_about_yourself,
b908fe6b
DH
104 .abort_to_error = afs_abort_to_error,
105 .destructor = afs_cm_destructor,
341f741f 106 .work = SRXAFSCB_TellMeAboutYourself,
b908fe6b
DH
107};
108
1da177e4 109/*
08e0e7c8
DH
110 * route an incoming cache manager call
111 * - return T if supported, F if not
1da177e4 112 */
08e0e7c8 113bool afs_cm_incoming_call(struct afs_call *call)
1da177e4 114{
50a2c953 115 _enter("{CB.OP %u}", call->operation_ID);
08e0e7c8 116
50a2c953 117 switch (call->operation_ID) {
08e0e7c8
DH
118 case CBCallBack:
119 call->type = &afs_SRXCBCallBack;
120 return true;
121 case CBInitCallBackState:
122 call->type = &afs_SRXCBInitCallBackState;
123 return true;
c35eccb1
DH
124 case CBInitCallBackState3:
125 call->type = &afs_SRXCBInitCallBackState3;
126 return true;
08e0e7c8
DH
127 case CBProbe:
128 call->type = &afs_SRXCBProbe;
129 return true;
80e642c0
DH
130 case CBProbeUuid:
131 call->type = &afs_SRXCBProbeUuid;
132 return true;
7c80bcce
DH
133 case CBTellMeAboutYourself:
134 call->type = &afs_SRXCBTellMeAboutYourself;
b908fe6b 135 return true;
08e0e7c8
DH
136 default:
137 return false;
1da177e4 138 }
ec26815a 139}
1da177e4 140
1da177e4 141/*
08e0e7c8 142 * clean up a cache manager call
1da177e4 143 */
08e0e7c8 144static void afs_cm_destructor(struct afs_call *call)
1da177e4 145{
08e0e7c8
DH
146 _enter("");
147
6c67c7c3
DH
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().
151 */
d001648e 152 if (call->unmarshall == 5) {
6c67c7c3
DH
153 ASSERT(call->server && call->count && call->request);
154 afs_break_callbacks(call->server, call->count, call->request);
155 }
156
08e0e7c8
DH
157 afs_put_server(call->server);
158 call->server = NULL;
159 kfree(call->buffer);
160 call->buffer = NULL;
ec26815a 161}
1da177e4 162
1da177e4 163/*
08e0e7c8 164 * allow the fileserver to see if the cache manager is still alive
1da177e4 165 */
08e0e7c8 166static void SRXAFSCB_CallBack(struct work_struct *work)
1da177e4 167{
08e0e7c8 168 struct afs_call *call = container_of(work, struct afs_call, work);
1da177e4 169
08e0e7c8 170 _enter("");
1da177e4 171
08e0e7c8
DH
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
176 * yet */
177 afs_send_empty_reply(call);
1da177e4 178
08e0e7c8 179 afs_break_callbacks(call->server, call->count, call->request);
341f741f 180 afs_put_call(call);
08e0e7c8 181 _leave("");
ec26815a 182}
1da177e4 183
1da177e4 184/*
08e0e7c8 185 * deliver request data to a CB.CallBack call
1da177e4 186 */
d001648e 187static int afs_deliver_cb_callback(struct afs_call *call)
1da177e4 188{
8324f0bc 189 struct sockaddr_rxrpc srx;
08e0e7c8
DH
190 struct afs_callback *cb;
191 struct afs_server *server;
08e0e7c8 192 __be32 *bp;
08e0e7c8
DH
193 int ret, loop;
194
d001648e 195 _enter("{%u}", call->unmarshall);
08e0e7c8
DH
196
197 switch (call->unmarshall) {
198 case 0:
8324f0bc 199 rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
08e0e7c8
DH
200 call->offset = 0;
201 call->unmarshall++;
202
203 /* extract the FID array and its count in two steps */
204 case 1:
205 _debug("extract FID count");
d001648e 206 ret = afs_extract_data(call, &call->tmp, 4, true);
372ee163
DH
207 if (ret < 0)
208 return ret;
1da177e4 209
08e0e7c8
DH
210 call->count = ntohl(call->tmp);
211 _debug("FID count: %u", call->count);
212 if (call->count > AFSCBMAX)
213 return -EBADMSG;
214
215 call->buffer = kmalloc(call->count * 3 * 4, GFP_KERNEL);
216 if (!call->buffer)
217 return -ENOMEM;
218 call->offset = 0;
219 call->unmarshall++;
220
221 case 2:
222 _debug("extract FID array");
d001648e
DH
223 ret = afs_extract_data(call, call->buffer,
224 call->count * 3 * 4, true);
372ee163
DH
225 if (ret < 0)
226 return ret;
1da177e4 227
08e0e7c8
DH
228 _debug("unmarshall FID array");
229 call->request = kcalloc(call->count,
230 sizeof(struct afs_callback),
231 GFP_KERNEL);
232 if (!call->request)
233 return -ENOMEM;
234
235 cb = call->request;
236 bp = call->buffer;
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;
1da177e4
LT
242 }
243
08e0e7c8
DH
244 call->offset = 0;
245 call->unmarshall++;
246
247 /* extract the callback array and its count in two steps */
248 case 3:
249 _debug("extract CB count");
d001648e 250 ret = afs_extract_data(call, &call->tmp, 4, true);
372ee163
DH
251 if (ret < 0)
252 return ret;
1da177e4 253
bcd89270
MD
254 call->count2 = ntohl(call->tmp);
255 _debug("CB count: %u", call->count2);
256 if (call->count2 != call->count && call->count2 != 0)
08e0e7c8
DH
257 return -EBADMSG;
258 call->offset = 0;
259 call->unmarshall++;
08e0e7c8
DH
260
261 case 4:
262 _debug("extract CB array");
d001648e 263 ret = afs_extract_data(call, call->buffer,
bcd89270 264 call->count2 * 3 * 4, false);
372ee163
DH
265 if (ret < 0)
266 return ret;
1da177e4 267
08e0e7c8
DH
268 _debug("unmarshall CB array");
269 cb = call->request;
270 bp = call->buffer;
bcd89270 271 for (loop = call->count2; loop > 0; loop--, cb++) {
08e0e7c8
DH
272 cb->version = ntohl(*bp++);
273 cb->expiry = ntohl(*bp++);
274 cb->type = ntohl(*bp++);
275 }
1da177e4 276
08e0e7c8
DH
277 call->offset = 0;
278 call->unmarshall++;
1da177e4 279
6c67c7c3
DH
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.
283 *
284 * If the step number changes, then afs_cm_destructor() must be
285 * updated also.
286 */
287 call->unmarshall++;
d001648e 288 case 5:
1da177e4
LT
289 break;
290 }
291
08e0e7c8 292 call->state = AFS_CALL_REPLYING;
1da177e4 293
08e0e7c8
DH
294 /* we'll need the file server record as that tells us which set of
295 * vnodes to operate upon */
8324f0bc 296 server = afs_find_server(&srx);
08e0e7c8
DH
297 if (!server)
298 return -ENOTCONN;
299 call->server = server;
300
341f741f 301 return afs_queue_call_work(call);
ec26815a 302}
1da177e4 303
1da177e4 304/*
08e0e7c8 305 * allow the fileserver to request callback state (re-)initialisation
1da177e4 306 */
08e0e7c8 307static void SRXAFSCB_InitCallBackState(struct work_struct *work)
1da177e4 308{
08e0e7c8 309 struct afs_call *call = container_of(work, struct afs_call, work);
1da177e4 310
08e0e7c8 311 _enter("{%p}", call->server);
1da177e4 312
08e0e7c8
DH
313 afs_init_callback_state(call->server);
314 afs_send_empty_reply(call);
341f741f 315 afs_put_call(call);
08e0e7c8 316 _leave("");
ec26815a 317}
1da177e4 318
1da177e4 319/*
08e0e7c8 320 * deliver request data to a CB.InitCallBackState call
1da177e4 321 */
d001648e 322static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
1da177e4 323{
8324f0bc 324 struct sockaddr_rxrpc srx;
1da177e4 325 struct afs_server *server;
372ee163 326 int ret;
1da177e4 327
d001648e 328 _enter("");
1da177e4 329
8324f0bc
DH
330 rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
331
d001648e 332 ret = afs_extract_data(call, NULL, 0, false);
372ee163
DH
333 if (ret < 0)
334 return ret;
1da177e4 335
08e0e7c8
DH
336 /* no unmarshalling required */
337 call->state = AFS_CALL_REPLYING;
1da177e4 338
08e0e7c8
DH
339 /* we'll need the file server record as that tells us which set of
340 * vnodes to operate upon */
8324f0bc 341 server = afs_find_server(&srx);
08e0e7c8
DH
342 if (!server)
343 return -ENOTCONN;
344 call->server = server;
1da177e4 345
341f741f 346 return afs_queue_call_work(call);
08e0e7c8 347}
1da177e4 348
c35eccb1
DH
349/*
350 * deliver request data to a CB.InitCallBackState3 call
351 */
d001648e 352static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
c35eccb1 353{
8324f0bc 354 struct sockaddr_rxrpc srx;
c35eccb1 355 struct afs_server *server;
41bb26f8 356 struct afs_uuid *r;
d001648e
DH
357 unsigned loop;
358 __be32 *b;
359 int ret;
c35eccb1 360
d001648e 361 _enter("");
c35eccb1 362
8324f0bc
DH
363 rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
364
d001648e
DH
365 _enter("{%u}", call->unmarshall);
366
367 switch (call->unmarshall) {
368 case 0:
369 call->offset = 0;
370 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
371 if (!call->buffer)
372 return -ENOMEM;
373 call->unmarshall++;
374
375 case 1:
376 _debug("extract UUID");
377 ret = afs_extract_data(call, call->buffer,
378 11 * sizeof(__be32), false);
379 switch (ret) {
380 case 0: break;
381 case -EAGAIN: return 0;
382 default: return ret;
383 }
384
385 _debug("unmarshall UUID");
41bb26f8 386 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
d001648e
DH
387 if (!call->request)
388 return -ENOMEM;
389
390 b = call->buffer;
391 r = call->request;
ff548773
DH
392 r->time_low = b[0];
393 r->time_mid = htons(ntohl(b[1]));
394 r->time_hi_and_version = htons(ntohl(b[2]));
d001648e
DH
395 r->clock_seq_hi_and_reserved = ntohl(b[3]);
396 r->clock_seq_low = ntohl(b[4]);
397
398 for (loop = 0; loop < 6; loop++)
399 r->node[loop] = ntohl(b[loop + 5]);
400
401 call->offset = 0;
402 call->unmarshall++;
403
404 case 2:
405 break;
406 }
c35eccb1
DH
407
408 /* no unmarshalling required */
409 call->state = AFS_CALL_REPLYING;
410
411 /* we'll need the file server record as that tells us which set of
412 * vnodes to operate upon */
8324f0bc 413 server = afs_find_server(&srx);
c35eccb1
DH
414 if (!server)
415 return -ENOTCONN;
416 call->server = server;
417
341f741f 418 return afs_queue_call_work(call);
c35eccb1
DH
419}
420
08e0e7c8
DH
421/*
422 * allow the fileserver to see if the cache manager is still alive
423 */
424static void SRXAFSCB_Probe(struct work_struct *work)
425{
426 struct afs_call *call = container_of(work, struct afs_call, work);
1da177e4 427
08e0e7c8
DH
428 _enter("");
429 afs_send_empty_reply(call);
341f741f 430 afs_put_call(call);
08e0e7c8
DH
431 _leave("");
432}
1da177e4 433
08e0e7c8
DH
434/*
435 * deliver request data to a CB.Probe call
436 */
d001648e 437static int afs_deliver_cb_probe(struct afs_call *call)
08e0e7c8 438{
372ee163
DH
439 int ret;
440
d001648e 441 _enter("");
1da177e4 442
d001648e 443 ret = afs_extract_data(call, NULL, 0, false);
372ee163
DH
444 if (ret < 0)
445 return ret;
1da177e4 446
08e0e7c8
DH
447 /* no unmarshalling required */
448 call->state = AFS_CALL_REPLYING;
1da177e4 449
341f741f 450 return afs_queue_call_work(call);
ec26815a 451}
b908fe6b 452
9396d496
DH
453/*
454 * allow the fileserver to quickly find out if the fileserver has been rebooted
455 */
456static void SRXAFSCB_ProbeUuid(struct work_struct *work)
457{
458 struct afs_call *call = container_of(work, struct afs_call, work);
41bb26f8 459 struct afs_uuid *r = call->request;
9396d496
DH
460
461 struct {
462 __be32 match;
463 } reply;
464
465 _enter("");
466
9396d496
DH
467 if (memcmp(r, &afs_uuid, sizeof(afs_uuid)) == 0)
468 reply.match = htonl(0);
469 else
470 reply.match = htonl(1);
471
472 afs_send_simple_reply(call, &reply, sizeof(reply));
341f741f 473 afs_put_call(call);
9396d496
DH
474 _leave("");
475}
476
477/*
478 * deliver request data to a CB.ProbeUuid call
479 */
d001648e 480static int afs_deliver_cb_probe_uuid(struct afs_call *call)
9396d496 481{
41bb26f8 482 struct afs_uuid *r;
9396d496
DH
483 unsigned loop;
484 __be32 *b;
485 int ret;
486
d001648e 487 _enter("{%u}", call->unmarshall);
9396d496
DH
488
489 switch (call->unmarshall) {
490 case 0:
491 call->offset = 0;
492 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
493 if (!call->buffer)
494 return -ENOMEM;
495 call->unmarshall++;
496
497 case 1:
498 _debug("extract UUID");
d001648e
DH
499 ret = afs_extract_data(call, call->buffer,
500 11 * sizeof(__be32), false);
9396d496
DH
501 switch (ret) {
502 case 0: break;
503 case -EAGAIN: return 0;
504 default: return ret;
505 }
506
507 _debug("unmarshall UUID");
41bb26f8 508 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
9396d496
DH
509 if (!call->request)
510 return -ENOMEM;
511
512 b = call->buffer;
513 r = call->request;
41bb26f8
CH
514 r->time_low = ntohl(b[0]);
515 r->time_mid = ntohl(b[1]);
516 r->time_hi_and_version = ntohl(b[2]);
9396d496
DH
517 r->clock_seq_hi_and_reserved = ntohl(b[3]);
518 r->clock_seq_low = ntohl(b[4]);
519
520 for (loop = 0; loop < 6; loop++)
521 r->node[loop] = ntohl(b[loop + 5]);
522
523 call->offset = 0;
524 call->unmarshall++;
525
526 case 2:
9396d496
DH
527 break;
528 }
529
9396d496
DH
530 call->state = AFS_CALL_REPLYING;
531
341f741f 532 return afs_queue_call_work(call);
9396d496
DH
533}
534
b908fe6b
DH
535/*
536 * allow the fileserver to ask about the cache manager's capabilities
537 */
7c80bcce 538static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
b908fe6b
DH
539{
540 struct afs_interface *ifs;
541 struct afs_call *call = container_of(work, struct afs_call, work);
542 int loop, nifs;
543
544 struct {
545 struct /* InterfaceAddr */ {
546 __be32 nifs;
547 __be32 uuid[11];
548 __be32 ifaddr[32];
549 __be32 netmask[32];
550 __be32 mtu[32];
551 } ia;
552 struct /* Capabilities */ {
553 __be32 capcount;
554 __be32 caps[1];
555 } cap;
556 } reply;
557
558 _enter("");
559
560 nifs = 0;
561 ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL);
562 if (ifs) {
563 nifs = afs_get_ipv4_interfaces(ifs, 32, false);
564 if (nifs < 0) {
565 kfree(ifs);
566 ifs = NULL;
567 nifs = 0;
568 }
569 }
570
571 memset(&reply, 0, sizeof(reply));
572 reply.ia.nifs = htonl(nifs);
573
ff548773
DH
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));
b908fe6b
DH
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]);
581
582 if (ifs) {
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);
587 }
5b35fad9 588 kfree(ifs);
b908fe6b
DH
589 }
590
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));
341f741f 594 afs_put_call(call);
b908fe6b
DH
595 _leave("");
596}
597
598/*
7c80bcce 599 * deliver request data to a CB.TellMeAboutYourself call
b908fe6b 600 */
d001648e 601static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
b908fe6b 602{
372ee163
DH
603 int ret;
604
d001648e 605 _enter("");
b908fe6b 606
d001648e 607 ret = afs_extract_data(call, NULL, 0, false);
372ee163
DH
608 if (ret < 0)
609 return ret;
b908fe6b
DH
610
611 /* no unmarshalling required */
612 call->state = AFS_CALL_REPLYING;
613
341f741f 614 return afs_queue_call_work(call);
b908fe6b 615}