From patchwork Thu Oct 24 13:22:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Schmidt X-Patchwork-Id: 3091931 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4271CBF924 for ; Thu, 24 Oct 2013 13:29:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9645A204D6 for ; Thu, 24 Oct 2013 13:29:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E8263204D2 for ; Thu, 24 Oct 2013 13:29:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754894Ab3JXN3i (ORCPT ); Thu, 24 Oct 2013 09:29:38 -0400 Received: from xp-ob.rzone.de ([81.169.146.138]:45612 "EHLO xp-ob.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754528Ab3JXN3i (ORCPT ); Thu, 24 Oct 2013 09:29:38 -0400 X-Greylist: delayed 434 seconds by postgrey-1.27 at vger.kernel.org; Thu, 24 Oct 2013 09:29:37 EDT X-RZG-CLASS-ID: xp Received: from pizpot.store ([192.168.43.236]) by jored.store (RZmta 32.11 OK) with ESMTP id 6026b2p9N9A7jI ; Thu, 24 Oct 2013 15:22:20 +0200 (CEST) From: Jan Schmidt To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, dustymabe@gmail.com Subject: [PATCH] Btrfs: fix negative qgroup tracking from owner accounting (bug #61951) Date: Thu, 24 Oct 2013 15:22:06 +0200 Message-Id: <1382620926-8513-1-git-send-email-list.btrfs@jan-o-sch.net> X-Mailer: git-send-email 1.8.4 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.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 btrfs_dec_ref() queued a delayed ref for owner of a tree block. The qgroup tracking is based on delayed refs. The owner of a tree block is set when a tree block is allocated, it is never updated. When you allocate a tree block and then remove the subvolume that did the allocation, the qgroup accounting for that removal is correct. However, the removal was accounted again for each subvolume deletion that also referenced the tree block, because accounting was erroneously based on the owner. Instead of queueing delayed refs for the non-existent owner, we now queue delayed refs for the root being removed. This fixes the qgroup accounting. Signed-off-by: Jan Schmidt Tested-by: --- fs/btrfs/extent-tree.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index d58bef1..7846cae 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3004,12 +3004,11 @@ out: static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *buf, - int full_backref, int inc, int for_cow) + int full_backref, u64 ref_root, int inc, int for_cow) { u64 bytenr; u64 num_bytes; u64 parent; - u64 ref_root; u32 nritems; struct btrfs_key key; struct btrfs_file_extent_item *fi; @@ -3019,7 +3018,6 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, int (*process_func)(struct btrfs_trans_handle *, struct btrfs_root *, u64, u64, u64, u64, u64, u64, int); - ref_root = btrfs_header_owner(buf); nritems = btrfs_header_nritems(buf); level = btrfs_header_level(buf); @@ -3075,13 +3073,19 @@ fail: int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *buf, int full_backref, int for_cow) { - return __btrfs_mod_ref(trans, root, buf, full_backref, 1, for_cow); + u64 ref_root; + + ref_root = btrfs_header_owner(buf); + + return __btrfs_mod_ref(trans, root, buf, full_backref, ref_root, + 1, for_cow); } int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *buf, int full_backref, int for_cow) { - return __btrfs_mod_ref(trans, root, buf, full_backref, 0, for_cow); + return __btrfs_mod_ref(trans, root, buf, full_backref, root->objectid, + 0, for_cow); } static int write_one_cache_group(struct btrfs_trans_handle *trans,