From patchwork Fri Aug 23 00:59:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Kent X-Patchwork-Id: 11110349 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D0E014DB for ; Fri, 23 Aug 2019 01:09:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7B93E23404 for ; Fri, 23 Aug 2019 01:09:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387618AbfHWBJG (ORCPT ); Thu, 22 Aug 2019 21:09:06 -0400 Received: from icp-osb-irony-out2.external.iinet.net.au ([203.59.1.155]:5585 "EHLO icp-osb-irony-out2.external.iinet.net.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732613AbfHWBJF (ORCPT ); Thu, 22 Aug 2019 21:09:05 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2DWAQAROl9d/3Wz0XYNWBwBAQEEAQEHBAEBgWeEM4Qgj1YBAQaBEYoRkSMJAQEBAQEBAQEBNwEBhDoDAgKDAjgTAgkBAQEEAQIBAQYDAYVYhhkCAQMjBFIQGA0CJgICRxAGE4UZq1BzfzMaikCBDCiBY4okeIEHgREzgx2EKYMmglgEjD2CV4UyXUKVdwmCH5RYDIIlizYDEIpQLYNzo2GBeU0uCoMnkRRligUBK4IlAQE X-IPAS-Result: A2DWAQAROl9d/3Wz0XYNWBwBAQEEAQEHBAEBgWeEM4Qgj1YBAQaBEYoRkSMJAQEBAQEBAQEBNwEBhDoDAgKDAjgTAgkBAQEEAQIBAQYDAYVYhhkCAQMjBFIQGA0CJgICRxAGE4UZq1BzfzMaikCBDCiBY4okeIEHgREzgx2EKYMmglgEjD2CV4UyXUKVdwmCH5RYDIIlizYDEIpQLYNzo2GBeU0uCoMnkRRligUBK4IlAQE X-IronPort-AV: E=Sophos;i="5.64,419,1559491200"; d="scan'208";a="231796719" Received: from unknown (HELO [192.168.1.222]) ([118.209.179.117]) by icp-osb-irony-out2.iinet.net.au with ESMTP; 23 Aug 2019 08:59:49 +0800 Subject: [PATCH v2 06/15] xfs: mount-api - move xfs_parseargs() validation to a helper From: Ian Kent To: linux-xfs Cc: Dave Chinner , David Howells , Al Viro , Eric Sandeen Date: Fri, 23 Aug 2019 08:59:49 +0800 Message-ID: <156652198915.2607.7532914515862448103.stgit@fedora-28> In-Reply-To: <156652158924.2607.14608448087216437699.stgit@fedora-28> References: <156652158924.2607.14608448087216437699.stgit@fedora-28> User-Agent: StGit/unknown-version MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Move the validation code of xfs_parseargs() into a helper for later use within the mount context methods. Signed-off-by: Ian Kent --- fs/xfs/xfs_super.c | 180 ++++++++++++++++++++++++++++------------------------ 1 file changed, 98 insertions(+), 82 deletions(-) diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 754d2ccfd960..7cdda17ee0ff 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -350,6 +350,97 @@ 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. @@ -372,6 +463,7 @@ xfs_parseargs( struct fs_context fc; struct xfs_fs_context context; struct xfs_fs_context *ctx = &context; + int ret; /* * set up the mount name first so all the errors will refer to the @@ -404,8 +496,10 @@ xfs_parseargs( mp->m_logbufs = -1; mp->m_logbsize = -1; - if (!options) + if (!options) { + ret = xfs_validate_params(mp, ctx, true); goto done; + } memset(&fc, 0, sizeof(fc)); memset(&ctx, 0, sizeof(ctx)); @@ -415,7 +509,6 @@ xfs_parseargs( while ((p = strsep(&options, ",")) != NULL) { struct fs_parameter param; char *value; - int ret; if (!*p) continue; @@ -442,89 +535,12 @@ xfs_parseargs( ret = xfs_parse_param(&fc, ¶m); kfree(param.string); if (ret < 0) - 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, - "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; + goto done; } + ret = xfs_validate_params(mp, ctx, false); 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; - } - - 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 {