Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 297911
b: refs/heads/master
c: 15d1ff8
h: refs/heads/master
i:
  297909: 68954f0
  297907: 0b0f58c
  297903: 882fc57
v: v3
  • Loading branch information
Liu Bo authored and Chris Mason committed Mar 29, 2012
1 parent a4c6b76 commit a904e0b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2bcc0328c3a043880796a602c75fbeb1537aa1e1
refs/heads/master: 15d1ff8111aad85d8b40ee396758990d17a2caac
50 changes: 50 additions & 0 deletions trunk/fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -3445,6 +3445,50 @@ static int should_alloc_chunk(struct btrfs_root *root,
return 1;
}

static u64 get_system_chunk_thresh(struct btrfs_root *root, u64 type)
{
u64 num_dev;

if (type & BTRFS_BLOCK_GROUP_RAID10 ||
type & BTRFS_BLOCK_GROUP_RAID0)
num_dev = root->fs_info->fs_devices->rw_devices;
else if (type & BTRFS_BLOCK_GROUP_RAID1)
num_dev = 2;
else
num_dev = 1; /* DUP or single */

/* metadata for updaing devices and chunk tree */
return btrfs_calc_trans_metadata_size(root, num_dev + 1);
}

static void check_system_chunk(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 type)
{
struct btrfs_space_info *info;
u64 left;
u64 thresh;

info = __find_space_info(root->fs_info, BTRFS_BLOCK_GROUP_SYSTEM);
spin_lock(&info->lock);
left = info->total_bytes - info->bytes_used - info->bytes_pinned -
info->bytes_reserved - info->bytes_readonly;
spin_unlock(&info->lock);

thresh = get_system_chunk_thresh(root, type);
if (left < thresh && btrfs_test_opt(root, ENOSPC_DEBUG)) {
printk(KERN_INFO "left=%llu, need=%llu, flags=%llu\n",
left, thresh, type);
dump_space_info(info, 0, 0);
}

if (left < thresh) {
u64 flags;

flags = btrfs_get_alloc_profile(root->fs_info->chunk_root, 0);
btrfs_alloc_chunk(trans, root, flags);
}
}

static int do_chunk_alloc(struct btrfs_trans_handle *trans,
struct btrfs_root *extent_root, u64 alloc_bytes,
u64 flags, int force)
Expand Down Expand Up @@ -3515,6 +3559,12 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans,
force_metadata_allocation(fs_info);
}

/*
* Check if we have enough space in SYSTEM chunk because we may need
* to update devices.
*/
check_system_chunk(trans, extent_root, flags);

ret = btrfs_alloc_chunk(trans, extent_root, flags);
if (ret < 0 && ret != -ENOSPC)
goto out;
Expand Down

0 comments on commit a904e0b

Please sign in to comment.