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;
31 ret
= afs_transfer_reply(call
);
35 /* unmarshall the reply once we've received all of it */
37 entry
= call
->reply
[0];
39 for (i
= 0; i
< ARRAY_SIZE(uvldb
->name
) - 1; i
++)
40 entry
->name
[i
] = (u8
)ntohl(uvldb
->name
[i
]);
42 entry
->name_len
= strlen(entry
->name
);
44 /* If there is a new replication site that we can use, ignore all the
45 * sites that aren't marked as new.
47 for (i
= 0; i
< AFS_NMAXNSERVERS
; i
++) {
48 tmp
= ntohl(uvldb
->serverFlags
[i
]);
49 if (!(tmp
& AFS_VLSF_DONTUSE
) &&
50 (tmp
& AFS_VLSF_NEWREPSITE
))
54 for (i
= 0; i
< AFS_NMAXNSERVERS
; i
++) {
55 struct afs_uuid__xdr
*xdr
;
56 struct afs_uuid
*uuid
;
59 tmp
= ntohl(uvldb
->serverFlags
[i
]);
60 if (tmp
& AFS_VLSF_DONTUSE
||
61 (new_only
&& !(tmp
& AFS_VLSF_NEWREPSITE
)))
63 if (tmp
& AFS_VLSF_RWVOL
)
64 entry
->fs_mask
[i
] |= AFS_VOL_VTM_RW
;
65 if (tmp
& AFS_VLSF_ROVOL
)
66 entry
->fs_mask
[i
] |= AFS_VOL_VTM_RO
;
67 if (tmp
& AFS_VLSF_BACKVOL
)
68 entry
->fs_mask
[i
] |= AFS_VOL_VTM_BAK
;
69 if (!entry
->fs_mask
[i
])
72 xdr
= &uvldb
->serverNumber
[i
];
73 uuid
= (struct afs_uuid
*)&entry
->fs_server
[i
];
74 uuid
->time_low
= xdr
->time_low
;
75 uuid
->time_mid
= htons(ntohl(xdr
->time_mid
));
76 uuid
->time_hi_and_version
= htons(ntohl(xdr
->time_hi_and_version
));
77 uuid
->clock_seq_hi_and_reserved
= (u8
)ntohl(xdr
->clock_seq_hi_and_reserved
);
78 uuid
->clock_seq_low
= (u8
)ntohl(xdr
->clock_seq_low
);
79 for (j
= 0; j
< 6; j
++)
80 uuid
->node
[j
] = (u8
)ntohl(xdr
->node
[j
]);
85 for (i
= 0; i
< AFS_MAXTYPES
; i
++)
86 entry
->vid
[i
] = ntohl(uvldb
->volumeId
[i
]);
88 tmp
= ntohl(uvldb
->flags
);
89 if (tmp
& AFS_VLF_RWEXISTS
)
90 __set_bit(AFS_VLDB_HAS_RW
, &entry
->flags
);
91 if (tmp
& AFS_VLF_ROEXISTS
)
92 __set_bit(AFS_VLDB_HAS_RO
, &entry
->flags
);
93 if (tmp
& AFS_VLF_BACKEXISTS
)
94 __set_bit(AFS_VLDB_HAS_BAK
, &entry
->flags
);
96 if (!(tmp
& (AFS_VLF_RWEXISTS
| AFS_VLF_ROEXISTS
| AFS_VLF_BACKEXISTS
))) {
97 entry
->error
= -ENOMEDIUM
;
98 __set_bit(AFS_VLDB_QUERY_ERROR
, &entry
->flags
);
101 __set_bit(AFS_VLDB_QUERY_VALID
, &entry
->flags
);
102 _leave(" = 0 [done]");
106 static void afs_destroy_vl_get_entry_by_name_u(struct afs_call
*call
)
108 kfree(call
->reply
[0]);
109 afs_flat_call_destructor(call
);
113 * VL.GetEntryByNameU operation type.
115 static const struct afs_call_type afs_RXVLGetEntryByNameU
= {
116 .name
= "VL.GetEntryByNameU",
117 .op
= afs_VL_GetEntryByNameU
,
118 .deliver
= afs_deliver_vl_get_entry_by_name_u
,
119 .destructor
= afs_destroy_vl_get_entry_by_name_u
,
123 * Dispatch a get volume entry by name or ID operation (uuid variant). If the
124 * volname is a decimal number then it's a volume ID not a volume name.
126 struct afs_vldb_entry
*afs_vl_get_entry_by_name_u(struct afs_net
*net
,
127 struct afs_addr_cursor
*ac
,
132 struct afs_vldb_entry
*entry
;
133 struct afs_call
*call
;
139 padsz
= (4 - (volnamesz
& 3)) & 3;
140 reqsz
= 8 + volnamesz
+ padsz
;
142 entry
= kzalloc(sizeof(struct afs_vldb_entry
), GFP_KERNEL
);
144 return ERR_PTR(-ENOMEM
);
146 call
= afs_alloc_flat_call(net
, &afs_RXVLGetEntryByNameU
, reqsz
,
147 sizeof(struct afs_uvldbentry__xdr
));
150 return ERR_PTR(-ENOMEM
);
154 call
->reply
[0] = entry
;
155 call
->ret_reply0
= true;
157 /* Marshall the parameters */
159 *bp
++ = htonl(VLGETENTRYBYNAMEU
);
160 *bp
++ = htonl(volnamesz
);
161 memcpy(bp
, volname
, volnamesz
);
163 memset((void *)bp
+ volnamesz
, 0, padsz
);
165 trace_afs_make_vl_call(call
);
166 return (struct afs_vldb_entry
*)afs_make_call(ac
, call
, GFP_KERNEL
, false);
170 * Deliver reply data to a VL.GetAddrsU call.
172 * GetAddrsU(IN ListAddrByAttributes *inaddr,
173 * OUT afsUUID *uuidp1,
174 * OUT uint32_t *uniquifier,
175 * OUT uint32_t *nentries,
176 * OUT bulkaddrs *blkaddrs);
178 static int afs_deliver_vl_get_addrs_u(struct afs_call
*call
)
180 struct afs_addr_list
*alist
;
182 u32 uniquifier
, nentries
, count
;
185 _enter("{%u,%zu/%u}", call
->unmarshall
, call
->offset
, call
->count
);
188 switch (call
->unmarshall
) {
193 /* Extract the returned uuid, uniquifier, nentries and blkaddrs size */
195 ret
= afs_extract_data(call
, call
->buffer
,
196 sizeof(struct afs_uuid__xdr
) + 3 * sizeof(__be32
),
201 bp
= call
->buffer
+ sizeof(struct afs_uuid__xdr
);
202 uniquifier
= ntohl(*bp
++);
203 nentries
= ntohl(*bp
++);
206 nentries
= min(nentries
, count
);
207 alist
= afs_alloc_addrlist(nentries
, FS_SERVICE
, AFS_FS_PORT
);
210 alist
->version
= uniquifier
;
211 call
->reply
[0] = alist
;
213 call
->count2
= nentries
;
217 /* Extract entries */
219 count
= min(call
->count
, 4U);
220 ret
= afs_extract_data(call
, call
->buffer
,
221 count
* sizeof(__be32
),
226 alist
= call
->reply
[0];
228 for (i
= 0; i
< count
; i
++)
229 if (alist
->nr_addrs
< call
->count2
)
230 afs_merge_fs_addr4(alist
, *bp
++, AFS_FS_PORT
);
232 call
->count
-= count
;
240 _leave(" = 0 [done]");
244 static void afs_vl_get_addrs_u_destructor(struct afs_call
*call
)
246 afs_put_server(call
->net
, (struct afs_server
*)call
->reply
[0]);
247 kfree(call
->reply
[1]);
248 return afs_flat_call_destructor(call
);
252 * VL.GetAddrsU operation type.
254 static const struct afs_call_type afs_RXVLGetAddrsU
= {
255 .name
= "VL.GetAddrsU",
256 .op
= afs_VL_GetAddrsU
,
257 .deliver
= afs_deliver_vl_get_addrs_u
,
258 .destructor
= afs_vl_get_addrs_u_destructor
,
262 * Dispatch an operation to get the addresses for a server, where the server is
265 struct afs_addr_list
*afs_vl_get_addrs_u(struct afs_net
*net
,
266 struct afs_addr_cursor
*ac
,
270 struct afs_ListAddrByAttributes__xdr
*r
;
271 const struct afs_uuid
*u
= (const struct afs_uuid
*)uuid
;
272 struct afs_call
*call
;
278 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
));
282 return ERR_PTR(-ENOMEM
);
285 call
->reply
[0] = NULL
;
286 call
->ret_reply0
= true;
288 /* Marshall the parameters */
290 *bp
++ = htonl(VLGETADDRSU
);
291 r
= (struct afs_ListAddrByAttributes__xdr
*)bp
;
292 r
->Mask
= htonl(AFS_VLADDR_UUID
);
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
++)
302 r
->uuid
.node
[i
] = ntohl(u
->node
[i
]);
304 trace_afs_make_vl_call(call
);
305 return (struct afs_addr_list
*)afs_make_call(ac
, call
, GFP_KERNEL
, false);
309 * Deliver reply data to an VL.GetCapabilities operation.
311 static int afs_deliver_vl_get_capabilities(struct afs_call
*call
)
316 _enter("{%u,%zu/%u}", call
->unmarshall
, call
->offset
, call
->count
);
319 switch (call
->unmarshall
) {
324 /* Extract the capabilities word count */
326 ret
= afs_extract_data(call
, &call
->tmp
,
332 count
= ntohl(call
->tmp
);
335 call
->count2
= count
;
339 /* Extract capabilities words */
341 count
= min(call
->count
, 16U);
342 ret
= afs_extract_data(call
, call
->buffer
,
343 count
* sizeof(__be32
),
348 /* TODO: Examine capabilities */
350 call
->count
-= count
;
358 call
->reply
[0] = (void *)(unsigned long)call
->service_id
;
360 _leave(" = 0 [done]");
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 .destructor
= afs_flat_call_destructor
,
375 * Probe a fileserver for the capabilities that it supports. This can
376 * return up to 196 words.
378 * We use this to probe for service upgrade to determine what the server at the
379 * other end supports.
381 int afs_vl_get_capabilities(struct afs_net
*net
,
382 struct afs_addr_cursor
*ac
,
385 struct afs_call
*call
;
390 call
= afs_alloc_flat_call(net
, &afs_RXVLGetCapabilities
, 1 * 4, 16 * 4);
395 call
->upgrade
= true; /* Let's see if this is a YFS server */
396 call
->reply
[0] = (void *)VLGETCAPABILITIES
;
397 call
->ret_reply0
= true;
399 /* marshall the parameters */
401 *bp
++ = htonl(VLGETCAPABILITIES
);
403 /* Can't take a ref on server */
404 trace_afs_make_vl_call(call
);
405 return afs_make_call(ac
, call
, GFP_KERNEL
, false);
409 * Deliver reply data to a YFSVL.GetEndpoints call.
411 * GetEndpoints(IN yfsServerAttributes *attr,
412 * OUT opr_uuid *uuid,
413 * OUT afs_int32 *uniquifier,
414 * OUT endpoints *fsEndpoints,
415 * OUT endpoints *volEndpoints)
417 static int afs_deliver_yfsvl_get_endpoints(struct afs_call
*call
)
419 struct afs_addr_list
*alist
;
421 u32 uniquifier
, size
;
424 _enter("{%u,%zu/%u,%u}", call
->unmarshall
, call
->offset
, call
->count
, call
->count2
);
427 switch (call
->unmarshall
) {
430 call
->unmarshall
= 1;
432 /* Extract the returned uuid, uniquifier, fsEndpoints count and
433 * either the first fsEndpoint type or the volEndpoints
434 * count if there are no fsEndpoints. */
436 ret
= afs_extract_data(call
, call
->buffer
,
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 */
448 if (call
->count
> YFS_MAXENDPOINTS
)
451 alist
= afs_alloc_addrlist(call
->count
, FS_SERVICE
, AFS_FS_PORT
);
454 alist
->version
= uniquifier
;
455 call
->reply
[0] = alist
;
458 if (call
->count
== 0)
459 goto extract_volendpoints
;
461 call
->unmarshall
= 2;
463 /* Extract fsEndpoints[] entries */
465 switch (call
->count2
) {
466 case YFS_ENDPOINT_IPV4
:
467 size
= sizeof(__be32
) * (1 + 1 + 1);
469 case YFS_ENDPOINT_IPV6
:
470 size
= sizeof(__be32
) * (1 + 4 + 1);
476 size
+= sizeof(__be32
);
477 ret
= afs_extract_data(call
, call
->buffer
, size
, true);
481 alist
= call
->reply
[0];
483 switch (call
->count2
) {
484 case YFS_ENDPOINT_IPV4
:
485 if (ntohl(bp
[0]) != sizeof(__be32
) * 2)
487 afs_merge_fs_addr4(alist
, bp
[1], ntohl(bp
[2]));
490 case YFS_ENDPOINT_IPV6
:
491 if (ntohl(bp
[0]) != sizeof(__be32
) * 5)
493 afs_merge_fs_addr6(alist
, bp
+ 1, ntohl(bp
[5]));
500 /* Got either the type of the next entry or the count of
501 * volEndpoints if no more fsEndpoints.
503 call
->count2
= htonl(*bp
++);
510 extract_volendpoints
:
511 /* Extract the list of volEndpoints. */
512 call
->count
= call
->count2
;
515 if (call
->count
> YFS_MAXENDPOINTS
)
518 call
->unmarshall
= 3;
520 /* Extract the type of volEndpoints[0]. Normally we would
521 * extract the type of the next endpoint when we extract the
522 * data of the current one, but this is the first...
525 ret
= afs_extract_data(call
, call
->buffer
, sizeof(__be32
), true);
530 call
->count2
= htonl(*bp
++);
532 call
->unmarshall
= 4;
534 /* Extract volEndpoints[] entries */
536 switch (call
->count2
) {
537 case YFS_ENDPOINT_IPV4
:
538 size
= sizeof(__be32
) * (1 + 1 + 1);
540 case YFS_ENDPOINT_IPV6
:
541 size
= sizeof(__be32
) * (1 + 4 + 1);
548 size
+= sizeof(__be32
);
549 ret
= afs_extract_data(call
, call
->buffer
, size
, true);
554 switch (call
->count2
) {
555 case YFS_ENDPOINT_IPV4
:
556 if (ntohl(bp
[0]) != sizeof(__be32
) * 2)
560 case YFS_ENDPOINT_IPV6
:
561 if (ntohl(bp
[0]) != sizeof(__be32
) * 5)
569 /* Got either the type of the next entry or the count of
570 * volEndpoints if no more fsEndpoints.
574 if (call
->count
> 0) {
575 call
->count2
= htonl(*bp
++);
580 call
->unmarshall
= 5;
584 ret
= afs_extract_data(call
, call
->buffer
, 0, false);
587 call
->unmarshall
= 6;
593 alist
= call
->reply
[0];
595 /* Start with IPv6 if available. */
596 if (alist
->nr_ipv4
< alist
->nr_addrs
)
597 alist
->index
= alist
->nr_ipv4
;
599 _leave(" = 0 [done]");
604 * YFSVL.GetEndpoints operation type.
606 static const struct afs_call_type afs_YFSVLGetEndpoints
= {
607 .name
= "YFSVL.GetEndpoints",
608 .op
= afs_YFSVL_GetEndpoints
,
609 .deliver
= afs_deliver_yfsvl_get_endpoints
,
610 .destructor
= afs_vl_get_addrs_u_destructor
,
614 * Dispatch an operation to get the addresses for a server, where the server is
617 struct afs_addr_list
*afs_yfsvl_get_endpoints(struct afs_net
*net
,
618 struct afs_addr_cursor
*ac
,
622 struct afs_call
*call
;
627 call
= afs_alloc_flat_call(net
, &afs_YFSVLGetEndpoints
,
628 sizeof(__be32
) * 2 + sizeof(*uuid
),
629 sizeof(struct in6_addr
) + sizeof(__be32
) * 3);
631 return ERR_PTR(-ENOMEM
);
634 call
->reply
[0] = NULL
;
635 call
->ret_reply0
= true;
637 /* Marshall the parameters */
639 *bp
++ = htonl(YVLGETENDPOINTS
);
640 *bp
++ = htonl(YFS_SERVER_UUID
);
641 memcpy(bp
, uuid
, sizeof(*uuid
)); /* Type opr_uuid */
643 trace_afs_make_vl_call(call
);
644 return (struct afs_addr_list
*)afs_make_call(ac
, call
, GFP_KERNEL
, false);