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