blob: d7e0fd3c00df9e8ee52b97d272ffc6ae71effa8c [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
David Howellsec268152007-04-26 15:49:28 -07002/* AFS Volume Location Service client
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09008#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/init.h>
10#include <linux/sched.h>
David Howells4d9df982017-11-02 15:27:47 +000011#include "afs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include "internal.h"
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014/*
David Howellsd2ddc772017-11-02 15:27:50 +000015 * Deliver reply data to a VL.GetEntryByNameU call.
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 */
David Howellsd2ddc772017-11-02 15:27:50 +000017static int afs_deliver_vl_get_entry_by_name_u(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018{
David Howellsd2ddc772017-11-02 15:27:50 +000019 struct afs_uvldbentry__xdr *uvldb;
20 struct afs_vldb_entry *entry;
21 bool new_only = false;
Marc Dionne1fba5862018-05-16 11:04:23 -030022 u32 tmp, nr_servers, vlflags;
David Howellsd2ddc772017-11-02 15:27:50 +000023 int i, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
David Howellsd0016482016-08-30 20:42:14 +010025 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
David Howellsd0016482016-08-30 20:42:14 +010027 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +010028 if (ret < 0)
29 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
David Howells08e0e7c2007-04-26 15:55:03 -070031 /* unmarshall the reply once we've received all of it */
David Howellsd2ddc772017-11-02 15:27:50 +000032 uvldb = call->buffer;
David Howellsffba7182019-05-09 22:22:50 +010033 entry = call->ret_vldb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
David Howells45df8462018-02-06 14:12:32 +000035 nr_servers = ntohl(uvldb->nServers);
36 if (nr_servers > AFS_NMAXNSERVERS)
37 nr_servers = AFS_NMAXNSERVERS;
38
David Howellsd2ddc772017-11-02 15:27:50 +000039 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
David Howellsd2ddc772017-11-02 15:27:50 +000044 /* If there is a new replication site that we can use, ignore all the
45 * sites that aren't marked as new.
46 */
David Howells45df8462018-02-06 14:12:32 +000047 for (i = 0; i < nr_servers; i++) {
David Howellsd2ddc772017-11-02 15:27:50 +000048 tmp = ntohl(uvldb->serverFlags[i]);
49 if (!(tmp & AFS_VLSF_DONTUSE) &&
50 (tmp & AFS_VLSF_NEWREPSITE))
51 new_only = true;
David Howells4d9df982017-11-02 15:27:47 +000052 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Marc Dionne1fba5862018-05-16 11:04:23 -030054 vlflags = ntohl(uvldb->flags);
David Howells45df8462018-02-06 14:12:32 +000055 for (i = 0; i < nr_servers; i++) {
David Howellsd2ddc772017-11-02 15:27:50 +000056 struct afs_uuid__xdr *xdr;
57 struct afs_uuid *uuid;
58 int j;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
David Howellsd2ddc772017-11-02 15:27:50 +000060 tmp = ntohl(uvldb->serverFlags[i]);
61 if (tmp & AFS_VLSF_DONTUSE ||
62 (new_only && !(tmp & AFS_VLSF_NEWREPSITE)))
63 continue;
Marc Dionne1fba5862018-05-16 11:04:23 -030064 if (tmp & AFS_VLSF_RWVOL) {
David Howellsd2ddc772017-11-02 15:27:50 +000065 entry->fs_mask[i] |= AFS_VOL_VTM_RW;
Marc Dionne1fba5862018-05-16 11:04:23 -030066 if (vlflags & AFS_VLF_BACKEXISTS)
67 entry->fs_mask[i] |= AFS_VOL_VTM_BAK;
68 }
David Howells08e0e7c2007-04-26 15:55:03 -070069 if (tmp & AFS_VLSF_ROVOL)
David Howellsd2ddc772017-11-02 15:27:50 +000070 entry->fs_mask[i] |= AFS_VOL_VTM_RO;
David Howellsd2ddc772017-11-02 15:27:50 +000071 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]);
83
84 entry->nr_servers++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 }
86
David Howellsd2ddc772017-11-02 15:27:50 +000087 for (i = 0; i < AFS_MAXTYPES; i++)
88 entry->vid[i] = ntohl(uvldb->volumeId[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Marc Dionne1fba5862018-05-16 11:04:23 -030090 if (vlflags & AFS_VLF_RWEXISTS)
David Howellsd2ddc772017-11-02 15:27:50 +000091 __set_bit(AFS_VLDB_HAS_RW, &entry->flags);
Marc Dionne1fba5862018-05-16 11:04:23 -030092 if (vlflags & AFS_VLF_ROEXISTS)
David Howellsd2ddc772017-11-02 15:27:50 +000093 __set_bit(AFS_VLDB_HAS_RO, &entry->flags);
Marc Dionne1fba5862018-05-16 11:04:23 -030094 if (vlflags & AFS_VLF_BACKEXISTS)
David Howellsd2ddc772017-11-02 15:27:50 +000095 __set_bit(AFS_VLDB_HAS_BAK, &entry->flags);
96
Marc Dionne1fba5862018-05-16 11:04:23 -030097 if (!(vlflags & (AFS_VLF_RWEXISTS | AFS_VLF_ROEXISTS | AFS_VLF_BACKEXISTS))) {
David Howellsd2ddc772017-11-02 15:27:50 +000098 entry->error = -ENOMEDIUM;
99 __set_bit(AFS_VLDB_QUERY_ERROR, &entry->flags);
100 }
101
102 __set_bit(AFS_VLDB_QUERY_VALID, &entry->flags);
103 _leave(" = 0 [done]");
104 return 0;
105}
106
107static void afs_destroy_vl_get_entry_by_name_u(struct afs_call *call)
108{
David Howellsffba7182019-05-09 22:22:50 +0100109 kfree(call->ret_vldb);
David Howellsd2ddc772017-11-02 15:27:50 +0000110 afs_flat_call_destructor(call);
111}
112
113/*
114 * VL.GetEntryByNameU operation type.
115 */
116static const struct afs_call_type afs_RXVLGetEntryByNameU = {
117 .name = "VL.GetEntryByNameU",
David Howells025db802017-11-02 15:27:51 +0000118 .op = afs_VL_GetEntryByNameU,
David Howellsd2ddc772017-11-02 15:27:50 +0000119 .deliver = afs_deliver_vl_get_entry_by_name_u,
120 .destructor = afs_destroy_vl_get_entry_by_name_u,
121};
122
123/*
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.
126 */
David Howells0a5143f2018-10-20 00:57:57 +0100127struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *vc,
David Howellsd2ddc772017-11-02 15:27:50 +0000128 const char *volname,
129 int volnamesz)
130{
131 struct afs_vldb_entry *entry;
132 struct afs_call *call;
David Howells0a5143f2018-10-20 00:57:57 +0100133 struct afs_net *net = vc->cell->net;
David Howellsd2ddc772017-11-02 15:27:50 +0000134 size_t reqsz, padsz;
135 __be32 *bp;
136
137 _enter("");
138
139 padsz = (4 - (volnamesz & 3)) & 3;
140 reqsz = 8 + volnamesz + padsz;
141
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 }
152
David Howells0a5143f2018-10-20 00:57:57 +0100153 call->key = vc->key;
David Howellsffba7182019-05-09 22:22:50 +0100154 call->ret_vldb = entry;
David Howells94f699c2019-05-16 13:21:59 +0100155 call->max_lifespan = AFS_VL_MAX_LIFESPAN;
David Howellsd2ddc772017-11-02 15:27:50 +0000156
157 /* Marshall the parameters */
158 bp = call->request;
159 *bp++ = htonl(VLGETENTRYBYNAMEU);
160 *bp++ = htonl(volnamesz);
161 memcpy(bp, volname, volnamesz);
162 if (padsz > 0)
163 memset((void *)bp + volnamesz, 0, padsz);
164
David Howells025db802017-11-02 15:27:51 +0000165 trace_afs_make_vl_call(call);
David Howells0b9bf382019-04-25 14:26:50 +0100166 afs_make_call(&vc->ac, call, GFP_KERNEL);
167 return (struct afs_vldb_entry *)afs_wait_for_call_to_complete(call, &vc->ac);
David Howellsd2ddc772017-11-02 15:27:50 +0000168}
169
170/*
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);
178 */
179static int afs_deliver_vl_get_addrs_u(struct afs_call *call)
180{
181 struct afs_addr_list *alist;
182 __be32 *bp;
183 u32 uniquifier, nentries, count;
184 int i, ret;
185
David Howells12bdcf32018-10-20 00:57:56 +0100186 _enter("{%u,%zu/%u}",
187 call->unmarshall, iov_iter_count(call->_iter), call->count);
David Howellsd2ddc772017-11-02 15:27:50 +0000188
David Howellsd2ddc772017-11-02 15:27:50 +0000189 switch (call->unmarshall) {
190 case 0:
David Howells12bdcf32018-10-20 00:57:56 +0100191 afs_extract_to_buf(call,
192 sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
David Howellsd2ddc772017-11-02 15:27:50 +0000193 call->unmarshall++;
194
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600195 /* Extract the returned uuid, uniquifier, nentries and
196 * blkaddrs size */
197 /* Fall through */
David Howellsd2ddc772017-11-02 15:27:50 +0000198 case 1:
David Howells12bdcf32018-10-20 00:57:56 +0100199 ret = afs_extract_data(call, true);
David Howellsd2ddc772017-11-02 15:27:50 +0000200 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;
David Howellsffba7182019-05-09 22:22:50 +0100213 call->ret_alist = alist;
David Howellsd2ddc772017-11-02 15:27:50 +0000214 call->count = count;
215 call->count2 = nentries;
David Howellsd2ddc772017-11-02 15:27:50 +0000216 call->unmarshall++;
217
David Howells12bdcf32018-10-20 00:57:56 +0100218 more_entries:
219 count = min(call->count, 4U);
220 afs_extract_to_buf(call, count * sizeof(__be32));
221
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600222 /* Fall through - and extract entries */
David Howellsd2ddc772017-11-02 15:27:50 +0000223 case 2:
David Howells12bdcf32018-10-20 00:57:56 +0100224 ret = afs_extract_data(call, call->count > 4);
David Howellsd2ddc772017-11-02 15:27:50 +0000225 if (ret < 0)
226 return ret;
227
David Howellsffba7182019-05-09 22:22:50 +0100228 alist = call->ret_alist;
David Howellsd2ddc772017-11-02 15:27:50 +0000229 bp = call->buffer;
David Howells12bdcf32018-10-20 00:57:56 +0100230 count = min(call->count, 4U);
David Howellsd2ddc772017-11-02 15:27:50 +0000231 for (i = 0; i < count; i++)
232 if (alist->nr_addrs < call->count2)
David Howellsbf99a532017-11-02 15:27:51 +0000233 afs_merge_fs_addr4(alist, *bp++, AFS_FS_PORT);
David Howellsd2ddc772017-11-02 15:27:50 +0000234
235 call->count -= count;
236 if (call->count > 0)
David Howells12bdcf32018-10-20 00:57:56 +0100237 goto more_entries;
David Howellsd2ddc772017-11-02 15:27:50 +0000238 call->unmarshall++;
239 break;
240 }
David Howells08e0e7c2007-04-26 15:55:03 -0700241
242 _leave(" = 0 [done]");
243 return 0;
David Howellsec268152007-04-26 15:49:28 -0700244}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
David Howellsd2ddc772017-11-02 15:27:50 +0000246static void afs_vl_get_addrs_u_destructor(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
David Howellsffba7182019-05-09 22:22:50 +0100248 afs_put_addrlist(call->ret_alist);
David Howellsd2ddc772017-11-02 15:27:50 +0000249 return afs_flat_call_destructor(call);
David Howellsec268152007-04-26 15:49:28 -0700250}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252/*
David Howellsd2ddc772017-11-02 15:27:50 +0000253 * VL.GetAddrsU operation type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 */
David Howellsd2ddc772017-11-02 15:27:50 +0000255static const struct afs_call_type afs_RXVLGetAddrsU = {
256 .name = "VL.GetAddrsU",
David Howells025db802017-11-02 15:27:51 +0000257 .op = afs_VL_GetAddrsU,
David Howellsd2ddc772017-11-02 15:27:50 +0000258 .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 */
David Howells0a5143f2018-10-20 00:57:57 +0100266struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *vc,
David Howellsd2ddc772017-11-02 15:27:50 +0000267 const uuid_t *uuid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
David Howellsd2ddc772017-11-02 15:27:50 +0000269 struct afs_ListAddrByAttributes__xdr *r;
270 const struct afs_uuid *u = (const struct afs_uuid *)uuid;
David Howells08e0e7c2007-04-26 15:55:03 -0700271 struct afs_call *call;
David Howells0a5143f2018-10-20 00:57:57 +0100272 struct afs_net *net = vc->cell->net;
David Howells08e0e7c2007-04-26 15:55:03 -0700273 __be32 *bp;
David Howellsd2ddc772017-11-02 15:27:50 +0000274 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
David Howells08e0e7c2007-04-26 15:55:03 -0700276 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
David Howellsd2ddc772017-11-02 15:27:50 +0000278 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));
David Howells08e0e7c2007-04-26 15:55:03 -0700281 if (!call)
David Howellsd2ddc772017-11-02 15:27:50 +0000282 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
David Howells0a5143f2018-10-20 00:57:57 +0100284 call->key = vc->key;
David Howellsffba7182019-05-09 22:22:50 +0100285 call->ret_alist = NULL;
David Howells94f699c2019-05-16 13:21:59 +0100286 call->max_lifespan = AFS_VL_MAX_LIFESPAN;
David Howells08e0e7c2007-04-26 15:55:03 -0700287
David Howellsd2ddc772017-11-02 15:27:50 +0000288 /* Marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700289 bp = call->request;
David Howellsd2ddc772017-11-02 15:27:50 +0000290 *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++)
David Howellsfe342cf2018-04-09 21:12:31 +0100302 r->uuid.node[i] = htonl(u->node[i]);
David Howells08e0e7c2007-04-26 15:55:03 -0700303
David Howells025db802017-11-02 15:27:51 +0000304 trace_afs_make_vl_call(call);
David Howells0b9bf382019-04-25 14:26:50 +0100305 afs_make_call(&vc->ac, call, GFP_KERNEL);
306 return (struct afs_addr_list *)afs_wait_for_call_to_complete(call, &vc->ac);
David Howellsec268152007-04-26 15:49:28 -0700307}
David Howellsbf99a532017-11-02 15:27:51 +0000308
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
David Howells12bdcf32018-10-20 00:57:56 +0100317 _enter("{%u,%zu/%u}",
318 call->unmarshall, iov_iter_count(call->_iter), call->count);
David Howellsbf99a532017-11-02 15:27:51 +0000319
David Howellsbf99a532017-11-02 15:27:51 +0000320 switch (call->unmarshall) {
321 case 0:
David Howells12bdcf32018-10-20 00:57:56 +0100322 afs_extract_to_tmp(call);
David Howellsbf99a532017-11-02 15:27:51 +0000323 call->unmarshall++;
324
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600325 /* Fall through - and extract the capabilities word count */
David Howellsbf99a532017-11-02 15:27:51 +0000326 case 1:
David Howells12bdcf32018-10-20 00:57:56 +0100327 ret = afs_extract_data(call, true);
David Howellsbf99a532017-11-02 15:27:51 +0000328 if (ret < 0)
329 return ret;
330
331 count = ntohl(call->tmp);
David Howellsbf99a532017-11-02 15:27:51 +0000332 call->count = count;
333 call->count2 = count;
David Howells12bdcf32018-10-20 00:57:56 +0100334
David Howellsbf99a532017-11-02 15:27:51 +0000335 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +0100336 afs_extract_discard(call, count * sizeof(__be32));
David Howellsbf99a532017-11-02 15:27:51 +0000337
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600338 /* Fall through - and extract capabilities words */
David Howellsbf99a532017-11-02 15:27:51 +0000339 case 2:
David Howells12bdcf32018-10-20 00:57:56 +0100340 ret = afs_extract_data(call, false);
David Howellsbf99a532017-11-02 15:27:51 +0000341 if (ret < 0)
342 return ret;
343
344 /* TODO: Examine capabilities */
345
David Howellsbf99a532017-11-02 15:27:51 +0000346 call->unmarshall++;
347 break;
348 }
349
David Howellsbf99a532017-11-02 15:27:51 +0000350 _leave(" = 0 [done]");
351 return 0;
352}
353
David Howells3bf0fb62018-10-20 00:57:59 +0100354static void afs_destroy_vl_get_capabilities(struct afs_call *call)
355{
David Howellsffba7182019-05-09 22:22:50 +0100356 afs_put_vlserver(call->net, call->vlserver);
David Howells3bf0fb62018-10-20 00:57:59 +0100357 afs_flat_call_destructor(call);
358}
359
David Howellsbf99a532017-11-02 15:27:51 +0000360/*
361 * VL.GetCapabilities operation type
362 */
363static const struct afs_call_type afs_RXVLGetCapabilities = {
364 .name = "VL.GetCapabilities",
David Howells025db802017-11-02 15:27:51 +0000365 .op = afs_VL_GetCapabilities,
David Howellsbf99a532017-11-02 15:27:51 +0000366 .deliver = afs_deliver_vl_get_capabilities,
David Howells3bf0fb62018-10-20 00:57:59 +0100367 .done = afs_vlserver_probe_result,
368 .destructor = afs_destroy_vl_get_capabilities,
David Howellsbf99a532017-11-02 15:27:51 +0000369};
370
371/*
David Howells0a5143f2018-10-20 00:57:57 +0100372 * Probe a volume server for the capabilities that it supports. This can
David Howellsbf99a532017-11-02 15:27:51 +0000373 * 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 */
David Howells0b9bf382019-04-25 14:26:50 +0100378struct 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)
David Howellsbf99a532017-11-02 15:27:51 +0000383{
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)
David Howells0b9bf382019-04-25 14:26:50 +0100391 return ERR_PTR(-ENOMEM);
David Howellsbf99a532017-11-02 15:27:51 +0000392
393 call->key = key;
David Howellsffba7182019-05-09 22:22:50 +0100394 call->vlserver = afs_get_vlserver(server);
395 call->server_index = server_index;
David Howells3bf0fb62018-10-20 00:57:59 +0100396 call->upgrade = true;
David Howells0b9bf382019-04-25 14:26:50 +0100397 call->async = true;
David Howells94f699c2019-05-16 13:21:59 +0100398 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
David Howellsbf99a532017-11-02 15:27:51 +0000399
400 /* marshall the parameters */
401 bp = call->request;
402 *bp++ = htonl(VLGETCAPABILITIES);
403
404 /* Can't take a ref on server */
David Howells025db802017-11-02 15:27:51 +0000405 trace_afs_make_vl_call(call);
David Howells0b9bf382019-04-25 14:26:50 +0100406 afs_make_call(ac, call, GFP_KERNEL);
407 return call;
David Howellsbf99a532017-11-02 15:27:51 +0000408}
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
David Howells12bdcf32018-10-20 00:57:56 +0100426 _enter("{%u,%zu,%u}",
427 call->unmarshall, iov_iter_count(call->_iter), call->count2);
David Howellsbf99a532017-11-02 15:27:51 +0000428
David Howellsbf99a532017-11-02 15:27:51 +0000429 switch (call->unmarshall) {
430 case 0:
David Howells12bdcf32018-10-20 00:57:56 +0100431 afs_extract_to_buf(call, sizeof(uuid_t) + 3 * sizeof(__be32));
David Howellsbf99a532017-11-02 15:27:51 +0000432 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. */
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600437 /* Fall through */
David Howellsbf99a532017-11-02 15:27:51 +0000438 case 1:
David Howells12bdcf32018-10-20 00:57:56 +0100439 ret = afs_extract_data(call, true);
David Howellsbf99a532017-11-02 15:27:51 +0000440 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)
David Howells160cb952018-10-20 00:57:56 +0100449 return afs_protocol_error(call, -EBADMSG,
450 afs_eproto_yvl_fsendpt_num);
David Howellsbf99a532017-11-02 15:27:51 +0000451
452 alist = afs_alloc_addrlist(call->count, FS_SERVICE, AFS_FS_PORT);
453 if (!alist)
454 return -ENOMEM;
455 alist->version = uniquifier;
David Howellsffba7182019-05-09 22:22:50 +0100456 call->ret_alist = alist;
David Howellsbf99a532017-11-02 15:27:51 +0000457
458 if (call->count == 0)
459 goto extract_volendpoints;
460
David Howells12bdcf32018-10-20 00:57:56 +0100461 next_fsendpoint:
David Howellsbf99a532017-11-02 15:27:51 +0000462 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:
David Howells160cb952018-10-20 00:57:56 +0100470 return afs_protocol_error(call, -EBADMSG,
471 afs_eproto_yvl_fsendpt_type);
David Howellsbf99a532017-11-02 15:27:51 +0000472 }
473
474 size += sizeof(__be32);
David Howells12bdcf32018-10-20 00:57:56 +0100475 afs_extract_to_buf(call, size);
476 call->unmarshall = 2;
477
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600478 /* Fall through - and extract fsEndpoints[] entries */
David Howells12bdcf32018-10-20 00:57:56 +0100479 case 2:
480 ret = afs_extract_data(call, true);
David Howellsbf99a532017-11-02 15:27:51 +0000481 if (ret < 0)
482 return ret;
483
David Howellsffba7182019-05-09 22:22:50 +0100484 alist = call->ret_alist;
David Howellsbf99a532017-11-02 15:27:51 +0000485 bp = call->buffer;
486 switch (call->count2) {
487 case YFS_ENDPOINT_IPV4:
488 if (ntohl(bp[0]) != sizeof(__be32) * 2)
David Howells160cb952018-10-20 00:57:56 +0100489 return afs_protocol_error(call, -EBADMSG,
490 afs_eproto_yvl_fsendpt4_len);
David Howellsbf99a532017-11-02 15:27:51 +0000491 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)
David Howells160cb952018-10-20 00:57:56 +0100496 return afs_protocol_error(call, -EBADMSG,
497 afs_eproto_yvl_fsendpt6_len);
David Howellsbf99a532017-11-02 15:27:51 +0000498 afs_merge_fs_addr6(alist, bp + 1, ntohl(bp[5]));
499 bp += 6;
500 break;
501 default:
David Howells160cb952018-10-20 00:57:56 +0100502 return afs_protocol_error(call, -EBADMSG,
503 afs_eproto_yvl_fsendpt_type);
David Howellsbf99a532017-11-02 15:27:51 +0000504 }
505
506 /* Got either the type of the next entry or the count of
507 * volEndpoints if no more fsEndpoints.
508 */
David Howellsfe342cf2018-04-09 21:12:31 +0100509 call->count2 = ntohl(*bp++);
David Howellsbf99a532017-11-02 15:27:51 +0000510
David Howellsbf99a532017-11-02 15:27:51 +0000511 call->count--;
512 if (call->count > 0)
David Howells12bdcf32018-10-20 00:57:56 +0100513 goto next_fsendpoint;
David Howellsbf99a532017-11-02 15:27:51 +0000514
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)
David Howells160cb952018-10-20 00:57:56 +0100521 return afs_protocol_error(call, -EBADMSG,
522 afs_eproto_yvl_vlendpt_type);
David Howellsbf99a532017-11-02 15:27:51 +0000523
David Howells12bdcf32018-10-20 00:57:56 +0100524 afs_extract_to_buf(call, 1 * sizeof(__be32));
David Howellsbf99a532017-11-02 15:27:51 +0000525 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 */
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600531 /* Fall through */
David Howellsbf99a532017-11-02 15:27:51 +0000532 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
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600558 /* Fall through - and extract volEndpoints[] entries */
David Howells12bdcf32018-10-20 00:57:56 +0100559 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
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600594 /* Fall through - Done */
David Howellsbf99a532017-11-02 15:27:51 +0000595 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
David Howellsbf99a532017-11-02 15:27:51 +0000605 _leave(" = 0 [done]");
606 return 0;
607}
608
609/*
610 * YFSVL.GetEndpoints operation type.
611 */
612static const struct afs_call_type afs_YFSVLGetEndpoints = {
David Howells025db802017-11-02 15:27:51 +0000613 .name = "YFSVL.GetEndpoints",
614 .op = afs_YFSVL_GetEndpoints,
David Howellsbf99a532017-11-02 15:27:51 +0000615 .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 */
David Howells0a5143f2018-10-20 00:57:57 +0100623struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *vc,
David Howellsbf99a532017-11-02 15:27:51 +0000624 const uuid_t *uuid)
625{
626 struct afs_call *call;
David Howells0a5143f2018-10-20 00:57:57 +0100627 struct afs_net *net = vc->cell->net;
David Howellsbf99a532017-11-02 15:27:51 +0000628 __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
David Howells0a5143f2018-10-20 00:57:57 +0100638 call->key = vc->key;
David Howellsffba7182019-05-09 22:22:50 +0100639 call->ret_alist = NULL;
David Howells94f699c2019-05-16 13:21:59 +0100640 call->max_lifespan = AFS_VL_MAX_LIFESPAN;
David Howellsbf99a532017-11-02 15:27:51 +0000641
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
David Howells025db802017-11-02 15:27:51 +0000648 trace_afs_make_vl_call(call);
David Howells0b9bf382019-04-25 14:26:50 +0100649 afs_make_call(&vc->ac, call, GFP_KERNEL);
650 return (struct afs_addr_list *)afs_wait_for_call_to_complete(call, &vc->ac);
David Howellsbf99a532017-11-02 15:27:51 +0000651}