@@ -91,18 +91,20 @@ static int bch2_snapshot_tree_create(struct btree_trans *trans,
91
91
92
92
/* Snapshot nodes: */
93
93
94
- static bool bch2_snapshot_is_ancestor_early (struct bch_fs * c , u32 id , u32 ancestor )
94
+ static bool __bch2_snapshot_is_ancestor_early (struct snapshot_table * t , u32 id , u32 ancestor )
95
95
{
96
- struct snapshot_table * t ;
97
-
98
- rcu_read_lock ();
99
- t = rcu_dereference (c -> snapshots );
100
-
101
96
while (id && id < ancestor )
102
97
id = __snapshot_t (t , id )-> parent ;
98
+ return id == ancestor ;
99
+ }
100
+
101
+ static bool bch2_snapshot_is_ancestor_early (struct bch_fs * c , u32 id , u32 ancestor )
102
+ {
103
+ rcu_read_lock ();
104
+ bool ret = __bch2_snapshot_is_ancestor_early (rcu_dereference (c -> snapshots ), id , ancestor );
103
105
rcu_read_unlock ();
104
106
105
- return id == ancestor ;
107
+ return ret ;
106
108
}
107
109
108
110
static inline u32 get_ancestor_below (struct snapshot_table * t , u32 id , u32 ancestor )
@@ -120,25 +122,27 @@ static inline u32 get_ancestor_below(struct snapshot_table *t, u32 id, u32 ances
120
122
121
123
bool __bch2_snapshot_is_ancestor (struct bch_fs * c , u32 id , u32 ancestor )
122
124
{
123
- struct snapshot_table * t ;
124
125
bool ret ;
125
126
126
- EBUG_ON (c -> recovery_pass_done <= BCH_RECOVERY_PASS_check_snapshots );
127
-
128
127
rcu_read_lock ();
129
- t = rcu_dereference (c -> snapshots );
128
+ struct snapshot_table * t = rcu_dereference (c -> snapshots );
129
+
130
+ if (unlikely (c -> recovery_pass_done <= BCH_RECOVERY_PASS_check_snapshots )) {
131
+ ret = __bch2_snapshot_is_ancestor_early (t , id , ancestor );
132
+ goto out ;
133
+ }
130
134
131
135
while (id && id < ancestor - IS_ANCESTOR_BITMAP )
132
136
id = get_ancestor_below (t , id , ancestor );
133
137
134
138
if (id && id < ancestor ) {
135
139
ret = test_bit (ancestor - id - 1 , __snapshot_t (t , id )-> is_ancestor );
136
140
137
- EBUG_ON (ret != bch2_snapshot_is_ancestor_early ( c , id , ancestor ));
141
+ EBUG_ON (ret != __bch2_snapshot_is_ancestor_early ( t , id , ancestor ));
138
142
} else {
139
143
ret = id == ancestor ;
140
144
}
141
-
145
+ out :
142
146
rcu_read_unlock ();
143
147
144
148
return ret ;
@@ -547,7 +551,7 @@ static int check_snapshot_tree(struct btree_trans *trans,
547
551
"snapshot tree points to missing subvolume:\n %s" ,
548
552
(printbuf_reset (& buf ),
549
553
bch2_bkey_val_to_text (& buf , c , st .s_c ), buf .buf )) ||
550
- fsck_err_on (!bch2_snapshot_is_ancestor_early (c ,
554
+ fsck_err_on (!bch2_snapshot_is_ancestor (c ,
551
555
le32_to_cpu (subvol .snapshot ),
552
556
root_id ),
553
557
c , snapshot_tree_to_wrong_subvol ,
0 commit comments