Skip to contentSkip to conversation

utils: add support for getting/changing file system, features

PATCH New Jeff Mahoney 1 participant 1 message Sep 10, 2013 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

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

---
 cmds-filesystem.c |  43 ++++
 ioctl.h           |  12 ++
 man/btrfs.8.in    |  28 +++
 utils.c           | 588 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 utils.h           |   9 +
 5 files changed, 680 insertions(+)
cmds-filesystem.c +43 -0
index f41a72a..8e2e693 100644
@@ -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 [<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 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 },
 	}
 };
ioctl.h +12 -0
index abe6dd4..3605c4a 100644
@@ -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
 }
man/btrfs.8.in +28 -0
index af7df4d..0b3815f 100644
@@ -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. It is also possible to clear a set flag by prefixing the flag name with a caret (^).
+.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 +588 -0

594 lines not on this page · raw message

utils.h +9 -0
index 3c17e14..6faad28 100644
@@ -55,6 +55,15 @@ 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 *change_mask,
+		   struct btrfs_ioctl_feature_flags *flags);
+int set_features(const char *btrfs_dev,
+		 const struct btrfs_ioctl_feature_flags *change_mask,
+		 const struct btrfs_ioctl_feature_flags *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