aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@fb.com>2016-09-02 15:40:06 -0400
committerDavid Sterba <dsterba@suse.com>2016-09-26 11:59:49 -0400
commit9c8e63db1de98c5cc3c6fb32d11b5cf55f228601 (patch)
tree8cd29cd632056a73ebc7bd4212662f6600e830b2
parent8436ea91a1c4fd8ed57ff0c0ca482ee3dbe744c7 (diff)
Btrfs: kill BUG_ON()'s in btrfs_mark_extent_written
No reason to bug on in here, fs corruption could easily cause these things to happen. Signed-off-by: Josef Bacik <jbacik@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/file.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index f1f1ae6ff08b..72a180d3503e 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1110,13 +1110,25 @@ again:
1110 1110
1111 leaf = path->nodes[0]; 1111 leaf = path->nodes[0];
1112 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); 1112 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
1113 BUG_ON(key.objectid != ino || key.type != BTRFS_EXTENT_DATA_KEY); 1113 if (key.objectid != ino ||
1114 key.type != BTRFS_EXTENT_DATA_KEY) {
1115 ret = -EINVAL;
1116 btrfs_abort_transaction(trans, ret);
1117 goto out;
1118 }
1114 fi = btrfs_item_ptr(leaf, path->slots[0], 1119 fi = btrfs_item_ptr(leaf, path->slots[0],
1115 struct btrfs_file_extent_item); 1120 struct btrfs_file_extent_item);
1116 BUG_ON(btrfs_file_extent_type(leaf, fi) != 1121 if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_PREALLOC) {
1117 BTRFS_FILE_EXTENT_PREALLOC); 1122 ret = -EINVAL;
1123 btrfs_abort_transaction(trans, ret);
1124 goto out;
1125 }
1118 extent_end = key.offset + btrfs_file_extent_num_bytes(leaf, fi); 1126 extent_end = key.offset + btrfs_file_extent_num_bytes(leaf, fi);
1119 BUG_ON(key.offset > start || extent_end < end); 1127 if (key.offset > start || extent_end < end) {
1128 ret = -EINVAL;
1129 btrfs_abort_transaction(trans, ret);
1130 goto out;
1131 }
1120 1132
1121 bytenr = btrfs_file_extent_disk_bytenr(leaf, fi); 1133 bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
1122 num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi); 1134 num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi);
@@ -1213,12 +1225,19 @@ again:
1213 ret = btrfs_inc_extent_ref(trans, root, bytenr, num_bytes, 0, 1225 ret = btrfs_inc_extent_ref(trans, root, bytenr, num_bytes, 0,
1214 root->root_key.objectid, 1226 root->root_key.objectid,
1215 ino, orig_offset); 1227 ino, orig_offset);
1216 BUG_ON(ret); /* -ENOMEM */ 1228 if (ret) {
1229 btrfs_abort_transaction(trans, ret);
1230 goto out;
1231 }
1217 1232
1218 if (split == start) { 1233 if (split == start) {
1219 key.offset = start; 1234 key.offset = start;
1220 } else { 1235 } else {
1221 BUG_ON(start != key.offset); 1236 if (start != key.offset) {
1237 ret = -EINVAL;
1238 btrfs_abort_transaction(trans, ret);
1239 goto out;
1240 }
1222 path->slots[0]--; 1241 path->slots[0]--;
1223 extent_end = end; 1242 extent_end = end;
1224 } 1243 }
@@ -1240,7 +1259,10 @@ again:
1240 ret = btrfs_free_extent(trans, root, bytenr, num_bytes, 1259 ret = btrfs_free_extent(trans, root, bytenr, num_bytes,
1241 0, root->root_key.objectid, 1260 0, root->root_key.objectid,
1242 ino, orig_offset); 1261 ino, orig_offset);
1243 BUG_ON(ret); /* -ENOMEM */ 1262 if (ret) {
1263 btrfs_abort_transaction(trans, ret);
1264 goto out;
1265 }
1244 } 1266 }
1245 other_start = 0; 1267 other_start = 0;
1246 other_end = start; 1268 other_end = start;
@@ -1257,7 +1279,10 @@ again:
1257 ret = btrfs_free_extent(trans, root, bytenr, num_bytes, 1279 ret = btrfs_free_extent(trans, root, bytenr, num_bytes,
1258 0, root->root_key.objectid, 1280 0, root->root_key.objectid,
1259 ino, orig_offset); 1281 ino, orig_offset);
1260 BUG_ON(ret); /* -ENOMEM */ 1282 if (ret) {
1283 btrfs_abort_transaction(trans, ret);
1284 goto out;
1285 }
1261 } 1286 }
1262 if (del_nr == 0) { 1287 if (del_nr == 0) {
1263 fi = btrfs_item_ptr(leaf, path->slots[0], 1288 fi = btrfs_item_ptr(leaf, path->slots[0],