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