diff mbox series

[v5,08/17] xfs: mount-api - move xfs_parseargs() validation to a helper

Message ID 157062065250.32346.13350789812067183237.stgit@fedora-28 (mailing list archive)
State Deferred, archived
Headers show
Series xfs: mount API patch series | expand

Commit Message

Ian Kent Oct. 9, 2019, 11:30 a.m. UTC
Move the validation code of xfs_parseargs() into a helper for later
use within the mount context methods.

Signed-off-by: Ian Kent <raven@themaw.net>
Reviewed-by: Brian Foster <bfoster@redhat.com>
---
 fs/xfs/xfs_super.c |  147 +++++++++++++++++++++++++++++++++-------------------
 1 file changed, 94 insertions(+), 53 deletions(-)

Comments

Christoph Hellwig Oct. 9, 2019, 3:02 p.m. UTC | #1
On Wed, Oct 09, 2019 at 07:30:52PM +0800, Ian Kent wrote:
> +#ifndef CONFIG_XFS_QUOTA
> +	if (XFS_IS_QUOTA_RUNNING(mp)) {
> +		xfs_warn(mp, "quota support not available in this kernel.");
> +		return -EINVAL;
> +	}
> +#endif

this can use IS_ENABLED.
Darrick J. Wong Oct. 9, 2019, 7:47 p.m. UTC | #2
On Wed, Oct 09, 2019 at 08:02:06AM -0700, Christoph Hellwig wrote:
> On Wed, Oct 09, 2019 at 07:30:52PM +0800, Ian Kent wrote:
> > +#ifndef CONFIG_XFS_QUOTA
> > +	if (XFS_IS_QUOTA_RUNNING(mp)) {
> > +		xfs_warn(mp, "quota support not available in this kernel.");
> > +		return -EINVAL;
> > +	}
> > +#endif
> 
> this can use IS_ENABLED.

I didn't think that macro needed a CONFIG_XFS_QUOTA check...?

--D
Christoph Hellwig Oct. 10, 2019, 6:38 a.m. UTC | #3
On Wed, Oct 09, 2019 at 12:47:47PM -0700, Darrick J. Wong wrote:
> On Wed, Oct 09, 2019 at 08:02:06AM -0700, Christoph Hellwig wrote:
> > On Wed, Oct 09, 2019 at 07:30:52PM +0800, Ian Kent wrote:
> > > +#ifndef CONFIG_XFS_QUOTA
> > > +	if (XFS_IS_QUOTA_RUNNING(mp)) {
> > > +		xfs_warn(mp, "quota support not available in this kernel.");
> > > +		return -EINVAL;
> > > +	}
> > > +#endif
> > 
> > this can use IS_ENABLED.
> 
> I didn't think that macro needed a CONFIG_XFS_QUOTA check...?

Even better if we don't need anything at al..
Christoph Hellwig Oct. 10, 2019, 7:57 a.m. UTC | #4
On Wed, Oct 09, 2019 at 11:38:24PM -0700, Christoph Hellwig wrote:
> On Wed, Oct 09, 2019 at 12:47:47PM -0700, Darrick J. Wong wrote:
> > On Wed, Oct 09, 2019 at 08:02:06AM -0700, Christoph Hellwig wrote:
> > > On Wed, Oct 09, 2019 at 07:30:52PM +0800, Ian Kent wrote:
> > > > +#ifndef CONFIG_XFS_QUOTA
> > > > +	if (XFS_IS_QUOTA_RUNNING(mp)) {
> > > > +		xfs_warn(mp, "quota support not available in this kernel.");
> > > > +		return -EINVAL;
> > > > +	}
> > > > +#endif
> > > 
> > > this can use IS_ENABLED.
> > 
> > I didn't think that macro needed a CONFIG_XFS_QUOTA check...?
> 
> Even better if we don't need anything at al..

Actually.  The test is and #ifndef, so yes we ctually need the check.
That being said I think and opencoded m_qflags != 0 instead of
XFS_IS_QUOTA_RUNNING would actually describing the intent to the
reader as we directly manipulate m_qflags elsewhere in the mount
code.
diff mbox series

Patch

diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 7fd3975d5523..7008355df065 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -347,6 +347,98 @@  xfs_parse_param(
 	return 0;
 }
 
+STATIC int
+xfs_validate_params(
+	struct xfs_mount        *mp,
+	struct xfs_fs_context   *ctx,
+	bool			nooptions)
+{
+	if (nooptions)
+		goto noopts;
+
+	/*
+	 * no recovery flag requires a read-only mount
+	 */
+	if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
+	    !(mp->m_flags & XFS_MOUNT_RDONLY)) {
+		xfs_warn(mp, "no-recovery mounts must be read-only.");
+		return -EINVAL;
+	}
+
+	if ((mp->m_flags & XFS_MOUNT_NOALIGN) &&
+	    (ctx->dsunit || ctx->dswidth)) {
+		xfs_warn(mp,
+	"sunit and swidth options incompatible with the noalign option");
+		return -EINVAL;
+	}
+
+#ifndef CONFIG_XFS_QUOTA
+	if (XFS_IS_QUOTA_RUNNING(mp)) {
+		xfs_warn(mp, "quota support not available in this kernel.");
+		return -EINVAL;
+	}
+#endif
+
+	if ((ctx->dsunit && !ctx->dswidth) || (!ctx->dsunit && ctx->dswidth)) {
+		xfs_warn(mp, "sunit and swidth must be specified together");
+		return -EINVAL;
+	}
+
+	if (ctx->dsunit && (ctx->dswidth % ctx->dsunit != 0)) {
+		xfs_warn(mp,
+	"stripe width (%d) must be a multiple of the stripe unit (%d)",
+			ctx->dswidth, ctx->dsunit);
+		return -EINVAL;
+	}
+
+noopts:
+	if (ctx->dsunit && !(mp->m_flags & XFS_MOUNT_NOALIGN)) {
+		/*
+		 * At this point the superblock has not been read
+		 * in, therefore we do not know the block size.
+		 * Before the mount call ends we will convert
+		 * these to FSBs.
+		 */
+		mp->m_dalign = ctx->dsunit;
+		mp->m_swidth = ctx->dswidth;
+	}
+
+	if (mp->m_logbufs != -1 &&
+	    mp->m_logbufs != 0 &&
+	    (mp->m_logbufs < XLOG_MIN_ICLOGS ||
+	     mp->m_logbufs > XLOG_MAX_ICLOGS)) {
+		xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
+			mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
+		return -EINVAL;
+	}
+	if (mp->m_logbsize != -1 &&
+	    mp->m_logbsize !=  0 &&
+	    (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
+	     mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
+	     !is_power_of_2(mp->m_logbsize))) {
+		xfs_warn(mp,
+			"invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
+			mp->m_logbsize);
+		return -EINVAL;
+	}
+
+	if (ctx->iosizelog) {
+		if (ctx->iosizelog > XFS_MAX_IO_LOG ||
+		    ctx->iosizelog < XFS_MIN_IO_LOG) {
+			xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
+				ctx->iosizelog, XFS_MIN_IO_LOG,
+				XFS_MAX_IO_LOG);
+			return -EINVAL;
+		}
+
+		mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
+		mp->m_readio_log = ctx->iosizelog;
+		mp->m_writeio_log = ctx->iosizelog;
+	}
+
+	return 0;
+}
+
 /*
  * This function fills in xfs_mount_t fields based on mount args.
  * Note: the superblock has _not_ yet been read in.
@@ -441,15 +533,6 @@  xfs_parseargs(
 			return ret;
 	}
 
-	/*
-	 * no recovery flag requires a read-only mount
-	 */
-	if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
-	    !(mp->m_flags & XFS_MOUNT_RDONLY)) {
-		xfs_warn(mp, "no-recovery mounts must be read-only.");
-		return -EINVAL;
-	}
-
 	if ((mp->m_flags & XFS_MOUNT_NOALIGN) &&
 	    (ctx->dsunit || ctx->dswidth)) {
 		xfs_warn(mp,
@@ -477,51 +560,9 @@  xfs_parseargs(
 	}
 
 done:
-	if (ctx->dsunit && !(mp->m_flags & XFS_MOUNT_NOALIGN)) {
-		/*
-		 * At this point the superblock has not been read
-		 * in, therefore we do not know the block size.
-		 * Before the mount call ends we will convert
-		 * these to FSBs.
-		 */
-		mp->m_dalign = ctx->dsunit;
-		mp->m_swidth = ctx->dswidth;
-	}
+	ret = xfs_validate_params(mp, &context, false);
 
-	if (mp->m_logbufs != -1 &&
-	    mp->m_logbufs != 0 &&
-	    (mp->m_logbufs < XLOG_MIN_ICLOGS ||
-	     mp->m_logbufs > XLOG_MAX_ICLOGS)) {
-		xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
-			mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
-		return -EINVAL;
-	}
-	if (mp->m_logbsize != -1 &&
-	    mp->m_logbsize !=  0 &&
-	    (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
-	     mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
-	     !is_power_of_2(mp->m_logbsize))) {
-		xfs_warn(mp,
-			"invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
-			mp->m_logbsize);
-		return -EINVAL;
-	}
-
-	if (ctx->iosizelog) {
-		if (ctx->iosizelog > XFS_MAX_IO_LOG ||
-		    ctx->iosizelog < XFS_MIN_IO_LOG) {
-			xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
-				ctx->iosizelog, XFS_MIN_IO_LOG,
-				XFS_MAX_IO_LOG);
-			return -EINVAL;
-		}
-
-		mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
-		mp->m_readio_log = ctx->iosizelog;
-		mp->m_writeio_log = ctx->iosizelog;
-	}
-
-	return 0;
+	return ret;
 }
 
 struct proc_xfs_info {