blob: 5c2729fc07e52b69c7af8d137ac545a2df94c257 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001// SPDX-License-Identifier: GPL-2.0-or-later
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/* AFS File Server client stubs
3 *
4 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00006 */
7
8#include <linux/init.h>
9#include <linux/slab.h>
10#include <linux/sched.h>
11#include <linux/circ_buf.h>
12#include <linux/iversion.h>
13#include "internal.h"
14#include "afs_fs.h"
15#include "xdr_fs.h"
David Brazdil0f672f62019-12-10 10:32:29 +000016#include "protocol_yfs.h"
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000017
18static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi)
19{
20 call->cbi = afs_get_cb_interest(cbi);
21}
22
23/*
24 * decode an AFSFid block
25 */
26static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
27{
28 const __be32 *bp = *_bp;
29
30 fid->vid = ntohl(*bp++);
31 fid->vnode = ntohl(*bp++);
32 fid->unique = ntohl(*bp++);
33 *_bp = bp;
34}
35
36/*
37 * Dump a bad file status record.
38 */
39static void xdr_dump_bad(const __be32 *bp)
40{
41 __be32 x[4];
42 int i;
43
44 pr_notice("AFS XDR: Bad status record\n");
45 for (i = 0; i < 5 * 4 * 4; i += 16) {
46 memcpy(x, bp, 16);
47 bp += 4;
48 pr_notice("%03x: %08x %08x %08x %08x\n",
49 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
50 }
51
52 memcpy(x, bp, 4);
53 pr_notice("0x50: %08x\n", ntohl(x[0]));
54}
55
56/*
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000057 * decode an AFSFetchStatus block
58 */
Olivier Deprez0e641232021-09-23 10:07:05 +020059static void xdr_decode_AFSFetchStatus(const __be32 **_bp,
60 struct afs_call *call,
61 struct afs_status_cb *scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000062{
63 const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
David Brazdil0f672f62019-12-10 10:32:29 +000064 struct afs_file_status *status = &scb->status;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000065 bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
66 u64 data_version, size;
67 u32 type, abort_code;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000068
69 abort_code = ntohl(xdr->abort_code);
70
71 if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
72 if (xdr->if_version == htonl(0) &&
73 abort_code != 0 &&
74 inline_error) {
75 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
76 * whereby it doesn't set the interface version in the error
77 * case.
78 */
79 status->abort_code = abort_code;
David Brazdil0f672f62019-12-10 10:32:29 +000080 scb->have_error = true;
Olivier Deprez0e641232021-09-23 10:07:05 +020081 goto advance;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000082 }
83
84 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
85 goto bad;
86 }
87
88 if (abort_code != 0 && inline_error) {
89 status->abort_code = abort_code;
Olivier Deprez0e641232021-09-23 10:07:05 +020090 scb->have_error = true;
91 goto advance;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000092 }
93
94 type = ntohl(xdr->type);
95 switch (type) {
96 case AFS_FTYPE_FILE:
97 case AFS_FTYPE_DIR:
98 case AFS_FTYPE_SYMLINK:
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000099 status->type = type;
100 break;
101 default:
102 goto bad;
103 }
104
David Brazdil0f672f62019-12-10 10:32:29 +0000105 status->nlink = ntohl(xdr->nlink);
106 status->author = ntohl(xdr->author);
107 status->owner = ntohl(xdr->owner);
108 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
109 status->anon_access = ntohl(xdr->anon_access);
110 status->mode = ntohl(xdr->mode) & S_IALLUGO;
111 status->group = ntohl(xdr->group);
112 status->lock_count = ntohl(xdr->lock_count);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000113
David Brazdil0f672f62019-12-10 10:32:29 +0000114 status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
115 status->mtime_client.tv_nsec = 0;
116 status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
117 status->mtime_server.tv_nsec = 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000118
119 size = (u64)ntohl(xdr->size_lo);
120 size |= (u64)ntohl(xdr->size_hi) << 32;
121 status->size = size;
122
123 data_version = (u64)ntohl(xdr->data_version_lo);
124 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
David Brazdil0f672f62019-12-10 10:32:29 +0000125 status->data_version = data_version;
126 scb->have_status = true;
Olivier Deprez0e641232021-09-23 10:07:05 +0200127advance:
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000128 *_bp = (const void *)*_bp + sizeof(*xdr);
Olivier Deprez0e641232021-09-23 10:07:05 +0200129 return;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000130
131bad:
132 xdr_dump_bad(*_bp);
Olivier Deprez0e641232021-09-23 10:07:05 +0200133 afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
134 goto advance;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000135}
136
David Brazdil0f672f62019-12-10 10:32:29 +0000137static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000138{
David Brazdil0f672f62019-12-10 10:32:29 +0000139 return ktime_divns(call->reply_time, NSEC_PER_SEC) + expiry;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000140}
141
David Brazdil0f672f62019-12-10 10:32:29 +0000142static void xdr_decode_AFSCallBack(const __be32 **_bp,
143 struct afs_call *call,
144 struct afs_status_cb *scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000145{
David Brazdil0f672f62019-12-10 10:32:29 +0000146 struct afs_callback *cb = &scb->callback;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000147 const __be32 *bp = *_bp;
148
David Brazdil0f672f62019-12-10 10:32:29 +0000149 bp++; /* version */
150 cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
151 bp++; /* type */
152 scb->have_cb = true;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000153 *_bp = bp;
154}
155
156/*
157 * decode an AFSVolSync block
158 */
159static void xdr_decode_AFSVolSync(const __be32 **_bp,
160 struct afs_volsync *volsync)
161{
162 const __be32 *bp = *_bp;
David Brazdil0f672f62019-12-10 10:32:29 +0000163 u32 creation;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000164
David Brazdil0f672f62019-12-10 10:32:29 +0000165 creation = ntohl(*bp++);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000166 bp++; /* spare2 */
167 bp++; /* spare3 */
168 bp++; /* spare4 */
169 bp++; /* spare5 */
170 bp++; /* spare6 */
171 *_bp = bp;
David Brazdil0f672f62019-12-10 10:32:29 +0000172
173 if (volsync)
174 volsync->creation = creation;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000175}
176
177/*
178 * 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;
193 owner = from_kuid(&init_user_ns, attr->ia_uid);
194 }
195
196 if (attr->ia_valid & ATTR_GID) {
197 mask |= AFS_SET_GROUP;
198 group = from_kgid(&init_user_ns, attr->ia_gid);
199 }
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/*
216 * 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 Brazdil0f672f62019-12-10 10:32:29 +0000235 vs->vol_copy_date = 0;
236 vs->vol_backup_date = 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000237 *_bp = bp;
238}
239
240/*
241 * deliver reply data to an FS.FetchStatus
242 */
243static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
244{
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000245 const __be32 *bp;
246 int ret;
247
248 ret = afs_transfer_reply(call);
249 if (ret < 0)
250 return ret;
251
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000252 /* unmarshall the reply once we've received all of it */
253 bp = call->buffer;
Olivier Deprez0e641232021-09-23 10:07:05 +0200254 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Brazdil0f672f62019-12-10 10:32:29 +0000255 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
256 xdr_decode_AFSVolSync(&bp, call->out_volsync);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000257
258 _leave(" = 0 [done]");
259 return 0;
260}
261
262/*
263 * FS.FetchStatus operation type
264 */
265static const struct afs_call_type afs_RXFSFetchStatus_vnode = {
266 .name = "FS.FetchStatus(vnode)",
267 .op = afs_FS_FetchStatus,
268 .deliver = afs_deliver_fs_fetch_status_vnode,
269 .destructor = afs_flat_call_destructor,
270};
271
272/*
273 * fetch the status information for a file
274 */
David Brazdil0f672f62019-12-10 10:32:29 +0000275int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_status_cb *scb,
276 struct afs_volsync *volsync)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000277{
278 struct afs_vnode *vnode = fc->vnode;
279 struct afs_call *call;
280 struct afs_net *net = afs_v2net(vnode);
281 __be32 *bp;
282
David Brazdil0f672f62019-12-10 10:32:29 +0000283 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
284 return yfs_fs_fetch_file_status(fc, scb, volsync);
285
286 _enter(",%x,{%llx:%llu},,",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000287 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
288
289 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus_vnode,
290 16, (21 + 3 + 6) * 4);
291 if (!call) {
292 fc->ac.error = -ENOMEM;
293 return -ENOMEM;
294 }
295
296 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +0000297 call->out_scb = scb;
298 call->out_volsync = volsync;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000299
300 /* marshall the parameters */
301 bp = call->request;
302 bp[0] = htonl(FSFETCHSTATUS);
303 bp[1] = htonl(vnode->fid.vid);
304 bp[2] = htonl(vnode->fid.vnode);
305 bp[3] = htonl(vnode->fid.unique);
306
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000307 afs_use_fs_server(call, fc->cbi);
308 trace_afs_make_fs_call(call, &vnode->fid);
David Brazdil0f672f62019-12-10 10:32:29 +0000309
310 afs_set_fc_call(call, fc);
311 afs_make_call(&fc->ac, call, GFP_NOFS);
312 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000313}
314
315/*
316 * deliver reply data to an FS.FetchData
317 */
318static int afs_deliver_fs_fetch_data(struct afs_call *call)
319{
David Brazdil0f672f62019-12-10 10:32:29 +0000320 struct afs_read *req = call->read_request;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000321 const __be32 *bp;
322 unsigned int size;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000323 int ret;
324
David Brazdil0f672f62019-12-10 10:32:29 +0000325 _enter("{%u,%zu/%llu}",
326 call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000327
328 switch (call->unmarshall) {
329 case 0:
330 req->actual_len = 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000331 req->index = 0;
David Brazdil0f672f62019-12-10 10:32:29 +0000332 req->offset = req->pos & (PAGE_SIZE - 1);
333 call->unmarshall++;
334 if (call->operation_ID == FSFETCHDATA64) {
335 afs_extract_to_tmp64(call);
336 } else {
337 call->tmp_u = htonl(0);
338 afs_extract_to_tmp(call);
339 }
340 /* Fall through */
341
342 /* extract the returned data length */
343 case 1:
344 _debug("extract data length");
345 ret = afs_extract_data(call, true);
346 if (ret < 0)
347 return ret;
348
349 req->actual_len = be64_to_cpu(call->tmp64);
350 _debug("DATA length: %llu", req->actual_len);
351 req->remain = min(req->len, req->actual_len);
352 if (req->remain == 0)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000353 goto no_more_data;
David Brazdil0f672f62019-12-10 10:32:29 +0000354
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000355 call->unmarshall++;
356
357 begin_page:
358 ASSERTCMP(req->index, <, req->nr_pages);
David Brazdil0f672f62019-12-10 10:32:29 +0000359 if (req->remain > PAGE_SIZE - req->offset)
360 size = PAGE_SIZE - req->offset;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000361 else
362 size = req->remain;
David Brazdil0f672f62019-12-10 10:32:29 +0000363 call->bvec[0].bv_len = size;
364 call->bvec[0].bv_offset = req->offset;
365 call->bvec[0].bv_page = req->pages[req->index];
366 iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
367 ASSERTCMP(size, <=, PAGE_SIZE);
368 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000369
370 /* extract the returned data */
David Brazdil0f672f62019-12-10 10:32:29 +0000371 case 2:
372 _debug("extract data %zu/%llu",
373 iov_iter_count(&call->iter), req->remain);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000374
David Brazdil0f672f62019-12-10 10:32:29 +0000375 ret = afs_extract_data(call, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000376 if (ret < 0)
377 return ret;
David Brazdil0f672f62019-12-10 10:32:29 +0000378 req->remain -= call->bvec[0].bv_len;
379 req->offset += call->bvec[0].bv_len;
380 ASSERTCMP(req->offset, <=, PAGE_SIZE);
381 if (req->offset == PAGE_SIZE) {
382 req->offset = 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000383 req->index++;
David Brazdil0f672f62019-12-10 10:32:29 +0000384 if (req->remain > 0)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000385 goto begin_page;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000386 }
David Brazdil0f672f62019-12-10 10:32:29 +0000387
388 ASSERTCMP(req->remain, ==, 0);
389 if (req->actual_len <= req->len)
390 goto no_more_data;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000391
392 /* Discard any excess data the server gave us */
David Brazdil0f672f62019-12-10 10:32:29 +0000393 afs_extract_discard(call, req->actual_len - req->len);
394 call->unmarshall = 3;
395 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000396
David Brazdil0f672f62019-12-10 10:32:29 +0000397 case 3:
398 _debug("extract discard %zu/%llu",
399 iov_iter_count(&call->iter), req->actual_len - req->len);
400
401 ret = afs_extract_data(call, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000402 if (ret < 0)
403 return ret;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000404
405 no_more_data:
David Brazdil0f672f62019-12-10 10:32:29 +0000406 call->unmarshall = 4;
407 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
408 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000409
410 /* extract the metadata */
David Brazdil0f672f62019-12-10 10:32:29 +0000411 case 4:
412 ret = afs_extract_data(call, false);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000413 if (ret < 0)
414 return ret;
415
416 bp = call->buffer;
Olivier Deprez0e641232021-09-23 10:07:05 +0200417 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Brazdil0f672f62019-12-10 10:32:29 +0000418 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
419 xdr_decode_AFSVolSync(&bp, call->out_volsync);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000420
David Brazdil0f672f62019-12-10 10:32:29 +0000421 req->data_version = call->out_scb->status.data_version;
422 req->file_size = call->out_scb->status.size;
423
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000424 call->unmarshall++;
425
David Brazdil0f672f62019-12-10 10:32:29 +0000426 case 5:
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000427 break;
428 }
429
430 for (; req->index < req->nr_pages; req->index++) {
David Brazdil0f672f62019-12-10 10:32:29 +0000431 if (req->offset < PAGE_SIZE)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000432 zero_user_segment(req->pages[req->index],
David Brazdil0f672f62019-12-10 10:32:29 +0000433 req->offset, PAGE_SIZE);
David Brazdil0f672f62019-12-10 10:32:29 +0000434 req->offset = 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000435 }
436
Olivier Deprez0e641232021-09-23 10:07:05 +0200437 if (req->page_done)
438 for (req->index = 0; req->index < req->nr_pages; req->index++)
439 req->page_done(req);
440
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000441 _leave(" = 0 [done]");
442 return 0;
443}
444
445static void afs_fetch_data_destructor(struct afs_call *call)
446{
David Brazdil0f672f62019-12-10 10:32:29 +0000447 struct afs_read *req = call->read_request;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000448
449 afs_put_read(req);
450 afs_flat_call_destructor(call);
451}
452
453/*
454 * FS.FetchData operation type
455 */
456static const struct afs_call_type afs_RXFSFetchData = {
457 .name = "FS.FetchData",
458 .op = afs_FS_FetchData,
459 .deliver = afs_deliver_fs_fetch_data,
460 .destructor = afs_fetch_data_destructor,
461};
462
463static const struct afs_call_type afs_RXFSFetchData64 = {
464 .name = "FS.FetchData64",
465 .op = afs_FS_FetchData64,
466 .deliver = afs_deliver_fs_fetch_data,
467 .destructor = afs_fetch_data_destructor,
468};
469
470/*
471 * fetch data from a very large file
472 */
David Brazdil0f672f62019-12-10 10:32:29 +0000473static int afs_fs_fetch_data64(struct afs_fs_cursor *fc,
474 struct afs_status_cb *scb,
475 struct afs_read *req)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000476{
477 struct afs_vnode *vnode = fc->vnode;
478 struct afs_call *call;
479 struct afs_net *net = afs_v2net(vnode);
480 __be32 *bp;
481
482 _enter("");
483
484 call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
485 if (!call)
486 return -ENOMEM;
487
488 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +0000489 call->out_scb = scb;
490 call->out_volsync = NULL;
491 call->read_request = req;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000492
493 /* marshall the parameters */
494 bp = call->request;
495 bp[0] = htonl(FSFETCHDATA64);
496 bp[1] = htonl(vnode->fid.vid);
497 bp[2] = htonl(vnode->fid.vnode);
498 bp[3] = htonl(vnode->fid.unique);
499 bp[4] = htonl(upper_32_bits(req->pos));
500 bp[5] = htonl(lower_32_bits(req->pos));
501 bp[6] = 0;
502 bp[7] = htonl(lower_32_bits(req->len));
503
504 refcount_inc(&req->usage);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000505 afs_use_fs_server(call, fc->cbi);
506 trace_afs_make_fs_call(call, &vnode->fid);
David Brazdil0f672f62019-12-10 10:32:29 +0000507 afs_set_fc_call(call, fc);
508 afs_make_call(&fc->ac, call, GFP_NOFS);
509 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000510}
511
512/*
513 * fetch data from a file
514 */
David Brazdil0f672f62019-12-10 10:32:29 +0000515int afs_fs_fetch_data(struct afs_fs_cursor *fc,
516 struct afs_status_cb *scb,
517 struct afs_read *req)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000518{
519 struct afs_vnode *vnode = fc->vnode;
520 struct afs_call *call;
521 struct afs_net *net = afs_v2net(vnode);
522 __be32 *bp;
523
David Brazdil0f672f62019-12-10 10:32:29 +0000524 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
525 return yfs_fs_fetch_data(fc, scb, req);
526
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000527 if (upper_32_bits(req->pos) ||
528 upper_32_bits(req->len) ||
529 upper_32_bits(req->pos + req->len))
David Brazdil0f672f62019-12-10 10:32:29 +0000530 return afs_fs_fetch_data64(fc, scb, req);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000531
532 _enter("");
533
534 call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
535 if (!call)
536 return -ENOMEM;
537
538 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +0000539 call->out_scb = scb;
540 call->out_volsync = NULL;
541 call->read_request = req;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000542
543 /* marshall the parameters */
544 bp = call->request;
545 bp[0] = htonl(FSFETCHDATA);
546 bp[1] = htonl(vnode->fid.vid);
547 bp[2] = htonl(vnode->fid.vnode);
548 bp[3] = htonl(vnode->fid.unique);
549 bp[4] = htonl(lower_32_bits(req->pos));
550 bp[5] = htonl(lower_32_bits(req->len));
551
552 refcount_inc(&req->usage);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000553 afs_use_fs_server(call, fc->cbi);
554 trace_afs_make_fs_call(call, &vnode->fid);
David Brazdil0f672f62019-12-10 10:32:29 +0000555 afs_set_fc_call(call, fc);
556 afs_make_call(&fc->ac, call, GFP_NOFS);
557 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000558}
559
560/*
561 * deliver reply data to an FS.CreateFile or an FS.MakeDir
562 */
563static int afs_deliver_fs_create_vnode(struct afs_call *call)
564{
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000565 const __be32 *bp;
566 int ret;
567
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000568 ret = afs_transfer_reply(call);
569 if (ret < 0)
570 return ret;
571
572 /* unmarshall the reply once we've received all of it */
573 bp = call->buffer;
David Brazdil0f672f62019-12-10 10:32:29 +0000574 xdr_decode_AFSFid(&bp, call->out_fid);
Olivier Deprez0e641232021-09-23 10:07:05 +0200575 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
576 xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Brazdil0f672f62019-12-10 10:32:29 +0000577 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
578 xdr_decode_AFSVolSync(&bp, call->out_volsync);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000579
580 _leave(" = 0 [done]");
581 return 0;
582}
583
584/*
585 * FS.CreateFile and FS.MakeDir operation type
586 */
587static const struct afs_call_type afs_RXFSCreateFile = {
588 .name = "FS.CreateFile",
589 .op = afs_FS_CreateFile,
590 .deliver = afs_deliver_fs_create_vnode,
591 .destructor = afs_flat_call_destructor,
592};
593
594static const struct afs_call_type afs_RXFSMakeDir = {
595 .name = "FS.MakeDir",
596 .op = afs_FS_MakeDir,
597 .deliver = afs_deliver_fs_create_vnode,
598 .destructor = afs_flat_call_destructor,
599};
600
601/*
602 * create a file or make a directory
603 */
604int afs_fs_create(struct afs_fs_cursor *fc,
605 const char *name,
606 umode_t mode,
David Brazdil0f672f62019-12-10 10:32:29 +0000607 struct afs_status_cb *dvnode_scb,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000608 struct afs_fid *newfid,
David Brazdil0f672f62019-12-10 10:32:29 +0000609 struct afs_status_cb *new_scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000610{
David Brazdil0f672f62019-12-10 10:32:29 +0000611 struct afs_vnode *dvnode = fc->vnode;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000612 struct afs_call *call;
David Brazdil0f672f62019-12-10 10:32:29 +0000613 struct afs_net *net = afs_v2net(dvnode);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000614 size_t namesz, reqsz, padsz;
615 __be32 *bp;
616
David Brazdil0f672f62019-12-10 10:32:29 +0000617 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags)){
618 if (S_ISDIR(mode))
619 return yfs_fs_make_dir(fc, name, mode, dvnode_scb,
620 newfid, new_scb);
621 else
622 return yfs_fs_create_file(fc, name, mode, dvnode_scb,
623 newfid, new_scb);
624 }
625
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000626 _enter("");
627
628 namesz = strlen(name);
629 padsz = (4 - (namesz & 3)) & 3;
630 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
631
632 call = afs_alloc_flat_call(
633 net, S_ISDIR(mode) ? &afs_RXFSMakeDir : &afs_RXFSCreateFile,
634 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
635 if (!call)
636 return -ENOMEM;
637
638 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +0000639 call->out_dir_scb = dvnode_scb;
640 call->out_fid = newfid;
641 call->out_scb = new_scb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000642
643 /* marshall the parameters */
644 bp = call->request;
645 *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
David Brazdil0f672f62019-12-10 10:32:29 +0000646 *bp++ = htonl(dvnode->fid.vid);
647 *bp++ = htonl(dvnode->fid.vnode);
648 *bp++ = htonl(dvnode->fid.unique);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000649 *bp++ = htonl(namesz);
650 memcpy(bp, name, namesz);
651 bp = (void *) bp + namesz;
652 if (padsz > 0) {
653 memset(bp, 0, padsz);
654 bp = (void *) bp + padsz;
655 }
656 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
David Brazdil0f672f62019-12-10 10:32:29 +0000657 *bp++ = htonl(dvnode->vfs_inode.i_mtime.tv_sec); /* mtime */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000658 *bp++ = 0; /* owner */
659 *bp++ = 0; /* group */
660 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
661 *bp++ = 0; /* segment size */
662
663 afs_use_fs_server(call, fc->cbi);
David Brazdil0f672f62019-12-10 10:32:29 +0000664 trace_afs_make_fs_call1(call, &dvnode->fid, name);
665 afs_set_fc_call(call, fc);
666 afs_make_call(&fc->ac, call, GFP_NOFS);
667 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000668}
669
670/*
David Brazdil0f672f62019-12-10 10:32:29 +0000671 * Deliver reply data to any operation that returns directory status and volume
672 * sync.
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000673 */
David Brazdil0f672f62019-12-10 10:32:29 +0000674static int afs_deliver_fs_dir_status_and_vol(struct afs_call *call)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000675{
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000676 const __be32 *bp;
677 int ret;
678
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000679 ret = afs_transfer_reply(call);
680 if (ret < 0)
681 return ret;
682
683 /* unmarshall the reply once we've received all of it */
684 bp = call->buffer;
Olivier Deprez0e641232021-09-23 10:07:05 +0200685 xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Brazdil0f672f62019-12-10 10:32:29 +0000686 xdr_decode_AFSVolSync(&bp, call->out_volsync);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000687
688 _leave(" = 0 [done]");
689 return 0;
690}
691
692/*
693 * FS.RemoveDir/FS.RemoveFile operation type
694 */
695static const struct afs_call_type afs_RXFSRemoveFile = {
696 .name = "FS.RemoveFile",
697 .op = afs_FS_RemoveFile,
David Brazdil0f672f62019-12-10 10:32:29 +0000698 .deliver = afs_deliver_fs_dir_status_and_vol,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000699 .destructor = afs_flat_call_destructor,
700};
701
702static const struct afs_call_type afs_RXFSRemoveDir = {
703 .name = "FS.RemoveDir",
704 .op = afs_FS_RemoveDir,
David Brazdil0f672f62019-12-10 10:32:29 +0000705 .deliver = afs_deliver_fs_dir_status_and_vol,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000706 .destructor = afs_flat_call_destructor,
707};
708
709/*
710 * remove a file or directory
711 */
David Brazdil0f672f62019-12-10 10:32:29 +0000712int afs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
713 const char *name, bool isdir, struct afs_status_cb *dvnode_scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000714{
David Brazdil0f672f62019-12-10 10:32:29 +0000715 struct afs_vnode *dvnode = fc->vnode;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000716 struct afs_call *call;
David Brazdil0f672f62019-12-10 10:32:29 +0000717 struct afs_net *net = afs_v2net(dvnode);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000718 size_t namesz, reqsz, padsz;
719 __be32 *bp;
720
David Brazdil0f672f62019-12-10 10:32:29 +0000721 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
722 return yfs_fs_remove(fc, vnode, name, isdir, dvnode_scb);
723
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000724 _enter("");
725
726 namesz = strlen(name);
727 padsz = (4 - (namesz & 3)) & 3;
728 reqsz = (5 * 4) + namesz + padsz;
729
730 call = afs_alloc_flat_call(
731 net, isdir ? &afs_RXFSRemoveDir : &afs_RXFSRemoveFile,
732 reqsz, (21 + 6) * 4);
733 if (!call)
734 return -ENOMEM;
735
736 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +0000737 call->out_dir_scb = dvnode_scb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000738
739 /* marshall the parameters */
740 bp = call->request;
741 *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
David Brazdil0f672f62019-12-10 10:32:29 +0000742 *bp++ = htonl(dvnode->fid.vid);
743 *bp++ = htonl(dvnode->fid.vnode);
744 *bp++ = htonl(dvnode->fid.unique);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000745 *bp++ = htonl(namesz);
746 memcpy(bp, name, namesz);
747 bp = (void *) bp + namesz;
748 if (padsz > 0) {
749 memset(bp, 0, padsz);
750 bp = (void *) bp + padsz;
751 }
752
753 afs_use_fs_server(call, fc->cbi);
David Brazdil0f672f62019-12-10 10:32:29 +0000754 trace_afs_make_fs_call1(call, &dvnode->fid, name);
755 afs_set_fc_call(call, fc);
756 afs_make_call(&fc->ac, call, GFP_NOFS);
757 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000758}
759
760/*
761 * deliver reply data to an FS.Link
762 */
763static int afs_deliver_fs_link(struct afs_call *call)
764{
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000765 const __be32 *bp;
766 int ret;
767
768 _enter("{%u}", call->unmarshall);
769
770 ret = afs_transfer_reply(call);
771 if (ret < 0)
772 return ret;
773
774 /* unmarshall the reply once we've received all of it */
775 bp = call->buffer;
Olivier Deprez0e641232021-09-23 10:07:05 +0200776 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
777 xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Brazdil0f672f62019-12-10 10:32:29 +0000778 xdr_decode_AFSVolSync(&bp, call->out_volsync);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000779
780 _leave(" = 0 [done]");
781 return 0;
782}
783
784/*
785 * FS.Link operation type
786 */
787static const struct afs_call_type afs_RXFSLink = {
788 .name = "FS.Link",
789 .op = afs_FS_Link,
790 .deliver = afs_deliver_fs_link,
791 .destructor = afs_flat_call_destructor,
792};
793
794/*
795 * make a hard link
796 */
797int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
David Brazdil0f672f62019-12-10 10:32:29 +0000798 const char *name,
799 struct afs_status_cb *dvnode_scb,
800 struct afs_status_cb *vnode_scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000801{
802 struct afs_vnode *dvnode = fc->vnode;
803 struct afs_call *call;
804 struct afs_net *net = afs_v2net(vnode);
805 size_t namesz, reqsz, padsz;
806 __be32 *bp;
807
David Brazdil0f672f62019-12-10 10:32:29 +0000808 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
809 return yfs_fs_link(fc, vnode, name, dvnode_scb, vnode_scb);
810
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000811 _enter("");
812
813 namesz = strlen(name);
814 padsz = (4 - (namesz & 3)) & 3;
815 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
816
817 call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
818 if (!call)
819 return -ENOMEM;
820
821 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +0000822 call->out_dir_scb = dvnode_scb;
823 call->out_scb = vnode_scb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000824
825 /* marshall the parameters */
826 bp = call->request;
827 *bp++ = htonl(FSLINK);
828 *bp++ = htonl(dvnode->fid.vid);
829 *bp++ = htonl(dvnode->fid.vnode);
830 *bp++ = htonl(dvnode->fid.unique);
831 *bp++ = htonl(namesz);
832 memcpy(bp, name, namesz);
833 bp = (void *) bp + namesz;
834 if (padsz > 0) {
835 memset(bp, 0, padsz);
836 bp = (void *) bp + padsz;
837 }
838 *bp++ = htonl(vnode->fid.vid);
839 *bp++ = htonl(vnode->fid.vnode);
840 *bp++ = htonl(vnode->fid.unique);
841
842 afs_use_fs_server(call, fc->cbi);
David Brazdil0f672f62019-12-10 10:32:29 +0000843 trace_afs_make_fs_call1(call, &vnode->fid, name);
844 afs_set_fc_call(call, fc);
845 afs_make_call(&fc->ac, call, GFP_NOFS);
846 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000847}
848
849/*
850 * deliver reply data to an FS.Symlink
851 */
852static int afs_deliver_fs_symlink(struct afs_call *call)
853{
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000854 const __be32 *bp;
855 int ret;
856
857 _enter("{%u}", call->unmarshall);
858
859 ret = afs_transfer_reply(call);
860 if (ret < 0)
861 return ret;
862
863 /* unmarshall the reply once we've received all of it */
864 bp = call->buffer;
David Brazdil0f672f62019-12-10 10:32:29 +0000865 xdr_decode_AFSFid(&bp, call->out_fid);
Olivier Deprez0e641232021-09-23 10:07:05 +0200866 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
867 xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
David Brazdil0f672f62019-12-10 10:32:29 +0000868 xdr_decode_AFSVolSync(&bp, call->out_volsync);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000869
870 _leave(" = 0 [done]");
871 return 0;
872}
873
874/*
875 * FS.Symlink operation type
876 */
877static const struct afs_call_type afs_RXFSSymlink = {
878 .name = "FS.Symlink",
879 .op = afs_FS_Symlink,
880 .deliver = afs_deliver_fs_symlink,
881 .destructor = afs_flat_call_destructor,
882};
883
884/*
885 * create a symbolic link
886 */
887int afs_fs_symlink(struct afs_fs_cursor *fc,
888 const char *name,
889 const char *contents,
David Brazdil0f672f62019-12-10 10:32:29 +0000890 struct afs_status_cb *dvnode_scb,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000891 struct afs_fid *newfid,
David Brazdil0f672f62019-12-10 10:32:29 +0000892 struct afs_status_cb *new_scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000893{
David Brazdil0f672f62019-12-10 10:32:29 +0000894 struct afs_vnode *dvnode = fc->vnode;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000895 struct afs_call *call;
David Brazdil0f672f62019-12-10 10:32:29 +0000896 struct afs_net *net = afs_v2net(dvnode);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000897 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
898 __be32 *bp;
899
David Brazdil0f672f62019-12-10 10:32:29 +0000900 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
901 return yfs_fs_symlink(fc, name, contents, dvnode_scb,
902 newfid, new_scb);
903
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000904 _enter("");
905
906 namesz = strlen(name);
907 padsz = (4 - (namesz & 3)) & 3;
908
909 c_namesz = strlen(contents);
910 c_padsz = (4 - (c_namesz & 3)) & 3;
911
912 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
913
914 call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
915 (3 + 21 + 21 + 6) * 4);
916 if (!call)
917 return -ENOMEM;
918
919 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +0000920 call->out_dir_scb = dvnode_scb;
921 call->out_fid = newfid;
922 call->out_scb = new_scb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000923
924 /* marshall the parameters */
925 bp = call->request;
926 *bp++ = htonl(FSSYMLINK);
David Brazdil0f672f62019-12-10 10:32:29 +0000927 *bp++ = htonl(dvnode->fid.vid);
928 *bp++ = htonl(dvnode->fid.vnode);
929 *bp++ = htonl(dvnode->fid.unique);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000930 *bp++ = htonl(namesz);
931 memcpy(bp, name, namesz);
932 bp = (void *) bp + namesz;
933 if (padsz > 0) {
934 memset(bp, 0, padsz);
935 bp = (void *) bp + padsz;
936 }
937 *bp++ = htonl(c_namesz);
938 memcpy(bp, contents, c_namesz);
939 bp = (void *) bp + c_namesz;
940 if (c_padsz > 0) {
941 memset(bp, 0, c_padsz);
942 bp = (void *) bp + c_padsz;
943 }
944 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
David Brazdil0f672f62019-12-10 10:32:29 +0000945 *bp++ = htonl(dvnode->vfs_inode.i_mtime.tv_sec); /* mtime */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000946 *bp++ = 0; /* owner */
947 *bp++ = 0; /* group */
948 *bp++ = htonl(S_IRWXUGO); /* unix mode */
949 *bp++ = 0; /* segment size */
950
951 afs_use_fs_server(call, fc->cbi);
David Brazdil0f672f62019-12-10 10:32:29 +0000952 trace_afs_make_fs_call1(call, &dvnode->fid, name);
953 afs_set_fc_call(call, fc);
954 afs_make_call(&fc->ac, call, GFP_NOFS);
955 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000956}
957
958/*
959 * deliver reply data to an FS.Rename
960 */
961static int afs_deliver_fs_rename(struct afs_call *call)
962{
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000963 const __be32 *bp;
964 int ret;
965
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000966 ret = afs_transfer_reply(call);
967 if (ret < 0)
968 return ret;
969
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000970 bp = call->buffer;
Olivier Deprez0e641232021-09-23 10:07:05 +0200971 /* If the two dirs are the same, we have two copies of the same status
972 * report, so we just decode it twice.
973 */
974 xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
975 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Brazdil0f672f62019-12-10 10:32:29 +0000976 xdr_decode_AFSVolSync(&bp, call->out_volsync);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000977
978 _leave(" = 0 [done]");
979 return 0;
980}
981
982/*
983 * FS.Rename operation type
984 */
985static const struct afs_call_type afs_RXFSRename = {
986 .name = "FS.Rename",
987 .op = afs_FS_Rename,
988 .deliver = afs_deliver_fs_rename,
989 .destructor = afs_flat_call_destructor,
990};
991
992/*
David Brazdil0f672f62019-12-10 10:32:29 +0000993 * Rename/move a file or directory.
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000994 */
995int afs_fs_rename(struct afs_fs_cursor *fc,
996 const char *orig_name,
997 struct afs_vnode *new_dvnode,
998 const char *new_name,
David Brazdil0f672f62019-12-10 10:32:29 +0000999 struct afs_status_cb *orig_dvnode_scb,
1000 struct afs_status_cb *new_dvnode_scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001001{
1002 struct afs_vnode *orig_dvnode = fc->vnode;
1003 struct afs_call *call;
1004 struct afs_net *net = afs_v2net(orig_dvnode);
1005 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1006 __be32 *bp;
1007
David Brazdil0f672f62019-12-10 10:32:29 +00001008 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1009 return yfs_fs_rename(fc, orig_name,
1010 new_dvnode, new_name,
1011 orig_dvnode_scb,
1012 new_dvnode_scb);
1013
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001014 _enter("");
1015
1016 o_namesz = strlen(orig_name);
1017 o_padsz = (4 - (o_namesz & 3)) & 3;
1018
1019 n_namesz = strlen(new_name);
1020 n_padsz = (4 - (n_namesz & 3)) & 3;
1021
1022 reqsz = (4 * 4) +
1023 4 + o_namesz + o_padsz +
1024 (3 * 4) +
1025 4 + n_namesz + n_padsz;
1026
1027 call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
1028 if (!call)
1029 return -ENOMEM;
1030
1031 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +00001032 call->out_dir_scb = orig_dvnode_scb;
1033 call->out_scb = new_dvnode_scb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001034
1035 /* marshall the parameters */
1036 bp = call->request;
1037 *bp++ = htonl(FSRENAME);
1038 *bp++ = htonl(orig_dvnode->fid.vid);
1039 *bp++ = htonl(orig_dvnode->fid.vnode);
1040 *bp++ = htonl(orig_dvnode->fid.unique);
1041 *bp++ = htonl(o_namesz);
1042 memcpy(bp, orig_name, o_namesz);
1043 bp = (void *) bp + o_namesz;
1044 if (o_padsz > 0) {
1045 memset(bp, 0, o_padsz);
1046 bp = (void *) bp + o_padsz;
1047 }
1048
1049 *bp++ = htonl(new_dvnode->fid.vid);
1050 *bp++ = htonl(new_dvnode->fid.vnode);
1051 *bp++ = htonl(new_dvnode->fid.unique);
1052 *bp++ = htonl(n_namesz);
1053 memcpy(bp, new_name, n_namesz);
1054 bp = (void *) bp + n_namesz;
1055 if (n_padsz > 0) {
1056 memset(bp, 0, n_padsz);
1057 bp = (void *) bp + n_padsz;
1058 }
1059
1060 afs_use_fs_server(call, fc->cbi);
David Brazdil0f672f62019-12-10 10:32:29 +00001061 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
1062 afs_set_fc_call(call, fc);
1063 afs_make_call(&fc->ac, call, GFP_NOFS);
1064 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001065}
1066
1067/*
1068 * deliver reply data to an FS.StoreData
1069 */
1070static int afs_deliver_fs_store_data(struct afs_call *call)
1071{
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001072 const __be32 *bp;
1073 int ret;
1074
1075 _enter("");
1076
1077 ret = afs_transfer_reply(call);
1078 if (ret < 0)
1079 return ret;
1080
1081 /* unmarshall the reply once we've received all of it */
1082 bp = call->buffer;
Olivier Deprez0e641232021-09-23 10:07:05 +02001083 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Brazdil0f672f62019-12-10 10:32:29 +00001084 xdr_decode_AFSVolSync(&bp, call->out_volsync);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001085
1086 _leave(" = 0 [done]");
1087 return 0;
1088}
1089
1090/*
1091 * FS.StoreData operation type
1092 */
1093static const struct afs_call_type afs_RXFSStoreData = {
1094 .name = "FS.StoreData",
1095 .op = afs_FS_StoreData,
1096 .deliver = afs_deliver_fs_store_data,
1097 .destructor = afs_flat_call_destructor,
1098};
1099
1100static const struct afs_call_type afs_RXFSStoreData64 = {
1101 .name = "FS.StoreData64",
1102 .op = afs_FS_StoreData64,
1103 .deliver = afs_deliver_fs_store_data,
1104 .destructor = afs_flat_call_destructor,
1105};
1106
1107/*
1108 * store a set of pages to a very large file
1109 */
1110static int afs_fs_store_data64(struct afs_fs_cursor *fc,
1111 struct address_space *mapping,
1112 pgoff_t first, pgoff_t last,
1113 unsigned offset, unsigned to,
David Brazdil0f672f62019-12-10 10:32:29 +00001114 loff_t size, loff_t pos, loff_t i_size,
1115 struct afs_status_cb *scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001116{
1117 struct afs_vnode *vnode = fc->vnode;
1118 struct afs_call *call;
1119 struct afs_net *net = afs_v2net(vnode);
1120 __be32 *bp;
1121
David Brazdil0f672f62019-12-10 10:32:29 +00001122 _enter(",%x,{%llx:%llu},,",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001123 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1124
1125 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
1126 (4 + 6 + 3 * 2) * 4,
1127 (21 + 6) * 4);
1128 if (!call)
1129 return -ENOMEM;
1130
1131 call->key = fc->key;
1132 call->mapping = mapping;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001133 call->first = first;
1134 call->last = last;
1135 call->first_offset = offset;
1136 call->last_to = to;
1137 call->send_pages = true;
David Brazdil0f672f62019-12-10 10:32:29 +00001138 call->out_scb = scb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001139
1140 /* marshall the parameters */
1141 bp = call->request;
1142 *bp++ = htonl(FSSTOREDATA64);
1143 *bp++ = htonl(vnode->fid.vid);
1144 *bp++ = htonl(vnode->fid.vnode);
1145 *bp++ = htonl(vnode->fid.unique);
1146
1147 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1148 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1149 *bp++ = 0; /* owner */
1150 *bp++ = 0; /* group */
1151 *bp++ = 0; /* unix mode */
1152 *bp++ = 0; /* segment size */
1153
1154 *bp++ = htonl(pos >> 32);
1155 *bp++ = htonl((u32) pos);
1156 *bp++ = htonl(size >> 32);
1157 *bp++ = htonl((u32) size);
1158 *bp++ = htonl(i_size >> 32);
1159 *bp++ = htonl((u32) i_size);
1160
1161 trace_afs_make_fs_call(call, &vnode->fid);
David Brazdil0f672f62019-12-10 10:32:29 +00001162 afs_set_fc_call(call, fc);
1163 afs_make_call(&fc->ac, call, GFP_NOFS);
1164 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001165}
1166
1167/*
1168 * store a set of pages
1169 */
1170int afs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1171 pgoff_t first, pgoff_t last,
David Brazdil0f672f62019-12-10 10:32:29 +00001172 unsigned offset, unsigned to,
1173 struct afs_status_cb *scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001174{
1175 struct afs_vnode *vnode = fc->vnode;
1176 struct afs_call *call;
1177 struct afs_net *net = afs_v2net(vnode);
1178 loff_t size, pos, i_size;
1179 __be32 *bp;
1180
David Brazdil0f672f62019-12-10 10:32:29 +00001181 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1182 return yfs_fs_store_data(fc, mapping, first, last, offset, to, scb);
1183
1184 _enter(",%x,{%llx:%llu},,",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001185 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1186
1187 size = (loff_t)to - (loff_t)offset;
1188 if (first != last)
1189 size += (loff_t)(last - first) << PAGE_SHIFT;
1190 pos = (loff_t)first << PAGE_SHIFT;
1191 pos += offset;
1192
1193 i_size = i_size_read(&vnode->vfs_inode);
1194 if (pos + size > i_size)
1195 i_size = size + pos;
1196
1197 _debug("size %llx, at %llx, i_size %llx",
1198 (unsigned long long) size, (unsigned long long) pos,
1199 (unsigned long long) i_size);
1200
1201 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
1202 return afs_fs_store_data64(fc, mapping, first, last, offset, to,
David Brazdil0f672f62019-12-10 10:32:29 +00001203 size, pos, i_size, scb);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001204
1205 call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
1206 (4 + 6 + 3) * 4,
1207 (21 + 6) * 4);
1208 if (!call)
1209 return -ENOMEM;
1210
1211 call->key = fc->key;
1212 call->mapping = mapping;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001213 call->first = first;
1214 call->last = last;
1215 call->first_offset = offset;
1216 call->last_to = to;
1217 call->send_pages = true;
David Brazdil0f672f62019-12-10 10:32:29 +00001218 call->out_scb = scb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001219
1220 /* marshall the parameters */
1221 bp = call->request;
1222 *bp++ = htonl(FSSTOREDATA);
1223 *bp++ = htonl(vnode->fid.vid);
1224 *bp++ = htonl(vnode->fid.vnode);
1225 *bp++ = htonl(vnode->fid.unique);
1226
1227 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1228 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1229 *bp++ = 0; /* owner */
1230 *bp++ = 0; /* group */
1231 *bp++ = 0; /* unix mode */
1232 *bp++ = 0; /* segment size */
1233
1234 *bp++ = htonl(pos);
1235 *bp++ = htonl(size);
1236 *bp++ = htonl(i_size);
1237
1238 afs_use_fs_server(call, fc->cbi);
1239 trace_afs_make_fs_call(call, &vnode->fid);
David Brazdil0f672f62019-12-10 10:32:29 +00001240 afs_set_fc_call(call, fc);
1241 afs_make_call(&fc->ac, call, GFP_NOFS);
1242 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001243}
1244
1245/*
1246 * deliver reply data to an FS.StoreStatus
1247 */
1248static int afs_deliver_fs_store_status(struct afs_call *call)
1249{
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001250 const __be32 *bp;
1251 int ret;
1252
1253 _enter("");
1254
1255 ret = afs_transfer_reply(call);
1256 if (ret < 0)
1257 return ret;
1258
1259 /* unmarshall the reply once we've received all of it */
1260 bp = call->buffer;
Olivier Deprez0e641232021-09-23 10:07:05 +02001261 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Brazdil0f672f62019-12-10 10:32:29 +00001262 xdr_decode_AFSVolSync(&bp, call->out_volsync);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001263
1264 _leave(" = 0 [done]");
1265 return 0;
1266}
1267
1268/*
1269 * FS.StoreStatus operation type
1270 */
1271static const struct afs_call_type afs_RXFSStoreStatus = {
1272 .name = "FS.StoreStatus",
1273 .op = afs_FS_StoreStatus,
1274 .deliver = afs_deliver_fs_store_status,
1275 .destructor = afs_flat_call_destructor,
1276};
1277
1278static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1279 .name = "FS.StoreData",
1280 .op = afs_FS_StoreData,
1281 .deliver = afs_deliver_fs_store_status,
1282 .destructor = afs_flat_call_destructor,
1283};
1284
1285static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1286 .name = "FS.StoreData64",
1287 .op = afs_FS_StoreData64,
1288 .deliver = afs_deliver_fs_store_status,
1289 .destructor = afs_flat_call_destructor,
1290};
1291
1292/*
1293 * set the attributes on a very large file, using FS.StoreData rather than
1294 * FS.StoreStatus so as to alter the file size also
1295 */
David Brazdil0f672f62019-12-10 10:32:29 +00001296static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr,
1297 struct afs_status_cb *scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001298{
1299 struct afs_vnode *vnode = fc->vnode;
1300 struct afs_call *call;
1301 struct afs_net *net = afs_v2net(vnode);
1302 __be32 *bp;
1303
David Brazdil0f672f62019-12-10 10:32:29 +00001304 _enter(",%x,{%llx:%llu},,",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001305 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1306
1307 ASSERT(attr->ia_valid & ATTR_SIZE);
1308
1309 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
1310 (4 + 6 + 3 * 2) * 4,
1311 (21 + 6) * 4);
1312 if (!call)
1313 return -ENOMEM;
1314
1315 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +00001316 call->out_scb = scb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001317
1318 /* marshall the parameters */
1319 bp = call->request;
1320 *bp++ = htonl(FSSTOREDATA64);
1321 *bp++ = htonl(vnode->fid.vid);
1322 *bp++ = htonl(vnode->fid.vnode);
1323 *bp++ = htonl(vnode->fid.unique);
1324
1325 xdr_encode_AFS_StoreStatus(&bp, attr);
1326
David Brazdil0f672f62019-12-10 10:32:29 +00001327 *bp++ = htonl(attr->ia_size >> 32); /* position of start of write */
1328 *bp++ = htonl((u32) attr->ia_size);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001329 *bp++ = 0; /* size of write */
1330 *bp++ = 0;
1331 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1332 *bp++ = htonl((u32) attr->ia_size);
1333
1334 afs_use_fs_server(call, fc->cbi);
1335 trace_afs_make_fs_call(call, &vnode->fid);
David Brazdil0f672f62019-12-10 10:32:29 +00001336 afs_set_fc_call(call, fc);
1337 afs_make_call(&fc->ac, call, GFP_NOFS);
1338 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001339}
1340
1341/*
1342 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1343 * so as to alter the file size also
1344 */
David Brazdil0f672f62019-12-10 10:32:29 +00001345static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr,
1346 struct afs_status_cb *scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001347{
1348 struct afs_vnode *vnode = fc->vnode;
1349 struct afs_call *call;
1350 struct afs_net *net = afs_v2net(vnode);
1351 __be32 *bp;
1352
David Brazdil0f672f62019-12-10 10:32:29 +00001353 _enter(",%x,{%llx:%llu},,",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001354 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1355
1356 ASSERT(attr->ia_valid & ATTR_SIZE);
1357 if (attr->ia_size >> 32)
David Brazdil0f672f62019-12-10 10:32:29 +00001358 return afs_fs_setattr_size64(fc, attr, scb);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001359
1360 call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
1361 (4 + 6 + 3) * 4,
1362 (21 + 6) * 4);
1363 if (!call)
1364 return -ENOMEM;
1365
1366 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +00001367 call->out_scb = scb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001368
1369 /* marshall the parameters */
1370 bp = call->request;
1371 *bp++ = htonl(FSSTOREDATA);
1372 *bp++ = htonl(vnode->fid.vid);
1373 *bp++ = htonl(vnode->fid.vnode);
1374 *bp++ = htonl(vnode->fid.unique);
1375
1376 xdr_encode_AFS_StoreStatus(&bp, attr);
1377
David Brazdil0f672f62019-12-10 10:32:29 +00001378 *bp++ = htonl(attr->ia_size); /* position of start of write */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001379 *bp++ = 0; /* size of write */
1380 *bp++ = htonl(attr->ia_size); /* new file length */
1381
1382 afs_use_fs_server(call, fc->cbi);
1383 trace_afs_make_fs_call(call, &vnode->fid);
David Brazdil0f672f62019-12-10 10:32:29 +00001384 afs_set_fc_call(call, fc);
1385 afs_make_call(&fc->ac, call, GFP_NOFS);
1386 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001387}
1388
1389/*
1390 * set the attributes on a file, using FS.StoreData if there's a change in file
1391 * size, and FS.StoreStatus otherwise
1392 */
David Brazdil0f672f62019-12-10 10:32:29 +00001393int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr,
1394 struct afs_status_cb *scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001395{
1396 struct afs_vnode *vnode = fc->vnode;
1397 struct afs_call *call;
1398 struct afs_net *net = afs_v2net(vnode);
1399 __be32 *bp;
1400
David Brazdil0f672f62019-12-10 10:32:29 +00001401 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1402 return yfs_fs_setattr(fc, attr, scb);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001403
David Brazdil0f672f62019-12-10 10:32:29 +00001404 if (attr->ia_valid & ATTR_SIZE)
1405 return afs_fs_setattr_size(fc, attr, scb);
1406
1407 _enter(",%x,{%llx:%llu},,",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001408 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1409
1410 call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
1411 (4 + 6) * 4,
1412 (21 + 6) * 4);
1413 if (!call)
1414 return -ENOMEM;
1415
1416 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +00001417 call->out_scb = scb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001418
1419 /* marshall the parameters */
1420 bp = call->request;
1421 *bp++ = htonl(FSSTORESTATUS);
1422 *bp++ = htonl(vnode->fid.vid);
1423 *bp++ = htonl(vnode->fid.vnode);
1424 *bp++ = htonl(vnode->fid.unique);
1425
1426 xdr_encode_AFS_StoreStatus(&bp, attr);
1427
1428 afs_use_fs_server(call, fc->cbi);
1429 trace_afs_make_fs_call(call, &vnode->fid);
David Brazdil0f672f62019-12-10 10:32:29 +00001430 afs_set_fc_call(call, fc);
1431 afs_make_call(&fc->ac, call, GFP_NOFS);
1432 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001433}
1434
1435/*
1436 * deliver reply data to an FS.GetVolumeStatus
1437 */
1438static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1439{
1440 const __be32 *bp;
1441 char *p;
David Brazdil0f672f62019-12-10 10:32:29 +00001442 u32 size;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001443 int ret;
1444
1445 _enter("{%u}", call->unmarshall);
1446
1447 switch (call->unmarshall) {
1448 case 0:
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001449 call->unmarshall++;
David Brazdil0f672f62019-12-10 10:32:29 +00001450 afs_extract_to_buf(call, 12 * 4);
1451 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001452
1453 /* extract the returned status record */
1454 case 1:
1455 _debug("extract status");
David Brazdil0f672f62019-12-10 10:32:29 +00001456 ret = afs_extract_data(call, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001457 if (ret < 0)
1458 return ret;
1459
1460 bp = call->buffer;
David Brazdil0f672f62019-12-10 10:32:29 +00001461 xdr_decode_AFSFetchVolumeStatus(&bp, call->out_volstatus);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001462 call->unmarshall++;
David Brazdil0f672f62019-12-10 10:32:29 +00001463 afs_extract_to_tmp(call);
1464 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001465
1466 /* extract the volume name length */
1467 case 2:
David Brazdil0f672f62019-12-10 10:32:29 +00001468 ret = afs_extract_data(call, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001469 if (ret < 0)
1470 return ret;
1471
1472 call->count = ntohl(call->tmp);
1473 _debug("volname length: %u", call->count);
1474 if (call->count >= AFSNAMEMAX)
David Brazdil0f672f62019-12-10 10:32:29 +00001475 return afs_protocol_error(call, -EBADMSG,
1476 afs_eproto_volname_len);
1477 size = (call->count + 3) & ~3; /* It's padded */
1478 afs_extract_to_buf(call, size);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001479 call->unmarshall++;
David Brazdil0f672f62019-12-10 10:32:29 +00001480 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001481
1482 /* extract the volume name */
1483 case 3:
1484 _debug("extract volname");
David Brazdil0f672f62019-12-10 10:32:29 +00001485 ret = afs_extract_data(call, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001486 if (ret < 0)
1487 return ret;
1488
David Brazdil0f672f62019-12-10 10:32:29 +00001489 p = call->buffer;
1490 p[call->count] = 0;
1491 _debug("volname '%s'", p);
1492 afs_extract_to_tmp(call);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001493 call->unmarshall++;
David Brazdil0f672f62019-12-10 10:32:29 +00001494 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001495
1496 /* extract the offline message length */
David Brazdil0f672f62019-12-10 10:32:29 +00001497 case 4:
1498 ret = afs_extract_data(call, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001499 if (ret < 0)
1500 return ret;
1501
1502 call->count = ntohl(call->tmp);
1503 _debug("offline msg length: %u", call->count);
1504 if (call->count >= AFSNAMEMAX)
David Brazdil0f672f62019-12-10 10:32:29 +00001505 return afs_protocol_error(call, -EBADMSG,
1506 afs_eproto_offline_msg_len);
1507 size = (call->count + 3) & ~3; /* It's padded */
1508 afs_extract_to_buf(call, size);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001509 call->unmarshall++;
David Brazdil0f672f62019-12-10 10:32:29 +00001510 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001511
1512 /* extract the offline message */
David Brazdil0f672f62019-12-10 10:32:29 +00001513 case 5:
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001514 _debug("extract offline");
David Brazdil0f672f62019-12-10 10:32:29 +00001515 ret = afs_extract_data(call, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001516 if (ret < 0)
1517 return ret;
1518
David Brazdil0f672f62019-12-10 10:32:29 +00001519 p = call->buffer;
1520 p[call->count] = 0;
1521 _debug("offline '%s'", p);
1522
1523 afs_extract_to_tmp(call);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001524 call->unmarshall++;
David Brazdil0f672f62019-12-10 10:32:29 +00001525 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001526
1527 /* extract the message of the day length */
David Brazdil0f672f62019-12-10 10:32:29 +00001528 case 6:
1529 ret = afs_extract_data(call, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001530 if (ret < 0)
1531 return ret;
1532
1533 call->count = ntohl(call->tmp);
1534 _debug("motd length: %u", call->count);
1535 if (call->count >= AFSNAMEMAX)
David Brazdil0f672f62019-12-10 10:32:29 +00001536 return afs_protocol_error(call, -EBADMSG,
1537 afs_eproto_motd_len);
1538 size = (call->count + 3) & ~3; /* It's padded */
1539 afs_extract_to_buf(call, size);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001540 call->unmarshall++;
David Brazdil0f672f62019-12-10 10:32:29 +00001541 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001542
1543 /* extract the message of the day */
David Brazdil0f672f62019-12-10 10:32:29 +00001544 case 7:
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001545 _debug("extract motd");
David Brazdil0f672f62019-12-10 10:32:29 +00001546 ret = afs_extract_data(call, false);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001547 if (ret < 0)
1548 return ret;
1549
David Brazdil0f672f62019-12-10 10:32:29 +00001550 p = call->buffer;
1551 p[call->count] = 0;
1552 _debug("motd '%s'", p);
1553
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001554 call->unmarshall++;
David Brazdil0f672f62019-12-10 10:32:29 +00001555
1556 case 8:
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001557 break;
1558 }
1559
1560 _leave(" = 0 [done]");
1561 return 0;
1562}
1563
1564/*
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001565 * FS.GetVolumeStatus operation type
1566 */
1567static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1568 .name = "FS.GetVolumeStatus",
1569 .op = afs_FS_GetVolumeStatus,
1570 .deliver = afs_deliver_fs_get_volume_status,
David Brazdil0f672f62019-12-10 10:32:29 +00001571 .destructor = afs_flat_call_destructor,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001572};
1573
1574/*
1575 * fetch the status of a volume
1576 */
1577int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
1578 struct afs_volume_status *vs)
1579{
1580 struct afs_vnode *vnode = fc->vnode;
1581 struct afs_call *call;
1582 struct afs_net *net = afs_v2net(vnode);
1583 __be32 *bp;
David Brazdil0f672f62019-12-10 10:32:29 +00001584
1585 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1586 return yfs_fs_get_volume_status(fc, vs);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001587
1588 _enter("");
1589
David Brazdil0f672f62019-12-10 10:32:29 +00001590 call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4,
1591 max(12 * 4, AFSOPAQUEMAX + 1));
1592 if (!call)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001593 return -ENOMEM;
1594
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001595 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +00001596 call->out_volstatus = vs;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001597
1598 /* marshall the parameters */
1599 bp = call->request;
1600 bp[0] = htonl(FSGETVOLUMESTATUS);
1601 bp[1] = htonl(vnode->fid.vid);
1602
1603 afs_use_fs_server(call, fc->cbi);
1604 trace_afs_make_fs_call(call, &vnode->fid);
David Brazdil0f672f62019-12-10 10:32:29 +00001605 afs_set_fc_call(call, fc);
1606 afs_make_call(&fc->ac, call, GFP_NOFS);
1607 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001608}
1609
1610/*
1611 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1612 */
1613static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1614{
1615 const __be32 *bp;
1616 int ret;
1617
1618 _enter("{%u}", call->unmarshall);
1619
1620 ret = afs_transfer_reply(call);
1621 if (ret < 0)
1622 return ret;
1623
1624 /* unmarshall the reply once we've received all of it */
1625 bp = call->buffer;
David Brazdil0f672f62019-12-10 10:32:29 +00001626 xdr_decode_AFSVolSync(&bp, call->out_volsync);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001627
1628 _leave(" = 0 [done]");
1629 return 0;
1630}
1631
1632/*
1633 * FS.SetLock operation type
1634 */
1635static const struct afs_call_type afs_RXFSSetLock = {
1636 .name = "FS.SetLock",
1637 .op = afs_FS_SetLock,
1638 .deliver = afs_deliver_fs_xxxx_lock,
David Brazdil0f672f62019-12-10 10:32:29 +00001639 .done = afs_lock_op_done,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001640 .destructor = afs_flat_call_destructor,
1641};
1642
1643/*
1644 * FS.ExtendLock operation type
1645 */
1646static const struct afs_call_type afs_RXFSExtendLock = {
1647 .name = "FS.ExtendLock",
1648 .op = afs_FS_ExtendLock,
1649 .deliver = afs_deliver_fs_xxxx_lock,
David Brazdil0f672f62019-12-10 10:32:29 +00001650 .done = afs_lock_op_done,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001651 .destructor = afs_flat_call_destructor,
1652};
1653
1654/*
1655 * FS.ReleaseLock operation type
1656 */
1657static const struct afs_call_type afs_RXFSReleaseLock = {
1658 .name = "FS.ReleaseLock",
1659 .op = afs_FS_ReleaseLock,
1660 .deliver = afs_deliver_fs_xxxx_lock,
1661 .destructor = afs_flat_call_destructor,
1662};
1663
1664/*
1665 * Set a lock on a file
1666 */
David Brazdil0f672f62019-12-10 10:32:29 +00001667int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type,
1668 struct afs_status_cb *scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001669{
1670 struct afs_vnode *vnode = fc->vnode;
1671 struct afs_call *call;
1672 struct afs_net *net = afs_v2net(vnode);
1673 __be32 *bp;
1674
David Brazdil0f672f62019-12-10 10:32:29 +00001675 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1676 return yfs_fs_set_lock(fc, type, scb);
1677
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001678 _enter("");
1679
1680 call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1681 if (!call)
1682 return -ENOMEM;
1683
1684 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +00001685 call->lvnode = vnode;
1686 call->out_scb = scb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001687
1688 /* marshall the parameters */
1689 bp = call->request;
1690 *bp++ = htonl(FSSETLOCK);
1691 *bp++ = htonl(vnode->fid.vid);
1692 *bp++ = htonl(vnode->fid.vnode);
1693 *bp++ = htonl(vnode->fid.unique);
1694 *bp++ = htonl(type);
1695
1696 afs_use_fs_server(call, fc->cbi);
David Brazdil0f672f62019-12-10 10:32:29 +00001697 trace_afs_make_fs_calli(call, &vnode->fid, type);
1698 afs_set_fc_call(call, fc);
1699 afs_make_call(&fc->ac, call, GFP_NOFS);
1700 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001701}
1702
1703/*
1704 * extend a lock on a file
1705 */
David Brazdil0f672f62019-12-10 10:32:29 +00001706int afs_fs_extend_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001707{
1708 struct afs_vnode *vnode = fc->vnode;
1709 struct afs_call *call;
1710 struct afs_net *net = afs_v2net(vnode);
1711 __be32 *bp;
1712
David Brazdil0f672f62019-12-10 10:32:29 +00001713 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1714 return yfs_fs_extend_lock(fc, scb);
1715
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001716 _enter("");
1717
1718 call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1719 if (!call)
1720 return -ENOMEM;
1721
1722 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +00001723 call->lvnode = vnode;
1724 call->out_scb = scb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001725
1726 /* marshall the parameters */
1727 bp = call->request;
1728 *bp++ = htonl(FSEXTENDLOCK);
1729 *bp++ = htonl(vnode->fid.vid);
1730 *bp++ = htonl(vnode->fid.vnode);
1731 *bp++ = htonl(vnode->fid.unique);
1732
1733 afs_use_fs_server(call, fc->cbi);
1734 trace_afs_make_fs_call(call, &vnode->fid);
David Brazdil0f672f62019-12-10 10:32:29 +00001735 afs_set_fc_call(call, fc);
1736 afs_make_call(&fc->ac, call, GFP_NOFS);
1737 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001738}
1739
1740/*
1741 * release a lock on a file
1742 */
David Brazdil0f672f62019-12-10 10:32:29 +00001743int afs_fs_release_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001744{
1745 struct afs_vnode *vnode = fc->vnode;
1746 struct afs_call *call;
1747 struct afs_net *net = afs_v2net(vnode);
1748 __be32 *bp;
1749
David Brazdil0f672f62019-12-10 10:32:29 +00001750 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1751 return yfs_fs_release_lock(fc, scb);
1752
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001753 _enter("");
1754
1755 call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1756 if (!call)
1757 return -ENOMEM;
1758
1759 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +00001760 call->lvnode = vnode;
1761 call->out_scb = scb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001762
1763 /* marshall the parameters */
1764 bp = call->request;
1765 *bp++ = htonl(FSRELEASELOCK);
1766 *bp++ = htonl(vnode->fid.vid);
1767 *bp++ = htonl(vnode->fid.vnode);
1768 *bp++ = htonl(vnode->fid.unique);
1769
1770 afs_use_fs_server(call, fc->cbi);
1771 trace_afs_make_fs_call(call, &vnode->fid);
David Brazdil0f672f62019-12-10 10:32:29 +00001772 afs_set_fc_call(call, fc);
1773 afs_make_call(&fc->ac, call, GFP_NOFS);
1774 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001775}
1776
1777/*
1778 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1779 */
1780static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1781{
1782 return afs_transfer_reply(call);
1783}
1784
1785/*
1786 * FS.GiveUpAllCallBacks operation type
1787 */
1788static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1789 .name = "FS.GiveUpAllCallBacks",
1790 .op = afs_FS_GiveUpAllCallBacks,
1791 .deliver = afs_deliver_fs_give_up_all_callbacks,
1792 .destructor = afs_flat_call_destructor,
1793};
1794
1795/*
1796 * Flush all the callbacks we have on a server.
1797 */
1798int afs_fs_give_up_all_callbacks(struct afs_net *net,
1799 struct afs_server *server,
1800 struct afs_addr_cursor *ac,
1801 struct key *key)
1802{
1803 struct afs_call *call;
1804 __be32 *bp;
1805
1806 _enter("");
1807
1808 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1809 if (!call)
1810 return -ENOMEM;
1811
1812 call->key = key;
1813
1814 /* marshall the parameters */
1815 bp = call->request;
1816 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1817
1818 /* Can't take a ref on server */
David Brazdil0f672f62019-12-10 10:32:29 +00001819 afs_make_call(ac, call, GFP_NOFS);
1820 return afs_wait_for_call_to_complete(call, ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001821}
1822
1823/*
1824 * Deliver reply data to an FS.GetCapabilities operation.
1825 */
1826static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1827{
1828 u32 count;
1829 int ret;
1830
David Brazdil0f672f62019-12-10 10:32:29 +00001831 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(&call->iter));
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001832
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001833 switch (call->unmarshall) {
1834 case 0:
David Brazdil0f672f62019-12-10 10:32:29 +00001835 afs_extract_to_tmp(call);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001836 call->unmarshall++;
David Brazdil0f672f62019-12-10 10:32:29 +00001837 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001838
1839 /* Extract the capabilities word count */
1840 case 1:
David Brazdil0f672f62019-12-10 10:32:29 +00001841 ret = afs_extract_data(call, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001842 if (ret < 0)
1843 return ret;
1844
1845 count = ntohl(call->tmp);
1846
1847 call->count = count;
1848 call->count2 = count;
David Brazdil0f672f62019-12-10 10:32:29 +00001849 afs_extract_discard(call, count * sizeof(__be32));
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001850 call->unmarshall++;
David Brazdil0f672f62019-12-10 10:32:29 +00001851 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001852
1853 /* Extract capabilities words */
1854 case 2:
David Brazdil0f672f62019-12-10 10:32:29 +00001855 ret = afs_extract_data(call, false);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001856 if (ret < 0)
1857 return ret;
1858
1859 /* TODO: Examine capabilities */
1860
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001861 call->unmarshall++;
1862 break;
1863 }
1864
1865 _leave(" = 0 [done]");
1866 return 0;
1867}
1868
1869/*
1870 * FS.GetCapabilities operation type
1871 */
1872static const struct afs_call_type afs_RXFSGetCapabilities = {
1873 .name = "FS.GetCapabilities",
1874 .op = afs_FS_GetCapabilities,
1875 .deliver = afs_deliver_fs_get_capabilities,
David Brazdil0f672f62019-12-10 10:32:29 +00001876 .done = afs_fileserver_probe_result,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001877 .destructor = afs_flat_call_destructor,
1878};
1879
1880/*
1881 * Probe a fileserver for the capabilities that it supports. This can
1882 * return up to 196 words.
1883 */
David Brazdil0f672f62019-12-10 10:32:29 +00001884struct afs_call *afs_fs_get_capabilities(struct afs_net *net,
1885 struct afs_server *server,
1886 struct afs_addr_cursor *ac,
1887 struct key *key,
1888 unsigned int server_index)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001889{
1890 struct afs_call *call;
1891 __be32 *bp;
1892
1893 _enter("");
1894
1895 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1896 if (!call)
David Brazdil0f672f62019-12-10 10:32:29 +00001897 return ERR_PTR(-ENOMEM);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001898
1899 call->key = key;
David Brazdil0f672f62019-12-10 10:32:29 +00001900 call->server = afs_get_server(server, afs_server_trace_get_caps);
1901 call->server_index = server_index;
1902 call->upgrade = true;
1903 call->async = true;
1904 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001905
1906 /* marshall the parameters */
1907 bp = call->request;
1908 *bp++ = htonl(FSGETCAPABILITIES);
1909
1910 /* Can't take a ref on server */
1911 trace_afs_make_fs_call(call, NULL);
David Brazdil0f672f62019-12-10 10:32:29 +00001912 afs_make_call(ac, call, GFP_NOFS);
1913 return call;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001914}
1915
1916/*
1917 * Deliver reply data to an FS.FetchStatus with no vnode.
1918 */
1919static int afs_deliver_fs_fetch_status(struct afs_call *call)
1920{
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001921 const __be32 *bp;
1922 int ret;
1923
1924 ret = afs_transfer_reply(call);
1925 if (ret < 0)
1926 return ret;
1927
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001928 /* unmarshall the reply once we've received all of it */
1929 bp = call->buffer;
Olivier Deprez0e641232021-09-23 10:07:05 +02001930 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Brazdil0f672f62019-12-10 10:32:29 +00001931 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
1932 xdr_decode_AFSVolSync(&bp, call->out_volsync);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001933
1934 _leave(" = 0 [done]");
1935 return 0;
1936}
1937
1938/*
1939 * FS.FetchStatus operation type
1940 */
1941static const struct afs_call_type afs_RXFSFetchStatus = {
1942 .name = "FS.FetchStatus",
1943 .op = afs_FS_FetchStatus,
1944 .deliver = afs_deliver_fs_fetch_status,
1945 .destructor = afs_flat_call_destructor,
1946};
1947
1948/*
1949 * Fetch the status information for a fid without needing a vnode handle.
1950 */
1951int afs_fs_fetch_status(struct afs_fs_cursor *fc,
1952 struct afs_net *net,
1953 struct afs_fid *fid,
David Brazdil0f672f62019-12-10 10:32:29 +00001954 struct afs_status_cb *scb,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001955 struct afs_volsync *volsync)
1956{
1957 struct afs_call *call;
1958 __be32 *bp;
1959
David Brazdil0f672f62019-12-10 10:32:29 +00001960 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1961 return yfs_fs_fetch_status(fc, net, fid, scb, volsync);
1962
1963 _enter(",%x,{%llx:%llu},,",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001964 key_serial(fc->key), fid->vid, fid->vnode);
1965
1966 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
1967 if (!call) {
1968 fc->ac.error = -ENOMEM;
1969 return -ENOMEM;
1970 }
1971
1972 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +00001973 call->out_fid = fid;
1974 call->out_scb = scb;
1975 call->out_volsync = volsync;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001976
1977 /* marshall the parameters */
1978 bp = call->request;
1979 bp[0] = htonl(FSFETCHSTATUS);
1980 bp[1] = htonl(fid->vid);
1981 bp[2] = htonl(fid->vnode);
1982 bp[3] = htonl(fid->unique);
1983
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001984 afs_use_fs_server(call, fc->cbi);
1985 trace_afs_make_fs_call(call, fid);
David Brazdil0f672f62019-12-10 10:32:29 +00001986 afs_set_fc_call(call, fc);
1987 afs_make_call(&fc->ac, call, GFP_NOFS);
1988 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001989}
1990
1991/*
1992 * Deliver reply data to an FS.InlineBulkStatus call
1993 */
1994static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
1995{
David Brazdil0f672f62019-12-10 10:32:29 +00001996 struct afs_status_cb *scb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001997 const __be32 *bp;
1998 u32 tmp;
1999 int ret;
2000
2001 _enter("{%u}", call->unmarshall);
2002
2003 switch (call->unmarshall) {
2004 case 0:
David Brazdil0f672f62019-12-10 10:32:29 +00002005 afs_extract_to_tmp(call);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002006 call->unmarshall++;
David Brazdil0f672f62019-12-10 10:32:29 +00002007 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002008
2009 /* Extract the file status count and array in two steps */
2010 case 1:
2011 _debug("extract status count");
David Brazdil0f672f62019-12-10 10:32:29 +00002012 ret = afs_extract_data(call, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002013 if (ret < 0)
2014 return ret;
2015
2016 tmp = ntohl(call->tmp);
2017 _debug("status count: %u/%u", tmp, call->count2);
2018 if (tmp != call->count2)
David Brazdil0f672f62019-12-10 10:32:29 +00002019 return afs_protocol_error(call, -EBADMSG,
2020 afs_eproto_ibulkst_count);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002021
2022 call->count = 0;
2023 call->unmarshall++;
2024 more_counts:
David Brazdil0f672f62019-12-10 10:32:29 +00002025 afs_extract_to_buf(call, 21 * sizeof(__be32));
2026 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002027
2028 case 2:
2029 _debug("extract status array %u", call->count);
David Brazdil0f672f62019-12-10 10:32:29 +00002030 ret = afs_extract_data(call, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002031 if (ret < 0)
2032 return ret;
2033
2034 bp = call->buffer;
David Brazdil0f672f62019-12-10 10:32:29 +00002035 scb = &call->out_scb[call->count];
Olivier Deprez0e641232021-09-23 10:07:05 +02002036 xdr_decode_AFSFetchStatus(&bp, call, scb);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002037 call->count++;
2038 if (call->count < call->count2)
2039 goto more_counts;
2040
2041 call->count = 0;
2042 call->unmarshall++;
David Brazdil0f672f62019-12-10 10:32:29 +00002043 afs_extract_to_tmp(call);
2044 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002045
2046 /* Extract the callback count and array in two steps */
2047 case 3:
2048 _debug("extract CB count");
David Brazdil0f672f62019-12-10 10:32:29 +00002049 ret = afs_extract_data(call, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002050 if (ret < 0)
2051 return ret;
2052
2053 tmp = ntohl(call->tmp);
2054 _debug("CB count: %u", tmp);
2055 if (tmp != call->count2)
David Brazdil0f672f62019-12-10 10:32:29 +00002056 return afs_protocol_error(call, -EBADMSG,
2057 afs_eproto_ibulkst_cb_count);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002058 call->count = 0;
2059 call->unmarshall++;
2060 more_cbs:
David Brazdil0f672f62019-12-10 10:32:29 +00002061 afs_extract_to_buf(call, 3 * sizeof(__be32));
2062 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002063
2064 case 4:
2065 _debug("extract CB array");
David Brazdil0f672f62019-12-10 10:32:29 +00002066 ret = afs_extract_data(call, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002067 if (ret < 0)
2068 return ret;
2069
2070 _debug("unmarshall CB array");
2071 bp = call->buffer;
David Brazdil0f672f62019-12-10 10:32:29 +00002072 scb = &call->out_scb[call->count];
2073 xdr_decode_AFSCallBack(&bp, call, scb);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002074 call->count++;
2075 if (call->count < call->count2)
2076 goto more_cbs;
2077
David Brazdil0f672f62019-12-10 10:32:29 +00002078 afs_extract_to_buf(call, 6 * sizeof(__be32));
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002079 call->unmarshall++;
David Brazdil0f672f62019-12-10 10:32:29 +00002080 /* Fall through */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002081
2082 case 5:
David Brazdil0f672f62019-12-10 10:32:29 +00002083 ret = afs_extract_data(call, false);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002084 if (ret < 0)
2085 return ret;
2086
2087 bp = call->buffer;
David Brazdil0f672f62019-12-10 10:32:29 +00002088 xdr_decode_AFSVolSync(&bp, call->out_volsync);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002089
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002090 call->unmarshall++;
2091
2092 case 6:
2093 break;
2094 }
2095
2096 _leave(" = 0 [done]");
2097 return 0;
2098}
2099
2100/*
2101 * FS.InlineBulkStatus operation type
2102 */
2103static const struct afs_call_type afs_RXFSInlineBulkStatus = {
2104 .name = "FS.InlineBulkStatus",
2105 .op = afs_FS_InlineBulkStatus,
2106 .deliver = afs_deliver_fs_inline_bulk_status,
2107 .destructor = afs_flat_call_destructor,
2108};
2109
2110/*
2111 * Fetch the status information for up to 50 files
2112 */
2113int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2114 struct afs_net *net,
2115 struct afs_fid *fids,
David Brazdil0f672f62019-12-10 10:32:29 +00002116 struct afs_status_cb *statuses,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002117 unsigned int nr_fids,
2118 struct afs_volsync *volsync)
2119{
2120 struct afs_call *call;
2121 __be32 *bp;
2122 int i;
2123
David Brazdil0f672f62019-12-10 10:32:29 +00002124 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2125 return yfs_fs_inline_bulk_status(fc, net, fids, statuses,
2126 nr_fids, volsync);
2127
2128 _enter(",%x,{%llx:%llu},%u",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002129 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2130
2131 call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
2132 (2 + nr_fids * 3) * 4,
2133 21 * 4);
2134 if (!call) {
2135 fc->ac.error = -ENOMEM;
2136 return -ENOMEM;
2137 }
2138
2139 call->key = fc->key;
David Brazdil0f672f62019-12-10 10:32:29 +00002140 call->out_scb = statuses;
2141 call->out_volsync = volsync;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002142 call->count2 = nr_fids;
2143
2144 /* marshall the parameters */
2145 bp = call->request;
2146 *bp++ = htonl(FSINLINEBULKSTATUS);
2147 *bp++ = htonl(nr_fids);
2148 for (i = 0; i < nr_fids; i++) {
2149 *bp++ = htonl(fids[i].vid);
2150 *bp++ = htonl(fids[i].vnode);
2151 *bp++ = htonl(fids[i].unique);
2152 }
2153
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002154 afs_use_fs_server(call, fc->cbi);
2155 trace_afs_make_fs_call(call, &fids[0]);
David Brazdil0f672f62019-12-10 10:32:29 +00002156 afs_set_fc_call(call, fc);
2157 afs_make_call(&fc->ac, call, GFP_NOFS);
2158 return afs_wait_for_call_to_complete(call, &fc->ac);
2159}
2160
2161/*
2162 * deliver reply data to an FS.FetchACL
2163 */
2164static int afs_deliver_fs_fetch_acl(struct afs_call *call)
2165{
2166 struct afs_acl *acl;
2167 const __be32 *bp;
2168 unsigned int size;
2169 int ret;
2170
2171 _enter("{%u}", call->unmarshall);
2172
2173 switch (call->unmarshall) {
2174 case 0:
2175 afs_extract_to_tmp(call);
2176 call->unmarshall++;
2177 /* Fall through */
2178
2179 /* extract the returned data length */
2180 case 1:
2181 ret = afs_extract_data(call, true);
2182 if (ret < 0)
2183 return ret;
2184
2185 size = call->count2 = ntohl(call->tmp);
2186 size = round_up(size, 4);
2187
2188 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2189 if (!acl)
2190 return -ENOMEM;
2191 call->ret_acl = acl;
2192 acl->size = call->count2;
2193 afs_extract_begin(call, acl->data, size);
2194 call->unmarshall++;
2195 /* Fall through */
2196
2197 /* extract the returned data */
2198 case 2:
2199 ret = afs_extract_data(call, true);
2200 if (ret < 0)
2201 return ret;
2202
2203 afs_extract_to_buf(call, (21 + 6) * 4);
2204 call->unmarshall++;
2205 /* Fall through */
2206
2207 /* extract the metadata */
2208 case 3:
2209 ret = afs_extract_data(call, false);
2210 if (ret < 0)
2211 return ret;
2212
2213 bp = call->buffer;
Olivier Deprez0e641232021-09-23 10:07:05 +02002214 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Brazdil0f672f62019-12-10 10:32:29 +00002215 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2216
2217 call->unmarshall++;
2218
2219 case 4:
2220 break;
2221 }
2222
2223 _leave(" = 0 [done]");
2224 return 0;
2225}
2226
2227static void afs_destroy_fs_fetch_acl(struct afs_call *call)
2228{
2229 kfree(call->ret_acl);
2230 afs_flat_call_destructor(call);
2231}
2232
2233/*
2234 * FS.FetchACL operation type
2235 */
2236static const struct afs_call_type afs_RXFSFetchACL = {
2237 .name = "FS.FetchACL",
2238 .op = afs_FS_FetchACL,
2239 .deliver = afs_deliver_fs_fetch_acl,
2240 .destructor = afs_destroy_fs_fetch_acl,
2241};
2242
2243/*
2244 * Fetch the ACL for a file.
2245 */
2246struct afs_acl *afs_fs_fetch_acl(struct afs_fs_cursor *fc,
2247 struct afs_status_cb *scb)
2248{
2249 struct afs_vnode *vnode = fc->vnode;
2250 struct afs_call *call;
2251 struct afs_net *net = afs_v2net(vnode);
2252 __be32 *bp;
2253
2254 _enter(",%x,{%llx:%llu},,",
2255 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2256
2257 call = afs_alloc_flat_call(net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2258 if (!call) {
2259 fc->ac.error = -ENOMEM;
2260 return ERR_PTR(-ENOMEM);
2261 }
2262
2263 call->key = fc->key;
2264 call->ret_acl = NULL;
2265 call->out_scb = scb;
2266 call->out_volsync = NULL;
2267
2268 /* marshall the parameters */
2269 bp = call->request;
2270 bp[0] = htonl(FSFETCHACL);
2271 bp[1] = htonl(vnode->fid.vid);
2272 bp[2] = htonl(vnode->fid.vnode);
2273 bp[3] = htonl(vnode->fid.unique);
2274
2275 afs_use_fs_server(call, fc->cbi);
2276 trace_afs_make_fs_call(call, &vnode->fid);
2277 afs_make_call(&fc->ac, call, GFP_KERNEL);
2278 return (struct afs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2279}
2280
2281/*
2282 * Deliver reply data to any operation that returns file status and volume
2283 * sync.
2284 */
2285static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
2286{
2287 const __be32 *bp;
2288 int ret;
2289
2290 ret = afs_transfer_reply(call);
2291 if (ret < 0)
2292 return ret;
2293
2294 bp = call->buffer;
Olivier Deprez0e641232021-09-23 10:07:05 +02002295 xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
David Brazdil0f672f62019-12-10 10:32:29 +00002296 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2297
2298 _leave(" = 0 [done]");
2299 return 0;
2300}
2301
2302/*
2303 * FS.StoreACL operation type
2304 */
2305static const struct afs_call_type afs_RXFSStoreACL = {
2306 .name = "FS.StoreACL",
2307 .op = afs_FS_StoreACL,
2308 .deliver = afs_deliver_fs_file_status_and_vol,
2309 .destructor = afs_flat_call_destructor,
2310};
2311
2312/*
2313 * Fetch the ACL for a file.
2314 */
2315int afs_fs_store_acl(struct afs_fs_cursor *fc, const struct afs_acl *acl,
2316 struct afs_status_cb *scb)
2317{
2318 struct afs_vnode *vnode = fc->vnode;
2319 struct afs_call *call;
2320 struct afs_net *net = afs_v2net(vnode);
2321 size_t size;
2322 __be32 *bp;
2323
2324 _enter(",%x,{%llx:%llu},,",
2325 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2326
2327 size = round_up(acl->size, 4);
2328 call = afs_alloc_flat_call(net, &afs_RXFSStoreACL,
2329 5 * 4 + size, (21 + 6) * 4);
2330 if (!call) {
2331 fc->ac.error = -ENOMEM;
2332 return -ENOMEM;
2333 }
2334
2335 call->key = fc->key;
2336 call->out_scb = scb;
2337 call->out_volsync = NULL;
2338
2339 /* marshall the parameters */
2340 bp = call->request;
2341 bp[0] = htonl(FSSTOREACL);
2342 bp[1] = htonl(vnode->fid.vid);
2343 bp[2] = htonl(vnode->fid.vnode);
2344 bp[3] = htonl(vnode->fid.unique);
2345 bp[4] = htonl(acl->size);
2346 memcpy(&bp[5], acl->data, acl->size);
2347 if (acl->size != size)
2348 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2349
2350 trace_afs_make_fs_call(call, &vnode->fid);
2351 afs_make_call(&fc->ac, call, GFP_KERNEL);
2352 return afs_wait_for_call_to_complete(call, &fc->ac);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002353}