mirror of
https://github.com/kdave/btrfs-progs
synced 2025-02-16 09:46:55 +00:00
Update for lzo support
[Btrfs-Progs][V2] Update for lzo support - Add incompat flag, otherwise btrfs-progs will report error when operating on btrfs filesystems mounted with lzo option. - Update man page. - Allow to turn on lzo compression for defrag operation: # btrfs filesystem defragment -c[zlib, lzo] <file> Note: "-c zlib" will fail, because that's how getopt() works for optional arguments. Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
This commit is contained in:
parent
b8802ae3fa
commit
a418b24318
2
btrfs.c
2
btrfs.c
@ -65,7 +65,7 @@ static struct Command commands[] = {
|
||||
"List the recently modified files in a filesystem."
|
||||
},
|
||||
{ do_defrag, -1,
|
||||
"filesystem defragment", "[-vcf] [-s start] [-l len] [-t size] <file>|<dir> [<file>|<dir>...]\n"
|
||||
"filesystem defragment", "[-vf] [-c[zlib,lzo]] [-s start] [-l len] [-t size] <file>|<dir> [<file>|<dir>...]\n"
|
||||
"Defragment a file or a directory."
|
||||
},
|
||||
{ do_set_default_subvol, 2,
|
||||
|
24
btrfs_cmds.c
24
btrfs_cmds.c
@ -142,10 +142,21 @@ static u64 parse_size(char *s)
|
||||
return atoll(s) * mult;
|
||||
}
|
||||
|
||||
static int parse_compress_type(char *s)
|
||||
{
|
||||
if (strcmp(optarg, "zlib") == 0)
|
||||
return BTRFS_COMPRESS_ZLIB;
|
||||
else if (strcmp(optarg, "lzo") == 0)
|
||||
return BTRFS_COMPRESS_LZO;
|
||||
else {
|
||||
fprintf(stderr, "Unknown compress type %s\n", s);
|
||||
exit(1);
|
||||
};
|
||||
}
|
||||
|
||||
int do_defrag(int ac, char **av)
|
||||
{
|
||||
int fd;
|
||||
int compress = 0;
|
||||
int flush = 0;
|
||||
u64 start = 0;
|
||||
u64 len = (u64)-1;
|
||||
@ -157,15 +168,18 @@ int do_defrag(int ac, char **av)
|
||||
int fancy_ioctl = 0;
|
||||
struct btrfs_ioctl_defrag_range_args range;
|
||||
int e=0;
|
||||
int compress_type = BTRFS_COMPRESS_NONE;
|
||||
|
||||
optind = 1;
|
||||
while(1) {
|
||||
int c = getopt(ac, av, "vcfs:l:t:");
|
||||
int c = getopt(ac, av, "vc::fs:l:t:");
|
||||
if (c < 0)
|
||||
break;
|
||||
switch(c) {
|
||||
case 'c':
|
||||
compress = 1;
|
||||
compress_type = BTRFS_COMPRESS_ZLIB;
|
||||
if (optarg)
|
||||
compress_type = parse_compress_type(optarg);
|
||||
fancy_ioctl = 1;
|
||||
break;
|
||||
case 'f':
|
||||
@ -203,8 +217,10 @@ int do_defrag(int ac, char **av)
|
||||
range.start = start;
|
||||
range.len = len;
|
||||
range.extent_thresh = thresh;
|
||||
if (compress)
|
||||
if (compress_type) {
|
||||
range.flags |= BTRFS_DEFRAG_RANGE_COMPRESS;
|
||||
range.compress_type = compress_type;
|
||||
}
|
||||
if (flush)
|
||||
range.flags |= BTRFS_DEFRAG_RANGE_START_IO;
|
||||
|
||||
|
10
ctree.h
10
ctree.h
@ -354,12 +354,14 @@ struct btrfs_super_block {
|
||||
#define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
|
||||
#define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
|
||||
#define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
|
||||
#define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3)
|
||||
|
||||
#define BTRFS_FEATURE_COMPAT_SUPP 0ULL
|
||||
#define BTRFS_FEATURE_COMPAT_RO_SUPP 0ULL
|
||||
#define BTRFS_FEATURE_INCOMPAT_SUPP \
|
||||
(BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
|
||||
BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \
|
||||
BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO | \
|
||||
BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
|
||||
|
||||
/*
|
||||
@ -505,9 +507,11 @@ struct btrfs_timespec {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
typedef enum {
|
||||
BTRFS_COMPRESS_NONE = 0,
|
||||
BTRFS_COMPRESS_ZLIB = 1,
|
||||
BTRFS_COMPRESS_LAST = 2,
|
||||
BTRFS_COMPRESS_NONE = 0,
|
||||
BTRFS_COMPRESS_ZLIB = 1,
|
||||
BTRFS_COMPRESS_LZO = 2,
|
||||
BTRFS_COMPRESS_TYPES = 2,
|
||||
BTRFS_COMPRESS_LAST = 3,
|
||||
} btrfs_compression_type;
|
||||
|
||||
/* we don't understand any encryption methods right now */
|
||||
|
9
ioctl.h
9
ioctl.h
@ -116,8 +116,15 @@ struct btrfs_ioctl_defrag_range_args {
|
||||
*/
|
||||
__u32 extent_thresh;
|
||||
|
||||
/*
|
||||
* which compression method to use if turning on compression
|
||||
* for this defrag operation. If unspecified, zlib will
|
||||
* be used
|
||||
*/
|
||||
__u32 compress_type;
|
||||
|
||||
/* spare for later */
|
||||
__u32 unused[5];
|
||||
__u32 unused[4];
|
||||
};
|
||||
|
||||
struct btrfs_ioctl_space_info {
|
||||
|
@ -15,12 +15,12 @@ btrfs \- control a btrfs filesystem
|
||||
.PP
|
||||
\fBbtrfs\fP \fBsubvolume set-default\fP\fI <id> <path>\fP
|
||||
.PP
|
||||
\fBbtrfs\fP \fBfilesystem defragment\fP\fI [-vcf] [-s start] [-l len] [-t size] <file>|<dir> [<file>|<dir>...]\fP
|
||||
.PP
|
||||
\fBbtrfs\fP \fBfilesystem sync\fP\fI <path> \fP
|
||||
.PP
|
||||
\fBbtrfs\fP \fBfilesystem resize\fP\fI [+/\-]<size>[gkm]|max <filesystem>\fP
|
||||
.PP
|
||||
\fBbtrfs\fP \fBfilesystem defrag\fP\fI [options] <file>|<dir> [<file>|<dir>...]\fP
|
||||
.PP
|
||||
\fBbtrfs\fP \fBdevice scan\fP\fI [<device> [<device>..]]\fP
|
||||
.PP
|
||||
\fBbtrfs\fP \fBdevice show\fP\fI <dev>|<label> [<dev>|<label>...]\fP
|
||||
@ -30,7 +30,6 @@ btrfs \- control a btrfs filesystem
|
||||
\fBbtrfs\fP \fBdevice add\fP\fI <dev> [<dev>..] <path> \fP
|
||||
.PP
|
||||
\fBbtrfs\fP \fBdevice delete\fP\fI <dev> [<dev>..] <path> \fP]
|
||||
|
||||
.PP
|
||||
\fBbtrfs\fP \fBhelp|\-\-help|\-h \fP\fI\fP
|
||||
.PP
|
||||
@ -104,10 +103,13 @@ Set the subvolume of the filesystem \fI<path>\fR which is mounted as
|
||||
is returned by the \fBsubvolume list\fR command.
|
||||
.TP
|
||||
|
||||
\fBfilesystem defragment\fP\fI [-vcf] [-s start] [-l len] [-t size] <file>|<dir> [<file>|<dir>...]\fR
|
||||
\fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] [-s \fIstart\fR] [-t \fIsize\fR] -[vf] <\fIfile\fR>|<\fIdir\fR> [<\fIfile\fR>|<\fIdir\fR>...]
|
||||
|
||||
Defragment file data and/or directory metadata. To defragment all files in a
|
||||
directory you have to specify each one on its own or use your shell wildcards.
|
||||
|
||||
The start position and the number of bytes to deframention can be specified by \fIstart\fR and \fIlen\fR. Any extent bigger than \fIthresh\fR will be considered already defragged. Use 0 to take the kernel default, and use 1 to say eveery single extent must be rewritten. You can also turn on compression in defragment operations.
|
||||
|
||||
\fB-v\fP be verbose
|
||||
|
||||
\fB-c\fP compress file contents while defragmenting
|
||||
|
Loading…
Reference in New Issue
Block a user