blob: 94bcd97d22b86789e5e192b38d450eb784eaedaa [file] [log] [blame]
David Howellsec268152007-04-26 15:49:28 -07001/* AFS Volume Location Service client
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
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 Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/init.h>
14#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include "internal.h"
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017/*
David Howells08e0e7c2007-04-26 15:55:03 -070018 * map volume locator abort codes to error codes
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 */
David Howells08e0e7c2007-04-26 15:55:03 -070020static int afs_vl_abort_to_error(u32 abort_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021{
David Howells08e0e7c2007-04-26 15:55:03 -070022 _enter("%u", abort_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
David Howells08e0e7c2007-04-26 15:55:03 -070024 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 Torvalds1da177e2005-04-16 15:20:36 -070053 default:
David Howells08e0e7c2007-04-26 15:55:03 -070054 return afs_abort_to_error(abort_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 }
David Howellsec268152007-04-26 15:49:28 -070056}
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Linus Torvalds1da177e2005-04-16 15:20:36 -070058/*
David Howells08e0e7c2007-04-26 15:55:03 -070059 * deliver reply data to a VL.GetEntryByXXX call
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 */
David Howellsd0016482016-08-30 20:42:14 +010061static int afs_deliver_vl_get_entry_by_xxx(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
David Howells08e0e7c2007-04-26 15:55:03 -070063 struct afs_cache_vlocation *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 __be32 *bp;
David Howells08e0e7c2007-04-26 15:55:03 -070065 u32 tmp;
David Howells372ee162016-08-03 14:11:40 +010066 int loop, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
David Howellsd0016482016-08-30 20:42:14 +010068 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
David Howellsd0016482016-08-30 20:42:14 +010070 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +010071 if (ret < 0)
72 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
David Howells08e0e7c2007-04-26 15:55:03 -070074 /* unmarshall the reply once we've received all of it */
75 entry = call->reply;
76 bp = call->buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
David Howells08e0e7c2007-04-26 15:55:03 -070078 for (loop = 0; loop < 64; loop++)
79 entry->name[loop] = ntohl(*bp++);
80 entry->name[loop] = 0;
81 bp++; /* final NUL */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
David Howells08e0e7c2007-04-26 15:55:03 -070083 bp++; /* type */
84 entry->nservers = ntohl(*bp++);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
David Howells08e0e7c2007-04-26 15:55:03 -070086 for (loop = 0; loop < 8; loop++)
87 entry->servers[loop].s_addr = *bp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
David Howells08e0e7c2007-04-26 15:55:03 -070089 bp += 8; /* partition IDs */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
David Howells08e0e7c2007-04-26 15:55:03 -070091 for (loop = 0; loop < 8; loop++) {
92 tmp = ntohl(*bp++);
93 entry->srvtmask[loop] = 0;
94 if (tmp & AFS_VLSF_RWVOL)
95 entry->srvtmask[loop] |= AFS_VOL_VTM_RW;
96 if (tmp & AFS_VLSF_ROVOL)
97 entry->srvtmask[loop] |= AFS_VOL_VTM_RO;
98 if (tmp & AFS_VLSF_BACKVOL)
99 entry->srvtmask[loop] |= AFS_VOL_VTM_BAK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 }
101
David Howells08e0e7c2007-04-26 15:55:03 -0700102 entry->vid[0] = ntohl(*bp++);
103 entry->vid[1] = ntohl(*bp++);
104 entry->vid[2] = ntohl(*bp++);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
David Howells08e0e7c2007-04-26 15:55:03 -0700106 bp++; /* clone ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
David Howells08e0e7c2007-04-26 15:55:03 -0700108 tmp = ntohl(*bp++); /* flags */
109 entry->vidmask = 0;
110 if (tmp & AFS_VLF_RWEXISTS)
111 entry->vidmask |= AFS_VOL_VTM_RW;
112 if (tmp & AFS_VLF_ROEXISTS)
113 entry->vidmask |= AFS_VOL_VTM_RO;
114 if (tmp & AFS_VLF_BACKEXISTS)
115 entry->vidmask |= AFS_VOL_VTM_BAK;
116 if (!entry->vidmask)
117 return -EBADMSG;
118
119 _leave(" = 0 [done]");
120 return 0;
David Howellsec268152007-04-26 15:49:28 -0700121}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123/*
David Howells08e0e7c2007-04-26 15:55:03 -0700124 * VL.GetEntryByName operation type
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 */
David Howells08e0e7c2007-04-26 15:55:03 -0700126static const struct afs_call_type afs_RXVLGetEntryByName = {
David Howells00d3b7a2007-04-26 15:57:07 -0700127 .name = "VL.GetEntryByName",
David Howells08e0e7c2007-04-26 15:55:03 -0700128 .deliver = afs_deliver_vl_get_entry_by_xxx,
129 .abort_to_error = afs_vl_abort_to_error,
130 .destructor = afs_flat_call_destructor,
131};
132
133/*
134 * VL.GetEntryById operation type
135 */
136static const struct afs_call_type afs_RXVLGetEntryById = {
David Howells00d3b7a2007-04-26 15:57:07 -0700137 .name = "VL.GetEntryById",
David Howells08e0e7c2007-04-26 15:55:03 -0700138 .deliver = afs_deliver_vl_get_entry_by_xxx,
139 .abort_to_error = afs_vl_abort_to_error,
140 .destructor = afs_flat_call_destructor,
141};
142
143/*
144 * dispatch a get volume entry by name operation
145 */
146int afs_vl_get_entry_by_name(struct in_addr *addr,
David Howells00d3b7a2007-04-26 15:57:07 -0700147 struct key *key,
David Howells08e0e7c2007-04-26 15:55:03 -0700148 const char *volname,
149 struct afs_cache_vlocation *entry,
150 const struct afs_wait_mode *wait_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
David Howells08e0e7c2007-04-26 15:55:03 -0700152 struct afs_call *call;
153 size_t volnamesz, reqsz, padsz;
154 __be32 *bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
David Howells08e0e7c2007-04-26 15:55:03 -0700156 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
David Howells08e0e7c2007-04-26 15:55:03 -0700158 volnamesz = strlen(volname);
159 padsz = (4 - (volnamesz & 3)) & 3;
160 reqsz = 8 + volnamesz + padsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
David Howells08e0e7c2007-04-26 15:55:03 -0700162 call = afs_alloc_flat_call(&afs_RXVLGetEntryByName, reqsz, 384);
163 if (!call)
164 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
David Howells00d3b7a2007-04-26 15:57:07 -0700166 call->key = key;
David Howells08e0e7c2007-04-26 15:55:03 -0700167 call->reply = entry;
168 call->service_id = VL_SERVICE;
169 call->port = htons(AFS_VL_PORT);
170
171 /* marshall the parameters */
172 bp = call->request;
173 *bp++ = htonl(VLGETENTRYBYNAME);
174 *bp++ = htonl(volnamesz);
175 memcpy(bp, volname, volnamesz);
176 if (padsz > 0)
177 memset((void *) bp + volnamesz, 0, padsz);
178
179 /* initiate the call */
180 return afs_make_call(addr, call, GFP_KERNEL, wait_mode);
David Howellsec268152007-04-26 15:49:28 -0700181}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183/*
David Howells08e0e7c2007-04-26 15:55:03 -0700184 * dispatch a get volume entry by ID operation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 */
David Howells08e0e7c2007-04-26 15:55:03 -0700186int afs_vl_get_entry_by_id(struct in_addr *addr,
David Howells00d3b7a2007-04-26 15:57:07 -0700187 struct key *key,
David Howells08e0e7c2007-04-26 15:55:03 -0700188 afs_volid_t volid,
189 afs_voltype_t voltype,
190 struct afs_cache_vlocation *entry,
191 const struct afs_wait_mode *wait_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
David Howells08e0e7c2007-04-26 15:55:03 -0700193 struct afs_call *call;
194 __be32 *bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
David Howells08e0e7c2007-04-26 15:55:03 -0700196 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
David Howells08e0e7c2007-04-26 15:55:03 -0700198 call = afs_alloc_flat_call(&afs_RXVLGetEntryById, 12, 384);
199 if (!call)
200 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
David Howells00d3b7a2007-04-26 15:57:07 -0700202 call->key = key;
David Howells08e0e7c2007-04-26 15:55:03 -0700203 call->reply = entry;
204 call->service_id = VL_SERVICE;
205 call->port = htons(AFS_VL_PORT);
206
207 /* marshall the parameters */
208 bp = call->request;
209 *bp++ = htonl(VLGETENTRYBYID);
210 *bp++ = htonl(volid);
211 *bp = htonl(voltype);
212
213 /* initiate the call */
214 return afs_make_call(addr, call, GFP_KERNEL, wait_mode);
David Howellsec268152007-04-26 15:49:28 -0700215}