Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5cb09b6 authored by Rob Landley's avatar Rob Landley Committed by Trond Myklebust
Browse files

Cleanup: Factor out some cut-and-paste code.



Factor out some cut-and-paste code in options parsing.
Saves about 800 bytes on x86-64.

Signed-off-by: default avatarRob Landley <rlandley@parallels.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent c12bacec
Loading
Loading
Loading
Loading
+44 −111
Original line number Original line Diff line number Diff line
@@ -979,6 +979,27 @@ static int nfs_parse_security_flavors(char *value,
	return 1;
	return 1;
}
}


static int nfs_get_option_str(substring_t args[], char **option)
{
	kfree(*option);
	*option = match_strdup(args);
	return !option;
}

static int nfs_get_option_ul(substring_t args[], unsigned long *option)
{
	int rc;
	char *string;

	string = match_strdup(args);
	if (string == NULL)
		return -ENOMEM;
	rc = strict_strtoul(string, 10, option);
	kfree(string);

	return rc;
}

/*
/*
 * Error-check and convert a string of mount options from user space into
 * Error-check and convert a string of mount options from user space into
 * a data structure.  The whole mount string is processed; bad options are
 * a data structure.  The whole mount string is processed; bad options are
@@ -1127,155 +1148,82 @@ static int nfs_parse_mount_options(char *raw,
		 * options that take numeric values
		 * options that take numeric values
		 */
		 */
		case Opt_port:
		case Opt_port:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option) ||
			if (string == NULL)
			    option > USHRT_MAX)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0 || option > USHRT_MAX)
				goto out_invalid_value;
				goto out_invalid_value;
			mnt->nfs_server.port = option;
			mnt->nfs_server.port = option;
			break;
			break;
		case Opt_rsize:
		case Opt_rsize:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option))
			if (string == NULL)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0)
				goto out_invalid_value;
				goto out_invalid_value;
			mnt->rsize = option;
			mnt->rsize = option;
			break;
			break;
		case Opt_wsize:
		case Opt_wsize:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option))
			if (string == NULL)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0)
				goto out_invalid_value;
				goto out_invalid_value;
			mnt->wsize = option;
			mnt->wsize = option;
			break;
			break;
		case Opt_bsize:
		case Opt_bsize:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option))
			if (string == NULL)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0)
				goto out_invalid_value;
				goto out_invalid_value;
			mnt->bsize = option;
			mnt->bsize = option;
			break;
			break;
		case Opt_timeo:
		case Opt_timeo:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option) || option == 0)
			if (string == NULL)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0 || option == 0)
				goto out_invalid_value;
				goto out_invalid_value;
			mnt->timeo = option;
			mnt->timeo = option;
			break;
			break;
		case Opt_retrans:
		case Opt_retrans:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option) || option == 0)
			if (string == NULL)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0 || option == 0)
				goto out_invalid_value;
				goto out_invalid_value;
			mnt->retrans = option;
			mnt->retrans = option;
			break;
			break;
		case Opt_acregmin:
		case Opt_acregmin:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option))
			if (string == NULL)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0)
				goto out_invalid_value;
				goto out_invalid_value;
			mnt->acregmin = option;
			mnt->acregmin = option;
			break;
			break;
		case Opt_acregmax:
		case Opt_acregmax:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option))
			if (string == NULL)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0)
				goto out_invalid_value;
				goto out_invalid_value;
			mnt->acregmax = option;
			mnt->acregmax = option;
			break;
			break;
		case Opt_acdirmin:
		case Opt_acdirmin:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option))
			if (string == NULL)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0)
				goto out_invalid_value;
				goto out_invalid_value;
			mnt->acdirmin = option;
			mnt->acdirmin = option;
			break;
			break;
		case Opt_acdirmax:
		case Opt_acdirmax:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option))
			if (string == NULL)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0)
				goto out_invalid_value;
				goto out_invalid_value;
			mnt->acdirmax = option;
			mnt->acdirmax = option;
			break;
			break;
		case Opt_actimeo:
		case Opt_actimeo:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option))
			if (string == NULL)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0)
				goto out_invalid_value;
				goto out_invalid_value;
			mnt->acregmin = mnt->acregmax =
			mnt->acregmin = mnt->acregmax =
			mnt->acdirmin = mnt->acdirmax = option;
			mnt->acdirmin = mnt->acdirmax = option;
			break;
			break;
		case Opt_namelen:
		case Opt_namelen:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option))
			if (string == NULL)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0)
				goto out_invalid_value;
				goto out_invalid_value;
			mnt->namlen = option;
			mnt->namlen = option;
			break;
			break;
		case Opt_mountport:
		case Opt_mountport:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option) ||
			if (string == NULL)
			    option > USHRT_MAX)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0 || option > USHRT_MAX)
				goto out_invalid_value;
				goto out_invalid_value;
			mnt->mount_server.port = option;
			mnt->mount_server.port = option;
			break;
			break;
		case Opt_mountvers:
		case Opt_mountvers:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option) ||
			if (string == NULL)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0 ||
			    option < NFS_MNT_VERSION ||
			    option < NFS_MNT_VERSION ||
			    option > NFS_MNT3_VERSION)
			    option > NFS_MNT3_VERSION)
				goto out_invalid_value;
				goto out_invalid_value;
			mnt->mount_server.version = option;
			mnt->mount_server.version = option;
			break;
			break;
		case Opt_nfsvers:
		case Opt_nfsvers:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option))
			if (string == NULL)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0)
				goto out_invalid_value;
				goto out_invalid_value;
			switch (option) {
			switch (option) {
			case NFS2_VERSION:
			case NFS2_VERSION:
@@ -1295,12 +1243,7 @@ static int nfs_parse_mount_options(char *raw,
			}
			}
			break;
			break;
		case Opt_minorversion:
		case Opt_minorversion:
			string = match_strdup(args);
			if (nfs_get_option_ul(args, &option))
			if (string == NULL)
				goto out_nomem;
			rc = strict_strtoul(string, 10, &option);
			kfree(string);
			if (rc != 0)
				goto out_invalid_value;
				goto out_invalid_value;
			if (option > NFS4_MAX_MINOR_VERSION)
			if (option > NFS4_MAX_MINOR_VERSION)
				goto out_invalid_value;
				goto out_invalid_value;
@@ -1336,21 +1279,18 @@ static int nfs_parse_mount_options(char *raw,
			case Opt_xprt_udp:
			case Opt_xprt_udp:
				mnt->flags &= ~NFS_MOUNT_TCP;
				mnt->flags &= ~NFS_MOUNT_TCP;
				mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
				mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
				kfree(string);
				break;
				break;
			case Opt_xprt_tcp6:
			case Opt_xprt_tcp6:
				protofamily = AF_INET6;
				protofamily = AF_INET6;
			case Opt_xprt_tcp:
			case Opt_xprt_tcp:
				mnt->flags |= NFS_MOUNT_TCP;
				mnt->flags |= NFS_MOUNT_TCP;
				mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
				mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
				kfree(string);
				break;
				break;
			case Opt_xprt_rdma:
			case Opt_xprt_rdma:
				/* vector side protocols to TCP */
				/* vector side protocols to TCP */
				mnt->flags |= NFS_MOUNT_TCP;
				mnt->flags |= NFS_MOUNT_TCP;
				mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
				mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
				xprt_load_transport(string);
				xprt_load_transport(string);
				kfree(string);
				break;
				break;
			default:
			default:
				dfprintk(MOUNT, "NFS:   unrecognized "
				dfprintk(MOUNT, "NFS:   unrecognized "
@@ -1358,6 +1298,7 @@ static int nfs_parse_mount_options(char *raw,
				kfree(string);
				kfree(string);
				return 0;
				return 0;
			}
			}
			kfree(string);
			break;
			break;
		case Opt_mountproto:
		case Opt_mountproto:
			string = match_strdup(args);
			string = match_strdup(args);
@@ -1400,18 +1341,13 @@ static int nfs_parse_mount_options(char *raw,
				goto out_invalid_address;
				goto out_invalid_address;
			break;
			break;
		case Opt_clientaddr:
		case Opt_clientaddr:
			string = match_strdup(args);
			if (nfs_get_option_str(args, &mnt->client_address))
			if (string == NULL)
				goto out_nomem;
				goto out_nomem;
			kfree(mnt->client_address);
			mnt->client_address = string;
			break;
			break;
		case Opt_mounthost:
		case Opt_mounthost:
			string = match_strdup(args);
			if (nfs_get_option_str(args,
			if (string == NULL)
					       &mnt->mount_server.hostname))
				goto out_nomem;
				goto out_nomem;
			kfree(mnt->mount_server.hostname);
			mnt->mount_server.hostname = string;
			break;
			break;
		case Opt_mountaddr:
		case Opt_mountaddr:
			string = match_strdup(args);
			string = match_strdup(args);
@@ -1451,11 +1387,8 @@ static int nfs_parse_mount_options(char *raw,
			};
			};
			break;
			break;
		case Opt_fscache_uniq:
		case Opt_fscache_uniq:
			string = match_strdup(args);
			if (nfs_get_option_str(args, &mnt->fscache_uniq))
			if (string == NULL)
				goto out_nomem;
				goto out_nomem;
			kfree(mnt->fscache_uniq);
			mnt->fscache_uniq = string;
			mnt->options |= NFS_OPTION_FSCACHE;
			mnt->options |= NFS_OPTION_FSCACHE;
			break;
			break;
		case Opt_local_lock:
		case Opt_local_lock: