diff options
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/ctree.c | 30 | ||||
-rw-r--r-- | fs/btrfs/disk-io.c | 14 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 84 | ||||
-rw-r--r-- | fs/btrfs/extent_io.c | 33 | ||||
-rw-r--r-- | fs/btrfs/extent_io.h | 2 | ||||
-rw-r--r-- | fs/btrfs/file-item.c | 6 | ||||
-rw-r--r-- | fs/btrfs/file.c | 9 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 22 | ||||
-rw-r--r-- | fs/btrfs/ordered-data.c | 2 | ||||
-rw-r--r-- | fs/btrfs/qgroup.c | 3 | ||||
-rw-r--r-- | fs/btrfs/scrub.c | 3 | ||||
-rw-r--r-- | fs/btrfs/send.c | 10 | ||||
-rw-r--r-- | fs/btrfs/volumes.c | 13 |
13 files changed, 188 insertions, 43 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index ecd25a1b4e51..ca9d8f1a3bb6 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -651,6 +651,8 @@ tree_mod_log_insert_root(struct btrfs_fs_info *fs_info, | |||
651 | if (tree_mod_dont_log(fs_info, NULL)) | 651 | if (tree_mod_dont_log(fs_info, NULL)) |
652 | return 0; | 652 | return 0; |
653 | 653 | ||
654 | __tree_mod_log_free_eb(fs_info, old_root); | ||
655 | |||
654 | ret = tree_mod_alloc(fs_info, flags, &tm); | 656 | ret = tree_mod_alloc(fs_info, flags, &tm); |
655 | if (ret < 0) | 657 | if (ret < 0) |
656 | goto out; | 658 | goto out; |
@@ -736,7 +738,7 @@ tree_mod_log_search(struct btrfs_fs_info *fs_info, u64 start, u64 min_seq) | |||
736 | static noinline void | 738 | static noinline void |
737 | tree_mod_log_eb_copy(struct btrfs_fs_info *fs_info, struct extent_buffer *dst, | 739 | tree_mod_log_eb_copy(struct btrfs_fs_info *fs_info, struct extent_buffer *dst, |
738 | struct extent_buffer *src, unsigned long dst_offset, | 740 | struct extent_buffer *src, unsigned long dst_offset, |
739 | unsigned long src_offset, int nr_items) | 741 | unsigned long src_offset, int nr_items, int log_removal) |
740 | { | 742 | { |
741 | int ret; | 743 | int ret; |
742 | int i; | 744 | int i; |
@@ -750,10 +752,12 @@ tree_mod_log_eb_copy(struct btrfs_fs_info *fs_info, struct extent_buffer *dst, | |||
750 | } | 752 | } |
751 | 753 | ||
752 | for (i = 0; i < nr_items; i++) { | 754 | for (i = 0; i < nr_items; i++) { |
753 | ret = tree_mod_log_insert_key_locked(fs_info, src, | 755 | if (log_removal) { |
754 | i + src_offset, | 756 | ret = tree_mod_log_insert_key_locked(fs_info, src, |
755 | MOD_LOG_KEY_REMOVE); | 757 | i + src_offset, |
756 | BUG_ON(ret < 0); | 758 | MOD_LOG_KEY_REMOVE); |
759 | BUG_ON(ret < 0); | ||
760 | } | ||
757 | ret = tree_mod_log_insert_key_locked(fs_info, dst, | 761 | ret = tree_mod_log_insert_key_locked(fs_info, dst, |
758 | i + dst_offset, | 762 | i + dst_offset, |
759 | MOD_LOG_KEY_ADD); | 763 | MOD_LOG_KEY_ADD); |
@@ -927,7 +931,6 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans, | |||
927 | ret = btrfs_dec_ref(trans, root, buf, 1, 1); | 931 | ret = btrfs_dec_ref(trans, root, buf, 1, 1); |
928 | BUG_ON(ret); /* -ENOMEM */ | 932 | BUG_ON(ret); /* -ENOMEM */ |
929 | } | 933 | } |
930 | tree_mod_log_free_eb(root->fs_info, buf); | ||
931 | clean_tree_block(trans, root, buf); | 934 | clean_tree_block(trans, root, buf); |
932 | *last_ref = 1; | 935 | *last_ref = 1; |
933 | } | 936 | } |
@@ -1046,6 +1049,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans, | |||
1046 | btrfs_set_node_ptr_generation(parent, parent_slot, | 1049 | btrfs_set_node_ptr_generation(parent, parent_slot, |
1047 | trans->transid); | 1050 | trans->transid); |
1048 | btrfs_mark_buffer_dirty(parent); | 1051 | btrfs_mark_buffer_dirty(parent); |
1052 | tree_mod_log_free_eb(root->fs_info, buf); | ||
1049 | btrfs_free_tree_block(trans, root, buf, parent_start, | 1053 | btrfs_free_tree_block(trans, root, buf, parent_start, |
1050 | last_ref); | 1054 | last_ref); |
1051 | } | 1055 | } |
@@ -1750,7 +1754,6 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, | |||
1750 | goto enospc; | 1754 | goto enospc; |
1751 | } | 1755 | } |
1752 | 1756 | ||
1753 | tree_mod_log_free_eb(root->fs_info, root->node); | ||
1754 | tree_mod_log_set_root_pointer(root, child); | 1757 | tree_mod_log_set_root_pointer(root, child); |
1755 | rcu_assign_pointer(root->node, child); | 1758 | rcu_assign_pointer(root->node, child); |
1756 | 1759 | ||
@@ -2995,7 +2998,7 @@ static int push_node_left(struct btrfs_trans_handle *trans, | |||
2995 | push_items = min(src_nritems - 8, push_items); | 2998 | push_items = min(src_nritems - 8, push_items); |
2996 | 2999 | ||
2997 | tree_mod_log_eb_copy(root->fs_info, dst, src, dst_nritems, 0, | 3000 | tree_mod_log_eb_copy(root->fs_info, dst, src, dst_nritems, 0, |
2998 | push_items); | 3001 | push_items, 1); |
2999 | copy_extent_buffer(dst, src, | 3002 | copy_extent_buffer(dst, src, |
3000 | btrfs_node_key_ptr_offset(dst_nritems), | 3003 | btrfs_node_key_ptr_offset(dst_nritems), |
3001 | btrfs_node_key_ptr_offset(0), | 3004 | btrfs_node_key_ptr_offset(0), |
@@ -3066,7 +3069,7 @@ static int balance_node_right(struct btrfs_trans_handle *trans, | |||
3066 | sizeof(struct btrfs_key_ptr)); | 3069 | sizeof(struct btrfs_key_ptr)); |
3067 | 3070 | ||
3068 | tree_mod_log_eb_copy(root->fs_info, dst, src, 0, | 3071 | tree_mod_log_eb_copy(root->fs_info, dst, src, 0, |
3069 | src_nritems - push_items, push_items); | 3072 | src_nritems - push_items, push_items, 1); |
3070 | copy_extent_buffer(dst, src, | 3073 | copy_extent_buffer(dst, src, |
3071 | btrfs_node_key_ptr_offset(0), | 3074 | btrfs_node_key_ptr_offset(0), |
3072 | btrfs_node_key_ptr_offset(src_nritems - push_items), | 3075 | btrfs_node_key_ptr_offset(src_nritems - push_items), |
@@ -3218,12 +3221,18 @@ static noinline int split_node(struct btrfs_trans_handle *trans, | |||
3218 | int mid; | 3221 | int mid; |
3219 | int ret; | 3222 | int ret; |
3220 | u32 c_nritems; | 3223 | u32 c_nritems; |
3224 | int tree_mod_log_removal = 1; | ||
3221 | 3225 | ||
3222 | c = path->nodes[level]; | 3226 | c = path->nodes[level]; |
3223 | WARN_ON(btrfs_header_generation(c) != trans->transid); | 3227 | WARN_ON(btrfs_header_generation(c) != trans->transid); |
3224 | if (c == root->node) { | 3228 | if (c == root->node) { |
3225 | /* trying to split the root, lets make a new one */ | 3229 | /* trying to split the root, lets make a new one */ |
3226 | ret = insert_new_root(trans, root, path, level + 1); | 3230 | ret = insert_new_root(trans, root, path, level + 1); |
3231 | /* | ||
3232 | * removal of root nodes has been logged by | ||
3233 | * tree_mod_log_set_root_pointer due to locking | ||
3234 | */ | ||
3235 | tree_mod_log_removal = 0; | ||
3227 | if (ret) | 3236 | if (ret) |
3228 | return ret; | 3237 | return ret; |
3229 | } else { | 3238 | } else { |
@@ -3261,7 +3270,8 @@ static noinline int split_node(struct btrfs_trans_handle *trans, | |||
3261 | (unsigned long)btrfs_header_chunk_tree_uuid(split), | 3270 | (unsigned long)btrfs_header_chunk_tree_uuid(split), |
3262 | BTRFS_UUID_SIZE); | 3271 | BTRFS_UUID_SIZE); |
3263 | 3272 | ||
3264 | tree_mod_log_eb_copy(root->fs_info, split, c, 0, mid, c_nritems - mid); | 3273 | tree_mod_log_eb_copy(root->fs_info, split, c, 0, mid, c_nritems - mid, |
3274 | tree_mod_log_removal); | ||
3265 | copy_extent_buffer(split, c, | 3275 | copy_extent_buffer(split, c, |
3266 | btrfs_node_key_ptr_offset(0), | 3276 | btrfs_node_key_ptr_offset(0), |
3267 | btrfs_node_key_ptr_offset(mid), | 3277 | btrfs_node_key_ptr_offset(mid), |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 7d84651e850b..6d19a0a554aa 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -1291,6 +1291,7 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, | |||
1291 | 0, objectid, NULL, 0, 0, 0); | 1291 | 0, objectid, NULL, 0, 0, 0); |
1292 | if (IS_ERR(leaf)) { | 1292 | if (IS_ERR(leaf)) { |
1293 | ret = PTR_ERR(leaf); | 1293 | ret = PTR_ERR(leaf); |
1294 | leaf = NULL; | ||
1294 | goto fail; | 1295 | goto fail; |
1295 | } | 1296 | } |
1296 | 1297 | ||
@@ -1334,11 +1335,16 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, | |||
1334 | 1335 | ||
1335 | btrfs_tree_unlock(leaf); | 1336 | btrfs_tree_unlock(leaf); |
1336 | 1337 | ||
1338 | return root; | ||
1339 | |||
1337 | fail: | 1340 | fail: |
1338 | if (ret) | 1341 | if (leaf) { |
1339 | return ERR_PTR(ret); | 1342 | btrfs_tree_unlock(leaf); |
1343 | free_extent_buffer(leaf); | ||
1344 | } | ||
1345 | kfree(root); | ||
1340 | 1346 | ||
1341 | return root; | 1347 | return ERR_PTR(ret); |
1342 | } | 1348 | } |
1343 | 1349 | ||
1344 | static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, | 1350 | static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, |
@@ -3253,7 +3259,7 @@ void btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root) | |||
3253 | if (btrfs_root_refs(&root->root_item) == 0) | 3259 | if (btrfs_root_refs(&root->root_item) == 0) |
3254 | synchronize_srcu(&fs_info->subvol_srcu); | 3260 | synchronize_srcu(&fs_info->subvol_srcu); |
3255 | 3261 | ||
3256 | if (fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) { | 3262 | if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { |
3257 | btrfs_free_log(NULL, root); | 3263 | btrfs_free_log(NULL, root); |
3258 | btrfs_free_log_root_tree(NULL, fs_info); | 3264 | btrfs_free_log_root_tree(NULL, fs_info); |
3259 | } | 3265 | } |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 9ac2eca681eb..3d551231caba 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -257,7 +257,8 @@ static int exclude_super_stripes(struct btrfs_root *root, | |||
257 | cache->bytes_super += stripe_len; | 257 | cache->bytes_super += stripe_len; |
258 | ret = add_excluded_extent(root, cache->key.objectid, | 258 | ret = add_excluded_extent(root, cache->key.objectid, |
259 | stripe_len); | 259 | stripe_len); |
260 | BUG_ON(ret); /* -ENOMEM */ | 260 | if (ret) |
261 | return ret; | ||
261 | } | 262 | } |
262 | 263 | ||
263 | for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { | 264 | for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { |
@@ -265,13 +266,17 @@ static int exclude_super_stripes(struct btrfs_root *root, | |||
265 | ret = btrfs_rmap_block(&root->fs_info->mapping_tree, | 266 | ret = btrfs_rmap_block(&root->fs_info->mapping_tree, |
266 | cache->key.objectid, bytenr, | 267 | cache->key.objectid, bytenr, |
267 | 0, &logical, &nr, &stripe_len); | 268 | 0, &logical, &nr, &stripe_len); |
268 | BUG_ON(ret); /* -ENOMEM */ | 269 | if (ret) |
270 | return ret; | ||
269 | 271 | ||
270 | while (nr--) { | 272 | while (nr--) { |
271 | cache->bytes_super += stripe_len; | 273 | cache->bytes_super += stripe_len; |
272 | ret = add_excluded_extent(root, logical[nr], | 274 | ret = add_excluded_extent(root, logical[nr], |
273 | stripe_len); | 275 | stripe_len); |
274 | BUG_ON(ret); /* -ENOMEM */ | 276 | if (ret) { |
277 | kfree(logical); | ||
278 | return ret; | ||
279 | } | ||
275 | } | 280 | } |
276 | 281 | ||
277 | kfree(logical); | 282 | kfree(logical); |
@@ -4438,7 +4443,7 @@ static void update_global_block_rsv(struct btrfs_fs_info *fs_info) | |||
4438 | spin_lock(&sinfo->lock); | 4443 | spin_lock(&sinfo->lock); |
4439 | spin_lock(&block_rsv->lock); | 4444 | spin_lock(&block_rsv->lock); |
4440 | 4445 | ||
4441 | block_rsv->size = num_bytes; | 4446 | block_rsv->size = min_t(u64, num_bytes, 512 * 1024 * 1024); |
4442 | 4447 | ||
4443 | num_bytes = sinfo->bytes_used + sinfo->bytes_pinned + | 4448 | num_bytes = sinfo->bytes_used + sinfo->bytes_pinned + |
4444 | sinfo->bytes_reserved + sinfo->bytes_readonly + | 4449 | sinfo->bytes_reserved + sinfo->bytes_readonly + |
@@ -4793,14 +4798,49 @@ out_fail: | |||
4793 | * If the inodes csum_bytes is the same as the original | 4798 | * If the inodes csum_bytes is the same as the original |
4794 | * csum_bytes then we know we haven't raced with any free()ers | 4799 | * csum_bytes then we know we haven't raced with any free()ers |
4795 | * so we can just reduce our inodes csum bytes and carry on. | 4800 | * so we can just reduce our inodes csum bytes and carry on. |
4796 | * Otherwise we have to do the normal free thing to account for | ||
4797 | * the case that the free side didn't free up its reserve | ||
4798 | * because of this outstanding reservation. | ||
4799 | */ | 4801 | */ |
4800 | if (BTRFS_I(inode)->csum_bytes == csum_bytes) | 4802 | if (BTRFS_I(inode)->csum_bytes == csum_bytes) { |
4801 | calc_csum_metadata_size(inode, num_bytes, 0); | 4803 | calc_csum_metadata_size(inode, num_bytes, 0); |
4802 | else | 4804 | } else { |
4803 | to_free = calc_csum_metadata_size(inode, num_bytes, 0); | 4805 | u64 orig_csum_bytes = BTRFS_I(inode)->csum_bytes; |
4806 | u64 bytes; | ||
4807 | |||
4808 | /* | ||
4809 | * This is tricky, but first we need to figure out how much we | ||
4810 | * free'd from any free-ers that occured during this | ||
4811 | * reservation, so we reset ->csum_bytes to the csum_bytes | ||
4812 | * before we dropped our lock, and then call the free for the | ||
4813 | * number of bytes that were freed while we were trying our | ||
4814 | * reservation. | ||
4815 | */ | ||
4816 | bytes = csum_bytes - BTRFS_I(inode)->csum_bytes; | ||
4817 | BTRFS_I(inode)->csum_bytes = csum_bytes; | ||
4818 | to_free = calc_csum_metadata_size(inode, bytes, 0); | ||
4819 | |||
4820 | |||
4821 | /* | ||
4822 | * Now we need to see how much we would have freed had we not | ||
4823 | * been making this reservation and our ->csum_bytes were not | ||
4824 | * artificially inflated. | ||
4825 | */ | ||
4826 | BTRFS_I(inode)->csum_bytes = csum_bytes - num_bytes; | ||
4827 | bytes = csum_bytes - orig_csum_bytes; | ||
4828 | bytes = calc_csum_metadata_size(inode, bytes, 0); | ||
4829 | |||
4830 | /* | ||
4831 | * Now reset ->csum_bytes to what it should be. If bytes is | ||
4832 | * more than to_free then we would have free'd more space had we | ||
4833 | * not had an artificially high ->csum_bytes, so we need to free | ||
4834 | * the remainder. If bytes is the same or less then we don't | ||
4835 | * need to do anything, the other free-ers did the correct | ||
4836 | * thing. | ||
4837 | */ | ||
4838 | BTRFS_I(inode)->csum_bytes = orig_csum_bytes - num_bytes; | ||
4839 | if (bytes > to_free) | ||
4840 | to_free = bytes - to_free; | ||
4841 | else | ||
4842 | to_free = 0; | ||
4843 | } | ||
4804 | spin_unlock(&BTRFS_I(inode)->lock); | 4844 | spin_unlock(&BTRFS_I(inode)->lock); |
4805 | if (dropped) | 4845 | if (dropped) |
4806 | to_free += btrfs_calc_trans_metadata_size(root, dropped); | 4846 | to_free += btrfs_calc_trans_metadata_size(root, dropped); |
@@ -7947,7 +7987,17 @@ int btrfs_read_block_groups(struct btrfs_root *root) | |||
7947 | * info has super bytes accounted for, otherwise we'll think | 7987 | * info has super bytes accounted for, otherwise we'll think |
7948 | * we have more space than we actually do. | 7988 | * we have more space than we actually do. |
7949 | */ | 7989 | */ |
7950 | exclude_super_stripes(root, cache); | 7990 | ret = exclude_super_stripes(root, cache); |
7991 | if (ret) { | ||
7992 | /* | ||
7993 | * We may have excluded something, so call this just in | ||
7994 | * case. | ||
7995 | */ | ||
7996 | free_excluded_extents(root, cache); | ||
7997 | kfree(cache->free_space_ctl); | ||
7998 | kfree(cache); | ||
7999 | goto error; | ||
8000 | } | ||
7951 | 8001 | ||
7952 | /* | 8002 | /* |
7953 | * check for two cases, either we are full, and therefore | 8003 | * check for two cases, either we are full, and therefore |
@@ -8089,7 +8139,17 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans, | |||
8089 | 8139 | ||
8090 | cache->last_byte_to_unpin = (u64)-1; | 8140 | cache->last_byte_to_unpin = (u64)-1; |
8091 | cache->cached = BTRFS_CACHE_FINISHED; | 8141 | cache->cached = BTRFS_CACHE_FINISHED; |
8092 | exclude_super_stripes(root, cache); | 8142 | ret = exclude_super_stripes(root, cache); |
8143 | if (ret) { | ||
8144 | /* | ||
8145 | * We may have excluded something, so call this just in | ||
8146 | * case. | ||
8147 | */ | ||
8148 | free_excluded_extents(root, cache); | ||
8149 | kfree(cache->free_space_ctl); | ||
8150 | kfree(cache); | ||
8151 | return ret; | ||
8152 | } | ||
8093 | 8153 | ||
8094 | add_new_free_space(cache, root->fs_info, chunk_offset, | 8154 | add_new_free_space(cache, root->fs_info, chunk_offset, |
8095 | chunk_offset + size); | 8155 | chunk_offset + size); |
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index f173c5af6461..cdee391fc7bf 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
@@ -1257,6 +1257,39 @@ int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end) | |||
1257 | GFP_NOFS); | 1257 | GFP_NOFS); |
1258 | } | 1258 | } |
1259 | 1259 | ||
1260 | int extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end) | ||
1261 | { | ||
1262 | unsigned long index = start >> PAGE_CACHE_SHIFT; | ||
1263 | unsigned long end_index = end >> PAGE_CACHE_SHIFT; | ||
1264 | struct page *page; | ||
1265 | |||
1266 | while (index <= end_index) { | ||
1267 | page = find_get_page(inode->i_mapping, index); | ||
1268 | BUG_ON(!page); /* Pages should be in the extent_io_tree */ | ||
1269 | clear_page_dirty_for_io(page); | ||
1270 | page_cache_release(page); | ||
1271 | index++; | ||
1272 | } | ||
1273 | return 0; | ||
1274 | } | ||
1275 | |||
1276 | int extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end) | ||
1277 | { | ||
1278 | unsigned long index = start >> PAGE_CACHE_SHIFT; | ||
1279 | unsigned long end_index = end >> PAGE_CACHE_SHIFT; | ||
1280 | struct page *page; | ||
1281 | |||
1282 | while (index <= end_index) { | ||
1283 | page = find_get_page(inode->i_mapping, index); | ||
1284 | BUG_ON(!page); /* Pages should be in the extent_io_tree */ | ||
1285 | account_page_redirty(page); | ||
1286 | __set_page_dirty_nobuffers(page); | ||
1287 | page_cache_release(page); | ||
1288 | index++; | ||
1289 | } | ||
1290 | return 0; | ||
1291 | } | ||
1292 | |||
1260 | /* | 1293 | /* |
1261 | * helper function to set both pages and extents in the tree writeback | 1294 | * helper function to set both pages and extents in the tree writeback |
1262 | */ | 1295 | */ |
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index 6068a1985560..258c92156857 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h | |||
@@ -325,6 +325,8 @@ int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset, | |||
325 | unsigned long *map_len); | 325 | unsigned long *map_len); |
326 | int extent_range_uptodate(struct extent_io_tree *tree, | 326 | int extent_range_uptodate(struct extent_io_tree *tree, |
327 | u64 start, u64 end); | 327 | u64 start, u64 end); |
328 | int extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end); | ||
329 | int extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end); | ||
328 | int extent_clear_unlock_delalloc(struct inode *inode, | 330 | int extent_clear_unlock_delalloc(struct inode *inode, |
329 | struct extent_io_tree *tree, | 331 | struct extent_io_tree *tree, |
330 | u64 start, u64 end, struct page *locked_page, | 332 | u64 start, u64 end, struct page *locked_page, |
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index ec160202be3e..c4628a201cb3 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c | |||
@@ -118,9 +118,11 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, | |||
118 | csums_in_item = btrfs_item_size_nr(leaf, path->slots[0]); | 118 | csums_in_item = btrfs_item_size_nr(leaf, path->slots[0]); |
119 | csums_in_item /= csum_size; | 119 | csums_in_item /= csum_size; |
120 | 120 | ||
121 | if (csum_offset >= csums_in_item) { | 121 | if (csum_offset == csums_in_item) { |
122 | ret = -EFBIG; | 122 | ret = -EFBIG; |
123 | goto fail; | 123 | goto fail; |
124 | } else if (csum_offset > csums_in_item) { | ||
125 | goto fail; | ||
124 | } | 126 | } |
125 | } | 127 | } |
126 | item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_csum_item); | 128 | item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_csum_item); |
@@ -728,7 +730,6 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, | |||
728 | return -ENOMEM; | 730 | return -ENOMEM; |
729 | 731 | ||
730 | sector_sum = sums->sums; | 732 | sector_sum = sums->sums; |
731 | trans->adding_csums = 1; | ||
732 | again: | 733 | again: |
733 | next_offset = (u64)-1; | 734 | next_offset = (u64)-1; |
734 | found_next = 0; | 735 | found_next = 0; |
@@ -899,7 +900,6 @@ next_sector: | |||
899 | goto again; | 900 | goto again; |
900 | } | 901 | } |
901 | out: | 902 | out: |
902 | trans->adding_csums = 0; | ||
903 | btrfs_free_path(path); | 903 | btrfs_free_path(path); |
904 | return ret; | 904 | return ret; |
905 | 905 | ||
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 5b4ea5f55b8f..ade03e6f7bd2 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -2142,6 +2142,7 @@ static long btrfs_fallocate(struct file *file, int mode, | |||
2142 | { | 2142 | { |
2143 | struct inode *inode = file_inode(file); | 2143 | struct inode *inode = file_inode(file); |
2144 | struct extent_state *cached_state = NULL; | 2144 | struct extent_state *cached_state = NULL; |
2145 | struct btrfs_root *root = BTRFS_I(inode)->root; | ||
2145 | u64 cur_offset; | 2146 | u64 cur_offset; |
2146 | u64 last_byte; | 2147 | u64 last_byte; |
2147 | u64 alloc_start; | 2148 | u64 alloc_start; |
@@ -2169,6 +2170,11 @@ static long btrfs_fallocate(struct file *file, int mode, | |||
2169 | ret = btrfs_check_data_free_space(inode, alloc_end - alloc_start); | 2170 | ret = btrfs_check_data_free_space(inode, alloc_end - alloc_start); |
2170 | if (ret) | 2171 | if (ret) |
2171 | return ret; | 2172 | return ret; |
2173 | if (root->fs_info->quota_enabled) { | ||
2174 | ret = btrfs_qgroup_reserve(root, alloc_end - alloc_start); | ||
2175 | if (ret) | ||
2176 | goto out_reserve_fail; | ||
2177 | } | ||
2172 | 2178 | ||
2173 | /* | 2179 | /* |
2174 | * wait for ordered IO before we have any locks. We'll loop again | 2180 | * wait for ordered IO before we have any locks. We'll loop again |
@@ -2272,6 +2278,9 @@ static long btrfs_fallocate(struct file *file, int mode, | |||
2272 | &cached_state, GFP_NOFS); | 2278 | &cached_state, GFP_NOFS); |
2273 | out: | 2279 | out: |
2274 | mutex_unlock(&inode->i_mutex); | 2280 | mutex_unlock(&inode->i_mutex); |
2281 | if (root->fs_info->quota_enabled) | ||
2282 | btrfs_qgroup_free(root, alloc_end - alloc_start); | ||
2283 | out_reserve_fail: | ||
2275 | /* Let go of our reservation. */ | 2284 | /* Let go of our reservation. */ |
2276 | btrfs_free_reserved_data_space(inode, alloc_end - alloc_start); | 2285 | btrfs_free_reserved_data_space(inode, alloc_end - alloc_start); |
2277 | return ret; | 2286 | return ret; |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index ca1b767d51f7..09c58a35b429 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -353,6 +353,7 @@ static noinline int compress_file_range(struct inode *inode, | |||
353 | int i; | 353 | int i; |
354 | int will_compress; | 354 | int will_compress; |
355 | int compress_type = root->fs_info->compress_type; | 355 | int compress_type = root->fs_info->compress_type; |
356 | int redirty = 0; | ||
356 | 357 | ||
357 | /* if this is a small write inside eof, kick off a defrag */ | 358 | /* if this is a small write inside eof, kick off a defrag */ |
358 | if ((end - start + 1) < 16 * 1024 && | 359 | if ((end - start + 1) < 16 * 1024 && |
@@ -415,6 +416,17 @@ again: | |||
415 | if (BTRFS_I(inode)->force_compress) | 416 | if (BTRFS_I(inode)->force_compress) |
416 | compress_type = BTRFS_I(inode)->force_compress; | 417 | compress_type = BTRFS_I(inode)->force_compress; |
417 | 418 | ||
419 | /* | ||
420 | * we need to call clear_page_dirty_for_io on each | ||
421 | * page in the range. Otherwise applications with the file | ||
422 | * mmap'd can wander in and change the page contents while | ||
423 | * we are compressing them. | ||
424 | * | ||
425 | * If the compression fails for any reason, we set the pages | ||
426 | * dirty again later on. | ||
427 | */ | ||
428 | extent_range_clear_dirty_for_io(inode, start, end); | ||
429 | redirty = 1; | ||
418 | ret = btrfs_compress_pages(compress_type, | 430 | ret = btrfs_compress_pages(compress_type, |
419 | inode->i_mapping, start, | 431 | inode->i_mapping, start, |
420 | total_compressed, pages, | 432 | total_compressed, pages, |
@@ -554,6 +566,8 @@ cleanup_and_bail_uncompressed: | |||
554 | __set_page_dirty_nobuffers(locked_page); | 566 | __set_page_dirty_nobuffers(locked_page); |
555 | /* unlocked later on in the async handlers */ | 567 | /* unlocked later on in the async handlers */ |
556 | } | 568 | } |
569 | if (redirty) | ||
570 | extent_range_redirty_for_io(inode, start, end); | ||
557 | add_async_extent(async_cow, start, end - start + 1, | 571 | add_async_extent(async_cow, start, end - start + 1, |
558 | 0, NULL, 0, BTRFS_COMPRESS_NONE); | 572 | 0, NULL, 0, BTRFS_COMPRESS_NONE); |
559 | *num_added += 1; | 573 | *num_added += 1; |
@@ -1743,8 +1757,10 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans, | |||
1743 | struct btrfs_ordered_sum *sum; | 1757 | struct btrfs_ordered_sum *sum; |
1744 | 1758 | ||
1745 | list_for_each_entry(sum, list, list) { | 1759 | list_for_each_entry(sum, list, list) { |
1760 | trans->adding_csums = 1; | ||
1746 | btrfs_csum_file_blocks(trans, | 1761 | btrfs_csum_file_blocks(trans, |
1747 | BTRFS_I(inode)->root->fs_info->csum_root, sum); | 1762 | BTRFS_I(inode)->root->fs_info->csum_root, sum); |
1763 | trans->adding_csums = 0; | ||
1748 | } | 1764 | } |
1749 | return 0; | 1765 | return 0; |
1750 | } | 1766 | } |
@@ -3679,11 +3695,9 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir, | |||
3679 | * 1 for the dir item | 3695 | * 1 for the dir item |
3680 | * 1 for the dir index | 3696 | * 1 for the dir index |
3681 | * 1 for the inode ref | 3697 | * 1 for the inode ref |
3682 | * 1 for the inode ref in the tree log | ||
3683 | * 2 for the dir entries in the log | ||
3684 | * 1 for the inode | 3698 | * 1 for the inode |
3685 | */ | 3699 | */ |
3686 | trans = btrfs_start_transaction(root, 8); | 3700 | trans = btrfs_start_transaction(root, 5); |
3687 | if (!IS_ERR(trans) || PTR_ERR(trans) != -ENOSPC) | 3701 | if (!IS_ERR(trans) || PTR_ERR(trans) != -ENOSPC) |
3688 | return trans; | 3702 | return trans; |
3689 | 3703 | ||
@@ -8127,7 +8141,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
8127 | * inodes. So 5 * 2 is 10, plus 1 for the new link, so 11 total items | 8141 | * inodes. So 5 * 2 is 10, plus 1 for the new link, so 11 total items |
8128 | * should cover the worst case number of items we'll modify. | 8142 | * should cover the worst case number of items we'll modify. |
8129 | */ | 8143 | */ |
8130 | trans = btrfs_start_transaction(root, 20); | 8144 | trans = btrfs_start_transaction(root, 11); |
8131 | if (IS_ERR(trans)) { | 8145 | if (IS_ERR(trans)) { |
8132 | ret = PTR_ERR(trans); | 8146 | ret = PTR_ERR(trans); |
8133 | goto out_notrans; | 8147 | goto out_notrans; |
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index dc08d77b717e..005c45db699e 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c | |||
@@ -557,6 +557,7 @@ void btrfs_wait_ordered_extents(struct btrfs_root *root, int delay_iput) | |||
557 | INIT_LIST_HEAD(&splice); | 557 | INIT_LIST_HEAD(&splice); |
558 | INIT_LIST_HEAD(&works); | 558 | INIT_LIST_HEAD(&works); |
559 | 559 | ||
560 | mutex_lock(&root->fs_info->ordered_operations_mutex); | ||
560 | spin_lock(&root->fs_info->ordered_extent_lock); | 561 | spin_lock(&root->fs_info->ordered_extent_lock); |
561 | list_splice_init(&root->fs_info->ordered_extents, &splice); | 562 | list_splice_init(&root->fs_info->ordered_extents, &splice); |
562 | while (!list_empty(&splice)) { | 563 | while (!list_empty(&splice)) { |
@@ -600,6 +601,7 @@ void btrfs_wait_ordered_extents(struct btrfs_root *root, int delay_iput) | |||
600 | 601 | ||
601 | cond_resched(); | 602 | cond_resched(); |
602 | } | 603 | } |
604 | mutex_unlock(&root->fs_info->ordered_operations_mutex); | ||
603 | } | 605 | } |
604 | 606 | ||
605 | /* | 607 | /* |
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 5471e47d6559..b44124dd2370 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c | |||
@@ -1153,7 +1153,7 @@ int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans, | |||
1153 | ret = btrfs_find_all_roots(trans, fs_info, node->bytenr, | 1153 | ret = btrfs_find_all_roots(trans, fs_info, node->bytenr, |
1154 | sgn > 0 ? node->seq - 1 : node->seq, &roots); | 1154 | sgn > 0 ? node->seq - 1 : node->seq, &roots); |
1155 | if (ret < 0) | 1155 | if (ret < 0) |
1156 | goto out; | 1156 | return ret; |
1157 | 1157 | ||
1158 | spin_lock(&fs_info->qgroup_lock); | 1158 | spin_lock(&fs_info->qgroup_lock); |
1159 | quota_root = fs_info->quota_root; | 1159 | quota_root = fs_info->quota_root; |
@@ -1275,7 +1275,6 @@ int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans, | |||
1275 | ret = 0; | 1275 | ret = 0; |
1276 | unlock: | 1276 | unlock: |
1277 | spin_unlock(&fs_info->qgroup_lock); | 1277 | spin_unlock(&fs_info->qgroup_lock); |
1278 | out: | ||
1279 | ulist_free(roots); | 1278 | ulist_free(roots); |
1280 | ulist_free(tmp); | 1279 | ulist_free(tmp); |
1281 | 1280 | ||
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 53c3501fa4ca..85e072b956d5 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c | |||
@@ -542,7 +542,6 @@ static void scrub_print_warning(const char *errstr, struct scrub_block *sblock) | |||
542 | eb = path->nodes[0]; | 542 | eb = path->nodes[0]; |
543 | ei = btrfs_item_ptr(eb, path->slots[0], struct btrfs_extent_item); | 543 | ei = btrfs_item_ptr(eb, path->slots[0], struct btrfs_extent_item); |
544 | item_size = btrfs_item_size_nr(eb, path->slots[0]); | 544 | item_size = btrfs_item_size_nr(eb, path->slots[0]); |
545 | btrfs_release_path(path); | ||
546 | 545 | ||
547 | if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) { | 546 | if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) { |
548 | do { | 547 | do { |
@@ -558,7 +557,9 @@ static void scrub_print_warning(const char *errstr, struct scrub_block *sblock) | |||
558 | ret < 0 ? -1 : ref_level, | 557 | ret < 0 ? -1 : ref_level, |
559 | ret < 0 ? -1 : ref_root); | 558 | ret < 0 ? -1 : ref_root); |
560 | } while (ret != 1); | 559 | } while (ret != 1); |
560 | btrfs_release_path(path); | ||
561 | } else { | 561 | } else { |
562 | btrfs_release_path(path); | ||
562 | swarn.path = path; | 563 | swarn.path = path; |
563 | swarn.dev = dev; | 564 | swarn.dev = dev; |
564 | iterate_extent_inodes(fs_info, found_key.objectid, | 565 | iterate_extent_inodes(fs_info, found_key.objectid, |
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index f7a8b861058b..c85e7c6b4598 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c | |||
@@ -3945,12 +3945,10 @@ static int is_extent_unchanged(struct send_ctx *sctx, | |||
3945 | found_key.type != key.type) { | 3945 | found_key.type != key.type) { |
3946 | key.offset += right_len; | 3946 | key.offset += right_len; |
3947 | break; | 3947 | break; |
3948 | } else { | 3948 | } |
3949 | if (found_key.offset != key.offset + right_len) { | 3949 | if (found_key.offset != key.offset + right_len) { |
3950 | /* Should really not happen */ | 3950 | ret = 0; |
3951 | ret = -EIO; | 3951 | goto out; |
3952 | goto out; | ||
3953 | } | ||
3954 | } | 3952 | } |
3955 | key = found_key; | 3953 | key = found_key; |
3956 | } | 3954 | } |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 5989a92236f7..2854c824ab64 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -4935,7 +4935,18 @@ int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree, | |||
4935 | em = lookup_extent_mapping(em_tree, chunk_start, 1); | 4935 | em = lookup_extent_mapping(em_tree, chunk_start, 1); |
4936 | read_unlock(&em_tree->lock); | 4936 | read_unlock(&em_tree->lock); |
4937 | 4937 | ||
4938 | BUG_ON(!em || em->start != chunk_start); | 4938 | if (!em) { |
4939 | printk(KERN_ERR "btrfs: couldn't find em for chunk %Lu\n", | ||
4940 | chunk_start); | ||
4941 | return -EIO; | ||
4942 | } | ||
4943 | |||
4944 | if (em->start != chunk_start) { | ||
4945 | printk(KERN_ERR "btrfs: bad chunk start, em=%Lu, wanted=%Lu\n", | ||
4946 | em->start, chunk_start); | ||
4947 | free_extent_map(em); | ||
4948 | return -EIO; | ||
4949 | } | ||
4939 | map = (struct map_lookup *)em->bdev; | 4950 | map = (struct map_lookup *)em->bdev; |
4940 | 4951 | ||
4941 | length = em->len; | 4952 | length = em->len; |