@@ -137,12 +137,15 @@ struct bkey_i *bch2_journal_keys_peek_prev_min(struct bch_fs *c, enum btree_id b
137
137
struct journal_key * k ;
138
138
139
139
BUG_ON (* idx > keys -> nr );
140
+
141
+ if (!keys -> nr )
142
+ return NULL ;
140
143
search :
141
144
if (!* idx )
142
145
* idx = __bch2_journal_key_search (keys , btree_id , level , pos );
143
146
144
147
while (* idx < keys -> nr &&
145
- __journal_key_cmp (btree_id , level , end_pos , idx_to_key (keys , * idx - 1 )) >= 0 ) {
148
+ __journal_key_cmp (btree_id , level , end_pos , idx_to_key (keys , * idx )) >= 0 ) {
146
149
(* idx )++ ;
147
150
iters ++ ;
148
151
if (iters == 10 ) {
@@ -151,18 +154,23 @@ struct bkey_i *bch2_journal_keys_peek_prev_min(struct bch_fs *c, enum btree_id b
151
154
}
152
155
}
153
156
157
+ if (* idx == keys -> nr )
158
+ -- (* idx );
159
+
154
160
struct bkey_i * ret = NULL ;
155
161
rcu_read_lock (); /* for overwritten_ranges */
156
162
157
- while ((k = * idx < keys -> nr ? idx_to_key (keys , * idx ) : NULL )) {
163
+ while (true) {
164
+ k = idx_to_key (keys , * idx );
158
165
if (__journal_key_cmp (btree_id , level , end_pos , k ) > 0 )
159
166
break ;
160
167
161
168
if (k -> overwritten ) {
162
169
if (k -> overwritten_range )
163
- * idx = rcu_dereference (k -> overwritten_range )-> start - 1 ;
164
- else
165
- * idx -= 1 ;
170
+ * idx = rcu_dereference (k -> overwritten_range )-> start ;
171
+ if (!* idx )
172
+ break ;
173
+ -- (* idx );
166
174
continue ;
167
175
}
168
176
@@ -171,6 +179,8 @@ struct bkey_i *bch2_journal_keys_peek_prev_min(struct bch_fs *c, enum btree_id b
171
179
break ;
172
180
}
173
181
182
+ if (!* idx )
183
+ break ;
174
184
-- (* idx );
175
185
iters ++ ;
176
186
if (iters == 10 ) {
0 commit comments