diff mbox series

[02/10] xfs: mount-api - refactor suffix_kstrtoint()

Message ID 156134510851.2519.2387740442257250106.stgit@fedora-28 (mailing list archive)
State Superseded
Headers show
Series [01/10] xfs: mount-api - add fs parameter description | expand

Commit Message

Ian Kent June 24, 2019, 2:58 a.m. UTC
The mount-api doesn't have a "human unit" parse type yet so
the options that have values like "10k" etc. still need to
be converted by the fs.

But the value comes to the fs as a string (not a substring_t
type) so there's a need to change the conversion function to
take a character string instead.

After switching to use the new mount-api match_kstrtoint()
will no longer be called and will be removed.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 fs/xfs/xfs_super.c |   22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

Comments

Darrick J. Wong June 24, 2019, 5:29 p.m. UTC | #1
On Mon, Jun 24, 2019 at 10:58:30AM +0800, Ian Kent wrote:
> The mount-api doesn't have a "human unit" parse type yet so
> the options that have values like "10k" etc. still need to
> be converted by the fs.

/me wonders if that ought to be lifted to fs_parser.c, or is xfs the
only filesystem that has mount options with unit suffixes?

--D

> But the value comes to the fs as a string (not a substring_t
> type) so there's a need to change the conversion function to
> take a character string instead.
> 
> After switching to use the new mount-api match_kstrtoint()
> will no longer be called and will be removed.
> 
> Signed-off-by: Ian Kent <raven@themaw.net>
> ---
>  fs/xfs/xfs_super.c |   22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
> index ab8145bf6fff..14c2a775786c 100644
> --- a/fs/xfs/xfs_super.c
> +++ b/fs/xfs/xfs_super.c
> @@ -166,13 +166,13 @@ static const struct fs_parameter_description xfs_fs_parameters = {
>  };
>  
>  STATIC int
> -suffix_kstrtoint(const substring_t *s, unsigned int base, int *res)
> +suffix_kstrtoint(const char *s, unsigned int base, int *res)
>  {
>  	int	last, shift_left_factor = 0, _res;
>  	char	*value;
>  	int	ret = 0;
>  
> -	value = match_strdup(s);
> +	value = kstrdup(s, GFP_KERNEL);
>  	if (!value)
>  		return -ENOMEM;
>  
> @@ -197,6 +197,20 @@ suffix_kstrtoint(const substring_t *s, unsigned int base, int *res)
>  	return ret;
>  }
>  
> +STATIC int
> +match_kstrtoint(const substring_t *s, unsigned int base, int *res)
> +{
> +	const char	*value;
> +	int ret;
> +
> +	value = match_strdup(s);
> +	if (!value)
> +		return -ENOMEM;
> +	ret = suffix_kstrtoint(value, base, res);
> +	kfree(value);
> +	return ret;
> +}
> +
>  /*
>   * This function fills in xfs_mount_t fields based on mount args.
>   * Note: the superblock has _not_ yet been read in.
> @@ -268,7 +282,7 @@ xfs_parseargs(
>  				return -EINVAL;
>  			break;
>  		case Opt_logbsize:
> -			if (suffix_kstrtoint(args, 10, &mp->m_logbsize))
> +			if (match_kstrtoint(args, 10, &mp->m_logbsize))
>  				return -EINVAL;
>  			break;
>  		case Opt_logdev:
> @@ -285,7 +299,7 @@ xfs_parseargs(
>  			break;
>  		case Opt_allocsize:
>  		case Opt_biosize:
> -			if (suffix_kstrtoint(args, 10, &iosize))
> +			if (match_kstrtoint(args, 10, &iosize))
>  				return -EINVAL;
>  			iosizelog = ffs(iosize) - 1;
>  			break;
>
Dave Chinner June 24, 2019, 10:35 p.m. UTC | #2
On Mon, Jun 24, 2019 at 10:29:43AM -0700, Darrick J. Wong wrote:
> On Mon, Jun 24, 2019 at 10:58:30AM +0800, Ian Kent wrote:
> > The mount-api doesn't have a "human unit" parse type yet so
> > the options that have values like "10k" etc. still need to
> > be converted by the fs.
> 
> /me wonders if that ought to be lifted to fs_parser.c, or is xfs the
> only filesystem that has mount options with unit suffixes?

I've suggested the same thing (I've seen this patchset before :)
and ISTR it makes everything easier if we just keep it here for this
patchset and then lift it once everything is merged...

-Dave.
Darrick J. Wong June 24, 2019, 11:06 p.m. UTC | #3
On Tue, Jun 25, 2019 at 08:35:54AM +1000, Dave Chinner wrote:
> On Mon, Jun 24, 2019 at 10:29:43AM -0700, Darrick J. Wong wrote:
> > On Mon, Jun 24, 2019 at 10:58:30AM +0800, Ian Kent wrote:
> > > The mount-api doesn't have a "human unit" parse type yet so
> > > the options that have values like "10k" etc. still need to
> > > be converted by the fs.
> > 
> > /me wonders if that ought to be lifted to fs_parser.c, or is xfs the
> > only filesystem that has mount options with unit suffixes?
> 
> I've suggested the same thing (I've seen this patchset before :)
> and ISTR it makes everything easier if we just keep it here for this
> patchset and then lift it once everything is merged...

Ok, fair enough. :)

--D

> -Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
Ian Kent June 24, 2019, 11:34 p.m. UTC | #4
On Mon, 2019-06-24 at 16:06 -0700, Darrick J. Wong wrote:
> On Tue, Jun 25, 2019 at 08:35:54AM +1000, Dave Chinner wrote:
> > On Mon, Jun 24, 2019 at 10:29:43AM -0700, Darrick J. Wong wrote:
> > > On Mon, Jun 24, 2019 at 10:58:30AM +0800, Ian Kent wrote:
> > > > The mount-api doesn't have a "human unit" parse type yet so
> > > > the options that have values like "10k" etc. still need to
> > > > be converted by the fs.
> > > 
> > > /me wonders if that ought to be lifted to fs_parser.c, or is xfs the
> > > only filesystem that has mount options with unit suffixes?
> > 
> > I've suggested the same thing (I've seen this patchset before :)
> > and ISTR it makes everything easier if we just keep it here for this
> > patchset and then lift it once everything is merged...
> 
> Ok, fair enough. :)

I mentioned it to David after Dave said much the same thing, David said
he had done some work on it but I haven't heard more yet.

> 
> --D
> 
> > -Dave.
> > -- 
> > Dave Chinner
> > david@fromorbit.com
diff mbox series

Patch

diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index ab8145bf6fff..14c2a775786c 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -166,13 +166,13 @@  static const struct fs_parameter_description xfs_fs_parameters = {
 };
 
 STATIC int
-suffix_kstrtoint(const substring_t *s, unsigned int base, int *res)
+suffix_kstrtoint(const char *s, unsigned int base, int *res)
 {
 	int	last, shift_left_factor = 0, _res;
 	char	*value;
 	int	ret = 0;
 
-	value = match_strdup(s);
+	value = kstrdup(s, GFP_KERNEL);
 	if (!value)
 		return -ENOMEM;
 
@@ -197,6 +197,20 @@  suffix_kstrtoint(const substring_t *s, unsigned int base, int *res)
 	return ret;
 }
 
+STATIC int
+match_kstrtoint(const substring_t *s, unsigned int base, int *res)
+{
+	const char	*value;
+	int ret;
+
+	value = match_strdup(s);
+	if (!value)
+		return -ENOMEM;
+	ret = suffix_kstrtoint(value, base, res);
+	kfree(value);
+	return ret;
+}
+
 /*
  * This function fills in xfs_mount_t fields based on mount args.
  * Note: the superblock has _not_ yet been read in.
@@ -268,7 +282,7 @@  xfs_parseargs(
 				return -EINVAL;
 			break;
 		case Opt_logbsize:
-			if (suffix_kstrtoint(args, 10, &mp->m_logbsize))
+			if (match_kstrtoint(args, 10, &mp->m_logbsize))
 				return -EINVAL;
 			break;
 		case Opt_logdev:
@@ -285,7 +299,7 @@  xfs_parseargs(
 			break;
 		case Opt_allocsize:
 		case Opt_biosize:
-			if (suffix_kstrtoint(args, 10, &iosize))
+			if (match_kstrtoint(args, 10, &iosize))
 				return -EINVAL;
 			iosizelog = ffs(iosize) - 1;
 			break;