blob: c3d9e5a5f67eeb13670b372b04f5b5dc4241282d [file] [log] [blame]
David Howellsec268152007-04-26 15:49:28 -07001/* AFS Volume Location Service client
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
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
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/init.h>
14#include <linux/sched.h>
David Howells4d9df982017-11-02 15:27:47 +000015#include "afs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include "internal.h"
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018/*
David Howellsd2ddc772017-11-02 15:27:50 +000019 * Deliver reply data to a VL.GetEntryByNameU call.
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 */
David Howellsd2ddc772017-11-02 15:27:50 +000021static int afs_deliver_vl_get_entry_by_name_u(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022{
David Howellsd2ddc772017-11-02 15:27:50 +000023 struct afs_uvldbentry__xdr *uvldb;
24 struct afs_vldb_entry *entry;
25 bool new_only = false;
Marc Dionne1fba5862018-05-16 11:04:23 -030026 u32 tmp, nr_servers, vlflags;
David Howellsd2ddc772017-11-02 15:27:50 +000027 int i, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
David Howellsd0016482016-08-30 20:42:14 +010029 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
David Howellsd0016482016-08-30 20:42:14 +010031 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +010032 if (ret < 0)
33 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
David Howells08e0e7c2007-04-26 15:55:03 -070035 /* unmarshall the reply once we've received all of it */
David Howellsd2ddc772017-11-02 15:27:50 +000036 uvldb = call->buffer;
David Howells97e30432017-11-02 15:27:48 +000037 entry = call->reply[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
David Howells45df8462018-02-06 14:12:32 +000039 nr_servers = ntohl(uvldb->nServers);
40 if (nr_servers > AFS_NMAXNSERVERS)
41 nr_servers = AFS_NMAXNSERVERS;
42
David Howellsd2ddc772017-11-02 15:27:50 +000043 for (i = 0; i < ARRAY_SIZE(uvldb->name) - 1; i++)
44 entry->name[i] = (u8)ntohl(uvldb->name[i]);
45 entry->name[i] = 0;
46 entry->name_len = strlen(entry->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
David Howellsd2ddc772017-11-02 15:27:50 +000048 /* If there is a new replication site that we can use, ignore all the
49 * sites that aren't marked as new.
50 */
David Howells45df8462018-02-06 14:12:32 +000051 for (i = 0; i < nr_servers; i++) {
David Howellsd2ddc772017-11-02 15:27:50 +000052 tmp = ntohl(uvldb->serverFlags[i]);
53 if (!(tmp & AFS_VLSF_DONTUSE) &&
54 (tmp & AFS_VLSF_NEWREPSITE))
55 new_only = true;
David Howells4d9df982017-11-02 15:27:47 +000056 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Marc Dionne1fba5862018-05-16 11:04:23 -030058 vlflags = ntohl(uvldb->flags);
David Howells45df8462018-02-06 14:12:32 +000059 for (i = 0; i < nr_servers; i++) {
David Howellsd2ddc772017-11-02 15:27:50 +000060 struct afs_uuid__xdr *xdr;
61 struct afs_uuid *uuid;
62 int j;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
David Howellsd2ddc772017-11-02 15:27:50 +000064 tmp = ntohl(uvldb->serverFlags[i]);
65 if (tmp & AFS_VLSF_DONTUSE ||
66 (new_only && !(tmp & AFS_VLSF_NEWREPSITE)))
67 continue;
Marc Dionne1fba5862018-05-16 11:04:23 -030068 if (tmp & AFS_VLSF_RWVOL) {
David Howellsd2ddc772017-11-02 15:27:50 +000069 entry->fs_mask[i] |= AFS_VOL_VTM_RW;
Marc Dionne1fba5862018-05-16 11:04:23 -030070 if (vlflags & AFS_VLF_BACKEXISTS)
71 entry->fs_mask[i] |= AFS_VOL_VTM_BAK;
72 }
David Howells08e0e7c2007-04-26 15:55:03 -070073 if (tmp & AFS_VLSF_ROVOL)
David Howellsd2ddc772017-11-02 15:27:50 +000074 entry->fs_mask[i] |= AFS_VOL_VTM_RO;
David Howellsd2ddc772017-11-02 15:27:50 +000075 if (!entry->fs_mask[i])
76 continue;
77
78 xdr = &uvldb->serverNumber[i];
79 uuid = (struct afs_uuid *)&entry->fs_server[i];
80 uuid->time_low = xdr->time_low;
81 uuid->time_mid = htons(ntohl(xdr->time_mid));
82 uuid->time_hi_and_version = htons(ntohl(xdr->time_hi_and_version));
83 uuid->clock_seq_hi_and_reserved = (u8)ntohl(xdr->clock_seq_hi_and_reserved);
84 uuid->clock_seq_low = (u8)ntohl(xdr->clock_seq_low);
85 for (j = 0; j < 6; j++)
86 uuid->node[j] = (u8)ntohl(xdr->node[j]);
87
88 entry->nr_servers++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 }
90
David Howellsd2ddc772017-11-02 15:27:50 +000091 for (i = 0; i < AFS_MAXTYPES; i++)
92 entry->vid[i] = ntohl(uvldb->volumeId[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Marc Dionne1fba5862018-05-16 11:04:23 -030094 if (vlflags & AFS_VLF_RWEXISTS)
David Howellsd2ddc772017-11-02 15:27:50 +000095 __set_bit(AFS_VLDB_HAS_RW, &entry->flags);
Marc Dionne1fba5862018-05-16 11:04:23 -030096 if (vlflags & AFS_VLF_ROEXISTS)
David Howellsd2ddc772017-11-02 15:27:50 +000097 __set_bit(AFS_VLDB_HAS_RO, &entry->flags);
Marc Dionne1fba5862018-05-16 11:04:23 -030098 if (vlflags & AFS_VLF_BACKEXISTS)
David Howellsd2ddc772017-11-02 15:27:50 +000099 __set_bit(AFS_VLDB_HAS_BAK, &entry->flags);
100
Marc Dionne1fba5862018-05-16 11:04:23 -0300101 if (!(vlflags & (AFS_VLF_RWEXISTS | AFS_VLF_ROEXISTS | AFS_VLF_BACKEXISTS))) {
David Howellsd2ddc772017-11-02 15:27:50 +0000102 entry->error = -ENOMEDIUM;
103 __set_bit(AFS_VLDB_QUERY_ERROR, &entry->flags);
104 }
105
106 __set_bit(AFS_VLDB_QUERY_VALID, &entry->flags);
107 _leave(" = 0 [done]");
108 return 0;
109}
110
111static void afs_destroy_vl_get_entry_by_name_u(struct afs_call *call)
112{
113 kfree(call->reply[0]);
114 afs_flat_call_destructor(call);
115}
116
117/*
118 * VL.GetEntryByNameU operation type.
119 */
120static const struct afs_call_type afs_RXVLGetEntryByNameU = {
121 .name = "VL.GetEntryByNameU",
David Howells025db802017-11-02 15:27:51 +0000122 .op = afs_VL_GetEntryByNameU,
David Howellsd2ddc772017-11-02 15:27:50 +0000123 .deliver = afs_deliver_vl_get_entry_by_name_u,
124 .destructor = afs_destroy_vl_get_entry_by_name_u,
125};
126
127/*
128 * Dispatch a get volume entry by name or ID operation (uuid variant). If the
129 * volname is a decimal number then it's a volume ID not a volume name.
130 */
David Howells0a5143f2018-10-20 00:57:57 +0100131struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *vc,
David Howellsd2ddc772017-11-02 15:27:50 +0000132 const char *volname,
133 int volnamesz)
134{
135 struct afs_vldb_entry *entry;
136 struct afs_call *call;
David Howells0a5143f2018-10-20 00:57:57 +0100137 struct afs_net *net = vc->cell->net;
David Howellsd2ddc772017-11-02 15:27:50 +0000138 size_t reqsz, padsz;
139 __be32 *bp;
140
141 _enter("");
142
143 padsz = (4 - (volnamesz & 3)) & 3;
144 reqsz = 8 + volnamesz + padsz;
145
146 entry = kzalloc(sizeof(struct afs_vldb_entry), GFP_KERNEL);
147 if (!entry)
148 return ERR_PTR(-ENOMEM);
149
150 call = afs_alloc_flat_call(net, &afs_RXVLGetEntryByNameU, reqsz,
151 sizeof(struct afs_uvldbentry__xdr));
152 if (!call) {
153 kfree(entry);
154 return ERR_PTR(-ENOMEM);
155 }
156
David Howells0a5143f2018-10-20 00:57:57 +0100157 call->key = vc->key;
David Howellsd2ddc772017-11-02 15:27:50 +0000158 call->reply[0] = entry;
159 call->ret_reply0 = true;
160
161 /* Marshall the parameters */
162 bp = call->request;
163 *bp++ = htonl(VLGETENTRYBYNAMEU);
164 *bp++ = htonl(volnamesz);
165 memcpy(bp, volname, volnamesz);
166 if (padsz > 0)
167 memset((void *)bp + volnamesz, 0, padsz);
168
David Howells025db802017-11-02 15:27:51 +0000169 trace_afs_make_vl_call(call);
David Howells0a5143f2018-10-20 00:57:57 +0100170 return (struct afs_vldb_entry *)afs_make_call(&vc->ac, call, GFP_KERNEL, false);
David Howellsd2ddc772017-11-02 15:27:50 +0000171}
172
173/*
174 * Deliver reply data to a VL.GetAddrsU call.
175 *
176 * GetAddrsU(IN ListAddrByAttributes *inaddr,
177 * OUT afsUUID *uuidp1,
178 * OUT uint32_t *uniquifier,
179 * OUT uint32_t *nentries,
180 * OUT bulkaddrs *blkaddrs);
181 */
182static int afs_deliver_vl_get_addrs_u(struct afs_call *call)
183{
184 struct afs_addr_list *alist;
185 __be32 *bp;
186 u32 uniquifier, nentries, count;
187 int i, ret;
188
David Howells12bdcf32018-10-20 00:57:56 +0100189 _enter("{%u,%zu/%u}",
190 call->unmarshall, iov_iter_count(call->_iter), call->count);
David Howellsd2ddc772017-11-02 15:27:50 +0000191
David Howellsd2ddc772017-11-02 15:27:50 +0000192 switch (call->unmarshall) {
193 case 0:
David Howells12bdcf32018-10-20 00:57:56 +0100194 afs_extract_to_buf(call,
195 sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
David Howellsd2ddc772017-11-02 15:27:50 +0000196 call->unmarshall++;
197
198 /* Extract the returned uuid, uniquifier, nentries and blkaddrs size */
199 case 1:
David Howells12bdcf32018-10-20 00:57:56 +0100200 ret = afs_extract_data(call, true);
David Howellsd2ddc772017-11-02 15:27:50 +0000201 if (ret < 0)
202 return ret;
203
204 bp = call->buffer + sizeof(struct afs_uuid__xdr);
205 uniquifier = ntohl(*bp++);
206 nentries = ntohl(*bp++);
207 count = ntohl(*bp);
208
209 nentries = min(nentries, count);
210 alist = afs_alloc_addrlist(nentries, FS_SERVICE, AFS_FS_PORT);
211 if (!alist)
212 return -ENOMEM;
213 alist->version = uniquifier;
214 call->reply[0] = alist;
215 call->count = count;
216 call->count2 = nentries;
David Howellsd2ddc772017-11-02 15:27:50 +0000217 call->unmarshall++;
218
David Howells12bdcf32018-10-20 00:57:56 +0100219 more_entries:
220 count = min(call->count, 4U);
221 afs_extract_to_buf(call, count * sizeof(__be32));
222
David Howellsd2ddc772017-11-02 15:27:50 +0000223 /* Extract entries */
224 case 2:
David Howells12bdcf32018-10-20 00:57:56 +0100225 ret = afs_extract_data(call, call->count > 4);
David Howellsd2ddc772017-11-02 15:27:50 +0000226 if (ret < 0)
227 return ret;
228
229 alist = call->reply[0];
230 bp = call->buffer;
David Howells12bdcf32018-10-20 00:57:56 +0100231 count = min(call->count, 4U);
David Howellsd2ddc772017-11-02 15:27:50 +0000232 for (i = 0; i < count; i++)
233 if (alist->nr_addrs < call->count2)
David Howellsbf99a532017-11-02 15:27:51 +0000234 afs_merge_fs_addr4(alist, *bp++, AFS_FS_PORT);
David Howellsd2ddc772017-11-02 15:27:50 +0000235
236 call->count -= count;
237 if (call->count > 0)
David Howells12bdcf32018-10-20 00:57:56 +0100238 goto more_entries;
David Howellsd2ddc772017-11-02 15:27:50 +0000239 call->unmarshall++;
240 break;
241 }
David Howells08e0e7c2007-04-26 15:55:03 -0700242
243 _leave(" = 0 [done]");
244 return 0;
David Howellsec268152007-04-26 15:49:28 -0700245}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
David Howellsd2ddc772017-11-02 15:27:50 +0000247static void afs_vl_get_addrs_u_destructor(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
David Howellsd2ddc772017-11-02 15:27:50 +0000249 afs_put_server(call->net, (struct afs_server *)call->reply[0]);
250 kfree(call->reply[1]);
251 return afs_flat_call_destructor(call);
David Howellsec268152007-04-26 15:49:28 -0700252}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254/*
David Howellsd2ddc772017-11-02 15:27:50 +0000255 * VL.GetAddrsU operation type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 */
David Howellsd2ddc772017-11-02 15:27:50 +0000257static const struct afs_call_type afs_RXVLGetAddrsU = {
258 .name = "VL.GetAddrsU",
David Howells025db802017-11-02 15:27:51 +0000259 .op = afs_VL_GetAddrsU,
David Howellsd2ddc772017-11-02 15:27:50 +0000260 .deliver = afs_deliver_vl_get_addrs_u,
261 .destructor = afs_vl_get_addrs_u_destructor,
262};
263
264/*
265 * Dispatch an operation to get the addresses for a server, where the server is
266 * nominated by UUID.
267 */
David Howells0a5143f2018-10-20 00:57:57 +0100268struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *vc,
David Howellsd2ddc772017-11-02 15:27:50 +0000269 const uuid_t *uuid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
David Howellsd2ddc772017-11-02 15:27:50 +0000271 struct afs_ListAddrByAttributes__xdr *r;
272 const struct afs_uuid *u = (const struct afs_uuid *)uuid;
David Howells08e0e7c2007-04-26 15:55:03 -0700273 struct afs_call *call;
David Howells0a5143f2018-10-20 00:57:57 +0100274 struct afs_net *net = vc->cell->net;
David Howells08e0e7c2007-04-26 15:55:03 -0700275 __be32 *bp;
David Howellsd2ddc772017-11-02 15:27:50 +0000276 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
David Howells08e0e7c2007-04-26 15:55:03 -0700278 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
David Howellsd2ddc772017-11-02 15:27:50 +0000280 call = afs_alloc_flat_call(net, &afs_RXVLGetAddrsU,
281 sizeof(__be32) + sizeof(struct afs_ListAddrByAttributes__xdr),
282 sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
David Howells08e0e7c2007-04-26 15:55:03 -0700283 if (!call)
David Howellsd2ddc772017-11-02 15:27:50 +0000284 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
David Howells0a5143f2018-10-20 00:57:57 +0100286 call->key = vc->key;
David Howellsd2ddc772017-11-02 15:27:50 +0000287 call->reply[0] = NULL;
288 call->ret_reply0 = true;
David Howells08e0e7c2007-04-26 15:55:03 -0700289
David Howellsd2ddc772017-11-02 15:27:50 +0000290 /* Marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700291 bp = call->request;
David Howellsd2ddc772017-11-02 15:27:50 +0000292 *bp++ = htonl(VLGETADDRSU);
293 r = (struct afs_ListAddrByAttributes__xdr *)bp;
294 r->Mask = htonl(AFS_VLADDR_UUID);
295 r->ipaddr = 0;
296 r->index = 0;
297 r->spare = 0;
298 r->uuid.time_low = u->time_low;
299 r->uuid.time_mid = htonl(ntohs(u->time_mid));
300 r->uuid.time_hi_and_version = htonl(ntohs(u->time_hi_and_version));
301 r->uuid.clock_seq_hi_and_reserved = htonl(u->clock_seq_hi_and_reserved);
302 r->uuid.clock_seq_low = htonl(u->clock_seq_low);
303 for (i = 0; i < 6; i++)
David Howellsfe342cf2018-04-09 21:12:31 +0100304 r->uuid.node[i] = htonl(u->node[i]);
David Howells08e0e7c2007-04-26 15:55:03 -0700305
David Howells025db802017-11-02 15:27:51 +0000306 trace_afs_make_vl_call(call);
David Howells0a5143f2018-10-20 00:57:57 +0100307 return (struct afs_addr_list *)afs_make_call(&vc->ac, call, GFP_KERNEL, false);
David Howellsec268152007-04-26 15:49:28 -0700308}
David Howellsbf99a532017-11-02 15:27:51 +0000309
310/*
311 * Deliver reply data to an VL.GetCapabilities operation.
312 */
313static int afs_deliver_vl_get_capabilities(struct afs_call *call)
314{
315 u32 count;
316 int ret;
317
David Howells12bdcf32018-10-20 00:57:56 +0100318 _enter("{%u,%zu/%u}",
319 call->unmarshall, iov_iter_count(call->_iter), call->count);
David Howellsbf99a532017-11-02 15:27:51 +0000320
David Howellsbf99a532017-11-02 15:27:51 +0000321 switch (call->unmarshall) {
322 case 0:
David Howells12bdcf32018-10-20 00:57:56 +0100323 afs_extract_to_tmp(call);
David Howellsbf99a532017-11-02 15:27:51 +0000324 call->unmarshall++;
325
326 /* Extract the capabilities word count */
327 case 1:
David Howells12bdcf32018-10-20 00:57:56 +0100328 ret = afs_extract_data(call, true);
David Howellsbf99a532017-11-02 15:27:51 +0000329 if (ret < 0)
330 return ret;
331
332 count = ntohl(call->tmp);
David Howellsbf99a532017-11-02 15:27:51 +0000333 call->count = count;
334 call->count2 = count;
David Howells12bdcf32018-10-20 00:57:56 +0100335
David Howellsbf99a532017-11-02 15:27:51 +0000336 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +0100337 afs_extract_discard(call, count * sizeof(__be32));
David Howellsbf99a532017-11-02 15:27:51 +0000338
339 /* Extract capabilities words */
340 case 2:
David Howells12bdcf32018-10-20 00:57:56 +0100341 ret = afs_extract_data(call, false);
David Howellsbf99a532017-11-02 15:27:51 +0000342 if (ret < 0)
343 return ret;
344
345 /* TODO: Examine capabilities */
346
David Howellsbf99a532017-11-02 15:27:51 +0000347 call->unmarshall++;
348 break;
349 }
350
David Howellsbf99a532017-11-02 15:27:51 +0000351 _leave(" = 0 [done]");
352 return 0;
353}
354
David Howells3bf0fb62018-10-20 00:57:59 +0100355static void afs_destroy_vl_get_capabilities(struct afs_call *call)
356{
357 struct afs_vlserver *server = call->reply[0];
358
359 afs_put_vlserver(call->net, server);
360 afs_flat_call_destructor(call);
361}
362
David Howellsbf99a532017-11-02 15:27:51 +0000363/*
364 * VL.GetCapabilities operation type
365 */
366static const struct afs_call_type afs_RXVLGetCapabilities = {
367 .name = "VL.GetCapabilities",
David Howells025db802017-11-02 15:27:51 +0000368 .op = afs_VL_GetCapabilities,
David Howellsbf99a532017-11-02 15:27:51 +0000369 .deliver = afs_deliver_vl_get_capabilities,
David Howells3bf0fb62018-10-20 00:57:59 +0100370 .done = afs_vlserver_probe_result,
371 .destructor = afs_destroy_vl_get_capabilities,
David Howellsbf99a532017-11-02 15:27:51 +0000372};
373
374/*
David Howells0a5143f2018-10-20 00:57:57 +0100375 * Probe a volume server for the capabilities that it supports. This can
David Howellsbf99a532017-11-02 15:27:51 +0000376 * return up to 196 words.
377 *
378 * We use this to probe for service upgrade to determine what the server at the
379 * other end supports.
380 */
David Howells3bf0fb62018-10-20 00:57:59 +0100381int afs_vl_get_capabilities(struct afs_net *net,
382 struct afs_addr_cursor *ac,
383 struct key *key,
384 struct afs_vlserver *server,
385 unsigned int server_index,
386 bool async)
David Howellsbf99a532017-11-02 15:27:51 +0000387{
388 struct afs_call *call;
389 __be32 *bp;
390
391 _enter("");
392
393 call = afs_alloc_flat_call(net, &afs_RXVLGetCapabilities, 1 * 4, 16 * 4);
394 if (!call)
395 return -ENOMEM;
396
397 call->key = key;
David Howells3bf0fb62018-10-20 00:57:59 +0100398 call->reply[0] = afs_get_vlserver(server);
399 call->reply[1] = (void *)(long)server_index;
400 call->upgrade = true;
401 call->want_reply_time = true;
David Howellsbf99a532017-11-02 15:27:51 +0000402
403 /* marshall the parameters */
404 bp = call->request;
405 *bp++ = htonl(VLGETCAPABILITIES);
406
407 /* Can't take a ref on server */
David Howells025db802017-11-02 15:27:51 +0000408 trace_afs_make_vl_call(call);
David Howells3bf0fb62018-10-20 00:57:59 +0100409 return afs_make_call(ac, call, GFP_KERNEL, async);
David Howellsbf99a532017-11-02 15:27:51 +0000410}
411
412/*
413 * Deliver reply data to a YFSVL.GetEndpoints call.
414 *
415 * GetEndpoints(IN yfsServerAttributes *attr,
416 * OUT opr_uuid *uuid,
417 * OUT afs_int32 *uniquifier,
418 * OUT endpoints *fsEndpoints,
419 * OUT endpoints *volEndpoints)
420 */
421static int afs_deliver_yfsvl_get_endpoints(struct afs_call *call)
422{
423 struct afs_addr_list *alist;
424 __be32 *bp;
425 u32 uniquifier, size;
426 int ret;
427
David Howells12bdcf32018-10-20 00:57:56 +0100428 _enter("{%u,%zu,%u}",
429 call->unmarshall, iov_iter_count(call->_iter), call->count2);
David Howellsbf99a532017-11-02 15:27:51 +0000430
David Howellsbf99a532017-11-02 15:27:51 +0000431 switch (call->unmarshall) {
432 case 0:
David Howells12bdcf32018-10-20 00:57:56 +0100433 afs_extract_to_buf(call, sizeof(uuid_t) + 3 * sizeof(__be32));
David Howellsbf99a532017-11-02 15:27:51 +0000434 call->unmarshall = 1;
435
436 /* Extract the returned uuid, uniquifier, fsEndpoints count and
437 * either the first fsEndpoint type or the volEndpoints
438 * count if there are no fsEndpoints. */
439 case 1:
David Howells12bdcf32018-10-20 00:57:56 +0100440 ret = afs_extract_data(call, true);
David Howellsbf99a532017-11-02 15:27:51 +0000441 if (ret < 0)
442 return ret;
443
444 bp = call->buffer + sizeof(uuid_t);
445 uniquifier = ntohl(*bp++);
446 call->count = ntohl(*bp++);
447 call->count2 = ntohl(*bp); /* Type or next count */
448
449 if (call->count > YFS_MAXENDPOINTS)
David Howells160cb952018-10-20 00:57:56 +0100450 return afs_protocol_error(call, -EBADMSG,
451 afs_eproto_yvl_fsendpt_num);
David Howellsbf99a532017-11-02 15:27:51 +0000452
453 alist = afs_alloc_addrlist(call->count, FS_SERVICE, AFS_FS_PORT);
454 if (!alist)
455 return -ENOMEM;
456 alist->version = uniquifier;
457 call->reply[0] = alist;
David Howellsbf99a532017-11-02 15:27:51 +0000458
459 if (call->count == 0)
460 goto extract_volendpoints;
461
David Howells12bdcf32018-10-20 00:57:56 +0100462 next_fsendpoint:
David Howellsbf99a532017-11-02 15:27:51 +0000463 switch (call->count2) {
464 case YFS_ENDPOINT_IPV4:
465 size = sizeof(__be32) * (1 + 1 + 1);
466 break;
467 case YFS_ENDPOINT_IPV6:
468 size = sizeof(__be32) * (1 + 4 + 1);
469 break;
470 default:
David Howells160cb952018-10-20 00:57:56 +0100471 return afs_protocol_error(call, -EBADMSG,
472 afs_eproto_yvl_fsendpt_type);
David Howellsbf99a532017-11-02 15:27:51 +0000473 }
474
475 size += sizeof(__be32);
David Howells12bdcf32018-10-20 00:57:56 +0100476 afs_extract_to_buf(call, size);
477 call->unmarshall = 2;
478
479 /* Extract fsEndpoints[] entries */
480 case 2:
481 ret = afs_extract_data(call, true);
David Howellsbf99a532017-11-02 15:27:51 +0000482 if (ret < 0)
483 return ret;
484
485 alist = call->reply[0];
486 bp = call->buffer;
487 switch (call->count2) {
488 case YFS_ENDPOINT_IPV4:
489 if (ntohl(bp[0]) != sizeof(__be32) * 2)
David Howells160cb952018-10-20 00:57:56 +0100490 return afs_protocol_error(call, -EBADMSG,
491 afs_eproto_yvl_fsendpt4_len);
David Howellsbf99a532017-11-02 15:27:51 +0000492 afs_merge_fs_addr4(alist, bp[1], ntohl(bp[2]));
493 bp += 3;
494 break;
495 case YFS_ENDPOINT_IPV6:
496 if (ntohl(bp[0]) != sizeof(__be32) * 5)
David Howells160cb952018-10-20 00:57:56 +0100497 return afs_protocol_error(call, -EBADMSG,
498 afs_eproto_yvl_fsendpt6_len);
David Howellsbf99a532017-11-02 15:27:51 +0000499 afs_merge_fs_addr6(alist, bp + 1, ntohl(bp[5]));
500 bp += 6;
501 break;
502 default:
David Howells160cb952018-10-20 00:57:56 +0100503 return afs_protocol_error(call, -EBADMSG,
504 afs_eproto_yvl_fsendpt_type);
David Howellsbf99a532017-11-02 15:27:51 +0000505 }
506
507 /* Got either the type of the next entry or the count of
508 * volEndpoints if no more fsEndpoints.
509 */
David Howellsfe342cf2018-04-09 21:12:31 +0100510 call->count2 = ntohl(*bp++);
David Howellsbf99a532017-11-02 15:27:51 +0000511
David Howellsbf99a532017-11-02 15:27:51 +0000512 call->count--;
513 if (call->count > 0)
David Howells12bdcf32018-10-20 00:57:56 +0100514 goto next_fsendpoint;
David Howellsbf99a532017-11-02 15:27:51 +0000515
516 extract_volendpoints:
517 /* Extract the list of volEndpoints. */
518 call->count = call->count2;
519 if (!call->count)
520 goto end;
521 if (call->count > YFS_MAXENDPOINTS)
David Howells160cb952018-10-20 00:57:56 +0100522 return afs_protocol_error(call, -EBADMSG,
523 afs_eproto_yvl_vlendpt_type);
David Howellsbf99a532017-11-02 15:27:51 +0000524
David Howells12bdcf32018-10-20 00:57:56 +0100525 afs_extract_to_buf(call, 1 * sizeof(__be32));
David Howellsbf99a532017-11-02 15:27:51 +0000526 call->unmarshall = 3;
527
528 /* Extract the type of volEndpoints[0]. Normally we would
529 * extract the type of the next endpoint when we extract the
530 * data of the current one, but this is the first...
531 */
532 case 3:
David Howells12bdcf32018-10-20 00:57:56 +0100533 ret = afs_extract_data(call, true);
David Howellsbf99a532017-11-02 15:27:51 +0000534 if (ret < 0)
535 return ret;
536
537 bp = call->buffer;
David Howellsbf99a532017-11-02 15:27:51 +0000538
David Howells12bdcf32018-10-20 00:57:56 +0100539 next_volendpoint:
540 call->count2 = ntohl(*bp++);
David Howellsbf99a532017-11-02 15:27:51 +0000541 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:
David Howells160cb952018-10-20 00:57:56 +0100549 return afs_protocol_error(call, -EBADMSG,
550 afs_eproto_yvl_vlendpt_type);
David Howellsbf99a532017-11-02 15:27:51 +0000551 }
552
553 if (call->count > 1)
David Howells12bdcf32018-10-20 00:57:56 +0100554 size += sizeof(__be32); /* Get next type too */
555 afs_extract_to_buf(call, size);
556 call->unmarshall = 4;
557
558 /* Extract volEndpoints[] entries */
559 case 4:
560 ret = afs_extract_data(call, true);
David Howellsbf99a532017-11-02 15:27:51 +0000561 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)
David Howells160cb952018-10-20 00:57:56 +0100568 return afs_protocol_error(call, -EBADMSG,
569 afs_eproto_yvl_vlendpt4_len);
David Howellsbf99a532017-11-02 15:27:51 +0000570 bp += 3;
571 break;
572 case YFS_ENDPOINT_IPV6:
573 if (ntohl(bp[0]) != sizeof(__be32) * 5)
David Howells160cb952018-10-20 00:57:56 +0100574 return afs_protocol_error(call, -EBADMSG,
575 afs_eproto_yvl_vlendpt6_len);
David Howellsbf99a532017-11-02 15:27:51 +0000576 bp += 6;
577 break;
578 default:
David Howells160cb952018-10-20 00:57:56 +0100579 return afs_protocol_error(call, -EBADMSG,
580 afs_eproto_yvl_vlendpt_type);
David Howellsbf99a532017-11-02 15:27:51 +0000581 }
582
583 /* Got either the type of the next entry or the count of
584 * volEndpoints if no more fsEndpoints.
585 */
David Howellsbf99a532017-11-02 15:27:51 +0000586 call->count--;
David Howells12bdcf32018-10-20 00:57:56 +0100587 if (call->count > 0)
588 goto next_volendpoint;
David Howellsbf99a532017-11-02 15:27:51 +0000589
590 end:
David Howells12bdcf32018-10-20 00:57:56 +0100591 afs_extract_discard(call, 0);
David Howellsbf99a532017-11-02 15:27:51 +0000592 call->unmarshall = 5;
593
594 /* Done */
595 case 5:
David Howells12bdcf32018-10-20 00:57:56 +0100596 ret = afs_extract_data(call, false);
David Howellsbf99a532017-11-02 15:27:51 +0000597 if (ret < 0)
598 return ret;
599 call->unmarshall = 6;
600
601 case 6:
602 break;
603 }
604
605 alist = call->reply[0];
David Howellsbf99a532017-11-02 15:27:51 +0000606 _leave(" = 0 [done]");
607 return 0;
608}
609
610/*
611 * YFSVL.GetEndpoints operation type.
612 */
613static const struct afs_call_type afs_YFSVLGetEndpoints = {
David Howells025db802017-11-02 15:27:51 +0000614 .name = "YFSVL.GetEndpoints",
615 .op = afs_YFSVL_GetEndpoints,
David Howellsbf99a532017-11-02 15:27:51 +0000616 .deliver = afs_deliver_yfsvl_get_endpoints,
617 .destructor = afs_vl_get_addrs_u_destructor,
618};
619
620/*
621 * Dispatch an operation to get the addresses for a server, where the server is
622 * nominated by UUID.
623 */
David Howells0a5143f2018-10-20 00:57:57 +0100624struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *vc,
David Howellsbf99a532017-11-02 15:27:51 +0000625 const uuid_t *uuid)
626{
627 struct afs_call *call;
David Howells0a5143f2018-10-20 00:57:57 +0100628 struct afs_net *net = vc->cell->net;
David Howellsbf99a532017-11-02 15:27:51 +0000629 __be32 *bp;
630
631 _enter("");
632
633 call = afs_alloc_flat_call(net, &afs_YFSVLGetEndpoints,
634 sizeof(__be32) * 2 + sizeof(*uuid),
635 sizeof(struct in6_addr) + sizeof(__be32) * 3);
636 if (!call)
637 return ERR_PTR(-ENOMEM);
638
David Howells0a5143f2018-10-20 00:57:57 +0100639 call->key = vc->key;
David Howellsbf99a532017-11-02 15:27:51 +0000640 call->reply[0] = NULL;
641 call->ret_reply0 = true;
642
643 /* Marshall the parameters */
644 bp = call->request;
645 *bp++ = htonl(YVLGETENDPOINTS);
646 *bp++ = htonl(YFS_SERVER_UUID);
647 memcpy(bp, uuid, sizeof(*uuid)); /* Type opr_uuid */
648
David Howells025db802017-11-02 15:27:51 +0000649 trace_afs_make_vl_call(call);
David Howells0a5143f2018-10-20 00:57:57 +0100650 return (struct afs_addr_list *)afs_make_call(&vc->ac, call, GFP_KERNEL, false);
David Howellsbf99a532017-11-02 15:27:51 +0000651}