diff mbox

2.6.39-rc1: btrfs "WARNING: at fs/btrfs/inode.c:2177"

Message ID 4D9F1DE4.7040306@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Josef Bacik April 8, 2011, 2:38 p.m. UTC
On 04/08/2011 01:53 AM, Jeff Wu wrote:
>
> Hi ,
> I applied the patch to 2.6.39-rc1,took the following steps to compile
> it:make&&  make modules_install&&  make install&&  mkinitramfs
> but , it seam that it don't run to "WARN_ON(block_rsv ==
> root->orphan_block_rsv);"
>
> i attached the codes and logs at the below:
>

Bummer ok so here's a much bigger debug patch, remove the previous one I 
sent you and apply this one instead and run with it.  As soon as you get 
a warning stop iozone because this debug patch will create _a lot_ of 
debug output, and I don't want to have to sift through all of it.  Just 
send me your logs after running this patch so I can try and piece 
together what's going on.  Thanks,

Josef
diff mbox

Patch

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 0d00a07..c0d8c1d 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -766,6 +766,7 @@  struct btrfs_block_rsv {
 	unsigned int durable:1;
 	unsigned int refill_used:1;
 	unsigned int full:1;
+	unsigned int orphan:1;
 };
 
 /*
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index f619c3c..5ebcda8 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3429,6 +3429,9 @@  static int reserve_metadata_bytes(struct btrfs_trans_handle *trans,
 	bool reserved = false;
 	bool committed = false;
 
+	if (block_rsv->orphan)
+		printk(KERN_ERR "resrving metadata bytes for orphan rsv %llu\n",
+		       orig_bytes);
 again:
 	ret = -ENOSPC;
 	if (reserved)
@@ -3556,6 +3559,9 @@  static struct btrfs_block_rsv *get_block_rsv(struct btrfs_trans_handle *trans,
 	if (!block_rsv)
 		block_rsv = &root->fs_info->empty_block_rsv;
 
+	if (block_rsv->orphan)
+		printk(KERN_ERR "got orphan block rsv\n");
+
 	return block_rsv;
 }
 
@@ -3563,6 +3569,9 @@  static int block_rsv_use_bytes(struct btrfs_block_rsv *block_rsv,
 			       u64 num_bytes)
 {
 	int ret = -ENOSPC;
+	if (block_rsv->orphan)
+		printk(KERN_ERR "using %llu bytes from orphan\n",
+		       num_bytes);
 	spin_lock(&block_rsv->lock);
 	if (block_rsv->reserved >= num_bytes) {
 		block_rsv->reserved -= num_bytes;
@@ -3577,6 +3586,9 @@  static int block_rsv_use_bytes(struct btrfs_block_rsv *block_rsv,
 static void block_rsv_add_bytes(struct btrfs_block_rsv *block_rsv,
 				u64 num_bytes, int update_size)
 {
+	if (block_rsv->orphan)
+		printk(KERN_ERR "adding %llu bytes, update_size=%d\n",
+		       num_bytes, update_size);
 	spin_lock(&block_rsv->lock);
 	block_rsv->reserved += num_bytes;
 	if (update_size)
@@ -3592,6 +3604,10 @@  void block_rsv_release_bytes(struct btrfs_block_rsv *block_rsv,
 	struct btrfs_space_info *space_info = block_rsv->space_info;
 
 	spin_lock(&block_rsv->lock);
+	if (block_rsv->orphan)
+		printk(KERN_ERR "releasing %llu bytes from orhan, size=%llu, "
+		       "reserved=%llu\n", num_bytes, block_rsv->size,
+		       block_rsv->reserved);
 	if (num_bytes == (u64)-1)
 		num_bytes = block_rsv->size;
 	block_rsv->size -= num_bytes;
@@ -3668,6 +3684,9 @@  struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root)
 void btrfs_free_block_rsv(struct btrfs_root *root,
 			  struct btrfs_block_rsv *rsv)
 {
+	if (rsv->orphan)
+		printk(KERN_ERR "freeing orphan rsv\n");
+
 	if (rsv && atomic_dec_and_test(&rsv->usage)) {
 		btrfs_block_rsv_release(root, rsv, (u64)-1);
 		if (!rsv->durable)
@@ -3696,6 +3715,10 @@  int btrfs_block_rsv_add(struct btrfs_trans_handle *trans,
 {
 	int ret;
 
+	if (block_rsv->orphan)
+		printk(KERN_ERR "adding %llu bytes to orphan\n",
+		       num_bytes);
+
 	if (num_bytes == 0)
 		return 0;
 
@@ -3720,6 +3743,10 @@  int btrfs_block_rsv_check(struct btrfs_trans_handle *trans,
 	if (!block_rsv)
 		return 0;
 
+	if (block_rsv->orphan)
+		printk(KERN_ERR "checking orphan reserve for %llu bytes, "
+		       "%d min factor\n", min_reserved, min_factor);
+
 	spin_lock(&block_rsv->lock);
 	if (min_factor > 0)
 		num_bytes = div_factor(block_rsv->size, min_factor);
@@ -3964,6 +3991,7 @@  int btrfs_orphan_reserve_metadata(struct btrfs_trans_handle *trans,
 	 * transaction and use space it freed.
 	 */
 	u64 num_bytes = calc_trans_metadata_size(root, 4);
+	printk(KERN_ERR "reserving %llu bytes for orphan\n", num_bytes);
 	return block_rsv_migrate_bytes(src_rsv, dst_rsv, num_bytes);
 }
 
@@ -3971,6 +3999,7 @@  void btrfs_orphan_release_metadata(struct inode *inode)
 {
 	struct btrfs_root *root = BTRFS_I(inode)->root;
 	u64 num_bytes = calc_trans_metadata_size(root, 4);
+	printk(KERN_ERR "first release of %llu bytes from orphan\n", num_bytes);
 	btrfs_block_rsv_release(root, root->orphan_block_rsv, num_bytes);
 }
 
@@ -5697,6 +5726,8 @@  use_block_rsv(struct btrfs_trans_handle *trans,
 
 	block_rsv = get_block_rsv(trans, root);
 
+	if (block_rsv->orphan)
+		printk(KERN_ERR "Using orphan block rsv for tree allocation\n");
 	if (block_rsv->size == 0) {
 		ret = reserve_metadata_bytes(trans, root, block_rsv,
 					     blocksize, 0);
@@ -5739,6 +5770,8 @@  use_block_rsv(struct btrfs_trans_handle *trans,
 
 static void unuse_block_rsv(struct btrfs_block_rsv *block_rsv, u32 blocksize)
 {
+	if (block_rsv->orphan)
+		printk(KERN_ERR "unusing orphan block rsv\n");
 	block_rsv_add_bytes(block_rsv, blocksize, 0);
 	block_rsv_release_bytes(block_rsv, NULL, 0);
 }
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 032e8fb..58b1361 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2176,7 +2176,11 @@  void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans,
 	}
 
 	if (root->orphan_block_rsv) {
-		WARN_ON(root->orphan_block_rsv->size > 0);
+		if (root->orphan_block_rsv->size > 0) {
+			printk(KERN_ERR "orphan rsv still has %llu bytes\n",
+			       root->orphan_block_rsv->size);
+			WARN_ON(1);
+		}
 		btrfs_free_block_rsv(root, root->orphan_block_rsv);
 		root->orphan_block_rsv = NULL;
 	}
@@ -2205,6 +2209,7 @@  int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode)
 	spin_lock(&root->orphan_lock);
 	if (!root->orphan_block_rsv) {
 		root->orphan_block_rsv = block_rsv;
+		block_rsv->orphan = 1;
 	} else if (block_rsv) {
 		btrfs_free_block_rsv(root, block_rsv);
 		block_rsv = NULL;