From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from cantor2.suse.de ([195.135.220.15]:56552 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753871Ab3H0TRy (ORCPT ); Tue, 27 Aug 2013 15:17:54 -0400 Message-ID: <521CFB5D.3020307@suse.com> Date: Tue, 27 Aug 2013 15:17:49 -0400 From: Jeff Mahoney MIME-Version: 1.0 To: Chris Mason Cc: linux-btrfs , David Sterba Subject: [PATCH 2/2] utils: add support for getting/changing file system, features Content-Type: text/plain; charset=ISO-8859-1 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. 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 --- 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(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index f41a72a..ca096e0 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -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 [|] [[-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 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 }, } }; diff --git a/ioctl.h b/ioctl.h index abe6dd4..44483d1 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_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 } diff --git a/man/btrfs.8.in b/man/btrfs.8.in index af7df4d..9c5b61e 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. +.TP + \fBfilesystem show\fR [--all-devices||