@@ -2187,7 +2187,11 @@ static int add_missing_dir_index(struct btrfs_root *root,
2187
2187
key .type = BTRFS_DIR_INDEX_KEY ;
2188
2188
key .offset = backref -> index ;
2189
2189
ret = btrfs_insert_empty_item (trans , root , & path , & key , data_size );
2190
- BUG_ON (ret );
2190
+ if (ret < 0 ) {
2191
+ errno = - ret ;
2192
+ error_msg (ERROR_MSG_START_TRANS , "%m" );
2193
+ return ret ;
2194
+ }
2191
2195
2192
2196
leaf = path .nodes [0 ];
2193
2197
dir_item = btrfs_item_ptr (leaf , path .slots [0 ], struct btrfs_dir_item );
@@ -2204,7 +2208,12 @@ static int add_missing_dir_index(struct btrfs_root *root,
2204
2208
write_extent_buffer (leaf , backref -> name , name_ptr , backref -> namelen );
2205
2209
btrfs_mark_buffer_dirty (leaf );
2206
2210
btrfs_release_path (& path );
2207
- btrfs_commit_transaction (trans , root );
2211
+ ret = btrfs_commit_transaction (trans , root );
2212
+ if (ret < 0 ) {
2213
+ errno = - ret ;
2214
+ error_msg (ERROR_MSG_START_TRANS , "%m" );
2215
+ return ret ;
2216
+ }
2208
2217
2209
2218
backref -> found_dir_index = 1 ;
2210
2219
dir_rec = get_inode_rec (inode_cache , backref -> dir , 0 );
@@ -2258,7 +2267,11 @@ static int delete_dir_index(struct btrfs_root *root,
2258
2267
ret = btrfs_delete_one_dir_name (trans , root , & path , di );
2259
2268
BUG_ON (ret );
2260
2269
btrfs_release_path (& path );
2261
- btrfs_commit_transaction (trans , root );
2270
+ ret = btrfs_commit_transaction (trans , root );
2271
+ if (ret < 0 ) {
2272
+ errno = - ret ;
2273
+ error_msg (ERROR_MSG_START_TRANS , "%m" );
2274
+ }
2262
2275
return ret ;
2263
2276
}
2264
2277
@@ -2295,8 +2308,18 @@ static int create_inode_item(struct btrfs_root *root,
2295
2308
2296
2309
ret = insert_inode_item (trans , root , rec -> ino , size , rec -> nbytes ,
2297
2310
nlink , mode );
2298
- btrfs_commit_transaction (trans , root );
2299
- return 0 ;
2311
+ if (ret < 0 ) {
2312
+ btrfs_abort_transaction (trans , ret );
2313
+ btrfs_commit_transaction (trans , root );
2314
+ return ret ;
2315
+ }
2316
+
2317
+ ret = btrfs_commit_transaction (trans , root );
2318
+ if (ret < 0 ) {
2319
+ errno = - ret ;
2320
+ error_msg (ERROR_MSG_START_TRANS , "%m" );
2321
+ }
2322
+ return ret ;
2300
2323
}
2301
2324
2302
2325
static int repair_inode_backrefs (struct btrfs_root * root ,
@@ -2390,8 +2413,17 @@ static int repair_inode_backrefs(struct btrfs_root *root,
2390
2413
backref -> dir , & location ,
2391
2414
imode_to_type (rec -> imode ),
2392
2415
backref -> index );
2393
- BUG_ON (ret );
2394
- btrfs_commit_transaction (trans , root );
2416
+ if (ret < 0 ) {
2417
+ btrfs_abort_transaction (trans , ret );
2418
+ btrfs_commit_transaction (trans , root );
2419
+ break ;
2420
+ }
2421
+ ret = btrfs_commit_transaction (trans , root );
2422
+ if (ret < 0 ) {
2423
+ errno = - ret ;
2424
+ error_msg (ERROR_MSG_COMMIT_TRANS , "%m" );
2425
+ break ;
2426
+ }
2395
2427
repaired ++ ;
2396
2428
}
2397
2429
@@ -3074,8 +3106,12 @@ static int try_repair_inode(struct btrfs_root *root, struct inode_record *rec)
3074
3106
ret = repair_unaligned_extent_recs (trans , root , & path , rec );
3075
3107
if (!ret && rec -> errors & I_ERR_INVALID_GEN )
3076
3108
ret = repair_inode_gen_original (trans , root , & path , rec );
3077
- btrfs_commit_transaction (trans , root );
3078
3109
btrfs_release_path (& path );
3110
+ ret = btrfs_commit_transaction (trans , root );
3111
+ if (ret < 0 ) {
3112
+ errno = - ret ;
3113
+ error_msg (ERROR_MSG_COMMIT_TRANS , "%m" );
3114
+ }
3079
3115
return ret ;
3080
3116
}
3081
3117
@@ -3184,7 +3220,12 @@ static int check_inode_recs(struct btrfs_root *root,
3184
3220
return ret ;
3185
3221
}
3186
3222
3187
- btrfs_commit_transaction (trans , root );
3223
+ ret = btrfs_commit_transaction (trans , root );
3224
+ if (ret < 0 ) {
3225
+ errno = - ret ;
3226
+ error_msg (ERROR_MSG_COMMIT_TRANS , "%m" );
3227
+ return ret ;
3228
+ }
3188
3229
return - EAGAIN ;
3189
3230
}
3190
3231
@@ -3662,8 +3703,12 @@ static int repair_btree(struct btrfs_root *root,
3662
3703
cache = next_cache_extent (cache );
3663
3704
}
3664
3705
out :
3665
- btrfs_commit_transaction (trans , root );
3666
3706
btrfs_release_path (& path );
3707
+ ret = btrfs_commit_transaction (trans , root );
3708
+ if (ret < 0 ) {
3709
+ errno = - ret ;
3710
+ error_msg (ERROR_MSG_COMMIT_TRANS , "%m" );
3711
+ }
3667
3712
return ret ;
3668
3713
}
3669
3714
@@ -4605,6 +4650,7 @@ static int try_to_fix_bad_block(struct btrfs_root *root,
4605
4650
ret = btrfs_search_slot (trans , search_root , & key , & path , 0 , 1 );
4606
4651
if (ret ) {
4607
4652
ret = - EIO ;
4653
+ btrfs_abort_transaction (trans , ret );
4608
4654
btrfs_commit_transaction (trans , search_root );
4609
4655
break ;
4610
4656
}
@@ -4613,11 +4659,17 @@ static int try_to_fix_bad_block(struct btrfs_root *root,
4613
4659
else if (status == BTRFS_TREE_BLOCK_INVALID_OFFSETS )
4614
4660
ret = fix_item_offset (search_root , & path );
4615
4661
if (ret ) {
4662
+ btrfs_abort_transaction (trans , ret );
4616
4663
btrfs_commit_transaction (trans , search_root );
4617
4664
break ;
4618
4665
}
4619
4666
btrfs_release_path (& path );
4620
- btrfs_commit_transaction (trans , search_root );
4667
+ ret = btrfs_commit_transaction (trans , search_root );
4668
+ if (ret < 0 ) {
4669
+ errno = - ret ;
4670
+ error_msg (ERROR_MSG_COMMIT_TRANS , "%m" );
4671
+ break ;
4672
+ }
4621
4673
}
4622
4674
ulist_free (roots );
4623
4675
btrfs_release_path (& path );
@@ -7843,6 +7895,7 @@ static int fixup_extent_flags(struct extent_record *rec)
7843
7895
ret = btrfs_search_slot (trans , root , & key , & path , 0 , 1 );
7844
7896
if (ret < 0 ) {
7845
7897
btrfs_release_path (& path );
7898
+ btrfs_abort_transaction (trans , ret );
7846
7899
btrfs_commit_transaction (trans , root );
7847
7900
return ret ;
7848
7901
} else if (ret ) {
@@ -7852,7 +7905,12 @@ static int fixup_extent_flags(struct extent_record *rec)
7852
7905
}
7853
7906
fprintf (stderr , "Didn't find extent for %llu\n" , rec -> start );
7854
7907
btrfs_release_path (& path );
7855
- btrfs_commit_transaction (trans , root );
7908
+ ret = btrfs_commit_transaction (trans , root );
7909
+ if (ret < 0 ) {
7910
+ errno = - ret ;
7911
+ error_msg (ERROR_MSG_COMMIT_TRANS , "%m" );
7912
+ return ret ;
7913
+ }
7856
7914
return - ENOENT ;
7857
7915
}
7858
7916
@@ -7870,8 +7928,12 @@ static int fixup_extent_flags(struct extent_record *rec)
7870
7928
btrfs_mark_buffer_dirty (path .nodes [0 ]);
7871
7929
btrfs_release_path (& path );
7872
7930
ret = btrfs_commit_transaction (trans , root );
7873
- if (!ret )
7931
+ if (ret < 0 ) {
7932
+ errno = - ret ;
7933
+ error_msg (ERROR_MSG_COMMIT_TRANS , "%m" );
7934
+ } else {
7874
7935
fprintf (stderr , "Repaired extent flags for %llu\n" , rec -> start );
7936
+ }
7875
7937
7876
7938
return ret ;
7877
7939
}
@@ -7950,7 +8012,7 @@ static int prune_corrupt_blocks(void)
7950
8012
struct btrfs_trans_handle * trans = NULL ;
7951
8013
struct cache_extent * cache ;
7952
8014
struct btrfs_corrupt_block * corrupt ;
7953
- int ret ;
8015
+ int ret = 0 ;
7954
8016
7955
8017
while (1 ) {
7956
8018
cache = search_cache_extent (gfs_info -> corrupt_blocks , 0 );
@@ -7969,9 +8031,14 @@ static int prune_corrupt_blocks(void)
7969
8031
prune_one_block (trans , corrupt );
7970
8032
remove_cache_extent (gfs_info -> corrupt_blocks , cache );
7971
8033
}
7972
- if (trans )
7973
- return btrfs_commit_transaction (trans , gfs_info -> tree_root );
7974
- return 0 ;
8034
+ if (trans ) {
8035
+ ret = btrfs_commit_transaction (trans , gfs_info -> tree_root );
8036
+ if (ret < 0 ) {
8037
+ errno = - ret ;
8038
+ error_msg (ERROR_MSG_COMMIT_TRANS , "%m" );
8039
+ }
8040
+ }
8041
+ return ret ;
7975
8042
}
7976
8043
7977
8044
static int record_unaligned_extent_rec (struct extent_record * rec )
@@ -8096,13 +8163,19 @@ static int repair_extent_item_generation(struct extent_record *rec)
8096
8163
/* Not possible */
8097
8164
if (ret == 0 )
8098
8165
ret = - EUCLEAN ;
8099
- if (ret < 0 )
8166
+ if (ret < 0 ) {
8167
+ btrfs_abort_transaction (trans , ret );
8168
+ btrfs_commit_transaction (trans , extent_root );
8100
8169
goto out ;
8170
+ }
8101
8171
ret = btrfs_previous_extent_item (extent_root , & path , rec -> start );
8102
8172
if (ret > 0 )
8103
8173
ret = - ENOENT ;
8104
- if (ret < 0 )
8174
+ if (ret < 0 ) {
8175
+ btrfs_abort_transaction (trans , ret );
8176
+ btrfs_commit_transaction (trans , extent_root );
8105
8177
goto out ;
8178
+ }
8106
8179
8107
8180
if (!new_gen )
8108
8181
new_gen = trans -> transid ;
@@ -8120,10 +8193,6 @@ static int repair_extent_item_generation(struct extent_record *rec)
8120
8193
rec -> generation = new_gen ;
8121
8194
out :
8122
8195
btrfs_release_path (& path );
8123
- if (ret < 0 ) {
8124
- btrfs_abort_transaction (trans , ret );
8125
- btrfs_commit_transaction (trans , extent_root );
8126
- }
8127
8196
return ret ;
8128
8197
}
8129
8198
@@ -8343,8 +8412,11 @@ static int check_extent_refs(struct btrfs_root *root,
8343
8412
goto repair_abort ;
8344
8413
}
8345
8414
ret = btrfs_commit_transaction (trans , root );
8346
- if (ret )
8415
+ if (ret < 0 ) {
8416
+ errno = - ret ;
8417
+ error_msg (ERROR_MSG_COMMIT_TRANS , "%m" );
8347
8418
goto repair_abort ;
8419
+ }
8348
8420
}
8349
8421
return ret ;
8350
8422
}
@@ -8826,8 +8898,18 @@ static int check_block_groups(struct block_group_tree *bg_cache)
8826
8898
}
8827
8899
8828
8900
ret = btrfs_fix_block_accounting (trans );
8829
- btrfs_commit_transaction (trans , gfs_info -> tree_root );
8830
- return ret ? ret : - EAGAIN ;
8901
+ if (ret < 0 ) {
8902
+ btrfs_abort_transaction (trans , ret );
8903
+ btrfs_commit_transaction (trans , gfs_info -> tree_root );
8904
+ return ret ;
8905
+ }
8906
+ ret = btrfs_commit_transaction (trans , gfs_info -> tree_root );
8907
+ if (ret < 0 ) {
8908
+ errno = - ret ;
8909
+ error_msg (ERROR_MSG_COMMIT_TRANS , "%m" );
8910
+ return ret ;
8911
+ }
8912
+ return - EAGAIN ;
8831
8913
}
8832
8914
8833
8915
/**
@@ -9646,14 +9728,24 @@ static int delete_bad_item(struct btrfs_root *root, struct bad_item *bad)
9646
9728
}
9647
9729
9648
9730
ret = btrfs_search_slot (trans , root , & bad -> key , & path , -1 , 1 );
9649
- if (ret ) {
9650
- if ( ret > 0 )
9651
- ret = 0 ;
9731
+ if (ret < 0 ) {
9732
+ btrfs_abort_transaction ( trans , ret );
9733
+ btrfs_commit_transaction ( trans , root ) ;
9652
9734
goto out ;
9653
9735
}
9736
+ if (ret > 0 ) {
9737
+ ret = 0 ;
9738
+ goto out_commit ;
9739
+ }
9654
9740
ret = btrfs_del_item (trans , root , & path );
9655
- out :
9741
+ if (ret < 0 ) {
9742
+ btrfs_abort_transaction (trans , ret );
9743
+ btrfs_commit_transaction (trans , root );
9744
+ goto out ;
9745
+ }
9746
+ out_commit :
9656
9747
btrfs_commit_transaction (trans , root );
9748
+ out :
9657
9749
btrfs_release_path (& path );
9658
9750
return ret ;
9659
9751
}
@@ -9998,8 +10090,14 @@ static int repair_root_items(void)
9998
10090
out :
9999
10091
free_roots_info_cache ();
10000
10092
btrfs_release_path (& path );
10001
- if (trans )
10002
- btrfs_commit_transaction (trans , gfs_info -> tree_root );
10093
+ if (trans ) {
10094
+ ret = btrfs_commit_transaction (trans , gfs_info -> tree_root );
10095
+ if (ret < 0 ) {
10096
+ errno = - ret ;
10097
+ error_msg (ERROR_MSG_COMMIT_TRANS , "%m" );
10098
+ return ret ;
10099
+ }
10100
+ }
10003
10101
if (ret < 0 )
10004
10102
return ret ;
10005
10103
0 commit comments