Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 297915
b: refs/heads/master
c: 17ce6ef
h: refs/heads/master
i:
  297913: e8863d4
  297911: a904e0b
v: v3
  • Loading branch information
Liu Bo authored and Chris Mason committed Mar 29, 2012
1 parent d7c9630 commit d18e1de
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 4cb13e5d6ecc47b91b24a35f8fbc2c9f33d075fe
refs/heads/master: 17ce6ef8d731af5edac8c39e806db4c7e1f6956f
36 changes: 35 additions & 1 deletion trunk/fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,31 @@ static int find_new_extents(struct btrfs_root *root,
return -ENOENT;
}

/*
* Validaty check of prev em and next em:
* 1) no prev/next em
* 2) prev/next em is an hole/inline extent
*/
static int check_adjacent_extents(struct inode *inode, struct extent_map *em)
{
struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
struct extent_map *prev = NULL, *next = NULL;
int ret = 0;

read_lock(&em_tree->lock);
prev = lookup_extent_mapping(em_tree, em->start - 1, (u64)-1);
next = lookup_extent_mapping(em_tree, em->start + em->len, (u64)-1);
read_unlock(&em_tree->lock);

if ((!prev || prev->block_start >= EXTENT_MAP_LAST_BYTE) &&
(!next || next->block_start >= EXTENT_MAP_LAST_BYTE))
ret = 1;
free_extent_map(prev);
free_extent_map(next);

return ret;
}

static int should_defrag_range(struct inode *inode, u64 start, u64 len,
int thresh, u64 *last_len, u64 *skip,
u64 *defrag_end)
Expand Down Expand Up @@ -821,15 +846,24 @@ static int should_defrag_range(struct inode *inode, u64 start, u64 len,
}

/* this will cover holes, and inline extents */
if (em->block_start >= EXTENT_MAP_LAST_BYTE)
if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
ret = 0;
goto out;
}

/* If we have nothing to merge with us, just skip. */
if (check_adjacent_extents(inode, em)) {
ret = 0;
goto out;
}

/*
* we hit a real extent, if it is big don't bother defragging it again
*/
if ((*last_len == 0 || *last_len >= thresh) && em->len >= thresh)
ret = 0;

out:
/*
* last_len ends up being a counter of how many bytes we've defragged.
* every time we choose not to defrag an extent, we reset *last_len
Expand Down

0 comments on commit d18e1de

Please sign in to comment.