From patchwork Mon Oct 30 22:29:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Maggard X-Patchwork-Id: 10033353 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 D8066600C5 for ; Mon, 30 Oct 2017 22:31:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C991D288A2 for ; Mon, 30 Oct 2017 22:31:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD2412897D; Mon, 30 Oct 2017 22:31:15 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 28292288A2 for ; Mon, 30 Oct 2017 22:31:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933305AbdJ3WbA (ORCPT ); Mon, 30 Oct 2017 18:31:00 -0400 Received: from mail-pg0-f46.google.com ([74.125.83.46]:52267 "EHLO mail-pg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932920AbdJ3W3Z (ORCPT ); Mon, 30 Oct 2017 18:29:25 -0400 Received: by mail-pg0-f46.google.com with SMTP id a192so12877621pge.9 for ; Mon, 30 Oct 2017 15:29:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=OeJQH4OrVHG2/T75yPqbxWEXLXQBYwn0q6hqQC8TQKk=; b=a/1RPND/p8jjv9U/F03BrXcZ+ofF9ezY7Q5PMZlTfBxNCVlzU0NlP1ThthA50pt1ZU pfd609TbG00t6eEUEnTp8wZLuS/zuHJAGNy2PC+kJKqvNyyh3+uIvHRUmuQPHcCO6Eb5 xbnyvap00EBXmxZwpWyTiCaHjBN0fXIy2+P6n66UwG25+P2A6kxz2VHAUJFH5CByR5CA Dhh6EufvKYop77J4WeK+YL1e+yf+dmSfpQ0eT2NAQ1esGRe2jvMbGCSwQDIrDuMmQenq 72i6t7/P6xtAwYIMV9GpUpj1MtSs4WgVsmEYgmLTmF4u37g2yEvQFFYwYKvmiv3804Ue N7eA== 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=OeJQH4OrVHG2/T75yPqbxWEXLXQBYwn0q6hqQC8TQKk=; b=Cf9JcdU+edWyVFFWlMa2zIwZK4lOLy4FXSpVOCOQWc9kVemSE+iJRp6cQmB63ydnWl z//C8kI/huZkv+HIT6kfSZ0vRMLEePNoJHWwjG2I1utcB0j2u86l8Z52JLiE8dMECiyz ggdsAreIXq/uELsjxPIgoJw1L4/8KWrzLtZM8iZc5ZDL881fe+acJjaNdqsP3eha6FBg xzKSAEJzZYuTub3Xw1Ijt6HYHd1bS+Rd1DBnCC5V38e+gbraCa+Yhvr0wo6OAMCcgk80 gSmL/NIQ1536BHqA+9N97ZuoLrWimGXNl1Td3fRSU4wexePwlHp44Q5o0QOE/lM65LD+ k7wA== X-Gm-Message-State: AMCzsaUoUhVjGgcaum8l7CKSt0qZ+sazRdtvcrmkaupmpThSXCiideCP jt51sQsCB6uGQ6QB/jkhJBa0GAgk X-Google-Smtp-Source: ABhQp+RCndk1WSnBHbBxHO8R8oOKzI/oYDYkei7PLb4EpdwqUMByQHVZXmGLFbUGDxXCX5RbvpqEEQ== X-Received: by 10.84.168.35 with SMTP id e32mr8596423plb.294.1509402563991; Mon, 30 Oct 2017 15:29:23 -0700 (PDT) Received: from jmaggard-thinkpad-t450s.infrant-6.com (198-0-192-140-static.hfc.comcastbusiness.net. [198.0.192.140]) by smtp.gmail.com with ESMTPSA id 19sm29366475pfj.154.2017.10.30.15.29.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Oct 2017 15:29:23 -0700 (PDT) From: Justin Maggard X-Google-Original-From: Justin Maggard To: linux-btrfs@vger.kernel.org Cc: Justin Maggard Subject: [PATCH] btrfs: Fix quota reservation leak on preallocated files Date: Mon, 30 Oct 2017 15:29:10 -0700 Message-Id: <20171030222910.21722-1-jmaggard@netgear.com> X-Mailer: git-send-email 2.14.2 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 Commit c6887cd11149 (Btrfs: don't do nocow check unless we have to) changed the behavior of __btrfs_buffered_write() so that it first tries to get a data space reservation, and then skips the relatively expensive nocow check if the reservation succeeded. If we have quotas enabled, the data space reservation also includes a quota reservation. But in the rewrite case, the space has already been accounted for in qgroups. So btrfs_check_data_free_space() increases the quota reservation, but it never gets decreased when the data actually gets written and overwrites the pre-existing data. So we're left with both the qgroup and qgroup reservation accounting for the same space. This commit adds the missing btrfs_qgroup_free_data() call in the case of BTRFS_ORDERED_PREALLOC extents. Signed-off-by: Justin Maggard Reviewed-by: Qu Wenruo --- fs/btrfs/inode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index d94e3f68b9b1..d7881ccf5310 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3006,6 +3006,8 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) compress_type = ordered_extent->compress_type; if (test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) { BUG_ON(compress_type); + btrfs_qgroup_free_data(inode, NULL, ordered_extent->file_offset, + ordered_extent->len); ret = btrfs_mark_extent_written(trans, BTRFS_I(inode), ordered_extent->file_offset, ordered_extent->file_offset +