vlclient.c 16.3 KB
Newer Older
D
David Howells 已提交
1
/* AFS Volume Location Service client
L
Linus Torvalds 已提交
2 3 4 5 6 7 8 9 10 11
 *
 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells (dhowells@redhat.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */

12
#include <linux/gfp.h>
L
Linus Torvalds 已提交
13 14
#include <linux/init.h>
#include <linux/sched.h>
15
#include "afs_fs.h"
L
Linus Torvalds 已提交
16 17 18
#include "internal.h"

/*
19
 * Deliver reply data to a VL.GetEntryByNameU call.
L
Linus Torvalds 已提交
20
 */
21
static int afs_deliver_vl_get_entry_by_name_u(struct afs_call *call)
L
Linus Torvalds 已提交
22
{
23 24 25
	struct afs_uvldbentry__xdr *uvldb;
	struct afs_vldb_entry *entry;
	bool new_only = false;
26
	u32 tmp, nr_servers, vlflags;
27
	int i, ret;
L
Linus Torvalds 已提交
28

29
	_enter("");
L
Linus Torvalds 已提交
30

31
	ret = afs_transfer_reply(call);
32 33
	if (ret < 0)
		return ret;
L
Linus Torvalds 已提交
34

35
	/* unmarshall the reply once we've received all of it */
36
	uvldb = call->buffer;
37
	entry = call->ret_vldb;
38

D
David Howells 已提交
39 40 41 42
	nr_servers = ntohl(uvldb->nServers);
	if (nr_servers > AFS_NMAXNSERVERS)
		nr_servers = AFS_NMAXNSERVERS;

43 44 45 46 47 48 49 50
	for (i = 0; i < ARRAY_SIZE(uvldb->name) - 1; i++)
		entry->name[i] = (u8)ntohl(uvldb->name[i]);
	entry->name[i] = 0;
	entry->name_len = strlen(entry->name);

	/* If there is a new replication site that we can use, ignore all the
	 * sites that aren't marked as new.
	 */
D
David Howells 已提交
51
	for (i = 0; i < nr_servers; i++) {
52 53 54 55
		tmp = ntohl(uvldb->serverFlags[i]);
		if (!(tmp & AFS_VLSF_DONTUSE) &&
		    (tmp & AFS_VLSF_NEWREPSITE))
			new_only = true;
56
	}
L
Linus Torvalds 已提交
57

58
	vlflags = ntohl(uvldb->flags);
D
David Howells 已提交
59
	for (i = 0; i < nr_servers; i++) {
60 61 62
		struct afs_uuid__xdr *xdr;
		struct afs_uuid *uuid;
		int j;
L
Linus Torvalds 已提交
63

64 65 66 67
		tmp = ntohl(uvldb->serverFlags[i]);
		if (tmp & AFS_VLSF_DONTUSE ||
		    (new_only && !(tmp & AFS_VLSF_NEWREPSITE)))
			continue;
68
		if (tmp & AFS_VLSF_RWVOL) {
69
			entry->fs_mask[i] |= AFS_VOL_VTM_RW;
70 71 72
			if (vlflags & AFS_VLF_BACKEXISTS)
				entry->fs_mask[i] |= AFS_VOL_VTM_BAK;
		}
L
Linus Torvalds 已提交
73
		if (tmp & AFS_VLSF_ROVOL)
74 75 76 77 78 79 80 81 82 83 84 85 86
			entry->fs_mask[i] |= AFS_VOL_VTM_RO;
		if (!entry->fs_mask[i])
			continue;

		xdr = &uvldb->serverNumber[i];
		uuid = (struct afs_uuid *)&entry->fs_server[i];
		uuid->time_low			= xdr->time_low;
		uuid->time_mid			= htons(ntohl(xdr->time_mid));
		uuid->time_hi_and_version	= htons(ntohl(xdr->time_hi_and_version));
		uuid->clock_seq_hi_and_reserved	= (u8)ntohl(xdr->clock_seq_hi_and_reserved);
		uuid->clock_seq_low		= (u8)ntohl(xdr->clock_seq_low);
		for (j = 0; j < 6; j++)
			uuid->node[j] = (u8)ntohl(xdr->node[j]);
L
Linus Torvalds 已提交
87

88 89
		entry->nr_servers++;
	}
L
Linus Torvalds 已提交
90

91 92
	for (i = 0; i < AFS_MAXTYPES; i++)
		entry->vid[i] = ntohl(uvldb->volumeId[i]);
L
Linus Torvalds 已提交
93

94
	if (vlflags & AFS_VLF_RWEXISTS)
95
		__set_bit(AFS_VLDB_HAS_RW, &entry->flags);
96
	if (vlflags & AFS_VLF_ROEXISTS)
97
		__set_bit(AFS_VLDB_HAS_RO, &entry->flags);
98
	if (vlflags & AFS_VLF_BACKEXISTS)
99
		__set_bit(AFS_VLDB_HAS_BAK, &entry->flags);
100

101
	if (!(vlflags & (AFS_VLF_RWEXISTS | AFS_VLF_ROEXISTS | AFS_VLF_BACKEXISTS))) {
102 103 104 105 106
		entry->error = -ENOMEDIUM;
		__set_bit(AFS_VLDB_QUERY_ERROR, &entry->flags);
	}

	__set_bit(AFS_VLDB_QUERY_VALID, &entry->flags);
107 108
	_leave(" = 0 [done]");
	return 0;
D
David Howells 已提交
109
}
L
Linus Torvalds 已提交
110

111 112
static void afs_destroy_vl_get_entry_by_name_u(struct afs_call *call)
{
113
	kfree(call->ret_vldb);
114 115
	afs_flat_call_destructor(call);
}
L
Linus Torvalds 已提交
116

117
/*
118
 * VL.GetEntryByNameU operation type.
119
 */
120 121
static const struct afs_call_type afs_RXVLGetEntryByNameU = {
	.name		= "VL.GetEntryByNameU",
122
	.op		= afs_VL_GetEntryByNameU,
123 124
	.deliver	= afs_deliver_vl_get_entry_by_name_u,
	.destructor	= afs_destroy_vl_get_entry_by_name_u,
125
};
L
Linus Torvalds 已提交
126 127

/*
128 129
 * Dispatch a get volume entry by name or ID operation (uuid variant).  If the
 * volname is a decimal number then it's a volume ID not a volume name.
L
Linus Torvalds 已提交
130
 */
D
David Howells 已提交
131
struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *vc,
132 133
						  const char *volname,
						  int volnamesz)
L
Linus Torvalds 已提交
134
{
135
	struct afs_vldb_entry *entry;
136
	struct afs_call *call;
D
David Howells 已提交
137
	struct afs_net *net = vc->cell->net;
138
	size_t reqsz, padsz;
139
	__be32 *bp;
L
Linus Torvalds 已提交
140

141
	_enter("");
L
Linus Torvalds 已提交
142

143 144
	padsz = (4 - (volnamesz & 3)) & 3;
	reqsz = 8 + volnamesz + padsz;
L
Linus Torvalds 已提交
145

146 147 148 149 150 151 152 153 154 155
	entry = kzalloc(sizeof(struct afs_vldb_entry), GFP_KERNEL);
	if (!entry)
		return ERR_PTR(-ENOMEM);

	call = afs_alloc_flat_call(net, &afs_RXVLGetEntryByNameU, reqsz,
				   sizeof(struct afs_uvldbentry__xdr));
	if (!call) {
		kfree(entry);
		return ERR_PTR(-ENOMEM);
	}
L
Linus Torvalds 已提交
156

D
David Howells 已提交
157
	call->key = vc->key;
158
	call->ret_vldb = entry;
159
	call->max_lifespan = AFS_VL_MAX_LIFESPAN;
L
Linus Torvalds 已提交
160

161
	/* Marshall the parameters */
162
	bp = call->request;
163
	*bp++ = htonl(VLGETENTRYBYNAMEU);
164 165 166
	*bp++ = htonl(volnamesz);
	memcpy(bp, volname, volnamesz);
	if (padsz > 0)
167
		memset((void *)bp + volnamesz, 0, padsz);
168

169
	trace_afs_make_vl_call(call);
170 171
	afs_make_call(&vc->ac, call, GFP_KERNEL);
	return (struct afs_vldb_entry *)afs_wait_for_call_to_complete(call, &vc->ac);
D
David Howells 已提交
172
}
L
Linus Torvalds 已提交
173 174

/*
175 176 177 178 179 180 181
 * Deliver reply data to a VL.GetAddrsU call.
 *
 *	GetAddrsU(IN ListAddrByAttributes *inaddr,
 *		  OUT afsUUID *uuidp1,
 *		  OUT uint32_t *uniquifier,
 *		  OUT uint32_t *nentries,
 *		  OUT bulkaddrs *blkaddrs);
L
Linus Torvalds 已提交
182
 */
183
static int afs_deliver_vl_get_addrs_u(struct afs_call *call)
L
Linus Torvalds 已提交
184
{
185 186 187 188 189
	struct afs_addr_list *alist;
	__be32 *bp;
	u32 uniquifier, nentries, count;
	int i, ret;

190 191
	_enter("{%u,%zu/%u}",
	       call->unmarshall, iov_iter_count(call->_iter), call->count);
192 193 194

	switch (call->unmarshall) {
	case 0:
195 196
		afs_extract_to_buf(call,
				   sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
197 198
		call->unmarshall++;

199 200 201
		/* Extract the returned uuid, uniquifier, nentries and
		 * blkaddrs size */
		/* Fall through */
202
	case 1:
203
		ret = afs_extract_data(call, true);
204 205 206 207 208 209 210 211 212 213 214 215 216
		if (ret < 0)
			return ret;

		bp = call->buffer + sizeof(struct afs_uuid__xdr);
		uniquifier	= ntohl(*bp++);
		nentries	= ntohl(*bp++);
		count		= ntohl(*bp);

		nentries = min(nentries, count);
		alist = afs_alloc_addrlist(nentries, FS_SERVICE, AFS_FS_PORT);
		if (!alist)
			return -ENOMEM;
		alist->version = uniquifier;
217
		call->ret_alist = alist;
218 219 220 221
		call->count = count;
		call->count2 = nentries;
		call->unmarshall++;

222 223 224 225
	more_entries:
		count = min(call->count, 4U);
		afs_extract_to_buf(call, count * sizeof(__be32));

226
		/* Fall through - and extract entries */
227
	case 2:
228
		ret = afs_extract_data(call, call->count > 4);
229 230 231
		if (ret < 0)
			return ret;

232
		alist = call->ret_alist;
233
		bp = call->buffer;
234
		count = min(call->count, 4U);
235 236
		for (i = 0; i < count; i++)
			if (alist->nr_addrs < call->count2)
237
				afs_merge_fs_addr4(alist, *bp++, AFS_FS_PORT);
238 239 240

		call->count -= count;
		if (call->count > 0)
241
			goto more_entries;
242 243 244 245 246 247 248 249 250 251
		call->unmarshall++;
		break;
	}

	_leave(" = 0 [done]");
	return 0;
}

static void afs_vl_get_addrs_u_destructor(struct afs_call *call)
{
252
	afs_put_addrlist(call->ret_alist);
253 254 255 256 257 258 259 260
	return afs_flat_call_destructor(call);
}

/*
 * VL.GetAddrsU operation type.
 */
static const struct afs_call_type afs_RXVLGetAddrsU = {
	.name		= "VL.GetAddrsU",
261
	.op		= afs_VL_GetAddrsU,
262 263 264 265 266 267 268 269
	.deliver	= afs_deliver_vl_get_addrs_u,
	.destructor	= afs_vl_get_addrs_u_destructor,
};

/*
 * Dispatch an operation to get the addresses for a server, where the server is
 * nominated by UUID.
 */
D
David Howells 已提交
270
struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *vc,
271 272 273 274
					 const uuid_t *uuid)
{
	struct afs_ListAddrByAttributes__xdr *r;
	const struct afs_uuid *u = (const struct afs_uuid *)uuid;
275
	struct afs_call *call;
D
David Howells 已提交
276
	struct afs_net *net = vc->cell->net;
L
Linus Torvalds 已提交
277
	__be32 *bp;
278
	int i;
L
Linus Torvalds 已提交
279

280
	_enter("");
L
Linus Torvalds 已提交
281

282 283 284
	call = afs_alloc_flat_call(net, &afs_RXVLGetAddrsU,
				   sizeof(__be32) + sizeof(struct afs_ListAddrByAttributes__xdr),
				   sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
285
	if (!call)
286
		return ERR_PTR(-ENOMEM);
L
Linus Torvalds 已提交
287

D
David Howells 已提交
288
	call->key = vc->key;
289
	call->ret_alist = NULL;
290
	call->max_lifespan = AFS_VL_MAX_LIFESPAN;
L
Linus Torvalds 已提交
291

292
	/* Marshall the parameters */
293
	bp = call->request;
294 295 296 297 298 299 300 301 302 303 304 305
	*bp++ = htonl(VLGETADDRSU);
	r = (struct afs_ListAddrByAttributes__xdr *)bp;
	r->Mask		= htonl(AFS_VLADDR_UUID);
	r->ipaddr	= 0;
	r->index	= 0;
	r->spare	= 0;
	r->uuid.time_low			= u->time_low;
	r->uuid.time_mid			= htonl(ntohs(u->time_mid));
	r->uuid.time_hi_and_version		= htonl(ntohs(u->time_hi_and_version));
	r->uuid.clock_seq_hi_and_reserved 	= htonl(u->clock_seq_hi_and_reserved);
	r->uuid.clock_seq_low			= htonl(u->clock_seq_low);
	for (i = 0; i < 6; i++)
D
David Howells 已提交
306
		r->uuid.node[i] = htonl(u->node[i]);
L
Linus Torvalds 已提交
307

308
	trace_afs_make_vl_call(call);
309 310
	afs_make_call(&vc->ac, call, GFP_KERNEL);
	return (struct afs_addr_list *)afs_wait_for_call_to_complete(call, &vc->ac);
D
David Howells 已提交
311
}
312 313 314 315 316 317 318 319 320

/*
 * Deliver reply data to an VL.GetCapabilities operation.
 */
static int afs_deliver_vl_get_capabilities(struct afs_call *call)
{
	u32 count;
	int ret;

321 322
	_enter("{%u,%zu/%u}",
	       call->unmarshall, iov_iter_count(call->_iter), call->count);
323 324 325

	switch (call->unmarshall) {
	case 0:
326
		afs_extract_to_tmp(call);
327 328
		call->unmarshall++;

329
		/* Fall through - and extract the capabilities word count */
330
	case 1:
331
		ret = afs_extract_data(call, true);
332 333 334 335 336 337
		if (ret < 0)
			return ret;

		count = ntohl(call->tmp);
		call->count = count;
		call->count2 = count;
338

339
		call->unmarshall++;
340
		afs_extract_discard(call, count * sizeof(__be32));
341

342
		/* Fall through - and extract capabilities words */
343
	case 2:
344
		ret = afs_extract_data(call, false);
345 346 347 348 349 350 351 352 353 354 355 356 357
		if (ret < 0)
			return ret;

		/* TODO: Examine capabilities */

		call->unmarshall++;
		break;
	}

	_leave(" = 0 [done]");
	return 0;
}

358 359
static void afs_destroy_vl_get_capabilities(struct afs_call *call)
{
360
	afs_put_vlserver(call->net, call->vlserver);
361 362 363
	afs_flat_call_destructor(call);
}

364 365 366 367 368
/*
 * VL.GetCapabilities operation type
 */
static const struct afs_call_type afs_RXVLGetCapabilities = {
	.name		= "VL.GetCapabilities",
369
	.op		= afs_VL_GetCapabilities,
370
	.deliver	= afs_deliver_vl_get_capabilities,
371 372
	.done		= afs_vlserver_probe_result,
	.destructor	= afs_destroy_vl_get_capabilities,
373 374 375
};

/*
D
David Howells 已提交
376
 * Probe a volume server for the capabilities that it supports.  This can
377 378 379 380 381
 * return up to 196 words.
 *
 * We use this to probe for service upgrade to determine what the server at the
 * other end supports.
 */
382 383 384 385 386
struct afs_call *afs_vl_get_capabilities(struct afs_net *net,
					 struct afs_addr_cursor *ac,
					 struct key *key,
					 struct afs_vlserver *server,
					 unsigned int server_index)
387 388 389 390 391 392 393 394
{
	struct afs_call *call;
	__be32 *bp;

	_enter("");

	call = afs_alloc_flat_call(net, &afs_RXVLGetCapabilities, 1 * 4, 16 * 4);
	if (!call)
395
		return ERR_PTR(-ENOMEM);
396 397

	call->key = key;
398 399
	call->vlserver = afs_get_vlserver(server);
	call->server_index = server_index;
400
	call->upgrade = true;
401
	call->async = true;
402
	call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
403 404 405 406 407 408

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(VLGETCAPABILITIES);

	/* Can't take a ref on server */
409
	trace_afs_make_vl_call(call);
410 411
	afs_make_call(ac, call, GFP_KERNEL);
	return call;
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
}

/*
 * Deliver reply data to a YFSVL.GetEndpoints call.
 *
 *	GetEndpoints(IN yfsServerAttributes *attr,
 *		     OUT opr_uuid *uuid,
 *		     OUT afs_int32 *uniquifier,
 *		     OUT endpoints *fsEndpoints,
 *		     OUT endpoints *volEndpoints)
 */
static int afs_deliver_yfsvl_get_endpoints(struct afs_call *call)
{
	struct afs_addr_list *alist;
	__be32 *bp;
	u32 uniquifier, size;
	int ret;

430 431
	_enter("{%u,%zu,%u}",
	       call->unmarshall, iov_iter_count(call->_iter), call->count2);
432 433 434

	switch (call->unmarshall) {
	case 0:
435
		afs_extract_to_buf(call, sizeof(uuid_t) + 3 * sizeof(__be32));
436 437 438 439 440
		call->unmarshall = 1;

		/* Extract the returned uuid, uniquifier, fsEndpoints count and
		 * either the first fsEndpoint type or the volEndpoints
		 * count if there are no fsEndpoints. */
441
		/* Fall through */
442
	case 1:
443
		ret = afs_extract_data(call, true);
444 445 446 447 448 449 450 451 452
		if (ret < 0)
			return ret;

		bp = call->buffer + sizeof(uuid_t);
		uniquifier	= ntohl(*bp++);
		call->count	= ntohl(*bp++);
		call->count2	= ntohl(*bp); /* Type or next count */

		if (call->count > YFS_MAXENDPOINTS)
453 454
			return afs_protocol_error(call, -EBADMSG,
						  afs_eproto_yvl_fsendpt_num);
455 456 457 458 459

		alist = afs_alloc_addrlist(call->count, FS_SERVICE, AFS_FS_PORT);
		if (!alist)
			return -ENOMEM;
		alist->version = uniquifier;
460
		call->ret_alist = alist;
461 462 463 464

		if (call->count == 0)
			goto extract_volendpoints;

465
	next_fsendpoint:
466 467 468 469 470 471 472 473
		switch (call->count2) {
		case YFS_ENDPOINT_IPV4:
			size = sizeof(__be32) * (1 + 1 + 1);
			break;
		case YFS_ENDPOINT_IPV6:
			size = sizeof(__be32) * (1 + 4 + 1);
			break;
		default:
474 475
			return afs_protocol_error(call, -EBADMSG,
						  afs_eproto_yvl_fsendpt_type);
476 477 478
		}

		size += sizeof(__be32);
479 480 481
		afs_extract_to_buf(call, size);
		call->unmarshall = 2;

482
		/* Fall through - and extract fsEndpoints[] entries */
483 484
	case 2:
		ret = afs_extract_data(call, true);
485 486 487
		if (ret < 0)
			return ret;

488
		alist = call->ret_alist;
489 490 491 492
		bp = call->buffer;
		switch (call->count2) {
		case YFS_ENDPOINT_IPV4:
			if (ntohl(bp[0]) != sizeof(__be32) * 2)
493 494
				return afs_protocol_error(call, -EBADMSG,
							  afs_eproto_yvl_fsendpt4_len);
495 496 497 498 499
			afs_merge_fs_addr4(alist, bp[1], ntohl(bp[2]));
			bp += 3;
			break;
		case YFS_ENDPOINT_IPV6:
			if (ntohl(bp[0]) != sizeof(__be32) * 5)
500 501
				return afs_protocol_error(call, -EBADMSG,
							  afs_eproto_yvl_fsendpt6_len);
502 503 504 505
			afs_merge_fs_addr6(alist, bp + 1, ntohl(bp[5]));
			bp += 6;
			break;
		default:
506 507
			return afs_protocol_error(call, -EBADMSG,
						  afs_eproto_yvl_fsendpt_type);
508 509 510 511 512
		}

		/* Got either the type of the next entry or the count of
		 * volEndpoints if no more fsEndpoints.
		 */
D
David Howells 已提交
513
		call->count2 = ntohl(*bp++);
514 515 516

		call->count--;
		if (call->count > 0)
517
			goto next_fsendpoint;
518 519 520 521 522 523 524

	extract_volendpoints:
		/* Extract the list of volEndpoints. */
		call->count = call->count2;
		if (!call->count)
			goto end;
		if (call->count > YFS_MAXENDPOINTS)
525 526
			return afs_protocol_error(call, -EBADMSG,
						  afs_eproto_yvl_vlendpt_type);
527

528
		afs_extract_to_buf(call, 1 * sizeof(__be32));
529 530 531 532 533 534
		call->unmarshall = 3;

		/* Extract the type of volEndpoints[0].  Normally we would
		 * extract the type of the next endpoint when we extract the
		 * data of the current one, but this is the first...
		 */
535
		/* Fall through */
536
	case 3:
537
		ret = afs_extract_data(call, true);
538 539 540 541 542
		if (ret < 0)
			return ret;

		bp = call->buffer;

543 544
	next_volendpoint:
		call->count2 = ntohl(*bp++);
545 546 547 548 549 550 551 552
		switch (call->count2) {
		case YFS_ENDPOINT_IPV4:
			size = sizeof(__be32) * (1 + 1 + 1);
			break;
		case YFS_ENDPOINT_IPV6:
			size = sizeof(__be32) * (1 + 4 + 1);
			break;
		default:
553 554
			return afs_protocol_error(call, -EBADMSG,
						  afs_eproto_yvl_vlendpt_type);
555 556 557
		}

		if (call->count > 1)
558 559 560 561
			size += sizeof(__be32); /* Get next type too */
		afs_extract_to_buf(call, size);
		call->unmarshall = 4;

562
		/* Fall through - and extract volEndpoints[] entries */
563 564
	case 4:
		ret = afs_extract_data(call, true);
565 566 567 568 569 570 571
		if (ret < 0)
			return ret;

		bp = call->buffer;
		switch (call->count2) {
		case YFS_ENDPOINT_IPV4:
			if (ntohl(bp[0]) != sizeof(__be32) * 2)
572 573
				return afs_protocol_error(call, -EBADMSG,
							  afs_eproto_yvl_vlendpt4_len);
574 575 576 577
			bp += 3;
			break;
		case YFS_ENDPOINT_IPV6:
			if (ntohl(bp[0]) != sizeof(__be32) * 5)
578 579
				return afs_protocol_error(call, -EBADMSG,
							  afs_eproto_yvl_vlendpt6_len);
580 581 582
			bp += 6;
			break;
		default:
583 584
			return afs_protocol_error(call, -EBADMSG,
						  afs_eproto_yvl_vlendpt_type);
585 586 587 588 589 590
		}

		/* Got either the type of the next entry or the count of
		 * volEndpoints if no more fsEndpoints.
		 */
		call->count--;
591 592
		if (call->count > 0)
			goto next_volendpoint;
593 594

	end:
595
		afs_extract_discard(call, 0);
596 597
		call->unmarshall = 5;

598
		/* Fall through - Done */
599
	case 5:
600
		ret = afs_extract_data(call, false);
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
		if (ret < 0)
			return ret;
		call->unmarshall = 6;

	case 6:
		break;
	}

	_leave(" = 0 [done]");
	return 0;
}

/*
 * YFSVL.GetEndpoints operation type.
 */
static const struct afs_call_type afs_YFSVLGetEndpoints = {
617 618
	.name		= "YFSVL.GetEndpoints",
	.op		= afs_YFSVL_GetEndpoints,
619 620 621 622 623 624 625 626
	.deliver	= afs_deliver_yfsvl_get_endpoints,
	.destructor	= afs_vl_get_addrs_u_destructor,
};

/*
 * Dispatch an operation to get the addresses for a server, where the server is
 * nominated by UUID.
 */
D
David Howells 已提交
627
struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *vc,
628 629 630
					      const uuid_t *uuid)
{
	struct afs_call *call;
D
David Howells 已提交
631
	struct afs_net *net = vc->cell->net;
632 633 634 635 636 637 638 639 640 641
	__be32 *bp;

	_enter("");

	call = afs_alloc_flat_call(net, &afs_YFSVLGetEndpoints,
				   sizeof(__be32) * 2 + sizeof(*uuid),
				   sizeof(struct in6_addr) + sizeof(__be32) * 3);
	if (!call)
		return ERR_PTR(-ENOMEM);

D
David Howells 已提交
642
	call->key = vc->key;
643
	call->ret_alist = NULL;
644
	call->max_lifespan = AFS_VL_MAX_LIFESPAN;
645 646 647 648 649 650 651

	/* Marshall the parameters */
	bp = call->request;
	*bp++ = htonl(YVLGETENDPOINTS);
	*bp++ = htonl(YFS_SERVER_UUID);
	memcpy(bp, uuid, sizeof(*uuid)); /* Type opr_uuid */

652
	trace_afs_make_vl_call(call);
653 654
	afs_make_call(&vc->ac, call, GFP_KERNEL);
	return (struct afs_addr_list *)afs_wait_for_call_to_complete(call, &vc->ac);
655
}