From patchwork Tue Jun 6 23:45:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9770197 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0A24A6034B for ; Tue, 6 Jun 2017 23:45:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDC35284E4 for ; Tue, 6 Jun 2017 23:45:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0D0E2851F; Tue, 6 Jun 2017 23:45:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52A69284E4 for ; Tue, 6 Jun 2017 23:45:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751454AbdFFXpm (ORCPT ); Tue, 6 Jun 2017 19:45:42 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:35889 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750766AbdFFXpl (ORCPT ); Tue, 6 Jun 2017 19:45:41 -0400 Received: by mail-pg0-f42.google.com with SMTP id a70so32457839pge.3 for ; Tue, 06 Jun 2017 16:45:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=ajcfHePSKDmFDJ5dAk9BUYe0uHdARSE/6vLUlhPJq2g=; b=thXvPLyMFfA/UzbGqG0qIGIytgL4tH1nqyPI78xV57++hWgNak5RdJQlqAH57Abmmi qDusYPl+5Jy//hc1SvhJBbHpl0zxMyoT6v0KtPfJNZn0BLjT7C1ABkZnA/TFGhmuhjZN R03rQAJCLBGq5yZoG+uHW0QBSvjdZZlFAPvXMIbHbiMe0V6+JrWCpjPBapb2Fldy1GKL TRYsUchj/hBbMzwReVRA8/d1zSxJd+MvM9jltpwNzSHv6/nOsC/nQlLJnZa2FAUT1gR+ 5miEufYDB9PjfUuko+3fyljAALl3ZeIavCdOif15qP+mXA+yDU1s4I3BGhnTPXthiv9h Wrkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ajcfHePSKDmFDJ5dAk9BUYe0uHdARSE/6vLUlhPJq2g=; b=GGZwLqdYt8qaN69lz1bDlkbOpJU/SUnDtotg3rMcc+3iU1CR5BfB8NNd4HG+MO02bV vfVVNQxbrm8jVvpFqx9EyUcDqis8chlobsptpnnKsHNdLY5i8G47XGpo4GM+9jkJmz76 FhElQj+2Y+65PJ7JvcxHVAU8R1g7+xUmcHSOoM1ZFxGwq05g4eVLRc185ZN4Ld9Qs15K t9PUpuZay+J/NPXOQrwBv3A+yjR+rQnYOyph+njEQZQmqx6B+PV6DjPAJVZrhewFPDEl C0l8AY5Ec/Q9EZK4ROILARvLTe4v9KqVIWmGsa5GK+/qEvPpdqSX+N0pTkoSqGC7aiei 4Rtw== X-Gm-Message-State: AODbwcCbpgiliFGNH5prmG2EDQsmdOIgdv8Wpmrlvz9XUg7ny/kkfQ96 wCIwPHUygPMGU0tyUaAhog== X-Received: by 10.99.185.5 with SMTP id z5mr25138086pge.231.1496792740412; Tue, 06 Jun 2017 16:45:40 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::3:f879]) by smtp.gmail.com with ESMTPSA id u194sm60175680pgc.2.2017.06.06.16.45.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Jun 2017 16:45:39 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Liu Bo , kernel-team@fb.com Subject: [PATCH 0/7] Btrfs: fix total_bytes_pinned counter Date: Tue, 6 Jun 2017 16:45:25 -0700 Message-Id: X-Mailer: git-send-email 2.13.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval This series fixes several problems with the total_bytes_pinned counter. Patches 1 and 2 are cleanups. Patches 3 and 4 are straightforward fixes. Patch 5 is prep for patch 6. Patch 6 is the most complicated fix. Patches 5 and 6 are ugly, I'd love any suggestions for a cleaner fix. Finally, patch 7 adds a warning to catch similar issues in the future. Tested with this xfstests diff, which exposes a bunch of the issues without these fixes: Omar Sandoval (7): Btrfs: make add_pinned_bytes() take an s64 num_bytes instead of u64 Btrfs: make BUG_ON() in add_pinned_bytes() an ASSERT() Btrfs: update total_bytes_pinned when pinning down extents Btrfs: always account pinned bytes when dropping a tree block ref Btrfs: return old and new total ref mods when adding delayed refs Btrfs: rework delayed ref total_bytes_pinned accounting Btrfs: warn if total_bytes_pinned is non-zero on unmount fs/btrfs/delayed-ref.c | 29 +++++++--- fs/btrfs/delayed-ref.h | 6 ++- fs/btrfs/extent-tree.c | 142 +++++++++++++++++++++++++++++-------------------- 3 files changed, 109 insertions(+), 68 deletions(-) Tested-by: Holger Hoffstätte diff --git a/common/rc b/common/rc index 743df427..95e7517b 100644 --- a/common/rc +++ b/common/rc @@ -484,6 +484,12 @@ _scratch_unmount() _overlay_scratch_unmount ;; btrfs) + if uuid="$(findmnt -n -o UUID "$SCRATCH_MNT")"; then + pushd "/sys/fs/btrfs/$uuid/allocation" >/dev/null + sync; sync; sync + grep -H -v '^0$' */total_bytes_pinned + popd >/dev/null + fi $UMOUNT_PROG $SCRATCH_MNT ;; *)