Commit 4d775673 authored by Chris Mason's avatar Chris Mason Committed by David Woodhouse

Btrfs: add owner and type fields to the extents aand block headers

Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 33ade1f8
...@@ -68,6 +68,7 @@ static int btrfs_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -68,6 +68,7 @@ static int btrfs_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root
memcpy(cow_node, btrfs_buffer_node(buf), root->blocksize); memcpy(cow_node, btrfs_buffer_node(buf), root->blocksize);
btrfs_set_header_blocknr(&cow_node->header, bh_blocknr(cow)); btrfs_set_header_blocknr(&cow_node->header, bh_blocknr(cow));
btrfs_set_header_generation(&cow_node->header, trans->transid); btrfs_set_header_generation(&cow_node->header, trans->transid);
btrfs_set_header_owner(&cow_node->header, root->root_key.objectid);
btrfs_inc_ref(trans, root, buf); btrfs_inc_ref(trans, root, buf);
if (buf == root->node) { if (buf == root->node) {
root->node = cow; root->node = cow;
...@@ -806,6 +807,7 @@ static int insert_new_root(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -806,6 +807,7 @@ static int insert_new_root(struct btrfs_trans_handle *trans, struct btrfs_root
btrfs_set_header_level(&c->header, level); btrfs_set_header_level(&c->header, level);
btrfs_set_header_blocknr(&c->header, bh_blocknr(t)); btrfs_set_header_blocknr(&c->header, bh_blocknr(t));
btrfs_set_header_generation(&c->header, trans->transid); btrfs_set_header_generation(&c->header, trans->transid);
btrfs_set_header_owner(&c->header, root->root_key.objectid);
lower = btrfs_buffer_node(path->nodes[level-1]); lower = btrfs_buffer_node(path->nodes[level-1]);
memcpy(c->header.fsid, root->fs_info->disk_super->fsid, memcpy(c->header.fsid, root->fs_info->disk_super->fsid,
sizeof(c->header.fsid)); sizeof(c->header.fsid));
...@@ -909,6 +911,7 @@ static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -909,6 +911,7 @@ static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root
btrfs_set_header_level(&split->header, btrfs_header_level(&c->header)); btrfs_set_header_level(&split->header, btrfs_header_level(&c->header));
btrfs_set_header_blocknr(&split->header, bh_blocknr(split_buffer)); btrfs_set_header_blocknr(&split->header, bh_blocknr(split_buffer));
btrfs_set_header_generation(&split->header, trans->transid); btrfs_set_header_generation(&split->header, trans->transid);
btrfs_set_header_owner(&split->header, root->root_key.objectid);
memcpy(split->header.fsid, root->fs_info->disk_super->fsid, memcpy(split->header.fsid, root->fs_info->disk_super->fsid,
sizeof(split->header.fsid)); sizeof(split->header.fsid));
mid = (c_nritems + 1) / 2; mid = (c_nritems + 1) / 2;
...@@ -1280,6 +1283,7 @@ static int split_leaf(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -1280,6 +1283,7 @@ static int split_leaf(struct btrfs_trans_handle *trans, struct btrfs_root
memset(&right->header, 0, sizeof(right->header)); memset(&right->header, 0, sizeof(right->header));
btrfs_set_header_blocknr(&right->header, bh_blocknr(right_buffer)); btrfs_set_header_blocknr(&right->header, bh_blocknr(right_buffer));
btrfs_set_header_generation(&right->header, trans->transid); btrfs_set_header_generation(&right->header, trans->transid);
btrfs_set_header_owner(&right->header, root->root_key.objectid);
btrfs_set_header_level(&right->header, 0); btrfs_set_header_level(&right->header, 0);
memcpy(right->header.fsid, root->fs_info->disk_super->fsid, memcpy(right->header.fsid, root->fs_info->disk_super->fsid,
sizeof(right->header.fsid)); sizeof(right->header.fsid));
...@@ -1376,6 +1380,7 @@ static int split_leaf(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -1376,6 +1380,7 @@ static int split_leaf(struct btrfs_trans_handle *trans, struct btrfs_root
memset(&right->header, 0, sizeof(right->header)); memset(&right->header, 0, sizeof(right->header));
btrfs_set_header_blocknr(&right->header, bh_blocknr(right_buffer)); btrfs_set_header_blocknr(&right->header, bh_blocknr(right_buffer));
btrfs_set_header_generation(&right->header, trans->transid); btrfs_set_header_generation(&right->header, trans->transid);
btrfs_set_header_owner(&right->header, root->root_key.objectid);
btrfs_set_header_level(&right->header, 0); btrfs_set_header_level(&right->header, 0);
memcpy(right->header.fsid, root->fs_info->disk_super->fsid, memcpy(right->header.fsid, root->fs_info->disk_super->fsid,
sizeof(right->header.fsid)); sizeof(right->header.fsid));
......
...@@ -62,6 +62,7 @@ struct btrfs_header { ...@@ -62,6 +62,7 @@ struct btrfs_header {
u8 fsid[16]; /* FS specific uuid */ u8 fsid[16]; /* FS specific uuid */
__le64 blocknr; /* which block this node is supposed to live in */ __le64 blocknr; /* which block this node is supposed to live in */
__le64 generation; __le64 generation;
__le64 owner;
__le16 nritems; __le16 nritems;
__le16 flags; __le16 flags;
u8 level; u8 level;
...@@ -151,12 +152,17 @@ struct btrfs_path { ...@@ -151,12 +152,17 @@ struct btrfs_path {
int slots[BTRFS_MAX_LEVEL]; int slots[BTRFS_MAX_LEVEL];
}; };
/* values for the type field in btrfs_extent_item */
#define BTRFS_EXTENT_TREE 1
#define BTRFS_EXTENT_FILE 2
/* /*
* items in the extent btree are used to record the objectid of the * items in the extent btree are used to record the objectid of the
* owner of the block and the number of references * owner of the block and the number of references
*/ */
struct btrfs_extent_item { struct btrfs_extent_item {
__le32 refs; __le32 refs;
__le64 owner;
u8 type;
} __attribute__ ((__packed__)); } __attribute__ ((__packed__));
struct btrfs_inode_timespec { struct btrfs_inode_timespec {
...@@ -473,11 +479,32 @@ static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val) ...@@ -473,11 +479,32 @@ static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
ei->refs = cpu_to_le32(val); ei->refs = cpu_to_le32(val);
} }
static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
{
return le64_to_cpu(ei->owner);
}
static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
{
ei->owner = cpu_to_le64(val);
}
static inline u8 btrfs_extent_type(struct btrfs_extent_item *ei)
{
return ei->type;
}
static inline void btrfs_set_extent_type(struct btrfs_extent_item *ei, u8 val)
{
ei->type = val;
}
static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr) static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
{ {
return le64_to_cpu(n->ptrs[nr].blockptr); return le64_to_cpu(n->ptrs[nr].blockptr);
} }
static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr, static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
u64 val) u64 val)
{ {
...@@ -636,6 +663,17 @@ static inline void btrfs_set_header_generation(struct btrfs_header *h, ...@@ -636,6 +663,17 @@ static inline void btrfs_set_header_generation(struct btrfs_header *h,
h->generation = cpu_to_le64(val); h->generation = cpu_to_le64(val);
} }
static inline u64 btrfs_header_owner(struct btrfs_header *h)
{
return le64_to_cpu(h->owner);
}
static inline void btrfs_set_header_owner(struct btrfs_header *h,
u64 val)
{
h->owner = cpu_to_le64(val);
}
static inline u16 btrfs_header_nritems(struct btrfs_header *h) static inline u16 btrfs_header_nritems(struct btrfs_header *h)
{ {
return le16_to_cpu(h->nritems); return le16_to_cpu(h->nritems);
...@@ -996,9 +1034,10 @@ int btrfs_inc_root_ref(struct btrfs_trans_handle *trans, ...@@ -996,9 +1034,10 @@ int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
struct btrfs_root *root); struct btrfs_root *root);
struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root); struct btrfs_root *root);
int btrfs_alloc_extent(struct btrfs_trans_handle *trans, struct btrfs_root int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
*root, u64 num_blocks, u64 search_start, u64 struct btrfs_root *root, u64 owner,
search_end, struct btrfs_key *ins); u8 type, u64 num_blocks, u64 search_start,
u64 search_end, struct btrfs_key *ins);
int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct buffer_head *buf); struct buffer_head *buf);
int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
......
...@@ -319,6 +319,7 @@ static int __setup_root(int blocksize, ...@@ -319,6 +319,7 @@ static int __setup_root(int blocksize,
root->last_inode_alloc = 0; root->last_inode_alloc = 0;
memset(&root->root_key, 0, sizeof(root->root_key)); memset(&root->root_key, 0, sizeof(root->root_key));
memset(&root->root_item, 0, sizeof(root->root_item)); memset(&root->root_item, 0, sizeof(root->root_item));
root->root_key.objectid = objectid;
return 0; return 0;
} }
......
...@@ -460,9 +460,10 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -460,9 +460,10 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
* *
* returns 0 if everything worked, non-zero otherwise. * returns 0 if everything worked, non-zero otherwise.
*/ */
int btrfs_alloc_extent(struct btrfs_trans_handle *trans, struct btrfs_root int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
*root, u64 num_blocks, u64 search_start, u64 struct btrfs_root *root, u64 owner,
search_end, struct btrfs_key *ins) u8 type, u64 num_blocks, u64 search_start,
u64 search_end, struct btrfs_key *ins)
{ {
int ret; int ret;
int pending_ret; int pending_ret;
...@@ -472,6 +473,8 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -472,6 +473,8 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans, struct btrfs_root
struct btrfs_extent_item extent_item; struct btrfs_extent_item extent_item;
btrfs_set_extent_refs(&extent_item, 1); btrfs_set_extent_refs(&extent_item, 1);
btrfs_set_extent_owner(&extent_item, owner);
btrfs_set_extent_type(&extent_item, type);
if (root == extent_root) { if (root == extent_root) {
BUG_ON(extent_root->fs_info->current_insert.offset == 0); BUG_ON(extent_root->fs_info->current_insert.offset == 0);
...@@ -514,7 +517,9 @@ struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, ...@@ -514,7 +517,9 @@ struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
int ret; int ret;
struct buffer_head *buf; struct buffer_head *buf;
ret = btrfs_alloc_extent(trans, root, 1, 0, (unsigned long)-1, &ins); ret = btrfs_alloc_extent(trans, root, root->root_key.objectid,
BTRFS_EXTENT_TREE,
1, 0, (unsigned long)-1, &ins);
if (ret) { if (ret) {
BUG(); BUG();
return NULL; return NULL;
......
...@@ -1819,7 +1819,8 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf, ...@@ -1819,7 +1819,8 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf,
} }
if (inode->i_size >= PAGE_CACHE_SIZE || pos + count < inode->i_size || if (inode->i_size >= PAGE_CACHE_SIZE || pos + count < inode->i_size ||
pos + count - start_pos > BTRFS_MAX_INLINE_DATA_SIZE(root)) { pos + count - start_pos > BTRFS_MAX_INLINE_DATA_SIZE(root)) {
ret = btrfs_alloc_extent(trans, root, num_blocks, 1, ret = btrfs_alloc_extent(trans, root, inode->i_ino,
BTRFS_EXTENT_FILE, num_blocks, 1,
(u64)-1, &ins); (u64)-1, &ins);
BUG_ON(ret); BUG_ON(ret);
ret = btrfs_insert_file_extent(trans, root, inode->i_ino, ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
...@@ -2017,8 +2018,12 @@ static int create_subvol(struct btrfs_root *root, char *name, int namelen) ...@@ -2017,8 +2018,12 @@ static int create_subvol(struct btrfs_root *root, char *name, int namelen)
btrfs_set_header_level(&leaf->header, 0); btrfs_set_header_level(&leaf->header, 0);
btrfs_set_header_blocknr(&leaf->header, bh_blocknr(subvol)); btrfs_set_header_blocknr(&leaf->header, bh_blocknr(subvol));
btrfs_set_header_generation(&leaf->header, trans->transid); btrfs_set_header_generation(&leaf->header, trans->transid);
btrfs_set_header_owner(&leaf->header, root->root_key.objectid);
memcpy(leaf->header.fsid, root->fs_info->disk_super->fsid, memcpy(leaf->header.fsid, root->fs_info->disk_super->fsid,
sizeof(leaf->header.fsid)); sizeof(leaf->header.fsid));
mark_buffer_dirty(subvol);
brelse(subvol);
subvol = NULL;
inode_item = &root_item.inode; inode_item = &root_item.inode;
memset(inode_item, 0, sizeof(*inode_item)); memset(inode_item, 0, sizeof(*inode_item));
...@@ -2031,10 +2036,6 @@ static int create_subvol(struct btrfs_root *root, char *name, int namelen) ...@@ -2031,10 +2036,6 @@ static int create_subvol(struct btrfs_root *root, char *name, int namelen)
btrfs_set_root_blocknr(&root_item, bh_blocknr(subvol)); btrfs_set_root_blocknr(&root_item, bh_blocknr(subvol));
btrfs_set_root_refs(&root_item, 1); btrfs_set_root_refs(&root_item, 1);
mark_buffer_dirty(subvol);
brelse(subvol);
subvol = NULL;
ret = btrfs_find_free_objectid(trans, root->fs_info->tree_root, ret = btrfs_find_free_objectid(trans, root->fs_info->tree_root,
0, &objectid); 0, &objectid);
BUG_ON(ret); BUG_ON(ret);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment