Linux Audio

Check our new training course

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