Skip to content

Commit

Permalink
btrfs: Make extent-io callbacks that never fail return void
Browse files Browse the repository at this point in the history
The set/clear bit and the extent split/merge hooks only ever return 0.

 Changing them to return void simplifies the error handling cases later.

 This patch changes the hook prototypes, the single implementation of each,
 and the functions that call them to return void instead.

 Since all four of these hooks execute under a spinlock, they're necessarily
 simple.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Jeff Mahoney authored and Chris Mason committed Aug 1, 2011
1 parent b6973aa commit 1bf8504
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 62 deletions.
52 changes: 14 additions & 38 deletions fs/btrfs/extent_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ static void merge_cb(struct extent_io_tree *tree, struct extent_state *new,
*
* This should be called with the tree lock held.
*/
static int merge_state(struct extent_io_tree *tree,
struct extent_state *state)
static void merge_state(struct extent_io_tree *tree,
struct extent_state *state)
{
struct extent_state *other;
struct rb_node *other_node;

if (state->state & (EXTENT_IOBITS | EXTENT_BOUNDARY))
return 0;
return;

other_node = rb_prev(&state->rb_node);
if (other_node) {
Expand All @@ -287,19 +287,13 @@ static int merge_state(struct extent_io_tree *tree,
free_extent_state(other);
}
}

return 0;
}

static int set_state_cb(struct extent_io_tree *tree,
static void set_state_cb(struct extent_io_tree *tree,
struct extent_state *state, int *bits)
{
if (tree->ops && tree->ops->set_bit_hook) {
return tree->ops->set_bit_hook(tree->mapping->host,
state, bits);
}

return 0;
if (tree->ops && tree->ops->set_bit_hook)
tree->ops->set_bit_hook(tree->mapping->host, state, bits);
}

static void clear_state_cb(struct extent_io_tree *tree,
Expand All @@ -325,7 +319,6 @@ static int insert_state(struct extent_io_tree *tree,
{
struct rb_node *node;
int bits_to_set = *bits & ~EXTENT_CTLBITS;
int ret;

if (end < start) {
printk(KERN_ERR "btrfs end < start %llu %llu\n",
Expand All @@ -335,9 +328,7 @@ static int insert_state(struct extent_io_tree *tree,
}
state->start = start;
state->end = end;
ret = set_state_cb(tree, state, bits);
if (ret)
return ret;
set_state_cb(tree, state, bits);

if (bits_to_set & EXTENT_DIRTY)
tree->dirty_bytes += end - start + 1;
Expand All @@ -357,13 +348,11 @@ static int insert_state(struct extent_io_tree *tree,
return 0;
}

static int split_cb(struct extent_io_tree *tree, struct extent_state *orig,
static void split_cb(struct extent_io_tree *tree, struct extent_state *orig,
u64 split)
{
if (tree->ops && tree->ops->split_extent_hook)
return tree->ops->split_extent_hook(tree->mapping->host,
orig, split);
return 0;
tree->ops->split_extent_hook(tree->mapping->host, orig, split);
}

/*
Expand Down Expand Up @@ -670,23 +659,18 @@ int wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits)
return 0;
}

static int set_state_bits(struct extent_io_tree *tree,
static void set_state_bits(struct extent_io_tree *tree,
struct extent_state *state,
int *bits)
{
int ret;
int bits_to_set = *bits & ~EXTENT_CTLBITS;

ret = set_state_cb(tree, state, bits);
if (ret)
return ret;
set_state_cb(tree, state, bits);
if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) {
u64 range = state->end - state->start + 1;
tree->dirty_bytes += range;
}
state->state |= bits_to_set;

return 0;
}

static void cache_state(struct extent_state *state,
Expand Down Expand Up @@ -779,9 +763,7 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
goto out;
}

err = set_state_bits(tree, state, &bits);
if (err)
goto out;
set_state_bits(tree, state, &bits);

cache_state(state, cached_state);
merge_state(tree, state);
Expand Down Expand Up @@ -830,9 +812,7 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
if (err)
goto out;
if (state->end <= end) {
err = set_state_bits(tree, state, &bits);
if (err)
goto out;
set_state_bits(tree, state, &bits);
cache_state(state, cached_state);
merge_state(tree, state);
if (last_end == (u64)-1)
Expand Down Expand Up @@ -893,11 +873,7 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
err = split_state(tree, state, prealloc, end + 1);
BUG_ON(err == -EEXIST);

err = set_state_bits(tree, prealloc, &bits);
if (err) {
prealloc = NULL;
goto out;
}
set_state_bits(tree, prealloc, &bits);
cache_state(prealloc, cached_state);
merge_state(tree, prealloc);
prealloc = NULL;
Expand Down
18 changes: 9 additions & 9 deletions fs/btrfs/extent_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ struct extent_io_ops {
struct extent_state *state);
int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
struct extent_state *state, int uptodate);
int (*set_bit_hook)(struct inode *inode, struct extent_state *state,
int *bits);
int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
int *bits);
int (*merge_extent_hook)(struct inode *inode,
struct extent_state *new,
struct extent_state *other);
int (*split_extent_hook)(struct inode *inode,
struct extent_state *orig, u64 split);
void (*set_bit_hook)(struct inode *inode, struct extent_state *state,
int *bits);
void (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
int *bits);
void (*merge_extent_hook)(struct inode *inode,
struct extent_state *new,
struct extent_state *other);
void (*split_extent_hook)(struct inode *inode,
struct extent_state *orig, u64 split);
int (*write_cache_pages_lock_hook)(struct page *page);
};

Expand Down
26 changes: 11 additions & 15 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,17 +1283,16 @@ static int run_delalloc_range(struct inode *inode, struct page *locked_page,
return ret;
}

static int btrfs_split_extent_hook(struct inode *inode,
struct extent_state *orig, u64 split)
static void btrfs_split_extent_hook(struct inode *inode,
struct extent_state *orig, u64 split)
{
/* not delalloc, ignore it */
if (!(orig->state & EXTENT_DELALLOC))
return 0;
return;

spin_lock(&BTRFS_I(inode)->lock);
BTRFS_I(inode)->outstanding_extents++;
spin_unlock(&BTRFS_I(inode)->lock);
return 0;
}

/*
Expand All @@ -1302,27 +1301,26 @@ static int btrfs_split_extent_hook(struct inode *inode,
* extents, such as when we are doing sequential writes, so we can properly
* account for the metadata space we'll need.
*/
static int btrfs_merge_extent_hook(struct inode *inode,
struct extent_state *new,
struct extent_state *other)
static void btrfs_merge_extent_hook(struct inode *inode,
struct extent_state *new,
struct extent_state *other)
{
/* not delalloc, ignore it */
if (!(other->state & EXTENT_DELALLOC))
return 0;
return;

spin_lock(&BTRFS_I(inode)->lock);
BTRFS_I(inode)->outstanding_extents--;
spin_unlock(&BTRFS_I(inode)->lock);
return 0;
}

/*
* extent_io.c set_bit_hook, used to track delayed allocation
* bytes in this file, and to maintain the list of inodes that
* have pending delalloc work to be done.
*/
static int btrfs_set_bit_hook(struct inode *inode,
struct extent_state *state, int *bits)
static void btrfs_set_bit_hook(struct inode *inode,
struct extent_state *state, int *bits)
{

/*
Expand Down Expand Up @@ -1352,14 +1350,13 @@ static int btrfs_set_bit_hook(struct inode *inode,
}
spin_unlock(&root->fs_info->delalloc_lock);
}
return 0;
}

/*
* extent_io.c clear_bit_hook, see set_bit_hook for why
*/
static int btrfs_clear_bit_hook(struct inode *inode,
struct extent_state *state, int *bits)
static void btrfs_clear_bit_hook(struct inode *inode,
struct extent_state *state, int *bits)
{
/*
* set_bit and clear bit hooks normally require _irqsave/restore
Expand Down Expand Up @@ -1396,7 +1393,6 @@ static int btrfs_clear_bit_hook(struct inode *inode,
}
spin_unlock(&root->fs_info->delalloc_lock);
}
return 0;
}

/*
Expand Down

0 comments on commit 1bf8504

Please sign in to comment.