aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@fb.com>2017-06-06 19:45:29 -0400
committerDavid Sterba <dsterba@suse.com>2017-06-29 14:17:01 -0400
commit0a16c7d7aecfae8987197e50116ebfc338cbe0a2 (patch)
tree45e7f32dd3253b5604db57d0fe198e6cef81d750
parent4da8b76d347bcae951f89522a040c36d9fc9f3b3 (diff)
Btrfs: always account pinned bytes when dropping a tree block ref
Currently, we only increment total_bytes_pinned in btrfs_free_tree_block() when dropping the last reference on the block. However, when the delayed ref is run later, we will decrement total_bytes_pinned regardless of whether it was the last reference or not. This causes the counter to underflow when the reference we dropped was not the last reference. Fix it by incrementing the counter unconditionally, which is what btrfs_free_extent() does. This makes total_bytes_pinned an overestimate when references to shared extents are dropped, but in the worst case this will just make us try to commit the transaction to try to free up space and find we didn't free enough. Signed-off-by: Omar Sandoval <osandov@fb.com> Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com> Reviewed-by: Liu Bo <bo.li.liu@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/extent-tree.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 152e04773767..40c80ed8d1f9 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -7193,10 +7193,7 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
7193 BUG_ON(ret); /* -ENOMEM */ 7193 BUG_ON(ret); /* -ENOMEM */
7194 } 7194 }
7195 7195
7196 if (!last_ref) 7196 if (last_ref && btrfs_header_generation(buf) == trans->transid) {
7197 return;
7198
7199 if (btrfs_header_generation(buf) == trans->transid) {
7200 struct btrfs_block_group_cache *cache; 7197 struct btrfs_block_group_cache *cache;
7201 7198
7202 if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { 7199 if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) {
@@ -7227,11 +7224,13 @@ out:
7227 add_pinned_bytes(fs_info, buf->len, btrfs_header_level(buf), 7224 add_pinned_bytes(fs_info, buf->len, btrfs_header_level(buf),
7228 root->root_key.objectid); 7225 root->root_key.objectid);
7229 7226
7230 /* 7227 if (last_ref) {
7231 * Deleting the buffer, clear the corrupt flag since it doesn't matter 7228 /*
7232 * anymore. 7229 * Deleting the buffer, clear the corrupt flag since it doesn't
7233 */ 7230 * matter anymore.
7234 clear_bit(EXTENT_BUFFER_CORRUPT, &buf->bflags); 7231 */
7232 clear_bit(EXTENT_BUFFER_CORRUPT, &buf->bflags);
7233 }
7235} 7234}
7236 7235
7237/* Can return -ENOMEM */ 7236/* Can return -ENOMEM */