aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-02-10 01:30:48 +0100
committerDavid Sterba <dsterba@suse.com>2016-04-07 16:54:55 +0200
commit3b38ca3ea82ce0f4417d0ffea8b0e5c0ec798fb1 (patch)
tree9ebfdebf32e70e8635b971c242267659d2fa439d
parent5e8f3cdbac9e341394550b6cf0a43c03e79b84b9 (diff)
downloadbtrfs-progs-dev/mkfs-defaults.tar.gz
btrfs-progs-dev/mkfs-defaults.tar.xz
btrfs-progs-dev/mkfs-defaults.zip
btrfs-progs: mkfs: autodetect and set featuresdev/mkfs-defaults
WIP Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--mkfs.c27
-rw-r--r--utils.c14
-rw-r--r--utils.h1
3 files changed, 38 insertions, 4 deletions
diff --git a/mkfs.c b/mkfs.c
index 5ad0ba5..a027086 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1368,9 +1368,24 @@ int main(int argc, char **argv)
int dev_cnt = 0;
int saved_optind;
char fs_uuid[BTRFS_UUID_UNPARSED_SIZE] = { 0 };
- u64 features = BTRFS_MKFS_DEFAULT_FEATURES;
+ u64 features;
+ u64 sysfs_features;
+ char features_buf[64];
struct mkfs_allocation allocation = { 0 };
struct btrfs_mkfs_config mkfs_cfg;
+ u32 version;
+
+ ret = get_sysfs_features(&sysfs_features);
+ if (ret) {
+ error("cannot find defaults, no /sys/fs/btrfs");
+ exit(1);
+ }
+ btrfs_parse_features_to_string(features_buf, sysfs_features);
+ version = get_running_kernel_version();
+ features = set_default_features_by_version(version);
+ btrfs_parse_features_to_string(features_buf, features);
+ features &= sysfs_features;
+ btrfs_parse_features_to_string(features_buf, features);
while(1) {
int c;
@@ -1442,7 +1457,6 @@ int main(int argc, char **argv)
free(orig);
if (features & BTRFS_FEATURE_LIST_ALL) {
u64 detected;
- char features_buf[64];
btrfs_list_all_fs_features(0);
ret = get_sysfs_features(&detected);
@@ -1684,6 +1698,13 @@ int main(int argc, char **argv)
"WARNING: metatdata has lower redundancy than data!\n\n");
}
+ /* TODO: add to summary */
+ /* Running wants more defaults than sysfs allows */
+ if (features & ~sysfs_features) {
+ btrfs_parse_features_to_string(features_buf, features & ~sysfs_features);
+ warning("requesting features that running kernel does not support: %s\n", features_buf);
+ }
+
mkfs_cfg.label = label;
mkfs_cfg.fs_uuid = fs_uuid;
memcpy(mkfs_cfg.blocks, blocks, sizeof(blocks));
@@ -1821,8 +1842,6 @@ raid_groups:
}
if (verbose) {
- char features_buf[64];
-
printf("Label: %s\n", label);
printf("UUID: %s\n", fs_uuid);
printf("Node size: %u\n", nodesize);
diff --git a/utils.c b/utils.c
index 0c9def0..1cd3a8b 100644
--- a/utils.c
+++ b/utils.c
@@ -851,6 +851,20 @@ int get_sysfs_features(u64 *features)
return 0;
}
+u64 set_default_features_by_version(u32 version)
+{
+ u64 features = 0;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(mkfs_features) - 1; i++) {
+ if (mkfs_features[i].default_ver &&
+ mkfs_features[i].default_ver < version)
+ features |= mkfs_features[i].flag;
+ }
+
+ return features;
+}
+
u64 btrfs_device_size(int fd, struct stat *st)
{
u64 size;
diff --git a/utils.h b/utils.h
index 55530ba..ff314f4 100644
--- a/utils.h
+++ b/utils.h
@@ -111,6 +111,7 @@ const char *min_default_version(u64 features);
void print_kernel_version(FILE *stream, u32 version);
u32 get_running_kernel_version(void);
int get_sysfs_features(u64 *features);
+u64 set_default_features_by_version(u32 version);
struct btrfs_mkfs_config {
char *label;