btrfs: defrag: introduce control structure for later use
authorQu Wenruo <wqu@suse.com>
Fri, 11 Feb 2022 06:41:41 +0000 (14:41 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 15 Feb 2022 15:26:29 +0000 (16:26 +0100)
commita65b76f42a5ea3e386784fc396a1e92d164c71bc
treefa6119cc10ff48faf2f9fa4b625bc8d970d9da38
parentd3394d779b146885a83586873e8c3f58a1176a3c
btrfs: defrag: introduce control structure for later use

Currently btrfs_defrag_file() accepts not only
btrfs_ioctl_defrag_range_args but also other parameters like @newer_than
and @max_sectors_to_defrag for extra policies.

Those extra values are hidden from defrag ioctl and even caused bugs in
the past due to different behavior based on those extra values.

Here we introduce a new structure, btrfs_defrag_ctrl, to include:

- all members in btrfs_ioctl_defrag_range_args

- @max_sectors_to_defrag and @newer_than

- Extra values which callers of btrfs_defrag_file() may care
  Like @sectors_defragged and @last_scanned.

With the new structure, also introduce a new helper,
btrfs_defrag_ioctl_args_to_ctrl() to:

- Do extra sanity check on @compress and @flags

- Do range alignment when possible

- Set default values.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/ioctl.c