From patchwork Fri Jun 21 05:16:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13706842 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70BE2A47 for ; Fri, 21 Jun 2024 05:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718947044; cv=none; b=CMqHGO4UfNACmuqp9vnSBIsxhSm5PUf+Kt5EZPeJ+rO2xlFAWV2UTq69hXYDhHqlSShAqYlBwgSBeSgNEVLc5mg3rhxmBspaotxdZO1EEfVnZX6/sPgGRMf7YzaCbXwZsXZ9+dayz549GH/uoArsgCgEP0qkXENoVhMjz0yTJu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718947044; c=relaxed/simple; bh=ycrtJLL4IICmxwVCqxkgfln6MkDtJsJbc8Nph+op2Gc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kO2eUKCbs0ngZUZAjzedEn71xg9xsAbuNue2n/5tnMG3RE5nZ510JYJRx67C+gI3doxN0XMgcG5twvFw2JjIUWLQiSfj0C0hyr90PDJg68Y4w3lAFSlVtDSm9DNLfgRJ0ztC3dtCXqlYKT8IdmDTE4iKlm7UWC1aOYZt8cXSNSs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=eOBq87YG; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=eOBq87YG; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="eOBq87YG"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="eOBq87YG" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BB1451FB3B for ; Fri, 21 Jun 2024 05:17:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1718947040; 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=XTxChFJpk0pIXnZORV+cGUkP80j6sNLhMF1bPOxN5rE=; b=eOBq87YGQgjw+Wajyi33s+nCnq9YW0LRlRdvlHPhUfW1tL4BtJEQ6Z2gzxWwHs+V/m2GmB HBj3cnqbnmnvEdoAOGIH3KNB0CXhnE0NsKJSwAMpHU8ZUCcVQYaFm2JG0fEnRbJW9jcoKJ iO+28lmro0XzZAof+/CN9DnCcC+XNQA= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1718947040; 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=XTxChFJpk0pIXnZORV+cGUkP80j6sNLhMF1bPOxN5rE=; b=eOBq87YGQgjw+Wajyi33s+nCnq9YW0LRlRdvlHPhUfW1tL4BtJEQ6Z2gzxWwHs+V/m2GmB HBj3cnqbnmnvEdoAOGIH3KNB0CXhnE0NsKJSwAMpHU8ZUCcVQYaFm2JG0fEnRbJW9jcoKJ iO+28lmro0XzZAof+/CN9DnCcC+XNQA= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id D15BA13ABD for ; Fri, 21 Jun 2024 05:17:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id oCpuId8MdWavbAAAD6G6ig (envelope-from ) for ; Fri, 21 Jun 2024 05:17:19 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 1/3] btrfs-progs: csum-change: add error handling for search old csums Date: Fri, 21 Jun 2024 14:46:54 +0930 Message-ID: <6bb6f483287cd3c15cabfabfbb81cc5c0392be32.1718946934.git.wqu@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Score: -2.79 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-2.79 / 50.00]; BAYES_HAM(-3.00)[99.98%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.19)[-0.968]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,imap1.dmz-prg2.suse.org:helo]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[linux-btrfs@vger.kernel.org]; RCVD_TLS_ALL(0.00)[] Inside delete_old_data_csums(), after calling btrfs_search_slot() there is no error handling at all. Fix it by doing a proper error detection and abort the current transaction. Signed-off-by: Qu Wenruo --- tune/change-csum.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tune/change-csum.c b/tune/change-csum.c index 0e7db20f5e6d..0f95cdb25533 100644 --- a/tune/change-csum.c +++ b/tune/change-csum.c @@ -395,6 +395,13 @@ static int delete_old_data_csums(struct btrfs_fs_info *fs_info) int nr; ret = btrfs_search_slot(trans, csum_root, &last_key, &path, -1, 1); + if (ret < 0) { + errno = -ret; + error("failed to search the last old csum item: %m"); + btrfs_abort_transaction(trans, ret); + return ret; + } + assert(ret > 0); nr = btrfs_header_nritems(path.nodes[0]); /* No item left (empty csum tree), exit. */ From patchwork Fri Jun 21 05:16:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13706844 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0A0112BF2B for ; Fri, 21 Jun 2024 05:17:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718947046; cv=none; b=OiViqTjRvRNWAfuVI3tZ1fh6QimnUg7pXZEJPikvs2+Es+KAM0cS/r4zgRxxQl+vWR9DJyJqJOCvQ1Wspjg+r2UjNtoRj+PtA+dNhoiARrTurZfnidaCNzfBMZshIwgL9UlWY1NpR3FML0dkbCh5P4BH8kokdcjmwCIm89o/KBs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718947046; c=relaxed/simple; bh=LWvNVaGthbYvI4yj3ghqWqZu/vYWrQ3wpV+A61DssWI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i4sJhqeHECBCn/ajHqPz/RBipDYILVgZKKuOCSGD/ANVgwUNCqLErUBOyAp7Q5DPjuLxbxkzjJcGEOLbUNhCNXqdrpO0PTZVLF0nTX1qHRX99EqTL15USSnApeRYk/7KbkOM8/YCuyZC3pnNK9qkG0Nk8eEDUfnqjhvhCRolirs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=PYjFJiaf; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=PYjFJiaf; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="PYjFJiaf"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="PYjFJiaf" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3D99F1FB3F for ; Fri, 21 Jun 2024 05:17:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1718947042; 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=OTpcAHvNRgz7hHOHyV971kpgK9P/XxuDK7599zOP8bk=; b=PYjFJiafeHTK2yeSiC4QGUVZ6fCXCdkyTcoEBIQXLZyhnW4x6FNF9gj7r/1NOe/GCcLn57 sb1jAMoBeVViAyyPmAR7KGjgBhLujdxZ6+UAaiQbTA4TyudCKnUQS6QqrcqWybYD+oEFFz CETc03ifNmmG21fcAHxenEYPvf7Q7cc= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1718947042; 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=OTpcAHvNRgz7hHOHyV971kpgK9P/XxuDK7599zOP8bk=; b=PYjFJiafeHTK2yeSiC4QGUVZ6fCXCdkyTcoEBIQXLZyhnW4x6FNF9gj7r/1NOe/GCcLn57 sb1jAMoBeVViAyyPmAR7KGjgBhLujdxZ6+UAaiQbTA4TyudCKnUQS6QqrcqWybYD+oEFFz CETc03ifNmmG21fcAHxenEYPvf7Q7cc= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 535BC13AAA for ; Fri, 21 Jun 2024 05:17:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id QPi1AuEMdWavbAAAD6G6ig (envelope-from ) for ; Fri, 21 Jun 2024 05:17:21 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 2/3] btrfs-progs: csum-change: add leaf based threshold Date: Fri, 21 Jun 2024 14:46:55 +0930 Message-ID: <9f7a033fe4e33c1c8122a523fe11844b6d8ba95e.1718946934.git.wqu@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spamd-Result: default: False [-2.79 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.19)[-0.972]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.com:email]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[linux-btrfs@vger.kernel.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Score: -2.79 X-Spam-Level: For "btrfstune --csum", currently we do the following operations in just one transaction for each: - Delete old data csums - Change new data csums objectid Both opeartion can modify up to GiB or even TiB level of metadata, doing them in just one transaction is definitely going to cause problems. This patch adds a leaf number based threshold (32 leaves), after modifying/deleteing this many leaves, we commit a transaction to avoid huge amount of dirty leaves piling up. Signed-off-by: Qu Wenruo --- tune/change-csum.c | 68 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/tune/change-csum.c b/tune/change-csum.c index 0f95cdb25533..66fdd207335c 100644 --- a/tune/change-csum.c +++ b/tune/change-csum.c @@ -371,29 +371,48 @@ static int generate_new_data_csums(struct btrfs_fs_info *fs_info, u16 new_csum_t return generate_new_data_csums_range(fs_info, 0, new_csum_type); } +/* After deleting/modifying this many leaves, commit a transaction. */ +#define CSUM_CHANGE_LEAVES_THRESHOLD 32 + static int delete_old_data_csums(struct btrfs_fs_info *fs_info) { struct btrfs_root *csum_root = btrfs_csum_root(fs_info, 0); - struct btrfs_trans_handle *trans; + struct btrfs_trans_handle *trans = 0; struct btrfs_path path = { 0 }; struct btrfs_key last_key; + unsigned int deleted_leaves = 0; int ret; last_key.objectid = BTRFS_EXTENT_CSUM_OBJECTID; last_key.type = BTRFS_EXTENT_CSUM_KEY; last_key.offset = (u64)-1; - trans = btrfs_start_transaction(csum_root, 1); - if (IS_ERR(trans)) { - ret = PTR_ERR(trans); - errno = -ret; - error("failed to start transaction to delete old data csums: %m"); - return ret; - } while (true) { int start_slot; int nr; + if (deleted_leaves >= CSUM_CHANGE_LEAVES_THRESHOLD) { + assert(trans); + ret = btrfs_commit_transaction(trans, csum_root); + if (ret < 0) { + errno = -ret; + error( + "failed to commit transaction to delete old data csums: %m"); + return ret; + } + trans = NULL; + deleted_leaves = 0; + } + if (!trans) { + trans = btrfs_start_transaction(csum_root, 1); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + errno = -ret; + error( + "failed to start transaction to delete old data csums: %m"); + return ret; + } + } ret = btrfs_search_slot(trans, csum_root, &last_key, &path, -1, 1); if (ret < 0) { errno = -ret; @@ -428,6 +447,7 @@ static int delete_old_data_csums(struct btrfs_fs_info *fs_info) break; } btrfs_release_path(&path); + deleted_leaves++; } btrfs_release_path(&path); if (ret < 0) @@ -445,9 +465,10 @@ static int delete_old_data_csums(struct btrfs_fs_info *fs_info) static int change_csum_objectids(struct btrfs_fs_info *fs_info) { struct btrfs_root *csum_root = btrfs_csum_root(fs_info, 0); - struct btrfs_trans_handle *trans; + struct btrfs_trans_handle *trans = NULL; struct btrfs_path path = { 0 }; struct btrfs_key last_key; + unsigned int changed_leaves = 0; u64 super_flags; int ret = 0; @@ -455,17 +476,32 @@ static int change_csum_objectids(struct btrfs_fs_info *fs_info) last_key.type = BTRFS_EXTENT_CSUM_KEY; last_key.offset = (u64)-1; - trans = btrfs_start_transaction(csum_root, 1); - if (IS_ERR(trans)) { - ret = PTR_ERR(trans); - errno = -ret; - error("failed to start transaction to change csum objectids: %m"); - return ret; - } while (true) { struct btrfs_key found_key; int nr; + if (changed_leaves >= CSUM_CHANGE_LEAVES_THRESHOLD) { + assert(trans); + ret = btrfs_commit_transaction(trans, csum_root); + if (ret < 0) { + errno = -ret; + error( + "failed to commit transaction to change data csum objectid: %m"); + return ret; + } + trans = NULL; + changed_leaves = 0; + } + if (!trans) { + trans = btrfs_start_transaction(csum_root, 1); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + errno = -ret; + error( + "failed to start transaction to change csum objectids: %m"); + return ret; + } + } ret = btrfs_search_slot(trans, csum_root, &last_key, &path, 0, 1); if (ret < 0) goto out; From patchwork Fri Jun 21 05:16:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13706845 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AD441369BB for ; Fri, 21 Jun 2024 05:17:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718947047; cv=none; b=mIAHrDdne6taSPyIHKHZegd3PRcCjiWW2lDb5UU3kFs1JAwSpWqeg1+7Ghkd2rR59BVAugcWiH+jMGVt/S8AZ9mGFmH2EQRRaFzFdU8X8MJcgltDoiZoqJifTuX2pploY7b5idFNxMaamCZR/1vA5kdaUEGD1bjOMc+5VoCXeug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718947047; c=relaxed/simple; bh=B45wM2FHxNLZE4fj6/kBPOgy7k1pLQ3vtxvY4CpVidk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=msCkw6E4ktfv/0G6FjZsPBGFPmEGPNi1+Aa8CVLD6G8ed6LjJu7LxYvmCrFMbEl63yTQ7Wp7AYfLGLK2s5SYU5BBHcQ4tlBm0Yptsr3H2jsTLBgvAYFjRwb20QDWkLR8GDoz/rZV3SunsrSH/gWr7sGdSIrhtgWnjIVAG3u7mY0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=qNm4jRyS; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=qNm4jRyS; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="qNm4jRyS"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="qNm4jRyS" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BDA5921AB6 for ; Fri, 21 Jun 2024 05:17:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1718947043; 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=6jw5xUZeGYpfF999dczFDMP5KGW6iKevnYsK3DhBF2g=; b=qNm4jRyS9YuAArxyDBOXr+RsWpeldn1NLQnFBFgWzPtWAD9xUL4hV7RGIA0FXKPxPEcl5y XbrOHco2u71yDJv8N0OR6mnukofokITEV+16gCINA5SUOS25sHLrVZNsLN3uhKth1MI3KI l86NOEnjy3wx25YPu8McJJIVUKzFBgM= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1718947043; 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=6jw5xUZeGYpfF999dczFDMP5KGW6iKevnYsK3DhBF2g=; b=qNm4jRyS9YuAArxyDBOXr+RsWpeldn1NLQnFBFgWzPtWAD9xUL4hV7RGIA0FXKPxPEcl5y XbrOHco2u71yDJv8N0OR6mnukofokITEV+16gCINA5SUOS25sHLrVZNsLN3uhKth1MI3KI l86NOEnjy3wx25YPu8McJJIVUKzFBgM= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C988713AAA for ; Fri, 21 Jun 2024 05:17:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 4JaCH+IMdWavbAAAD6G6ig (envelope-from ) for ; Fri, 21 Jun 2024 05:17:22 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 3/3] btrfs-progs: misc-tests: add a basic resume test using error injection Date: Fri, 21 Jun 2024 14:46:56 +0930 Message-ID: <470dda58291481fe01e53d904be3db6141ff93fb.1718946934.git.wqu@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Score: -2.79 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-2.79 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.19)[-0.972]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,imap1.dmz-prg2.suse.org:helo]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[linux-btrfs@vger.kernel.org]; RCVD_TLS_ALL(0.00)[] The new test case does: - Inject error at the very first commit transaction to make sure the injection is compiled in Furthermore check the stdout/stderr to make sure the failure is really caued by the error injection. - Inject error at the last commit transaction of new data csum generation - Resume the csum conversion and make sure it works Signed-off-by: Qu Wenruo --- .../065-csum-conversion-inject/test.sh | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 tests/misc-tests/065-csum-conversion-inject/test.sh diff --git a/tests/misc-tests/065-csum-conversion-inject/test.sh b/tests/misc-tests/065-csum-conversion-inject/test.sh new file mode 100755 index 000000000000..c213232ec545 --- /dev/null +++ b/tests/misc-tests/065-csum-conversion-inject/test.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# Verify the csum conversion can still resume after an interruption + +source "$TEST_TOP/common" || exit +source "$TEST_TOP/common.convert" || exit + +check_experimental_build +setup_root_helper +prepare_test_dev + +check_injection() +{ + local tmp_output=$(mktemp --tmpdir btrfs-progs-check-injection.XXXXXX) + local ret + + run_check_mkfs_test_dev --csum crc32c + + # This is for the very first transaction commit. + export INJECT="0x3964edd9" + "$TOP/btrfstune" --csum xxhash "$TEST_DEV" &> "$tmp_output" + ret=$? + cat "$tmp_output" >> "$RESULTS" + if [ "$ret" -eq 0 ]; then + _not_run "this test requires debug build with error injection" + fi + if ! grep -q "$INJECT" "$tmp_output"; then + rm "$tmp_output" + unset INJECT + _fail "csum conversion failed for unexpected reasons." + fi + rm "$tmp_output" + unset INJECT +} + +test_resume_data_csum_generation() +{ + local new_csum="$1" + + # Error at the end of the data csum generation. + export INJECT="0x4de02239" + run_mustfail "error injection not working" "$TOP/btrfstune" \ + --csum "$new_csum" "$TEST_DEV" + unset INJECT + run_check "$TOP/btrfstune" --csum "$new_csum" "$TEST_DEV" + run_check "$TOP/btrfs" check --check-data-csum "$TEST_DEV" +} + +check_injection + +run_check_mkfs_test_dev --csum crc32c + +# We only mount the filesystem once to populate its contents, later one we +# would never mount the fs (to reduce the dependency on kernel features). +run_check_mount_test_dev +populate_fs +run_check_umount_test_dev + +test_resume_data_csum_generation xxhash +test_resume_data_csum_generation blake2 +test_resume_data_csum_generation sha256 +test_resume_data_csum_generation crc32c