sweettea / rpms / btrfs-progs

Forked from rpms/btrfs-progs 9 months ago
Clone

Blame Btrfs-progs-only-enforce-a-maximum-size-if-we-specif.patch

Josef Bacik b5e03c
From cbe7ca77431c40bab80135c7b8ee6a5dece56e03 Mon Sep 17 00:00:00 2001
Josef Bacik b5e03c
From: Josef Bacik <jbacik@fusionio.com>
Josef Bacik b5e03c
Date: Fri, 27 Jul 2012 08:24:37 -0400
Josef Bacik b5e03c
Subject: [PATCH 3/3] Btrfs-progs: only enforce a maximum size if we specify
Josef Bacik b5e03c
 one
Josef Bacik b5e03c
Josef Bacik b5e03c
My patch
Josef Bacik b5e03c
Josef Bacik b5e03c
04609add88ef8428d725de6ef60f46a3ff0dbc8e
Josef Bacik b5e03c
Josef Bacik b5e03c
introduced a regression where if you mkfs'ed a group of disks with different
Josef Bacik b5e03c
sizes it limited the disks to the size of the first one that is specified.
Josef Bacik b5e03c
This was not the intent of my patch, I only want it to limit the size based
Josef Bacik b5e03c
on the -b option, so I've reworked the code to pass in a max block count and
Josef Bacik b5e03c
that fixes the issue.  Thanks,
Josef Bacik b5e03c
Josef Bacik b5e03c
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Josef Bacik b5e03c
---
Josef Bacik b5e03c
 btrfs-vol.c   |    3 ++-
Josef Bacik b5e03c
 cmds-device.c |    3 ++-
Josef Bacik b5e03c
 mkfs.c        |   15 ++++++---------
Josef Bacik b5e03c
 utils.c       |   12 +++---------
Josef Bacik b5e03c
 utils.h       |    6 ++----
Josef Bacik b5e03c
 5 files changed, 15 insertions(+), 24 deletions(-)
Josef Bacik b5e03c
Josef Bacik b5e03c
diff --git a/btrfs-vol.c b/btrfs-vol.c
Josef Bacik b5e03c
index 0efdbc1..ad824bd 100644
Josef Bacik b5e03c
--- a/btrfs-vol.c
Josef Bacik b5e03c
+++ b/btrfs-vol.c
Josef Bacik b5e03c
@@ -150,7 +150,8 @@ int main(int ac, char **av)
Josef Bacik b5e03c
 	if (cmd == BTRFS_IOC_ADD_DEV) {
Josef Bacik b5e03c
 		int mixed = 0;
Josef Bacik b5e03c
 
Josef Bacik b5e03c
-		ret = btrfs_prepare_device(devfd, device, 1, &dev_block_count, &mixed);
Josef Bacik b5e03c
+		ret = btrfs_prepare_device(devfd, device, 1, &dev_block_count,
Josef Bacik b5e03c
+					   0, &mixed, 0);
Josef Bacik b5e03c
 		if (ret) {
Josef Bacik b5e03c
 			fprintf(stderr, "Unable to init %s\n", device);
Josef Bacik b5e03c
 			exit(1);
Josef Bacik b5e03c
diff --git a/cmds-device.c b/cmds-device.c
Josef Bacik b5e03c
index b24e2a3..75ee293 100644
Josef Bacik b5e03c
--- a/cmds-device.c
Josef Bacik b5e03c
+++ b/cmds-device.c
Josef Bacik b5e03c
@@ -107,7 +107,8 @@ static int cmd_add_dev(int argc, char **argv)
Josef Bacik b5e03c
 			continue;
Josef Bacik b5e03c
 		}
Josef Bacik b5e03c
 
Josef Bacik b5e03c
-		res = btrfs_prepare_device(devfd, argv[i], 1, &dev_block_count, &mixed);
Josef Bacik b5e03c
+		res = btrfs_prepare_device(devfd, argv[i], 1, &dev_block_count,
Josef Bacik b5e03c
+					   0, &mixed, 0);
Josef Bacik b5e03c
 		if (res) {
Josef Bacik b5e03c
 			fprintf(stderr, "ERROR: Unable to init '%s'\n", argv[i]);
Josef Bacik b5e03c
 			close(devfd);
Josef Bacik b5e03c
diff --git a/mkfs.c b/mkfs.c
Josef Bacik b5e03c
index 8816db8..93cd83c 100644
Josef Bacik b5e03c
--- a/mkfs.c
Josef Bacik b5e03c
+++ b/mkfs.c
Josef Bacik b5e03c
@@ -1373,11 +1373,9 @@ int main(int ac, char **av)
Josef Bacik b5e03c
 			exit(1);
Josef Bacik b5e03c
 		}
Josef Bacik b5e03c
 		first_file = file;
Josef Bacik b5e03c
-		ret = __btrfs_prepare_device(fd, file, zero_end,
Josef Bacik b5e03c
-				&dev_block_count, &mixed, nodiscard);
Josef Bacik b5e03c
-		if (block_count == 0)
Josef Bacik b5e03c
-			block_count = dev_block_count;
Josef Bacik b5e03c
-		else if (block_count > dev_block_count) {
Josef Bacik b5e03c
+		ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count,
Josef Bacik b5e03c
+					   block_count, &mixed, nodiscard);
Josef Bacik b5e03c
+		if (block_count && block_count > dev_block_count) {
Josef Bacik b5e03c
 			fprintf(stderr, "%s is smaller than requested size\n", file);
Josef Bacik b5e03c
 			exit(1);
Josef Bacik b5e03c
 		}
Josef Bacik b5e03c
@@ -1418,7 +1416,7 @@ int main(int ac, char **av)
Josef Bacik b5e03c
 			leafsize * i;
Josef Bacik b5e03c
 	}
Josef Bacik b5e03c
 
Josef Bacik b5e03c
-	ret = make_btrfs(fd, file, label, blocks, block_count,
Josef Bacik b5e03c
+	ret = make_btrfs(fd, file, label, blocks, dev_block_count,
Josef Bacik b5e03c
 			 nodesize, leafsize,
Josef Bacik b5e03c
 			 sectorsize, stripesize);
Josef Bacik b5e03c
 	if (ret) {
Josef Bacik b5e03c
@@ -1474,9 +1472,8 @@ int main(int ac, char **av)
Josef Bacik b5e03c
 			close(fd);
Josef Bacik b5e03c
 			continue;
Josef Bacik b5e03c
 		}
Josef Bacik b5e03c
-		dev_block_count = block_count;
Josef Bacik b5e03c
-		ret = __btrfs_prepare_device(fd, file, zero_end,
Josef Bacik b5e03c
-					   &dev_block_count, &mixed, nodiscard);
Josef Bacik b5e03c
+		ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count,
Josef Bacik b5e03c
+					   block_count, &mixed, nodiscard);
Josef Bacik b5e03c
 		mixed = old_mixed;
Josef Bacik b5e03c
 		BUG_ON(ret);
Josef Bacik b5e03c
 
Josef Bacik b5e03c
diff --git a/utils.c b/utils.c
Josef Bacik b5e03c
index aade9e2..a5ffb62 100644
Josef Bacik b5e03c
--- a/utils.c
Josef Bacik b5e03c
+++ b/utils.c
Josef Bacik b5e03c
@@ -537,13 +537,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
Josef Bacik b5e03c
 }
Josef Bacik b5e03c
 
Josef Bacik b5e03c
 int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
Josef Bacik b5e03c
-			 int *mixed)
Josef Bacik b5e03c
-{
Josef Bacik b5e03c
-	/* discard by default when called from 'device add' */
Josef Bacik b5e03c
-	return __btrfs_prepare_device(fd, file, zero_end, block_count_ret, mixed, 0);
Josef Bacik b5e03c
-}
Josef Bacik b5e03c
-int __btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
Josef Bacik b5e03c
-			 int *mixed, int nodiscard)
Josef Bacik b5e03c
+			   u64 max_block_count, int *mixed, int nodiscard)
Josef Bacik b5e03c
 {
Josef Bacik b5e03c
 	u64 block_count;
Josef Bacik b5e03c
 	u64 bytenr;
Josef Bacik b5e03c
@@ -561,8 +555,8 @@ int __btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_re
Josef Bacik b5e03c
 		fprintf(stderr, "unable to find %s size\n", file);
Josef Bacik b5e03c
 		exit(1);
Josef Bacik b5e03c
 	}
Josef Bacik b5e03c
-	if (*block_count_ret)
Josef Bacik b5e03c
-		block_count = min(block_count, *block_count_ret);
Josef Bacik b5e03c
+	if (max_block_count)
Josef Bacik b5e03c
+		block_count = min(block_count, max_block_count);
Josef Bacik b5e03c
 	zero_end = 1;
Josef Bacik b5e03c
 
Josef Bacik b5e03c
 	if (block_count < 1024 * 1024 * 1024 && !(*mixed)) {
Josef Bacik b5e03c
diff --git a/utils.h b/utils.h
Josef Bacik b5e03c
index c147c12..3a0368b 100644
Josef Bacik b5e03c
--- a/utils.h
Josef Bacik b5e03c
+++ b/utils.h
Josef Bacik b5e03c
@@ -26,10 +26,8 @@ int make_btrfs(int fd, const char *device, const char *label,
Josef Bacik b5e03c
 	       u32 leafsize, u32 sectorsize, u32 stripesize);
Josef Bacik b5e03c
 int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
Josef Bacik b5e03c
 			struct btrfs_root *root, u64 objectid);
Josef Bacik b5e03c
-int btrfs_prepare_device(int fd, char *file, int zero_end,
Josef Bacik b5e03c
-			 u64 *block_count_ret, int *mixed);
Josef Bacik b5e03c
-int __btrfs_prepare_device(int fd, char *file, int zero_end,
Josef Bacik b5e03c
-			 u64 *block_count_ret, int *mixed, int nodiscard);
Josef Bacik b5e03c
+int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
Josef Bacik b5e03c
+			 u64 max_block_count, int *mixed, int nodiscard);
Josef Bacik b5e03c
 int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
Josef Bacik b5e03c
 		      struct btrfs_root *root, int fd, char *path,
Josef Bacik b5e03c
 		      u64 block_count, u32 io_width, u32 io_align,
Josef Bacik b5e03c
-- 
Josef Bacik b5e03c
1.7.7.6
Josef Bacik b5e03c