From patchwork Tue Jun 25 05:07:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13710615 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 29E92143899 for ; Tue, 25 Jun 2024 05:07:56 +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=1719292079; cv=none; b=Rf3OC3i+R7stNN20LehwQWLeMnCyOXiwHw4tfDTaEk9wWDKJ9x7g7TaXUioabQl8woUQJ3s8X9xP0Idcacazv0TS4SCChLhp8wTAoaI8RGia5F/dfxLBajiaz98EZ79sB5Ipi5h3tT+kx7sOLimnn/yyEdalUWdSj64sIjmctoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719292079; c=relaxed/simple; bh=JUMmICTKSnT55CY314nWWuzM7owJJOTmgmyL2CiGjU0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZP34lTee8gY0tF+IUDOGMwgzseIjqZpQOLo8KRuX9PdljST1Wkcx/Pn9a6LxCTu02rePFA6euAbFUgk6VlhItY5JJoRsAp0ghDgUqK5op46ClIVJOnq7XWirDUOqUG7ua/fUFlsonNWFb1VPzC5ye6PwGkQiLv5aYRBUoBUoYgw= 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=oERYA5JN; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=oERYA5JN; 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="oERYA5JN"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="oERYA5JN" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 3D2CF1F844 for ; Tue, 25 Jun 2024 05:07:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1719292075; 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=Jd3cirDEkMvD+UZByMmRvY/lzsscOiHNbzdY/cdYEMo=; b=oERYA5JNhRdSKbJXOScVn/qC8g2VL3jZN3Pm+m0RoeC5Lw7Kw/LIURHEhJ5BIE/9nwWGDq pVxGWxC+an9GoqiqWJr+f3/qG4A7rEdL3yjP9PLZ7DxnoHDv+5clm/IvMlKdTo4JfnE3Pr QN6Eff8eDnHmAtDh6QN956isH5CSCvM= Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=oERYA5JN DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1719292075; 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=Jd3cirDEkMvD+UZByMmRvY/lzsscOiHNbzdY/cdYEMo=; b=oERYA5JNhRdSKbJXOScVn/qC8g2VL3jZN3Pm+m0RoeC5Lw7Kw/LIURHEhJ5BIE/9nwWGDq pVxGWxC+an9GoqiqWJr+f3/qG4A7rEdL3yjP9PLZ7DxnoHDv+5clm/IvMlKdTo4JfnE3Pr QN6Eff8eDnHmAtDh6QN956isH5CSCvM= 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 574971384C for ; Tue, 25 Jun 2024 05:07:54 +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 aB0DBKpQembqdgAAD6G6ig (envelope-from ) for ; Tue, 25 Jun 2024 05:07:54 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/4] btrfs: cleanup the bytenr usage inside btrfs_extent_item_to_extent_map() Date: Tue, 25 Jun 2024 14:37:27 +0930 Message-ID: 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 [-3.01 / 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)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.com:email,suse.com:dkim]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:106:10:150:64:167:received]; PREVIOUSLY_DELIVERED(0.00)[linux-btrfs@vger.kernel.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCVD_TLS_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: 3D2CF1F844 X-Spam-Flag: NO X-Spam-Score: -3.01 X-Spam-Level: [PROBLEMS] Before commit 85de2be7129c ("btrfs: remove extent_map::block_start member"), we utilized @bytenr variable inside btrfs_extent_item_to_extent_map() to calculate block_start. But that commit removed block_start completely, we have no need to advance @bytenr at all. Furthermore with recent enhanced btrfs-progs check for ram_bytes mimsatch, it turns out that for truncated ordered extents, their ram_bytes can be smaller than disk_num_bytes. [ENHANCEMENT] Thankfully all above problems are not really going to affect end users, fix them by: - Declare @bytenr only inside the if branch and make it const So we can remove the unnecessary advance of @bytenr. - Manually override extent_map::ram_bytes using disk_num_bytes This is for non-compressed regular/preallocated extents. Signed-off-by: Qu Wenruo --- fs/btrfs/file-item.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 55703c833f3d..2cc61c792ee6 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -1281,7 +1281,6 @@ void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode, const int slot = path->slots[0]; struct btrfs_key key; u64 extent_start; - u64 bytenr; u8 type = btrfs_file_extent_type(leaf, fi); int compress_type = btrfs_file_extent_compression(leaf, fi); @@ -1291,22 +1290,22 @@ void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode, em->generation = btrfs_file_extent_generation(leaf, fi); if (type == BTRFS_FILE_EXTENT_REG || type == BTRFS_FILE_EXTENT_PREALLOC) { + const u64 disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi); + em->start = extent_start; em->len = btrfs_file_extent_end(path) - extent_start; - bytenr = btrfs_file_extent_disk_bytenr(leaf, fi); - if (bytenr == 0) { + if (disk_bytenr == 0) { em->disk_bytenr = EXTENT_MAP_HOLE; em->disk_num_bytes = 0; em->offset = 0; return; } - em->disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi); + em->disk_bytenr = disk_bytenr; em->disk_num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi); em->offset = btrfs_file_extent_offset(leaf, fi); if (compress_type != BTRFS_COMPRESS_NONE) { extent_map_set_compression(em, compress_type); } else { - bytenr += btrfs_file_extent_offset(leaf, fi); if (type == BTRFS_FILE_EXTENT_PREALLOC) em->flags |= EXTENT_FLAG_PREALLOC; } From patchwork Tue Jun 25 05:07:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13710617 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 F2FBF144306 for ; Tue, 25 Jun 2024 05:08:04 +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=1719292086; cv=none; b=pyP6TEu12ekHO4kE8kZVdc0z1PXOl4BzBTneAz1mEse63URbGdIkF80lqTakeCtJG4Sq2udGmoxZN7ktHojzirE7TdNUefVBpWD3+H+5LOfAVmwF2C106bhGgYZrFzrgZZvZZQOStcdG6fHXxO75oW3b8B/vOabgULr31kthg9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719292086; c=relaxed/simple; bh=0nyyD4dEOuOYtk1bDJrbYw1XaxBHlJBL8IIsi5b8+cQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HL+0NQVBcHtk771eokN6zhAnUiDHbA0m55BjEQNmY4j1vukZN1nfYloHaSYdLGfQAnEsO8KPW51ASHCM/RweVipo2DxbYcSaiPTwW9cBZgxR/L6b/6Xe1Xjc07MrtPZe164xJAdMigQ9CWAwq9Ke4CiY5fb2ql7qYb5aIM55P08= 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=balI8U4G; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=balI8U4G; 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="balI8U4G"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="balI8U4G" 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 ACA9321A28 for ; Tue, 25 Jun 2024 05:07:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1719292076; 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=Vaq4dpnMgMxzG0nAxzlJh0vZzkQmVbgP5ufPN0PjRN8=; b=balI8U4GtbpeHUWr3/1Zmi8PgyNKb3ilmO1EDsTdx3L7eLu1WowLnaeFjIpHpjldHAHV/t mFsYfBtFzerblwtyFbT+7bHEe5ETtMOlk+Ed4n1EMCNdCLWeay/R5el1yqYwuC4eIVQBa3 0X6TVrmccn3uFTTSn2qg2MZ+QeJ5cr0= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1719292076; 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=Vaq4dpnMgMxzG0nAxzlJh0vZzkQmVbgP5ufPN0PjRN8=; b=balI8U4GtbpeHUWr3/1Zmi8PgyNKb3ilmO1EDsTdx3L7eLu1WowLnaeFjIpHpjldHAHV/t mFsYfBtFzerblwtyFbT+7bHEe5ETtMOlk+Ed4n1EMCNdCLWeay/R5el1yqYwuC4eIVQBa3 0X6TVrmccn3uFTTSn2qg2MZ+QeJ5cr0= 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 C6EEC1384C for ; Tue, 25 Jun 2024 05:07:55 +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 QFs2H6tQembqdgAAD6G6ig (envelope-from ) for ; Tue, 25 Jun 2024 05:07:55 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/4] btrfs: make validate_extent_map() to catch ram_bytes mismatch Date: Tue, 25 Jun 2024 14:37:28 +0930 Message-ID: <8ae9d9cbfce4a3c1d21a413d5072694b1814aad1.1719291793.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.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; 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.80 X-Spam-Level: Previously validate_extent_map() is only to catch bugs related to extent_map member cleanups. But with recent btrfs-check enhancement to catch ram_bytes mismatch with disk_num_bytes, it would be much better to catch such extent maps earlier. So this patch would add extra ram_bytes validation for extent maps. Please note that, older filesystems with such mismatch won't trigger this error: - extent_map::ram_bytes is already fixed when reading from disk At btrfs_extent_item_to_extent_map() we override extent_map::ram_bytes to disk_num_bytes for non-compressed regular/preallocated extents. So this enhanced sanity checks should not affect end users. Signed-off-by: Qu Wenruo --- fs/btrfs/extent_map.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index b869a0ee24d2..6961cc73fe3f 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c @@ -317,6 +317,11 @@ static void validate_extent_map(struct btrfs_fs_info *fs_info, struct extent_map if (em->offset + em->len > em->disk_num_bytes && !extent_map_is_compressed(em)) dump_extent_map(fs_info, "disk_num_bytes too small", em); + if (!extent_map_is_compressed(em) && + em->ram_bytes != em->disk_num_bytes) + dump_extent_map(fs_info, + "ram_bytes mismatch with disk_num_bytes for non-compressed em", + em); } else if (em->offset) { dump_extent_map(fs_info, "non-zero offset for hole/inline", em); } From patchwork Tue Jun 25 05:07:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13710618 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 BD4D2143890 for ; Tue, 25 Jun 2024 05:08:05 +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=1719292087; cv=none; b=FwR3/ojzw3f7nEkvVk9vCTr45yTgYXLp4AeeELvT6/o6uw2qUoz7t3NxjsS3oPWSi5/3wRZHax9pQCL6d8v3kdVsyKdbT0Zv9B+Js/ewDYZzajfBVkgxN/raORi14tW2nYxZq5EyHObnCjxSGrRN9s3c459+rd0VCRQQu3ZZ3bw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719292087; c=relaxed/simple; bh=MsXfub5zhmU5wQKzQO19fvSw5awOSW9jNG1nd8jscS0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gXWrutpc1+70X6+qJsn8SHw1+j9/6mvFwDr4btDNqkzY6vCwpXIV2ZDbTHjk63wgaXP7I0/gbK+61Qw+4DP0aMQC5new5XerG8JbdsjPBPgqDayYeFQNYgw5/+9pCrJtCEXmwgijEdYx7ZBtNG1c9KsNqx2ZyOWaJFnGWQvsg+k= 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=jpOmgBrq; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=jpOmgBrq; 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="jpOmgBrq"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="jpOmgBrq" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 26D04219A0 for ; Tue, 25 Jun 2024 05:07:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1719292078; 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=8GT6Z73B/0OpuFH1c08BhUqpfsJDHBPKnDQHVFws/m4=; b=jpOmgBrqtBPD3u6cVvGcUHMwPbQXIGczYWUInTOY17g7Ag1suXoxjcZM7TywGQ8wWaPzgH lp69rXqLGMuiPgGbnQyr68YSqDTxBTwzJ9sbEuk5/VvVoBJQ328me9eL+Yr/kgLE3IR2IU MvMdct4yKVrycflJa4xZyrnwKLx63hw= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=jpOmgBrq DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1719292078; 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=8GT6Z73B/0OpuFH1c08BhUqpfsJDHBPKnDQHVFws/m4=; b=jpOmgBrqtBPD3u6cVvGcUHMwPbQXIGczYWUInTOY17g7Ag1suXoxjcZM7TywGQ8wWaPzgH lp69rXqLGMuiPgGbnQyr68YSqDTxBTwzJ9sbEuk5/VvVoBJQ328me9eL+Yr/kgLE3IR2IU MvMdct4yKVrycflJa4xZyrnwKLx63hw= 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 4160E1384C for ; Tue, 25 Jun 2024 05:07:56 +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 qClOOqxQembqdgAAD6G6ig (envelope-from ) for ; Tue, 25 Jun 2024 05:07:56 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/4] btrfs: fix the ram_bytes assignment for truncated ordered extents Date: Tue, 25 Jun 2024 14:37:29 +0930 Message-ID: <0bd7715ef04abbfca4b97137b5b197333f2eb227.1719291793.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 [-3.01 / 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)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.com:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:106:10:150:64:167:received]; PREVIOUSLY_DELIVERED(0.00)[linux-btrfs@vger.kernel.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCVD_TLS_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: 26D04219A0 X-Spam-Flag: NO X-Spam-Score: -3.01 X-Spam-Level: [BUG] After adding extra checks on btrfs_file_extent_item::ram_bytes to tree-checker, running fsstress with multiple threads can lead to tree-checker warning at write time, as we created file extent items with ram_bytes. All those offending file extents have offset 0, and ram_bytes matching num_bytes, and smaller than disk_num_bytes. This would also trigger the recently enhanced btrfs-check, which would catch such mismatch and report them as minor errors. [CAUSE] When a folio/page is invalidated and it is part of a submitted OE, we mark the OE truncated just to the beginning of the folio/page. And for truncated OE, we insert the file extent item with incorrect value for ram_bytes (using num_bytes instead of the usual value). This is not a big deal for end users, as we do not utilize the ram_bytes field for regular non-compressed extents. This mismatch is just a small violation against on-disk format. [FIX] Fix it by removing the override on btrfs_file_extent_item::ram_bytes. Signed-off-by: Qu Wenruo Reviewed-by: Filipe Manana --- fs/btrfs/inode.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index d6c43120c5d3..45f77ae8963f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3018,10 +3018,8 @@ static int insert_ordered_extent_file_extent(struct btrfs_trans_handle *trans, btrfs_set_stack_file_extent_disk_num_bytes(&stack_fi, oe->disk_num_bytes); btrfs_set_stack_file_extent_offset(&stack_fi, oe->offset); - if (test_bit(BTRFS_ORDERED_TRUNCATED, &oe->flags)) { + if (test_bit(BTRFS_ORDERED_TRUNCATED, &oe->flags)) num_bytes = oe->truncated_len; - ram_bytes = num_bytes; - } btrfs_set_stack_file_extent_num_bytes(&stack_fi, num_bytes); btrfs_set_stack_file_extent_ram_bytes(&stack_fi, ram_bytes); btrfs_set_stack_file_extent_compression(&stack_fi, oe->compress_type); From patchwork Tue Jun 25 05:07:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13710616 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 E0C9F1442FD for ; Tue, 25 Jun 2024 05:08:03 +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=1719292085; cv=none; b=m8jenQZ0vUbAu3VlzS5OkYU+SznPA+BZp6yZxCRVSPS1G4lRM8UF4KdNqeStBp/ZfXRMNvnGbePsCMZwD6VBUcwyjzQP71WqCSZl4oyLmjBMRxh0ytqBJi3+cXVXlXl3/YMNSn2PAWTuSIfVQzxq5APhvZhqOB+mHFOOVo4m+qU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719292085; c=relaxed/simple; bh=i4iE9i6insNomRMpTZdw22lqaWT/4gPrXSLkyw4GjkM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Peic9iUNsyesHsO4bcOoAB+kE3PnJnBIfeIJ7tFYZmOkoKJUpne9yzGQFnTcReFmhyffIM7rp6MKSh4DqnnM0WnLiUVWmxGvu0pVOalKlI9MsO4/PGoZ3f9yCG1Fh5735GLENeMpsiQlSZIU8HznKNhm/EBjtmFqhEIvuaw3w64= 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=h2ddFoxL; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=eIDvX2xU; 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="h2ddFoxL"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="eIDvX2xU" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 D0BD31F844 for ; Tue, 25 Jun 2024 05:08:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1719292082; 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=H/JgymkJZYfnB/W/oe5lw1OdWA4qZNWoe9SGXOaM3Ac=; b=h2ddFoxL5RcNlnVBHmfx9ABnlec0qAxbmOIIAAsliHcdc91LyQhGAkrlyO2lR4B3m0X5yH pVbnjcOHnTnHRiynnZUXe/XuuomNmJRF3qvwA3MDlBuTwVCPcH+maRmI84TFxPfUGkcDa4 bOlpe4okKtbuSORCwJ5bhZkip/ZvDoM= Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=eIDvX2xU DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1719292081; 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=H/JgymkJZYfnB/W/oe5lw1OdWA4qZNWoe9SGXOaM3Ac=; b=eIDvX2xU24Vt15HfLTzooWf02fH21mD4uSvVzFFQjden9EdbYOtDWWgw8ooeSWq76GKxIk WGK8f7dUHTYjbJcu3OeBGCprLTMcLmGXxJW5PtoFn47QeBzymNPlouSd4Z3AH95LdnSV3x nwBEy5uKW1Xtvs+ErU2BAquoJbXNguY= 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 425591384C for ; Tue, 25 Jun 2024 05:07:58 +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 OMO4Ga5QembqdgAAD6G6ig (envelope-from ) for ; Tue, 25 Jun 2024 05:07:58 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/4] btrfs: tree-checker: add extra ram_bytes and disk_num_bytes check Date: Tue, 25 Jun 2024 14:37:30 +0930 Message-ID: <75a7f80c92184ced08a904dc3ce0d43518d399a5.1719291793.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-Rspamd-Queue-Id: D0BD31F844 X-Spam-Score: -3.01 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-3.01 / 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)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.com:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:106:10:150:64:167:received]; PREVIOUSLY_DELIVERED(0.00)[linux-btrfs@vger.kernel.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCVD_TLS_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org This is to ensure non-compressed file extents (both regular and prealloc) should have matching ram_bytes and disk_num_bytes. This is only for CONFIG_BTRFS_DEBUG and CONFIG_BTRFS_ASSERT case, furthermore this will not return error, but just a kernel warning to inform developers. Signed-off-by: Qu Wenruo --- fs/btrfs/tree-checker.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index a2c3651a3d8f..cddabd9a0e37 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -340,6 +340,25 @@ static int check_extent_data_item(struct extent_buffer *leaf, } } + /* + * For non-compressed data extents, ram_bytes should match its disk_bytenr. + * However we do not really utilize ram_bytes in this case, so this check + * is only optional for DEBUG+ASSERT builds for developers to catch the + * unexpected behaviors. + */ + if (IS_ENABLED(CONFIG_BTRFS_DEBUG) && IS_ENABLED(CONFIG_BTRFS_ASSERT) && + btrfs_file_extent_compression(leaf, fi) == BTRFS_COMPRESS_NONE && + btrfs_file_extent_disk_bytenr(leaf, fi)) { + if (unlikely(btrfs_file_extent_ram_bytes(leaf, fi) != + btrfs_file_extent_disk_num_bytes(leaf, fi))) { + file_extent_err(leaf, slot, +"mismatch ram_bytes (%llu) and disk_num_bytes (%llu) for non-compressed extent", + btrfs_file_extent_ram_bytes(leaf, fi), + btrfs_file_extent_disk_num_bytes(leaf, fi)); + WARN_ON(1); + } + } + return 0; }