borisb / rpms / btrfs-progs

Forked from rpms/btrfs-progs 2 years ago
Clone
Blob Blame History Raw
From fcd0fd043749cd2623a918cf9862d10e2a227ae4 Mon Sep 17 00:00:00 2001
From: David Sterba <dsterba@suse.com>
Date: Tue, 21 Jul 2020 12:13:27 +0200
Subject: [PATCH 1/2] btrfs-progs: mkfs: clean up default profile settings

Extract the defaults for data and metadata profiles to a header and
use the symbolic names instead of hardcoding the profiles.

Signed-off-by: David Sterba <dsterba@suse.com>
(cherry picked from commit 071cb030a41fde2cab07217b52ba7c86b72fb8d8)
---
 mkfs/common.h | 10 ++++++++++
 mkfs/main.c   | 21 ++++++++++++++++-----
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/mkfs/common.h b/mkfs/common.h
index 426852be..61969dcc 100644
--- a/mkfs/common.h
+++ b/mkfs/common.h
@@ -28,6 +28,16 @@
 #define BTRFS_MKFS_SYSTEM_GROUP_SIZE SZ_4M
 #define BTRFS_MKFS_SMALL_VOLUME_SIZE SZ_1G
 
+/*
+ * Default settings for block group types
+ */
+#define BTRFS_MKFS_DEFAULT_DATA_ONE_DEVICE	0	/* SINGLE */
+#define BTRFS_MKFS_DEFAULT_META_ONE_DEVICE	BTRFS_BLOCK_GROUP_DUP
+#define BTRFS_MKFS_DEFAULT_META_ONE_DEVICE_SSD	0	/* SINGLE */
+
+#define BTRFS_MKFS_DEFAULT_DATA_MULTI_DEVICE	BTRFS_BLOCK_GROUP_RAID0
+#define BTRFS_MKFS_DEFAULT_META_MULTI_DEVICE	BTRFS_BLOCK_GROUP_RAID1
+
 /*
  * Tree root blocks created during mkfs
  */
diff --git a/mkfs/main.c b/mkfs/main.c
index 0a4de617..6c9a24a4 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1144,19 +1144,30 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
 	* For mixed groups defaults are single/single.
 	*/
 	if (!mixed) {
+		u64 tmp;
+
 		if (!metadata_profile_opt) {
 			if (dev_cnt == 1 && ssd && verbose)
 				printf("Detected a SSD, turning off metadata "
 				"duplication.  Mkfs with -m dup if you want to "
 				"force metadata duplication.\n");
 
-			metadata_profile = (dev_cnt > 1) ?
-					BTRFS_BLOCK_GROUP_RAID1 : (ssd) ?
-					0: BTRFS_BLOCK_GROUP_DUP;
+			if (dev_cnt > 1) {
+				tmp = BTRFS_MKFS_DEFAULT_META_MULTI_DEVICE;
+			} else {
+				if (ssd)
+					tmp = BTRFS_MKFS_DEFAULT_META_ONE_DEVICE_SSD;
+				else
+					tmp = BTRFS_MKFS_DEFAULT_META_ONE_DEVICE;
+			}
+			metadata_profile = tmp;
 		}
 		if (!data_profile_opt) {
-			data_profile = (dev_cnt > 1) ?
-				BTRFS_BLOCK_GROUP_RAID0 : 0; /* raid0 or single */
+			if (dev_cnt > 1)
+				tmp = BTRFS_MKFS_DEFAULT_DATA_MULTI_DEVICE;
+			else
+				tmp = BTRFS_MKFS_DEFAULT_DATA_ONE_DEVICE;
+			data_profile = tmp;
 		}
 	} else {
 		u32 best_nodesize = max_t(u32, sysconf(_SC_PAGESIZE), sectorsize);
-- 
2.26.2