aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2021-07-18 09:15:28 -0400
committerTheodore Ts'o <tytso@mit.edu>2021-07-18 11:05:20 -0400
commit6568ba325e54a2ae1d2617c5175936c819ab4c8c (patch)
treef773d23fe9791f6828a4c8b6f607894005524f95
parentd0b6b64f62eff5c7545be8b71adf6fd537613a90 (diff)
downloade2fsprogs-6568ba325e54a2ae1d2617c5175936c819ab4c8c.tar.gz
mke2fs: only try discarding a single block to test if discard works
Commit d2bfdc7ff15c ("Use punch hole as "discard" on regular files") added a test to see if the storage device actually supports discard. The intent was to try discarding the first block but since io_channel_discard() interprets the offset and count arguments in blocks, and not bytes, mke2fs was actually discarding the first 16 megabytes (when the block size is 4k). This is normally not a problem, since most file systems are larger than that, and requests to discard beyond the end of the block device are ignored. However, when creating a small file system as part of a image containing multiple partitions, the initial test discard can end up discarding data beyond the file system being created. Addresses-Debian-Bug: #989630 Reported-by: Josh Triplett <josh@joshtriplett.org> Fixes: d2bfdc7ff15c ("Use punch hole as "discard" on regular files") Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--misc/mke2fs.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 9fa6eaa73..5a35e9ef8 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -2794,7 +2794,7 @@ static int mke2fs_discard_device(ext2_filsys fs)
struct ext2fs_numeric_progress_struct progress;
blk64_t blocks = ext2fs_blocks_count(fs->super);
blk64_t count = DISCARD_STEP_MB;
- blk64_t cur;
+ blk64_t cur = 0;
int retval = 0;
/*
@@ -2802,10 +2802,9 @@ static int mke2fs_discard_device(ext2_filsys fs)
* we do not print numeric progress resulting in failure
* afterwards.
*/
- retval = io_channel_discard(fs->io, 0, fs->blocksize);
+ retval = io_channel_discard(fs->io, 0, 1);
if (retval)
return retval;
- cur = fs->blocksize;
count *= (1024 * 1024);
count /= fs->blocksize;