From patchwork Thu Jan 16 23:31:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13942660 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBA2C248BC5; Thu, 16 Jan 2025 23:31:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737070286; cv=none; b=sUYycudf7GeVKiHeLgKNMRJu9yQ4lltEMrMSC+qqj/sNMYjM2Kbt4gaT9Q6aKSLFkbRHVHh5izJo40rQQfA5uFTxoffNixl/bba9UJ0rmeCGx95/mmU2bXaKz/AjV95jwiZenWo7/sHXoVnfyqtPmoHOrleindAzyEaJ+p6Z+R0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737070286; c=relaxed/simple; bh=vY1gfLO5bZF2Cl00vzdm0c5onlHSrw/mq5Hnh/8rccw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZhmLjqgoaWURyVF04H5yDXWMMZWwObcluBHkedklCTTy5OxXFYenNxS0Ho6msf5vpjF6K46w13EQlwVfR3RxVIm3+/UrXXqKf/vpruE9wmZ0ZeLOtgnfrJXqjv4ozchh8QKnd6z2YFwkDSBCCLx7jYmGSrBpfE5lxQmmMpOuDpA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GeaF3Hxq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GeaF3Hxq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E71CC4CED6; Thu, 16 Jan 2025 23:31:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737070286; bh=vY1gfLO5bZF2Cl00vzdm0c5onlHSrw/mq5Hnh/8rccw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=GeaF3HxqeLai1Z3CsKs7kjPrmg6pG5DQOuE/xR6Uav3nee2eNjxxXRgcc2uHFipgU 1lJjSbzKHG3DScHi1FZd3NQJ3CuCqKabCT1hNtnNm35YCwvBhr2gyxta2Y4tZKkAFI +ObWrzVOuJFP6YZkU5p7WSeXStdoc9taUZtb5z2XjkSYTwPHQ9uHZ7DF895ieidzNK oHh7UhQ8LpQizNcnBBZ5QUE2fOlu52NKiu0UXQtR5tWaDNFSG4O2USl2wD3Mo1cC4/ PZVVKS8kvcJuKA8sbi+yBMrJ81UHV6gsf62asvtp+oiBQs3bEZx2NZD/eoPC6dbGpw NPQIr4q5keolw== Date: Thu, 16 Jan 2025 15:31:25 -0800 Subject: [PATCH 1/3] logwrites: warn if we don't think read after discard returns zeroes From: "Darrick J. Wong" To: zlang@redhat.com, djwong@kernel.org Cc: hch@lst.de, fstests@vger.kernel.org, linux-xfs@vger.kernel.org Message-ID: <173706974749.1928123.12633707385824957220.stgit@frogsfrogsfrogs> In-Reply-To: <173706974730.1928123.3781657849818195379.stgit@frogsfrogsfrogs> References: <173706974730.1928123.3781657849818195379.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong The logwrites replay program expects that it can issue a DISCARD against the block device passed to _log_writes_init and that will cause all subsequent reads to return zeroes. This is required for correct log recovery on filesystems such as XFS that skip recovering buffers if newer ones are found on disk. Unfortunately, there's no way to discover if a device's discard implementation actually guarantees zeroes. There used to be a sysfs knob keyed to an allowlist, but it is now hardwired to return 0. So either we need a magic device that does discard-and-zero, or we need to do the zeroing ourselves. The logwrites program does its own zeroing if there is no discard support, and some tests do their own zeroing. The only devices we know to work reliably are the software defined ones that are provided by the kernel itself -- which means dm-thinp. Warn if we have a device that supports discard that isn't thinp and the test fails. Signed-off-by: "Darrick J. Wong" --- common/dmlogwrites | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/common/dmlogwrites b/common/dmlogwrites index a27e1966a933a6..96101d53c38b4a 100644 --- a/common/dmlogwrites +++ b/common/dmlogwrites @@ -59,6 +59,35 @@ _require_log_writes_dax_mountopt() fi } +_log_writes_check_bdev() +{ + local sysfs="/sys/block/$(_short_dev $1)" + + # Some filesystems (e.g. XFS) optimize log recovery by assuming that + # they can elide replay of metadata blocks if the block has a higher + # log serial number than the transaction being recovered. This is a + # problem if the filesystem log contents can go back in time, which is + # what the logwrites replay program does. + # + # The logwrites replay program begins by erasing the block device's + # contents. This can be done very quickly with DISCARD provided the + # device guarantees that all reads after a DISCARD return zeroes, or + # very slowly by writing zeroes to the device. Fast is preferable, but + # there's no longer any way to detect that DISCARD actually unmaps + # zeroes, so warn the user about this requirement if the test happens + # to fail. + + # No discard support means the logwrites will do its own zeroing + test "$(cat "$sysfs/queue/discard_max_bytes")" -eq 0 && return + + # dm-thinp guarantees that reads after discards return zeroes + dmsetup status "$blkdev" 2>/dev/null | grep -q '^0.* thin ' && return + + echo "HINT: $blkdev doesn't guarantee that reads after DISCARD will return zeroes" >> $seqres.hints + echo " This is required for correct journal replay on some filesystems (e.g. xfs)" >> $seqres.hints + echo >> $seqres.hints +} + # Set up a dm-log-writes device # # blkdev: the specified target device @@ -84,6 +113,8 @@ _log_writes_init() LOGWRITES_NAME=logwrites-test LOGWRITES_DMDEV=/dev/mapper/$LOGWRITES_NAME LOGWRITES_TABLE="0 $BLK_DEV_SIZE log-writes $blkdev $LOGWRITES_DEV" + + _log_writes_check_bdev "$blkdev" _dmsetup_create $LOGWRITES_NAME --table "$LOGWRITES_TABLE" || \ _fail "failed to create log-writes device" } From patchwork Thu Jan 16 23:31:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13942661 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D54951F1502; Thu, 16 Jan 2025 23:31:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737070301; cv=none; b=IHzY8MMze1/vfhI1JEsv+C7lweMPk6oYCm6+NYDS3Cbxyx0+ZV+MYnymN9pgj2UH5rLIa1712bcmJsS7qcaMcitvMcGyOJzc/yVsWbg2HCoCa+pICvmkEqmuWaC9p67tc27PKW7f3xNeI7klh+UjNz/c3O3Q+Ijw4IvVnP76P90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737070301; c=relaxed/simple; bh=1b3WRsNnivAxyi55OjZu3eEOrtb0Id4ruAwv8YsLp24=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bEO97EorrxNskD/fTlHT/RQ0zv/8XqS8qlOS3RBV3rtPRRgsKJcSmXpJR6OoBcRexJVPz90OO3lyfxSd0vEmv9LeT2qUWVXG1M4FabsPAuheuTw5d1LkHEWaAG3VyqPvs68UTNB82C75EH1UiR3US6VADjMj48OpPUS3B20nHOA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mKZpWbzH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mKZpWbzH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8BBCC4CED6; Thu, 16 Jan 2025 23:31:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737070301; bh=1b3WRsNnivAxyi55OjZu3eEOrtb0Id4ruAwv8YsLp24=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=mKZpWbzHpLEp9xeJWW1jsH4lib5BmrkzBCUXDsYrp8JeZd3NEwmBg4TlmG5a7V7kb 8lgpLunatj7vl57MvdBCY1tydPQx2+SfmmAQGei5Fxky6QzMfU4sU0razKMfJViCkz JyDTdP//1jHt4zSNdWNEnSrGa4/5bBkqlbazAGeItg5Vq56H3dY/XdEUmj/KJEU1tm Itu/PM5PzLBdN4+HWd6i8G9hhGdDA/chr0z62KmW8sOC1/ZhnA1ccypFsIsGN7j0xq DgknJX3A7YgvBKsbC+sd3JSOfsrtyBVmOQ7U1cfZK1v8oaHvSPj22rMcUMO+hTPhi0 RC/uDyHTOdmCQ== Date: Thu, 16 Jan 2025 15:31:41 -0800 Subject: [PATCH 2/3] logwrites: use BLKZEROOUT if it's available From: "Darrick J. Wong" To: zlang@redhat.com, djwong@kernel.org Cc: hch@lst.de, fstests@vger.kernel.org, linux-xfs@vger.kernel.org Message-ID: <173706974764.1928123.15642624942297043790.stgit@frogsfrogsfrogs> In-Reply-To: <173706974730.1928123.3781657849818195379.stgit@frogsfrogsfrogs> References: <173706974730.1928123.3781657849818195379.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Use the BLKZEROOUT ioctl instead of writing zeroed buffers if the kernel supports it. Signed-off-by: "Darrick J. Wong" --- src/log-writes/log-writes.c | 10 ++++++++++ src/log-writes/log-writes.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/log-writes/log-writes.c b/src/log-writes/log-writes.c index aa53473974d9e8..8f94ae5629e085 100644 --- a/src/log-writes/log-writes.c +++ b/src/log-writes/log-writes.c @@ -42,6 +42,7 @@ static int discard_range(struct log *log, u64 start, u64 len) static int zero_range(struct log *log, u64 start, u64 len) { + u64 range[2] = { start, len }; u64 bufsize = len; ssize_t ret; char *buf = NULL; @@ -54,6 +55,15 @@ static int zero_range(struct log *log, u64 start, u64 len) return 0; } + if (!(log->flags & LOG_ZEROOUT_NOT_SUPP)) { + if (ioctl(log->replayfd, BLKZEROOUT, &range) < 0) { + if (log_writes_verbose) + printf( + "replay device doesn't support zeroout, switching to writing zeros\n"); + log->flags |= LOG_ZEROOUT_NOT_SUPP; + } + } + while (!buf) { buf = malloc(bufsize); if (!buf) diff --git a/src/log-writes/log-writes.h b/src/log-writes/log-writes.h index b9f571ac3b2384..f659931634e64a 100644 --- a/src/log-writes/log-writes.h +++ b/src/log-writes/log-writes.h @@ -63,6 +63,7 @@ struct log_write_entry { #define LOG_IGNORE_DISCARD (1 << 0) #define LOG_DISCARD_NOT_SUPP (1 << 1) +#define LOG_ZEROOUT_NOT_SUPP (1 << 2) struct log { int logfd; From patchwork Thu Jan 16 23:31:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13942662 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB0D31F1504; Thu, 16 Jan 2025 23:31:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737070318; cv=none; b=Oex6ju688f6+Tveja4a8GhL1xmN3iv3PQic7aYZuahb9OxHGBJKH0rtYdtskt2rIPyu1FTWgBK8zmfYAzQz4f9+JHDAaAl/lBV3/Sg0G6enf/PIV+rr72gPKPdar6OqFzFwx5XQLSFbteGwbu75uMRfsZyUQjVEfSSD/CsLhBko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737070318; c=relaxed/simple; bh=TsSMnjKtE+SIRtkHK/xoJs0IUyUvd3znhcLf9lWRSY0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ic13BXvhmSBUqJgcsSIb6XMhaf3Amv58ggxnqHgLf10ssdvMYuJceJ6BGf6DfHKqyQPQ/+JlU95bxX8adSU0Vt0Xk7B/OYu/qJkeZzdiUexg78IJqXtjja32igWTPs5hd6i40JiCG0F79Tf3US9P7RTeTGwt6aLtM3y+a06k76k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ItmYSmff; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ItmYSmff" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5070AC4CED6; Thu, 16 Jan 2025 23:31:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737070317; bh=TsSMnjKtE+SIRtkHK/xoJs0IUyUvd3znhcLf9lWRSY0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ItmYSmff9bbDPOcSFog0K7t1rg8OoRpt0K+zkHJmaLU+levQhs0Njp3Z98/MxXXJ7 +NQuwkO9dhO0c/fnA9OjGPJaq5gjYQhZoPNdgvyqTEqIjb/P/O6RD8zumBPLxGiMXx qdgUU8GiWc+T0h6asnM1KxrcBDZ4yJd3nZ5OUAfhVpdOOj5UZE14cnkk+cH/TZ89pR Ezu0SULtwAep6cZ1UVuO+I6fkkG4gcDLujp7JR0o0tc25KO/TqhE3FtaJ0i6+cgiep 9LMVs8dD58gCpuX5kesgH24fwtkNyFgO0Vi24FJCqhQTOgfbGDfNqm93JR77OhmvBj kRoZIQ9+/We2w== Date: Thu, 16 Jan 2025 15:31:56 -0800 Subject: [PATCH 3/3] logwrites: only use BLKDISCARD if we know discard zeroes data From: "Darrick J. Wong" To: zlang@redhat.com, djwong@kernel.org Cc: hch@lst.de, fstests@vger.kernel.org, linux-xfs@vger.kernel.org Message-ID: <173706974778.1928123.15171471070777684986.stgit@frogsfrogsfrogs> In-Reply-To: <173706974730.1928123.3781657849818195379.stgit@frogsfrogsfrogs> References: <173706974730.1928123.3781657849818195379.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Building off the checks established in the previous patch, only enable the use of BLKDISCARD if we know that the logwrites device guarantees that reads after a discard return zeroes. Signed-off-by: "Darrick J. Wong" --- common/dmlogwrites | 10 ++++++++-- src/log-writes/replay-log.c | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/common/dmlogwrites b/common/dmlogwrites index 96101d53c38b4a..fbc8beb5ce597e 100644 --- a/common/dmlogwrites +++ b/common/dmlogwrites @@ -81,7 +81,10 @@ _log_writes_check_bdev() test "$(cat "$sysfs/queue/discard_max_bytes")" -eq 0 && return # dm-thinp guarantees that reads after discards return zeroes - dmsetup status "$blkdev" 2>/dev/null | grep -q '^0.* thin ' && return + if dmsetup status "$blkdev" 2>/dev/null | grep -q '^0.* thin '; then + LOGWRITES_REPLAY_ARGS+=(--discard-zeroes-data) + return + fi echo "HINT: $blkdev doesn't guarantee that reads after DISCARD will return zeroes" >> $seqres.hints echo " This is required for correct journal replay on some filesystems (e.g. xfs)" >> $seqres.hints @@ -110,6 +113,7 @@ _log_writes_init() BLK_DEV_SIZE=$((length / blksz)) fi + LOGWRITES_REPLAY_ARGS=() LOGWRITES_NAME=logwrites-test LOGWRITES_DMDEV=/dev/mapper/$LOGWRITES_NAME LOGWRITES_TABLE="0 $BLK_DEV_SIZE log-writes $blkdev $LOGWRITES_DEV" @@ -161,7 +165,8 @@ _log_writes_replay_log() [ $? -ne 0 ] && _fail "mark '$_mark' does not exist" $here/src/log-writes/replay-log --log $LOGWRITES_DEV --replay $_blkdev \ - --end-mark $_mark >> $seqres.full 2>&1 + --end-mark $_mark "${LOGWRITES_REPLAY_ARGS[@]}" \ + >> $seqres.full 2>&1 [ $? -ne 0 ] && _fail "replay failed" } @@ -231,6 +236,7 @@ _log_writes_replay_log_range() echo "=== replay to $end ===" >> $seqres.full $here/src/log-writes/replay-log -vv --log $LOGWRITES_DEV \ --replay $blkdev --limit $(($end + 1)) \ + "${LOGWRITES_REPLAY_ARGS[@]}" \ >> $seqres.full 2>&1 [ $? -ne 0 ] && _fail "replay failed" } diff --git a/src/log-writes/replay-log.c b/src/log-writes/replay-log.c index 968c82ab64a9ad..e07401f63af573 100644 --- a/src/log-writes/replay-log.c +++ b/src/log-writes/replay-log.c @@ -18,6 +18,7 @@ enum option_indexes { FIND, NUM_ENTRIES, NO_DISCARD, + DISCARD_ZEROES_DATA, FSCK, CHECK, START_MARK, @@ -37,6 +38,7 @@ static struct option long_options[] = { {"find", no_argument, NULL, 0}, {"num-entries", no_argument, NULL, 0}, {"no-discard", no_argument, NULL, 0}, + {"discard-zeroes-data", no_argument, NULL, 0}, {"fsck", required_argument, NULL, 0}, {"check", required_argument, NULL, 0}, {"start-mark", required_argument, NULL, 0}, @@ -155,6 +157,7 @@ int main(int argc, char **argv) int ret; int print_num_entries = 0; int discard = 1; + int use_kernel_discard = 0; enum log_replay_check_mode check_mode = 0; while ((c = getopt_long(argc, argv, "v", long_options, @@ -242,6 +245,9 @@ int main(int argc, char **argv) case NO_DISCARD: discard = 0; break; + case DISCARD_ZEROES_DATA: + use_kernel_discard = 1; + break; case FSCK: fsck_command = strdup(optarg); if (!fsck_command) { @@ -299,6 +305,8 @@ int main(int argc, char **argv) if (!discard) log->flags |= LOG_IGNORE_DISCARD; + if (!use_kernel_discard) + log->flags |= LOG_DISCARD_NOT_SUPP; log->start_sector = start_sector; log->end_sector = end_sector;