summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-07-28 01:47:40 +0200
committerDavid Sterba <dsterba@suse.com>2016-07-28 14:08:30 +0200
commit5407ee85fcaba91c9a0207ffad97a9b8b1c45c8c (patch)
tree8b9e427c1995e4dbea858746dbe5a7a33875953d /utils.c
parent9c92c4eb92c41860819a5c9e25972451541f1b02 (diff)
btrfs-progs: refactor and extend btrfs_prepare_device arguments
The message about discard is printed unconditionally and does not conform to the --quite option eg. in mkfs. Consolidate the operation flags into one argument and add support for verbosity. Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/utils.c b/utils.c
index f73b048c..79bf9466 100644
--- a/utils.c
+++ b/utils.c
@@ -1682,8 +1682,8 @@ out:
return ret;
}
-int btrfs_prepare_device(int fd, const char *file, int zero_end,
- u64 *block_count_ret, u64 max_block_count, int discard)
+int btrfs_prepare_device(int fd, const char *file, u64 *block_count_ret,
+ u64 max_block_count, unsigned opflags)
{
u64 block_count;
struct stat st;
@@ -1703,15 +1703,16 @@ int btrfs_prepare_device(int fd, const char *file, int zero_end,
if (max_block_count)
block_count = min(block_count, max_block_count);
- if (discard) {
+ if (opflags & PREP_DEVICE_DISCARD) {
/*
* We intentionally ignore errors from the discard ioctl. It
* is not necessary for the mkfs functionality but just an
* optimization.
*/
if (discard_range(fd, 0, 0) == 0) {
- printf("Performing full device TRIM (%s) ...\n",
- pretty_size(block_count));
+ if (opflags & PREP_DEVICE_VERBOSE)
+ printf("Performing full device TRIM (%s) ...\n",
+ pretty_size(block_count));
discard_blocks(fd, 0, block_count);
}
}
@@ -1720,7 +1721,7 @@ int btrfs_prepare_device(int fd, const char *file, int zero_end,
for (i = 0 ; !ret && i < BTRFS_SUPER_MIRROR_MAX; i++)
ret = zero_dev_clamped(fd, btrfs_sb_offset(i),
BTRFS_SUPER_INFO_SIZE, block_count);
- if (!ret && zero_end)
+ if (!ret && (opflags & PREP_DEVICE_ZERO_END))
ret = zero_dev_clamped(fd, block_count - ZERO_DEV_BYTES,
ZERO_DEV_BYTES, block_count);