aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/transaction.c
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2012-09-07 03:43:32 -0400
committerChris Mason <chris.mason@fusionio.com>2012-10-01 15:19:17 -0400
commit8407aa464331556e4f6784f974030b83fc7585ed (patch)
treea522976de80295edd552d08fd5ff897e05e07d1e /fs/btrfs/transaction.c
parent837e197283199de640857192ca32767cb6e24fe8 (diff)
Btrfs: fix corrupted metadata in the snapshot
When we delete a inode, we will remove all the delayed items including delayed inode update, and then truncate all the relative metadata. If there is lots of metadata, we will end the current transaction, and start a new transaction to truncate the left metadata. In this way, we will leave a inode item that its link counter is > 0, and also may leave some directory index items in fs/file tree after the current transaction ends. In other words, the metadata in this fs/file tree is inconsistent. If we create a snapshot for this tree now, we will find a inode with corrupted metadata in the new snapshot, and we won't continue to drop the left metadata, because its link counter is not 0. We fix this problem by updating the inode item before the current transaction ends. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Diffstat (limited to 'fs/btrfs/transaction.c')
-rw-r--r--fs/btrfs/transaction.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index a86fc723aad..f8ae448ebec 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -290,7 +290,8 @@ static int may_wait_transaction(struct btrfs_root *root, int type)
290} 290}
291 291
292static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, 292static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
293 u64 num_items, int type) 293 u64 num_items, int type,
294 int noflush)
294{ 295{
295 struct btrfs_trans_handle *h; 296 struct btrfs_trans_handle *h;
296 struct btrfs_transaction *cur_trans; 297 struct btrfs_transaction *cur_trans;
@@ -324,9 +325,14 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
324 } 325 }
325 326
326 num_bytes = btrfs_calc_trans_metadata_size(root, num_items); 327 num_bytes = btrfs_calc_trans_metadata_size(root, num_items);
327 ret = btrfs_block_rsv_add(root, 328 if (noflush)
328 &root->fs_info->trans_block_rsv, 329 ret = btrfs_block_rsv_add_noflush(root,
329 num_bytes); 330 &root->fs_info->trans_block_rsv,
331 num_bytes);
332 else
333 ret = btrfs_block_rsv_add(root,
334 &root->fs_info->trans_block_rsv,
335 num_bytes);
330 if (ret) 336 if (ret)
331 return ERR_PTR(ret); 337 return ERR_PTR(ret);
332 } 338 }
@@ -393,21 +399,28 @@ got_it:
393struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root, 399struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
394 int num_items) 400 int num_items)
395{ 401{
396 return start_transaction(root, num_items, TRANS_START); 402 return start_transaction(root, num_items, TRANS_START, 0);
397} 403}
404
405struct btrfs_trans_handle *btrfs_start_transaction_noflush(
406 struct btrfs_root *root, int num_items)
407{
408 return start_transaction(root, num_items, TRANS_START, 1);
409}
410
398struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root) 411struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root)
399{ 412{
400 return start_transaction(root, 0, TRANS_JOIN); 413 return start_transaction(root, 0, TRANS_JOIN, 0);
401} 414}
402 415
403struct btrfs_trans_handle *btrfs_join_transaction_nolock(struct btrfs_root *root) 416struct btrfs_trans_handle *btrfs_join_transaction_nolock(struct btrfs_root *root)
404{ 417{
405 return start_transaction(root, 0, TRANS_JOIN_NOLOCK); 418 return start_transaction(root, 0, TRANS_JOIN_NOLOCK, 0);
406} 419}
407 420
408struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *root) 421struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *root)
409{ 422{
410 return start_transaction(root, 0, TRANS_USERSPACE); 423 return start_transaction(root, 0, TRANS_USERSPACE, 0);
411} 424}
412 425
413/* wait for a transaction commit to be fully complete */ 426/* wait for a transaction commit to be fully complete */