utils: add support for getting/changing file system, features
PATCH 2/2 utils: add support for getting/changing file system, features
This patch adds support for getting and changing file system feature bits. It supports both unmounted and mounted operation via a new set of ioctls.
Setting bits not supported by the running kernel, if the file system is mounted, or the tools, if the file system is unmounted, can be forced with a -f option.
It supports clearing of feature bits, but I've left that undocumented intentionally.
Signed-off-by Jeff Mahoney <[email protected]>
--- cmds-filesystem.c | 42 +++++ ioctl.h | 12 ++ man/btrfs.8.in | 28 ++++ utils.c | 478 +++++++++++++++++++++++++++++++++++++++++++++++++++++- utils.h | 10 ++ 5 files changed, 569 insertions(+), 1 deletion(-)
cmds-filesystem.c +42 -0
@@ -515,6 +515,47 @@ static int cmd_label(int argc, char **argv)return get_label (argv[1 ]); } +static const char *const cmd_features_usage[] = { +"btrfs filesystem features [<device>|<mountpoint>] [[-f] <features>]" , +"Get or change the list of features currently enabled by a filesystem" , +"With one argument, get the currently enabled features of filesystem" , +"on <device> or <mountpoint>." ,"" , +"If <features> is passed, add new features to the file system." , +"The format of new features can be a comma separated list of names or" , +"or a comma-separated list of specifiers of the following format: A" , +"prefix of compat, compat_ro, or incompat and a decimal number, " , +"separated by a colon: (e.g. compat:10)" ,"" , +"Features to be enabled will be confirmed against the supported" , +"features of the kernel (if mounted) or the progs (if unmounted). This" , +"behavior can be overridden when operating on unmounted" , +"filesystems by using the -f (force) flag." ,"" , +"A list of features supported by the progs can be found in the manual." , +NULL +}; + +static int cmd_features (int argc,char **argv) +{ +if (check_argc_min (argc,2 ) ||check_argc_max (argc,4 )) +usage (cmd_features_usage); + +if (argc >2 ) { +char *features = argv[2 ]; +int force =0 ; +if (argc >3 ) { +if (!strcmp (argv[3 ],"-f" )) + force =1 ; +else if (!strcmp (argv[2 ],"-f" )) { + force =1 ; + features = argv[3 ]; + }else +usage (cmd_features_usage); + } + +return parse_and_set_features (argv[1 ], features, force); + }else +return get_features (argv[1 ]); +} +const struct cmd_group filesystem_cmd_group = { filesystem_cmd_group_usage,NULL , { {"df" , cmd_df, cmd_df_usage,NULL ,0 },
@@ -524,6 +565,7 @@ const struct cmd_group filesystem_cmd_group = { { "balance", cmd_balance, NULL, &balance_cmd_group, 1 }, { "resize", cmd_resize, cmd_resize_usage, NULL, 0 }, { "label", cmd_label, cmd_label_usage, NULL, 0 }, + { "features", cmd_features, cmd_features_usage, NULL, 0 }, { 0, 0, 0, 0, 0 }, } };
ioctl.h +12 -0
@@ -172,6 +172,12 @@ struct btrfs_ioctl_fs_info_args {__u64 reserved[124 ];/* pad to 1k */ }; +struct btrfs_ioctl_feature_flags { +__u64 compat_flags; +__u64 compat_ro_flags; +__u64 incompat_flags; +}; +/* balance control ioctl modes */ #define BTRFS_BALANCE_CTL_PAUSE 1#define BTRFS_BALANCE_CTL_CANCEL 2
@@ -537,6 +543,12 @@ struct btrfs_ioctl_clone_range_args { struct btrfs_ioctl_get_dev_stats)#define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53, \ struct btrfs_ioctl_dev_replace_args) +#define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 54, \ + struct btrfs_ioctl_feature_flags) +#define BTRFS_IOC_ADD_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 55, \ + struct btrfs_ioctl_feature_flags) +#define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 56, \ + struct btrfs_ioctl_feature_flags[2]) #ifdef __cplusplus }
man/btrfs.8.in +28 -0
@@ -31,6 +31,8 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBfilesystem label\fP\fI <dev> [newlabel]\fP .PP +\fBbtrfs\fP \fBfilesystem features\fP\fI <dev|mountpoint> [[-f ]newlabel]\fP +.PP \fBbtrfs\fP \fBfilesystem balance\fP\fI <path> \fP .PP \fBbtrfs\fP \fBdevice scan\fP\fI [--all-devices|<device> [<device>...]]\fP
@@ -280,6 +282,32 @@ NOTE: Currently there are the following limitations: - the filesystem should not have more than one device. .TP +\fBfilesystem features\fP\fI <dev|mountpoint> [[-f] features]\fP +Show or update the features of a filesystem. \fI<dev>\fR is used to identify an umounted filesystem. \fI<mountpoint>\fR is used to identify a mounted filesystem. +If a \fIfeatures\fR optional argument is passed, the features are updated. +The following features are currently supported by the tool: +.br +- mixed_backref +.br +- default_subvol +.br +- mixed_groups +.br +- compress_lzo +.br +- compress_lzov2 +.br +- big_metadata +.br +- extended_iref +.br +- raid56 +.br +- skinny_metadata +.IP +It is possible, but not recommended to set undocumented features using one of the following prefixes: compat, compat_ro, incompat and a bit number, separated by a colon. e.g. compat:12. Please note that changing unrecognized feature bits is a dangerous operation and may result in an umountable file system that needs to be manually repaired by an expert. +.TP + \fBfilesystem show\fR [--all-devices|<uuid>|<label>]\fR Show the btrfs filesystem with some additional info. If no \fIUUID\fP or \fIlabel\fP is passed, \fBbtrfs\fR show info of all the btrfs filesystem.
utils.c +477 -1
490 lines not on this page · raw message
utils.h +10 -0
@@ -55,6 +55,16 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args, struct btrfs_ioctl_dev_info_args **di_ret);int get_label (const char *btrfs_dev);int set_label (const char *btrfs_dev,const char *label); +int get_features (const char *btrfs_dev); +int parse_features (const char *features, +struct btrfs_ioctl_feature_flags *set_flags, +struct btrfs_ioctl_feature_flags *clear_flags); +int set_features (const char *btrfs_dev, +const struct btrfs_ioctl_feature_flags *flags, +const struct btrfs_ioctl_feature_flags *clear_flags, +int force); +int parse_and_set_features (const char *btrfs_dev,const char *features, +int force);char *__strncpy__null (char *dest,const char *src,size_t n);int is_block_device (const char *file);
Signature · 6 lines
1.8.1.4 -- Jeff Mahoney SUSE Labs