Btrfs: fix wrong file extent length
There are two types of the file extent - inline extent and regular extent, When we log file extents, we didn't take inline extent into account, fix it. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Reviewed-by: Liu Bo <bo.li.liu@oracle.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
This commit is contained in:
parent
ca46963718
commit
315a9850da
|
@ -3263,6 +3263,7 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
|
||||||
struct btrfs_root *root,
|
struct btrfs_root *root,
|
||||||
struct btrfs_path *path, u64 objectid,
|
struct btrfs_path *path, u64 objectid,
|
||||||
u64 bytenr, int mod);
|
u64 bytenr, int mod);
|
||||||
|
u64 btrfs_file_extent_length(struct btrfs_path *path);
|
||||||
int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
|
int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
|
||||||
struct btrfs_root *root,
|
struct btrfs_root *root,
|
||||||
struct btrfs_ordered_sum *sums);
|
struct btrfs_ordered_sum *sums);
|
||||||
|
|
|
@ -133,7 +133,6 @@ fail:
|
||||||
return ERR_PTR(ret);
|
return ERR_PTR(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
|
int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
|
||||||
struct btrfs_root *root,
|
struct btrfs_root *root,
|
||||||
struct btrfs_path *path, u64 objectid,
|
struct btrfs_path *path, u64 objectid,
|
||||||
|
@ -151,6 +150,26 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 btrfs_file_extent_length(struct btrfs_path *path)
|
||||||
|
{
|
||||||
|
int extent_type;
|
||||||
|
struct btrfs_file_extent_item *fi;
|
||||||
|
u64 len;
|
||||||
|
|
||||||
|
fi = btrfs_item_ptr(path->nodes[0], path->slots[0],
|
||||||
|
struct btrfs_file_extent_item);
|
||||||
|
extent_type = btrfs_file_extent_type(path->nodes[0], fi);
|
||||||
|
|
||||||
|
if (extent_type == BTRFS_FILE_EXTENT_REG ||
|
||||||
|
extent_type == BTRFS_FILE_EXTENT_PREALLOC)
|
||||||
|
len = btrfs_file_extent_num_bytes(path->nodes[0], fi);
|
||||||
|
else if (extent_type == BTRFS_FILE_EXTENT_INLINE)
|
||||||
|
len = btrfs_file_extent_inline_len(path->nodes[0], fi);
|
||||||
|
else
|
||||||
|
BUG();
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
|
static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
|
||||||
struct inode *inode, struct bio *bio,
|
struct inode *inode, struct bio *bio,
|
||||||
|
|
|
@ -3143,7 +3143,6 @@ static int log_one_extent(struct btrfs_trans_handle *trans,
|
||||||
struct btrfs_path *dst_path, struct log_args *args)
|
struct btrfs_path *dst_path, struct log_args *args)
|
||||||
{
|
{
|
||||||
struct btrfs_root *log = root->log_root;
|
struct btrfs_root *log = root->log_root;
|
||||||
struct btrfs_file_extent_item *fi;
|
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
u64 start = em->mod_start;
|
u64 start = em->mod_start;
|
||||||
u64 search_start = start;
|
u64 search_start = start;
|
||||||
|
@ -3199,10 +3198,7 @@ again:
|
||||||
}
|
}
|
||||||
} while (key.offset > start);
|
} while (key.offset > start);
|
||||||
|
|
||||||
fi = btrfs_item_ptr(path->nodes[0], path->slots[0],
|
num_bytes = btrfs_file_extent_length(path);
|
||||||
struct btrfs_file_extent_item);
|
|
||||||
num_bytes = btrfs_file_extent_num_bytes(path->nodes[0],
|
|
||||||
fi);
|
|
||||||
if (key.offset + num_bytes <= start) {
|
if (key.offset + num_bytes <= start) {
|
||||||
btrfs_release_path(path);
|
btrfs_release_path(path);
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
@ -3211,8 +3207,7 @@ again:
|
||||||
args->src = path->nodes[0];
|
args->src = path->nodes[0];
|
||||||
next_slot:
|
next_slot:
|
||||||
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
|
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
|
||||||
fi = btrfs_item_ptr(args->src, path->slots[0],
|
num_bytes = btrfs_file_extent_length(path);
|
||||||
struct btrfs_file_extent_item);
|
|
||||||
if (args->nr &&
|
if (args->nr &&
|
||||||
args->start_slot + args->nr == path->slots[0]) {
|
args->start_slot + args->nr == path->slots[0]) {
|
||||||
args->nr++;
|
args->nr++;
|
||||||
|
@ -3230,7 +3225,6 @@ next_slot:
|
||||||
}
|
}
|
||||||
nritems = btrfs_header_nritems(path->nodes[0]);
|
nritems = btrfs_header_nritems(path->nodes[0]);
|
||||||
path->slots[0]++;
|
path->slots[0]++;
|
||||||
num_bytes = btrfs_file_extent_num_bytes(args->src, fi);
|
|
||||||
if (len < num_bytes) {
|
if (len < num_bytes) {
|
||||||
/* I _think_ this is ok, envision we write to a
|
/* I _think_ this is ok, envision we write to a
|
||||||
* preallocated space that is adjacent to a previously
|
* preallocated space that is adjacent to a previously
|
||||||
|
|
Loading…
Reference in New Issue