Whamcloud - gitweb
mke2fs: only try discarding a single block to test if discard works
authorTheodore Ts'o <tytso@mit.edu>
Sun, 18 Jul 2021 13:15:28 +0000 (09:15 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 18 Jul 2021 15:05:20 +0000 (11:05 -0400)
commit6568ba325e54a2ae1d2617c5175936c819ab4c8c
treef773d23fe9791f6828a4c8b6f607894005524f95
parentd0b6b64f62eff5c7545be8b71adf6fd537613a90
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>
misc/mke2fs.c