From 083faf794fd87a7897545a2a16a15599f62beffb Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Fri, 25 Apr 2008 16:55:21 -0400 Subject: Add mkfs.btrfs -A offset to control allocation start on devices This is a utility option for the resizer, it makes sure to allocate at offset bytes in the disk or higher. It ensures the resizer will have something to move when testing it. --- ctree.h | 1 + mkfs.c | 8 +++++++- volumes.c | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ctree.h b/ctree.h index 8de46083..d2853448 100644 --- a/ctree.h +++ b/ctree.h @@ -501,6 +501,7 @@ struct btrfs_fs_info { u64 data_alloc_profile; u64 metadata_alloc_profile; u64 system_alloc_profile; + u64 alloc_start; struct btrfs_trans_handle *running_transaction; struct btrfs_super_block super_copy; diff --git a/mkfs.c b/mkfs.c index 7317bcd3..ac81ab5a 100644 --- a/mkfs.c +++ b/mkfs.c @@ -280,6 +280,7 @@ static char *parse_label(char *input) } static struct option long_options[] = { + { "alloc-start", 1, NULL, 'A'}, { "byte-count", 1, NULL, 'b' }, { "leafsize", 1, NULL, 'l' }, { "label", 1, NULL, 'L'}, @@ -300,6 +301,7 @@ int main(int ac, char **av) u64 block_count = 0; u64 dev_block_count = 0; u64 blocks[6]; + u64 alloc_start; u64 metadata_profile = BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_DUP; u64 data_profile = BTRFS_BLOCK_GROUP_RAID0; u32 leafsize = getpagesize(); @@ -315,11 +317,14 @@ int main(int ac, char **av) while(1) { int c; - c = getopt_long(ac, av, "b:l:n:s:m:d:L:", long_options, + c = getopt_long(ac, av, "A:b:l:n:s:m:d:L:", long_options, &option_index); if (c < 0) break; switch(c) { + case 'A': + alloc_start = parse_size(optarg); + break; case 'd': data_profile = parse_profile(optarg); break; @@ -397,6 +402,7 @@ int main(int ac, char **av) exit(1); } root = open_ctree(file, 0); + root->fs_info->alloc_start = alloc_start; trans = btrfs_start_transaction(root, 1); if (ac == 0) diff --git a/volumes.c b/volumes.c index 0a9ee02c..2d04f643 100644 --- a/volumes.c +++ b/volumes.c @@ -252,6 +252,10 @@ static int find_free_dev_extent(struct btrfs_trans_handle *trans, * so we make sure to start at an offset of at least 1MB */ search_start = max((u64)1024 * 1024, search_start); + + if (root->fs_info->alloc_start + num_bytes <= device->total_bytes) + search_start = max(root->fs_info->alloc_start, search_start); + key.objectid = device->devid; key.offset = search_start; key.type = BTRFS_DEV_EXTENT_KEY; -- cgit v1.2.3