Skip to content

Commit 11550af

Browse files
maharmstonekdave
authored andcommitted
btrfs-progs: mkfs: do zeroing before discard
mkfs.btrfs clears the very beginning and very end of a block device, to prevent it from potentially being identified as another filesystem. Change btrfs_prepare_device() so that this happens immediately before the whole-device discard, rather than afterwards. This means that the contents of these regions is either all zeroes (if discard did nothing) or indeterminate (if discard was effective): either way it's clearing the other filesystem's markers. Pull-request: #1021 Signed-off-by: Mark Harmstone <mark@harmstone.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 16ee6b5 commit 11550af

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

common/device-utils.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@ int btrfs_prepare_device(int fd, const char *file, u64 *byte_count_ret,
277277
goto err;
278278
}
279279
}
280-
} else if (opflags & PREP_DEVICE_DISCARD) {
281-
prepare_discard_device(file, fd, byte_count, opflags);
282280
}
283281

284282
ret = zero_dev_clamped(fd, zinfo, 0, ZERO_DEV_BYTES, byte_count);
@@ -295,6 +293,9 @@ int btrfs_prepare_device(int fd, const char *file, u64 *byte_count_ret,
295293
goto err;
296294
}
297295

296+
if (!(opflags & PREP_DEVICE_ZONED) && opflags & PREP_DEVICE_DISCARD)
297+
prepare_discard_device(file, fd, byte_count, opflags);
298+
298299
ret = btrfs_wipe_existing_sb(fd, zinfo);
299300
if (ret < 0) {
300301
error("cannot wipe superblocks on %s", file);

0 commit comments

Comments
 (0)