btrfs-progs: defrag: new option --nocomp to do no-compression defrag
Subsystems (2)
David Sterba
maintainerPATCH 1/1 btrfs-progs: defrag: new option --nocomp to do no-compression defrag
Add new option --nocomp to set flag which will tell kernel to defragment file extents without compression and decompress existing extents if needed. The defrag setting will override any current compression settings like mount options or file properties. The option is separate from '-c' so it's more obvious it's mutually exclusive.
Signed-off-by David Sterba <[email protected]>
--- Documentation/btrfs-filesystem.rst | 2 ++ cmds/filesystem.c | 19 ++++++++++++++++++- kernel-shared/uapi/btrfs.h | 2 ++ libbtrfsutil/btrfs.h | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-)
Documentation/btrfs-filesystem.rst +2 -0
@@ -124,6 +124,8 @@ defragment [options] <file>|<dir> [<file>|<dir>...] 1..9, *lzo* does not have any levels, *zstd* the standard levels 1..15 and also the realtime -1..-15. + --nocomp + Do not compress while defragmenting, uncompress extents if needed. -r defragment files recursively in given directories, does not descend to subvolumes or mount points
cmds/filesystem.c +18 -1
@@ -948,6 +948,7 @@ static const char * const cmd_filesystem_defrag_usage[] = {OPTLINE ("-r" ,"defragment files recursively" ),OPTLINE ("-c[zlib,lzo,zstd]" ,"compress the file while defragmenting, optional parameter (no space in between)" ),OPTLINE ("-L|--level level" ,"use given compression level if enabled (zlib: 1..9, zstd: -15..15, and 0 selects the default level)" ), +OPTLINE ("--nocomp" ,"don't compress while defragmenting (uncompress if needed)" ),OPTLINE ("-f" ,"flush data to disk immediately after defragmenting" ),OPTLINE ("-s start" ,"defragment only from byte onward" ), OPTLINE("-l len", "defragment only up to len bytes"),
@@ -1053,6 +1054,7 @@ static int cmd_filesystem_defrag(const struct cmd_struct *cmd,int ret =0 ;int compress_type =BTRFS_COMPRESS_NONE ;int compress_level =0 ; +bool opt_nocomp = false;/* * Kernel 4.19+ supports defragmention of files open read-only,
@@ -1085,10 +1087,11 @@ static int cmd_filesystem_defrag(const struct cmd_struct *cmd, defrag_global_errors =0 ; optind =0 ;while (1 ) { -enum {GETOPT_VAL_STEP =GETOPT_VAL_FIRST }; +enum {GETOPT_VAL_STEP =GETOPT_VAL_FIRST ,GETOPT_VAL_NOCOMP };static const struct option long_options[] = { {"level" , required_argument,NULL ,'L' }, {"step" , required_argument,NULL ,GETOPT_VAL_STEP }, + {"nocomp" , no_argument,NULL ,GETOPT_VAL_NOCOMP }, {NULL ,0 ,NULL ,0 } };int c;
@@ -1099,6 +1102,11 @@ static int cmd_filesystem_defrag(const struct cmd_struct *cmd,switch (c) {case 'c' : +if (opt_nocomp) { +error ("cannot use compression with --nocomp" ); +return 1 ; + } + compress_type =BTRFS_COMPRESS_ZLIB ;if (optarg) compress_type =parse_compress_type_arg (optarg);
@@ -1142,6 +1150,13 @@ static int cmd_filesystem_defrag(const struct cmd_struct *cmd,case 'r' : recursive = true;break ; +case GETOPT_VAL_NOCOMP : +if (compress_level !=BTRFS_COMPRESS_NONE ) { +error ("cannot use --nocomp with compression set" ); +return 1 ; + } + opt_nocomp = true; +break ;case GETOPT_VAL_STEP : defrag_global_step =arg_strtou64_with_suffix (optarg);if (defrag_global_step <SZ_256K ) {
@@ -1171,6 +1186,8 @@ static int cmd_filesystem_defrag(const struct cmd_struct *cmd, }else defrag_global_range.compress_type = compress_type; } +if (opt_nocomp) + defrag_global_range.flags |=BTRFS_DEFRAG_RANGE_NOCOMPRESS ;if (flush) defrag_global_range.flags |=BTRFS_DEFRAG_RANGE_START_IO ;
kernel-shared/uapi/btrfs.h +2 -0
@@ -646,8 +646,10 @@ _static_assert(sizeof(struct btrfs_ioctl_clone_range_args) == 32);#define BTRFS_DEFRAG_RANGE_COMPRESS 1#define BTRFS_DEFRAG_RANGE_START_IO 2#define BTRFS_DEFRAG_RANGE_COMPRESS_LEVEL 4 +#define BTRFS_DEFRAG_RANGE_NOCOMPRESS 8#define BTRFS_DEFRAG_RANGE_FLAGS_SUPP (BTRFS_DEFRAG_RANGE_COMPRESS | \ BTRFS_DEFRAG_RANGE_COMPRESS_LEVEL | \ + BTRFS_DEFRAG_RANGE_NOCOMPRESS | \ BTRFS_DEFRAG_RANGE_START_IO)struct btrfs_ioctl_defrag_range_args {
libbtrfsutil/btrfs.h +2 -0
@@ -609,8 +609,10 @@ struct btrfs_ioctl_clone_range_args {#define BTRFS_DEFRAG_RANGE_COMPRESS 1#define BTRFS_DEFRAG_RANGE_START_IO 2#define BTRFS_DEFRAG_RANGE_COMPRESS_LEVEL 4 +#define BTRFS_DEFRAG_RANGE_NOCOMPRESS 8#define BTRFS_DEFRAG_RANGE_FLAGS_SUPP (BTRFS_DEFRAG_RANGE_COMPRESS | \ BTRFS_DEFRAG_RANGE_COMPRESS_LEVEL | \ + BTRFS_DEFRAG_RANGE_NOCOMPRESS | \ BTRFS_DEFRAG_RANGE_START_IO)struct btrfs_ioctl_defrag_range_args {
Signature · 1 line
2.49.0