blob: 114f281f3687880a9739a94d23228179f83b8bfa [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
David Howells08e0e7c2007-04-26 15:55:03 -07002/* AFS File Server client stubs
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
David Howells08e0e7c2007-04-26 15:55:03 -07004 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Written by David Howells (dhowells@redhat.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
8#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/sched.h>
David Howells08e0e7c2007-04-26 15:55:03 -070011#include <linux/circ_buf.h>
Jeff Laytona01179e2017-12-11 06:35:11 -050012#include <linux/iversion.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "internal.h"
David Howells08e0e7c2007-04-26 15:55:03 -070014#include "afs_fs.h"
David Howellsdd9fbcb2018-04-06 14:17:24 +010015#include "xdr_fs.h"
David Howells30062bd2018-10-20 00:57:58 +010016#include "protocol_yfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
David Howells025db802017-11-02 15:27:51 +000018static const struct afs_fid afs_zero_fid;
19
David Howellsd2ddc772017-11-02 15:27:50 +000020static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi)
David Howellsc435ee32017-11-02 15:27:49 +000021{
David Howellsd2ddc772017-11-02 15:27:50 +000022 call->cbi = afs_get_cb_interest(cbi);
David Howellsc435ee32017-11-02 15:27:49 +000023}
24
David Howells6db3ac32017-03-16 16:27:44 +000025/*
David Howells260a9802007-04-26 15:59:35 -070026 * decode an AFSFid block
27 */
28static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
29{
30 const __be32 *bp = *_bp;
31
32 fid->vid = ntohl(*bp++);
33 fid->vnode = ntohl(*bp++);
34 fid->unique = ntohl(*bp++);
35 *_bp = bp;
36}
37
38/*
David Howells888b3382018-04-06 14:17:24 +010039 * Dump a bad file status record.
40 */
41static void xdr_dump_bad(const __be32 *bp)
42{
43 __be32 x[4];
44 int i;
45
46 pr_notice("AFS XDR: Bad status record\n");
47 for (i = 0; i < 5 * 4 * 4; i += 16) {
48 memcpy(x, bp, 16);
49 bp += 4;
50 pr_notice("%03x: %08x %08x %08x %08x\n",
51 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
52 }
53
54 memcpy(x, bp, 4);
55 pr_notice("0x50: %08x\n", ntohl(x[0]));
56}
57
58/*
David Howellsdd9fbcb2018-04-06 14:17:24 +010059 * decode an AFSFetchStatus block
60 */
David Howellsa58823a2019-05-09 15:16:10 +010061static int xdr_decode_AFSFetchStatus(const __be32 **_bp,
62 struct afs_call *call,
63 struct afs_status_cb *scb)
David Howellsdd9fbcb2018-04-06 14:17:24 +010064{
65 const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
David Howellsa58823a2019-05-09 15:16:10 +010066 struct afs_file_status *status = &scb->status;
David Howells684b0f62018-05-10 21:51:47 +010067 bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
David Howellsdd9fbcb2018-04-06 14:17:24 +010068 u64 data_version, size;
69 u32 type, abort_code;
David Howellsdd9fbcb2018-04-06 14:17:24 +010070
David Howells684b0f62018-05-10 21:51:47 +010071 abort_code = ntohl(xdr->abort_code);
72
David Howellsdd9fbcb2018-04-06 14:17:24 +010073 if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
David Howells684b0f62018-05-10 21:51:47 +010074 if (xdr->if_version == htonl(0) &&
75 abort_code != 0 &&
76 inline_error) {
77 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
78 * whereby it doesn't set the interface version in the error
79 * case.
80 */
81 status->abort_code = abort_code;
David Howellsa38a7552019-05-14 12:29:11 +010082 scb->have_error = true;
Al Virode52cf92018-06-02 18:08:11 -040083 return 0;
David Howells684b0f62018-05-10 21:51:47 +010084 }
85
David Howellsdd9fbcb2018-04-06 14:17:24 +010086 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
87 goto bad;
88 }
89
David Howells684b0f62018-05-10 21:51:47 +010090 if (abort_code != 0 && inline_error) {
91 status->abort_code = abort_code;
Al Virode52cf92018-06-02 18:08:11 -040092 return 0;
David Howells684b0f62018-05-10 21:51:47 +010093 }
94
David Howellsdd9fbcb2018-04-06 14:17:24 +010095 type = ntohl(xdr->type);
David Howellsdd9fbcb2018-04-06 14:17:24 +010096 switch (type) {
97 case AFS_FTYPE_FILE:
98 case AFS_FTYPE_DIR:
99 case AFS_FTYPE_SYMLINK:
David Howellsdd9fbcb2018-04-06 14:17:24 +0100100 status->type = type;
101 break;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100102 default:
103 goto bad;
104 }
105
David Howellsa58823a2019-05-09 15:16:10 +0100106 status->nlink = ntohl(xdr->nlink);
107 status->author = ntohl(xdr->author);
108 status->owner = ntohl(xdr->owner);
109 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
110 status->anon_access = ntohl(xdr->anon_access);
111 status->mode = ntohl(xdr->mode) & S_IALLUGO;
112 status->group = ntohl(xdr->group);
113 status->lock_count = ntohl(xdr->lock_count);
David Howellsdd9fbcb2018-04-06 14:17:24 +0100114
David Howellsd4936802018-10-20 00:57:58 +0100115 status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
116 status->mtime_client.tv_nsec = 0;
117 status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
118 status->mtime_server.tv_nsec = 0;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100119
120 size = (u64)ntohl(xdr->size_lo);
121 size |= (u64)ntohl(xdr->size_hi) << 32;
David Howells63a46812018-04-06 14:17:25 +0100122 status->size = size;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100123
124 data_version = (u64)ntohl(xdr->data_version_lo);
125 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
David Howellsa58823a2019-05-09 15:16:10 +0100126 status->data_version = data_version;
David Howellsa38a7552019-05-14 12:29:11 +0100127 scb->have_status = true;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100128
129 *_bp = (const void *)*_bp + sizeof(*xdr);
David Howellsc875c762018-05-23 11:32:06 +0100130 return 0;
David Howellsdd9fbcb2018-04-06 14:17:24 +0100131
132bad:
133 xdr_dump_bad(*_bp);
David Howells160cb952018-10-20 00:57:56 +0100134 return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
David Howellsc875c762018-05-23 11:32:06 +0100135}
136
David Howells78107052019-05-09 17:56:53 +0100137static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
138{
139 return ktime_divns(call->reply_time, NSEC_PER_SEC) + expiry;
140}
141
David Howellsa58823a2019-05-09 15:16:10 +0100142static void xdr_decode_AFSCallBack(const __be32 **_bp,
143 struct afs_call *call,
144 struct afs_status_cb *scb)
David Howells78107052019-05-09 17:56:53 +0100145{
David Howellsa58823a2019-05-09 15:16:10 +0100146 struct afs_callback *cb = &scb->callback;
David Howells78107052019-05-09 17:56:53 +0100147 const __be32 *bp = *_bp;
148
David Howells7c712452019-05-14 15:35:44 +0100149 bp++; /* version */
David Howells78107052019-05-09 17:56:53 +0100150 cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
David Howells7c712452019-05-14 15:35:44 +0100151 bp++; /* type */
David Howellsa58823a2019-05-09 15:16:10 +0100152 scb->have_cb = true;
David Howells78107052019-05-09 17:56:53 +0100153 *_bp = bp;
154}
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156/*
David Howells08e0e7c2007-04-26 15:55:03 -0700157 * decode an AFSVolSync block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 */
David Howells08e0e7c2007-04-26 15:55:03 -0700159static void xdr_decode_AFSVolSync(const __be32 **_bp,
160 struct afs_volsync *volsync)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161{
David Howells08e0e7c2007-04-26 15:55:03 -0700162 const __be32 *bp = *_bp;
David Howells30062bd2018-10-20 00:57:58 +0100163 u32 creation;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
David Howells30062bd2018-10-20 00:57:58 +0100165 creation = ntohl(*bp++);
David Howells08e0e7c2007-04-26 15:55:03 -0700166 bp++; /* spare2 */
167 bp++; /* spare3 */
168 bp++; /* spare4 */
169 bp++; /* spare5 */
170 bp++; /* spare6 */
171 *_bp = bp;
David Howells30062bd2018-10-20 00:57:58 +0100172
173 if (volsync)
174 volsync->creation = creation;
David Howellsec268152007-04-26 15:49:28 -0700175}
David Howells08e0e7c2007-04-26 15:55:03 -0700176
177/*
David Howells31143d52007-05-09 02:33:46 -0700178 * encode the requested attributes into an AFSStoreStatus block
179 */
180static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
181{
182 __be32 *bp = *_bp;
183 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
184
185 mask = 0;
186 if (attr->ia_valid & ATTR_MTIME) {
187 mask |= AFS_SET_MTIME;
188 mtime = attr->ia_mtime.tv_sec;
189 }
190
191 if (attr->ia_valid & ATTR_UID) {
192 mask |= AFS_SET_OWNER;
Eric W. Biedermana0a53862012-02-07 16:20:48 -0800193 owner = from_kuid(&init_user_ns, attr->ia_uid);
David Howells31143d52007-05-09 02:33:46 -0700194 }
195
196 if (attr->ia_valid & ATTR_GID) {
197 mask |= AFS_SET_GROUP;
Eric W. Biedermana0a53862012-02-07 16:20:48 -0800198 group = from_kgid(&init_user_ns, attr->ia_gid);
David Howells31143d52007-05-09 02:33:46 -0700199 }
200
201 if (attr->ia_valid & ATTR_MODE) {
202 mask |= AFS_SET_MODE;
203 mode = attr->ia_mode & S_IALLUGO;
204 }
205
206 *bp++ = htonl(mask);
207 *bp++ = htonl(mtime);
208 *bp++ = htonl(owner);
209 *bp++ = htonl(group);
210 *bp++ = htonl(mode);
211 *bp++ = 0; /* segment size */
212 *_bp = bp;
213}
214
215/*
David Howells45222b92007-05-10 22:22:20 -0700216 * decode an AFSFetchVolumeStatus block
217 */
218static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
219 struct afs_volume_status *vs)
220{
221 const __be32 *bp = *_bp;
222
223 vs->vid = ntohl(*bp++);
224 vs->parent_id = ntohl(*bp++);
225 vs->online = ntohl(*bp++);
226 vs->in_service = ntohl(*bp++);
227 vs->blessed = ntohl(*bp++);
228 vs->needs_salvage = ntohl(*bp++);
229 vs->type = ntohl(*bp++);
230 vs->min_quota = ntohl(*bp++);
231 vs->max_quota = ntohl(*bp++);
232 vs->blocks_in_use = ntohl(*bp++);
233 vs->part_blocks_avail = ntohl(*bp++);
234 vs->part_max_blocks = ntohl(*bp++);
David Howells30062bd2018-10-20 00:57:58 +0100235 vs->vol_copy_date = 0;
236 vs->vol_backup_date = 0;
David Howells45222b92007-05-10 22:22:20 -0700237 *_bp = bp;
238}
239
240/*
David Howells08e0e7c2007-04-26 15:55:03 -0700241 * deliver reply data to an FS.FetchStatus
242 */
David Howells5cf9dd52018-04-09 21:12:31 +0100243static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
David Howells08e0e7c2007-04-26 15:55:03 -0700244{
245 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100246 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700247
David Howellsd0016482016-08-30 20:42:14 +0100248 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100249 if (ret < 0)
250 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700251
252 /* unmarshall the reply once we've received all of it */
253 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +0100254 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +0100255 if (ret < 0)
256 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100257 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
David Howellsffba7182019-05-09 22:22:50 +0100258 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells08e0e7c2007-04-26 15:55:03 -0700259
260 _leave(" = 0 [done]");
261 return 0;
262}
263
264/*
265 * FS.FetchStatus operation type
266 */
David Howells5cf9dd52018-04-09 21:12:31 +0100267static const struct afs_call_type afs_RXFSFetchStatus_vnode = {
268 .name = "FS.FetchStatus(vnode)",
David Howells025db802017-11-02 15:27:51 +0000269 .op = afs_FS_FetchStatus,
David Howells5cf9dd52018-04-09 21:12:31 +0100270 .deliver = afs_deliver_fs_fetch_status_vnode,
David Howells08e0e7c2007-04-26 15:55:03 -0700271 .destructor = afs_flat_call_destructor,
272};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274/*
275 * fetch the status information for a file
276 */
David Howellsa58823a2019-05-09 15:16:10 +0100277int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_status_cb *scb,
278 struct afs_volsync *volsync)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
David Howellsd2ddc772017-11-02 15:27:50 +0000280 struct afs_vnode *vnode = fc->vnode;
David Howells08e0e7c2007-04-26 15:55:03 -0700281 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000282 struct afs_net *net = afs_v2net(vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 __be32 *bp;
284
David Howells30062bd2018-10-20 00:57:58 +0100285 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +0100286 return yfs_fs_fetch_file_status(fc, scb, volsync);
David Howells30062bd2018-10-20 00:57:58 +0100287
David Howells3b6492d2018-10-20 00:57:57 +0100288 _enter(",%x,{%llx:%llu},,",
David Howellsd2ddc772017-11-02 15:27:50 +0000289 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
David Howells5cf9dd52018-04-09 21:12:31 +0100291 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus_vnode,
292 16, (21 + 3 + 6) * 4);
David Howellsd2ddc772017-11-02 15:27:50 +0000293 if (!call) {
294 fc->ac.error = -ENOMEM;
David Howells08e0e7c2007-04-26 15:55:03 -0700295 return -ENOMEM;
David Howellsd2ddc772017-11-02 15:27:50 +0000296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
David Howellsd2ddc772017-11-02 15:27:50 +0000298 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100299 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +0100300 call->out_volsync = volsync;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700303 bp = call->request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 bp[0] = htonl(FSFETCHSTATUS);
305 bp[1] = htonl(vnode->fid.vid);
306 bp[2] = htonl(vnode->fid.vnode);
307 bp[3] = htonl(vnode->fid.unique);
308
David Howellsd2ddc772017-11-02 15:27:50 +0000309 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +0000310 trace_afs_make_fs_call(call, &vnode->fid);
David Howells0b9bf382019-04-25 14:26:50 +0100311
David Howells20b83912019-05-08 16:16:31 +0100312 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100313 afs_make_call(&fc->ac, call, GFP_NOFS);
314 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsec268152007-04-26 15:49:28 -0700315}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317/*
David Howells08e0e7c2007-04-26 15:55:03 -0700318 * deliver reply data to an FS.FetchData
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 */
David Howellsd0016482016-08-30 20:42:14 +0100320static int afs_deliver_fs_fetch_data(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
David Howellsffba7182019-05-09 22:22:50 +0100322 struct afs_read *req = call->read_request;
David Howells08e0e7c2007-04-26 15:55:03 -0700323 const __be32 *bp;
David Howells196ee9c2017-01-05 10:38:34 +0000324 unsigned int size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700326
David Howells12bdcf32018-10-20 00:57:56 +0100327 _enter("{%u,%zu/%llu}",
328 call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
David Howells08e0e7c2007-04-26 15:55:03 -0700329
330 switch (call->unmarshall) {
331 case 0:
David Howells196ee9c2017-01-05 10:38:34 +0000332 req->actual_len = 0;
David Howells12bdcf32018-10-20 00:57:56 +0100333 req->index = 0;
334 req->offset = req->pos & (PAGE_SIZE - 1);
David Howells08e0e7c2007-04-26 15:55:03 -0700335 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +0100336 if (call->operation_ID == FSFETCHDATA64) {
337 afs_extract_to_tmp64(call);
338 } else {
339 call->tmp_u = htonl(0);
340 afs_extract_to_tmp(call);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700341 }
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500342 /* Fall through */
David Howells08e0e7c2007-04-26 15:55:03 -0700343
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500344 /* extract the returned data length */
David Howells12bdcf32018-10-20 00:57:56 +0100345 case 1:
David Howells08e0e7c2007-04-26 15:55:03 -0700346 _debug("extract data length");
David Howells12bdcf32018-10-20 00:57:56 +0100347 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100348 if (ret < 0)
349 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700350
David Howells12bdcf32018-10-20 00:57:56 +0100351 req->actual_len = be64_to_cpu(call->tmp64);
David Howells196ee9c2017-01-05 10:38:34 +0000352 _debug("DATA length: %llu", req->actual_len);
David Howells12bdcf32018-10-20 00:57:56 +0100353 req->remain = min(req->len, req->actual_len);
354 if (req->remain == 0)
David Howells196ee9c2017-01-05 10:38:34 +0000355 goto no_more_data;
David Howells12bdcf32018-10-20 00:57:56 +0100356
David Howells08e0e7c2007-04-26 15:55:03 -0700357 call->unmarshall++;
358
David Howells196ee9c2017-01-05 10:38:34 +0000359 begin_page:
David Howells6db3ac32017-03-16 16:27:44 +0000360 ASSERTCMP(req->index, <, req->nr_pages);
David Howells12bdcf32018-10-20 00:57:56 +0100361 if (req->remain > PAGE_SIZE - req->offset)
362 size = PAGE_SIZE - req->offset;
David Howells196ee9c2017-01-05 10:38:34 +0000363 else
364 size = req->remain;
David Howells12bdcf32018-10-20 00:57:56 +0100365 call->bvec[0].bv_len = size;
366 call->bvec[0].bv_offset = req->offset;
367 call->bvec[0].bv_page = req->pages[req->index];
368 iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
369 ASSERTCMP(size, <=, PAGE_SIZE);
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500370 /* Fall through */
David Howells196ee9c2017-01-05 10:38:34 +0000371
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500372 /* extract the returned data */
David Howells12bdcf32018-10-20 00:57:56 +0100373 case 2:
374 _debug("extract data %zu/%llu",
375 iov_iter_count(&call->iter), req->remain);
David Howells196ee9c2017-01-05 10:38:34 +0000376
David Howells12bdcf32018-10-20 00:57:56 +0100377 ret = afs_extract_data(call, true);
David Howells196ee9c2017-01-05 10:38:34 +0000378 if (ret < 0)
379 return ret;
David Howells12bdcf32018-10-20 00:57:56 +0100380 req->remain -= call->bvec[0].bv_len;
381 req->offset += call->bvec[0].bv_len;
382 ASSERTCMP(req->offset, <=, PAGE_SIZE);
383 if (req->offset == PAGE_SIZE) {
384 req->offset = 0;
David Howells196ee9c2017-01-05 10:38:34 +0000385 if (req->page_done)
David Howellsa58823a2019-05-09 15:16:10 +0100386 req->page_done(req);
David Howells29f06982017-03-16 16:27:46 +0000387 req->index++;
David Howells12bdcf32018-10-20 00:57:56 +0100388 if (req->remain > 0)
David Howells196ee9c2017-01-05 10:38:34 +0000389 goto begin_page;
David Howells08e0e7c2007-04-26 15:55:03 -0700390 }
David Howells12bdcf32018-10-20 00:57:56 +0100391
392 ASSERTCMP(req->remain, ==, 0);
393 if (req->actual_len <= req->len)
394 goto no_more_data;
David Howells6db3ac32017-03-16 16:27:44 +0000395
396 /* Discard any excess data the server gave us */
David Howells12bdcf32018-10-20 00:57:56 +0100397 iov_iter_discard(&call->iter, READ, req->actual_len - req->len);
398 call->unmarshall = 3;
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600399 /* Fall through */
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500400
David Howells12bdcf32018-10-20 00:57:56 +0100401 case 3:
402 _debug("extract discard %zu/%llu",
403 iov_iter_count(&call->iter), req->actual_len - req->len);
David Howells6db3ac32017-03-16 16:27:44 +0000404
David Howells12bdcf32018-10-20 00:57:56 +0100405 ret = afs_extract_data(call, true);
David Howells6db3ac32017-03-16 16:27:44 +0000406 if (ret < 0)
407 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700408
David Howells196ee9c2017-01-05 10:38:34 +0000409 no_more_data:
David Howells12bdcf32018-10-20 00:57:56 +0100410 call->unmarshall = 4;
411 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500412 /* Fall through */
David Howells08e0e7c2007-04-26 15:55:03 -0700413
Gustavo A. R. Silva29881602019-05-19 18:43:53 -0500414 /* extract the metadata */
David Howells12bdcf32018-10-20 00:57:56 +0100415 case 4:
416 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100417 if (ret < 0)
418 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700419
420 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +0100421 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +0100422 if (ret < 0)
423 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100424 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
David Howellsffba7182019-05-09 22:22:50 +0100425 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells08e0e7c2007-04-26 15:55:03 -0700426
David Howellsa58823a2019-05-09 15:16:10 +0100427 req->data_version = call->out_scb->status.data_version;
428 req->file_size = call->out_scb->status.size;
429
David Howells08e0e7c2007-04-26 15:55:03 -0700430 call->unmarshall++;
431
David Howells12bdcf32018-10-20 00:57:56 +0100432 case 5:
David Howells08e0e7c2007-04-26 15:55:03 -0700433 break;
434 }
435
David Howells6db3ac32017-03-16 16:27:44 +0000436 for (; req->index < req->nr_pages; req->index++) {
David Howells12bdcf32018-10-20 00:57:56 +0100437 if (req->offset < PAGE_SIZE)
David Howells6db3ac32017-03-16 16:27:44 +0000438 zero_user_segment(req->pages[req->index],
David Howells12bdcf32018-10-20 00:57:56 +0100439 req->offset, PAGE_SIZE);
David Howells196ee9c2017-01-05 10:38:34 +0000440 if (req->page_done)
David Howellsa58823a2019-05-09 15:16:10 +0100441 req->page_done(req);
David Howells12bdcf32018-10-20 00:57:56 +0100442 req->offset = 0;
David Howells416351f2007-05-09 02:33:45 -0700443 }
444
David Howells08e0e7c2007-04-26 15:55:03 -0700445 _leave(" = 0 [done]");
446 return 0;
447}
448
David Howells196ee9c2017-01-05 10:38:34 +0000449static void afs_fetch_data_destructor(struct afs_call *call)
450{
David Howellsffba7182019-05-09 22:22:50 +0100451 struct afs_read *req = call->read_request;
David Howells196ee9c2017-01-05 10:38:34 +0000452
453 afs_put_read(req);
454 afs_flat_call_destructor(call);
455}
456
David Howells08e0e7c2007-04-26 15:55:03 -0700457/*
458 * FS.FetchData operation type
459 */
460static const struct afs_call_type afs_RXFSFetchData = {
David Howells00d3b7a2007-04-26 15:57:07 -0700461 .name = "FS.FetchData",
David Howells025db802017-11-02 15:27:51 +0000462 .op = afs_FS_FetchData,
David Howells08e0e7c2007-04-26 15:55:03 -0700463 .deliver = afs_deliver_fs_fetch_data,
David Howells196ee9c2017-01-05 10:38:34 +0000464 .destructor = afs_fetch_data_destructor,
David Howells08e0e7c2007-04-26 15:55:03 -0700465};
466
David Howellsb9b1f8d2007-05-10 03:15:21 -0700467static const struct afs_call_type afs_RXFSFetchData64 = {
468 .name = "FS.FetchData64",
David Howells025db802017-11-02 15:27:51 +0000469 .op = afs_FS_FetchData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -0700470 .deliver = afs_deliver_fs_fetch_data,
David Howells196ee9c2017-01-05 10:38:34 +0000471 .destructor = afs_fetch_data_destructor,
David Howellsb9b1f8d2007-05-10 03:15:21 -0700472};
473
474/*
475 * fetch data from a very large file
476 */
David Howellsa58823a2019-05-09 15:16:10 +0100477static int afs_fs_fetch_data64(struct afs_fs_cursor *fc,
478 struct afs_status_cb *scb,
479 struct afs_read *req)
David Howellsb9b1f8d2007-05-10 03:15:21 -0700480{
David Howellsd2ddc772017-11-02 15:27:50 +0000481 struct afs_vnode *vnode = fc->vnode;
David Howellsb9b1f8d2007-05-10 03:15:21 -0700482 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000483 struct afs_net *net = afs_v2net(vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700484 __be32 *bp;
485
486 _enter("");
487
David Howellsf044c882017-11-02 15:27:45 +0000488 call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700489 if (!call)
490 return -ENOMEM;
491
David Howellsd2ddc772017-11-02 15:27:50 +0000492 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100493 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +0100494 call->out_volsync = NULL;
495 call->read_request = req;
David Howellsb9b1f8d2007-05-10 03:15:21 -0700496
497 /* marshall the parameters */
498 bp = call->request;
499 bp[0] = htonl(FSFETCHDATA64);
500 bp[1] = htonl(vnode->fid.vid);
501 bp[2] = htonl(vnode->fid.vnode);
502 bp[3] = htonl(vnode->fid.unique);
David Howells196ee9c2017-01-05 10:38:34 +0000503 bp[4] = htonl(upper_32_bits(req->pos));
504 bp[5] = htonl(lower_32_bits(req->pos));
David Howellsb9b1f8d2007-05-10 03:15:21 -0700505 bp[6] = 0;
David Howells196ee9c2017-01-05 10:38:34 +0000506 bp[7] = htonl(lower_32_bits(req->len));
David Howellsb9b1f8d2007-05-10 03:15:21 -0700507
David Howellsf3ddee82018-04-06 14:17:25 +0100508 refcount_inc(&req->usage);
David Howellsd2ddc772017-11-02 15:27:50 +0000509 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +0000510 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +0100511 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100512 afs_make_call(&fc->ac, call, GFP_NOFS);
513 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700514}
515
David Howells08e0e7c2007-04-26 15:55:03 -0700516/*
517 * fetch data from a file
518 */
David Howellsa58823a2019-05-09 15:16:10 +0100519int afs_fs_fetch_data(struct afs_fs_cursor *fc,
520 struct afs_status_cb *scb,
521 struct afs_read *req)
David Howells08e0e7c2007-04-26 15:55:03 -0700522{
David Howellsd2ddc772017-11-02 15:27:50 +0000523 struct afs_vnode *vnode = fc->vnode;
David Howells08e0e7c2007-04-26 15:55:03 -0700524 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000525 struct afs_net *net = afs_v2net(vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 __be32 *bp;
527
David Howells30062bd2018-10-20 00:57:58 +0100528 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +0100529 return yfs_fs_fetch_data(fc, scb, req);
David Howells30062bd2018-10-20 00:57:58 +0100530
David Howells196ee9c2017-01-05 10:38:34 +0000531 if (upper_32_bits(req->pos) ||
532 upper_32_bits(req->len) ||
533 upper_32_bits(req->pos + req->len))
David Howellsa58823a2019-05-09 15:16:10 +0100534 return afs_fs_fetch_data64(fc, scb, req);
David Howellsb9b1f8d2007-05-10 03:15:21 -0700535
David Howells08e0e7c2007-04-26 15:55:03 -0700536 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
David Howellsf044c882017-11-02 15:27:45 +0000538 call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700539 if (!call)
540 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
David Howellsd2ddc772017-11-02 15:27:50 +0000542 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100543 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +0100544 call->out_volsync = NULL;
545 call->read_request = req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547 /* marshall the parameters */
David Howells08e0e7c2007-04-26 15:55:03 -0700548 bp = call->request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 bp[0] = htonl(FSFETCHDATA);
David Howells08e0e7c2007-04-26 15:55:03 -0700550 bp[1] = htonl(vnode->fid.vid);
551 bp[2] = htonl(vnode->fid.vnode);
552 bp[3] = htonl(vnode->fid.unique);
David Howells196ee9c2017-01-05 10:38:34 +0000553 bp[4] = htonl(lower_32_bits(req->pos));
554 bp[5] = htonl(lower_32_bits(req->len));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
David Howellsf3ddee82018-04-06 14:17:25 +0100556 refcount_inc(&req->usage);
David Howellsd2ddc772017-11-02 15:27:50 +0000557 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +0000558 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +0100559 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100560 afs_make_call(&fc->ac, call, GFP_NOFS);
561 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsec268152007-04-26 15:49:28 -0700562}
David Howells260a9802007-04-26 15:59:35 -0700563
564/*
565 * deliver reply data to an FS.CreateFile or an FS.MakeDir
566 */
David Howellsd0016482016-08-30 20:42:14 +0100567static int afs_deliver_fs_create_vnode(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700568{
David Howells260a9802007-04-26 15:59:35 -0700569 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100570 int ret;
David Howells260a9802007-04-26 15:59:35 -0700571
David Howellsd0016482016-08-30 20:42:14 +0100572 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100573 if (ret < 0)
574 return ret;
David Howells260a9802007-04-26 15:59:35 -0700575
576 /* unmarshall the reply once we've received all of it */
577 bp = call->buffer;
David Howellsffba7182019-05-09 22:22:50 +0100578 xdr_decode_AFSFid(&bp, call->out_fid);
David Howellsa58823a2019-05-09 15:16:10 +0100579 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +0100580 if (ret < 0)
581 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100582 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Howells160cb952018-10-20 00:57:56 +0100583 if (ret < 0)
584 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100585 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
David Howellsffba7182019-05-09 22:22:50 +0100586 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells260a9802007-04-26 15:59:35 -0700587
588 _leave(" = 0 [done]");
589 return 0;
590}
591
592/*
593 * FS.CreateFile and FS.MakeDir operation type
594 */
David Howells025db802017-11-02 15:27:51 +0000595static const struct afs_call_type afs_RXFSCreateFile = {
596 .name = "FS.CreateFile",
597 .op = afs_FS_CreateFile,
598 .deliver = afs_deliver_fs_create_vnode,
599 .destructor = afs_flat_call_destructor,
600};
601
602static const struct afs_call_type afs_RXFSMakeDir = {
603 .name = "FS.MakeDir",
604 .op = afs_FS_MakeDir,
David Howells260a9802007-04-26 15:59:35 -0700605 .deliver = afs_deliver_fs_create_vnode,
David Howells260a9802007-04-26 15:59:35 -0700606 .destructor = afs_flat_call_destructor,
607};
608
609/*
610 * create a file or make a directory
611 */
David Howells8b2a4642017-11-02 15:27:50 +0000612int afs_fs_create(struct afs_fs_cursor *fc,
David Howells260a9802007-04-26 15:59:35 -0700613 const char *name,
614 umode_t mode,
David Howellsa58823a2019-05-09 15:16:10 +0100615 struct afs_status_cb *dvnode_scb,
David Howells260a9802007-04-26 15:59:35 -0700616 struct afs_fid *newfid,
David Howellsa58823a2019-05-09 15:16:10 +0100617 struct afs_status_cb *new_scb)
David Howells260a9802007-04-26 15:59:35 -0700618{
David Howellsffba7182019-05-09 22:22:50 +0100619 struct afs_vnode *dvnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -0700620 struct afs_call *call;
David Howellsffba7182019-05-09 22:22:50 +0100621 struct afs_net *net = afs_v2net(dvnode);
David Howells260a9802007-04-26 15:59:35 -0700622 size_t namesz, reqsz, padsz;
623 __be32 *bp;
624
David Howells30062bd2018-10-20 00:57:58 +0100625 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags)){
626 if (S_ISDIR(mode))
David Howellsa58823a2019-05-09 15:16:10 +0100627 return yfs_fs_make_dir(fc, name, mode, dvnode_scb,
628 newfid, new_scb);
David Howells30062bd2018-10-20 00:57:58 +0100629 else
David Howellsa58823a2019-05-09 15:16:10 +0100630 return yfs_fs_create_file(fc, name, mode, dvnode_scb,
631 newfid, new_scb);
David Howells30062bd2018-10-20 00:57:58 +0100632 }
633
David Howells260a9802007-04-26 15:59:35 -0700634 _enter("");
635
636 namesz = strlen(name);
637 padsz = (4 - (namesz & 3)) & 3;
638 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
639
David Howells025db802017-11-02 15:27:51 +0000640 call = afs_alloc_flat_call(
641 net, S_ISDIR(mode) ? &afs_RXFSMakeDir : &afs_RXFSCreateFile,
642 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -0700643 if (!call)
644 return -ENOMEM;
645
David Howellsd2ddc772017-11-02 15:27:50 +0000646 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100647 call->out_dir_scb = dvnode_scb;
David Howellsffba7182019-05-09 22:22:50 +0100648 call->out_fid = newfid;
David Howellsa58823a2019-05-09 15:16:10 +0100649 call->out_scb = new_scb;
David Howells260a9802007-04-26 15:59:35 -0700650
651 /* marshall the parameters */
652 bp = call->request;
653 *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
David Howellsffba7182019-05-09 22:22:50 +0100654 *bp++ = htonl(dvnode->fid.vid);
655 *bp++ = htonl(dvnode->fid.vnode);
656 *bp++ = htonl(dvnode->fid.unique);
David Howells260a9802007-04-26 15:59:35 -0700657 *bp++ = htonl(namesz);
658 memcpy(bp, name, namesz);
659 bp = (void *) bp + namesz;
660 if (padsz > 0) {
661 memset(bp, 0, padsz);
662 bp = (void *) bp + padsz;
663 }
Marc Dionneab94f5d2017-03-16 16:27:47 +0000664 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
David Howellsffba7182019-05-09 22:22:50 +0100665 *bp++ = htonl(dvnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howells260a9802007-04-26 15:59:35 -0700666 *bp++ = 0; /* owner */
667 *bp++ = 0; /* group */
668 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
669 *bp++ = 0; /* segment size */
670
David Howellsd2ddc772017-11-02 15:27:50 +0000671 afs_use_fs_server(call, fc->cbi);
David Howellsffba7182019-05-09 22:22:50 +0100672 trace_afs_make_fs_call1(call, &dvnode->fid, name);
David Howells20b83912019-05-08 16:16:31 +0100673 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100674 afs_make_call(&fc->ac, call, GFP_NOFS);
675 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -0700676}
677
678/*
David Howellsffba7182019-05-09 22:22:50 +0100679 * Deliver reply data to any operation that returns directory status and volume
Joe Gorseb10494a2019-04-25 14:26:52 +0100680 * sync.
David Howells260a9802007-04-26 15:59:35 -0700681 */
David Howellsffba7182019-05-09 22:22:50 +0100682static int afs_deliver_fs_dir_status_and_vol(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700683{
David Howells260a9802007-04-26 15:59:35 -0700684 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100685 int ret;
David Howells260a9802007-04-26 15:59:35 -0700686
David Howellsd0016482016-08-30 20:42:14 +0100687 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100688 if (ret < 0)
689 return ret;
David Howells260a9802007-04-26 15:59:35 -0700690
691 /* unmarshall the reply once we've received all of it */
692 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +0100693 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Howells160cb952018-10-20 00:57:56 +0100694 if (ret < 0)
695 return ret;
David Howellsffba7182019-05-09 22:22:50 +0100696 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells260a9802007-04-26 15:59:35 -0700697
698 _leave(" = 0 [done]");
699 return 0;
700}
701
702/*
703 * FS.RemoveDir/FS.RemoveFile operation type
704 */
David Howells025db802017-11-02 15:27:51 +0000705static const struct afs_call_type afs_RXFSRemoveFile = {
706 .name = "FS.RemoveFile",
707 .op = afs_FS_RemoveFile,
David Howellsffba7182019-05-09 22:22:50 +0100708 .deliver = afs_deliver_fs_dir_status_and_vol,
David Howells025db802017-11-02 15:27:51 +0000709 .destructor = afs_flat_call_destructor,
710};
711
712static const struct afs_call_type afs_RXFSRemoveDir = {
713 .name = "FS.RemoveDir",
714 .op = afs_FS_RemoveDir,
David Howellsffba7182019-05-09 22:22:50 +0100715 .deliver = afs_deliver_fs_dir_status_and_vol,
David Howells260a9802007-04-26 15:59:35 -0700716 .destructor = afs_flat_call_destructor,
717};
718
719/*
720 * remove a file or directory
721 */
David Howells30062bd2018-10-20 00:57:58 +0100722int afs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
David Howellsa58823a2019-05-09 15:16:10 +0100723 const char *name, bool isdir, struct afs_status_cb *dvnode_scb)
David Howells260a9802007-04-26 15:59:35 -0700724{
David Howells30062bd2018-10-20 00:57:58 +0100725 struct afs_vnode *dvnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -0700726 struct afs_call *call;
David Howells30062bd2018-10-20 00:57:58 +0100727 struct afs_net *net = afs_v2net(dvnode);
David Howells260a9802007-04-26 15:59:35 -0700728 size_t namesz, reqsz, padsz;
729 __be32 *bp;
730
David Howells30062bd2018-10-20 00:57:58 +0100731 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +0100732 return yfs_fs_remove(fc, vnode, name, isdir, dvnode_scb);
David Howells30062bd2018-10-20 00:57:58 +0100733
David Howells260a9802007-04-26 15:59:35 -0700734 _enter("");
735
736 namesz = strlen(name);
737 padsz = (4 - (namesz & 3)) & 3;
738 reqsz = (5 * 4) + namesz + padsz;
739
David Howells025db802017-11-02 15:27:51 +0000740 call = afs_alloc_flat_call(
741 net, isdir ? &afs_RXFSRemoveDir : &afs_RXFSRemoveFile,
742 reqsz, (21 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -0700743 if (!call)
744 return -ENOMEM;
745
David Howellsd2ddc772017-11-02 15:27:50 +0000746 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100747 call->out_dir_scb = dvnode_scb;
David Howells260a9802007-04-26 15:59:35 -0700748
749 /* marshall the parameters */
750 bp = call->request;
751 *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
David Howells30062bd2018-10-20 00:57:58 +0100752 *bp++ = htonl(dvnode->fid.vid);
753 *bp++ = htonl(dvnode->fid.vnode);
754 *bp++ = htonl(dvnode->fid.unique);
David Howells260a9802007-04-26 15:59:35 -0700755 *bp++ = htonl(namesz);
756 memcpy(bp, name, namesz);
757 bp = (void *) bp + namesz;
758 if (padsz > 0) {
759 memset(bp, 0, padsz);
760 bp = (void *) bp + padsz;
761 }
762
David Howellsd2ddc772017-11-02 15:27:50 +0000763 afs_use_fs_server(call, fc->cbi);
David Howells80548b02019-04-25 14:26:51 +0100764 trace_afs_make_fs_call1(call, &dvnode->fid, name);
David Howells20b83912019-05-08 16:16:31 +0100765 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100766 afs_make_call(&fc->ac, call, GFP_NOFS);
767 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -0700768}
769
770/*
771 * deliver reply data to an FS.Link
772 */
David Howellsd0016482016-08-30 20:42:14 +0100773static int afs_deliver_fs_link(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700774{
David Howells260a9802007-04-26 15:59:35 -0700775 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 Howellsa58823a2019-05-09 15:16:10 +0100786 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +0100787 if (ret < 0)
788 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100789 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Howells160cb952018-10-20 00:57:56 +0100790 if (ret < 0)
791 return ret;
David Howellsffba7182019-05-09 22:22:50 +0100792 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells260a9802007-04-26 15:59:35 -0700793
794 _leave(" = 0 [done]");
795 return 0;
796}
797
798/*
799 * FS.Link operation type
800 */
801static const struct afs_call_type afs_RXFSLink = {
802 .name = "FS.Link",
David Howells025db802017-11-02 15:27:51 +0000803 .op = afs_FS_Link,
David Howells260a9802007-04-26 15:59:35 -0700804 .deliver = afs_deliver_fs_link,
David Howells260a9802007-04-26 15:59:35 -0700805 .destructor = afs_flat_call_destructor,
806};
807
808/*
809 * make a hard link
810 */
David Howellsd2ddc772017-11-02 15:27:50 +0000811int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
David Howellsa58823a2019-05-09 15:16:10 +0100812 const char *name,
813 struct afs_status_cb *dvnode_scb,
814 struct afs_status_cb *vnode_scb)
David Howells260a9802007-04-26 15:59:35 -0700815{
David Howellsd2ddc772017-11-02 15:27:50 +0000816 struct afs_vnode *dvnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -0700817 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +0000818 struct afs_net *net = afs_v2net(vnode);
David Howells260a9802007-04-26 15:59:35 -0700819 size_t namesz, reqsz, padsz;
820 __be32 *bp;
821
David Howells30062bd2018-10-20 00:57:58 +0100822 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +0100823 return yfs_fs_link(fc, vnode, name, dvnode_scb, vnode_scb);
David Howells30062bd2018-10-20 00:57:58 +0100824
David Howells260a9802007-04-26 15:59:35 -0700825 _enter("");
826
827 namesz = strlen(name);
828 padsz = (4 - (namesz & 3)) & 3;
829 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
830
David Howellsf044c882017-11-02 15:27:45 +0000831 call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -0700832 if (!call)
833 return -ENOMEM;
834
David Howellsd2ddc772017-11-02 15:27:50 +0000835 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100836 call->out_dir_scb = dvnode_scb;
837 call->out_scb = vnode_scb;
David Howells260a9802007-04-26 15:59:35 -0700838
839 /* marshall the parameters */
840 bp = call->request;
841 *bp++ = htonl(FSLINK);
842 *bp++ = htonl(dvnode->fid.vid);
843 *bp++ = htonl(dvnode->fid.vnode);
844 *bp++ = htonl(dvnode->fid.unique);
845 *bp++ = htonl(namesz);
846 memcpy(bp, name, namesz);
847 bp = (void *) bp + namesz;
848 if (padsz > 0) {
849 memset(bp, 0, padsz);
850 bp = (void *) bp + padsz;
851 }
852 *bp++ = htonl(vnode->fid.vid);
853 *bp++ = htonl(vnode->fid.vnode);
854 *bp++ = htonl(vnode->fid.unique);
855
David Howellsd2ddc772017-11-02 15:27:50 +0000856 afs_use_fs_server(call, fc->cbi);
David Howells80548b02019-04-25 14:26:51 +0100857 trace_afs_make_fs_call1(call, &vnode->fid, name);
David Howells20b83912019-05-08 16:16:31 +0100858 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100859 afs_make_call(&fc->ac, call, GFP_NOFS);
860 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -0700861}
862
863/*
864 * deliver reply data to an FS.Symlink
865 */
David Howellsd0016482016-08-30 20:42:14 +0100866static int afs_deliver_fs_symlink(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700867{
David Howells260a9802007-04-26 15:59:35 -0700868 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100869 int ret;
David Howells260a9802007-04-26 15:59:35 -0700870
David Howellsd0016482016-08-30 20:42:14 +0100871 _enter("{%u}", call->unmarshall);
David Howells260a9802007-04-26 15:59:35 -0700872
David Howellsd0016482016-08-30 20:42:14 +0100873 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100874 if (ret < 0)
875 return ret;
David Howells260a9802007-04-26 15:59:35 -0700876
877 /* unmarshall the reply once we've received all of it */
878 bp = call->buffer;
David Howellsffba7182019-05-09 22:22:50 +0100879 xdr_decode_AFSFid(&bp, call->out_fid);
David Howellsa58823a2019-05-09 15:16:10 +0100880 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +0100881 if (ret < 0)
882 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100883 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Howells160cb952018-10-20 00:57:56 +0100884 if (ret < 0)
885 return ret;
David Howellsffba7182019-05-09 22:22:50 +0100886 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells260a9802007-04-26 15:59:35 -0700887
888 _leave(" = 0 [done]");
889 return 0;
890}
891
892/*
893 * FS.Symlink operation type
894 */
895static const struct afs_call_type afs_RXFSSymlink = {
896 .name = "FS.Symlink",
David Howells025db802017-11-02 15:27:51 +0000897 .op = afs_FS_Symlink,
David Howells260a9802007-04-26 15:59:35 -0700898 .deliver = afs_deliver_fs_symlink,
David Howells260a9802007-04-26 15:59:35 -0700899 .destructor = afs_flat_call_destructor,
900};
901
902/*
903 * create a symbolic link
904 */
David Howells8b2a4642017-11-02 15:27:50 +0000905int afs_fs_symlink(struct afs_fs_cursor *fc,
David Howells260a9802007-04-26 15:59:35 -0700906 const char *name,
907 const char *contents,
David Howellsa58823a2019-05-09 15:16:10 +0100908 struct afs_status_cb *dvnode_scb,
David Howells260a9802007-04-26 15:59:35 -0700909 struct afs_fid *newfid,
David Howellsa58823a2019-05-09 15:16:10 +0100910 struct afs_status_cb *new_scb)
David Howells260a9802007-04-26 15:59:35 -0700911{
David Howellsffba7182019-05-09 22:22:50 +0100912 struct afs_vnode *dvnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -0700913 struct afs_call *call;
David Howellsffba7182019-05-09 22:22:50 +0100914 struct afs_net *net = afs_v2net(dvnode);
David Howells260a9802007-04-26 15:59:35 -0700915 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
916 __be32 *bp;
917
David Howells30062bd2018-10-20 00:57:58 +0100918 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +0100919 return yfs_fs_symlink(fc, name, contents, dvnode_scb,
920 newfid, new_scb);
David Howells30062bd2018-10-20 00:57:58 +0100921
David Howells260a9802007-04-26 15:59:35 -0700922 _enter("");
923
924 namesz = strlen(name);
925 padsz = (4 - (namesz & 3)) & 3;
926
927 c_namesz = strlen(contents);
928 c_padsz = (4 - (c_namesz & 3)) & 3;
929
930 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
931
David Howellsf044c882017-11-02 15:27:45 +0000932 call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
David Howells260a9802007-04-26 15:59:35 -0700933 (3 + 21 + 21 + 6) * 4);
934 if (!call)
935 return -ENOMEM;
936
David Howellsd2ddc772017-11-02 15:27:50 +0000937 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +0100938 call->out_dir_scb = dvnode_scb;
David Howellsffba7182019-05-09 22:22:50 +0100939 call->out_fid = newfid;
David Howellsa58823a2019-05-09 15:16:10 +0100940 call->out_scb = new_scb;
David Howells260a9802007-04-26 15:59:35 -0700941
942 /* marshall the parameters */
943 bp = call->request;
944 *bp++ = htonl(FSSYMLINK);
David Howellsffba7182019-05-09 22:22:50 +0100945 *bp++ = htonl(dvnode->fid.vid);
946 *bp++ = htonl(dvnode->fid.vnode);
947 *bp++ = htonl(dvnode->fid.unique);
David Howells260a9802007-04-26 15:59:35 -0700948 *bp++ = htonl(namesz);
949 memcpy(bp, name, namesz);
950 bp = (void *) bp + namesz;
951 if (padsz > 0) {
952 memset(bp, 0, padsz);
953 bp = (void *) bp + padsz;
954 }
955 *bp++ = htonl(c_namesz);
956 memcpy(bp, contents, c_namesz);
957 bp = (void *) bp + c_namesz;
958 if (c_padsz > 0) {
959 memset(bp, 0, c_padsz);
960 bp = (void *) bp + c_padsz;
961 }
Marc Dionneab94f5d2017-03-16 16:27:47 +0000962 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
David Howellsffba7182019-05-09 22:22:50 +0100963 *bp++ = htonl(dvnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howells260a9802007-04-26 15:59:35 -0700964 *bp++ = 0; /* owner */
965 *bp++ = 0; /* group */
966 *bp++ = htonl(S_IRWXUGO); /* unix mode */
967 *bp++ = 0; /* segment size */
968
David Howellsd2ddc772017-11-02 15:27:50 +0000969 afs_use_fs_server(call, fc->cbi);
David Howellsffba7182019-05-09 22:22:50 +0100970 trace_afs_make_fs_call1(call, &dvnode->fid, name);
David Howells20b83912019-05-08 16:16:31 +0100971 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +0100972 afs_make_call(&fc->ac, call, GFP_NOFS);
973 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -0700974}
975
976/*
977 * deliver reply data to an FS.Rename
978 */
David Howellsd0016482016-08-30 20:42:14 +0100979static int afs_deliver_fs_rename(struct afs_call *call)
David Howells260a9802007-04-26 15:59:35 -0700980{
David Howells260a9802007-04-26 15:59:35 -0700981 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +0100982 int ret;
David Howells260a9802007-04-26 15:59:35 -0700983
David Howellsd0016482016-08-30 20:42:14 +0100984 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +0100985 if (ret < 0)
986 return ret;
David Howells260a9802007-04-26 15:59:35 -0700987
988 /* unmarshall the reply once we've received all of it */
989 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +0100990 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Howells160cb952018-10-20 00:57:56 +0100991 if (ret < 0)
992 return ret;
David Howellsa58823a2019-05-09 15:16:10 +0100993 if (call->out_dir_scb != call->out_scb) {
994 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +0100995 if (ret < 0)
996 return ret;
997 }
David Howellsffba7182019-05-09 22:22:50 +0100998 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells260a9802007-04-26 15:59:35 -0700999
1000 _leave(" = 0 [done]");
1001 return 0;
1002}
1003
1004/*
1005 * FS.Rename operation type
1006 */
1007static const struct afs_call_type afs_RXFSRename = {
1008 .name = "FS.Rename",
David Howells025db802017-11-02 15:27:51 +00001009 .op = afs_FS_Rename,
David Howells260a9802007-04-26 15:59:35 -07001010 .deliver = afs_deliver_fs_rename,
David Howells260a9802007-04-26 15:59:35 -07001011 .destructor = afs_flat_call_destructor,
1012};
1013
1014/*
David Howellsa58823a2019-05-09 15:16:10 +01001015 * Rename/move a file or directory.
David Howells260a9802007-04-26 15:59:35 -07001016 */
David Howells8b2a4642017-11-02 15:27:50 +00001017int afs_fs_rename(struct afs_fs_cursor *fc,
David Howells260a9802007-04-26 15:59:35 -07001018 const char *orig_name,
1019 struct afs_vnode *new_dvnode,
David Howells63a46812018-04-06 14:17:25 +01001020 const char *new_name,
David Howellsa58823a2019-05-09 15:16:10 +01001021 struct afs_status_cb *orig_dvnode_scb,
1022 struct afs_status_cb *new_dvnode_scb)
David Howells260a9802007-04-26 15:59:35 -07001023{
David Howellsd2ddc772017-11-02 15:27:50 +00001024 struct afs_vnode *orig_dvnode = fc->vnode;
David Howells260a9802007-04-26 15:59:35 -07001025 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001026 struct afs_net *net = afs_v2net(orig_dvnode);
David Howells260a9802007-04-26 15:59:35 -07001027 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1028 __be32 *bp;
1029
David Howells30062bd2018-10-20 00:57:58 +01001030 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1031 return yfs_fs_rename(fc, orig_name,
1032 new_dvnode, new_name,
David Howellsa58823a2019-05-09 15:16:10 +01001033 orig_dvnode_scb,
1034 new_dvnode_scb);
David Howells30062bd2018-10-20 00:57:58 +01001035
David Howells260a9802007-04-26 15:59:35 -07001036 _enter("");
1037
1038 o_namesz = strlen(orig_name);
1039 o_padsz = (4 - (o_namesz & 3)) & 3;
1040
1041 n_namesz = strlen(new_name);
1042 n_padsz = (4 - (n_namesz & 3)) & 3;
1043
1044 reqsz = (4 * 4) +
1045 4 + o_namesz + o_padsz +
1046 (3 * 4) +
1047 4 + n_namesz + n_padsz;
1048
David Howellsf044c882017-11-02 15:27:45 +00001049 call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
David Howells260a9802007-04-26 15:59:35 -07001050 if (!call)
1051 return -ENOMEM;
1052
David Howellsd2ddc772017-11-02 15:27:50 +00001053 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001054 call->out_dir_scb = orig_dvnode_scb;
1055 call->out_scb = new_dvnode_scb;
David Howells260a9802007-04-26 15:59:35 -07001056
1057 /* marshall the parameters */
1058 bp = call->request;
1059 *bp++ = htonl(FSRENAME);
1060 *bp++ = htonl(orig_dvnode->fid.vid);
1061 *bp++ = htonl(orig_dvnode->fid.vnode);
1062 *bp++ = htonl(orig_dvnode->fid.unique);
1063 *bp++ = htonl(o_namesz);
1064 memcpy(bp, orig_name, o_namesz);
1065 bp = (void *) bp + o_namesz;
1066 if (o_padsz > 0) {
1067 memset(bp, 0, o_padsz);
1068 bp = (void *) bp + o_padsz;
1069 }
1070
1071 *bp++ = htonl(new_dvnode->fid.vid);
1072 *bp++ = htonl(new_dvnode->fid.vnode);
1073 *bp++ = htonl(new_dvnode->fid.unique);
1074 *bp++ = htonl(n_namesz);
1075 memcpy(bp, new_name, n_namesz);
1076 bp = (void *) bp + n_namesz;
1077 if (n_padsz > 0) {
1078 memset(bp, 0, n_padsz);
1079 bp = (void *) bp + n_padsz;
1080 }
1081
David Howellsd2ddc772017-11-02 15:27:50 +00001082 afs_use_fs_server(call, fc->cbi);
David Howells80548b02019-04-25 14:26:51 +01001083 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
David Howells20b83912019-05-08 16:16:31 +01001084 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001085 afs_make_call(&fc->ac, call, GFP_NOFS);
1086 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells260a9802007-04-26 15:59:35 -07001087}
David Howells31143d52007-05-09 02:33:46 -07001088
1089/*
1090 * deliver reply data to an FS.StoreData
1091 */
David Howellsd0016482016-08-30 20:42:14 +01001092static int afs_deliver_fs_store_data(struct afs_call *call)
David Howells31143d52007-05-09 02:33:46 -07001093{
David Howells31143d52007-05-09 02:33:46 -07001094 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001095 int ret;
David Howells31143d52007-05-09 02:33:46 -07001096
David Howellsd0016482016-08-30 20:42:14 +01001097 _enter("");
David Howells31143d52007-05-09 02:33:46 -07001098
David Howellsd0016482016-08-30 20:42:14 +01001099 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001100 if (ret < 0)
1101 return ret;
David Howells31143d52007-05-09 02:33:46 -07001102
1103 /* unmarshall the reply once we've received all of it */
1104 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01001105 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +01001106 if (ret < 0)
1107 return ret;
David Howellsffba7182019-05-09 22:22:50 +01001108 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells31143d52007-05-09 02:33:46 -07001109
David Howells31143d52007-05-09 02:33:46 -07001110 _leave(" = 0 [done]");
1111 return 0;
1112}
1113
1114/*
1115 * FS.StoreData operation type
1116 */
1117static const struct afs_call_type afs_RXFSStoreData = {
1118 .name = "FS.StoreData",
David Howells025db802017-11-02 15:27:51 +00001119 .op = afs_FS_StoreData,
David Howells31143d52007-05-09 02:33:46 -07001120 .deliver = afs_deliver_fs_store_data,
David Howells31143d52007-05-09 02:33:46 -07001121 .destructor = afs_flat_call_destructor,
1122};
1123
David Howellsb9b1f8d2007-05-10 03:15:21 -07001124static const struct afs_call_type afs_RXFSStoreData64 = {
1125 .name = "FS.StoreData64",
David Howells025db802017-11-02 15:27:51 +00001126 .op = afs_FS_StoreData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001127 .deliver = afs_deliver_fs_store_data,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001128 .destructor = afs_flat_call_destructor,
1129};
1130
1131/*
1132 * store a set of pages to a very large file
1133 */
David Howells8b2a4642017-11-02 15:27:50 +00001134static int afs_fs_store_data64(struct afs_fs_cursor *fc,
David Howells4343d002017-11-02 15:27:52 +00001135 struct address_space *mapping,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001136 pgoff_t first, pgoff_t last,
1137 unsigned offset, unsigned to,
David Howellsa58823a2019-05-09 15:16:10 +01001138 loff_t size, loff_t pos, loff_t i_size,
1139 struct afs_status_cb *scb)
David Howellsb9b1f8d2007-05-10 03:15:21 -07001140{
David Howells4343d002017-11-02 15:27:52 +00001141 struct afs_vnode *vnode = fc->vnode;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001142 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001143 struct afs_net *net = afs_v2net(vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001144 __be32 *bp;
1145
David Howells3b6492d2018-10-20 00:57:57 +01001146 _enter(",%x,{%llx:%llu},,",
David Howells4343d002017-11-02 15:27:52 +00001147 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001148
David Howellsf044c882017-11-02 15:27:45 +00001149 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001150 (4 + 6 + 3 * 2) * 4,
1151 (21 + 6) * 4);
1152 if (!call)
1153 return -ENOMEM;
1154
David Howells4343d002017-11-02 15:27:52 +00001155 call->key = fc->key;
1156 call->mapping = mapping;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001157 call->first = first;
1158 call->last = last;
1159 call->first_offset = offset;
1160 call->last_to = to;
1161 call->send_pages = true;
David Howellsa58823a2019-05-09 15:16:10 +01001162 call->out_scb = scb;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001163
1164 /* marshall the parameters */
1165 bp = call->request;
1166 *bp++ = htonl(FSSTOREDATA64);
1167 *bp++ = htonl(vnode->fid.vid);
1168 *bp++ = htonl(vnode->fid.vnode);
1169 *bp++ = htonl(vnode->fid.unique);
1170
Marc Dionneab94f5d2017-03-16 16:27:47 +00001171 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1172 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howellsb9b1f8d2007-05-10 03:15:21 -07001173 *bp++ = 0; /* owner */
1174 *bp++ = 0; /* group */
1175 *bp++ = 0; /* unix mode */
1176 *bp++ = 0; /* segment size */
1177
1178 *bp++ = htonl(pos >> 32);
1179 *bp++ = htonl((u32) pos);
1180 *bp++ = htonl(size >> 32);
1181 *bp++ = htonl((u32) size);
1182 *bp++ = htonl(i_size >> 32);
1183 *bp++ = htonl((u32) i_size);
1184
David Howells025db802017-11-02 15:27:51 +00001185 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001186 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001187 afs_make_call(&fc->ac, call, GFP_NOFS);
1188 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001189}
1190
David Howells31143d52007-05-09 02:33:46 -07001191/*
1192 * store a set of pages
1193 */
David Howells4343d002017-11-02 15:27:52 +00001194int afs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
David Howells31143d52007-05-09 02:33:46 -07001195 pgoff_t first, pgoff_t last,
David Howellsa58823a2019-05-09 15:16:10 +01001196 unsigned offset, unsigned to,
1197 struct afs_status_cb *scb)
David Howells31143d52007-05-09 02:33:46 -07001198{
David Howells4343d002017-11-02 15:27:52 +00001199 struct afs_vnode *vnode = fc->vnode;
David Howells31143d52007-05-09 02:33:46 -07001200 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001201 struct afs_net *net = afs_v2net(vnode);
David Howells31143d52007-05-09 02:33:46 -07001202 loff_t size, pos, i_size;
1203 __be32 *bp;
1204
David Howells30062bd2018-10-20 00:57:58 +01001205 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001206 return yfs_fs_store_data(fc, mapping, first, last, offset, to, scb);
David Howells30062bd2018-10-20 00:57:58 +01001207
David Howells3b6492d2018-10-20 00:57:57 +01001208 _enter(",%x,{%llx:%llu},,",
David Howells4343d002017-11-02 15:27:52 +00001209 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howells31143d52007-05-09 02:33:46 -07001210
David Howells146a1192017-03-16 16:27:47 +00001211 size = (loff_t)to - (loff_t)offset;
David Howells31143d52007-05-09 02:33:46 -07001212 if (first != last)
1213 size += (loff_t)(last - first) << PAGE_SHIFT;
1214 pos = (loff_t)first << PAGE_SHIFT;
1215 pos += offset;
1216
1217 i_size = i_size_read(&vnode->vfs_inode);
1218 if (pos + size > i_size)
1219 i_size = size + pos;
1220
1221 _debug("size %llx, at %llx, i_size %llx",
1222 (unsigned long long) size, (unsigned long long) pos,
1223 (unsigned long long) i_size);
1224
David Howellsb9b1f8d2007-05-10 03:15:21 -07001225 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
David Howells4343d002017-11-02 15:27:52 +00001226 return afs_fs_store_data64(fc, mapping, first, last, offset, to,
David Howellsa58823a2019-05-09 15:16:10 +01001227 size, pos, i_size, scb);
David Howells31143d52007-05-09 02:33:46 -07001228
David Howellsf044c882017-11-02 15:27:45 +00001229 call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
David Howells31143d52007-05-09 02:33:46 -07001230 (4 + 6 + 3) * 4,
1231 (21 + 6) * 4);
1232 if (!call)
1233 return -ENOMEM;
1234
David Howells4343d002017-11-02 15:27:52 +00001235 call->key = fc->key;
1236 call->mapping = mapping;
David Howells31143d52007-05-09 02:33:46 -07001237 call->first = first;
1238 call->last = last;
1239 call->first_offset = offset;
1240 call->last_to = to;
1241 call->send_pages = true;
David Howellsa58823a2019-05-09 15:16:10 +01001242 call->out_scb = scb;
David Howells31143d52007-05-09 02:33:46 -07001243
1244 /* marshall the parameters */
1245 bp = call->request;
1246 *bp++ = htonl(FSSTOREDATA);
1247 *bp++ = htonl(vnode->fid.vid);
1248 *bp++ = htonl(vnode->fid.vnode);
1249 *bp++ = htonl(vnode->fid.unique);
1250
Marc Dionneab94f5d2017-03-16 16:27:47 +00001251 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1252 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
David Howells31143d52007-05-09 02:33:46 -07001253 *bp++ = 0; /* owner */
1254 *bp++ = 0; /* group */
1255 *bp++ = 0; /* unix mode */
1256 *bp++ = 0; /* segment size */
1257
1258 *bp++ = htonl(pos);
1259 *bp++ = htonl(size);
1260 *bp++ = htonl(i_size);
1261
David Howellsd2ddc772017-11-02 15:27:50 +00001262 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001263 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001264 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001265 afs_make_call(&fc->ac, call, GFP_NOFS);
1266 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells31143d52007-05-09 02:33:46 -07001267}
1268
1269/*
1270 * deliver reply data to an FS.StoreStatus
1271 */
David Howellsd0016482016-08-30 20:42:14 +01001272static int afs_deliver_fs_store_status(struct afs_call *call)
David Howells31143d52007-05-09 02:33:46 -07001273{
David Howells31143d52007-05-09 02:33:46 -07001274 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001275 int ret;
David Howells31143d52007-05-09 02:33:46 -07001276
David Howellsd0016482016-08-30 20:42:14 +01001277 _enter("");
David Howells31143d52007-05-09 02:33:46 -07001278
David Howellsd0016482016-08-30 20:42:14 +01001279 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001280 if (ret < 0)
1281 return ret;
David Howells31143d52007-05-09 02:33:46 -07001282
1283 /* unmarshall the reply once we've received all of it */
David Howells31143d52007-05-09 02:33:46 -07001284 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01001285 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +01001286 if (ret < 0)
1287 return ret;
David Howellsffba7182019-05-09 22:22:50 +01001288 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells31143d52007-05-09 02:33:46 -07001289
1290 _leave(" = 0 [done]");
1291 return 0;
1292}
1293
1294/*
1295 * FS.StoreStatus operation type
1296 */
1297static const struct afs_call_type afs_RXFSStoreStatus = {
1298 .name = "FS.StoreStatus",
David Howells025db802017-11-02 15:27:51 +00001299 .op = afs_FS_StoreStatus,
David Howells31143d52007-05-09 02:33:46 -07001300 .deliver = afs_deliver_fs_store_status,
David Howells31143d52007-05-09 02:33:46 -07001301 .destructor = afs_flat_call_destructor,
1302};
1303
1304static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1305 .name = "FS.StoreData",
David Howells025db802017-11-02 15:27:51 +00001306 .op = afs_FS_StoreData,
David Howells31143d52007-05-09 02:33:46 -07001307 .deliver = afs_deliver_fs_store_status,
David Howells31143d52007-05-09 02:33:46 -07001308 .destructor = afs_flat_call_destructor,
1309};
1310
David Howellsb9b1f8d2007-05-10 03:15:21 -07001311static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1312 .name = "FS.StoreData64",
David Howells025db802017-11-02 15:27:51 +00001313 .op = afs_FS_StoreData64,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001314 .deliver = afs_deliver_fs_store_status,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001315 .destructor = afs_flat_call_destructor,
1316};
1317
1318/*
1319 * set the attributes on a very large file, using FS.StoreData rather than
1320 * FS.StoreStatus so as to alter the file size also
1321 */
David Howellsa58823a2019-05-09 15:16:10 +01001322static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr,
1323 struct afs_status_cb *scb)
David Howellsb9b1f8d2007-05-10 03:15:21 -07001324{
David Howellsd2ddc772017-11-02 15:27:50 +00001325 struct afs_vnode *vnode = fc->vnode;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001326 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001327 struct afs_net *net = afs_v2net(vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001328 __be32 *bp;
1329
David Howells3b6492d2018-10-20 00:57:57 +01001330 _enter(",%x,{%llx:%llu},,",
David Howellsd2ddc772017-11-02 15:27:50 +00001331 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001332
1333 ASSERT(attr->ia_valid & ATTR_SIZE);
1334
David Howellsf044c882017-11-02 15:27:45 +00001335 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
David Howellsb9b1f8d2007-05-10 03:15:21 -07001336 (4 + 6 + 3 * 2) * 4,
1337 (21 + 6) * 4);
1338 if (!call)
1339 return -ENOMEM;
1340
David Howellsd2ddc772017-11-02 15:27:50 +00001341 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001342 call->out_scb = scb;
David Howellsb9b1f8d2007-05-10 03:15:21 -07001343
1344 /* marshall the parameters */
1345 bp = call->request;
1346 *bp++ = htonl(FSSTOREDATA64);
1347 *bp++ = htonl(vnode->fid.vid);
1348 *bp++ = htonl(vnode->fid.vnode);
1349 *bp++ = htonl(vnode->fid.unique);
1350
1351 xdr_encode_AFS_StoreStatus(&bp, attr);
1352
David Howells8c7ae382019-03-27 22:48:02 +00001353 *bp++ = htonl(attr->ia_size >> 32); /* position of start of write */
1354 *bp++ = htonl((u32) attr->ia_size);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001355 *bp++ = 0; /* size of write */
1356 *bp++ = 0;
1357 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1358 *bp++ = htonl((u32) attr->ia_size);
1359
David Howellsd2ddc772017-11-02 15:27:50 +00001360 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001361 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001362 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001363 afs_make_call(&fc->ac, call, GFP_NOFS);
1364 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001365}
1366
David Howells31143d52007-05-09 02:33:46 -07001367/*
1368 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1369 * so as to alter the file size also
1370 */
David Howellsa58823a2019-05-09 15:16:10 +01001371static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr,
1372 struct afs_status_cb *scb)
David Howells31143d52007-05-09 02:33:46 -07001373{
David Howellsd2ddc772017-11-02 15:27:50 +00001374 struct afs_vnode *vnode = fc->vnode;
David Howells31143d52007-05-09 02:33:46 -07001375 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001376 struct afs_net *net = afs_v2net(vnode);
David Howells31143d52007-05-09 02:33:46 -07001377 __be32 *bp;
1378
David Howells3b6492d2018-10-20 00:57:57 +01001379 _enter(",%x,{%llx:%llu},,",
David Howellsd2ddc772017-11-02 15:27:50 +00001380 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howells31143d52007-05-09 02:33:46 -07001381
1382 ASSERT(attr->ia_valid & ATTR_SIZE);
David Howellsb9b1f8d2007-05-10 03:15:21 -07001383 if (attr->ia_size >> 32)
David Howellsa58823a2019-05-09 15:16:10 +01001384 return afs_fs_setattr_size64(fc, attr, scb);
David Howells31143d52007-05-09 02:33:46 -07001385
David Howellsf044c882017-11-02 15:27:45 +00001386 call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
David Howells31143d52007-05-09 02:33:46 -07001387 (4 + 6 + 3) * 4,
1388 (21 + 6) * 4);
1389 if (!call)
1390 return -ENOMEM;
1391
David Howellsd2ddc772017-11-02 15:27:50 +00001392 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001393 call->out_scb = scb;
David Howells31143d52007-05-09 02:33:46 -07001394
1395 /* marshall the parameters */
1396 bp = call->request;
1397 *bp++ = htonl(FSSTOREDATA);
1398 *bp++ = htonl(vnode->fid.vid);
1399 *bp++ = htonl(vnode->fid.vnode);
1400 *bp++ = htonl(vnode->fid.unique);
1401
1402 xdr_encode_AFS_StoreStatus(&bp, attr);
1403
David Howells8c7ae382019-03-27 22:48:02 +00001404 *bp++ = htonl(attr->ia_size); /* position of start of write */
David Howells31143d52007-05-09 02:33:46 -07001405 *bp++ = 0; /* size of write */
1406 *bp++ = htonl(attr->ia_size); /* new file length */
1407
David Howellsd2ddc772017-11-02 15:27:50 +00001408 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001409 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001410 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001411 afs_make_call(&fc->ac, call, GFP_NOFS);
1412 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells31143d52007-05-09 02:33:46 -07001413}
1414
1415/*
1416 * set the attributes on a file, using FS.StoreData if there's a change in file
1417 * size, and FS.StoreStatus otherwise
1418 */
David Howellsa58823a2019-05-09 15:16:10 +01001419int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr,
1420 struct afs_status_cb *scb)
David Howells31143d52007-05-09 02:33:46 -07001421{
David Howellsd2ddc772017-11-02 15:27:50 +00001422 struct afs_vnode *vnode = fc->vnode;
David Howells31143d52007-05-09 02:33:46 -07001423 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001424 struct afs_net *net = afs_v2net(vnode);
David Howells31143d52007-05-09 02:33:46 -07001425 __be32 *bp;
1426
David Howells30062bd2018-10-20 00:57:58 +01001427 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001428 return yfs_fs_setattr(fc, attr, scb);
David Howells30062bd2018-10-20 00:57:58 +01001429
David Howells31143d52007-05-09 02:33:46 -07001430 if (attr->ia_valid & ATTR_SIZE)
David Howellsa58823a2019-05-09 15:16:10 +01001431 return afs_fs_setattr_size(fc, attr, scb);
David Howells31143d52007-05-09 02:33:46 -07001432
David Howells3b6492d2018-10-20 00:57:57 +01001433 _enter(",%x,{%llx:%llu},,",
David Howellsd2ddc772017-11-02 15:27:50 +00001434 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
David Howells31143d52007-05-09 02:33:46 -07001435
David Howellsf044c882017-11-02 15:27:45 +00001436 call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
David Howells31143d52007-05-09 02:33:46 -07001437 (4 + 6) * 4,
1438 (21 + 6) * 4);
1439 if (!call)
1440 return -ENOMEM;
1441
David Howellsd2ddc772017-11-02 15:27:50 +00001442 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001443 call->out_scb = scb;
David Howells31143d52007-05-09 02:33:46 -07001444
1445 /* marshall the parameters */
1446 bp = call->request;
1447 *bp++ = htonl(FSSTORESTATUS);
1448 *bp++ = htonl(vnode->fid.vid);
1449 *bp++ = htonl(vnode->fid.vnode);
1450 *bp++ = htonl(vnode->fid.unique);
1451
1452 xdr_encode_AFS_StoreStatus(&bp, attr);
1453
David Howellsd2ddc772017-11-02 15:27:50 +00001454 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001455 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001456 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001457 afs_make_call(&fc->ac, call, GFP_NOFS);
1458 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells31143d52007-05-09 02:33:46 -07001459}
David Howells45222b92007-05-10 22:22:20 -07001460
1461/*
1462 * deliver reply data to an FS.GetVolumeStatus
1463 */
David Howellsd0016482016-08-30 20:42:14 +01001464static int afs_deliver_fs_get_volume_status(struct afs_call *call)
David Howells45222b92007-05-10 22:22:20 -07001465{
1466 const __be32 *bp;
1467 char *p;
David Howells12bdcf32018-10-20 00:57:56 +01001468 u32 size;
David Howells45222b92007-05-10 22:22:20 -07001469 int ret;
1470
David Howellsd0016482016-08-30 20:42:14 +01001471 _enter("{%u}", call->unmarshall);
David Howells45222b92007-05-10 22:22:20 -07001472
1473 switch (call->unmarshall) {
1474 case 0:
David Howells45222b92007-05-10 22:22:20 -07001475 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +01001476 afs_extract_to_buf(call, 12 * 4);
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001477 /* Fall through */
David Howells45222b92007-05-10 22:22:20 -07001478
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001479 /* extract the returned status record */
David Howells45222b92007-05-10 22:22:20 -07001480 case 1:
1481 _debug("extract status");
David Howells12bdcf32018-10-20 00:57:56 +01001482 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001483 if (ret < 0)
1484 return ret;
David Howells45222b92007-05-10 22:22:20 -07001485
1486 bp = call->buffer;
David Howellsffba7182019-05-09 22:22:50 +01001487 xdr_decode_AFSFetchVolumeStatus(&bp, call->out_volstatus);
David Howells45222b92007-05-10 22:22:20 -07001488 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +01001489 afs_extract_to_tmp(call);
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001490 /* Fall through */
David Howells45222b92007-05-10 22:22:20 -07001491
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001492 /* extract the volume name length */
David Howells45222b92007-05-10 22:22:20 -07001493 case 2:
David Howells12bdcf32018-10-20 00:57:56 +01001494 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001495 if (ret < 0)
1496 return ret;
David Howells45222b92007-05-10 22:22:20 -07001497
1498 call->count = ntohl(call->tmp);
1499 _debug("volname length: %u", call->count);
1500 if (call->count >= AFSNAMEMAX)
David Howells160cb952018-10-20 00:57:56 +01001501 return afs_protocol_error(call, -EBADMSG,
1502 afs_eproto_volname_len);
David Howells12bdcf32018-10-20 00:57:56 +01001503 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001504 afs_extract_to_buf(call, size);
David Howells45222b92007-05-10 22:22:20 -07001505 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001506 /* Fall through */
David Howells45222b92007-05-10 22:22:20 -07001507
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001508 /* extract the volume name */
David Howells45222b92007-05-10 22:22:20 -07001509 case 3:
1510 _debug("extract volname");
David Howells12bdcf32018-10-20 00:57:56 +01001511 ret = afs_extract_data(call, true);
1512 if (ret < 0)
1513 return ret;
David Howells45222b92007-05-10 22:22:20 -07001514
David Howellsffba7182019-05-09 22:22:50 +01001515 p = call->buffer;
David Howells45222b92007-05-10 22:22:20 -07001516 p[call->count] = 0;
1517 _debug("volname '%s'", p);
David Howells12bdcf32018-10-20 00:57:56 +01001518 afs_extract_to_tmp(call);
David Howells45222b92007-05-10 22:22:20 -07001519 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001520 /* Fall through */
David Howells45222b92007-05-10 22:22:20 -07001521
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001522 /* extract the offline message length */
David Howells12bdcf32018-10-20 00:57:56 +01001523 case 4:
1524 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +01001525 if (ret < 0)
1526 return ret;
David Howells45222b92007-05-10 22:22:20 -07001527
1528 call->count = ntohl(call->tmp);
1529 _debug("offline msg length: %u", call->count);
1530 if (call->count >= AFSNAMEMAX)
David Howells160cb952018-10-20 00:57:56 +01001531 return afs_protocol_error(call, -EBADMSG,
1532 afs_eproto_offline_msg_len);
David Howells12bdcf32018-10-20 00:57:56 +01001533 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001534 afs_extract_to_buf(call, size);
David Howells45222b92007-05-10 22:22:20 -07001535 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001536 /* Fall through */
David Howells45222b92007-05-10 22:22:20 -07001537
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001538 /* extract the offline message */
David Howells12bdcf32018-10-20 00:57:56 +01001539 case 5:
David Howells45222b92007-05-10 22:22:20 -07001540 _debug("extract offline");
David Howells12bdcf32018-10-20 00:57:56 +01001541 ret = afs_extract_data(call, true);
1542 if (ret < 0)
1543 return ret;
David Howells45222b92007-05-10 22:22:20 -07001544
David Howellsffba7182019-05-09 22:22:50 +01001545 p = call->buffer;
David Howells45222b92007-05-10 22:22:20 -07001546 p[call->count] = 0;
1547 _debug("offline '%s'", p);
1548
David Howells12bdcf32018-10-20 00:57:56 +01001549 afs_extract_to_tmp(call);
David Howells45222b92007-05-10 22:22:20 -07001550 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001551 /* Fall through */
David Howells45222b92007-05-10 22:22:20 -07001552
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001553 /* extract the message of the day length */
David Howells12bdcf32018-10-20 00:57:56 +01001554 case 6:
1555 ret = afs_extract_data(call, 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)
David Howells160cb952018-10-20 00:57:56 +01001562 return afs_protocol_error(call, -EBADMSG,
1563 afs_eproto_motd_len);
David Howells12bdcf32018-10-20 00:57:56 +01001564 size = (call->count + 3) & ~3; /* It's padded */
David Howellsffba7182019-05-09 22:22:50 +01001565 afs_extract_to_buf(call, size);
David Howells45222b92007-05-10 22:22:20 -07001566 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001567 /* Fall through */
David Howells45222b92007-05-10 22:22:20 -07001568
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001569 /* extract the message of the day */
David Howells12bdcf32018-10-20 00:57:56 +01001570 case 7:
David Howells45222b92007-05-10 22:22:20 -07001571 _debug("extract motd");
David Howells12bdcf32018-10-20 00:57:56 +01001572 ret = afs_extract_data(call, false);
1573 if (ret < 0)
1574 return ret;
David Howells45222b92007-05-10 22:22:20 -07001575
David Howellsffba7182019-05-09 22:22:50 +01001576 p = call->buffer;
David Howells45222b92007-05-10 22:22:20 -07001577 p[call->count] = 0;
1578 _debug("motd '%s'", p);
1579
David Howells45222b92007-05-10 22:22:20 -07001580 call->unmarshall++;
1581
David Howells12bdcf32018-10-20 00:57:56 +01001582 case 8:
David Howells45222b92007-05-10 22:22:20 -07001583 break;
1584 }
1585
David Howells45222b92007-05-10 22:22:20 -07001586 _leave(" = 0 [done]");
1587 return 0;
1588}
1589
1590/*
David Howells45222b92007-05-10 22:22:20 -07001591 * FS.GetVolumeStatus operation type
1592 */
1593static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1594 .name = "FS.GetVolumeStatus",
David Howells025db802017-11-02 15:27:51 +00001595 .op = afs_FS_GetVolumeStatus,
David Howells45222b92007-05-10 22:22:20 -07001596 .deliver = afs_deliver_fs_get_volume_status,
David Howellsffba7182019-05-09 22:22:50 +01001597 .destructor = afs_flat_call_destructor,
David Howells45222b92007-05-10 22:22:20 -07001598};
1599
1600/*
1601 * fetch the status of a volume
1602 */
David Howells8b2a4642017-11-02 15:27:50 +00001603int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
David Howellsd2ddc772017-11-02 15:27:50 +00001604 struct afs_volume_status *vs)
David Howells45222b92007-05-10 22:22:20 -07001605{
David Howellsd2ddc772017-11-02 15:27:50 +00001606 struct afs_vnode *vnode = fc->vnode;
David Howells45222b92007-05-10 22:22:20 -07001607 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001608 struct afs_net *net = afs_v2net(vnode);
David Howells45222b92007-05-10 22:22:20 -07001609 __be32 *bp;
David Howells45222b92007-05-10 22:22:20 -07001610
David Howells30062bd2018-10-20 00:57:58 +01001611 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1612 return yfs_fs_get_volume_status(fc, vs);
1613
David Howells45222b92007-05-10 22:22:20 -07001614 _enter("");
1615
David Howellsffba7182019-05-09 22:22:50 +01001616 call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4,
1617 max(12 * 4, AFSOPAQUEMAX + 1));
1618 if (!call)
David Howells45222b92007-05-10 22:22:20 -07001619 return -ENOMEM;
1620
David Howellsd2ddc772017-11-02 15:27:50 +00001621 call->key = fc->key;
David Howellsffba7182019-05-09 22:22:50 +01001622 call->out_volstatus = vs;
David Howells45222b92007-05-10 22:22:20 -07001623
1624 /* marshall the parameters */
1625 bp = call->request;
1626 bp[0] = htonl(FSGETVOLUMESTATUS);
1627 bp[1] = htonl(vnode->fid.vid);
1628
David Howellsd2ddc772017-11-02 15:27:50 +00001629 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001630 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001631 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001632 afs_make_call(&fc->ac, call, GFP_NOFS);
1633 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells45222b92007-05-10 22:22:20 -07001634}
David Howellse8d6c552007-07-15 23:40:12 -07001635
1636/*
1637 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1638 */
David Howellsd0016482016-08-30 20:42:14 +01001639static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
David Howellse8d6c552007-07-15 23:40:12 -07001640{
1641 const __be32 *bp;
David Howells372ee162016-08-03 14:11:40 +01001642 int ret;
David Howellse8d6c552007-07-15 23:40:12 -07001643
David Howellsd0016482016-08-30 20:42:14 +01001644 _enter("{%u}", call->unmarshall);
David Howellse8d6c552007-07-15 23:40:12 -07001645
David Howellsd0016482016-08-30 20:42:14 +01001646 ret = afs_transfer_reply(call);
David Howells372ee162016-08-03 14:11:40 +01001647 if (ret < 0)
1648 return ret;
David Howellse8d6c552007-07-15 23:40:12 -07001649
1650 /* unmarshall the reply once we've received all of it */
1651 bp = call->buffer;
David Howellsffba7182019-05-09 22:22:50 +01001652 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howellse8d6c552007-07-15 23:40:12 -07001653
1654 _leave(" = 0 [done]");
1655 return 0;
1656}
1657
1658/*
1659 * FS.SetLock operation type
1660 */
1661static const struct afs_call_type afs_RXFSSetLock = {
1662 .name = "FS.SetLock",
David Howells025db802017-11-02 15:27:51 +00001663 .op = afs_FS_SetLock,
David Howellse8d6c552007-07-15 23:40:12 -07001664 .deliver = afs_deliver_fs_xxxx_lock,
David Howellsa690f602019-04-25 14:26:50 +01001665 .done = afs_lock_op_done,
David Howellse8d6c552007-07-15 23:40:12 -07001666 .destructor = afs_flat_call_destructor,
1667};
1668
1669/*
1670 * FS.ExtendLock operation type
1671 */
1672static const struct afs_call_type afs_RXFSExtendLock = {
1673 .name = "FS.ExtendLock",
David Howells025db802017-11-02 15:27:51 +00001674 .op = afs_FS_ExtendLock,
David Howellse8d6c552007-07-15 23:40:12 -07001675 .deliver = afs_deliver_fs_xxxx_lock,
David Howellsa690f602019-04-25 14:26:50 +01001676 .done = afs_lock_op_done,
David Howellse8d6c552007-07-15 23:40:12 -07001677 .destructor = afs_flat_call_destructor,
1678};
1679
1680/*
1681 * FS.ReleaseLock operation type
1682 */
1683static const struct afs_call_type afs_RXFSReleaseLock = {
1684 .name = "FS.ReleaseLock",
David Howells025db802017-11-02 15:27:51 +00001685 .op = afs_FS_ReleaseLock,
David Howellse8d6c552007-07-15 23:40:12 -07001686 .deliver = afs_deliver_fs_xxxx_lock,
David Howellse8d6c552007-07-15 23:40:12 -07001687 .destructor = afs_flat_call_destructor,
1688};
1689
1690/*
David Howellsd2ddc772017-11-02 15:27:50 +00001691 * Set a lock on a file
David Howellse8d6c552007-07-15 23:40:12 -07001692 */
David Howellsa58823a2019-05-09 15:16:10 +01001693int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type,
1694 struct afs_status_cb *scb)
David Howellse8d6c552007-07-15 23:40:12 -07001695{
David Howellsd2ddc772017-11-02 15:27:50 +00001696 struct afs_vnode *vnode = fc->vnode;
David Howellse8d6c552007-07-15 23:40:12 -07001697 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001698 struct afs_net *net = afs_v2net(vnode);
David Howellse8d6c552007-07-15 23:40:12 -07001699 __be32 *bp;
1700
David Howells30062bd2018-10-20 00:57:58 +01001701 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001702 return yfs_fs_set_lock(fc, type, scb);
David Howells30062bd2018-10-20 00:57:58 +01001703
David Howellse8d6c552007-07-15 23:40:12 -07001704 _enter("");
1705
David Howellsf044c882017-11-02 15:27:45 +00001706 call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001707 if (!call)
1708 return -ENOMEM;
1709
David Howellsd2ddc772017-11-02 15:27:50 +00001710 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001711 call->lvnode = vnode;
1712 call->out_scb = scb;
David Howellse8d6c552007-07-15 23:40:12 -07001713
1714 /* marshall the parameters */
1715 bp = call->request;
1716 *bp++ = htonl(FSSETLOCK);
1717 *bp++ = htonl(vnode->fid.vid);
1718 *bp++ = htonl(vnode->fid.vnode);
1719 *bp++ = htonl(vnode->fid.unique);
1720 *bp++ = htonl(type);
1721
David Howellsd2ddc772017-11-02 15:27:50 +00001722 afs_use_fs_server(call, fc->cbi);
David Howells6c6c1d62019-04-25 14:26:52 +01001723 trace_afs_make_fs_calli(call, &vnode->fid, type);
David Howells20b83912019-05-08 16:16:31 +01001724 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001725 afs_make_call(&fc->ac, call, GFP_NOFS);
1726 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellse8d6c552007-07-15 23:40:12 -07001727}
1728
1729/*
1730 * extend a lock on a file
1731 */
David Howellsa58823a2019-05-09 15:16:10 +01001732int afs_fs_extend_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
David Howellse8d6c552007-07-15 23:40:12 -07001733{
David Howellsd2ddc772017-11-02 15:27:50 +00001734 struct afs_vnode *vnode = fc->vnode;
David Howellse8d6c552007-07-15 23:40:12 -07001735 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001736 struct afs_net *net = afs_v2net(vnode);
David Howellse8d6c552007-07-15 23:40:12 -07001737 __be32 *bp;
1738
David Howells30062bd2018-10-20 00:57:58 +01001739 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001740 return yfs_fs_extend_lock(fc, scb);
David Howells30062bd2018-10-20 00:57:58 +01001741
David Howellse8d6c552007-07-15 23:40:12 -07001742 _enter("");
1743
David Howellsf044c882017-11-02 15:27:45 +00001744 call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001745 if (!call)
1746 return -ENOMEM;
1747
David Howellsd2ddc772017-11-02 15:27:50 +00001748 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001749 call->lvnode = vnode;
1750 call->out_scb = scb;
David Howellse8d6c552007-07-15 23:40:12 -07001751
1752 /* marshall the parameters */
1753 bp = call->request;
1754 *bp++ = htonl(FSEXTENDLOCK);
1755 *bp++ = htonl(vnode->fid.vid);
1756 *bp++ = htonl(vnode->fid.vnode);
1757 *bp++ = htonl(vnode->fid.unique);
1758
David Howellsd2ddc772017-11-02 15:27:50 +00001759 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001760 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001761 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001762 afs_make_call(&fc->ac, call, GFP_NOFS);
1763 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellse8d6c552007-07-15 23:40:12 -07001764}
1765
1766/*
1767 * release a lock on a file
1768 */
David Howellsa58823a2019-05-09 15:16:10 +01001769int afs_fs_release_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
David Howellse8d6c552007-07-15 23:40:12 -07001770{
David Howellsd2ddc772017-11-02 15:27:50 +00001771 struct afs_vnode *vnode = fc->vnode;
David Howellse8d6c552007-07-15 23:40:12 -07001772 struct afs_call *call;
David Howellsf044c882017-11-02 15:27:45 +00001773 struct afs_net *net = afs_v2net(vnode);
David Howellse8d6c552007-07-15 23:40:12 -07001774 __be32 *bp;
1775
David Howells30062bd2018-10-20 00:57:58 +01001776 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001777 return yfs_fs_release_lock(fc, scb);
David Howells30062bd2018-10-20 00:57:58 +01001778
David Howellse8d6c552007-07-15 23:40:12 -07001779 _enter("");
1780
David Howellsf044c882017-11-02 15:27:45 +00001781 call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
David Howellse8d6c552007-07-15 23:40:12 -07001782 if (!call)
1783 return -ENOMEM;
1784
David Howellsd2ddc772017-11-02 15:27:50 +00001785 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01001786 call->lvnode = vnode;
1787 call->out_scb = scb;
David Howellse8d6c552007-07-15 23:40:12 -07001788
1789 /* marshall the parameters */
1790 bp = call->request;
1791 *bp++ = htonl(FSRELEASELOCK);
1792 *bp++ = htonl(vnode->fid.vid);
1793 *bp++ = htonl(vnode->fid.vnode);
1794 *bp++ = htonl(vnode->fid.unique);
1795
David Howellsd2ddc772017-11-02 15:27:50 +00001796 afs_use_fs_server(call, fc->cbi);
David Howells025db802017-11-02 15:27:51 +00001797 trace_afs_make_fs_call(call, &vnode->fid);
David Howells20b83912019-05-08 16:16:31 +01001798 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01001799 afs_make_call(&fc->ac, call, GFP_NOFS);
1800 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howellsc435ee32017-11-02 15:27:49 +00001801}
1802
1803/*
1804 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1805 */
1806static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1807{
1808 return afs_transfer_reply(call);
1809}
1810
1811/*
1812 * FS.GiveUpAllCallBacks operation type
1813 */
1814static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1815 .name = "FS.GiveUpAllCallBacks",
David Howells025db802017-11-02 15:27:51 +00001816 .op = afs_FS_GiveUpAllCallBacks,
David Howellsc435ee32017-11-02 15:27:49 +00001817 .deliver = afs_deliver_fs_give_up_all_callbacks,
1818 .destructor = afs_flat_call_destructor,
1819};
1820
1821/*
1822 * Flush all the callbacks we have on a server.
1823 */
David Howellsd2ddc772017-11-02 15:27:50 +00001824int afs_fs_give_up_all_callbacks(struct afs_net *net,
1825 struct afs_server *server,
David Howells8b2a4642017-11-02 15:27:50 +00001826 struct afs_addr_cursor *ac,
David Howellsd2ddc772017-11-02 15:27:50 +00001827 struct key *key)
David Howellsc435ee32017-11-02 15:27:49 +00001828{
1829 struct afs_call *call;
1830 __be32 *bp;
1831
1832 _enter("");
1833
David Howellsd2ddc772017-11-02 15:27:50 +00001834 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
David Howellsc435ee32017-11-02 15:27:49 +00001835 if (!call)
1836 return -ENOMEM;
1837
1838 call->key = key;
1839
1840 /* marshall the parameters */
1841 bp = call->request;
1842 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1843
1844 /* Can't take a ref on server */
David Howells0b9bf382019-04-25 14:26:50 +01001845 afs_make_call(ac, call, GFP_NOFS);
1846 return afs_wait_for_call_to_complete(call, ac);
David Howellsd2ddc772017-11-02 15:27:50 +00001847}
1848
1849/*
1850 * Deliver reply data to an FS.GetCapabilities operation.
1851 */
1852static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1853{
1854 u32 count;
1855 int ret;
1856
David Howells12bdcf32018-10-20 00:57:56 +01001857 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(&call->iter));
David Howellsd2ddc772017-11-02 15:27:50 +00001858
David Howellsd2ddc772017-11-02 15:27:50 +00001859 switch (call->unmarshall) {
1860 case 0:
David Howells12bdcf32018-10-20 00:57:56 +01001861 afs_extract_to_tmp(call);
David Howellsd2ddc772017-11-02 15:27:50 +00001862 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001863 /* Fall through */
David Howellsd2ddc772017-11-02 15:27:50 +00001864
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001865 /* Extract the capabilities word count */
David Howellsd2ddc772017-11-02 15:27:50 +00001866 case 1:
David Howells12bdcf32018-10-20 00:57:56 +01001867 ret = afs_extract_data(call, true);
David Howellsd2ddc772017-11-02 15:27:50 +00001868 if (ret < 0)
1869 return ret;
1870
1871 count = ntohl(call->tmp);
1872
1873 call->count = count;
1874 call->count2 = count;
David Howells12bdcf32018-10-20 00:57:56 +01001875 iov_iter_discard(&call->iter, READ, count * sizeof(__be32));
David Howellsd2ddc772017-11-02 15:27:50 +00001876 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001877 /* Fall through */
David Howellsd2ddc772017-11-02 15:27:50 +00001878
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05001879 /* Extract capabilities words */
David Howellsd2ddc772017-11-02 15:27:50 +00001880 case 2:
David Howells12bdcf32018-10-20 00:57:56 +01001881 ret = afs_extract_data(call, false);
David Howellsd2ddc772017-11-02 15:27:50 +00001882 if (ret < 0)
1883 return ret;
1884
1885 /* TODO: Examine capabilities */
1886
David Howellsd2ddc772017-11-02 15:27:50 +00001887 call->unmarshall++;
1888 break;
1889 }
1890
1891 _leave(" = 0 [done]");
1892 return 0;
1893}
1894
1895/*
1896 * FS.GetCapabilities operation type
1897 */
1898static const struct afs_call_type afs_RXFSGetCapabilities = {
1899 .name = "FS.GetCapabilities",
David Howells025db802017-11-02 15:27:51 +00001900 .op = afs_FS_GetCapabilities,
David Howellsd2ddc772017-11-02 15:27:50 +00001901 .deliver = afs_deliver_fs_get_capabilities,
David Howells3bf0fb62018-10-20 00:57:59 +01001902 .done = afs_fileserver_probe_result,
David Howellsffba7182019-05-09 22:22:50 +01001903 .destructor = afs_flat_call_destructor,
David Howellsd2ddc772017-11-02 15:27:50 +00001904};
1905
1906/*
1907 * Probe a fileserver for the capabilities that it supports. This can
1908 * return up to 196 words.
1909 */
David Howells0b9bf382019-04-25 14:26:50 +01001910struct afs_call *afs_fs_get_capabilities(struct afs_net *net,
1911 struct afs_server *server,
1912 struct afs_addr_cursor *ac,
1913 struct key *key,
1914 unsigned int server_index)
David Howellsd2ddc772017-11-02 15:27:50 +00001915{
1916 struct afs_call *call;
1917 __be32 *bp;
1918
1919 _enter("");
1920
1921 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1922 if (!call)
David Howells0b9bf382019-04-25 14:26:50 +01001923 return ERR_PTR(-ENOMEM);
David Howellsd2ddc772017-11-02 15:27:50 +00001924
1925 call->key = key;
David Howells45218192019-06-20 18:12:17 +01001926 call->server = afs_get_server(server, afs_server_trace_get_caps);
David Howellsffba7182019-05-09 22:22:50 +01001927 call->server_index = server_index;
David Howells30062bd2018-10-20 00:57:58 +01001928 call->upgrade = true;
David Howells0b9bf382019-04-25 14:26:50 +01001929 call->async = true;
David Howells94f699c2019-05-16 13:21:59 +01001930 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
David Howellsd2ddc772017-11-02 15:27:50 +00001931
1932 /* marshall the parameters */
1933 bp = call->request;
1934 *bp++ = htonl(FSGETCAPABILITIES);
1935
1936 /* Can't take a ref on server */
David Howells025db802017-11-02 15:27:51 +00001937 trace_afs_make_fs_call(call, NULL);
David Howells0b9bf382019-04-25 14:26:50 +01001938 afs_make_call(ac, call, GFP_NOFS);
1939 return call;
David Howellse8d6c552007-07-15 23:40:12 -07001940}
David Howells5cf9dd52018-04-09 21:12:31 +01001941
1942/*
1943 * Deliver reply data to an FS.FetchStatus with no vnode.
1944 */
1945static int afs_deliver_fs_fetch_status(struct afs_call *call)
1946{
David Howells5cf9dd52018-04-09 21:12:31 +01001947 const __be32 *bp;
1948 int ret;
1949
1950 ret = afs_transfer_reply(call);
1951 if (ret < 0)
1952 return ret;
1953
David Howells5cf9dd52018-04-09 21:12:31 +01001954 /* unmarshall the reply once we've received all of it */
1955 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01001956 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells160cb952018-10-20 00:57:56 +01001957 if (ret < 0)
1958 return ret;
David Howellsa58823a2019-05-09 15:16:10 +01001959 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
1960 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells5cf9dd52018-04-09 21:12:31 +01001961
1962 _leave(" = 0 [done]");
1963 return 0;
1964}
1965
1966/*
1967 * FS.FetchStatus operation type
1968 */
1969static const struct afs_call_type afs_RXFSFetchStatus = {
1970 .name = "FS.FetchStatus",
1971 .op = afs_FS_FetchStatus,
1972 .deliver = afs_deliver_fs_fetch_status,
1973 .destructor = afs_flat_call_destructor,
1974};
1975
1976/*
1977 * Fetch the status information for a fid without needing a vnode handle.
1978 */
1979int afs_fs_fetch_status(struct afs_fs_cursor *fc,
1980 struct afs_net *net,
1981 struct afs_fid *fid,
David Howellsa58823a2019-05-09 15:16:10 +01001982 struct afs_status_cb *scb,
David Howells5cf9dd52018-04-09 21:12:31 +01001983 struct afs_volsync *volsync)
1984{
1985 struct afs_call *call;
1986 __be32 *bp;
1987
David Howells30062bd2018-10-20 00:57:58 +01001988 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howellsa58823a2019-05-09 15:16:10 +01001989 return yfs_fs_fetch_status(fc, net, fid, scb, volsync);
David Howells30062bd2018-10-20 00:57:58 +01001990
David Howells3b6492d2018-10-20 00:57:57 +01001991 _enter(",%x,{%llx:%llu},,",
David Howells5cf9dd52018-04-09 21:12:31 +01001992 key_serial(fc->key), fid->vid, fid->vnode);
1993
1994 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
1995 if (!call) {
1996 fc->ac.error = -ENOMEM;
1997 return -ENOMEM;
1998 }
1999
2000 call->key = fc->key;
David Howellsffba7182019-05-09 22:22:50 +01002001 call->out_fid = fid;
David Howellsa58823a2019-05-09 15:16:10 +01002002 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +01002003 call->out_volsync = volsync;
David Howells5cf9dd52018-04-09 21:12:31 +01002004
2005 /* marshall the parameters */
2006 bp = call->request;
2007 bp[0] = htonl(FSFETCHSTATUS);
2008 bp[1] = htonl(fid->vid);
2009 bp[2] = htonl(fid->vnode);
2010 bp[3] = htonl(fid->unique);
2011
David Howells5cf9dd52018-04-09 21:12:31 +01002012 afs_use_fs_server(call, fc->cbi);
2013 trace_afs_make_fs_call(call, fid);
David Howells20b83912019-05-08 16:16:31 +01002014 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01002015 afs_make_call(&fc->ac, call, GFP_NOFS);
2016 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells5cf9dd52018-04-09 21:12:31 +01002017}
2018
2019/*
2020 * Deliver reply data to an FS.InlineBulkStatus call
2021 */
2022static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
2023{
David Howells87182752019-05-09 16:17:05 +01002024 struct afs_status_cb *scb;
David Howells5cf9dd52018-04-09 21:12:31 +01002025 const __be32 *bp;
2026 u32 tmp;
2027 int ret;
2028
2029 _enter("{%u}", call->unmarshall);
2030
2031 switch (call->unmarshall) {
2032 case 0:
David Howells12bdcf32018-10-20 00:57:56 +01002033 afs_extract_to_tmp(call);
David Howells5cf9dd52018-04-09 21:12:31 +01002034 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002035 /* Fall through */
David Howells5cf9dd52018-04-09 21:12:31 +01002036
2037 /* Extract the file status count and array in two steps */
2038 case 1:
2039 _debug("extract status count");
David Howells12bdcf32018-10-20 00:57:56 +01002040 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002041 if (ret < 0)
2042 return ret;
2043
2044 tmp = ntohl(call->tmp);
2045 _debug("status count: %u/%u", tmp, call->count2);
2046 if (tmp != call->count2)
David Howells160cb952018-10-20 00:57:56 +01002047 return afs_protocol_error(call, -EBADMSG,
2048 afs_eproto_ibulkst_count);
David Howells5cf9dd52018-04-09 21:12:31 +01002049
2050 call->count = 0;
2051 call->unmarshall++;
2052 more_counts:
David Howells12bdcf32018-10-20 00:57:56 +01002053 afs_extract_to_buf(call, 21 * sizeof(__be32));
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06002054 /* Fall through */
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002055
David Howells5cf9dd52018-04-09 21:12:31 +01002056 case 2:
2057 _debug("extract status array %u", call->count);
David Howells12bdcf32018-10-20 00:57:56 +01002058 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002059 if (ret < 0)
2060 return ret;
2061
2062 bp = call->buffer;
David Howells87182752019-05-09 16:17:05 +01002063 scb = &call->out_scb[call->count];
David Howellsa58823a2019-05-09 15:16:10 +01002064 ret = xdr_decode_AFSFetchStatus(&bp, call, scb);
David Howells160cb952018-10-20 00:57:56 +01002065 if (ret < 0)
2066 return ret;
David Howells5cf9dd52018-04-09 21:12:31 +01002067
2068 call->count++;
2069 if (call->count < call->count2)
2070 goto more_counts;
2071
2072 call->count = 0;
2073 call->unmarshall++;
David Howells12bdcf32018-10-20 00:57:56 +01002074 afs_extract_to_tmp(call);
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002075 /* Fall through */
David Howells5cf9dd52018-04-09 21:12:31 +01002076
2077 /* Extract the callback count and array in two steps */
2078 case 3:
2079 _debug("extract CB count");
David Howells12bdcf32018-10-20 00:57:56 +01002080 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002081 if (ret < 0)
2082 return ret;
2083
2084 tmp = ntohl(call->tmp);
2085 _debug("CB count: %u", tmp);
2086 if (tmp != call->count2)
David Howells160cb952018-10-20 00:57:56 +01002087 return afs_protocol_error(call, -EBADMSG,
2088 afs_eproto_ibulkst_cb_count);
David Howells5cf9dd52018-04-09 21:12:31 +01002089 call->count = 0;
2090 call->unmarshall++;
2091 more_cbs:
David Howells12bdcf32018-10-20 00:57:56 +01002092 afs_extract_to_buf(call, 3 * sizeof(__be32));
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06002093 /* Fall through */
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002094
David Howells5cf9dd52018-04-09 21:12:31 +01002095 case 4:
2096 _debug("extract CB array");
David Howells12bdcf32018-10-20 00:57:56 +01002097 ret = afs_extract_data(call, true);
David Howells5cf9dd52018-04-09 21:12:31 +01002098 if (ret < 0)
2099 return ret;
2100
2101 _debug("unmarshall CB array");
2102 bp = call->buffer;
David Howells87182752019-05-09 16:17:05 +01002103 scb = &call->out_scb[call->count];
David Howellsa58823a2019-05-09 15:16:10 +01002104 xdr_decode_AFSCallBack(&bp, call, scb);
David Howells5cf9dd52018-04-09 21:12:31 +01002105 call->count++;
2106 if (call->count < call->count2)
2107 goto more_cbs;
2108
David Howells12bdcf32018-10-20 00:57:56 +01002109 afs_extract_to_buf(call, 6 * sizeof(__be32));
David Howells5cf9dd52018-04-09 21:12:31 +01002110 call->unmarshall++;
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -06002111 /* Fall through */
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002112
David Howells5cf9dd52018-04-09 21:12:31 +01002113 case 5:
David Howells12bdcf32018-10-20 00:57:56 +01002114 ret = afs_extract_data(call, false);
David Howells5cf9dd52018-04-09 21:12:31 +01002115 if (ret < 0)
2116 return ret;
2117
2118 bp = call->buffer;
David Howellsffba7182019-05-09 22:22:50 +01002119 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells5cf9dd52018-04-09 21:12:31 +01002120
David Howells5cf9dd52018-04-09 21:12:31 +01002121 call->unmarshall++;
2122
2123 case 6:
2124 break;
2125 }
2126
2127 _leave(" = 0 [done]");
2128 return 0;
2129}
2130
2131/*
2132 * FS.InlineBulkStatus operation type
2133 */
2134static const struct afs_call_type afs_RXFSInlineBulkStatus = {
2135 .name = "FS.InlineBulkStatus",
2136 .op = afs_FS_InlineBulkStatus,
2137 .deliver = afs_deliver_fs_inline_bulk_status,
2138 .destructor = afs_flat_call_destructor,
2139};
2140
2141/*
2142 * Fetch the status information for up to 50 files
2143 */
2144int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2145 struct afs_net *net,
2146 struct afs_fid *fids,
David Howells87182752019-05-09 16:17:05 +01002147 struct afs_status_cb *statuses,
David Howells5cf9dd52018-04-09 21:12:31 +01002148 unsigned int nr_fids,
2149 struct afs_volsync *volsync)
2150{
2151 struct afs_call *call;
2152 __be32 *bp;
2153 int i;
2154
David Howells30062bd2018-10-20 00:57:58 +01002155 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
David Howells87182752019-05-09 16:17:05 +01002156 return yfs_fs_inline_bulk_status(fc, net, fids, statuses,
David Howells30062bd2018-10-20 00:57:58 +01002157 nr_fids, volsync);
2158
David Howells3b6492d2018-10-20 00:57:57 +01002159 _enter(",%x,{%llx:%llu},%u",
David Howells5cf9dd52018-04-09 21:12:31 +01002160 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2161
2162 call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
2163 (2 + nr_fids * 3) * 4,
2164 21 * 4);
2165 if (!call) {
2166 fc->ac.error = -ENOMEM;
2167 return -ENOMEM;
2168 }
2169
2170 call->key = fc->key;
David Howells87182752019-05-09 16:17:05 +01002171 call->out_scb = statuses;
David Howellsffba7182019-05-09 22:22:50 +01002172 call->out_volsync = volsync;
David Howells5cf9dd52018-04-09 21:12:31 +01002173 call->count2 = nr_fids;
2174
2175 /* marshall the parameters */
2176 bp = call->request;
2177 *bp++ = htonl(FSINLINEBULKSTATUS);
2178 *bp++ = htonl(nr_fids);
2179 for (i = 0; i < nr_fids; i++) {
2180 *bp++ = htonl(fids[i].vid);
2181 *bp++ = htonl(fids[i].vnode);
2182 *bp++ = htonl(fids[i].unique);
2183 }
2184
David Howells5cf9dd52018-04-09 21:12:31 +01002185 afs_use_fs_server(call, fc->cbi);
2186 trace_afs_make_fs_call(call, &fids[0]);
David Howells20b83912019-05-08 16:16:31 +01002187 afs_set_fc_call(call, fc);
David Howells0b9bf382019-04-25 14:26:50 +01002188 afs_make_call(&fc->ac, call, GFP_NOFS);
2189 return afs_wait_for_call_to_complete(call, &fc->ac);
David Howells5cf9dd52018-04-09 21:12:31 +01002190}
David Howells260f0822019-04-25 14:26:52 +01002191
2192/*
2193 * deliver reply data to an FS.FetchACL
2194 */
2195static int afs_deliver_fs_fetch_acl(struct afs_call *call)
2196{
David Howells260f0822019-04-25 14:26:52 +01002197 struct afs_acl *acl;
2198 const __be32 *bp;
2199 unsigned int size;
2200 int ret;
2201
2202 _enter("{%u}", call->unmarshall);
2203
2204 switch (call->unmarshall) {
2205 case 0:
2206 afs_extract_to_tmp(call);
2207 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002208 /* Fall through */
David Howells260f0822019-04-25 14:26:52 +01002209
2210 /* extract the returned data length */
2211 case 1:
2212 ret = afs_extract_data(call, true);
2213 if (ret < 0)
2214 return ret;
2215
2216 size = call->count2 = ntohl(call->tmp);
2217 size = round_up(size, 4);
2218
2219 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2220 if (!acl)
2221 return -ENOMEM;
David Howellsffba7182019-05-09 22:22:50 +01002222 call->ret_acl = acl;
David Howells260f0822019-04-25 14:26:52 +01002223 acl->size = call->count2;
2224 afs_extract_begin(call, acl->data, size);
2225 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002226 /* Fall through */
David Howells260f0822019-04-25 14:26:52 +01002227
2228 /* extract the returned data */
2229 case 2:
2230 ret = afs_extract_data(call, true);
2231 if (ret < 0)
2232 return ret;
2233
2234 afs_extract_to_buf(call, (21 + 6) * 4);
2235 call->unmarshall++;
Gustavo A. R. Silva29881602019-05-19 18:43:53 -05002236 /* Fall through */
David Howells260f0822019-04-25 14:26:52 +01002237
2238 /* extract the metadata */
2239 case 3:
2240 ret = afs_extract_data(call, false);
2241 if (ret < 0)
2242 return ret;
2243
2244 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01002245 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howells260f0822019-04-25 14:26:52 +01002246 if (ret < 0)
2247 return ret;
David Howellsffba7182019-05-09 22:22:50 +01002248 xdr_decode_AFSVolSync(&bp, call->out_volsync);
David Howells260f0822019-04-25 14:26:52 +01002249
2250 call->unmarshall++;
2251
2252 case 4:
2253 break;
2254 }
2255
2256 _leave(" = 0 [done]");
2257 return 0;
2258}
2259
2260static void afs_destroy_fs_fetch_acl(struct afs_call *call)
2261{
David Howellsffba7182019-05-09 22:22:50 +01002262 kfree(call->ret_acl);
David Howells260f0822019-04-25 14:26:52 +01002263 afs_flat_call_destructor(call);
2264}
2265
2266/*
2267 * FS.FetchACL operation type
2268 */
2269static const struct afs_call_type afs_RXFSFetchACL = {
2270 .name = "FS.FetchACL",
2271 .op = afs_FS_FetchACL,
2272 .deliver = afs_deliver_fs_fetch_acl,
2273 .destructor = afs_destroy_fs_fetch_acl,
2274};
2275
2276/*
2277 * Fetch the ACL for a file.
2278 */
David Howellsa58823a2019-05-09 15:16:10 +01002279struct afs_acl *afs_fs_fetch_acl(struct afs_fs_cursor *fc,
2280 struct afs_status_cb *scb)
David Howells260f0822019-04-25 14:26:52 +01002281{
2282 struct afs_vnode *vnode = fc->vnode;
2283 struct afs_call *call;
2284 struct afs_net *net = afs_v2net(vnode);
2285 __be32 *bp;
2286
2287 _enter(",%x,{%llx:%llu},,",
2288 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2289
2290 call = afs_alloc_flat_call(net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2291 if (!call) {
2292 fc->ac.error = -ENOMEM;
2293 return ERR_PTR(-ENOMEM);
2294 }
2295
2296 call->key = fc->key;
David Howellsffba7182019-05-09 22:22:50 +01002297 call->ret_acl = NULL;
David Howellsa58823a2019-05-09 15:16:10 +01002298 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +01002299 call->out_volsync = NULL;
David Howells260f0822019-04-25 14:26:52 +01002300
2301 /* marshall the parameters */
2302 bp = call->request;
2303 bp[0] = htonl(FSFETCHACL);
2304 bp[1] = htonl(vnode->fid.vid);
2305 bp[2] = htonl(vnode->fid.vnode);
2306 bp[3] = htonl(vnode->fid.unique);
2307
David Howells260f0822019-04-25 14:26:52 +01002308 afs_use_fs_server(call, fc->cbi);
2309 trace_afs_make_fs_call(call, &vnode->fid);
2310 afs_make_call(&fc->ac, call, GFP_KERNEL);
2311 return (struct afs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2312}
Joe Gorseb10494a2019-04-25 14:26:52 +01002313
2314/*
David Howellsffba7182019-05-09 22:22:50 +01002315 * Deliver reply data to any operation that returns file status and volume
2316 * sync.
2317 */
2318static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
2319{
David Howellsffba7182019-05-09 22:22:50 +01002320 const __be32 *bp;
2321 int ret;
2322
David Howellsffba7182019-05-09 22:22:50 +01002323 ret = afs_transfer_reply(call);
2324 if (ret < 0)
2325 return ret;
2326
David Howellsffba7182019-05-09 22:22:50 +01002327 bp = call->buffer;
David Howellsa58823a2019-05-09 15:16:10 +01002328 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Howellsffba7182019-05-09 22:22:50 +01002329 if (ret < 0)
2330 return ret;
2331 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2332
2333 _leave(" = 0 [done]");
2334 return 0;
2335}
2336
2337/*
Joe Gorseb10494a2019-04-25 14:26:52 +01002338 * FS.StoreACL operation type
2339 */
2340static const struct afs_call_type afs_RXFSStoreACL = {
2341 .name = "FS.StoreACL",
2342 .op = afs_FS_StoreACL,
David Howellsffba7182019-05-09 22:22:50 +01002343 .deliver = afs_deliver_fs_file_status_and_vol,
Joe Gorseb10494a2019-04-25 14:26:52 +01002344 .destructor = afs_flat_call_destructor,
2345};
2346
2347/*
2348 * Fetch the ACL for a file.
2349 */
David Howellsa58823a2019-05-09 15:16:10 +01002350int afs_fs_store_acl(struct afs_fs_cursor *fc, const struct afs_acl *acl,
2351 struct afs_status_cb *scb)
Joe Gorseb10494a2019-04-25 14:26:52 +01002352{
2353 struct afs_vnode *vnode = fc->vnode;
2354 struct afs_call *call;
2355 struct afs_net *net = afs_v2net(vnode);
2356 size_t size;
2357 __be32 *bp;
2358
2359 _enter(",%x,{%llx:%llu},,",
2360 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2361
2362 size = round_up(acl->size, 4);
2363 call = afs_alloc_flat_call(net, &afs_RXFSStoreACL,
2364 5 * 4 + size, (21 + 6) * 4);
2365 if (!call) {
2366 fc->ac.error = -ENOMEM;
2367 return -ENOMEM;
2368 }
2369
2370 call->key = fc->key;
David Howellsa58823a2019-05-09 15:16:10 +01002371 call->out_scb = scb;
David Howellsffba7182019-05-09 22:22:50 +01002372 call->out_volsync = NULL;
Joe Gorseb10494a2019-04-25 14:26:52 +01002373
2374 /* marshall the parameters */
2375 bp = call->request;
2376 bp[0] = htonl(FSSTOREACL);
2377 bp[1] = htonl(vnode->fid.vid);
2378 bp[2] = htonl(vnode->fid.vnode);
2379 bp[3] = htonl(vnode->fid.unique);
2380 bp[4] = htonl(acl->size);
2381 memcpy(&bp[5], acl->data, acl->size);
2382 if (acl->size != size)
2383 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2384
2385 trace_afs_make_fs_call(call, &vnode->fid);
2386 afs_make_call(&fc->ac, call, GFP_KERNEL);
2387 return afs_wait_for_call_to_complete(call, &fc->ac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388}