@@ -277,17 +277,19 @@ static int process_one_buffer(struct btrfs_root *log,
277
277
struct extent_buffer * eb ,
278
278
struct walk_control * wc , u64 gen )
279
279
{
280
+ int ret = 0 ;
281
+
280
282
if (wc -> pin )
281
- btrfs_pin_extent_for_log_replay (log -> fs_info -> extent_root ,
282
- eb -> start , eb -> len );
283
+ ret = btrfs_pin_extent_for_log_replay (log -> fs_info -> extent_root ,
284
+ eb -> start , eb -> len );
283
285
284
- if (btrfs_buffer_uptodate (eb , gen , 0 )) {
286
+ if (! ret && btrfs_buffer_uptodate (eb , gen , 0 )) {
285
287
if (wc -> write )
286
288
btrfs_write_tree_block (eb );
287
289
if (wc -> wait )
288
290
btrfs_wait_tree_block_writeback (eb );
289
291
}
290
- return 0 ;
292
+ return ret ;
291
293
}
292
294
293
295
/*
@@ -623,7 +625,8 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
623
625
ins .objectid , ins .offset ,
624
626
0 , root -> root_key .objectid ,
625
627
key -> objectid , offset , 0 );
626
- BUG_ON (ret );
628
+ if (ret )
629
+ goto out ;
627
630
} else {
628
631
/*
629
632
* insert the extent pointer in the extent
@@ -632,7 +635,8 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
632
635
ret = btrfs_alloc_logged_file_extent (trans ,
633
636
root , root -> root_key .objectid ,
634
637
key -> objectid , offset , & ins );
635
- BUG_ON (ret );
638
+ if (ret )
639
+ goto out ;
636
640
}
637
641
btrfs_release_path (path );
638
642
@@ -1952,11 +1956,13 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
1952
1956
if (S_ISDIR (mode )) {
1953
1957
ret = replay_dir_deletes (wc -> trans ,
1954
1958
root , log , path , key .objectid , 0 );
1955
- BUG_ON (ret );
1959
+ if (ret )
1960
+ break ;
1956
1961
}
1957
1962
ret = overwrite_item (wc -> trans , root , path ,
1958
1963
eb , i , & key );
1959
- BUG_ON (ret );
1964
+ if (ret )
1965
+ break ;
1960
1966
1961
1967
/* for regular files, make sure corresponding
1962
1968
* orhpan item exist. extents past the new EOF
@@ -1965,12 +1971,14 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
1965
1971
if (S_ISREG (mode )) {
1966
1972
ret = insert_orphan_item (wc -> trans , root ,
1967
1973
key .objectid );
1968
- BUG_ON (ret );
1974
+ if (ret )
1975
+ break ;
1969
1976
}
1970
1977
1971
1978
ret = link_to_fixup_dir (wc -> trans , root ,
1972
1979
path , key .objectid );
1973
- BUG_ON (ret );
1980
+ if (ret )
1981
+ break ;
1974
1982
}
1975
1983
if (wc -> stage < LOG_WALK_REPLAY_ALL )
1976
1984
continue ;
@@ -1979,28 +1987,35 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
1979
1987
if (key .type == BTRFS_XATTR_ITEM_KEY ) {
1980
1988
ret = overwrite_item (wc -> trans , root , path ,
1981
1989
eb , i , & key );
1982
- BUG_ON (ret );
1990
+ if (ret )
1991
+ break ;
1983
1992
} else if (key .type == BTRFS_INODE_REF_KEY ) {
1984
1993
ret = add_inode_ref (wc -> trans , root , log , path ,
1985
1994
eb , i , & key );
1986
- BUG_ON (ret && ret != - ENOENT );
1995
+ if (ret && ret != - ENOENT )
1996
+ break ;
1997
+ ret = 0 ;
1987
1998
} else if (key .type == BTRFS_INODE_EXTREF_KEY ) {
1988
1999
ret = add_inode_ref (wc -> trans , root , log , path ,
1989
2000
eb , i , & key );
1990
- BUG_ON (ret && ret != - ENOENT );
2001
+ if (ret && ret != - ENOENT )
2002
+ break ;
2003
+ ret = 0 ;
1991
2004
} else if (key .type == BTRFS_EXTENT_DATA_KEY ) {
1992
2005
ret = replay_one_extent (wc -> trans , root , path ,
1993
2006
eb , i , & key );
1994
- BUG_ON (ret );
2007
+ if (ret )
2008
+ break ;
1995
2009
} else if (key .type == BTRFS_DIR_ITEM_KEY ||
1996
2010
key .type == BTRFS_DIR_INDEX_KEY ) {
1997
2011
ret = replay_one_dir_item (wc -> trans , root , path ,
1998
2012
eb , i , & key );
1999
- BUG_ON (ret );
2013
+ if (ret )
2014
+ break ;
2000
2015
}
2001
2016
}
2002
2017
btrfs_free_path (path );
2003
- return 0 ;
2018
+ return ret ;
2004
2019
}
2005
2020
2006
2021
static noinline int walk_down_log_tree (struct btrfs_trans_handle * trans ,
@@ -2045,8 +2060,10 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
2045
2060
2046
2061
if (* level == 1 ) {
2047
2062
ret = wc -> process_func (root , next , wc , ptr_gen );
2048
- if (ret )
2063
+ if (ret ) {
2064
+ free_extent_buffer (next );
2049
2065
return ret ;
2066
+ }
2050
2067
2051
2068
path -> slots [* level ]++ ;
2052
2069
if (wc -> free ) {
@@ -3970,6 +3987,9 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)
3970
3987
wc .replay_dest = btrfs_read_fs_root_no_name (fs_info , & tmp_key );
3971
3988
if (IS_ERR (wc .replay_dest )) {
3972
3989
ret = PTR_ERR (wc .replay_dest );
3990
+ free_extent_buffer (log -> node );
3991
+ free_extent_buffer (log -> commit_root );
3992
+ kfree (log );
3973
3993
btrfs_error (fs_info , ret , "Couldn't read target root "
3974
3994
"for tree log recovery." );
3975
3995
goto error ;
@@ -3978,12 +3998,10 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)
3978
3998
wc .replay_dest -> log_root = log ;
3979
3999
btrfs_record_root_in_trans (trans , wc .replay_dest );
3980
4000
ret = walk_log_tree (trans , log , & wc );
3981
- BUG_ON (ret );
3982
4001
3983
- if (wc .stage == LOG_WALK_REPLAY_ALL ) {
4002
+ if (! ret && wc .stage == LOG_WALK_REPLAY_ALL ) {
3984
4003
ret = fixup_inode_link_counts (trans , wc .replay_dest ,
3985
4004
path );
3986
- BUG_ON (ret );
3987
4005
}
3988
4006
3989
4007
key .offset = found_key .offset - 1 ;
@@ -3992,6 +4010,9 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)
3992
4010
free_extent_buffer (log -> commit_root );
3993
4011
kfree (log );
3994
4012
4013
+ if (ret )
4014
+ goto error ;
4015
+
3995
4016
if (found_key .offset == 0 )
3996
4017
break ;
3997
4018
}
@@ -4024,6 +4045,8 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)
4024
4045
4025
4046
return 0 ;
4026
4047
error :
4048
+ if (wc .trans )
4049
+ btrfs_end_transaction (wc .trans , fs_info -> tree_root );
4027
4050
btrfs_free_path (path );
4028
4051
return ret ;
4029
4052
}
0 commit comments