96
96
static int btrfs_log_inode (struct btrfs_trans_handle * trans ,
97
97
struct btrfs_root * root , struct btrfs_inode * inode ,
98
98
int inode_only ,
99
- u64 start ,
100
- u64 end ,
99
+ const loff_t start ,
100
+ const loff_t end ,
101
101
struct btrfs_log_ctx * ctx );
102
102
static int link_to_fixup_dir (struct btrfs_trans_handle * trans ,
103
103
struct btrfs_root * root ,
@@ -4533,37 +4533,28 @@ static int btrfs_log_all_xattrs(struct btrfs_trans_handle *trans,
4533
4533
static int btrfs_log_holes (struct btrfs_trans_handle * trans ,
4534
4534
struct btrfs_root * root ,
4535
4535
struct btrfs_inode * inode ,
4536
- struct btrfs_path * path ,
4537
- const u64 start ,
4538
- const u64 end )
4536
+ struct btrfs_path * path )
4539
4537
{
4540
4538
struct btrfs_fs_info * fs_info = root -> fs_info ;
4541
4539
struct btrfs_key key ;
4542
4540
const u64 ino = btrfs_ino (inode );
4543
4541
const u64 i_size = i_size_read (& inode -> vfs_inode );
4544
- u64 prev_extent_end = start ;
4542
+ u64 prev_extent_end = 0 ;
4545
4543
int ret ;
4546
4544
4547
4545
if (!btrfs_fs_incompat (fs_info , NO_HOLES ) || i_size == 0 )
4548
4546
return 0 ;
4549
4547
4550
4548
key .objectid = ino ;
4551
4549
key .type = BTRFS_EXTENT_DATA_KEY ;
4552
- key .offset = start ;
4550
+ key .offset = 0 ;
4553
4551
4554
4552
ret = btrfs_search_slot (NULL , root , & key , path , 0 , 0 );
4555
4553
if (ret < 0 )
4556
4554
return ret ;
4557
4555
4558
- if (ret > 0 && path -> slots [0 ] > 0 ) {
4559
- btrfs_item_key_to_cpu (path -> nodes [0 ], & key , path -> slots [0 ] - 1 );
4560
- if (key .objectid == ino && key .type == BTRFS_EXTENT_DATA_KEY )
4561
- path -> slots [0 ]-- ;
4562
- }
4563
-
4564
4556
while (true) {
4565
4557
struct extent_buffer * leaf = path -> nodes [0 ];
4566
- u64 extent_end ;
4567
4558
4568
4559
if (path -> slots [0 ] >= btrfs_header_nritems (path -> nodes [0 ])) {
4569
4560
ret = btrfs_next_leaf (root , path );
@@ -4580,18 +4571,9 @@ static int btrfs_log_holes(struct btrfs_trans_handle *trans,
4580
4571
if (key .objectid != ino || key .type != BTRFS_EXTENT_DATA_KEY )
4581
4572
break ;
4582
4573
4583
- extent_end = btrfs_file_extent_end (path );
4584
- if (extent_end <= start )
4585
- goto next_slot ;
4586
-
4587
4574
/* We have a hole, log it. */
4588
4575
if (prev_extent_end < key .offset ) {
4589
- u64 hole_len ;
4590
-
4591
- if (key .offset >= end )
4592
- hole_len = end - prev_extent_end ;
4593
- else
4594
- hole_len = key .offset - prev_extent_end ;
4576
+ const u64 hole_len = key .offset - prev_extent_end ;
4595
4577
4596
4578
/*
4597
4579
* Release the path to avoid deadlocks with other code
@@ -4621,20 +4603,16 @@ static int btrfs_log_holes(struct btrfs_trans_handle *trans,
4621
4603
leaf = path -> nodes [0 ];
4622
4604
}
4623
4605
4624
- prev_extent_end = min (extent_end , end );
4625
- if (extent_end >= end )
4626
- break ;
4627
- next_slot :
4606
+ prev_extent_end = btrfs_file_extent_end (path );
4628
4607
path -> slots [0 ]++ ;
4629
4608
cond_resched ();
4630
4609
}
4631
4610
4632
- if (prev_extent_end < end && prev_extent_end < i_size ) {
4611
+ if (prev_extent_end < i_size ) {
4633
4612
u64 hole_len ;
4634
4613
4635
4614
btrfs_release_path (path );
4636
- hole_len = min (ALIGN (i_size , fs_info -> sectorsize ), end );
4637
- hole_len -= prev_extent_end ;
4615
+ hole_len = ALIGN (i_size - prev_extent_end , fs_info -> sectorsize );
4638
4616
ret = btrfs_insert_file_extent (trans , root -> log_root ,
4639
4617
ino , prev_extent_end , 0 , 0 ,
4640
4618
hole_len , 0 , hole_len ,
@@ -4971,8 +4949,6 @@ static int copy_inode_items_to_log(struct btrfs_trans_handle *trans,
4971
4949
const u64 logged_isize ,
4972
4950
const bool recursive_logging ,
4973
4951
const int inode_only ,
4974
- const u64 start ,
4975
- const u64 end ,
4976
4952
struct btrfs_log_ctx * ctx ,
4977
4953
bool * need_log_inode_item )
4978
4954
{
@@ -4981,21 +4957,6 @@ static int copy_inode_items_to_log(struct btrfs_trans_handle *trans,
4981
4957
int ins_nr = 0 ;
4982
4958
int ret ;
4983
4959
4984
- /*
4985
- * We must make sure we don't copy extent items that are entirely out of
4986
- * the range [start, end - 1]. This is not just an optimization to avoid
4987
- * copying but also needed to avoid a corruption where we end up with
4988
- * file extent items in the log tree that have overlapping ranges - this
4989
- * can happen if we race with ordered extent completion for ranges that
4990
- * are outside our target range. For example we copy an extent item and
4991
- * when we move to the next leaf, that extent was trimmed and a new one
4992
- * covering a subrange of it, but with a higher key, was inserted - we
4993
- * would then copy this other extent too, resulting in a log tree with
4994
- * 2 extent items that represent overlapping ranges.
4995
- *
4996
- * We can copy the entire extents at the range bondaries however, even
4997
- * if they cover an area outside the target range. That's ok.
4998
- */
4999
4960
while (1 ) {
5000
4961
ret = btrfs_search_forward (root , min_key , path , trans -> transid );
5001
4962
if (ret < 0 )
@@ -5063,29 +5024,6 @@ static int copy_inode_items_to_log(struct btrfs_trans_handle *trans,
5063
5024
goto next_slot ;
5064
5025
}
5065
5026
5066
- if (min_key -> type == BTRFS_EXTENT_DATA_KEY ) {
5067
- const u64 extent_end = btrfs_file_extent_end (path );
5068
-
5069
- if (extent_end <= start ) {
5070
- if (ins_nr > 0 ) {
5071
- ret = copy_items (trans , inode , dst_path ,
5072
- path , ins_start_slot ,
5073
- ins_nr , inode_only ,
5074
- logged_isize );
5075
- if (ret < 0 )
5076
- return ret ;
5077
- ins_nr = 0 ;
5078
- }
5079
- goto next_slot ;
5080
- }
5081
- if (extent_end >= end ) {
5082
- ins_nr ++ ;
5083
- if (ins_nr == 1 )
5084
- ins_start_slot = path -> slots [0 ];
5085
- break ;
5086
- }
5087
- }
5088
-
5089
5027
if (ins_nr && ins_start_slot + ins_nr == path -> slots [0 ]) {
5090
5028
ins_nr ++ ;
5091
5029
goto next_slot ;
@@ -5151,8 +5089,8 @@ static int copy_inode_items_to_log(struct btrfs_trans_handle *trans,
5151
5089
static int btrfs_log_inode (struct btrfs_trans_handle * trans ,
5152
5090
struct btrfs_root * root , struct btrfs_inode * inode ,
5153
5091
int inode_only ,
5154
- u64 start ,
5155
- u64 end ,
5092
+ const loff_t start ,
5093
+ const loff_t end ,
5156
5094
struct btrfs_log_ctx * ctx )
5157
5095
{
5158
5096
struct btrfs_fs_info * fs_info = root -> fs_info ;
@@ -5180,9 +5118,6 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
5180
5118
return - ENOMEM ;
5181
5119
}
5182
5120
5183
- start = ALIGN_DOWN (start , fs_info -> sectorsize );
5184
- end = ALIGN (end , fs_info -> sectorsize );
5185
-
5186
5121
min_key .objectid = ino ;
5187
5122
min_key .type = BTRFS_INODE_ITEM_KEY ;
5188
5123
min_key .offset = 0 ;
@@ -5298,8 +5233,8 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
5298
5233
5299
5234
err = copy_inode_items_to_log (trans , inode , & min_key , & max_key ,
5300
5235
path , dst_path , logged_isize ,
5301
- recursive_logging , inode_only ,
5302
- start , end , ctx , & need_log_inode_item );
5236
+ recursive_logging , inode_only , ctx ,
5237
+ & need_log_inode_item );
5303
5238
if (err )
5304
5239
goto out_unlock ;
5305
5240
@@ -5312,7 +5247,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
5312
5247
if (max_key .type >= BTRFS_EXTENT_DATA_KEY && !fast_search ) {
5313
5248
btrfs_release_path (path );
5314
5249
btrfs_release_path (dst_path );
5315
- err = btrfs_log_holes (trans , root , inode , path , start , end );
5250
+ err = btrfs_log_holes (trans , root , inode , path );
5316
5251
if (err )
5317
5252
goto out_unlock ;
5318
5253
}
0 commit comments