From patchwork Thu May 18 02:10:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13246041 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 AD867C77B7A for ; Thu, 18 May 2023 02:11:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229626AbjERCLL (ORCPT ); Wed, 17 May 2023 22:11:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229739AbjERCLI (ORCPT ); Wed, 17 May 2023 22:11:08 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B2683AAF for ; Wed, 17 May 2023 19:11:07 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4D51720019 for ; Thu, 18 May 2023 02:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1684375866; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=shT6JAVzDIl9W31VXrwplD+sYZEFYwPLksGTz/UxirY=; b=P+9VqhSk7Wd3fHz6yQZmZnrsz9xphsr+nlNjbV7wgyp/mx9WzJfTYyeIMSZBZ2fXkHdVcb r9zhNzsusbWvP3RStFh/oTv+vqRunYHYtKEt1iZXA4Ul068BCdzgLGc46rloYU6i5D6f12 NLby+1OB3PGLJDAQPpkd5Bn6COVGAoU= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9D6281332D for ; Thu, 18 May 2023 02:11:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aGoQGDmJZWRVJAAAMHmgww (envelope-from ) for ; Thu, 18 May 2023 02:11:05 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 2/7] btrfs-progs: tune: implement the prerequisite checks for csum change Date: Thu, 18 May 2023 10:10:40 +0800 Message-Id: <7e638e79f7e1d2bce75961626f3aa18ff8a5abc2.1684375729.git.wqu@suse.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The overall idea is to make sure no running operations (balance, dev-replace, dirty log) for the fs before csum change. And also reject half converted csums for now. Signed-off-by: Qu Wenruo --- tune/change-csum.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tune/change-csum.c b/tune/change-csum.c index 7a9f6351e7fe..daab70b6eb4a 100644 --- a/tune/change-csum.c +++ b/tune/change-csum.c @@ -26,9 +26,68 @@ #include "common/internal.h" #include "tune/tune.h" +static int check_csum_change_requreiment(struct btrfs_fs_info *fs_info) +{ + struct btrfs_root *tree_root = fs_info->tree_root; + struct btrfs_root *dev_root = fs_info->dev_root; + struct btrfs_path path = { 0 }; + struct btrfs_key key; + int ret; + + if (btrfs_super_log_root(fs_info->super_copy)) { + error("dirty log tree detected, please replay the log or zero it."); + return -EINVAL; + } + if (btrfs_fs_incompat(fs_info, EXTENT_TREE_V2)) { + error("no csum change support for extent-tree-v2 feature yet."); + return -EOPNOTSUPP; + } + if (btrfs_super_flags(fs_info->super_copy) & + (BTRFS_SUPER_FLAG_CHANGING_DATA_CSUM | + BTRFS_SUPER_FLAG_CHANGING_META_CSUM)) { + error("resume from half converted status is not yet supported"); + return -EOPNOTSUPP; + } + key.objectid = BTRFS_BALANCE_OBJECTID; + key.type = BTRFS_TEMPORARY_ITEM_KEY; + key.offset = 0; + ret = btrfs_search_slot(NULL, tree_root, &key, &path, 0, 0); + btrfs_release_path(&path); + if (ret < 0) { + errno = -ret; + error("failed to check the balance status: %m"); + return ret; + } + if (ret == 0) { + error("running balance detected, please finish or cancel it."); + return -EINVAL; + } + + key.objectid = 0; + key.type = BTRFS_DEV_REPLACE_KEY; + key.offset = 0; + ret = btrfs_search_slot(NULL, dev_root, &key, &path, 0, 0); + btrfs_release_path(&path); + if (ret < 0) { + errno = -ret; + error("failed to check the dev-reaplce status: %m"); + return ret; + } + if (ret == 0) { + error("running dev-replace detected, please finish or cancel it."); + return -EINVAL; + } + return 0; +} + int btrfs_change_csum_type(struct btrfs_fs_info *fs_info, u16 new_csum_type) { + int ret; + /* Phase 0, check conflicting features. */ + ret = check_csum_change_requreiment(fs_info); + if (ret < 0) + return ret; /* * Phase 1, generate new data csums.