Minor cleanups
David Sterba
maintainercover Minor cleanups
Minor and safe cleanups.
David Sterba (11):
btrfs: use struct_size to calculate size of raid hash table
btrfs: move mapping of block for discard to its caller
btrfs: open code trivial helper btrfs_header_fsid
btrfs: open code trivial helper btrfs_header_chunk_tree_uuid
btrfs: simplify parameters of btrfs_set_disk_extent_flags
btrfs: adjust message level for unrecognized mount option
btrfs: raid56: simplify sort_parity_stripes
btrfs: replace u_long type cast with unsigned long
btrfs: adjust delayed refs message level
btrfs: merge unlocking to common exit block in
btrfs_commit_transaction
btrfs: reduce pointer intdirections in btree_readpage_end_io_hook
fs/btrfs/ctree.c | 4 +-- fs/btrfs/ctree.h | 12 +-------- fs/btrfs/disk-io.c | 18 +++++++------ fs/btrfs/extent-tree.c | 7 +++--- fs/btrfs/raid56.c | 4 +-- fs/btrfs/super.c | 2 +- fs/btrfs/transaction.c | 57 +++++++++++++++--------------------------- fs/btrfs/volumes.c | 33 ++++++++---------------- 8 files changed, 49 insertions(+), 88 deletions(-)
Signature · 1 line
2.25.0
David Sterba
maintainerPATCH 1/11 btrfs: use struct_size to calculate size of raid hash table
The struct_size macro does the same calculation and is safe regarding overflows. Though we're not expecting them to happen, use the helper for clarity.
--- fs/btrfs/raid56.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/raid56.c +1 -3
@@ -206,7 +206,6 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info)struct btrfs_stripe_hash *h;int num_entries =1 <<BTRFS_STRIPE_HASH_TABLE_BITS ;int i; -int table_size;if (info->stripe_hash_table)return 0 ;
@@ -218,8 +217,7 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info)* Try harder to allocate and fallback to vmalloc to lower the chance * of a failing mount. */ - table_size =sizeof (*table) +sizeof (*h) * num_entries; - table =kvzalloc (table_size,GFP_KERNEL ); + table =kvzalloc (struct_size (table, table, num_entries),GFP_KERNEL );if (!table)return -ENOMEM ;
Signature · 1 line
2.25.0
Re: [PATCH 01/11] btrfs: use struct_size to calculate size of raid hash table
Looks good,
David Sterba
maintainerPATCH 2/11 btrfs: move mapping of block for discard to its caller
In reply to David SterbaThere's a simple forwarded call based on the operation that would better fit the caller btrfs_map_block that's until now a trivial wrapper.
--- fs/btrfs/volumes.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/btrfs/volumes.c +5 -4
@@ -5953,10 +5953,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,struct btrfs_io_geometry geom;ASSERT (bbio_ret); - -if (op ==BTRFS_MAP_DISCARD ) -return __btrfs_map_block_for_discard (fs_info, logical, - length, bbio_ret); +ASSERT (op !=BTRFS_MAP_DISCARD ); ret =btrfs_get_io_geometry (fs_info, op, logical, *length, &geom);if (ret <0 )
@@ -6186,6 +6183,10 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, u64 logical, u64 *length, struct btrfs_bio **bbio_ret, int mirror_num) { + if (op == BTRFS_MAP_DISCARD) + return __btrfs_map_block_for_discard(fs_info, logical, + length, bbio_ret); +return __btrfs_map_block (fs_info, op, logical, length, bbio_ret, mirror_num,0 ); }
Signature · 1 line
2.25.0
Re: [PATCH 02/11] btrfs: move mapping of block for discard to its caller
Looks good,
Re: [PATCH 02/11] btrfs: move mapping of block for discard to its caller
In reply to David SterbaQuoted 4 lines · David Sterba
There's a simple forwarded call based on the operation that would better fit the caller
btrfs_map_blockthat's until now a trivial wrapper.Signed-off-by David Sterba <[email protected]>
David Sterba
maintainerPATCH 3/11 btrfs: open code trivial helper btrfs_header_fsid
In reply to David SterbaThe helper btrfs_header_fsid follows naming convention of other struct accessors but does something compeletly different. As the offsetof calculation is clear in the context of extent buffer operations we can remove it.
--- fs/btrfs/ctree.h | 5 ----- fs/btrfs/disk-io.c | 6 ++++-- 2 files changed, 4 insertions(+), 7 deletions(-)
fs/btrfs/ctree.h +0 -5
@@ -1976,11 +1976,6 @@ static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb,btrfs_set_header_flags (eb, flags); } -static inline unsigned long btrfs_header_fsid (void ) -{ -return offsetof(struct btrfs_header , fsid); -} -static inline unsigned long btrfs_header_chunk_tree_uuid (const struct extent_buffer *eb) {return offsetof(struct btrfs_header , chunk_tree_uuid);
fs/btrfs/disk-io.c +4 -2
@@ -541,7 +541,8 @@ static int csum_dirty_buffer(struct btrfs_fs_info *fs_info, struct page *page)return -EUCLEAN ;ASSERT (memcmp_extent_buffer (eb, fs_info->fs_devices->metadata_uuid, -btrfs_header_fsid (),BTRFS_FSID_SIZE ) ==0 ); + offsetof(struct btrfs_header , fsid), +BTRFS_FSID_SIZE ) ==0 );if (csum_tree_block (eb, result))return -EINVAL ;
@@ -571,7 +572,8 @@ static int check_tree_block_fsid(struct extent_buffer *eb)u8 fsid[BTRFS_FSID_SIZE ];int ret =1 ; -read_extent_buffer (eb, fsid,btrfs_header_fsid (),BTRFS_FSID_SIZE ); +read_extent_buffer (eb, fsid, offsetof(struct btrfs_header , fsid), +BTRFS_FSID_SIZE );while (fs_devices) {u8 *metadata_uuid;
Signature · 1 line
2.25.0
Re: [PATCH 03/11] btrfs: open code trivial helper btrfs_header_fsid
Looks good,
David Sterba
maintainerPATCH 4/11 btrfs: open code trivial helper btrfs_header_chunk_tree_uuid
In reply to David SterbaThe helper btrfs_header_chunk_tree_uuid follows naming convention of other struct accessors but does something compeletly different. As the offsetof calculation is clear in the context of extent buffer operations we can remove it.
--- fs/btrfs/ctree.h | 5 ----- fs/btrfs/disk-io.c | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-)
fs/btrfs/ctree.h +0 -5
@@ -1976,11 +1976,6 @@ static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb,btrfs_set_header_flags (eb, flags); } -static inline unsigned long btrfs_header_chunk_tree_uuid (const struct extent_buffer *eb) -{ -return offsetof(struct btrfs_header , chunk_tree_uuid); -} -static inline int btrfs_is_leaf (const struct extent_buffer *eb) {return btrfs_header_level (eb) ==0 ;
fs/btrfs/disk-io.c +2 -1
@@ -3093,7 +3093,8 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device chunk_root->commit_root =btrfs_root_node (chunk_root);read_extent_buffer (chunk_root->node, fs_info->chunk_tree_uuid, -btrfs_header_chunk_tree_uuid (chunk_root->node),BTRFS_UUID_SIZE ); + offsetof(struct btrfs_header , chunk_tree_uuid), +BTRFS_UUID_SIZE ); ret =btrfs_read_chunk_tree (fs_info);if (ret) {
Signature · 1 line
2.25.0
Re: [PATCH 04/11] btrfs: open code trivial helper btrfs_header_chunk_tree_uuid
Looks good,
David Sterba
maintainerPATCH 5/11 btrfs: simplify parameters of btrfs_set_disk_extent_flags
In reply to David SterbaAll callers pass extent buffer start and length so the extent buffer itself should work fine.
--- fs/btrfs/ctree.c | 4 +--- fs/btrfs/ctree.h | 2 +- fs/btrfs/extent-tree.c | 7 +++---- 3 files changed, 5 insertions(+), 8 deletions(-)
fs/btrfs/ctree.c +1 -3
@@ -925,9 +925,7 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,if (new_flags !=0 ) {int level =btrfs_header_level (buf); - ret =btrfs_set_disk_extent_flags (trans, - buf->start, - buf->len, + ret =btrfs_set_disk_extent_flags (trans, buf, new_flags, level,0 );if (ret)return ret;
fs/btrfs/ctree.h +1 -1
@@ -2485,7 +2485,7 @@ int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,int btrfs_dec_ref (struct btrfs_trans_handle *trans,struct btrfs_root *root,struct extent_buffer *buf,int full_backref);int btrfs_set_disk_extent_flags (struct btrfs_trans_handle *trans, -u64 bytenr,u64 num_bytes,u64 flags, +struct extent_buffer *eb,u64 flags,int level,int is_data);int btrfs_free_extent (struct btrfs_trans_handle *trans,struct btrfs_ref *ref);
fs/btrfs/extent-tree.c +3 -4
@@ -2231,7 +2231,7 @@ int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, }int btrfs_set_disk_extent_flags (struct btrfs_trans_handle *trans, -u64 bytenr,u64 num_bytes,u64 flags, +struct extent_buffer *eb,u64 flags,int level,int is_data) {struct btrfs_delayed_extent_op *extent_op;
@@ -2247,7 +2247,7 @@ int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, extent_op->is_data = is_data ? true : false; extent_op->level = level; - ret =btrfs_add_delayed_extent_op (trans, bytenr, num_bytes, extent_op); + ret =btrfs_add_delayed_extent_op (trans, eb->start, eb->len, extent_op);if (ret)btrfs_free_delayed_extent_op (extent_op);return ret;
@@ -4741,8 +4741,7 @@ static noinline int walk_down_proc(struct btrfs_trans_handle *trans,BUG_ON (ret);/* -ENOMEM */ ret =btrfs_dec_ref (trans, root, eb,0 );BUG_ON (ret);/* -ENOMEM */ - ret =btrfs_set_disk_extent_flags (trans, eb->start, - eb->len, flag, + ret =btrfs_set_disk_extent_flags (trans, eb, flag,btrfs_header_level (eb),0 );BUG_ON (ret);/* -ENOMEM */ wc->flags[level] |= flag;
Signature · 1 line
2.25.0
Re: [PATCH 05/11] btrfs: simplify parameters of btrfs_set_disk_extent_flags
A similar change should work for btrfs_add_delayed_extent_op() as well, shouldn't it?
Anyhow,
Re: [PATCH 05/11] btrfs: simplify parameters of btrfs_set_disk_extent_flags
Quoted 2 lines · Johannes Thumshirn
A similar change should work for
btrfs_add_delayed_extent_op()as well, shouldn't it?
Yes. Possibly pushing that further down the call chain to the delayed refs, if all num_bytes is extent_buffer->len then this can be simplified to fs_info->nodesize.
Re: [PATCH 05/11] btrfs: simplify parameters of btrfs_set_disk_extent_flags
In reply to David SterbaQuoted 4 lines · David Sterba
All callers pass extent buffer start and length so the extent buffer itself should work fine.
Signed-off-by David Sterba <[email protected]>
David Sterba
maintainerPATCH 6/11 btrfs: adjust message level for unrecognized mount option
In reply to David SterbaAn unrecognized option is a failure that should get user/administrator attention, the info level is often below what gets logged, so make it error.
--- fs/btrfs/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/super.c +1 -1
@@ -873,7 +873,7 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,break ;#endif case Opt_err: -btrfs_info (info,"unrecognized mount option '%s'" , p); +btrfs_err (info,"unrecognized mount option '%s'" , p); ret = -EINVAL ; goto out;default :
Signature · 1 line
2.25.0
Re: [PATCH 06/11] btrfs: adjust message level for unrecognized mount option
Looks good,
Re: [PATCH 06/11] btrfs: adjust message level for unrecognized mount option
In reply to David SterbaQuoted 5 lines · David Sterba
An unrecognized option is a failure that should get user/administrator attention, the info level is often below what gets logged, so make it error.
Signed-off-by David Sterba <[email protected]>
David Sterba
maintainerPATCH 7/11 btrfs: raid56: simplify sort_parity_stripes
In reply to David SterbaRemove trivial comprator and open coded swap of two values.
--- fs/btrfs/volumes.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-)
fs/btrfs/volumes.c +4 -16
@@ -5428,31 +5428,19 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,return preferred_mirror; } -static inline int parity_smaller (u64 a,u64 b) -{ -return a > b; -} -/* Bubble-sort the stripe set to put the parity/syndrome stripes last */ static void sort_parity_stripes (struct btrfs_bio *bbio,int num_stripes) { -struct btrfs_bio_stripe s;int i; -u64 l;int again =1 ;while (again) { again =0 ;for (i =0 ; i < num_stripes -1 ; i++) { -if (parity_smaller (bbio->raid_map[i], - bbio->raid_map[i+1 ])) { - s = bbio->stripes[i]; - l = bbio->raid_map[i]; - bbio->stripes[i] = bbio->stripes[i+1 ]; - bbio->raid_map[i] = bbio->raid_map[i+1 ]; - bbio->stripes[i+1 ] = s; - bbio->raid_map[i+1 ] = l; - +/* Swap if parity is on a smaller index */ +if (bbio->raid_map[i] > bbio->raid_map[i +1 ]) { +swap (bbio->stripes[i], bbio->stripes[i +1 ]); +swap (bbio->raid_map[i], bbio->raid_map[i +1 ]); again =1 ; } }
Signature · 1 line
2.25.0
Re: [PATCH 07/11] btrfs: raid56: simplify sort_parity_stripes
Looks good,
David Sterba
maintainerPATCH 8/11 btrfs: replace u_long type cast with unsigned long
In reply to David SterbaWe don't use the u_XX types anywhere, though they're defined.
--- fs/btrfs/volumes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +2 -2
@@ -6269,8 +6269,8 @@ static void submit_stripe_bio(struct btrfs_bio *bbio, struct bio *bio,btrfs_debug_in_rcu (fs_info,"btrfs_map_bio: rw %d 0x%x, sector=%llu, dev=%lu (%s id %llu), size=%u" ,bio_op (bio), bio->bi_opf, (u64 )bio->bi_iter.bi_sector, - (u_long )dev->bdev->bd_dev,rcu_str_deref (dev->name), dev->devid, - bio->bi_iter.bi_size); + (unsigned long )dev->bdev->bd_dev,rcu_str_deref (dev->name), + dev->devid, bio->bi_iter.bi_size);bio_set_dev (bio, dev->bdev);btrfs_bio_counter_inc_noblocked (fs_info);
Signature · 1 line
2.25.0
Re: [PATCH 08/11] btrfs: replace u_long type cast with unsigned long
Looks good,
Re: [PATCH 08/11] btrfs: replace u_long type cast with unsigned long
In reply to David SterbaQuoted 12 lines · David Sterba
We don't use the
u_XXtypes anywhere, though they're defined.Signed-off-by David Sterba <[email protected]>--- fs/btrfs/volumes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/btrfs/volumes.c +0
-0
fs/btrfs/volumes.c static void submit_stripe_bio(struct btrfs_bio *bbio, struct bio *bio, · line 6273
Quoted 7 lines
fs/btrfs/volumes.c +2
-2@@ -6269,8 +6269,8 @@ static void submit_stripe_bio(struct btrfs_bio *bbio, struct bio *bio,btrfs_debug_in_rcu (fs_info,"btrfs_map_bio: rw %d 0x%x, sector=%llu, dev=%lu (%s id %llu), size=%u" ,bio_op (bio), bio->bi_opf, (u64 )bio->bi_iter.bi_sector, - (u_long )dev->bdev->bd_dev,rcu_str_deref (dev->name), dev->devid, - bio->bi_iter.bi_size); + (unsigned long )dev->bdev->bd_dev,rcu_str_deref (dev->name), + dev->devid, bio->bi_iter.bi_size);
Mostly we just print major and minor separately, which would remove the cast entirely.
David Sterba
maintainerPATCH 9/11 btrfs: adjust delayed refs message level
In reply to David SterbaThe message seems to be for debugging and has little value for users.
--- fs/btrfs/disk-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/disk-io.c +1 -1
@@ -4280,7 +4280,7 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,spin_lock (&delayed_refs->lock);if (atomic_read (&delayed_refs->num_entries) ==0 ) {spin_unlock (&delayed_refs->lock); -btrfs_info (fs_info,"delayed_refs has NO entry" ); +btrfs_debug (fs_info,"delayed_refs has NO entry" );return ret; }
Signature · 1 line
2.25.0
Re: [PATCH 09/11] btrfs: adjust delayed refs message level
Looks good,
Re: [PATCH 09/11] btrfs: adjust delayed refs message level
In reply to David SterbaQuoted 4 lines · David Sterba
The message seems to be for debugging and has little value for users.
Signed-off-by David Sterba <[email protected]>---
David Sterba
maintainerPATCH 10/11 btrfs: merge unlocking to common exit block in btrfs_commit_transaction
In reply to David SterbaThe tree_log_mutex and reloc_mutex locks are properly nested so we can simplify error handling and add labels for them. This reduces line count of the function.
--- fs/btrfs/transaction.c | 57 +++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 37 deletions(-)
fs/btrfs/transaction.c +20 -37
@@ -2194,10 +2194,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)* core function of the snapshot creation. */ ret =create_pending_snapshots (trans); -if (ret) { -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_reloc;/* * We insert the dir indexes of the snapshots and update the inode
@@ -2210,16 +2208,12 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)* the nodes and leaves. */ ret =btrfs_run_delayed_items (trans); -if (ret) { -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_reloc; ret =btrfs_run_delayed_refs (trans, (unsigned long )-1 ); -if (ret) { -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_reloc;/* * make sure none of the code above managed to slip in a
@@ -2245,11 +2239,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)mutex_lock (&fs_info->tree_log_mutex); ret =commit_fs_roots (trans); -if (ret) { -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_reloc;/* * Since the transaction is done, we can apply the pending changes
@@ -2267,29 +2258,20 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)* new delayed refs. Must handle them or qgroup can be wrong. */ ret =btrfs_run_delayed_refs (trans, (unsigned long )-1 ); -if (ret) { -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_tree_log;/* * Since fs roots are all committed, we can get a quite accurate * new_roots. So let's do quota accounting. */ ret =btrfs_qgroup_account_extents (trans); -if (ret <0 ) { -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret <0 ) + goto unlock_tree_log; ret =commit_cowonly_roots (trans); -if (ret) { -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_tree_log;/* * The tasks which save the space cache and inode cache may also
@@ -2297,9 +2279,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)*/ if (TRANS_ABORTED (cur_trans)) { ret = cur_trans->aborted; -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; + goto unlock_tree_log; }btrfs_prepare_extent_commit (fs_info);
@@ -2346,8 +2326,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)if (ret) {btrfs_handle_fs_error (fs_info, ret,"Error while writing out transaction" ); -mutex_unlock (&fs_info->tree_log_mutex); - goto scrub_continue; + goto unlock_tree_log; } ret =write_all_supers (fs_info,0 );
@@ -2394,6 +2373,10 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)return ret; +unlock_tree_log: +mutex_unlock (&fs_info->tree_log_mutex); +unlock_reloc: +mutex_unlock (&fs_info->reloc_mutex); scrub_continue:btrfs_scrub_continue (fs_info); cleanup_transaction:
Signature · 1 line
2.25.0
Re: [PATCH 10/11] btrfs: merge unlocking to common exit block in btrfs_commit_transaction
Looks good,
Re: [PATCH 10/11] btrfs: merge unlocking to common exit block in btrfs_commit_transaction
In reply to David SterbaQuoted 48 lines · David Sterba
The
tree_log_mutexandreloc_mutexlocks are properly nested so we can simplify error handling and add labels for them. This reduces line count of the function.Signed-off-by David Sterba <[email protected]>--- fs/btrfs/transaction.c | 57 +++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 37 deletions(-)fs/btrfs/transaction.c +6
-12@@ -2194,10 +2194,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)* core function of the snapshot creation. */ ret =create_pending_snapshots (trans); -if (ret) { -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_reloc;/* * We insert the dir indexes of the snapshots and update the inode @@ -2210,16 +2208,12 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)* the nodes and leaves. */ ret =btrfs_run_delayed_items (trans); -if (ret) { -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_reloc; ret =btrfs_run_delayed_refs (trans, (unsigned long )-1 ); -if (ret) { -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_reloc;/* * make sure none of the code above managed to slip in a
fs/btrfs/transaction.c int btrfs_commit_transaction(struct btrfs_trans_handle *trans) · line 2243
Quoted 10 lines
fs/btrfs/transaction.c +2
-5@@ -2245,11 +2239,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)mutex_lock (&fs_info->tree_log_mutex); ret =commit_fs_roots (trans); -if (ret) { -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_reloc;
goto unlock_tree_log;
Otherwise looks good. When fixed this you may add.
Thanks, Anand
Quoted 71 lines
fs/btrfs/transaction.c +12
-20/* * Since the transaction is done, we can apply the pending changes @@ -2267,29 +2258,20 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)* new delayed refs. Must handle them or qgroup can be wrong. */ ret =btrfs_run_delayed_refs (trans, (unsigned long )-1 ); -if (ret) { -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_tree_log;/* * Since fs roots are all committed, we can get a quite accurate * new_roots. So let's do quota accounting. */ ret =btrfs_qgroup_account_extents (trans); -if (ret <0 ) { -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret <0 ) + goto unlock_tree_log; ret =commit_cowonly_roots (trans); -if (ret) { -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_tree_log;/* * The tasks which save the space cache and inode cache may also @@ -2297,9 +2279,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)*/ if (TRANS_ABORTED (cur_trans)) { ret = cur_trans->aborted; -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; + goto unlock_tree_log; }btrfs_prepare_extent_commit (fs_info);@@ -2346,8 +2326,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)if (ret) {btrfs_handle_fs_error (fs_info, ret,"Error while writing out transaction" ); -mutex_unlock (&fs_info->tree_log_mutex); - goto scrub_continue; + goto unlock_tree_log; } ret =write_all_supers (fs_info,0 );@@ -2394,6 +2373,10 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)return ret; +unlock_tree_log: +mutex_unlock (&fs_info->tree_log_mutex); +unlock_reloc: +mutex_unlock (&fs_info->reloc_mutex); scrub_continue:btrfs_scrub_continue (fs_info); cleanup_transaction:
Re: [PATCH 10/11] btrfs: merge unlocking to common exit block in btrfs_commit_transaction
In reply to David Sterbafs/btrfs/transaction.c int btrfs_commit_transaction(struct btrfs_trans_handle *trans) · line 2329
Quoted 8 lines · David Sterba
fs/btrfs/transaction.c +1
-2btrfs_prepare_extent_commit (fs_info);@@ -2346,8 +2326,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)if (ret) {btrfs_handle_fs_error (fs_info, ret,"Error while writing out transaction" ); -mutex_unlock (&fs_info->tree_log_mutex); - goto scrub_continue; + goto unlock_tree_log;
Hm and this one is also wrong, in other cases that jump to unlock_tree_log the unlocking order is tree_log_mutex/reloc_mutex, while a few lines before there is unlock of reloc_mutex (while tree_log_mutex is still held). This means the unlocking order is reversed compared to the other cases and we can't jump to the label as this would lead to double unlock of reloc_mutex.
So the above hunk must stay as is, with a comment.
Quoted 16 lines
fs/btrfs/transaction.c +4
-0} ret =write_all_supers (fs_info,0 );@@ -2394,6 +2373,10 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)return ret; +unlock_tree_log: +mutex_unlock (&fs_info->tree_log_mutex); +unlock_reloc: +mutex_unlock (&fs_info->reloc_mutex); scrub_continue:btrfs_scrub_continue (fs_info); cleanup_transaction:Signature · 1 line
2.25.0
David Sterba
maintainerPATCH v2 1/1 btrfs: merge unlocking to common exit block in btrfs_commit_transaction
In reply to David SterbaThe tree_log_mutex and reloc_mutex locks are properly nested so we can simplify error handling and add labels for them. This reduces line count of the function.
---
v2:
- fixed label after commit_fs_roots, to point to unlock_tree_log
- added comment after btrfs_handle_fs_error and keep the locks as is
fs/btrfs/transaction.c | 58 +++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 35 deletions(-)
fs/btrfs/transaction.c +23 -35
@@ -2194,10 +2194,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)* core function of the snapshot creation. */ ret =create_pending_snapshots (trans); -if (ret) { -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_reloc;/* * We insert the dir indexes of the snapshots and update the inode
@@ -2210,16 +2208,12 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)* the nodes and leaves. */ ret =btrfs_run_delayed_items (trans); -if (ret) { -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_reloc; ret =btrfs_run_delayed_refs (trans, (unsigned long )-1 ); -if (ret) { -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_reloc;/* * make sure none of the code above managed to slip in a
@@ -2245,11 +2239,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)mutex_lock (&fs_info->tree_log_mutex); ret =commit_fs_roots (trans); -if (ret) { -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_tree_log;/* * Since the transaction is done, we can apply the pending changes
@@ -2267,29 +2258,20 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)* new delayed refs. Must handle them or qgroup can be wrong. */ ret =btrfs_run_delayed_refs (trans, (unsigned long )-1 ); -if (ret) { -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_tree_log;/* * Since fs roots are all committed, we can get a quite accurate * new_roots. So let's do quota accounting. */ ret =btrfs_qgroup_account_extents (trans); -if (ret <0 ) { -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret <0 ) + goto unlock_tree_log; ret =commit_cowonly_roots (trans); -if (ret) { -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; - } +if (ret) + goto unlock_tree_log;/* * The tasks which save the space cache and inode cache may also
@@ -2297,9 +2279,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)*/ if (TRANS_ABORTED (cur_trans)) { ret = cur_trans->aborted; -mutex_unlock (&fs_info->tree_log_mutex); -mutex_unlock (&fs_info->reloc_mutex); - goto scrub_continue; + goto unlock_tree_log; }btrfs_prepare_extent_commit (fs_info);
@@ -2346,6 +2326,10 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)if (ret) {btrfs_handle_fs_error (fs_info, ret,"Error while writing out transaction" ); +/* +* reloc_mutex has been unlocked, tree_log_mutex is still held +* but we can't jump to unlock_tree_log causing double unlock +*/ mutex_unlock (&fs_info->tree_log_mutex); goto scrub_continue; }
@@ -2394,6 +2378,10 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)return ret; +unlock_tree_log: +mutex_unlock (&fs_info->tree_log_mutex); +unlock_reloc: +mutex_unlock (&fs_info->reloc_mutex); scrub_continue:btrfs_scrub_continue (fs_info); cleanup_transaction:
Signature · 1 line
2.25.0
Re: [PATCH v2] btrfs: merge unlocking to common exit block in btrfs_commit_transaction
Quoted 10 lines · David Sterba
The
tree_log_mutexandreloc_mutexlocks are properly nested so we can simplify error handling and add labels for them. This reduces line count of the function.Signed-off-by David Sterba <[email protected]>---
v2:
- fixed label aftercommit_fs_roots, to point tounlock_tree_log
- added comment afterbtrfs_handle_fs_errorand keep the locks as is
David Sterba
maintainerPATCH 11/11 btrfs: reduce pointer intdirections in btree_readpage_end_io_hook
In reply to David SterbaAll we need to read is checksum size from fs_info superblock, and fs_info is provided by extent buffer so we can get rid of the wild pointer indirections from page/inode/root.
--- fs/btrfs/disk-io.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/btrfs/disk-io.c +4 -3
@@ -604,9 +604,8 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,u64 found_start;int found_level;struct extent_buffer *eb; -struct btrfs_root *root =BTRFS_I (page->mapping->host)->root; -struct btrfs_fs_info *fs_info = root->fs_info; -u16 csum_size =btrfs_super_csum_size (fs_info->super_copy); +struct btrfs_fs_info *fs_info; +u16 csum_size;int ret =0 ;u8 result[BTRFS_CSUM_SIZE ];int reads_done;
@@ -615,6 +614,8 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio, goto out; eb = (struct extent_buffer *)page->private; + fs_info = eb->fs_info; + csum_size =btrfs_super_csum_size (fs_info->super_copy);/* the pending IO might have been the only thing that kept this buffer * in memory. Make sure we have a ref for all this other checks
Signature · 1 line
2.25.0
Re: [PATCH 11/11] btrfs: reduce pointer intdirections in btree_readpage_end_io_hook