@@ -100,9 +100,10 @@ static bool bkey_nocow_lock(struct bch_fs *c, struct moving_context *ctxt, struc
100
100
return true;
101
101
}
102
102
103
- static noinline void trace_io_move_finish2 (struct data_update * u ,
104
- struct bkey_i * new ,
105
- struct bkey_i * insert )
103
+ noinline_for_stack
104
+ static void trace_io_move_finish2 (struct data_update * u ,
105
+ struct bkey_i * new ,
106
+ struct bkey_i * insert )
106
107
{
107
108
struct bch_fs * c = u -> op .c ;
108
109
struct printbuf buf = PRINTBUF ;
@@ -124,6 +125,7 @@ static noinline void trace_io_move_finish2(struct data_update *u,
124
125
printbuf_exit (& buf );
125
126
}
126
127
128
+ noinline_for_stack
127
129
static void trace_io_move_fail2 (struct data_update * m ,
128
130
struct bkey_s_c new ,
129
131
struct bkey_s_c wrote ,
@@ -179,19 +181,84 @@ static void trace_io_move_fail2(struct data_update *m,
179
181
printbuf_exit (& buf );
180
182
}
181
183
184
+ noinline_for_stack
185
+ static void trace_data_update2 (struct data_update * m ,
186
+ struct bkey_s_c old , struct bkey_s_c k ,
187
+ struct bkey_i * insert )
188
+ {
189
+ struct bch_fs * c = m -> op .c ;
190
+ struct printbuf buf = PRINTBUF ;
191
+
192
+ prt_str (& buf , "\nold: " );
193
+ bch2_bkey_val_to_text (& buf , c , old );
194
+ prt_str (& buf , "\nk: " );
195
+ bch2_bkey_val_to_text (& buf , c , k );
196
+ prt_str (& buf , "\nnew: " );
197
+ bch2_bkey_val_to_text (& buf , c , bkey_i_to_s_c (insert ));
198
+
199
+ trace_data_update (c , buf .buf );
200
+ printbuf_exit (& buf );
201
+ }
202
+
203
+ noinline_for_stack
204
+ static void trace_io_move_created_rebalance2 (struct data_update * m ,
205
+ struct bkey_s_c old , struct bkey_s_c k ,
206
+ struct bkey_i * insert )
207
+ {
208
+ struct bch_fs * c = m -> op .c ;
209
+ struct printbuf buf = PRINTBUF ;
210
+
211
+ bch2_data_update_opts_to_text (& buf , c , & m -> op .opts , & m -> data_opts );
212
+
213
+ prt_str (& buf , "\nold: " );
214
+ bch2_bkey_val_to_text (& buf , c , old );
215
+ prt_str (& buf , "\nk: " );
216
+ bch2_bkey_val_to_text (& buf , c , k );
217
+ prt_str (& buf , "\nnew: " );
218
+ bch2_bkey_val_to_text (& buf , c , bkey_i_to_s_c (insert ));
219
+
220
+ trace_io_move_created_rebalance (c , buf .buf );
221
+ printbuf_exit (& buf );
222
+
223
+ this_cpu_inc (c -> counters [BCH_COUNTER_io_move_created_rebalance ]);
224
+ }
225
+
226
+ noinline_for_stack
227
+ static int data_update_invalid_bkey (struct data_update * m ,
228
+ struct bkey_s_c old , struct bkey_s_c k ,
229
+ struct bkey_i * insert )
230
+ {
231
+ struct bch_fs * c = m -> op .c ;
232
+ struct printbuf buf = PRINTBUF ;
233
+ bch2_log_msg_start (c , & buf );
234
+
235
+ prt_str (& buf , "about to insert invalid key in data update path" );
236
+ prt_printf (& buf , "\nop.nonce: %u" , m -> op .nonce );
237
+ prt_str (& buf , "\nold: " );
238
+ bch2_bkey_val_to_text (& buf , c , old );
239
+ prt_str (& buf , "\nk: " );
240
+ bch2_bkey_val_to_text (& buf , c , k );
241
+ prt_str (& buf , "\nnew: " );
242
+ bch2_bkey_val_to_text (& buf , c , bkey_i_to_s_c (insert ));
243
+
244
+ bch2_fs_emergency_read_only2 (c , & buf );
245
+
246
+ bch2_print_str (c , KERN_ERR , buf .buf );
247
+ printbuf_exit (& buf );
248
+
249
+ return - BCH_ERR_invalid_bkey ;
250
+ }
251
+
182
252
static int __bch2_data_update_index_update (struct btree_trans * trans ,
183
253
struct bch_write_op * op )
184
254
{
185
255
struct bch_fs * c = op -> c ;
186
256
struct btree_iter iter ;
187
- struct data_update * m =
188
- container_of (op , struct data_update , op );
189
- struct keylist * keys = & op -> insert_keys ;
190
- struct printbuf journal_msg = PRINTBUF ;
257
+ struct data_update * m = container_of (op , struct data_update , op );
191
258
int ret = 0 ;
192
259
193
260
bch2_trans_iter_init (trans , & iter , m -> btree_id ,
194
- bkey_start_pos (& bch2_keylist_front (keys )-> k ),
261
+ bkey_start_pos (& bch2_keylist_front (& op -> insert_keys )-> k ),
195
262
BTREE_ITER_slots |BTREE_ITER_intent );
196
263
197
264
while (1 ) {
@@ -216,11 +283,11 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
216
283
if (ret )
217
284
goto err ;
218
285
219
- new = bkey_i_to_extent (bch2_keylist_front (keys ));
286
+ new = bkey_i_to_extent (bch2_keylist_front (& op -> insert_keys ));
220
287
221
288
if (!bch2_extents_match (k , old )) {
222
289
trace_io_move_fail2 (m , k , bkey_i_to_s_c (& new -> k_i ),
223
- NULL , "no match:" );
290
+ NULL , "no match:" );
224
291
goto nowork ;
225
292
}
226
293
@@ -239,7 +306,7 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
239
306
if (ret )
240
307
goto err ;
241
308
242
- bkey_copy (& new -> k_i , bch2_keylist_front (keys ));
309
+ bkey_copy (& new -> k_i , bch2_keylist_front (& op -> insert_keys ));
243
310
bch2_cut_front (iter .pos , & new -> k_i );
244
311
245
312
bch2_cut_front (iter .pos , insert );
@@ -353,31 +420,11 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
353
420
.flags = BCH_VALIDATE_commit ,
354
421
});
355
422
if (unlikely (invalid )) {
356
- struct printbuf buf = PRINTBUF ;
357
- bch2_log_msg_start (c , & buf );
358
-
359
- prt_str (& buf , "about to insert invalid key in data update path" );
360
- prt_printf (& buf , "\nop.nonce: %u" , m -> op .nonce );
361
- prt_str (& buf , "\nold: " );
362
- bch2_bkey_val_to_text (& buf , c , old );
363
- prt_str (& buf , "\nk: " );
364
- bch2_bkey_val_to_text (& buf , c , k );
365
- prt_str (& buf , "\nnew: " );
366
- bch2_bkey_val_to_text (& buf , c , bkey_i_to_s_c (insert ));
367
-
368
- bch2_fs_emergency_read_only2 (c , & buf );
369
-
370
- bch2_print_str (c , KERN_ERR , buf .buf );
371
- printbuf_exit (& buf );
372
-
373
- ret = - BCH_ERR_invalid_bkey ;
423
+ ret = data_update_invalid_bkey (m , old , k , insert );
374
424
goto out ;
375
425
}
376
426
377
- printbuf_reset (& journal_msg );
378
- prt_str (& journal_msg , bch2_data_update_type_strs [m -> type ]);
379
-
380
- ret = bch2_trans_log_msg (trans , & journal_msg ) ?:
427
+ ret = bch2_trans_log_str (trans , bch2_data_update_type_strs [m -> type ]) ?:
381
428
bch2_trans_log_bkey (trans , m -> btree_id , 0 , m -> k .k ) ?:
382
429
bch2_insert_snapshot_whiteouts (trans , m -> btree_id ,
383
430
k .k -> p , bkey_start_pos (& insert -> k )) ?:
@@ -389,38 +436,12 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
389
436
if (ret )
390
437
goto err ;
391
438
392
- if (trace_data_update_enabled ()) {
393
- struct printbuf buf = PRINTBUF ;
394
-
395
- prt_str (& buf , "\nold: " );
396
- bch2_bkey_val_to_text (& buf , c , old );
397
- prt_str (& buf , "\nk: " );
398
- bch2_bkey_val_to_text (& buf , c , k );
399
- prt_str (& buf , "\nnew: " );
400
- bch2_bkey_val_to_text (& buf , c , bkey_i_to_s_c (insert ));
401
-
402
- trace_data_update (c , buf .buf );
403
- printbuf_exit (& buf );
404
- }
439
+ if (trace_data_update_enabled ())
440
+ trace_data_update2 (m , old , k , insert );
405
441
406
442
if (bch2_bkey_sectors_need_rebalance (c , bkey_i_to_s_c (insert )) * k .k -> size >
407
- bch2_bkey_sectors_need_rebalance (c , k ) * insert -> k .size ) {
408
- struct printbuf buf = PRINTBUF ;
409
-
410
- bch2_data_update_opts_to_text (& buf , c , & m -> op .opts , & m -> data_opts );
411
-
412
- prt_str (& buf , "\nold: " );
413
- bch2_bkey_val_to_text (& buf , c , old );
414
- prt_str (& buf , "\nk: " );
415
- bch2_bkey_val_to_text (& buf , c , k );
416
- prt_str (& buf , "\nnew: " );
417
- bch2_bkey_val_to_text (& buf , c , bkey_i_to_s_c (insert ));
418
-
419
- trace_io_move_created_rebalance (c , buf .buf );
420
- printbuf_exit (& buf );
421
-
422
- this_cpu_inc (c -> counters [BCH_COUNTER_io_move_created_rebalance ]);
423
- }
443
+ bch2_bkey_sectors_need_rebalance (c , k ) * insert -> k .size )
444
+ trace_io_move_created_rebalance2 (m , old , k , insert );
424
445
425
446
ret = bch2_trans_commit (trans , & op -> res ,
426
447
NULL ,
@@ -441,9 +462,9 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
441
462
if (ret )
442
463
break ;
443
464
next :
444
- while (bkey_ge (iter .pos , bch2_keylist_front (keys )-> k .p )) {
445
- bch2_keylist_pop_front (keys );
446
- if (bch2_keylist_empty (keys ))
465
+ while (bkey_ge (iter .pos , bch2_keylist_front (& op -> insert_keys )-> k .p )) {
466
+ bch2_keylist_pop_front (& op -> insert_keys );
467
+ if (bch2_keylist_empty (& op -> insert_keys ))
447
468
goto out ;
448
469
}
449
470
continue ;
@@ -461,7 +482,6 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
461
482
goto next ;
462
483
}
463
484
out :
464
- printbuf_exit (& journal_msg );
465
485
bch2_trans_iter_exit (trans , & iter );
466
486
BUG_ON (bch2_err_matches (ret , BCH_ERR_transaction_restart ));
467
487
return ret ;
0 commit comments