.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* AFS Volume Location Service client |
---|
2 | 3 | * |
---|
3 | 4 | * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. |
---|
4 | 5 | * 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 | 6 | */ |
---|
11 | 7 | |
---|
12 | 8 | #include <linux/gfp.h> |
---|
.. | .. |
---|
34 | 30 | |
---|
35 | 31 | /* unmarshall the reply once we've received all of it */ |
---|
36 | 32 | uvldb = call->buffer; |
---|
37 | | - entry = call->reply[0]; |
---|
| 33 | + entry = call->ret_vldb; |
---|
38 | 34 | |
---|
39 | 35 | nr_servers = ntohl(uvldb->nServers); |
---|
40 | 36 | if (nr_servers > AFS_NMAXNSERVERS) |
---|
.. | .. |
---|
86 | 82 | for (j = 0; j < 6; j++) |
---|
87 | 83 | uuid->node[j] = (u8)ntohl(xdr->node[j]); |
---|
88 | 84 | |
---|
| 85 | + entry->addr_version[n] = ntohl(uvldb->serverUnique[i]); |
---|
89 | 86 | entry->nr_servers++; |
---|
90 | 87 | } |
---|
91 | 88 | |
---|
.. | .. |
---|
111 | 108 | |
---|
112 | 109 | static void afs_destroy_vl_get_entry_by_name_u(struct afs_call *call) |
---|
113 | 110 | { |
---|
114 | | - kfree(call->reply[0]); |
---|
| 111 | + kfree(call->ret_vldb); |
---|
115 | 112 | afs_flat_call_destructor(call); |
---|
116 | 113 | } |
---|
117 | 114 | |
---|
.. | .. |
---|
129 | 126 | * Dispatch a get volume entry by name or ID operation (uuid variant). If the |
---|
130 | 127 | * volname is a decimal number then it's a volume ID not a volume name. |
---|
131 | 128 | */ |
---|
132 | | -struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *net, |
---|
133 | | - struct afs_addr_cursor *ac, |
---|
134 | | - struct key *key, |
---|
| 129 | +struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *vc, |
---|
135 | 130 | const char *volname, |
---|
136 | 131 | int volnamesz) |
---|
137 | 132 | { |
---|
138 | 133 | struct afs_vldb_entry *entry; |
---|
139 | 134 | struct afs_call *call; |
---|
| 135 | + struct afs_net *net = vc->cell->net; |
---|
140 | 136 | size_t reqsz, padsz; |
---|
141 | 137 | __be32 *bp; |
---|
142 | 138 | |
---|
.. | .. |
---|
156 | 152 | return ERR_PTR(-ENOMEM); |
---|
157 | 153 | } |
---|
158 | 154 | |
---|
159 | | - call->key = key; |
---|
160 | | - call->reply[0] = entry; |
---|
161 | | - call->ret_reply0 = true; |
---|
| 155 | + call->key = vc->key; |
---|
| 156 | + call->ret_vldb = entry; |
---|
| 157 | + call->max_lifespan = AFS_VL_MAX_LIFESPAN; |
---|
162 | 158 | |
---|
163 | 159 | /* Marshall the parameters */ |
---|
164 | 160 | bp = call->request; |
---|
.. | .. |
---|
169 | 165 | memset((void *)bp + volnamesz, 0, padsz); |
---|
170 | 166 | |
---|
171 | 167 | trace_afs_make_vl_call(call); |
---|
172 | | - return (struct afs_vldb_entry *)afs_make_call(ac, call, GFP_KERNEL, false); |
---|
| 168 | + afs_make_call(&vc->ac, call, GFP_KERNEL); |
---|
| 169 | + return (struct afs_vldb_entry *)afs_wait_for_call_to_complete(call, &vc->ac); |
---|
173 | 170 | } |
---|
174 | 171 | |
---|
175 | 172 | /* |
---|
.. | .. |
---|
188 | 185 | u32 uniquifier, nentries, count; |
---|
189 | 186 | int i, ret; |
---|
190 | 187 | |
---|
191 | | - _enter("{%u,%zu/%u}", call->unmarshall, call->offset, call->count); |
---|
| 188 | + _enter("{%u,%zu/%u}", |
---|
| 189 | + call->unmarshall, iov_iter_count(call->iter), call->count); |
---|
192 | 190 | |
---|
193 | | -again: |
---|
194 | 191 | switch (call->unmarshall) { |
---|
195 | 192 | case 0: |
---|
196 | | - call->offset = 0; |
---|
| 193 | + afs_extract_to_buf(call, |
---|
| 194 | + sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32)); |
---|
197 | 195 | call->unmarshall++; |
---|
198 | 196 | |
---|
199 | | - /* Extract the returned uuid, uniquifier, nentries and blkaddrs size */ |
---|
| 197 | + /* Extract the returned uuid, uniquifier, nentries and |
---|
| 198 | + * blkaddrs size */ |
---|
| 199 | + fallthrough; |
---|
200 | 200 | case 1: |
---|
201 | | - ret = afs_extract_data(call, call->buffer, |
---|
202 | | - sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32), |
---|
203 | | - true); |
---|
| 201 | + ret = afs_extract_data(call, true); |
---|
204 | 202 | if (ret < 0) |
---|
205 | 203 | return ret; |
---|
206 | 204 | |
---|
.. | .. |
---|
214 | 212 | if (!alist) |
---|
215 | 213 | return -ENOMEM; |
---|
216 | 214 | alist->version = uniquifier; |
---|
217 | | - call->reply[0] = alist; |
---|
| 215 | + call->ret_alist = alist; |
---|
218 | 216 | call->count = count; |
---|
219 | 217 | call->count2 = nentries; |
---|
220 | | - call->offset = 0; |
---|
221 | 218 | call->unmarshall++; |
---|
222 | 219 | |
---|
223 | | - /* Extract entries */ |
---|
224 | | - case 2: |
---|
| 220 | + more_entries: |
---|
225 | 221 | count = min(call->count, 4U); |
---|
226 | | - ret = afs_extract_data(call, call->buffer, |
---|
227 | | - count * sizeof(__be32), |
---|
228 | | - call->count > 4); |
---|
| 222 | + afs_extract_to_buf(call, count * sizeof(__be32)); |
---|
| 223 | + |
---|
| 224 | + fallthrough; /* and extract entries */ |
---|
| 225 | + case 2: |
---|
| 226 | + ret = afs_extract_data(call, call->count > 4); |
---|
229 | 227 | if (ret < 0) |
---|
230 | 228 | return ret; |
---|
231 | 229 | |
---|
232 | | - alist = call->reply[0]; |
---|
| 230 | + alist = call->ret_alist; |
---|
233 | 231 | bp = call->buffer; |
---|
| 232 | + count = min(call->count, 4U); |
---|
234 | 233 | for (i = 0; i < count; i++) |
---|
235 | 234 | if (alist->nr_addrs < call->count2) |
---|
236 | 235 | afs_merge_fs_addr4(alist, *bp++, AFS_FS_PORT); |
---|
237 | 236 | |
---|
238 | 237 | call->count -= count; |
---|
239 | 238 | if (call->count > 0) |
---|
240 | | - goto again; |
---|
241 | | - call->offset = 0; |
---|
| 239 | + goto more_entries; |
---|
242 | 240 | call->unmarshall++; |
---|
243 | 241 | break; |
---|
244 | 242 | } |
---|
.. | .. |
---|
249 | 247 | |
---|
250 | 248 | static void afs_vl_get_addrs_u_destructor(struct afs_call *call) |
---|
251 | 249 | { |
---|
252 | | - afs_put_server(call->net, (struct afs_server *)call->reply[0]); |
---|
253 | | - kfree(call->reply[1]); |
---|
| 250 | + afs_put_addrlist(call->ret_alist); |
---|
254 | 251 | return afs_flat_call_destructor(call); |
---|
255 | 252 | } |
---|
256 | 253 | |
---|
.. | .. |
---|
268 | 265 | * Dispatch an operation to get the addresses for a server, where the server is |
---|
269 | 266 | * nominated by UUID. |
---|
270 | 267 | */ |
---|
271 | | -struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *net, |
---|
272 | | - struct afs_addr_cursor *ac, |
---|
273 | | - struct key *key, |
---|
| 268 | +struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *vc, |
---|
274 | 269 | const uuid_t *uuid) |
---|
275 | 270 | { |
---|
276 | 271 | struct afs_ListAddrByAttributes__xdr *r; |
---|
277 | 272 | const struct afs_uuid *u = (const struct afs_uuid *)uuid; |
---|
278 | 273 | struct afs_call *call; |
---|
| 274 | + struct afs_net *net = vc->cell->net; |
---|
279 | 275 | __be32 *bp; |
---|
280 | 276 | int i; |
---|
281 | 277 | |
---|
.. | .. |
---|
287 | 283 | if (!call) |
---|
288 | 284 | return ERR_PTR(-ENOMEM); |
---|
289 | 285 | |
---|
290 | | - call->key = key; |
---|
291 | | - call->reply[0] = NULL; |
---|
292 | | - call->ret_reply0 = true; |
---|
| 286 | + call->key = vc->key; |
---|
| 287 | + call->ret_alist = NULL; |
---|
| 288 | + call->max_lifespan = AFS_VL_MAX_LIFESPAN; |
---|
293 | 289 | |
---|
294 | 290 | /* Marshall the parameters */ |
---|
295 | 291 | bp = call->request; |
---|
.. | .. |
---|
308 | 304 | r->uuid.node[i] = htonl(u->node[i]); |
---|
309 | 305 | |
---|
310 | 306 | trace_afs_make_vl_call(call); |
---|
311 | | - return (struct afs_addr_list *)afs_make_call(ac, call, GFP_KERNEL, false); |
---|
| 307 | + afs_make_call(&vc->ac, call, GFP_KERNEL); |
---|
| 308 | + return (struct afs_addr_list *)afs_wait_for_call_to_complete(call, &vc->ac); |
---|
312 | 309 | } |
---|
313 | 310 | |
---|
314 | 311 | /* |
---|
.. | .. |
---|
319 | 316 | u32 count; |
---|
320 | 317 | int ret; |
---|
321 | 318 | |
---|
322 | | - _enter("{%u,%zu/%u}", call->unmarshall, call->offset, call->count); |
---|
| 319 | + _enter("{%u,%zu/%u}", |
---|
| 320 | + call->unmarshall, iov_iter_count(call->iter), call->count); |
---|
323 | 321 | |
---|
324 | | -again: |
---|
325 | 322 | switch (call->unmarshall) { |
---|
326 | 323 | case 0: |
---|
327 | | - call->offset = 0; |
---|
| 324 | + afs_extract_to_tmp(call); |
---|
328 | 325 | call->unmarshall++; |
---|
329 | 326 | |
---|
330 | | - /* Extract the capabilities word count */ |
---|
| 327 | + fallthrough; /* and extract the capabilities word count */ |
---|
331 | 328 | case 1: |
---|
332 | | - ret = afs_extract_data(call, &call->tmp, |
---|
333 | | - 1 * sizeof(__be32), |
---|
334 | | - true); |
---|
| 329 | + ret = afs_extract_data(call, true); |
---|
335 | 330 | if (ret < 0) |
---|
336 | 331 | return ret; |
---|
337 | 332 | |
---|
338 | 333 | count = ntohl(call->tmp); |
---|
339 | | - |
---|
340 | 334 | call->count = count; |
---|
341 | 335 | call->count2 = count; |
---|
342 | | - call->offset = 0; |
---|
343 | | - call->unmarshall++; |
---|
344 | 336 | |
---|
345 | | - /* Extract capabilities words */ |
---|
| 337 | + call->unmarshall++; |
---|
| 338 | + afs_extract_discard(call, count * sizeof(__be32)); |
---|
| 339 | + |
---|
| 340 | + fallthrough; /* and extract capabilities words */ |
---|
346 | 341 | case 2: |
---|
347 | | - count = min(call->count, 16U); |
---|
348 | | - ret = afs_extract_data(call, call->buffer, |
---|
349 | | - count * sizeof(__be32), |
---|
350 | | - call->count > 16); |
---|
| 342 | + ret = afs_extract_data(call, false); |
---|
351 | 343 | if (ret < 0) |
---|
352 | 344 | return ret; |
---|
353 | 345 | |
---|
354 | 346 | /* TODO: Examine capabilities */ |
---|
355 | 347 | |
---|
356 | | - call->count -= count; |
---|
357 | | - if (call->count > 0) |
---|
358 | | - goto again; |
---|
359 | | - call->offset = 0; |
---|
360 | 348 | call->unmarshall++; |
---|
361 | 349 | break; |
---|
362 | 350 | } |
---|
363 | 351 | |
---|
364 | | - call->reply[0] = (void *)(unsigned long)call->service_id; |
---|
365 | | - |
---|
366 | 352 | _leave(" = 0 [done]"); |
---|
367 | 353 | return 0; |
---|
| 354 | +} |
---|
| 355 | + |
---|
| 356 | +static void afs_destroy_vl_get_capabilities(struct afs_call *call) |
---|
| 357 | +{ |
---|
| 358 | + afs_put_vlserver(call->net, call->vlserver); |
---|
| 359 | + afs_flat_call_destructor(call); |
---|
368 | 360 | } |
---|
369 | 361 | |
---|
370 | 362 | /* |
---|
.. | .. |
---|
374 | 366 | .name = "VL.GetCapabilities", |
---|
375 | 367 | .op = afs_VL_GetCapabilities, |
---|
376 | 368 | .deliver = afs_deliver_vl_get_capabilities, |
---|
377 | | - .destructor = afs_flat_call_destructor, |
---|
| 369 | + .done = afs_vlserver_probe_result, |
---|
| 370 | + .destructor = afs_destroy_vl_get_capabilities, |
---|
378 | 371 | }; |
---|
379 | 372 | |
---|
380 | 373 | /* |
---|
381 | | - * Probe a fileserver for the capabilities that it supports. This can |
---|
| 374 | + * Probe a volume server for the capabilities that it supports. This can |
---|
382 | 375 | * return up to 196 words. |
---|
383 | 376 | * |
---|
384 | 377 | * We use this to probe for service upgrade to determine what the server at the |
---|
385 | 378 | * other end supports. |
---|
386 | 379 | */ |
---|
387 | | -int afs_vl_get_capabilities(struct afs_net *net, |
---|
388 | | - struct afs_addr_cursor *ac, |
---|
389 | | - struct key *key) |
---|
| 380 | +struct afs_call *afs_vl_get_capabilities(struct afs_net *net, |
---|
| 381 | + struct afs_addr_cursor *ac, |
---|
| 382 | + struct key *key, |
---|
| 383 | + struct afs_vlserver *server, |
---|
| 384 | + unsigned int server_index) |
---|
390 | 385 | { |
---|
391 | 386 | struct afs_call *call; |
---|
392 | 387 | __be32 *bp; |
---|
.. | .. |
---|
395 | 390 | |
---|
396 | 391 | call = afs_alloc_flat_call(net, &afs_RXVLGetCapabilities, 1 * 4, 16 * 4); |
---|
397 | 392 | if (!call) |
---|
398 | | - return -ENOMEM; |
---|
| 393 | + return ERR_PTR(-ENOMEM); |
---|
399 | 394 | |
---|
400 | 395 | call->key = key; |
---|
401 | | - call->upgrade = true; /* Let's see if this is a YFS server */ |
---|
402 | | - call->reply[0] = (void *)VLGETCAPABILITIES; |
---|
403 | | - call->ret_reply0 = true; |
---|
| 396 | + call->vlserver = afs_get_vlserver(server); |
---|
| 397 | + call->server_index = server_index; |
---|
| 398 | + call->upgrade = true; |
---|
| 399 | + call->async = true; |
---|
| 400 | + call->max_lifespan = AFS_PROBE_MAX_LIFESPAN; |
---|
404 | 401 | |
---|
405 | 402 | /* marshall the parameters */ |
---|
406 | 403 | bp = call->request; |
---|
.. | .. |
---|
408 | 405 | |
---|
409 | 406 | /* Can't take a ref on server */ |
---|
410 | 407 | trace_afs_make_vl_call(call); |
---|
411 | | - return afs_make_call(ac, call, GFP_KERNEL, false); |
---|
| 408 | + afs_make_call(ac, call, GFP_KERNEL); |
---|
| 409 | + return call; |
---|
412 | 410 | } |
---|
413 | 411 | |
---|
414 | 412 | /* |
---|
.. | .. |
---|
427 | 425 | u32 uniquifier, size; |
---|
428 | 426 | int ret; |
---|
429 | 427 | |
---|
430 | | - _enter("{%u,%zu/%u,%u}", call->unmarshall, call->offset, call->count, call->count2); |
---|
| 428 | + _enter("{%u,%zu,%u}", |
---|
| 429 | + call->unmarshall, iov_iter_count(call->iter), call->count2); |
---|
431 | 430 | |
---|
432 | | -again: |
---|
433 | 431 | switch (call->unmarshall) { |
---|
434 | 432 | case 0: |
---|
435 | | - call->offset = 0; |
---|
| 433 | + afs_extract_to_buf(call, sizeof(uuid_t) + 3 * sizeof(__be32)); |
---|
436 | 434 | call->unmarshall = 1; |
---|
437 | 435 | |
---|
438 | 436 | /* Extract the returned uuid, uniquifier, fsEndpoints count and |
---|
439 | 437 | * either the first fsEndpoint type or the volEndpoints |
---|
440 | 438 | * count if there are no fsEndpoints. */ |
---|
| 439 | + fallthrough; |
---|
441 | 440 | case 1: |
---|
442 | | - ret = afs_extract_data(call, call->buffer, |
---|
443 | | - sizeof(uuid_t) + |
---|
444 | | - 3 * sizeof(__be32), |
---|
445 | | - true); |
---|
| 441 | + ret = afs_extract_data(call, true); |
---|
446 | 442 | if (ret < 0) |
---|
447 | 443 | return ret; |
---|
448 | 444 | |
---|
.. | .. |
---|
452 | 448 | call->count2 = ntohl(*bp); /* Type or next count */ |
---|
453 | 449 | |
---|
454 | 450 | if (call->count > YFS_MAXENDPOINTS) |
---|
455 | | - return afs_protocol_error(call, -EBADMSG); |
---|
| 451 | + return afs_protocol_error(call, afs_eproto_yvl_fsendpt_num); |
---|
456 | 452 | |
---|
457 | 453 | alist = afs_alloc_addrlist(call->count, FS_SERVICE, AFS_FS_PORT); |
---|
458 | 454 | if (!alist) |
---|
459 | 455 | return -ENOMEM; |
---|
460 | 456 | alist->version = uniquifier; |
---|
461 | | - call->reply[0] = alist; |
---|
462 | | - call->offset = 0; |
---|
| 457 | + call->ret_alist = alist; |
---|
463 | 458 | |
---|
464 | 459 | if (call->count == 0) |
---|
465 | 460 | goto extract_volendpoints; |
---|
466 | 461 | |
---|
467 | | - call->unmarshall = 2; |
---|
468 | | - |
---|
469 | | - /* Extract fsEndpoints[] entries */ |
---|
470 | | - case 2: |
---|
| 462 | + next_fsendpoint: |
---|
471 | 463 | switch (call->count2) { |
---|
472 | 464 | case YFS_ENDPOINT_IPV4: |
---|
473 | 465 | size = sizeof(__be32) * (1 + 1 + 1); |
---|
.. | .. |
---|
476 | 468 | size = sizeof(__be32) * (1 + 4 + 1); |
---|
477 | 469 | break; |
---|
478 | 470 | default: |
---|
479 | | - return afs_protocol_error(call, -EBADMSG); |
---|
| 471 | + return afs_protocol_error(call, afs_eproto_yvl_fsendpt_type); |
---|
480 | 472 | } |
---|
481 | 473 | |
---|
482 | 474 | size += sizeof(__be32); |
---|
483 | | - ret = afs_extract_data(call, call->buffer, size, true); |
---|
| 475 | + afs_extract_to_buf(call, size); |
---|
| 476 | + call->unmarshall = 2; |
---|
| 477 | + |
---|
| 478 | + fallthrough; /* and extract fsEndpoints[] entries */ |
---|
| 479 | + case 2: |
---|
| 480 | + ret = afs_extract_data(call, true); |
---|
484 | 481 | if (ret < 0) |
---|
485 | 482 | return ret; |
---|
486 | 483 | |
---|
487 | | - alist = call->reply[0]; |
---|
| 484 | + alist = call->ret_alist; |
---|
488 | 485 | bp = call->buffer; |
---|
489 | 486 | switch (call->count2) { |
---|
490 | 487 | case YFS_ENDPOINT_IPV4: |
---|
491 | 488 | if (ntohl(bp[0]) != sizeof(__be32) * 2) |
---|
492 | | - return afs_protocol_error(call, -EBADMSG); |
---|
| 489 | + return afs_protocol_error( |
---|
| 490 | + call, afs_eproto_yvl_fsendpt4_len); |
---|
493 | 491 | afs_merge_fs_addr4(alist, bp[1], ntohl(bp[2])); |
---|
494 | 492 | bp += 3; |
---|
495 | 493 | break; |
---|
496 | 494 | case YFS_ENDPOINT_IPV6: |
---|
497 | 495 | if (ntohl(bp[0]) != sizeof(__be32) * 5) |
---|
498 | | - return afs_protocol_error(call, -EBADMSG); |
---|
| 496 | + return afs_protocol_error( |
---|
| 497 | + call, afs_eproto_yvl_fsendpt6_len); |
---|
499 | 498 | afs_merge_fs_addr6(alist, bp + 1, ntohl(bp[5])); |
---|
500 | 499 | bp += 6; |
---|
501 | 500 | break; |
---|
502 | 501 | default: |
---|
503 | | - return afs_protocol_error(call, -EBADMSG); |
---|
| 502 | + return afs_protocol_error(call, afs_eproto_yvl_fsendpt_type); |
---|
504 | 503 | } |
---|
505 | 504 | |
---|
506 | 505 | /* Got either the type of the next entry or the count of |
---|
.. | .. |
---|
508 | 507 | */ |
---|
509 | 508 | call->count2 = ntohl(*bp++); |
---|
510 | 509 | |
---|
511 | | - call->offset = 0; |
---|
512 | 510 | call->count--; |
---|
513 | 511 | if (call->count > 0) |
---|
514 | | - goto again; |
---|
| 512 | + goto next_fsendpoint; |
---|
515 | 513 | |
---|
516 | 514 | extract_volendpoints: |
---|
517 | 515 | /* Extract the list of volEndpoints. */ |
---|
.. | .. |
---|
519 | 517 | if (!call->count) |
---|
520 | 518 | goto end; |
---|
521 | 519 | if (call->count > YFS_MAXENDPOINTS) |
---|
522 | | - return afs_protocol_error(call, -EBADMSG); |
---|
| 520 | + return afs_protocol_error(call, afs_eproto_yvl_vlendpt_type); |
---|
523 | 521 | |
---|
| 522 | + afs_extract_to_buf(call, 1 * sizeof(__be32)); |
---|
524 | 523 | call->unmarshall = 3; |
---|
525 | 524 | |
---|
526 | 525 | /* Extract the type of volEndpoints[0]. Normally we would |
---|
527 | 526 | * extract the type of the next endpoint when we extract the |
---|
528 | 527 | * data of the current one, but this is the first... |
---|
529 | 528 | */ |
---|
| 529 | + fallthrough; |
---|
530 | 530 | case 3: |
---|
531 | | - ret = afs_extract_data(call, call->buffer, sizeof(__be32), true); |
---|
| 531 | + ret = afs_extract_data(call, true); |
---|
532 | 532 | if (ret < 0) |
---|
533 | 533 | return ret; |
---|
534 | 534 | |
---|
535 | 535 | bp = call->buffer; |
---|
536 | | - call->count2 = ntohl(*bp++); |
---|
537 | | - call->offset = 0; |
---|
538 | | - call->unmarshall = 4; |
---|
539 | 536 | |
---|
540 | | - /* Extract volEndpoints[] entries */ |
---|
541 | | - case 4: |
---|
| 537 | + next_volendpoint: |
---|
| 538 | + call->count2 = ntohl(*bp++); |
---|
542 | 539 | switch (call->count2) { |
---|
543 | 540 | case YFS_ENDPOINT_IPV4: |
---|
544 | 541 | size = sizeof(__be32) * (1 + 1 + 1); |
---|
.. | .. |
---|
547 | 544 | size = sizeof(__be32) * (1 + 4 + 1); |
---|
548 | 545 | break; |
---|
549 | 546 | default: |
---|
550 | | - return afs_protocol_error(call, -EBADMSG); |
---|
| 547 | + return afs_protocol_error(call, afs_eproto_yvl_vlendpt_type); |
---|
551 | 548 | } |
---|
552 | 549 | |
---|
553 | 550 | if (call->count > 1) |
---|
554 | | - size += sizeof(__be32); |
---|
555 | | - ret = afs_extract_data(call, call->buffer, size, true); |
---|
| 551 | + size += sizeof(__be32); /* Get next type too */ |
---|
| 552 | + afs_extract_to_buf(call, size); |
---|
| 553 | + call->unmarshall = 4; |
---|
| 554 | + |
---|
| 555 | + fallthrough; /* and extract volEndpoints[] entries */ |
---|
| 556 | + case 4: |
---|
| 557 | + ret = afs_extract_data(call, true); |
---|
556 | 558 | if (ret < 0) |
---|
557 | 559 | return ret; |
---|
558 | 560 | |
---|
.. | .. |
---|
560 | 562 | switch (call->count2) { |
---|
561 | 563 | case YFS_ENDPOINT_IPV4: |
---|
562 | 564 | if (ntohl(bp[0]) != sizeof(__be32) * 2) |
---|
563 | | - return afs_protocol_error(call, -EBADMSG); |
---|
| 565 | + return afs_protocol_error( |
---|
| 566 | + call, afs_eproto_yvl_vlendpt4_len); |
---|
564 | 567 | bp += 3; |
---|
565 | 568 | break; |
---|
566 | 569 | case YFS_ENDPOINT_IPV6: |
---|
567 | 570 | if (ntohl(bp[0]) != sizeof(__be32) * 5) |
---|
568 | | - return afs_protocol_error(call, -EBADMSG); |
---|
| 571 | + return afs_protocol_error( |
---|
| 572 | + call, afs_eproto_yvl_vlendpt6_len); |
---|
569 | 573 | bp += 6; |
---|
570 | 574 | break; |
---|
571 | 575 | default: |
---|
572 | | - return afs_protocol_error(call, -EBADMSG); |
---|
| 576 | + return afs_protocol_error(call, afs_eproto_yvl_vlendpt_type); |
---|
573 | 577 | } |
---|
574 | 578 | |
---|
575 | 579 | /* Got either the type of the next entry or the count of |
---|
576 | 580 | * volEndpoints if no more fsEndpoints. |
---|
577 | 581 | */ |
---|
578 | | - call->offset = 0; |
---|
579 | 582 | call->count--; |
---|
580 | | - if (call->count > 0) { |
---|
581 | | - call->count2 = ntohl(*bp++); |
---|
582 | | - goto again; |
---|
583 | | - } |
---|
| 583 | + if (call->count > 0) |
---|
| 584 | + goto next_volendpoint; |
---|
584 | 585 | |
---|
585 | 586 | end: |
---|
| 587 | + afs_extract_discard(call, 0); |
---|
586 | 588 | call->unmarshall = 5; |
---|
587 | 589 | |
---|
588 | | - /* Done */ |
---|
| 590 | + fallthrough; /* Done */ |
---|
589 | 591 | case 5: |
---|
590 | | - ret = afs_extract_data(call, call->buffer, 0, false); |
---|
| 592 | + ret = afs_extract_data(call, false); |
---|
591 | 593 | if (ret < 0) |
---|
592 | 594 | return ret; |
---|
593 | 595 | call->unmarshall = 6; |
---|
.. | .. |
---|
595 | 597 | case 6: |
---|
596 | 598 | break; |
---|
597 | 599 | } |
---|
598 | | - |
---|
599 | | - alist = call->reply[0]; |
---|
600 | | - |
---|
601 | | - /* Start with IPv6 if available. */ |
---|
602 | | - if (alist->nr_ipv4 < alist->nr_addrs) |
---|
603 | | - alist->index = alist->nr_ipv4; |
---|
604 | 600 | |
---|
605 | 601 | _leave(" = 0 [done]"); |
---|
606 | 602 | return 0; |
---|
.. | .. |
---|
620 | 616 | * Dispatch an operation to get the addresses for a server, where the server is |
---|
621 | 617 | * nominated by UUID. |
---|
622 | 618 | */ |
---|
623 | | -struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_net *net, |
---|
624 | | - struct afs_addr_cursor *ac, |
---|
625 | | - struct key *key, |
---|
| 619 | +struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *vc, |
---|
626 | 620 | const uuid_t *uuid) |
---|
627 | 621 | { |
---|
628 | 622 | struct afs_call *call; |
---|
| 623 | + struct afs_net *net = vc->cell->net; |
---|
629 | 624 | __be32 *bp; |
---|
630 | 625 | |
---|
631 | 626 | _enter(""); |
---|
.. | .. |
---|
636 | 631 | if (!call) |
---|
637 | 632 | return ERR_PTR(-ENOMEM); |
---|
638 | 633 | |
---|
639 | | - call->key = key; |
---|
640 | | - call->reply[0] = NULL; |
---|
641 | | - call->ret_reply0 = true; |
---|
| 634 | + call->key = vc->key; |
---|
| 635 | + call->ret_alist = NULL; |
---|
| 636 | + call->max_lifespan = AFS_VL_MAX_LIFESPAN; |
---|
642 | 637 | |
---|
643 | 638 | /* Marshall the parameters */ |
---|
644 | 639 | bp = call->request; |
---|
.. | .. |
---|
647 | 642 | memcpy(bp, uuid, sizeof(*uuid)); /* Type opr_uuid */ |
---|
648 | 643 | |
---|
649 | 644 | trace_afs_make_vl_call(call); |
---|
650 | | - return (struct afs_addr_list *)afs_make_call(ac, call, GFP_KERNEL, false); |
---|
| 645 | + afs_make_call(&vc->ac, call, GFP_KERNEL); |
---|
| 646 | + return (struct afs_addr_list *)afs_wait_for_call_to_complete(call, &vc->ac); |
---|
| 647 | +} |
---|
| 648 | + |
---|
| 649 | +/* |
---|
| 650 | + * Deliver reply data to a YFSVL.GetCellName operation. |
---|
| 651 | + */ |
---|
| 652 | +static int afs_deliver_yfsvl_get_cell_name(struct afs_call *call) |
---|
| 653 | +{ |
---|
| 654 | + char *cell_name; |
---|
| 655 | + u32 namesz, paddedsz; |
---|
| 656 | + int ret; |
---|
| 657 | + |
---|
| 658 | + _enter("{%u,%zu/%u}", |
---|
| 659 | + call->unmarshall, iov_iter_count(call->iter), call->count); |
---|
| 660 | + |
---|
| 661 | + switch (call->unmarshall) { |
---|
| 662 | + case 0: |
---|
| 663 | + afs_extract_to_tmp(call); |
---|
| 664 | + call->unmarshall++; |
---|
| 665 | + |
---|
| 666 | + fallthrough; /* and extract the cell name length */ |
---|
| 667 | + case 1: |
---|
| 668 | + ret = afs_extract_data(call, true); |
---|
| 669 | + if (ret < 0) |
---|
| 670 | + return ret; |
---|
| 671 | + |
---|
| 672 | + namesz = ntohl(call->tmp); |
---|
| 673 | + if (namesz > AFS_MAXCELLNAME) |
---|
| 674 | + return afs_protocol_error(call, afs_eproto_cellname_len); |
---|
| 675 | + paddedsz = (namesz + 3) & ~3; |
---|
| 676 | + call->count = namesz; |
---|
| 677 | + call->count2 = paddedsz - namesz; |
---|
| 678 | + |
---|
| 679 | + cell_name = kmalloc(namesz + 1, GFP_KERNEL); |
---|
| 680 | + if (!cell_name) |
---|
| 681 | + return -ENOMEM; |
---|
| 682 | + cell_name[namesz] = 0; |
---|
| 683 | + call->ret_str = cell_name; |
---|
| 684 | + |
---|
| 685 | + afs_extract_begin(call, cell_name, namesz); |
---|
| 686 | + call->unmarshall++; |
---|
| 687 | + |
---|
| 688 | + fallthrough; /* and extract cell name */ |
---|
| 689 | + case 2: |
---|
| 690 | + ret = afs_extract_data(call, true); |
---|
| 691 | + if (ret < 0) |
---|
| 692 | + return ret; |
---|
| 693 | + |
---|
| 694 | + afs_extract_discard(call, call->count2); |
---|
| 695 | + call->unmarshall++; |
---|
| 696 | + |
---|
| 697 | + fallthrough; /* and extract padding */ |
---|
| 698 | + case 3: |
---|
| 699 | + ret = afs_extract_data(call, false); |
---|
| 700 | + if (ret < 0) |
---|
| 701 | + return ret; |
---|
| 702 | + |
---|
| 703 | + call->unmarshall++; |
---|
| 704 | + break; |
---|
| 705 | + } |
---|
| 706 | + |
---|
| 707 | + _leave(" = 0 [done]"); |
---|
| 708 | + return 0; |
---|
| 709 | +} |
---|
| 710 | + |
---|
| 711 | +static void afs_destroy_yfsvl_get_cell_name(struct afs_call *call) |
---|
| 712 | +{ |
---|
| 713 | + kfree(call->ret_str); |
---|
| 714 | + afs_flat_call_destructor(call); |
---|
| 715 | +} |
---|
| 716 | + |
---|
| 717 | +/* |
---|
| 718 | + * VL.GetCapabilities operation type |
---|
| 719 | + */ |
---|
| 720 | +static const struct afs_call_type afs_YFSVLGetCellName = { |
---|
| 721 | + .name = "YFSVL.GetCellName", |
---|
| 722 | + .op = afs_YFSVL_GetCellName, |
---|
| 723 | + .deliver = afs_deliver_yfsvl_get_cell_name, |
---|
| 724 | + .destructor = afs_destroy_yfsvl_get_cell_name, |
---|
| 725 | +}; |
---|
| 726 | + |
---|
| 727 | +/* |
---|
| 728 | + * Probe a volume server for the capabilities that it supports. This can |
---|
| 729 | + * return up to 196 words. |
---|
| 730 | + * |
---|
| 731 | + * We use this to probe for service upgrade to determine what the server at the |
---|
| 732 | + * other end supports. |
---|
| 733 | + */ |
---|
| 734 | +char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *vc) |
---|
| 735 | +{ |
---|
| 736 | + struct afs_call *call; |
---|
| 737 | + struct afs_net *net = vc->cell->net; |
---|
| 738 | + __be32 *bp; |
---|
| 739 | + |
---|
| 740 | + _enter(""); |
---|
| 741 | + |
---|
| 742 | + call = afs_alloc_flat_call(net, &afs_YFSVLGetCellName, 1 * 4, 0); |
---|
| 743 | + if (!call) |
---|
| 744 | + return ERR_PTR(-ENOMEM); |
---|
| 745 | + |
---|
| 746 | + call->key = vc->key; |
---|
| 747 | + call->ret_str = NULL; |
---|
| 748 | + call->max_lifespan = AFS_VL_MAX_LIFESPAN; |
---|
| 749 | + |
---|
| 750 | + /* marshall the parameters */ |
---|
| 751 | + bp = call->request; |
---|
| 752 | + *bp++ = htonl(YVLGETCELLNAME); |
---|
| 753 | + |
---|
| 754 | + /* Can't take a ref on server */ |
---|
| 755 | + trace_afs_make_vl_call(call); |
---|
| 756 | + afs_make_call(&vc->ac, call, GFP_KERNEL); |
---|
| 757 | + return (char *)afs_wait_for_call_to_complete(call, &vc->ac); |
---|
651 | 758 | } |
---|