@@ -123,76 +123,44 @@ static int need_whiteout_for_snapshot(struct btree_trans *trans,
123
123
}
124
124
125
125
int __bch2_insert_snapshot_whiteouts (struct btree_trans * trans ,
126
- enum btree_id id ,
127
- struct bpos old_pos ,
128
- struct bpos new_pos )
126
+ enum btree_id btree , struct bpos pos ,
127
+ snapshot_id_list * s )
129
128
{
130
- struct bch_fs * c = trans -> c ;
131
- struct btree_iter old_iter , new_iter = {};
132
- struct bkey_s_c old_k , new_k ;
133
- snapshot_id_list s ;
134
- struct bkey_i * update ;
135
129
int ret = 0 ;
136
130
137
- if (!bch2_snapshot_has_children (c , old_pos .snapshot ))
138
- return 0 ;
139
-
140
- darray_init (& s );
131
+ darray_for_each (* s , id ) {
132
+ pos .snapshot = * id ;
141
133
142
- bch2_trans_iter_init (trans , & old_iter , id , old_pos ,
143
- BTREE_ITER_not_extents |
144
- BTREE_ITER_all_snapshots );
145
- while ((old_k = bch2_btree_iter_prev (trans , & old_iter )).k &&
146
- !(ret = bkey_err (old_k )) &&
147
- bkey_eq (old_pos , old_k .k -> p )) {
148
- struct bpos whiteout_pos =
149
- SPOS (new_pos .inode , new_pos .offset , old_k .k -> p .snapshot );
150
-
151
- if (!bch2_snapshot_is_ancestor (c , old_k .k -> p .snapshot , old_pos .snapshot ) ||
152
- snapshot_list_has_ancestor (c , & s , old_k .k -> p .snapshot ))
153
- continue ;
154
-
155
- new_k = bch2_bkey_get_iter (trans , & new_iter , id , whiteout_pos ,
156
- BTREE_ITER_not_extents |
157
- BTREE_ITER_intent );
158
- ret = bkey_err (new_k );
134
+ struct btree_iter iter ;
135
+ struct bkey_s_c k = bch2_bkey_get_iter (trans , & iter , btree , pos ,
136
+ BTREE_ITER_not_extents |
137
+ BTREE_ITER_intent );
138
+ ret = bkey_err (k );
159
139
if (ret )
160
140
break ;
161
141
162
- if (new_k .k -> type == KEY_TYPE_deleted ) {
163
- update = bch2_trans_kmalloc (trans , sizeof (struct bkey_i ));
142
+ if (k .k -> type == KEY_TYPE_deleted ) {
143
+ struct bkey_i * update = bch2_trans_kmalloc (trans , sizeof (struct bkey_i ));
164
144
ret = PTR_ERR_OR_ZERO (update );
165
- if (ret )
145
+ if (ret ) {
146
+ bch2_trans_iter_exit (trans , & iter );
166
147
break ;
148
+ }
167
149
168
150
bkey_init (& update -> k );
169
- update -> k .p = whiteout_pos ;
151
+ update -> k .p = pos ;
170
152
update -> k .type = KEY_TYPE_whiteout ;
171
153
172
- ret = bch2_trans_update (trans , & new_iter , update ,
154
+ ret = bch2_trans_update (trans , & iter , update ,
173
155
BTREE_UPDATE_internal_snapshot_node );
174
156
}
175
- bch2_trans_iter_exit (trans , & new_iter );
157
+ bch2_trans_iter_exit (trans , & iter );
176
158
177
- ret = snapshot_list_add (c , & s , old_k .k -> p .snapshot );
178
159
if (ret )
179
160
break ;
180
161
}
181
- bch2_trans_iter_exit (trans , & new_iter );
182
- bch2_trans_iter_exit (trans , & old_iter );
183
-
184
- snapshot_id_list s2 ;
185
- ret = bch2_get_snapshot_overwrites (trans , id , old_pos , & s2 );
186
- if (ret ) {
187
- darray_exit (& s );
188
- return ret ;
189
- }
190
-
191
- BUG_ON (s .nr != s2 .nr );
192
- BUG_ON (memcmp (s .data , s2 .data , sizeof (s .data [0 ]) * s .nr ));
193
162
194
- darray_exit (& s2 );
195
- darray_exit (& s );
163
+ darray_exit (s );
196
164
return ret ;
197
165
}
198
166
0 commit comments