Skip to contentSkip to conversation

btrfs-progs: btrfs-convert: Allow setting nodesize

PATCH In review Sebastian Thorarensen 2 participants 6 messages Mar 20, 2015 – Mar 23, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover btrfs-progs: btrfs-convert: Allow setting nodesize

Changes since v1:
* Split patch into smaller patches
* btrfs-convert and mkfs now shares check_node_or_leaf_size
* Rebased onto latest v3.19.x

Sebastian Thorarensen (4):
btrfs-progs: mkfs: Move out some nodesize code
btrfs-progs: Fix msgs in check_node_or_leaf_size
btrfs-progs: btrfs-convert: Allow setting nodesize
btrfs-progs: Add nodesize test for btrfs-convert

 Documentation/btrfs-convert.txt |    4 +++
 btrfs-convert.c                 |   60 ++++++++++++++++++++++++++++++++++-----
 mkfs.c                          |   26 ++---------------
 tests/convert-tests.sh          |   15 ++++++----
 utils.c                         |   21 ++++++++++++++
 utils.h                         |    2 ++
 6 files changed, 92 insertions(+), 36 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v2 1/4 btrfs-progs: mkfs: Move out some nodesize code

Move the constant DEFAULT_MKFS_LEAF_SIZE to utils.h and rename it to BTRFS_MKFS_DEFAULT_NODE_SIZE for consistency. Move the function check_leaf_or_node_size to utils.c and rename it to check_node_or_leaf_size.

---
 mkfs.c  |   26 ++------------------------
 utils.c |   21 +++++++++++++++++++++
 utils.h |    2 ++
 3 files changed, 25 insertions(+), 24 deletions(-)
mkfs.c +2 -24
index f83554d..b846090 100644
@@ -47,8 +47,6 @@ static u64 index_cnt = 2;
 #define DEFAULT_MKFS_FEATURES	(BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF \
 		| BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA)
 
-#define DEFAULT_MKFS_LEAF_SIZE 16384
-
 struct directory_name_entry {
 	char *dir_name;
 	char *path;
@@ -1057,27 +1055,6 @@ static int zero_output_file(int out_fd, u64 size, u32 sectorsize)
 	return ret;
 }
 
-static int check_leaf_or_node_size(u32 size, u32 sectorsize)
-{
-	if (size < sectorsize) {
-		fprintf(stderr,
-			"Illegal leafsize (or nodesize) %u (smaller than %u)\n",
-			size, sectorsize);
-		return -1;
-	} else if (size > BTRFS_MAX_METADATA_BLOCKSIZE) {
-		fprintf(stderr,
-			"Illegal leafsize (or nodesize) %u (larger than %u)\n",
-			size, BTRFS_MAX_METADATA_BLOCKSIZE);
-		return -1;
-	} else if (size & (sectorsize - 1)) {
-		fprintf(stderr,
-			"Illegal leafsize (or nodesize) %u (not align to %u)\n",
-			size, sectorsize);
-		return -1;
-	}
-	return 0;
-}
-
 static int is_ssd(const char *file)
 {
 	blkid_probe probe;
@@ -1230,7 +1207,8 @@ int main(int ac, char **av)
 	u64 alloc_start = 0;
 	u64 metadata_profile = 0;
 	u64 data_profile = 0;
-	u32 leafsize = max_t(u32, sysconf(_SC_PAGESIZE), DEFAULT_MKFS_LEAF_SIZE);
+	u32 leafsize = max_t(u32, sysconf(_SC_PAGESIZE),
+			BTRFS_MKFS_DEFAULT_NODE_SIZE);
 	u32 sectorsize = 4096;
 	u32 nodesize = leafsize;
 	u32 stripesize = 4096;
utils.c +21 -0
index 6228c7f..ba01e0c 100644
@@ -2720,3 +2720,24 @@ int btrfs_tree_search2_ioctl_supported(int fd)
 
 	return v2_supported;
 }
+
+int check_node_or_leaf_size(u32 size, u32 sectorsize)
+{
+	if (size < sectorsize) {
+		fprintf(stderr,
+			"Illegal leafsize (or nodesize) %u (smaller than %u)\n",
+			size, sectorsize);
+		return -1;
+	} else if (size > BTRFS_MAX_METADATA_BLOCKSIZE) {
+		fprintf(stderr,
+			"Illegal leafsize (or nodesize) %u (larger than %u)\n",
+			size, BTRFS_MAX_METADATA_BLOCKSIZE);
+		return -1;
+	} else if (size & (sectorsize - 1)) {
+		fprintf(stderr,
+			"Illegal leafsize (or nodesize) %u (not align to %u)\n",
+			size, sectorsize);
+		return -1;
+	}
+	return 0;
+}
utils.h +2 -0
index 82ab5e8..30b6a57 100644
@@ -25,6 +25,7 @@
 
 #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024)
 #define BTRFS_MKFS_SMALL_VOLUME_SIZE (1024 * 1024 * 1024)
+#define BTRFS_MKFS_DEFAULT_NODE_SIZE 16384
 
 #define BTRFS_SCAN_MOUNTED	(1ULL << 0)
 #define BTRFS_SCAN_LBLKID	(1ULL << 1)
@@ -208,5 +209,6 @@ static inline u64 div_factor(u64 num, int factor)
 }
 
 int btrfs_tree_search2_ioctl_supported(int fd);
+int check_node_or_leaf_size(u32 size, u32 sectorsize);
 
 #endif
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH v2 2/4 btrfs-progs: Fix msgs in check_node_or_leaf_size

In reply to Sebastian Thorarensen

check_node_or_leaf_size in utils.c now prints 'nodesize (or leafsize)' instead of 'leafsize (or nodesize)' in the error messages, in order to be less confusing for the user, as leafsize in mkfs is deprecated. 'ERROR: ' is also prepended to be consistent with other error messages.

---
 utils.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
utils.c +3 -3
index ba01e0c..ffd3e6e 100644
@@ -2725,17 +2725,17 @@ int check_node_or_leaf_size(u32 size, u32 sectorsize)
 {
 	if (size < sectorsize) {
 		fprintf(stderr,
-			"Illegal leafsize (or nodesize) %u (smaller than %u)\n",
+			"ERROR: Illegal nodesize (or leafsize) %u (smaller than %u)\n",
 			size, sectorsize);
 		return -1;
 	} else if (size > BTRFS_MAX_METADATA_BLOCKSIZE) {
 		fprintf(stderr,
-			"Illegal leafsize (or nodesize) %u (larger than %u)\n",
+			"ERROR: Illegal nodesize (or leafsize) %u (larger than %u)\n",
 			size, BTRFS_MAX_METADATA_BLOCKSIZE);
 		return -1;
 	} else if (size & (sectorsize - 1)) {
 		fprintf(stderr,
-			"Illegal leafsize (or nodesize) %u (not align to %u)\n",
+			"ERROR: Illegal nodesize (or leafsize) %u (not aligned to %u)\n",
 			size, sectorsize);
 		return -1;
 	}
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH v2 3/4 btrfs-progs: btrfs-convert: Allow setting nodesize

In reply to Sebastian Thorarensen

Allow btrfs-convert to use nodesizes other than 4096. It defaults to max(16384, pagesize), like mkfs.

---
 Documentation/btrfs-convert.txt |    4 +++
 btrfs-convert.c                 |   60 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 57 insertions(+), 7 deletions(-)
Documentation/btrfs-convert.txt +4 -0
index 6a9e1de..89b2fbd 100644
@@ -23,6 +23,10 @@ Disable data checksum.
 Ignore xattrs and ACLs.
 -n::
 Disable packing of small files.
+-N <SIZE>::
+Set filesystem nodesize, the tree block size in which btrfs stores data.
+The default value is 16KB (16384) or the page size, whichever is bigger.
+Must be a multiple of the sectorsize, but not larger than 65536.
 -r::
 Roll back to ext2fs.
 -l <LABEL>::
btrfs-convert.c +53 -7

128 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#4 lore raw

PATCH v2 4/4 btrfs-progs: Add nodesize test for btrfs-convert

In reply to Sebastian Thorarensen

convert-tests now test both 4096 and 16384 nodesizes.

---
 tests/convert-tests.sh |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
tests/convert-tests.sh +10 -5
index 6094287..3d912f3 100644
@@ -16,7 +16,8 @@ rm -f convert-tests-results.txt
 
 test(){
 	echo "    [TEST]   $1"
-	shift
+	nodesize=$2
+	shift 2
 	echo "creating ext image with: $*" >> convert-tests-results.txt
 	# 256MB is the smallest acceptable btrfs image.
 	rm -f $here/test.img >> convert-tests-results.txt 2>&1 \
@@ -25,13 +26,17 @@ test(){
 		|| _fail "could not create test image file"
 	$* -F $here/test.img >> convert-tests-results.txt 2>&1 \
 		|| _fail "filesystem create failed"
-	$here/btrfs-convert $here/test.img >> convert-tests-results.txt 2>&1 \
+	$here/btrfs-convert -N "$nodesize" $here/test.img \
+			>> convert-tests-results.txt 2>&1 \
 		|| _fail "btrfs-convert failed"
 	$here/btrfs check $here/test.img >> convert-tests-results.txt 2>&1 \
 		|| _fail "btrfs check detected errors"
 }
 
 # btrfs-convert requires 4k blocksize.
-test "ext2" mke2fs -b 4096
-test "ext3" mke2fs -j -b 4096
-test "ext4" mke2fs -t ext4 -b 4096
+test "ext2 4k nodesize" 4096 mke2fs -b 4096
+test "ext3 4k nodesize" 4096 mke2fs -j -b 4096
+test "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096
+test "ext2 16k nodesize" 16384 mke2fs -b 4096
+test "ext3 16k nodesize" 16384 mke2fs -j -b 4096
+test "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096
Signature · 1 line
1.7.10.4
#5 lore raw
In reply to Sebastian Thorarensen
Quoted 4 lines · Sebastian Thorarensen

Changes since v1:
* Split patch into smaller patches
* btrfs-convert and mkfs now shares check_node_or_leaf_size
* Rebased onto latest v3.19.x

Thanks! Minor changes: I've fixed build failure of mkfs, added btrfs_ prefix to the function (as it's now in utils.c) and added the remaining nodesizes to tests. Queued for 3.19.1.