From: Chris Mason Date: Tue, 10 Apr 2007 16:13:29 +0000 (-0400) Subject: drop the inode map tree X-Git-Tag: upstream/0.20.rc1~418 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1b4ca380ed92eac7b8897c812e21ca92ccc346c4;p=platform%2Fupstream%2Fbtrfs-progs.git drop the inode map tree --- diff --git a/ctree.h b/ctree.h index 4c75289..178ab79 100644 --- a/ctree.h +++ b/ctree.h @@ -10,9 +10,8 @@ struct btrfs_trans_handle; #define BTRFS_ROOT_TREE_OBJECTID 1ULL #define BTRFS_EXTENT_TREE_OBJECTID 2ULL -#define BTRFS_INODE_MAP_OBJECTID 3ULL -#define BTRFS_FS_TREE_OBJECTID 4ULL -#define BTRFS_FIRST_FREE_OBJECTID 5ULL +#define BTRFS_FS_TREE_OBJECTID 3ULL +#define BTRFS_FIRST_FREE_OBJECTID 4ULL /* * we can actually store much bigger names, but lets not confuse the rest @@ -58,7 +57,6 @@ struct btrfs_header { __le64 blocknr; /* which block this node is supposed to live in */ __le64 generation; __le64 parentid; /* objectid of the tree root */ - __le32 ham; __le16 nritems; __le16 flags; u8 level; @@ -222,16 +220,10 @@ struct btrfs_csum_item { u8 csum[BTRFS_CSUM_SIZE]; } __attribute__ ((__packed__)); -struct btrfs_inode_map_item { - struct btrfs_disk_key key; -} __attribute__ ((__packed__)); - - struct btrfs_fs_info { struct btrfs_root *fs_root; struct btrfs_root *extent_root; struct btrfs_root *tree_root; - struct btrfs_root *inode_root; struct btrfs_key current_insert; struct btrfs_key last_insert; struct radix_tree_root cache_radix; @@ -310,15 +302,10 @@ struct btrfs_root { #define BTRFS_EXTENT_ITEM_KEY 8 /* - * the inode map records which inode numbers are in use and where - * they actually live on disk - */ -#define BTRFS_INODE_MAP_ITEM_KEY 9 -/* * string items are for debugging. They just store a short string of * data in the FS */ -#define BTRFS_STRING_ITEM_KEY 10 +#define BTRFS_STRING_ITEM_KEY 9 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i) { @@ -922,12 +909,6 @@ int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path, int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, struct btrfs_root *fs_root, u64 dirid, u64 *objectid); -int btrfs_insert_inode_map(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - u64 objectid, struct btrfs_key *location); -int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans, - struct btrfs_root *root, struct btrfs_path *path, - u64 objectid, int mod); int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 objectid, struct btrfs_inode_item *inode_item); diff --git a/debug-tree.c b/debug-tree.c index 5e7165c..9699e3c 100644 --- a/debug-tree.c +++ b/debug-tree.c @@ -66,9 +66,6 @@ int main(int ac, char **av) { case BTRFS_EXTENT_TREE_OBJECTID: printf("extent tree "); break; - case BTRFS_INODE_MAP_OBJECTID: - printf("inode map"); - break; } printf("tree %Lu %Lu %u\n", found_key.objectid, found_key.offset, found_key.flags); diff --git a/dir-test.c b/dir-test.c index 078284e..cdef716 100644 --- a/dir-test.c +++ b/dir-test.c @@ -72,10 +72,6 @@ static int ins_one(struct btrfs_trans_handle *trans, struct btrfs_root *root, btrfs_set_key_type(&inode_map, BTRFS_INODE_ITEM_KEY); inode_map.offset = 0; - ret = btrfs_insert_inode_map(trans, root, objectid, &inode_map); - if (ret) - goto error; - initial_inode_init(root, &inode_item); ret = btrfs_insert_inode(trans, root, objectid, &inode_item); if (ret) @@ -187,18 +183,8 @@ static int del_dir_item(struct btrfs_trans_handle *trans, goto out_release; btrfs_release_path(root, path); - /* delete the inode mapping */ - btrfs_init_path(path); - ret = btrfs_lookup_inode_map(trans, root, path, file_objectid, -1); - if (ret) - goto out_release; - ret = btrfs_del_item(trans, root->fs_info->inode_root, path); - if (ret) - goto out_release; - if (root->fs_info->last_inode_alloc > file_objectid) root->fs_info->last_inode_alloc = file_objectid; - btrfs_release_path(root, path); ptr = radix_tree_delete(radix, radix_index); if (!ptr) { ret = -5555; @@ -261,9 +247,6 @@ static int lookup_item(struct btrfs_trans_handle *trans, struct btrfs_root di = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0], struct btrfs_dir_item); objectid = btrfs_disk_key_objectid(&di->location); - btrfs_release_path(root, &path); - btrfs_init_path(&path); - ret = btrfs_lookup_inode_map(trans, root, &path, objectid, 0); } btrfs_release_path(root, &path); if (ret) { diff --git a/disk-io.c b/disk-io.c index d30f63a..448482f 100644 --- a/disk-io.c +++ b/disk-io.c @@ -89,7 +89,6 @@ struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 blocknr) loff_t offset = blocknr * root->blocksize; struct btrfs_buffer *buf; int ret; - buf = radix_tree_lookup(&root->fs_info->cache_radix, blocknr); if (buf) { buf->count++; @@ -169,14 +168,7 @@ static int commit_tree_roots(struct btrfs_trans_handle *trans, u64 old_extent_block; struct btrfs_root *tree_root = fs_info->tree_root; struct btrfs_root *extent_root = fs_info->extent_root; - struct btrfs_root *inode_root = fs_info->inode_root; - btrfs_set_root_blocknr(&inode_root->root_item, - inode_root->node->blocknr); - ret = btrfs_update_root(trans, tree_root, - &inode_root->root_key, - &inode_root->root_item); - BUG_ON(ret); while(1) { old_extent_block = btrfs_root_blocknr(&extent_root->root_item); if (old_extent_block == extent_root->node->blocknr) @@ -281,7 +273,6 @@ struct btrfs_root *open_ctree_fd(int fp, struct btrfs_super_block *super) struct btrfs_root *root = malloc(sizeof(struct btrfs_root)); struct btrfs_root *extent_root = malloc(sizeof(struct btrfs_root)); struct btrfs_root *tree_root = malloc(sizeof(struct btrfs_root)); - struct btrfs_root *inode_root = malloc(sizeof(struct btrfs_root)); struct btrfs_fs_info *fs_info = malloc(sizeof(*fs_info)); int ret; @@ -295,7 +286,6 @@ struct btrfs_root *open_ctree_fd(int fp, struct btrfs_super_block *super) fs_info->fs_root = root; fs_info->tree_root = tree_root; fs_info->extent_root = extent_root; - fs_info->inode_root = inode_root; fs_info->last_inode_alloc = 0; fs_info->last_inode_alloc_dirid = 0; fs_info->disk_super = super; @@ -309,7 +299,6 @@ struct btrfs_root *open_ctree_fd(int fp, struct btrfs_super_block *super) return NULL; } BUG_ON(ret < 0); - __setup_root(super, tree_root, fs_info, BTRFS_ROOT_TREE_OBJECTID, fp); tree_root->node = read_tree_block(tree_root, btrfs_super_root(super)); BUG_ON(!tree_root->node); @@ -319,10 +308,6 @@ struct btrfs_root *open_ctree_fd(int fp, struct btrfs_super_block *super) BUG_ON(ret); ret = find_and_setup_root(super, tree_root, fs_info, - BTRFS_INODE_MAP_OBJECTID, inode_root, fp); - BUG_ON(ret); - - ret = find_and_setup_root(super, tree_root, fs_info, BTRFS_FS_TREE_OBJECTID, root, fp); BUG_ON(ret); @@ -379,9 +364,6 @@ int close_ctree(struct btrfs_root *root, struct btrfs_super_block *s) if (root->fs_info->extent_root->node) btrfs_block_release(root->fs_info->extent_root, root->fs_info->extent_root->node); - if (root->fs_info->inode_root->node) - btrfs_block_release(root->fs_info->inode_root, - root->fs_info->inode_root->node); if (root->fs_info->tree_root->node) btrfs_block_release(root->fs_info->tree_root, root->fs_info->tree_root->node); diff --git a/inode-map.c b/inode-map.c index cf9f42e..330b362 100644 --- a/inode-map.c +++ b/inode-map.c @@ -10,7 +10,7 @@ * walks the btree of allocated inodes and find a hole. */ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, - struct btrfs_root *fs_root, + struct btrfs_root *root, u64 dirid, u64 *objectid) { struct btrfs_path path; @@ -21,18 +21,16 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, u64 last_ino; int start_found; struct btrfs_leaf *l; - struct btrfs_root *root = fs_root->fs_info->inode_root; struct btrfs_key search_key; u64 search_start = dirid; - if (fs_root->fs_info->last_inode_alloc_dirid == dirid) - search_start = fs_root->fs_info->last_inode_alloc; + if (root->fs_info->last_inode_alloc_dirid == dirid) + search_start = root->fs_info->last_inode_alloc; if (search_start < BTRFS_FIRST_FREE_OBJECTID) search_start = BTRFS_FIRST_FREE_OBJECTID; search_key.objectid = search_start; search_key.flags = 0; - btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY); search_key.offset = 0; btrfs_init_path(&path); @@ -89,50 +87,3 @@ error: btrfs_release_path(root, &path); return ret; } - -int btrfs_insert_inode_map(struct btrfs_trans_handle *trans, - struct btrfs_root *fs_root, - u64 objectid, struct btrfs_key *location) -{ - int ret = 0; - struct btrfs_path path; - struct btrfs_inode_map_item *inode_item; - struct btrfs_key key; - struct btrfs_root *inode_root = fs_root->fs_info->inode_root; - - key.objectid = objectid; - key.flags = 0; - btrfs_set_key_type(&key, BTRFS_INODE_MAP_ITEM_KEY); - key.offset = 0; - btrfs_init_path(&path); - ret = btrfs_insert_empty_item(trans, inode_root, &path, &key, - sizeof(struct btrfs_inode_map_item)); - if (ret) - goto out; - - inode_item = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0], - struct btrfs_inode_map_item); - btrfs_cpu_key_to_disk(&inode_item->key, location); -out: - btrfs_release_path(inode_root, &path); - return ret; -} - -int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans, - struct btrfs_root *fs_root, struct btrfs_path *path, - u64 objectid, int mod) -{ - int ret; - struct btrfs_key key; - int ins_len = mod < 0 ? -1 : 0; - int cow = mod != 0; - struct btrfs_root *inode_root = fs_root->fs_info->inode_root; - - key.objectid = objectid; - key.flags = 0; - key.offset = 0; - btrfs_set_key_type(&key, BTRFS_INODE_MAP_ITEM_KEY); - ret = btrfs_search_slot(trans, inode_root, &key, path, ins_len, cow); - return ret; -} - diff --git a/mkfs.c b/mkfs.c index c94dbf9..fa5b1be 100644 --- a/mkfs.c +++ b/mkfs.c @@ -42,10 +42,6 @@ static int __make_root_dir(struct btrfs_trans_handle *trans, btrfs_set_key_type(&inode_map, BTRFS_INODE_ITEM_KEY); inode_map.offset = 0; - ret = btrfs_insert_inode_map(trans, root, objectid, &inode_map); - if (ret) - goto error; - memset(&inode_item, 0, sizeof(inode_item)); btrfs_set_inode_generation(&inode_item, root->fs_info->generation); btrfs_set_inode_size(&inode_item, 3); @@ -119,14 +115,13 @@ int mkfs(int fd, u64 num_blocks, u32 blocksize) int ret; u32 itemoff; u32 start_block = BTRFS_SUPER_INFO_OFFSET / blocksize; - btrfs_set_super_generation(&super, 1); btrfs_set_super_blocknr(&super, start_block); btrfs_set_super_root(&super, start_block + 1); strcpy((char *)(&super.magic), BTRFS_MAGIC); btrfs_set_super_blocksize(&super, blocksize); btrfs_set_super_total_blocks(&super, num_blocks); - btrfs_set_super_blocks_used(&super, start_block + 5); + btrfs_set_super_blocks_used(&super, start_block + 4); uuid_generate(super.fsid); block = malloc(blocksize); @@ -142,7 +137,7 @@ int mkfs(int fd, u64 num_blocks, u32 blocksize) btrfs_set_header_parentid(&empty_leaf->header, BTRFS_ROOT_TREE_OBJECTID); btrfs_set_header_blocknr(&empty_leaf->header, start_block + 1); - btrfs_set_header_nritems(&empty_leaf->header, 3); + btrfs_set_header_nritems(&empty_leaf->header, 2); btrfs_set_header_generation(&empty_leaf->header, 0); memcpy(empty_leaf->header.fsid, super.fsid, sizeof(empty_leaf->header.fsid)); @@ -173,16 +168,8 @@ int mkfs(int fd, u64 num_blocks, u32 blocksize) btrfs_set_root_blocknr(&root_item, start_block + 3); itemoff = itemoff - sizeof(root_item); btrfs_set_item_offset(&item, itemoff); - btrfs_set_disk_key_objectid(&item.key, BTRFS_INODE_MAP_OBJECTID); - memcpy(empty_leaf->items + 1, &item, sizeof(item)); - memcpy(btrfs_leaf_data(empty_leaf) + itemoff, - &root_item, sizeof(root_item)); - - btrfs_set_root_blocknr(&root_item, start_block + 4); - itemoff = itemoff - sizeof(root_item); - btrfs_set_item_offset(&item, itemoff); btrfs_set_disk_key_objectid(&item.key, BTRFS_FS_TREE_OBJECTID); - memcpy(empty_leaf->items + 2, &item, sizeof(item)); + memcpy(empty_leaf->items + 1, &item, sizeof(item)); memcpy(btrfs_leaf_data(empty_leaf) + itemoff, &root_item, sizeof(root_item)); ret = pwrite(fd, empty_leaf, blocksize, (start_block + 1) * blocksize); @@ -191,7 +178,7 @@ int mkfs(int fd, u64 num_blocks, u32 blocksize) btrfs_set_header_parentid(&empty_leaf->header, BTRFS_EXTENT_TREE_OBJECTID); btrfs_set_header_blocknr(&empty_leaf->header, start_block + 2); - btrfs_set_header_nritems(&empty_leaf->header, 5); + btrfs_set_header_nritems(&empty_leaf->header, 4); /* item1, reserve blocks 0-16 */ btrfs_set_disk_key_objectid(&item.key, 0); @@ -228,46 +215,24 @@ int mkfs(int fd, u64 num_blocks, u32 blocksize) memcpy(btrfs_leaf_data(empty_leaf) + btrfs_item_offset(&item), &extent_item, btrfs_item_size(&item)); - /* item4, give block 19 to the inode map */ + /* item5, give block 19 to the FS root */ btrfs_set_disk_key_objectid(&item.key, start_block + 3); btrfs_set_disk_key_offset(&item.key, 1); itemoff = itemoff - sizeof(struct btrfs_extent_item); btrfs_set_item_offset(&item, itemoff); - btrfs_set_extent_owner(&extent_item, BTRFS_INODE_MAP_OBJECTID); - memcpy(empty_leaf->items + 3, &item, sizeof(item)); - memcpy(btrfs_leaf_data(empty_leaf) + btrfs_item_offset(&item), - &extent_item, btrfs_item_size(&item)); - ret = pwrite(fd, empty_leaf, blocksize, (start_block + 2) * blocksize); - if (ret != blocksize) - return -1; - - /* item5, give block 20 to the FS root */ - btrfs_set_disk_key_objectid(&item.key, start_block + 4); - btrfs_set_disk_key_offset(&item.key, 1); - itemoff = itemoff - sizeof(struct btrfs_extent_item); - btrfs_set_item_offset(&item, itemoff); btrfs_set_extent_owner(&extent_item, BTRFS_FS_TREE_OBJECTID); - memcpy(empty_leaf->items + 4, &item, sizeof(item)); + memcpy(empty_leaf->items + 3, &item, sizeof(item)); memcpy(btrfs_leaf_data(empty_leaf) + btrfs_item_offset(&item), &extent_item, btrfs_item_size(&item)); ret = pwrite(fd, empty_leaf, blocksize, (start_block + 2) * blocksize); if (ret != blocksize) return -1; - /* create the inode map */ - btrfs_set_header_parentid(&empty_leaf->header, - BTRFS_INODE_MAP_OBJECTID); - btrfs_set_header_blocknr(&empty_leaf->header, start_block + 3); - btrfs_set_header_nritems(&empty_leaf->header, 0); - ret = pwrite(fd, empty_leaf, blocksize, (start_block + 3) * blocksize); - if (ret != blocksize) - return -1; - /* finally create the FS root */ btrfs_set_header_parentid(&empty_leaf->header, BTRFS_FS_TREE_OBJECTID); - btrfs_set_header_blocknr(&empty_leaf->header, start_block + 4); + btrfs_set_header_blocknr(&empty_leaf->header, start_block + 3); btrfs_set_header_nritems(&empty_leaf->header, 0); - ret = pwrite(fd, empty_leaf, blocksize, (start_block + 4) * blocksize); + ret = pwrite(fd, empty_leaf, blocksize, (start_block + 3) * blocksize); if (ret != blocksize) return -1; return 0; @@ -285,8 +250,7 @@ u64 device_size(int fd, struct stat *st) if (ioctl(fd, BLKGETSIZE64, &size) >= 0) { return size; } - return 0; -} + return 0; } int main(int ac, char **av) { diff --git a/print-tree.c b/print-tree.c index 0a6332d..03dfeb5 100644 --- a/print-tree.c +++ b/print-tree.c @@ -13,7 +13,6 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l) struct btrfs_extent_item *ei; struct btrfs_root_item *ri; struct btrfs_dir_item *di; - struct btrfs_inode_map_item *mi; struct btrfs_inode_item *ii; struct btrfs_file_extent_item *fi; char *p; @@ -77,13 +76,6 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l) printf("\t\textent data refs %u owner %Lu\n", btrfs_extent_refs(ei), btrfs_extent_owner(ei)); break; - case BTRFS_INODE_MAP_ITEM_KEY: - mi = btrfs_item_ptr(l, i, struct btrfs_inode_map_item); - printf("\t\tinode map key %Lu %Lu %u\n", - btrfs_disk_key_objectid(&mi->key), - btrfs_disk_key_offset(&mi->key), - btrfs_disk_key_flags(&mi->key)); - break; case BTRFS_EXTENT_DATA_KEY: fi = btrfs_item_ptr(l, i, struct btrfs_file_extent_item);