Btrfs: just flush the delalloc inodes in the source tree before snapshot creation
authorMiao Xie <miaox@cn.fujitsu.com>
Wed, 15 May 2013 07:48:24 +0000 (07:48 +0000)
committerJosef Bacik <jbacik@fusionio.com>
Fri, 14 Jun 2013 15:29:42 +0000 (11:29 -0400)
Before applying this patch, we need flush all the delalloc inodes in
the fs when we want to create a snapshot, it wastes time, and make
the transaction commit be blocked for a long time. It means some other
user operation would also be blocked for a long time.

This patch improves this problem, we just flush the delalloc inodes that
in the source trees before snapshot creation, so the transaction commit
will complete quickly.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
fs/btrfs/ioctl.c
fs/btrfs/transaction.c

index 10484f4bb2cce3bb44e46a7eafefa61331c58492..1f50fe2e62c7d80020db20ea94c05e2e0fd88a58 100644 (file)
@@ -555,6 +555,12 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
        if (!root->ref_cows)
                return -EINVAL;
 
+       ret = btrfs_start_delalloc_inodes(root, 0);
+       if (ret)
+               return ret;
+
+       btrfs_wait_ordered_extents(root, 0);
+
        pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_NOFS);
        if (!pending_snapshot)
                return -ENOMEM;
index 2b17213571a0c7f1e9ae3f2b812b4acdade26705..bc22be9b69b4267d16245132445f79563fde83af 100644 (file)
@@ -1491,17 +1491,9 @@ static int btrfs_flush_all_pending_stuffs(struct btrfs_trans_handle *trans,
                                          struct btrfs_root *root)
 {
        int flush_on_commit = btrfs_test_opt(root, FLUSHONCOMMIT);
-       int snap_pending = 0;
        int ret;
 
-       if (!flush_on_commit) {
-               spin_lock(&root->fs_info->trans_lock);
-               if (!list_empty(&trans->transaction->pending_snapshots))
-                       snap_pending = 1;
-               spin_unlock(&root->fs_info->trans_lock);
-       }
-
-       if (flush_on_commit || snap_pending) {
+       if (flush_on_commit) {
                ret = btrfs_start_all_delalloc_inodes(root->fs_info, 1);
                if (ret)
                        return ret;