From patchwork Tue May 23 00:37:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13251316 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 75808C77B73 for ; Tue, 23 May 2023 00:48:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233034AbjEWAsa (ORCPT ); Mon, 22 May 2023 20:48:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233996AbjEWAsM (ORCPT ); Mon, 22 May 2023 20:48:12 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC8BD4C27 for ; Mon, 22 May 2023 17:37:33 -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-out1.suse.de (Postfix) with ESMTPS id 8C71D2236E for ; Tue, 23 May 2023 00:37:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1684802252; 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=hwuyl+YlmnhMaiqB+9vXiDdlZbn3K3urnM4RhrzU64k=; b=Z8zzwXZy9ryhdIHd5ot+6kUZTlopPlpIQuZfhjr8ALeExmMcfSYI5lPDsdGisLFgdpnW7I jHHyfYfsfHt13x5k9HqFA5Tg2oJCwuHpHFYRtY0UM4D1D6KcDls8fl6hZyrUTTy/Sbzf/w Fb1Zi2mKd6XJH1TQN319jirisDTJt9M= 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 E31C713588 for ; Tue, 23 May 2023 00:37:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wJPvKssKbGTIIgAAMHmgww (envelope-from ) for ; Tue, 23 May 2023 00:37:31 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/2] btrfs-progs: tune: delete the csum change item after converting the fs Date: Tue, 23 May 2023 08:37:12 +0800 Message-Id: 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 [BUG] Doing the following csum change in a row, it would fail: # mkfs.btrfs -f --csum crc32c $dev # btrfstune --csum sha256 $dev # btrfstune --csum crc32c $dev # btrfstune --csum sha256 $dev WARNING: Experimental build with unstable or unfinished features WARNING: Switching checksums is experimental, do not use for valuable data! Proceed to switch checksums ERROR: failed to insert csum change item: File exists ERROR: failed to generate new data csums: File exists WARNING: reserved space leaked, flag=0x4 bytes_reserved=16384 extent buffer leak: start 30572544 len 16384 extent buffer leak: start 30441472 len 16384 WARNING: dirty eb leak (aborted trans): start 30441472 len 16384 [CAUSE] During every csum change operation, btrfstune would insert an temporaray csum change item into root tree. But unfortunately after the conversion btrfstune doesn't properly delete the csum change item, result the following items in the root tree: item 10 key (CSUM_CHANGE TEMPORARY_ITEM 0) itemoff 13423 itemsize 0 temporary item objectid CSUM_CHANGE offset 0 target csum type crc32c (0) item 11 key (CSUM_CHANGE TEMPORARY_ITEM 2) itemoff 13423 itemsize 0 temporary item objectid CSUM_CHANGE offset 2 target csum type sha256 (2) Thus at the last conversion try to go back to SHA256, we failed to insert the same item, and caused the above error. [FIX] After finishing the metadata csum conversion, do a proper removal of the csum item. Signed-off-by: Qu Wenruo --- tune/change-csum.c | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/tune/change-csum.c b/tune/change-csum.c index c8809300a143..b5efc3a8807f 100644 --- a/tune/change-csum.c +++ b/tune/change-csum.c @@ -583,10 +583,13 @@ out: btrfs_release_path(&path); /* - * Finish the change by clearing the csum change flag and update the superblock - * csum type. + * Finish the change by clearing the csum change flag, update the superblock + * csum type, and delete the csum change item in the fs with new csum type. */ if (ret == 0) { + struct btrfs_root *tree_root = fs_info->tree_root; + struct btrfs_trans_handle *trans; + u64 super_flags = btrfs_super_flags(fs_info->super_copy); btrfs_set_super_csum_type(fs_info->super_copy, new_csum_type); @@ -596,11 +599,42 @@ out: fs_info->csum_type = new_csum_type; fs_info->csum_size = btrfs_csum_type_size(new_csum_type); + fs_info->skip_csum_check = 0; - ret = write_all_supers(fs_info); + trans = btrfs_start_transaction(tree_root, 1); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + errno = -ret; + error("failed to start new transaction with new csum type: %m"); + return ret; + } + key.objectid = BTRFS_CSUM_CHANGE_OBJECTID; + key.type = BTRFS_TEMPORARY_ITEM_KEY; + key.offset = new_csum_type; + + ret = btrfs_search_slot(trans, tree_root, &key, &path, -1, 1); + if (ret > 0) + ret = -ENOENT; if (ret < 0) { errno = -ret; - error("failed to write super blocks: %m"); + error("failed to locate the csum change item: %m"); + btrfs_release_path(&path); + btrfs_abort_transaction(trans, ret); + return ret; + } + ret = btrfs_del_item(trans, tree_root, &path); + if (ret < 0) { + errno = -ret; + error("failed to delete the csum change item: %m"); + btrfs_release_path(&path); + btrfs_abort_transaction(trans, ret); + return ret; + } + btrfs_release_path(&path); + ret = btrfs_commit_transaction(trans, tree_root); + if (ret < 0) { + errno = -ret; + error("failed to finalize the csum change: %m"); } } return ret; From patchwork Tue May 23 00:37:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13251315 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 D0A1AC7EE2A for ; Tue, 23 May 2023 00:46:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235134AbjEWAqT (ORCPT ); Mon, 22 May 2023 20:46:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235884AbjEWApu (ORCPT ); Mon, 22 May 2023 20:45:50 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 467D84C29 for ; Mon, 22 May 2023 17:37:35 -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 971911FFA2 for ; Tue, 23 May 2023 00:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1684802253; 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=FaTw0p2WgQol2ErKxrGbPX8MpjjJWTvifKse97Bl9hw=; b=j05bPmfoXh7GCi2EQdGK+9sQVwyUp1AmWMAP07U5XfmuddYwiEJ4xrXvjuoP78+mXRd/7E Of37dW2L+6ZJlLoLeq0zOqHWwxHVvbPf3sGgVBpSWxATLUI5ycabHyYhi0iz1Te+LQrotx CatPYOgbpvmOeswDd3m6no12rOCGEuQ= 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 EE23413588 for ; Tue, 23 May 2023 00:37:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oNyvLcwKbGTIIgAAMHmgww (envelope-from ) for ; Tue, 23 May 2023 00:37:32 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] btrfs-progs: tests/misc: add a test case for csum change Date: Tue, 23 May 2023 08:37:13 +0800 Message-Id: <0d8e9a8dd3b9ba9d91a9ae826565c1a324218ba0.1684802060.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 test case would: - Populate the fs - Run csum change for all the target csum type - Run above csum change again This should more or less cover the common paths, and detect any conflicting csum change item. Signed-off-by: Qu Wenruo --- .../058-btrfstune-csum-change/test.sh | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 tests/misc-tests/058-btrfstune-csum-change/test.sh diff --git a/tests/misc-tests/058-btrfstune-csum-change/test.sh b/tests/misc-tests/058-btrfstune-csum-change/test.sh new file mode 100755 index 000000000000..925e71b86285 --- /dev/null +++ b/tests/misc-tests/058-btrfstune-csum-change/test.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# Test btrfstune --csum option + +source "$TEST_TOP/common" || exit +source "$TEST_TOP/common.convert" || exit + +check_prereq mkfs.btrfs +check_prereq btrfstune +check_prereq btrfs + +setup_root_helper +prepare_test_dev + +run_check_mkfs_test_dev --csum crc32c +run_check_mount_test_dev +populate_fs +run_check_umount_test_dev + +for hash in "blake2" "crc32c" "xxhash" "sha256"; do + run_check $SUDO_HELPER "$TOP/btrfstune" --csum $hash "$TEST_DEV" + run_check $SUDO_HELPER "$TOP/btrfs" check --check-data-csum "$TEST_DEV" +done +for hash in "blake2" "crc32c" "xxhash" "sha256"; do + run_check $SUDO_HELPER "$TOP/btrfstune" --csum $hash "$TEST_DEV" + run_check $SUDO_HELPER "$TOP/btrfs" check --check-data-csum "$TEST_DEV" +done