blob: 0c7eba174836d6915aeab5fc1cdd93b42dc4f837 [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
12#include <linux/init.h>
13#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include "internal.h"
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016/*
David Howells08e0e7c2007-04-26 15:55:03 -070017 * map volume locator abort codes to error codes
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 */
David Howells08e0e7c2007-04-26 15:55:03 -070019static int afs_vl_abort_to_error(u32 abort_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020{
David Howells08e0e7c2007-04-26 15:55:03 -070021 _enter("%u", abort_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
David Howells08e0e7c2007-04-26 15:55:03 -070023 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 Torvalds1da177e2005-04-16 15:20:36 -070052 default:
David Howells08e0e7c2007-04-26 15:55:03 -070053 return afs_abort_to_error(abort_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 }
David Howellsec268152007-04-26 15:49:28 -070055}
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/*
David Howells08e0e7c2007-04-26 15:55:03 -070058 * deliver reply data to a VL.GetEntryByXXX call
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 */
David Howells08e0e7c2007-04-26 15:55:03 -070060static int afs_deliver_vl_get_entry_by_xxx(struct afs_call *call,
61 struct sk_buff *skb, bool last)
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;
66 int loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
David Howells08e0e7c2007-04-26 15:55:03 -070068 _enter(",,%u", last);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
David Howells08e0e7c2007-04-26 15:55:03 -070070 afs_transfer_reply(call, skb);
71 if (!last)
72 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
David Howells08e0e7c2007-04-26 15:55:03 -070074 if (call->reply_size != call->reply_max)
75 return -EBADMSG;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
David Howells08e0e7c2007-04-26 15:55:03 -070077 /* unmarshall the reply once we've received all of it */
78 entry = call->reply;
79 bp = call->buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
David Howells08e0e7c2007-04-26 15:55:03 -070081 for (loop = 0; loop < 64; loop++)
82 entry->name[loop] = ntohl(*bp++);
83 entry->name[loop] = 0;
84 bp++; /* final NUL */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
David Howells08e0e7c2007-04-26 15:55:03 -070086 bp++; /* type */
87 entry->nservers = ntohl(*bp++);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
David Howells08e0e7c2007-04-26 15:55:03 -070089 for (loop = 0; loop < 8; loop++)
90 entry->servers[loop].s_addr = *bp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
David Howells08e0e7c2007-04-26 15:55:03 -070092 bp += 8; /* partition IDs */
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
David Howells08e0e7c2007-04-26 15:55:03 -070094 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 Torvalds1da177e2005-04-16 15:20:36 -0700103 }
104
David Howells08e0e7c2007-04-26 15:55:03 -0700105 entry->vid[0] = ntohl(*bp++);
106 entry->vid[1] = ntohl(*bp++);
107 entry->vid[2] = ntohl(*bp++);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
David Howells08e0e7c2007-04-26 15:55:03 -0700109 bp++; /* clone ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
David Howells08e0e7c2007-04-26 15:55:03 -0700111 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 Howellsec268152007-04-26 15:49:28 -0700124}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126/*
David Howells08e0e7c2007-04-26 15:55:03 -0700127 * VL.GetEntryByName operation type
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 */
David Howells08e0e7c2007-04-26 15:55:03 -0700129static const struct afs_call_type afs_RXVLGetEntryByName = {
130 .deliver = afs_deliver_vl_get_entry_by_xxx,
131 .abort_to_error = afs_vl_abort_to_error,
132 .destructor = afs_flat_call_destructor,
133};
134
135/*
136 * VL.GetEntryById operation type
137 */
138static const struct afs_call_type afs_RXVLGetEntryById = {
139 .deliver = afs_deliver_vl_get_entry_by_xxx,
140 .abort_to_error = afs_vl_abort_to_error,
141 .destructor = afs_flat_call_destructor,
142};
143
144/*
145 * dispatch a get volume entry by name operation
146 */
147int afs_vl_get_entry_by_name(struct in_addr *addr,
148 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 Howells08e0e7c2007-04-26 15:55:03 -0700166 call->reply = entry;
167 call->service_id = VL_SERVICE;
168 call->port = htons(AFS_VL_PORT);
169
170 /* marshall the parameters */
171 bp = call->request;
172 *bp++ = htonl(VLGETENTRYBYNAME);
173 *bp++ = htonl(volnamesz);
174 memcpy(bp, volname, volnamesz);
175 if (padsz > 0)
176 memset((void *) bp + volnamesz, 0, padsz);
177
178 /* initiate the call */
179 return afs_make_call(addr, call, GFP_KERNEL, wait_mode);
David Howellsec268152007-04-26 15:49:28 -0700180}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182/*
David Howells08e0e7c2007-04-26 15:55:03 -0700183 * dispatch a get volume entry by ID operation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 */
David Howells08e0e7c2007-04-26 15:55:03 -0700185int afs_vl_get_entry_by_id(struct in_addr *addr,
186 afs_volid_t volid,
187 afs_voltype_t voltype,
188 struct afs_cache_vlocation *entry,
189 const struct afs_wait_mode *wait_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
David Howells08e0e7c2007-04-26 15:55:03 -0700191 struct afs_call *call;
192 __be32 *bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
David Howells08e0e7c2007-04-26 15:55:03 -0700194 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
David Howells08e0e7c2007-04-26 15:55:03 -0700196 call = afs_alloc_flat_call(&afs_RXVLGetEntryById, 12, 384);
197 if (!call)
198 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
David Howells08e0e7c2007-04-26 15:55:03 -0700200 call->reply = entry;
201 call->service_id = VL_SERVICE;
202 call->port = htons(AFS_VL_PORT);
203
204 /* marshall the parameters */
205 bp = call->request;
206 *bp++ = htonl(VLGETENTRYBYID);
207 *bp++ = htonl(volid);
208 *bp = htonl(voltype);
209
210 /* initiate the call */
211 return afs_make_call(addr, call, GFP_KERNEL, wait_mode);
David Howellsec268152007-04-26 15:49:28 -0700212}