Skip to content

Commit

Permalink
btrfs: extent_io: Introduce new function clear_record_extent_bits()
Browse files Browse the repository at this point in the history
Introduce new function clear_record_extent_bits(), which will clear bits
for given range and record the details about which ranges are cleared
and how many bytes in total it changes.

This provides the basis for later qgroup reserve codes.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
  • Loading branch information
Qu Wenruo authored and Chris Mason committed Oct 22, 2015
1 parent d38ed27 commit fefdc55
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
50 changes: 39 additions & 11 deletions fs/btrfs/extent_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ static void add_extent_changeset(struct extent_state *state, unsigned bits,
return;
if (set && (state->state & bits) == bits)
return;
if (!set && (state->state & bits) == 0)
return;
changeset->bytes_changed += state->end - state->start + 1;
ret = ulist_add(changeset->range_changed, state->start, state->end,
GFP_ATOMIC);
Expand Down Expand Up @@ -529,7 +531,8 @@ static struct extent_state *next_state(struct extent_state *state)
*/
static struct extent_state *clear_state_bit(struct extent_io_tree *tree,
struct extent_state *state,
unsigned *bits, int wake)
unsigned *bits, int wake,
struct extent_changeset *changeset)
{
struct extent_state *next;
unsigned bits_to_clear = *bits & ~EXTENT_CTLBITS;
Expand All @@ -540,6 +543,7 @@ static struct extent_state *clear_state_bit(struct extent_io_tree *tree,
tree->dirty_bytes -= range;
}
clear_state_cb(tree, state, bits);
add_extent_changeset(state, bits_to_clear, changeset, 0);
state->state &= ~bits_to_clear;
if (wake)
wake_up(&state->wq);
Expand Down Expand Up @@ -587,10 +591,10 @@ static void extent_io_tree_panic(struct extent_io_tree *tree, int err)
*
* This takes the tree lock, and returns 0 on success and < 0 on error.
*/
int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
unsigned bits, int wake, int delete,
struct extent_state **cached_state,
gfp_t mask)
static int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
unsigned bits, int wake, int delete,
struct extent_state **cached_state,
gfp_t mask, struct extent_changeset *changeset)
{
struct extent_state *state;
struct extent_state *cached;
Expand Down Expand Up @@ -689,7 +693,8 @@ int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
if (err)
goto out;
if (state->end <= end) {
state = clear_state_bit(tree, state, &bits, wake);
state = clear_state_bit(tree, state, &bits, wake,
changeset);
goto next;
}
goto search_again;
Expand All @@ -710,13 +715,13 @@ int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
if (wake)
wake_up(&state->wq);

clear_state_bit(tree, prealloc, &bits, wake);
clear_state_bit(tree, prealloc, &bits, wake, changeset);

prealloc = NULL;
goto out;
}

state = clear_state_bit(tree, state, &bits, wake);
state = clear_state_bit(tree, state, &bits, wake, changeset);
next:
if (last_end == (u64)-1)
goto out;
Expand Down Expand Up @@ -1151,7 +1156,7 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
if (state->start == start && state->end <= end) {
set_state_bits(tree, state, &bits, NULL);
cache_state(state, cached_state);
state = clear_state_bit(tree, state, &clear_bits, 0);
state = clear_state_bit(tree, state, &clear_bits, 0, NULL);
if (last_end == (u64)-1)
goto out;
start = last_end + 1;
Expand Down Expand Up @@ -1192,7 +1197,8 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
if (state->end <= end) {
set_state_bits(tree, state, &bits, NULL);
cache_state(state, cached_state);
state = clear_state_bit(tree, state, &clear_bits, 0);
state = clear_state_bit(tree, state, &clear_bits, 0,
NULL);
if (last_end == (u64)-1)
goto out;
start = last_end + 1;
Expand Down Expand Up @@ -1254,7 +1260,7 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,

set_state_bits(tree, prealloc, &bits, NULL);
cache_state(prealloc, cached_state);
clear_state_bit(tree, prealloc, &clear_bits, 0);
clear_state_bit(tree, prealloc, &clear_bits, 0, NULL);
prealloc = NULL;
goto out;
}
Expand Down Expand Up @@ -1309,6 +1315,14 @@ int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
changeset);
}

int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
unsigned bits, int wake, int delete,
struct extent_state **cached, gfp_t mask)
{
return __clear_extent_bit(tree, start, end, bits, wake, delete,
cached, mask, NULL);
}

int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
unsigned bits, gfp_t mask)
{
Expand All @@ -1320,6 +1334,20 @@ int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
return clear_extent_bit(tree, start, end, bits, wake, 0, NULL, mask);
}

int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
unsigned bits, gfp_t mask,
struct extent_changeset *changeset)
{
/*
* Don't support EXTENT_LOCKED case, same reason as
* set_record_extent_bits().
*/
BUG_ON(bits & EXTENT_LOCKED);

return __clear_extent_bit(tree, start, end, bits, 0, 0, NULL, mask,
changeset);
}

int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end,
struct extent_state **cached_state, gfp_t mask)
{
Expand Down
3 changes: 3 additions & 0 deletions fs/btrfs/extent_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
struct extent_state *cached_state);
int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
unsigned bits, gfp_t mask);
int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
unsigned bits, gfp_t mask,
struct extent_changeset *changeset);
int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
unsigned bits, int wake, int delete,
struct extent_state **cached, gfp_t mask);
Expand Down

0 comments on commit fefdc55

Please sign in to comment.