Commit 236454df authored by Chris Mason's avatar Chris Mason Committed by David Woodhouse

Btrfs: many file_write fixes, inline data

Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent a429e513
...@@ -73,6 +73,9 @@ struct btrfs_header { ...@@ -73,6 +73,9 @@ struct btrfs_header {
(sizeof(struct btrfs_disk_key) + sizeof(u64))) (sizeof(struct btrfs_disk_key) + sizeof(u64)))
#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize)) #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
sizeof(struct btrfs_item) - \
sizeof(struct btrfs_file_extent_item))
struct buffer_head; struct buffer_head;
/* /*
...@@ -204,8 +207,12 @@ struct btrfs_root_item { ...@@ -204,8 +207,12 @@ struct btrfs_root_item {
__le32 refs; __le32 refs;
} __attribute__ ((__packed__)); } __attribute__ ((__packed__));
#define BTRFS_FILE_EXTENT_REG 0
#define BTRFS_FILE_EXTENT_INLINE 1
struct btrfs_file_extent_item { struct btrfs_file_extent_item {
__le64 generation; __le64 generation;
u8 type;
/* /*
* disk space consumed by the extent, checksum blocks are included * disk space consumed by the extent, checksum blocks are included
* in these numbers * in these numbers
...@@ -862,6 +869,34 @@ static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l) ...@@ -862,6 +869,34 @@ static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
return (u8 *)l->items; return (u8 *)l->items;
} }
static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
{
return e->type;
}
static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
u8 val)
{
e->type = val;
}
static inline char *btrfs_file_extent_inline_start(struct
btrfs_file_extent_item *e)
{
return (char *)(&e->disk_blocknr);
}
static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
{
return (unsigned long)(&((struct
btrfs_file_extent_item *)NULL)->disk_blocknr) + datasize;
}
static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
{
struct btrfs_file_extent_item *fe = NULL;
return btrfs_item_size(e) - (unsigned long)(&fe->disk_blocknr);
}
static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
*e) *e)
{ {
......
...@@ -108,6 +108,12 @@ int btrfs_map_bh_to_logical(struct btrfs_root *root, struct buffer_head *bh, ...@@ -108,6 +108,12 @@ int btrfs_map_bh_to_logical(struct btrfs_root *root, struct buffer_head *bh,
int ret; int ret;
if (logical == 0) {
bh->b_bdev = NULL;
bh->b_blocknr = 0;
set_buffer_mapped(bh);
return 0;
}
root = root->fs_info->dev_root; root = root->fs_info->dev_root;
ret = radix_tree_gang_lookup(&root->fs_info->dev_radix, ret = radix_tree_gang_lookup(&root->fs_info->dev_radix,
(void **)lookup, (void **)lookup,
......
...@@ -111,6 +111,9 @@ int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, ...@@ -111,6 +111,9 @@ int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
continue; continue;
fi = btrfs_item_ptr(buf_leaf, i, fi = btrfs_item_ptr(buf_leaf, i,
struct btrfs_file_extent_item); struct btrfs_file_extent_item);
if (btrfs_file_extent_type(fi) ==
BTRFS_FILE_EXTENT_INLINE)
continue;
ret = btrfs_inc_extent_ref(trans, root, ret = btrfs_inc_extent_ref(trans, root,
btrfs_file_extent_disk_blocknr(fi), btrfs_file_extent_disk_blocknr(fi),
btrfs_file_extent_disk_num_blocks(fi)); btrfs_file_extent_disk_num_blocks(fi));
...@@ -539,6 +542,8 @@ static int drop_leaf_ref(struct btrfs_trans_handle *trans, ...@@ -539,6 +542,8 @@ static int drop_leaf_ref(struct btrfs_trans_handle *trans,
if (btrfs_disk_key_type(key) != BTRFS_EXTENT_DATA_KEY) if (btrfs_disk_key_type(key) != BTRFS_EXTENT_DATA_KEY)
continue; continue;
fi = btrfs_item_ptr(leaf, i, struct btrfs_file_extent_item); fi = btrfs_item_ptr(leaf, i, struct btrfs_file_extent_item);
if (btrfs_file_extent_type(fi) == BTRFS_FILE_EXTENT_INLINE)
continue;
/* /*
* FIXME make sure to insert a trans record that * FIXME make sure to insert a trans record that
* repeats the snapshot del on crash * repeats the snapshot del on crash
......
...@@ -34,6 +34,7 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, ...@@ -34,6 +34,7 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
btrfs_set_file_extent_offset(item, 0); btrfs_set_file_extent_offset(item, 0);
btrfs_set_file_extent_num_blocks(item, num_blocks); btrfs_set_file_extent_num_blocks(item, num_blocks);
btrfs_set_file_extent_generation(item, trans->transid); btrfs_set_file_extent_generation(item, trans->transid);
btrfs_set_file_extent_type(item, BTRFS_FILE_EXTENT_REG);
btrfs_mark_buffer_dirty(path->nodes[0]); btrfs_mark_buffer_dirty(path->nodes[0]);
btrfs_release_path(root, path); btrfs_release_path(root, path);
......
This diff is collapsed.
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