Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 346653
b: refs/heads/master
c: 9afab88
h: refs/heads/master
i:
  346651: c28e4d4
v: v3
  • Loading branch information
Miao Xie authored and Josef Bacik committed Dec 11, 2012
1 parent 4b81a2e commit bcbbf04
Show file tree
Hide file tree
Showing 3 changed files with 38 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: 25287e0a16c0ad068aa89ab01aea6c699b31ec12
refs/heads/master: 9afab8820bb8b55af669b199597d6716e04d1ba8
41 changes: 33 additions & 8 deletions trunk/fs/btrfs/ordered-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ static int __btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
init_waitqueue_head(&entry->wait);
INIT_LIST_HEAD(&entry->list);
INIT_LIST_HEAD(&entry->root_extent_list);
INIT_LIST_HEAD(&entry->work_list);
init_completion(&entry->completion);

trace_btrfs_ordered_extent_add(inode, entry);

Expand Down Expand Up @@ -464,18 +466,28 @@ void btrfs_remove_ordered_extent(struct inode *inode,
wake_up(&entry->wait);
}

static void btrfs_run_ordered_extent_work(struct btrfs_work *work)
{
struct btrfs_ordered_extent *ordered;

ordered = container_of(work, struct btrfs_ordered_extent, flush_work);
btrfs_start_ordered_extent(ordered->inode, ordered, 1);
complete(&ordered->completion);
}

/*
* wait for all the ordered extents in a root. This is done when balancing
* space between drives.
*/
void btrfs_wait_ordered_extents(struct btrfs_root *root, int delay_iput)
{
struct list_head splice;
struct list_head splice, works;
struct list_head *cur;
struct btrfs_ordered_extent *ordered;
struct btrfs_ordered_extent *ordered, *next;
struct inode *inode;

INIT_LIST_HEAD(&splice);
INIT_LIST_HEAD(&works);

spin_lock(&root->fs_info->ordered_extent_lock);
list_splice_init(&root->fs_info->ordered_extents, &splice);
Expand All @@ -494,19 +506,32 @@ void btrfs_wait_ordered_extents(struct btrfs_root *root, int delay_iput)
spin_unlock(&root->fs_info->ordered_extent_lock);

if (inode) {
btrfs_start_ordered_extent(inode, ordered, 1);
btrfs_put_ordered_extent(ordered);
if (delay_iput)
btrfs_add_delayed_iput(inode);
else
iput(inode);
ordered->flush_work.func = btrfs_run_ordered_extent_work;
list_add_tail(&ordered->work_list, &works);
btrfs_queue_worker(&root->fs_info->flush_workers,
&ordered->flush_work);
} else {
btrfs_put_ordered_extent(ordered);
}

cond_resched();
spin_lock(&root->fs_info->ordered_extent_lock);
}
spin_unlock(&root->fs_info->ordered_extent_lock);

list_for_each_entry_safe(ordered, next, &works, work_list) {
list_del_init(&ordered->work_list);
wait_for_completion(&ordered->completion);

inode = ordered->inode;
btrfs_put_ordered_extent(ordered);
if (delay_iput)
btrfs_add_delayed_iput(inode);
else
iput(inode);

cond_resched();
}
}

/*
Expand Down
5 changes: 4 additions & 1 deletion trunk/fs/btrfs/ordered-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ struct btrfs_ordered_extent {
struct list_head root_extent_list;

struct btrfs_work work;
};

struct completion completion;
struct btrfs_work flush_work;
struct list_head work_list;
};

/*
* calculates the total size you need to allocate for an ordered sum
Expand Down

0 comments on commit bcbbf04

Please sign in to comment.