Commit 5630e2bc authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: use a constant for the number of metadata units needed for an unlink

Instead of hard coding the number of metadata units for an unlink operation
in a couple places, define a macro and use it instead. This eliminates the
problem of one place getting out of sync with the other, such as recently
fixed by the previous patch in the series ("btrfs: fix calculation of the
global block reserve's size").
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent ba4ec8fb
...@@ -350,14 +350,15 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info) ...@@ -350,14 +350,15 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
/* /*
* But we also want to reserve enough space so we can do the fallback * But we also want to reserve enough space so we can do the fallback
* global reserve for an unlink, which is an additional 6 items (see the * global reserve for an unlink, which is an additional
* comment in __unlink_start_trans for what we're modifying.) * BTRFS_UNLINK_METADATA_UNITS items.
* *
* But we also need space for the delayed ref updates from the unlink, * But we also need space for the delayed ref updates from the unlink,
* so its 12, 6 for the actual operation, and 6 for the delayed ref * so it's BTRFS_UNLINK_METADATA_UNITS * 2, BTRFS_UNLINK_METADATA_UNITS
* updates. * for the actual operation, and BTRFS_UNLINK_METADATA_UNITS more for
* the delayed ref updates.
*/ */
min_items += 12; min_items += BTRFS_UNLINK_METADATA_UNITS * 2;
num_bytes = max_t(u64, num_bytes, num_bytes = max_t(u64, num_bytes,
btrfs_calc_insert_metadata_size(fs_info, min_items)); btrfs_calc_insert_metadata_size(fs_info, min_items));
......
...@@ -24,6 +24,18 @@ ...@@ -24,6 +24,18 @@
#define BTRFS_SUPER_INFO_SIZE 4096 #define BTRFS_SUPER_INFO_SIZE 4096
static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE); static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);
/*
* Number of metadata items necessary for an unlink operation:
*
* 1 for the possible orphan item
* 1 for the dir item
* 1 for the dir index
* 1 for the inode ref
* 1 for the inode
* 1 for the parent inode
*/
#define BTRFS_UNLINK_METADATA_UNITS 6
/* /*
* The reserved space at the beginning of each device. It covers the primary * The reserved space at the beginning of each device. It covers the primary
* super block and leaves space for potential use by other tools like * super block and leaves space for potential use by other tools like
......
...@@ -4248,15 +4248,8 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct btrfs_inode *dir) ...@@ -4248,15 +4248,8 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct btrfs_inode *dir)
{ {
struct btrfs_root *root = dir->root; struct btrfs_root *root = dir->root;
/* return btrfs_start_transaction_fallback_global_rsv(root,
* 1 for the possible orphan item BTRFS_UNLINK_METADATA_UNITS);
* 1 for the dir item
* 1 for the dir index
* 1 for the inode ref
* 1 for the inode
* 1 for the parent inode
*/
return btrfs_start_transaction_fallback_global_rsv(root, 6);
} }
static int btrfs_unlink(struct inode *dir, struct dentry *dentry) static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
......
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