Skip to content

Commit

Permalink
Btrfs: many file_write fixes, inline data
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 19, 2007
1 parent a429e51 commit 236454d
Showing 5 changed files with 484 additions and 116 deletions.
35 changes: 35 additions & 0 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
@@ -73,6 +73,9 @@ struct btrfs_header {
(sizeof(struct btrfs_disk_key) + sizeof(u64)))
#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_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
sizeof(struct btrfs_item) - \
sizeof(struct btrfs_file_extent_item))

struct buffer_head;
/*
@@ -204,8 +207,12 @@ struct btrfs_root_item {
__le32 refs;
} __attribute__ ((__packed__));

#define BTRFS_FILE_EXTENT_REG 0
#define BTRFS_FILE_EXTENT_INLINE 1

struct btrfs_file_extent_item {
__le64 generation;
u8 type;
/*
* disk space consumed by the extent, checksum blocks are included
* in these numbers
@@ -862,6 +869,34 @@ static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
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
*e)
{
6 changes: 6 additions & 0 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
@@ -108,6 +108,12 @@ int btrfs_map_bh_to_logical(struct btrfs_root *root, struct buffer_head *bh,

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;
ret = radix_tree_gang_lookup(&root->fs_info->dev_radix,
(void **)lookup,
5 changes: 5 additions & 0 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
@@ -111,6 +111,9 @@ int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
continue;
fi = btrfs_item_ptr(buf_leaf, i,
struct btrfs_file_extent_item);
if (btrfs_file_extent_type(fi) ==
BTRFS_FILE_EXTENT_INLINE)
continue;
ret = btrfs_inc_extent_ref(trans, root,
btrfs_file_extent_disk_blocknr(fi),
btrfs_file_extent_disk_num_blocks(fi));
@@ -539,6 +542,8 @@ static int drop_leaf_ref(struct btrfs_trans_handle *trans,
if (btrfs_disk_key_type(key) != BTRFS_EXTENT_DATA_KEY)
continue;
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
* repeats the snapshot del on crash
1 change: 1 addition & 0 deletions fs/btrfs/file-item.c
Original file line number Diff line number Diff line change
@@ -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_num_blocks(item, num_blocks);
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_release_path(root, path);
553 changes: 437 additions & 116 deletions fs/btrfs/super.c

Large diffs are not rendered by default.

0 comments on commit 236454d

Please sign in to comment.