David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 1 | /* AFS Volume Location Service client |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 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 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame^] | 12 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/init.h> |
| 14 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include "internal.h" |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 18 | * map volume locator abort codes to error codes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 20 | static int afs_vl_abort_to_error(u32 abort_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 22 | _enter("%u", abort_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | default: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 54 | return afs_abort_to_error(abort_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 56 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 59 | * deliver reply data to a VL.GetEntryByXXX call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 61 | static int afs_deliver_vl_get_entry_by_xxx(struct afs_call *call, |
| 62 | struct sk_buff *skb, bool last) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 64 | struct afs_cache_vlocation *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | __be32 *bp; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 66 | u32 tmp; |
| 67 | int loop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 69 | _enter(",,%u", last); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 71 | afs_transfer_reply(call, skb); |
| 72 | if (!last) |
| 73 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 75 | if (call->reply_size != call->reply_max) |
| 76 | return -EBADMSG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 78 | /* unmarshall the reply once we've received all of it */ |
| 79 | entry = call->reply; |
| 80 | bp = call->buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 82 | for (loop = 0; loop < 64; loop++) |
| 83 | entry->name[loop] = ntohl(*bp++); |
| 84 | entry->name[loop] = 0; |
| 85 | bp++; /* final NUL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 87 | bp++; /* type */ |
| 88 | entry->nservers = ntohl(*bp++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 90 | for (loop = 0; loop < 8; loop++) |
| 91 | entry->servers[loop].s_addr = *bp++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 93 | bp += 8; /* partition IDs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 95 | for (loop = 0; loop < 8; loop++) { |
| 96 | tmp = ntohl(*bp++); |
| 97 | entry->srvtmask[loop] = 0; |
| 98 | if (tmp & AFS_VLSF_RWVOL) |
| 99 | entry->srvtmask[loop] |= AFS_VOL_VTM_RW; |
| 100 | if (tmp & AFS_VLSF_ROVOL) |
| 101 | entry->srvtmask[loop] |= AFS_VOL_VTM_RO; |
| 102 | if (tmp & AFS_VLSF_BACKVOL) |
| 103 | entry->srvtmask[loop] |= AFS_VOL_VTM_BAK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 106 | entry->vid[0] = ntohl(*bp++); |
| 107 | entry->vid[1] = ntohl(*bp++); |
| 108 | entry->vid[2] = ntohl(*bp++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 110 | bp++; /* clone ID */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 112 | tmp = ntohl(*bp++); /* flags */ |
| 113 | entry->vidmask = 0; |
| 114 | if (tmp & AFS_VLF_RWEXISTS) |
| 115 | entry->vidmask |= AFS_VOL_VTM_RW; |
| 116 | if (tmp & AFS_VLF_ROEXISTS) |
| 117 | entry->vidmask |= AFS_VOL_VTM_RO; |
| 118 | if (tmp & AFS_VLF_BACKEXISTS) |
| 119 | entry->vidmask |= AFS_VOL_VTM_BAK; |
| 120 | if (!entry->vidmask) |
| 121 | return -EBADMSG; |
| 122 | |
| 123 | _leave(" = 0 [done]"); |
| 124 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 125 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 128 | * VL.GetEntryByName operation type |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 130 | static const struct afs_call_type afs_RXVLGetEntryByName = { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 131 | .name = "VL.GetEntryByName", |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 132 | .deliver = afs_deliver_vl_get_entry_by_xxx, |
| 133 | .abort_to_error = afs_vl_abort_to_error, |
| 134 | .destructor = afs_flat_call_destructor, |
| 135 | }; |
| 136 | |
| 137 | /* |
| 138 | * VL.GetEntryById operation type |
| 139 | */ |
| 140 | static const struct afs_call_type afs_RXVLGetEntryById = { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 141 | .name = "VL.GetEntryById", |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 142 | .deliver = afs_deliver_vl_get_entry_by_xxx, |
| 143 | .abort_to_error = afs_vl_abort_to_error, |
| 144 | .destructor = afs_flat_call_destructor, |
| 145 | }; |
| 146 | |
| 147 | /* |
| 148 | * dispatch a get volume entry by name operation |
| 149 | */ |
| 150 | int afs_vl_get_entry_by_name(struct in_addr *addr, |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 151 | struct key *key, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 152 | const char *volname, |
| 153 | struct afs_cache_vlocation *entry, |
| 154 | const struct afs_wait_mode *wait_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 156 | struct afs_call *call; |
| 157 | size_t volnamesz, reqsz, padsz; |
| 158 | __be32 *bp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 160 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 162 | volnamesz = strlen(volname); |
| 163 | padsz = (4 - (volnamesz & 3)) & 3; |
| 164 | reqsz = 8 + volnamesz + padsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 166 | call = afs_alloc_flat_call(&afs_RXVLGetEntryByName, reqsz, 384); |
| 167 | if (!call) |
| 168 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 170 | call->key = key; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 171 | call->reply = entry; |
| 172 | call->service_id = VL_SERVICE; |
| 173 | call->port = htons(AFS_VL_PORT); |
| 174 | |
| 175 | /* marshall the parameters */ |
| 176 | bp = call->request; |
| 177 | *bp++ = htonl(VLGETENTRYBYNAME); |
| 178 | *bp++ = htonl(volnamesz); |
| 179 | memcpy(bp, volname, volnamesz); |
| 180 | if (padsz > 0) |
| 181 | memset((void *) bp + volnamesz, 0, padsz); |
| 182 | |
| 183 | /* initiate the call */ |
| 184 | return afs_make_call(addr, call, GFP_KERNEL, wait_mode); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 185 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 188 | * dispatch a get volume entry by ID operation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 190 | int afs_vl_get_entry_by_id(struct in_addr *addr, |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 191 | struct key *key, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 192 | afs_volid_t volid, |
| 193 | afs_voltype_t voltype, |
| 194 | struct afs_cache_vlocation *entry, |
| 195 | const struct afs_wait_mode *wait_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 197 | struct afs_call *call; |
| 198 | __be32 *bp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 200 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 202 | call = afs_alloc_flat_call(&afs_RXVLGetEntryById, 12, 384); |
| 203 | if (!call) |
| 204 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 206 | call->key = key; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 207 | call->reply = entry; |
| 208 | call->service_id = VL_SERVICE; |
| 209 | call->port = htons(AFS_VL_PORT); |
| 210 | |
| 211 | /* marshall the parameters */ |
| 212 | bp = call->request; |
| 213 | *bp++ = htonl(VLGETENTRYBYID); |
| 214 | *bp++ = htonl(volid); |
| 215 | *bp = htonl(voltype); |
| 216 | |
| 217 | /* initiate the call */ |
| 218 | return afs_make_call(addr, call, GFP_KERNEL, wait_mode); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 219 | } |