diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-04-12 21:37:04 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-04-12 21:37:04 -0400 |
commit | d6cf853d4d73c268fc8920ac4e812ee26a12847c (patch) | |
tree | c909145638eb5c4897ea7e424759eb9b564ebe18 /fs | |
parent | 6a945f38be5f2c198853069a336c887a51d1a238 (diff) | |
parent | 9f680ce04ea19dabbbafe01b57b61930a9b70741 (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/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
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/extent-tree.c | 20 | ||||
-rw-r--r-- | fs/btrfs/volumes.c | 6 |
2 files changed, 21 insertions, 5 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 9e23ffea7f54..b34d32fdaaec 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -3235,7 +3235,8 @@ int btrfs_check_data_free_space(struct btrfs_root *root, struct inode *inode, | |||
3235 | u64 bytes) | 3235 | u64 bytes) |
3236 | { | 3236 | { |
3237 | struct btrfs_space_info *data_sinfo; | 3237 | struct btrfs_space_info *data_sinfo; |
3238 | int ret = 0, committed = 0; | 3238 | u64 used; |
3239 | int ret = 0, committed = 0, flushed = 0; | ||
3239 | 3240 | ||
3240 | /* make sure bytes are sectorsize aligned */ | 3241 | /* make sure bytes are sectorsize aligned */ |
3241 | bytes = (bytes + root->sectorsize - 1) & ~((u64)root->sectorsize - 1); | 3242 | bytes = (bytes + root->sectorsize - 1) & ~((u64)root->sectorsize - 1); |
@@ -3247,12 +3248,21 @@ int btrfs_check_data_free_space(struct btrfs_root *root, struct inode *inode, | |||
3247 | again: | 3248 | again: |
3248 | /* make sure we have enough space to handle the data first */ | 3249 | /* make sure we have enough space to handle the data first */ |
3249 | spin_lock(&data_sinfo->lock); | 3250 | spin_lock(&data_sinfo->lock); |
3250 | if (data_sinfo->total_bytes - data_sinfo->bytes_used - | 3251 | used = data_sinfo->bytes_used + data_sinfo->bytes_delalloc + |
3251 | data_sinfo->bytes_delalloc - data_sinfo->bytes_reserved - | 3252 | data_sinfo->bytes_reserved + data_sinfo->bytes_pinned + |
3252 | data_sinfo->bytes_pinned - data_sinfo->bytes_readonly - | 3253 | data_sinfo->bytes_readonly + data_sinfo->bytes_may_use + |
3253 | data_sinfo->bytes_may_use - data_sinfo->bytes_super < bytes) { | 3254 | data_sinfo->bytes_super; |
3255 | |||
3256 | if (used + bytes > data_sinfo->total_bytes) { | ||
3254 | struct btrfs_trans_handle *trans; | 3257 | struct btrfs_trans_handle *trans; |
3255 | 3258 | ||
3259 | if (!flushed) { | ||
3260 | spin_unlock(&data_sinfo->lock); | ||
3261 | flush_delalloc(root, data_sinfo); | ||
3262 | flushed = 1; | ||
3263 | goto again; | ||
3264 | } | ||
3265 | |||
3256 | /* | 3266 | /* |
3257 | * if we don't have enough free bytes in this space then we need | 3267 | * if we don't have enough free bytes in this space then we need |
3258 | * to alloc a new chunk. | 3268 | * to alloc a new chunk. |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index aa7dc36dac78..8db7b14bbae8 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -2250,6 +2250,12 @@ again: | |||
2250 | if (!looped) | 2250 | if (!looped) |
2251 | calc_size = max_t(u64, min_stripe_size, calc_size); | 2251 | calc_size = max_t(u64, min_stripe_size, calc_size); |
2252 | 2252 | ||
2253 | /* | ||
2254 | * we're about to do_div by the stripe_len so lets make sure | ||
2255 | * we end up with something bigger than a stripe | ||
2256 | */ | ||
2257 | calc_size = max_t(u64, calc_size, stripe_len * 4); | ||
2258 | |||
2253 | do_div(calc_size, stripe_len); | 2259 | do_div(calc_size, stripe_len); |
2254 | calc_size *= stripe_len; | 2260 | calc_size *= stripe_len; |
2255 | 2261 | ||