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