]> err.no Git - linux-2.6/commitdiff
NFS: Clean up nfs_validate_mount_data
authorChuck Lever <chuck.lever@oracle.com>
Sun, 1 Jul 2007 16:12:56 +0000 (12:12 -0400)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Wed, 11 Jul 2007 03:40:45 +0000 (23:40 -0400)
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>
fs/nfs/super.c

index 7f5bc28ea8d10a284ffd2f60678b1647ec1c526f..baf75e9bd3fedfd44a10a30f229312cc8bde046b 100644 (file)
@@ -470,77 +470,86 @@ static int nfs_verify_server_address(struct sockaddr *addr)
 static int nfs_validate_mount_data(struct nfs_mount_data *data,
                                   struct nfs_fh *mntfh)
 {
-       if (data == NULL) {
-               dprintk("%s: missing data argument\n", __FUNCTION__);
-               return -EINVAL;
-       }
-
-       if (data->version <= 0 || data->version > NFS_MOUNT_VERSION) {
-               dprintk("%s: bad mount version\n", __FUNCTION__);
-               return -EINVAL;
-       }
+       if (data == NULL)
+               goto out_no_data;
 
        switch (data->version) {
-               case 1:
-                       data->namlen = 0;
-               case 2:
-                       data->bsize  = 0;
-               case 3:
-                       if (data->flags & NFS_MOUNT_VER3) {
-                               dprintk("%s: mount structure version %d does not support NFSv3\n",
-                                               __FUNCTION__,
-                                               data->version);
-                               return -EINVAL;
-                       }
-                       data->root.size = NFS2_FHSIZE;
-                       memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
-               case 4:
-                       if (data->flags & NFS_MOUNT_SECFLAVOUR) {
-                               dprintk("%s: mount structure version %d does not support strong security\n",
-                                               __FUNCTION__,
-                                               data->version);
-                               return -EINVAL;
-                       }
-               case 5:
-                       memset(data->context, 0, sizeof(data->context));
+       case 1:
+               data->namlen = 0;
+       case 2:
+               data->bsize = 0;
+       case 3:
+               if (data->flags & NFS_MOUNT_VER3)
+                       goto out_no_v3;
+               data->root.size = NFS2_FHSIZE;
+               memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
+       case 4:
+               if (data->flags & NFS_MOUNT_SECFLAVOUR)
+                       goto out_no_sec;
+       case 5:
+               memset(data->context, 0, sizeof(data->context));
+       case 6:
+               if (data->flags & NFS_MOUNT_VER3)
+                       mntfh->size = data->root.size;
+               else
+                       mntfh->size = NFS2_FHSIZE;
+
+               if (mntfh->size > sizeof(mntfh->data))
+                       goto out_invalid_fh;
+
+               memcpy(mntfh->data, data->root.data, mntfh->size);
+               if (mntfh->size < sizeof(mntfh->data))
+                       memset(mntfh->data + mntfh->size, 0,
+                              sizeof(mntfh->data) - mntfh->size);
+               break;
+       default:
+               goto out_bad_version;
        }
 
-       /* Set the pseudoflavor */
        if (!(data->flags & NFS_MOUNT_SECFLAVOUR))
                data->pseudoflavor = RPC_AUTH_UNIX;
 
 #ifndef CONFIG_NFS_V3
-       /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */
-       if (data->flags & NFS_MOUNT_VER3) {
-               dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__);
-               return -EPROTONOSUPPORT;
-       }
-#endif /* CONFIG_NFS_V3 */
+       if (data->flags & NFS_MOUNT_VER3)
+               goto out_v3_not_compiled;
+#endif /* !CONFIG_NFS_V3 */
 
-       /* We now require that the mount process passes the remote address */
-       if (!nfs_verify_server_address((struct sockaddr *) &data->addr)) {
-               dprintk("%s: mount program didn't pass remote address!\n",
-                       __FUNCTION__);
-               return -EINVAL;
-       }
+       if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
+               goto out_no_address;
 
-       /* Prepare the root filehandle */
-       if (data->flags & NFS_MOUNT_VER3)
-               mntfh->size = data->root.size;
-       else
-               mntfh->size = NFS2_FHSIZE;
+       return 0;
 
-       if (mntfh->size > sizeof(mntfh->data)) {
-               dprintk("%s: invalid root filehandle\n", __FUNCTION__);
-               return -EINVAL;
-       }
+out_no_data:
+       dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
+       return -EINVAL;
 
-       memcpy(mntfh->data, data->root.data, mntfh->size);
-       if (mntfh->size < sizeof(mntfh->data))
-               memset(mntfh->data + mntfh->size, 0,
-                      sizeof(mntfh->data) - mntfh->size);
+out_no_v3:
+       dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
+                data->version);
+       return -EINVAL;
 
-       return 0;
+out_no_sec:
+       dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
+       return -EINVAL;
+
+out_bad_version:
+       dfprintk(MOUNT, "NFS: bad nfs_mount_data version %d\n",
+                data->version);
+       return -EINVAL;
+
+#ifndef CONFIG_NFS_V3
+out_v3_not_compiled:
+       dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
+       return -EPROTONOSUPPORT;
+#endif /* !CONFIG_NFS_V3 */
+
+out_no_address:
+       dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
+       return -EINVAL;
+
+out_invalid_fh:
+       dfprintk(MOUNT, "NFS: invalid root filehandle\n");
+       return -EINVAL;
 }
 
 /*