Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 128824
b: refs/heads/master
c: f929574
h: refs/heads/master
v: v3
  • Loading branch information
Chris Mason committed Sep 25, 2008
1 parent 94b44c2 commit a59a661
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 10 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: dbe674a99c8af088faa4c95eddaeb271a3140ab6
refs/heads/master: f9295749388f82c8d2f485e99c72cd7c7876a99b
1 change: 1 addition & 0 deletions trunk/fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ struct btrfs_fs_info {
u64 alloc_start;
struct btrfs_transaction *running_transaction;
wait_queue_head_t transaction_throttle;
wait_queue_head_t transaction_wait;
struct btrfs_super_block super_copy;
struct btrfs_super_block super_for_commit;
struct block_device *__bdev;
Expand Down
1 change: 1 addition & 0 deletions trunk/fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,
mutex_init(&fs_info->cleaner_mutex);
mutex_init(&fs_info->volume_mutex);
init_waitqueue_head(&fs_info->transaction_throttle);
init_waitqueue_head(&fs_info->transaction_wait);

#if 0
ret = add_hasher(fs_info, "crc32c");
Expand Down
2 changes: 1 addition & 1 deletion trunk/fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static int noinline dirty_and_release_pages(struct btrfs_trans_handle *trans,
end_of_last_block = start_pos + num_bytes - 1;

lock_extent(io_tree, start_pos, end_of_last_block, GFP_NOFS);
trans = btrfs_start_transaction(root, 1);
trans = btrfs_join_transaction(root, 1);
if (!trans) {
err = -ENOMEM;
goto out_unlock;
Expand Down
10 changes: 5 additions & 5 deletions trunk/fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static int cow_file_range(struct inode *inode, u64 start, u64 end)
struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
int ret = 0;

trans = btrfs_start_transaction(root, 1);
trans = btrfs_join_transaction(root, 1);
BUG_ON(!trans);
btrfs_set_trans_block_group(trans, inode);

Expand Down Expand Up @@ -502,7 +502,7 @@ int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end,
return 0;
}

trans = btrfs_start_transaction(root, 1);
trans = btrfs_join_transaction(root, 1);

ordered_extent = btrfs_lookup_ordered_extent(inode, start);
BUG_ON(!ordered_extent);
Expand Down Expand Up @@ -1812,7 +1812,7 @@ int btrfs_write_inode(struct inode *inode, int wait)
int ret = 0;

if (wait) {
trans = btrfs_start_transaction(root, 1);
trans = btrfs_join_transaction(root, 1);
btrfs_set_trans_block_group(trans, inode);
ret = btrfs_commit_transaction(trans, root);
}
Expand All @@ -1830,7 +1830,7 @@ void btrfs_dirty_inode(struct inode *inode)
struct btrfs_root *root = BTRFS_I(inode)->root;
struct btrfs_trans_handle *trans;

trans = btrfs_start_transaction(root, 1);
trans = btrfs_join_transaction(root, 1);
btrfs_set_trans_block_group(trans, inode);
btrfs_update_inode(trans, root, inode);
btrfs_end_transaction(trans, root);
Expand Down Expand Up @@ -2395,7 +2395,7 @@ struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
free_extent_map(em);
em = NULL;
btrfs_release_path(root, path);
trans = btrfs_start_transaction(root, 1);
trans = btrfs_join_transaction(root, 1);
goto again;
}
write_extent_buffer(leaf, map + pg_offset, ptr,
Expand Down
43 changes: 40 additions & 3 deletions trunk/fs/btrfs/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static noinline int join_transaction(struct btrfs_root *root)
init_waitqueue_head(&cur_trans->writer_wait);
init_waitqueue_head(&cur_trans->commit_wait);
cur_trans->in_commit = 0;
cur_trans->blocked = 0;
cur_trans->use_count = 1;
cur_trans->commit_done = 0;
cur_trans->start_time = get_seconds();
Expand Down Expand Up @@ -99,14 +100,36 @@ static noinline int record_root_in_trans(struct btrfs_root *root)
return 0;
}

struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
int num_blocks)
struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
int num_blocks, int join)
{
struct btrfs_trans_handle *h =
kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS);
struct btrfs_transaction *cur_trans;
int ret;

mutex_lock(&root->fs_info->trans_mutex);
cur_trans = root->fs_info->running_transaction;
if (cur_trans && cur_trans->blocked && !join) {
DEFINE_WAIT(wait);
cur_trans->use_count++;
while(1) {
prepare_to_wait(&root->fs_info->transaction_wait, &wait,
TASK_UNINTERRUPTIBLE);
if (cur_trans->blocked) {
mutex_unlock(&root->fs_info->trans_mutex);
schedule();
mutex_lock(&root->fs_info->trans_mutex);
finish_wait(&root->fs_info->transaction_wait,
&wait);
} else {
finish_wait(&root->fs_info->transaction_wait,
&wait);
break;
}
}
put_transaction(cur_trans);
}
ret = join_transaction(root);
BUG_ON(ret);

Expand All @@ -123,6 +146,17 @@ struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
return h;
}

struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
int num_blocks)
{
return start_transaction(root, num_blocks, 0);
}
struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root,
int num_blocks)
{
return start_transaction(root, num_blocks, 1);
}

static noinline int wait_for_commit(struct btrfs_root *root,
struct btrfs_transaction *commit)
{
Expand Down Expand Up @@ -156,7 +190,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
if (waitqueue_active(&cur_trans->writer_wait))
wake_up(&cur_trans->writer_wait);

if (cur_trans->in_commit && throttle) {
if (0 && cur_trans->in_commit && throttle) {
DEFINE_WAIT(wait);
mutex_unlock(&root->fs_info->trans_mutex);
prepare_to_wait(&root->fs_info->transaction_throttle, &wait,
Expand Down Expand Up @@ -617,6 +651,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,

printk("commit trans %Lu\n", trans->transid);
trans->transaction->in_commit = 1;
trans->transaction->blocked = 1;
cur_trans = trans->transaction;
if (cur_trans->list.prev != &root->fs_info->trans_list) {
prev_trans = list_entry(cur_trans->list.prev,
Expand Down Expand Up @@ -684,7 +719,9 @@ printk("commit trans %Lu\n", trans->transid);

btrfs_copy_pinned(root, pinned_copy);

trans->transaction->blocked = 0;
wake_up(&root->fs_info->transaction_throttle);
wake_up(&root->fs_info->transaction_wait);

mutex_unlock(&root->fs_info->trans_mutex);
ret = btrfs_write_and_wait_transaction(trans, root);
Expand Down
3 changes: 3 additions & 0 deletions trunk/fs/btrfs/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct btrfs_transaction {
int in_commit;
int use_count;
int commit_done;
int blocked;
struct list_head list;
struct extent_io_tree dirty_pages;
unsigned long start_time;
Expand Down Expand Up @@ -75,6 +76,8 @@ int btrfs_end_transaction(struct btrfs_trans_handle *trans,
struct btrfs_root *root);
struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
int num_blocks);
struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root,
int num_blocks);
int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
struct btrfs_root *root);
int btrfs_commit_tree_roots(struct btrfs_trans_handle *trans,
Expand Down

0 comments on commit a59a661

Please sign in to comment.