aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/ctree.h1
-rw-r--r--fs/btrfs/file-item.c21
-rw-r--r--fs/btrfs/tree-log.c10
3 files changed, 23 insertions, 9 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 2d41cb25266b..f9a078661ebc 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3263,6 +3263,7 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
3263 struct btrfs_root *root, 3263 struct btrfs_root *root,
3264 struct btrfs_path *path, u64 objectid, 3264 struct btrfs_path *path, u64 objectid,
3265 u64 bytenr, int mod); 3265 u64 bytenr, int mod);
3266u64 btrfs_file_extent_length(struct btrfs_path *path);
3266int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, 3267int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
3267 struct btrfs_root *root, 3268 struct btrfs_root *root,
3268 struct btrfs_ordered_sum *sums); 3269 struct btrfs_ordered_sum *sums);
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 1ad08e4e4a15..bd38cef42358 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -133,7 +133,6 @@ fail:
133 return ERR_PTR(ret); 133 return ERR_PTR(ret);
134} 134}
135 135
136
137int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, 136int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
138 struct btrfs_root *root, 137 struct btrfs_root *root,
139 struct btrfs_path *path, u64 objectid, 138 struct btrfs_path *path, u64 objectid,
@@ -151,6 +150,26 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
151 return ret; 150 return ret;
152} 151}
153 152
153u64 btrfs_file_extent_length(struct btrfs_path *path)
154{
155 int extent_type;
156 struct btrfs_file_extent_item *fi;
157 u64 len;
158
159 fi = btrfs_item_ptr(path->nodes[0], path->slots[0],
160 struct btrfs_file_extent_item);
161 extent_type = btrfs_file_extent_type(path->nodes[0], fi);
162
163 if (extent_type == BTRFS_FILE_EXTENT_REG ||
164 extent_type == BTRFS_FILE_EXTENT_PREALLOC)
165 len = btrfs_file_extent_num_bytes(path->nodes[0], fi);
166 else if (extent_type == BTRFS_FILE_EXTENT_INLINE)
167 len = btrfs_file_extent_inline_len(path->nodes[0], fi);
168 else
169 BUG();
170
171 return len;
172}
154 173
155static int __btrfs_lookup_bio_sums(struct btrfs_root *root, 174static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
156 struct inode *inode, struct bio *bio, 175 struct inode *inode, struct bio *bio,
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 4ec41ecb4d65..bcf0e48b1932 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -3143,7 +3143,6 @@ static int log_one_extent(struct btrfs_trans_handle *trans,
3143 struct btrfs_path *dst_path, struct log_args *args) 3143 struct btrfs_path *dst_path, struct log_args *args)
3144{ 3144{
3145 struct btrfs_root *log = root->log_root; 3145 struct btrfs_root *log = root->log_root;
3146 struct btrfs_file_extent_item *fi;
3147 struct btrfs_key key; 3146 struct btrfs_key key;
3148 u64 start = em->mod_start; 3147 u64 start = em->mod_start;
3149 u64 search_start = start; 3148 u64 search_start = start;
@@ -3199,10 +3198,7 @@ again:
3199 } 3198 }
3200 } while (key.offset > start); 3199 } while (key.offset > start);
3201 3200
3202 fi = btrfs_item_ptr(path->nodes[0], path->slots[0], 3201 num_bytes = btrfs_file_extent_length(path);
3203 struct btrfs_file_extent_item);
3204 num_bytes = btrfs_file_extent_num_bytes(path->nodes[0],
3205 fi);
3206 if (key.offset + num_bytes <= start) { 3202 if (key.offset + num_bytes <= start) {
3207 btrfs_release_path(path); 3203 btrfs_release_path(path);
3208 return -ENOENT; 3204 return -ENOENT;
@@ -3211,8 +3207,7 @@ again:
3211 args->src = path->nodes[0]; 3207 args->src = path->nodes[0];
3212next_slot: 3208next_slot:
3213 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); 3209 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
3214 fi = btrfs_item_ptr(args->src, path->slots[0], 3210 num_bytes = btrfs_file_extent_length(path);
3215 struct btrfs_file_extent_item);
3216 if (args->nr && 3211 if (args->nr &&
3217 args->start_slot + args->nr == path->slots[0]) { 3212 args->start_slot + args->nr == path->slots[0]) {
3218 args->nr++; 3213 args->nr++;
@@ -3230,7 +3225,6 @@ next_slot:
3230 } 3225 }
3231 nritems = btrfs_header_nritems(path->nodes[0]); 3226 nritems = btrfs_header_nritems(path->nodes[0]);
3232 path->slots[0]++; 3227 path->slots[0]++;
3233 num_bytes = btrfs_file_extent_num_bytes(args->src, fi);
3234 if (len < num_bytes) { 3228 if (len < num_bytes) {
3235 /* I _think_ this is ok, envision we write to a 3229 /* I _think_ this is ok, envision we write to a
3236 * preallocated space that is adjacent to a previously 3230 * preallocated space that is adjacent to a previously