aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@fusionio.com>2012-12-03 10:31:19 -0500
committerChris Mason <chris.mason@fusionio.com>2012-12-16 20:46:23 -0500
commitb493968096944a11422c4d80fb87af537ca1cac7 (patch)
treee1ab00ec2a527615c2f17c2665e6597fc3b81c7d /fs/btrfs/inode.c
parentb812ce28796f746f14ba6cc451250c422db447b2 (diff)
Btrfs: keep track of the extents original block length
If we've written to a prealloc extent we need to know the original block len for the extent. We can't figure this out currently since ->block_len is just set to the extent length. So introduce ->orig_block_len so that we know how many bytes were in the original extent for proper extent logging that future patches will need. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 7855aac36706..bfd59bcc50d7 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -699,6 +699,7 @@ retry:
699 699
700 em->block_start = ins.objectid; 700 em->block_start = ins.objectid;
701 em->block_len = ins.offset; 701 em->block_len = ins.offset;
702 em->orig_block_len = ins.offset;
702 em->bdev = root->fs_info->fs_devices->latest_bdev; 703 em->bdev = root->fs_info->fs_devices->latest_bdev;
703 em->compress_type = async_extent->compress_type; 704 em->compress_type = async_extent->compress_type;
704 set_bit(EXTENT_FLAG_PINNED, &em->flags); 705 set_bit(EXTENT_FLAG_PINNED, &em->flags);
@@ -886,6 +887,7 @@ static noinline int __cow_file_range(struct btrfs_trans_handle *trans,
886 887
887 em->block_start = ins.objectid; 888 em->block_start = ins.objectid;
888 em->block_len = ins.offset; 889 em->block_len = ins.offset;
890 em->orig_block_len = ins.offset;
889 em->bdev = root->fs_info->fs_devices->latest_bdev; 891 em->bdev = root->fs_info->fs_devices->latest_bdev;
890 set_bit(EXTENT_FLAG_PINNED, &em->flags); 892 set_bit(EXTENT_FLAG_PINNED, &em->flags);
891 893
@@ -1143,6 +1145,7 @@ static noinline int run_delalloc_nocow(struct inode *inode,
1143 u64 extent_offset; 1145 u64 extent_offset;
1144 u64 disk_bytenr; 1146 u64 disk_bytenr;
1145 u64 num_bytes; 1147 u64 num_bytes;
1148 u64 disk_num_bytes;
1146 int extent_type; 1149 int extent_type;
1147 int ret, err; 1150 int ret, err;
1148 int type; 1151 int type;
@@ -1245,6 +1248,8 @@ next_slot:
1245 extent_offset = btrfs_file_extent_offset(leaf, fi); 1248 extent_offset = btrfs_file_extent_offset(leaf, fi);
1246 extent_end = found_key.offset + 1249 extent_end = found_key.offset +
1247 btrfs_file_extent_num_bytes(leaf, fi); 1250 btrfs_file_extent_num_bytes(leaf, fi);
1251 disk_num_bytes =
1252 btrfs_file_extent_disk_num_bytes(leaf, fi);
1248 if (extent_end <= start) { 1253 if (extent_end <= start) {
1249 path->slots[0]++; 1254 path->slots[0]++;
1250 goto next_slot; 1255 goto next_slot;
@@ -1319,6 +1324,7 @@ out_check:
1319 em->len = num_bytes; 1324 em->len = num_bytes;
1320 em->block_len = num_bytes; 1325 em->block_len = num_bytes;
1321 em->block_start = disk_bytenr; 1326 em->block_start = disk_bytenr;
1327 em->orig_block_len = disk_num_bytes;
1322 em->bdev = root->fs_info->fs_devices->latest_bdev; 1328 em->bdev = root->fs_info->fs_devices->latest_bdev;
1323 set_bit(EXTENT_FLAG_PINNED, &em->flags); 1329 set_bit(EXTENT_FLAG_PINNED, &em->flags);
1324 set_bit(EXTENT_FLAG_PREALLOC, &em->flags); 1330 set_bit(EXTENT_FLAG_PREALLOC, &em->flags);
@@ -3696,6 +3702,7 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size)
3696 3702
3697 hole_em->block_start = EXTENT_MAP_HOLE; 3703 hole_em->block_start = EXTENT_MAP_HOLE;
3698 hole_em->block_len = 0; 3704 hole_em->block_len = 0;
3705 hole_em->orig_block_len = 0;
3699 hole_em->bdev = root->fs_info->fs_devices->latest_bdev; 3706 hole_em->bdev = root->fs_info->fs_devices->latest_bdev;
3700 hole_em->compress_type = BTRFS_COMPRESS_NONE; 3707 hole_em->compress_type = BTRFS_COMPRESS_NONE;
3701 hole_em->generation = trans->transid; 3708 hole_em->generation = trans->transid;
@@ -5374,6 +5381,8 @@ again:
5374 em->len = extent_end - extent_start; 5381 em->len = extent_end - extent_start;
5375 em->orig_start = extent_start - 5382 em->orig_start = extent_start -
5376 btrfs_file_extent_offset(leaf, item); 5383 btrfs_file_extent_offset(leaf, item);
5384 em->orig_block_len = btrfs_file_extent_disk_num_bytes(leaf,
5385 item);
5377 bytenr = btrfs_file_extent_disk_bytenr(leaf, item); 5386 bytenr = btrfs_file_extent_disk_bytenr(leaf, item);
5378 if (bytenr == 0) { 5387 if (bytenr == 0) {
5379 em->block_start = EXTENT_MAP_HOLE; 5388 em->block_start = EXTENT_MAP_HOLE;
@@ -5383,8 +5392,7 @@ again:
5383 set_bit(EXTENT_FLAG_COMPRESSED, &em->flags); 5392 set_bit(EXTENT_FLAG_COMPRESSED, &em->flags);
5384 em->compress_type = compress_type; 5393 em->compress_type = compress_type;
5385 em->block_start = bytenr; 5394 em->block_start = bytenr;
5386 em->block_len = btrfs_file_extent_disk_num_bytes(leaf, 5395 em->block_len = em->orig_block_len;
5387 item);
5388 } else { 5396 } else {
5389 bytenr += btrfs_file_extent_offset(leaf, item); 5397 bytenr += btrfs_file_extent_offset(leaf, item);
5390 em->block_start = bytenr; 5398 em->block_start = bytenr;
@@ -5414,6 +5422,7 @@ again:
5414 em->start = extent_start + extent_offset; 5422 em->start = extent_start + extent_offset;
5415 em->len = (copy_size + root->sectorsize - 1) & 5423 em->len = (copy_size + root->sectorsize - 1) &
5416 ~((u64)root->sectorsize - 1); 5424 ~((u64)root->sectorsize - 1);
5425 em->orig_block_len = em->len;
5417 em->orig_start = EXTENT_MAP_INLINE; 5426 em->orig_start = EXTENT_MAP_INLINE;
5418 if (compress_type) { 5427 if (compress_type) {
5419 set_bit(EXTENT_FLAG_COMPRESSED, &em->flags); 5428 set_bit(EXTENT_FLAG_COMPRESSED, &em->flags);
@@ -5721,6 +5730,7 @@ static struct extent_map *btrfs_new_extent_direct(struct inode *inode,
5721 5730
5722 em->block_start = ins.objectid; 5731 em->block_start = ins.objectid;
5723 em->block_len = ins.offset; 5732 em->block_len = ins.offset;
5733 em->orig_block_len = ins.offset;
5724 em->bdev = root->fs_info->fs_devices->latest_bdev; 5734 em->bdev = root->fs_info->fs_devices->latest_bdev;
5725 5735
5726 /* 5736 /*
@@ -5914,7 +5924,7 @@ static int lock_extent_direct(struct inode *inode, u64 lockstart, u64 lockend,
5914static struct extent_map *create_pinned_em(struct inode *inode, u64 start, 5924static struct extent_map *create_pinned_em(struct inode *inode, u64 start,
5915 u64 len, u64 orig_start, 5925 u64 len, u64 orig_start,
5916 u64 block_start, u64 block_len, 5926 u64 block_start, u64 block_len,
5917 int type) 5927 u64 orig_block_len, int type)
5918{ 5928{
5919 struct extent_map_tree *em_tree; 5929 struct extent_map_tree *em_tree;
5920 struct extent_map *em; 5930 struct extent_map *em;
@@ -5932,6 +5942,7 @@ static struct extent_map *create_pinned_em(struct inode *inode, u64 start,
5932 em->block_len = block_len; 5942 em->block_len = block_len;
5933 em->block_start = block_start; 5943 em->block_start = block_start;
5934 em->bdev = root->fs_info->fs_devices->latest_bdev; 5944 em->bdev = root->fs_info->fs_devices->latest_bdev;
5945 em->orig_block_len = orig_block_len;
5935 set_bit(EXTENT_FLAG_PINNED, &em->flags); 5946 set_bit(EXTENT_FLAG_PINNED, &em->flags);
5936 if (type == BTRFS_ORDERED_PREALLOC) 5947 if (type == BTRFS_ORDERED_PREALLOC)
5937 set_bit(EXTENT_FLAG_PREALLOC, &em->flags); 5948 set_bit(EXTENT_FLAG_PREALLOC, &em->flags);
@@ -6068,12 +6079,14 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock,
6068 6079
6069 if (can_nocow_odirect(trans, inode, start, len) == 1) { 6080 if (can_nocow_odirect(trans, inode, start, len) == 1) {
6070 u64 orig_start = em->start; 6081 u64 orig_start = em->start;
6082 u64 orig_block_len = em->orig_block_len;
6071 6083
6072 if (type == BTRFS_ORDERED_PREALLOC) { 6084 if (type == BTRFS_ORDERED_PREALLOC) {
6073 free_extent_map(em); 6085 free_extent_map(em);
6074 em = create_pinned_em(inode, start, len, 6086 em = create_pinned_em(inode, start, len,
6075 orig_start, 6087 orig_start,
6076 block_start, len, type); 6088 block_start, len,
6089 orig_block_len, type);
6077 if (IS_ERR(em)) { 6090 if (IS_ERR(em)) {
6078 btrfs_end_transaction(trans, root); 6091 btrfs_end_transaction(trans, root);
6079 goto unlock_err; 6092 goto unlock_err;
@@ -7771,6 +7784,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
7771 em->len = ins.offset; 7784 em->len = ins.offset;
7772 em->block_start = ins.objectid; 7785 em->block_start = ins.objectid;
7773 em->block_len = ins.offset; 7786 em->block_len = ins.offset;
7787 em->orig_block_len = ins.offset;
7774 em->bdev = root->fs_info->fs_devices->latest_bdev; 7788 em->bdev = root->fs_info->fs_devices->latest_bdev;
7775 set_bit(EXTENT_FLAG_PREALLOC, &em->flags); 7789 set_bit(EXTENT_FLAG_PREALLOC, &em->flags);
7776 em->generation = trans->transid; 7790 em->generation = trans->transid;