From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F6B3C49ED7 for ; Fri, 20 Sep 2019 09:56:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E162720665 for ; Fri, 20 Sep 2019 09:56:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2408600AbfITJ4M (ORCPT ); Fri, 20 Sep 2019 05:56:12 -0400 Received: from icp-osb-irony-out5.external.iinet.net.au ([203.59.1.221]:6242 "EHLO icp-osb-irony-out5.external.iinet.net.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408596AbfITJ4M (ORCPT ); Fri, 20 Sep 2019 05:56:12 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2CNAQDfoYRd/zmr0HYNVxwBAQEEAQE?= =?us-ascii?q?HBAEBgWcChDKEIo9nAQEGiyuFH4wJCQEBAQEBAQEBATcBAYQ6AwICgyo4EwI?= =?us-ascii?q?MAQEBBAEBAQEBBQMBhViBEAEQAYR3AgEDIwRSEBgNAiYCAkcQBhOFGasGc38?= =?us-ascii?q?zGoougQwoAYFiij54gQeEYYQpgyaCWASMcYJlhixClkeCLJUlDIIqi10DEIp?= =?us-ascii?q?+LYQGpQ2BeU0uCoMnUJBEZoJriW4BK4InAQE?= X-IPAS-Result: =?us-ascii?q?A2CNAQDfoYRd/zmr0HYNVxwBAQEEAQEHBAEBgWcChDKEI?= =?us-ascii?q?o9nAQEGiyuFH4wJCQEBAQEBAQEBATcBAYQ6AwICgyo4EwIMAQEBBAEBAQEBB?= =?us-ascii?q?QMBhViBEAEQAYR3AgEDIwRSEBgNAiYCAkcQBhOFGasGc38zGoougQwoAYFii?= =?us-ascii?q?j54gQeEYYQpgyaCWASMcYJlhixClkeCLJUlDIIqi10DEIp+LYQGpQ2BeU0uC?= =?us-ascii?q?oMnUJBEZoJriW4BK4InAQE?= X-IronPort-AV: E=Sophos;i="5.64,528,1559491200"; d="scan'208";a="253491497" Received: from unknown (HELO [192.168.1.222]) ([118.208.171.57]) by icp-osb-irony-out5.iinet.net.au with ESMTP; 20 Sep 2019 17:56:09 +0800 Subject: [PATCH v3 07/16] xfs: mount-api - move xfs_parseargs() validation to a helper From: Ian Kent To: linux-xfs Cc: David Howells , Dave Chinner , Al Viro , Eric Sandeen Date: Fri, 20 Sep 2019 17:56:09 +0800 Message-ID: <156897336977.20210.76910391411183299.stgit@fedora-28> In-Reply-To: <156897321789.20210.339237101446767141.stgit@fedora-28> References: <156897321789.20210.339237101446767141.stgit@fedora-28> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 | 148 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 94 insertions(+), 54 deletions(-) diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 041ab8b52a7d..5cb9a9fd1a15 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -356,6 +356,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. @@ -445,16 +536,7 @@ 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; + goto done; } if ((mp->m_flags & XFS_MOUNT_NOALIGN) && @@ -484,51 +566,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; - } - - 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; - } + ret = xfs_validate_params(mp, &context, false); - 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 {