fsclient.c 20.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
/* fsclient.c: AFS File Server client stubs
 *
 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells (dhowells@redhat.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */

#include <linux/init.h>
#include <linux/sched.h>
#include <rxrpc/rxrpc.h>
#include <rxrpc/transport.h>
#include <rxrpc/connection.h>
#include <rxrpc/call.h>
#include "fsclient.h"
#include "cmservice.h"
#include "vnode.h"
#include "server.h"
#include "errors.h"
#include "internal.h"

#define FSFETCHSTATUS		132	/* AFS Fetch file status */
#define FSFETCHDATA		130	/* AFS Fetch file data */
#define FSGIVEUPCALLBACKS	147	/* AFS Discard callback promises */
#define FSGETVOLUMEINFO		148	/* AFS Get root volume information */
#define FSGETROOTVOLUME		151	/* AFS Get root volume name */
#define FSLOOKUP		161	/* AFS lookup file in directory */

/*
 * map afs abort codes to/from Linux error codes
 * - called with call->lock held
 */
static void afs_rxfs_aemap(struct rxrpc_call *call)
{
	switch (call->app_err_state) {
	case RXRPC_ESTATE_LOCAL_ABORT:
		call->app_abort_code = -call->app_errno;
		break;
	case RXRPC_ESTATE_PEER_ABORT:
		call->app_errno = afs_abort_to_error(call->app_abort_code);
		break;
	default:
		break;
	}
D
David Howells 已提交
48
}
L
Linus Torvalds 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

/*
 * get the root volume name from a fileserver
 * - this operation doesn't seem to work correctly in OpenAFS server 1.2.2
 */
#if 0
int afs_rxfs_get_root_volume(struct afs_server *server,
			     char *buf, size_t *buflen)
{
	struct rxrpc_connection *conn;
	struct rxrpc_call *call;
	struct kvec piov[2];
	size_t sent;
	int ret;
	u32 param[1];

	DECLARE_WAITQUEUE(myself, current);

	kenter("%p,%p,%u",server, buf, *buflen);

	/* get hold of the fileserver connection */
	ret = afs_server_get_fsconn(server, &conn);
	if (ret < 0)
		goto out;

	/* create a call through that connection */
	ret = rxrpc_create_call(conn, NULL, NULL, afs_rxfs_aemap, &call);
	if (ret < 0) {
		printk("kAFS: Unable to create call: %d\n", ret);
		goto out_put_conn;
	}
	call->app_opcode = FSGETROOTVOLUME;

	/* we want to get event notifications from the call */
	add_wait_queue(&call->waitq, &myself);

	/* marshall the parameters */
	param[0] = htonl(FSGETROOTVOLUME);

	piov[0].iov_len = sizeof(param);
	piov[0].iov_base = param;

	/* send the parameters to the server */
	ret = rxrpc_call_write_data(call, 1, piov, RXRPC_LAST_PACKET, GFP_NOFS,
				    0, &sent);
	if (ret < 0)
		goto abort;

	/* wait for the reply to completely arrive */
	for (;;) {
		set_current_state(TASK_INTERRUPTIBLE);
		if (call->app_call_state != RXRPC_CSTATE_CLNT_RCV_REPLY ||
		    signal_pending(current))
			break;
		schedule();
	}
	set_current_state(TASK_RUNNING);

	ret = -EINTR;
	if (signal_pending(current))
		goto abort;

	switch (call->app_call_state) {
	case RXRPC_CSTATE_ERROR:
		ret = call->app_errno;
		kdebug("Got Error: %d", ret);
		goto out_unwait;

	case RXRPC_CSTATE_CLNT_GOT_REPLY:
		/* read the reply */
		kdebug("Got Reply: qty=%d", call->app_ready_qty);

		ret = -EBADMSG;
		if (call->app_ready_qty <= 4)
			goto abort;

		ret = rxrpc_call_read_data(call, NULL, call->app_ready_qty, 0);
		if (ret < 0)
			goto abort;

#if 0
		/* unmarshall the reply */
		bp = buffer;
		for (loop = 0; loop < 65; loop++)
			entry->name[loop] = ntohl(*bp++);
		entry->name[64] = 0;

		entry->type = ntohl(*bp++);
		entry->num_servers = ntohl(*bp++);

		for (loop = 0; loop < 8; loop++)
			entry->servers[loop].addr.s_addr = *bp++;

		for (loop = 0; loop < 8; loop++)
			entry->servers[loop].partition = ntohl(*bp++);

		for (loop = 0; loop < 8; loop++)
			entry->servers[loop].flags = ntohl(*bp++);

		for (loop = 0; loop < 3; loop++)
			entry->volume_ids[loop] = ntohl(*bp++);

		entry->clone_id = ntohl(*bp++);
		entry->flags = ntohl(*bp);
#endif

		/* success */
		ret = 0;
		goto out_unwait;

	default:
		BUG();
	}

D
David Howells 已提交
163
abort:
L
Linus Torvalds 已提交
164 165 166
	set_current_state(TASK_UNINTERRUPTIBLE);
	rxrpc_call_abort(call, ret);
	schedule();
D
David Howells 已提交
167
out_unwait:
L
Linus Torvalds 已提交
168 169 170
	set_current_state(TASK_RUNNING);
	remove_wait_queue(&call->waitq, &myself);
	rxrpc_put_call(call);
D
David Howells 已提交
171
out_put_conn:
L
Linus Torvalds 已提交
172
	afs_server_release_fsconn(server, conn);
D
David Howells 已提交
173
out:
L
Linus Torvalds 已提交
174 175
	kleave("");
	return ret;
D
David Howells 已提交
176
}
L
Linus Torvalds 已提交
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
#endif

/*
 * get information about a volume
 */
#if 0
int afs_rxfs_get_volume_info(struct afs_server *server,
			     const char *name,
			     struct afs_volume_info *vinfo)
{
	struct rxrpc_connection *conn;
	struct rxrpc_call *call;
	struct kvec piov[3];
	size_t sent;
	int ret;
	u32 param[2], *bp, zero;

	DECLARE_WAITQUEUE(myself, current);

	_enter("%p,%s,%p", server, name, vinfo);

	/* get hold of the fileserver connection */
	ret = afs_server_get_fsconn(server, &conn);
	if (ret < 0)
		goto out;

	/* create a call through that connection */
	ret = rxrpc_create_call(conn, NULL, NULL, afs_rxfs_aemap, &call);
	if (ret < 0) {
		printk("kAFS: Unable to create call: %d\n", ret);
		goto out_put_conn;
	}
	call->app_opcode = FSGETVOLUMEINFO;

	/* we want to get event notifications from the call */
	add_wait_queue(&call->waitq, &myself);

	/* marshall the parameters */
	piov[1].iov_len = strlen(name);
	piov[1].iov_base = (char *) name;

	zero = 0;
	piov[2].iov_len = (4 - (piov[1].iov_len & 3)) & 3;
	piov[2].iov_base = &zero;

	param[0] = htonl(FSGETVOLUMEINFO);
	param[1] = htonl(piov[1].iov_len);

	piov[0].iov_len = sizeof(param);
	piov[0].iov_base = param;

	/* send the parameters to the server */
	ret = rxrpc_call_write_data(call, 3, piov, RXRPC_LAST_PACKET, GFP_NOFS,
				    0, &sent);
	if (ret < 0)
		goto abort;

	/* wait for the reply to completely arrive */
	bp = rxrpc_call_alloc_scratch(call, 64);

	ret = rxrpc_call_read_data(call, bp, 64,
				   RXRPC_CALL_READ_BLOCK |
				   RXRPC_CALL_READ_ALL);
	if (ret < 0) {
		if (ret == -ECONNABORTED) {
			ret = call->app_errno;
			goto out_unwait;
		}
		goto abort;
	}

	/* unmarshall the reply */
	vinfo->vid = ntohl(*bp++);
	vinfo->type = ntohl(*bp++);

	vinfo->type_vids[0] = ntohl(*bp++);
	vinfo->type_vids[1] = ntohl(*bp++);
	vinfo->type_vids[2] = ntohl(*bp++);
	vinfo->type_vids[3] = ntohl(*bp++);
	vinfo->type_vids[4] = ntohl(*bp++);

	vinfo->nservers = ntohl(*bp++);
	vinfo->servers[0].addr.s_addr = *bp++;
	vinfo->servers[1].addr.s_addr = *bp++;
	vinfo->servers[2].addr.s_addr = *bp++;
	vinfo->servers[3].addr.s_addr = *bp++;
	vinfo->servers[4].addr.s_addr = *bp++;
	vinfo->servers[5].addr.s_addr = *bp++;
	vinfo->servers[6].addr.s_addr = *bp++;
	vinfo->servers[7].addr.s_addr = *bp++;

	ret = -EBADMSG;
	if (vinfo->nservers > 8)
		goto abort;

	/* success */
	ret = 0;

D
David Howells 已提交
275
out_unwait:
L
Linus Torvalds 已提交
276 277 278
	set_current_state(TASK_RUNNING);
	remove_wait_queue(&call->waitq, &myself);
	rxrpc_put_call(call);
D
David Howells 已提交
279
out_put_conn:
L
Linus Torvalds 已提交
280
	afs_server_release_fsconn(server, conn);
D
David Howells 已提交
281
out:
L
Linus Torvalds 已提交
282 283 284
	_leave("");
	return ret;

D
David Howells 已提交
285
abort:
L
Linus Torvalds 已提交
286 287 288 289
	set_current_state(TASK_UNINTERRUPTIBLE);
	rxrpc_call_abort(call, ret);
	schedule();
	goto out_unwait;
D
David Howells 已提交
290
}
L
Linus Torvalds 已提交
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
#endif

/*
 * fetch the status information for a file
 */
int afs_rxfs_fetch_file_status(struct afs_server *server,
			       struct afs_vnode *vnode,
			       struct afs_volsync *volsync)
{
	struct afs_server_callslot callslot;
	struct rxrpc_call *call;
	struct kvec piov[1];
	size_t sent;
	int ret;
	__be32 *bp;

	DECLARE_WAITQUEUE(myself, current);

	_enter("%p,{%u,%u,%u}",
	       server, vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique);

	/* get hold of the fileserver connection */
	ret = afs_server_request_callslot(server, &callslot);
	if (ret < 0)
		goto out;

	/* create a call through that connection */
	ret = rxrpc_create_call(callslot.conn, NULL, NULL, afs_rxfs_aemap,
				&call);
	if (ret < 0) {
		printk("kAFS: Unable to create call: %d\n", ret);
		goto out_put_conn;
	}
	call->app_opcode = FSFETCHSTATUS;

	/* we want to get event notifications from the call */
	add_wait_queue(&call->waitq, &myself);

	/* marshall the parameters */
	bp = rxrpc_call_alloc_scratch(call, 16);
	bp[0] = htonl(FSFETCHSTATUS);
	bp[1] = htonl(vnode->fid.vid);
	bp[2] = htonl(vnode->fid.vnode);
	bp[3] = htonl(vnode->fid.unique);

	piov[0].iov_len = 16;
	piov[0].iov_base = bp;

	/* send the parameters to the server */
	ret = rxrpc_call_write_data(call, 1, piov, RXRPC_LAST_PACKET, GFP_NOFS,
				    0, &sent);
	if (ret < 0)
		goto abort;

	/* wait for the reply to completely arrive */
	bp = rxrpc_call_alloc_scratch(call, 120);

	ret = rxrpc_call_read_data(call, bp, 120,
				   RXRPC_CALL_READ_BLOCK |
				   RXRPC_CALL_READ_ALL);
	if (ret < 0) {
		if (ret == -ECONNABORTED) {
			ret = call->app_errno;
			goto out_unwait;
		}
		goto abort;
	}

	/* unmarshall the reply */
	vnode->status.if_version	= ntohl(*bp++);
	vnode->status.type		= ntohl(*bp++);
	vnode->status.nlink		= ntohl(*bp++);
	vnode->status.size		= ntohl(*bp++);
	vnode->status.version		= ntohl(*bp++);
	vnode->status.author		= ntohl(*bp++);
	vnode->status.owner		= ntohl(*bp++);
	vnode->status.caller_access	= ntohl(*bp++);
	vnode->status.anon_access	= ntohl(*bp++);
	vnode->status.mode		= ntohl(*bp++);
	vnode->status.parent.vid	= vnode->fid.vid;
	vnode->status.parent.vnode	= ntohl(*bp++);
	vnode->status.parent.unique	= ntohl(*bp++);
	bp++; /* seg size */
	vnode->status.mtime_client	= ntohl(*bp++);
	vnode->status.mtime_server	= ntohl(*bp++);
	bp++; /* group */
	bp++; /* sync counter */
	vnode->status.version |= ((unsigned long long) ntohl(*bp++)) << 32;
	bp++; /* spare2 */
	bp++; /* spare3 */
	bp++; /* spare4 */

	vnode->cb_version		= ntohl(*bp++);
	vnode->cb_expiry		= ntohl(*bp++);
	vnode->cb_type			= ntohl(*bp++);

	if (volsync) {
		volsync->creation	= ntohl(*bp++);
		bp++; /* spare2 */
		bp++; /* spare3 */
		bp++; /* spare4 */
		bp++; /* spare5 */
		bp++; /* spare6 */
	}

	/* success */
	ret = 0;

D
David Howells 已提交
399
out_unwait:
L
Linus Torvalds 已提交
400 401 402
	set_current_state(TASK_RUNNING);
	remove_wait_queue(&call->waitq, &myself);
	rxrpc_put_call(call);
D
David Howells 已提交
403
out_put_conn:
L
Linus Torvalds 已提交
404
	afs_server_release_callslot(server, &callslot);
D
David Howells 已提交
405
out:
L
Linus Torvalds 已提交
406 407 408
	_leave("");
	return ret;

D
David Howells 已提交
409
abort:
L
Linus Torvalds 已提交
410 411 412 413
	set_current_state(TASK_UNINTERRUPTIBLE);
	rxrpc_call_abort(call, ret);
	schedule();
	goto out_unwait;
D
David Howells 已提交
414
}
L
Linus Torvalds 已提交
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543

/*
 * fetch the contents of a file or directory
 */
int afs_rxfs_fetch_file_data(struct afs_server *server,
			     struct afs_vnode *vnode,
			     struct afs_rxfs_fetch_descriptor *desc,
			     struct afs_volsync *volsync)
{
	struct afs_server_callslot callslot;
	struct rxrpc_call *call;
	struct kvec piov[1];
	size_t sent;
	int ret;
	__be32 *bp;

	DECLARE_WAITQUEUE(myself, current);

	_enter("%p,{fid={%u,%u,%u},sz=%Zu,of=%lu}",
	       server,
	       desc->fid.vid,
	       desc->fid.vnode,
	       desc->fid.unique,
	       desc->size,
	       desc->offset);

	/* get hold of the fileserver connection */
	ret = afs_server_request_callslot(server, &callslot);
	if (ret < 0)
		goto out;

	/* create a call through that connection */
	ret = rxrpc_create_call(callslot.conn, NULL, NULL, afs_rxfs_aemap, &call);
	if (ret < 0) {
		printk("kAFS: Unable to create call: %d\n", ret);
		goto out_put_conn;
	}
	call->app_opcode = FSFETCHDATA;

	/* we want to get event notifications from the call */
	add_wait_queue(&call->waitq, &myself);

	/* marshall the parameters */
	bp = rxrpc_call_alloc_scratch(call, 24);
	bp[0] = htonl(FSFETCHDATA);
	bp[1] = htonl(desc->fid.vid);
	bp[2] = htonl(desc->fid.vnode);
	bp[3] = htonl(desc->fid.unique);
	bp[4] = htonl(desc->offset);
	bp[5] = htonl(desc->size);

	piov[0].iov_len = 24;
	piov[0].iov_base = bp;

	/* send the parameters to the server */
	ret = rxrpc_call_write_data(call, 1, piov, RXRPC_LAST_PACKET, GFP_NOFS,
				    0, &sent);
	if (ret < 0)
		goto abort;

	/* wait for the data count to arrive */
	ret = rxrpc_call_read_data(call, bp, 4, RXRPC_CALL_READ_BLOCK);
	if (ret < 0)
		goto read_failed;

	desc->actual = ntohl(bp[0]);
	if (desc->actual != desc->size) {
		ret = -EBADMSG;
		goto abort;
	}

	/* call the app to read the actual data */
	rxrpc_call_reset_scratch(call);

	ret = rxrpc_call_read_data(call, desc->buffer, desc->actual,
				   RXRPC_CALL_READ_BLOCK);
	if (ret < 0)
		goto read_failed;

	/* wait for the rest of the reply to completely arrive */
	rxrpc_call_reset_scratch(call);
	bp = rxrpc_call_alloc_scratch(call, 120);

	ret = rxrpc_call_read_data(call, bp, 120,
				   RXRPC_CALL_READ_BLOCK |
				   RXRPC_CALL_READ_ALL);
	if (ret < 0)
		goto read_failed;

	/* unmarshall the reply */
	vnode->status.if_version	= ntohl(*bp++);
	vnode->status.type		= ntohl(*bp++);
	vnode->status.nlink		= ntohl(*bp++);
	vnode->status.size		= ntohl(*bp++);
	vnode->status.version		= ntohl(*bp++);
	vnode->status.author		= ntohl(*bp++);
	vnode->status.owner		= ntohl(*bp++);
	vnode->status.caller_access	= ntohl(*bp++);
	vnode->status.anon_access	= ntohl(*bp++);
	vnode->status.mode		= ntohl(*bp++);
	vnode->status.parent.vid	= desc->fid.vid;
	vnode->status.parent.vnode	= ntohl(*bp++);
	vnode->status.parent.unique	= ntohl(*bp++);
	bp++; /* seg size */
	vnode->status.mtime_client	= ntohl(*bp++);
	vnode->status.mtime_server	= ntohl(*bp++);
	bp++; /* group */
	bp++; /* sync counter */
	vnode->status.version |= ((unsigned long long) ntohl(*bp++)) << 32;
	bp++; /* spare2 */
	bp++; /* spare3 */
	bp++; /* spare4 */

	vnode->cb_version		= ntohl(*bp++);
	vnode->cb_expiry		= ntohl(*bp++);
	vnode->cb_type			= ntohl(*bp++);

	if (volsync) {
		volsync->creation	= ntohl(*bp++);
		bp++; /* spare2 */
		bp++; /* spare3 */
		bp++; /* spare4 */
		bp++; /* spare5 */
		bp++; /* spare6 */
	}

	/* success */
	ret = 0;

D
David Howells 已提交
544
out_unwait:
L
Linus Torvalds 已提交
545 546 547
	set_current_state(TASK_RUNNING);
	remove_wait_queue(&call->waitq,&myself);
	rxrpc_put_call(call);
D
David Howells 已提交
548
out_put_conn:
L
Linus Torvalds 已提交
549
	afs_server_release_callslot(server, &callslot);
D
David Howells 已提交
550
out:
L
Linus Torvalds 已提交
551 552 553
	_leave(" = %d", ret);
	return ret;

D
David Howells 已提交
554
read_failed:
L
Linus Torvalds 已提交
555 556 557 558 559
	if (ret == -ECONNABORTED) {
		ret = call->app_errno;
		goto out_unwait;
	}

D
David Howells 已提交
560
abort:
L
Linus Torvalds 已提交
561 562 563 564
	set_current_state(TASK_UNINTERRUPTIBLE);
	rxrpc_call_abort(call, ret);
	schedule();
	goto out_unwait;
D
David Howells 已提交
565
}
L
Linus Torvalds 已提交
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649

/*
 * ask the AFS fileserver to discard a callback request on a file
 */
int afs_rxfs_give_up_callback(struct afs_server *server,
			      struct afs_vnode *vnode)
{
	struct afs_server_callslot callslot;
	struct rxrpc_call *call;
	struct kvec piov[1];
	size_t sent;
	int ret;
	__be32 *bp;

	DECLARE_WAITQUEUE(myself, current);

	_enter("%p,{%u,%u,%u}",
	       server, vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique);

	/* get hold of the fileserver connection */
	ret = afs_server_request_callslot(server, &callslot);
	if (ret < 0)
		goto out;

	/* create a call through that connection */
	ret = rxrpc_create_call(callslot.conn, NULL, NULL, afs_rxfs_aemap, &call);
	if (ret < 0) {
		printk("kAFS: Unable to create call: %d\n", ret);
		goto out_put_conn;
	}
	call->app_opcode = FSGIVEUPCALLBACKS;

	/* we want to get event notifications from the call */
	add_wait_queue(&call->waitq, &myself);

	/* marshall the parameters */
	bp = rxrpc_call_alloc_scratch(call, (1 + 4 + 4) * 4);

	piov[0].iov_len = (1 + 4 + 4) * 4;
	piov[0].iov_base = bp;

	*bp++ = htonl(FSGIVEUPCALLBACKS);
	*bp++ = htonl(1);
	*bp++ = htonl(vnode->fid.vid);
	*bp++ = htonl(vnode->fid.vnode);
	*bp++ = htonl(vnode->fid.unique);
	*bp++ = htonl(1);
	*bp++ = htonl(vnode->cb_version);
	*bp++ = htonl(vnode->cb_expiry);
	*bp++ = htonl(vnode->cb_type);

	/* send the parameters to the server */
	ret = rxrpc_call_write_data(call, 1, piov, RXRPC_LAST_PACKET, GFP_NOFS,
				    0, &sent);
	if (ret < 0)
		goto abort;

	/* wait for the reply to completely arrive */
	for (;;) {
		set_current_state(TASK_INTERRUPTIBLE);
		if (call->app_call_state != RXRPC_CSTATE_CLNT_RCV_REPLY ||
		    signal_pending(current))
			break;
		schedule();
	}
	set_current_state(TASK_RUNNING);

	ret = -EINTR;
	if (signal_pending(current))
		goto abort;

	switch (call->app_call_state) {
	case RXRPC_CSTATE_ERROR:
		ret = call->app_errno;
		goto out_unwait;

	case RXRPC_CSTATE_CLNT_GOT_REPLY:
		ret = 0;
		goto out_unwait;

	default:
		BUG();
	}

D
David Howells 已提交
650
out_unwait:
L
Linus Torvalds 已提交
651 652 653
	set_current_state(TASK_RUNNING);
	remove_wait_queue(&call->waitq, &myself);
	rxrpc_put_call(call);
D
David Howells 已提交
654
out_put_conn:
L
Linus Torvalds 已提交
655
	afs_server_release_callslot(server, &callslot);
D
David Howells 已提交
656
out:
L
Linus Torvalds 已提交
657 658 659
	_leave("");
	return ret;

D
David Howells 已提交
660
abort:
L
Linus Torvalds 已提交
661 662 663 664
	set_current_state(TASK_UNINTERRUPTIBLE);
	rxrpc_call_abort(call, ret);
	schedule();
	goto out_unwait;
D
David Howells 已提交
665
}
L
Linus Torvalds 已提交
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 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811

/*
 * look a filename up in a directory
 * - this operation doesn't seem to work correctly in OpenAFS server 1.2.2
 */
#if 0
int afs_rxfs_lookup(struct afs_server *server,
		    struct afs_vnode *dir,
		    const char *filename,
		    struct afs_vnode *vnode,
		    struct afs_volsync *volsync)
{
	struct rxrpc_connection *conn;
	struct rxrpc_call *call;
	struct kvec piov[3];
	size_t sent;
	int ret;
	u32 *bp, zero;

	DECLARE_WAITQUEUE(myself, current);

	kenter("%p,{%u,%u,%u},%s",
	       server, fid->vid, fid->vnode, fid->unique, filename);

	/* get hold of the fileserver connection */
	ret = afs_server_get_fsconn(server, &conn);
	if (ret < 0)
		goto out;

	/* create a call through that connection */
	ret = rxrpc_create_call(conn, NULL, NULL, afs_rxfs_aemap, &call);
	if (ret < 0) {
		printk("kAFS: Unable to create call: %d\n", ret);
		goto out_put_conn;
	}
	call->app_opcode = FSLOOKUP;

	/* we want to get event notifications from the call */
	add_wait_queue(&call->waitq,&myself);

	/* marshall the parameters */
	bp = rxrpc_call_alloc_scratch(call, 20);

	zero = 0;

	piov[0].iov_len = 20;
	piov[0].iov_base = bp;
	piov[1].iov_len = strlen(filename);
	piov[1].iov_base = (char *) filename;
	piov[2].iov_len = (4 - (piov[1].iov_len & 3)) & 3;
	piov[2].iov_base = &zero;

	*bp++ = htonl(FSLOOKUP);
	*bp++ = htonl(dirfid->vid);
	*bp++ = htonl(dirfid->vnode);
	*bp++ = htonl(dirfid->unique);
	*bp++ = htonl(piov[1].iov_len);

	/* send the parameters to the server */
	ret = rxrpc_call_write_data(call, 3, piov, RXRPC_LAST_PACKET, GFP_NOFS,
				    0, &sent);
	if (ret < 0)
		goto abort;

	/* wait for the reply to completely arrive */
	bp = rxrpc_call_alloc_scratch(call, 220);

	ret = rxrpc_call_read_data(call, bp, 220,
				   RXRPC_CALL_READ_BLOCK |
				   RXRPC_CALL_READ_ALL);
	if (ret < 0) {
		if (ret == -ECONNABORTED) {
			ret = call->app_errno;
			goto out_unwait;
		}
		goto abort;
	}

	/* unmarshall the reply */
	fid->vid		= ntohl(*bp++);
	fid->vnode		= ntohl(*bp++);
	fid->unique		= ntohl(*bp++);

	vnode->status.if_version	= ntohl(*bp++);
	vnode->status.type		= ntohl(*bp++);
	vnode->status.nlink		= ntohl(*bp++);
	vnode->status.size		= ntohl(*bp++);
	vnode->status.version		= ntohl(*bp++);
	vnode->status.author		= ntohl(*bp++);
	vnode->status.owner		= ntohl(*bp++);
	vnode->status.caller_access	= ntohl(*bp++);
	vnode->status.anon_access	= ntohl(*bp++);
	vnode->status.mode		= ntohl(*bp++);
	vnode->status.parent.vid	= dirfid->vid;
	vnode->status.parent.vnode	= ntohl(*bp++);
	vnode->status.parent.unique	= ntohl(*bp++);
	bp++; /* seg size */
	vnode->status.mtime_client	= ntohl(*bp++);
	vnode->status.mtime_server	= ntohl(*bp++);
	bp++; /* group */
	bp++; /* sync counter */
	vnode->status.version |= ((unsigned long long) ntohl(*bp++)) << 32;
	bp++; /* spare2 */
	bp++; /* spare3 */
	bp++; /* spare4 */

	dir->status.if_version		= ntohl(*bp++);
	dir->status.type		= ntohl(*bp++);
	dir->status.nlink		= ntohl(*bp++);
	dir->status.size		= ntohl(*bp++);
	dir->status.version		= ntohl(*bp++);
	dir->status.author		= ntohl(*bp++);
	dir->status.owner		= ntohl(*bp++);
	dir->status.caller_access	= ntohl(*bp++);
	dir->status.anon_access		= ntohl(*bp++);
	dir->status.mode		= ntohl(*bp++);
	dir->status.parent.vid		= dirfid->vid;
	dir->status.parent.vnode	= ntohl(*bp++);
	dir->status.parent.unique	= ntohl(*bp++);
	bp++; /* seg size */
	dir->status.mtime_client	= ntohl(*bp++);
	dir->status.mtime_server	= ntohl(*bp++);
	bp++; /* group */
	bp++; /* sync counter */
	dir->status.version |= ((unsigned long long) ntohl(*bp++)) << 32;
	bp++; /* spare2 */
	bp++; /* spare3 */
	bp++; /* spare4 */

	callback->fid		= *fid;
	callback->version	= ntohl(*bp++);
	callback->expiry	= ntohl(*bp++);
	callback->type		= ntohl(*bp++);

	if (volsync) {
		volsync->creation	= ntohl(*bp++);
		bp++; /* spare2 */
		bp++; /* spare3 */
		bp++; /* spare4 */
		bp++; /* spare5 */
		bp++; /* spare6 */
	}

	/* success */
	ret = 0;

D
David Howells 已提交
812
out_unwait:
L
Linus Torvalds 已提交
813 814 815
	set_current_state(TASK_RUNNING);
	remove_wait_queue(&call->waitq, &myself);
	rxrpc_put_call(call);
D
David Howells 已提交
816
out_put_conn:
L
Linus Torvalds 已提交
817
	afs_server_release_fsconn(server, conn);
D
David Howells 已提交
818
out:
L
Linus Torvalds 已提交
819 820 821
	kleave("");
	return ret;

D
David Howells 已提交
822
abort:
L
Linus Torvalds 已提交
823 824 825 826
	set_current_state(TASK_UNINTERRUPTIBLE);
	rxrpc_call_abort(call, ret);
	schedule();
	goto out_unwait;
D
David Howells 已提交
827
}
L
Linus Torvalds 已提交
828
#endif