]>
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 | */ |
08e0e7c8 DH |
61 | static int afs_deliver_vl_get_entry_by_xxx(struct afs_call *call, |
62 | struct sk_buff *skb, bool last) | |
1da177e4 | 63 | { |
08e0e7c8 DH |
64 | struct afs_cache_vlocation *entry; |
65 | __be32 *bp; | |
66 | u32 tmp; | |
372ee163 | 67 | int loop, ret; |
1da177e4 | 68 | |
08e0e7c8 | 69 | _enter(",,%u", last); |
1da177e4 | 70 | |
372ee163 DH |
71 | ret = afs_transfer_reply(call, skb, last); |
72 | if (ret < 0) | |
73 | return ret; | |
1da177e4 | 74 | |
08e0e7c8 DH |
75 | /* unmarshall the reply once we've received all of it */ |
76 | entry = call->reply; | |
77 | bp = call->buffer; | |
1da177e4 | 78 | |
1da177e4 LT |
79 | for (loop = 0; loop < 64; loop++) |
80 | entry->name[loop] = ntohl(*bp++); | |
08e0e7c8 | 81 | entry->name[loop] = 0; |
1da177e4 LT |
82 | bp++; /* final NUL */ |
83 | ||
84 | bp++; /* type */ | |
85 | entry->nservers = ntohl(*bp++); | |
86 | ||
87 | for (loop = 0; loop < 8; loop++) | |
88 | entry->servers[loop].s_addr = *bp++; | |
89 | ||
90 | bp += 8; /* partition IDs */ | |
91 | ||
92 | for (loop = 0; loop < 8; loop++) { | |
93 | tmp = ntohl(*bp++); | |
08e0e7c8 | 94 | entry->srvtmask[loop] = 0; |
1da177e4 LT |
95 | if (tmp & AFS_VLSF_RWVOL) |
96 | entry->srvtmask[loop] |= AFS_VOL_VTM_RW; | |
97 | if (tmp & AFS_VLSF_ROVOL) | |
98 | entry->srvtmask[loop] |= AFS_VOL_VTM_RO; | |
99 | if (tmp & AFS_VLSF_BACKVOL) | |
100 | entry->srvtmask[loop] |= AFS_VOL_VTM_BAK; | |
101 | } | |
102 | ||
103 | entry->vid[0] = ntohl(*bp++); | |
104 | entry->vid[1] = ntohl(*bp++); | |
105 | entry->vid[2] = ntohl(*bp++); | |
106 | ||
107 | bp++; /* clone ID */ | |
108 | ||
109 | tmp = ntohl(*bp++); /* flags */ | |
08e0e7c8 | 110 | entry->vidmask = 0; |
1da177e4 LT |
111 | if (tmp & AFS_VLF_RWEXISTS) |
112 | entry->vidmask |= AFS_VOL_VTM_RW; | |
113 | if (tmp & AFS_VLF_ROEXISTS) | |
114 | entry->vidmask |= AFS_VOL_VTM_RO; | |
115 | if (tmp & AFS_VLF_BACKEXISTS) | |
116 | entry->vidmask |= AFS_VOL_VTM_BAK; | |
1da177e4 | 117 | if (!entry->vidmask) |
08e0e7c8 DH |
118 | return -EBADMSG; |
119 | ||
120 | _leave(" = 0 [done]"); | |
121 | return 0; | |
ec26815a | 122 | } |
1da177e4 | 123 | |
1da177e4 | 124 | /* |
08e0e7c8 | 125 | * VL.GetEntryByName operation type |
1da177e4 | 126 | */ |
08e0e7c8 | 127 | static const struct afs_call_type afs_RXVLGetEntryByName = { |
00d3b7a4 | 128 | .name = "VL.GetEntryByName", |
08e0e7c8 DH |
129 | .deliver = afs_deliver_vl_get_entry_by_xxx, |
130 | .abort_to_error = afs_vl_abort_to_error, | |
131 | .destructor = afs_flat_call_destructor, | |
132 | }; | |
1da177e4 | 133 | |
08e0e7c8 DH |
134 | /* |
135 | * VL.GetEntryById operation type | |
136 | */ | |
137 | static const struct afs_call_type afs_RXVLGetEntryById = { | |
00d3b7a4 | 138 | .name = "VL.GetEntryById", |
08e0e7c8 DH |
139 | .deliver = afs_deliver_vl_get_entry_by_xxx, |
140 | .abort_to_error = afs_vl_abort_to_error, | |
141 | .destructor = afs_flat_call_destructor, | |
142 | }; | |
1da177e4 | 143 | |
1da177e4 | 144 | /* |
08e0e7c8 | 145 | * dispatch a get volume entry by name operation |
1da177e4 | 146 | */ |
08e0e7c8 | 147 | int afs_vl_get_entry_by_name(struct in_addr *addr, |
00d3b7a4 | 148 | struct key *key, |
08e0e7c8 DH |
149 | const char *volname, |
150 | struct afs_cache_vlocation *entry, | |
151 | const struct afs_wait_mode *wait_mode) | |
1da177e4 | 152 | { |
08e0e7c8 DH |
153 | struct afs_call *call; |
154 | size_t volnamesz, reqsz, padsz; | |
155 | __be32 *bp; | |
1da177e4 | 156 | |
08e0e7c8 | 157 | _enter(""); |
1da177e4 | 158 | |
08e0e7c8 DH |
159 | volnamesz = strlen(volname); |
160 | padsz = (4 - (volnamesz & 3)) & 3; | |
161 | reqsz = 8 + volnamesz + padsz; | |
1da177e4 | 162 | |
08e0e7c8 DH |
163 | call = afs_alloc_flat_call(&afs_RXVLGetEntryByName, reqsz, 384); |
164 | if (!call) | |
165 | return -ENOMEM; | |
1da177e4 | 166 | |
00d3b7a4 | 167 | call->key = key; |
08e0e7c8 DH |
168 | call->reply = entry; |
169 | call->service_id = VL_SERVICE; | |
170 | call->port = htons(AFS_VL_PORT); | |
1da177e4 LT |
171 | |
172 | /* marshall the parameters */ | |
08e0e7c8 DH |
173 | bp = call->request; |
174 | *bp++ = htonl(VLGETENTRYBYNAME); | |
175 | *bp++ = htonl(volnamesz); | |
176 | memcpy(bp, volname, volnamesz); | |
177 | if (padsz > 0) | |
178 | memset((void *) bp + volnamesz, 0, padsz); | |
179 | ||
180 | /* initiate the call */ | |
181 | return afs_make_call(addr, call, GFP_KERNEL, wait_mode); | |
ec26815a | 182 | } |
1da177e4 | 183 | |
1da177e4 | 184 | /* |
08e0e7c8 | 185 | * dispatch a get volume entry by ID operation |
1da177e4 | 186 | */ |
08e0e7c8 | 187 | int afs_vl_get_entry_by_id(struct in_addr *addr, |
00d3b7a4 | 188 | struct key *key, |
08e0e7c8 DH |
189 | afs_volid_t volid, |
190 | afs_voltype_t voltype, | |
191 | struct afs_cache_vlocation *entry, | |
192 | const struct afs_wait_mode *wait_mode) | |
1da177e4 | 193 | { |
08e0e7c8 | 194 | struct afs_call *call; |
1da177e4 | 195 | __be32 *bp; |
1da177e4 | 196 | |
08e0e7c8 | 197 | _enter(""); |
1da177e4 | 198 | |
08e0e7c8 DH |
199 | call = afs_alloc_flat_call(&afs_RXVLGetEntryById, 12, 384); |
200 | if (!call) | |
201 | return -ENOMEM; | |
1da177e4 | 202 | |
00d3b7a4 | 203 | call->key = key; |
08e0e7c8 DH |
204 | call->reply = entry; |
205 | call->service_id = VL_SERVICE; | |
206 | call->port = htons(AFS_VL_PORT); | |
1da177e4 | 207 | |
08e0e7c8 DH |
208 | /* marshall the parameters */ |
209 | bp = call->request; | |
210 | *bp++ = htonl(VLGETENTRYBYID); | |
211 | *bp++ = htonl(volid); | |
212 | *bp = htonl(voltype); | |
1da177e4 | 213 | |
08e0e7c8 DH |
214 | /* initiate the call */ |
215 | return afs_make_call(addr, call, GFP_KERNEL, wait_mode); | |
ec26815a | 216 | } |