1 /* AFS Volume Location Service client
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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
->reply
[0];
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
->reply
[0]);
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_net
*net
,
132 struct afs_addr_cursor
*ac
,
137 struct afs_vldb_entry
*entry
;
138 struct afs_call
*call
;
144 padsz
= (4 - (volnamesz
& 3)) & 3;
145 reqsz
= 8 + volnamesz
+ padsz
;
147 entry
= kzalloc(sizeof(struct afs_vldb_entry
), GFP_KERNEL
);
149 return ERR_PTR(-ENOMEM
);
151 call
= afs_alloc_flat_call(net
, &afs_RXVLGetEntryByNameU
, reqsz
,
152 sizeof(struct afs_uvldbentry__xdr
));
155 return ERR_PTR(-ENOMEM
);
159 call
->reply
[0] = entry
;
160 call
->ret_reply0
= true;
162 /* Marshall the parameters */
164 *bp
++ = htonl(VLGETENTRYBYNAMEU
);
165 *bp
++ = htonl(volnamesz
);
166 memcpy(bp
, volname
, volnamesz
);
168 memset((void *)bp
+ volnamesz
, 0, padsz
);
170 trace_afs_make_vl_call(call
);
171 return (struct afs_vldb_entry
*)afs_make_call(ac
, call
, GFP_KERNEL
, false);
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}", call
->unmarshall
, call
->offset
, call
->count
);
193 switch (call
->unmarshall
) {
198 /* Extract the returned uuid, uniquifier, nentries and blkaddrs size */
200 ret
= afs_extract_data(call
, call
->buffer
,
201 sizeof(struct afs_uuid__xdr
) + 3 * sizeof(__be32
),
206 bp
= call
->buffer
+ sizeof(struct afs_uuid__xdr
);
207 uniquifier
= ntohl(*bp
++);
208 nentries
= ntohl(*bp
++);
211 nentries
= min(nentries
, count
);
212 alist
= afs_alloc_addrlist(nentries
, FS_SERVICE
, AFS_FS_PORT
);
215 alist
->version
= uniquifier
;
216 call
->reply
[0] = alist
;
218 call
->count2
= nentries
;
222 /* Extract entries */
224 count
= min(call
->count
, 4U);
225 ret
= afs_extract_data(call
, call
->buffer
,
226 count
* sizeof(__be32
),
231 alist
= call
->reply
[0];
233 for (i
= 0; i
< count
; i
++)
234 if (alist
->nr_addrs
< call
->count2
)
235 afs_merge_fs_addr4(alist
, *bp
++, AFS_FS_PORT
);
237 call
->count
-= count
;
245 _leave(" = 0 [done]");
249 static void afs_vl_get_addrs_u_destructor(struct afs_call
*call
)
251 afs_put_server(call
->net
, (struct afs_server
*)call
->reply
[0]);
252 kfree(call
->reply
[1]);
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_net
*net
,
271 struct afs_addr_cursor
*ac
,
275 struct afs_ListAddrByAttributes__xdr
*r
;
276 const struct afs_uuid
*u
= (const struct afs_uuid
*)uuid
;
277 struct afs_call
*call
;
283 call
= afs_alloc_flat_call(net
, &afs_RXVLGetAddrsU
,
284 sizeof(__be32
) + sizeof(struct afs_ListAddrByAttributes__xdr
),
285 sizeof(struct afs_uuid__xdr
) + 3 * sizeof(__be32
));
287 return ERR_PTR(-ENOMEM
);
290 call
->reply
[0] = NULL
;
291 call
->ret_reply0
= true;
293 /* Marshall the parameters */
295 *bp
++ = htonl(VLGETADDRSU
);
296 r
= (struct afs_ListAddrByAttributes__xdr
*)bp
;
297 r
->Mask
= htonl(AFS_VLADDR_UUID
);
301 r
->uuid
.time_low
= u
->time_low
;
302 r
->uuid
.time_mid
= htonl(ntohs(u
->time_mid
));
303 r
->uuid
.time_hi_and_version
= htonl(ntohs(u
->time_hi_and_version
));
304 r
->uuid
.clock_seq_hi_and_reserved
= htonl(u
->clock_seq_hi_and_reserved
);
305 r
->uuid
.clock_seq_low
= htonl(u
->clock_seq_low
);
306 for (i
= 0; i
< 6; i
++)
307 r
->uuid
.node
[i
] = htonl(u
->node
[i
]);
309 trace_afs_make_vl_call(call
);
310 return (struct afs_addr_list
*)afs_make_call(ac
, call
, GFP_KERNEL
, false);
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}", call
->unmarshall
, call
->offset
, call
->count
);
324 switch (call
->unmarshall
) {
329 /* Extract the capabilities word count */
331 ret
= afs_extract_data(call
, &call
->tmp
,
337 count
= ntohl(call
->tmp
);
340 call
->count2
= count
;
344 /* Extract capabilities words */
346 count
= min(call
->count
, 16U);
347 ret
= afs_extract_data(call
, call
->buffer
,
348 count
* sizeof(__be32
),
353 /* TODO: Examine capabilities */
355 call
->count
-= count
;
363 call
->reply
[0] = (void *)(unsigned long)call
->service_id
;
365 _leave(" = 0 [done]");
370 * VL.GetCapabilities operation type
372 static const struct afs_call_type afs_RXVLGetCapabilities
= {
373 .name
= "VL.GetCapabilities",
374 .op
= afs_VL_GetCapabilities
,
375 .deliver
= afs_deliver_vl_get_capabilities
,
376 .destructor
= afs_flat_call_destructor
,
380 * Probe a fileserver for the capabilities that it supports. This can
381 * return up to 196 words.
383 * We use this to probe for service upgrade to determine what the server at the
384 * other end supports.
386 int afs_vl_get_capabilities(struct afs_net
*net
,
387 struct afs_addr_cursor
*ac
,
390 struct afs_call
*call
;
395 call
= afs_alloc_flat_call(net
, &afs_RXVLGetCapabilities
, 1 * 4, 16 * 4);
400 call
->upgrade
= true; /* Let's see if this is a YFS server */
401 call
->reply
[0] = (void *)VLGETCAPABILITIES
;
402 call
->ret_reply0
= true;
404 /* marshall the parameters */
406 *bp
++ = htonl(VLGETCAPABILITIES
);
408 /* Can't take a ref on server */
409 trace_afs_make_vl_call(call
);
410 return afs_make_call(ac
, call
, GFP_KERNEL
, false);
414 * Deliver reply data to a YFSVL.GetEndpoints call.
416 * GetEndpoints(IN yfsServerAttributes *attr,
417 * OUT opr_uuid *uuid,
418 * OUT afs_int32 *uniquifier,
419 * OUT endpoints *fsEndpoints,
420 * OUT endpoints *volEndpoints)
422 static int afs_deliver_yfsvl_get_endpoints(struct afs_call
*call
)
424 struct afs_addr_list
*alist
;
426 u32 uniquifier
, size
;
429 _enter("{%u,%zu/%u,%u}", call
->unmarshall
, call
->offset
, call
->count
, call
->count2
);
432 switch (call
->unmarshall
) {
435 call
->unmarshall
= 1;
437 /* Extract the returned uuid, uniquifier, fsEndpoints count and
438 * either the first fsEndpoint type or the volEndpoints
439 * count if there are no fsEndpoints. */
441 ret
= afs_extract_data(call
, call
->buffer
,
448 bp
= call
->buffer
+ sizeof(uuid_t
);
449 uniquifier
= ntohl(*bp
++);
450 call
->count
= ntohl(*bp
++);
451 call
->count2
= ntohl(*bp
); /* Type or next count */
453 if (call
->count
> YFS_MAXENDPOINTS
)
454 return afs_protocol_error(call
, -EBADMSG
);
456 alist
= afs_alloc_addrlist(call
->count
, FS_SERVICE
, AFS_FS_PORT
);
459 alist
->version
= uniquifier
;
460 call
->reply
[0] = alist
;
463 if (call
->count
== 0)
464 goto extract_volendpoints
;
466 call
->unmarshall
= 2;
468 /* Extract fsEndpoints[] entries */
470 switch (call
->count2
) {
471 case YFS_ENDPOINT_IPV4
:
472 size
= sizeof(__be32
) * (1 + 1 + 1);
474 case YFS_ENDPOINT_IPV6
:
475 size
= sizeof(__be32
) * (1 + 4 + 1);
478 return afs_protocol_error(call
, -EBADMSG
);
481 size
+= sizeof(__be32
);
482 ret
= afs_extract_data(call
, call
->buffer
, size
, true);
486 alist
= call
->reply
[0];
488 switch (call
->count2
) {
489 case YFS_ENDPOINT_IPV4
:
490 if (ntohl(bp
[0]) != sizeof(__be32
) * 2)
491 return afs_protocol_error(call
, -EBADMSG
);
492 afs_merge_fs_addr4(alist
, bp
[1], ntohl(bp
[2]));
495 case YFS_ENDPOINT_IPV6
:
496 if (ntohl(bp
[0]) != sizeof(__be32
) * 5)
497 return afs_protocol_error(call
, -EBADMSG
);
498 afs_merge_fs_addr6(alist
, bp
+ 1, ntohl(bp
[5]));
502 return afs_protocol_error(call
, -EBADMSG
);
505 /* Got either the type of the next entry or the count of
506 * volEndpoints if no more fsEndpoints.
508 call
->count2
= ntohl(*bp
++);
515 extract_volendpoints
:
516 /* Extract the list of volEndpoints. */
517 call
->count
= call
->count2
;
520 if (call
->count
> YFS_MAXENDPOINTS
)
521 return afs_protocol_error(call
, -EBADMSG
);
523 call
->unmarshall
= 3;
525 /* Extract the type of volEndpoints[0]. Normally we would
526 * extract the type of the next endpoint when we extract the
527 * data of the current one, but this is the first...
530 ret
= afs_extract_data(call
, call
->buffer
, sizeof(__be32
), true);
535 call
->count2
= ntohl(*bp
++);
537 call
->unmarshall
= 4;
539 /* Extract volEndpoints[] entries */
541 switch (call
->count2
) {
542 case YFS_ENDPOINT_IPV4
:
543 size
= sizeof(__be32
) * (1 + 1 + 1);
545 case YFS_ENDPOINT_IPV6
:
546 size
= sizeof(__be32
) * (1 + 4 + 1);
549 return afs_protocol_error(call
, -EBADMSG
);
553 size
+= sizeof(__be32
);
554 ret
= afs_extract_data(call
, call
->buffer
, size
, true);
559 switch (call
->count2
) {
560 case YFS_ENDPOINT_IPV4
:
561 if (ntohl(bp
[0]) != sizeof(__be32
) * 2)
562 return afs_protocol_error(call
, -EBADMSG
);
565 case YFS_ENDPOINT_IPV6
:
566 if (ntohl(bp
[0]) != sizeof(__be32
) * 5)
567 return afs_protocol_error(call
, -EBADMSG
);
571 return afs_protocol_error(call
, -EBADMSG
);
574 /* Got either the type of the next entry or the count of
575 * volEndpoints if no more fsEndpoints.
579 if (call
->count
> 0) {
580 call
->count2
= ntohl(*bp
++);
585 call
->unmarshall
= 5;
589 ret
= afs_extract_data(call
, call
->buffer
, 0, false);
592 call
->unmarshall
= 6;
598 alist
= call
->reply
[0];
600 /* Start with IPv6 if available. */
601 if (alist
->nr_ipv4
< alist
->nr_addrs
)
602 alist
->index
= alist
->nr_ipv4
;
604 _leave(" = 0 [done]");
609 * YFSVL.GetEndpoints operation type.
611 static const struct afs_call_type afs_YFSVLGetEndpoints
= {
612 .name
= "YFSVL.GetEndpoints",
613 .op
= afs_YFSVL_GetEndpoints
,
614 .deliver
= afs_deliver_yfsvl_get_endpoints
,
615 .destructor
= afs_vl_get_addrs_u_destructor
,
619 * Dispatch an operation to get the addresses for a server, where the server is
622 struct afs_addr_list
*afs_yfsvl_get_endpoints(struct afs_net
*net
,
623 struct afs_addr_cursor
*ac
,
627 struct afs_call
*call
;
632 call
= afs_alloc_flat_call(net
, &afs_YFSVLGetEndpoints
,
633 sizeof(__be32
) * 2 + sizeof(*uuid
),
634 sizeof(struct in6_addr
) + sizeof(__be32
) * 3);
636 return ERR_PTR(-ENOMEM
);
639 call
->reply
[0] = NULL
;
640 call
->ret_reply0
= true;
642 /* Marshall the parameters */
644 *bp
++ = htonl(YVLGETENDPOINTS
);
645 *bp
++ = htonl(YFS_SERVER_UUID
);
646 memcpy(bp
, uuid
, sizeof(*uuid
)); /* Type opr_uuid */
648 trace_afs_make_vl_call(call
);
649 return (struct afs_addr_list
*)afs_make_call(ac
, call
, GFP_KERNEL
, false);