Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 374833
b: refs/heads/master
c: 9d1a2a3
h: refs/heads/master
i:
  374831: 8f999d9
v: v3
  • Loading branch information
David Sterba authored and Josef Bacik committed May 6, 2013
1 parent 8372aad commit b6aaeca
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 30 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: 6841ebee6b02abe178abd30f40806e385cd96777
refs/heads/master: 9d1a2a3ad59f7ae810bf04a5a05995bf2d79300c
17 changes: 11 additions & 6 deletions trunk/fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1658,15 +1658,20 @@ static int cleaner_kthread(void *arg)
struct btrfs_root *root = arg;

do {
int again = 0;

if (!(root->fs_info->sb->s_flags & MS_RDONLY) &&
mutex_trylock(&root->fs_info->cleaner_mutex)) {
btrfs_run_delayed_iputs(root);
btrfs_clean_old_snapshots(root);
mutex_unlock(&root->fs_info->cleaner_mutex);
down_read_trylock(&root->fs_info->sb->s_umount)) {
if (mutex_trylock(&root->fs_info->cleaner_mutex)) {
btrfs_run_delayed_iputs(root);
again = btrfs_clean_one_deleted_snapshot(root);
mutex_unlock(&root->fs_info->cleaner_mutex);
}
btrfs_run_defrag_inodes(root->fs_info);
up_read(&root->fs_info->sb->s_umount);
}

if (!try_to_freeze()) {
if (!try_to_freeze() && !again) {
set_current_state(TASK_INTERRUPTIBLE);
if (!kthread_should_stop())
schedule();
Expand Down Expand Up @@ -3358,8 +3363,8 @@ int btrfs_commit_super(struct btrfs_root *root)

mutex_lock(&root->fs_info->cleaner_mutex);
btrfs_run_delayed_iputs(root);
btrfs_clean_old_snapshots(root);
mutex_unlock(&root->fs_info->cleaner_mutex);
wake_up_process(root->fs_info->cleaner_kthread);

/* wait until ongoing cleanup work done */
down_write(&root->fs_info->cleanup_work_sem);
Expand Down
8 changes: 8 additions & 0 deletions trunk/fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -7286,6 +7286,8 @@ static noinline int walk_up_tree(struct btrfs_trans_handle *trans,
* reference count by one. if update_ref is true, this function
* also make sure backrefs for the shared block and all lower level
* blocks are properly updated.
*
* If called with for_reloc == 0, may exit early with -EAGAIN
*/
int btrfs_drop_snapshot(struct btrfs_root *root,
struct btrfs_block_rsv *block_rsv, int update_ref,
Expand Down Expand Up @@ -7386,6 +7388,12 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root);

while (1) {
if (!for_reloc && btrfs_fs_closing(root->fs_info)) {
pr_debug("btrfs: drop snapshot early exit\n");
err = -EAGAIN;
goto out_end_trans;
}

ret = walk_down_tree(trans, root, path, wc);
if (ret < 0) {
err = ret;
Expand Down
3 changes: 0 additions & 3 deletions trunk/fs/btrfs/relocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -4148,10 +4148,7 @@ int btrfs_relocate_block_group(struct btrfs_root *extent_root, u64 group_start)

while (1) {
mutex_lock(&fs_info->cleaner_mutex);

btrfs_clean_old_snapshots(fs_info->tree_root);
ret = relocate_block_group(rc);

mutex_unlock(&fs_info->cleaner_mutex);
if (ret < 0) {
err = ret;
Expand Down
56 changes: 37 additions & 19 deletions trunk/fs/btrfs/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans,
int btrfs_add_dead_root(struct btrfs_root *root)
{
spin_lock(&root->fs_info->trans_lock);
list_add(&root->root_list, &root->fs_info->dead_roots);
list_add_tail(&root->root_list, &root->fs_info->dead_roots);
spin_unlock(&root->fs_info->trans_lock);
return 0;
}
Expand Down Expand Up @@ -1873,31 +1873,49 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
}

/*
* interface function to delete all the snapshots we have scheduled for deletion
* return < 0 if error
* 0 if there are no more dead_roots at the time of call
* 1 there are more to be processed, call me again
*
* The return value indicates there are certainly more snapshots to delete, but
* if there comes a new one during processing, it may return 0. We don't mind,
* because btrfs_commit_super will poke cleaner thread and it will process it a
* few seconds later.
*/
int btrfs_clean_old_snapshots(struct btrfs_root *root)
int btrfs_clean_one_deleted_snapshot(struct btrfs_root *root)
{
LIST_HEAD(list);
int ret;
struct btrfs_fs_info *fs_info = root->fs_info;

if (fs_info->sb->s_flags & MS_RDONLY) {
pr_debug("btrfs: cleaner called for RO fs!\n");
return 0;
}

spin_lock(&fs_info->trans_lock);
list_splice_init(&fs_info->dead_roots, &list);
if (list_empty(&fs_info->dead_roots)) {
spin_unlock(&fs_info->trans_lock);
return 0;
}
root = list_first_entry(&fs_info->dead_roots,
struct btrfs_root, root_list);
list_del(&root->root_list);
spin_unlock(&fs_info->trans_lock);

while (!list_empty(&list)) {
int ret;

root = list_entry(list.next, struct btrfs_root, root_list);
list_del(&root->root_list);
pr_debug("btrfs: cleaner removing %llu\n",
(unsigned long long)root->objectid);

btrfs_kill_all_delayed_nodes(root);
btrfs_kill_all_delayed_nodes(root);

if (btrfs_header_backref_rev(root->node) <
BTRFS_MIXED_BACKREF_REV)
ret = btrfs_drop_snapshot(root, NULL, 0, 0);
else
ret =btrfs_drop_snapshot(root, NULL, 1, 0);
BUG_ON(ret < 0);
}
return 0;
if (btrfs_header_backref_rev(root->node) <
BTRFS_MIXED_BACKREF_REV)
ret = btrfs_drop_snapshot(root, NULL, 0, 0);
else
ret = btrfs_drop_snapshot(root, NULL, 1, 0);
/*
* If we encounter a transaction abort during snapshot cleaning, we
* don't want to crash here
*/
BUG_ON(ret < 0 && ret != -EAGAIN && ret != -EROFS);
return 1;
}
2 changes: 1 addition & 1 deletion trunk/fs/btrfs/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,

int btrfs_add_dead_root(struct btrfs_root *root);
int btrfs_defrag_root(struct btrfs_root *root);
int btrfs_clean_old_snapshots(struct btrfs_root *root);
int btrfs_clean_one_deleted_snapshot(struct btrfs_root *root);
int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
struct btrfs_root *root);
int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
Expand Down

0 comments on commit b6aaeca

Please sign in to comment.