From patchwork Tue Apr 26 14:24:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 8939271 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E1D2BBF29F for ; Tue, 26 Apr 2016 14:25:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7EBD620172 for ; Tue, 26 Apr 2016 14:25:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E01B72014A for ; Tue, 26 Apr 2016 14:25:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751871AbcDZOZT (ORCPT ); Tue, 26 Apr 2016 10:25:19 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:34317 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750835AbcDZOZS (ORCPT ); Tue, 26 Apr 2016 10:25:18 -0400 Received: from pps.filterd (m0001255.ppops.net [127.0.0.1]) by mx0b-00082601.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u3QEOI59015795; Tue, 26 Apr 2016 07:25:03 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : subject : date : message-id : mime-version : content-type; s=facebook; bh=NAfKNMYCy18D7tvTAUyO745AGVUCcSvnxrv8Fk4ytzw=; b=gKbgTaBzVYNRD4peiiEhNHZ4rCaDfR27x1hsfy+hRRtxq5iR3EYPBDzFzZlk0slX0u1a FgLcUUssYgrD5Q0GjO47ijLA6Ruo1QxU2G3igEdxnad15WP4tH6QolQx1ieDP7OZOb+g OD0cK80/vgYoOYULvV1+/6KpQ8Q1SYqU8UQ= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0b-00082601.pphosted.com with ESMTP id 22gukmdhe1-8 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 26 Apr 2016 07:25:03 -0700 Received: from localhost (192.168.54.13) by mail.thefacebook.com (192.168.16.12) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 26 Apr 2016 07:24:47 -0700 From: Josef Bacik To: , , Subject: [PATCH] Btrfs: fix qgroup accounting when snapshotting Date: Tue, 26 Apr 2016 10:24:45 -0400 Message-ID: <1461680685-2432-1-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [192.168.54.13] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-04-26_08:, , signatures=0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The new qgroup stuff needs the quota accounting to be run before doing the inherit, unfortunately they need the commit root switch to happen at a specific time for this to work properly. Fix this by delaying the inherit until after we do the qgroup accounting, and remove the inherit and accounting dance in create_pending_snapshot. Thanks, Signed-off-by: Josef Bacik --- fs/btrfs/transaction.c | 51 ++++++++++++++++++++++++++++++-------------------- fs/btrfs/transaction.h | 1 + 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 7c7671d..aa3025a 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1353,6 +1353,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, pending->error = btrfs_find_free_objectid(tree_root, &objectid); if (pending->error) goto no_free_objectid; + pending->objectid = objectid; /* * Make qgroup to skip current new snapshot's qgroupid, as it is @@ -1559,24 +1560,6 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, btrfs_abort_transaction(trans, root, ret); goto fail; } - - /* - * account qgroup counters before qgroup_inherit() - */ - ret = btrfs_qgroup_prepare_account_extents(trans, fs_info); - if (ret) - goto fail; - ret = btrfs_qgroup_account_extents(trans, fs_info); - if (ret) - goto fail; - ret = btrfs_qgroup_inherit(trans, fs_info, - root->root_key.objectid, - objectid, pending->inherit); - if (ret) { - btrfs_abort_transaction(trans, root, ret); - goto fail; - } - fail: pending->error = ret; dir_item_existed: @@ -1599,15 +1582,35 @@ no_free_objectid: static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info) { + struct btrfs_pending_snapshot *pending; + struct list_head *head = &trans->transaction->pending_snapshots; + int ret = 0; + + list_for_each_entry(pending, head, list) { + ret = create_pending_snapshot(trans, fs_info, pending); + if (ret) + break; + } + return ret; +} + +static noinline int inherit_pending_snapshots(struct btrfs_trans_handle *trans, + struct btrfs_fs_info *fs_info) +{ struct btrfs_pending_snapshot *pending, *next; struct list_head *head = &trans->transaction->pending_snapshots; int ret = 0; list_for_each_entry_safe(pending, next, head, list) { + struct btrfs_root *root = pending->root; list_del(&pending->list); - ret = create_pending_snapshot(trans, fs_info, pending); - if (ret) + ret = btrfs_qgroup_inherit(trans, fs_info, + root->root_key.objectid, + pending->objectid, pending->inherit); + if (ret) { + btrfs_abort_transaction(trans, root, ret); break; + } } return ret; } @@ -2084,6 +2087,14 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, goto scrub_continue; } + /* Inherit the qgroup information for the snapshots. */ + ret = inherit_pending_snapshots(trans, root->fs_info); + if (ret) { + mutex_unlock(&root->fs_info->reloc_mutex); + goto scrub_continue; + } + + ret = commit_cowonly_roots(trans, root); if (ret) { mutex_unlock(&root->fs_info->tree_log_mutex); diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index 72be51f..c118e6e 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h @@ -144,6 +144,7 @@ struct btrfs_pending_snapshot { /* block reservation for the operation */ struct btrfs_block_rsv block_rsv; u64 qgroup_reserved; + u64 objectid; /* extra metadata reseration for relocation */ int error; bool readonly;