summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-11-30 11:30:24 -0500
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-11-30 11:30:24 -0500
commit1883251686b1de012e909c4459deceff1f95a96c (patch)
tree4434ca0e314fa0d117b1833fcd5f5cdf347c49e2
parente3815ddde6e8ffdc7bec54a04611cfc243862372 (diff)
Add simple stripe size parameter
-rw-r--r--ctree.h15
-rw-r--r--disk-io.c1
-rw-r--r--extent-tree.c27
-rw-r--r--mkfs.c11
4 files changed, 44 insertions, 10 deletions
diff --git a/ctree.h b/ctree.h
index 2f55b15e..fb972c1d 100644
--- a/ctree.h
+++ b/ctree.h
@@ -122,6 +122,7 @@ struct btrfs_super_block {
__le32 sectorsize;
__le32 nodesize;
__le32 leafsize;
+ __le32 stripesize;
u8 root_level;
} __attribute__ ((__packed__));
@@ -324,6 +325,9 @@ struct btrfs_root {
/* leaf allocations are done in leafsize units */
u32 leafsize;
+ /* leaf allocations are done in leafsize units */
+ u32 stripesize;
+
int ref_cows;
u32 type;
};
@@ -903,6 +907,17 @@ static inline void btrfs_set_super_leafsize(struct btrfs_super_block *s,
s->leafsize = cpu_to_le32(val);
}
+static inline u32 btrfs_super_stripesize(struct btrfs_super_block *s)
+{
+ return le32_to_cpu(s->stripesize);
+}
+
+static inline void btrfs_set_super_stripesize(struct btrfs_super_block *s,
+ u32 val)
+{
+ s->stripesize = cpu_to_le32(val);
+}
+
static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
{
return le64_to_cpu(s->root_dir_objectid);
diff --git a/disk-io.c b/disk-io.c
index df770407..026cdfde 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -320,6 +320,7 @@ static int __setup_root(struct btrfs_super_block *super,
root->sectorsize = btrfs_super_sectorsize(super);
root->nodesize = btrfs_super_nodesize(super);
root->leafsize = btrfs_super_leafsize(super);
+ root->stripesize = btrfs_super_stripesize(super);
root->ref_cows = 0;
root->fs_info = fs_info;
memset(&root->root_key, 0, sizeof(root->root_key));
diff --git a/extent-tree.c b/extent-tree.c
index 8f7dc068..8615a432 100644
--- a/extent-tree.c
+++ b/extent-tree.c
@@ -372,6 +372,13 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
return ret ? ret : pending_ret;
}
+static u64 stripe_align(struct btrfs_root *root, u64 val)
+{
+ u64 mask = ((u64)root->stripesize - 1);
+ u64 ret = (val + mask) & ~mask;
+ return ret;
+}
+
/*
* walks the btree of allocated extents and find a hole of a given size.
* The key ins is changed to record the hole:
@@ -390,6 +397,7 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
u64 hole_size = 0;
int slot = 0;
u64 last_byte = 0;
+ u64 aligned;
int start_found;
struct btrfs_leaf *l;
struct btrfs_root * root = orig_root->fs_info->extent_root;
@@ -397,6 +405,7 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
if (root->fs_info->last_insert.objectid > search_start)
search_start = root->fs_info->last_insert.objectid;
+ search_start = stripe_align(root, search_start);
btrfs_set_key_type(ins, BTRFS_EXTENT_ITEM_KEY);
check_failed:
@@ -421,13 +430,15 @@ check_failed:
if (ret < 0)
goto error;
if (!start_found) {
- ins->objectid = search_start;
- ins->offset = (u64)-1 - search_start;
+ aligned = stripe_align(root, search_start);
+ ins->objectid = aligned;
+ ins->offset = (u64)-1 - aligned;
start_found = 1;
goto check_pending;
}
- ins->objectid = last_byte > search_start ?
- last_byte : search_start;
+ ins->objectid = stripe_align(root,
+ last_byte > search_start ?
+ last_byte : search_start);
ins->offset = (u64)-1 - ins->objectid;
goto check_pending;
}
@@ -438,9 +449,11 @@ check_failed:
if (start_found) {
if (last_byte < search_start)
last_byte = search_start;
- hole_size = key.objectid - last_byte;
- if (hole_size > total_needed) {
- ins->objectid = last_byte;
+ aligned = stripe_align(root, last_byte);
+ hole_size = key.objectid - aligned;
+ if (key.objectid > aligned &&
+ hole_size > total_needed) {
+ ins->objectid = aligned;
ins->offset = hole_size;
goto check_pending;
}
diff --git a/mkfs.c b/mkfs.c
index 1f1519e7..044117a8 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -180,7 +180,7 @@ err:
}
int mkfs(int fd, char *pathname, u64 num_bytes, u32 nodesize, u32 leafsize,
- u32 sectorsize)
+ u32 sectorsize, u32 stripesize)
{
struct btrfs_super_block super;
struct btrfs_leaf *empty_leaf;
@@ -204,6 +204,7 @@ printf("blocksize is %d\n", leafsize);
btrfs_set_super_sectorsize(&super, sectorsize);
btrfs_set_super_leafsize(&super, leafsize);
btrfs_set_super_nodesize(&super, nodesize);
+ btrfs_set_super_stripesize(&super, stripesize);
num_bytes = (num_bytes / sectorsize) * sectorsize;
btrfs_set_super_total_bytes(&super, num_bytes);
@@ -353,12 +354,13 @@ int main(int ac, char **av)
u32 leafsize = 8 * 1024;
u32 sectorsize = 4096;
u32 nodesize = 8 * 1024;
+ u32 stripesize = 4096;
char *buf = malloc(sectorsize);
char *realpath_name;
while(1) {
int c;
- c = getopt(ac, av, "l:n:");
+ c = getopt(ac, av, "l:n:s:");
if (c < 0)
break;
switch(c) {
@@ -368,6 +370,9 @@ int main(int ac, char **av)
case 'n':
nodesize = atol(optarg);
break;
+ case 's':
+ stripesize = atol(optarg);
+ break;
default:
print_usage();
}
@@ -426,7 +431,7 @@ int main(int ac, char **av)
}
realpath_name = realpath(file, NULL);
ret = mkfs(fd, realpath_name, block_count, nodesize, leafsize,
- sectorsize);
+ sectorsize, stripesize);
if (ret) {
fprintf(stderr, "error during mkfs %d\n", ret);
exit(1);