From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from cantor2.suse.de ([195.135.220.15]:47465 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753759Ab3IJEfK (ORCPT ); Tue, 10 Sep 2013 00:35:10 -0400 Message-ID: <522EA170.1030003@suse.com> Date: Tue, 10 Sep 2013 00:34:56 -0400 From: Jeff Mahoney MIME-Version: 1.0 To: linux-btrfs Cc: Chris Mason , David Sterba Subject: [PATCH 2/2 v2] utils: add support for getting/changing file system, features Content-Type: text/plain; charset=US-ASCII Sender: linux-btrfs-owner@vger.kernel.org List-ID: 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. Changing bits not supported by the tools directly can be forced with -f when the file system is unmounted. v2: Implemented new ioctl methods from newer ioctl patchset; Cleanup Signed-off-by: Jeff Mahoney --- cmds-filesystem.c | 43 ++++ ioctl.h | 12 ++ man/btrfs.8.in | 28 +++ utils.c | 588 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ utils.h | 9 + 5 files changed, 680 insertions(+) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index f41a72a..8e2e693 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -515,6 +515,48 @@ static int cmd_label(int argc, char **argv) return get_label(argv[1]); } +static const char * const cmd_features_usage[] = { + "btrfs filesystem features [|] [[-f] ]", + "Get or change the list of features currently enabled by a filesystem", + "With one argument, get the currently enabled features of filesystem", + "on or .", "", + "If is passed, add or remove new features to the ", + "filesystem. The format of 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). Prefixing the ", + "feature name with a caret (^) will clear the flag.", "", + "The kernel has a defined set of feature flags that it will allow", + "to be set or cleared at runtime. Features not supported by the", + "tools can be changed by using the -f (force) flag when operating", + "on an unmounted filesystem.", "", + "A list of features supported by the tools 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 +566,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 }, } }; diff --git a/ioctl.h b/ioctl.h index abe6dd4..3605c4a 100644 --- a/ioctl.h +++ b/ioctl.h @@ -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_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 54, \ + struct btrfs_ioctl_feature_flags[2]) +#define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 54, \ + struct btrfs_ioctl_feature_flags[3]) #ifdef __cplusplus } diff --git a/man/btrfs.8.in b/man/btrfs.8.in index af7df4d..0b3815f 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -31,6 +31,8 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBfilesystem label\fP\fI [newlabel]\fP .PP +\fBbtrfs\fP \fBfilesystem features\fP\fI [[-f ]newlabel]\fP +.PP \fBbtrfs\fP \fBfilesystem balance\fP\fI \fP .PP \fBbtrfs\fP \fBdevice scan\fP\fI [--all-devices| [...]]\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 [[-f] features]\fP +Show or update the features of a filesystem. \fI\fR is used to identify an umounted filesystem. \fI\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. It is also possible to clear a set flag by prefixing the flag name with a caret (^). +.TP + \fBfilesystem show\fR [--all-devices||