@@ -224,13 +224,14 @@ void bch2_logged_op_truncate_to_text(struct printbuf *out, struct bch_fs *c, str
224
224
225
225
static int truncate_set_isize (struct btree_trans * trans ,
226
226
subvol_inum inum ,
227
- u64 new_i_size )
227
+ u64 new_i_size ,
228
+ bool warn )
228
229
{
229
230
struct btree_iter iter = { NULL };
230
231
struct bch_inode_unpacked inode_u ;
231
232
int ret ;
232
233
233
- ret = bch2_inode_peek (trans , & iter , & inode_u , inum , BTREE_ITER_intent ) ?:
234
+ ret = __bch2_inode_peek (trans , & iter , & inode_u , inum , BTREE_ITER_intent , warn ) ?:
234
235
(inode_u .bi_size = new_i_size , 0 ) ?:
235
236
bch2_inode_write (trans , & iter , & inode_u );
236
237
@@ -247,10 +248,11 @@ static int __bch2_resume_logged_op_truncate(struct btree_trans *trans,
247
248
struct bkey_i_logged_op_truncate * op = bkey_i_to_logged_op_truncate (op_k );
248
249
subvol_inum inum = { le32_to_cpu (op -> v .subvol ), le64_to_cpu (op -> v .inum ) };
249
250
u64 new_i_size = le64_to_cpu (op -> v .new_i_size );
251
+ bool warn_errors = i_sectors_delta != NULL ;
250
252
int ret ;
251
253
252
254
ret = commit_do (trans , NULL , NULL , BCH_TRANS_COMMIT_no_enospc ,
253
- truncate_set_isize (trans , inum , new_i_size ));
255
+ truncate_set_isize (trans , inum , new_i_size , i_sectors_delta != NULL ));
254
256
if (ret )
255
257
goto err ;
256
258
@@ -263,8 +265,8 @@ static int __bch2_resume_logged_op_truncate(struct btree_trans *trans,
263
265
if (bch2_err_matches (ret , BCH_ERR_transaction_restart ))
264
266
ret = 0 ;
265
267
err :
266
- bch2_logged_op_finish ( trans , op_k );
267
- bch_err_fn (c , ret );
268
+ if ( warn_errors )
269
+ bch_err_fn (c , ret );
268
270
return ret ;
269
271
}
270
272
@@ -288,9 +290,14 @@ int bch2_truncate(struct bch_fs *c, subvol_inum inum, u64 new_i_size, u64 *i_sec
288
290
* resume only proceeding in one of the snapshots
289
291
*/
290
292
down_read (& c -> snapshot_create_lock );
291
- int ret = bch2_trans_run (c ,
292
- bch2_logged_op_start (trans , & op .k_i ) ?:
293
- __bch2_resume_logged_op_truncate (trans , & op .k_i , i_sectors_delta ));
293
+ struct btree_trans * trans = bch2_trans_get (c );
294
+ int ret = bch2_logged_op_start (trans , & op .k_i );
295
+ if (ret )
296
+ goto out ;
297
+ ret = __bch2_resume_logged_op_truncate (trans , & op .k_i , i_sectors_delta );
298
+ ret = bch2_logged_op_finish (trans , & op .k_i ) ?: ret ;
299
+ out :
300
+ bch2_trans_put (trans );
294
301
up_read (& c -> snapshot_create_lock );
295
302
296
303
return ret ;
@@ -308,7 +315,8 @@ void bch2_logged_op_finsert_to_text(struct printbuf *out, struct bch_fs *c, stru
308
315
prt_printf (out , " src_offset=%llu" , le64_to_cpu (op .v -> src_offset ));
309
316
}
310
317
311
- static int adjust_i_size (struct btree_trans * trans , subvol_inum inum , u64 offset , s64 len )
318
+ static int adjust_i_size (struct btree_trans * trans , subvol_inum inum ,
319
+ u64 offset , s64 len , bool warn )
312
320
{
313
321
struct btree_iter iter ;
314
322
struct bch_inode_unpacked inode_u ;
@@ -317,7 +325,7 @@ static int adjust_i_size(struct btree_trans *trans, subvol_inum inum, u64 offset
317
325
offset <<= 9 ;
318
326
len <<= 9 ;
319
327
320
- ret = bch2_inode_peek (trans , & iter , & inode_u , inum , BTREE_ITER_intent );
328
+ ret = __bch2_inode_peek (trans , & iter , & inode_u , inum , BTREE_ITER_intent , warn );
321
329
if (ret )
322
330
return ret ;
323
331
@@ -357,12 +365,22 @@ static int __bch2_resume_logged_op_finsert(struct btree_trans *trans,
357
365
u64 len = abs (shift );
358
366
u64 pos = le64_to_cpu (op -> v .pos );
359
367
bool insert = shift > 0 ;
368
+ u32 snapshot ;
369
+ bool warn_errors = i_sectors_delta != NULL ;
360
370
int ret = 0 ;
361
371
362
372
ret = bch2_inum_opts_get (trans , inum , & opts );
363
373
if (ret )
364
374
return ret ;
365
375
376
+ /*
377
+ * check for missing subvolume before fpunch, as in resume we don't want
378
+ * it to be a fatal error
379
+ */
380
+ ret = __bch2_subvolume_get_snapshot (trans , inum .subvol , & snapshot , warn_errors );
381
+ if (ret )
382
+ return ret ;
383
+
366
384
bch2_trans_iter_init (trans , & iter , BTREE_ID_extents ,
367
385
POS (inum .inum , 0 ),
368
386
BTREE_ITER_intent );
@@ -373,7 +391,7 @@ case LOGGED_OP_FINSERT_start:
373
391
374
392
if (insert ) {
375
393
ret = commit_do (trans , NULL , NULL , BCH_TRANS_COMMIT_no_enospc ,
376
- adjust_i_size (trans , inum , src_offset , len ) ?:
394
+ adjust_i_size (trans , inum , src_offset , len , warn_errors ) ?:
377
395
bch2_logged_op_update (trans , & op -> k_i ));
378
396
if (ret )
379
397
goto err ;
@@ -396,11 +414,11 @@ case LOGGED_OP_FINSERT_shift_extents:
396
414
struct bkey_i delete , * copy ;
397
415
struct bkey_s_c k ;
398
416
struct bpos src_pos = POS (inum .inum , src_offset );
399
- u32 snapshot ;
400
417
401
418
bch2_trans_begin (trans );
402
419
403
- ret = bch2_subvolume_get_snapshot (trans , inum .subvol , & snapshot );
420
+ ret = __bch2_subvolume_get_snapshot (trans , inum .subvol , & snapshot ,
421
+ warn_errors );
404
422
if (ret )
405
423
goto btree_err ;
406
424
@@ -463,12 +481,12 @@ case LOGGED_OP_FINSERT_shift_extents:
463
481
464
482
if (!insert ) {
465
483
ret = commit_do (trans , NULL , NULL , BCH_TRANS_COMMIT_no_enospc ,
466
- adjust_i_size (trans , inum , src_offset , shift ) ?:
484
+ adjust_i_size (trans , inum , src_offset , shift , warn_errors ) ?:
467
485
bch2_logged_op_update (trans , & op -> k_i ));
468
486
} else {
469
487
/* We need an inode update to update bi_journal_seq for fsync: */
470
488
ret = commit_do (trans , NULL , NULL , BCH_TRANS_COMMIT_no_enospc ,
471
- adjust_i_size (trans , inum , 0 , 0 ) ?:
489
+ adjust_i_size (trans , inum , 0 , 0 , warn_errors ) ?:
472
490
bch2_logged_op_update (trans , & op -> k_i ));
473
491
}
474
492
@@ -477,9 +495,9 @@ case LOGGED_OP_FINSERT_finish:
477
495
break ;
478
496
}
479
497
err :
480
- bch_err_fn (c , ret );
481
- bch2_logged_op_finish (trans , op_k );
482
498
bch2_trans_iter_exit (trans , & iter );
499
+ if (warn_errors )
500
+ bch_err_fn (c , ret );
483
501
return ret ;
484
502
}
485
503
@@ -508,9 +526,14 @@ int bch2_fcollapse_finsert(struct bch_fs *c, subvol_inum inum,
508
526
* resume only proceeding in one of the snapshots
509
527
*/
510
528
down_read (& c -> snapshot_create_lock );
511
- int ret = bch2_trans_run (c ,
512
- bch2_logged_op_start (trans , & op .k_i ) ?:
513
- __bch2_resume_logged_op_finsert (trans , & op .k_i , i_sectors_delta ));
529
+ struct btree_trans * trans = bch2_trans_get (c );
530
+ int ret = bch2_logged_op_start (trans , & op .k_i );
531
+ if (ret )
532
+ goto out ;
533
+ ret = __bch2_resume_logged_op_finsert (trans , & op .k_i , i_sectors_delta );
534
+ ret = bch2_logged_op_finish (trans , & op .k_i ) ?: ret ;
535
+ out :
536
+ bch2_trans_put (trans );
514
537
up_read (& c -> snapshot_create_lock );
515
538
516
539
return ret ;
0 commit comments