aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2012-09-06 06:02:28 -0400
committerChris Mason <chris.mason@fusionio.com>2012-10-01 15:19:11 -0400
commit66d8f3dd1c87813d7f1cf8b774cb03e9b8d7e87e (patch)
tree74d18d716f42e15958a9723ece4cd98dfdfd6a74 /fs
parent6352b91da1a2108bb8cc5115e8714f90d706f15f (diff)
Btrfs: add a new "type" field into the block reservation structure
Sometimes we need choose the method of the reservation according to the type of the block reservation, such as the reservation for the delayed inode update. Now we identify the type just by comparing the address of the reservation variants, it is very ugly if it is a temporary one because we need compare it with all the common reservation variants. So we add a new "type" field to keep the type the reservation variants. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/ctree.h18
-rw-r--r--fs/btrfs/delayed-inode.c4
-rw-r--r--fs/btrfs/disk-io.c15
-rw-r--r--fs/btrfs/extent-tree.c8
-rw-r--r--fs/btrfs/file.c2
-rw-r--r--fs/btrfs/inode.c8
-rw-r--r--fs/btrfs/ioctl.c3
-rw-r--r--fs/btrfs/relocation.c3
8 files changed, 39 insertions, 22 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index b7cd3adb5a58..2990a7ea6248 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1028,13 +1028,22 @@ struct btrfs_space_info {
1028 wait_queue_head_t wait; 1028 wait_queue_head_t wait;
1029}; 1029};
1030 1030
1031#define BTRFS_BLOCK_RSV_GLOBAL 1
1032#define BTRFS_BLOCK_RSV_DELALLOC 2
1033#define BTRFS_BLOCK_RSV_TRANS 3
1034#define BTRFS_BLOCK_RSV_CHUNK 4
1035#define BTRFS_BLOCK_RSV_DELOPS 5
1036#define BTRFS_BLOCK_RSV_EMPTY 6
1037#define BTRFS_BLOCK_RSV_TEMP 7
1038
1031struct btrfs_block_rsv { 1039struct btrfs_block_rsv {
1032 u64 size; 1040 u64 size;
1033 u64 reserved; 1041 u64 reserved;
1034 struct btrfs_space_info *space_info; 1042 struct btrfs_space_info *space_info;
1035 spinlock_t lock; 1043 spinlock_t lock;
1036 unsigned int full; 1044 unsigned short full;
1037 unsigned int failfast; 1045 unsigned short type;
1046 unsigned short failfast;
1038}; 1047};
1039 1048
1040/* 1049/*
@@ -2875,8 +2884,9 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes);
2875void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes); 2884void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes);
2876int btrfs_delalloc_reserve_space(struct inode *inode, u64 num_bytes); 2885int btrfs_delalloc_reserve_space(struct inode *inode, u64 num_bytes);
2877void btrfs_delalloc_release_space(struct inode *inode, u64 num_bytes); 2886void btrfs_delalloc_release_space(struct inode *inode, u64 num_bytes);
2878void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv); 2887void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type);
2879struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root); 2888struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root,
2889 unsigned short type);
2880void btrfs_free_block_rsv(struct btrfs_root *root, 2890void btrfs_free_block_rsv(struct btrfs_root *root,
2881 struct btrfs_block_rsv *rsv); 2891 struct btrfs_block_rsv *rsv);
2882int btrfs_block_rsv_add(struct btrfs_root *root, 2892int btrfs_block_rsv_add(struct btrfs_root *root,
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 07d5eeb1e6f1..eb768c4c1358 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -650,7 +650,7 @@ static int btrfs_delayed_inode_reserve_metadata(
650 * we're accounted for. 650 * we're accounted for.
651 */ 651 */
652 if (!src_rsv || (!trans->bytes_reserved && 652 if (!src_rsv || (!trans->bytes_reserved &&
653 src_rsv != &root->fs_info->delalloc_block_rsv)) { 653 src_rsv->type != BTRFS_BLOCK_RSV_DELALLOC)) {
654 ret = btrfs_block_rsv_add_noflush(root, dst_rsv, num_bytes); 654 ret = btrfs_block_rsv_add_noflush(root, dst_rsv, num_bytes);
655 /* 655 /*
656 * Since we're under a transaction reserve_metadata_bytes could 656 * Since we're under a transaction reserve_metadata_bytes could
@@ -668,7 +668,7 @@ static int btrfs_delayed_inode_reserve_metadata(
668 num_bytes, 1); 668 num_bytes, 1);
669 } 669 }
670 return ret; 670 return ret;
671 } else if (src_rsv == &root->fs_info->delalloc_block_rsv) { 671 } else if (src_rsv->type == BTRFS_BLOCK_RSV_DELALLOC) {
672 spin_lock(&BTRFS_I(inode)->lock); 672 spin_lock(&BTRFS_I(inode)->lock);
673 if (test_and_clear_bit(BTRFS_INODE_DELALLOC_META_RESERVED, 673 if (test_and_clear_bit(BTRFS_INODE_DELALLOC_META_RESERVED,
674 &BTRFS_I(inode)->runtime_flags)) { 674 &BTRFS_I(inode)->runtime_flags)) {
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 22e98e04c2ea..0dcfb998229e 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2014,12 +2014,15 @@ int open_ctree(struct super_block *sb,
2014 INIT_LIST_HEAD(&fs_info->space_info); 2014 INIT_LIST_HEAD(&fs_info->space_info);
2015 INIT_LIST_HEAD(&fs_info->tree_mod_seq_list); 2015 INIT_LIST_HEAD(&fs_info->tree_mod_seq_list);
2016 btrfs_mapping_init(&fs_info->mapping_tree); 2016 btrfs_mapping_init(&fs_info->mapping_tree);
2017 btrfs_init_block_rsv(&fs_info->global_block_rsv); 2017 btrfs_init_block_rsv(&fs_info->global_block_rsv,
2018 btrfs_init_block_rsv(&fs_info->delalloc_block_rsv); 2018 BTRFS_BLOCK_RSV_GLOBAL);
2019 btrfs_init_block_rsv(&fs_info->trans_block_rsv); 2019 btrfs_init_block_rsv(&fs_info->delalloc_block_rsv,
2020 btrfs_init_block_rsv(&fs_info->chunk_block_rsv); 2020 BTRFS_BLOCK_RSV_DELALLOC);
2021 btrfs_init_block_rsv(&fs_info->empty_block_rsv); 2021 btrfs_init_block_rsv(&fs_info->trans_block_rsv, BTRFS_BLOCK_RSV_TRANS);
2022 btrfs_init_block_rsv(&fs_info->delayed_block_rsv); 2022 btrfs_init_block_rsv(&fs_info->chunk_block_rsv, BTRFS_BLOCK_RSV_CHUNK);
2023 btrfs_init_block_rsv(&fs_info->empty_block_rsv, BTRFS_BLOCK_RSV_EMPTY);
2024 btrfs_init_block_rsv(&fs_info->delayed_block_rsv,
2025 BTRFS_BLOCK_RSV_DELOPS);
2023 atomic_set(&fs_info->nr_async_submits, 0); 2026 atomic_set(&fs_info->nr_async_submits, 0);
2024 atomic_set(&fs_info->async_delalloc_pages, 0); 2027 atomic_set(&fs_info->async_delalloc_pages, 0);
2025 atomic_set(&fs_info->async_submit_draining, 0); 2028 atomic_set(&fs_info->async_submit_draining, 0);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index ee51b7afe97d..36e03312267a 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4108,13 +4108,15 @@ static int block_rsv_migrate_bytes(struct btrfs_block_rsv *src,
4108 return 0; 4108 return 0;
4109} 4109}
4110 4110
4111void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv) 4111void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type)
4112{ 4112{
4113 memset(rsv, 0, sizeof(*rsv)); 4113 memset(rsv, 0, sizeof(*rsv));
4114 spin_lock_init(&rsv->lock); 4114 spin_lock_init(&rsv->lock);
4115 rsv->type = type;
4115} 4116}
4116 4117
4117struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root) 4118struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root,
4119 unsigned short type)
4118{ 4120{
4119 struct btrfs_block_rsv *block_rsv; 4121 struct btrfs_block_rsv *block_rsv;
4120 struct btrfs_fs_info *fs_info = root->fs_info; 4122 struct btrfs_fs_info *fs_info = root->fs_info;
@@ -4123,7 +4125,7 @@ struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root)
4123 if (!block_rsv) 4125 if (!block_rsv)
4124 return NULL; 4126 return NULL;
4125 4127
4126 btrfs_init_block_rsv(block_rsv); 4128 btrfs_init_block_rsv(block_rsv, type);
4127 block_rsv->space_info = __find_space_info(fs_info, 4129 block_rsv->space_info = __find_space_info(fs_info,
4128 BTRFS_BLOCK_GROUP_METADATA); 4130 BTRFS_BLOCK_GROUP_METADATA);
4129 return block_rsv; 4131 return block_rsv;
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index a50e98733e28..a9d7815cf58e 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1874,7 +1874,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
1874 goto out; 1874 goto out;
1875 } 1875 }
1876 1876
1877 rsv = btrfs_alloc_block_rsv(root); 1877 rsv = btrfs_alloc_block_rsv(root, BTRFS_BLOCK_RSV_TEMP);
1878 if (!rsv) { 1878 if (!rsv) {
1879 ret = -ENOMEM; 1879 ret = -ENOMEM;
1880 goto out_free; 1880 goto out_free;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 073af0724bc0..d34eb329720d 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2195,7 +2195,7 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode)
2195 int ret; 2195 int ret;
2196 2196
2197 if (!root->orphan_block_rsv) { 2197 if (!root->orphan_block_rsv) {
2198 block_rsv = btrfs_alloc_block_rsv(root); 2198 block_rsv = btrfs_alloc_block_rsv(root, BTRFS_BLOCK_RSV_TEMP);
2199 if (!block_rsv) 2199 if (!block_rsv)
2200 return -ENOMEM; 2200 return -ENOMEM;
2201 } 2201 }
@@ -3070,7 +3070,7 @@ out:
3070static void __unlink_end_trans(struct btrfs_trans_handle *trans, 3070static void __unlink_end_trans(struct btrfs_trans_handle *trans,
3071 struct btrfs_root *root) 3071 struct btrfs_root *root)
3072{ 3072{
3073 if (trans->block_rsv == &root->fs_info->global_block_rsv) { 3073 if (trans->block_rsv->type == BTRFS_BLOCK_RSV_GLOBAL) {
3074 btrfs_block_rsv_release(root, trans->block_rsv, 3074 btrfs_block_rsv_release(root, trans->block_rsv,
3075 trans->bytes_reserved); 3075 trans->bytes_reserved);
3076 trans->block_rsv = &root->fs_info->trans_block_rsv; 3076 trans->block_rsv = &root->fs_info->trans_block_rsv;
@@ -3821,7 +3821,7 @@ void btrfs_evict_inode(struct inode *inode)
3821 goto no_delete; 3821 goto no_delete;
3822 } 3822 }
3823 3823
3824 rsv = btrfs_alloc_block_rsv(root); 3824 rsv = btrfs_alloc_block_rsv(root, BTRFS_BLOCK_RSV_TEMP);
3825 if (!rsv) { 3825 if (!rsv) {
3826 btrfs_orphan_del(NULL, inode); 3826 btrfs_orphan_del(NULL, inode);
3827 goto no_delete; 3827 goto no_delete;
@@ -6851,7 +6851,7 @@ static int btrfs_truncate(struct inode *inode)
6851 * 3) fs_info->trans_block_rsv - this will have 1 items worth left for 6851 * 3) fs_info->trans_block_rsv - this will have 1 items worth left for
6852 * updating the inode. 6852 * updating the inode.
6853 */ 6853 */
6854 rsv = btrfs_alloc_block_rsv(root); 6854 rsv = btrfs_alloc_block_rsv(root, BTRFS_BLOCK_RSV_TEMP);
6855 if (!rsv) 6855 if (!rsv)
6856 return -ENOMEM; 6856 return -ENOMEM;
6857 rsv->size = min_size; 6857 rsv->size = min_size;
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 5543fd562b55..e6934de55a8b 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -516,7 +516,8 @@ static int create_snapshot(struct btrfs_root *root, struct dentry *dentry,
516 if (!pending_snapshot) 516 if (!pending_snapshot)
517 return -ENOMEM; 517 return -ENOMEM;
518 518
519 btrfs_init_block_rsv(&pending_snapshot->block_rsv); 519 btrfs_init_block_rsv(&pending_snapshot->block_rsv,
520 BTRFS_BLOCK_RSV_TEMP);
520 pending_snapshot->dentry = dentry; 521 pending_snapshot->dentry = dentry;
521 pending_snapshot->root = root; 522 pending_snapshot->root = root;
522 pending_snapshot->readonly = readonly; 523 pending_snapshot->readonly = readonly;
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 4da08652004d..5a15c96a18ff 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3674,7 +3674,8 @@ int prepare_to_relocate(struct reloc_control *rc)
3674 struct btrfs_trans_handle *trans; 3674 struct btrfs_trans_handle *trans;
3675 int ret; 3675 int ret;
3676 3676
3677 rc->block_rsv = btrfs_alloc_block_rsv(rc->extent_root); 3677 rc->block_rsv = btrfs_alloc_block_rsv(rc->extent_root,
3678 BTRFS_BLOCK_RSV_TEMP);
3678 if (!rc->block_rsv) 3679 if (!rc->block_rsv)
3679 return -ENOMEM; 3680 return -ENOMEM;
3680 3681