]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - fs/afs/vlclient.c
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152
[mirror_ubuntu-focal-kernel.git] / fs / afs / vlclient.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
ec26815a 2/* AFS Volume Location Service client
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
5a0e3ad6 8#include <linux/gfp.h>
1da177e4
LT
9#include <linux/init.h>
10#include <linux/sched.h>
4d9df986 11#include "afs_fs.h"
1da177e4
LT
12#include "internal.h"
13
1da177e4 14/*
d2ddc776 15 * Deliver reply data to a VL.GetEntryByNameU call.
1da177e4 16 */
d2ddc776 17static int afs_deliver_vl_get_entry_by_name_u(struct afs_call *call)
1da177e4 18{
d2ddc776
DH
19 struct afs_uvldbentry__xdr *uvldb;
20 struct afs_vldb_entry *entry;
21 bool new_only = false;
1fba5868 22 u32 tmp, nr_servers, vlflags;
d2ddc776 23 int i, ret;
1da177e4 24
d001648e 25 _enter("");
1da177e4 26
d001648e 27 ret = afs_transfer_reply(call);
372ee163
DH
28 if (ret < 0)
29 return ret;
1da177e4 30
08e0e7c8 31 /* unmarshall the reply once we've received all of it */
d2ddc776 32 uvldb = call->buffer;
ffba718e 33 entry = call->ret_vldb;
d2ddc776 34
45df8462
DH
35 nr_servers = ntohl(uvldb->nServers);
36 if (nr_servers > AFS_NMAXNSERVERS)
37 nr_servers = AFS_NMAXNSERVERS;
38
d2ddc776
DH
39 for (i = 0; i < ARRAY_SIZE(uvldb->name) - 1; i++)
40 entry->name[i] = (u8)ntohl(uvldb->name[i]);
41 entry->name[i] = 0;
42 entry->name_len = strlen(entry->name);
43
44 /* If there is a new replication site that we can use, ignore all the
45 * sites that aren't marked as new.
46 */
45df8462 47 for (i = 0; i < nr_servers; i++) {
d2ddc776
DH
48 tmp = ntohl(uvldb->serverFlags[i]);
49 if (!(tmp & AFS_VLSF_DONTUSE) &&
50 (tmp & AFS_VLSF_NEWREPSITE))
51 new_only = true;
4d9df986 52 }
1da177e4 53
1fba5868 54 vlflags = ntohl(uvldb->flags);
45df8462 55 for (i = 0; i < nr_servers; i++) {
d2ddc776
DH
56 struct afs_uuid__xdr *xdr;
57 struct afs_uuid *uuid;
58 int j;
1da177e4 59
d2ddc776
DH
60 tmp = ntohl(uvldb->serverFlags[i]);
61 if (tmp & AFS_VLSF_DONTUSE ||
62 (new_only && !(tmp & AFS_VLSF_NEWREPSITE)))
63 continue;
1fba5868 64 if (tmp & AFS_VLSF_RWVOL) {
d2ddc776 65 entry->fs_mask[i] |= AFS_VOL_VTM_RW;
1fba5868
MD
66 if (vlflags & AFS_VLF_BACKEXISTS)
67 entry->fs_mask[i] |= AFS_VOL_VTM_BAK;
68 }
1da177e4 69 if (tmp & AFS_VLSF_ROVOL)
d2ddc776 70 entry->fs_mask[i] |= AFS_VOL_VTM_RO;
d2ddc776
DH
71 if (!entry->fs_mask[i])
72 continue;
73
74 xdr = &uvldb->serverNumber[i];
75 uuid = (struct afs_uuid *)&entry->fs_server[i];
76 uuid->time_low = xdr->time_low;
77 uuid->time_mid = htons(ntohl(xdr->time_mid));
78 uuid->time_hi_and_version = htons(ntohl(xdr->time_hi_and_version));
79 uuid->clock_seq_hi_and_reserved = (u8)ntohl(xdr->clock_seq_hi_and_reserved);
80 uuid->clock_seq_low = (u8)ntohl(xdr->clock_seq_low);
81 for (j = 0; j < 6; j++)
82 uuid->node[j] = (u8)ntohl(xdr->node[j]);
1da177e4 83
d2ddc776
DH
84 entry->nr_servers++;
85 }
1da177e4 86
d2ddc776
DH
87 for (i = 0; i < AFS_MAXTYPES; i++)
88 entry->vid[i] = ntohl(uvldb->volumeId[i]);
1da177e4 89
1fba5868 90 if (vlflags & AFS_VLF_RWEXISTS)
d2ddc776 91 __set_bit(AFS_VLDB_HAS_RW, &entry->flags);
1fba5868 92 if (vlflags & AFS_VLF_ROEXISTS)
d2ddc776 93 __set_bit(AFS_VLDB_HAS_RO, &entry->flags);
1fba5868 94 if (vlflags & AFS_VLF_BACKEXISTS)
d2ddc776 95 __set_bit(AFS_VLDB_HAS_BAK, &entry->flags);
08e0e7c8 96
1fba5868 97 if (!(vlflags & (AFS_VLF_RWEXISTS | AFS_VLF_ROEXISTS | AFS_VLF_BACKEXISTS))) {
d2ddc776
DH
98 entry->error = -ENOMEDIUM;
99 __set_bit(AFS_VLDB_QUERY_ERROR, &entry->flags);
100 }
101
102 __set_bit(AFS_VLDB_QUERY_VALID, &entry->flags);
08e0e7c8
DH
103 _leave(" = 0 [done]");
104 return 0;
ec26815a 105}
1da177e4 106
d2ddc776
DH
107static void afs_destroy_vl_get_entry_by_name_u(struct afs_call *call)
108{
ffba718e 109 kfree(call->ret_vldb);
d2ddc776
DH
110 afs_flat_call_destructor(call);
111}
1da177e4 112
08e0e7c8 113/*
d2ddc776 114 * VL.GetEntryByNameU operation type.
08e0e7c8 115 */
d2ddc776
DH
116static const struct afs_call_type afs_RXVLGetEntryByNameU = {
117 .name = "VL.GetEntryByNameU",
025db80c 118 .op = afs_VL_GetEntryByNameU,
d2ddc776
DH
119 .deliver = afs_deliver_vl_get_entry_by_name_u,
120 .destructor = afs_destroy_vl_get_entry_by_name_u,
08e0e7c8 121};
1da177e4 122
1da177e4 123/*
d2ddc776
DH
124 * Dispatch a get volume entry by name or ID operation (uuid variant). If the
125 * volname is a decimal number then it's a volume ID not a volume name.
1da177e4 126 */
0a5143f2 127struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *vc,
d2ddc776
DH
128 const char *volname,
129 int volnamesz)
1da177e4 130{
d2ddc776 131 struct afs_vldb_entry *entry;
08e0e7c8 132 struct afs_call *call;
0a5143f2 133 struct afs_net *net = vc->cell->net;
d2ddc776 134 size_t reqsz, padsz;
08e0e7c8 135 __be32 *bp;
1da177e4 136
08e0e7c8 137 _enter("");
1da177e4 138
08e0e7c8
DH
139 padsz = (4 - (volnamesz & 3)) & 3;
140 reqsz = 8 + volnamesz + padsz;
1da177e4 141
d2ddc776
DH
142 entry = kzalloc(sizeof(struct afs_vldb_entry), GFP_KERNEL);
143 if (!entry)
144 return ERR_PTR(-ENOMEM);
145
146 call = afs_alloc_flat_call(net, &afs_RXVLGetEntryByNameU, reqsz,
147 sizeof(struct afs_uvldbentry__xdr));
148 if (!call) {
149 kfree(entry);
150 return ERR_PTR(-ENOMEM);
151 }
1da177e4 152
0a5143f2 153 call->key = vc->key;
ffba718e 154 call->ret_vldb = entry;
94f699c9 155 call->max_lifespan = AFS_VL_MAX_LIFESPAN;
1da177e4 156
d2ddc776 157 /* Marshall the parameters */
08e0e7c8 158 bp = call->request;
d2ddc776 159 *bp++ = htonl(VLGETENTRYBYNAMEU);
08e0e7c8
DH
160 *bp++ = htonl(volnamesz);
161 memcpy(bp, volname, volnamesz);
162 if (padsz > 0)
d2ddc776 163 memset((void *)bp + volnamesz, 0, padsz);
08e0e7c8 164
025db80c 165 trace_afs_make_vl_call(call);
0b9bf381
DH
166 afs_make_call(&vc->ac, call, GFP_KERNEL);
167 return (struct afs_vldb_entry *)afs_wait_for_call_to_complete(call, &vc->ac);
ec26815a 168}
1da177e4 169
1da177e4 170/*
d2ddc776
DH
171 * Deliver reply data to a VL.GetAddrsU call.
172 *
173 * GetAddrsU(IN ListAddrByAttributes *inaddr,
174 * OUT afsUUID *uuidp1,
175 * OUT uint32_t *uniquifier,
176 * OUT uint32_t *nentries,
177 * OUT bulkaddrs *blkaddrs);
1da177e4 178 */
d2ddc776 179static int afs_deliver_vl_get_addrs_u(struct afs_call *call)
1da177e4 180{
d2ddc776
DH
181 struct afs_addr_list *alist;
182 __be32 *bp;
183 u32 uniquifier, nentries, count;
184 int i, ret;
185
12bdcf33
DH
186 _enter("{%u,%zu/%u}",
187 call->unmarshall, iov_iter_count(call->_iter), call->count);
d2ddc776 188
d2ddc776
DH
189 switch (call->unmarshall) {
190 case 0:
12bdcf33
DH
191 afs_extract_to_buf(call,
192 sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
d2ddc776
DH
193 call->unmarshall++;
194
e690c9e3
GS
195 /* Extract the returned uuid, uniquifier, nentries and
196 * blkaddrs size */
197 /* Fall through */
d2ddc776 198 case 1:
12bdcf33 199 ret = afs_extract_data(call, true);
d2ddc776
DH
200 if (ret < 0)
201 return ret;
202
203 bp = call->buffer + sizeof(struct afs_uuid__xdr);
204 uniquifier = ntohl(*bp++);
205 nentries = ntohl(*bp++);
206 count = ntohl(*bp);
207
208 nentries = min(nentries, count);
209 alist = afs_alloc_addrlist(nentries, FS_SERVICE, AFS_FS_PORT);
210 if (!alist)
211 return -ENOMEM;
212 alist->version = uniquifier;
ffba718e 213 call->ret_alist = alist;
d2ddc776
DH
214 call->count = count;
215 call->count2 = nentries;
d2ddc776
DH
216 call->unmarshall++;
217
12bdcf33
DH
218 more_entries:
219 count = min(call->count, 4U);
220 afs_extract_to_buf(call, count * sizeof(__be32));
221
e690c9e3 222 /* Fall through - and extract entries */
d2ddc776 223 case 2:
12bdcf33 224 ret = afs_extract_data(call, call->count > 4);
d2ddc776
DH
225 if (ret < 0)
226 return ret;
227
ffba718e 228 alist = call->ret_alist;
d2ddc776 229 bp = call->buffer;
12bdcf33 230 count = min(call->count, 4U);
d2ddc776
DH
231 for (i = 0; i < count; i++)
232 if (alist->nr_addrs < call->count2)
bf99a53c 233 afs_merge_fs_addr4(alist, *bp++, AFS_FS_PORT);
d2ddc776
DH
234
235 call->count -= count;
236 if (call->count > 0)
12bdcf33 237 goto more_entries;
d2ddc776
DH
238 call->unmarshall++;
239 break;
240 }
241
242 _leave(" = 0 [done]");
243 return 0;
244}
245
246static void afs_vl_get_addrs_u_destructor(struct afs_call *call)
247{
ffba718e 248 afs_put_addrlist(call->ret_alist);
d2ddc776
DH
249 return afs_flat_call_destructor(call);
250}
251
252/*
253 * VL.GetAddrsU operation type.
254 */
255static const struct afs_call_type afs_RXVLGetAddrsU = {
256 .name = "VL.GetAddrsU",
025db80c 257 .op = afs_VL_GetAddrsU,
d2ddc776
DH
258 .deliver = afs_deliver_vl_get_addrs_u,
259 .destructor = afs_vl_get_addrs_u_destructor,
260};
261
262/*
263 * Dispatch an operation to get the addresses for a server, where the server is
264 * nominated by UUID.
265 */
0a5143f2 266struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *vc,
d2ddc776
DH
267 const uuid_t *uuid)
268{
269 struct afs_ListAddrByAttributes__xdr *r;
270 const struct afs_uuid *u = (const struct afs_uuid *)uuid;
08e0e7c8 271 struct afs_call *call;
0a5143f2 272 struct afs_net *net = vc->cell->net;
1da177e4 273 __be32 *bp;
d2ddc776 274 int i;
1da177e4 275
08e0e7c8 276 _enter("");
1da177e4 277
d2ddc776
DH
278 call = afs_alloc_flat_call(net, &afs_RXVLGetAddrsU,
279 sizeof(__be32) + sizeof(struct afs_ListAddrByAttributes__xdr),
280 sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
08e0e7c8 281 if (!call)
d2ddc776 282 return ERR_PTR(-ENOMEM);
1da177e4 283
0a5143f2 284 call->key = vc->key;
ffba718e 285 call->ret_alist = NULL;
94f699c9 286 call->max_lifespan = AFS_VL_MAX_LIFESPAN;
1da177e4 287
d2ddc776 288 /* Marshall the parameters */
08e0e7c8 289 bp = call->request;
d2ddc776
DH
290 *bp++ = htonl(VLGETADDRSU);
291 r = (struct afs_ListAddrByAttributes__xdr *)bp;
292 r->Mask = htonl(AFS_VLADDR_UUID);
293 r->ipaddr = 0;
294 r->index = 0;
295 r->spare = 0;
296 r->uuid.time_low = u->time_low;
297 r->uuid.time_mid = htonl(ntohs(u->time_mid));
298 r->uuid.time_hi_and_version = htonl(ntohs(u->time_hi_and_version));
299 r->uuid.clock_seq_hi_and_reserved = htonl(u->clock_seq_hi_and_reserved);
300 r->uuid.clock_seq_low = htonl(u->clock_seq_low);
301 for (i = 0; i < 6; i++)
fe342cf7 302 r->uuid.node[i] = htonl(u->node[i]);
1da177e4 303
025db80c 304 trace_afs_make_vl_call(call);
0b9bf381
DH
305 afs_make_call(&vc->ac, call, GFP_KERNEL);
306 return (struct afs_addr_list *)afs_wait_for_call_to_complete(call, &vc->ac);
ec26815a 307}
bf99a53c
DH
308
309/*
310 * Deliver reply data to an VL.GetCapabilities operation.
311 */
312static int afs_deliver_vl_get_capabilities(struct afs_call *call)
313{
314 u32 count;
315 int ret;
316
12bdcf33
DH
317 _enter("{%u,%zu/%u}",
318 call->unmarshall, iov_iter_count(call->_iter), call->count);
bf99a53c 319
bf99a53c
DH
320 switch (call->unmarshall) {
321 case 0:
12bdcf33 322 afs_extract_to_tmp(call);
bf99a53c
DH
323 call->unmarshall++;
324
e690c9e3 325 /* Fall through - and extract the capabilities word count */
bf99a53c 326 case 1:
12bdcf33 327 ret = afs_extract_data(call, true);
bf99a53c
DH
328 if (ret < 0)
329 return ret;
330
331 count = ntohl(call->tmp);
bf99a53c
DH
332 call->count = count;
333 call->count2 = count;
12bdcf33 334
bf99a53c 335 call->unmarshall++;
12bdcf33 336 afs_extract_discard(call, count * sizeof(__be32));
bf99a53c 337
e690c9e3 338 /* Fall through - and extract capabilities words */
bf99a53c 339 case 2:
12bdcf33 340 ret = afs_extract_data(call, false);
bf99a53c
DH
341 if (ret < 0)
342 return ret;
343
344 /* TODO: Examine capabilities */
345
bf99a53c
DH
346 call->unmarshall++;
347 break;
348 }
349
bf99a53c
DH
350 _leave(" = 0 [done]");
351 return 0;
352}
353
3bf0fb6f
DH
354static void afs_destroy_vl_get_capabilities(struct afs_call *call)
355{
ffba718e 356 afs_put_vlserver(call->net, call->vlserver);
3bf0fb6f
DH
357 afs_flat_call_destructor(call);
358}
359
bf99a53c
DH
360/*
361 * VL.GetCapabilities operation type
362 */
363static const struct afs_call_type afs_RXVLGetCapabilities = {
364 .name = "VL.GetCapabilities",
025db80c 365 .op = afs_VL_GetCapabilities,
bf99a53c 366 .deliver = afs_deliver_vl_get_capabilities,
3bf0fb6f
DH
367 .done = afs_vlserver_probe_result,
368 .destructor = afs_destroy_vl_get_capabilities,
bf99a53c
DH
369};
370
371/*
0a5143f2 372 * Probe a volume server for the capabilities that it supports. This can
bf99a53c
DH
373 * return up to 196 words.
374 *
375 * We use this to probe for service upgrade to determine what the server at the
376 * other end supports.
377 */
0b9bf381
DH
378struct afs_call *afs_vl_get_capabilities(struct afs_net *net,
379 struct afs_addr_cursor *ac,
380 struct key *key,
381 struct afs_vlserver *server,
382 unsigned int server_index)
bf99a53c
DH
383{
384 struct afs_call *call;
385 __be32 *bp;
386
387 _enter("");
388
389 call = afs_alloc_flat_call(net, &afs_RXVLGetCapabilities, 1 * 4, 16 * 4);
390 if (!call)
0b9bf381 391 return ERR_PTR(-ENOMEM);
bf99a53c
DH
392
393 call->key = key;
ffba718e
DH
394 call->vlserver = afs_get_vlserver(server);
395 call->server_index = server_index;
3bf0fb6f 396 call->upgrade = true;
0b9bf381 397 call->async = true;
94f699c9 398 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
bf99a53c
DH
399
400 /* marshall the parameters */
401 bp = call->request;
402 *bp++ = htonl(VLGETCAPABILITIES);
403
404 /* Can't take a ref on server */
025db80c 405 trace_afs_make_vl_call(call);
0b9bf381
DH
406 afs_make_call(ac, call, GFP_KERNEL);
407 return call;
bf99a53c
DH
408}
409
410/*
411 * Deliver reply data to a YFSVL.GetEndpoints call.
412 *
413 * GetEndpoints(IN yfsServerAttributes *attr,
414 * OUT opr_uuid *uuid,
415 * OUT afs_int32 *uniquifier,
416 * OUT endpoints *fsEndpoints,
417 * OUT endpoints *volEndpoints)
418 */
419static int afs_deliver_yfsvl_get_endpoints(struct afs_call *call)
420{
421 struct afs_addr_list *alist;
422 __be32 *bp;
423 u32 uniquifier, size;
424 int ret;
425
12bdcf33
DH
426 _enter("{%u,%zu,%u}",
427 call->unmarshall, iov_iter_count(call->_iter), call->count2);
bf99a53c 428
bf99a53c
DH
429 switch (call->unmarshall) {
430 case 0:
12bdcf33 431 afs_extract_to_buf(call, sizeof(uuid_t) + 3 * sizeof(__be32));
bf99a53c
DH
432 call->unmarshall = 1;
433
434 /* Extract the returned uuid, uniquifier, fsEndpoints count and
435 * either the first fsEndpoint type or the volEndpoints
436 * count if there are no fsEndpoints. */
e690c9e3 437 /* Fall through */
bf99a53c 438 case 1:
12bdcf33 439 ret = afs_extract_data(call, true);
bf99a53c
DH
440 if (ret < 0)
441 return ret;
442
443 bp = call->buffer + sizeof(uuid_t);
444 uniquifier = ntohl(*bp++);
445 call->count = ntohl(*bp++);
446 call->count2 = ntohl(*bp); /* Type or next count */
447
448 if (call->count > YFS_MAXENDPOINTS)
160cb957
DH
449 return afs_protocol_error(call, -EBADMSG,
450 afs_eproto_yvl_fsendpt_num);
bf99a53c
DH
451
452 alist = afs_alloc_addrlist(call->count, FS_SERVICE, AFS_FS_PORT);
453 if (!alist)
454 return -ENOMEM;
455 alist->version = uniquifier;
ffba718e 456 call->ret_alist = alist;
bf99a53c
DH
457
458 if (call->count == 0)
459 goto extract_volendpoints;
460
12bdcf33 461 next_fsendpoint:
bf99a53c
DH
462 switch (call->count2) {
463 case YFS_ENDPOINT_IPV4:
464 size = sizeof(__be32) * (1 + 1 + 1);
465 break;
466 case YFS_ENDPOINT_IPV6:
467 size = sizeof(__be32) * (1 + 4 + 1);
468 break;
469 default:
160cb957
DH
470 return afs_protocol_error(call, -EBADMSG,
471 afs_eproto_yvl_fsendpt_type);
bf99a53c
DH
472 }
473
474 size += sizeof(__be32);
12bdcf33
DH
475 afs_extract_to_buf(call, size);
476 call->unmarshall = 2;
477
e690c9e3 478 /* Fall through - and extract fsEndpoints[] entries */
12bdcf33
DH
479 case 2:
480 ret = afs_extract_data(call, true);
bf99a53c
DH
481 if (ret < 0)
482 return ret;
483
ffba718e 484 alist = call->ret_alist;
bf99a53c
DH
485 bp = call->buffer;
486 switch (call->count2) {
487 case YFS_ENDPOINT_IPV4:
488 if (ntohl(bp[0]) != sizeof(__be32) * 2)
160cb957
DH
489 return afs_protocol_error(call, -EBADMSG,
490 afs_eproto_yvl_fsendpt4_len);
bf99a53c
DH
491 afs_merge_fs_addr4(alist, bp[1], ntohl(bp[2]));
492 bp += 3;
493 break;
494 case YFS_ENDPOINT_IPV6:
495 if (ntohl(bp[0]) != sizeof(__be32) * 5)
160cb957
DH
496 return afs_protocol_error(call, -EBADMSG,
497 afs_eproto_yvl_fsendpt6_len);
bf99a53c
DH
498 afs_merge_fs_addr6(alist, bp + 1, ntohl(bp[5]));
499 bp += 6;
500 break;
501 default:
160cb957
DH
502 return afs_protocol_error(call, -EBADMSG,
503 afs_eproto_yvl_fsendpt_type);
bf99a53c
DH
504 }
505
506 /* Got either the type of the next entry or the count of
507 * volEndpoints if no more fsEndpoints.
508 */
fe342cf7 509 call->count2 = ntohl(*bp++);
bf99a53c 510
bf99a53c
DH
511 call->count--;
512 if (call->count > 0)
12bdcf33 513 goto next_fsendpoint;
bf99a53c
DH
514
515 extract_volendpoints:
516 /* Extract the list of volEndpoints. */
517 call->count = call->count2;
518 if (!call->count)
519 goto end;
520 if (call->count > YFS_MAXENDPOINTS)
160cb957
DH
521 return afs_protocol_error(call, -EBADMSG,
522 afs_eproto_yvl_vlendpt_type);
bf99a53c 523
12bdcf33 524 afs_extract_to_buf(call, 1 * sizeof(__be32));
bf99a53c
DH
525 call->unmarshall = 3;
526
527 /* Extract the type of volEndpoints[0]. Normally we would
528 * extract the type of the next endpoint when we extract the
529 * data of the current one, but this is the first...
530 */
e690c9e3 531 /* Fall through */
bf99a53c 532 case 3:
12bdcf33 533 ret = afs_extract_data(call, true);
bf99a53c
DH
534 if (ret < 0)
535 return ret;
536
537 bp = call->buffer;
bf99a53c 538
12bdcf33
DH
539 next_volendpoint:
540 call->count2 = ntohl(*bp++);
bf99a53c
DH
541 switch (call->count2) {
542 case YFS_ENDPOINT_IPV4:
543 size = sizeof(__be32) * (1 + 1 + 1);
544 break;
545 case YFS_ENDPOINT_IPV6:
546 size = sizeof(__be32) * (1 + 4 + 1);
547 break;
548 default:
160cb957
DH
549 return afs_protocol_error(call, -EBADMSG,
550 afs_eproto_yvl_vlendpt_type);
bf99a53c
DH
551 }
552
553 if (call->count > 1)
12bdcf33
DH
554 size += sizeof(__be32); /* Get next type too */
555 afs_extract_to_buf(call, size);
556 call->unmarshall = 4;
557
e690c9e3 558 /* Fall through - and extract volEndpoints[] entries */
12bdcf33
DH
559 case 4:
560 ret = afs_extract_data(call, true);
bf99a53c
DH
561 if (ret < 0)
562 return ret;
563
564 bp = call->buffer;
565 switch (call->count2) {
566 case YFS_ENDPOINT_IPV4:
567 if (ntohl(bp[0]) != sizeof(__be32) * 2)
160cb957
DH
568 return afs_protocol_error(call, -EBADMSG,
569 afs_eproto_yvl_vlendpt4_len);
bf99a53c
DH
570 bp += 3;
571 break;
572 case YFS_ENDPOINT_IPV6:
573 if (ntohl(bp[0]) != sizeof(__be32) * 5)
160cb957
DH
574 return afs_protocol_error(call, -EBADMSG,
575 afs_eproto_yvl_vlendpt6_len);
bf99a53c
DH
576 bp += 6;
577 break;
578 default:
160cb957
DH
579 return afs_protocol_error(call, -EBADMSG,
580 afs_eproto_yvl_vlendpt_type);
bf99a53c
DH
581 }
582
583 /* Got either the type of the next entry or the count of
584 * volEndpoints if no more fsEndpoints.
585 */
bf99a53c 586 call->count--;
12bdcf33
DH
587 if (call->count > 0)
588 goto next_volendpoint;
bf99a53c
DH
589
590 end:
12bdcf33 591 afs_extract_discard(call, 0);
bf99a53c
DH
592 call->unmarshall = 5;
593
e690c9e3 594 /* Fall through - Done */
bf99a53c 595 case 5:
12bdcf33 596 ret = afs_extract_data(call, false);
bf99a53c
DH
597 if (ret < 0)
598 return ret;
599 call->unmarshall = 6;
600
601 case 6:
602 break;
603 }
604
bf99a53c
DH
605 _leave(" = 0 [done]");
606 return 0;
607}
608
609/*
610 * YFSVL.GetEndpoints operation type.
611 */
612static const struct afs_call_type afs_YFSVLGetEndpoints = {
025db80c
DH
613 .name = "YFSVL.GetEndpoints",
614 .op = afs_YFSVL_GetEndpoints,
bf99a53c
DH
615 .deliver = afs_deliver_yfsvl_get_endpoints,
616 .destructor = afs_vl_get_addrs_u_destructor,
617};
618
619/*
620 * Dispatch an operation to get the addresses for a server, where the server is
621 * nominated by UUID.
622 */
0a5143f2 623struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *vc,
bf99a53c
DH
624 const uuid_t *uuid)
625{
626 struct afs_call *call;
0a5143f2 627 struct afs_net *net = vc->cell->net;
bf99a53c
DH
628 __be32 *bp;
629
630 _enter("");
631
632 call = afs_alloc_flat_call(net, &afs_YFSVLGetEndpoints,
633 sizeof(__be32) * 2 + sizeof(*uuid),
634 sizeof(struct in6_addr) + sizeof(__be32) * 3);
635 if (!call)
636 return ERR_PTR(-ENOMEM);
637
0a5143f2 638 call->key = vc->key;
ffba718e 639 call->ret_alist = NULL;
94f699c9 640 call->max_lifespan = AFS_VL_MAX_LIFESPAN;
bf99a53c
DH
641
642 /* Marshall the parameters */
643 bp = call->request;
644 *bp++ = htonl(YVLGETENDPOINTS);
645 *bp++ = htonl(YFS_SERVER_UUID);
646 memcpy(bp, uuid, sizeof(*uuid)); /* Type opr_uuid */
647
025db80c 648 trace_afs_make_vl_call(call);
0b9bf381
DH
649 afs_make_call(&vc->ac, call, GFP_KERNEL);
650 return (struct afs_addr_list *)afs_wait_for_call_to_complete(call, &vc->ac);
bf99a53c 651}