mirror of
https://github.com/kdave/btrfs-progs
synced 2025-01-12 16:59:51 +00:00
Remove the last radix tree (block_group_cache)
This commit is contained in:
parent
167388ab2b
commit
678af9b3a4
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
||||
CC=gcc
|
||||
CFLAGS = -g -Wall -fno-strict-aliasing -Werror
|
||||
CFLAGS = -g -Wall -fno-strict-aliasing -Werror -D_FILE_OFFSET_BITS=64
|
||||
objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
|
||||
root-tree.o dir-item.o hash.o file-item.o inode-item.o \
|
||||
inode-map.o crc32c.o rbtree.o extent-cache.o \
|
||||
|
4
ctree.h
4
ctree.h
@ -276,8 +276,10 @@ struct btrfs_block_group_item {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct btrfs_block_group_cache {
|
||||
struct cache_extent cache;
|
||||
struct btrfs_key key;
|
||||
struct btrfs_block_group_item item;
|
||||
int dirty;
|
||||
};
|
||||
|
||||
struct btrfs_fs_info {
|
||||
@ -286,7 +288,7 @@ struct btrfs_fs_info {
|
||||
struct btrfs_root *tree_root;
|
||||
struct btrfs_key last_insert;
|
||||
struct cache_tree extent_cache;
|
||||
struct radix_tree_root block_group_radix;
|
||||
struct cache_tree block_group_cache;
|
||||
struct cache_tree pending_tree;
|
||||
struct cache_tree pinned_tree;
|
||||
struct cache_tree del_pending;
|
||||
|
@ -377,13 +377,13 @@ struct btrfs_root *open_ctree_fd(int fp, struct btrfs_super_block *super)
|
||||
struct btrfs_fs_info *fs_info = malloc(sizeof(*fs_info));
|
||||
int ret;
|
||||
|
||||
INIT_RADIX_TREE(&fs_info->block_group_radix, GFP_KERNEL);
|
||||
INIT_LIST_HEAD(&fs_info->trans);
|
||||
INIT_LIST_HEAD(&fs_info->cache);
|
||||
cache_tree_init(&fs_info->extent_cache);
|
||||
cache_tree_init(&fs_info->pending_tree);
|
||||
cache_tree_init(&fs_info->pinned_tree);
|
||||
cache_tree_init(&fs_info->del_pending);
|
||||
cache_tree_init(&fs_info->block_group_cache);
|
||||
fs_info->cache_size = 0;
|
||||
fs_info->fp = fp;
|
||||
fs_info->running_transaction = NULL;
|
||||
|
@ -134,30 +134,29 @@ static int write_one_cache_group(struct btrfs_trans_handle *trans,
|
||||
int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_root *root)
|
||||
{
|
||||
struct btrfs_block_group_cache *cache[8];
|
||||
int ret;
|
||||
struct btrfs_block_group_cache *bg;
|
||||
struct cache_extent *cache;
|
||||
int err = 0;
|
||||
int werr = 0;
|
||||
struct radix_tree_root *radix = &root->fs_info->block_group_radix;
|
||||
int i;
|
||||
struct cache_tree *bg_cache = &root->fs_info->block_group_cache;
|
||||
struct btrfs_path path;
|
||||
btrfs_init_path(&path);
|
||||
u64 start = 0;
|
||||
|
||||
while(1) {
|
||||
ret = radix_tree_gang_lookup_tag(radix, (void *)cache,
|
||||
0, ARRAY_SIZE(cache),
|
||||
BTRFS_BLOCK_GROUP_DIRTY);
|
||||
if (!ret)
|
||||
cache = find_first_cache_extent(bg_cache, start);
|
||||
if (!cache)
|
||||
break;
|
||||
for (i = 0; i < ret; i++) {
|
||||
radix_tree_tag_clear(radix, cache[i]->key.objectid +
|
||||
cache[i]->key.offset -1,
|
||||
BTRFS_BLOCK_GROUP_DIRTY);
|
||||
bg = container_of(cache, struct btrfs_block_group_cache,
|
||||
cache);
|
||||
start = cache->start + cache->size;
|
||||
if (bg->dirty) {
|
||||
err = write_one_cache_group(trans, root,
|
||||
&path, cache[i]);
|
||||
&path, bg);
|
||||
if (err)
|
||||
werr = err;
|
||||
}
|
||||
bg->dirty = 0;
|
||||
}
|
||||
return werr;
|
||||
}
|
||||
@ -166,26 +165,25 @@ static int update_block_group(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_root *root,
|
||||
u64 bytenr, u64 num, int alloc)
|
||||
{
|
||||
struct btrfs_block_group_cache *cache;
|
||||
struct btrfs_block_group_cache *bg;
|
||||
struct cache_extent *cache;
|
||||
struct btrfs_fs_info *info = root->fs_info;
|
||||
u64 total = num;
|
||||
u64 old_val;
|
||||
u64 byte_in_group;
|
||||
int ret;
|
||||
|
||||
while(total) {
|
||||
ret = radix_tree_gang_lookup(&info->block_group_radix,
|
||||
(void *)&cache, bytenr, 1);
|
||||
if (!ret)
|
||||
cache = find_first_cache_extent(&info->block_group_cache,
|
||||
bytenr);
|
||||
if (!cache)
|
||||
return -1;
|
||||
radix_tree_tag_set(&info->block_group_radix,
|
||||
cache->key.objectid + cache->key.offset - 1,
|
||||
BTRFS_BLOCK_GROUP_DIRTY);
|
||||
|
||||
byte_in_group = bytenr - cache->key.objectid;
|
||||
old_val = btrfs_block_group_used(&cache->item);
|
||||
if (total > cache->key.offset - byte_in_group)
|
||||
num = cache->key.offset - byte_in_group;
|
||||
bg = container_of(cache, struct btrfs_block_group_cache,
|
||||
cache);
|
||||
bg->dirty = 1;
|
||||
byte_in_group = bytenr - bg->key.objectid;
|
||||
old_val = btrfs_block_group_used(&bg->item);
|
||||
if (total > bg->key.offset - byte_in_group)
|
||||
num = bg->key.offset - byte_in_group;
|
||||
else
|
||||
num = total;
|
||||
total -= num;
|
||||
@ -194,7 +192,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,
|
||||
old_val += num;
|
||||
else
|
||||
old_val -= num;
|
||||
btrfs_set_block_group_used(&cache->item, old_val);
|
||||
btrfs_set_block_group_used(&bg->item, old_val);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -688,22 +686,17 @@ int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
|
||||
|
||||
int btrfs_free_block_groups(struct btrfs_fs_info *info)
|
||||
{
|
||||
int ret;
|
||||
struct btrfs_block_group_cache *cache[8];
|
||||
int i;
|
||||
struct btrfs_block_group_cache *bg;
|
||||
struct cache_extent *cache;
|
||||
|
||||
while(1) {
|
||||
ret = radix_tree_gang_lookup(&info->block_group_radix,
|
||||
(void *)cache, 0,
|
||||
ARRAY_SIZE(cache));
|
||||
if (!ret)
|
||||
cache = find_first_cache_extent(&info->block_group_cache, 0);
|
||||
if (!cache)
|
||||
break;
|
||||
for (i = 0; i < ret; i++) {
|
||||
radix_tree_delete(&info->block_group_radix,
|
||||
cache[i]->key.objectid +
|
||||
cache[i]->key.offset - 1);
|
||||
free(cache[i]);
|
||||
}
|
||||
bg = container_of(cache, struct btrfs_block_group_cache,
|
||||
cache);
|
||||
remove_cache_extent(&info->block_group_cache, cache);
|
||||
free(bg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -714,13 +707,15 @@ int btrfs_read_block_groups(struct btrfs_root *root)
|
||||
int ret;
|
||||
int err = 0;
|
||||
struct btrfs_block_group_item *bi;
|
||||
struct btrfs_block_group_cache *cache;
|
||||
struct btrfs_block_group_cache *bg;
|
||||
struct cache_tree *bg_cache;
|
||||
struct btrfs_key key;
|
||||
struct btrfs_key found_key;
|
||||
struct btrfs_leaf *leaf;
|
||||
u64 group_size = BTRFS_BLOCK_GROUP_SIZE;
|
||||
|
||||
root = root->fs_info->extent_root;
|
||||
bg_cache = &root->fs_info->block_group_cache;
|
||||
key.objectid = 0;
|
||||
key.offset = group_size;
|
||||
btrfs_set_key_type(&key, BTRFS_BLOCK_GROUP_ITEM_KEY);
|
||||
@ -736,20 +731,20 @@ int btrfs_read_block_groups(struct btrfs_root *root)
|
||||
leaf = &path.nodes[0]->leaf;
|
||||
btrfs_disk_key_to_cpu(&found_key,
|
||||
&leaf->items[path.slots[0]].key);
|
||||
cache = malloc(sizeof(*cache));
|
||||
if (!cache) {
|
||||
bg = malloc(sizeof(*bg));
|
||||
if (!bg) {
|
||||
err = -1;
|
||||
break;
|
||||
}
|
||||
bi = btrfs_item_ptr(leaf, path.slots[0],
|
||||
struct btrfs_block_group_item);
|
||||
memcpy(&cache->item, bi, sizeof(*bi));
|
||||
memcpy(&cache->key, &found_key, sizeof(found_key));
|
||||
memcpy(&bg->item, bi, sizeof(*bi));
|
||||
memcpy(&bg->key, &found_key, sizeof(found_key));
|
||||
key.objectid = found_key.objectid + found_key.offset;
|
||||
btrfs_release_path(root, &path);
|
||||
ret = radix_tree_insert(&root->fs_info->block_group_radix,
|
||||
found_key.objectid +
|
||||
found_key.offset - 1, (void *)cache);
|
||||
bg->cache.start = found_key.objectid;
|
||||
bg->cache.size = found_key.offset;
|
||||
ret = insert_existing_cache_extent(bg_cache, &bg->cache);
|
||||
BUG_ON(ret);
|
||||
if (key.objectid >=
|
||||
btrfs_super_total_bytes(root->fs_info->disk_super))
|
||||
|
23
mkfs.c
23
mkfs.c
@ -28,7 +28,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <uuid/uuid.h>
|
||||
#include "radix-tree.h"
|
||||
#include <linux/fs.h>
|
||||
#include "kerncompat.h"
|
||||
#include "ctree.h"
|
||||
@ -91,6 +90,7 @@ static int make_block_groups(struct btrfs_trans_handle *trans,
|
||||
int ret;
|
||||
u64 nr = 0;
|
||||
struct btrfs_block_group_cache *cache;
|
||||
struct cache_tree *bg_cache = &root->fs_info->block_group_cache;
|
||||
|
||||
root = root->fs_info->extent_root;
|
||||
|
||||
@ -99,13 +99,14 @@ static int make_block_groups(struct btrfs_trans_handle *trans,
|
||||
cache = malloc(sizeof(*cache));
|
||||
cache->key.objectid = 0;
|
||||
cache->key.offset = group_size;
|
||||
cache->cache.start = 0;
|
||||
cache->cache.size = group_size;
|
||||
btrfs_set_key_type(&cache->key, BTRFS_BLOCK_GROUP_ITEM_KEY);
|
||||
|
||||
memset(&cache->item, 0, sizeof(cache->item));
|
||||
btrfs_set_block_group_used(&cache->item,
|
||||
btrfs_super_bytes_used(root->fs_info->disk_super));
|
||||
ret = radix_tree_insert(&root->fs_info->block_group_radix,
|
||||
group_size - 1, (void *)cache);
|
||||
ret = insert_existing_cache_extent(bg_cache, &cache->cache);
|
||||
BUG_ON(ret);
|
||||
|
||||
total_bytes = btrfs_super_total_bytes(root->fs_info->disk_super);
|
||||
@ -114,14 +115,14 @@ static int make_block_groups(struct btrfs_trans_handle *trans,
|
||||
cache = malloc(sizeof(*cache));
|
||||
cache->key.objectid = cur_start;
|
||||
cache->key.offset = group_size;
|
||||
cache->cache.start = cur_start;
|
||||
cache->cache.size = group_size;
|
||||
btrfs_set_key_type(&cache->key, BTRFS_BLOCK_GROUP_ITEM_KEY);
|
||||
memset(&cache->item, 0, sizeof(cache->item));
|
||||
if (nr % 3)
|
||||
cache->item.flags |= BTRFS_BLOCK_GROUP_DATA;
|
||||
|
||||
ret = radix_tree_insert(&root->fs_info->block_group_radix,
|
||||
cur_start + group_size - 1,
|
||||
(void *)cache);
|
||||
ret = insert_existing_cache_extent(bg_cache, &cache->cache);
|
||||
BUG_ON(ret);
|
||||
cur_start += group_size;
|
||||
nr++;
|
||||
@ -129,9 +130,11 @@ static int make_block_groups(struct btrfs_trans_handle *trans,
|
||||
/* then insert all the items */
|
||||
cur_start = 0;
|
||||
while(cur_start < total_bytes) {
|
||||
cache = radix_tree_lookup(&root->fs_info->block_group_radix,
|
||||
cur_start + group_size - 1);
|
||||
BUG_ON(!cache);
|
||||
struct cache_extent *ce;
|
||||
ce = find_first_cache_extent(bg_cache, cur_start);
|
||||
BUG_ON(!ce);
|
||||
cache = container_of(ce, struct btrfs_block_group_cache,
|
||||
cache);
|
||||
ret = btrfs_insert_block_group(trans, root, &cache->key,
|
||||
&cache->item);
|
||||
BUG_ON(ret);
|
||||
@ -353,8 +356,6 @@ int main(int ac, char **av)
|
||||
char *buf = malloc(sectorsize);
|
||||
char *realpath_name;
|
||||
|
||||
radix_tree_init();
|
||||
|
||||
while(1) {
|
||||
int c;
|
||||
c = getopt(ac, av, "l:n:");
|
||||
|
Loading…
Reference in New Issue
Block a user