Merge tag 'spi-fix-v5.13-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/brooni...
[linux-2.6-block.git] / fs / afs / cmservice.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
ec26815a 2/* AFS Cache Manager Service
1da177e4
LT
3 *
4 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
1da177e4
LT
6 */
7
8#include <linux/module.h>
9#include <linux/init.h>
5a0e3ad6 10#include <linux/slab.h>
1da177e4 11#include <linux/sched.h>
08e0e7c8 12#include <linux/ip.h>
1da177e4 13#include "internal.h"
08e0e7c8 14#include "afs_cm.h"
35dbfba3 15#include "protocol_yfs.h"
1da177e4 16
d001648e
DH
17static int afs_deliver_cb_init_call_back_state(struct afs_call *);
18static int afs_deliver_cb_init_call_back_state3(struct afs_call *);
19static int afs_deliver_cb_probe(struct afs_call *);
20static int afs_deliver_cb_callback(struct afs_call *);
21static int afs_deliver_cb_probe_uuid(struct afs_call *);
22static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *);
08e0e7c8 23static void afs_cm_destructor(struct afs_call *);
341f741f
DH
24static void SRXAFSCB_CallBack(struct work_struct *);
25static void SRXAFSCB_InitCallBackState(struct work_struct *);
26static void SRXAFSCB_Probe(struct work_struct *);
27static void SRXAFSCB_ProbeUuid(struct work_struct *);
28static void SRXAFSCB_TellMeAboutYourself(struct work_struct *);
1da177e4 29
35dbfba3
DH
30static int afs_deliver_yfs_cb_callback(struct afs_call *);
31
8e8d7f13 32#define CM_NAME(name) \
d2abfa86 33 char afs_SRXCB##name##_name[] __tracepoint_string = \
8e8d7f13
DH
34 "CB." #name
35
1da177e4 36/*
08e0e7c8 37 * CB.CallBack operation type
1da177e4 38 */
8e8d7f13 39static CM_NAME(CallBack);
08e0e7c8 40static const struct afs_call_type afs_SRXCBCallBack = {
8e8d7f13 41 .name = afs_SRXCBCallBack_name,
08e0e7c8 42 .deliver = afs_deliver_cb_callback,
08e0e7c8 43 .destructor = afs_cm_destructor,
341f741f 44 .work = SRXAFSCB_CallBack,
08e0e7c8 45};
1da177e4 46
1da177e4 47/*
08e0e7c8 48 * CB.InitCallBackState operation type
1da177e4 49 */
8e8d7f13 50static CM_NAME(InitCallBackState);
08e0e7c8 51static const struct afs_call_type afs_SRXCBInitCallBackState = {
8e8d7f13 52 .name = afs_SRXCBInitCallBackState_name,
08e0e7c8 53 .deliver = afs_deliver_cb_init_call_back_state,
08e0e7c8 54 .destructor = afs_cm_destructor,
341f741f 55 .work = SRXAFSCB_InitCallBackState,
08e0e7c8 56};
1da177e4 57
c35eccb1
DH
58/*
59 * CB.InitCallBackState3 operation type
60 */
8e8d7f13 61static CM_NAME(InitCallBackState3);
c35eccb1 62static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
8e8d7f13 63 .name = afs_SRXCBInitCallBackState3_name,
c35eccb1 64 .deliver = afs_deliver_cb_init_call_back_state3,
c35eccb1 65 .destructor = afs_cm_destructor,
341f741f 66 .work = SRXAFSCB_InitCallBackState,
c35eccb1
DH
67};
68
1da177e4 69/*
08e0e7c8 70 * CB.Probe operation type
1da177e4 71 */
8e8d7f13 72static CM_NAME(Probe);
08e0e7c8 73static const struct afs_call_type afs_SRXCBProbe = {
8e8d7f13 74 .name = afs_SRXCBProbe_name,
08e0e7c8 75 .deliver = afs_deliver_cb_probe,
08e0e7c8 76 .destructor = afs_cm_destructor,
341f741f 77 .work = SRXAFSCB_Probe,
08e0e7c8 78};
1da177e4 79
9396d496
DH
80/*
81 * CB.ProbeUuid operation type
82 */
8e8d7f13 83static CM_NAME(ProbeUuid);
9396d496 84static const struct afs_call_type afs_SRXCBProbeUuid = {
8e8d7f13 85 .name = afs_SRXCBProbeUuid_name,
9396d496 86 .deliver = afs_deliver_cb_probe_uuid,
9396d496 87 .destructor = afs_cm_destructor,
341f741f 88 .work = SRXAFSCB_ProbeUuid,
9396d496
DH
89};
90
b908fe6b 91/*
7c80bcce 92 * CB.TellMeAboutYourself operation type
b908fe6b 93 */
8e8d7f13 94static CM_NAME(TellMeAboutYourself);
7c80bcce 95static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
8e8d7f13 96 .name = afs_SRXCBTellMeAboutYourself_name,
7c80bcce 97 .deliver = afs_deliver_cb_tell_me_about_yourself,
b908fe6b 98 .destructor = afs_cm_destructor,
341f741f 99 .work = SRXAFSCB_TellMeAboutYourself,
b908fe6b
DH
100};
101
35dbfba3
DH
102/*
103 * YFS CB.CallBack operation type
104 */
105static CM_NAME(YFS_CallBack);
106static const struct afs_call_type afs_SRXYFSCB_CallBack = {
107 .name = afs_SRXCBYFS_CallBack_name,
108 .deliver = afs_deliver_yfs_cb_callback,
109 .destructor = afs_cm_destructor,
110 .work = SRXAFSCB_CallBack,
111};
112
1da177e4 113/*
08e0e7c8
DH
114 * route an incoming cache manager call
115 * - return T if supported, F if not
1da177e4 116 */
08e0e7c8 117bool afs_cm_incoming_call(struct afs_call *call)
1da177e4 118{
35dbfba3 119 _enter("{%u, CB.OP %u}", call->service_id, call->operation_ID);
08e0e7c8 120
50a2c953 121 switch (call->operation_ID) {
08e0e7c8
DH
122 case CBCallBack:
123 call->type = &afs_SRXCBCallBack;
124 return true;
125 case CBInitCallBackState:
126 call->type = &afs_SRXCBInitCallBackState;
127 return true;
c35eccb1
DH
128 case CBInitCallBackState3:
129 call->type = &afs_SRXCBInitCallBackState3;
130 return true;
08e0e7c8
DH
131 case CBProbe:
132 call->type = &afs_SRXCBProbe;
133 return true;
f4b3526d
DH
134 case CBProbeUuid:
135 call->type = &afs_SRXCBProbeUuid;
136 return true;
7c80bcce
DH
137 case CBTellMeAboutYourself:
138 call->type = &afs_SRXCBTellMeAboutYourself;
b908fe6b 139 return true;
35dbfba3
DH
140 case YFSCBCallBack:
141 if (call->service_id != YFS_CM_SERVICE)
142 return false;
143 call->type = &afs_SRXYFSCB_CallBack;
144 return true;
08e0e7c8
DH
145 default:
146 return false;
1da177e4 147 }
ec26815a 148}
1da177e4 149
3bf0fb6f
DH
150/*
151 * Find the server record by peer address and record a probe to the cache
152 * manager from a server.
153 */
154static int afs_find_cm_server_by_peer(struct afs_call *call)
155{
156 struct sockaddr_rxrpc srx;
157 struct afs_server *server;
158
159 rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
160
161 server = afs_find_server(call->net, &srx);
162 if (!server) {
163 trace_afs_cm_no_server(call, &srx);
164 return 0;
165 }
166
ffba718e 167 call->server = server;
44746355 168 return 0;
3bf0fb6f
DH
169}
170
171/*
172 * Find the server record by server UUID and record a probe to the cache
173 * manager from a server.
174 */
175static int afs_find_cm_server_by_uuid(struct afs_call *call,
176 struct afs_uuid *uuid)
177{
178 struct afs_server *server;
179
180 rcu_read_lock();
181 server = afs_find_server_by_uuid(call->net, call->request);
182 rcu_read_unlock();
183 if (!server) {
184 trace_afs_cm_no_server_u(call, call->request);
185 return 0;
186 }
187
ffba718e 188 call->server = server;
44746355 189 return 0;
3bf0fb6f
DH
190}
191
1da177e4 192/*
428edade 193 * Clean up a cache manager call.
1da177e4 194 */
08e0e7c8 195static void afs_cm_destructor(struct afs_call *call)
1da177e4 196{
08e0e7c8
DH
197 kfree(call->buffer);
198 call->buffer = NULL;
ec26815a 199}
1da177e4 200
dde9f095
DH
201/*
202 * Abort a service call from within an action function.
203 */
204static void afs_abort_service_call(struct afs_call *call, u32 abort_code, int error,
205 const char *why)
206{
207 rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
208 abort_code, error, why);
209 afs_set_call_complete(call, error, 0);
210}
211
1da177e4 212/*
c435ee34 213 * The server supplied a list of callbacks that it wanted to break.
1da177e4 214 */
08e0e7c8 215static void SRXAFSCB_CallBack(struct work_struct *work)
1da177e4 216{
08e0e7c8 217 struct afs_call *call = container_of(work, struct afs_call, work);
1da177e4 218
08e0e7c8 219 _enter("");
1da177e4 220
428edade
DH
221 /* We need to break the callbacks before sending the reply as the
222 * server holds up change visibility till it receives our reply so as
223 * to maintain cache coherency.
224 */
45218193 225 if (call->server) {
977e5f8e
DH
226 trace_afs_server(call->server,
227 atomic_read(&call->server->ref),
228 atomic_read(&call->server->active),
45218193 229 afs_server_trace_callback);
ffba718e 230 afs_break_callbacks(call->server, call->count, call->request);
45218193 231 }
428edade
DH
232
233 afs_send_empty_reply(call);
341f741f 234 afs_put_call(call);
08e0e7c8 235 _leave("");
ec26815a 236}
1da177e4 237
1da177e4 238/*
08e0e7c8 239 * deliver request data to a CB.CallBack call
1da177e4 240 */
d001648e 241static int afs_deliver_cb_callback(struct afs_call *call)
1da177e4 242{
5cf9dd55 243 struct afs_callback_break *cb;
08e0e7c8 244 __be32 *bp;
08e0e7c8
DH
245 int ret, loop;
246
d001648e 247 _enter("{%u}", call->unmarshall);
08e0e7c8
DH
248
249 switch (call->unmarshall) {
250 case 0:
12bdcf33 251 afs_extract_to_tmp(call);
08e0e7c8
DH
252 call->unmarshall++;
253
254 /* extract the FID array and its count in two steps */
df561f66 255 fallthrough;
08e0e7c8
DH
256 case 1:
257 _debug("extract FID count");
12bdcf33 258 ret = afs_extract_data(call, true);
372ee163
DH
259 if (ret < 0)
260 return ret;
1da177e4 261
08e0e7c8
DH
262 call->count = ntohl(call->tmp);
263 _debug("FID count: %u", call->count);
264 if (call->count > AFSCBMAX)
7126ead9 265 return afs_protocol_error(call, afs_eproto_cb_fid_count);
08e0e7c8 266
6da2ec56
KC
267 call->buffer = kmalloc(array3_size(call->count, 3, 4),
268 GFP_KERNEL);
08e0e7c8
DH
269 if (!call->buffer)
270 return -ENOMEM;
12bdcf33 271 afs_extract_to_buf(call, call->count * 3 * 4);
08e0e7c8
DH
272 call->unmarshall++;
273
df561f66 274 fallthrough;
08e0e7c8
DH
275 case 2:
276 _debug("extract FID array");
12bdcf33 277 ret = afs_extract_data(call, true);
372ee163
DH
278 if (ret < 0)
279 return ret;
1da177e4 280
08e0e7c8
DH
281 _debug("unmarshall FID array");
282 call->request = kcalloc(call->count,
5cf9dd55 283 sizeof(struct afs_callback_break),
08e0e7c8
DH
284 GFP_KERNEL);
285 if (!call->request)
286 return -ENOMEM;
287
288 cb = call->request;
289 bp = call->buffer;
290 for (loop = call->count; loop > 0; loop--, cb++) {
291 cb->fid.vid = ntohl(*bp++);
292 cb->fid.vnode = ntohl(*bp++);
293 cb->fid.unique = ntohl(*bp++);
1da177e4
LT
294 }
295
12bdcf33 296 afs_extract_to_tmp(call);
08e0e7c8
DH
297 call->unmarshall++;
298
299 /* extract the callback array and its count in two steps */
df561f66 300 fallthrough;
08e0e7c8
DH
301 case 3:
302 _debug("extract CB count");
12bdcf33 303 ret = afs_extract_data(call, true);
372ee163
DH
304 if (ret < 0)
305 return ret;
1da177e4 306
bcd89270
MD
307 call->count2 = ntohl(call->tmp);
308 _debug("CB count: %u", call->count2);
309 if (call->count2 != call->count && call->count2 != 0)
7126ead9 310 return afs_protocol_error(call, afs_eproto_cb_count);
fc276122
DH
311 call->iter = &call->def_iter;
312 iov_iter_discard(&call->def_iter, READ, call->count2 * 3 * 4);
08e0e7c8 313 call->unmarshall++;
08e0e7c8 314
df561f66 315 fallthrough;
08e0e7c8 316 case 4:
06aeb297 317 _debug("extract discard %zu/%u",
fc276122 318 iov_iter_count(call->iter), call->count2 * 3 * 4);
06aeb297 319
12bdcf33 320 ret = afs_extract_data(call, false);
372ee163
DH
321 if (ret < 0)
322 return ret;
1da177e4 323
08e0e7c8 324 call->unmarshall++;
b2db6c35
GS
325 fallthrough;
326
d001648e 327 case 5:
1da177e4
LT
328 break;
329 }
330
98bf40cd 331 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
f51375cd 332 return afs_io_error(call, afs_io_error_cm_reply);
1da177e4 333
08e0e7c8
DH
334 /* we'll need the file server record as that tells us which set of
335 * vnodes to operate upon */
3bf0fb6f 336 return afs_find_cm_server_by_peer(call);
ec26815a 337}
1da177e4 338
1da177e4 339/*
08e0e7c8 340 * allow the fileserver to request callback state (re-)initialisation
1da177e4 341 */
08e0e7c8 342static void SRXAFSCB_InitCallBackState(struct work_struct *work)
1da177e4 343{
08e0e7c8 344 struct afs_call *call = container_of(work, struct afs_call, work);
1da177e4 345
ffba718e 346 _enter("{%p}", call->server);
1da177e4 347
ffba718e
DH
348 if (call->server)
349 afs_init_callback_state(call->server);
08e0e7c8 350 afs_send_empty_reply(call);
341f741f 351 afs_put_call(call);
08e0e7c8 352 _leave("");
ec26815a 353}
1da177e4 354
1da177e4 355/*
08e0e7c8 356 * deliver request data to a CB.InitCallBackState call
1da177e4 357 */
d001648e 358static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
1da177e4 359{
372ee163 360 int ret;
1da177e4 361
d001648e 362 _enter("");
1da177e4 363
12bdcf33
DH
364 afs_extract_discard(call, 0);
365 ret = afs_extract_data(call, false);
372ee163
DH
366 if (ret < 0)
367 return ret;
1da177e4 368
08e0e7c8
DH
369 /* we'll need the file server record as that tells us which set of
370 * vnodes to operate upon */
3bf0fb6f 371 return afs_find_cm_server_by_peer(call);
08e0e7c8 372}
1da177e4 373
c35eccb1
DH
374/*
375 * deliver request data to a CB.InitCallBackState3 call
376 */
d001648e 377static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
c35eccb1 378{
41bb26f8 379 struct afs_uuid *r;
d001648e
DH
380 unsigned loop;
381 __be32 *b;
382 int ret;
c35eccb1 383
d001648e 384 _enter("");
c35eccb1 385
d001648e
DH
386 _enter("{%u}", call->unmarshall);
387
388 switch (call->unmarshall) {
389 case 0:
6da2ec56 390 call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
d001648e
DH
391 if (!call->buffer)
392 return -ENOMEM;
12bdcf33 393 afs_extract_to_buf(call, 11 * sizeof(__be32));
d001648e
DH
394 call->unmarshall++;
395
df561f66 396 fallthrough;
d001648e
DH
397 case 1:
398 _debug("extract UUID");
12bdcf33 399 ret = afs_extract_data(call, false);
d001648e
DH
400 switch (ret) {
401 case 0: break;
402 case -EAGAIN: return 0;
403 default: return ret;
404 }
405
406 _debug("unmarshall UUID");
41bb26f8 407 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
d001648e
DH
408 if (!call->request)
409 return -ENOMEM;
410
411 b = call->buffer;
412 r = call->request;
ff548773
DH
413 r->time_low = b[0];
414 r->time_mid = htons(ntohl(b[1]));
415 r->time_hi_and_version = htons(ntohl(b[2]));
d001648e
DH
416 r->clock_seq_hi_and_reserved = ntohl(b[3]);
417 r->clock_seq_low = ntohl(b[4]);
418
419 for (loop = 0; loop < 6; loop++)
420 r->node[loop] = ntohl(b[loop + 5]);
421
d001648e 422 call->unmarshall++;
b2db6c35 423 fallthrough;
d001648e
DH
424
425 case 2:
426 break;
427 }
c35eccb1 428
98bf40cd 429 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
f51375cd 430 return afs_io_error(call, afs_io_error_cm_reply);
c35eccb1
DH
431
432 /* we'll need the file server record as that tells us which set of
433 * vnodes to operate upon */
3bf0fb6f 434 return afs_find_cm_server_by_uuid(call, call->request);
c35eccb1
DH
435}
436
08e0e7c8
DH
437/*
438 * allow the fileserver to see if the cache manager is still alive
439 */
440static void SRXAFSCB_Probe(struct work_struct *work)
441{
442 struct afs_call *call = container_of(work, struct afs_call, work);
1da177e4 443
08e0e7c8
DH
444 _enter("");
445 afs_send_empty_reply(call);
341f741f 446 afs_put_call(call);
08e0e7c8
DH
447 _leave("");
448}
1da177e4 449
08e0e7c8
DH
450/*
451 * deliver request data to a CB.Probe call
452 */
d001648e 453static int afs_deliver_cb_probe(struct afs_call *call)
08e0e7c8 454{
372ee163
DH
455 int ret;
456
d001648e 457 _enter("");
1da177e4 458
12bdcf33
DH
459 afs_extract_discard(call, 0);
460 ret = afs_extract_data(call, false);
372ee163
DH
461 if (ret < 0)
462 return ret;
1da177e4 463
98bf40cd 464 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
f51375cd 465 return afs_io_error(call, afs_io_error_cm_reply);
3bf0fb6f 466 return afs_find_cm_server_by_peer(call);
ec26815a 467}
b908fe6b 468
9396d496 469/*
3120c170
DH
470 * Allow the fileserver to quickly find out if the cache manager has been
471 * rebooted.
9396d496
DH
472 */
473static void SRXAFSCB_ProbeUuid(struct work_struct *work)
474{
475 struct afs_call *call = container_of(work, struct afs_call, work);
41bb26f8 476 struct afs_uuid *r = call->request;
9396d496 477
9396d496
DH
478 _enter("");
479
f044c884 480 if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0)
2067b2b3 481 afs_send_empty_reply(call);
9396d496 482 else
dde9f095 483 afs_abort_service_call(call, 1, 1, "K-1");
9396d496 484
341f741f 485 afs_put_call(call);
9396d496
DH
486 _leave("");
487}
488
489/*
490 * deliver request data to a CB.ProbeUuid call
491 */
d001648e 492static int afs_deliver_cb_probe_uuid(struct afs_call *call)
9396d496 493{
41bb26f8 494 struct afs_uuid *r;
9396d496
DH
495 unsigned loop;
496 __be32 *b;
497 int ret;
498
d001648e 499 _enter("{%u}", call->unmarshall);
9396d496
DH
500
501 switch (call->unmarshall) {
502 case 0:
6da2ec56 503 call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
9396d496
DH
504 if (!call->buffer)
505 return -ENOMEM;
12bdcf33 506 afs_extract_to_buf(call, 11 * sizeof(__be32));
9396d496
DH
507 call->unmarshall++;
508
df561f66 509 fallthrough;
9396d496
DH
510 case 1:
511 _debug("extract UUID");
12bdcf33 512 ret = afs_extract_data(call, false);
9396d496
DH
513 switch (ret) {
514 case 0: break;
515 case -EAGAIN: return 0;
516 default: return ret;
517 }
518
519 _debug("unmarshall UUID");
41bb26f8 520 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
9396d496
DH
521 if (!call->request)
522 return -ENOMEM;
523
524 b = call->buffer;
525 r = call->request;
fe342cf7
DH
526 r->time_low = b[0];
527 r->time_mid = htons(ntohl(b[1]));
528 r->time_hi_and_version = htons(ntohl(b[2]));
9396d496
DH
529 r->clock_seq_hi_and_reserved = ntohl(b[3]);
530 r->clock_seq_low = ntohl(b[4]);
531
532 for (loop = 0; loop < 6; loop++)
533 r->node[loop] = ntohl(b[loop + 5]);
534
9396d496 535 call->unmarshall++;
b2db6c35 536 fallthrough;
9396d496
DH
537
538 case 2:
9396d496
DH
539 break;
540 }
541
98bf40cd 542 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
f51375cd 543 return afs_io_error(call, afs_io_error_cm_reply);
3120c170 544 return afs_find_cm_server_by_peer(call);
9396d496
DH
545}
546
b908fe6b
DH
547/*
548 * allow the fileserver to ask about the cache manager's capabilities
549 */
7c80bcce 550static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
b908fe6b 551{
b908fe6b 552 struct afs_call *call = container_of(work, struct afs_call, work);
35ebfc22 553 int loop;
b908fe6b
DH
554
555 struct {
556 struct /* InterfaceAddr */ {
557 __be32 nifs;
558 __be32 uuid[11];
559 __be32 ifaddr[32];
560 __be32 netmask[32];
561 __be32 mtu[32];
562 } ia;
563 struct /* Capabilities */ {
564 __be32 capcount;
565 __be32 caps[1];
566 } cap;
567 } reply;
568
569 _enter("");
570
b908fe6b 571 memset(&reply, 0, sizeof(reply));
b908fe6b 572
f044c884
DH
573 reply.ia.uuid[0] = call->net->uuid.time_low;
574 reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid));
575 reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version));
576 reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved);
577 reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low);
b908fe6b 578 for (loop = 0; loop < 6; loop++)
f044c884 579 reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]);
b908fe6b 580
b908fe6b
DH
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));
341f741f 584 afs_put_call(call);
b908fe6b
DH
585 _leave("");
586}
587
588/*
7c80bcce 589 * deliver request data to a CB.TellMeAboutYourself call
b908fe6b 590 */
d001648e 591static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
b908fe6b 592{
372ee163
DH
593 int ret;
594
d001648e 595 _enter("");
b908fe6b 596
12bdcf33
DH
597 afs_extract_discard(call, 0);
598 ret = afs_extract_data(call, false);
372ee163
DH
599 if (ret < 0)
600 return ret;
b908fe6b 601
98bf40cd 602 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
f51375cd 603 return afs_io_error(call, afs_io_error_cm_reply);
3bf0fb6f 604 return afs_find_cm_server_by_peer(call);
b908fe6b 605}
35dbfba3
DH
606
607/*
608 * deliver request data to a YFS CB.CallBack call
609 */
610static int afs_deliver_yfs_cb_callback(struct afs_call *call)
611{
612 struct afs_callback_break *cb;
35dbfba3
DH
613 struct yfs_xdr_YFSFid *bp;
614 size_t size;
615 int ret, loop;
616
617 _enter("{%u}", call->unmarshall);
618
619 switch (call->unmarshall) {
620 case 0:
621 afs_extract_to_tmp(call);
622 call->unmarshall++;
623
624 /* extract the FID array and its count in two steps */
df561f66 625 fallthrough;
35dbfba3
DH
626 case 1:
627 _debug("extract FID count");
628 ret = afs_extract_data(call, true);
629 if (ret < 0)
630 return ret;
631
632 call->count = ntohl(call->tmp);
633 _debug("FID count: %u", call->count);
634 if (call->count > YFSCBMAX)
7126ead9 635 return afs_protocol_error(call, afs_eproto_cb_fid_count);
35dbfba3
DH
636
637 size = array_size(call->count, sizeof(struct yfs_xdr_YFSFid));
638 call->buffer = kmalloc(size, GFP_KERNEL);
639 if (!call->buffer)
640 return -ENOMEM;
641 afs_extract_to_buf(call, size);
642 call->unmarshall++;
643
df561f66 644 fallthrough;
35dbfba3
DH
645 case 2:
646 _debug("extract FID array");
647 ret = afs_extract_data(call, false);
648 if (ret < 0)
649 return ret;
650
651 _debug("unmarshall FID array");
652 call->request = kcalloc(call->count,
653 sizeof(struct afs_callback_break),
654 GFP_KERNEL);
655 if (!call->request)
656 return -ENOMEM;
657
658 cb = call->request;
659 bp = call->buffer;
660 for (loop = call->count; loop > 0; loop--, cb++) {
661 cb->fid.vid = xdr_to_u64(bp->volume);
662 cb->fid.vnode = xdr_to_u64(bp->vnode.lo);
663 cb->fid.vnode_hi = ntohl(bp->vnode.hi);
664 cb->fid.unique = ntohl(bp->vnode.unique);
665 bp++;
666 }
667
668 afs_extract_to_tmp(call);
669 call->unmarshall++;
b2db6c35 670 fallthrough;
35dbfba3
DH
671
672 case 3:
673 break;
674 }
675
676 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
677 return afs_io_error(call, afs_io_error_cm_reply);
678
679 /* We'll need the file server record as that tells us which set of
680 * vnodes to operate upon.
681 */
3bf0fb6f 682 return afs_find_cm_server_by_peer(call);
35dbfba3 683}