blob: 88e440607ed71ad6da305ed38186f5558ba45a54 [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
Marc Dionne833acb32017-03-16 16:27:47 +0000108 vnode->vfs_inode.i_ctime.tv_sec = status->mtime_client;
David Howells260a9802007-04-26 15:59:35 -0700109 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++);
Tina Ruchandani9329ae42017-03-16 16:27:46 +0000142 vnode->cb_expires = vnode->cb_expiry + ktime_get_real_seconds();
David Howells08e0e7c2007-04-26 15:55:03 -0700143 *_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 */
David Howellsd0016482016-08-30 20:42:14 +0100238static int afs_deliver_fs_fetch_status(struct afs_call *call)
David Howells08e0e7c2007-04-26 15:55:03 -0700239{
David Howells260a9802007-04-26 15:59:35 -0700240 struct afs_vnode *vnode = call->reply;
David Howells08e0e7c2007-04-26 15:55:03 -0700241 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100242 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700243
David Howellsd0016482016-08-30 20:42:14 +0100244 _enter("");
David Howells08e0e7c2007-04-26 15:55:03 -0700245
David Howellsd0016482016-08-30 20:42:14 +0100246 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100247 if (ret < 0)
248 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700249
250 /* unmarshall the reply once we've received all of it */
251 bp = call->buffer;
David Howells31143d52007-05-09 02:33:46 -0700252 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
David Howells260a9802007-04-26 15:59:35 -0700253 xdr_decode_AFSCallBack(&bp, vnode);
David Howells08e0e7c2007-04-26 15:55:03 -0700254 if (call->reply2)
255 xdr_decode_AFSVolSync(&bp, call->reply2);
256
257 _leave(" = 0 [done]");
258 return 0;
259}
260
261/*
262 * FS.FetchStatus operation type
263 */
264static const struct afs_call_type afs_RXFSFetchStatus = {
David Howells00d3b7a2007-04-26 15:57:07 -0700265 .name = "FS.FetchStatus",
David Howells08e0e7c2007-04-26 15:55:03 -0700266 .deliver = afs_deliver_fs_fetch_status,
267 .abort_to_error = afs_abort_to_error,
268 .destructor = afs_flat_call_destructor,
269};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271/*
272 * fetch the status information for a file
273 */
David Howells08e0e7c2007-04-26 15:55:03 -0700274int afs_fs_fetch_file_status(struct afs_server *server,
David Howells00d3b7a2007-04-26 15:57:07 -0700275 struct key *key,
David Howells08e0e7c2007-04-26 15:55:03 -0700276 struct afs_vnode *vnode,
277 struct afs_volsync *volsync,
278 const struct afs_wait_mode *wait_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
David Howells08e0e7c2007-04-26 15:55:03 -0700280 struct afs_call *call;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 __be32 *bp;
282
David Howells416351f2007-05-09 02:33:45 -0700283 _enter(",%x,{%x:%u},,",
David Howells260a9802007-04-26 15:59:35 -0700284 key_serial(key), vnode->fid.vid, vnode->fid.vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
David Howells260a9802007-04-26 15:59:35 -0700286 call = afs_alloc_flat_call(&afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700287 if (!call)
288 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
David Howells00d3b7a2007-04-26 15:57:07 -0700290 call->key = key;
David Howells08e0e7c2007-04-26 15:55:03 -0700291 call->reply = vnode;
292 call->reply2 = volsync;
293 call->service_id = FS_SERVICE;
294 call->port = htons(AFS_FS_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700297 bp = call->request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 bp[0] = htonl(FSFETCHSTATUS);
299 bp[1] = htonl(vnode->fid.vid);
300 bp[2] = htonl(vnode->fid.vnode);
301 bp[3] = htonl(vnode->fid.unique);
302
David Howells08e0e7c2007-04-26 15:55:03 -0700303 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
David Howellsec268152007-04-26 15:49:28 -0700304}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306/*
David Howells08e0e7c2007-04-26 15:55:03 -0700307 * deliver reply data to an FS.FetchData
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 */
David Howellsd0016482016-08-30 20:42:14 +0100309static int afs_deliver_fs_fetch_data(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
David Howells260a9802007-04-26 15:59:35 -0700311 struct afs_vnode *vnode = call->reply;
David Howells08e0e7c2007-04-26 15:55:03 -0700312 const __be32 *bp;
313 struct page *page;
314 void *buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700316
David Howellsd0016482016-08-30 20:42:14 +0100317 _enter("{%u}", call->unmarshall);
David Howells08e0e7c2007-04-26 15:55:03 -0700318
319 switch (call->unmarshall) {
320 case 0:
321 call->offset = 0;
322 call->unmarshall++;
David Howellsb9b1f8d2007-05-10 03:15:21 -0700323 if (call->operation_ID != FSFETCHDATA64) {
324 call->unmarshall++;
325 goto no_msw;
326 }
David Howells08e0e7c2007-04-26 15:55:03 -0700327
David Howellsb9b1f8d2007-05-10 03:15:21 -0700328 /* extract the upper part of the returned data length of an
329 * FSFETCHDATA64 op (which should always be 0 using this
330 * client) */
David Howells08e0e7c2007-04-26 15:55:03 -0700331 case 1:
David Howellsb9b1f8d2007-05-10 03:15:21 -0700332 _debug("extract data length (MSW)");
David Howellsd0016482016-08-30 20:42:14 +0100333 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +0100334 if (ret < 0)
335 return ret;
David Howellsb9b1f8d2007-05-10 03:15:21 -0700336
337 call->count = ntohl(call->tmp);
338 _debug("DATA length MSW: %u", call->count);
339 if (call->count > 0)
340 return -EBADMSG;
341 call->offset = 0;
342 call->unmarshall++;
343
344 no_msw:
345 /* extract the returned data length */
346 case 2:
David Howells08e0e7c2007-04-26 15:55:03 -0700347 _debug("extract data length");
David Howellsd0016482016-08-30 20:42:14 +0100348 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +0100349 if (ret < 0)
350 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700351
352 call->count = ntohl(call->tmp);
353 _debug("DATA length: %u", call->count);
354 if (call->count > PAGE_SIZE)
355 return -EBADMSG;
356 call->offset = 0;
357 call->unmarshall++;
358
David Howells08e0e7c2007-04-26 15:55:03 -0700359 /* extract the returned data */
David Howellsb9b1f8d2007-05-10 03:15:21 -0700360 case 3:
David Howells08e0e7c2007-04-26 15:55:03 -0700361 _debug("extract data");
David Howells416351f2007-05-09 02:33:45 -0700362 if (call->count > 0) {
363 page = call->reply3;
David Howellsd0016482016-08-30 20:42:14 +0100364 buffer = kmap(page);
365 ret = afs_extract_data(call, buffer,
366 call->count, true);
Dan Carpenter233c9ed2016-10-12 09:09:44 +0300367 kunmap(page);
David Howells372ee162016-08-03 14:11:40 +0100368 if (ret < 0)
369 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700370 }
371
372 call->offset = 0;
373 call->unmarshall++;
374
375 /* extract the metadata */
David Howellsb9b1f8d2007-05-10 03:15:21 -0700376 case 4:
David Howellsd0016482016-08-30 20:42:14 +0100377 ret = afs_extract_data(call, call->buffer,
378 (21 + 3 + 6) * 4, false);
David Howells372ee162016-08-03 14:11:40 +0100379 if (ret < 0)
380 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700381
382 bp = call->buffer;
David Howells31143d52007-05-09 02:33:46 -0700383 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
David Howells260a9802007-04-26 15:59:35 -0700384 xdr_decode_AFSCallBack(&bp, vnode);
David Howells08e0e7c2007-04-26 15:55:03 -0700385 if (call->reply2)
386 xdr_decode_AFSVolSync(&bp, call->reply2);
387
388 call->offset = 0;
389 call->unmarshall++;
390
David Howellsb9b1f8d2007-05-10 03:15:21 -0700391 case 5:
David Howells08e0e7c2007-04-26 15:55:03 -0700392 break;
393 }
394
David Howells416351f2007-05-09 02:33:45 -0700395 if (call->count < PAGE_SIZE) {
396 _debug("clear");
397 page = call->reply3;
David Howellsd0016482016-08-30 20:42:14 +0100398 buffer = kmap(page);
David Howells416351f2007-05-09 02:33:45 -0700399 memset(buffer + call->count, 0, PAGE_SIZE - call->count);
Dan Carpenter233c9ed2016-10-12 09:09:44 +0300400 kunmap(page);
David Howells416351f2007-05-09 02:33:45 -0700401 }
402
David Howells08e0e7c2007-04-26 15:55:03 -0700403 _leave(" = 0 [done]");
404 return 0;
405}
406
407/*
408 * FS.FetchData operation type
409 */
410static const struct afs_call_type afs_RXFSFetchData = {
David Howells00d3b7a2007-04-26 15:57:07 -0700411 .name = "FS.FetchData",
David Howells08e0e7c2007-04-26 15:55:03 -0700412 .deliver = afs_deliver_fs_fetch_data,
413 .abort_to_error = afs_abort_to_error,
414 .destructor = afs_flat_call_destructor,
415};
416
David Howellsb9b1f8d2007-05-10 03:15:21 -0700417static const struct afs_call_type afs_RXFSFetchData64 = {
418 .name = "FS.FetchData64",
419 .deliver = afs_deliver_fs_fetch_data,
420 .abort_to_error = afs_abort_to_error,
421 .destructor = afs_flat_call_destructor,
422};
423
424/*
425 * fetch data from a very large file
426 */
427static int afs_fs_fetch_data64(struct afs_server *server,
428 struct key *key,
429 struct afs_vnode *vnode,
430 off_t offset, size_t length,
431 struct page *buffer,
432 const struct afs_wait_mode *wait_mode)
433{
434 struct afs_call *call;
435 __be32 *bp;
436
437 _enter("");
438
439 ASSERTCMP(length, <, ULONG_MAX);
440
441 call = afs_alloc_flat_call(&afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
442 if (!call)
443 return -ENOMEM;
444
445 call->key = key;
446 call->reply = vnode;
447 call->reply2 = NULL; /* volsync */
448 call->reply3 = buffer;
449 call->service_id = FS_SERVICE;
450 call->port = htons(AFS_FS_PORT);
451 call->operation_ID = FSFETCHDATA64;
452
453 /* marshall the parameters */
454 bp = call->request;
455 bp[0] = htonl(FSFETCHDATA64);
456 bp[1] = htonl(vnode->fid.vid);
457 bp[2] = htonl(vnode->fid.vnode);
458 bp[3] = htonl(vnode->fid.unique);
459 bp[4] = htonl(upper_32_bits(offset));
460 bp[5] = htonl((u32) offset);
461 bp[6] = 0;
462 bp[7] = htonl((u32) length);
463
464 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
465}
466
David Howells08e0e7c2007-04-26 15:55:03 -0700467/*
468 * fetch data from a file
469 */
470int afs_fs_fetch_data(struct afs_server *server,
David Howells00d3b7a2007-04-26 15:57:07 -0700471 struct key *key,
David Howells08e0e7c2007-04-26 15:55:03 -0700472 struct afs_vnode *vnode,
473 off_t offset, size_t length,
474 struct page *buffer,
David Howells08e0e7c2007-04-26 15:55:03 -0700475 const struct afs_wait_mode *wait_mode)
476{
477 struct afs_call *call;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 __be32 *bp;
479
David Howellsb9b1f8d2007-05-10 03:15:21 -0700480 if (upper_32_bits(offset) || upper_32_bits(offset + length))
481 return afs_fs_fetch_data64(server, key, vnode, offset, length,
482 buffer, wait_mode);
483
David Howells08e0e7c2007-04-26 15:55:03 -0700484 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
David Howells260a9802007-04-26 15:59:35 -0700486 call = afs_alloc_flat_call(&afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700487 if (!call)
488 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
David Howells00d3b7a2007-04-26 15:57:07 -0700490 call->key = key;
David Howells08e0e7c2007-04-26 15:55:03 -0700491 call->reply = vnode;
David Howells260a9802007-04-26 15:59:35 -0700492 call->reply2 = NULL; /* volsync */
David Howells08e0e7c2007-04-26 15:55:03 -0700493 call->reply3 = buffer;
494 call->service_id = FS_SERVICE;
495 call->port = htons(AFS_FS_PORT);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700496 call->operation_ID = FSFETCHDATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700499 bp = call->request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 bp[0] = htonl(FSFETCHDATA);
David Howells08e0e7c2007-04-26 15:55:03 -0700501 bp[1] = htonl(vnode->fid.vid);
502 bp[2] = htonl(vnode->fid.vnode);
503 bp[3] = htonl(vnode->fid.unique);
504 bp[4] = htonl(offset);
505 bp[5] = htonl(length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
David Howells08e0e7c2007-04-26 15:55:03 -0700507 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
David Howellsec268152007-04-26 15:49:28 -0700508}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510/*
David Howells08e0e7c2007-04-26 15:55:03 -0700511 * deliver reply data to an FS.GiveUpCallBacks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 */
David Howellsd0016482016-08-30 20:42:14 +0100513static int afs_deliver_fs_give_up_callbacks(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514{
David Howellsd0016482016-08-30 20:42:14 +0100515 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
David Howells372ee162016-08-03 14:11:40 +0100517 /* shouldn't be any reply data */
David Howellsd0016482016-08-30 20:42:14 +0100518 return afs_extract_data(call, NULL, 0, false);
David Howells08e0e7c2007-04-26 15:55:03 -0700519}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
David Howells08e0e7c2007-04-26 15:55:03 -0700521/*
522 * FS.GiveUpCallBacks operation type
523 */
524static const struct afs_call_type afs_RXFSGiveUpCallBacks = {
David Howells00d3b7a2007-04-26 15:57:07 -0700525 .name = "FS.GiveUpCallBacks",
David Howells08e0e7c2007-04-26 15:55:03 -0700526 .deliver = afs_deliver_fs_give_up_callbacks,
527 .abort_to_error = afs_abort_to_error,
528 .destructor = afs_flat_call_destructor,
529};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
David Howells08e0e7c2007-04-26 15:55:03 -0700531/*
532 * give up a set of callbacks
533 * - the callbacks are held in the server->cb_break ring
534 */
535int afs_fs_give_up_callbacks(struct afs_server *server,
536 const struct afs_wait_mode *wait_mode)
537{
538 struct afs_call *call;
539 size_t ncallbacks;
540 __be32 *bp, *tp;
541 int loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
David Howells08e0e7c2007-04-26 15:55:03 -0700543 ncallbacks = CIRC_CNT(server->cb_break_head, server->cb_break_tail,
544 ARRAY_SIZE(server->cb_break));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
David Howells08e0e7c2007-04-26 15:55:03 -0700546 _enter("{%zu},", ncallbacks);
547
548 if (ncallbacks == 0)
549 return 0;
550 if (ncallbacks > AFSCBMAX)
551 ncallbacks = AFSCBMAX;
552
553 _debug("break %zu callbacks", ncallbacks);
554
555 call = afs_alloc_flat_call(&afs_RXFSGiveUpCallBacks,
556 12 + ncallbacks * 6 * 4, 0);
557 if (!call)
558 return -ENOMEM;
559
560 call->service_id = FS_SERVICE;
561 call->port = htons(AFS_FS_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700564 bp = call->request;
565 tp = bp + 2 + ncallbacks * 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 *bp++ = htonl(FSGIVEUPCALLBACKS);
David Howells08e0e7c2007-04-26 15:55:03 -0700567 *bp++ = htonl(ncallbacks);
568 *tp++ = htonl(ncallbacks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
David Howells08e0e7c2007-04-26 15:55:03 -0700570 atomic_sub(ncallbacks, &server->cb_break_n);
571 for (loop = ncallbacks; loop > 0; loop--) {
572 struct afs_callback *cb =
573 &server->cb_break[server->cb_break_tail];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
David Howells08e0e7c2007-04-26 15:55:03 -0700575 *bp++ = htonl(cb->fid.vid);
576 *bp++ = htonl(cb->fid.vnode);
577 *bp++ = htonl(cb->fid.unique);
578 *tp++ = htonl(cb->version);
579 *tp++ = htonl(cb->expiry);
580 *tp++ = htonl(cb->type);
581 smp_mb();
582 server->cb_break_tail =
583 (server->cb_break_tail + 1) &
584 (ARRAY_SIZE(server->cb_break) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586
David Howells08e0e7c2007-04-26 15:55:03 -0700587 ASSERT(ncallbacks > 0);
588 wake_up_nr(&server->cb_break_waitq, ncallbacks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
David Howells08e0e7c2007-04-26 15:55:03 -0700590 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
David Howellsec268152007-04-26 15:49:28 -0700591}
David Howells260a9802007-04-26 15:59:35 -0700592
593/*
594 * deliver reply data to an FS.CreateFile or an FS.MakeDir
595 */
David Howellsd0016482016-08-30 20:42:14 +0100596static int afs_deliver_fs_create_vnode(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700597{
598 struct afs_vnode *vnode = call->reply;
599 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100600 int ret;
David Howells260a9802007-04-26 15:59:35 -0700601
David Howellsd0016482016-08-30 20:42:14 +0100602 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -0700603
David Howellsd0016482016-08-30 20:42:14 +0100604 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100605 if (ret < 0)
606 return ret;
David Howells260a9802007-04-26 15:59:35 -0700607
608 /* unmarshall the reply once we've received all of it */
609 bp = call->buffer;
610 xdr_decode_AFSFid(&bp, call->reply2);
David Howells31143d52007-05-09 02:33:46 -0700611 xdr_decode_AFSFetchStatus(&bp, call->reply3, NULL, NULL);
612 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
David Howells260a9802007-04-26 15:59:35 -0700613 xdr_decode_AFSCallBack_raw(&bp, call->reply4);
614 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
615
616 _leave(" = 0 [done]");
617 return 0;
618}
619
620/*
621 * FS.CreateFile and FS.MakeDir operation type
622 */
623static const struct afs_call_type afs_RXFSCreateXXXX = {
624 .name = "FS.CreateXXXX",
625 .deliver = afs_deliver_fs_create_vnode,
626 .abort_to_error = afs_abort_to_error,
627 .destructor = afs_flat_call_destructor,
628};
629
630/*
631 * create a file or make a directory
632 */
633int afs_fs_create(struct afs_server *server,
634 struct key *key,
635 struct afs_vnode *vnode,
636 const char *name,
637 umode_t mode,
638 struct afs_fid *newfid,
639 struct afs_file_status *newstatus,
640 struct afs_callback *newcb,
641 const struct afs_wait_mode *wait_mode)
642{
643 struct afs_call *call;
644 size_t namesz, reqsz, padsz;
645 __be32 *bp;
646
647 _enter("");
648
649 namesz = strlen(name);
650 padsz = (4 - (namesz & 3)) & 3;
651 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
652
653 call = afs_alloc_flat_call(&afs_RXFSCreateXXXX, reqsz,
654 (3 + 21 + 21 + 3 + 6) * 4);
655 if (!call)
656 return -ENOMEM;
657
658 call->key = key;
659 call->reply = vnode;
660 call->reply2 = newfid;
661 call->reply3 = newstatus;
662 call->reply4 = newcb;
663 call->service_id = FS_SERVICE;
664 call->port = htons(AFS_FS_PORT);
665
666 /* marshall the parameters */
667 bp = call->request;
668 *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
669 *bp++ = htonl(vnode->fid.vid);
670 *bp++ = htonl(vnode->fid.vnode);
671 *bp++ = htonl(vnode->fid.unique);
672 *bp++ = htonl(namesz);
673 memcpy(bp, name, namesz);
674 bp = (void *) bp + namesz;
675 if (padsz > 0) {
676 memset(bp, 0, padsz);
677 bp = (void *) bp + padsz;
678 }
Marc Dionne833acb32017-03-16 16:27:47 +0000679 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
680 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howells260a9802007-04-26 15:59:35 -0700681 *bp++ = 0; /* owner */
682 *bp++ = 0; /* group */
683 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
684 *bp++ = 0; /* segment size */
685
686 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
687}
688
689/*
690 * deliver reply data to an FS.RemoveFile or FS.RemoveDir
691 */
David Howellsd0016482016-08-30 20:42:14 +0100692static int afs_deliver_fs_remove(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700693{
694 struct afs_vnode *vnode = call->reply;
695 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100696 int ret;
David Howells260a9802007-04-26 15:59:35 -0700697
David Howellsd0016482016-08-30 20:42:14 +0100698 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -0700699
David Howellsd0016482016-08-30 20:42:14 +0100700 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100701 if (ret < 0)
702 return ret;
David Howells260a9802007-04-26 15:59:35 -0700703
704 /* unmarshall the reply once we've received all of it */
705 bp = call->buffer;
David Howells31143d52007-05-09 02:33:46 -0700706 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
David Howells260a9802007-04-26 15:59:35 -0700707 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
708
709 _leave(" = 0 [done]");
710 return 0;
711}
712
713/*
714 * FS.RemoveDir/FS.RemoveFile operation type
715 */
716static const struct afs_call_type afs_RXFSRemoveXXXX = {
717 .name = "FS.RemoveXXXX",
718 .deliver = afs_deliver_fs_remove,
719 .abort_to_error = afs_abort_to_error,
720 .destructor = afs_flat_call_destructor,
721};
722
723/*
724 * remove a file or directory
725 */
726int afs_fs_remove(struct afs_server *server,
727 struct key *key,
728 struct afs_vnode *vnode,
729 const char *name,
730 bool isdir,
731 const struct afs_wait_mode *wait_mode)
732{
733 struct afs_call *call;
734 size_t namesz, reqsz, padsz;
735 __be32 *bp;
736
737 _enter("");
738
739 namesz = strlen(name);
740 padsz = (4 - (namesz & 3)) & 3;
741 reqsz = (5 * 4) + namesz + padsz;
742
743 call = afs_alloc_flat_call(&afs_RXFSRemoveXXXX, reqsz, (21 + 6) * 4);
744 if (!call)
745 return -ENOMEM;
746
747 call->key = key;
748 call->reply = vnode;
749 call->service_id = FS_SERVICE;
750 call->port = htons(AFS_FS_PORT);
751
752 /* marshall the parameters */
753 bp = call->request;
754 *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
755 *bp++ = htonl(vnode->fid.vid);
756 *bp++ = htonl(vnode->fid.vnode);
757 *bp++ = htonl(vnode->fid.unique);
758 *bp++ = htonl(namesz);
759 memcpy(bp, name, namesz);
760 bp = (void *) bp + namesz;
761 if (padsz > 0) {
762 memset(bp, 0, padsz);
763 bp = (void *) bp + padsz;
764 }
765
766 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
767}
768
769/*
770 * deliver reply data to an FS.Link
771 */
David Howellsd0016482016-08-30 20:42:14 +0100772static int afs_deliver_fs_link(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700773{
774 struct afs_vnode *dvnode = call->reply, *vnode = call->reply2;
775 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100776 int ret;
David Howells260a9802007-04-26 15:59:35 -0700777
David Howellsd0016482016-08-30 20:42:14 +0100778 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -0700779
David Howellsd0016482016-08-30 20:42:14 +0100780 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100781 if (ret < 0)
782 return ret;
David Howells260a9802007-04-26 15:59:35 -0700783
784 /* unmarshall the reply once we've received all of it */
785 bp = call->buffer;
David Howells31143d52007-05-09 02:33:46 -0700786 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
787 xdr_decode_AFSFetchStatus(&bp, &dvnode->status, dvnode, NULL);
David Howells260a9802007-04-26 15:59:35 -0700788 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
789
790 _leave(" = 0 [done]");
791 return 0;
792}
793
794/*
795 * FS.Link operation type
796 */
797static const struct afs_call_type afs_RXFSLink = {
798 .name = "FS.Link",
799 .deliver = afs_deliver_fs_link,
800 .abort_to_error = afs_abort_to_error,
801 .destructor = afs_flat_call_destructor,
802};
803
804/*
805 * make a hard link
806 */
807int afs_fs_link(struct afs_server *server,
808 struct key *key,
809 struct afs_vnode *dvnode,
810 struct afs_vnode *vnode,
811 const char *name,
812 const struct afs_wait_mode *wait_mode)
813{
814 struct afs_call *call;
815 size_t namesz, reqsz, padsz;
816 __be32 *bp;
817
818 _enter("");
819
820 namesz = strlen(name);
821 padsz = (4 - (namesz & 3)) & 3;
822 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
823
824 call = afs_alloc_flat_call(&afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
825 if (!call)
826 return -ENOMEM;
827
828 call->key = key;
829 call->reply = dvnode;
830 call->reply2 = vnode;
831 call->service_id = FS_SERVICE;
832 call->port = htons(AFS_FS_PORT);
833
834 /* marshall the parameters */
835 bp = call->request;
836 *bp++ = htonl(FSLINK);
837 *bp++ = htonl(dvnode->fid.vid);
838 *bp++ = htonl(dvnode->fid.vnode);
839 *bp++ = htonl(dvnode->fid.unique);
840 *bp++ = htonl(namesz);
841 memcpy(bp, name, namesz);
842 bp = (void *) bp + namesz;
843 if (padsz > 0) {
844 memset(bp, 0, padsz);
845 bp = (void *) bp + padsz;
846 }
847 *bp++ = htonl(vnode->fid.vid);
848 *bp++ = htonl(vnode->fid.vnode);
849 *bp++ = htonl(vnode->fid.unique);
850
851 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
852}
853
854/*
855 * deliver reply data to an FS.Symlink
856 */
David Howellsd0016482016-08-30 20:42:14 +0100857static int afs_deliver_fs_symlink(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700858{
859 struct afs_vnode *vnode = call->reply;
860 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100861 int ret;
David Howells260a9802007-04-26 15:59:35 -0700862
David Howellsd0016482016-08-30 20:42:14 +0100863 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -0700864
David Howellsd0016482016-08-30 20:42:14 +0100865 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100866 if (ret < 0)
867 return ret;
David Howells260a9802007-04-26 15:59:35 -0700868
869 /* unmarshall the reply once we've received all of it */
870 bp = call->buffer;
871 xdr_decode_AFSFid(&bp, call->reply2);
David Howells31143d52007-05-09 02:33:46 -0700872 xdr_decode_AFSFetchStatus(&bp, call->reply3, NULL, NULL);
873 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
David Howells260a9802007-04-26 15:59:35 -0700874 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
875
876 _leave(" = 0 [done]");
877 return 0;
878}
879
880/*
881 * FS.Symlink operation type
882 */
883static const struct afs_call_type afs_RXFSSymlink = {
884 .name = "FS.Symlink",
885 .deliver = afs_deliver_fs_symlink,
886 .abort_to_error = afs_abort_to_error,
887 .destructor = afs_flat_call_destructor,
888};
889
890/*
891 * create a symbolic link
892 */
893int afs_fs_symlink(struct afs_server *server,
894 struct key *key,
895 struct afs_vnode *vnode,
896 const char *name,
897 const char *contents,
898 struct afs_fid *newfid,
899 struct afs_file_status *newstatus,
900 const struct afs_wait_mode *wait_mode)
901{
902 struct afs_call *call;
903 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
904 __be32 *bp;
905
906 _enter("");
907
908 namesz = strlen(name);
909 padsz = (4 - (namesz & 3)) & 3;
910
911 c_namesz = strlen(contents);
912 c_padsz = (4 - (c_namesz & 3)) & 3;
913
914 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
915
916 call = afs_alloc_flat_call(&afs_RXFSSymlink, reqsz,
917 (3 + 21 + 21 + 6) * 4);
918 if (!call)
919 return -ENOMEM;
920
921 call->key = key;
922 call->reply = vnode;
923 call->reply2 = newfid;
924 call->reply3 = newstatus;
925 call->service_id = FS_SERVICE;
926 call->port = htons(AFS_FS_PORT);
927
928 /* marshall the parameters */
929 bp = call->request;
930 *bp++ = htonl(FSSYMLINK);
931 *bp++ = htonl(vnode->fid.vid);
932 *bp++ = htonl(vnode->fid.vnode);
933 *bp++ = htonl(vnode->fid.unique);
934 *bp++ = htonl(namesz);
935 memcpy(bp, name, namesz);
936 bp = (void *) bp + namesz;
937 if (padsz > 0) {
938 memset(bp, 0, padsz);
939 bp = (void *) bp + padsz;
940 }
941 *bp++ = htonl(c_namesz);
942 memcpy(bp, contents, c_namesz);
943 bp = (void *) bp + c_namesz;
944 if (c_padsz > 0) {
945 memset(bp, 0, c_padsz);
946 bp = (void *) bp + c_padsz;
947 }
Marc Dionne833acb32017-03-16 16:27:47 +0000948 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
949 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howells260a9802007-04-26 15:59:35 -0700950 *bp++ = 0; /* owner */
951 *bp++ = 0; /* group */
952 *bp++ = htonl(S_IRWXUGO); /* unix mode */
953 *bp++ = 0; /* segment size */
954
955 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
956}
957
958/*
959 * deliver reply data to an FS.Rename
960 */
David Howellsd0016482016-08-30 20:42:14 +0100961static int afs_deliver_fs_rename(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700962{
963 struct afs_vnode *orig_dvnode = call->reply, *new_dvnode = call->reply2;
964 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100965 int ret;
David Howells260a9802007-04-26 15:59:35 -0700966
David Howellsd0016482016-08-30 20:42:14 +0100967 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -0700968
David Howellsd0016482016-08-30 20:42:14 +0100969 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100970 if (ret < 0)
971 return ret;
David Howells260a9802007-04-26 15:59:35 -0700972
973 /* unmarshall the reply once we've received all of it */
974 bp = call->buffer;
David Howells31143d52007-05-09 02:33:46 -0700975 xdr_decode_AFSFetchStatus(&bp, &orig_dvnode->status, orig_dvnode, NULL);
David Howells260a9802007-04-26 15:59:35 -0700976 if (new_dvnode != orig_dvnode)
David Howells31143d52007-05-09 02:33:46 -0700977 xdr_decode_AFSFetchStatus(&bp, &new_dvnode->status, new_dvnode,
978 NULL);
David Howells260a9802007-04-26 15:59:35 -0700979 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
980
981 _leave(" = 0 [done]");
982 return 0;
983}
984
985/*
986 * FS.Rename operation type
987 */
988static const struct afs_call_type afs_RXFSRename = {
989 .name = "FS.Rename",
990 .deliver = afs_deliver_fs_rename,
991 .abort_to_error = afs_abort_to_error,
992 .destructor = afs_flat_call_destructor,
993};
994
995/*
996 * create a symbolic link
997 */
998int afs_fs_rename(struct afs_server *server,
999 struct key *key,
1000 struct afs_vnode *orig_dvnode,
1001 const char *orig_name,
1002 struct afs_vnode *new_dvnode,
1003 const char *new_name,
1004 const struct afs_wait_mode *wait_mode)
1005{
1006 struct afs_call *call;
1007 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1008 __be32 *bp;
1009
1010 _enter("");
1011
1012 o_namesz = strlen(orig_name);
1013 o_padsz = (4 - (o_namesz & 3)) & 3;
1014
1015 n_namesz = strlen(new_name);
1016 n_padsz = (4 - (n_namesz & 3)) & 3;
1017
1018 reqsz = (4 * 4) +
1019 4 + o_namesz + o_padsz +
1020 (3 * 4) +
1021 4 + n_namesz + n_padsz;
1022
1023 call = afs_alloc_flat_call(&afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
1024 if (!call)
1025 return -ENOMEM;
1026
1027 call->key = key;
1028 call->reply = orig_dvnode;
1029 call->reply2 = new_dvnode;
1030 call->service_id = FS_SERVICE;
1031 call->port = htons(AFS_FS_PORT);
1032
1033 /* marshall the parameters */
1034 bp = call->request;
1035 *bp++ = htonl(FSRENAME);
1036 *bp++ = htonl(orig_dvnode->fid.vid);
1037 *bp++ = htonl(orig_dvnode->fid.vnode);
1038 *bp++ = htonl(orig_dvnode->fid.unique);
1039 *bp++ = htonl(o_namesz);
1040 memcpy(bp, orig_name, o_namesz);
1041 bp = (void *) bp + o_namesz;
1042 if (o_padsz > 0) {
1043 memset(bp, 0, o_padsz);
1044 bp = (void *) bp + o_padsz;
1045 }
1046
1047 *bp++ = htonl(new_dvnode->fid.vid);
1048 *bp++ = htonl(new_dvnode->fid.vnode);
1049 *bp++ = htonl(new_dvnode->fid.unique);
1050 *bp++ = htonl(n_namesz);
1051 memcpy(bp, new_name, n_namesz);
1052 bp = (void *) bp + n_namesz;
1053 if (n_padsz > 0) {
1054 memset(bp, 0, n_padsz);
1055 bp = (void *) bp + n_padsz;
1056 }
1057
1058 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1059}
David Howells31143d52007-05-09 02:33:46 -07001060
1061/*
1062 * deliver reply data to an FS.StoreData
1063 */
David Howellsd0016482016-08-30 20:42:14 +01001064static int afs_deliver_fs_store_data(struct afs_call *call)
David Howells31143d52007-05-09 02:33:46 -07001065{
1066 struct afs_vnode *vnode = call->reply;
1067 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001068 int ret;
David Howells31143d52007-05-09 02:33:46 -07001069
David Howellsd0016482016-08-30 20:42:14 +01001070 _enter("");
David Howells31143d52007-05-09 02:33:46 -07001071
David Howellsd0016482016-08-30 20:42:14 +01001072 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001073 if (ret < 0)
1074 return ret;
David Howells31143d52007-05-09 02:33:46 -07001075
1076 /* unmarshall the reply once we've received all of it */
1077 bp = call->buffer;
1078 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode,
1079 &call->store_version);
1080 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
1081
1082 afs_pages_written_back(vnode, call);
1083
1084 _leave(" = 0 [done]");
1085 return 0;
1086}
1087
1088/*
1089 * FS.StoreData operation type
1090 */
1091static const struct afs_call_type afs_RXFSStoreData = {
1092 .name = "FS.StoreData",
1093 .deliver = afs_deliver_fs_store_data,
1094 .abort_to_error = afs_abort_to_error,
1095 .destructor = afs_flat_call_destructor,
1096};
1097
David Howellsb9b1f8d2007-05-10 03:15:21 -07001098static const struct afs_call_type afs_RXFSStoreData64 = {
1099 .name = "FS.StoreData64",
1100 .deliver = afs_deliver_fs_store_data,
1101 .abort_to_error = afs_abort_to_error,
1102 .destructor = afs_flat_call_destructor,
1103};
1104
1105/*
1106 * store a set of pages to a very large file
1107 */
1108static int afs_fs_store_data64(struct afs_server *server,
1109 struct afs_writeback *wb,
1110 pgoff_t first, pgoff_t last,
1111 unsigned offset, unsigned to,
1112 loff_t size, loff_t pos, loff_t i_size,
1113 const struct afs_wait_mode *wait_mode)
1114{
1115 struct afs_vnode *vnode = wb->vnode;
1116 struct afs_call *call;
1117 __be32 *bp;
1118
1119 _enter(",%x,{%x:%u},,",
1120 key_serial(wb->key), vnode->fid.vid, vnode->fid.vnode);
1121
1122 call = afs_alloc_flat_call(&afs_RXFSStoreData64,
1123 (4 + 6 + 3 * 2) * 4,
1124 (21 + 6) * 4);
1125 if (!call)
1126 return -ENOMEM;
1127
1128 call->wb = wb;
1129 call->key = wb->key;
1130 call->reply = vnode;
1131 call->service_id = FS_SERVICE;
1132 call->port = htons(AFS_FS_PORT);
1133 call->mapping = vnode->vfs_inode.i_mapping;
1134 call->first = first;
1135 call->last = last;
1136 call->first_offset = offset;
1137 call->last_to = to;
1138 call->send_pages = true;
1139 call->store_version = vnode->status.data_version + 1;
1140
1141 /* marshall the parameters */
1142 bp = call->request;
1143 *bp++ = htonl(FSSTOREDATA64);
1144 *bp++ = htonl(vnode->fid.vid);
1145 *bp++ = htonl(vnode->fid.vnode);
1146 *bp++ = htonl(vnode->fid.unique);
1147
Marc Dionne833acb32017-03-16 16:27:47 +00001148 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1149 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howellsb9b1f8d2007-05-10 03:15:21 -07001150 *bp++ = 0; /* owner */
1151 *bp++ = 0; /* group */
1152 *bp++ = 0; /* unix mode */
1153 *bp++ = 0; /* segment size */
1154
1155 *bp++ = htonl(pos >> 32);
1156 *bp++ = htonl((u32) pos);
1157 *bp++ = htonl(size >> 32);
1158 *bp++ = htonl((u32) size);
1159 *bp++ = htonl(i_size >> 32);
1160 *bp++ = htonl((u32) i_size);
1161
1162 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1163}
1164
David Howells31143d52007-05-09 02:33:46 -07001165/*
1166 * store a set of pages
1167 */
1168int afs_fs_store_data(struct afs_server *server, struct afs_writeback *wb,
1169 pgoff_t first, pgoff_t last,
1170 unsigned offset, unsigned to,
1171 const struct afs_wait_mode *wait_mode)
1172{
1173 struct afs_vnode *vnode = wb->vnode;
1174 struct afs_call *call;
1175 loff_t size, pos, i_size;
1176 __be32 *bp;
1177
1178 _enter(",%x,{%x:%u},,",
1179 key_serial(wb->key), vnode->fid.vid, vnode->fid.vnode);
1180
David Howells972e7b72017-03-16 16:27:47 +00001181 size = (loff_t)to - (loff_t)offset;
David Howells31143d52007-05-09 02:33:46 -07001182 if (first != last)
1183 size += (loff_t)(last - first) << PAGE_SHIFT;
1184 pos = (loff_t)first << PAGE_SHIFT;
1185 pos += offset;
1186
1187 i_size = i_size_read(&vnode->vfs_inode);
1188 if (pos + size > i_size)
1189 i_size = size + pos;
1190
1191 _debug("size %llx, at %llx, i_size %llx",
1192 (unsigned long long) size, (unsigned long long) pos,
1193 (unsigned long long) i_size);
1194
David Howellsb9b1f8d2007-05-10 03:15:21 -07001195 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
1196 return afs_fs_store_data64(server, wb, first, last, offset, to,
1197 size, pos, i_size, wait_mode);
David Howells31143d52007-05-09 02:33:46 -07001198
1199 call = afs_alloc_flat_call(&afs_RXFSStoreData,
1200 (4 + 6 + 3) * 4,
1201 (21 + 6) * 4);
1202 if (!call)
1203 return -ENOMEM;
1204
1205 call->wb = wb;
1206 call->key = wb->key;
1207 call->reply = vnode;
1208 call->service_id = FS_SERVICE;
1209 call->port = htons(AFS_FS_PORT);
1210 call->mapping = vnode->vfs_inode.i_mapping;
1211 call->first = first;
1212 call->last = last;
1213 call->first_offset = offset;
1214 call->last_to = to;
1215 call->send_pages = true;
1216 call->store_version = vnode->status.data_version + 1;
1217
1218 /* marshall the parameters */
1219 bp = call->request;
1220 *bp++ = htonl(FSSTOREDATA);
1221 *bp++ = htonl(vnode->fid.vid);
1222 *bp++ = htonl(vnode->fid.vnode);
1223 *bp++ = htonl(vnode->fid.unique);
1224
Marc Dionne833acb32017-03-16 16:27:47 +00001225 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1226 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howells31143d52007-05-09 02:33:46 -07001227 *bp++ = 0; /* owner */
1228 *bp++ = 0; /* group */
1229 *bp++ = 0; /* unix mode */
1230 *bp++ = 0; /* segment size */
1231
1232 *bp++ = htonl(pos);
1233 *bp++ = htonl(size);
1234 *bp++ = htonl(i_size);
1235
1236 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1237}
1238
1239/*
1240 * deliver reply data to an FS.StoreStatus
1241 */
David Howellsd0016482016-08-30 20:42:14 +01001242static int afs_deliver_fs_store_status(struct afs_call *call)
David Howells31143d52007-05-09 02:33:46 -07001243{
1244 afs_dataversion_t *store_version;
1245 struct afs_vnode *vnode = call->reply;
1246 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001247 int ret;
David Howells31143d52007-05-09 02:33:46 -07001248
David Howellsd0016482016-08-30 20:42:14 +01001249 _enter("");
David Howells31143d52007-05-09 02:33:46 -07001250
David Howellsd0016482016-08-30 20:42:14 +01001251 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001252 if (ret < 0)
1253 return ret;
David Howells31143d52007-05-09 02:33:46 -07001254
1255 /* unmarshall the reply once we've received all of it */
1256 store_version = NULL;
1257 if (call->operation_ID == FSSTOREDATA)
1258 store_version = &call->store_version;
1259
1260 bp = call->buffer;
1261 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, store_version);
1262 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
1263
1264 _leave(" = 0 [done]");
1265 return 0;
1266}
1267
1268/*
1269 * FS.StoreStatus operation type
1270 */
1271static const struct afs_call_type afs_RXFSStoreStatus = {
1272 .name = "FS.StoreStatus",
1273 .deliver = afs_deliver_fs_store_status,
1274 .abort_to_error = afs_abort_to_error,
1275 .destructor = afs_flat_call_destructor,
1276};
1277
1278static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1279 .name = "FS.StoreData",
1280 .deliver = afs_deliver_fs_store_status,
1281 .abort_to_error = afs_abort_to_error,
1282 .destructor = afs_flat_call_destructor,
1283};
1284
David Howellsb9b1f8d2007-05-10 03:15:21 -07001285static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1286 .name = "FS.StoreData64",
1287 .deliver = afs_deliver_fs_store_status,
1288 .abort_to_error = afs_abort_to_error,
1289 .destructor = afs_flat_call_destructor,
1290};
1291
1292/*
1293 * set the attributes on a very large file, using FS.StoreData rather than
1294 * FS.StoreStatus so as to alter the file size also
1295 */
1296static int afs_fs_setattr_size64(struct afs_server *server, struct key *key,
1297 struct afs_vnode *vnode, struct iattr *attr,
1298 const struct afs_wait_mode *wait_mode)
1299{
1300 struct afs_call *call;
1301 __be32 *bp;
1302
1303 _enter(",%x,{%x:%u},,",
1304 key_serial(key), vnode->fid.vid, vnode->fid.vnode);
1305
1306 ASSERT(attr->ia_valid & ATTR_SIZE);
1307
1308 call = afs_alloc_flat_call(&afs_RXFSStoreData64_as_Status,
1309 (4 + 6 + 3 * 2) * 4,
1310 (21 + 6) * 4);
1311 if (!call)
1312 return -ENOMEM;
1313
1314 call->key = key;
1315 call->reply = vnode;
1316 call->service_id = FS_SERVICE;
1317 call->port = htons(AFS_FS_PORT);
1318 call->store_version = vnode->status.data_version + 1;
1319 call->operation_ID = FSSTOREDATA;
1320
1321 /* marshall the parameters */
1322 bp = call->request;
1323 *bp++ = htonl(FSSTOREDATA64);
1324 *bp++ = htonl(vnode->fid.vid);
1325 *bp++ = htonl(vnode->fid.vnode);
1326 *bp++ = htonl(vnode->fid.unique);
1327
1328 xdr_encode_AFS_StoreStatus(&bp, attr);
1329
1330 *bp++ = 0; /* position of start of write */
1331 *bp++ = 0;
1332 *bp++ = 0; /* size of write */
1333 *bp++ = 0;
1334 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1335 *bp++ = htonl((u32) attr->ia_size);
1336
1337 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1338}
1339
David Howells31143d52007-05-09 02:33:46 -07001340/*
1341 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1342 * so as to alter the file size also
1343 */
1344static int afs_fs_setattr_size(struct afs_server *server, struct key *key,
1345 struct afs_vnode *vnode, struct iattr *attr,
1346 const struct afs_wait_mode *wait_mode)
1347{
1348 struct afs_call *call;
1349 __be32 *bp;
1350
1351 _enter(",%x,{%x:%u},,",
1352 key_serial(key), vnode->fid.vid, vnode->fid.vnode);
1353
1354 ASSERT(attr->ia_valid & ATTR_SIZE);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001355 if (attr->ia_size >> 32)
1356 return afs_fs_setattr_size64(server, key, vnode, attr,
1357 wait_mode);
David Howells31143d52007-05-09 02:33:46 -07001358
1359 call = afs_alloc_flat_call(&afs_RXFSStoreData_as_Status,
1360 (4 + 6 + 3) * 4,
1361 (21 + 6) * 4);
1362 if (!call)
1363 return -ENOMEM;
1364
1365 call->key = key;
1366 call->reply = vnode;
1367 call->service_id = FS_SERVICE;
1368 call->port = htons(AFS_FS_PORT);
1369 call->store_version = vnode->status.data_version + 1;
1370 call->operation_ID = FSSTOREDATA;
1371
1372 /* marshall the parameters */
1373 bp = call->request;
1374 *bp++ = htonl(FSSTOREDATA);
1375 *bp++ = htonl(vnode->fid.vid);
1376 *bp++ = htonl(vnode->fid.vnode);
1377 *bp++ = htonl(vnode->fid.unique);
1378
1379 xdr_encode_AFS_StoreStatus(&bp, attr);
1380
1381 *bp++ = 0; /* position of start of write */
1382 *bp++ = 0; /* size of write */
1383 *bp++ = htonl(attr->ia_size); /* new file length */
1384
1385 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1386}
1387
1388/*
1389 * set the attributes on a file, using FS.StoreData if there's a change in file
1390 * size, and FS.StoreStatus otherwise
1391 */
1392int afs_fs_setattr(struct afs_server *server, struct key *key,
1393 struct afs_vnode *vnode, struct iattr *attr,
1394 const struct afs_wait_mode *wait_mode)
1395{
1396 struct afs_call *call;
1397 __be32 *bp;
1398
1399 if (attr->ia_valid & ATTR_SIZE)
1400 return afs_fs_setattr_size(server, key, vnode, attr,
1401 wait_mode);
1402
1403 _enter(",%x,{%x:%u},,",
1404 key_serial(key), vnode->fid.vid, vnode->fid.vnode);
1405
1406 call = afs_alloc_flat_call(&afs_RXFSStoreStatus,
1407 (4 + 6) * 4,
1408 (21 + 6) * 4);
1409 if (!call)
1410 return -ENOMEM;
1411
1412 call->key = key;
1413 call->reply = vnode;
1414 call->service_id = FS_SERVICE;
1415 call->port = htons(AFS_FS_PORT);
1416 call->operation_ID = FSSTORESTATUS;
1417
1418 /* marshall the parameters */
1419 bp = call->request;
1420 *bp++ = htonl(FSSTORESTATUS);
1421 *bp++ = htonl(vnode->fid.vid);
1422 *bp++ = htonl(vnode->fid.vnode);
1423 *bp++ = htonl(vnode->fid.unique);
1424
1425 xdr_encode_AFS_StoreStatus(&bp, attr);
1426
1427 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1428}
David Howells45222b92007-05-10 22:22:20 -07001429
1430/*
1431 * deliver reply data to an FS.GetVolumeStatus
1432 */
David Howellsd0016482016-08-30 20:42:14 +01001433static int afs_deliver_fs_get_volume_status(struct afs_call *call)
David Howells45222b92007-05-10 22:22:20 -07001434{
1435 const __be32 *bp;
1436 char *p;
1437 int ret;
1438
David Howellsd0016482016-08-30 20:42:14 +01001439 _enter("{%u}", call->unmarshall);
David Howells45222b92007-05-10 22:22:20 -07001440
1441 switch (call->unmarshall) {
1442 case 0:
1443 call->offset = 0;
1444 call->unmarshall++;
1445
1446 /* extract the returned status record */
1447 case 1:
1448 _debug("extract status");
David Howellsd0016482016-08-30 20:42:14 +01001449 ret = afs_extract_data(call, call->buffer,
1450 12 * 4, true);
David Howells372ee162016-08-03 14:11:40 +01001451 if (ret < 0)
1452 return ret;
David Howells45222b92007-05-10 22:22:20 -07001453
1454 bp = call->buffer;
1455 xdr_decode_AFSFetchVolumeStatus(&bp, call->reply2);
1456 call->offset = 0;
1457 call->unmarshall++;
1458
1459 /* extract the volume name length */
1460 case 2:
David Howellsd0016482016-08-30 20:42:14 +01001461 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +01001462 if (ret < 0)
1463 return ret;
David Howells45222b92007-05-10 22:22:20 -07001464
1465 call->count = ntohl(call->tmp);
1466 _debug("volname length: %u", call->count);
1467 if (call->count >= AFSNAMEMAX)
1468 return -EBADMSG;
1469 call->offset = 0;
1470 call->unmarshall++;
1471
1472 /* extract the volume name */
1473 case 3:
1474 _debug("extract volname");
1475 if (call->count > 0) {
David Howellsd0016482016-08-30 20:42:14 +01001476 ret = afs_extract_data(call, call->reply3,
1477 call->count, true);
David Howells372ee162016-08-03 14:11:40 +01001478 if (ret < 0)
1479 return ret;
David Howells45222b92007-05-10 22:22:20 -07001480 }
1481
1482 p = call->reply3;
1483 p[call->count] = 0;
1484 _debug("volname '%s'", p);
1485
1486 call->offset = 0;
1487 call->unmarshall++;
1488
1489 /* extract the volume name padding */
1490 if ((call->count & 3) == 0) {
1491 call->unmarshall++;
1492 goto no_volname_padding;
1493 }
1494 call->count = 4 - (call->count & 3);
1495
1496 case 4:
David Howellsd0016482016-08-30 20:42:14 +01001497 ret = afs_extract_data(call, call->buffer,
1498 call->count, true);
David Howells372ee162016-08-03 14:11:40 +01001499 if (ret < 0)
1500 return ret;
David Howells45222b92007-05-10 22:22:20 -07001501
1502 call->offset = 0;
1503 call->unmarshall++;
1504 no_volname_padding:
1505
1506 /* extract the offline message length */
1507 case 5:
David Howellsd0016482016-08-30 20:42:14 +01001508 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +01001509 if (ret < 0)
1510 return ret;
David Howells45222b92007-05-10 22:22:20 -07001511
1512 call->count = ntohl(call->tmp);
1513 _debug("offline msg length: %u", call->count);
1514 if (call->count >= AFSNAMEMAX)
1515 return -EBADMSG;
1516 call->offset = 0;
1517 call->unmarshall++;
1518
1519 /* extract the offline message */
1520 case 6:
1521 _debug("extract offline");
1522 if (call->count > 0) {
David Howellsd0016482016-08-30 20:42:14 +01001523 ret = afs_extract_data(call, call->reply3,
1524 call->count, true);
David Howells372ee162016-08-03 14:11:40 +01001525 if (ret < 0)
1526 return ret;
David Howells45222b92007-05-10 22:22:20 -07001527 }
1528
1529 p = call->reply3;
1530 p[call->count] = 0;
1531 _debug("offline '%s'", p);
1532
1533 call->offset = 0;
1534 call->unmarshall++;
1535
1536 /* extract the offline message padding */
1537 if ((call->count & 3) == 0) {
1538 call->unmarshall++;
1539 goto no_offline_padding;
1540 }
1541 call->count = 4 - (call->count & 3);
1542
1543 case 7:
David Howellsd0016482016-08-30 20:42:14 +01001544 ret = afs_extract_data(call, call->buffer,
1545 call->count, true);
David Howells372ee162016-08-03 14:11:40 +01001546 if (ret < 0)
1547 return ret;
David Howells45222b92007-05-10 22:22:20 -07001548
1549 call->offset = 0;
1550 call->unmarshall++;
1551 no_offline_padding:
1552
1553 /* extract the message of the day length */
1554 case 8:
David Howellsd0016482016-08-30 20:42:14 +01001555 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +01001556 if (ret < 0)
1557 return ret;
David Howells45222b92007-05-10 22:22:20 -07001558
1559 call->count = ntohl(call->tmp);
1560 _debug("motd length: %u", call->count);
1561 if (call->count >= AFSNAMEMAX)
1562 return -EBADMSG;
1563 call->offset = 0;
1564 call->unmarshall++;
1565
1566 /* extract the message of the day */
1567 case 9:
1568 _debug("extract motd");
1569 if (call->count > 0) {
David Howellsd0016482016-08-30 20:42:14 +01001570 ret = afs_extract_data(call, call->reply3,
1571 call->count, true);
David Howells372ee162016-08-03 14:11:40 +01001572 if (ret < 0)
1573 return ret;
David Howells45222b92007-05-10 22:22:20 -07001574 }
1575
1576 p = call->reply3;
1577 p[call->count] = 0;
1578 _debug("motd '%s'", p);
1579
1580 call->offset = 0;
1581 call->unmarshall++;
1582
1583 /* extract the message of the day padding */
David Howellsd0016482016-08-30 20:42:14 +01001584 call->count = (4 - (call->count & 3)) & 3;
David Howells45222b92007-05-10 22:22:20 -07001585
1586 case 10:
David Howellsd0016482016-08-30 20:42:14 +01001587 ret = afs_extract_data(call, call->buffer,
1588 call->count, false);
David Howells372ee162016-08-03 14:11:40 +01001589 if (ret < 0)
1590 return ret;
David Howells45222b92007-05-10 22:22:20 -07001591
1592 call->offset = 0;
1593 call->unmarshall++;
David Howells45222b92007-05-10 22:22:20 -07001594 case 11:
David Howells45222b92007-05-10 22:22:20 -07001595 break;
1596 }
1597
David Howells45222b92007-05-10 22:22:20 -07001598 _leave(" = 0 [done]");
1599 return 0;
1600}
1601
1602/*
1603 * destroy an FS.GetVolumeStatus call
1604 */
1605static void afs_get_volume_status_call_destructor(struct afs_call *call)
1606{
1607 kfree(call->reply3);
1608 call->reply3 = NULL;
1609 afs_flat_call_destructor(call);
1610}
1611
1612/*
1613 * FS.GetVolumeStatus operation type
1614 */
1615static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1616 .name = "FS.GetVolumeStatus",
1617 .deliver = afs_deliver_fs_get_volume_status,
1618 .abort_to_error = afs_abort_to_error,
1619 .destructor = afs_get_volume_status_call_destructor,
1620};
1621
1622/*
1623 * fetch the status of a volume
1624 */
1625int afs_fs_get_volume_status(struct afs_server *server,
1626 struct key *key,
1627 struct afs_vnode *vnode,
1628 struct afs_volume_status *vs,
1629 const struct afs_wait_mode *wait_mode)
1630{
1631 struct afs_call *call;
1632 __be32 *bp;
1633 void *tmpbuf;
1634
1635 _enter("");
1636
1637 tmpbuf = kmalloc(AFSOPAQUEMAX, GFP_KERNEL);
1638 if (!tmpbuf)
1639 return -ENOMEM;
1640
1641 call = afs_alloc_flat_call(&afs_RXFSGetVolumeStatus, 2 * 4, 12 * 4);
1642 if (!call) {
1643 kfree(tmpbuf);
1644 return -ENOMEM;
1645 }
1646
1647 call->key = key;
1648 call->reply = vnode;
1649 call->reply2 = vs;
1650 call->reply3 = tmpbuf;
1651 call->service_id = FS_SERVICE;
1652 call->port = htons(AFS_FS_PORT);
1653
1654 /* marshall the parameters */
1655 bp = call->request;
1656 bp[0] = htonl(FSGETVOLUMESTATUS);
1657 bp[1] = htonl(vnode->fid.vid);
1658
1659 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1660}
David Howellse8d6c552007-07-15 23:40:12 -07001661
1662/*
1663 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1664 */
David Howellsd0016482016-08-30 20:42:14 +01001665static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
David Howellse8d6c552007-07-15 23:40:12 -07001666{
1667 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001668 int ret;
David Howellse8d6c552007-07-15 23:40:12 -07001669
David Howellsd0016482016-08-30 20:42:14 +01001670 _enter("{%u}", call->unmarshall);
David Howellse8d6c552007-07-15 23:40:12 -07001671
David Howellsd0016482016-08-30 20:42:14 +01001672 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001673 if (ret < 0)
1674 return ret;
David Howellse8d6c552007-07-15 23:40:12 -07001675
1676 /* unmarshall the reply once we've received all of it */
1677 bp = call->buffer;
1678 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
1679
1680 _leave(" = 0 [done]");
1681 return 0;
1682}
1683
1684/*
1685 * FS.SetLock operation type
1686 */
1687static const struct afs_call_type afs_RXFSSetLock = {
1688 .name = "FS.SetLock",
1689 .deliver = afs_deliver_fs_xxxx_lock,
1690 .abort_to_error = afs_abort_to_error,
1691 .destructor = afs_flat_call_destructor,
1692};
1693
1694/*
1695 * FS.ExtendLock operation type
1696 */
1697static const struct afs_call_type afs_RXFSExtendLock = {
1698 .name = "FS.ExtendLock",
1699 .deliver = afs_deliver_fs_xxxx_lock,
1700 .abort_to_error = afs_abort_to_error,
1701 .destructor = afs_flat_call_destructor,
1702};
1703
1704/*
1705 * FS.ReleaseLock operation type
1706 */
1707static const struct afs_call_type afs_RXFSReleaseLock = {
1708 .name = "FS.ReleaseLock",
1709 .deliver = afs_deliver_fs_xxxx_lock,
1710 .abort_to_error = afs_abort_to_error,
1711 .destructor = afs_flat_call_destructor,
1712};
1713
1714/*
1715 * get a lock on a file
1716 */
1717int afs_fs_set_lock(struct afs_server *server,
1718 struct key *key,
1719 struct afs_vnode *vnode,
1720 afs_lock_type_t type,
1721 const struct afs_wait_mode *wait_mode)
1722{
1723 struct afs_call *call;
1724 __be32 *bp;
1725
1726 _enter("");
1727
1728 call = afs_alloc_flat_call(&afs_RXFSSetLock, 5 * 4, 6 * 4);
1729 if (!call)
1730 return -ENOMEM;
1731
1732 call->key = key;
1733 call->reply = vnode;
1734 call->service_id = FS_SERVICE;
1735 call->port = htons(AFS_FS_PORT);
1736
1737 /* marshall the parameters */
1738 bp = call->request;
1739 *bp++ = htonl(FSSETLOCK);
1740 *bp++ = htonl(vnode->fid.vid);
1741 *bp++ = htonl(vnode->fid.vnode);
1742 *bp++ = htonl(vnode->fid.unique);
1743 *bp++ = htonl(type);
1744
1745 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1746}
1747
1748/*
1749 * extend a lock on a file
1750 */
1751int afs_fs_extend_lock(struct afs_server *server,
1752 struct key *key,
1753 struct afs_vnode *vnode,
1754 const struct afs_wait_mode *wait_mode)
1755{
1756 struct afs_call *call;
1757 __be32 *bp;
1758
1759 _enter("");
1760
1761 call = afs_alloc_flat_call(&afs_RXFSExtendLock, 4 * 4, 6 * 4);
1762 if (!call)
1763 return -ENOMEM;
1764
1765 call->key = key;
1766 call->reply = vnode;
1767 call->service_id = FS_SERVICE;
1768 call->port = htons(AFS_FS_PORT);
1769
1770 /* marshall the parameters */
1771 bp = call->request;
1772 *bp++ = htonl(FSEXTENDLOCK);
1773 *bp++ = htonl(vnode->fid.vid);
1774 *bp++ = htonl(vnode->fid.vnode);
1775 *bp++ = htonl(vnode->fid.unique);
1776
1777 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1778}
1779
1780/*
1781 * release a lock on a file
1782 */
1783int afs_fs_release_lock(struct afs_server *server,
1784 struct key *key,
1785 struct afs_vnode *vnode,
1786 const struct afs_wait_mode *wait_mode)
1787{
1788 struct afs_call *call;
1789 __be32 *bp;
1790
1791 _enter("");
1792
1793 call = afs_alloc_flat_call(&afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1794 if (!call)
1795 return -ENOMEM;
1796
1797 call->key = key;
1798 call->reply = vnode;
1799 call->service_id = FS_SERVICE;
1800 call->port = htons(AFS_FS_PORT);
1801
1802 /* marshall the parameters */
1803 bp = call->request;
1804 *bp++ = htonl(FSRELEASELOCK);
1805 *bp++ = htonl(vnode->fid.vid);
1806 *bp++ = htonl(vnode->fid.vnode);
1807 *bp++ = htonl(vnode->fid.unique);
1808
1809 return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
1810}