Commit 1bf85046 authored by Jeff Mahoney's avatar Jeff Mahoney Committed by Chris Mason

btrfs: Make extent-io callbacks that never fail return void

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: default avatarJeff Mahoney <jeffm@suse.com>
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent b6973aa6
...@@ -254,14 +254,14 @@ static void merge_cb(struct extent_io_tree *tree, struct extent_state *new, ...@@ -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. * This should be called with the tree lock held.
*/ */
static int merge_state(struct extent_io_tree *tree, static void merge_state(struct extent_io_tree *tree,
struct extent_state *state) struct extent_state *state)
{ {
struct extent_state *other; struct extent_state *other;
struct rb_node *other_node; struct rb_node *other_node;
if (state->state & (EXTENT_IOBITS | EXTENT_BOUNDARY)) if (state->state & (EXTENT_IOBITS | EXTENT_BOUNDARY))
return 0; return;
other_node = rb_prev(&state->rb_node); other_node = rb_prev(&state->rb_node);
if (other_node) { if (other_node) {
...@@ -287,19 +287,13 @@ static int merge_state(struct extent_io_tree *tree, ...@@ -287,19 +287,13 @@ static int merge_state(struct extent_io_tree *tree,
free_extent_state(other); 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) struct extent_state *state, int *bits)
{ {
if (tree->ops && tree->ops->set_bit_hook) { if (tree->ops && tree->ops->set_bit_hook)
return tree->ops->set_bit_hook(tree->mapping->host, tree->ops->set_bit_hook(tree->mapping->host, state, bits);
state, bits);
}
return 0;
} }
static void clear_state_cb(struct extent_io_tree *tree, static void clear_state_cb(struct extent_io_tree *tree,
...@@ -325,7 +319,6 @@ static int insert_state(struct extent_io_tree *tree, ...@@ -325,7 +319,6 @@ static int insert_state(struct extent_io_tree *tree,
{ {
struct rb_node *node; struct rb_node *node;
int bits_to_set = *bits & ~EXTENT_CTLBITS; int bits_to_set = *bits & ~EXTENT_CTLBITS;
int ret;
if (end < start) { if (end < start) {
printk(KERN_ERR "btrfs end < start %llu %llu\n", printk(KERN_ERR "btrfs end < start %llu %llu\n",
...@@ -335,9 +328,7 @@ static int insert_state(struct extent_io_tree *tree, ...@@ -335,9 +328,7 @@ static int insert_state(struct extent_io_tree *tree,
} }
state->start = start; state->start = start;
state->end = end; state->end = end;
ret = set_state_cb(tree, state, bits); set_state_cb(tree, state, bits);
if (ret)
return ret;
if (bits_to_set & EXTENT_DIRTY) if (bits_to_set & EXTENT_DIRTY)
tree->dirty_bytes += end - start + 1; tree->dirty_bytes += end - start + 1;
...@@ -357,13 +348,11 @@ static int insert_state(struct extent_io_tree *tree, ...@@ -357,13 +348,11 @@ static int insert_state(struct extent_io_tree *tree,
return 0; 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) u64 split)
{ {
if (tree->ops && tree->ops->split_extent_hook) if (tree->ops && tree->ops->split_extent_hook)
return tree->ops->split_extent_hook(tree->mapping->host, tree->ops->split_extent_hook(tree->mapping->host, orig, split);
orig, split);
return 0;
} }
/* /*
...@@ -670,23 +659,18 @@ int wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits) ...@@ -670,23 +659,18 @@ int wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits)
return 0; 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, struct extent_state *state,
int *bits) int *bits)
{ {
int ret;
int bits_to_set = *bits & ~EXTENT_CTLBITS; int bits_to_set = *bits & ~EXTENT_CTLBITS;
ret = set_state_cb(tree, state, bits); set_state_cb(tree, state, bits);
if (ret)
return ret;
if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) { if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) {
u64 range = state->end - state->start + 1; u64 range = state->end - state->start + 1;
tree->dirty_bytes += range; tree->dirty_bytes += range;
} }
state->state |= bits_to_set; state->state |= bits_to_set;
return 0;
} }
static void cache_state(struct extent_state *state, static void cache_state(struct extent_state *state,
...@@ -779,9 +763,7 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, ...@@ -779,9 +763,7 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
goto out; goto out;
} }
err = set_state_bits(tree, state, &bits); set_state_bits(tree, state, &bits);
if (err)
goto out;
cache_state(state, cached_state); cache_state(state, cached_state);
merge_state(tree, state); merge_state(tree, state);
...@@ -830,9 +812,7 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, ...@@ -830,9 +812,7 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
if (err) if (err)
goto out; goto out;
if (state->end <= end) { if (state->end <= end) {
err = set_state_bits(tree, state, &bits); set_state_bits(tree, state, &bits);
if (err)
goto out;
cache_state(state, cached_state); cache_state(state, cached_state);
merge_state(tree, state); merge_state(tree, state);
if (last_end == (u64)-1) if (last_end == (u64)-1)
...@@ -893,11 +873,7 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, ...@@ -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); err = split_state(tree, state, prealloc, end + 1);
BUG_ON(err == -EEXIST); BUG_ON(err == -EEXIST);
err = set_state_bits(tree, prealloc, &bits); set_state_bits(tree, prealloc, &bits);
if (err) {
prealloc = NULL;
goto out;
}
cache_state(prealloc, cached_state); cache_state(prealloc, cached_state);
merge_state(tree, prealloc); merge_state(tree, prealloc);
prealloc = NULL; prealloc = NULL;
......
...@@ -76,15 +76,15 @@ struct extent_io_ops { ...@@ -76,15 +76,15 @@ struct extent_io_ops {
struct extent_state *state); struct extent_state *state);
int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end, int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
struct extent_state *state, int uptodate); struct extent_state *state, int uptodate);
int (*set_bit_hook)(struct inode *inode, struct extent_state *state, void (*set_bit_hook)(struct inode *inode, struct extent_state *state,
int *bits); int *bits);
int (*clear_bit_hook)(struct inode *inode, struct extent_state *state, void (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
int *bits); int *bits);
int (*merge_extent_hook)(struct inode *inode, void (*merge_extent_hook)(struct inode *inode,
struct extent_state *new, struct extent_state *new,
struct extent_state *other); struct extent_state *other);
int (*split_extent_hook)(struct inode *inode, void (*split_extent_hook)(struct inode *inode,
struct extent_state *orig, u64 split); struct extent_state *orig, u64 split);
int (*write_cache_pages_lock_hook)(struct page *page); int (*write_cache_pages_lock_hook)(struct page *page);
}; };
......
...@@ -1283,17 +1283,16 @@ static int run_delalloc_range(struct inode *inode, struct page *locked_page, ...@@ -1283,17 +1283,16 @@ static int run_delalloc_range(struct inode *inode, struct page *locked_page,
return ret; return ret;
} }
static int btrfs_split_extent_hook(struct inode *inode, static void btrfs_split_extent_hook(struct inode *inode,
struct extent_state *orig, u64 split) struct extent_state *orig, u64 split)
{ {
/* not delalloc, ignore it */ /* not delalloc, ignore it */
if (!(orig->state & EXTENT_DELALLOC)) if (!(orig->state & EXTENT_DELALLOC))
return 0; return;
spin_lock(&BTRFS_I(inode)->lock); spin_lock(&BTRFS_I(inode)->lock);
BTRFS_I(inode)->outstanding_extents++; BTRFS_I(inode)->outstanding_extents++;
spin_unlock(&BTRFS_I(inode)->lock); spin_unlock(&BTRFS_I(inode)->lock);
return 0;
} }
/* /*
...@@ -1302,18 +1301,17 @@ static int btrfs_split_extent_hook(struct inode *inode, ...@@ -1302,18 +1301,17 @@ static int btrfs_split_extent_hook(struct inode *inode,
* extents, such as when we are doing sequential writes, so we can properly * extents, such as when we are doing sequential writes, so we can properly
* account for the metadata space we'll need. * account for the metadata space we'll need.
*/ */
static int btrfs_merge_extent_hook(struct inode *inode, static void btrfs_merge_extent_hook(struct inode *inode,
struct extent_state *new, struct extent_state *new,
struct extent_state *other) struct extent_state *other)
{ {
/* not delalloc, ignore it */ /* not delalloc, ignore it */
if (!(other->state & EXTENT_DELALLOC)) if (!(other->state & EXTENT_DELALLOC))
return 0; return;
spin_lock(&BTRFS_I(inode)->lock); spin_lock(&BTRFS_I(inode)->lock);
BTRFS_I(inode)->outstanding_extents--; BTRFS_I(inode)->outstanding_extents--;
spin_unlock(&BTRFS_I(inode)->lock); spin_unlock(&BTRFS_I(inode)->lock);
return 0;
} }
/* /*
...@@ -1321,8 +1319,8 @@ static int btrfs_merge_extent_hook(struct inode *inode, ...@@ -1321,8 +1319,8 @@ static int btrfs_merge_extent_hook(struct inode *inode,
* bytes in this file, and to maintain the list of inodes that * bytes in this file, and to maintain the list of inodes that
* have pending delalloc work to be done. * have pending delalloc work to be done.
*/ */
static int btrfs_set_bit_hook(struct inode *inode, static void btrfs_set_bit_hook(struct inode *inode,
struct extent_state *state, int *bits) struct extent_state *state, int *bits)
{ {
/* /*
...@@ -1352,14 +1350,13 @@ static int btrfs_set_bit_hook(struct inode *inode, ...@@ -1352,14 +1350,13 @@ static int btrfs_set_bit_hook(struct inode *inode,
} }
spin_unlock(&root->fs_info->delalloc_lock); spin_unlock(&root->fs_info->delalloc_lock);
} }
return 0;
} }
/* /*
* extent_io.c clear_bit_hook, see set_bit_hook for why * extent_io.c clear_bit_hook, see set_bit_hook for why
*/ */
static int btrfs_clear_bit_hook(struct inode *inode, static void btrfs_clear_bit_hook(struct inode *inode,
struct extent_state *state, int *bits) struct extent_state *state, int *bits)
{ {
/* /*
* set_bit and clear bit hooks normally require _irqsave/restore * set_bit and clear bit hooks normally require _irqsave/restore
...@@ -1396,7 +1393,6 @@ static int btrfs_clear_bit_hook(struct inode *inode, ...@@ -1396,7 +1393,6 @@ static int btrfs_clear_bit_hook(struct inode *inode,
} }
spin_unlock(&root->fs_info->delalloc_lock); spin_unlock(&root->fs_info->delalloc_lock);
} }
return 0;
} }
/* /*
......
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