Skip to content

Commit

Permalink
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/gi…
Browse files Browse the repository at this point in the history
…t/mason/btrfs-unstable

* 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable:
  Btrfs: make sure the chunk allocator doesn't create zero length chunks
  Btrfs: fix data enospc check overflow
  • Loading branch information
torvalds committed Apr 13, 2010
2 parents 6a945f3 + 9f680ce commit d6cf853
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 15 additions & 5 deletions fs/btrfs/extent-tree.c
Expand Up @@ -3235,7 +3235,8 @@ int btrfs_check_data_free_space(struct btrfs_root *root, struct inode *inode,
u64 bytes)
{
struct btrfs_space_info *data_sinfo;
int ret = 0, committed = 0;
u64 used;
int ret = 0, committed = 0, flushed = 0;

/* make sure bytes are sectorsize aligned */
bytes = (bytes + root->sectorsize - 1) & ~((u64)root->sectorsize - 1);
Expand All @@ -3247,12 +3248,21 @@ int btrfs_check_data_free_space(struct btrfs_root *root, struct inode *inode,
again:
/* make sure we have enough space to handle the data first */
spin_lock(&data_sinfo->lock);
if (data_sinfo->total_bytes - data_sinfo->bytes_used -
data_sinfo->bytes_delalloc - data_sinfo->bytes_reserved -
data_sinfo->bytes_pinned - data_sinfo->bytes_readonly -
data_sinfo->bytes_may_use - data_sinfo->bytes_super < bytes) {
used = data_sinfo->bytes_used + data_sinfo->bytes_delalloc +
data_sinfo->bytes_reserved + data_sinfo->bytes_pinned +
data_sinfo->bytes_readonly + data_sinfo->bytes_may_use +
data_sinfo->bytes_super;

if (used + bytes > data_sinfo->total_bytes) {
struct btrfs_trans_handle *trans;

if (!flushed) {
spin_unlock(&data_sinfo->lock);
flush_delalloc(root, data_sinfo);
flushed = 1;
goto again;
}

/*
* if we don't have enough free bytes in this space then we need
* to alloc a new chunk.
Expand Down
6 changes: 6 additions & 0 deletions fs/btrfs/volumes.c
Expand Up @@ -2250,6 +2250,12 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
if (!looped)
calc_size = max_t(u64, min_stripe_size, calc_size);

/*
* we're about to do_div by the stripe_len so lets make sure
* we end up with something bigger than a stripe
*/
calc_size = max_t(u64, calc_size, stripe_len * 4);

do_div(calc_size, stripe_len);
calc_size *= stripe_len;

Expand Down

0 comments on commit d6cf853

Please sign in to comment.