Commit 66d8f3dd authored by Miao Xie's avatar Miao Xie Committed by Chris Mason

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: default avatarMiao Xie <miaox@cn.fujitsu.com>
parent 6352b91d
...@@ -1028,13 +1028,22 @@ struct btrfs_space_info { ...@@ -1028,13 +1028,22 @@ struct btrfs_space_info {
wait_queue_head_t wait; wait_queue_head_t wait;
}; };
#define BTRFS_BLOCK_RSV_GLOBAL 1
#define BTRFS_BLOCK_RSV_DELALLOC 2
#define BTRFS_BLOCK_RSV_TRANS 3
#define BTRFS_BLOCK_RSV_CHUNK 4
#define BTRFS_BLOCK_RSV_DELOPS 5
#define BTRFS_BLOCK_RSV_EMPTY 6
#define BTRFS_BLOCK_RSV_TEMP 7
struct btrfs_block_rsv { struct btrfs_block_rsv {
u64 size; u64 size;
u64 reserved; u64 reserved;
struct btrfs_space_info *space_info; struct btrfs_space_info *space_info;
spinlock_t lock; spinlock_t lock;
unsigned int full; unsigned short full;
unsigned int failfast; unsigned short type;
unsigned short failfast;
}; };
/* /*
...@@ -2875,8 +2884,9 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes); ...@@ -2875,8 +2884,9 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes);
void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes); void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes);
int btrfs_delalloc_reserve_space(struct inode *inode, u64 num_bytes); int btrfs_delalloc_reserve_space(struct inode *inode, u64 num_bytes);
void btrfs_delalloc_release_space(struct inode *inode, u64 num_bytes); void btrfs_delalloc_release_space(struct inode *inode, u64 num_bytes);
void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv); void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type);
struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root); struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root,
unsigned short type);
void btrfs_free_block_rsv(struct btrfs_root *root, void btrfs_free_block_rsv(struct btrfs_root *root,
struct btrfs_block_rsv *rsv); struct btrfs_block_rsv *rsv);
int btrfs_block_rsv_add(struct btrfs_root *root, int btrfs_block_rsv_add(struct btrfs_root *root,
......
...@@ -650,7 +650,7 @@ static int btrfs_delayed_inode_reserve_metadata( ...@@ -650,7 +650,7 @@ static int btrfs_delayed_inode_reserve_metadata(
* we're accounted for. * we're accounted for.
*/ */
if (!src_rsv || (!trans->bytes_reserved && if (!src_rsv || (!trans->bytes_reserved &&
src_rsv != &root->fs_info->delalloc_block_rsv)) { src_rsv->type != BTRFS_BLOCK_RSV_DELALLOC)) {
ret = btrfs_block_rsv_add_noflush(root, dst_rsv, num_bytes); ret = btrfs_block_rsv_add_noflush(root, dst_rsv, num_bytes);
/* /*
* Since we're under a transaction reserve_metadata_bytes could * Since we're under a transaction reserve_metadata_bytes could
...@@ -668,7 +668,7 @@ static int btrfs_delayed_inode_reserve_metadata( ...@@ -668,7 +668,7 @@ static int btrfs_delayed_inode_reserve_metadata(
num_bytes, 1); num_bytes, 1);
} }
return ret; return ret;
} else if (src_rsv == &root->fs_info->delalloc_block_rsv) { } else if (src_rsv->type == BTRFS_BLOCK_RSV_DELALLOC) {
spin_lock(&BTRFS_I(inode)->lock); spin_lock(&BTRFS_I(inode)->lock);
if (test_and_clear_bit(BTRFS_INODE_DELALLOC_META_RESERVED, if (test_and_clear_bit(BTRFS_INODE_DELALLOC_META_RESERVED,
&BTRFS_I(inode)->runtime_flags)) { &BTRFS_I(inode)->runtime_flags)) {
......
...@@ -2014,12 +2014,15 @@ int open_ctree(struct super_block *sb, ...@@ -2014,12 +2014,15 @@ int open_ctree(struct super_block *sb,
INIT_LIST_HEAD(&fs_info->space_info); INIT_LIST_HEAD(&fs_info->space_info);
INIT_LIST_HEAD(&fs_info->tree_mod_seq_list); INIT_LIST_HEAD(&fs_info->tree_mod_seq_list);
btrfs_mapping_init(&fs_info->mapping_tree); btrfs_mapping_init(&fs_info->mapping_tree);
btrfs_init_block_rsv(&fs_info->global_block_rsv); btrfs_init_block_rsv(&fs_info->global_block_rsv,
btrfs_init_block_rsv(&fs_info->delalloc_block_rsv); BTRFS_BLOCK_RSV_GLOBAL);
btrfs_init_block_rsv(&fs_info->trans_block_rsv); btrfs_init_block_rsv(&fs_info->delalloc_block_rsv,
btrfs_init_block_rsv(&fs_info->chunk_block_rsv); BTRFS_BLOCK_RSV_DELALLOC);
btrfs_init_block_rsv(&fs_info->empty_block_rsv); btrfs_init_block_rsv(&fs_info->trans_block_rsv, BTRFS_BLOCK_RSV_TRANS);
btrfs_init_block_rsv(&fs_info->delayed_block_rsv); btrfs_init_block_rsv(&fs_info->chunk_block_rsv, BTRFS_BLOCK_RSV_CHUNK);
btrfs_init_block_rsv(&fs_info->empty_block_rsv, BTRFS_BLOCK_RSV_EMPTY);
btrfs_init_block_rsv(&fs_info->delayed_block_rsv,
BTRFS_BLOCK_RSV_DELOPS);
atomic_set(&fs_info->nr_async_submits, 0); atomic_set(&fs_info->nr_async_submits, 0);
atomic_set(&fs_info->async_delalloc_pages, 0); atomic_set(&fs_info->async_delalloc_pages, 0);
atomic_set(&fs_info->async_submit_draining, 0); atomic_set(&fs_info->async_submit_draining, 0);
......
...@@ -4108,13 +4108,15 @@ static int block_rsv_migrate_bytes(struct btrfs_block_rsv *src, ...@@ -4108,13 +4108,15 @@ static int block_rsv_migrate_bytes(struct btrfs_block_rsv *src,
return 0; return 0;
} }
void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv) void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type)
{ {
memset(rsv, 0, sizeof(*rsv)); memset(rsv, 0, sizeof(*rsv));
spin_lock_init(&rsv->lock); spin_lock_init(&rsv->lock);
rsv->type = type;
} }
struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root) struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root,
unsigned short type)
{ {
struct btrfs_block_rsv *block_rsv; struct btrfs_block_rsv *block_rsv;
struct btrfs_fs_info *fs_info = root->fs_info; 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,7 +4125,7 @@ struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root)
if (!block_rsv) if (!block_rsv)
return NULL; return NULL;
btrfs_init_block_rsv(block_rsv); btrfs_init_block_rsv(block_rsv, type);
block_rsv->space_info = __find_space_info(fs_info, block_rsv->space_info = __find_space_info(fs_info,
BTRFS_BLOCK_GROUP_METADATA); BTRFS_BLOCK_GROUP_METADATA);
return block_rsv; return block_rsv;
......
...@@ -1874,7 +1874,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) ...@@ -1874,7 +1874,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
goto out; goto out;
} }
rsv = btrfs_alloc_block_rsv(root); rsv = btrfs_alloc_block_rsv(root, BTRFS_BLOCK_RSV_TEMP);
if (!rsv) { if (!rsv) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_free; goto out_free;
......
...@@ -2195,7 +2195,7 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode) ...@@ -2195,7 +2195,7 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode)
int ret; int ret;
if (!root->orphan_block_rsv) { if (!root->orphan_block_rsv) {
block_rsv = btrfs_alloc_block_rsv(root); block_rsv = btrfs_alloc_block_rsv(root, BTRFS_BLOCK_RSV_TEMP);
if (!block_rsv) if (!block_rsv)
return -ENOMEM; return -ENOMEM;
} }
...@@ -3070,7 +3070,7 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir, ...@@ -3070,7 +3070,7 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir,
static void __unlink_end_trans(struct btrfs_trans_handle *trans, static void __unlink_end_trans(struct btrfs_trans_handle *trans,
struct btrfs_root *root) struct btrfs_root *root)
{ {
if (trans->block_rsv == &root->fs_info->global_block_rsv) { if (trans->block_rsv->type == BTRFS_BLOCK_RSV_GLOBAL) {
btrfs_block_rsv_release(root, trans->block_rsv, btrfs_block_rsv_release(root, trans->block_rsv,
trans->bytes_reserved); trans->bytes_reserved);
trans->block_rsv = &root->fs_info->trans_block_rsv; trans->block_rsv = &root->fs_info->trans_block_rsv;
...@@ -3821,7 +3821,7 @@ void btrfs_evict_inode(struct inode *inode) ...@@ -3821,7 +3821,7 @@ void btrfs_evict_inode(struct inode *inode)
goto no_delete; goto no_delete;
} }
rsv = btrfs_alloc_block_rsv(root); rsv = btrfs_alloc_block_rsv(root, BTRFS_BLOCK_RSV_TEMP);
if (!rsv) { if (!rsv) {
btrfs_orphan_del(NULL, inode); btrfs_orphan_del(NULL, inode);
goto no_delete; goto no_delete;
...@@ -6851,7 +6851,7 @@ static int btrfs_truncate(struct inode *inode) ...@@ -6851,7 +6851,7 @@ static int btrfs_truncate(struct inode *inode)
* 3) fs_info->trans_block_rsv - this will have 1 items worth left for * 3) fs_info->trans_block_rsv - this will have 1 items worth left for
* updating the inode. * updating the inode.
*/ */
rsv = btrfs_alloc_block_rsv(root); rsv = btrfs_alloc_block_rsv(root, BTRFS_BLOCK_RSV_TEMP);
if (!rsv) if (!rsv)
return -ENOMEM; return -ENOMEM;
rsv->size = min_size; rsv->size = min_size;
......
...@@ -516,7 +516,8 @@ static int create_snapshot(struct btrfs_root *root, struct dentry *dentry, ...@@ -516,7 +516,8 @@ static int create_snapshot(struct btrfs_root *root, struct dentry *dentry,
if (!pending_snapshot) if (!pending_snapshot)
return -ENOMEM; return -ENOMEM;
btrfs_init_block_rsv(&pending_snapshot->block_rsv); btrfs_init_block_rsv(&pending_snapshot->block_rsv,
BTRFS_BLOCK_RSV_TEMP);
pending_snapshot->dentry = dentry; pending_snapshot->dentry = dentry;
pending_snapshot->root = root; pending_snapshot->root = root;
pending_snapshot->readonly = readonly; pending_snapshot->readonly = readonly;
......
...@@ -3674,7 +3674,8 @@ int prepare_to_relocate(struct reloc_control *rc) ...@@ -3674,7 +3674,8 @@ int prepare_to_relocate(struct reloc_control *rc)
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
int ret; int ret;
rc->block_rsv = btrfs_alloc_block_rsv(rc->extent_root); rc->block_rsv = btrfs_alloc_block_rsv(rc->extent_root,
BTRFS_BLOCK_RSV_TEMP);
if (!rc->block_rsv) if (!rc->block_rsv)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment