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

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