]> Pileus Git - ~andy/linux/blobdiff - fs/btrfs/transaction.c
Merge branch 'qgroup' of git://git.jan-o-sch.net/btrfs-unstable into for-linus
[~andy/linux] / fs / btrfs / transaction.c
index d20d2e24f8d2d1fe801c0e342789ef2e46f83f6d..cc20e95ea2898ce11af1c100d781d1795a1fb187 100644 (file)
@@ -99,8 +99,8 @@ loop:
                kmem_cache_free(btrfs_transaction_cachep, cur_trans);
                cur_trans = fs_info->running_transaction;
                goto loop;
-       } else if (root->fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) {
-               spin_unlock(&root->fs_info->trans_lock);
+       } else if (fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) {
+               spin_unlock(&fs_info->trans_lock);
                kmem_cache_free(btrfs_transaction_cachep, cur_trans);
                return -EROFS;
        }
@@ -295,6 +295,7 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
        struct btrfs_transaction *cur_trans;
        u64 num_bytes = 0;
        int ret;
+       u64 qgroup_reserved = 0;
 
        if (root->fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR)
                return ERR_PTR(-EROFS);
@@ -313,6 +314,14 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
         * the appropriate flushing if need be.
         */
        if (num_items > 0 && root != root->fs_info->chunk_root) {
+               if (root->fs_info->quota_enabled &&
+                   is_fstree(root->root_key.objectid)) {
+                       qgroup_reserved = num_items * root->leafsize;
+                       ret = btrfs_qgroup_reserve(root, qgroup_reserved);
+                       if (ret)
+                               return ERR_PTR(ret);
+               }
+
                num_bytes = btrfs_calc_trans_metadata_size(root, num_items);
                ret = btrfs_block_rsv_add(root,
                                          &root->fs_info->trans_block_rsv,
@@ -348,9 +357,11 @@ again:
        h->root = root;
        h->delayed_ref_updates = 0;
        h->use_count = 1;
+       h->adding_csums = 0;
        h->block_rsv = NULL;
        h->orig_rsv = NULL;
        h->aborted = 0;
+       h->qgroup_reserved = qgroup_reserved;
        h->delayed_ref_elem.seq = 0;
        INIT_LIST_HEAD(&h->qgroup_ref_list);
 
@@ -472,7 +483,6 @@ int btrfs_should_end_transaction(struct btrfs_trans_handle *trans,
                                 struct btrfs_root *root)
 {
        struct btrfs_transaction *cur_trans = trans->transaction;
-       struct btrfs_block_rsv *rsv = trans->block_rsv;
        int updates;
        int err;
 
@@ -480,12 +490,6 @@ int btrfs_should_end_transaction(struct btrfs_trans_handle *trans,
        if (cur_trans->blocked || cur_trans->delayed_refs.flushing)
                return 1;
 
-       /*
-        * We need to do this in case we're deleting csums so the global block
-        * rsv get's used instead of the csum block rsv.
-        */
-       trans->block_rsv = NULL;
-
        updates = trans->delayed_ref_updates;
        trans->delayed_ref_updates = 0;
        if (updates) {
@@ -494,8 +498,6 @@ int btrfs_should_end_transaction(struct btrfs_trans_handle *trans,
                        return err;
        }
 
-       trans->block_rsv = rsv;
-
        return should_end_transaction(trans, root);
 }
 
@@ -524,6 +526,12 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
         * end_transaction. Subvolume quota depends on this.
         */
        WARN_ON(trans->root != root);
+
+       if (trans->qgroup_reserved) {
+               btrfs_qgroup_free(root, trans->qgroup_reserved);
+               trans->qgroup_reserved = 0;
+       }
+
        while (count < 2) {
                unsigned long cur = trans->delayed_ref_updates;
                trans->delayed_ref_updates = 0;
@@ -536,6 +544,8 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
                }
                count++;
        }
+       btrfs_trans_release_metadata(trans, root);
+       trans->block_rsv = NULL;
 
        if (lock && !atomic_read(&root->fs_info->open_ioctl_trans) &&
            should_end_transaction(trans, root)) {
@@ -795,6 +805,13 @@ static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans,
        ret = btrfs_run_dev_stats(trans, root->fs_info);
        BUG_ON(ret);
 
+       ret = btrfs_run_qgroups(trans, root->fs_info);
+       BUG_ON(ret);
+
+       /* run_qgroups might have added some more refs */
+       ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1);
+       BUG_ON(ret);
+
        while (!list_empty(&fs_info->dirty_cowonly_roots)) {
                next = fs_info->dirty_cowonly_roots.next;
                list_del_init(next);
@@ -967,6 +984,14 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
                }
        }
 
+       ret = btrfs_qgroup_inherit(trans, fs_info, root->root_key.objectid,
+                                  objectid, pending->inherit);
+       kfree(pending->inherit);
+       if (ret) {
+               pending->error = ret;
+               goto fail;
+       }
+
        key.objectid = objectid;
        key.offset = (u64)-1;
        key.type = BTRFS_ROOT_ITEM_KEY;
@@ -1279,9 +1304,6 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
 
        btrfs_run_ordered_operations(root, 0);
 
-       btrfs_trans_release_metadata(trans, root);
-       trans->block_rsv = NULL;
-
        if (cur_trans->aborted)
                goto cleanup_transaction;
 
@@ -1292,6 +1314,9 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
        if (ret)
                goto cleanup_transaction;
 
+       btrfs_trans_release_metadata(trans, root);
+       trans->block_rsv = NULL;
+
        cur_trans = trans->transaction;
 
        /*
@@ -1340,7 +1365,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
                spin_unlock(&root->fs_info->trans_lock);
        }
 
-       if (now < cur_trans->start_time || now - cur_trans->start_time < 1)
+       if (!btrfs_test_opt(root, SSD) &&
+           (now < cur_trans->start_time || now - cur_trans->start_time < 1))
                should_grow = 1;
 
        do {
@@ -1550,6 +1576,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
        return ret;
 
 cleanup_transaction:
+       btrfs_trans_release_metadata(trans, root);
+       trans->block_rsv = NULL;
        btrfs_printk(root->fs_info, "Skipping commit of aborted transaction.\n");
 //     WARN_ON(1);
        if (current->journal_info == trans)