@@ -402,61 +402,36 @@ static int bch2_write_index_default(struct bch_write_op *op)
402402
403403/* Writes */
404404
405- void bch2_write_op_error_trans (struct btree_trans * trans , struct printbuf * out ,
406- struct bch_write_op * op , u64 offset , const char * fmt , ...)
405+ void bch2_write_op_error (struct bch_write_op * op , u64 offset , const char * fmt , ...)
407406{
408- if (op -> subvol )
409- lockrestart_do (trans ,
410- bch2_inum_offset_err_msg_trans (trans , out ,
411- (subvol_inum ) { op -> subvol , op -> pos .inode , },
412- offset << 9 ));
413- else {
414- struct bpos pos = op -> pos ;
415- pos .offset = offset ;
416- lockrestart_do (trans , bch2_inum_snap_offset_err_msg_trans (trans , out , pos ));
417- }
418-
419- prt_str (out , "write error: " );
420-
421- va_list args ;
422- va_start (args , fmt );
423- prt_vprintf (out , fmt , args );
424- va_end (args );
425-
426- if (op -> flags & BCH_WRITE_move ) {
427- struct data_update * u = container_of (op , struct data_update , op );
428-
429- prt_printf (out , "\n from internal move " );
430- bch2_bkey_val_to_text (out , op -> c , bkey_i_to_s_c (u -> k .k ));
431- }
432- }
407+ struct printbuf buf = PRINTBUF ;
433408
434- void bch2_write_op_error (struct printbuf * out , struct bch_write_op * op , u64 offset ,
435- const char * fmt , ...)
436- {
437- if (op -> subvol )
438- bch2_inum_offset_err_msg (op -> c , out ,
409+ if (op -> subvol ) {
410+ bch2_inum_offset_err_msg (op -> c , & buf ,
439411 (subvol_inum ) { op -> subvol , op -> pos .inode , },
440412 offset << 9 );
441- else {
413+ } else {
442414 struct bpos pos = op -> pos ;
443415 pos .offset = offset ;
444- bch2_inum_snap_offset_err_msg (op -> c , out , pos );
416+ bch2_inum_snap_offset_err_msg (op -> c , & buf , pos );
445417 }
446418
447- prt_str (out , "write error: " );
419+ prt_str (& buf , "write error: " );
448420
449421 va_list args ;
450422 va_start (args , fmt );
451- prt_vprintf (out , fmt , args );
423+ prt_vprintf (& buf , fmt , args );
452424 va_end (args );
453425
454426 if (op -> flags & BCH_WRITE_move ) {
455427 struct data_update * u = container_of (op , struct data_update , op );
456428
457- prt_printf (out , "\n from internal move " );
458- bch2_bkey_val_to_text (out , op -> c , bkey_i_to_s_c (u -> k .k ));
429+ prt_printf (& buf , "\n from internal move " );
430+ bch2_bkey_val_to_text (& buf , op -> c , bkey_i_to_s_c (u -> k .k ));
459431 }
432+
433+ bch_err_ratelimited (op -> c , "%s" , buf .buf );
434+ printbuf_exit (& buf );
460435}
461436
462437void bch2_submit_wbio_replicas (struct bch_write_bio * wbio , struct bch_fs * c ,
@@ -598,11 +573,8 @@ static void __bch2_write_index(struct bch_write_op *op)
598573 if (unlikely (ret && !bch2_err_matches (ret , EROFS ))) {
599574 struct bkey_i * insert = bch2_keylist_front (& op -> insert_keys );
600575
601- struct printbuf buf = PRINTBUF ;
602- bch2_write_op_error (& buf , op , bkey_start_offset (& insert -> k ),
576+ bch2_write_op_error (op , bkey_start_offset (& insert -> k ),
603577 "btree update error: %s" , bch2_err_str (ret ));
604- bch_err_ratelimited (c , "%s" , buf .buf );
605- printbuf_exit (& buf );
606578 }
607579
608580 if (ret )
@@ -1169,13 +1141,8 @@ static int bch2_write_extent(struct bch_write_op *op, struct write_point *wp,
11691141 * _dst = dst ;
11701142 return more ;
11711143csum_err :
1172- {
1173- struct printbuf buf = PRINTBUF ;
1174- bch2_write_op_error (& buf , op , op -> pos .offset ,
1175- "error verifying existing checksum while rewriting existing data (memory corruption?)" );
1176- bch_err_ratelimited (c , "%s" , buf .buf );
1177- printbuf_exit (& buf );
1178- }
1144+ bch2_write_op_error (op , op -> pos .offset ,
1145+ "error verifying existing checksum while rewriting existing data (memory corruption?)" );
11791146
11801147 ret = - EIO ;
11811148err :
@@ -1255,32 +1222,29 @@ static void bch2_nocow_write_convert_unwritten(struct bch_write_op *op)
12551222{
12561223 struct bch_fs * c = op -> c ;
12571224 struct btree_trans * trans = bch2_trans_get (c );
1225+ int ret = 0 ;
12581226
12591227 for_each_keylist_key (& op -> insert_keys , orig ) {
1260- int ret = for_each_btree_key_max_commit (trans , iter , BTREE_ID_extents ,
1228+ ret = for_each_btree_key_max_commit (trans , iter , BTREE_ID_extents ,
12611229 bkey_start_pos (& orig -> k ), orig -> k .p ,
12621230 BTREE_ITER_intent , k ,
12631231 NULL , NULL , BCH_TRANS_COMMIT_no_enospc , ({
12641232 bch2_nocow_write_convert_one_unwritten (trans , & iter , orig , k , op -> new_i_size );
12651233 }));
1266-
1267- if (ret && !bch2_err_matches (ret , EROFS )) {
1268- struct bkey_i * insert = bch2_keylist_front (& op -> insert_keys );
1269-
1270- struct printbuf buf = PRINTBUF ;
1271- bch2_write_op_error_trans (trans , & buf , op , bkey_start_offset (& insert -> k ),
1272- "btree update error: %s" , bch2_err_str (ret ));
1273- bch_err_ratelimited (c , "%s" , buf .buf );
1274- printbuf_exit (& buf );
1275- }
1276-
1277- if (ret ) {
1278- op -> error = ret ;
1234+ if (ret )
12791235 break ;
1280- }
12811236 }
12821237
12831238 bch2_trans_put (trans );
1239+
1240+ if (ret && !bch2_err_matches (ret , EROFS )) {
1241+ struct bkey_i * insert = bch2_keylist_front (& op -> insert_keys );
1242+ bch2_write_op_error (op , bkey_start_offset (& insert -> k ),
1243+ "btree update error: %s" , bch2_err_str (ret ));
1244+ }
1245+
1246+ if (ret )
1247+ op -> error = ret ;
12841248}
12851249
12861250static void __bch2_nocow_write_done (struct bch_write_op * op )
@@ -1436,11 +1400,8 @@ static void bch2_nocow_write(struct bch_write_op *op)
14361400 darray_exit (& buckets );
14371401
14381402 if (ret ) {
1439- struct printbuf buf = PRINTBUF ;
1440- bch2_write_op_error (& buf , op , op -> pos .offset ,
1403+ bch2_write_op_error (op , op -> pos .offset ,
14411404 "%s(): btree lookup error: %s" , __func__ , bch2_err_str (ret ));
1442- bch_err_ratelimited (c , "%s" , buf .buf );
1443- printbuf_exit (& buf );
14441405 op -> error = ret ;
14451406 op -> flags |= BCH_WRITE_submitted ;
14461407 }
@@ -1558,13 +1519,9 @@ static void __bch2_write(struct bch_write_op *op)
15581519 op -> flags |= BCH_WRITE_submitted ;
15591520
15601521 if (unlikely (ret < 0 )) {
1561- if (!(op -> flags & BCH_WRITE_alloc_nowait )) {
1562- struct printbuf buf = PRINTBUF ;
1563- bch2_write_op_error (& buf , op , op -> pos .offset ,
1522+ if (!(op -> flags & BCH_WRITE_alloc_nowait ))
1523+ bch2_write_op_error (op , op -> pos .offset ,
15641524 "%s(): %s" , __func__ , bch2_err_str (ret ));
1565- bch_err_ratelimited (c , "%s" , buf .buf );
1566- printbuf_exit (& buf );
1567- }
15681525 op -> error = ret ;
15691526 break ;
15701527 }
@@ -1691,10 +1648,7 @@ CLOSURE_CALLBACK(bch2_write)
16911648 wbio_init (bio )-> put_bio = false;
16921649
16931650 if (unlikely (bio -> bi_iter .bi_size & (c -> opts .block_size - 1 ))) {
1694- struct printbuf buf = PRINTBUF ;
1695- bch2_write_op_error (& buf , op , op -> pos .offset ,
1696- "misaligned write" );
1697- printbuf_exit (& buf );
1651+ bch2_write_op_error (op , op -> pos .offset , "misaligned write" );
16981652 op -> error = - EIO ;
16991653 goto err ;
17001654 }
0 commit comments