aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/file.c
diff options
context:
space:
mode:
authorYan <yanzheng@21cn.com>2007-10-25 15:42:57 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:03:57 -0400
commit18f16f7ba62a01c29e09b40ac6ad6d92a8955859 (patch)
tree9bb9ce1955d4dd880643a32d144448972bd37cbd /fs/btrfs/file.c
parentcc0c55384796b422133ff1f21646835b31590f88 (diff)
Btrfs: Fix for insert_inline_extent to handle offset != 0
This modifies inline extent size calculation, so that insert_inline_extent can handle the case that parameter 'offset' is not zero; it also a few codes to zero uninitialized area in inline extent. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r--fs/btrfs/file.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 96df1b10cb60..9260d3478aad 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -108,7 +108,6 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans,
108 key.objectid = inode->i_ino; 108 key.objectid = inode->i_ino;
109 key.offset = offset; 109 key.offset = offset;
110 btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY); 110 btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY);
111 datasize = btrfs_file_extent_calc_inline_size(offset + size);
112 111
113 ret = btrfs_search_slot(trans, root, &key, path, 0, 1); 112 ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
114 if (ret < 0) { 113 if (ret < 0) {
@@ -130,7 +129,7 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans,
130 } 129 }
131 if (ret == 0) { 130 if (ret == 0) {
132 u32 found_size; 131 u32 found_size;
133 u64 found_start; 132 u64 found_end;
134 133
135 leaf = path->nodes[0]; 134 leaf = path->nodes[0];
136 ei = btrfs_item_ptr(leaf, path->slots[0], 135 ei = btrfs_item_ptr(leaf, path->slots[0],
@@ -144,19 +143,17 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans,
144 offset, inode->i_ino); 143 offset, inode->i_ino);
145 goto fail; 144 goto fail;
146 } 145 }
147 found_start = key.offset;
148 found_size = btrfs_file_extent_inline_len(leaf, 146 found_size = btrfs_file_extent_inline_len(leaf,
149 btrfs_item_nr(leaf, path->slots[0])); 147 btrfs_item_nr(leaf, path->slots[0]));
148 found_end = key.offset + found_size;
150 149
151 if (found_size < offset + size) { 150 if (found_end < offset + size) {
152 btrfs_release_path(root, path); 151 btrfs_release_path(root, path);
153 ret = btrfs_search_slot(trans, root, &key, path, 152 ret = btrfs_search_slot(trans, root, &key, path,
154 offset + size - found_size - 153 offset + size - found_end, 1);
155 found_start, 1);
156 BUG_ON(ret != 0); 154 BUG_ON(ret != 0);
157 ret = btrfs_extend_item(trans, root, path, 155 ret = btrfs_extend_item(trans, root, path,
158 offset + size - found_size - 156 offset + size - found_end);
159 found_start);
160 if (ret) { 157 if (ret) {
161 err = ret; 158 err = ret;
162 goto fail; 159 goto fail;
@@ -165,9 +162,15 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans,
165 ei = btrfs_item_ptr(leaf, path->slots[0], 162 ei = btrfs_item_ptr(leaf, path->slots[0],
166 struct btrfs_file_extent_item); 163 struct btrfs_file_extent_item);
167 } 164 }
165 if (found_end < offset) {
166 ptr = btrfs_file_extent_inline_start(ei) + found_size;
167 memset_extent_buffer(leaf, 0, ptr, offset - found_end);
168 }
168 } else { 169 } else {
169insert: 170insert:
170 btrfs_release_path(root, path); 171 btrfs_release_path(root, path);
172 datasize = offset + size - key.offset;
173 datasize = btrfs_file_extent_calc_inline_size(datasize);
171 ret = btrfs_insert_empty_item(trans, root, path, &key, 174 ret = btrfs_insert_empty_item(trans, root, path, &key,
172 datasize); 175 datasize);
173 if (ret) { 176 if (ret) {
@@ -181,7 +184,7 @@ insert:
181 btrfs_set_file_extent_generation(leaf, ei, trans->transid); 184 btrfs_set_file_extent_generation(leaf, ei, trans->transid);
182 btrfs_set_file_extent_type(leaf, ei, BTRFS_FILE_EXTENT_INLINE); 185 btrfs_set_file_extent_type(leaf, ei, BTRFS_FILE_EXTENT_INLINE);
183 } 186 }
184 ptr = btrfs_file_extent_inline_start(ei) + offset; 187 ptr = btrfs_file_extent_inline_start(ei) + offset - key.offset;
185 188
186 cur_size = size; 189 cur_size = size;
187 i = 0; 190 i = 0;