btrfs: move random block rsv code around
cover btrfs: move random block rsv code around
We have some specialized block rsvs, like the inode rsv and the delayed refs rsv, that have their own special oddities. These don't fit in extent-tree.c, so migrate them to different places. Most of them go to existing files, but the delalloc stuff gets its own file because it's a lot of code, and inode.c and file.c are relatively large already.
This depends on the previous two chunks of migrations. These are relatively small and straightforward since all of the functions were exported already as they are used throughout the entire codebase. The diffstat is as follows
fs/btrfs/Makefile | 2 +- fs/btrfs/ctree.h | 24 -- fs/btrfs/delalloc-space.c | 497 ++++++++++++++++++++++++++++++ fs/btrfs/delalloc-space.h | 25 ++ fs/btrfs/delayed-ref.c | 177 +++++++++++ fs/btrfs/delayed-ref.h | 10 + fs/btrfs/extent-tree.c | 733 +------------------------------------------- fs/btrfs/file.c | 1 + fs/btrfs/free-space-cache.c | 1 + fs/btrfs/inode-map.c | 1 + fs/btrfs/inode.c | 1 + fs/btrfs/ioctl.c | 1 + fs/btrfs/ordered-data.c | 1 + fs/btrfs/relocation.c | 1 + fs/btrfs/root-tree.c | 56 ++++ fs/btrfs/transaction.c | 18 ++ fs/btrfs/transaction.h | 1 + 17 files changed, 793 insertions(+), 757 deletions(-)
Thanks,
Josef
PATCH 1/4 btrfs: migrate the delayed refs rsv code
These belong with the delayed refs related code, not in extent-tree.c.
--- fs/btrfs/ctree.h | 9 --- fs/btrfs/delayed-ref.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/delayed-ref.h | 10 +++ fs/btrfs/extent-tree.c | 175 ------------------------------------------------ 4 files changed, 187 insertions(+), 184 deletions(-)
fs/btrfs/ctree.h +0 -9
@@ -2606,8 +2606,6 @@ static inline u64 btrfs_calc_trunc_metadata_size(struct btrfs_fs_info *fs_info,return (u64 )fs_info->nodesize *BTRFS_MAX_LEVEL * num_items; } -int btrfs_should_throttle_delayed_refs (struct btrfs_trans_handle *trans); -bool btrfs_check_space_for_delayed_refs (struct btrfs_fs_info *fs_info);void btrfs_dec_block_group_reservations (struct btrfs_fs_info *fs_info,const u64 start);void btrfs_wait_block_group_reservations (struct btrfs_block_group_cache *bg);
@@ -2768,13 +2766,6 @@ void btrfs_delalloc_release_metadata(struct btrfs_inode *inode, u64 num_bytes, bool qgroup_free);int btrfs_delalloc_reserve_space (struct inode *inode,struct extent_changeset **reserved,u64 start,u64 len); -void btrfs_delayed_refs_rsv_release (struct btrfs_fs_info *fs_info,int nr); -void btrfs_update_delayed_refs_rsv (struct btrfs_trans_handle *trans); -int btrfs_delayed_refs_rsv_refill (struct btrfs_fs_info *fs_info, -enum btrfs_reserve_flush_enum flush); -void btrfs_migrate_to_delayed_refs_rsv (struct btrfs_fs_info *fs_info, -struct btrfs_block_rsv *src, -u64 num_bytes);int btrfs_inc_block_group_ro (struct btrfs_block_group_cache *cache);void btrfs_dec_block_group_ro (struct btrfs_block_group_cache *cache);void btrfs_put_block_group_cache (struct btrfs_fs_info *info);
fs/btrfs/delayed-ref.c +177 -0
189 lines not on this page · raw message
fs/btrfs/delayed-ref.h +10 -0
@@ -364,6 +364,16 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head(int btrfs_check_delayed_seq (struct btrfs_fs_info *fs_info,u64 seq); +void btrfs_delayed_refs_rsv_release (struct btrfs_fs_info *fs_info,int nr); +void btrfs_update_delayed_refs_rsv (struct btrfs_trans_handle *trans); +int btrfs_delayed_refs_rsv_refill (struct btrfs_fs_info *fs_info, +enum btrfs_reserve_flush_enum flush); +void btrfs_migrate_to_delayed_refs_rsv (struct btrfs_fs_info *fs_info, +struct btrfs_block_rsv *src, +u64 num_bytes); +int btrfs_should_throttle_delayed_refs (struct btrfs_trans_handle *trans); +bool btrfs_check_space_for_delayed_refs (struct btrfs_fs_info *fs_info); +/* * helper functions to cast a node into its container */
fs/btrfs/extent-tree.c +0 -175
193 lines not on this page · raw message
Signature · 1 line
2.14.3
PATCH 2/4 btrfs: migrate btrfs_trans_release_chunk_metadata
In reply to Josef BacikMove this into transaction.c with the rest of the transaction related code.
--- fs/btrfs/ctree.h | 1 - fs/btrfs/extent-tree.c | 18 ------------------ fs/btrfs/transaction.c | 18 ++++++++++++++++++ fs/btrfs/transaction.h | 1 + 4 files changed, 19 insertions(+), 19 deletions(-)
fs/btrfs/ctree.h +0 -1
@@ -2752,7 +2752,6 @@ void btrfs_delalloc_release_space(struct inode *inode, u64 start, u64 len, bool qgroup_free);void btrfs_free_reserved_data_space_noquota (struct inode *inode,u64 start,u64 len); -void btrfs_trans_release_chunk_metadata (struct btrfs_trans_handle *trans);int btrfs_subvolume_reserve_metadata (struct btrfs_root *root,struct btrfs_block_rsv *rsv,int nitems,bool use_global_rsv);
fs/btrfs/extent-tree.c +0 -18
@@ -4341,24 +4341,6 @@ static void btrfs_inode_rsv_release(struct btrfs_inode *inode, bool qgroup_free) qgroup_to_release); } -/* -* To be called after all the new block groups attached to the transaction -* handle have been created (btrfs_create_pending_block_groups()). -*/ -void btrfs_trans_release_chunk_metadata (struct btrfs_trans_handle *trans) -{ -struct btrfs_fs_info *fs_info = trans->fs_info; - -if (!trans->chunk_bytes_reserved) -return ; - -WARN_ON_ONCE (!list_empty (&trans->new_bgs)); - -btrfs_block_rsv_release (fs_info, &fs_info->chunk_block_rsv, - trans->chunk_bytes_reserved); - trans->chunk_bytes_reserved =0 ; -} -/* * btrfs_subvolume_reserve_metadata() - reserve space for subvolume operation * root: the root of the parent directory
fs/btrfs/transaction.c +18 -0
@@ -128,6 +128,24 @@ static inline int extwriter_counter_read(struct btrfs_transaction *trans)return atomic_read (&trans->num_extwriters); } +/* +* To be called after all the new block groups attached to the transaction +* handle have been created (btrfs_create_pending_block_groups()). +*/ +void btrfs_trans_release_chunk_metadata (struct btrfs_trans_handle *trans) +{ +struct btrfs_fs_info *fs_info = trans->fs_info; + +if (!trans->chunk_bytes_reserved) +return ; + +WARN_ON_ONCE (!list_empty (&trans->new_bgs)); + +btrfs_block_rsv_release (fs_info, &fs_info->chunk_block_rsv, + trans->chunk_bytes_reserved); + trans->chunk_bytes_reserved =0 ; +} +/* * either allocate a new transaction or hop into the existing one */
fs/btrfs/transaction.h +1 -0
@@ -224,5 +224,6 @@ void btrfs_put_transaction(struct btrfs_transaction *transaction);void btrfs_apply_pending_changes (struct btrfs_fs_info *fs_info);void btrfs_add_dropped_root (struct btrfs_trans_handle *trans,struct btrfs_root *root); +void btrfs_trans_release_chunk_metadata (struct btrfs_trans_handle *trans);#endif
Signature · 1 line
2.14.3
PATCH 3/4 btrfs: migrate the delalloc space stuff to it's own home
In reply to Josef BacikWe have code for data and metadata reservations for delalloc. There's quite a bit of code here, and it's used in a lot of places so I've separated it out to it's own file. inode.c and file.c are already pretty large, and this code is complicated enough to live in its own space.
--- fs/btrfs/Makefile | 2 +- fs/btrfs/ctree.h | 14 -- fs/btrfs/delalloc-space.c | 497 ++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/delalloc-space.h | 25 +++ fs/btrfs/extent-tree.c | 486 +------------------------------------------ fs/btrfs/file.c | 1 + fs/btrfs/free-space-cache.c | 1 + fs/btrfs/inode-map.c | 1 + fs/btrfs/inode.c | 1 + fs/btrfs/ioctl.c | 1 + fs/btrfs/ordered-data.c | 1 + fs/btrfs/relocation.c | 1 + 12 files changed, 531 insertions(+), 500 deletions(-) create mode 100644 fs/btrfs/delalloc-space.c create mode 100644 fs/btrfs/delalloc-space.h
fs/btrfs/Makefile +1 -1
@@ -11,7 +11,7 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ compression.o delayed-ref.o relocation.o delayed-inode.o scrub.o \ reada.o backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o \ uuid-tree.o props.o free-space-tree.o tree-checker.o space-info.o \ - block-rsv.o + block-rsv.o delalloc-space.o btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
fs/btrfs/ctree.h +0 -14
@@ -2742,16 +2742,6 @@ enum btrfs_chunk_alloc_enum {int btrfs_chunk_alloc (struct btrfs_trans_handle *trans,u64 flags,enum btrfs_chunk_alloc_enum force); -int btrfs_alloc_data_chunk_ondemand (struct btrfs_inode *inode,u64 bytes); -int btrfs_check_data_free_space (struct inode *inode, -struct extent_changeset **reserved,u64 start,u64 len); -void btrfs_free_reserved_data_space (struct inode *inode, -struct extent_changeset *reserved,u64 start,u64 len); -void btrfs_delalloc_release_space (struct inode *inode, -struct extent_changeset *reserved, -u64 start,u64 len,bool qgroup_free); -void btrfs_free_reserved_data_space_noquota (struct inode *inode,u64 start, -u64 len);int btrfs_subvolume_reserve_metadata (struct btrfs_root *root,struct btrfs_block_rsv *rsv,int nitems,bool use_global_rsv);
@@ -2761,10 +2751,6 @@ void btrfs_delalloc_release_extents(struct btrfs_inode *inode, u64 num_bytes, bool qgroup_free);int btrfs_delalloc_reserve_metadata (struct btrfs_inode *inode,u64 num_bytes); -void btrfs_delalloc_release_metadata (struct btrfs_inode *inode,u64 num_bytes, -bool qgroup_free); -int btrfs_delalloc_reserve_space (struct inode *inode, -struct extent_changeset **reserved,u64 start,u64 len);int btrfs_inc_block_group_ro (struct btrfs_block_group_cache *cache);void btrfs_dec_block_group_ro (struct btrfs_block_group_cache *cache);void btrfs_put_block_group_cache (struct btrfs_fs_info *info);
fs/btrfs/delalloc-space.c new file +497 -0
497 lines not on this page · raw message
fs/btrfs/delalloc-space.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2019 Facebook. All rights reserved. +*/ + +#ifndef BTRFS_DELALLOC_SPACE_H +#define BTRFS_DELALLOC_SPACE_H + +struct extent_changeset ; + +int btrfs_alloc_data_chunk_ondemand (struct btrfs_inode *inode,u64 bytes); +int btrfs_check_data_free_space (struct inode *inode, +struct extent_changeset **reserved,u64 start,u64 len); +void btrfs_free_reserved_data_space (struct inode *inode, +struct extent_changeset *reserved,u64 start,u64 len); +void btrfs_delalloc_release_space (struct inode *inode, +struct extent_changeset *reserved, +u64 start,u64 len,bool qgroup_free); +void btrfs_free_reserved_data_space_noquota (struct inode *inode,u64 start, +u64 len); +void btrfs_delalloc_release_metadata (struct btrfs_inode *inode,u64 num_bytes, +bool qgroup_free); +int btrfs_delalloc_reserve_space (struct inode *inode, +struct extent_changeset **reserved,u64 start,u64 len); +#endif /* BTRFS_DELALLOC_SPACE_H */
fs/btrfs/extent-tree.c +1 -485
510 lines not on this page · raw message
fs/btrfs/file.c +1 -0
@@ -26,6 +26,7 @@#include "volumes.h" #include "qgroup.h" #include "compression.h" +#include "delalloc-space.h" static struct kmem_cache *btrfs_inode_defrag_cachep;/*
fs/btrfs/free-space-cache.c +1 -0
@@ -19,6 +19,7 @@#include "inode-map.h" #include "volumes.h" #include "space-info.h" +#include "delalloc-space.h" #define BITS_PER_BITMAP (PAGE_SIZE * 8UL)#define MAX_CACHE_BYTES_PER_GIG SZ_32K
fs/btrfs/inode-map.c +1 -0
@@ -11,6 +11,7 @@#include "free-space-cache.h" #include "inode-map.h" #include "transaction.h" +#include "delalloc-space.h" static int caching_kthread (void *data) {
fs/btrfs/inode.c +1 -0
@@ -47,6 +47,7 @@#include "props.h" #include "qgroup.h" #include "dedupe.h" +#include "delalloc-space.h" struct btrfs_iget_args {struct btrfs_key *location;
fs/btrfs/ioctl.c +1 -0
@@ -44,6 +44,7 @@#include "tree-log.h" #include "compression.h" #include "space-info.h" +#include "delalloc-space.h" #ifdef CONFIG_64BIT /* If we have a 32-bit userspace and 64-bit kernel, then the UAPI
fs/btrfs/ordered-data.c +1 -0
@@ -13,6 +13,7 @@#include "extent_io.h" #include "disk-io.h" #include "compression.h" +#include "delalloc-space.h" static struct kmem_cache *btrfs_ordered_extent_cache;
fs/btrfs/relocation.c +1 -0
@@ -20,6 +20,7 @@#include "inode-map.h" #include "qgroup.h" #include "print-tree.h" +#include "delalloc-space.h" /* * backref_node, mapping_node and tree_block start with this
Signature · 1 line
2.14.3
PATCH 4/4 btrfs: move the subvolume reservation stuff out of extent-tree.c
In reply to Josef BacikThis is just two functions, put it in root-tree.c since it involves root items.
--- fs/btrfs/extent-tree.c | 54 ------------------------------------------------ fs/btrfs/root-tree.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 54 deletions(-)
fs/btrfs/extent-tree.c +0 -54
@@ -4107,60 +4107,6 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,return ret; } -/* -* btrfs_subvolume_reserve_metadata() - reserve space for subvolume operation -* root: the root of the parent directory -* rsv: block reservation -* items: the number of items that we need do reservation -* use_global_rsv: allow fallback to the global block reservation -* -* This function is used to reserve the space for snapshot/subvolume -* creation and deletion. Those operations are different with the -* common file/directory operations, they change two fs/file trees -* and root tree, the number of items that the qgroup reserves is -* different with the free space reservation. So we can not use -* the space reservation mechanism in start_transaction(). -*/ -int btrfs_subvolume_reserve_metadata (struct btrfs_root *root, -struct btrfs_block_rsv *rsv,int items, -bool use_global_rsv) -{ -u64 qgroup_num_bytes =0 ; -u64 num_bytes; -int ret; -struct btrfs_fs_info *fs_info = root->fs_info; -struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv; - -if (test_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags)) { -/* One for parent inode, two for dir entries */ - qgroup_num_bytes =3 * fs_info->nodesize; - ret =btrfs_qgroup_reserve_meta_prealloc (root, - qgroup_num_bytes, true); -if (ret) -return ret; - } - - num_bytes =btrfs_calc_trans_metadata_size (fs_info, items); - rsv->space_info =btrfs_find_space_info (fs_info, -BTRFS_BLOCK_GROUP_METADATA ); - ret =btrfs_block_rsv_add (root, rsv, num_bytes, -BTRFS_RESERVE_FLUSH_ALL ); - -if (ret == -ENOSPC && use_global_rsv) - ret =btrfs_block_rsv_migrate (global_rsv, rsv, num_bytes, true); - -if (ret && qgroup_num_bytes) -btrfs_qgroup_free_meta_prealloc (root, qgroup_num_bytes); - -return ret; -} - -void btrfs_subvolume_release_metadata (struct btrfs_fs_info *fs_info, -struct btrfs_block_rsv *rsv) -{ -btrfs_block_rsv_release (fs_info, rsv, (u64)-1 ); -} -static int update_block_group (struct btrfs_trans_handle *trans,u64 bytenr,u64 num_bytes,int alloc) {
fs/btrfs/root-tree.c +56 -0
65 lines not on this page · raw message
Signature · 1 line
2.14.3