@@ -1980,92 +1980,78 @@ static int __free_extent(struct btrfs_trans_handle *trans,
19801980 bytenr , num_bytes , parent ,
19811981 root_objectid , owner_objectid ,
19821982 owner_offset );
1983- if (ret == 0 ) {
1984- extent_slot = path -> slots [0 ];
1985- while (extent_slot >= 0 ) {
1986- btrfs_item_key_to_cpu (path -> nodes [0 ], & key ,
1987- extent_slot );
1988- if (key .objectid != bytenr )
1989- break ;
1990- if (key .type == BTRFS_EXTENT_ITEM_KEY &&
1991- key .offset == num_bytes ) {
1992- found_extent = 1 ;
1993- break ;
1994- }
1995- if (key .type == BTRFS_METADATA_ITEM_KEY &&
1996- key .offset == owner_objectid ) {
1997- found_extent = 1 ;
1998- break ;
1999- }
2000- if (path -> slots [0 ] - extent_slot > 5 )
2001- break ;
2002- extent_slot -- ;
1983+ if (ret ) {
1984+ error ("unable to find ref byte nr %llu parent %llu root %llu owner %llu offset %llu ret %d" ,
1985+ bytenr , parent , root_objectid , owner_objectid , owner_offset , ret );
1986+ if (path -> nodes [0 ]) {
1987+ printf ("path->slots[0]: %d path->nodes[0]:\n" , path -> slots [0 ]);
1988+ btrfs_print_leaf (path -> nodes [0 ]);
20031989 }
2004- if (!found_extent ) {
2005- BUG_ON (iref );
2006- ret = remove_extent_backref (trans , extent_root , path ,
2007- NULL , refs_to_drop ,
2008- is_data );
2009- BUG_ON (ret );
2010- btrfs_release_path (path );
1990+ ret = - EIO ;
1991+ goto fail ;
1992+ }
1993+ extent_slot = path -> slots [0 ];
1994+ while (extent_slot >= 0 ) {
1995+ btrfs_item_key_to_cpu (path -> nodes [0 ], & key , extent_slot );
1996+ if (key .objectid != bytenr )
1997+ break ;
1998+ if (key .type == BTRFS_EXTENT_ITEM_KEY && key .offset == num_bytes ) {
1999+ found_extent = 1 ;
2000+ break ;
2001+ }
2002+ if (key .type == BTRFS_METADATA_ITEM_KEY && key .offset == owner_objectid ) {
2003+ found_extent = 1 ;
2004+ break ;
2005+ }
2006+ if (path -> slots [0 ] - extent_slot > 5 )
2007+ break ;
2008+ extent_slot -- ;
2009+ }
2010+ if (!found_extent ) {
2011+ BUG_ON (iref );
2012+ ret = remove_extent_backref (trans , extent_root , path , NULL ,
2013+ refs_to_drop , is_data );
2014+ BUG_ON (ret );
2015+ btrfs_release_path (path );
20112016
2012- key .objectid = bytenr ;
2017+ key .objectid = bytenr ;
20132018
2014- if (skinny_metadata ) {
2015- key .type = BTRFS_METADATA_ITEM_KEY ;
2016- key .offset = owner_objectid ;
2017- } else {
2018- key .type = BTRFS_EXTENT_ITEM_KEY ;
2019- key .offset = num_bytes ;
2020- }
2019+ if (skinny_metadata ) {
2020+ key .type = BTRFS_METADATA_ITEM_KEY ;
2021+ key .offset = owner_objectid ;
2022+ } else {
2023+ key .type = BTRFS_EXTENT_ITEM_KEY ;
2024+ key .offset = num_bytes ;
2025+ }
2026+
2027+ ret = btrfs_search_slot (trans , extent_root , & key , path , -1 , 1 );
2028+ if (ret > 0 && skinny_metadata && path -> slots [0 ]) {
2029+ path -> slots [0 ]-- ;
2030+ btrfs_item_key_to_cpu (path -> nodes [0 ], & key , path -> slots [0 ]);
2031+ if (key .objectid == bytenr &&
2032+ key .type == BTRFS_EXTENT_ITEM_KEY &&
2033+ key .offset == num_bytes )
2034+ ret = 0 ;
2035+ }
20212036
2037+ if (ret > 0 && skinny_metadata ) {
2038+ skinny_metadata = 0 ;
2039+ btrfs_release_path (path );
2040+ key .type = BTRFS_EXTENT_ITEM_KEY ;
2041+ key .offset = num_bytes ;
20222042 ret = btrfs_search_slot (trans , extent_root ,
20232043 & key , path , -1 , 1 );
2024- if (ret > 0 && skinny_metadata && path -> slots [0 ]) {
2025- path -> slots [0 ]-- ;
2026- btrfs_item_key_to_cpu (path -> nodes [0 ],
2027- & key ,
2028- path -> slots [0 ]);
2029- if (key .objectid == bytenr &&
2030- key .type == BTRFS_EXTENT_ITEM_KEY &&
2031- key .offset == num_bytes )
2032- ret = 0 ;
2033- }
2034-
2035- if (ret > 0 && skinny_metadata ) {
2036- skinny_metadata = 0 ;
2037- btrfs_release_path (path );
2038- key .type = BTRFS_EXTENT_ITEM_KEY ;
2039- key .offset = num_bytes ;
2040- ret = btrfs_search_slot (trans , extent_root ,
2041- & key , path , -1 , 1 );
2042- }
2043-
2044- if (ret ) {
2045- printk (KERN_ERR "umm, got %d back from search"
2046- ", was looking for %llu\n" , ret ,
2047- (unsigned long long )bytenr );
2048- btrfs_print_leaf (path -> nodes [0 ]);
2049- }
2050- BUG_ON (ret );
2051- extent_slot = path -> slots [0 ];
20522044 }
2053- } else {
2054- printk (KERN_ERR "btrfs unable to find ref byte nr %llu "
2055- "parent %llu root %llu owner %llu offset %llu\n" ,
2056- (unsigned long long )bytenr ,
2057- (unsigned long long )parent ,
2058- (unsigned long long )root_objectid ,
2059- (unsigned long long )owner_objectid ,
2060- (unsigned long long )owner_offset );
2061- if (path -> nodes [0 ]) {
2062- printf ("path->slots[0]: %d path->nodes[0]:\n" , path -> slots [0 ]);
2045+
2046+ if (ret ) {
2047+ printk (KERN_ERR "umm, got %d back from search"
2048+ ", was looking for %llu\n" , ret ,
2049+ (unsigned long long )bytenr );
20632050 btrfs_print_leaf (path -> nodes [0 ]);
20642051 }
2065- ret = - EIO ;
2066- goto fail ;
2052+ BUG_ON ( ret ) ;
2053+ extent_slot = path -> slots [ 0 ] ;
20672054 }
2068-
20692055 leaf = path -> nodes [0 ];
20702056 item_size = btrfs_item_size (leaf , extent_slot );
20712057 if (item_size < sizeof (* ei )) {
0 commit comments