Couple of misc patches
cover Couple of misc patches
Here are 4 patches which are independent of one another. The first 2 just change two more function to take btrfs_inode. Patch 3 just extends the usage of in_range which renders offset_in_entry redundant thus removing the function. Final patch just restructures btrfs_inc_block_group_ro to use a do{} while() loo rather than a label-based. This doesn't introduce extra nesting so I don't know why the label approach was chosen in the first place.
Nikolay Borisov (4):
btrfs: Make btrfs_replace_file_extents take btrfs_inode
btrfs: Make find_desired_extent take btrfs_inode
btrfs: Replace offset_in_entry with in_range
btrfs: Replace opencoded while loop with proper construct
fs/btrfs/block-group.c | 42 ++++++++++++++------------ fs/btrfs/ctree.h | 5 ++-- fs/btrfs/file.c | 66 ++++++++++++++++++++--------------------- fs/btrfs/inode.c | 2 +- fs/btrfs/ordered-data.c | 19 +++--------- fs/btrfs/reflink.c | 10 +++---- 6 files changed, 68 insertions(+), 76 deletions(-)
--
2.25.1
PATCH 1/4 btrfs: Make btrfs_replace_file_extents take btrfs_inode
--- fs/btrfs/ctree.h | 5 +++-- fs/btrfs/file.c | 51 +++++++++++++++++++++++----------------------- fs/btrfs/inode.c | 2 +- fs/btrfs/reflink.c | 10 ++++----- 4 files changed, 34 insertions(+), 34 deletions(-)
fs/btrfs/ctree.h +3 -2
@@ -3212,8 +3212,9 @@ extern const struct file_operations btrfs_file_operations;int btrfs_drop_extents (struct btrfs_trans_handle *trans,struct btrfs_root *root,struct btrfs_inode *inode,struct btrfs_drop_extents_args *args); -int btrfs_replace_file_extents (struct inode *inode,struct btrfs_path *path, -const u64 start,const u64 end, +int btrfs_replace_file_extents (struct btrfs_inode *inode, +struct btrfs_path *path,const u64 start, +const u64 end,struct btrfs_replace_extent_info *extent_info,struct btrfs_trans_handle **trans_out); int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
fs/btrfs/file.c +25 -26
128 lines not on this page · raw message
fs/btrfs/inode.c +1 -1
@@ -9915,7 +9915,7 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent(if (!path)return ERR_PTR (-ENOMEM ); - ret =btrfs_replace_file_extents (&inode->vfs_inode, path, file_offset, + ret =btrfs_replace_file_extents (inode, path, file_offset, file_offset + len -1 , &extent_info, &trans);btrfs_free_path (path);
fs/btrfs/reflink.c +5 -5
@@ -482,9 +482,9 @@ static int btrfs_clone(struct inode *src, struct inode *inode, clone_info.file_offset = new_key.offset; clone_info.extent_buf = buf; clone_info.is_new_extent = false; - ret =btrfs_replace_file_extents (inode, path, drop_start, - new_key.offset + datal -1 , &clone_info, - &trans); + ret =btrfs_replace_file_extents (BTRFS_I (inode), path, + drop_start, new_key.offset + datal -1 , + &clone_info, &trans);if (ret) goto out; }else if (type ==BTRFS_FILE_EXTENT_INLINE ) {
@@ -553,8 +553,8 @@ static int btrfs_clone(struct inode *src, struct inode *inode,*/ btrfs_release_path (path); - ret =btrfs_replace_file_extents (inode, path, last_dest_end, - destoff + len -1 ,NULL , &trans); + ret =btrfs_replace_file_extents (BTRFS_I (inode), path, + last_dest_end, destoff + len -1 ,NULL , &trans);if (ret) goto out;
Signature · 1 line
2.25.1
PATCH 2/4 btrfs: Make find_desired_extent take btrfs_inode
In reply to Nikolay Borisov--- fs/btrfs/file.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
fs/btrfs/file.c +7 -8
@@ -3492,13 +3492,13 @@ static long btrfs_fallocate(struct file *file, int mode,return ret; } -static loff_t find_desired_extent (struct inode *inode,loff_t offset, +static loff_t find_desired_extent (struct btrfs_inode *inode,loff_t offset,int whence) { -struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb); +struct btrfs_fs_info *fs_info = inode->root->fs_info;struct extent_map *em =NULL ;struct extent_state *cached_state =NULL ; -loff_t i_size = inode->i_size; +loff_t i_size = inode->vfs_inode.i_size;u64 lockstart;u64 lockend;u64 start;
@@ -3521,11 +3521,10 @@ static loff_t find_desired_extent(struct inode *inode, loff_t offset, lockend--; len = lockend - lockstart +1 ; -lock_extent_bits (&BTRFS_I (inode)->io_tree, lockstart, lockend, - &cached_state); +lock_extent_bits (&inode->io_tree, lockstart, lockend, &cached_state);while (start < i_size) { - em =btrfs_get_extent_fiemap (BTRFS_I (inode), start, len); + em =btrfs_get_extent_fiemap (inode, start, len);if (IS_ERR (em)) { ret =PTR_ERR (em); em =NULL ;
@@ -3547,7 +3546,7 @@ static loff_t find_desired_extent(struct inode *inode, loff_t offset,cond_resched (); }free_extent_map (em); -unlock_extent_cached (&BTRFS_I (inode)->io_tree, lockstart, lockend, +unlock_extent_cached (&inode->io_tree, lockstart, lockend, &cached_state);if (ret) { offset = ret;
@@ -3571,7 +3570,7 @@ static loff_t btrfs_file_llseek(struct file *file, loff_t offset, int whence)case SEEK_DATA :case SEEK_HOLE :btrfs_inode_lock (inode,BTRFS_ILOCK_SHARED ); - offset =find_desired_extent (inode, offset, whence); + offset =find_desired_extent (BTRFS_I (inode), offset, whence);btrfs_inode_unlock (inode,BTRFS_ILOCK_SHARED );break ; }
Signature · 1 line
2.25.1
PATCH 3/4 btrfs: Replace offset_in_entry with in_range
In reply to Nikolay BorisovNo point in duplicating the functionality just use the generic helper we have.
--- fs/btrfs/ordered-data.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
fs/btrfs/ordered-data.c +4 -15
@@ -107,17 +107,6 @@ static struct rb_node *__tree_search(struct rb_root *root, u64 file_offset,return NULL ; } -/* -* helper to check if a given offset is inside a given entry -*/ -static int offset_in_entry (struct btrfs_ordered_extent *entry,u64 file_offset) -{ -if (file_offset < entry->file_offset || - entry->file_offset + entry->num_bytes <= file_offset) -return 0 ; -return 1 ; -} -static int range_overlaps (struct btrfs_ordered_extent *entry,u64 file_offset,u64 len) {
@@ -142,7 +131,7 @@ static inline struct rb_node *tree_search(struct btrfs_ordered_inode_tree *tree,if (tree->last) { entry = rb_entry(tree->last, struct btrfs_ordered_extent, rb_node); -if (offset_in_entry (entry, file_offset)) +if (in_range (file_offset, entry->file_offset, entry->num_bytes))return tree->last; } ret =__tree_search (root, file_offset, &prev);
@@ -349,7 +338,7 @@ bool btrfs_dec_test_first_ordered_pending(struct btrfs_inode *inode, goto out; entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); -if (!offset_in_entry (entry, *file_offset)) +if (!in_range (*file_offset, entry->file_offset, entry->num_bytes)) goto out; dec_start =max (*file_offset, entry->file_offset);
@@ -428,7 +417,7 @@ bool btrfs_dec_test_ordered_pending(struct btrfs_inode *inode, entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); have_entry: -if (!offset_in_entry (entry, file_offset)) +if (!in_range (file_offset, entry->file_offset, entry->num_bytes)) goto out;if (io_size > entry->bytes_left)
@@ -779,7 +768,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct btrfs_inode *ino goto out; entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); -if (!offset_in_entry (entry, file_offset)) +if (!in_range (file_offset, entry->file_offset, entry->num_bytes)) entry =NULL ;if (entry)refcount_inc (&entry->refs);
Signature · 1 line
2.25.1
PATCH 4/4 btrfs: Replace opencoded while loop with proper construct
In reply to Nikolay Borisovbtrfs_inc_block_group_ro wants to ensure that the current transaction is not running dirty block groups, if it is it waits and loops again. That logic is currently implemented using a goto label. Actually using a proper do {} while() construct doesn't hurt readibility nor does it introduce excessive nesting and makes the relevant code stand out by being encompassed in the loop construct. No functional changes.
--- fs/btrfs/block-group.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-)
fs/btrfs/block-group.c +23 -19
@@ -2262,29 +2262,33 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,struct btrfs_trans_handle *trans;u64 alloc_flags;int ret; +bool dirty_bg_running; -again: - trans =btrfs_join_transaction (fs_info->extent_root); -if (IS_ERR (trans)) -return PTR_ERR (trans); +do { + trans =btrfs_join_transaction (fs_info->extent_root); +if (IS_ERR (trans)) +return PTR_ERR (trans); -/* -* we're not allowed to set block groups readonly after the dirty -* block groups cache has started writing. If it already started, -* back off and let this transaction commit -*/ -mutex_lock (&fs_info->ro_block_group_mutex); -if (test_bit (BTRFS_TRANS_DIRTY_BG_RUN , &trans->transaction->flags)) { -u64 transid = trans->transid; + dirty_bg_running = false; -mutex_unlock (&fs_info->ro_block_group_mutex); -btrfs_end_transaction (trans); +/* +* we're not allowed to set block groups readonly after the dirty +* block groups cache has started writing. If it already started, +* back off and let this transaction commit +*/ +mutex_lock (&fs_info->ro_block_group_mutex); +if (test_bit (BTRFS_TRANS_DIRTY_BG_RUN , &trans->transaction->flags)) { +u64 transid = trans->transid; - ret =btrfs_wait_for_commit (fs_info, transid); -if (ret) -return ret; - goto again; - } +mutex_unlock (&fs_info->ro_block_group_mutex); +btrfs_end_transaction (trans); + + ret =btrfs_wait_for_commit (fs_info, transid); +if (ret) +return ret; + dirty_bg_running = true; + } + }while (dirty_bg_running);if (do_chunk_alloc) {/*
Signature · 1 line
2.25.1
Quoted 7 lines · Nikolay Borisov
Here are 4 patches which are independent of one another. The first 2 just change two more function to take
btrfs_inode. Patch 3 just extends the usage ofin_rangewhich rendersoffset_in_entryredundant thus removing the function. Final patch just restructuresbtrfs_inc_block_group_roto use a do{}while()loo rather than a label-based. This doesn't introduce extra nesting so I don't know why the label approach was chosen in the first place.
Quoted 5 lines
Nikolay Borisov (4):
btrfs: Makebtrfs_replace_file_extentstakebtrfs_inode
btrfs: Makefind_desired_extenttakebtrfs_inode
btrfs: Replaceoffset_in_entrywithin_range
btrfs: Replace opencoded while loop with proper construct
Added to topic branch, will be in for-next once merge window is over. Thanks.