fsclient.c 47.8 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
/* AFS File Server client stubs
L
Linus Torvalds 已提交
3
 *
4
 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
L
Linus Torvalds 已提交
5 6 7 8
 * Written by David Howells (dhowells@redhat.com)
 */

#include <linux/init.h>
9
#include <linux/slab.h>
L
Linus Torvalds 已提交
10
#include <linux/sched.h>
11
#include <linux/circ_buf.h>
J
Jeff Layton 已提交
12
#include <linux/iversion.h>
13
#include <linux/netfs.h>
L
Linus Torvalds 已提交
14
#include "internal.h"
15
#include "afs_fs.h"
D
David Howells 已提交
16
#include "xdr_fs.h"
17

18 19 20 21 22 23 24 25 26 27 28 29 30
/*
 * decode an AFSFid block
 */
static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
{
	const __be32 *bp = *_bp;

	fid->vid		= ntohl(*bp++);
	fid->vnode		= ntohl(*bp++);
	fid->unique		= ntohl(*bp++);
	*_bp = bp;
}

D
David Howells 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/*
 * Dump a bad file status record.
 */
static void xdr_dump_bad(const __be32 *bp)
{
	__be32 x[4];
	int i;

	pr_notice("AFS XDR: Bad status record\n");
	for (i = 0; i < 5 * 4 * 4; i += 16) {
		memcpy(x, bp, 16);
		bp += 4;
		pr_notice("%03x: %08x %08x %08x %08x\n",
			  i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
	}

	memcpy(x, bp, 4);
	pr_notice("0x50: %08x\n", ntohl(x[0]));
}

D
David Howells 已提交
51 52 53
/*
 * decode an AFSFetchStatus block
 */
54 55 56
static void xdr_decode_AFSFetchStatus(const __be32 **_bp,
				      struct afs_call *call,
				      struct afs_status_cb *scb)
D
David Howells 已提交
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;
D
David Howells 已提交
62
	u32 type, abort_code;
63

64 65
	abort_code = ntohl(xdr->abort_code);

D
David Howells 已提交
66
	if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
67 68 69 70 71 72 73 74
		if (xdr->if_version == htonl(0) &&
		    abort_code != 0 &&
		    inline_error) {
			/* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
			 * whereby it doesn't set the interface version in the error
			 * case.
			 */
			status->abort_code = abort_code;
75
			scb->have_error = true;
76
			goto advance;
77 78
		}

D
David Howells 已提交
79 80 81
		pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
		goto bad;
	}
82

83 84
	if (abort_code != 0 && inline_error) {
		status->abort_code = abort_code;
85
		scb->have_error = true;
86
		goto advance;
87 88
	}

D
David Howells 已提交
89 90
	type = ntohl(xdr->type);
	switch (type) {
D
David Howells 已提交
91 92 93
	case AFS_FTYPE_FILE:
	case AFS_FTYPE_DIR:
	case AFS_FTYPE_SYMLINK:
D
David Howells 已提交
94
		status->type = type;
D
David Howells 已提交
95 96
		break;
	default:
D
David Howells 已提交
97
		goto bad;
D
David Howells 已提交
98 99
	}

100 101 102 103 104 105 106 107
	status->nlink		= ntohl(xdr->nlink);
	status->author		= ntohl(xdr->author);
	status->owner		= ntohl(xdr->owner);
	status->caller_access	= ntohl(xdr->caller_access); /* Ticket dependent */
	status->anon_access	= ntohl(xdr->anon_access);
	status->mode		= ntohl(xdr->mode) & S_IALLUGO;
	status->group		= ntohl(xdr->group);
	status->lock_count	= ntohl(xdr->lock_count);
D
David Howells 已提交
108

109 110 111 112
	status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
	status->mtime_client.tv_nsec = 0;
	status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
	status->mtime_server.tv_nsec = 0;
D
David Howells 已提交
113 114 115

	size  = (u64)ntohl(xdr->size_lo);
	size |= (u64)ntohl(xdr->size_hi) << 32;
116
	status->size = size;
D
David Howells 已提交
117 118 119

	data_version  = (u64)ntohl(xdr->data_version_lo);
	data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
120
	status->data_version = data_version;
121
	scb->have_status = true;
122
advance:
D
David Howells 已提交
123
	*_bp = (const void *)*_bp + sizeof(*xdr);
124
	return;
D
David Howells 已提交
125 126 127

bad:
	xdr_dump_bad(*_bp);
128
	afs_protocol_error(call, afs_eproto_bad_status);
129
	goto advance;
130 131
}

132 133 134 135 136
static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
{
	return ktime_divns(call->reply_time, NSEC_PER_SEC) + expiry;
}

137 138 139
static void xdr_decode_AFSCallBack(const __be32 **_bp,
				   struct afs_call *call,
				   struct afs_status_cb *scb)
140
{
141
	struct afs_callback *cb = &scb->callback;
142 143
	const __be32 *bp = *_bp;

144
	bp++; /* version */
145
	cb->expires_at	= xdr_decode_expiry(call, ntohl(*bp++));
146
	bp++; /* type */
147
	scb->have_cb	= true;
148 149 150
	*_bp = bp;
}

L
Linus Torvalds 已提交
151
/*
152
 * decode an AFSVolSync block
L
Linus Torvalds 已提交
153
 */
154 155
static void xdr_decode_AFSVolSync(const __be32 **_bp,
				  struct afs_volsync *volsync)
L
Linus Torvalds 已提交
156
{
157
	const __be32 *bp = *_bp;
158
	u32 creation;
L
Linus Torvalds 已提交
159

160
	creation = ntohl(*bp++);
161 162 163 164 165 166
	bp++; /* spare2 */
	bp++; /* spare3 */
	bp++; /* spare4 */
	bp++; /* spare5 */
	bp++; /* spare6 */
	*_bp = bp;
167 168 169

	if (volsync)
		volsync->creation = creation;
170
}
L
Linus Torvalds 已提交
171

172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
/*
 * encode the requested attributes into an AFSStoreStatus block
 */
static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
{
	__be32 *bp = *_bp;
	u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;

	mask = 0;
	if (attr->ia_valid & ATTR_MTIME) {
		mask |= AFS_SET_MTIME;
		mtime = attr->ia_mtime.tv_sec;
	}

	if (attr->ia_valid & ATTR_UID) {
		mask |= AFS_SET_OWNER;
188
		owner = from_kuid(&init_user_ns, attr->ia_uid);
189 190 191 192
	}

	if (attr->ia_valid & ATTR_GID) {
		mask |= AFS_SET_GROUP;
193
		group = from_kgid(&init_user_ns, attr->ia_gid);
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
	}

	if (attr->ia_valid & ATTR_MODE) {
		mask |= AFS_SET_MODE;
		mode = attr->ia_mode & S_IALLUGO;
	}

	*bp++ = htonl(mask);
	*bp++ = htonl(mtime);
	*bp++ = htonl(owner);
	*bp++ = htonl(group);
	*bp++ = htonl(mode);
	*bp++ = 0;		/* segment size */
	*_bp = bp;
}

D
David Howells 已提交
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
/*
 * decode an AFSFetchVolumeStatus block
 */
static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
					    struct afs_volume_status *vs)
{
	const __be32 *bp = *_bp;

	vs->vid			= ntohl(*bp++);
	vs->parent_id		= ntohl(*bp++);
	vs->online		= ntohl(*bp++);
	vs->in_service		= ntohl(*bp++);
	vs->blessed		= ntohl(*bp++);
	vs->needs_salvage	= ntohl(*bp++);
	vs->type		= ntohl(*bp++);
	vs->min_quota		= ntohl(*bp++);
	vs->max_quota		= ntohl(*bp++);
	vs->blocks_in_use	= ntohl(*bp++);
	vs->part_blocks_avail	= ntohl(*bp++);
	vs->part_max_blocks	= ntohl(*bp++);
230 231
	vs->vol_copy_date	= 0;
	vs->vol_backup_date	= 0;
D
David Howells 已提交
232 233 234
	*_bp = bp;
}

235 236 237
/*
 * deliver reply data to an FS.FetchStatus
 */
238
static int afs_deliver_fs_fetch_status(struct afs_call *call)
239
{
240 241
	struct afs_operation *op = call->op;
	struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
242
	const __be32 *bp;
243
	int ret;
L
Linus Torvalds 已提交
244

245
	ret = afs_transfer_reply(call);
246 247
	if (ret < 0)
		return ret;
L
Linus Torvalds 已提交
248

249 250
	/* unmarshall the reply once we've received all of it */
	bp = call->buffer;
251 252 253
	xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
	xdr_decode_AFSCallBack(&bp, call, &vp->scb);
	xdr_decode_AFSVolSync(&bp, &op->volsync);
L
Linus Torvalds 已提交
254

255 256
	_leave(" = 0 [done]");
	return 0;
D
David Howells 已提交
257
}
258 259 260 261

/*
 * FS.FetchStatus operation type
 */
262 263
static const struct afs_call_type afs_RXFSFetchStatus = {
	.name		= "FS.FetchStatus",
264
	.op		= afs_FS_FetchStatus,
265
	.deliver	= afs_deliver_fs_fetch_status,
266 267
	.destructor	= afs_flat_call_destructor,
};
L
Linus Torvalds 已提交
268 269 270 271

/*
 * fetch the status information for a file
 */
272
void afs_fs_fetch_status(struct afs_operation *op)
L
Linus Torvalds 已提交
273
{
274
	struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
275
	struct afs_call *call;
L
Linus Torvalds 已提交
276 277
	__be32 *bp;

278
	_enter(",%x,{%llx:%llu},,",
279
	       key_serial(op->key), vp->fid.vid, vp->fid.vnode);
L
Linus Torvalds 已提交
280

281
	call = afs_alloc_flat_call(op->net, &afs_RXFSFetchStatus,
282
				   16, (21 + 3 + 6) * 4);
283 284
	if (!call)
		return afs_op_nomem(op);
L
Linus Torvalds 已提交
285 286

	/* marshall the parameters */
287
	bp = call->request;
L
Linus Torvalds 已提交
288
	bp[0] = htonl(FSFETCHSTATUS);
289 290 291
	bp[1] = htonl(vp->fid.vid);
	bp[2] = htonl(vp->fid.vnode);
	bp[3] = htonl(vp->fid.unique);
L
Linus Torvalds 已提交
292

293 294
	trace_afs_make_fs_call(call, &vp->fid);
	afs_make_op_call(op, call, GFP_NOFS);
D
David Howells 已提交
295
}
L
Linus Torvalds 已提交
296 297

/*
298
 * deliver reply data to an FS.FetchData
L
Linus Torvalds 已提交
299
 */
300
static int afs_deliver_fs_fetch_data(struct afs_call *call)
L
Linus Torvalds 已提交
301
{
302 303 304
	struct afs_operation *op = call->op;
	struct afs_vnode_param *vp = &op->file[0];
	struct afs_read *req = op->fetch.req;
305
	const __be32 *bp;
L
Linus Torvalds 已提交
306 307
	int ret;

308 309 310
	_enter("{%u,%zu,%zu/%llu}",
	       call->unmarshall, call->iov_len, iov_iter_count(call->iter),
	       req->actual_len);
311 312 313

	switch (call->unmarshall) {
	case 0:
314
		req->actual_len = 0;
315
		call->unmarshall++;
316 317 318 319 320
		if (call->operation_ID == FSFETCHDATA64) {
			afs_extract_to_tmp64(call);
		} else {
			call->tmp_u = htonl(0);
			afs_extract_to_tmp(call);
D
David Howells 已提交
321
		}
322
		fallthrough;
323

324 325 326 327
		/* Extract the returned data length into
		 * ->actual_len.  This may indicate more or less data than was
		 * requested will be returned.
		 */
328
	case 1:
329
		_debug("extract data length");
330
		ret = afs_extract_data(call, true);
331 332
		if (ret < 0)
			return ret;
L
Linus Torvalds 已提交
333

334
		req->actual_len = be64_to_cpu(call->tmp64);
335
		_debug("DATA length: %llu", req->actual_len);
336 337

		if (req->actual_len == 0)
338
			goto no_more_data;
339

340 341
		call->iter = req->iter;
		call->iov_len = min(req->actual_len, req->len);
342
		call->unmarshall++;
343
		fallthrough;
344

345
		/* extract the returned data */
346 347
	case 2:
		_debug("extract data %zu/%llu",
348
		       iov_iter_count(call->iter), req->actual_len);
349

350
		ret = afs_extract_data(call, true);
351 352
		if (ret < 0)
			return ret;
353

354
		call->iter = &call->def_iter;
355 356
		if (req->actual_len <= req->len)
			goto no_more_data;
357 358

		/* Discard any excess data the server gave us */
359
		afs_extract_discard(call, req->actual_len - req->len);
360
		call->unmarshall = 3;
361
		fallthrough;
362

363 364
	case 3:
		_debug("extract discard %zu/%llu",
365
		       iov_iter_count(call->iter), req->actual_len - req->len);
366 367

		ret = afs_extract_data(call, true);
368 369
		if (ret < 0)
			return ret;
L
Linus Torvalds 已提交
370

371
	no_more_data:
372 373
		call->unmarshall = 4;
		afs_extract_to_buf(call, (21 + 3 + 6) * 4);
374
		fallthrough;
L
Linus Torvalds 已提交
375

376
		/* extract the metadata */
377 378
	case 4:
		ret = afs_extract_data(call, false);
379 380
		if (ret < 0)
			return ret;
381 382

		bp = call->buffer;
383 384 385
		xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
		xdr_decode_AFSCallBack(&bp, call, &vp->scb);
		xdr_decode_AFSVolSync(&bp, &op->volsync);
386

387 388
		req->data_version = vp->scb.status.data_version;
		req->file_size = vp->scb.status.size;
389

390
		call->unmarshall++;
391
		fallthrough;
L
Linus Torvalds 已提交
392

393
	case 5:
394
		break;
L
Linus Torvalds 已提交
395 396
	}

397 398
	_leave(" = 0 [done]");
	return 0;
D
David Howells 已提交
399
}
L
Linus Torvalds 已提交
400 401

/*
402
 * FS.FetchData operation type
L
Linus Torvalds 已提交
403
 */
404
static const struct afs_call_type afs_RXFSFetchData = {
D
David Howells 已提交
405
	.name		= "FS.FetchData",
406
	.op		= afs_FS_FetchData,
407
	.deliver	= afs_deliver_fs_fetch_data,
408
	.destructor	= afs_flat_call_destructor,
409 410
};

D
David Howells 已提交
411 412
static const struct afs_call_type afs_RXFSFetchData64 = {
	.name		= "FS.FetchData64",
413
	.op		= afs_FS_FetchData64,
D
David Howells 已提交
414
	.deliver	= afs_deliver_fs_fetch_data,
415
	.destructor	= afs_flat_call_destructor,
D
David Howells 已提交
416 417 418 419 420
};

/*
 * fetch data from a very large file
 */
421
static void afs_fs_fetch_data64(struct afs_operation *op)
D
David Howells 已提交
422
{
423 424
	struct afs_vnode_param *vp = &op->file[0];
	struct afs_read *req = op->fetch.req;
D
David Howells 已提交
425 426 427 428 429
	struct afs_call *call;
	__be32 *bp;

	_enter("");

430
	call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
D
David Howells 已提交
431
	if (!call)
432
		return afs_op_nomem(op);
D
David Howells 已提交
433 434 435 436

	/* marshall the parameters */
	bp = call->request;
	bp[0] = htonl(FSFETCHDATA64);
437 438 439
	bp[1] = htonl(vp->fid.vid);
	bp[2] = htonl(vp->fid.vnode);
	bp[3] = htonl(vp->fid.unique);
440 441
	bp[4] = htonl(upper_32_bits(req->pos));
	bp[5] = htonl(lower_32_bits(req->pos));
D
David Howells 已提交
442
	bp[6] = 0;
443
	bp[7] = htonl(lower_32_bits(req->len));
D
David Howells 已提交
444

445 446
	trace_afs_make_fs_call(call, &vp->fid);
	afs_make_op_call(op, call, GFP_NOFS);
D
David Howells 已提交
447 448
}

449 450 451
/*
 * fetch data from a file
 */
452
void afs_fs_fetch_data(struct afs_operation *op)
L
Linus Torvalds 已提交
453
{
454
	struct afs_vnode_param *vp = &op->file[0];
455
	struct afs_call *call;
456
	struct afs_read *req = op->fetch.req;
L
Linus Torvalds 已提交
457 458
	__be32 *bp;

459
	if (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
460
		return afs_fs_fetch_data64(op);
D
David Howells 已提交
461

462
	_enter("");
L
Linus Torvalds 已提交
463

464
	call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
465
	if (!call)
466
		return afs_op_nomem(op);
L
Linus Torvalds 已提交
467

468 469
	req->call_debug_id = call->debug_id;

L
Linus Torvalds 已提交
470
	/* marshall the parameters */
471 472
	bp = call->request;
	bp[0] = htonl(FSFETCHDATA);
473 474 475
	bp[1] = htonl(vp->fid.vid);
	bp[2] = htonl(vp->fid.vnode);
	bp[3] = htonl(vp->fid.unique);
476 477
	bp[4] = htonl(lower_32_bits(req->pos));
	bp[5] = htonl(lower_32_bits(req->len));
L
Linus Torvalds 已提交
478

479 480
	trace_afs_make_fs_call(call, &vp->fid);
	afs_make_op_call(op, call, GFP_NOFS);
D
David Howells 已提交
481
}
482 483 484 485

/*
 * deliver reply data to an FS.CreateFile or an FS.MakeDir
 */
486
static int afs_deliver_fs_create_vnode(struct afs_call *call)
487
{
488 489 490
	struct afs_operation *op = call->op;
	struct afs_vnode_param *dvp = &op->file[0];
	struct afs_vnode_param *vp = &op->file[1];
491
	const __be32 *bp;
492
	int ret;
493

494
	ret = afs_transfer_reply(call);
495 496
	if (ret < 0)
		return ret;
497 498 499

	/* unmarshall the reply once we've received all of it */
	bp = call->buffer;
500 501 502 503 504
	xdr_decode_AFSFid(&bp, &op->file[1].fid);
	xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
	xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
	xdr_decode_AFSCallBack(&bp, call, &vp->scb);
	xdr_decode_AFSVolSync(&bp, &op->volsync);
505 506 507 508 509 510 511 512

	_leave(" = 0 [done]");
	return 0;
}

/*
 * FS.CreateFile and FS.MakeDir operation type
 */
513 514 515 516 517 518 519
static const struct afs_call_type afs_RXFSCreateFile = {
	.name		= "FS.CreateFile",
	.op		= afs_FS_CreateFile,
	.deliver	= afs_deliver_fs_create_vnode,
	.destructor	= afs_flat_call_destructor,
};

520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
/*
 * Create a file.
 */
void afs_fs_create_file(struct afs_operation *op)
{
	const struct qstr *name = &op->dentry->d_name;
	struct afs_vnode_param *dvp = &op->file[0];
	struct afs_call *call;
	size_t namesz, reqsz, padsz;
	__be32 *bp;

	_enter("");

	namesz = name->len;
	padsz = (4 - (namesz & 3)) & 3;
	reqsz = (5 * 4) + namesz + padsz + (6 * 4);

	call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile,
				   reqsz, (3 + 21 + 21 + 3 + 6) * 4);
	if (!call)
		return afs_op_nomem(op);

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSCREATEFILE);
	*bp++ = htonl(dvp->fid.vid);
	*bp++ = htonl(dvp->fid.vnode);
	*bp++ = htonl(dvp->fid.unique);
	*bp++ = htonl(namesz);
	memcpy(bp, name->name, namesz);
	bp = (void *) bp + namesz;
	if (padsz > 0) {
		memset(bp, 0, padsz);
		bp = (void *) bp + padsz;
	}
	*bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
	*bp++ = htonl(op->mtime.tv_sec); /* mtime */
	*bp++ = 0; /* owner */
	*bp++ = 0; /* group */
	*bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
	*bp++ = 0; /* segment size */

	trace_afs_make_fs_call1(call, &dvp->fid, name);
	afs_make_op_call(op, call, GFP_NOFS);
}

566 567 568
static const struct afs_call_type afs_RXFSMakeDir = {
	.name		= "FS.MakeDir",
	.op		= afs_FS_MakeDir,
569 570 571 572 573
	.deliver	= afs_deliver_fs_create_vnode,
	.destructor	= afs_flat_call_destructor,
};

/*
574
 * Create a new directory
575
 */
576
void afs_fs_make_dir(struct afs_operation *op)
577
{
578 579
	const struct qstr *name = &op->dentry->d_name;
	struct afs_vnode_param *dvp = &op->file[0];
580 581 582 583 584 585
	struct afs_call *call;
	size_t namesz, reqsz, padsz;
	__be32 *bp;

	_enter("");

586
	namesz = name->len;
587 588 589
	padsz = (4 - (namesz & 3)) & 3;
	reqsz = (5 * 4) + namesz + padsz + (6 * 4);

590 591
	call = afs_alloc_flat_call(op->net, &afs_RXFSMakeDir,
				   reqsz, (3 + 21 + 21 + 3 + 6) * 4);
592
	if (!call)
593
		return afs_op_nomem(op);
594 595 596

	/* marshall the parameters */
	bp = call->request;
597 598 599 600
	*bp++ = htonl(FSMAKEDIR);
	*bp++ = htonl(dvp->fid.vid);
	*bp++ = htonl(dvp->fid.vnode);
	*bp++ = htonl(dvp->fid.unique);
601
	*bp++ = htonl(namesz);
602
	memcpy(bp, name->name, namesz);
603 604 605 606 607
	bp = (void *) bp + namesz;
	if (padsz > 0) {
		memset(bp, 0, padsz);
		bp = (void *) bp + padsz;
	}
608
	*bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
609
	*bp++ = htonl(op->mtime.tv_sec); /* mtime */
610 611
	*bp++ = 0; /* owner */
	*bp++ = 0; /* group */
612
	*bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
613 614
	*bp++ = 0; /* segment size */

615 616
	trace_afs_make_fs_call1(call, &dvp->fid, name);
	afs_make_op_call(op, call, GFP_NOFS);
617 618 619
}

/*
620
 * Deliver reply data to any operation that returns status and volume sync.
621
 */
622
static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
623
{
624 625
	struct afs_operation *op = call->op;
	struct afs_vnode_param *vp = &op->file[0];
626
	const __be32 *bp;
627
	int ret;
628

629
	ret = afs_transfer_reply(call);
630 631
	if (ret < 0)
		return ret;
632 633 634

	/* unmarshall the reply once we've received all of it */
	bp = call->buffer;
635 636
	xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
	xdr_decode_AFSVolSync(&bp, &op->volsync);
637 638 639 640 641 642

	_leave(" = 0 [done]");
	return 0;
}

/*
643
 * FS.RemoveFile operation type
644
 */
645 646 647
static const struct afs_call_type afs_RXFSRemoveFile = {
	.name		= "FS.RemoveFile",
	.op		= afs_FS_RemoveFile,
648
	.deliver	= afs_deliver_fs_file_status_and_vol,
649 650 651
	.destructor	= afs_flat_call_destructor,
};

652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
/*
 * Remove a file.
 */
void afs_fs_remove_file(struct afs_operation *op)
{
	const struct qstr *name = &op->dentry->d_name;
	struct afs_vnode_param *dvp = &op->file[0];
	struct afs_call *call;
	size_t namesz, reqsz, padsz;
	__be32 *bp;

	_enter("");

	namesz = name->len;
	padsz = (4 - (namesz & 3)) & 3;
	reqsz = (5 * 4) + namesz + padsz;

	call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveFile,
				   reqsz, (21 + 6) * 4);
	if (!call)
		return afs_op_nomem(op);

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSREMOVEFILE);
	*bp++ = htonl(dvp->fid.vid);
	*bp++ = htonl(dvp->fid.vnode);
	*bp++ = htonl(dvp->fid.unique);
	*bp++ = htonl(namesz);
	memcpy(bp, name->name, namesz);
	bp = (void *) bp + namesz;
	if (padsz > 0) {
		memset(bp, 0, padsz);
		bp = (void *) bp + padsz;
	}

	trace_afs_make_fs_call1(call, &dvp->fid, name);
	afs_make_op_call(op, call, GFP_NOFS);
}

692 693 694
static const struct afs_call_type afs_RXFSRemoveDir = {
	.name		= "FS.RemoveDir",
	.op		= afs_FS_RemoveDir,
695
	.deliver	= afs_deliver_fs_file_status_and_vol,
696 697 698 699
	.destructor	= afs_flat_call_destructor,
};

/*
700
 * Remove a directory.
701
 */
702
void afs_fs_remove_dir(struct afs_operation *op)
703
{
704 705
	const struct qstr *name = &op->dentry->d_name;
	struct afs_vnode_param *dvp = &op->file[0];
706 707 708 709 710 711
	struct afs_call *call;
	size_t namesz, reqsz, padsz;
	__be32 *bp;

	_enter("");

712
	namesz = name->len;
713 714 715
	padsz = (4 - (namesz & 3)) & 3;
	reqsz = (5 * 4) + namesz + padsz;

716 717
	call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveDir,
				   reqsz, (21 + 6) * 4);
718
	if (!call)
719
		return afs_op_nomem(op);
720 721 722

	/* marshall the parameters */
	bp = call->request;
723 724 725 726
	*bp++ = htonl(FSREMOVEDIR);
	*bp++ = htonl(dvp->fid.vid);
	*bp++ = htonl(dvp->fid.vnode);
	*bp++ = htonl(dvp->fid.unique);
727
	*bp++ = htonl(namesz);
728
	memcpy(bp, name->name, namesz);
729 730 731 732 733 734
	bp = (void *) bp + namesz;
	if (padsz > 0) {
		memset(bp, 0, padsz);
		bp = (void *) bp + padsz;
	}

735 736
	trace_afs_make_fs_call1(call, &dvp->fid, name);
	afs_make_op_call(op, call, GFP_NOFS);
737 738 739 740 741
}

/*
 * deliver reply data to an FS.Link
 */
742
static int afs_deliver_fs_link(struct afs_call *call)
743
{
744 745 746
	struct afs_operation *op = call->op;
	struct afs_vnode_param *dvp = &op->file[0];
	struct afs_vnode_param *vp = &op->file[1];
747
	const __be32 *bp;
748
	int ret;
749

750
	_enter("{%u}", call->unmarshall);
751

752
	ret = afs_transfer_reply(call);
753 754
	if (ret < 0)
		return ret;
755 756 757

	/* unmarshall the reply once we've received all of it */
	bp = call->buffer;
758 759 760
	xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
	xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
	xdr_decode_AFSVolSync(&bp, &op->volsync);
761 762 763 764 765 766 767 768 769 770

	_leave(" = 0 [done]");
	return 0;
}

/*
 * FS.Link operation type
 */
static const struct afs_call_type afs_RXFSLink = {
	.name		= "FS.Link",
771
	.op		= afs_FS_Link,
772 773 774 775 776 777 778
	.deliver	= afs_deliver_fs_link,
	.destructor	= afs_flat_call_destructor,
};

/*
 * make a hard link
 */
779
void afs_fs_link(struct afs_operation *op)
780
{
781 782 783
	const struct qstr *name = &op->dentry->d_name;
	struct afs_vnode_param *dvp = &op->file[0];
	struct afs_vnode_param *vp = &op->file[1];
784 785 786 787 788 789
	struct afs_call *call;
	size_t namesz, reqsz, padsz;
	__be32 *bp;

	_enter("");

790
	namesz = name->len;
791 792 793
	padsz = (4 - (namesz & 3)) & 3;
	reqsz = (5 * 4) + namesz + padsz + (3 * 4);

794
	call = afs_alloc_flat_call(op->net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
795
	if (!call)
796
		return afs_op_nomem(op);
797 798 799 800

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSLINK);
801 802 803
	*bp++ = htonl(dvp->fid.vid);
	*bp++ = htonl(dvp->fid.vnode);
	*bp++ = htonl(dvp->fid.unique);
804
	*bp++ = htonl(namesz);
805
	memcpy(bp, name->name, namesz);
806 807 808 809 810
	bp = (void *) bp + namesz;
	if (padsz > 0) {
		memset(bp, 0, padsz);
		bp = (void *) bp + padsz;
	}
811 812 813 814 815 816
	*bp++ = htonl(vp->fid.vid);
	*bp++ = htonl(vp->fid.vnode);
	*bp++ = htonl(vp->fid.unique);

	trace_afs_make_fs_call1(call, &vp->fid, name);
	afs_make_op_call(op, call, GFP_NOFS);
817 818 819 820 821
}

/*
 * deliver reply data to an FS.Symlink
 */
822
static int afs_deliver_fs_symlink(struct afs_call *call)
823
{
824 825 826
	struct afs_operation *op = call->op;
	struct afs_vnode_param *dvp = &op->file[0];
	struct afs_vnode_param *vp = &op->file[1];
827
	const __be32 *bp;
828
	int ret;
829

830
	_enter("{%u}", call->unmarshall);
831

832
	ret = afs_transfer_reply(call);
833 834
	if (ret < 0)
		return ret;
835 836 837

	/* unmarshall the reply once we've received all of it */
	bp = call->buffer;
838 839 840 841
	xdr_decode_AFSFid(&bp, &vp->fid);
	xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
	xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
	xdr_decode_AFSVolSync(&bp, &op->volsync);
842 843 844 845 846 847 848 849 850 851

	_leave(" = 0 [done]");
	return 0;
}

/*
 * FS.Symlink operation type
 */
static const struct afs_call_type afs_RXFSSymlink = {
	.name		= "FS.Symlink",
852
	.op		= afs_FS_Symlink,
853 854 855 856 857 858 859
	.deliver	= afs_deliver_fs_symlink,
	.destructor	= afs_flat_call_destructor,
};

/*
 * create a symbolic link
 */
860
void afs_fs_symlink(struct afs_operation *op)
861
{
862 863
	const struct qstr *name = &op->dentry->d_name;
	struct afs_vnode_param *dvp = &op->file[0];
864 865 866 867 868 869
	struct afs_call *call;
	size_t namesz, reqsz, padsz, c_namesz, c_padsz;
	__be32 *bp;

	_enter("");

870
	namesz = name->len;
871 872
	padsz = (4 - (namesz & 3)) & 3;

873
	c_namesz = strlen(op->create.symlink);
874 875 876 877
	c_padsz = (4 - (c_namesz & 3)) & 3;

	reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);

878
	call = afs_alloc_flat_call(op->net, &afs_RXFSSymlink, reqsz,
879 880
				   (3 + 21 + 21 + 6) * 4);
	if (!call)
881
		return afs_op_nomem(op);
882 883 884 885

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSSYMLINK);
886 887 888
	*bp++ = htonl(dvp->fid.vid);
	*bp++ = htonl(dvp->fid.vnode);
	*bp++ = htonl(dvp->fid.unique);
889
	*bp++ = htonl(namesz);
890
	memcpy(bp, name->name, namesz);
891 892 893 894 895 896
	bp = (void *) bp + namesz;
	if (padsz > 0) {
		memset(bp, 0, padsz);
		bp = (void *) bp + padsz;
	}
	*bp++ = htonl(c_namesz);
897
	memcpy(bp, op->create.symlink, c_namesz);
898 899 900 901 902
	bp = (void *) bp + c_namesz;
	if (c_padsz > 0) {
		memset(bp, 0, c_padsz);
		bp = (void *) bp + c_padsz;
	}
903
	*bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
904
	*bp++ = htonl(op->mtime.tv_sec); /* mtime */
905 906 907 908 909
	*bp++ = 0; /* owner */
	*bp++ = 0; /* group */
	*bp++ = htonl(S_IRWXUGO); /* unix mode */
	*bp++ = 0; /* segment size */

910 911
	trace_afs_make_fs_call1(call, &dvp->fid, name);
	afs_make_op_call(op, call, GFP_NOFS);
912 913 914 915 916
}

/*
 * deliver reply data to an FS.Rename
 */
917
static int afs_deliver_fs_rename(struct afs_call *call)
918
{
919 920 921
	struct afs_operation *op = call->op;
	struct afs_vnode_param *orig_dvp = &op->file[0];
	struct afs_vnode_param *new_dvp = &op->file[1];
922
	const __be32 *bp;
923
	int ret;
924

925
	ret = afs_transfer_reply(call);
926 927
	if (ret < 0)
		return ret;
928

929
	bp = call->buffer;
930 931 932
	/* If the two dirs are the same, we have two copies of the same status
	 * report, so we just decode it twice.
	 */
933 934 935
	xdr_decode_AFSFetchStatus(&bp, call, &orig_dvp->scb);
	xdr_decode_AFSFetchStatus(&bp, call, &new_dvp->scb);
	xdr_decode_AFSVolSync(&bp, &op->volsync);
936 937 938 939 940 941 942 943 944 945

	_leave(" = 0 [done]");
	return 0;
}

/*
 * FS.Rename operation type
 */
static const struct afs_call_type afs_RXFSRename = {
	.name		= "FS.Rename",
946
	.op		= afs_FS_Rename,
947 948 949 950 951
	.deliver	= afs_deliver_fs_rename,
	.destructor	= afs_flat_call_destructor,
};

/*
952
 * Rename/move a file or directory.
953
 */
954
void afs_fs_rename(struct afs_operation *op)
955
{
956 957 958 959
	struct afs_vnode_param *orig_dvp = &op->file[0];
	struct afs_vnode_param *new_dvp = &op->file[1];
	const struct qstr *orig_name = &op->dentry->d_name;
	const struct qstr *new_name = &op->dentry_2->d_name;
960 961 962 963 964 965
	struct afs_call *call;
	size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
	__be32 *bp;

	_enter("");

966
	o_namesz = orig_name->len;
967 968
	o_padsz = (4 - (o_namesz & 3)) & 3;

969
	n_namesz = new_name->len;
970 971 972 973 974 975 976
	n_padsz = (4 - (n_namesz & 3)) & 3;

	reqsz = (4 * 4) +
		4 + o_namesz + o_padsz +
		(3 * 4) +
		4 + n_namesz + n_padsz;

977
	call = afs_alloc_flat_call(op->net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
978
	if (!call)
979
		return afs_op_nomem(op);
980 981 982 983

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSRENAME);
984 985 986
	*bp++ = htonl(orig_dvp->fid.vid);
	*bp++ = htonl(orig_dvp->fid.vnode);
	*bp++ = htonl(orig_dvp->fid.unique);
987
	*bp++ = htonl(o_namesz);
988
	memcpy(bp, orig_name->name, o_namesz);
989 990 991 992 993 994
	bp = (void *) bp + o_namesz;
	if (o_padsz > 0) {
		memset(bp, 0, o_padsz);
		bp = (void *) bp + o_padsz;
	}

995 996 997
	*bp++ = htonl(new_dvp->fid.vid);
	*bp++ = htonl(new_dvp->fid.vnode);
	*bp++ = htonl(new_dvp->fid.unique);
998
	*bp++ = htonl(n_namesz);
999
	memcpy(bp, new_name->name, n_namesz);
1000 1001 1002 1003 1004 1005
	bp = (void *) bp + n_namesz;
	if (n_padsz > 0) {
		memset(bp, 0, n_padsz);
		bp = (void *) bp + n_padsz;
	}

1006 1007
	trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
	afs_make_op_call(op, call, GFP_NOFS);
1008
}
1009 1010

/*
1011
 * Deliver reply data to FS.StoreData or FS.StoreStatus
1012
 */
1013
static int afs_deliver_fs_store_data(struct afs_call *call)
1014
{
1015 1016
	struct afs_operation *op = call->op;
	struct afs_vnode_param *vp = &op->file[0];
1017
	const __be32 *bp;
1018
	int ret;
1019

1020
	_enter("");
1021

1022
	ret = afs_transfer_reply(call);
1023 1024
	if (ret < 0)
		return ret;
1025 1026 1027

	/* unmarshall the reply once we've received all of it */
	bp = call->buffer;
1028 1029
	xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
	xdr_decode_AFSVolSync(&bp, &op->volsync);
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039

	_leave(" = 0 [done]");
	return 0;
}

/*
 * FS.StoreData operation type
 */
static const struct afs_call_type afs_RXFSStoreData = {
	.name		= "FS.StoreData",
1040
	.op		= afs_FS_StoreData,
1041 1042 1043 1044
	.deliver	= afs_deliver_fs_store_data,
	.destructor	= afs_flat_call_destructor,
};

D
David Howells 已提交
1045 1046
static const struct afs_call_type afs_RXFSStoreData64 = {
	.name		= "FS.StoreData64",
1047
	.op		= afs_FS_StoreData64,
D
David Howells 已提交
1048 1049 1050 1051 1052 1053 1054
	.deliver	= afs_deliver_fs_store_data,
	.destructor	= afs_flat_call_destructor,
};

/*
 * store a set of pages to a very large file
 */
D
David Howells 已提交
1055
static void afs_fs_store_data64(struct afs_operation *op)
D
David Howells 已提交
1056
{
1057
	struct afs_vnode_param *vp = &op->file[0];
D
David Howells 已提交
1058 1059 1060
	struct afs_call *call;
	__be32 *bp;

1061
	_enter(",%x,{%llx:%llu},,",
1062
	       key_serial(op->key), vp->fid.vid, vp->fid.vnode);
D
David Howells 已提交
1063

1064
	call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64,
D
David Howells 已提交
1065 1066 1067
				   (4 + 6 + 3 * 2) * 4,
				   (21 + 6) * 4);
	if (!call)
1068
		return afs_op_nomem(op);
D
David Howells 已提交
1069

D
David Howells 已提交
1070
	call->write_iter = op->store.write_iter;
D
David Howells 已提交
1071 1072 1073 1074

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSSTOREDATA64);
1075 1076 1077
	*bp++ = htonl(vp->fid.vid);
	*bp++ = htonl(vp->fid.vnode);
	*bp++ = htonl(vp->fid.unique);
D
David Howells 已提交
1078

1079
	*bp++ = htonl(AFS_SET_MTIME); /* mask */
1080
	*bp++ = htonl(op->mtime.tv_sec); /* mtime */
D
David Howells 已提交
1081 1082 1083 1084 1085
	*bp++ = 0; /* owner */
	*bp++ = 0; /* group */
	*bp++ = 0; /* unix mode */
	*bp++ = 0; /* segment size */

D
David Howells 已提交
1086 1087 1088 1089 1090 1091
	*bp++ = htonl(upper_32_bits(op->store.pos));
	*bp++ = htonl(lower_32_bits(op->store.pos));
	*bp++ = htonl(upper_32_bits(op->store.size));
	*bp++ = htonl(lower_32_bits(op->store.size));
	*bp++ = htonl(upper_32_bits(op->store.i_size));
	*bp++ = htonl(lower_32_bits(op->store.i_size));
1092 1093 1094

	trace_afs_make_fs_call(call, &vp->fid);
	afs_make_op_call(op, call, GFP_NOFS);
D
David Howells 已提交
1095 1096
}

1097
/*
D
David Howells 已提交
1098
 * Write data to a file on the server.
1099
 */
1100
void afs_fs_store_data(struct afs_operation *op)
1101
{
1102
	struct afs_vnode_param *vp = &op->file[0];
1103 1104 1105
	struct afs_call *call;
	__be32 *bp;

1106
	_enter(",%x,{%llx:%llu},,",
1107
	       key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1108 1109

	_debug("size %llx, at %llx, i_size %llx",
D
David Howells 已提交
1110 1111 1112
	       (unsigned long long)op->store.size,
	       (unsigned long long)op->store.pos,
	       (unsigned long long)op->store.i_size);
1113

1114
	if (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
D
David Howells 已提交
1115
		return afs_fs_store_data64(op);
1116

1117
	call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData,
1118 1119 1120
				   (4 + 6 + 3) * 4,
				   (21 + 6) * 4);
	if (!call)
1121
		return afs_op_nomem(op);
1122

D
David Howells 已提交
1123
	call->write_iter = op->store.write_iter;
1124 1125 1126 1127

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSSTOREDATA);
1128 1129 1130
	*bp++ = htonl(vp->fid.vid);
	*bp++ = htonl(vp->fid.vnode);
	*bp++ = htonl(vp->fid.unique);
1131

1132
	*bp++ = htonl(AFS_SET_MTIME); /* mask */
1133
	*bp++ = htonl(op->mtime.tv_sec); /* mtime */
1134 1135 1136 1137 1138
	*bp++ = 0; /* owner */
	*bp++ = 0; /* group */
	*bp++ = 0; /* unix mode */
	*bp++ = 0; /* segment size */

D
David Howells 已提交
1139 1140 1141
	*bp++ = htonl(lower_32_bits(op->store.pos));
	*bp++ = htonl(lower_32_bits(op->store.size));
	*bp++ = htonl(lower_32_bits(op->store.i_size));
1142

1143 1144
	trace_afs_make_fs_call(call, &vp->fid);
	afs_make_op_call(op, call, GFP_NOFS);
1145 1146 1147 1148 1149 1150 1151
}

/*
 * FS.StoreStatus operation type
 */
static const struct afs_call_type afs_RXFSStoreStatus = {
	.name		= "FS.StoreStatus",
1152
	.op		= afs_FS_StoreStatus,
1153
	.deliver	= afs_deliver_fs_store_data,
1154 1155 1156 1157 1158
	.destructor	= afs_flat_call_destructor,
};

static const struct afs_call_type afs_RXFSStoreData_as_Status = {
	.name		= "FS.StoreData",
1159
	.op		= afs_FS_StoreData,
1160
	.deliver	= afs_deliver_fs_store_data,
1161 1162 1163
	.destructor	= afs_flat_call_destructor,
};

D
David Howells 已提交
1164 1165
static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
	.name		= "FS.StoreData64",
1166
	.op		= afs_FS_StoreData64,
1167
	.deliver	= afs_deliver_fs_store_data,
D
David Howells 已提交
1168 1169 1170 1171 1172 1173 1174
	.destructor	= afs_flat_call_destructor,
};

/*
 * set the attributes on a very large file, using FS.StoreData rather than
 * FS.StoreStatus so as to alter the file size also
 */
1175
static void afs_fs_setattr_size64(struct afs_operation *op)
D
David Howells 已提交
1176
{
1177
	struct afs_vnode_param *vp = &op->file[0];
D
David Howells 已提交
1178
	struct afs_call *call;
1179
	struct iattr *attr = op->setattr.attr;
D
David Howells 已提交
1180 1181
	__be32 *bp;

1182
	_enter(",%x,{%llx:%llu},,",
1183
	       key_serial(op->key), vp->fid.vid, vp->fid.vnode);
D
David Howells 已提交
1184 1185 1186

	ASSERT(attr->ia_valid & ATTR_SIZE);

1187
	call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64_as_Status,
D
David Howells 已提交
1188 1189 1190
				   (4 + 6 + 3 * 2) * 4,
				   (21 + 6) * 4);
	if (!call)
1191
		return afs_op_nomem(op);
D
David Howells 已提交
1192 1193 1194 1195

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSSTOREDATA64);
1196 1197 1198
	*bp++ = htonl(vp->fid.vid);
	*bp++ = htonl(vp->fid.vnode);
	*bp++ = htonl(vp->fid.unique);
D
David Howells 已提交
1199 1200 1201

	xdr_encode_AFS_StoreStatus(&bp, attr);

1202 1203 1204
	*bp++ = htonl(upper_32_bits(attr->ia_size));	/* position of start of write */
	*bp++ = htonl(lower_32_bits(attr->ia_size));
	*bp++ = 0;					/* size of write */
D
David Howells 已提交
1205
	*bp++ = 0;
1206 1207 1208 1209 1210
	*bp++ = htonl(upper_32_bits(attr->ia_size));	/* new file length */
	*bp++ = htonl(lower_32_bits(attr->ia_size));

	trace_afs_make_fs_call(call, &vp->fid);
	afs_make_op_call(op, call, GFP_NOFS);
D
David Howells 已提交
1211 1212
}

1213 1214 1215 1216
/*
 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
 * so as to alter the file size also
 */
1217
static void afs_fs_setattr_size(struct afs_operation *op)
1218
{
1219
	struct afs_vnode_param *vp = &op->file[0];
1220
	struct afs_call *call;
1221
	struct iattr *attr = op->setattr.attr;
1222 1223
	__be32 *bp;

1224
	_enter(",%x,{%llx:%llu},,",
1225
	       key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1226 1227

	ASSERT(attr->ia_valid & ATTR_SIZE);
1228
	if (test_bit(AFS_SERVER_FL_HAS_FS64, &op->server->flags))
1229
		return afs_fs_setattr_size64(op);
1230

1231
	call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData_as_Status,
1232 1233 1234
				   (4 + 6 + 3) * 4,
				   (21 + 6) * 4);
	if (!call)
1235
		return afs_op_nomem(op);
1236 1237 1238 1239

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSSTOREDATA);
1240 1241 1242
	*bp++ = htonl(vp->fid.vid);
	*bp++ = htonl(vp->fid.vnode);
	*bp++ = htonl(vp->fid.unique);
1243 1244 1245

	xdr_encode_AFS_StoreStatus(&bp, attr);

1246
	*bp++ = htonl(attr->ia_size);		/* position of start of write */
1247 1248 1249
	*bp++ = 0;				/* size of write */
	*bp++ = htonl(attr->ia_size);		/* new file length */

1250 1251
	trace_afs_make_fs_call(call, &vp->fid);
	afs_make_op_call(op, call, GFP_NOFS);
1252 1253 1254 1255 1256 1257
}

/*
 * set the attributes on a file, using FS.StoreData if there's a change in file
 * size, and FS.StoreStatus otherwise
 */
1258
void afs_fs_setattr(struct afs_operation *op)
1259
{
1260
	struct afs_vnode_param *vp = &op->file[0];
1261
	struct afs_call *call;
1262
	struct iattr *attr = op->setattr.attr;
1263 1264 1265
	__be32 *bp;

	if (attr->ia_valid & ATTR_SIZE)
1266
		return afs_fs_setattr_size(op);
1267

1268
	_enter(",%x,{%llx:%llu},,",
1269
	       key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1270

1271
	call = afs_alloc_flat_call(op->net, &afs_RXFSStoreStatus,
1272 1273 1274
				   (4 + 6) * 4,
				   (21 + 6) * 4);
	if (!call)
1275
		return afs_op_nomem(op);
1276 1277 1278 1279

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSSTORESTATUS);
1280 1281 1282
	*bp++ = htonl(vp->fid.vid);
	*bp++ = htonl(vp->fid.vnode);
	*bp++ = htonl(vp->fid.unique);
1283

1284
	xdr_encode_AFS_StoreStatus(&bp, op->setattr.attr);
1285

1286 1287
	trace_afs_make_fs_call(call, &vp->fid);
	afs_make_op_call(op, call, GFP_NOFS);
1288
}
D
David Howells 已提交
1289 1290 1291 1292

/*
 * deliver reply data to an FS.GetVolumeStatus
 */
1293
static int afs_deliver_fs_get_volume_status(struct afs_call *call)
D
David Howells 已提交
1294
{
1295
	struct afs_operation *op = call->op;
D
David Howells 已提交
1296 1297
	const __be32 *bp;
	char *p;
1298
	u32 size;
D
David Howells 已提交
1299 1300
	int ret;

1301
	_enter("{%u}", call->unmarshall);
D
David Howells 已提交
1302 1303 1304 1305

	switch (call->unmarshall) {
	case 0:
		call->unmarshall++;
1306
		afs_extract_to_buf(call, 12 * 4);
1307
		fallthrough;
D
David Howells 已提交
1308

1309
		/* extract the returned status record */
D
David Howells 已提交
1310 1311
	case 1:
		_debug("extract status");
1312
		ret = afs_extract_data(call, true);
1313 1314
		if (ret < 0)
			return ret;
D
David Howells 已提交
1315 1316

		bp = call->buffer;
1317
		xdr_decode_AFSFetchVolumeStatus(&bp, &op->volstatus.vs);
D
David Howells 已提交
1318
		call->unmarshall++;
1319
		afs_extract_to_tmp(call);
1320
		fallthrough;
D
David Howells 已提交
1321

1322
		/* extract the volume name length */
D
David Howells 已提交
1323
	case 2:
1324
		ret = afs_extract_data(call, true);
1325 1326
		if (ret < 0)
			return ret;
D
David Howells 已提交
1327 1328 1329 1330

		call->count = ntohl(call->tmp);
		_debug("volname length: %u", call->count);
		if (call->count >= AFSNAMEMAX)
1331
			return afs_protocol_error(call, afs_eproto_volname_len);
1332
		size = (call->count + 3) & ~3; /* It's padded */
1333
		afs_extract_to_buf(call, size);
D
David Howells 已提交
1334
		call->unmarshall++;
1335
		fallthrough;
D
David Howells 已提交
1336

1337
		/* extract the volume name */
D
David Howells 已提交
1338 1339
	case 3:
		_debug("extract volname");
1340 1341 1342
		ret = afs_extract_data(call, true);
		if (ret < 0)
			return ret;
D
David Howells 已提交
1343

1344
		p = call->buffer;
D
David Howells 已提交
1345 1346
		p[call->count] = 0;
		_debug("volname '%s'", p);
1347
		afs_extract_to_tmp(call);
D
David Howells 已提交
1348
		call->unmarshall++;
1349
		fallthrough;
D
David Howells 已提交
1350

1351
		/* extract the offline message length */
1352 1353
	case 4:
		ret = afs_extract_data(call, true);
1354 1355
		if (ret < 0)
			return ret;
D
David Howells 已提交
1356 1357 1358 1359

		call->count = ntohl(call->tmp);
		_debug("offline msg length: %u", call->count);
		if (call->count >= AFSNAMEMAX)
1360
			return afs_protocol_error(call, afs_eproto_offline_msg_len);
1361
		size = (call->count + 3) & ~3; /* It's padded */
1362
		afs_extract_to_buf(call, size);
D
David Howells 已提交
1363
		call->unmarshall++;
1364
		fallthrough;
D
David Howells 已提交
1365

1366
		/* extract the offline message */
1367
	case 5:
D
David Howells 已提交
1368
		_debug("extract offline");
1369 1370 1371
		ret = afs_extract_data(call, true);
		if (ret < 0)
			return ret;
D
David Howells 已提交
1372

1373
		p = call->buffer;
D
David Howells 已提交
1374 1375 1376
		p[call->count] = 0;
		_debug("offline '%s'", p);

1377
		afs_extract_to_tmp(call);
D
David Howells 已提交
1378
		call->unmarshall++;
1379
		fallthrough;
D
David Howells 已提交
1380

1381
		/* extract the message of the day length */
1382 1383
	case 6:
		ret = afs_extract_data(call, true);
1384 1385
		if (ret < 0)
			return ret;
D
David Howells 已提交
1386 1387 1388 1389

		call->count = ntohl(call->tmp);
		_debug("motd length: %u", call->count);
		if (call->count >= AFSNAMEMAX)
1390
			return afs_protocol_error(call, afs_eproto_motd_len);
1391
		size = (call->count + 3) & ~3; /* It's padded */
1392
		afs_extract_to_buf(call, size);
D
David Howells 已提交
1393
		call->unmarshall++;
1394
		fallthrough;
D
David Howells 已提交
1395

1396
		/* extract the message of the day */
1397
	case 7:
D
David Howells 已提交
1398
		_debug("extract motd");
1399 1400 1401
		ret = afs_extract_data(call, false);
		if (ret < 0)
			return ret;
D
David Howells 已提交
1402

1403
		p = call->buffer;
D
David Howells 已提交
1404 1405 1406 1407
		p[call->count] = 0;
		_debug("motd '%s'", p);

		call->unmarshall++;
1408
		fallthrough;
D
David Howells 已提交
1409

1410
	case 8:
D
David Howells 已提交
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422
		break;
	}

	_leave(" = 0 [done]");
	return 0;
}

/*
 * FS.GetVolumeStatus operation type
 */
static const struct afs_call_type afs_RXFSGetVolumeStatus = {
	.name		= "FS.GetVolumeStatus",
1423
	.op		= afs_FS_GetVolumeStatus,
D
David Howells 已提交
1424
	.deliver	= afs_deliver_fs_get_volume_status,
1425
	.destructor	= afs_flat_call_destructor,
D
David Howells 已提交
1426 1427 1428 1429 1430
};

/*
 * fetch the status of a volume
 */
1431
void afs_fs_get_volume_status(struct afs_operation *op)
D
David Howells 已提交
1432
{
1433
	struct afs_vnode_param *vp = &op->file[0];
D
David Howells 已提交
1434 1435 1436 1437 1438
	struct afs_call *call;
	__be32 *bp;

	_enter("");

1439
	call = afs_alloc_flat_call(op->net, &afs_RXFSGetVolumeStatus, 2 * 4,
1440 1441
				   max(12 * 4, AFSOPAQUEMAX + 1));
	if (!call)
1442
		return afs_op_nomem(op);
D
David Howells 已提交
1443 1444 1445 1446

	/* marshall the parameters */
	bp = call->request;
	bp[0] = htonl(FSGETVOLUMESTATUS);
1447
	bp[1] = htonl(vp->fid.vid);
D
David Howells 已提交
1448

1449 1450
	trace_afs_make_fs_call(call, &vp->fid);
	afs_make_op_call(op, call, GFP_NOFS);
D
David Howells 已提交
1451
}
D
David Howells 已提交
1452 1453 1454 1455

/*
 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
 */
1456
static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
D
David Howells 已提交
1457
{
1458
	struct afs_operation *op = call->op;
D
David Howells 已提交
1459
	const __be32 *bp;
1460
	int ret;
D
David Howells 已提交
1461

1462
	_enter("{%u}", call->unmarshall);
D
David Howells 已提交
1463

1464
	ret = afs_transfer_reply(call);
1465 1466
	if (ret < 0)
		return ret;
D
David Howells 已提交
1467 1468 1469

	/* unmarshall the reply once we've received all of it */
	bp = call->buffer;
1470
	xdr_decode_AFSVolSync(&bp, &op->volsync);
D
David Howells 已提交
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480

	_leave(" = 0 [done]");
	return 0;
}

/*
 * FS.SetLock operation type
 */
static const struct afs_call_type afs_RXFSSetLock = {
	.name		= "FS.SetLock",
1481
	.op		= afs_FS_SetLock,
D
David Howells 已提交
1482
	.deliver	= afs_deliver_fs_xxxx_lock,
1483
	.done		= afs_lock_op_done,
D
David Howells 已提交
1484 1485 1486 1487 1488 1489 1490 1491
	.destructor	= afs_flat_call_destructor,
};

/*
 * FS.ExtendLock operation type
 */
static const struct afs_call_type afs_RXFSExtendLock = {
	.name		= "FS.ExtendLock",
1492
	.op		= afs_FS_ExtendLock,
D
David Howells 已提交
1493
	.deliver	= afs_deliver_fs_xxxx_lock,
1494
	.done		= afs_lock_op_done,
D
David Howells 已提交
1495 1496 1497 1498 1499 1500 1501 1502
	.destructor	= afs_flat_call_destructor,
};

/*
 * FS.ReleaseLock operation type
 */
static const struct afs_call_type afs_RXFSReleaseLock = {
	.name		= "FS.ReleaseLock",
1503
	.op		= afs_FS_ReleaseLock,
D
David Howells 已提交
1504 1505 1506 1507 1508
	.deliver	= afs_deliver_fs_xxxx_lock,
	.destructor	= afs_flat_call_destructor,
};

/*
1509
 * Set a lock on a file
D
David Howells 已提交
1510
 */
1511
void afs_fs_set_lock(struct afs_operation *op)
D
David Howells 已提交
1512
{
1513
	struct afs_vnode_param *vp = &op->file[0];
D
David Howells 已提交
1514 1515 1516 1517 1518
	struct afs_call *call;
	__be32 *bp;

	_enter("");

1519
	call = afs_alloc_flat_call(op->net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
D
David Howells 已提交
1520
	if (!call)
1521
		return afs_op_nomem(op);
D
David Howells 已提交
1522 1523 1524 1525

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSSETLOCK);
1526 1527 1528 1529 1530 1531 1532
	*bp++ = htonl(vp->fid.vid);
	*bp++ = htonl(vp->fid.vnode);
	*bp++ = htonl(vp->fid.unique);
	*bp++ = htonl(op->lock.type);

	trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
	afs_make_op_call(op, call, GFP_NOFS);
D
David Howells 已提交
1533 1534 1535 1536 1537
}

/*
 * extend a lock on a file
 */
1538
void afs_fs_extend_lock(struct afs_operation *op)
D
David Howells 已提交
1539
{
1540
	struct afs_vnode_param *vp = &op->file[0];
D
David Howells 已提交
1541 1542 1543 1544 1545
	struct afs_call *call;
	__be32 *bp;

	_enter("");

1546
	call = afs_alloc_flat_call(op->net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
D
David Howells 已提交
1547
	if (!call)
1548
		return afs_op_nomem(op);
D
David Howells 已提交
1549 1550 1551 1552

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSEXTENDLOCK);
1553 1554 1555 1556 1557 1558
	*bp++ = htonl(vp->fid.vid);
	*bp++ = htonl(vp->fid.vnode);
	*bp++ = htonl(vp->fid.unique);

	trace_afs_make_fs_call(call, &vp->fid);
	afs_make_op_call(op, call, GFP_NOFS);
D
David Howells 已提交
1559 1560 1561 1562 1563
}

/*
 * release a lock on a file
 */
1564
void afs_fs_release_lock(struct afs_operation *op)
D
David Howells 已提交
1565
{
1566
	struct afs_vnode_param *vp = &op->file[0];
D
David Howells 已提交
1567 1568 1569 1570 1571
	struct afs_call *call;
	__be32 *bp;

	_enter("");

1572
	call = afs_alloc_flat_call(op->net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
D
David Howells 已提交
1573
	if (!call)
1574
		return afs_op_nomem(op);
D
David Howells 已提交
1575 1576 1577 1578

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSRELEASELOCK);
1579 1580 1581 1582 1583 1584
	*bp++ = htonl(vp->fid.vid);
	*bp++ = htonl(vp->fid.vnode);
	*bp++ = htonl(vp->fid.unique);

	trace_afs_make_fs_call(call, &vp->fid);
	afs_make_op_call(op, call, GFP_NOFS);
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599
}

/*
 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
 */
static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
{
	return afs_transfer_reply(call);
}

/*
 * FS.GiveUpAllCallBacks operation type
 */
static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
	.name		= "FS.GiveUpAllCallBacks",
1600
	.op		= afs_FS_GiveUpAllCallBacks,
1601 1602 1603 1604 1605 1606 1607
	.deliver	= afs_deliver_fs_give_up_all_callbacks,
	.destructor	= afs_flat_call_destructor,
};

/*
 * Flush all the callbacks we have on a server.
 */
1608 1609
int afs_fs_give_up_all_callbacks(struct afs_net *net,
				 struct afs_server *server,
D
David Howells 已提交
1610
				 struct afs_addr_cursor *ac,
1611
				 struct key *key)
1612 1613 1614 1615 1616 1617
{
	struct afs_call *call;
	__be32 *bp;

	_enter("");

1618
	call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1619 1620 1621 1622 1623 1624 1625 1626 1627
	if (!call)
		return -ENOMEM;

	call->key = key;

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSGIVEUPALLCALLBACKS);

1628
	call->server = afs_use_server(server, afs_server_trace_give_up_cb);
1629 1630
	afs_make_call(ac, call, GFP_NOFS);
	return afs_wait_for_call_to_complete(call, ac);
1631 1632 1633 1634 1635 1636 1637 1638 1639 1640
}

/*
 * Deliver reply data to an FS.GetCapabilities operation.
 */
static int afs_deliver_fs_get_capabilities(struct afs_call *call)
{
	u32 count;
	int ret;

1641
	_enter("{%u,%zu}", call->unmarshall, iov_iter_count(call->iter));
1642 1643 1644

	switch (call->unmarshall) {
	case 0:
1645
		afs_extract_to_tmp(call);
1646
		call->unmarshall++;
1647
		fallthrough;
1648

1649
		/* Extract the capabilities word count */
1650
	case 1:
1651
		ret = afs_extract_data(call, true);
1652 1653 1654 1655 1656 1657
		if (ret < 0)
			return ret;

		count = ntohl(call->tmp);
		call->count = count;
		call->count2 = count;
1658 1659 1660 1661 1662 1663 1664 1665
		if (count == 0) {
			call->unmarshall = 4;
			call->tmp = 0;
			break;
		}

		/* Extract the first word of the capabilities to call->tmp */
		afs_extract_to_tmp(call);
1666
		call->unmarshall++;
1667
		fallthrough;
1668 1669

	case 2:
1670
		ret = afs_extract_data(call, false);
1671 1672 1673
		if (ret < 0)
			return ret;

1674 1675 1676 1677 1678 1679 1680 1681 1682
		afs_extract_discard(call, (count - 1) * sizeof(__be32));
		call->unmarshall++;
		fallthrough;

		/* Extract remaining capabilities words */
	case 3:
		ret = afs_extract_data(call, false);
		if (ret < 0)
			return ret;
1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696

		call->unmarshall++;
		break;
	}

	_leave(" = 0 [done]");
	return 0;
}

/*
 * FS.GetCapabilities operation type
 */
static const struct afs_call_type afs_RXFSGetCapabilities = {
	.name		= "FS.GetCapabilities",
1697
	.op		= afs_FS_GetCapabilities,
1698
	.deliver	= afs_deliver_fs_get_capabilities,
1699
	.done		= afs_fileserver_probe_result,
1700
	.destructor	= afs_flat_call_destructor,
1701 1702 1703
};

/*
1704 1705 1706 1707
 * Probe a fileserver for the capabilities that it supports.  This RPC can
 * reply with up to 196 words.  The operation is asynchronous and if we managed
 * to allocate a call, true is returned the result is delivered through the
 * ->done() - otherwise we return false to indicate we didn't even try.
1708
 */
1709 1710
bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
			     struct afs_addr_cursor *ac, struct key *key)
1711 1712 1713 1714 1715 1716 1717 1718
{
	struct afs_call *call;
	__be32 *bp;

	_enter("");

	call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
	if (!call)
1719
		return false;
1720 1721

	call->key = key;
1722
	call->server = afs_use_server(server, afs_server_trace_get_caps);
1723
	call->upgrade = true;
1724
	call->async = true;
1725
	call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
1726 1727 1728 1729 1730

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSGETCAPABILITIES);

1731
	trace_afs_make_fs_call(call, NULL);
1732
	afs_make_call(ac, call, GFP_NOFS);
1733 1734
	afs_put_call(call);
	return true;
D
David Howells 已提交
1735
}
1736 1737 1738 1739 1740 1741

/*
 * Deliver reply data to an FS.InlineBulkStatus call
 */
static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
{
1742
	struct afs_operation *op = call->op;
1743
	struct afs_status_cb *scb;
1744 1745 1746 1747 1748 1749 1750 1751
	const __be32 *bp;
	u32 tmp;
	int ret;

	_enter("{%u}", call->unmarshall);

	switch (call->unmarshall) {
	case 0:
1752
		afs_extract_to_tmp(call);
1753
		call->unmarshall++;
1754
		fallthrough;
1755 1756 1757 1758

		/* Extract the file status count and array in two steps */
	case 1:
		_debug("extract status count");
1759
		ret = afs_extract_data(call, true);
1760 1761 1762 1763
		if (ret < 0)
			return ret;

		tmp = ntohl(call->tmp);
1764 1765
		_debug("status count: %u/%u", tmp, op->nr_files);
		if (tmp != op->nr_files)
1766
			return afs_protocol_error(call, afs_eproto_ibulkst_count);
1767 1768 1769 1770

		call->count = 0;
		call->unmarshall++;
	more_counts:
1771
		afs_extract_to_buf(call, 21 * sizeof(__be32));
1772
		fallthrough;
1773

1774 1775
	case 2:
		_debug("extract status array %u", call->count);
1776
		ret = afs_extract_data(call, true);
1777 1778 1779
		if (ret < 0)
			return ret;

1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791
		switch (call->count) {
		case 0:
			scb = &op->file[0].scb;
			break;
		case 1:
			scb = &op->file[1].scb;
			break;
		default:
			scb = &op->more_files[call->count - 2].scb;
			break;
		}

1792
		bp = call->buffer;
1793
		xdr_decode_AFSFetchStatus(&bp, call, scb);
1794

1795
		call->count++;
1796
		if (call->count < op->nr_files)
1797 1798 1799 1800
			goto more_counts;

		call->count = 0;
		call->unmarshall++;
1801
		afs_extract_to_tmp(call);
1802
		fallthrough;
1803 1804 1805 1806

		/* Extract the callback count and array in two steps */
	case 3:
		_debug("extract CB count");
1807
		ret = afs_extract_data(call, true);
1808 1809 1810 1811 1812
		if (ret < 0)
			return ret;

		tmp = ntohl(call->tmp);
		_debug("CB count: %u", tmp);
1813
		if (tmp != op->nr_files)
1814
			return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
1815 1816 1817
		call->count = 0;
		call->unmarshall++;
	more_cbs:
1818
		afs_extract_to_buf(call, 3 * sizeof(__be32));
1819
		fallthrough;
1820

1821 1822
	case 4:
		_debug("extract CB array");
1823
		ret = afs_extract_data(call, true);
1824 1825 1826 1827
		if (ret < 0)
			return ret;

		_debug("unmarshall CB array");
1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839
		switch (call->count) {
		case 0:
			scb = &op->file[0].scb;
			break;
		case 1:
			scb = &op->file[1].scb;
			break;
		default:
			scb = &op->more_files[call->count - 2].scb;
			break;
		}

1840
		bp = call->buffer;
1841
		xdr_decode_AFSCallBack(&bp, call, scb);
1842
		call->count++;
1843
		if (call->count < op->nr_files)
1844 1845
			goto more_cbs;

1846
		afs_extract_to_buf(call, 6 * sizeof(__be32));
1847
		call->unmarshall++;
1848
		fallthrough;
1849

1850
	case 5:
1851
		ret = afs_extract_data(call, false);
1852 1853 1854 1855
		if (ret < 0)
			return ret;

		bp = call->buffer;
1856
		xdr_decode_AFSVolSync(&bp, &op->volsync);
1857 1858

		call->unmarshall++;
1859
		fallthrough;
1860 1861 1862 1863 1864 1865 1866 1867 1868

	case 6:
		break;
	}

	_leave(" = 0 [done]");
	return 0;
}

1869 1870 1871
static void afs_done_fs_inline_bulk_status(struct afs_call *call)
{
	if (call->error == -ECONNABORTED &&
1872
	    call->abort_code == RX_INVALID_OPERATION) {
1873
		set_bit(AFS_SERVER_FL_NO_IBULK, &call->server->flags);
1874 1875 1876
		if (call->op)
			set_bit(AFS_VOLUME_MAYBE_NO_IBULK, &call->op->volume->flags);
	}
1877 1878
}

1879 1880 1881 1882 1883 1884 1885
/*
 * FS.InlineBulkStatus operation type
 */
static const struct afs_call_type afs_RXFSInlineBulkStatus = {
	.name		= "FS.InlineBulkStatus",
	.op		= afs_FS_InlineBulkStatus,
	.deliver	= afs_deliver_fs_inline_bulk_status,
1886
	.done		= afs_done_fs_inline_bulk_status,
1887 1888 1889 1890 1891 1892
	.destructor	= afs_flat_call_destructor,
};

/*
 * Fetch the status information for up to 50 files
 */
1893
void afs_fs_inline_bulk_status(struct afs_operation *op)
1894
{
1895 1896
	struct afs_vnode_param *dvp = &op->file[0];
	struct afs_vnode_param *vp = &op->file[1];
1897 1898 1899 1900
	struct afs_call *call;
	__be32 *bp;
	int i;

1901
	if (test_bit(AFS_SERVER_FL_NO_IBULK, &op->server->flags)) {
1902 1903 1904
		op->error = -ENOTSUPP;
		return;
	}
1905

1906
	_enter(",%x,{%llx:%llu},%u",
1907
	       key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
1908

1909 1910
	call = afs_alloc_flat_call(op->net, &afs_RXFSInlineBulkStatus,
				   (2 + op->nr_files * 3) * 4,
1911
				   21 * 4);
1912 1913
	if (!call)
		return afs_op_nomem(op);
1914 1915 1916 1917

	/* marshall the parameters */
	bp = call->request;
	*bp++ = htonl(FSINLINEBULKSTATUS);
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928
	*bp++ = htonl(op->nr_files);
	*bp++ = htonl(dvp->fid.vid);
	*bp++ = htonl(dvp->fid.vnode);
	*bp++ = htonl(dvp->fid.unique);
	*bp++ = htonl(vp->fid.vid);
	*bp++ = htonl(vp->fid.vnode);
	*bp++ = htonl(vp->fid.unique);
	for (i = 0; i < op->nr_files - 2; i++) {
		*bp++ = htonl(op->more_files[i].fid.vid);
		*bp++ = htonl(op->more_files[i].fid.vnode);
		*bp++ = htonl(op->more_files[i].fid.unique);
1929 1930
	}

1931 1932
	trace_afs_make_fs_call(call, &vp->fid);
	afs_make_op_call(op, call, GFP_NOFS);
1933
}
D
David Howells 已提交
1934 1935 1936 1937 1938 1939

/*
 * deliver reply data to an FS.FetchACL
 */
static int afs_deliver_fs_fetch_acl(struct afs_call *call)
{
1940 1941
	struct afs_operation *op = call->op;
	struct afs_vnode_param *vp = &op->file[0];
D
David Howells 已提交
1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952
	struct afs_acl *acl;
	const __be32 *bp;
	unsigned int size;
	int ret;

	_enter("{%u}", call->unmarshall);

	switch (call->unmarshall) {
	case 0:
		afs_extract_to_tmp(call);
		call->unmarshall++;
1953
		fallthrough;
D
David Howells 已提交
1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966

		/* extract the returned data length */
	case 1:
		ret = afs_extract_data(call, true);
		if (ret < 0)
			return ret;

		size = call->count2 = ntohl(call->tmp);
		size = round_up(size, 4);

		acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
		if (!acl)
			return -ENOMEM;
1967
		op->acl = acl;
D
David Howells 已提交
1968 1969 1970
		acl->size = call->count2;
		afs_extract_begin(call, acl->data, size);
		call->unmarshall++;
1971
		fallthrough;
D
David Howells 已提交
1972 1973 1974 1975 1976 1977 1978 1979 1980

		/* extract the returned data */
	case 2:
		ret = afs_extract_data(call, true);
		if (ret < 0)
			return ret;

		afs_extract_to_buf(call, (21 + 6) * 4);
		call->unmarshall++;
1981
		fallthrough;
D
David Howells 已提交
1982 1983 1984 1985 1986 1987 1988 1989

		/* extract the metadata */
	case 3:
		ret = afs_extract_data(call, false);
		if (ret < 0)
			return ret;

		bp = call->buffer;
1990 1991
		xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
		xdr_decode_AFSVolSync(&bp, &op->volsync);
D
David Howells 已提交
1992 1993

		call->unmarshall++;
1994
		fallthrough;
D
David Howells 已提交
1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015

	case 4:
		break;
	}

	_leave(" = 0 [done]");
	return 0;
}

/*
 * FS.FetchACL operation type
 */
static const struct afs_call_type afs_RXFSFetchACL = {
	.name		= "FS.FetchACL",
	.op		= afs_FS_FetchACL,
	.deliver	= afs_deliver_fs_fetch_acl,
};

/*
 * Fetch the ACL for a file.
 */
2016
void afs_fs_fetch_acl(struct afs_operation *op)
D
David Howells 已提交
2017
{
2018
	struct afs_vnode_param *vp = &op->file[0];
D
David Howells 已提交
2019 2020 2021 2022
	struct afs_call *call;
	__be32 *bp;

	_enter(",%x,{%llx:%llu},,",
2023
	       key_serial(op->key), vp->fid.vid, vp->fid.vnode);
D
David Howells 已提交
2024

2025 2026 2027
	call = afs_alloc_flat_call(op->net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
	if (!call)
		return afs_op_nomem(op);
D
David Howells 已提交
2028 2029 2030 2031

	/* marshall the parameters */
	bp = call->request;
	bp[0] = htonl(FSFETCHACL);
2032 2033 2034
	bp[1] = htonl(vp->fid.vid);
	bp[2] = htonl(vp->fid.vnode);
	bp[3] = htonl(vp->fid.unique);
J
Joe Gorse 已提交
2035

2036 2037
	trace_afs_make_fs_call(call, &vp->fid);
	afs_make_op_call(op, call, GFP_KERNEL);
2038 2039
}

J
Joe Gorse 已提交
2040 2041 2042 2043 2044 2045
/*
 * FS.StoreACL operation type
 */
static const struct afs_call_type afs_RXFSStoreACL = {
	.name		= "FS.StoreACL",
	.op		= afs_FS_StoreACL,
2046
	.deliver	= afs_deliver_fs_file_status_and_vol,
J
Joe Gorse 已提交
2047 2048 2049 2050 2051 2052
	.destructor	= afs_flat_call_destructor,
};

/*
 * Fetch the ACL for a file.
 */
2053
void afs_fs_store_acl(struct afs_operation *op)
J
Joe Gorse 已提交
2054
{
2055
	struct afs_vnode_param *vp = &op->file[0];
J
Joe Gorse 已提交
2056
	struct afs_call *call;
2057
	const struct afs_acl *acl = op->acl;
J
Joe Gorse 已提交
2058 2059 2060 2061
	size_t size;
	__be32 *bp;

	_enter(",%x,{%llx:%llu},,",
2062
	       key_serial(op->key), vp->fid.vid, vp->fid.vnode);
J
Joe Gorse 已提交
2063 2064

	size = round_up(acl->size, 4);
2065
	call = afs_alloc_flat_call(op->net, &afs_RXFSStoreACL,
J
Joe Gorse 已提交
2066
				   5 * 4 + size, (21 + 6) * 4);
2067 2068
	if (!call)
		return afs_op_nomem(op);
J
Joe Gorse 已提交
2069 2070 2071 2072

	/* marshall the parameters */
	bp = call->request;
	bp[0] = htonl(FSSTOREACL);
2073 2074 2075
	bp[1] = htonl(vp->fid.vid);
	bp[2] = htonl(vp->fid.vnode);
	bp[3] = htonl(vp->fid.unique);
J
Joe Gorse 已提交
2076 2077 2078 2079 2080
	bp[4] = htonl(acl->size);
	memcpy(&bp[5], acl->data, acl->size);
	if (acl->size != size)
		memset((void *)&bp[5] + acl->size, 0, size - acl->size);

2081 2082
	trace_afs_make_fs_call(call, &vp->fid);
	afs_make_op_call(op, call, GFP_KERNEL);
2083
}