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