Linux Audio

Check our new training course

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