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