From patchwork Sat Oct 22 07:19:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7221 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1090442wrr; Sat, 22 Oct 2022 00:47:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7EQzzfQ2SEiAwZPujZzSHCWviG26fPpgnOqeSXAMs6oQvMZwo7HlZ1IuxV606occ3+Xtn7 X-Received: by 2002:a63:8349:0:b0:46b:2bd4:f291 with SMTP id h70-20020a638349000000b0046b2bd4f291mr19572185pge.75.1666424827259; Sat, 22 Oct 2022 00:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666424827; cv=none; d=google.com; s=arc-20160816; b=Z3ApqlF2042JjAdIgT8rXXlcbcVRzrfzMpoNPaqKNCK58PwTbpkRtwlr11OZZJHbi9 zBsm4COEM9pLDOomtRnOJGw3vNA0gKyajSE6fc6Zpbcg1opwjdZ42W5nQa+7ZNhOYx+o GOvpuYvMOo/S7b4mQAAQVIqraaQkYXJyiS/wdbj0hhb1160COUXTiYf3JS/z7Zo+v/N6 YD3YnFuG1DNyWi3NbJMOheRFmTv9m8os9Gl+nQfq3Lfr8HBOiOq+FbJnSdyFIKVqkjML 4Szzo893/yPGZp1L4goS8GBwN4zYlmI99hVuCvN+185f/pn98JHQSvtFHyd9nZTQ9Lgm oC1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2w+KEqjQkyj2+GPQASTIqG8O/MZ5vynYiinlfMNNjUg=; b=KcWbQg/FzJd5bFynLW37hfG4HsCcJG1OLyB7SrWPYqWxR9zxXGLkR/EJE2Q2MEuAJH 5zsAVz7tlty7lbbLaEWv5xg6Cf/IKcEFsrP0rkmrZK/wzUSWCWa9/Ka+xumAEhAQdexq tkUJ558UK+OiMmSU5xpyXH/ppHMVnoX4d2XYo35WoqmMoNAt+BeDnLNwFaBnRoiE+97B gzSg6VEopF/Lpn+SN/eLZyyHL+DfUbQlyE18ScNCE+7lC1IqTSaJjeQOBAmcFK+4kVCk 6arXwaAM8BigiBV7gh3KmJ5yvBg7W4WUXPiDKbvSjhzNCrrqBDpdt7qECyMZ9yRDilt/ Rb6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yxdwsd29; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ng13-20020a17090b1a8d00b00205fb99a5fesi11085254pjb.136.2022.10.22.00.46.54; Sat, 22 Oct 2022 00:47:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yxdwsd29; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230388AbiJVHqf (ORCPT + 99 others); Sat, 22 Oct 2022 03:46:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231561AbiJVHoa (ORCPT ); Sat, 22 Oct 2022 03:44:30 -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 C3520625EA; Sat, 22 Oct 2022 00:43:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 526F160B27; Sat, 22 Oct 2022 07:38:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54109C433C1; Sat, 22 Oct 2022 07:38:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424334; bh=zSw86Kfl/43rpUiQkO8CuqcSTmXOw99N9G+BtcjPwjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yxdwsd29PcmCABdETN0Fzm96sE29aCMV+8vCOmKMWV1rq8rZ8jvhKExNkcuyrYFYH x+xgUeh/yrdiiZE1zaFb0KJMAERIHq8urhrbNhDKxX6oPtrFvGyfv+F+fRWSlYYxf6 NqxISR4pk4e/AajXpuaFLuKN+Zcg5Src9ZR7Xy6I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikolay Borisov , Qu Wenruo , David Sterba Subject: [PATCH 5.19 108/717] btrfs: enhance unsupported compat RO flags handling Date: Sat, 22 Oct 2022 09:19:47 +0200 Message-Id: <20221022072434.561112249@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747373079366901761?= X-GMAIL-MSGID: =?utf-8?q?1747373079366901761?= From: Qu Wenruo commit 81d5d61454c365718655cfc87d8200c84e25d596 upstream. Currently there are two corner cases not handling compat RO flags correctly: - Remount We can still mount the fs RO with compat RO flags, then remount it RW. We should not allow any write into a fs with unsupported RO flags. - Still try to search block group items In fact, behavior/on-disk format change to extent tree should not need a full incompat flag. And since we can ensure fs with unsupported RO flags never got any writes (with above case fixed), then we can even skip block group items search at mount time. This patch will enhance the unsupported RO compat flags by: - Reject read-write remount if there are unsupported RO compat flags - Go dummy block group items directly for unsupported RO compat flags In fact, only changes to chunk/subvolume/root/csum trees should go incompat flags. The latter part should allow future change to extent tree to be compat RO flags. Thus this patch also needs to be backported to all stable trees. CC: stable@vger.kernel.org # 4.9+ Reviewed-by: Nikolay Borisov Signed-off-by: Qu Wenruo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/block-group.c | 11 ++++++++++- fs/btrfs/super.c | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2191,7 +2191,16 @@ int btrfs_read_block_groups(struct btrfs int need_clear = 0; u64 cache_gen; - if (!root) + /* + * Either no extent root (with ibadroots rescue option) or we have + * unsupported RO options. The fs can never be mounted read-write, so no + * need to waste time searching block group items. + * + * This also allows new extent tree related changes to be RO compat, + * no need for a full incompat flag. + */ + if (!root || (btrfs_super_compat_ro_flags(info->super_copy) & + ~BTRFS_FEATURE_COMPAT_RO_SUPP)) return fill_dummy_bgs(info); key.objectid = 0; --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2113,6 +2113,15 @@ static int btrfs_remount(struct super_bl ret = -EINVAL; goto restore; } + if (btrfs_super_compat_ro_flags(fs_info->super_copy) & + ~BTRFS_FEATURE_COMPAT_RO_SUPP) { + btrfs_err(fs_info, + "can not remount read-write due to unsupported optional flags 0x%llx", + btrfs_super_compat_ro_flags(fs_info->super_copy) & + ~BTRFS_FEATURE_COMPAT_RO_SUPP); + ret = -EINVAL; + goto restore; + } if (fs_info->fs_devices->rw_devices == 0) { ret = -EACCES; goto restore;