@@ -709,7 +709,6 @@ static noinline struct btree *bch2_btree_node_fill(struct btree_trans *trans,
709709 struct bch_fs * c = trans -> c ;
710710 struct btree_cache * bc = & c -> btree_cache ;
711711 struct btree * b ;
712- u32 seq ;
713712
714713 if (unlikely (level >= BTREE_MAX_DEPTH )) {
715714 int ret = bch2_fs_topology_error (c , "attempting to get btree node at level %u, >= max depth %u" ,
@@ -775,34 +774,26 @@ static noinline struct btree *bch2_btree_node_fill(struct btree_trans *trans,
775774 }
776775
777776 set_btree_node_read_in_flight (b );
778-
779777 six_unlock_write (& b -> c .lock );
780- seq = six_lock_seq (& b -> c .lock );
781- six_unlock_intent (& b -> c .lock );
782778
783- /* Unlock before doing IO: */
784- if (path && sync )
785- bch2_trans_unlock_noassert (trans );
786-
787- bch2_btree_node_read (trans , b , sync );
779+ if (path ) {
780+ u32 seq = six_lock_seq (& b -> c .lock );
788781
789- if (!sync )
790- return NULL ;
782+ /* Unlock before doing IO: */
783+ six_unlock_intent (& b -> c .lock );
784+ bch2_trans_unlock_noassert (trans );
791785
792- if (path ) {
793- int ret = bch2_trans_relock (trans ) ?:
794- bch2_btree_path_relock_intent (trans , path );
795- if (ret ) {
796- BUG_ON (!trans -> restarted );
797- return ERR_PTR (ret );
798- }
799- }
786+ bch2_btree_node_read (trans , b , sync );
800787
801- if (!six_relock_type ( & b -> c . lock , lock_type , seq )) {
802- BUG_ON (! path ) ;
788+ if (!sync )
789+ return NULL ;
803790
804- trace_and_count (c , trans_restart_relock_after_fill , trans , _THIS_IP_ , path );
805- return ERR_PTR (btree_trans_restart (trans , BCH_ERR_transaction_restart_relock_after_fill ));
791+ if (!six_relock_type (& b -> c .lock , lock_type , seq ))
792+ b = NULL ;
793+ } else {
794+ bch2_btree_node_read (trans , b , sync );
795+ if (lock_type == SIX_LOCK_read )
796+ six_lock_downgrade (& b -> c .lock );
806797 }
807798
808799 return b ;
@@ -1135,18 +1126,19 @@ int bch2_btree_node_prefetch(struct btree_trans *trans,
11351126{
11361127 struct bch_fs * c = trans -> c ;
11371128 struct btree_cache * bc = & c -> btree_cache ;
1138- struct btree * b ;
11391129
11401130 BUG_ON (path && !btree_node_locked (path , level + 1 ));
11411131 BUG_ON (level >= BTREE_MAX_DEPTH );
11421132
1143- b = btree_cache_find (bc , k );
1133+ struct btree * b = btree_cache_find (bc , k );
11441134 if (b )
11451135 return 0 ;
11461136
11471137 b = bch2_btree_node_fill (trans , path , k , btree_id ,
11481138 level , SIX_LOCK_read , false);
1149- return PTR_ERR_OR_ZERO (b );
1139+ if (!IS_ERR_OR_NULL (b ))
1140+ six_unlock_read (& b -> c .lock );
1141+ return bch2_trans_relock (trans ) ?: PTR_ERR_OR_ZERO (b );
11501142}
11511143
11521144void bch2_btree_node_evict (struct btree_trans * trans , const struct bkey_i * k )
0 commit comments