diff mbox

[5/7] btrfs-progs: introduce framework version to features

Message ID 1448453300-8449-6-git-send-email-anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Anand Jain Nov. 25, 2015, 12:08 p.m. UTC
As discussed in the mailing list this provides a framework to introduce
the feature where mkfs and btrfs-convert can set the default features
as per the given mainline kernel version.

Suggested-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 utils.c | 23 +++++++++++++++++++++++
 utils.h |  1 +
 2 files changed, 24 insertions(+)
diff mbox

Patch

diff --git a/utils.c b/utils.c
index 216efa6..a9b46b8 100644
--- a/utils.c
+++ b/utils.c
@@ -3222,3 +3222,26 @@  int btrfs_features_allowed_by_sysfs(u64 *features)
 	closedir(dir);
 	return 0;
 }
+
+int btrfs_features_allowed_by_version(char *version, u64 *features)
+{
+	int i;
+	int code;
+	char *ver = strdup(version);
+
+	*features = 0;
+	code = version_to_code(ver);
+	free(ver);
+	if (code < 0)
+		return code;
+
+	for (i = 0; i < ARRAY_SIZE(mkfs_features) - 1; i++) {
+		ver = strdup(mkfs_features[i].min_ker_ver);
+
+		if (code >= version_to_code(ver))
+			*features |= mkfs_features[i].flag;
+
+		free(ver);
+	}
+	return 0;
+}
diff --git a/utils.h b/utils.h
index cb20d73..1418e84 100644
--- a/utils.h
+++ b/utils.h
@@ -106,6 +106,7 @@  void btrfs_process_fs_features(u64 flags);
 void btrfs_parse_features_to_string(char *buf, u64 flags);
 u64 btrfs_features_allowed_by_kernel(void);
 int btrfs_features_allowed_by_sysfs(u64 *features);
+int btrfs_features_allowed_by_version(char *version, u64 *features);
 
 struct btrfs_mkfs_config {
 	char *label;