Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b05da2e authored by Chris Mason's avatar Chris Mason Committed by David Woodhouse
Browse files

Btrfs: drop the inode map tree

parent c5739bba
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -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)
{
+5 −34
Original line number Diff line number Diff line
@@ -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
@@ -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;
@@ -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;
@@ -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 */
@@ -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)
{
@@ -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;
@@ -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 */
+9 −16
Original line number Diff line number Diff line
@@ -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;
@@ -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);
@@ -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;
}
@@ -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;
@@ -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;
@@ -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);
@@ -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);
@@ -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;
+2 −0
Original line number Diff line number Diff line
@@ -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;
}

+4 −61
Original line number Diff line number Diff line
@@ -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;

@@ -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;
@@ -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;
@@ -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);
@@ -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;
}
Loading