__le32 sectorsize;
__le32 nodesize;
__le32 leafsize;
+ __le32 stripesize;
u8 root_level;
} __attribute__ ((__packed__));
/* leaf allocations are done in leafsize units */
u32 leafsize;
+ /* leaf allocations are done in leafsize units */
+ u32 stripesize;
+
int ref_cows;
u32 type;
};
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);
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));
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:
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;
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:
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;
}
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;
}
}
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;
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);
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) {
case 'n':
nodesize = atol(optarg);
break;
+ case 's':
+ stripesize = atol(optarg);
+ break;
default:
print_usage();
}
}
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);