@@ -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;
};
/*
@@ -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);
}
@@ -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;