Blob Blame History Raw
From: Jeff Mahoney <jeffm@suse.com>
Subject: btrfs: dump_space_info when encountering total_bytes_pinned != 0 at umount
Patch-mainline: Submitted, as review feedback: https://www.spinics.net/lists/linux-btrfs/msg66484.html
References: bsc#1040182

This patch dumps the spaceinfo when we hit total_bytes_pinned != 0 so we
can track down likely causes.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/block-group.c |    5 ++++-
 fs/btrfs/extent-tree.c |    1 -
 fs/btrfs/space-info.c  |    2 ++
 3 files changed, 6 insertions(+), 2 deletions(-)

--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -3254,6 +3254,7 @@ int btrfs_free_block_groups(struct btrfs
 
 	while (!list_empty(&info->space_info)) {
 		int i;
+		s64 pinned;
 		space_info = list_entry(info->space_info.next,
 					struct btrfs_space_info,
 					list);
@@ -3262,9 +3263,11 @@ int btrfs_free_block_groups(struct btrfs
 		 * Do not hide this behind enospc_debug, this is actually
 		 * important and indicates a real bug if this happens.
 		 */
+		pinned = percpu_counter_sum(&space_info->total_bytes_pinned);
 		if (WARN_ON(space_info->bytes_pinned > 0 ||
 			    space_info->bytes_reserved > 0 ||
-			    space_info->bytes_may_use > 0))
+			    space_info->bytes_may_use > 0 ||
+			    pinned != 0))
 			btrfs_dump_space_info(info, space_info, 0, 0);
 		WARN_ON(space_info->reclaim_size > 0);
 		list_del(&space_info->list);
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1325,7 +1325,6 @@ int btrfs_discard_extent(struct btrfs_fs
 		struct btrfs_bio_stripe *stripe = bbio->stripes;
 		int i;
 
-
 		for (i = 0; i < bbio->num_stripes; i++, stripe++) {
 			u64 bytes;
 			struct request_queue *req_q;
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -302,6 +302,8 @@ static void __btrfs_dump_space_info(stru
 		info->total_bytes, info->bytes_used, info->bytes_pinned,
 		info->bytes_reserved, info->bytes_may_use,
 		info->bytes_readonly);
+	btrfs_info(fs_info, "total_bytes_pinned=%lld",
+		   percpu_counter_sum(&info->total_bytes_pinned));
 
 	DUMP_BLOCK_RSV(fs_info, global_block_rsv);
 	DUMP_BLOCK_RSV(fs_info, trans_block_rsv);