diff options
Diffstat (limited to 'fs/btrfs/transaction.c')
-rw-r--r-- | fs/btrfs/transaction.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 02721eea9a7a..3ed5868e7c0f 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -67,6 +67,7 @@ static int join_transaction(struct btrfs_root *root) | |||
67 | cur_trans->commit_done = 0; | 67 | cur_trans->commit_done = 0; |
68 | cur_trans->start_time = get_seconds(); | 68 | cur_trans->start_time = get_seconds(); |
69 | list_add_tail(&cur_trans->list, &root->fs_info->trans_list); | 69 | list_add_tail(&cur_trans->list, &root->fs_info->trans_list); |
70 | btrfs_ordered_inode_tree_init(&cur_trans->ordered_inode_tree); | ||
70 | extent_map_tree_init(&cur_trans->dirty_pages, | 71 | extent_map_tree_init(&cur_trans->dirty_pages, |
71 | root->fs_info->btree_inode->i_mapping, | 72 | root->fs_info->btree_inode->i_mapping, |
72 | GFP_NOFS); | 73 | GFP_NOFS); |
@@ -473,6 +474,60 @@ static int drop_dirty_roots(struct btrfs_root *tree_root, | |||
473 | return ret; | 474 | return ret; |
474 | } | 475 | } |
475 | 476 | ||
477 | int btrfs_write_ordered_inodes(struct btrfs_trans_handle *trans, | ||
478 | struct btrfs_root *root) | ||
479 | { | ||
480 | struct btrfs_transaction *cur_trans = trans->transaction; | ||
481 | struct inode *inode; | ||
482 | u64 root_objectid = 0; | ||
483 | u64 objectid = 0; | ||
484 | u64 transid = trans->transid; | ||
485 | int ret; | ||
486 | |||
487 | printk("write ordered trans %Lu\n", transid); | ||
488 | while(1) { | ||
489 | ret = btrfs_find_first_ordered_inode( | ||
490 | &cur_trans->ordered_inode_tree, | ||
491 | &root_objectid, &objectid); | ||
492 | if (!ret) | ||
493 | break; | ||
494 | |||
495 | mutex_unlock(&root->fs_info->trans_mutex); | ||
496 | mutex_unlock(&root->fs_info->fs_mutex); | ||
497 | inode = btrfs_ilookup(root->fs_info->sb, objectid, | ||
498 | root_objectid); | ||
499 | if (inode) { | ||
500 | if (S_ISREG(inode->i_mode)) | ||
501 | filemap_fdatawrite(inode->i_mapping); | ||
502 | iput(inode); | ||
503 | } | ||
504 | mutex_lock(&root->fs_info->fs_mutex); | ||
505 | mutex_lock(&root->fs_info->trans_mutex); | ||
506 | } | ||
507 | while(1) { | ||
508 | root_objectid = 0; | ||
509 | objectid = 0; | ||
510 | ret = btrfs_find_del_first_ordered_inode( | ||
511 | &cur_trans->ordered_inode_tree, | ||
512 | &root_objectid, &objectid); | ||
513 | if (!ret) | ||
514 | break; | ||
515 | mutex_unlock(&root->fs_info->trans_mutex); | ||
516 | mutex_unlock(&root->fs_info->fs_mutex); | ||
517 | inode = btrfs_ilookup(root->fs_info->sb, objectid, | ||
518 | root_objectid); | ||
519 | if (inode) { | ||
520 | if (S_ISREG(inode->i_mode)) | ||
521 | filemap_write_and_wait(inode->i_mapping); | ||
522 | iput(inode); | ||
523 | } | ||
524 | mutex_lock(&root->fs_info->fs_mutex); | ||
525 | mutex_lock(&root->fs_info->trans_mutex); | ||
526 | } | ||
527 | printk("done write ordered trans %Lu\n", transid); | ||
528 | return 0; | ||
529 | } | ||
530 | |||
476 | int btrfs_commit_transaction(struct btrfs_trans_handle *trans, | 531 | int btrfs_commit_transaction(struct btrfs_trans_handle *trans, |
477 | struct btrfs_root *root) | 532 | struct btrfs_root *root) |
478 | { | 533 | { |
@@ -550,10 +605,13 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, | |||
550 | mutex_lock(&root->fs_info->fs_mutex); | 605 | mutex_lock(&root->fs_info->fs_mutex); |
551 | mutex_lock(&root->fs_info->trans_mutex); | 606 | mutex_lock(&root->fs_info->trans_mutex); |
552 | finish_wait(&cur_trans->writer_wait, &wait); | 607 | finish_wait(&cur_trans->writer_wait, &wait); |
608 | ret = btrfs_write_ordered_inodes(trans, root); | ||
609 | |||
553 | } while (cur_trans->num_writers > 1 || | 610 | } while (cur_trans->num_writers > 1 || |
554 | (cur_trans->num_joined != joined)); | 611 | (cur_trans->num_joined != joined)); |
555 | 612 | ||
556 | WARN_ON(cur_trans != trans->transaction); | 613 | WARN_ON(cur_trans != trans->transaction); |
614 | |||
557 | ret = add_dirty_roots(trans, &root->fs_info->fs_roots_radix, | 615 | ret = add_dirty_roots(trans, &root->fs_info->fs_roots_radix, |
558 | &dirty_fs_roots); | 616 | &dirty_fs_roots); |
559 | BUG_ON(ret); | 617 | BUG_ON(ret); |