GNU Linux-libre 6.7.9-gnu
[releases.git] / fs / afs / vlclient.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* AFS Volume Location Service client
3  *
4  * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
5  * Written by David Howells (dhowells@redhat.com)
6  */
7
8 #include <linux/gfp.h>
9 #include <linux/init.h>
10 #include <linux/sched.h>
11 #include "afs_fs.h"
12 #include "internal.h"
13
14 /*
15  * Deliver reply data to a VL.GetEntryByNameU call.
16  */
17 static int afs_deliver_vl_get_entry_by_name_u(struct afs_call *call)
18 {
19         struct afs_uvldbentry__xdr *uvldb;
20         struct afs_vldb_entry *entry;
21         bool new_only = false;
22         u32 tmp, nr_servers, vlflags;
23         int i, ret;
24
25         _enter("");
26
27         ret = afs_transfer_reply(call);
28         if (ret < 0)
29                 return ret;
30
31         /* unmarshall the reply once we've received all of it */
32         uvldb = call->buffer;
33         entry = call->ret_vldb;
34
35         nr_servers = ntohl(uvldb->nServers);
36         if (nr_servers > AFS_NMAXNSERVERS)
37                 nr_servers = AFS_NMAXNSERVERS;
38
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          */
47         for (i = 0; i < nr_servers; i++) {
48                 tmp = ntohl(uvldb->serverFlags[i]);
49                 if (!(tmp & AFS_VLSF_DONTUSE) &&
50                     (tmp & AFS_VLSF_NEWREPSITE))
51                         new_only = true;
52         }
53
54         vlflags = ntohl(uvldb->flags);
55         for (i = 0; i < nr_servers; i++) {
56                 struct afs_uuid__xdr *xdr;
57                 struct afs_uuid *uuid;
58                 int j;
59                 int n = entry->nr_servers;
60
61                 tmp = ntohl(uvldb->serverFlags[i]);
62                 if (tmp & AFS_VLSF_DONTUSE ||
63                     (new_only && !(tmp & AFS_VLSF_NEWREPSITE)))
64                         continue;
65                 if (tmp & AFS_VLSF_RWVOL) {
66                         entry->fs_mask[n] |= AFS_VOL_VTM_RW;
67                         if (vlflags & AFS_VLF_BACKEXISTS)
68                                 entry->fs_mask[n] |= AFS_VOL_VTM_BAK;
69                 }
70                 if (tmp & AFS_VLSF_ROVOL)
71                         entry->fs_mask[n] |= AFS_VOL_VTM_RO;
72                 if (!entry->fs_mask[n])
73                         continue;
74
75                 xdr = &uvldb->serverNumber[i];
76                 uuid = (struct afs_uuid *)&entry->fs_server[n];
77                 uuid->time_low                  = xdr->time_low;
78                 uuid->time_mid                  = htons(ntohl(xdr->time_mid));
79                 uuid->time_hi_and_version       = htons(ntohl(xdr->time_hi_and_version));
80                 uuid->clock_seq_hi_and_reserved = (u8)ntohl(xdr->clock_seq_hi_and_reserved);
81                 uuid->clock_seq_low             = (u8)ntohl(xdr->clock_seq_low);
82                 for (j = 0; j < 6; j++)
83                         uuid->node[j] = (u8)ntohl(xdr->node[j]);
84
85                 entry->addr_version[n] = ntohl(uvldb->serverUnique[i]);
86                 entry->nr_servers++;
87         }
88
89         for (i = 0; i < AFS_MAXTYPES; i++)
90                 entry->vid[i] = ntohl(uvldb->volumeId[i]);
91
92         if (vlflags & AFS_VLF_RWEXISTS)
93                 __set_bit(AFS_VLDB_HAS_RW, &entry->flags);
94         if (vlflags & AFS_VLF_ROEXISTS)
95                 __set_bit(AFS_VLDB_HAS_RO, &entry->flags);
96         if (vlflags & AFS_VLF_BACKEXISTS)
97                 __set_bit(AFS_VLDB_HAS_BAK, &entry->flags);
98
99         if (!(vlflags & (AFS_VLF_RWEXISTS | AFS_VLF_ROEXISTS | AFS_VLF_BACKEXISTS))) {
100                 entry->error = -ENOMEDIUM;
101                 __set_bit(AFS_VLDB_QUERY_ERROR, &entry->flags);
102         }
103
104         __set_bit(AFS_VLDB_QUERY_VALID, &entry->flags);
105         _leave(" = 0 [done]");
106         return 0;
107 }
108
109 /*
110  * VL.GetEntryByNameU operation type.
111  */
112 static const struct afs_call_type afs_RXVLGetEntryByNameU = {
113         .name           = "VL.GetEntryByNameU",
114         .op             = afs_VL_GetEntryByNameU,
115         .deliver        = afs_deliver_vl_get_entry_by_name_u,
116         .destructor     = afs_flat_call_destructor,
117 };
118
119 /*
120  * Dispatch a get volume entry by name or ID operation (uuid variant).  If the
121  * volname is a decimal number then it's a volume ID not a volume name.
122  */
123 struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *vc,
124                                                   const char *volname,
125                                                   int volnamesz)
126 {
127         struct afs_vldb_entry *entry;
128         struct afs_call *call;
129         struct afs_net *net = vc->cell->net;
130         size_t reqsz, padsz;
131         __be32 *bp;
132
133         _enter("");
134
135         padsz = (4 - (volnamesz & 3)) & 3;
136         reqsz = 8 + volnamesz + padsz;
137
138         entry = kzalloc(sizeof(struct afs_vldb_entry), GFP_KERNEL);
139         if (!entry)
140                 return ERR_PTR(-ENOMEM);
141
142         call = afs_alloc_flat_call(net, &afs_RXVLGetEntryByNameU, reqsz,
143                                    sizeof(struct afs_uvldbentry__xdr));
144         if (!call) {
145                 kfree(entry);
146                 return ERR_PTR(-ENOMEM);
147         }
148
149         call->key = vc->key;
150         call->ret_vldb = entry;
151         call->max_lifespan = AFS_VL_MAX_LIFESPAN;
152
153         /* Marshall the parameters */
154         bp = call->request;
155         *bp++ = htonl(VLGETENTRYBYNAMEU);
156         *bp++ = htonl(volnamesz);
157         memcpy(bp, volname, volnamesz);
158         if (padsz > 0)
159                 memset((void *)bp + volnamesz, 0, padsz);
160
161         trace_afs_make_vl_call(call);
162         afs_make_call(&vc->ac, call, GFP_KERNEL);
163         afs_wait_for_call_to_complete(call, &vc->ac);
164         vc->call_abort_code     = call->abort_code;
165         vc->call_error          = call->error;
166         vc->call_responded      = call->responded;
167         afs_put_call(call);
168         if (vc->call_error) {
169                 kfree(entry);
170                 return ERR_PTR(vc->call_error);
171         }
172         return entry;
173 }
174
175 /*
176  * Deliver reply data to a VL.GetAddrsU call.
177  *
178  *      GetAddrsU(IN ListAddrByAttributes *inaddr,
179  *                OUT afsUUID *uuidp1,
180  *                OUT uint32_t *uniquifier,
181  *                OUT uint32_t *nentries,
182  *                OUT bulkaddrs *blkaddrs);
183  */
184 static int afs_deliver_vl_get_addrs_u(struct afs_call *call)
185 {
186         struct afs_addr_list *alist;
187         __be32 *bp;
188         u32 uniquifier, nentries, count;
189         int i, ret;
190
191         _enter("{%u,%zu/%u}",
192                call->unmarshall, iov_iter_count(call->iter), call->count);
193
194         switch (call->unmarshall) {
195         case 0:
196                 afs_extract_to_buf(call,
197                                    sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
198                 call->unmarshall++;
199
200                 /* Extract the returned uuid, uniquifier, nentries and
201                  * blkaddrs size */
202                 fallthrough;
203         case 1:
204                 ret = afs_extract_data(call, true);
205                 if (ret < 0)
206                         return ret;
207
208                 bp = call->buffer + sizeof(struct afs_uuid__xdr);
209                 uniquifier      = ntohl(*bp++);
210                 nentries        = ntohl(*bp++);
211                 count           = ntohl(*bp);
212
213                 nentries = min(nentries, count);
214                 alist = afs_alloc_addrlist(nentries, FS_SERVICE);
215                 if (!alist)
216                         return -ENOMEM;
217                 alist->version = uniquifier;
218                 call->ret_alist = alist;
219                 call->count = count;
220                 call->count2 = nentries;
221                 call->unmarshall++;
222
223         more_entries:
224                 count = min(call->count, 4U);
225                 afs_extract_to_buf(call, count * sizeof(__be32));
226
227                 fallthrough;    /* and extract entries */
228         case 2:
229                 ret = afs_extract_data(call, call->count > 4);
230                 if (ret < 0)
231                         return ret;
232
233                 alist = call->ret_alist;
234                 bp = call->buffer;
235                 count = min(call->count, 4U);
236                 for (i = 0; i < count; i++) {
237                         if (alist->nr_addrs < call->count2) {
238                                 ret = afs_merge_fs_addr4(call->net, alist, *bp++, AFS_FS_PORT);
239                                 if (ret < 0)
240                                         return ret;
241                         }
242                 }
243
244                 call->count -= count;
245                 if (call->count > 0)
246                         goto more_entries;
247                 call->unmarshall++;
248                 break;
249         }
250
251         _leave(" = 0 [done]");
252         return 0;
253 }
254
255 /*
256  * VL.GetAddrsU operation type.
257  */
258 static const struct afs_call_type afs_RXVLGetAddrsU = {
259         .name           = "VL.GetAddrsU",
260         .op             = afs_VL_GetAddrsU,
261         .deliver        = afs_deliver_vl_get_addrs_u,
262         .destructor     = afs_flat_call_destructor,
263 };
264
265 /*
266  * Dispatch an operation to get the addresses for a server, where the server is
267  * nominated by UUID.
268  */
269 struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *vc,
270                                          const uuid_t *uuid)
271 {
272         struct afs_ListAddrByAttributes__xdr *r;
273         struct afs_addr_list *alist;
274         const struct afs_uuid *u = (const struct afs_uuid *)uuid;
275         struct afs_call *call;
276         struct afs_net *net = vc->cell->net;
277         __be32 *bp;
278         int i;
279
280         _enter("");
281
282         call = afs_alloc_flat_call(net, &afs_RXVLGetAddrsU,
283                                    sizeof(__be32) + sizeof(struct afs_ListAddrByAttributes__xdr),
284                                    sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
285         if (!call)
286                 return ERR_PTR(-ENOMEM);
287
288         call->key = vc->key;
289         call->ret_alist = NULL;
290         call->max_lifespan = AFS_VL_MAX_LIFESPAN;
291
292         /* Marshall the parameters */
293         bp = call->request;
294         *bp++ = htonl(VLGETADDRSU);
295         r = (struct afs_ListAddrByAttributes__xdr *)bp;
296         r->Mask         = htonl(AFS_VLADDR_UUID);
297         r->ipaddr       = 0;
298         r->index        = 0;
299         r->spare        = 0;
300         r->uuid.time_low                        = u->time_low;
301         r->uuid.time_mid                        = htonl(ntohs(u->time_mid));
302         r->uuid.time_hi_and_version             = htonl(ntohs(u->time_hi_and_version));
303         r->uuid.clock_seq_hi_and_reserved       = htonl(u->clock_seq_hi_and_reserved);
304         r->uuid.clock_seq_low                   = htonl(u->clock_seq_low);
305         for (i = 0; i < 6; i++)
306                 r->uuid.node[i] = htonl(u->node[i]);
307
308         trace_afs_make_vl_call(call);
309         afs_make_call(&vc->ac, call, GFP_KERNEL);
310         afs_wait_for_call_to_complete(call, &vc->ac);
311         vc->call_abort_code     = call->abort_code;
312         vc->call_error          = call->error;
313         vc->call_responded      = call->responded;
314         alist                   = call->ret_alist;
315         afs_put_call(call);
316         if (vc->call_error) {
317                 afs_put_addrlist(alist);
318                 return ERR_PTR(vc->call_error);
319         }
320         return alist;
321 }
322
323 /*
324  * Deliver reply data to an VL.GetCapabilities operation.
325  */
326 static int afs_deliver_vl_get_capabilities(struct afs_call *call)
327 {
328         u32 count;
329         int ret;
330
331         _enter("{%u,%zu/%u}",
332                call->unmarshall, iov_iter_count(call->iter), call->count);
333
334         switch (call->unmarshall) {
335         case 0:
336                 afs_extract_to_tmp(call);
337                 call->unmarshall++;
338
339                 fallthrough;    /* and extract the capabilities word count */
340         case 1:
341                 ret = afs_extract_data(call, true);
342                 if (ret < 0)
343                         return ret;
344
345                 count = ntohl(call->tmp);
346                 call->count = count;
347                 call->count2 = count;
348
349                 call->unmarshall++;
350                 afs_extract_discard(call, count * sizeof(__be32));
351
352                 fallthrough;    /* and extract capabilities words */
353         case 2:
354                 ret = afs_extract_data(call, false);
355                 if (ret < 0)
356                         return ret;
357
358                 /* TODO: Examine capabilities */
359
360                 call->unmarshall++;
361                 break;
362         }
363
364         _leave(" = 0 [done]");
365         return 0;
366 }
367
368 static void afs_destroy_vl_get_capabilities(struct afs_call *call)
369 {
370         afs_put_vlserver(call->net, call->vlserver);
371         afs_flat_call_destructor(call);
372 }
373
374 /*
375  * VL.GetCapabilities operation type
376  */
377 static const struct afs_call_type afs_RXVLGetCapabilities = {
378         .name           = "VL.GetCapabilities",
379         .op             = afs_VL_GetCapabilities,
380         .deliver        = afs_deliver_vl_get_capabilities,
381         .done           = afs_vlserver_probe_result,
382         .destructor     = afs_destroy_vl_get_capabilities,
383 };
384
385 /*
386  * Probe a volume server for the capabilities that it supports.  This can
387  * return up to 196 words.
388  *
389  * We use this to probe for service upgrade to determine what the server at the
390  * other end supports.
391  */
392 struct afs_call *afs_vl_get_capabilities(struct afs_net *net,
393                                          struct afs_addr_cursor *ac,
394                                          struct key *key,
395                                          struct afs_vlserver *server,
396                                          unsigned int server_index)
397 {
398         struct afs_call *call;
399         __be32 *bp;
400
401         _enter("");
402
403         call = afs_alloc_flat_call(net, &afs_RXVLGetCapabilities, 1 * 4, 16 * 4);
404         if (!call)
405                 return ERR_PTR(-ENOMEM);
406
407         call->key = key;
408         call->vlserver = afs_get_vlserver(server);
409         call->server_index = server_index;
410         call->upgrade = true;
411         call->async = true;
412         call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
413
414         /* marshall the parameters */
415         bp = call->request;
416         *bp++ = htonl(VLGETCAPABILITIES);
417
418         /* Can't take a ref on server */
419         trace_afs_make_vl_call(call);
420         afs_make_call(ac, call, GFP_KERNEL);
421         return call;
422 }
423
424 /*
425  * Deliver reply data to a YFSVL.GetEndpoints call.
426  *
427  *      GetEndpoints(IN yfsServerAttributes *attr,
428  *                   OUT opr_uuid *uuid,
429  *                   OUT afs_int32 *uniquifier,
430  *                   OUT endpoints *fsEndpoints,
431  *                   OUT endpoints *volEndpoints)
432  */
433 static int afs_deliver_yfsvl_get_endpoints(struct afs_call *call)
434 {
435         struct afs_addr_list *alist;
436         __be32 *bp;
437         u32 uniquifier, size;
438         int ret;
439
440         _enter("{%u,%zu,%u}",
441                call->unmarshall, iov_iter_count(call->iter), call->count2);
442
443         switch (call->unmarshall) {
444         case 0:
445                 afs_extract_to_buf(call, sizeof(uuid_t) + 3 * sizeof(__be32));
446                 call->unmarshall = 1;
447
448                 /* Extract the returned uuid, uniquifier, fsEndpoints count and
449                  * either the first fsEndpoint type or the volEndpoints
450                  * count if there are no fsEndpoints. */
451                 fallthrough;
452         case 1:
453                 ret = afs_extract_data(call, true);
454                 if (ret < 0)
455                         return ret;
456
457                 bp = call->buffer + sizeof(uuid_t);
458                 uniquifier      = ntohl(*bp++);
459                 call->count     = ntohl(*bp++);
460                 call->count2    = ntohl(*bp); /* Type or next count */
461
462                 if (call->count > YFS_MAXENDPOINTS)
463                         return afs_protocol_error(call, afs_eproto_yvl_fsendpt_num);
464
465                 alist = afs_alloc_addrlist(call->count, FS_SERVICE);
466                 if (!alist)
467                         return -ENOMEM;
468                 alist->version = uniquifier;
469                 call->ret_alist = alist;
470
471                 if (call->count == 0)
472                         goto extract_volendpoints;
473
474         next_fsendpoint:
475                 switch (call->count2) {
476                 case YFS_ENDPOINT_IPV4:
477                         size = sizeof(__be32) * (1 + 1 + 1);
478                         break;
479                 case YFS_ENDPOINT_IPV6:
480                         size = sizeof(__be32) * (1 + 4 + 1);
481                         break;
482                 default:
483                         return afs_protocol_error(call, afs_eproto_yvl_fsendpt_type);
484                 }
485
486                 size += sizeof(__be32);
487                 afs_extract_to_buf(call, size);
488                 call->unmarshall = 2;
489
490                 fallthrough;    /* and extract fsEndpoints[] entries */
491         case 2:
492                 ret = afs_extract_data(call, true);
493                 if (ret < 0)
494                         return ret;
495
496                 alist = call->ret_alist;
497                 bp = call->buffer;
498                 switch (call->count2) {
499                 case YFS_ENDPOINT_IPV4:
500                         if (ntohl(bp[0]) != sizeof(__be32) * 2)
501                                 return afs_protocol_error(
502                                         call, afs_eproto_yvl_fsendpt4_len);
503                         ret = afs_merge_fs_addr4(call->net, alist, bp[1], ntohl(bp[2]));
504                         if (ret < 0)
505                                 return ret;
506                         bp += 3;
507                         break;
508                 case YFS_ENDPOINT_IPV6:
509                         if (ntohl(bp[0]) != sizeof(__be32) * 5)
510                                 return afs_protocol_error(
511                                         call, afs_eproto_yvl_fsendpt6_len);
512                         ret = afs_merge_fs_addr6(call->net, alist, bp + 1, ntohl(bp[5]));
513                         if (ret < 0)
514                                 return ret;
515                         bp += 6;
516                         break;
517                 default:
518                         return afs_protocol_error(call, afs_eproto_yvl_fsendpt_type);
519                 }
520
521                 /* Got either the type of the next entry or the count of
522                  * volEndpoints if no more fsEndpoints.
523                  */
524                 call->count2 = ntohl(*bp++);
525
526                 call->count--;
527                 if (call->count > 0)
528                         goto next_fsendpoint;
529
530         extract_volendpoints:
531                 /* Extract the list of volEndpoints. */
532                 call->count = call->count2;
533                 if (!call->count)
534                         goto end;
535                 if (call->count > YFS_MAXENDPOINTS)
536                         return afs_protocol_error(call, afs_eproto_yvl_vlendpt_type);
537
538                 afs_extract_to_buf(call, 1 * sizeof(__be32));
539                 call->unmarshall = 3;
540
541                 /* Extract the type of volEndpoints[0].  Normally we would
542                  * extract the type of the next endpoint when we extract the
543                  * data of the current one, but this is the first...
544                  */
545                 fallthrough;
546         case 3:
547                 ret = afs_extract_data(call, true);
548                 if (ret < 0)
549                         return ret;
550
551                 bp = call->buffer;
552
553         next_volendpoint:
554                 call->count2 = ntohl(*bp++);
555                 switch (call->count2) {
556                 case YFS_ENDPOINT_IPV4:
557                         size = sizeof(__be32) * (1 + 1 + 1);
558                         break;
559                 case YFS_ENDPOINT_IPV6:
560                         size = sizeof(__be32) * (1 + 4 + 1);
561                         break;
562                 default:
563                         return afs_protocol_error(call, afs_eproto_yvl_vlendpt_type);
564                 }
565
566                 if (call->count > 1)
567                         size += sizeof(__be32); /* Get next type too */
568                 afs_extract_to_buf(call, size);
569                 call->unmarshall = 4;
570
571                 fallthrough;    /* and extract volEndpoints[] entries */
572         case 4:
573                 ret = afs_extract_data(call, true);
574                 if (ret < 0)
575                         return ret;
576
577                 bp = call->buffer;
578                 switch (call->count2) {
579                 case YFS_ENDPOINT_IPV4:
580                         if (ntohl(bp[0]) != sizeof(__be32) * 2)
581                                 return afs_protocol_error(
582                                         call, afs_eproto_yvl_vlendpt4_len);
583                         bp += 3;
584                         break;
585                 case YFS_ENDPOINT_IPV6:
586                         if (ntohl(bp[0]) != sizeof(__be32) * 5)
587                                 return afs_protocol_error(
588                                         call, afs_eproto_yvl_vlendpt6_len);
589                         bp += 6;
590                         break;
591                 default:
592                         return afs_protocol_error(call, afs_eproto_yvl_vlendpt_type);
593                 }
594
595                 /* Got either the type of the next entry or the count of
596                  * volEndpoints if no more fsEndpoints.
597                  */
598                 call->count--;
599                 if (call->count > 0)
600                         goto next_volendpoint;
601
602         end:
603                 afs_extract_discard(call, 0);
604                 call->unmarshall = 5;
605
606                 fallthrough;    /* Done */
607         case 5:
608                 ret = afs_extract_data(call, false);
609                 if (ret < 0)
610                         return ret;
611                 call->unmarshall = 6;
612                 fallthrough;
613
614         case 6:
615                 break;
616         }
617
618         _leave(" = 0 [done]");
619         return 0;
620 }
621
622 /*
623  * YFSVL.GetEndpoints operation type.
624  */
625 static const struct afs_call_type afs_YFSVLGetEndpoints = {
626         .name           = "YFSVL.GetEndpoints",
627         .op             = afs_YFSVL_GetEndpoints,
628         .deliver        = afs_deliver_yfsvl_get_endpoints,
629         .destructor     = afs_flat_call_destructor,
630 };
631
632 /*
633  * Dispatch an operation to get the addresses for a server, where the server is
634  * nominated by UUID.
635  */
636 struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *vc,
637                                               const uuid_t *uuid)
638 {
639         struct afs_addr_list *alist;
640         struct afs_call *call;
641         struct afs_net *net = vc->cell->net;
642         __be32 *bp;
643
644         _enter("");
645
646         call = afs_alloc_flat_call(net, &afs_YFSVLGetEndpoints,
647                                    sizeof(__be32) * 2 + sizeof(*uuid),
648                                    sizeof(struct in6_addr) + sizeof(__be32) * 3);
649         if (!call)
650                 return ERR_PTR(-ENOMEM);
651
652         call->key = vc->key;
653         call->ret_alist = NULL;
654         call->max_lifespan = AFS_VL_MAX_LIFESPAN;
655
656         /* Marshall the parameters */
657         bp = call->request;
658         *bp++ = htonl(YVLGETENDPOINTS);
659         *bp++ = htonl(YFS_SERVER_UUID);
660         memcpy(bp, uuid, sizeof(*uuid)); /* Type opr_uuid */
661
662         trace_afs_make_vl_call(call);
663         afs_make_call(&vc->ac, call, GFP_KERNEL);
664         afs_wait_for_call_to_complete(call, &vc->ac);
665         vc->call_abort_code     = call->abort_code;
666         vc->call_error          = call->error;
667         vc->call_responded      = call->responded;
668         alist                   = call->ret_alist;
669         afs_put_call(call);
670         if (vc->call_error) {
671                 afs_put_addrlist(alist);
672                 return ERR_PTR(vc->call_error);
673         }
674         return alist;
675 }
676
677 /*
678  * Deliver reply data to a YFSVL.GetCellName operation.
679  */
680 static int afs_deliver_yfsvl_get_cell_name(struct afs_call *call)
681 {
682         char *cell_name;
683         u32 namesz, paddedsz;
684         int ret;
685
686         _enter("{%u,%zu/%u}",
687                call->unmarshall, iov_iter_count(call->iter), call->count);
688
689         switch (call->unmarshall) {
690         case 0:
691                 afs_extract_to_tmp(call);
692                 call->unmarshall++;
693
694                 fallthrough;    /* and extract the cell name length */
695         case 1:
696                 ret = afs_extract_data(call, true);
697                 if (ret < 0)
698                         return ret;
699
700                 namesz = ntohl(call->tmp);
701                 if (namesz > AFS_MAXCELLNAME)
702                         return afs_protocol_error(call, afs_eproto_cellname_len);
703                 paddedsz = (namesz + 3) & ~3;
704                 call->count = namesz;
705                 call->count2 = paddedsz - namesz;
706
707                 cell_name = kmalloc(namesz + 1, GFP_KERNEL);
708                 if (!cell_name)
709                         return -ENOMEM;
710                 cell_name[namesz] = 0;
711                 call->ret_str = cell_name;
712
713                 afs_extract_begin(call, cell_name, namesz);
714                 call->unmarshall++;
715
716                 fallthrough;    /* and extract cell name */
717         case 2:
718                 ret = afs_extract_data(call, true);
719                 if (ret < 0)
720                         return ret;
721
722                 afs_extract_discard(call, call->count2);
723                 call->unmarshall++;
724
725                 fallthrough;    /* and extract padding */
726         case 3:
727                 ret = afs_extract_data(call, false);
728                 if (ret < 0)
729                         return ret;
730
731                 call->unmarshall++;
732                 break;
733         }
734
735         _leave(" = 0 [done]");
736         return 0;
737 }
738
739 /*
740  * VL.GetCapabilities operation type
741  */
742 static const struct afs_call_type afs_YFSVLGetCellName = {
743         .name           = "YFSVL.GetCellName",
744         .op             = afs_YFSVL_GetCellName,
745         .deliver        = afs_deliver_yfsvl_get_cell_name,
746         .destructor     = afs_flat_call_destructor,
747 };
748
749 /*
750  * Probe a volume server for the capabilities that it supports.  This can
751  * return up to 196 words.
752  *
753  * We use this to probe for service upgrade to determine what the server at the
754  * other end supports.
755  */
756 char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *vc)
757 {
758         struct afs_call *call;
759         struct afs_net *net = vc->cell->net;
760         __be32 *bp;
761         char *cellname;
762
763         _enter("");
764
765         call = afs_alloc_flat_call(net, &afs_YFSVLGetCellName, 1 * 4, 0);
766         if (!call)
767                 return ERR_PTR(-ENOMEM);
768
769         call->key = vc->key;
770         call->ret_str = NULL;
771         call->max_lifespan = AFS_VL_MAX_LIFESPAN;
772
773         /* marshall the parameters */
774         bp = call->request;
775         *bp++ = htonl(YVLGETCELLNAME);
776
777         /* Can't take a ref on server */
778         trace_afs_make_vl_call(call);
779         afs_make_call(&vc->ac, call, GFP_KERNEL);
780         afs_wait_for_call_to_complete(call, &vc->ac);
781         vc->call_abort_code     = call->abort_code;
782         vc->call_error          = call->error;
783         vc->call_responded      = call->responded;
784         cellname                = call->ret_str;
785         afs_put_call(call);
786         if (vc->call_error) {
787                 kfree(cellname);
788                 return ERR_PTR(vc->call_error);
789         }
790         return cellname;
791 }