Linux Audio

Check our new training course

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