From patchwork Thu Aug 24 23:21:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13364862 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE4ECC727A8 for ; Thu, 24 Aug 2023 23:22:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244065AbjHXXWN (ORCPT ); Thu, 24 Aug 2023 19:22:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244070AbjHXXVo (ORCPT ); Thu, 24 Aug 2023 19:21:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8124B198E for ; Thu, 24 Aug 2023 16:21:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 138F865314 for ; Thu, 24 Aug 2023 23:21:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B155C433CA; Thu, 24 Aug 2023 23:21:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692919301; bh=hx6zrA3cnrEMgEuzTlQ3T9Iw7OHbae7BwzgcR6SCASU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Ke6G3sKqRReKL8EVSnsxzQRqF8mo17gpGiNhuDm+4AzvafPXD9Lu089j0aDSvG7RO 7tY05P1TTeKFPzkFHPElRFl8xS2LPdgf2/elwYSiH4f/qzHkq5IMQVtXcK5mSGs0mZ ojd75EOw/oEx2wH3fL1B6gtJRbBkM91aNVB5ll0O8dkapWIYz6D/kCfk0YVXsE+1HD CV4UxX8PU3jsQbiXj1uaSP+LVYtUGkOzOvsZ6J8ODhxqvRR3kQbZGpWhnv5Jz49jpM ACOGiBEYtyUqaaQw8dd/6LaqeocKy4wkRP4iPAapnRymhGsTJHe5fl249LboSDJzAy yakvQNRoVe0Xg== Subject: [PATCH 1/3] xfs: allow inode inactivation during a ro mount log recovery From: "Darrick J. Wong" To: chandan.babu@gmail.com, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, david@fromorbit.com, sandeen@sandeen.net Date: Thu, 24 Aug 2023 16:21:41 -0700 Message-ID: <169291930098.220104.7975355323280629292.stgit@frogsfrogsfrogs> In-Reply-To: <169291929524.220104.3844042018007786965.stgit@frogsfrogsfrogs> References: <169291929524.220104.3844042018007786965.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong In the next patch, we're going to prohibit log recovery if the primary superblock contains an unrecognized rocompat feature bit even on readonly mounts. This requires removing all the code in the log mounting process that temporarily disables the readonly state. Unfortunately, inode inactivation disables itself on readonly mounts. Clearing the iunlinked lists after log recovery needs inactivation to run to free the unreferenced inodes, which (AFAICT) is the only reason why log mounting plays games with the readonly state in the first place. Therefore, change the inactivation predicates to allow inactivation during log recovery of a readonly mount. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_inode.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 9e62cc500140..6ee266be45d4 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1643,8 +1643,11 @@ xfs_inode_needs_inactive( if (VFS_I(ip)->i_mode == 0) return false; - /* If this is a read-only mount, don't do this (would generate I/O) */ - if (xfs_is_readonly(mp)) + /* + * If this is a read-only mount, don't do this (would generate I/O) + * unless we're in log recovery and cleaning the iunlinked list. + */ + if (xfs_is_readonly(mp) && !xlog_recovery_needed(mp->m_log)) return false; /* If the log isn't running, push inodes straight to reclaim. */ @@ -1704,8 +1707,11 @@ xfs_inactive( mp = ip->i_mount; ASSERT(!xfs_iflags_test(ip, XFS_IRECOVERY)); - /* If this is a read-only mount, don't do this (would generate I/O) */ - if (xfs_is_readonly(mp)) + /* + * If this is a read-only mount, don't do this (would generate I/O) + * unless we're in log recovery and cleaning the iunlinked list. + */ + if (xfs_is_readonly(mp) && !xlog_recovery_needed(mp->m_log)) goto out; /* Metadata inodes require explicit resource cleanup. */ From patchwork Thu Aug 24 23:21:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13364861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CA6AC727A3 for ; Thu, 24 Aug 2023 23:22:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244048AbjHXXWM (ORCPT ); Thu, 24 Aug 2023 19:22:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244065AbjHXXVy (ORCPT ); Thu, 24 Aug 2023 19:21:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18B3A1993 for ; Thu, 24 Aug 2023 16:21:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A3F8A65314 for ; Thu, 24 Aug 2023 23:21:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10A19C433C9; Thu, 24 Aug 2023 23:21:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692919307; bh=b3NFzny0HHABVZsHDiAWL7mB8aU+lQQzZVbmVKRUOmw=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Jf3SoDfNPTTJVIhcTrq+R4q9WyHEF5T+dYkw/kLWH8ur9v1a5z+ohILLUfj0ObOQx z1wd7PHpS6S4tJqfCKQqsFG9GGyq9NWirJe75EFvamJl4GMUO4w/f/2252fdMStbtd jdKw74wndc6NzOG8GEf9QdYBP/AgEohLargkCT1mC9DCTvudvYa95Ezy9FyOHS27BI 8P27Wl2Q6uXFegsLJ1SiwojPspaSpV0FfDTgIFUzpabBWv/gLcQN/qFbizZwlIZ4ec VzGje0AVfxruOYmTo75mKPXVkKFpSQ+qWlJsmn7SBxClnNr8abGF46KiAXy57j96QE wKN7cuNK1ETlA== Subject: [PATCH 2/3] xfs: don't allow log recovery when unknown rocompat bits are set From: "Darrick J. Wong" To: chandan.babu@gmail.com, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, david@fromorbit.com, sandeen@sandeen.net Date: Thu, 24 Aug 2023 16:21:46 -0700 Message-ID: <169291930662.220104.8435560164784332097.stgit@frogsfrogsfrogs> In-Reply-To: <169291929524.220104.3844042018007786965.stgit@frogsfrogsfrogs> References: <169291929524.220104.3844042018007786965.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Don't allow log recovery to proceed on a readonly mount if the primary superblock advertises unknown rocompat bits. We used to allow this, but due to a misunderstanding between Dave and Darrick back in 2016, we cannot do that anymore. The XFS_SB_FEAT_RO_COMPAT_RMAPBT feature (4.8) protects RUI log items, and the REFLINK feature (4.9) protects CUI/BUI log items, which is why we can't allow older kernels to recover them. Fixes: b87049444ac4 ("xfs: introduce rmap btree definitions") Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_log.c | 17 ----------------- fs/xfs/xfs_log_recover.c | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c index 79004d193e54..51c100c86177 100644 --- a/fs/xfs/xfs_log.c +++ b/fs/xfs/xfs_log.c @@ -715,15 +715,7 @@ xfs_log_mount( * just worked. */ if (!xfs_has_norecovery(mp)) { - /* - * log recovery ignores readonly state and so we need to clear - * mount-based read only state so it can write to disk. - */ - bool readonly = test_and_clear_bit(XFS_OPSTATE_READONLY, - &mp->m_opstate); error = xlog_recover(log); - if (readonly) - set_bit(XFS_OPSTATE_READONLY, &mp->m_opstate); if (error) { xfs_warn(mp, "log mount/recovery failed: error %d", error); @@ -772,7 +764,6 @@ xfs_log_mount_finish( struct xfs_mount *mp) { struct xlog *log = mp->m_log; - bool readonly; int error = 0; if (xfs_has_norecovery(mp)) { @@ -780,12 +771,6 @@ xfs_log_mount_finish( return 0; } - /* - * log recovery ignores readonly state and so we need to clear - * mount-based read only state so it can write to disk. - */ - readonly = test_and_clear_bit(XFS_OPSTATE_READONLY, &mp->m_opstate); - /* * During the second phase of log recovery, we need iget and * iput to behave like they do for an active filesystem. @@ -835,8 +820,6 @@ xfs_log_mount_finish( xfs_buftarg_drain(mp->m_ddev_targp); clear_bit(XLOG_RECOVERY_NEEDED, &log->l_opstate); - if (readonly) - set_bit(XFS_OPSTATE_READONLY, &mp->m_opstate); /* Make sure the log is dead if we're returning failure. */ ASSERT(!error || xlog_is_shutdown(log)); diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c index 82c81d20459d..b4458b7fd6f7 100644 --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c @@ -3354,6 +3354,7 @@ xlog_recover( struct xlog *log) { xfs_daddr_t head_blk, tail_blk; + bool unknown_rocompat = false; int error; /* find the tail of the log */ @@ -3370,6 +3371,12 @@ xlog_recover( !xfs_log_check_lsn(log->l_mp, log->l_mp->m_sb.sb_lsn)) return -EINVAL; + /* Detect unknown rocompat features in the superblock */ + if (xfs_has_crc(log->l_mp) && + xfs_sb_has_ro_compat_feature(&log->l_mp->m_sb, + XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) + unknown_rocompat = true; + if (tail_blk != head_blk) { /* There used to be a comment here: * @@ -3407,6 +3414,24 @@ xlog_recover( return -EINVAL; } + /* + * Don't allow log recovery on a ro mount if there are unknown + * ro compat bits set. We used to allow this, but BUI/CUI log + * items are protected by the REFLINK rocompat bit so now we + * cannot. + */ + if (xfs_is_readonly(log->l_mp) && unknown_rocompat) { + xfs_alert(log->l_mp, +"Superblock has unknown read-only compatible features (0x%x) enabled.", + (log->l_mp->m_sb.sb_features_ro_compat & + XFS_SB_FEAT_RO_COMPAT_UNKNOWN)); + xfs_warn(log->l_mp, +"The log can not be fully and/or safely recovered by this kernel."); + xfs_warn(log->l_mp, +"Please recover the log on a kernel that supports the unknown features."); + return -EINVAL; + } + /* * Delay log recovery if the debug hook is set. This is debug * instrumentation to coordinate simulation of I/O failures with From patchwork Thu Aug 24 23:21:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13364863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CBCDC727A9 for ; Thu, 24 Aug 2023 23:22:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244057AbjHXXWO (ORCPT ); Thu, 24 Aug 2023 19:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244080AbjHXXV5 (ORCPT ); Thu, 24 Aug 2023 19:21:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B07401FC1 for ; Thu, 24 Aug 2023 16:21:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4727464B19 for ; Thu, 24 Aug 2023 23:21:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6B52C433C7; Thu, 24 Aug 2023 23:21:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692919312; bh=QNP2RUiEFYKkkNqAxOBo5/xT5UQyi5LPXchJafajL3Q=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=QrXxKPU140h7R3WRpNlwF/m/1nlmn3rmhns1Ofq3EVJ/3Viw9LvoOYCQuBT4Kwds6 MkJyfkWW/buDMYYCQOrZ8jVpBvsCOKKSLF0xz7OlfLxG+yM3cVglzo++i9eWEsF6KO c2Ik1sgzB28RLSSXvgvQ/oxAibXOyDPRaWUINQtiRm7saVoxtbC2LxCn4O7xgIq6eG xxo4i6tYpJagIa3KaXN5NMNCdnlOW4lrj2ac/A8ZvDmtjK29kY6I49W2djbZ9ppwRU Dyq9elnBPMfFjMIZO2K2ceIBssdBZRY6x3zsAn3fIES0aPJvoSTTQs5ELpc2+yX8Le xovLpQ+6VpqbQ== Subject: [PATCH 3/3] xfs: log is not writable if we have unknown rocompat features From: "Darrick J. Wong" To: chandan.babu@gmail.com, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, david@fromorbit.com, sandeen@sandeen.net Date: Thu, 24 Aug 2023 16:21:52 -0700 Message-ID: <169291931221.220104.3437825303883889120.stgit@frogsfrogsfrogs> In-Reply-To: <169291929524.220104.3844042018007786965.stgit@frogsfrogsfrogs> References: <169291929524.220104.3844042018007786965.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Ever since commit 9e037cb7972f, the superblock write verifier will trip if someone tries to write a superblock with unknown rocompat features. However, we allow ro mounts of a filesystem with unknown rocompat features if the log is clean, except that has been broken for years because the end of an ro mount cleans the log, which logs and writes the superblock. Therefore, don't allow log writes to happen if there are unknown rocompat features set. Fixes: 9e037cb7972f ("xfs: check for unknown v5 feature bits in superblock write verifier") Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- fs/xfs/xfs_log.c | 6 ++++++ fs/xfs/xfs_log_priv.h | 7 +++++++ fs/xfs/xfs_log_recover.c | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c index 51c100c86177..c1bbc8040bcb 100644 --- a/fs/xfs/xfs_log.c +++ b/fs/xfs/xfs_log.c @@ -391,6 +391,8 @@ xfs_log_writable( return false; if (xlog_is_shutdown(mp->m_log)) return false; + if (xlog_is_readonly(mp->m_log)) + return false; return true; } @@ -408,6 +410,8 @@ xfs_log_regrant( if (xlog_is_shutdown(log)) return -EIO; + if (xlog_is_readonly(log)) + return -EROFS; XFS_STATS_INC(mp, xs_try_logspace); @@ -471,6 +475,8 @@ xfs_log_reserve( if (xlog_is_shutdown(log)) return -EIO; + if (xlog_is_readonly(log)) + return -EROFS; XFS_STATS_INC(mp, xs_try_logspace); diff --git a/fs/xfs/xfs_log_priv.h b/fs/xfs/xfs_log_priv.h index af87648331d5..14892e01de38 100644 --- a/fs/xfs/xfs_log_priv.h +++ b/fs/xfs/xfs_log_priv.h @@ -461,6 +461,7 @@ struct xlog { #define XLOG_IO_ERROR 2 /* log hit an I/O error, and being shutdown */ #define XLOG_TAIL_WARN 3 /* log tail verify warning issued */ +#define XLOG_READONLY 4 /* cannot write to the log */ static inline bool xlog_recovery_needed(struct xlog *log) @@ -480,6 +481,12 @@ xlog_is_shutdown(struct xlog *log) return test_bit(XLOG_IO_ERROR, &log->l_opstate); } +static inline bool +xlog_is_readonly(struct xlog *log) +{ + return test_bit(XLOG_READONLY, &log->l_opstate); +} + /* * Wait until the xlog_force_shutdown() has marked the log as shut down * so xlog_is_shutdown() will always return true. diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c index b4458b7fd6f7..f8f13d5f79cd 100644 --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c @@ -3450,6 +3450,13 @@ xlog_recover( error = xlog_do_recover(log, head_blk, tail_blk); set_bit(XLOG_RECOVERY_NEEDED, &log->l_opstate); + } else if (unknown_rocompat) { + /* + * Log recovery wasn't needed, but if the superblock has + * unknown rocompat features, don't allow log writes at all + * because the sb write verifier will trip. + */ + set_bit(XLOG_READONLY, &log->l_opstate); } return error; } From patchwork Thu Aug 24 23:27:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13364865 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CFF0C88CB9 for ; Thu, 24 Aug 2023 23:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbjHXX2N (ORCPT ); Thu, 24 Aug 2023 19:28:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236629AbjHXX1m (ORCPT ); Thu, 24 Aug 2023 19:27:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F9D2A1 for ; Thu, 24 Aug 2023 16:27:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C9BD663AFB for ; Thu, 24 Aug 2023 23:27:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F0E1C433C7; Thu, 24 Aug 2023 23:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692919659; bh=EqVXpjLmXcu6q6nkQXB4l9cxMQnxDoAGDCj8lCUUhBo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rpHN7IlR3mS43E0TDjccXFN8zpaqI3CzS/169yiUOHYKW2TaZLMW/bbgpWJIQf5WB qhBI9REuKiyUUqULd0Ckn3M7xjEx4SLkCmraowrQCB39oAJiJXWvr23nA2OAe0kKn7 sEIEwubByPei/4Kp4U70wOi4ZedGZk6uzXldg9NmZPzQkdBaVlS3KYy6KB2yW+fU5A RCldrSfIxR/5Xs97tzhoLKD2BXw1xCHqODKst0jXAmGqybkczrucn0vi5LTtL0tlf8 mF9C2MWWBnQJv+anjr4uZOWXeJ6dcQRe+qNKYtIyiBOux3I9GAIfMoYGEZ++fIsKJ4 FLbP252WNiRBg== Date: Thu, 24 Aug 2023 16:27:38 -0700 From: "Darrick J. Wong" To: chandan.babu@gmail.com Cc: linux-xfs@vger.kernel.org, david@fromorbit.com, sandeen@sandeen.net Subject: [PATCH 4/3] xfs/270: actually test file readability Message-ID: <20230824232738.GB17912@frogsfrogsfrogs> References: <169291929524.220104.3844042018007786965.stgit@frogsfrogsfrogs> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <169291929524.220104.3844042018007786965.stgit@frogsfrogsfrogs> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Make sure we can actually read files off the ro mounted filesystem that has an unknown rocompat feature set. Signed-off-by: Darrick J. Wong --- tests/xfs/270 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/xfs/270 b/tests/xfs/270 index 7447ce87be..511dfe9fcd 100755 --- a/tests/xfs/270 +++ b/tests/xfs/270 @@ -23,6 +23,9 @@ _require_scratch_nocheck _require_scratch_xfs_crc _scratch_mkfs_xfs >>$seqres.full 2>&1 +_scratch_mount +echo moo > $SCRATCH_MNT/testfile +_scratch_unmount # set the highest bit of features_ro_compat, use it as an unknown # feature bit. If one day this bit become known feature, please @@ -68,6 +71,7 @@ if [ $? -ne 0 ]; then _fail "ro mount test failed" else # no hang/panic is fine + cat $SCRATCH_MNT/testfile > /dev/null $FSSTRESS_PROG -d $SCRATCH_MNT -p 4 -n 400 >>$seqres.full 2>&1 fi From patchwork Thu Aug 24 23:28:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13364864 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4979EC88CB2 for ; Thu, 24 Aug 2023 23:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232300AbjHXX2N (ORCPT ); Thu, 24 Aug 2023 19:28:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237312AbjHXX2J (ORCPT ); Thu, 24 Aug 2023 19:28:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F1CB19B0 for ; Thu, 24 Aug 2023 16:28:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1433060C16 for ; Thu, 24 Aug 2023 23:28:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72211C433C7; Thu, 24 Aug 2023 23:28:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692919686; bh=2GxWfyN7L7MXXz0DElcxJfxXrjphFMUoXKbRtKd9Cx0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=et/bUqza3PPlctb1VNS5XwC86tNUz6IP/JO11GSuqKcynsICcBX03f3zoP9ObriF4 ak8qagydKlMcwHVXN8SYEPaq98d25iGWOtHR07of81nqWXToSgK+m07ksWAMWxGp90 S0VT86QW1oOHrMAfP7RlGOT554l3qPtpRkQnTOzKAHuVqwJBhWWw6ktcQDZoXdbTrX 1kWMkKxID1YHsdpzpg55FIKD/tP56n8XFtu3C581a1NwAPpwqhXc3L3FnCbauUrVcB TveOS7zRocbiRuiufLfpHwM6S+NP7UchHW90cYr6ojzFpiG5M3uwwzMC5ye2A4S1FS 8nHEaabEgm9Yw== Date: Thu, 24 Aug 2023 16:28:05 -0700 From: "Darrick J. Wong" To: chandan.babu@gmail.com Cc: linux-xfs@vger.kernel.org, david@fromorbit.com, sandeen@sandeen.net Subject: [PATCH 5/3] xfs/270: actually test log recovery with unknown rocompat features Message-ID: <20230824232805.GC17912@frogsfrogsfrogs> References: <169291929524.220104.3844042018007786965.stgit@frogsfrogsfrogs> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <169291929524.220104.3844042018007786965.stgit@frogsfrogsfrogs> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Make sure that log recovery will not succeed if there are unknown rocompat features in the superblock and the log is dirty. Signed-off-by: Darrick J. Wong --- tests/xfs/270 | 81 ++++++++++++++++++++++++++++++++++++----------------- tests/xfs/270.out | 2 + 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/tests/xfs/270 b/tests/xfs/270 index 511dfe9fcd..ee925b0fc6 100755 --- a/tests/xfs/270 +++ b/tests/xfs/270 @@ -21,41 +21,48 @@ _supported_fs xfs _require_scratch_nocheck # Only V5 XFS disallow rw mount/remount with unknown ro-compat features _require_scratch_xfs_crc - -_scratch_mkfs_xfs >>$seqres.full 2>&1 -_scratch_mount -echo moo > $SCRATCH_MNT/testfile -_scratch_unmount +_require_scratch_shutdown # set the highest bit of features_ro_compat, use it as an unknown # feature bit. If one day this bit become known feature, please # change this case. +set_bad_rocompat() { + ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0") + echo $ro_compat | grep -q -E '^0x[[:xdigit:]]$' + if [[ $? != 0 ]]; then + echo "features_ro_compat has an invalid value." + return 1 + fi -ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0") -echo $ro_compat | grep -q -E '^0x[[:xdigit:]]$' -if [[ $? != 0 ]]; then - echo "features_ro_compat has an invalid value." -fi + ro_compat=$(echo $ro_compat | \ + awk '/^0x[[:xdigit:]]+/ { + printf("0x%x\n", or(strtonum($1), 0x80000000)) + }') -ro_compat=$(echo $ro_compat | \ - awk '/^0x[[:xdigit:]]+/ { - printf("0x%x\n", or(strtonum($1), 0x80000000)) - }') + # write the new ro compat field to the superblock + _scratch_xfs_set_metadata_field "features_ro_compat" "$ro_compat" "sb 0" \ + > $seqres.full 2>&1 -# write the new ro compat field to the superblock -_scratch_xfs_set_metadata_field "features_ro_compat" "$ro_compat" "sb 0" \ - > $seqres.full 2>&1 + # read the newly set ro compat filed for verification + new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0" \ + 2>/dev/null) -# read the newly set ro compat filed for verification -new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0" \ - 2>/dev/null) + # verify the new ro_compat field is correct. Without xfsprogs commit + # f4afdcb0ad ("xfs_db: clean up the salvage read callsites in set_cur()"), + # we can't get new_ro_compat value. + if [ "$new_ro_compat" != "$ro_compat" ]; then + echo "Unable to set new features_ro_compat. Wanted $ro_compat, got $new_ro_compat" + return 1 + fi + return 0 +} -# verify the new ro_compat field is correct. Without xfsprogs commit -# f4afdcb0ad ("xfs_db: clean up the salvage read callsites in set_cur()"), -# we can't get new_ro_compat value. -if [ "$new_ro_compat" != "$ro_compat" ]; then - echo "Unable to set new features_ro_compat. Wanted $ro_compat, got $new_ro_compat" -fi +# Once with a clean filesystem... +_scratch_mkfs_xfs >>$seqres.full 2>&1 +_scratch_mount +echo moo > $SCRATCH_MNT/testfile +_scratch_unmount +set_bad_rocompat # rw mount with unknown ro-compat feature should fail echo "rw mount test" @@ -85,6 +92,28 @@ fi _scratch_unmount +# And again with a dirty filesystem... +_scratch_mkfs_xfs >>$seqres.full 2>&1 +_scratch_mount +echo moo > $SCRATCH_MNT/testfile +$XFS_IO_PROG -x -c 'shutdown -f' "${SCRATCH_MNT}" +_scratch_unmount +set_bad_rocompat + +# rw mount with unknown ro-compat feature should fail +echo "rw mount test" +_try_scratch_mount 2>>$seqres.full +if [ $? -eq 0 ]; then + _fail "rw mount test failed" +fi + +# ro mount should not succeed due to log recovery +echo "ro mount test" +_try_scratch_mount -o ro 2>>$seqres.full +if [ $? -eq 0 ]; then + _fail "ro mount test succeeded" +fi + # success, all done status=0 exit diff --git a/tests/xfs/270.out b/tests/xfs/270.out index edf4c25489..a519d2f328 100644 --- a/tests/xfs/270.out +++ b/tests/xfs/270.out @@ -2,3 +2,5 @@ QA output created by 270 rw mount test ro mount test rw remount test +rw mount test +ro mount test