Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1132777rwi; Wed, 19 Oct 2022 07:07:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4bsSHnhbjMl/KsNlGfWWezv26UBhsH4ArcWXlgByrvSasOn37+oq+bRCzSuHetZzcjbHDn X-Received: by 2002:a05:6402:ea8:b0:456:d188:b347 with SMTP id h40-20020a0564020ea800b00456d188b347mr7689929eda.15.1666188437792; Wed, 19 Oct 2022 07:07:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666188437; cv=none; d=google.com; s=arc-20160816; b=kCzdY8evoqdBiROCSacdgxpU5dJjgltsrwibCgmo6ZxRiqlYB1YoPSP/YzV1u8J5tb u+CZ/eN66ngcuTPYC0J95+D7FzOw5CIfp+OhtnTZ25EQI5DctJeptXxc+ecZW1zr5f3Q SY7MEKWmHKEf+qPs5Wohz/9SGl26fO07CYWJjMjYaaZrD1bJqBj2s5ZnEfqY8I8jOj7c XmdgS9FueFsLyF2/swoWelwrNjysxVE+xnj2lI8PUsc5o1vGALc+PzXkyGzWtkO1Chkb XgU3eCAYr0PUzUDS63t9nrMBE9rBeC6jPYqM3NErXHsCf4W5vVvCqYeSRMThir1dms79 I+yA== 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=PCEdJAFm1Dnr500SDsIn8JlXgVVr4fAqhHx+ugTW9Rg=; b=SO9X9Xf45kIfa2QbnuNfT9ePIqDiDefnikedC0WMFR2WdnolGKQJI7l4Vj+x9hevsC 3YAlyuYloeESJwpYijzdC/pmDXae6tBw+1DFVsqrxgrHGhUYwQhhnhBzPN9fnIUDHDve bfu38t7U7IxZmemGi9pG+3VLCUHqNj4A86Akvqsa27ejYrvbfWQqVuyYiHHcsmBxmFxr Zv1xRMlUDANKOA+70pS6SQ2l1wa8Tdm6+e2CFzhkUMZ1CWn6VL304JUbKA1pCGmpY0S3 KIJO7RMEtLPNzUFvE/U8yhVMgvN3vJJTRm8lTZVyQ7MT3Zd6aLDtuIIenU9lCCxApcy5 safw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZS6DktjQ; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y12-20020a056402270c00b0045d636ca148si11609239edd.575.2022.10.19.07.06.51; Wed, 19 Oct 2022 07:07:17 -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=ZS6DktjQ; 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 S231174AbiJSN0Z (ORCPT + 99 others); Wed, 19 Oct 2022 09:26:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231824AbiJSN0A (ORCPT ); Wed, 19 Oct 2022 09:26:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 306BC1CC74F; Wed, 19 Oct 2022 06:12:23 -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 ams.source.kernel.org (Postfix) with ESMTPS id 08DAEB822DF; Wed, 19 Oct 2022 08:43:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6638CC433D7; Wed, 19 Oct 2022 08:43:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168981; bh=+kzFWhmia5w1mBkbgYOwAljW+SBIesxD8Be950Xz91U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZS6DktjQckPJQyaeNGtVhs7oIbxEhkAc3htuYcOij7KBx0QnyVXOmpeLxTlKYMIX0 oVcsLXRtsANu42CeTiidPS5bPgd6FCFm1pmSfPqg5tBqxxDi/vt+naQhWIJg0EFQpx cdKt5xtAXCUU3POSFVj9yYiYTuHRA9g5EV5ArlbQ= 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 6.0 119/862] btrfs: enhance unsupported compat RO flags handling Date: Wed, 19 Oct 2022 10:23:26 +0200 Message-Id: <20221019083255.205949482@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 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 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 @@ -2190,7 +2190,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 @@ -2112,6 +2112,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;