blob: 9312b92e54bedb3310e725a1d10249f2dee21337 [file] [log] [blame]
David Howells08e0e7c2007-04-26 15:55:03 -07001/* AFS File Server client stubs
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David Howells08e0e7c2007-04-26 15:55:03 -07003 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/sched.h>
David Howells08e0e7c2007-04-26 15:55:03 -070015#include <linux/circ_buf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include "internal.h"
David Howells08e0e7c2007-04-26 15:55:03 -070017#include "afs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/*
David Howells260a9802007-04-26 15:59:35 -070020 * decode an AFSFid block
21 */
22static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
23{
24 const __be32 *bp = *_bp;
25
26 fid->vid = ntohl(*bp++);
27 fid->vnode = ntohl(*bp++);
28 fid->unique = ntohl(*bp++);
29 *_bp = bp;
30}
31
32/*
David Howells08e0e7c2007-04-26 15:55:03 -070033 * decode an AFSFetchStatus block
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 */
David Howells08e0e7c2007-04-26 15:55:03 -070035static void xdr_decode_AFSFetchStatus(const __be32 **_bp,
David Howells260a9802007-04-26 15:59:35 -070036 struct afs_file_status *status,
David Howells31143d52007-05-09 02:33:46 -070037 struct afs_vnode *vnode,
38 afs_dataversion_t *store_version)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
David Howells31143d52007-05-09 02:33:46 -070040 afs_dataversion_t expected_version;
David Howells08e0e7c2007-04-26 15:55:03 -070041 const __be32 *bp = *_bp;
42 umode_t mode;
David Howells260a9802007-04-26 15:59:35 -070043 u64 data_version, size;
David Howells08e0e7c2007-04-26 15:55:03 -070044 u32 changed = 0; /* becomes non-zero if ctime-type changes seen */
Eric W. Biedermana0a53862012-02-07 16:20:48 -080045 kuid_t owner;
46 kgid_t group;
David Howells08e0e7c2007-04-26 15:55:03 -070047
48#define EXTRACT(DST) \
49 do { \
50 u32 x = ntohl(*bp++); \
51 changed |= DST - x; \
52 DST = x; \
53 } while (0)
54
David Howells260a9802007-04-26 15:59:35 -070055 status->if_version = ntohl(*bp++);
56 EXTRACT(status->type);
57 EXTRACT(status->nlink);
58 size = ntohl(*bp++);
David Howells08e0e7c2007-04-26 15:55:03 -070059 data_version = ntohl(*bp++);
David Howells260a9802007-04-26 15:59:35 -070060 EXTRACT(status->author);
Eric W. Biedermana0a53862012-02-07 16:20:48 -080061 owner = make_kuid(&init_user_ns, ntohl(*bp++));
62 changed |= !uid_eq(owner, status->owner);
63 status->owner = owner;
David Howells260a9802007-04-26 15:59:35 -070064 EXTRACT(status->caller_access); /* call ticket dependent */
65 EXTRACT(status->anon_access);
66 EXTRACT(status->mode);
67 EXTRACT(status->parent.vnode);
68 EXTRACT(status->parent.unique);
David Howells08e0e7c2007-04-26 15:55:03 -070069 bp++; /* seg size */
David Howells260a9802007-04-26 15:59:35 -070070 status->mtime_client = ntohl(*bp++);
71 status->mtime_server = ntohl(*bp++);
Eric W. Biedermana0a53862012-02-07 16:20:48 -080072 group = make_kgid(&init_user_ns, ntohl(*bp++));
73 changed |= !gid_eq(group, status->group);
74 status->group = group;
David Howells08e0e7c2007-04-26 15:55:03 -070075 bp++; /* sync counter */
76 data_version |= (u64) ntohl(*bp++) << 32;
David Howellse8d6c552007-07-15 23:40:12 -070077 EXTRACT(status->lock_count);
David Howells260a9802007-04-26 15:59:35 -070078 size |= (u64) ntohl(*bp++) << 32;
79 bp++; /* spare 4 */
David Howells08e0e7c2007-04-26 15:55:03 -070080 *_bp = bp;
81
David Howells260a9802007-04-26 15:59:35 -070082 if (size != status->size) {
83 status->size = size;
84 changed |= true;
David Howells08e0e7c2007-04-26 15:55:03 -070085 }
David Howells260a9802007-04-26 15:59:35 -070086 status->mode &= S_IALLUGO;
David Howells08e0e7c2007-04-26 15:55:03 -070087
88 _debug("vnode time %lx, %lx",
David Howells260a9802007-04-26 15:59:35 -070089 status->mtime_client, status->mtime_server);
David Howells08e0e7c2007-04-26 15:55:03 -070090
David Howells260a9802007-04-26 15:59:35 -070091 if (vnode) {
92 status->parent.vid = vnode->fid.vid;
93 if (changed && !test_bit(AFS_VNODE_UNSET, &vnode->flags)) {
94 _debug("vnode changed");
95 i_size_write(&vnode->vfs_inode, size);
96 vnode->vfs_inode.i_uid = status->owner;
97 vnode->vfs_inode.i_gid = status->group;
David Howellsd6e43f72011-06-14 00:45:44 +010098 vnode->vfs_inode.i_generation = vnode->fid.unique;
Miklos Szeredibfe86842011-10-28 14:13:29 +020099 set_nlink(&vnode->vfs_inode, status->nlink);
David Howells260a9802007-04-26 15:59:35 -0700100
101 mode = vnode->vfs_inode.i_mode;
102 mode &= ~S_IALLUGO;
103 mode |= status->mode;
104 barrier();
105 vnode->vfs_inode.i_mode = mode;
106 }
107
108 vnode->vfs_inode.i_ctime.tv_sec = status->mtime_server;
109 vnode->vfs_inode.i_mtime = vnode->vfs_inode.i_ctime;
110 vnode->vfs_inode.i_atime = vnode->vfs_inode.i_ctime;
David Howellsd6e43f72011-06-14 00:45:44 +0100111 vnode->vfs_inode.i_version = data_version;
David Howells260a9802007-04-26 15:59:35 -0700112 }
113
David Howells31143d52007-05-09 02:33:46 -0700114 expected_version = status->data_version;
115 if (store_version)
116 expected_version = *store_version;
117
118 if (expected_version != data_version) {
David Howells260a9802007-04-26 15:59:35 -0700119 status->data_version = data_version;
120 if (vnode && !test_bit(AFS_VNODE_UNSET, &vnode->flags)) {
121 _debug("vnode modified %llx on {%x:%u}",
David S. Millerba3e0e12007-04-26 16:06:22 -0700122 (unsigned long long) data_version,
123 vnode->fid.vid, vnode->fid.vnode);
David Howells260a9802007-04-26 15:59:35 -0700124 set_bit(AFS_VNODE_MODIFIED, &vnode->flags);
125 set_bit(AFS_VNODE_ZAP_DATA, &vnode->flags);
126 }
David Howells31143d52007-05-09 02:33:46 -0700127 } else if (store_version) {
128 status->data_version = data_version;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 }
David Howellsec268152007-04-26 15:49:28 -0700130}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/*
David Howells08e0e7c2007-04-26 15:55:03 -0700133 * decode an AFSCallBack block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 */
David Howells08e0e7c2007-04-26 15:55:03 -0700135static void xdr_decode_AFSCallBack(const __be32 **_bp, struct afs_vnode *vnode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
David Howells08e0e7c2007-04-26 15:55:03 -0700137 const __be32 *bp = *_bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
David Howells08e0e7c2007-04-26 15:55:03 -0700139 vnode->cb_version = ntohl(*bp++);
140 vnode->cb_expiry = ntohl(*bp++);
141 vnode->cb_type = ntohl(*bp++);
142 vnode->cb_expires = vnode->cb_expiry + get_seconds();
143 *_bp = bp;
David Howellsec268152007-04-26 15:49:28 -0700144}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
David Howells260a9802007-04-26 15:59:35 -0700146static void xdr_decode_AFSCallBack_raw(const __be32 **_bp,
147 struct afs_callback *cb)
148{
149 const __be32 *bp = *_bp;
150
151 cb->version = ntohl(*bp++);
152 cb->expiry = ntohl(*bp++);
153 cb->type = ntohl(*bp++);
154 *_bp = bp;
155}
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157/*
David Howells08e0e7c2007-04-26 15:55:03 -0700158 * decode an AFSVolSync block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 */
David Howells08e0e7c2007-04-26 15:55:03 -0700160static void xdr_decode_AFSVolSync(const __be32 **_bp,
161 struct afs_volsync *volsync)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
David Howells08e0e7c2007-04-26 15:55:03 -0700163 const __be32 *bp = *_bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
David Howells08e0e7c2007-04-26 15:55:03 -0700165 volsync->creation = ntohl(*bp++);
166 bp++; /* spare2 */
167 bp++; /* spare3 */
168 bp++; /* spare4 */
169 bp++; /* spare5 */
170 bp++; /* spare6 */
171 *_bp = bp;
David Howellsec268152007-04-26 15:49:28 -0700172}
David Howells08e0e7c2007-04-26 15:55:03 -0700173
174/*
David Howells31143d52007-05-09 02:33:46 -0700175 * encode the requested attributes into an AFSStoreStatus block
176 */
177static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
178{
179 __be32 *bp = *_bp;
180 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
181
182 mask = 0;
183 if (attr->ia_valid & ATTR_MTIME) {
184 mask |= AFS_SET_MTIME;
185 mtime = attr->ia_mtime.tv_sec;
186 }
187
188 if (attr->ia_valid & ATTR_UID) {
189 mask |= AFS_SET_OWNER;
Eric W. Biedermana0a53862012-02-07 16:20:48 -0800190 owner = from_kuid(&init_user_ns, attr->ia_uid);
David Howells31143d52007-05-09 02:33:46 -0700191 }
192
193 if (attr->ia_valid & ATTR_GID) {
194 mask |= AFS_SET_GROUP;
Eric W. Biedermana0a53862012-02-07 16:20:48 -0800195 group = from_kgid(&init_user_ns, attr->ia_gid);
David Howells31143d52007-05-09 02:33:46 -0700196 }
197
198 if (attr->ia_valid & ATTR_MODE) {
199 mask |= AFS_SET_MODE;
200 mode = attr->ia_mode & S_IALLUGO;
201 }
202
203 *bp++ = htonl(mask);
204 *bp++ = htonl(mtime);
205 *bp++ = htonl(owner);
206 *bp++ = htonl(group);
207 *bp++ = htonl(mode);
208 *bp++ = 0; /* segment size */
209 *_bp = bp;
210}
211
212/*
David Howells45222b92007-05-10 22:22:20 -0700213 * decode an AFSFetchVolumeStatus block
214 */
215static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
216 struct afs_volume_status *vs)
217{
218 const __be32 *bp = *_bp;
219
220 vs->vid = ntohl(*bp++);
221 vs->parent_id = ntohl(*bp++);
222 vs->online = ntohl(*bp++);
223 vs->in_service = ntohl(*bp++);
224 vs->blessed = ntohl(*bp++);
225 vs->needs_salvage = ntohl(*bp++);
226 vs->type = ntohl(*bp++);
227 vs->min_quota = ntohl(*bp++);
228 vs->max_quota = ntohl(*bp++);
229 vs->blocks_in_use = ntohl(*bp++);
230 vs->part_blocks_avail = ntohl(*bp++);
231 vs->part_max_blocks = ntohl(*bp++);
232 *_bp = bp;
233}
234
235/*
David Howells08e0e7c2007-04-26 15:55:03 -0700236 * deliver reply data to an FS.FetchStatus
237 */
238static int afs_deliver_fs_fetch_status(struct afs_call *call,
239 struct sk_buff *skb, bool last)
240{
David Howells260a9802007-04-26 15:59:35 -0700241 struct afs_vnode *vnode = call->reply;
David Howells08e0e7c2007-04-26 15:55:03 -0700242 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100243 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700244
245 _enter(",,%u", last);
246
David Howells372ee162016-08-03 14:11:40 +0100247 ret = afs_transfer_reply(call, skb, last);
248 if (ret < 0)
249 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700250
251 /* unmarshall the reply once we've received all of it */
252 bp = call->buffer;
David Howells31143d52007-05-09 02:33:46 -0700253 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
David Howells260a9802007-04-26 15:59:35 -0700254 xdr_decode_AFSCallBack(&bp, vnode);
David Howells08e0e7c2007-04-26 15:55:03 -0700255 if (call->reply2)
256 xdr_decode_AFSVolSync(&bp, call->reply2);
257
258 _leave(" = 0 [done]");
259 return 0;
260}
261
262/*
263 * FS.FetchStatus operation type
264 */
265static const struct afs_call_type afs_RXFSFetchStatus = {
David Howells00d3b7a2007-04-26 15:57:07 -0700266 .name = "FS.FetchStatus",
David Howells08e0e7c2007-04-26 15:55:03 -0700267 .deliver = afs_deliver_fs_fetch_status,
268 .abort_to_error = afs_abort_to_error,
269 .destructor = afs_flat_call_destructor,
270};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272/*
273 * fetch the status information for a file
274 */
David Howells08e0e7c2007-04-26 15:55:03 -0700275int afs_fs_fetch_file_status(struct afs_server *server,
David Howells00d3b7a2007-04-26 15:57:07 -0700276 struct key *key,
David Howells08e0e7c2007-04-26 15:55:03 -0700277 struct afs_vnode *vnode,
278 struct afs_volsync *volsync,
279 const struct afs_wait_mode *wait_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
David Howells08e0e7c2007-04-26 15:55:03 -0700281 struct afs_call *call;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 __be32 *bp;
283
David Howells416351f2007-05-09 02:33:45 -0700284 _enter(",%x,{%x:%u},,",
David Howells260a9802007-04-26 15:59:35 -0700285 key_serial(key), vnode->fid.vid, vnode->fid.vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
David Howells260a9802007-04-26 15:59:35 -0700287 call = afs_alloc_flat_call(&afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700288 if (!call)
289 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
David Howells00d3b7a2007-04-26 15:57:07 -0700291 call->key = key;
David Howells08e0e7c2007-04-26 15:55:03 -0700292 call->reply = vnode;
293 call->reply2 = volsync;
294 call->service_id = FS_SERVICE;
295 call->port = htons(AFS_FS_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700298 bp = call->request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 bp[0] = htonl(FSFETCHSTATUS);
300 bp[1] = htonl(vnode->fid.vid);
301 bp[2] = htonl(vnode->fid.vnode);
302 bp[3] = htonl(vnode->fid.unique);
303
David Howells08e0e7c2007-04-26 15:55:03 -0700304 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
David Howellsec268152007-04-26 15:49:28 -0700305}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307/*
David Howells08e0e7c2007-04-26 15:55:03 -0700308 * deliver reply data to an FS.FetchData
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 */
David Howells08e0e7c2007-04-26 15:55:03 -0700310static int afs_deliver_fs_fetch_data(struct afs_call *call,
311 struct sk_buff *skb, bool last)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
David Howells260a9802007-04-26 15:59:35 -0700313 struct afs_vnode *vnode = call->reply;
David Howells08e0e7c2007-04-26 15:55:03 -0700314 const __be32 *bp;
315 struct page *page;
316 void *buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700318
319 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
320
321 switch (call->unmarshall) {
322 case 0:
323 call->offset = 0;
324 call->unmarshall++;
David Howellsb9b1f8d2007-05-10 03:15:21 -0700325 if (call->operation_ID != FSFETCHDATA64) {
326 call->unmarshall++;
327 goto no_msw;
328 }
David Howells08e0e7c2007-04-26 15:55:03 -0700329
David Howellsb9b1f8d2007-05-10 03:15:21 -0700330 /* extract the upper part of the returned data length of an
331 * FSFETCHDATA64 op (which should always be 0 using this
332 * client) */
David Howells08e0e7c2007-04-26 15:55:03 -0700333 case 1:
David Howellsb9b1f8d2007-05-10 03:15:21 -0700334 _debug("extract data length (MSW)");
335 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
David Howells372ee162016-08-03 14:11:40 +0100336 if (ret < 0)
337 return ret;
David Howellsb9b1f8d2007-05-10 03:15:21 -0700338
339 call->count = ntohl(call->tmp);
340 _debug("DATA length MSW: %u", call->count);
341 if (call->count > 0)
342 return -EBADMSG;
343 call->offset = 0;
344 call->unmarshall++;
345
346 no_msw:
347 /* extract the returned data length */
348 case 2:
David Howells08e0e7c2007-04-26 15:55:03 -0700349 _debug("extract data length");
350 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
David Howells372ee162016-08-03 14:11:40 +0100351 if (ret < 0)
352 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700353
354 call->count = ntohl(call->tmp);
355 _debug("DATA length: %u", call->count);
356 if (call->count > PAGE_SIZE)
357 return -EBADMSG;
358 call->offset = 0;
359 call->unmarshall++;
360
David Howells08e0e7c2007-04-26 15:55:03 -0700361 /* extract the returned data */
David Howellsb9b1f8d2007-05-10 03:15:21 -0700362 case 3:
David Howells08e0e7c2007-04-26 15:55:03 -0700363 _debug("extract data");
David Howells416351f2007-05-09 02:33:45 -0700364 if (call->count > 0) {
365 page = call->reply3;
Cong Wangda4aa362011-11-25 23:14:26 +0800366 buffer = kmap_atomic(page);
David Howells416351f2007-05-09 02:33:45 -0700367 ret = afs_extract_data(call, skb, last, buffer,
368 call->count);
Cong Wangda4aa362011-11-25 23:14:26 +0800369 kunmap_atomic(buffer);
David Howells372ee162016-08-03 14:11:40 +0100370 if (ret < 0)
371 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700372 }
373
374 call->offset = 0;
375 call->unmarshall++;
376
377 /* extract the metadata */
David Howellsb9b1f8d2007-05-10 03:15:21 -0700378 case 4:
David Howells260a9802007-04-26 15:59:35 -0700379 ret = afs_extract_data(call, skb, last, call->buffer,
380 (21 + 3 + 6) * 4);
David Howells372ee162016-08-03 14:11:40 +0100381 if (ret < 0)
382 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700383
384 bp = call->buffer;
David Howells31143d52007-05-09 02:33:46 -0700385 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
David Howells260a9802007-04-26 15:59:35 -0700386 xdr_decode_AFSCallBack(&bp, vnode);
David Howells08e0e7c2007-04-26 15:55:03 -0700387 if (call->reply2)
388 xdr_decode_AFSVolSync(&bp, call->reply2);
389
390 call->offset = 0;
391 call->unmarshall++;
392
David Howellsb9b1f8d2007-05-10 03:15:21 -0700393 case 5:
David Howells372ee162016-08-03 14:11:40 +0100394 ret = afs_data_complete(call, skb, last);
395 if (ret < 0)
396 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700397 break;
398 }
399
David Howells416351f2007-05-09 02:33:45 -0700400 if (call->count < PAGE_SIZE) {
401 _debug("clear");
402 page = call->reply3;
Cong Wangda4aa362011-11-25 23:14:26 +0800403 buffer = kmap_atomic(page);
David Howells416351f2007-05-09 02:33:45 -0700404 memset(buffer + call->count, 0, PAGE_SIZE - call->count);
Cong Wangda4aa362011-11-25 23:14:26 +0800405 kunmap_atomic(buffer);
David Howells416351f2007-05-09 02:33:45 -0700406 }
407
David Howells08e0e7c2007-04-26 15:55:03 -0700408 _leave(" = 0 [done]");
409 return 0;
410}
411
412/*
413 * FS.FetchData operation type
414 */
415static const struct afs_call_type afs_RXFSFetchData = {
David Howells00d3b7a2007-04-26 15:57:07 -0700416 .name = "FS.FetchData",
David Howells08e0e7c2007-04-26 15:55:03 -0700417 .deliver = afs_deliver_fs_fetch_data,
418 .abort_to_error = afs_abort_to_error,
419 .destructor = afs_flat_call_destructor,
420};
421
David Howellsb9b1f8d2007-05-10 03:15:21 -0700422static const struct afs_call_type afs_RXFSFetchData64 = {
423 .name = "FS.FetchData64",
424 .deliver = afs_deliver_fs_fetch_data,
425 .abort_to_error = afs_abort_to_error,
426 .destructor = afs_flat_call_destructor,
427};
428
429/*
430 * fetch data from a very large file
431 */
432static int afs_fs_fetch_data64(struct afs_server *server,
433 struct key *key,
434 struct afs_vnode *vnode,
435 off_t offset, size_t length,
436 struct page *buffer,
437 const struct afs_wait_mode *wait_mode)
438{
439 struct afs_call *call;
440 __be32 *bp;
441
442 _enter("");
443
444 ASSERTCMP(length, <, ULONG_MAX);
445
446 call = afs_alloc_flat_call(&afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
447 if (!call)
448 return -ENOMEM;
449
450 call->key = key;
451 call->reply = vnode;
452 call->reply2 = NULL; /* volsync */
453 call->reply3 = buffer;
454 call->service_id = FS_SERVICE;
455 call->port = htons(AFS_FS_PORT);
456 call->operation_ID = FSFETCHDATA64;
457
458 /* marshall the parameters */
459 bp = call->request;
460 bp[0] = htonl(FSFETCHDATA64);
461 bp[1] = htonl(vnode->fid.vid);
462 bp[2] = htonl(vnode->fid.vnode);
463 bp[3] = htonl(vnode->fid.unique);
464 bp[4] = htonl(upper_32_bits(offset));
465 bp[5] = htonl((u32) offset);
466 bp[6] = 0;
467 bp[7] = htonl((u32) length);
468
469 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
470}
471
David Howells08e0e7c2007-04-26 15:55:03 -0700472/*
473 * fetch data from a file
474 */
475int afs_fs_fetch_data(struct afs_server *server,
David Howells00d3b7a2007-04-26 15:57:07 -0700476 struct key *key,
David Howells08e0e7c2007-04-26 15:55:03 -0700477 struct afs_vnode *vnode,
478 off_t offset, size_t length,
479 struct page *buffer,
David Howells08e0e7c2007-04-26 15:55:03 -0700480 const struct afs_wait_mode *wait_mode)
481{
482 struct afs_call *call;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 __be32 *bp;
484
David Howellsb9b1f8d2007-05-10 03:15:21 -0700485 if (upper_32_bits(offset) || upper_32_bits(offset + length))
486 return afs_fs_fetch_data64(server, key, vnode, offset, length,
487 buffer, wait_mode);
488
David Howells08e0e7c2007-04-26 15:55:03 -0700489 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
David Howells260a9802007-04-26 15:59:35 -0700491 call = afs_alloc_flat_call(&afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700492 if (!call)
493 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
David Howells00d3b7a2007-04-26 15:57:07 -0700495 call->key = key;
David Howells08e0e7c2007-04-26 15:55:03 -0700496 call->reply = vnode;
David Howells260a9802007-04-26 15:59:35 -0700497 call->reply2 = NULL; /* volsync */
David Howells08e0e7c2007-04-26 15:55:03 -0700498 call->reply3 = buffer;
499 call->service_id = FS_SERVICE;
500 call->port = htons(AFS_FS_PORT);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700501 call->operation_ID = FSFETCHDATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700504 bp = call->request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 bp[0] = htonl(FSFETCHDATA);
David Howells08e0e7c2007-04-26 15:55:03 -0700506 bp[1] = htonl(vnode->fid.vid);
507 bp[2] = htonl(vnode->fid.vnode);
508 bp[3] = htonl(vnode->fid.unique);
509 bp[4] = htonl(offset);
510 bp[5] = htonl(length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
David Howells08e0e7c2007-04-26 15:55:03 -0700512 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
David Howellsec268152007-04-26 15:49:28 -0700513}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515/*
David Howells08e0e7c2007-04-26 15:55:03 -0700516 * deliver reply data to an FS.GiveUpCallBacks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 */
David Howells08e0e7c2007-04-26 15:55:03 -0700518static int afs_deliver_fs_give_up_callbacks(struct afs_call *call,
519 struct sk_buff *skb, bool last)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520{
David Howells08e0e7c2007-04-26 15:55:03 -0700521 _enter(",{%u},%d", skb->len, last);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
David Howells372ee162016-08-03 14:11:40 +0100523 /* shouldn't be any reply data */
524 return afs_data_complete(call, skb, last);
David Howells08e0e7c2007-04-26 15:55:03 -0700525}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
David Howells08e0e7c2007-04-26 15:55:03 -0700527/*
528 * FS.GiveUpCallBacks operation type
529 */
530static const struct afs_call_type afs_RXFSGiveUpCallBacks = {
David Howells00d3b7a2007-04-26 15:57:07 -0700531 .name = "FS.GiveUpCallBacks",
David Howells08e0e7c2007-04-26 15:55:03 -0700532 .deliver = afs_deliver_fs_give_up_callbacks,
533 .abort_to_error = afs_abort_to_error,
534 .destructor = afs_flat_call_destructor,
535};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
David Howells08e0e7c2007-04-26 15:55:03 -0700537/*
538 * give up a set of callbacks
539 * - the callbacks are held in the server->cb_break ring
540 */
541int afs_fs_give_up_callbacks(struct afs_server *server,
542 const struct afs_wait_mode *wait_mode)
543{
544 struct afs_call *call;
545 size_t ncallbacks;
546 __be32 *bp, *tp;
547 int loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
David Howells08e0e7c2007-04-26 15:55:03 -0700549 ncallbacks = CIRC_CNT(server->cb_break_head, server->cb_break_tail,
550 ARRAY_SIZE(server->cb_break));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
David Howells08e0e7c2007-04-26 15:55:03 -0700552 _enter("{%zu},", ncallbacks);
553
554 if (ncallbacks == 0)
555 return 0;
556 if (ncallbacks > AFSCBMAX)
557 ncallbacks = AFSCBMAX;
558
559 _debug("break %zu callbacks", ncallbacks);
560
561 call = afs_alloc_flat_call(&afs_RXFSGiveUpCallBacks,
562 12 + ncallbacks * 6 * 4, 0);
563 if (!call)
564 return -ENOMEM;
565
566 call->service_id = FS_SERVICE;
567 call->port = htons(AFS_FS_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
569 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700570 bp = call->request;
571 tp = bp + 2 + ncallbacks * 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 *bp++ = htonl(FSGIVEUPCALLBACKS);
David Howells08e0e7c2007-04-26 15:55:03 -0700573 *bp++ = htonl(ncallbacks);
574 *tp++ = htonl(ncallbacks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
David Howells08e0e7c2007-04-26 15:55:03 -0700576 atomic_sub(ncallbacks, &server->cb_break_n);
577 for (loop = ncallbacks; loop > 0; loop--) {
578 struct afs_callback *cb =
579 &server->cb_break[server->cb_break_tail];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
David Howells08e0e7c2007-04-26 15:55:03 -0700581 *bp++ = htonl(cb->fid.vid);
582 *bp++ = htonl(cb->fid.vnode);
583 *bp++ = htonl(cb->fid.unique);
584 *tp++ = htonl(cb->version);
585 *tp++ = htonl(cb->expiry);
586 *tp++ = htonl(cb->type);
587 smp_mb();
588 server->cb_break_tail =
589 (server->cb_break_tail + 1) &
590 (ARRAY_SIZE(server->cb_break) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 }
592
David Howells08e0e7c2007-04-26 15:55:03 -0700593 ASSERT(ncallbacks > 0);
594 wake_up_nr(&server->cb_break_waitq, ncallbacks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
David Howells08e0e7c2007-04-26 15:55:03 -0700596 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
David Howellsec268152007-04-26 15:49:28 -0700597}
David Howells260a9802007-04-26 15:59:35 -0700598
599/*
600 * deliver reply data to an FS.CreateFile or an FS.MakeDir
601 */
602static int afs_deliver_fs_create_vnode(struct afs_call *call,
603 struct sk_buff *skb, bool last)
604{
605 struct afs_vnode *vnode = call->reply;
606 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100607 int ret;
David Howells260a9802007-04-26 15:59:35 -0700608
609 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
610
David Howells372ee162016-08-03 14:11:40 +0100611 ret = afs_transfer_reply(call, skb, last);
612 if (ret < 0)
613 return ret;
David Howells260a9802007-04-26 15:59:35 -0700614
615 /* unmarshall the reply once we've received all of it */
616 bp = call->buffer;
617 xdr_decode_AFSFid(&bp, call->reply2);
David Howells31143d52007-05-09 02:33:46 -0700618 xdr_decode_AFSFetchStatus(&bp, call->reply3, NULL, NULL);
619 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
David Howells260a9802007-04-26 15:59:35 -0700620 xdr_decode_AFSCallBack_raw(&bp, call->reply4);
621 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
622
623 _leave(" = 0 [done]");
624 return 0;
625}
626
627/*
628 * FS.CreateFile and FS.MakeDir operation type
629 */
630static const struct afs_call_type afs_RXFSCreateXXXX = {
631 .name = "FS.CreateXXXX",
632 .deliver = afs_deliver_fs_create_vnode,
633 .abort_to_error = afs_abort_to_error,
634 .destructor = afs_flat_call_destructor,
635};
636
637/*
638 * create a file or make a directory
639 */
640int afs_fs_create(struct afs_server *server,
641 struct key *key,
642 struct afs_vnode *vnode,
643 const char *name,
644 umode_t mode,
645 struct afs_fid *newfid,
646 struct afs_file_status *newstatus,
647 struct afs_callback *newcb,
648 const struct afs_wait_mode *wait_mode)
649{
650 struct afs_call *call;
651 size_t namesz, reqsz, padsz;
652 __be32 *bp;
653
654 _enter("");
655
656 namesz = strlen(name);
657 padsz = (4 - (namesz & 3)) & 3;
658 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
659
660 call = afs_alloc_flat_call(&afs_RXFSCreateXXXX, reqsz,
661 (3 + 21 + 21 + 3 + 6) * 4);
662 if (!call)
663 return -ENOMEM;
664
665 call->key = key;
666 call->reply = vnode;
667 call->reply2 = newfid;
668 call->reply3 = newstatus;
669 call->reply4 = newcb;
670 call->service_id = FS_SERVICE;
671 call->port = htons(AFS_FS_PORT);
672
673 /* marshall the parameters */
674 bp = call->request;
675 *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
676 *bp++ = htonl(vnode->fid.vid);
677 *bp++ = htonl(vnode->fid.vnode);
678 *bp++ = htonl(vnode->fid.unique);
679 *bp++ = htonl(namesz);
680 memcpy(bp, name, namesz);
681 bp = (void *) bp + namesz;
682 if (padsz > 0) {
683 memset(bp, 0, padsz);
684 bp = (void *) bp + padsz;
685 }
686 *bp++ = htonl(AFS_SET_MODE);
687 *bp++ = 0; /* mtime */
688 *bp++ = 0; /* owner */
689 *bp++ = 0; /* group */
690 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
691 *bp++ = 0; /* segment size */
692
693 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
694}
695
696/*
697 * deliver reply data to an FS.RemoveFile or FS.RemoveDir
698 */
699static int afs_deliver_fs_remove(struct afs_call *call,
700 struct sk_buff *skb, bool last)
701{
702 struct afs_vnode *vnode = call->reply;
703 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100704 int ret;
David Howells260a9802007-04-26 15:59:35 -0700705
706 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
707
David Howells372ee162016-08-03 14:11:40 +0100708 ret = afs_transfer_reply(call, skb, last);
709 if (ret < 0)
710 return ret;
David Howells260a9802007-04-26 15:59:35 -0700711
712 /* unmarshall the reply once we've received all of it */
713 bp = call->buffer;
David Howells31143d52007-05-09 02:33:46 -0700714 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
David Howells260a9802007-04-26 15:59:35 -0700715 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
716
717 _leave(" = 0 [done]");
718 return 0;
719}
720
721/*
722 * FS.RemoveDir/FS.RemoveFile operation type
723 */
724static const struct afs_call_type afs_RXFSRemoveXXXX = {
725 .name = "FS.RemoveXXXX",
726 .deliver = afs_deliver_fs_remove,
727 .abort_to_error = afs_abort_to_error,
728 .destructor = afs_flat_call_destructor,
729};
730
731/*
732 * remove a file or directory
733 */
734int afs_fs_remove(struct afs_server *server,
735 struct key *key,
736 struct afs_vnode *vnode,
737 const char *name,
738 bool isdir,
739 const struct afs_wait_mode *wait_mode)
740{
741 struct afs_call *call;
742 size_t namesz, reqsz, padsz;
743 __be32 *bp;
744
745 _enter("");
746
747 namesz = strlen(name);
748 padsz = (4 - (namesz & 3)) & 3;
749 reqsz = (5 * 4) + namesz + padsz;
750
751 call = afs_alloc_flat_call(&afs_RXFSRemoveXXXX, reqsz, (21 + 6) * 4);
752 if (!call)
753 return -ENOMEM;
754
755 call->key = key;
756 call->reply = vnode;
757 call->service_id = FS_SERVICE;
758 call->port = htons(AFS_FS_PORT);
759
760 /* marshall the parameters */
761 bp = call->request;
762 *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
763 *bp++ = htonl(vnode->fid.vid);
764 *bp++ = htonl(vnode->fid.vnode);
765 *bp++ = htonl(vnode->fid.unique);
766 *bp++ = htonl(namesz);
767 memcpy(bp, name, namesz);
768 bp = (void *) bp + namesz;
769 if (padsz > 0) {
770 memset(bp, 0, padsz);
771 bp = (void *) bp + padsz;
772 }
773
774 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
775}
776
777/*
778 * deliver reply data to an FS.Link
779 */
780static int afs_deliver_fs_link(struct afs_call *call,
781 struct sk_buff *skb, bool last)
782{
783 struct afs_vnode *dvnode = call->reply, *vnode = call->reply2;
784 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100785 int ret;
David Howells260a9802007-04-26 15:59:35 -0700786
787 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
788
David Howells372ee162016-08-03 14:11:40 +0100789 ret = afs_transfer_reply(call, skb, last);
790 if (ret < 0)
791 return ret;
David Howells260a9802007-04-26 15:59:35 -0700792
793 /* unmarshall the reply once we've received all of it */
794 bp = call->buffer;
David Howells31143d52007-05-09 02:33:46 -0700795 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
796 xdr_decode_AFSFetchStatus(&bp, &dvnode->status, dvnode, NULL);
David Howells260a9802007-04-26 15:59:35 -0700797 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
798
799 _leave(" = 0 [done]");
800 return 0;
801}
802
803/*
804 * FS.Link operation type
805 */
806static const struct afs_call_type afs_RXFSLink = {
807 .name = "FS.Link",
808 .deliver = afs_deliver_fs_link,
809 .abort_to_error = afs_abort_to_error,
810 .destructor = afs_flat_call_destructor,
811};
812
813/*
814 * make a hard link
815 */
816int afs_fs_link(struct afs_server *server,
817 struct key *key,
818 struct afs_vnode *dvnode,
819 struct afs_vnode *vnode,
820 const char *name,
821 const struct afs_wait_mode *wait_mode)
822{
823 struct afs_call *call;
824 size_t namesz, reqsz, padsz;
825 __be32 *bp;
826
827 _enter("");
828
829 namesz = strlen(name);
830 padsz = (4 - (namesz & 3)) & 3;
831 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
832
833 call = afs_alloc_flat_call(&afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
834 if (!call)
835 return -ENOMEM;
836
837 call->key = key;
838 call->reply = dvnode;
839 call->reply2 = vnode;
840 call->service_id = FS_SERVICE;
841 call->port = htons(AFS_FS_PORT);
842
843 /* marshall the parameters */
844 bp = call->request;
845 *bp++ = htonl(FSLINK);
846 *bp++ = htonl(dvnode->fid.vid);
847 *bp++ = htonl(dvnode->fid.vnode);
848 *bp++ = htonl(dvnode->fid.unique);
849 *bp++ = htonl(namesz);
850 memcpy(bp, name, namesz);
851 bp = (void *) bp + namesz;
852 if (padsz > 0) {
853 memset(bp, 0, padsz);
854 bp = (void *) bp + padsz;
855 }
856 *bp++ = htonl(vnode->fid.vid);
857 *bp++ = htonl(vnode->fid.vnode);
858 *bp++ = htonl(vnode->fid.unique);
859
860 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
861}
862
863/*
864 * deliver reply data to an FS.Symlink
865 */
866static int afs_deliver_fs_symlink(struct afs_call *call,
867 struct sk_buff *skb, bool last)
868{
869 struct afs_vnode *vnode = call->reply;
870 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100871 int ret;
David Howells260a9802007-04-26 15:59:35 -0700872
873 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
874
David Howells372ee162016-08-03 14:11:40 +0100875 ret = afs_transfer_reply(call, skb, last);
876 if (ret < 0)
877 return ret;
David Howells260a9802007-04-26 15:59:35 -0700878
879 /* unmarshall the reply once we've received all of it */
880 bp = call->buffer;
881 xdr_decode_AFSFid(&bp, call->reply2);
David Howells31143d52007-05-09 02:33:46 -0700882 xdr_decode_AFSFetchStatus(&bp, call->reply3, NULL, NULL);
883 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
David Howells260a9802007-04-26 15:59:35 -0700884 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
885
886 _leave(" = 0 [done]");
887 return 0;
888}
889
890/*
891 * FS.Symlink operation type
892 */
893static const struct afs_call_type afs_RXFSSymlink = {
894 .name = "FS.Symlink",
895 .deliver = afs_deliver_fs_symlink,
896 .abort_to_error = afs_abort_to_error,
897 .destructor = afs_flat_call_destructor,
898};
899
900/*
901 * create a symbolic link
902 */
903int afs_fs_symlink(struct afs_server *server,
904 struct key *key,
905 struct afs_vnode *vnode,
906 const char *name,
907 const char *contents,
908 struct afs_fid *newfid,
909 struct afs_file_status *newstatus,
910 const struct afs_wait_mode *wait_mode)
911{
912 struct afs_call *call;
913 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
914 __be32 *bp;
915
916 _enter("");
917
918 namesz = strlen(name);
919 padsz = (4 - (namesz & 3)) & 3;
920
921 c_namesz = strlen(contents);
922 c_padsz = (4 - (c_namesz & 3)) & 3;
923
924 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
925
926 call = afs_alloc_flat_call(&afs_RXFSSymlink, reqsz,
927 (3 + 21 + 21 + 6) * 4);
928 if (!call)
929 return -ENOMEM;
930
931 call->key = key;
932 call->reply = vnode;
933 call->reply2 = newfid;
934 call->reply3 = newstatus;
935 call->service_id = FS_SERVICE;
936 call->port = htons(AFS_FS_PORT);
937
938 /* marshall the parameters */
939 bp = call->request;
940 *bp++ = htonl(FSSYMLINK);
941 *bp++ = htonl(vnode->fid.vid);
942 *bp++ = htonl(vnode->fid.vnode);
943 *bp++ = htonl(vnode->fid.unique);
944 *bp++ = htonl(namesz);
945 memcpy(bp, name, namesz);
946 bp = (void *) bp + namesz;
947 if (padsz > 0) {
948 memset(bp, 0, padsz);
949 bp = (void *) bp + padsz;
950 }
951 *bp++ = htonl(c_namesz);
952 memcpy(bp, contents, c_namesz);
953 bp = (void *) bp + c_namesz;
954 if (c_padsz > 0) {
955 memset(bp, 0, c_padsz);
956 bp = (void *) bp + c_padsz;
957 }
958 *bp++ = htonl(AFS_SET_MODE);
959 *bp++ = 0; /* mtime */
960 *bp++ = 0; /* owner */
961 *bp++ = 0; /* group */
962 *bp++ = htonl(S_IRWXUGO); /* unix mode */
963 *bp++ = 0; /* segment size */
964
965 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
966}
967
968/*
969 * deliver reply data to an FS.Rename
970 */
971static int afs_deliver_fs_rename(struct afs_call *call,
972 struct sk_buff *skb, bool last)
973{
974 struct afs_vnode *orig_dvnode = call->reply, *new_dvnode = call->reply2;
975 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100976 int ret;
David Howells260a9802007-04-26 15:59:35 -0700977
978 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
979
David Howells372ee162016-08-03 14:11:40 +0100980 ret = afs_transfer_reply(call, skb, last);
981 if (ret < 0)
982 return ret;
David Howells260a9802007-04-26 15:59:35 -0700983
984 /* unmarshall the reply once we've received all of it */
985 bp = call->buffer;
David Howells31143d52007-05-09 02:33:46 -0700986 xdr_decode_AFSFetchStatus(&bp, &orig_dvnode->status, orig_dvnode, NULL);
David Howells260a9802007-04-26 15:59:35 -0700987 if (new_dvnode != orig_dvnode)
David Howells31143d52007-05-09 02:33:46 -0700988 xdr_decode_AFSFetchStatus(&bp, &new_dvnode->status, new_dvnode,
989 NULL);
David Howells260a9802007-04-26 15:59:35 -0700990 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
991
992 _leave(" = 0 [done]");
993 return 0;
994}
995
996/*
997 * FS.Rename operation type
998 */
999static const struct afs_call_type afs_RXFSRename = {
1000 .name = "FS.Rename",
1001 .deliver = afs_deliver_fs_rename,
1002 .abort_to_error = afs_abort_to_error,
1003 .destructor = afs_flat_call_destructor,
1004};
1005
1006/*
1007 * create a symbolic link
1008 */
1009int afs_fs_rename(struct afs_server *server,
1010 struct key *key,
1011 struct afs_vnode *orig_dvnode,
1012 const char *orig_name,
1013 struct afs_vnode *new_dvnode,
1014 const char *new_name,
1015 const struct afs_wait_mode *wait_mode)
1016{
1017 struct afs_call *call;
1018 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1019 __be32 *bp;
1020
1021 _enter("");
1022
1023 o_namesz = strlen(orig_name);
1024 o_padsz = (4 - (o_namesz & 3)) & 3;
1025
1026 n_namesz = strlen(new_name);
1027 n_padsz = (4 - (n_namesz & 3)) & 3;
1028
1029 reqsz = (4 * 4) +
1030 4 + o_namesz + o_padsz +
1031 (3 * 4) +
1032 4 + n_namesz + n_padsz;
1033
1034 call = afs_alloc_flat_call(&afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
1035 if (!call)
1036 return -ENOMEM;
1037
1038 call->key = key;
1039 call->reply = orig_dvnode;
1040 call->reply2 = new_dvnode;
1041 call->service_id = FS_SERVICE;
1042 call->port = htons(AFS_FS_PORT);
1043
1044 /* marshall the parameters */
1045 bp = call->request;
1046 *bp++ = htonl(FSRENAME);
1047 *bp++ = htonl(orig_dvnode->fid.vid);
1048 *bp++ = htonl(orig_dvnode->fid.vnode);
1049 *bp++ = htonl(orig_dvnode->fid.unique);
1050 *bp++ = htonl(o_namesz);
1051 memcpy(bp, orig_name, o_namesz);
1052 bp = (void *) bp + o_namesz;
1053 if (o_padsz > 0) {
1054 memset(bp, 0, o_padsz);
1055 bp = (void *) bp + o_padsz;
1056 }
1057
1058 *bp++ = htonl(new_dvnode->fid.vid);
1059 *bp++ = htonl(new_dvnode->fid.vnode);
1060 *bp++ = htonl(new_dvnode->fid.unique);
1061 *bp++ = htonl(n_namesz);
1062 memcpy(bp, new_name, n_namesz);
1063 bp = (void *) bp + n_namesz;
1064 if (n_padsz > 0) {
1065 memset(bp, 0, n_padsz);
1066 bp = (void *) bp + n_padsz;
1067 }
1068
1069 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1070}
David Howells31143d52007-05-09 02:33:46 -07001071
1072/*
1073 * deliver reply data to an FS.StoreData
1074 */
1075static int afs_deliver_fs_store_data(struct afs_call *call,
1076 struct sk_buff *skb, bool last)
1077{
1078 struct afs_vnode *vnode = call->reply;
1079 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001080 int ret;
David Howells31143d52007-05-09 02:33:46 -07001081
1082 _enter(",,%u", last);
1083
David Howells372ee162016-08-03 14:11:40 +01001084 ret = afs_transfer_reply(call, skb, last);
1085 if (ret < 0)
1086 return ret;
David Howells31143d52007-05-09 02:33:46 -07001087
1088 /* unmarshall the reply once we've received all of it */
1089 bp = call->buffer;
1090 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode,
1091 &call->store_version);
1092 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
1093
1094 afs_pages_written_back(vnode, call);
1095
1096 _leave(" = 0 [done]");
1097 return 0;
1098}
1099
1100/*
1101 * FS.StoreData operation type
1102 */
1103static const struct afs_call_type afs_RXFSStoreData = {
1104 .name = "FS.StoreData",
1105 .deliver = afs_deliver_fs_store_data,
1106 .abort_to_error = afs_abort_to_error,
1107 .destructor = afs_flat_call_destructor,
1108};
1109
David Howellsb9b1f8d2007-05-10 03:15:21 -07001110static const struct afs_call_type afs_RXFSStoreData64 = {
1111 .name = "FS.StoreData64",
1112 .deliver = afs_deliver_fs_store_data,
1113 .abort_to_error = afs_abort_to_error,
1114 .destructor = afs_flat_call_destructor,
1115};
1116
1117/*
1118 * store a set of pages to a very large file
1119 */
1120static int afs_fs_store_data64(struct afs_server *server,
1121 struct afs_writeback *wb,
1122 pgoff_t first, pgoff_t last,
1123 unsigned offset, unsigned to,
1124 loff_t size, loff_t pos, loff_t i_size,
1125 const struct afs_wait_mode *wait_mode)
1126{
1127 struct afs_vnode *vnode = wb->vnode;
1128 struct afs_call *call;
1129 __be32 *bp;
1130
1131 _enter(",%x,{%x:%u},,",
1132 key_serial(wb->key), vnode->fid.vid, vnode->fid.vnode);
1133
1134 call = afs_alloc_flat_call(&afs_RXFSStoreData64,
1135 (4 + 6 + 3 * 2) * 4,
1136 (21 + 6) * 4);
1137 if (!call)
1138 return -ENOMEM;
1139
1140 call->wb = wb;
1141 call->key = wb->key;
1142 call->reply = vnode;
1143 call->service_id = FS_SERVICE;
1144 call->port = htons(AFS_FS_PORT);
1145 call->mapping = vnode->vfs_inode.i_mapping;
1146 call->first = first;
1147 call->last = last;
1148 call->first_offset = offset;
1149 call->last_to = to;
1150 call->send_pages = true;
1151 call->store_version = vnode->status.data_version + 1;
1152
1153 /* marshall the parameters */
1154 bp = call->request;
1155 *bp++ = htonl(FSSTOREDATA64);
1156 *bp++ = htonl(vnode->fid.vid);
1157 *bp++ = htonl(vnode->fid.vnode);
1158 *bp++ = htonl(vnode->fid.unique);
1159
1160 *bp++ = 0; /* mask */
1161 *bp++ = 0; /* mtime */
1162 *bp++ = 0; /* owner */
1163 *bp++ = 0; /* group */
1164 *bp++ = 0; /* unix mode */
1165 *bp++ = 0; /* segment size */
1166
1167 *bp++ = htonl(pos >> 32);
1168 *bp++ = htonl((u32) pos);
1169 *bp++ = htonl(size >> 32);
1170 *bp++ = htonl((u32) size);
1171 *bp++ = htonl(i_size >> 32);
1172 *bp++ = htonl((u32) i_size);
1173
1174 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1175}
1176
David Howells31143d52007-05-09 02:33:46 -07001177/*
1178 * store a set of pages
1179 */
1180int afs_fs_store_data(struct afs_server *server, struct afs_writeback *wb,
1181 pgoff_t first, pgoff_t last,
1182 unsigned offset, unsigned to,
1183 const struct afs_wait_mode *wait_mode)
1184{
1185 struct afs_vnode *vnode = wb->vnode;
1186 struct afs_call *call;
1187 loff_t size, pos, i_size;
1188 __be32 *bp;
1189
1190 _enter(",%x,{%x:%u},,",
1191 key_serial(wb->key), vnode->fid.vid, vnode->fid.vnode);
1192
1193 size = to - offset;
1194 if (first != last)
1195 size += (loff_t)(last - first) << PAGE_SHIFT;
1196 pos = (loff_t)first << PAGE_SHIFT;
1197 pos += offset;
1198
1199 i_size = i_size_read(&vnode->vfs_inode);
1200 if (pos + size > i_size)
1201 i_size = size + pos;
1202
1203 _debug("size %llx, at %llx, i_size %llx",
1204 (unsigned long long) size, (unsigned long long) pos,
1205 (unsigned long long) i_size);
1206
David Howellsb9b1f8d2007-05-10 03:15:21 -07001207 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
1208 return afs_fs_store_data64(server, wb, first, last, offset, to,
1209 size, pos, i_size, wait_mode);
David Howells31143d52007-05-09 02:33:46 -07001210
1211 call = afs_alloc_flat_call(&afs_RXFSStoreData,
1212 (4 + 6 + 3) * 4,
1213 (21 + 6) * 4);
1214 if (!call)
1215 return -ENOMEM;
1216
1217 call->wb = wb;
1218 call->key = wb->key;
1219 call->reply = vnode;
1220 call->service_id = FS_SERVICE;
1221 call->port = htons(AFS_FS_PORT);
1222 call->mapping = vnode->vfs_inode.i_mapping;
1223 call->first = first;
1224 call->last = last;
1225 call->first_offset = offset;
1226 call->last_to = to;
1227 call->send_pages = true;
1228 call->store_version = vnode->status.data_version + 1;
1229
1230 /* marshall the parameters */
1231 bp = call->request;
1232 *bp++ = htonl(FSSTOREDATA);
1233 *bp++ = htonl(vnode->fid.vid);
1234 *bp++ = htonl(vnode->fid.vnode);
1235 *bp++ = htonl(vnode->fid.unique);
1236
1237 *bp++ = 0; /* mask */
1238 *bp++ = 0; /* mtime */
1239 *bp++ = 0; /* owner */
1240 *bp++ = 0; /* group */
1241 *bp++ = 0; /* unix mode */
1242 *bp++ = 0; /* segment size */
1243
1244 *bp++ = htonl(pos);
1245 *bp++ = htonl(size);
1246 *bp++ = htonl(i_size);
1247
1248 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1249}
1250
1251/*
1252 * deliver reply data to an FS.StoreStatus
1253 */
1254static int afs_deliver_fs_store_status(struct afs_call *call,
1255 struct sk_buff *skb, bool last)
1256{
1257 afs_dataversion_t *store_version;
1258 struct afs_vnode *vnode = call->reply;
1259 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001260 int ret;
David Howells31143d52007-05-09 02:33:46 -07001261
1262 _enter(",,%u", last);
1263
David Howells372ee162016-08-03 14:11:40 +01001264 ret = afs_transfer_reply(call, skb, last);
1265 if (ret < 0)
1266 return ret;
David Howells31143d52007-05-09 02:33:46 -07001267
1268 /* unmarshall the reply once we've received all of it */
1269 store_version = NULL;
1270 if (call->operation_ID == FSSTOREDATA)
1271 store_version = &call->store_version;
1272
1273 bp = call->buffer;
1274 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, store_version);
1275 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
1276
1277 _leave(" = 0 [done]");
1278 return 0;
1279}
1280
1281/*
1282 * FS.StoreStatus operation type
1283 */
1284static const struct afs_call_type afs_RXFSStoreStatus = {
1285 .name = "FS.StoreStatus",
1286 .deliver = afs_deliver_fs_store_status,
1287 .abort_to_error = afs_abort_to_error,
1288 .destructor = afs_flat_call_destructor,
1289};
1290
1291static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1292 .name = "FS.StoreData",
1293 .deliver = afs_deliver_fs_store_status,
1294 .abort_to_error = afs_abort_to_error,
1295 .destructor = afs_flat_call_destructor,
1296};
1297
David Howellsb9b1f8d2007-05-10 03:15:21 -07001298static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1299 .name = "FS.StoreData64",
1300 .deliver = afs_deliver_fs_store_status,
1301 .abort_to_error = afs_abort_to_error,
1302 .destructor = afs_flat_call_destructor,
1303};
1304
1305/*
1306 * set the attributes on a very large file, using FS.StoreData rather than
1307 * FS.StoreStatus so as to alter the file size also
1308 */
1309static int afs_fs_setattr_size64(struct afs_server *server, struct key *key,
1310 struct afs_vnode *vnode, struct iattr *attr,
1311 const struct afs_wait_mode *wait_mode)
1312{
1313 struct afs_call *call;
1314 __be32 *bp;
1315
1316 _enter(",%x,{%x:%u},,",
1317 key_serial(key), vnode->fid.vid, vnode->fid.vnode);
1318
1319 ASSERT(attr->ia_valid & ATTR_SIZE);
1320
1321 call = afs_alloc_flat_call(&afs_RXFSStoreData64_as_Status,
1322 (4 + 6 + 3 * 2) * 4,
1323 (21 + 6) * 4);
1324 if (!call)
1325 return -ENOMEM;
1326
1327 call->key = key;
1328 call->reply = vnode;
1329 call->service_id = FS_SERVICE;
1330 call->port = htons(AFS_FS_PORT);
1331 call->store_version = vnode->status.data_version + 1;
1332 call->operation_ID = FSSTOREDATA;
1333
1334 /* marshall the parameters */
1335 bp = call->request;
1336 *bp++ = htonl(FSSTOREDATA64);
1337 *bp++ = htonl(vnode->fid.vid);
1338 *bp++ = htonl(vnode->fid.vnode);
1339 *bp++ = htonl(vnode->fid.unique);
1340
1341 xdr_encode_AFS_StoreStatus(&bp, attr);
1342
1343 *bp++ = 0; /* position of start of write */
1344 *bp++ = 0;
1345 *bp++ = 0; /* size of write */
1346 *bp++ = 0;
1347 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1348 *bp++ = htonl((u32) attr->ia_size);
1349
1350 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1351}
1352
David Howells31143d52007-05-09 02:33:46 -07001353/*
1354 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1355 * so as to alter the file size also
1356 */
1357static int afs_fs_setattr_size(struct afs_server *server, struct key *key,
1358 struct afs_vnode *vnode, struct iattr *attr,
1359 const struct afs_wait_mode *wait_mode)
1360{
1361 struct afs_call *call;
1362 __be32 *bp;
1363
1364 _enter(",%x,{%x:%u},,",
1365 key_serial(key), vnode->fid.vid, vnode->fid.vnode);
1366
1367 ASSERT(attr->ia_valid & ATTR_SIZE);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001368 if (attr->ia_size >> 32)
1369 return afs_fs_setattr_size64(server, key, vnode, attr,
1370 wait_mode);
David Howells31143d52007-05-09 02:33:46 -07001371
1372 call = afs_alloc_flat_call(&afs_RXFSStoreData_as_Status,
1373 (4 + 6 + 3) * 4,
1374 (21 + 6) * 4);
1375 if (!call)
1376 return -ENOMEM;
1377
1378 call->key = key;
1379 call->reply = vnode;
1380 call->service_id = FS_SERVICE;
1381 call->port = htons(AFS_FS_PORT);
1382 call->store_version = vnode->status.data_version + 1;
1383 call->operation_ID = FSSTOREDATA;
1384
1385 /* marshall the parameters */
1386 bp = call->request;
1387 *bp++ = htonl(FSSTOREDATA);
1388 *bp++ = htonl(vnode->fid.vid);
1389 *bp++ = htonl(vnode->fid.vnode);
1390 *bp++ = htonl(vnode->fid.unique);
1391
1392 xdr_encode_AFS_StoreStatus(&bp, attr);
1393
1394 *bp++ = 0; /* position of start of write */
1395 *bp++ = 0; /* size of write */
1396 *bp++ = htonl(attr->ia_size); /* new file length */
1397
1398 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1399}
1400
1401/*
1402 * set the attributes on a file, using FS.StoreData if there's a change in file
1403 * size, and FS.StoreStatus otherwise
1404 */
1405int afs_fs_setattr(struct afs_server *server, struct key *key,
1406 struct afs_vnode *vnode, struct iattr *attr,
1407 const struct afs_wait_mode *wait_mode)
1408{
1409 struct afs_call *call;
1410 __be32 *bp;
1411
1412 if (attr->ia_valid & ATTR_SIZE)
1413 return afs_fs_setattr_size(server, key, vnode, attr,
1414 wait_mode);
1415
1416 _enter(",%x,{%x:%u},,",
1417 key_serial(key), vnode->fid.vid, vnode->fid.vnode);
1418
1419 call = afs_alloc_flat_call(&afs_RXFSStoreStatus,
1420 (4 + 6) * 4,
1421 (21 + 6) * 4);
1422 if (!call)
1423 return -ENOMEM;
1424
1425 call->key = key;
1426 call->reply = vnode;
1427 call->service_id = FS_SERVICE;
1428 call->port = htons(AFS_FS_PORT);
1429 call->operation_ID = FSSTORESTATUS;
1430
1431 /* marshall the parameters */
1432 bp = call->request;
1433 *bp++ = htonl(FSSTORESTATUS);
1434 *bp++ = htonl(vnode->fid.vid);
1435 *bp++ = htonl(vnode->fid.vnode);
1436 *bp++ = htonl(vnode->fid.unique);
1437
1438 xdr_encode_AFS_StoreStatus(&bp, attr);
1439
1440 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1441}
David Howells45222b92007-05-10 22:22:20 -07001442
1443/*
1444 * deliver reply data to an FS.GetVolumeStatus
1445 */
1446static int afs_deliver_fs_get_volume_status(struct afs_call *call,
1447 struct sk_buff *skb, bool last)
1448{
1449 const __be32 *bp;
1450 char *p;
1451 int ret;
1452
1453 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
1454
1455 switch (call->unmarshall) {
1456 case 0:
1457 call->offset = 0;
1458 call->unmarshall++;
1459
1460 /* extract the returned status record */
1461 case 1:
1462 _debug("extract status");
1463 ret = afs_extract_data(call, skb, last, call->buffer,
1464 12 * 4);
David Howells372ee162016-08-03 14:11:40 +01001465 if (ret < 0)
1466 return ret;
David Howells45222b92007-05-10 22:22:20 -07001467
1468 bp = call->buffer;
1469 xdr_decode_AFSFetchVolumeStatus(&bp, call->reply2);
1470 call->offset = 0;
1471 call->unmarshall++;
1472
1473 /* extract the volume name length */
1474 case 2:
1475 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
David Howells372ee162016-08-03 14:11:40 +01001476 if (ret < 0)
1477 return ret;
David Howells45222b92007-05-10 22:22:20 -07001478
1479 call->count = ntohl(call->tmp);
1480 _debug("volname length: %u", call->count);
1481 if (call->count >= AFSNAMEMAX)
1482 return -EBADMSG;
1483 call->offset = 0;
1484 call->unmarshall++;
1485
1486 /* extract the volume name */
1487 case 3:
1488 _debug("extract volname");
1489 if (call->count > 0) {
1490 ret = afs_extract_data(call, skb, last, call->reply3,
1491 call->count);
David Howells372ee162016-08-03 14:11:40 +01001492 if (ret < 0)
1493 return ret;
David Howells45222b92007-05-10 22:22:20 -07001494 }
1495
1496 p = call->reply3;
1497 p[call->count] = 0;
1498 _debug("volname '%s'", p);
1499
1500 call->offset = 0;
1501 call->unmarshall++;
1502
1503 /* extract the volume name padding */
1504 if ((call->count & 3) == 0) {
1505 call->unmarshall++;
1506 goto no_volname_padding;
1507 }
1508 call->count = 4 - (call->count & 3);
1509
1510 case 4:
1511 ret = afs_extract_data(call, skb, last, call->buffer,
1512 call->count);
David Howells372ee162016-08-03 14:11:40 +01001513 if (ret < 0)
1514 return ret;
David Howells45222b92007-05-10 22:22:20 -07001515
1516 call->offset = 0;
1517 call->unmarshall++;
1518 no_volname_padding:
1519
1520 /* extract the offline message length */
1521 case 5:
1522 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
David Howells372ee162016-08-03 14:11:40 +01001523 if (ret < 0)
1524 return ret;
David Howells45222b92007-05-10 22:22:20 -07001525
1526 call->count = ntohl(call->tmp);
1527 _debug("offline msg length: %u", call->count);
1528 if (call->count >= AFSNAMEMAX)
1529 return -EBADMSG;
1530 call->offset = 0;
1531 call->unmarshall++;
1532
1533 /* extract the offline message */
1534 case 6:
1535 _debug("extract offline");
1536 if (call->count > 0) {
1537 ret = afs_extract_data(call, skb, last, call->reply3,
1538 call->count);
David Howells372ee162016-08-03 14:11:40 +01001539 if (ret < 0)
1540 return ret;
David Howells45222b92007-05-10 22:22:20 -07001541 }
1542
1543 p = call->reply3;
1544 p[call->count] = 0;
1545 _debug("offline '%s'", p);
1546
1547 call->offset = 0;
1548 call->unmarshall++;
1549
1550 /* extract the offline message padding */
1551 if ((call->count & 3) == 0) {
1552 call->unmarshall++;
1553 goto no_offline_padding;
1554 }
1555 call->count = 4 - (call->count & 3);
1556
1557 case 7:
1558 ret = afs_extract_data(call, skb, last, call->buffer,
1559 call->count);
David Howells372ee162016-08-03 14:11:40 +01001560 if (ret < 0)
1561 return ret;
David Howells45222b92007-05-10 22:22:20 -07001562
1563 call->offset = 0;
1564 call->unmarshall++;
1565 no_offline_padding:
1566
1567 /* extract the message of the day length */
1568 case 8:
1569 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
David Howells372ee162016-08-03 14:11:40 +01001570 if (ret < 0)
1571 return ret;
David Howells45222b92007-05-10 22:22:20 -07001572
1573 call->count = ntohl(call->tmp);
1574 _debug("motd length: %u", call->count);
1575 if (call->count >= AFSNAMEMAX)
1576 return -EBADMSG;
1577 call->offset = 0;
1578 call->unmarshall++;
1579
1580 /* extract the message of the day */
1581 case 9:
1582 _debug("extract motd");
1583 if (call->count > 0) {
1584 ret = afs_extract_data(call, skb, last, call->reply3,
1585 call->count);
David Howells372ee162016-08-03 14:11:40 +01001586 if (ret < 0)
1587 return ret;
David Howells45222b92007-05-10 22:22:20 -07001588 }
1589
1590 p = call->reply3;
1591 p[call->count] = 0;
1592 _debug("motd '%s'", p);
1593
1594 call->offset = 0;
1595 call->unmarshall++;
1596
1597 /* extract the message of the day padding */
1598 if ((call->count & 3) == 0) {
1599 call->unmarshall++;
1600 goto no_motd_padding;
1601 }
1602 call->count = 4 - (call->count & 3);
1603
1604 case 10:
1605 ret = afs_extract_data(call, skb, last, call->buffer,
1606 call->count);
David Howells372ee162016-08-03 14:11:40 +01001607 if (ret < 0)
1608 return ret;
David Howells45222b92007-05-10 22:22:20 -07001609
1610 call->offset = 0;
1611 call->unmarshall++;
1612 no_motd_padding:
1613
1614 case 11:
David Howells372ee162016-08-03 14:11:40 +01001615 ret = afs_data_complete(call, skb, last);
1616 if (ret < 0)
1617 return ret;
David Howells45222b92007-05-10 22:22:20 -07001618 break;
1619 }
1620
David Howells45222b92007-05-10 22:22:20 -07001621 _leave(" = 0 [done]");
1622 return 0;
1623}
1624
1625/*
1626 * destroy an FS.GetVolumeStatus call
1627 */
1628static void afs_get_volume_status_call_destructor(struct afs_call *call)
1629{
1630 kfree(call->reply3);
1631 call->reply3 = NULL;
1632 afs_flat_call_destructor(call);
1633}
1634
1635/*
1636 * FS.GetVolumeStatus operation type
1637 */
1638static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1639 .name = "FS.GetVolumeStatus",
1640 .deliver = afs_deliver_fs_get_volume_status,
1641 .abort_to_error = afs_abort_to_error,
1642 .destructor = afs_get_volume_status_call_destructor,
1643};
1644
1645/*
1646 * fetch the status of a volume
1647 */
1648int afs_fs_get_volume_status(struct afs_server *server,
1649 struct key *key,
1650 struct afs_vnode *vnode,
1651 struct afs_volume_status *vs,
1652 const struct afs_wait_mode *wait_mode)
1653{
1654 struct afs_call *call;
1655 __be32 *bp;
1656 void *tmpbuf;
1657
1658 _enter("");
1659
1660 tmpbuf = kmalloc(AFSOPAQUEMAX, GFP_KERNEL);
1661 if (!tmpbuf)
1662 return -ENOMEM;
1663
1664 call = afs_alloc_flat_call(&afs_RXFSGetVolumeStatus, 2 * 4, 12 * 4);
1665 if (!call) {
1666 kfree(tmpbuf);
1667 return -ENOMEM;
1668 }
1669
1670 call->key = key;
1671 call->reply = vnode;
1672 call->reply2 = vs;
1673 call->reply3 = tmpbuf;
1674 call->service_id = FS_SERVICE;
1675 call->port = htons(AFS_FS_PORT);
1676
1677 /* marshall the parameters */
1678 bp = call->request;
1679 bp[0] = htonl(FSGETVOLUMESTATUS);
1680 bp[1] = htonl(vnode->fid.vid);
1681
1682 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1683}
David Howellse8d6c552007-07-15 23:40:12 -07001684
1685/*
1686 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1687 */
1688static int afs_deliver_fs_xxxx_lock(struct afs_call *call,
1689 struct sk_buff *skb, bool last)
1690{
1691 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001692 int ret;
David Howellse8d6c552007-07-15 23:40:12 -07001693
1694 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
1695
David Howells372ee162016-08-03 14:11:40 +01001696 ret = afs_transfer_reply(call, skb, last);
1697 if (ret < 0)
1698 return ret;
David Howellse8d6c552007-07-15 23:40:12 -07001699
1700 /* unmarshall the reply once we've received all of it */
1701 bp = call->buffer;
1702 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
1703
1704 _leave(" = 0 [done]");
1705 return 0;
1706}
1707
1708/*
1709 * FS.SetLock operation type
1710 */
1711static const struct afs_call_type afs_RXFSSetLock = {
1712 .name = "FS.SetLock",
1713 .deliver = afs_deliver_fs_xxxx_lock,
1714 .abort_to_error = afs_abort_to_error,
1715 .destructor = afs_flat_call_destructor,
1716};
1717
1718/*
1719 * FS.ExtendLock operation type
1720 */
1721static const struct afs_call_type afs_RXFSExtendLock = {
1722 .name = "FS.ExtendLock",
1723 .deliver = afs_deliver_fs_xxxx_lock,
1724 .abort_to_error = afs_abort_to_error,
1725 .destructor = afs_flat_call_destructor,
1726};
1727
1728/*
1729 * FS.ReleaseLock operation type
1730 */
1731static const struct afs_call_type afs_RXFSReleaseLock = {
1732 .name = "FS.ReleaseLock",
1733 .deliver = afs_deliver_fs_xxxx_lock,
1734 .abort_to_error = afs_abort_to_error,
1735 .destructor = afs_flat_call_destructor,
1736};
1737
1738/*
1739 * get a lock on a file
1740 */
1741int afs_fs_set_lock(struct afs_server *server,
1742 struct key *key,
1743 struct afs_vnode *vnode,
1744 afs_lock_type_t type,
1745 const struct afs_wait_mode *wait_mode)
1746{
1747 struct afs_call *call;
1748 __be32 *bp;
1749
1750 _enter("");
1751
1752 call = afs_alloc_flat_call(&afs_RXFSSetLock, 5 * 4, 6 * 4);
1753 if (!call)
1754 return -ENOMEM;
1755
1756 call->key = key;
1757 call->reply = vnode;
1758 call->service_id = FS_SERVICE;
1759 call->port = htons(AFS_FS_PORT);
1760
1761 /* marshall the parameters */
1762 bp = call->request;
1763 *bp++ = htonl(FSSETLOCK);
1764 *bp++ = htonl(vnode->fid.vid);
1765 *bp++ = htonl(vnode->fid.vnode);
1766 *bp++ = htonl(vnode->fid.unique);
1767 *bp++ = htonl(type);
1768
1769 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1770}
1771
1772/*
1773 * extend a lock on a file
1774 */
1775int afs_fs_extend_lock(struct afs_server *server,
1776 struct key *key,
1777 struct afs_vnode *vnode,
1778 const struct afs_wait_mode *wait_mode)
1779{
1780 struct afs_call *call;
1781 __be32 *bp;
1782
1783 _enter("");
1784
1785 call = afs_alloc_flat_call(&afs_RXFSExtendLock, 4 * 4, 6 * 4);
1786 if (!call)
1787 return -ENOMEM;
1788
1789 call->key = key;
1790 call->reply = vnode;
1791 call->service_id = FS_SERVICE;
1792 call->port = htons(AFS_FS_PORT);
1793
1794 /* marshall the parameters */
1795 bp = call->request;
1796 *bp++ = htonl(FSEXTENDLOCK);
1797 *bp++ = htonl(vnode->fid.vid);
1798 *bp++ = htonl(vnode->fid.vnode);
1799 *bp++ = htonl(vnode->fid.unique);
1800
1801 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1802}
1803
1804/*
1805 * release a lock on a file
1806 */
1807int afs_fs_release_lock(struct afs_server *server,
1808 struct key *key,
1809 struct afs_vnode *vnode,
1810 const struct afs_wait_mode *wait_mode)
1811{
1812 struct afs_call *call;
1813 __be32 *bp;
1814
1815 _enter("");
1816
1817 call = afs_alloc_flat_call(&afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1818 if (!call)
1819 return -ENOMEM;
1820
1821 call->key = key;
1822 call->reply = vnode;
1823 call->service_id = FS_SERVICE;
1824 call->port = htons(AFS_FS_PORT);
1825
1826 /* marshall the parameters */
1827 bp = call->request;
1828 *bp++ = htonl(FSRELEASELOCK);
1829 *bp++ = htonl(vnode->fid.vid);
1830 *bp++ = htonl(vnode->fid.vnode);
1831 *bp++ = htonl(vnode->fid.unique);
1832
1833 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1834}