Skip to content

Commit

Permalink
Btrfs: drop the inode map tree
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Chris Mason authored and David Woodhouse committed Apr 10, 2007
1 parent c5739bb commit 1b05da2
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 204 deletions.
2 changes: 0 additions & 2 deletions fs/btrfs/btrfs_inode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
#define __BTRFS_I__

struct btrfs_inode {
u32 magic;
struct btrfs_root *root;
struct btrfs_key location;
struct inode vfs_inode;
u32 magic2;
};
static inline struct btrfs_inode *BTRFS_I(struct inode *inode)
{
Expand Down
39 changes: 5 additions & 34 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ extern struct kmem_cache *btrfs_path_cachep;

#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
Expand Down Expand Up @@ -62,7 +61,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;
Expand Down Expand Up @@ -226,23 +224,16 @@ struct btrfs_csum_item {
u8 csum[BTRFS_CSUM_SIZE];
} __attribute__ ((__packed__));

struct btrfs_inode_map_item {
u32 refs;
} __attribute__ ((__packed__));

struct crypto_hash;
struct btrfs_fs_info {
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 fs_roots_radix;
struct radix_tree_root pending_del_radix;
struct radix_tree_root pinned_radix;
u64 last_inode_alloc;
u64 generation;
u64 highest_inode;
struct btrfs_transaction *running_transaction;
struct btrfs_super_block *disk_super;
struct buffer_head *sb_buffer;
Expand Down Expand Up @@ -272,6 +263,8 @@ struct btrfs_root {
u32 blocksize;
int ref_cows;
u32 type;
u64 highest_inode;
u64 last_inode_alloc;
};

/* the lower bits in the key flags defines the item type */
Expand Down Expand Up @@ -320,16 +313,11 @@ 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)
{
Expand Down Expand Up @@ -883,17 +871,6 @@ static inline void btrfs_set_file_extent_num_blocks(struct
e->num_blocks = cpu_to_le64(val);
}

static inline u32 btrfs_inode_map_refs(struct btrfs_inode_map_item *m)
{
return le32_to_cpu(m->refs);
}

static inline void btrfs_set_inode_map_refs(struct btrfs_inode_map_item *m,
u32 val)
{
m->refs = cpu_to_le32(val);
}

static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
{
return sb->s_fs_info;
Expand Down Expand Up @@ -996,12 +973,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_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);

/* inode-item.c */
Expand Down
25 changes: 9 additions & 16 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ static int __setup_root(int blocksize,
root->fs_info = fs_info;
root->objectid = objectid;
root->last_trans = 0;
root->highest_inode = 0;
root->last_inode_alloc = 0;
memset(&root->root_key, 0, sizeof(root->root_key));
memset(&root->root_item, 0, sizeof(root->root_item));
return 0;
Expand Down Expand Up @@ -295,6 +297,7 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
struct btrfs_root *tree_root = fs_info->tree_root;
struct btrfs_path *path;
struct btrfs_leaf *l;
u64 highest_inode;
int ret = 0;

printk("read_fs_root looking for %Lu %Lu %u\n", location->objectid, location->offset, location->flags);
Expand Down Expand Up @@ -354,6 +357,12 @@ printk("radix_tree_insert gives us %d\n", ret);
kfree(root);
return ERR_PTR(ret);
}
ret = btrfs_find_highest_inode(root, &highest_inode);
if (ret == 0) {
root->highest_inode = highest_inode;
root->last_inode_alloc = highest_inode;
printk("highest inode is %Lu\n", highest_inode);
}
printk("all worked\n");
return root;
}
Expand All @@ -364,8 +373,6 @@ struct btrfs_root *open_ctree(struct super_block *sb)
GFP_NOFS);
struct btrfs_root *tree_root = kmalloc(sizeof(struct btrfs_root),
GFP_NOFS);
struct btrfs_root *inode_root = kmalloc(sizeof(struct btrfs_root),
GFP_NOFS);
struct btrfs_fs_info *fs_info = kmalloc(sizeof(*fs_info),
GFP_NOFS);
int ret;
Expand All @@ -378,9 +385,6 @@ struct btrfs_root *open_ctree(struct super_block *sb)
fs_info->running_transaction = NULL;
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->highest_inode = 0;
fs_info->sb = sb;
fs_info->btree_inode = new_inode(sb);
fs_info->btree_inode->i_ino = 1;
Expand Down Expand Up @@ -425,14 +429,7 @@ struct btrfs_root *open_ctree(struct super_block *sb)
BTRFS_EXTENT_TREE_OBJECTID, extent_root);
BUG_ON(ret);

ret = find_and_setup_root(sb->s_blocksize, tree_root, fs_info,
BTRFS_INODE_MAP_OBJECTID, inode_root);
BUG_ON(ret);

fs_info->generation = btrfs_super_generation(disk_super) + 1;
ret = btrfs_find_highest_inode(tree_root, &fs_info->last_inode_alloc);
if (ret == 0)
fs_info->highest_inode = fs_info->last_inode_alloc;
memset(&fs_info->kobj, 0, sizeof(fs_info->kobj));
kobj_set_kset_s(fs_info, btrfs_subsys);
kobject_set_name(&fs_info->kobj, "%s", sb->s_id);
Expand Down Expand Up @@ -512,9 +509,6 @@ int close_ctree(struct btrfs_root *root)
if (fs_info->extent_root->node)
btrfs_block_release(fs_info->extent_root,
fs_info->extent_root->node);
if (fs_info->inode_root->node)
btrfs_block_release(fs_info->inode_root,
fs_info->inode_root->node);
if (fs_info->tree_root->node)
btrfs_block_release(fs_info->tree_root,
fs_info->tree_root->node);
Expand All @@ -524,7 +518,6 @@ int close_ctree(struct btrfs_root *root)
iput(fs_info->btree_inode);
del_fs_roots(fs_info);
kfree(fs_info->extent_root);
kfree(fs_info->inode_root);
kfree(fs_info->tree_root);
kobject_unregister(&fs_info->kobj);
return 0;
Expand Down
2 changes: 2 additions & 0 deletions fs/btrfs/inode-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
sizeof(*inode_item));
btrfs_release_path(root, path);
btrfs_free_path(path);
if (ret == 0 && objectid > root->highest_inode)
root->highest_inode = objectid;
return ret;
}

Expand Down
65 changes: 4 additions & 61 deletions fs/btrfs/inode-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
#include "disk-io.h"
#include "transaction.h"

int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid)
int btrfs_find_highest_inode(struct btrfs_root *root, u64 *objectid)
{
struct btrfs_path *path;
int ret;
struct btrfs_leaf *l;
struct btrfs_root *root = fs_root->fs_info->inode_root;
struct btrfs_key search_key;
int slot;

Expand Down Expand Up @@ -38,7 +37,7 @@ int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid)
* 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;
Expand All @@ -49,16 +48,13 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
u64 last_ino = 0;
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;

path = btrfs_alloc_path();
BUG_ON(!path);
search_key.flags = 0;
btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY);

search_start = fs_root->fs_info->last_inode_alloc;
search_start = root->last_inode_alloc;
search_start = max(search_start, BTRFS_FIRST_FREE_OBJECTID);
search_key.objectid = search_start;
search_key.offset = 0;
Expand Down Expand Up @@ -108,7 +104,7 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
}
// FIXME -ENOSPC
found:
root->fs_info->last_inode_alloc = *objectid;
root->last_inode_alloc = *objectid;
btrfs_release_path(root, path);
btrfs_free_path(path);
BUG_ON(*objectid < search_start);
Expand All @@ -118,56 +114,3 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
btrfs_free_path(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;
path = btrfs_alloc_path();
BUG_ON(!path);
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(btrfs_buffer_leaf(path->nodes[0]),
path->slots[0], struct btrfs_inode_map_item);
btrfs_cpu_key_to_disk(&inode_item->key, location);
btrfs_mark_buffer_dirty(path->nodes[0]);
if (objectid > fs_root->fs_info->highest_inode)
fs_root->fs_info->highest_inode = objectid;
out:
btrfs_release_path(inode_root, path);
btrfs_free_path(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;
}

8 changes: 0 additions & 8 deletions fs/btrfs/print-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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;
u32 type;

Expand Down Expand Up @@ -54,13 +53,6 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
printk("\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);
printk("\t\tinode map key %Lu %u %Lu\n",
btrfs_disk_key_objectid(&mi->key),
btrfs_disk_key_flags(&mi->key),
btrfs_disk_key_offset(&mi->key));
break;
case BTRFS_STRING_ITEM_KEY:
printk("\t\titem data %.*s\n", btrfs_item_size(item),
btrfs_leaf_data(l) + btrfs_item_offset(item));
Expand Down
Loading

0 comments on commit 1b05da2

Please sign in to comment.