Blame SOURCES/e2fsprogs-1.45.6-mke2fs-only-try-discarding-a-single-block-to-test-if.patch

a77133
From 2831f4202dd1bec289a9a3459d553fcffda0f280 Mon Sep 17 00:00:00 2001
a77133
From: Theodore Ts'o <tytso@mit.edu>
a77133
Date: Sun, 18 Jul 2021 09:15:28 -0400
a77133
Subject: [PATCH 34/46] mke2fs: only try discarding a single block to test if
a77133
 discard works
a77133
Content-Type: text/plain
a77133
a77133
Commit d2bfdc7ff15c ("Use punch hole as "discard" on regular files")
a77133
added a test to see if the storage device actually supports discard.
a77133
The intent was to try discarding the first block but since
a77133
io_channel_discard() interprets the offset and count arguments in
a77133
blocks, and not bytes, mke2fs was actually discarding the first 16
a77133
megabytes (when the block size is 4k).  This is normally not a
a77133
problem, since most file systems are larger than that, and requests to
a77133
discard beyond the end of the block device are ignored.
a77133
a77133
However, when creating a small file system as part of a image
a77133
containing multiple partitions, the initial test discard can end up
a77133
discarding data beyond the file system being created.
a77133
a77133
Addresses-Debian-Bug: #989630
a77133
Reported-by: Josh Triplett <josh@joshtriplett.org>
a77133
Fixes: d2bfdc7ff15c ("Use punch hole as "discard" on regular files")
a77133
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
a77133
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
a77133
---
a77133
 misc/mke2fs.c | 5 ++---
a77133
 1 file changed, 2 insertions(+), 3 deletions(-)
a77133
a77133
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
a77133
index 389d0981..b2bb2847 100644
a77133
--- a/misc/mke2fs.c
a77133
+++ b/misc/mke2fs.c
a77133
@@ -2768,7 +2768,7 @@ static int mke2fs_discard_device(ext2_filsys fs)
a77133
 	struct ext2fs_numeric_progress_struct progress;
a77133
 	blk64_t blocks = ext2fs_blocks_count(fs->super);
a77133
 	blk64_t count = DISCARD_STEP_MB;
a77133
-	blk64_t cur;
a77133
+	blk64_t cur = 0;
a77133
 	int retval = 0;
a77133
 
a77133
 	/*
a77133
@@ -2776,10 +2776,9 @@ static int mke2fs_discard_device(ext2_filsys fs)
a77133
 	 * we do not print numeric progress resulting in failure
a77133
 	 * afterwards.
a77133
 	 */
a77133
-	retval = io_channel_discard(fs->io, 0, fs->blocksize);
a77133
+	retval = io_channel_discard(fs->io, 0, 1);
a77133
 	if (retval)
a77133
 		return retval;
a77133
-	cur = fs->blocksize;
a77133
 
a77133
 	count *= (1024 * 1024);
a77133
 	count /= fs->blocksize;
a77133
-- 
a77133
2.35.1
a77133