diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2007-07-01 12:12:56 -0400 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2007-07-10 23:40:45 -0400 |
commit | 5df36e78da9db1c5f02b429116ed98902bcc75e5 (patch) | |
tree | b8724195fa2f6a12a095ae4c63da58be3de0afdb /fs | |
parent | f18289931d705f9c4634b361341a1677bea97aca (diff) |
NFS: Clean up nfs_validate_mount_data
Move error handling code out of the main code path. The switch statement
was also improperly indented, according to Documentation/CodingStyle. This
prepares nfs_validate_mount_data for the addition of option string parsing.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/nfs/super.c | 125 |
1 files changed, 67 insertions, 58 deletions
diff --git a/fs/nfs/super.c b/fs/nfs/super.c index 7f5bc28ea8d1..baf75e9bd3fe 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c | |||
@@ -470,77 +470,86 @@ static int nfs_verify_server_address(struct sockaddr *addr) | |||
470 | static int nfs_validate_mount_data(struct nfs_mount_data *data, | 470 | static int nfs_validate_mount_data(struct nfs_mount_data *data, |
471 | struct nfs_fh *mntfh) | 471 | struct nfs_fh *mntfh) |
472 | { | 472 | { |
473 | if (data == NULL) { | 473 | if (data == NULL) |
474 | dprintk("%s: missing data argument\n", __FUNCTION__); | 474 | goto out_no_data; |
475 | return -EINVAL; | ||
476 | } | ||
477 | |||
478 | if (data->version <= 0 || data->version > NFS_MOUNT_VERSION) { | ||
479 | dprintk("%s: bad mount version\n", __FUNCTION__); | ||
480 | return -EINVAL; | ||
481 | } | ||
482 | 475 | ||
483 | switch (data->version) { | 476 | switch (data->version) { |
484 | case 1: | 477 | case 1: |
485 | data->namlen = 0; | 478 | data->namlen = 0; |
486 | case 2: | 479 | case 2: |
487 | data->bsize = 0; | 480 | data->bsize = 0; |
488 | case 3: | 481 | case 3: |
489 | if (data->flags & NFS_MOUNT_VER3) { | 482 | if (data->flags & NFS_MOUNT_VER3) |
490 | dprintk("%s: mount structure version %d does not support NFSv3\n", | 483 | goto out_no_v3; |
491 | __FUNCTION__, | 484 | data->root.size = NFS2_FHSIZE; |
492 | data->version); | 485 | memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE); |
493 | return -EINVAL; | 486 | case 4: |
494 | } | 487 | if (data->flags & NFS_MOUNT_SECFLAVOUR) |
495 | data->root.size = NFS2_FHSIZE; | 488 | goto out_no_sec; |
496 | memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE); | 489 | case 5: |
497 | case 4: | 490 | memset(data->context, 0, sizeof(data->context)); |
498 | if (data->flags & NFS_MOUNT_SECFLAVOUR) { | 491 | case 6: |
499 | dprintk("%s: mount structure version %d does not support strong security\n", | 492 | if (data->flags & NFS_MOUNT_VER3) |
500 | __FUNCTION__, | 493 | mntfh->size = data->root.size; |
501 | data->version); | 494 | else |
502 | return -EINVAL; | 495 | mntfh->size = NFS2_FHSIZE; |
503 | } | 496 | |
504 | case 5: | 497 | if (mntfh->size > sizeof(mntfh->data)) |
505 | memset(data->context, 0, sizeof(data->context)); | 498 | goto out_invalid_fh; |
499 | |||
500 | memcpy(mntfh->data, data->root.data, mntfh->size); | ||
501 | if (mntfh->size < sizeof(mntfh->data)) | ||
502 | memset(mntfh->data + mntfh->size, 0, | ||
503 | sizeof(mntfh->data) - mntfh->size); | ||
504 | break; | ||
505 | default: | ||
506 | goto out_bad_version; | ||
506 | } | 507 | } |
507 | 508 | ||
508 | /* Set the pseudoflavor */ | ||
509 | if (!(data->flags & NFS_MOUNT_SECFLAVOUR)) | 509 | if (!(data->flags & NFS_MOUNT_SECFLAVOUR)) |
510 | data->pseudoflavor = RPC_AUTH_UNIX; | 510 | data->pseudoflavor = RPC_AUTH_UNIX; |
511 | 511 | ||
512 | #ifndef CONFIG_NFS_V3 | 512 | #ifndef CONFIG_NFS_V3 |
513 | /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */ | 513 | if (data->flags & NFS_MOUNT_VER3) |
514 | if (data->flags & NFS_MOUNT_VER3) { | 514 | goto out_v3_not_compiled; |
515 | dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__); | 515 | #endif /* !CONFIG_NFS_V3 */ |
516 | return -EPROTONOSUPPORT; | ||
517 | } | ||
518 | #endif /* CONFIG_NFS_V3 */ | ||
519 | 516 | ||
520 | /* We now require that the mount process passes the remote address */ | 517 | if (!nfs_verify_server_address((struct sockaddr *) &data->addr)) |
521 | if (!nfs_verify_server_address((struct sockaddr *) &data->addr)) { | 518 | goto out_no_address; |
522 | dprintk("%s: mount program didn't pass remote address!\n", | ||
523 | __FUNCTION__); | ||
524 | return -EINVAL; | ||
525 | } | ||
526 | 519 | ||
527 | /* Prepare the root filehandle */ | 520 | return 0; |
528 | if (data->flags & NFS_MOUNT_VER3) | ||
529 | mntfh->size = data->root.size; | ||
530 | else | ||
531 | mntfh->size = NFS2_FHSIZE; | ||
532 | 521 | ||
533 | if (mntfh->size > sizeof(mntfh->data)) { | 522 | out_no_data: |
534 | dprintk("%s: invalid root filehandle\n", __FUNCTION__); | 523 | dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n"); |
535 | return -EINVAL; | 524 | return -EINVAL; |
536 | } | ||
537 | 525 | ||
538 | memcpy(mntfh->data, data->root.data, mntfh->size); | 526 | out_no_v3: |
539 | if (mntfh->size < sizeof(mntfh->data)) | 527 | dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n", |
540 | memset(mntfh->data + mntfh->size, 0, | 528 | data->version); |
541 | sizeof(mntfh->data) - mntfh->size); | 529 | return -EINVAL; |
542 | 530 | ||
543 | return 0; | 531 | out_no_sec: |
532 | dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n"); | ||
533 | return -EINVAL; | ||
534 | |||
535 | out_bad_version: | ||
536 | dfprintk(MOUNT, "NFS: bad nfs_mount_data version %d\n", | ||
537 | data->version); | ||
538 | return -EINVAL; | ||
539 | |||
540 | #ifndef CONFIG_NFS_V3 | ||
541 | out_v3_not_compiled: | ||
542 | dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n"); | ||
543 | return -EPROTONOSUPPORT; | ||
544 | #endif /* !CONFIG_NFS_V3 */ | ||
545 | |||
546 | out_no_address: | ||
547 | dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n"); | ||
548 | return -EINVAL; | ||
549 | |||
550 | out_invalid_fh: | ||
551 | dfprintk(MOUNT, "NFS: invalid root filehandle\n"); | ||
552 | return -EINVAL; | ||
544 | } | 553 | } |
545 | 554 | ||
546 | /* | 555 | /* |