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