mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-10 11:11:16 +00:00
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>
This commit is contained in:
parent
9c92c4eb92
commit
5407ee85fc
@ -107,8 +107,9 @@ static int cmd_device_add(int argc, char **argv)
|
||||
continue;
|
||||
}
|
||||
|
||||
res = btrfs_prepare_device(devfd, argv[i], 1, &dev_block_count,
|
||||
0, discard);
|
||||
res = btrfs_prepare_device(devfd, argv[i], &dev_block_count, 0,
|
||||
PREP_DEVICE_ZERO_END | PREP_DEVICE_VERBOSE |
|
||||
(discard ? PREP_DEVICE_DISCARD : 0));
|
||||
close(devfd);
|
||||
if (res) {
|
||||
ret++;
|
||||
|
@ -254,8 +254,8 @@ static int cmd_replace_start(int argc, char **argv)
|
||||
}
|
||||
strncpy((char *)start_args.start.tgtdev_name, dstdev,
|
||||
BTRFS_DEVICE_PATH_NAME_MAX);
|
||||
ret = btrfs_prepare_device(fddstdev, dstdev, 1, &dstdev_block_count, 0,
|
||||
0);
|
||||
ret = btrfs_prepare_device(fddstdev, dstdev, &dstdev_block_count, 0,
|
||||
PREP_DEVICE_ZERO_END | PREP_DEVICE_VERBOSE);
|
||||
if (ret)
|
||||
goto leave_with_error;
|
||||
|
||||
|
14
mkfs.c
14
mkfs.c
@ -1636,8 +1636,11 @@ int main(int argc, char **argv)
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count,
|
||||
block_count, discard);
|
||||
ret = btrfs_prepare_device(fd, file, &dev_block_count,
|
||||
block_count,
|
||||
(zero_end ? PREP_DEVICE_ZERO_END : 0) |
|
||||
(discard ? PREP_DEVICE_DISCARD : 0) |
|
||||
(verbose ? PREP_DEVICE_VERBOSE : 0));
|
||||
if (ret) {
|
||||
close(fd);
|
||||
exit(1);
|
||||
@ -1767,8 +1770,11 @@ int main(int argc, char **argv)
|
||||
close(fd);
|
||||
continue;
|
||||
}
|
||||
ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count,
|
||||
block_count, discard);
|
||||
ret = btrfs_prepare_device(fd, file, &dev_block_count,
|
||||
block_count,
|
||||
(verbose ? PREP_DEVICE_VERBOSE : 0) |
|
||||
(zero_end ? PREP_DEVICE_ZERO_END : 0) |
|
||||
(discard ? PREP_DEVICE_DISCARD : 0));
|
||||
if (ret) {
|
||||
close(fd);
|
||||
exit(1);
|
||||
|
13
utils.c
13
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);
|
||||
|
||||
|
8
utils.h
8
utils.h
@ -147,12 +147,16 @@ struct btrfs_convert_context {
|
||||
void *fs_data;
|
||||
};
|
||||
|
||||
#define PREP_DEVICE_ZERO_END (1U << 0)
|
||||
#define PREP_DEVICE_DISCARD (1U << 1)
|
||||
#define PREP_DEVICE_VERBOSE (1U << 2)
|
||||
|
||||
int make_btrfs(int fd, struct btrfs_mkfs_config *cfg,
|
||||
struct btrfs_convert_context *cctx);
|
||||
int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_root *root, u64 objectid);
|
||||
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);
|
||||
int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_root *root, int fd, char *path,
|
||||
u64 block_count, u32 io_width, u32 io_align,
|
||||
|
Loading…
Reference in New Issue
Block a user