1 /* AFS Volume Location Service client
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
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.
12 #include <linux/gfp.h>
13 #include <linux/init.h>
14 #include <linux/sched.h>
19 * Deliver reply data to a VL.GetEntryByNameU call.
21 static int afs_deliver_vl_get_entry_by_name_u(struct afs_call *call)
23 struct afs_uvldbentry__xdr *uvldb;
24 struct afs_vldb_entry *entry;
25 bool new_only = false;
26 u32 tmp, nr_servers, vlflags;
31 ret = afs_transfer_reply(call);
35 /* unmarshall the reply once we've received all of it */
37 entry = call->ret_vldb;
39 nr_servers = ntohl(uvldb->nServers);
40 if (nr_servers > AFS_NMAXNSERVERS)
41 nr_servers = AFS_NMAXNSERVERS;
43 for (i = 0; i < ARRAY_SIZE(uvldb->name) - 1; i++)
44 entry->name[i] = (u8)ntohl(uvldb->name[i]);
46 entry->name_len = strlen(entry->name);
48 /* If there is a new replication site that we can use, ignore all the
49 * sites that aren't marked as new.
51 for (i = 0; i < nr_servers; i++) {
52 tmp = ntohl(uvldb->serverFlags[i]);
53 if (!(tmp & AFS_VLSF_DONTUSE) &&
54 (tmp & AFS_VLSF_NEWREPSITE))
58 vlflags = ntohl(uvldb->flags);
59 for (i = 0; i < nr_servers; i++) {
60 struct afs_uuid__xdr *xdr;
61 struct afs_uuid *uuid;
64 tmp = ntohl(uvldb->serverFlags[i]);
65 if (tmp & AFS_VLSF_DONTUSE ||
66 (new_only && !(tmp & AFS_VLSF_NEWREPSITE)))
68 if (tmp & AFS_VLSF_RWVOL) {
69 entry->fs_mask[i] |= AFS_VOL_VTM_RW;
70 if (vlflags & AFS_VLF_BACKEXISTS)
71 entry->fs_mask[i] |= AFS_VOL_VTM_BAK;
73 if (tmp & AFS_VLSF_ROVOL)
74 entry->fs_mask[i] |= AFS_VOL_VTM_RO;
75 if (!entry->fs_mask[i])
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]);
91 for (i = 0; i < AFS_MAXTYPES; i++)
92 entry->vid[i] = ntohl(uvldb->volumeId[i]);
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);
101 if (!(vlflags & (AFS_VLF_RWEXISTS | AFS_VLF_ROEXISTS | AFS_VLF_BACKEXISTS))) {
102 entry->error = -ENOMEDIUM;
103 __set_bit(AFS_VLDB_QUERY_ERROR, &entry->flags);
106 __set_bit(AFS_VLDB_QUERY_VALID, &entry->flags);
107 _leave(" = 0 [done]");
111 static void afs_destroy_vl_get_entry_by_name_u(struct afs_call *call)
113 kfree(call->ret_vldb);
114 afs_flat_call_destructor(call);
118 * VL.GetEntryByNameU operation type.
120 static const struct afs_call_type afs_RXVLGetEntryByNameU = {
121 .name = "VL.GetEntryByNameU",
122 .op = afs_VL_GetEntryByNameU,
123 .deliver = afs_deliver_vl_get_entry_by_name_u,
124 .destructor = afs_destroy_vl_get_entry_by_name_u,
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.
131 struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *vc,
135 struct afs_vldb_entry *entry;
136 struct afs_call *call;
137 struct afs_net *net = vc->cell->net;
143 padsz = (4 - (volnamesz & 3)) & 3;
144 reqsz = 8 + volnamesz + padsz;
146 entry = kzalloc(sizeof(struct afs_vldb_entry), GFP_KERNEL);
148 return ERR_PTR(-ENOMEM);
150 call = afs_alloc_flat_call(net, &afs_RXVLGetEntryByNameU, reqsz,
151 sizeof(struct afs_uvldbentry__xdr));
154 return ERR_PTR(-ENOMEM);
158 call->ret_vldb = entry;
159 call->max_lifespan = AFS_VL_MAX_LIFESPAN;
161 /* Marshall the parameters */
163 *bp++ = htonl(VLGETENTRYBYNAMEU);
164 *bp++ = htonl(volnamesz);
165 memcpy(bp, volname, volnamesz);
167 memset((void *)bp + volnamesz, 0, padsz);
169 trace_afs_make_vl_call(call);
170 afs_make_call(&vc->ac, call, GFP_KERNEL);
171 return (struct afs_vldb_entry *)afs_wait_for_call_to_complete(call, &vc->ac);
175 * Deliver reply data to a VL.GetAddrsU call.
177 * GetAddrsU(IN ListAddrByAttributes *inaddr,
178 * OUT afsUUID *uuidp1,
179 * OUT uint32_t *uniquifier,
180 * OUT uint32_t *nentries,
181 * OUT bulkaddrs *blkaddrs);
183 static int afs_deliver_vl_get_addrs_u(struct afs_call *call)
185 struct afs_addr_list *alist;
187 u32 uniquifier, nentries, count;
190 _enter("{%u,%zu/%u}",
191 call->unmarshall, iov_iter_count(call->_iter), call->count);
193 switch (call->unmarshall) {
195 afs_extract_to_buf(call,
196 sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
199 /* Extract the returned uuid, uniquifier, nentries and
203 ret = afs_extract_data(call, true);
207 bp = call->buffer + sizeof(struct afs_uuid__xdr);
208 uniquifier = ntohl(*bp++);
209 nentries = ntohl(*bp++);
212 nentries = min(nentries, count);
213 alist = afs_alloc_addrlist(nentries, FS_SERVICE, AFS_FS_PORT);
216 alist->version = uniquifier;
217 call->ret_alist = alist;
219 call->count2 = nentries;
223 count = min(call->count, 4U);
224 afs_extract_to_buf(call, count * sizeof(__be32));
226 /* Fall through - and extract entries */
228 ret = afs_extract_data(call, call->count > 4);
232 alist = call->ret_alist;
234 count = min(call->count, 4U);
235 for (i = 0; i < count; i++)
236 if (alist->nr_addrs < call->count2)
237 afs_merge_fs_addr4(alist, *bp++, AFS_FS_PORT);
239 call->count -= count;
246 _leave(" = 0 [done]");
250 static void afs_vl_get_addrs_u_destructor(struct afs_call *call)
252 afs_put_addrlist(call->ret_alist);
253 return afs_flat_call_destructor(call);
257 * VL.GetAddrsU operation type.
259 static const struct afs_call_type afs_RXVLGetAddrsU = {
260 .name = "VL.GetAddrsU",
261 .op = afs_VL_GetAddrsU,
262 .deliver = afs_deliver_vl_get_addrs_u,
263 .destructor = afs_vl_get_addrs_u_destructor,
267 * Dispatch an operation to get the addresses for a server, where the server is
270 struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *vc,
273 struct afs_ListAddrByAttributes__xdr *r;
274 const struct afs_uuid *u = (const struct afs_uuid *)uuid;
275 struct afs_call *call;
276 struct afs_net *net = vc->cell->net;
282 call = afs_alloc_flat_call(net, &afs_RXVLGetAddrsU,
283 sizeof(__be32) + sizeof(struct afs_ListAddrByAttributes__xdr),
284 sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
286 return ERR_PTR(-ENOMEM);
289 call->ret_alist = NULL;
290 call->max_lifespan = AFS_VL_MAX_LIFESPAN;
292 /* Marshall the parameters */
294 *bp++ = htonl(VLGETADDRSU);
295 r = (struct afs_ListAddrByAttributes__xdr *)bp;
296 r->Mask = htonl(AFS_VLADDR_UUID);
300 r->uuid.time_low = u->time_low;
301 r->uuid.time_mid = htonl(ntohs(u->time_mid));
302 r->uuid.time_hi_and_version = htonl(ntohs(u->time_hi_and_version));
303 r->uuid.clock_seq_hi_and_reserved = htonl(u->clock_seq_hi_and_reserved);
304 r->uuid.clock_seq_low = htonl(u->clock_seq_low);
305 for (i = 0; i < 6; i++)
306 r->uuid.node[i] = htonl(u->node[i]);
308 trace_afs_make_vl_call(call);
309 afs_make_call(&vc->ac, call, GFP_KERNEL);
310 return (struct afs_addr_list *)afs_wait_for_call_to_complete(call, &vc->ac);
314 * Deliver reply data to an VL.GetCapabilities operation.
316 static int afs_deliver_vl_get_capabilities(struct afs_call *call)
321 _enter("{%u,%zu/%u}",
322 call->unmarshall, iov_iter_count(call->_iter), call->count);
324 switch (call->unmarshall) {
326 afs_extract_to_tmp(call);
329 /* Fall through - and extract the capabilities word count */
331 ret = afs_extract_data(call, true);
335 count = ntohl(call->tmp);
337 call->count2 = count;
340 afs_extract_discard(call, count * sizeof(__be32));
342 /* Fall through - and extract capabilities words */
344 ret = afs_extract_data(call, false);
348 /* TODO: Examine capabilities */
354 _leave(" = 0 [done]");
358 static void afs_destroy_vl_get_capabilities(struct afs_call *call)
360 afs_put_vlserver(call->net, call->vlserver);
361 afs_flat_call_destructor(call);
365 * VL.GetCapabilities operation type
367 static const struct afs_call_type afs_RXVLGetCapabilities = {
368 .name = "VL.GetCapabilities",
369 .op = afs_VL_GetCapabilities,
370 .deliver = afs_deliver_vl_get_capabilities,
371 .done = afs_vlserver_probe_result,
372 .destructor = afs_destroy_vl_get_capabilities,
376 * Probe a volume server for the capabilities that it supports. This can
377 * return up to 196 words.
379 * We use this to probe for service upgrade to determine what the server at the
380 * other end supports.
382 struct afs_call *afs_vl_get_capabilities(struct afs_net *net,
383 struct afs_addr_cursor *ac,
385 struct afs_vlserver *server,
386 unsigned int server_index)
388 struct afs_call *call;
393 call = afs_alloc_flat_call(net, &afs_RXVLGetCapabilities, 1 * 4, 16 * 4);
395 return ERR_PTR(-ENOMEM);
398 call->vlserver = afs_get_vlserver(server);
399 call->server_index = server_index;
400 call->upgrade = true;
402 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
404 /* marshall the parameters */
406 *bp++ = htonl(VLGETCAPABILITIES);
408 /* Can't take a ref on server */
409 trace_afs_make_vl_call(call);
410 afs_make_call(ac, call, GFP_KERNEL);
415 * Deliver reply data to a YFSVL.GetEndpoints call.
417 * GetEndpoints(IN yfsServerAttributes *attr,
418 * OUT opr_uuid *uuid,
419 * OUT afs_int32 *uniquifier,
420 * OUT endpoints *fsEndpoints,
421 * OUT endpoints *volEndpoints)
423 static int afs_deliver_yfsvl_get_endpoints(struct afs_call *call)
425 struct afs_addr_list *alist;
427 u32 uniquifier, size;
430 _enter("{%u,%zu,%u}",
431 call->unmarshall, iov_iter_count(call->_iter), call->count2);
433 switch (call->unmarshall) {
435 afs_extract_to_buf(call, sizeof(uuid_t) + 3 * sizeof(__be32));
436 call->unmarshall = 1;
438 /* Extract the returned uuid, uniquifier, fsEndpoints count and
439 * either the first fsEndpoint type or the volEndpoints
440 * count if there are no fsEndpoints. */
443 ret = afs_extract_data(call, true);
447 bp = call->buffer + sizeof(uuid_t);
448 uniquifier = ntohl(*bp++);
449 call->count = ntohl(*bp++);
450 call->count2 = ntohl(*bp); /* Type or next count */
452 if (call->count > YFS_MAXENDPOINTS)
453 return afs_protocol_error(call, -EBADMSG,
454 afs_eproto_yvl_fsendpt_num);
456 alist = afs_alloc_addrlist(call->count, FS_SERVICE, AFS_FS_PORT);
459 alist->version = uniquifier;
460 call->ret_alist = alist;
462 if (call->count == 0)
463 goto extract_volendpoints;
466 switch (call->count2) {
467 case YFS_ENDPOINT_IPV4:
468 size = sizeof(__be32) * (1 + 1 + 1);
470 case YFS_ENDPOINT_IPV6:
471 size = sizeof(__be32) * (1 + 4 + 1);
474 return afs_protocol_error(call, -EBADMSG,
475 afs_eproto_yvl_fsendpt_type);
478 size += sizeof(__be32);
479 afs_extract_to_buf(call, size);
480 call->unmarshall = 2;
482 /* Fall through - and extract fsEndpoints[] entries */
484 ret = afs_extract_data(call, true);
488 alist = call->ret_alist;
490 switch (call->count2) {
491 case YFS_ENDPOINT_IPV4:
492 if (ntohl(bp[0]) != sizeof(__be32) * 2)
493 return afs_protocol_error(call, -EBADMSG,
494 afs_eproto_yvl_fsendpt4_len);
495 afs_merge_fs_addr4(alist, bp[1], ntohl(bp[2]));
498 case YFS_ENDPOINT_IPV6:
499 if (ntohl(bp[0]) != sizeof(__be32) * 5)
500 return afs_protocol_error(call, -EBADMSG,
501 afs_eproto_yvl_fsendpt6_len);
502 afs_merge_fs_addr6(alist, bp + 1, ntohl(bp[5]));
506 return afs_protocol_error(call, -EBADMSG,
507 afs_eproto_yvl_fsendpt_type);
510 /* Got either the type of the next entry or the count of
511 * volEndpoints if no more fsEndpoints.
513 call->count2 = ntohl(*bp++);
517 goto next_fsendpoint;
519 extract_volendpoints:
520 /* Extract the list of volEndpoints. */
521 call->count = call->count2;
524 if (call->count > YFS_MAXENDPOINTS)
525 return afs_protocol_error(call, -EBADMSG,
526 afs_eproto_yvl_vlendpt_type);
528 afs_extract_to_buf(call, 1 * sizeof(__be32));
529 call->unmarshall = 3;
531 /* Extract the type of volEndpoints[0]. Normally we would
532 * extract the type of the next endpoint when we extract the
533 * data of the current one, but this is the first...
537 ret = afs_extract_data(call, true);
544 call->count2 = ntohl(*bp++);
545 switch (call->count2) {
546 case YFS_ENDPOINT_IPV4:
547 size = sizeof(__be32) * (1 + 1 + 1);
549 case YFS_ENDPOINT_IPV6:
550 size = sizeof(__be32) * (1 + 4 + 1);
553 return afs_protocol_error(call, -EBADMSG,
554 afs_eproto_yvl_vlendpt_type);
558 size += sizeof(__be32); /* Get next type too */
559 afs_extract_to_buf(call, size);
560 call->unmarshall = 4;
562 /* Fall through - and extract volEndpoints[] entries */
564 ret = afs_extract_data(call, true);
569 switch (call->count2) {
570 case YFS_ENDPOINT_IPV4:
571 if (ntohl(bp[0]) != sizeof(__be32) * 2)
572 return afs_protocol_error(call, -EBADMSG,
573 afs_eproto_yvl_vlendpt4_len);
576 case YFS_ENDPOINT_IPV6:
577 if (ntohl(bp[0]) != sizeof(__be32) * 5)
578 return afs_protocol_error(call, -EBADMSG,
579 afs_eproto_yvl_vlendpt6_len);
583 return afs_protocol_error(call, -EBADMSG,
584 afs_eproto_yvl_vlendpt_type);
587 /* Got either the type of the next entry or the count of
588 * volEndpoints if no more fsEndpoints.
592 goto next_volendpoint;
595 afs_extract_discard(call, 0);
596 call->unmarshall = 5;
598 /* Fall through - Done */
600 ret = afs_extract_data(call, false);
603 call->unmarshall = 6;
609 _leave(" = 0 [done]");
614 * YFSVL.GetEndpoints operation type.
616 static const struct afs_call_type afs_YFSVLGetEndpoints = {
617 .name = "YFSVL.GetEndpoints",
618 .op = afs_YFSVL_GetEndpoints,
619 .deliver = afs_deliver_yfsvl_get_endpoints,
620 .destructor = afs_vl_get_addrs_u_destructor,
624 * Dispatch an operation to get the addresses for a server, where the server is
627 struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *vc,
630 struct afs_call *call;
631 struct afs_net *net = vc->cell->net;
636 call = afs_alloc_flat_call(net, &afs_YFSVLGetEndpoints,
637 sizeof(__be32) * 2 + sizeof(*uuid),
638 sizeof(struct in6_addr) + sizeof(__be32) * 3);
640 return ERR_PTR(-ENOMEM);
643 call->ret_alist = NULL;
644 call->max_lifespan = AFS_VL_MAX_LIFESPAN;
646 /* Marshall the parameters */
648 *bp++ = htonl(YVLGETENDPOINTS);
649 *bp++ = htonl(YFS_SERVER_UUID);
650 memcpy(bp, uuid, sizeof(*uuid)); /* Type opr_uuid */
652 trace_afs_make_vl_call(call);
653 afs_make_call(&vc->ac, call, GFP_KERNEL);
654 return (struct afs_addr_list *)afs_wait_for_call_to_complete(call, &vc->ac);