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> |
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 | * deliver reply data to a VL.GetEntryByXXX call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 21 | 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] | 22 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 23 | struct afs_cache_vlocation *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | __be32 *bp; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 25 | u32 tmp; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 26 | int loop, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 28 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 30 | ret = afs_transfer_reply(call); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 31 | if (ret < 0) |
| 32 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 34 | /* unmarshall the reply once we've received all of it */ |
David Howells | 97e3043 | 2017-11-02 15:27:48 +0000 | [diff] [blame^] | 35 | entry = call->reply[0]; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 36 | bp = call->buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 38 | for (loop = 0; loop < 64; loop++) |
| 39 | entry->name[loop] = ntohl(*bp++); |
| 40 | entry->name[loop] = 0; |
| 41 | bp++; /* final NUL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 43 | bp++; /* type */ |
| 44 | entry->nservers = ntohl(*bp++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 46 | for (loop = 0; loop < 8; loop++) { |
| 47 | entry->servers[loop].srx_family = AF_RXRPC; |
| 48 | entry->servers[loop].srx_service = FS_SERVICE; |
| 49 | entry->servers[loop].transport_type = SOCK_DGRAM; |
David Howells | 3838d3e | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 50 | entry->servers[loop].transport_len = sizeof(entry->servers[loop].transport.sin6); |
| 51 | entry->servers[loop].transport.sin6.sin6_family = AF_INET6; |
| 52 | entry->servers[loop].transport.sin6.sin6_port = htons(AFS_FS_PORT); |
| 53 | entry->servers[loop].transport.sin6.sin6_flowinfo = 0; |
| 54 | entry->servers[loop].transport.sin6.sin6_scope_id = 0; |
| 55 | entry->servers[loop].transport.sin6.sin6_addr.s6_addr32[0] = 0; |
| 56 | entry->servers[loop].transport.sin6.sin6_addr.s6_addr32[1] = 0; |
| 57 | entry->servers[loop].transport.sin6.sin6_addr.s6_addr32[2] = htonl(0xffff); |
| 58 | entry->servers[loop].transport.sin6.sin6_addr.s6_addr32[3] = *bp++; |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 59 | } |
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 | bp += 8; /* partition IDs */ |
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 | for (loop = 0; loop < 8; loop++) { |
| 64 | tmp = ntohl(*bp++); |
| 65 | entry->srvtmask[loop] = 0; |
| 66 | if (tmp & AFS_VLSF_RWVOL) |
| 67 | entry->srvtmask[loop] |= AFS_VOL_VTM_RW; |
| 68 | if (tmp & AFS_VLSF_ROVOL) |
| 69 | entry->srvtmask[loop] |= AFS_VOL_VTM_RO; |
| 70 | if (tmp & AFS_VLSF_BACKVOL) |
| 71 | entry->srvtmask[loop] |= AFS_VOL_VTM_BAK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 74 | entry->vid[0] = ntohl(*bp++); |
| 75 | entry->vid[1] = ntohl(*bp++); |
| 76 | entry->vid[2] = ntohl(*bp++); |
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 | bp++; /* clone ID */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 80 | tmp = ntohl(*bp++); /* flags */ |
| 81 | entry->vidmask = 0; |
| 82 | if (tmp & AFS_VLF_RWEXISTS) |
| 83 | entry->vidmask |= AFS_VOL_VTM_RW; |
| 84 | if (tmp & AFS_VLF_ROEXISTS) |
| 85 | entry->vidmask |= AFS_VOL_VTM_RO; |
| 86 | if (tmp & AFS_VLF_BACKEXISTS) |
| 87 | entry->vidmask |= AFS_VOL_VTM_BAK; |
| 88 | if (!entry->vidmask) |
| 89 | return -EBADMSG; |
| 90 | |
| 91 | _leave(" = 0 [done]"); |
| 92 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 93 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 96 | * VL.GetEntryByName operation type |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 98 | static const struct afs_call_type afs_RXVLGetEntryByName = { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 99 | .name = "VL.GetEntryByName", |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 100 | .deliver = afs_deliver_vl_get_entry_by_xxx, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 101 | .destructor = afs_flat_call_destructor, |
| 102 | }; |
| 103 | |
| 104 | /* |
| 105 | * VL.GetEntryById operation type |
| 106 | */ |
| 107 | static const struct afs_call_type afs_RXVLGetEntryById = { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 108 | .name = "VL.GetEntryById", |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 109 | .deliver = afs_deliver_vl_get_entry_by_xxx, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 110 | .destructor = afs_flat_call_destructor, |
| 111 | }; |
| 112 | |
| 113 | /* |
| 114 | * dispatch a get volume entry by name operation |
| 115 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 116 | int afs_vl_get_entry_by_name(struct afs_net *net, |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 117 | struct sockaddr_rxrpc *addr, |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 118 | struct key *key, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 119 | const char *volname, |
| 120 | struct afs_cache_vlocation *entry, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 121 | bool async) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 123 | struct afs_call *call; |
| 124 | size_t volnamesz, reqsz, padsz; |
| 125 | __be32 *bp; |
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 | _enter(""); |
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 | volnamesz = strlen(volname); |
| 130 | padsz = (4 - (volnamesz & 3)) & 3; |
| 131 | reqsz = 8 + volnamesz + padsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 133 | call = afs_alloc_flat_call(net, &afs_RXVLGetEntryByName, reqsz, 384); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 134 | if (!call) |
| 135 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 137 | call->key = key; |
David Howells | 97e3043 | 2017-11-02 15:27:48 +0000 | [diff] [blame^] | 138 | call->reply[0] = entry; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 139 | |
| 140 | /* marshall the parameters */ |
| 141 | bp = call->request; |
| 142 | *bp++ = htonl(VLGETENTRYBYNAME); |
| 143 | *bp++ = htonl(volnamesz); |
| 144 | memcpy(bp, volname, volnamesz); |
| 145 | if (padsz > 0) |
| 146 | memset((void *) bp + volnamesz, 0, padsz); |
| 147 | |
| 148 | /* initiate the call */ |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 149 | return afs_make_call(addr, call, GFP_KERNEL, async); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 153 | * dispatch a get volume entry by ID operation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 155 | int afs_vl_get_entry_by_id(struct afs_net *net, |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 156 | struct sockaddr_rxrpc *addr, |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 157 | struct key *key, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 158 | afs_volid_t volid, |
| 159 | afs_voltype_t voltype, |
| 160 | struct afs_cache_vlocation *entry, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 161 | bool async) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 163 | struct afs_call *call; |
| 164 | __be32 *bp; |
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 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 168 | call = afs_alloc_flat_call(net, &afs_RXVLGetEntryById, 12, 384); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 169 | if (!call) |
| 170 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 172 | call->key = key; |
David Howells | 97e3043 | 2017-11-02 15:27:48 +0000 | [diff] [blame^] | 173 | call->reply[0] = entry; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 174 | |
| 175 | /* marshall the parameters */ |
| 176 | bp = call->request; |
| 177 | *bp++ = htonl(VLGETENTRYBYID); |
| 178 | *bp++ = htonl(volid); |
| 179 | *bp = htonl(voltype); |
| 180 | |
| 181 | /* initiate the call */ |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 182 | return afs_make_call(addr, call, GFP_KERNEL, async); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 183 | } |