All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] btrfs-progs: force mixed groups when -r rootdir is small
@ 2014-08-13  0:13 Guangyu Sun
  2014-08-13  0:13 ` [PATCH 2/2] btrfs-progs: don't zero dev if dev size is smaller than -r rootdir size Guangyu Sun
  0 siblings, 1 reply; 2+ messages in thread
From: Guangyu Sun @ 2014-08-13  0:13 UTC (permalink / raw)
  To: linux-btrfs

mkfs.btrfs did not force mixed data/metadata groups if the size of
rootdir given by -r option is small.

 # mkdir -p /tmp/mydir
 # echo "aaa" > /tmp/mydir/myfile
 # mkfs.btrfs -f -r /tmp/mydir /dev/sdb1
 ...
 fs created label (null) on /dev/sdb1
 	nodesize 16384 leafsize 16384 sectorsize 4096 size 28.00MiB
 ...

leafsize and sectorsize are different means it is not using mixed
groups.

after this patch:

 # mkfs.btrfs -f -r /tmp/mydir /dev/sdb1
 ...
 Turning ON incompat feature 'mixed-bg': mixed data and metadata block
 groups
 ...
 fs created label (null) on /dev/sdb1
 	nodesize 4096 leafsize 4096 sectorsize 4096 size 28.00MiB
 ...

Also the size check in option -b is inconsistent with other similar
size checks in utils.c. Make it consistent by removing '='.

Signed-off-by: Guangyu Sun <guangyu.sun@oracle.com>
---
 mkfs.c |   21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/mkfs.c b/mkfs.c
index 16e9222..71aea40 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1332,11 +1332,6 @@ int main(int ac, char **av)
 				break;
 			case 'b':
 				block_count = parse_size(optarg);
-				if (block_count <= 1024*1024*1024) {
-					printf("SMALL VOLUME: forcing mixed "
-					       "metadata/data groups\n");
-					mixed = 1;
-				}
 				zero_end = 0;
 				break;
 			case 'V':
@@ -1388,6 +1383,18 @@ int main(int ac, char **av)
 		mixed = 1;
 	}
 
+	if (source_dir_set) {
+		source_dir_size = size_sourcedir(source_dir, sectorsize,
+					     &num_of_meta_chunks, &size_of_data);
+		if (block_count < source_dir_size)
+			block_count = source_dir_size;
+	}
+
+	if (block_count && block_count < 1024 * 1024 * 1024 && !mixed) {
+		printf("SMALL VOLUME: forcing mixed metadata/data groups\n");
+		mixed = 1;
+	}
+
 	/*
 	* Set default profiles according to number of added devices.
 	* For mixed groups defaults are single/single.
@@ -1475,10 +1482,6 @@ int main(int ac, char **av)
 		}
 
 		first_file = file;
-		source_dir_size = size_sourcedir(source_dir, sectorsize,
-					     &num_of_meta_chunks, &size_of_data);
-		if(block_count < source_dir_size)
-			block_count = source_dir_size;
 		ret = zero_output_file(fd, block_count, sectorsize);
 		if (ret) {
 			fprintf(stderr, "unable to zero the output file\n");
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] btrfs-progs: don't zero dev if dev size is smaller than -r rootdir size
  2014-08-13  0:13 [PATCH 1/2] btrfs-progs: force mixed groups when -r rootdir is small Guangyu Sun
@ 2014-08-13  0:13 ` Guangyu Sun
  0 siblings, 0 replies; 2+ messages in thread
From: Guangyu Sun @ 2014-08-13  0:13 UTC (permalink / raw)
  To: linux-btrfs

Even if the size of rootdir given by -r option is larger than the
specified partition, zero_output_file() is still called. It will take
time to fill up the partition with zero if the partition is big, and
end up with an EIO.

The size should be checked before zeroing the partition.

Signed-off-by: Guangyu Sun <guangyu.sun@oracle.com>
---
 mkfs.c |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/mkfs.c b/mkfs.c
index 71aea40..ea61180 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1475,12 +1475,31 @@ int main(int ac, char **av)
 			exit(1);
 		}
 	} else {
+		struct stat st;
+		u64 size;
+
 		fd = open_target(file);
 		if (fd < 0) {
 			fprintf(stderr, "unable to open the %s\n", file);
 			exit(1);
 		}
 
+		if (fstat(fd, &st) < 0) {
+			fprintf(stderr, "unable to stat %s\n", file);
+			exit(1);
+		}
+
+		size = btrfs_device_size(fd, &st);
+		if (size == 0) {
+			fprintf(stderr, "unable to find %s size\n", file);
+			exit(1);
+		}
+
+		if (size < block_count) {
+			fprintf(stderr, "%s is smaller than requested size\n", file);
+			exit(1);
+		}
+
 		first_file = file;
 		ret = zero_output_file(fd, block_count, sectorsize);
 		if (ret) {
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-08-13  0:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-13  0:13 [PATCH 1/2] btrfs-progs: force mixed groups when -r rootdir is small Guangyu Sun
2014-08-13  0:13 ` [PATCH 2/2] btrfs-progs: don't zero dev if dev size is smaller than -r rootdir size Guangyu Sun

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.