]>
Commit | Line | Data |
---|---|---|
ec26815a | 1 | /* AFS Volume Location Service client |
1da177e4 LT |
2 | * |
3 | * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. | |
4 | * Written by David Howells ([email protected]) | |
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 | */ | |
11 | ||
5a0e3ad6 | 12 | #include <linux/gfp.h> |
1da177e4 LT |
13 | #include <linux/init.h> |
14 | #include <linux/sched.h> | |
1da177e4 LT |
15 | #include "internal.h" |
16 | ||
1da177e4 | 17 | /* |
08e0e7c8 | 18 | * map volume locator abort codes to error codes |
1da177e4 | 19 | */ |
08e0e7c8 | 20 | static int afs_vl_abort_to_error(u32 abort_code) |
1da177e4 | 21 | { |
08e0e7c8 DH |
22 | _enter("%u", abort_code); |
23 | ||
24 | switch (abort_code) { | |
25 | case AFSVL_IDEXIST: return -EEXIST; | |
26 | case AFSVL_IO: return -EREMOTEIO; | |
27 | case AFSVL_NAMEEXIST: return -EEXIST; | |
28 | case AFSVL_CREATEFAIL: return -EREMOTEIO; | |
29 | case AFSVL_NOENT: return -ENOMEDIUM; | |
30 | case AFSVL_EMPTY: return -ENOMEDIUM; | |
31 | case AFSVL_ENTDELETED: return -ENOMEDIUM; | |
32 | case AFSVL_BADNAME: return -EINVAL; | |
33 | case AFSVL_BADINDEX: return -EINVAL; | |
34 | case AFSVL_BADVOLTYPE: return -EINVAL; | |
35 | case AFSVL_BADSERVER: return -EINVAL; | |
36 | case AFSVL_BADPARTITION: return -EINVAL; | |
37 | case AFSVL_REPSFULL: return -EFBIG; | |
38 | case AFSVL_NOREPSERVER: return -ENOENT; | |
39 | case AFSVL_DUPREPSERVER: return -EEXIST; | |
40 | case AFSVL_RWNOTFOUND: return -ENOENT; | |
41 | case AFSVL_BADREFCOUNT: return -EINVAL; | |
42 | case AFSVL_SIZEEXCEEDED: return -EINVAL; | |
43 | case AFSVL_BADENTRY: return -EINVAL; | |
44 | case AFSVL_BADVOLIDBUMP: return -EINVAL; | |
45 | case AFSVL_IDALREADYHASHED: return -EINVAL; | |
46 | case AFSVL_ENTRYLOCKED: return -EBUSY; | |
47 | case AFSVL_BADVOLOPER: return -EBADRQC; | |
48 | case AFSVL_BADRELLOCKTYPE: return -EINVAL; | |
49 | case AFSVL_RERELEASE: return -EREMOTEIO; | |
50 | case AFSVL_BADSERVERFLAG: return -EINVAL; | |
51 | case AFSVL_PERM: return -EACCES; | |
52 | case AFSVL_NOMEM: return -EREMOTEIO; | |
1da177e4 | 53 | default: |
08e0e7c8 | 54 | return afs_abort_to_error(abort_code); |
1da177e4 | 55 | } |
ec26815a | 56 | } |
1da177e4 | 57 | |
1da177e4 | 58 | /* |
08e0e7c8 | 59 | * deliver reply data to a VL.GetEntryByXXX call |
1da177e4 | 60 | */ |
d001648e | 61 | static int afs_deliver_vl_get_entry_by_xxx(struct afs_call *call) |
1da177e4 | 62 | { |
08e0e7c8 DH |
63 | struct afs_cache_vlocation *entry; |
64 | __be32 *bp; | |
65 | u32 tmp; | |
372ee163 | 66 | int loop, ret; |
1da177e4 | 67 | |
d001648e | 68 | _enter(""); |
1da177e4 | 69 | |
d001648e | 70 | ret = afs_transfer_reply(call); |
372ee163 DH |
71 | if (ret < 0) |
72 | return ret; | |
1da177e4 | 73 | |
08e0e7c8 DH |
74 | /* unmarshall the reply once we've received all of it */ |
75 | entry = call->reply; | |
76 | bp = call->buffer; | |
1da177e4 | 77 | |
1da177e4 LT |
78 | for (loop = 0; loop < 64; loop++) |
79 | entry->name[loop] = ntohl(*bp++); | |
08e0e7c8 | 80 | entry->name[loop] = 0; |
1da177e4 LT |
81 | bp++; /* final NUL */ |
82 | ||
83 | bp++; /* type */ | |
84 | entry->nservers = ntohl(*bp++); | |
85 | ||
86 | for (loop = 0; loop < 8; loop++) | |
87 | entry->servers[loop].s_addr = *bp++; | |
88 | ||
89 | bp += 8; /* partition IDs */ | |
90 | ||
91 | for (loop = 0; loop < 8; loop++) { | |
92 | tmp = ntohl(*bp++); | |
08e0e7c8 | 93 | entry->srvtmask[loop] = 0; |
1da177e4 LT |
94 | if (tmp & AFS_VLSF_RWVOL) |
95 | entry->srvtmask[loop] |= AFS_VOL_VTM_RW; | |
96 | if (tmp & AFS_VLSF_ROVOL) | |
97 | entry->srvtmask[loop] |= AFS_VOL_VTM_RO; | |
98 | if (tmp & AFS_VLSF_BACKVOL) | |
99 | entry->srvtmask[loop] |= AFS_VOL_VTM_BAK; | |
100 | } | |
101 | ||
102 | entry->vid[0] = ntohl(*bp++); | |
103 | entry->vid[1] = ntohl(*bp++); | |
104 | entry->vid[2] = ntohl(*bp++); | |
105 | ||
106 | bp++; /* clone ID */ | |
107 | ||
108 | tmp = ntohl(*bp++); /* flags */ | |
08e0e7c8 | 109 | entry->vidmask = 0; |
1da177e4 LT |
110 | if (tmp & AFS_VLF_RWEXISTS) |
111 | entry->vidmask |= AFS_VOL_VTM_RW; | |
112 | if (tmp & AFS_VLF_ROEXISTS) | |
113 | entry->vidmask |= AFS_VOL_VTM_RO; | |
114 | if (tmp & AFS_VLF_BACKEXISTS) | |
115 | entry->vidmask |= AFS_VOL_VTM_BAK; | |
1da177e4 | 116 | if (!entry->vidmask) |
08e0e7c8 DH |
117 | return -EBADMSG; |
118 | ||
119 | _leave(" = 0 [done]"); | |
120 | return 0; | |
ec26815a | 121 | } |
1da177e4 | 122 | |
1da177e4 | 123 | /* |
08e0e7c8 | 124 | * VL.GetEntryByName operation type |
1da177e4 | 125 | */ |
08e0e7c8 | 126 | static const struct afs_call_type afs_RXVLGetEntryByName = { |
00d3b7a4 | 127 | .name = "VL.GetEntryByName", |
08e0e7c8 DH |
128 | .deliver = afs_deliver_vl_get_entry_by_xxx, |
129 | .abort_to_error = afs_vl_abort_to_error, | |
130 | .destructor = afs_flat_call_destructor, | |
131 | }; | |
1da177e4 | 132 | |
08e0e7c8 DH |
133 | /* |
134 | * VL.GetEntryById operation type | |
135 | */ | |
136 | static const struct afs_call_type afs_RXVLGetEntryById = { | |
00d3b7a4 | 137 | .name = "VL.GetEntryById", |
08e0e7c8 DH |
138 | .deliver = afs_deliver_vl_get_entry_by_xxx, |
139 | .abort_to_error = afs_vl_abort_to_error, | |
140 | .destructor = afs_flat_call_destructor, | |
141 | }; | |
1da177e4 | 142 | |
1da177e4 | 143 | /* |
08e0e7c8 | 144 | * dispatch a get volume entry by name operation |
1da177e4 | 145 | */ |
08e0e7c8 | 146 | int afs_vl_get_entry_by_name(struct in_addr *addr, |
00d3b7a4 | 147 | struct key *key, |
08e0e7c8 DH |
148 | const char *volname, |
149 | struct afs_cache_vlocation *entry, | |
56ff9c83 | 150 | bool async) |
1da177e4 | 151 | { |
08e0e7c8 DH |
152 | struct afs_call *call; |
153 | size_t volnamesz, reqsz, padsz; | |
154 | __be32 *bp; | |
1da177e4 | 155 | |
08e0e7c8 | 156 | _enter(""); |
1da177e4 | 157 | |
08e0e7c8 DH |
158 | volnamesz = strlen(volname); |
159 | padsz = (4 - (volnamesz & 3)) & 3; | |
160 | reqsz = 8 + volnamesz + padsz; | |
1da177e4 | 161 | |
08e0e7c8 DH |
162 | call = afs_alloc_flat_call(&afs_RXVLGetEntryByName, reqsz, 384); |
163 | if (!call) | |
164 | return -ENOMEM; | |
1da177e4 | 165 | |
00d3b7a4 | 166 | call->key = key; |
08e0e7c8 DH |
167 | call->reply = entry; |
168 | call->service_id = VL_SERVICE; | |
169 | call->port = htons(AFS_VL_PORT); | |
1da177e4 LT |
170 | |
171 | /* marshall the parameters */ | |
08e0e7c8 DH |
172 | bp = call->request; |
173 | *bp++ = htonl(VLGETENTRYBYNAME); | |
174 | *bp++ = htonl(volnamesz); | |
175 | memcpy(bp, volname, volnamesz); | |
176 | if (padsz > 0) | |
177 | memset((void *) bp + volnamesz, 0, padsz); | |
178 | ||
179 | /* initiate the call */ | |
56ff9c83 | 180 | return afs_make_call(addr, call, GFP_KERNEL, async); |
ec26815a | 181 | } |
1da177e4 | 182 | |
1da177e4 | 183 | /* |
08e0e7c8 | 184 | * dispatch a get volume entry by ID operation |
1da177e4 | 185 | */ |
08e0e7c8 | 186 | int afs_vl_get_entry_by_id(struct in_addr *addr, |
00d3b7a4 | 187 | struct key *key, |
08e0e7c8 DH |
188 | afs_volid_t volid, |
189 | afs_voltype_t voltype, | |
190 | struct afs_cache_vlocation *entry, | |
56ff9c83 | 191 | bool async) |
1da177e4 | 192 | { |
08e0e7c8 | 193 | struct afs_call *call; |
1da177e4 | 194 | __be32 *bp; |
1da177e4 | 195 | |
08e0e7c8 | 196 | _enter(""); |
1da177e4 | 197 | |
08e0e7c8 DH |
198 | call = afs_alloc_flat_call(&afs_RXVLGetEntryById, 12, 384); |
199 | if (!call) | |
200 | return -ENOMEM; | |
1da177e4 | 201 | |
00d3b7a4 | 202 | call->key = key; |
08e0e7c8 DH |
203 | call->reply = entry; |
204 | call->service_id = VL_SERVICE; | |
205 | call->port = htons(AFS_VL_PORT); | |
1da177e4 | 206 | |
08e0e7c8 DH |
207 | /* marshall the parameters */ |
208 | bp = call->request; | |
209 | *bp++ = htonl(VLGETENTRYBYID); | |
210 | *bp++ = htonl(volid); | |
211 | *bp = htonl(voltype); | |
1da177e4 | 212 | |
08e0e7c8 | 213 | /* initiate the call */ |
56ff9c83 | 214 | return afs_make_call(addr, call, GFP_KERNEL, async); |
ec26815a | 215 | } |