From patchwork Tue Sep 10 04:33:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Mahoney X-Patchwork-Id: 2864061 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AB7439F485 for ; Tue, 10 Sep 2013 04:34:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4101D2030E for ; Tue, 10 Sep 2013 04:34:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 903A9202F6 for ; Tue, 10 Sep 2013 04:34:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753204Ab3IJEeH (ORCPT ); Tue, 10 Sep 2013 00:34:07 -0400 Received: from cantor2.suse.de ([195.135.220.15]:47431 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752698Ab3IJEeF (ORCPT ); Tue, 10 Sep 2013 00:34:05 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id A1846A51BB; Tue, 10 Sep 2013 06:34:03 +0200 (CEST) Message-ID: <522EA12E.3000408@suse.com> Date: Tue, 10 Sep 2013 00:33:50 -0400 From: Jeff Mahoney User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 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 X-Enigmail-Version: 1.5.2 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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||