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