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