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