From patchwork Thu Jul 20 22:52:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 13321148 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 532B8EB64DA for ; Thu, 20 Jul 2023 22:54:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbjGTWyu (ORCPT ); Thu, 20 Jul 2023 18:54:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229757AbjGTWyt (ORCPT ); Thu, 20 Jul 2023 18:54:49 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06A7F30D0 for ; Thu, 20 Jul 2023 15:54:28 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 613DA5C018B; Thu, 20 Jul 2023 18:54:27 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 20 Jul 2023 18:54:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1689893667; x= 1689980067; bh=FA2ij8OqublvACzxe7mIgdfXV8I9eHgXi7D+L0QbFO4=; b=X epuKDBwQo8YOzkPirCjaI8nclnItfEeiULeIgtFJj1abTEbOu9NJtZ0oSQGQDGLK HPQ1e3Fzk92vZBsXKbPo3apP8XZ8THSTsxym9eIUdmIkXpQaMmN6JEW7w5/K4uCT kaLTDvq4xeQPYrN+U63FZjiwZR9Z+8LAVEvzmrdBHdqhlhTVR8AGQnIYmFNYkU3D 7uf5Q9AjZR96uxHavdg0Wv8hIRmDJycXblQfSHwsfYFkfo5ZE1rWEkjHI4eCahik Dvz00uSJZLNMMLhqHQXWIgSL6ltewALP3iy/njb/D2U6nlAJ4XK/s90O5rGxHBar AaNSkEFi3AUjOF4EhbSEA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1689893667; x=1689980067; bh=F A2ij8OqublvACzxe7mIgdfXV8I9eHgXi7D+L0QbFO4=; b=ZqFK+4+gsgSw9dMkO CxxqPu36TIlBg5Ur3rhcI/4UoMV/IF9z6gWwSXEqSVwiDXR7/buIFgIEDOUu4VZN V/oRB5+mTpdu8LhqWsVKw3dvAWRpDVI3+WqwqgGR4i8NGcfz68ItS8Pe5Z9vZHXD JV0YK6/EgKNamFr8VN4XaV9E8kly6zjOibpJ8e//ZQlOKtaslj0GcAQTA96uW4s3 dmuDPyKNg5DT2PeQPKmZCa1YrfljdMJY6/7VR34NILwgUy1Mnpkmv98t7lvvB6jo AlbqKqjs/kJlTo3RtI0vHr68GOSDXa0iFFl16/bjGdibJfMfgR5vM5/Q5D5K3RFx rW7sw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrhedugdduhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhrrdhi oheqnecuggftrfgrthhtvghrnhepieeuffeuvdeiueejhfehiefgkeevudejjeejffevvd ehtddufeeihfekgeeuheelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomhepsghorhhishessghurhdrihho X-ME-Proxy: Feedback-ID: i083147f8:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 20 Jul 2023 18:54:26 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v2 01/20] btrfs: free qgroup rsv on io failure Date: Thu, 20 Jul 2023 15:52:29 -0700 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If we do a write whose bio suffers an error, we will never reclaim the qgroup reserved space for it. We allocate the space in the write_iter codepath, then release the reservation as we allocate the ordered extent, but we only create a delayed ref if the ordered extent finishes. If it has an error, we simply leak the rsv. This is apparent in running any error injecting (dmerror) fstests like btrfs/146 or btrfs/160. Such tests fail due to dmesg on umount complaining about the leaked qgroup data space. When we clean up other aspects of space on failed ordered_extents, also free the qgroup rsv. Signed-off-by: Boris Burkov Reviewed-by: Josef Bacik --- fs/btrfs/inode.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index ebe70ed96f25..6daaa4fd69f2 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3358,6 +3358,13 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent) btrfs_free_reserved_extent(fs_info, ordered_extent->disk_bytenr, ordered_extent->disk_num_bytes, 1); + /* + * Actually free the qgroup rsv which was released when + * the ordered extent was created. + */ + btrfs_qgroup_free_refroot(fs_info, inode->root->root_key.objectid, + ordered_extent->qgroup_rsv, + BTRFS_QGROUP_RSV_DATA); } }