From patchwork Wed Oct 19 08:23:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5461 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp331499wrs; Wed, 19 Oct 2022 06:36:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5qVrQUF9OzB/msN27Qc2uGNAghSo+VtUxbjznLzHsEGb+vkExoIfLx3xsaOAPrfcRr1YNB X-Received: by 2002:a63:5559:0:b0:464:a987:8365 with SMTP id f25-20020a635559000000b00464a9878365mr7363194pgm.479.1666186615198; Wed, 19 Oct 2022 06:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666186615; cv=none; d=google.com; s=arc-20160816; b=PUfgvFO7buoKFjz6F8fq2bPThKj/UUN2IgHaKsvUVIsIl2rlMy4ZQ2PUBDBuihYgUd KcMkWfCjUJcCrePZjuQj4zCAam1Lp+YSrhV1JDG/fnah6wWFDGjONPjN6RtaWjRdcMUc PLbKj7M9ncxKT/TZt5XWgBylr2I/N7JFxzCMZUhfsMeaf1GIAXFgdFdO6QuuF9/QLnoQ SSKGB0so+NGSdpZiUxyY1cIXIfQWKFYEEXdK1Z+ci+/KrHK8ZayrQvmt5Nap8kCLVuUt aswLpQPZ+iHJECweDQSGQgA8DweQSP6QBZx6VHuD9OvjGCzEUBOLQ+Wb8o6Rcoeerhbb VHyQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lp15-20020a17090b4a8f00b00202a34035bfsi18821987pjb.78.2022.10.19.06.36.42; Wed, 19 Oct 2022 06:36:55 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747123296075938860?= X-GMAIL-MSGID: =?utf-8?q?1747123296075938860?= 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;