Merge tag 'pm-6.10-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
[linux-2.6-block.git] / fs / afs / fsclient.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
08e0e7c8 2/* AFS File Server client stubs
1da177e4 3 *
08e0e7c8 4 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
1da177e4 5 * Written by David Howells (dhowells@redhat.com)
1da177e4
LT
6 */
7
8#include <linux/init.h>
5a0e3ad6 9#include <linux/slab.h>
1da177e4 10#include <linux/sched.h>
08e0e7c8 11#include <linux/circ_buf.h>
a01179e6 12#include <linux/iversion.h>
5cbf0398 13#include <linux/netfs.h>
1da177e4 14#include "internal.h"
08e0e7c8 15#include "afs_fs.h"
dd9fbcb8 16#include "xdr_fs.h"
c435ee34 17
260a9803
DH
18/*
19 * decode an AFSFid block
20 */
21static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
22{
23 const __be32 *bp = *_bp;
24
25 fid->vid = ntohl(*bp++);
26 fid->vnode = ntohl(*bp++);
27 fid->unique = ntohl(*bp++);
28 *_bp = bp;
29}
30
888b3384
DH
31/*
32 * Dump a bad file status record.
33 */
34static void xdr_dump_bad(const __be32 *bp)
35{
36 __be32 x[4];
37 int i;
38
39 pr_notice("AFS XDR: Bad status record\n");
40 for (i = 0; i < 5 * 4 * 4; i += 16) {
41 memcpy(x, bp, 16);
42 bp += 4;
43 pr_notice("%03x: %08x %08x %08x %08x\n",
44 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
45 }
46
47 memcpy(x, bp, 4);
48 pr_notice("0x50: %08x\n", ntohl(x[0]));
49}
50
dd9fbcb8
DH
51/*
52 * decode an AFSFetchStatus block
53 */
38355eec
DH
54static void xdr_decode_AFSFetchStatus(const __be32 **_bp,
55 struct afs_call *call,
56 struct afs_status_cb *scb)
dd9fbcb8
DH
57{
58 const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
a58823ac 59 struct afs_file_status *status = &scb->status;
684b0f68 60 bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
260a9803 61 u64 data_version, size;
dd9fbcb8 62 u32 type, abort_code;
c435ee34 63
684b0f68
DH
64 abort_code = ntohl(xdr->abort_code);
65
dd9fbcb8 66 if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
684b0f68
DH
67 if (xdr->if_version == htonl(0) &&
68 abort_code != 0 &&
69 inline_error) {
70 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
71 * whereby it doesn't set the interface version in the error
72 * case.
73 */
74 status->abort_code = abort_code;
a38a7558 75 scb->have_error = true;
38355eec 76 goto advance;
684b0f68
DH
77 }
78
dd9fbcb8
DH
79 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
80 goto bad;
81 }
08e0e7c8 82
684b0f68
DH
83 if (abort_code != 0 && inline_error) {
84 status->abort_code = abort_code;
3e0d9892 85 scb->have_error = true;
38355eec 86 goto advance;
684b0f68
DH
87 }
88
dd9fbcb8 89 type = ntohl(xdr->type);
dd9fbcb8 90 switch (type) {
888b3384
DH
91 case AFS_FTYPE_FILE:
92 case AFS_FTYPE_DIR:
93 case AFS_FTYPE_SYMLINK:
dd9fbcb8 94 status->type = type;
888b3384 95 break;
888b3384 96 default:
dd9fbcb8 97 goto bad;
888b3384
DH
98 }
99
a58823ac
DH
100 status->nlink = ntohl(xdr->nlink);
101 status->author = ntohl(xdr->author);
102 status->owner = ntohl(xdr->owner);
103 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
104 status->anon_access = ntohl(xdr->anon_access);
105 status->mode = ntohl(xdr->mode) & S_IALLUGO;
106 status->group = ntohl(xdr->group);
107 status->lock_count = ntohl(xdr->lock_count);
dd9fbcb8 108
d4936803
DH
109 status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
110 status->mtime_client.tv_nsec = 0;
111 status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
112 status->mtime_server.tv_nsec = 0;
dd9fbcb8
DH
113
114 size = (u64)ntohl(xdr->size_lo);
115 size |= (u64)ntohl(xdr->size_hi) << 32;
63a4681f 116 status->size = size;
dd9fbcb8
DH
117
118 data_version = (u64)ntohl(xdr->data_version_lo);
119 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
a58823ac 120 status->data_version = data_version;
a38a7558 121 scb->have_status = true;
c72057b5 122advance:
dd9fbcb8 123 *_bp = (const void *)*_bp + sizeof(*xdr);
38355eec 124 return;
dd9fbcb8
DH
125
126bad:
127 xdr_dump_bad(*_bp);
7126ead9 128 afs_protocol_error(call, afs_eproto_bad_status);
c72057b5 129 goto advance;
c875c76a
DH
130}
131
78107055
DH
132static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
133{
7903192c 134 return ktime_divns(call->issue_time, NSEC_PER_SEC) + expiry;
78107055
DH
135}
136
a58823ac
DH
137static void xdr_decode_AFSCallBack(const __be32 **_bp,
138 struct afs_call *call,
139 struct afs_status_cb *scb)
78107055 140{
a58823ac 141 struct afs_callback *cb = &scb->callback;
78107055
DH
142 const __be32 *bp = *_bp;
143
7c712458 144 bp++; /* version */
78107055 145 cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
7c712458 146 bp++; /* type */
a58823ac 147 scb->have_cb = true;
78107055
DH
148 *_bp = bp;
149}
150
1da177e4 151/*
08e0e7c8 152 * decode an AFSVolSync block
1da177e4 153 */
08e0e7c8
DH
154static void xdr_decode_AFSVolSync(const __be32 **_bp,
155 struct afs_volsync *volsync)
1da177e4 156{
08e0e7c8 157 const __be32 *bp = *_bp;
30062bd1 158 u32 creation;
1da177e4 159
30062bd1 160 creation = ntohl(*bp++);
08e0e7c8
DH
161 bp++; /* spare2 */
162 bp++; /* spare3 */
163 bp++; /* spare4 */
164 bp++; /* spare5 */
165 bp++; /* spare6 */
166 *_bp = bp;
30062bd1
DH
167
168 if (volsync)
169 volsync->creation = creation;
08e0e7c8 170}
1da177e4 171
31143d5d
DH
172/*
173 * encode the requested attributes into an AFSStoreStatus block
174 */
175static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
176{
177 __be32 *bp = *_bp;
178 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
179
180 mask = 0;
181 if (attr->ia_valid & ATTR_MTIME) {
182 mask |= AFS_SET_MTIME;
183 mtime = attr->ia_mtime.tv_sec;
184 }
185
186 if (attr->ia_valid & ATTR_UID) {
187 mask |= AFS_SET_OWNER;
a0a5386a 188 owner = from_kuid(&init_user_ns, attr->ia_uid);
31143d5d
DH
189 }
190
191 if (attr->ia_valid & ATTR_GID) {
192 mask |= AFS_SET_GROUP;
a0a5386a 193 group = from_kgid(&init_user_ns, attr->ia_gid);
31143d5d
DH
194 }
195
196 if (attr->ia_valid & ATTR_MODE) {
197 mask |= AFS_SET_MODE;
198 mode = attr->ia_mode & S_IALLUGO;
199 }
200
201 *bp++ = htonl(mask);
202 *bp++ = htonl(mtime);
203 *bp++ = htonl(owner);
204 *bp++ = htonl(group);
205 *bp++ = htonl(mode);
206 *bp++ = 0; /* segment size */
207 *_bp = bp;
208}
209
45222b9e
DH
210/*
211 * decode an AFSFetchVolumeStatus block
212 */
213static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
214 struct afs_volume_status *vs)
215{
216 const __be32 *bp = *_bp;
217
218 vs->vid = ntohl(*bp++);
219 vs->parent_id = ntohl(*bp++);
220 vs->online = ntohl(*bp++);
221 vs->in_service = ntohl(*bp++);
222 vs->blessed = ntohl(*bp++);
223 vs->needs_salvage = ntohl(*bp++);
224 vs->type = ntohl(*bp++);
225 vs->min_quota = ntohl(*bp++);
226 vs->max_quota = ntohl(*bp++);
227 vs->blocks_in_use = ntohl(*bp++);
228 vs->part_blocks_avail = ntohl(*bp++);
229 vs->part_max_blocks = ntohl(*bp++);
30062bd1
DH
230 vs->vol_copy_date = 0;
231 vs->vol_backup_date = 0;
45222b9e
DH
232 *_bp = bp;
233}
234
08e0e7c8
DH
235/*
236 * deliver reply data to an FS.FetchStatus
237 */
e49c7b2f 238static int afs_deliver_fs_fetch_status(struct afs_call *call)
08e0e7c8 239{
e49c7b2f
DH
240 struct afs_operation *op = call->op;
241 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
08e0e7c8 242 const __be32 *bp;
372ee163 243 int ret;
1da177e4 244
d001648e 245 ret = afs_transfer_reply(call);
372ee163
DH
246 if (ret < 0)
247 return ret;
1da177e4 248
08e0e7c8
DH
249 /* unmarshall the reply once we've received all of it */
250 bp = call->buffer;
e49c7b2f
DH
251 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
252 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
253 xdr_decode_AFSVolSync(&bp, &op->volsync);
1da177e4 254
08e0e7c8
DH
255 _leave(" = 0 [done]");
256 return 0;
ec26815a 257}
08e0e7c8
DH
258
259/*
260 * FS.FetchStatus operation type
261 */
e49c7b2f
DH
262static const struct afs_call_type afs_RXFSFetchStatus = {
263 .name = "FS.FetchStatus",
025db80c 264 .op = afs_FS_FetchStatus,
e49c7b2f 265 .deliver = afs_deliver_fs_fetch_status,
08e0e7c8
DH
266 .destructor = afs_flat_call_destructor,
267};
1da177e4 268
1da177e4
LT
269/*
270 * fetch the status information for a file
271 */
e49c7b2f 272void afs_fs_fetch_status(struct afs_operation *op)
1da177e4 273{
e49c7b2f 274 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
08e0e7c8 275 struct afs_call *call;
1da177e4
LT
276 __be32 *bp;
277
3b6492df 278 _enter(",%x,{%llx:%llu},,",
e49c7b2f 279 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1da177e4 280
e49c7b2f 281 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchStatus,
5cf9dd55 282 16, (21 + 3 + 6) * 4);
e49c7b2f
DH
283 if (!call)
284 return afs_op_nomem(op);
1da177e4
LT
285
286 /* marshall the parameters */
08e0e7c8 287 bp = call->request;
1da177e4 288 bp[0] = htonl(FSFETCHSTATUS);
e49c7b2f
DH
289 bp[1] = htonl(vp->fid.vid);
290 bp[2] = htonl(vp->fid.vnode);
291 bp[3] = htonl(vp->fid.unique);
1da177e4 292
abcbd3bf 293 call->fid = vp->fid;
e49c7b2f
DH
294 trace_afs_make_fs_call(call, &vp->fid);
295 afs_make_op_call(op, call, GFP_NOFS);
ec26815a 296}
1da177e4 297
1da177e4 298/*
08e0e7c8 299 * deliver reply data to an FS.FetchData
1da177e4 300 */
d001648e 301static int afs_deliver_fs_fetch_data(struct afs_call *call)
1da177e4 302{
e49c7b2f
DH
303 struct afs_operation *op = call->op;
304 struct afs_vnode_param *vp = &op->file[0];
305 struct afs_read *req = op->fetch.req;
08e0e7c8 306 const __be32 *bp;
1da177e4 307 int ret;
1da177e4 308
f105da1a
DH
309 _enter("{%u,%zu,%zu/%llu}",
310 call->unmarshall, call->iov_len, iov_iter_count(call->iter),
311 req->actual_len);
08e0e7c8
DH
312
313 switch (call->unmarshall) {
314 case 0:
196ee9cd 315 req->actual_len = 0;
08e0e7c8 316 call->unmarshall++;
12bdcf33
DH
317 if (call->operation_ID == FSFETCHDATA64) {
318 afs_extract_to_tmp64(call);
319 } else {
320 call->tmp_u = htonl(0);
321 afs_extract_to_tmp(call);
b9b1f8d5 322 }
df561f66 323 fallthrough;
08e0e7c8 324
c4508464
DH
325 /* Extract the returned data length into
326 * ->actual_len. This may indicate more or less data than was
327 * requested will be returned.
328 */
12bdcf33 329 case 1:
08e0e7c8 330 _debug("extract data length");
12bdcf33 331 ret = afs_extract_data(call, true);
372ee163
DH
332 if (ret < 0)
333 return ret;
1da177e4 334
12bdcf33 335 req->actual_len = be64_to_cpu(call->tmp64);
196ee9cd 336 _debug("DATA length: %llu", req->actual_len);
c4508464
DH
337
338 if (req->actual_len == 0)
196ee9cd 339 goto no_more_data;
12bdcf33 340
c4508464
DH
341 call->iter = req->iter;
342 call->iov_len = min(req->actual_len, req->len);
08e0e7c8 343 call->unmarshall++;
df561f66 344 fallthrough;
196ee9cd 345
29881608 346 /* extract the returned data */
12bdcf33
DH
347 case 2:
348 _debug("extract data %zu/%llu",
c4508464 349 iov_iter_count(call->iter), req->actual_len);
196ee9cd 350
12bdcf33 351 ret = afs_extract_data(call, true);
196ee9cd
DH
352 if (ret < 0)
353 return ret;
12bdcf33 354
c4508464 355 call->iter = &call->def_iter;
12bdcf33
DH
356 if (req->actual_len <= req->len)
357 goto no_more_data;
6db3ac3c
DH
358
359 /* Discard any excess data the server gave us */
23a28913 360 afs_extract_discard(call, req->actual_len - req->len);
12bdcf33 361 call->unmarshall = 3;
df561f66 362 fallthrough;
29881608 363
12bdcf33
DH
364 case 3:
365 _debug("extract discard %zu/%llu",
fc276122 366 iov_iter_count(call->iter), req->actual_len - req->len);
12bdcf33
DH
367
368 ret = afs_extract_data(call, true);
6db3ac3c
DH
369 if (ret < 0)
370 return ret;
1da177e4 371
196ee9cd 372 no_more_data:
12bdcf33
DH
373 call->unmarshall = 4;
374 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
df561f66 375 fallthrough;
1da177e4 376
29881608 377 /* extract the metadata */
12bdcf33
DH
378 case 4:
379 ret = afs_extract_data(call, false);
372ee163
DH
380 if (ret < 0)
381 return ret;
08e0e7c8
DH
382
383 bp = call->buffer;
e49c7b2f
DH
384 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
385 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
386 xdr_decode_AFSVolSync(&bp, &op->volsync);
08e0e7c8 387
e49c7b2f
DH
388 req->data_version = vp->scb.status.data_version;
389 req->file_size = vp->scb.status.size;
a58823ac 390
08e0e7c8 391 call->unmarshall++;
b2db6c35 392 fallthrough;
1da177e4 393
12bdcf33 394 case 5:
08e0e7c8 395 break;
1da177e4
LT
396 }
397
08e0e7c8
DH
398 _leave(" = 0 [done]");
399 return 0;
ec26815a 400}
1da177e4 401
1da177e4 402/*
08e0e7c8 403 * FS.FetchData operation type
1da177e4 404 */
08e0e7c8 405static const struct afs_call_type afs_RXFSFetchData = {
00d3b7a4 406 .name = "FS.FetchData",
025db80c 407 .op = afs_FS_FetchData,
08e0e7c8 408 .deliver = afs_deliver_fs_fetch_data,
e49c7b2f 409 .destructor = afs_flat_call_destructor,
08e0e7c8
DH
410};
411
b9b1f8d5
DH
412static const struct afs_call_type afs_RXFSFetchData64 = {
413 .name = "FS.FetchData64",
025db80c 414 .op = afs_FS_FetchData64,
b9b1f8d5 415 .deliver = afs_deliver_fs_fetch_data,
e49c7b2f 416 .destructor = afs_flat_call_destructor,
b9b1f8d5
DH
417};
418
419/*
420 * fetch data from a very large file
421 */
e49c7b2f 422static void afs_fs_fetch_data64(struct afs_operation *op)
b9b1f8d5 423{
e49c7b2f
DH
424 struct afs_vnode_param *vp = &op->file[0];
425 struct afs_read *req = op->fetch.req;
b9b1f8d5
DH
426 struct afs_call *call;
427 __be32 *bp;
428
429 _enter("");
430
e49c7b2f 431 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
b9b1f8d5 432 if (!call)
e49c7b2f 433 return afs_op_nomem(op);
b9b1f8d5
DH
434
435 /* marshall the parameters */
436 bp = call->request;
437 bp[0] = htonl(FSFETCHDATA64);
e49c7b2f
DH
438 bp[1] = htonl(vp->fid.vid);
439 bp[2] = htonl(vp->fid.vnode);
440 bp[3] = htonl(vp->fid.unique);
196ee9cd
DH
441 bp[4] = htonl(upper_32_bits(req->pos));
442 bp[5] = htonl(lower_32_bits(req->pos));
b9b1f8d5 443 bp[6] = 0;
196ee9cd 444 bp[7] = htonl(lower_32_bits(req->len));
b9b1f8d5 445
abcbd3bf 446 call->fid = vp->fid;
e49c7b2f
DH
447 trace_afs_make_fs_call(call, &vp->fid);
448 afs_make_op_call(op, call, GFP_NOFS);
b9b1f8d5
DH
449}
450
08e0e7c8
DH
451/*
452 * fetch data from a file
453 */
e49c7b2f 454void afs_fs_fetch_data(struct afs_operation *op)
1da177e4 455{
e49c7b2f 456 struct afs_vnode_param *vp = &op->file[0];
08e0e7c8 457 struct afs_call *call;
e49c7b2f 458 struct afs_read *req = op->fetch.req;
1da177e4
LT
459 __be32 *bp;
460
b537a3c2 461 if (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
e49c7b2f 462 return afs_fs_fetch_data64(op);
b9b1f8d5 463
08e0e7c8 464 _enter("");
1da177e4 465
e49c7b2f 466 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
08e0e7c8 467 if (!call)
e49c7b2f 468 return afs_op_nomem(op);
1da177e4 469
c4508464
DH
470 req->call_debug_id = call->debug_id;
471
1da177e4 472 /* marshall the parameters */
08e0e7c8
DH
473 bp = call->request;
474 bp[0] = htonl(FSFETCHDATA);
e49c7b2f
DH
475 bp[1] = htonl(vp->fid.vid);
476 bp[2] = htonl(vp->fid.vnode);
477 bp[3] = htonl(vp->fid.unique);
196ee9cd
DH
478 bp[4] = htonl(lower_32_bits(req->pos));
479 bp[5] = htonl(lower_32_bits(req->len));
1da177e4 480
abcbd3bf 481 call->fid = vp->fid;
e49c7b2f
DH
482 trace_afs_make_fs_call(call, &vp->fid);
483 afs_make_op_call(op, call, GFP_NOFS);
ec26815a 484}
260a9803
DH
485
486/*
487 * deliver reply data to an FS.CreateFile or an FS.MakeDir
488 */
d001648e 489static int afs_deliver_fs_create_vnode(struct afs_call *call)
260a9803 490{
e49c7b2f
DH
491 struct afs_operation *op = call->op;
492 struct afs_vnode_param *dvp = &op->file[0];
493 struct afs_vnode_param *vp = &op->file[1];
260a9803 494 const __be32 *bp;
372ee163 495 int ret;
260a9803 496
d001648e 497 ret = afs_transfer_reply(call);
372ee163
DH
498 if (ret < 0)
499 return ret;
260a9803
DH
500
501 /* unmarshall the reply once we've received all of it */
502 bp = call->buffer;
e49c7b2f
DH
503 xdr_decode_AFSFid(&bp, &op->file[1].fid);
504 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
505 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
506 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
507 xdr_decode_AFSVolSync(&bp, &op->volsync);
260a9803
DH
508
509 _leave(" = 0 [done]");
510 return 0;
511}
512
513/*
514 * FS.CreateFile and FS.MakeDir operation type
515 */
025db80c
DH
516static const struct afs_call_type afs_RXFSCreateFile = {
517 .name = "FS.CreateFile",
518 .op = afs_FS_CreateFile,
519 .deliver = afs_deliver_fs_create_vnode,
520 .destructor = afs_flat_call_destructor,
521};
522
e49c7b2f
DH
523/*
524 * Create a file.
525 */
526void afs_fs_create_file(struct afs_operation *op)
527{
528 const struct qstr *name = &op->dentry->d_name;
529 struct afs_vnode_param *dvp = &op->file[0];
530 struct afs_call *call;
531 size_t namesz, reqsz, padsz;
532 __be32 *bp;
533
534 _enter("");
535
536 namesz = name->len;
537 padsz = (4 - (namesz & 3)) & 3;
538 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
539
540 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile,
541 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
542 if (!call)
543 return afs_op_nomem(op);
544
545 /* marshall the parameters */
546 bp = call->request;
547 *bp++ = htonl(FSCREATEFILE);
548 *bp++ = htonl(dvp->fid.vid);
549 *bp++ = htonl(dvp->fid.vnode);
550 *bp++ = htonl(dvp->fid.unique);
551 *bp++ = htonl(namesz);
552 memcpy(bp, name->name, namesz);
553 bp = (void *) bp + namesz;
554 if (padsz > 0) {
555 memset(bp, 0, padsz);
556 bp = (void *) bp + padsz;
557 }
558 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
559 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
560 *bp++ = 0; /* owner */
561 *bp++ = 0; /* group */
562 *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
563 *bp++ = 0; /* segment size */
564
abcbd3bf 565 call->fid = dvp->fid;
e49c7b2f
DH
566 trace_afs_make_fs_call1(call, &dvp->fid, name);
567 afs_make_op_call(op, call, GFP_NOFS);
568}
569
025db80c
DH
570static const struct afs_call_type afs_RXFSMakeDir = {
571 .name = "FS.MakeDir",
572 .op = afs_FS_MakeDir,
260a9803 573 .deliver = afs_deliver_fs_create_vnode,
260a9803
DH
574 .destructor = afs_flat_call_destructor,
575};
576
577/*
e49c7b2f 578 * Create a new directory
260a9803 579 */
e49c7b2f 580void afs_fs_make_dir(struct afs_operation *op)
260a9803 581{
e49c7b2f
DH
582 const struct qstr *name = &op->dentry->d_name;
583 struct afs_vnode_param *dvp = &op->file[0];
260a9803
DH
584 struct afs_call *call;
585 size_t namesz, reqsz, padsz;
586 __be32 *bp;
587
588 _enter("");
589
e49c7b2f 590 namesz = name->len;
260a9803
DH
591 padsz = (4 - (namesz & 3)) & 3;
592 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
593
e49c7b2f
DH
594 call = afs_alloc_flat_call(op->net, &afs_RXFSMakeDir,
595 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
260a9803 596 if (!call)
e49c7b2f 597 return afs_op_nomem(op);
260a9803
DH
598
599 /* marshall the parameters */
600 bp = call->request;
e49c7b2f
DH
601 *bp++ = htonl(FSMAKEDIR);
602 *bp++ = htonl(dvp->fid.vid);
603 *bp++ = htonl(dvp->fid.vnode);
604 *bp++ = htonl(dvp->fid.unique);
260a9803 605 *bp++ = htonl(namesz);
e49c7b2f 606 memcpy(bp, name->name, namesz);
260a9803
DH
607 bp = (void *) bp + namesz;
608 if (padsz > 0) {
609 memset(bp, 0, padsz);
610 bp = (void *) bp + padsz;
611 }
ab94f5d0 612 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
e49c7b2f 613 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
260a9803
DH
614 *bp++ = 0; /* owner */
615 *bp++ = 0; /* group */
e49c7b2f 616 *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
260a9803
DH
617 *bp++ = 0; /* segment size */
618
abcbd3bf 619 call->fid = dvp->fid;
e49c7b2f
DH
620 trace_afs_make_fs_call1(call, &dvp->fid, name);
621 afs_make_op_call(op, call, GFP_NOFS);
260a9803
DH
622}
623
624/*
e49c7b2f 625 * Deliver reply data to any operation that returns status and volume sync.
260a9803 626 */
e49c7b2f 627static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
260a9803 628{
e49c7b2f
DH
629 struct afs_operation *op = call->op;
630 struct afs_vnode_param *vp = &op->file[0];
260a9803 631 const __be32 *bp;
372ee163 632 int ret;
260a9803 633
d001648e 634 ret = afs_transfer_reply(call);
372ee163
DH
635 if (ret < 0)
636 return ret;
260a9803
DH
637
638 /* unmarshall the reply once we've received all of it */
639 bp = call->buffer;
e49c7b2f
DH
640 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
641 xdr_decode_AFSVolSync(&bp, &op->volsync);
260a9803
DH
642
643 _leave(" = 0 [done]");
644 return 0;
645}
646
647/*
e49c7b2f 648 * FS.RemoveFile operation type
260a9803 649 */
025db80c
DH
650static const struct afs_call_type afs_RXFSRemoveFile = {
651 .name = "FS.RemoveFile",
652 .op = afs_FS_RemoveFile,
e49c7b2f 653 .deliver = afs_deliver_fs_file_status_and_vol,
025db80c
DH
654 .destructor = afs_flat_call_destructor,
655};
656
e49c7b2f
DH
657/*
658 * Remove a file.
659 */
660void afs_fs_remove_file(struct afs_operation *op)
661{
662 const struct qstr *name = &op->dentry->d_name;
663 struct afs_vnode_param *dvp = &op->file[0];
664 struct afs_call *call;
665 size_t namesz, reqsz, padsz;
666 __be32 *bp;
667
668 _enter("");
669
670 namesz = name->len;
671 padsz = (4 - (namesz & 3)) & 3;
672 reqsz = (5 * 4) + namesz + padsz;
673
674 call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveFile,
675 reqsz, (21 + 6) * 4);
676 if (!call)
677 return afs_op_nomem(op);
678
679 /* marshall the parameters */
680 bp = call->request;
681 *bp++ = htonl(FSREMOVEFILE);
682 *bp++ = htonl(dvp->fid.vid);
683 *bp++ = htonl(dvp->fid.vnode);
684 *bp++ = htonl(dvp->fid.unique);
685 *bp++ = htonl(namesz);
686 memcpy(bp, name->name, namesz);
687 bp = (void *) bp + namesz;
688 if (padsz > 0) {
689 memset(bp, 0, padsz);
690 bp = (void *) bp + padsz;
691 }
692
abcbd3bf 693 call->fid = dvp->fid;
e49c7b2f
DH
694 trace_afs_make_fs_call1(call, &dvp->fid, name);
695 afs_make_op_call(op, call, GFP_NOFS);
696}
697
025db80c
DH
698static const struct afs_call_type afs_RXFSRemoveDir = {
699 .name = "FS.RemoveDir",
700 .op = afs_FS_RemoveDir,
e49c7b2f 701 .deliver = afs_deliver_fs_file_status_and_vol,
260a9803
DH
702 .destructor = afs_flat_call_destructor,
703};
704
705/*
e49c7b2f 706 * Remove a directory.
260a9803 707 */
e49c7b2f 708void afs_fs_remove_dir(struct afs_operation *op)
260a9803 709{
e49c7b2f
DH
710 const struct qstr *name = &op->dentry->d_name;
711 struct afs_vnode_param *dvp = &op->file[0];
260a9803
DH
712 struct afs_call *call;
713 size_t namesz, reqsz, padsz;
714 __be32 *bp;
715
716 _enter("");
717
e49c7b2f 718 namesz = name->len;
260a9803
DH
719 padsz = (4 - (namesz & 3)) & 3;
720 reqsz = (5 * 4) + namesz + padsz;
721
e49c7b2f
DH
722 call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveDir,
723 reqsz, (21 + 6) * 4);
260a9803 724 if (!call)
e49c7b2f 725 return afs_op_nomem(op);
260a9803
DH
726
727 /* marshall the parameters */
728 bp = call->request;
e49c7b2f
DH
729 *bp++ = htonl(FSREMOVEDIR);
730 *bp++ = htonl(dvp->fid.vid);
731 *bp++ = htonl(dvp->fid.vnode);
732 *bp++ = htonl(dvp->fid.unique);
260a9803 733 *bp++ = htonl(namesz);
e49c7b2f 734 memcpy(bp, name->name, namesz);
260a9803
DH
735 bp = (void *) bp + namesz;
736 if (padsz > 0) {
737 memset(bp, 0, padsz);
738 bp = (void *) bp + padsz;
739 }
740
abcbd3bf 741 call->fid = dvp->fid;
e49c7b2f
DH
742 trace_afs_make_fs_call1(call, &dvp->fid, name);
743 afs_make_op_call(op, call, GFP_NOFS);
260a9803
DH
744}
745
746/*
747 * deliver reply data to an FS.Link
748 */
d001648e 749static int afs_deliver_fs_link(struct afs_call *call)
260a9803 750{
e49c7b2f
DH
751 struct afs_operation *op = call->op;
752 struct afs_vnode_param *dvp = &op->file[0];
753 struct afs_vnode_param *vp = &op->file[1];
260a9803 754 const __be32 *bp;
372ee163 755 int ret;
260a9803 756
d001648e 757 _enter("{%u}", call->unmarshall);
260a9803 758
d001648e 759 ret = afs_transfer_reply(call);
372ee163
DH
760 if (ret < 0)
761 return ret;
260a9803
DH
762
763 /* unmarshall the reply once we've received all of it */
764 bp = call->buffer;
e49c7b2f
DH
765 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
766 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
767 xdr_decode_AFSVolSync(&bp, &op->volsync);
260a9803
DH
768
769 _leave(" = 0 [done]");
770 return 0;
771}
772
773/*
774 * FS.Link operation type
775 */
776static const struct afs_call_type afs_RXFSLink = {
777 .name = "FS.Link",
025db80c 778 .op = afs_FS_Link,
260a9803 779 .deliver = afs_deliver_fs_link,
260a9803
DH
780 .destructor = afs_flat_call_destructor,
781};
782
783/*
784 * make a hard link
785 */
e49c7b2f 786void afs_fs_link(struct afs_operation *op)
260a9803 787{
e49c7b2f
DH
788 const struct qstr *name = &op->dentry->d_name;
789 struct afs_vnode_param *dvp = &op->file[0];
790 struct afs_vnode_param *vp = &op->file[1];
260a9803
DH
791 struct afs_call *call;
792 size_t namesz, reqsz, padsz;
793 __be32 *bp;
794
795 _enter("");
796
e49c7b2f 797 namesz = name->len;
260a9803
DH
798 padsz = (4 - (namesz & 3)) & 3;
799 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
800
e49c7b2f 801 call = afs_alloc_flat_call(op->net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
260a9803 802 if (!call)
e49c7b2f 803 return afs_op_nomem(op);
260a9803
DH
804
805 /* marshall the parameters */
806 bp = call->request;
807 *bp++ = htonl(FSLINK);
e49c7b2f
DH
808 *bp++ = htonl(dvp->fid.vid);
809 *bp++ = htonl(dvp->fid.vnode);
810 *bp++ = htonl(dvp->fid.unique);
260a9803 811 *bp++ = htonl(namesz);
e49c7b2f 812 memcpy(bp, name->name, namesz);
260a9803
DH
813 bp = (void *) bp + namesz;
814 if (padsz > 0) {
815 memset(bp, 0, padsz);
816 bp = (void *) bp + padsz;
817 }
e49c7b2f
DH
818 *bp++ = htonl(vp->fid.vid);
819 *bp++ = htonl(vp->fid.vnode);
820 *bp++ = htonl(vp->fid.unique);
821
abcbd3bf 822 call->fid = vp->fid;
e49c7b2f
DH
823 trace_afs_make_fs_call1(call, &vp->fid, name);
824 afs_make_op_call(op, call, GFP_NOFS);
260a9803
DH
825}
826
827/*
828 * deliver reply data to an FS.Symlink
829 */
d001648e 830static int afs_deliver_fs_symlink(struct afs_call *call)
260a9803 831{
e49c7b2f
DH
832 struct afs_operation *op = call->op;
833 struct afs_vnode_param *dvp = &op->file[0];
834 struct afs_vnode_param *vp = &op->file[1];
260a9803 835 const __be32 *bp;
372ee163 836 int ret;
260a9803 837
d001648e 838 _enter("{%u}", call->unmarshall);
260a9803 839
d001648e 840 ret = afs_transfer_reply(call);
372ee163
DH
841 if (ret < 0)
842 return ret;
260a9803
DH
843
844 /* unmarshall the reply once we've received all of it */
845 bp = call->buffer;
e49c7b2f
DH
846 xdr_decode_AFSFid(&bp, &vp->fid);
847 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
848 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
849 xdr_decode_AFSVolSync(&bp, &op->volsync);
260a9803
DH
850
851 _leave(" = 0 [done]");
852 return 0;
853}
854
855/*
856 * FS.Symlink operation type
857 */
858static const struct afs_call_type afs_RXFSSymlink = {
859 .name = "FS.Symlink",
025db80c 860 .op = afs_FS_Symlink,
260a9803 861 .deliver = afs_deliver_fs_symlink,
260a9803
DH
862 .destructor = afs_flat_call_destructor,
863};
864
865/*
866 * create a symbolic link
867 */
e49c7b2f 868void afs_fs_symlink(struct afs_operation *op)
260a9803 869{
e49c7b2f
DH
870 const struct qstr *name = &op->dentry->d_name;
871 struct afs_vnode_param *dvp = &op->file[0];
260a9803
DH
872 struct afs_call *call;
873 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
874 __be32 *bp;
875
876 _enter("");
877
e49c7b2f 878 namesz = name->len;
260a9803
DH
879 padsz = (4 - (namesz & 3)) & 3;
880
e49c7b2f 881 c_namesz = strlen(op->create.symlink);
260a9803
DH
882 c_padsz = (4 - (c_namesz & 3)) & 3;
883
884 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
885
e49c7b2f 886 call = afs_alloc_flat_call(op->net, &afs_RXFSSymlink, reqsz,
260a9803
DH
887 (3 + 21 + 21 + 6) * 4);
888 if (!call)
e49c7b2f 889 return afs_op_nomem(op);
260a9803
DH
890
891 /* marshall the parameters */
892 bp = call->request;
893 *bp++ = htonl(FSSYMLINK);
e49c7b2f
DH
894 *bp++ = htonl(dvp->fid.vid);
895 *bp++ = htonl(dvp->fid.vnode);
896 *bp++ = htonl(dvp->fid.unique);
260a9803 897 *bp++ = htonl(namesz);
e49c7b2f 898 memcpy(bp, name->name, namesz);
260a9803
DH
899 bp = (void *) bp + namesz;
900 if (padsz > 0) {
901 memset(bp, 0, padsz);
902 bp = (void *) bp + padsz;
903 }
904 *bp++ = htonl(c_namesz);
e49c7b2f 905 memcpy(bp, op->create.symlink, c_namesz);
260a9803
DH
906 bp = (void *) bp + c_namesz;
907 if (c_padsz > 0) {
908 memset(bp, 0, c_padsz);
909 bp = (void *) bp + c_padsz;
910 }
ab94f5d0 911 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
e49c7b2f 912 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
260a9803
DH
913 *bp++ = 0; /* owner */
914 *bp++ = 0; /* group */
915 *bp++ = htonl(S_IRWXUGO); /* unix mode */
916 *bp++ = 0; /* segment size */
917
abcbd3bf 918 call->fid = dvp->fid;
e49c7b2f
DH
919 trace_afs_make_fs_call1(call, &dvp->fid, name);
920 afs_make_op_call(op, call, GFP_NOFS);
260a9803
DH
921}
922
923/*
924 * deliver reply data to an FS.Rename
925 */
d001648e 926static int afs_deliver_fs_rename(struct afs_call *call)
260a9803 927{
e49c7b2f
DH
928 struct afs_operation *op = call->op;
929 struct afs_vnode_param *orig_dvp = &op->file[0];
930 struct afs_vnode_param *new_dvp = &op->file[1];
260a9803 931 const __be32 *bp;
372ee163 932 int ret;
260a9803 933
d001648e 934 ret = afs_transfer_reply(call);
372ee163
DH
935 if (ret < 0)
936 return ret;
260a9803 937
38355eec 938 bp = call->buffer;
b98f0ec9
DH
939 /* If the two dirs are the same, we have two copies of the same status
940 * report, so we just decode it twice.
941 */
e49c7b2f
DH
942 xdr_decode_AFSFetchStatus(&bp, call, &orig_dvp->scb);
943 xdr_decode_AFSFetchStatus(&bp, call, &new_dvp->scb);
944 xdr_decode_AFSVolSync(&bp, &op->volsync);
260a9803
DH
945
946 _leave(" = 0 [done]");
947 return 0;
948}
949
950/*
951 * FS.Rename operation type
952 */
953static const struct afs_call_type afs_RXFSRename = {
954 .name = "FS.Rename",
025db80c 955 .op = afs_FS_Rename,
260a9803 956 .deliver = afs_deliver_fs_rename,
260a9803
DH
957 .destructor = afs_flat_call_destructor,
958};
959
960/*
a58823ac 961 * Rename/move a file or directory.
260a9803 962 */
e49c7b2f 963void afs_fs_rename(struct afs_operation *op)
260a9803 964{
e49c7b2f
DH
965 struct afs_vnode_param *orig_dvp = &op->file[0];
966 struct afs_vnode_param *new_dvp = &op->file[1];
967 const struct qstr *orig_name = &op->dentry->d_name;
968 const struct qstr *new_name = &op->dentry_2->d_name;
260a9803
DH
969 struct afs_call *call;
970 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
971 __be32 *bp;
972
973 _enter("");
974
e49c7b2f 975 o_namesz = orig_name->len;
260a9803
DH
976 o_padsz = (4 - (o_namesz & 3)) & 3;
977
e49c7b2f 978 n_namesz = new_name->len;
260a9803
DH
979 n_padsz = (4 - (n_namesz & 3)) & 3;
980
981 reqsz = (4 * 4) +
982 4 + o_namesz + o_padsz +
983 (3 * 4) +
984 4 + n_namesz + n_padsz;
985
e49c7b2f 986 call = afs_alloc_flat_call(op->net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
260a9803 987 if (!call)
e49c7b2f 988 return afs_op_nomem(op);
260a9803
DH
989
990 /* marshall the parameters */
991 bp = call->request;
992 *bp++ = htonl(FSRENAME);
e49c7b2f
DH
993 *bp++ = htonl(orig_dvp->fid.vid);
994 *bp++ = htonl(orig_dvp->fid.vnode);
995 *bp++ = htonl(orig_dvp->fid.unique);
260a9803 996 *bp++ = htonl(o_namesz);
e49c7b2f 997 memcpy(bp, orig_name->name, o_namesz);
260a9803
DH
998 bp = (void *) bp + o_namesz;
999 if (o_padsz > 0) {
1000 memset(bp, 0, o_padsz);
1001 bp = (void *) bp + o_padsz;
1002 }
1003
e49c7b2f
DH
1004 *bp++ = htonl(new_dvp->fid.vid);
1005 *bp++ = htonl(new_dvp->fid.vnode);
1006 *bp++ = htonl(new_dvp->fid.unique);
260a9803 1007 *bp++ = htonl(n_namesz);
e49c7b2f 1008 memcpy(bp, new_name->name, n_namesz);
260a9803
DH
1009 bp = (void *) bp + n_namesz;
1010 if (n_padsz > 0) {
1011 memset(bp, 0, n_padsz);
1012 bp = (void *) bp + n_padsz;
1013 }
1014
abcbd3bf 1015 call->fid = orig_dvp->fid;
e49c7b2f
DH
1016 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1017 afs_make_op_call(op, call, GFP_NOFS);
260a9803 1018}
31143d5d
DH
1019
1020/*
e49c7b2f 1021 * Deliver reply data to FS.StoreData or FS.StoreStatus
31143d5d 1022 */
d001648e 1023static int afs_deliver_fs_store_data(struct afs_call *call)
31143d5d 1024{
e49c7b2f
DH
1025 struct afs_operation *op = call->op;
1026 struct afs_vnode_param *vp = &op->file[0];
31143d5d 1027 const __be32 *bp;
372ee163 1028 int ret;
31143d5d 1029
d001648e 1030 _enter("");
31143d5d 1031
d001648e 1032 ret = afs_transfer_reply(call);
372ee163
DH
1033 if (ret < 0)
1034 return ret;
31143d5d
DH
1035
1036 /* unmarshall the reply once we've received all of it */
1037 bp = call->buffer;
e49c7b2f
DH
1038 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
1039 xdr_decode_AFSVolSync(&bp, &op->volsync);
31143d5d 1040
31143d5d
DH
1041 _leave(" = 0 [done]");
1042 return 0;
1043}
1044
1045/*
1046 * FS.StoreData operation type
1047 */
1048static const struct afs_call_type afs_RXFSStoreData = {
1049 .name = "FS.StoreData",
025db80c 1050 .op = afs_FS_StoreData,
31143d5d 1051 .deliver = afs_deliver_fs_store_data,
31143d5d
DH
1052 .destructor = afs_flat_call_destructor,
1053};
1054
b9b1f8d5
DH
1055static const struct afs_call_type afs_RXFSStoreData64 = {
1056 .name = "FS.StoreData64",
025db80c 1057 .op = afs_FS_StoreData64,
b9b1f8d5 1058 .deliver = afs_deliver_fs_store_data,
b9b1f8d5
DH
1059 .destructor = afs_flat_call_destructor,
1060};
1061
1062/*
1063 * store a set of pages to a very large file
1064 */
bd80d8a8 1065static void afs_fs_store_data64(struct afs_operation *op)
b9b1f8d5 1066{
e49c7b2f 1067 struct afs_vnode_param *vp = &op->file[0];
b9b1f8d5
DH
1068 struct afs_call *call;
1069 __be32 *bp;
1070
3b6492df 1071 _enter(",%x,{%llx:%llu},,",
e49c7b2f 1072 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
b9b1f8d5 1073
e49c7b2f 1074 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64,
b9b1f8d5
DH
1075 (4 + 6 + 3 * 2) * 4,
1076 (21 + 6) * 4);
1077 if (!call)
e49c7b2f 1078 return afs_op_nomem(op);
b9b1f8d5 1079
bd80d8a8 1080 call->write_iter = op->store.write_iter;
b9b1f8d5
DH
1081
1082 /* marshall the parameters */
1083 bp = call->request;
1084 *bp++ = htonl(FSSTOREDATA64);
e49c7b2f
DH
1085 *bp++ = htonl(vp->fid.vid);
1086 *bp++ = htonl(vp->fid.vnode);
1087 *bp++ = htonl(vp->fid.unique);
b9b1f8d5 1088
ab94f5d0 1089 *bp++ = htonl(AFS_SET_MTIME); /* mask */
e49c7b2f 1090 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
b9b1f8d5
DH
1091 *bp++ = 0; /* owner */
1092 *bp++ = 0; /* group */
1093 *bp++ = 0; /* unix mode */
1094 *bp++ = 0; /* segment size */
1095
bd80d8a8
DH
1096 *bp++ = htonl(upper_32_bits(op->store.pos));
1097 *bp++ = htonl(lower_32_bits(op->store.pos));
1098 *bp++ = htonl(upper_32_bits(op->store.size));
1099 *bp++ = htonl(lower_32_bits(op->store.size));
1100 *bp++ = htonl(upper_32_bits(op->store.i_size));
1101 *bp++ = htonl(lower_32_bits(op->store.i_size));
e49c7b2f 1102
abcbd3bf 1103 call->fid = vp->fid;
e49c7b2f
DH
1104 trace_afs_make_fs_call(call, &vp->fid);
1105 afs_make_op_call(op, call, GFP_NOFS);
b9b1f8d5
DH
1106}
1107
31143d5d 1108/*
bd80d8a8 1109 * Write data to a file on the server.
31143d5d 1110 */
e49c7b2f 1111void afs_fs_store_data(struct afs_operation *op)
31143d5d 1112{
e49c7b2f 1113 struct afs_vnode_param *vp = &op->file[0];
31143d5d 1114 struct afs_call *call;
31143d5d
DH
1115 __be32 *bp;
1116
3b6492df 1117 _enter(",%x,{%llx:%llu},,",
e49c7b2f 1118 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
31143d5d 1119
31143d5d 1120 _debug("size %llx, at %llx, i_size %llx",
bd80d8a8
DH
1121 (unsigned long long)op->store.size,
1122 (unsigned long long)op->store.pos,
1123 (unsigned long long)op->store.i_size);
31143d5d 1124
b537a3c2 1125 if (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
bd80d8a8 1126 return afs_fs_store_data64(op);
31143d5d 1127
e49c7b2f 1128 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData,
31143d5d
DH
1129 (4 + 6 + 3) * 4,
1130 (21 + 6) * 4);
1131 if (!call)
e49c7b2f 1132 return afs_op_nomem(op);
31143d5d 1133
bd80d8a8 1134 call->write_iter = op->store.write_iter;
31143d5d
DH
1135
1136 /* marshall the parameters */
1137 bp = call->request;
1138 *bp++ = htonl(FSSTOREDATA);
e49c7b2f
DH
1139 *bp++ = htonl(vp->fid.vid);
1140 *bp++ = htonl(vp->fid.vnode);
1141 *bp++ = htonl(vp->fid.unique);
31143d5d 1142
ab94f5d0 1143 *bp++ = htonl(AFS_SET_MTIME); /* mask */
e49c7b2f 1144 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
31143d5d
DH
1145 *bp++ = 0; /* owner */
1146 *bp++ = 0; /* group */
1147 *bp++ = 0; /* unix mode */
1148 *bp++ = 0; /* segment size */
1149
bd80d8a8
DH
1150 *bp++ = htonl(lower_32_bits(op->store.pos));
1151 *bp++ = htonl(lower_32_bits(op->store.size));
1152 *bp++ = htonl(lower_32_bits(op->store.i_size));
31143d5d 1153
abcbd3bf 1154 call->fid = vp->fid;
e49c7b2f
DH
1155 trace_afs_make_fs_call(call, &vp->fid);
1156 afs_make_op_call(op, call, GFP_NOFS);
31143d5d
DH
1157}
1158
1159/*
1160 * FS.StoreStatus operation type
1161 */
1162static const struct afs_call_type afs_RXFSStoreStatus = {
1163 .name = "FS.StoreStatus",
025db80c 1164 .op = afs_FS_StoreStatus,
e49c7b2f 1165 .deliver = afs_deliver_fs_store_data,
31143d5d
DH
1166 .destructor = afs_flat_call_destructor,
1167};
1168
1169static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1170 .name = "FS.StoreData",
025db80c 1171 .op = afs_FS_StoreData,
e49c7b2f 1172 .deliver = afs_deliver_fs_store_data,
31143d5d
DH
1173 .destructor = afs_flat_call_destructor,
1174};
1175
b9b1f8d5
DH
1176static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1177 .name = "FS.StoreData64",
025db80c 1178 .op = afs_FS_StoreData64,
e49c7b2f 1179 .deliver = afs_deliver_fs_store_data,
b9b1f8d5
DH
1180 .destructor = afs_flat_call_destructor,
1181};
1182
1183/*
1184 * set the attributes on a very large file, using FS.StoreData rather than
1185 * FS.StoreStatus so as to alter the file size also
1186 */
e49c7b2f 1187static void afs_fs_setattr_size64(struct afs_operation *op)
b9b1f8d5 1188{
e49c7b2f 1189 struct afs_vnode_param *vp = &op->file[0];
b9b1f8d5 1190 struct afs_call *call;
e49c7b2f 1191 struct iattr *attr = op->setattr.attr;
b9b1f8d5
DH
1192 __be32 *bp;
1193
3b6492df 1194 _enter(",%x,{%llx:%llu},,",
e49c7b2f 1195 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
b9b1f8d5
DH
1196
1197 ASSERT(attr->ia_valid & ATTR_SIZE);
1198
e49c7b2f 1199 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64_as_Status,
b9b1f8d5
DH
1200 (4 + 6 + 3 * 2) * 4,
1201 (21 + 6) * 4);
1202 if (!call)
e49c7b2f 1203 return afs_op_nomem(op);
b9b1f8d5
DH
1204
1205 /* marshall the parameters */
1206 bp = call->request;
1207 *bp++ = htonl(FSSTOREDATA64);
e49c7b2f
DH
1208 *bp++ = htonl(vp->fid.vid);
1209 *bp++ = htonl(vp->fid.vnode);
1210 *bp++ = htonl(vp->fid.unique);
b9b1f8d5
DH
1211
1212 xdr_encode_AFS_StoreStatus(&bp, attr);
1213
e49c7b2f
DH
1214 *bp++ = htonl(upper_32_bits(attr->ia_size)); /* position of start of write */
1215 *bp++ = htonl(lower_32_bits(attr->ia_size));
1216 *bp++ = 0; /* size of write */
b9b1f8d5 1217 *bp++ = 0;
e49c7b2f
DH
1218 *bp++ = htonl(upper_32_bits(attr->ia_size)); /* new file length */
1219 *bp++ = htonl(lower_32_bits(attr->ia_size));
1220
abcbd3bf 1221 call->fid = vp->fid;
e49c7b2f
DH
1222 trace_afs_make_fs_call(call, &vp->fid);
1223 afs_make_op_call(op, call, GFP_NOFS);
b9b1f8d5
DH
1224}
1225
31143d5d
DH
1226/*
1227 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1228 * so as to alter the file size also
1229 */
e49c7b2f 1230static void afs_fs_setattr_size(struct afs_operation *op)
31143d5d 1231{
e49c7b2f 1232 struct afs_vnode_param *vp = &op->file[0];
31143d5d 1233 struct afs_call *call;
e49c7b2f 1234 struct iattr *attr = op->setattr.attr;
31143d5d
DH
1235 __be32 *bp;
1236
3b6492df 1237 _enter(",%x,{%llx:%llu},,",
e49c7b2f 1238 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
31143d5d
DH
1239
1240 ASSERT(attr->ia_valid & ATTR_SIZE);
b537a3c2 1241 if (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
e49c7b2f 1242 return afs_fs_setattr_size64(op);
31143d5d 1243
e49c7b2f 1244 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData_as_Status,
31143d5d
DH
1245 (4 + 6 + 3) * 4,
1246 (21 + 6) * 4);
1247 if (!call)
e49c7b2f 1248 return afs_op_nomem(op);
31143d5d
DH
1249
1250 /* marshall the parameters */
1251 bp = call->request;
1252 *bp++ = htonl(FSSTOREDATA);
e49c7b2f
DH
1253 *bp++ = htonl(vp->fid.vid);
1254 *bp++ = htonl(vp->fid.vnode);
1255 *bp++ = htonl(vp->fid.unique);
31143d5d
DH
1256
1257 xdr_encode_AFS_StoreStatus(&bp, attr);
1258
8c7ae38d 1259 *bp++ = htonl(attr->ia_size); /* position of start of write */
31143d5d
DH
1260 *bp++ = 0; /* size of write */
1261 *bp++ = htonl(attr->ia_size); /* new file length */
1262
abcbd3bf 1263 call->fid = vp->fid;
e49c7b2f
DH
1264 trace_afs_make_fs_call(call, &vp->fid);
1265 afs_make_op_call(op, call, GFP_NOFS);
31143d5d
DH
1266}
1267
1268/*
1269 * set the attributes on a file, using FS.StoreData if there's a change in file
1270 * size, and FS.StoreStatus otherwise
1271 */
e49c7b2f 1272void afs_fs_setattr(struct afs_operation *op)
31143d5d 1273{
e49c7b2f 1274 struct afs_vnode_param *vp = &op->file[0];
31143d5d 1275 struct afs_call *call;
e49c7b2f 1276 struct iattr *attr = op->setattr.attr;
31143d5d
DH
1277 __be32 *bp;
1278
1279 if (attr->ia_valid & ATTR_SIZE)
e49c7b2f 1280 return afs_fs_setattr_size(op);
31143d5d 1281
3b6492df 1282 _enter(",%x,{%llx:%llu},,",
e49c7b2f 1283 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
31143d5d 1284
e49c7b2f 1285 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreStatus,
31143d5d
DH
1286 (4 + 6) * 4,
1287 (21 + 6) * 4);
1288 if (!call)
e49c7b2f 1289 return afs_op_nomem(op);
31143d5d
DH
1290
1291 /* marshall the parameters */
1292 bp = call->request;
1293 *bp++ = htonl(FSSTORESTATUS);
e49c7b2f
DH
1294 *bp++ = htonl(vp->fid.vid);
1295 *bp++ = htonl(vp->fid.vnode);
1296 *bp++ = htonl(vp->fid.unique);
31143d5d 1297
e49c7b2f 1298 xdr_encode_AFS_StoreStatus(&bp, op->setattr.attr);
31143d5d 1299
abcbd3bf 1300 call->fid = vp->fid;
e49c7b2f
DH
1301 trace_afs_make_fs_call(call, &vp->fid);
1302 afs_make_op_call(op, call, GFP_NOFS);
31143d5d 1303}
45222b9e
DH
1304
1305/*
1306 * deliver reply data to an FS.GetVolumeStatus
1307 */
d001648e 1308static int afs_deliver_fs_get_volume_status(struct afs_call *call)
45222b9e 1309{
e49c7b2f 1310 struct afs_operation *op = call->op;
45222b9e
DH
1311 const __be32 *bp;
1312 char *p;
12bdcf33 1313 u32 size;
45222b9e
DH
1314 int ret;
1315
d001648e 1316 _enter("{%u}", call->unmarshall);
45222b9e
DH
1317
1318 switch (call->unmarshall) {
1319 case 0:
45222b9e 1320 call->unmarshall++;
12bdcf33 1321 afs_extract_to_buf(call, 12 * 4);
df561f66 1322 fallthrough;
45222b9e 1323
29881608 1324 /* extract the returned status record */
45222b9e
DH
1325 case 1:
1326 _debug("extract status");
12bdcf33 1327 ret = afs_extract_data(call, true);
372ee163
DH
1328 if (ret < 0)
1329 return ret;
45222b9e
DH
1330
1331 bp = call->buffer;
e49c7b2f 1332 xdr_decode_AFSFetchVolumeStatus(&bp, &op->volstatus.vs);
45222b9e 1333 call->unmarshall++;
12bdcf33 1334 afs_extract_to_tmp(call);
df561f66 1335 fallthrough;
45222b9e 1336
29881608 1337 /* extract the volume name length */
45222b9e 1338 case 2:
12bdcf33 1339 ret = afs_extract_data(call, true);
372ee163
DH
1340 if (ret < 0)
1341 return ret;
45222b9e
DH
1342
1343 call->count = ntohl(call->tmp);
1344 _debug("volname length: %u", call->count);
1345 if (call->count >= AFSNAMEMAX)
7126ead9 1346 return afs_protocol_error(call, afs_eproto_volname_len);
12bdcf33 1347 size = (call->count + 3) & ~3; /* It's padded */
ffba718e 1348 afs_extract_to_buf(call, size);
45222b9e 1349 call->unmarshall++;
df561f66 1350 fallthrough;
45222b9e 1351
29881608 1352 /* extract the volume name */
45222b9e
DH
1353 case 3:
1354 _debug("extract volname");
12bdcf33
DH
1355 ret = afs_extract_data(call, true);
1356 if (ret < 0)
1357 return ret;
45222b9e 1358
ffba718e 1359 p = call->buffer;
45222b9e
DH
1360 p[call->count] = 0;
1361 _debug("volname '%s'", p);
12bdcf33 1362 afs_extract_to_tmp(call);
45222b9e 1363 call->unmarshall++;
df561f66 1364 fallthrough;
45222b9e 1365
29881608 1366 /* extract the offline message length */
12bdcf33
DH
1367 case 4:
1368 ret = afs_extract_data(call, true);
372ee163
DH
1369 if (ret < 0)
1370 return ret;
45222b9e
DH
1371
1372 call->count = ntohl(call->tmp);
1373 _debug("offline msg length: %u", call->count);
1374 if (call->count >= AFSNAMEMAX)
7126ead9 1375 return afs_protocol_error(call, afs_eproto_offline_msg_len);
12bdcf33 1376 size = (call->count + 3) & ~3; /* It's padded */
ffba718e 1377 afs_extract_to_buf(call, size);
45222b9e 1378 call->unmarshall++;
df561f66 1379 fallthrough;
45222b9e 1380
29881608 1381 /* extract the offline message */
12bdcf33 1382 case 5:
45222b9e 1383 _debug("extract offline");
12bdcf33
DH
1384 ret = afs_extract_data(call, true);
1385 if (ret < 0)
1386 return ret;
45222b9e 1387
ffba718e 1388 p = call->buffer;
45222b9e
DH
1389 p[call->count] = 0;
1390 _debug("offline '%s'", p);
1391
12bdcf33 1392 afs_extract_to_tmp(call);
45222b9e 1393 call->unmarshall++;
df561f66 1394 fallthrough;
45222b9e 1395
29881608 1396 /* extract the message of the day length */
12bdcf33
DH
1397 case 6:
1398 ret = afs_extract_data(call, true);
372ee163
DH
1399 if (ret < 0)
1400 return ret;
45222b9e
DH
1401
1402 call->count = ntohl(call->tmp);
1403 _debug("motd length: %u", call->count);
1404 if (call->count >= AFSNAMEMAX)
7126ead9 1405 return afs_protocol_error(call, afs_eproto_motd_len);
12bdcf33 1406 size = (call->count + 3) & ~3; /* It's padded */
ffba718e 1407 afs_extract_to_buf(call, size);
45222b9e 1408 call->unmarshall++;
df561f66 1409 fallthrough;
45222b9e 1410
29881608 1411 /* extract the message of the day */
12bdcf33 1412 case 7:
45222b9e 1413 _debug("extract motd");
12bdcf33
DH
1414 ret = afs_extract_data(call, false);
1415 if (ret < 0)
1416 return ret;
45222b9e 1417
ffba718e 1418 p = call->buffer;
45222b9e
DH
1419 p[call->count] = 0;
1420 _debug("motd '%s'", p);
1421
45222b9e 1422 call->unmarshall++;
b2db6c35 1423 fallthrough;
45222b9e 1424
12bdcf33 1425 case 8:
45222b9e
DH
1426 break;
1427 }
1428
45222b9e
DH
1429 _leave(" = 0 [done]");
1430 return 0;
1431}
1432
45222b9e
DH
1433/*
1434 * FS.GetVolumeStatus operation type
1435 */
1436static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1437 .name = "FS.GetVolumeStatus",
025db80c 1438 .op = afs_FS_GetVolumeStatus,
45222b9e 1439 .deliver = afs_deliver_fs_get_volume_status,
ffba718e 1440 .destructor = afs_flat_call_destructor,
45222b9e
DH
1441};
1442
1443/*
1444 * fetch the status of a volume
1445 */
e49c7b2f 1446void afs_fs_get_volume_status(struct afs_operation *op)
45222b9e 1447{
e49c7b2f 1448 struct afs_vnode_param *vp = &op->file[0];
45222b9e
DH
1449 struct afs_call *call;
1450 __be32 *bp;
45222b9e
DH
1451
1452 _enter("");
1453
e49c7b2f 1454 call = afs_alloc_flat_call(op->net, &afs_RXFSGetVolumeStatus, 2 * 4,
ffba718e
DH
1455 max(12 * 4, AFSOPAQUEMAX + 1));
1456 if (!call)
e49c7b2f 1457 return afs_op_nomem(op);
45222b9e
DH
1458
1459 /* marshall the parameters */
1460 bp = call->request;
1461 bp[0] = htonl(FSGETVOLUMESTATUS);
e49c7b2f 1462 bp[1] = htonl(vp->fid.vid);
45222b9e 1463
abcbd3bf 1464 call->fid = vp->fid;
e49c7b2f
DH
1465 trace_afs_make_fs_call(call, &vp->fid);
1466 afs_make_op_call(op, call, GFP_NOFS);
45222b9e 1467}
e8d6c554
DH
1468
1469/*
1470 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1471 */
d001648e 1472static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
e8d6c554 1473{
e49c7b2f 1474 struct afs_operation *op = call->op;
e8d6c554 1475 const __be32 *bp;
372ee163 1476 int ret;
e8d6c554 1477
d001648e 1478 _enter("{%u}", call->unmarshall);
e8d6c554 1479
d001648e 1480 ret = afs_transfer_reply(call);
372ee163
DH
1481 if (ret < 0)
1482 return ret;
e8d6c554
DH
1483
1484 /* unmarshall the reply once we've received all of it */
1485 bp = call->buffer;
e49c7b2f 1486 xdr_decode_AFSVolSync(&bp, &op->volsync);
e8d6c554
DH
1487
1488 _leave(" = 0 [done]");
1489 return 0;
1490}
1491
1492/*
1493 * FS.SetLock operation type
1494 */
1495static const struct afs_call_type afs_RXFSSetLock = {
1496 .name = "FS.SetLock",
025db80c 1497 .op = afs_FS_SetLock,
e8d6c554 1498 .deliver = afs_deliver_fs_xxxx_lock,
a690f60a 1499 .done = afs_lock_op_done,
e8d6c554
DH
1500 .destructor = afs_flat_call_destructor,
1501};
1502
1503/*
1504 * FS.ExtendLock operation type
1505 */
1506static const struct afs_call_type afs_RXFSExtendLock = {
1507 .name = "FS.ExtendLock",
025db80c 1508 .op = afs_FS_ExtendLock,
e8d6c554 1509 .deliver = afs_deliver_fs_xxxx_lock,
a690f60a 1510 .done = afs_lock_op_done,
e8d6c554
DH
1511 .destructor = afs_flat_call_destructor,
1512};
1513
1514/*
1515 * FS.ReleaseLock operation type
1516 */
1517static const struct afs_call_type afs_RXFSReleaseLock = {
1518 .name = "FS.ReleaseLock",
025db80c 1519 .op = afs_FS_ReleaseLock,
e8d6c554 1520 .deliver = afs_deliver_fs_xxxx_lock,
e8d6c554
DH
1521 .destructor = afs_flat_call_destructor,
1522};
1523
1524/*
d2ddc776 1525 * Set a lock on a file
e8d6c554 1526 */
e49c7b2f 1527void afs_fs_set_lock(struct afs_operation *op)
e8d6c554 1528{
e49c7b2f 1529 struct afs_vnode_param *vp = &op->file[0];
e8d6c554
DH
1530 struct afs_call *call;
1531 __be32 *bp;
1532
1533 _enter("");
1534
e49c7b2f 1535 call = afs_alloc_flat_call(op->net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
e8d6c554 1536 if (!call)
e49c7b2f 1537 return afs_op_nomem(op);
e8d6c554
DH
1538
1539 /* marshall the parameters */
1540 bp = call->request;
1541 *bp++ = htonl(FSSETLOCK);
e49c7b2f
DH
1542 *bp++ = htonl(vp->fid.vid);
1543 *bp++ = htonl(vp->fid.vnode);
1544 *bp++ = htonl(vp->fid.unique);
1545 *bp++ = htonl(op->lock.type);
1546
abcbd3bf 1547 call->fid = vp->fid;
e49c7b2f
DH
1548 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1549 afs_make_op_call(op, call, GFP_NOFS);
e8d6c554
DH
1550}
1551
1552/*
1553 * extend a lock on a file
1554 */
e49c7b2f 1555void afs_fs_extend_lock(struct afs_operation *op)
e8d6c554 1556{
e49c7b2f 1557 struct afs_vnode_param *vp = &op->file[0];
e8d6c554
DH
1558 struct afs_call *call;
1559 __be32 *bp;
1560
1561 _enter("");
1562
e49c7b2f 1563 call = afs_alloc_flat_call(op->net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
e8d6c554 1564 if (!call)
e49c7b2f 1565 return afs_op_nomem(op);
e8d6c554
DH
1566
1567 /* marshall the parameters */
1568 bp = call->request;
1569 *bp++ = htonl(FSEXTENDLOCK);
e49c7b2f
DH
1570 *bp++ = htonl(vp->fid.vid);
1571 *bp++ = htonl(vp->fid.vnode);
1572 *bp++ = htonl(vp->fid.unique);
1573
abcbd3bf 1574 call->fid = vp->fid;
e49c7b2f
DH
1575 trace_afs_make_fs_call(call, &vp->fid);
1576 afs_make_op_call(op, call, GFP_NOFS);
e8d6c554
DH
1577}
1578
1579/*
1580 * release a lock on a file
1581 */
e49c7b2f 1582void afs_fs_release_lock(struct afs_operation *op)
e8d6c554 1583{
e49c7b2f 1584 struct afs_vnode_param *vp = &op->file[0];
e8d6c554
DH
1585 struct afs_call *call;
1586 __be32 *bp;
1587
1588 _enter("");
1589
e49c7b2f 1590 call = afs_alloc_flat_call(op->net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
e8d6c554 1591 if (!call)
e49c7b2f 1592 return afs_op_nomem(op);
e8d6c554
DH
1593
1594 /* marshall the parameters */
1595 bp = call->request;
1596 *bp++ = htonl(FSRELEASELOCK);
e49c7b2f
DH
1597 *bp++ = htonl(vp->fid.vid);
1598 *bp++ = htonl(vp->fid.vnode);
1599 *bp++ = htonl(vp->fid.unique);
1600
abcbd3bf 1601 call->fid = vp->fid;
e49c7b2f
DH
1602 trace_afs_make_fs_call(call, &vp->fid);
1603 afs_make_op_call(op, call, GFP_NOFS);
c435ee34
DH
1604}
1605
1606/*
1607 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1608 */
1609static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1610{
1611 return afs_transfer_reply(call);
1612}
1613
1614/*
1615 * FS.GiveUpAllCallBacks operation type
1616 */
1617static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1618 .name = "FS.GiveUpAllCallBacks",
025db80c 1619 .op = afs_FS_GiveUpAllCallBacks,
c435ee34
DH
1620 .deliver = afs_deliver_fs_give_up_all_callbacks,
1621 .destructor = afs_flat_call_destructor,
1622};
1623
1624/*
1625 * Flush all the callbacks we have on a server.
1626 */
98f9fda2
DH
1627int afs_fs_give_up_all_callbacks(struct afs_net *net, struct afs_server *server,
1628 struct afs_address *addr, struct key *key)
c435ee34
DH
1629{
1630 struct afs_call *call;
1631 __be32 *bp;
6f2ff7e8 1632 int ret;
c435ee34
DH
1633
1634 _enter("");
1635
d2ddc776 1636 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
c435ee34
DH
1637 if (!call)
1638 return -ENOMEM;
1639
e38f299e 1640 call->key = key;
98f9fda2 1641 call->peer = rxrpc_kernel_get_peer(addr->peer);
e38f299e 1642 call->service_id = server->service_id;
c435ee34
DH
1643
1644 /* marshall the parameters */
1645 bp = call->request;
1646 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1647
977e5f8e 1648 call->server = afs_use_server(server, afs_server_trace_give_up_cb);
98f9fda2
DH
1649 afs_make_call(call, GFP_NOFS);
1650 afs_wait_for_call_to_complete(call);
aa453bec 1651 ret = call->error;
98f9fda2
DH
1652 if (call->responded)
1653 set_bit(AFS_SERVER_FL_RESPONDING, &server->flags);
6f2ff7e8
DH
1654 afs_put_call(call);
1655 return ret;
d2ddc776
DH
1656}
1657
1658/*
1659 * Deliver reply data to an FS.GetCapabilities operation.
1660 */
1661static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1662{
1663 u32 count;
1664 int ret;
1665
fc276122 1666 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(call->iter));
d2ddc776 1667
d2ddc776
DH
1668 switch (call->unmarshall) {
1669 case 0:
12bdcf33 1670 afs_extract_to_tmp(call);
d2ddc776 1671 call->unmarshall++;
df561f66 1672 fallthrough;
d2ddc776 1673
29881608 1674 /* Extract the capabilities word count */
d2ddc776 1675 case 1:
12bdcf33 1676 ret = afs_extract_data(call, true);
d2ddc776
DH
1677 if (ret < 0)
1678 return ret;
1679
1680 count = ntohl(call->tmp);
d2ddc776
DH
1681 call->count = count;
1682 call->count2 = count;
b537a3c2
DH
1683 if (count == 0) {
1684 call->unmarshall = 4;
1685 call->tmp = 0;
1686 break;
1687 }
1688
1689 /* Extract the first word of the capabilities to call->tmp */
1690 afs_extract_to_tmp(call);
d2ddc776 1691 call->unmarshall++;
df561f66 1692 fallthrough;
d2ddc776 1693
d2ddc776 1694 case 2:
12bdcf33 1695 ret = afs_extract_data(call, false);
d2ddc776
DH
1696 if (ret < 0)
1697 return ret;
1698
b537a3c2
DH
1699 afs_extract_discard(call, (count - 1) * sizeof(__be32));
1700 call->unmarshall++;
1701 fallthrough;
1702
1703 /* Extract remaining capabilities words */
1704 case 3:
1705 ret = afs_extract_data(call, false);
1706 if (ret < 0)
1707 return ret;
d2ddc776 1708
d2ddc776
DH
1709 call->unmarshall++;
1710 break;
1711 }
1712
1713 _leave(" = 0 [done]");
1714 return 0;
1715}
1716
98f9fda2
DH
1717static void afs_fs_get_capabilities_destructor(struct afs_call *call)
1718{
f49b594d 1719 afs_put_endpoint_state(call->probe, afs_estate_trace_put_getcaps);
98f9fda2
DH
1720 afs_flat_call_destructor(call);
1721}
1722
d2ddc776
DH
1723/*
1724 * FS.GetCapabilities operation type
1725 */
1726static const struct afs_call_type afs_RXFSGetCapabilities = {
1727 .name = "FS.GetCapabilities",
025db80c 1728 .op = afs_FS_GetCapabilities,
d2ddc776 1729 .deliver = afs_deliver_fs_get_capabilities,
3bf0fb6f 1730 .done = afs_fileserver_probe_result,
98f9fda2 1731 .destructor = afs_fs_get_capabilities_destructor,
d2ddc776
DH
1732};
1733
1734/*
f6cbb368
DH
1735 * Probe a fileserver for the capabilities that it supports. This RPC can
1736 * reply with up to 196 words. The operation is asynchronous and if we managed
1737 * to allocate a call, true is returned the result is delivered through the
1738 * ->done() - otherwise we return false to indicate we didn't even try.
d2ddc776 1739 */
f6cbb368 1740bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
f49b594d 1741 struct afs_endpoint_state *estate, unsigned int addr_index,
98f9fda2 1742 struct key *key)
d2ddc776
DH
1743{
1744 struct afs_call *call;
1745 __be32 *bp;
1746
1747 _enter("");
1748
1749 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1750 if (!call)
f6cbb368 1751 return false;
d2ddc776 1752
e38f299e
DH
1753 call->key = key;
1754 call->server = afs_use_server(server, afs_server_trace_get_caps);
f49b594d
DH
1755 call->peer = rxrpc_kernel_get_peer(estate->addresses->addrs[addr_index].peer);
1756 call->probe = afs_get_endpoint_state(estate, afs_estate_trace_get_getcaps);
98f9fda2 1757 call->probe_index = addr_index;
e38f299e
DH
1758 call->service_id = server->service_id;
1759 call->upgrade = true;
1760 call->async = true;
94f699c9 1761 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
d2ddc776
DH
1762
1763 /* marshall the parameters */
1764 bp = call->request;
1765 *bp++ = htonl(FSGETCAPABILITIES);
1766
025db80c 1767 trace_afs_make_fs_call(call, NULL);
98f9fda2 1768 afs_make_call(call, GFP_NOFS);
f6cbb368
DH
1769 afs_put_call(call);
1770 return true;
e8d6c554 1771}
5cf9dd55 1772
5cf9dd55
DH
1773/*
1774 * Deliver reply data to an FS.InlineBulkStatus call
1775 */
1776static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
1777{
e49c7b2f 1778 struct afs_operation *op = call->op;
87182759 1779 struct afs_status_cb *scb;
5cf9dd55
DH
1780 const __be32 *bp;
1781 u32 tmp;
1782 int ret;
1783
1784 _enter("{%u}", call->unmarshall);
1785
1786 switch (call->unmarshall) {
1787 case 0:
12bdcf33 1788 afs_extract_to_tmp(call);
5cf9dd55 1789 call->unmarshall++;
df561f66 1790 fallthrough;
5cf9dd55
DH
1791
1792 /* Extract the file status count and array in two steps */
1793 case 1:
1794 _debug("extract status count");
12bdcf33 1795 ret = afs_extract_data(call, true);
5cf9dd55
DH
1796 if (ret < 0)
1797 return ret;
1798
1799 tmp = ntohl(call->tmp);
e49c7b2f
DH
1800 _debug("status count: %u/%u", tmp, op->nr_files);
1801 if (tmp != op->nr_files)
7126ead9 1802 return afs_protocol_error(call, afs_eproto_ibulkst_count);
5cf9dd55
DH
1803
1804 call->count = 0;
1805 call->unmarshall++;
1806 more_counts:
12bdcf33 1807 afs_extract_to_buf(call, 21 * sizeof(__be32));
df561f66 1808 fallthrough;
29881608 1809
5cf9dd55
DH
1810 case 2:
1811 _debug("extract status array %u", call->count);
12bdcf33 1812 ret = afs_extract_data(call, true);
5cf9dd55
DH
1813 if (ret < 0)
1814 return ret;
1815
e49c7b2f
DH
1816 switch (call->count) {
1817 case 0:
1818 scb = &op->file[0].scb;
1819 break;
1820 case 1:
1821 scb = &op->file[1].scb;
1822 break;
1823 default:
1824 scb = &op->more_files[call->count - 2].scb;
1825 break;
1826 }
1827
5cf9dd55 1828 bp = call->buffer;
38355eec 1829 xdr_decode_AFSFetchStatus(&bp, call, scb);
e49c7b2f 1830
5cf9dd55 1831 call->count++;
e49c7b2f 1832 if (call->count < op->nr_files)
5cf9dd55
DH
1833 goto more_counts;
1834
1835 call->count = 0;
1836 call->unmarshall++;
12bdcf33 1837 afs_extract_to_tmp(call);
df561f66 1838 fallthrough;
5cf9dd55
DH
1839
1840 /* Extract the callback count and array in two steps */
1841 case 3:
1842 _debug("extract CB count");
12bdcf33 1843 ret = afs_extract_data(call, true);
5cf9dd55
DH
1844 if (ret < 0)
1845 return ret;
1846
1847 tmp = ntohl(call->tmp);
1848 _debug("CB count: %u", tmp);
e49c7b2f 1849 if (tmp != op->nr_files)
7126ead9 1850 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
5cf9dd55
DH
1851 call->count = 0;
1852 call->unmarshall++;
1853 more_cbs:
12bdcf33 1854 afs_extract_to_buf(call, 3 * sizeof(__be32));
df561f66 1855 fallthrough;
29881608 1856
5cf9dd55
DH
1857 case 4:
1858 _debug("extract CB array");
12bdcf33 1859 ret = afs_extract_data(call, true);
5cf9dd55
DH
1860 if (ret < 0)
1861 return ret;
1862
1863 _debug("unmarshall CB array");
e49c7b2f
DH
1864 switch (call->count) {
1865 case 0:
1866 scb = &op->file[0].scb;
1867 break;
1868 case 1:
1869 scb = &op->file[1].scb;
1870 break;
1871 default:
1872 scb = &op->more_files[call->count - 2].scb;
1873 break;
1874 }
1875
5cf9dd55 1876 bp = call->buffer;
a58823ac 1877 xdr_decode_AFSCallBack(&bp, call, scb);
5cf9dd55 1878 call->count++;
e49c7b2f 1879 if (call->count < op->nr_files)
5cf9dd55
DH
1880 goto more_cbs;
1881
12bdcf33 1882 afs_extract_to_buf(call, 6 * sizeof(__be32));
5cf9dd55 1883 call->unmarshall++;
df561f66 1884 fallthrough;
29881608 1885
5cf9dd55 1886 case 5:
12bdcf33 1887 ret = afs_extract_data(call, false);
5cf9dd55
DH
1888 if (ret < 0)
1889 return ret;
1890
1891 bp = call->buffer;
16069e13
DH
1892 /* Unfortunately, prior to OpenAFS-1.6, volsync here is filled
1893 * with rubbish.
1894 */
1895 xdr_decode_AFSVolSync(&bp, NULL);
5cf9dd55 1896
5cf9dd55 1897 call->unmarshall++;
b2db6c35 1898 fallthrough;
5cf9dd55
DH
1899
1900 case 6:
1901 break;
1902 }
1903
1904 _leave(" = 0 [done]");
1905 return 0;
1906}
1907
e49c7b2f
DH
1908static void afs_done_fs_inline_bulk_status(struct afs_call *call)
1909{
1910 if (call->error == -ECONNABORTED &&
20325960 1911 call->abort_code == RX_INVALID_OPERATION) {
e49c7b2f 1912 set_bit(AFS_SERVER_FL_NO_IBULK, &call->server->flags);
20325960
DH
1913 if (call->op)
1914 set_bit(AFS_VOLUME_MAYBE_NO_IBULK, &call->op->volume->flags);
1915 }
e49c7b2f
DH
1916}
1917
5cf9dd55
DH
1918/*
1919 * FS.InlineBulkStatus operation type
1920 */
1921static const struct afs_call_type afs_RXFSInlineBulkStatus = {
1922 .name = "FS.InlineBulkStatus",
1923 .op = afs_FS_InlineBulkStatus,
1924 .deliver = afs_deliver_fs_inline_bulk_status,
e49c7b2f 1925 .done = afs_done_fs_inline_bulk_status,
5cf9dd55
DH
1926 .destructor = afs_flat_call_destructor,
1927};
1928
1929/*
1930 * Fetch the status information for up to 50 files
1931 */
e49c7b2f 1932void afs_fs_inline_bulk_status(struct afs_operation *op)
5cf9dd55 1933{
e49c7b2f
DH
1934 struct afs_vnode_param *dvp = &op->file[0];
1935 struct afs_vnode_param *vp = &op->file[1];
5cf9dd55
DH
1936 struct afs_call *call;
1937 __be32 *bp;
1938 int i;
1939
20325960 1940 if (test_bit(AFS_SERVER_FL_NO_IBULK, &op->server->flags)) {
2de5599f 1941 afs_op_set_error(op, -ENOTSUPP);
e49c7b2f
DH
1942 return;
1943 }
30062bd1 1944
3b6492df 1945 _enter(",%x,{%llx:%llu},%u",
e49c7b2f 1946 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
5cf9dd55 1947
e49c7b2f
DH
1948 call = afs_alloc_flat_call(op->net, &afs_RXFSInlineBulkStatus,
1949 (2 + op->nr_files * 3) * 4,
5cf9dd55 1950 21 * 4);
e49c7b2f
DH
1951 if (!call)
1952 return afs_op_nomem(op);
5cf9dd55
DH
1953
1954 /* marshall the parameters */
1955 bp = call->request;
1956 *bp++ = htonl(FSINLINEBULKSTATUS);
e49c7b2f
DH
1957 *bp++ = htonl(op->nr_files);
1958 *bp++ = htonl(dvp->fid.vid);
1959 *bp++ = htonl(dvp->fid.vnode);
1960 *bp++ = htonl(dvp->fid.unique);
1961 *bp++ = htonl(vp->fid.vid);
1962 *bp++ = htonl(vp->fid.vnode);
1963 *bp++ = htonl(vp->fid.unique);
1964 for (i = 0; i < op->nr_files - 2; i++) {
1965 *bp++ = htonl(op->more_files[i].fid.vid);
1966 *bp++ = htonl(op->more_files[i].fid.vnode);
1967 *bp++ = htonl(op->more_files[i].fid.unique);
5cf9dd55
DH
1968 }
1969
abcbd3bf 1970 call->fid = vp->fid;
e49c7b2f
DH
1971 trace_afs_make_fs_call(call, &vp->fid);
1972 afs_make_op_call(op, call, GFP_NOFS);
5cf9dd55 1973}
260f082b
DH
1974
1975/*
1976 * deliver reply data to an FS.FetchACL
1977 */
1978static int afs_deliver_fs_fetch_acl(struct afs_call *call)
1979{
e49c7b2f
DH
1980 struct afs_operation *op = call->op;
1981 struct afs_vnode_param *vp = &op->file[0];
260f082b
DH
1982 struct afs_acl *acl;
1983 const __be32 *bp;
1984 unsigned int size;
1985 int ret;
1986
1987 _enter("{%u}", call->unmarshall);
1988
1989 switch (call->unmarshall) {
1990 case 0:
1991 afs_extract_to_tmp(call);
1992 call->unmarshall++;
df561f66 1993 fallthrough;
260f082b
DH
1994
1995 /* extract the returned data length */
1996 case 1:
1997 ret = afs_extract_data(call, true);
1998 if (ret < 0)
1999 return ret;
2000
2001 size = call->count2 = ntohl(call->tmp);
2002 size = round_up(size, 4);
2003
2004 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2005 if (!acl)
2006 return -ENOMEM;
e49c7b2f 2007 op->acl = acl;
260f082b
DH
2008 acl->size = call->count2;
2009 afs_extract_begin(call, acl->data, size);
2010 call->unmarshall++;
df561f66 2011 fallthrough;
260f082b
DH
2012
2013 /* extract the returned data */
2014 case 2:
2015 ret = afs_extract_data(call, true);
2016 if (ret < 0)
2017 return ret;
2018
2019 afs_extract_to_buf(call, (21 + 6) * 4);
2020 call->unmarshall++;
df561f66 2021 fallthrough;
260f082b
DH
2022
2023 /* extract the metadata */
2024 case 3:
2025 ret = afs_extract_data(call, false);
2026 if (ret < 0)
2027 return ret;
2028
2029 bp = call->buffer;
e49c7b2f
DH
2030 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
2031 xdr_decode_AFSVolSync(&bp, &op->volsync);
260f082b
DH
2032
2033 call->unmarshall++;
b2db6c35 2034 fallthrough;
260f082b
DH
2035
2036 case 4:
2037 break;
2038 }
2039
2040 _leave(" = 0 [done]");
2041 return 0;
2042}
2043
260f082b
DH
2044/*
2045 * FS.FetchACL operation type
2046 */
2047static const struct afs_call_type afs_RXFSFetchACL = {
2048 .name = "FS.FetchACL",
2049 .op = afs_FS_FetchACL,
2050 .deliver = afs_deliver_fs_fetch_acl,
260f082b
DH
2051};
2052
2053/*
2054 * Fetch the ACL for a file.
2055 */
e49c7b2f 2056void afs_fs_fetch_acl(struct afs_operation *op)
260f082b 2057{
e49c7b2f 2058 struct afs_vnode_param *vp = &op->file[0];
260f082b 2059 struct afs_call *call;
260f082b
DH
2060 __be32 *bp;
2061
2062 _enter(",%x,{%llx:%llu},,",
e49c7b2f 2063 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
260f082b 2064
e49c7b2f
DH
2065 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2066 if (!call)
2067 return afs_op_nomem(op);
260f082b
DH
2068
2069 /* marshall the parameters */
2070 bp = call->request;
2071 bp[0] = htonl(FSFETCHACL);
e49c7b2f
DH
2072 bp[1] = htonl(vp->fid.vid);
2073 bp[2] = htonl(vp->fid.vnode);
2074 bp[3] = htonl(vp->fid.unique);
b10494af 2075
abcbd3bf 2076 call->fid = vp->fid;
e49c7b2f
DH
2077 trace_afs_make_fs_call(call, &vp->fid);
2078 afs_make_op_call(op, call, GFP_KERNEL);
ffba718e
DH
2079}
2080
b10494af
JG
2081/*
2082 * FS.StoreACL operation type
2083 */
2084static const struct afs_call_type afs_RXFSStoreACL = {
2085 .name = "FS.StoreACL",
2086 .op = afs_FS_StoreACL,
ffba718e 2087 .deliver = afs_deliver_fs_file_status_and_vol,
b10494af
JG
2088 .destructor = afs_flat_call_destructor,
2089};
2090
2091/*
2092 * Fetch the ACL for a file.
2093 */
e49c7b2f 2094void afs_fs_store_acl(struct afs_operation *op)
b10494af 2095{
e49c7b2f 2096 struct afs_vnode_param *vp = &op->file[0];
b10494af 2097 struct afs_call *call;
e49c7b2f 2098 const struct afs_acl *acl = op->acl;
b10494af
JG
2099 size_t size;
2100 __be32 *bp;
2101
2102 _enter(",%x,{%llx:%llu},,",
e49c7b2f 2103 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
b10494af
JG
2104
2105 size = round_up(acl->size, 4);
e49c7b2f 2106 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreACL,
b10494af 2107 5 * 4 + size, (21 + 6) * 4);
e49c7b2f
DH
2108 if (!call)
2109 return afs_op_nomem(op);
b10494af
JG
2110
2111 /* marshall the parameters */
2112 bp = call->request;
2113 bp[0] = htonl(FSSTOREACL);
e49c7b2f
DH
2114 bp[1] = htonl(vp->fid.vid);
2115 bp[2] = htonl(vp->fid.vnode);
2116 bp[3] = htonl(vp->fid.unique);
b10494af
JG
2117 bp[4] = htonl(acl->size);
2118 memcpy(&bp[5], acl->data, acl->size);
2119 if (acl->size != size)
2120 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2121
abcbd3bf 2122 call->fid = vp->fid;
e49c7b2f
DH
2123 trace_afs_make_fs_call(call, &vp->fid);
2124 afs_make_op_call(op, call, GFP_KERNEL);
5cf9dd55 2125}