From patchwork Wed Dec 16 16:26:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977897 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DC9FC0018C for ; Wed, 16 Dec 2020 16:27:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE1CC233E2 for ; Wed, 16 Dec 2020 16:27:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726713AbgLPQ1j (ORCPT ); Wed, 16 Dec 2020 11:27:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726708AbgLPQ1j (ORCPT ); Wed, 16 Dec 2020 11:27:39 -0500 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C25C6C06179C for ; Wed, 16 Dec 2020 08:26:58 -0800 (PST) Received: by mail-qv1-xf29.google.com with SMTP id h16so7178996qvu.8 for ; Wed, 16 Dec 2020 08:26:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tVK6HYY5L6khzQdNnCfvNhn+/fCGGpYOkn+GtTYGk6c=; b=JHGgtmkMrgYFH6oIWwDFcFbrICfdNWo0PaOulzPmsrHR8DPV2pgvfF9FYhnJ/j7isQ IYvsAYWI7NuFZ/USuUpCtrDV6NKM9WGs2kUPZsIACqRBvuYwH1bM8xOxcBqUm1aIFdHl uUUfosb9vVTK7Tn+RsNs6kCcR/JkZh5UEv8OZRRkC9meGq2srYOyq2DQBPd2sO+j/fdT sFCMouFOCkkpbLeZSFQY2iQ6CZrajd+id+QQVmfy6pWO5CgRcWJ7dh/LmF6p08IIEFDZ ObGjNqWUDgg8EaY6z+/7ANc5I2KtaZ34dcAjrqRUBYFbfrG5JPwOYhU7Zjwot++A+E8/ ffyA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=tVK6HYY5L6khzQdNnCfvNhn+/fCGGpYOkn+GtTYGk6c=; b=BGuXUtGaKDqEyTzKC6csZI/Jc/zsFsluwk1aKdze1g42uL3QTDq63/3SrtuhWzoq9y ogCFOf1QPUXo1eeYAaRAxHT+dwU9z9hZVRl/RMnr0JwdEKKD1JkCj1W2M28lXHtY4oiW Z0a8b1g+TLkjtx5dNSJfWi3ICPN07vULDpSKPnbdpIc3WN8kyV1g6nNDgZEpKNIQHgD2 uVjCiNyw+PkTcXcv3+MdK0y0+dCj23gq3tCq+G3feYiP64xHP6p0ZambAA8PZYdrI7b+ wnIFhsn5XG0Rjk8IU6pJdIBDSa4pUPN2VH4XUg0edQKca1SfzOkXEsXKu1qKipKF+r+9 tr+g== X-Gm-Message-State: AOAM530fgq2AMhC8OInPpS9laWL4UKpiZMMcSoSs3NnHl/DNC0oMHV7x 2MH29Gsb9kXwESh01BYwR8mHI+vVXXj3aomv X-Google-Smtp-Source: ABdhPJzU3hE/t55cgCNwPrc4Up9BMmmn1QTQ9W5lxO2T9wWThe17bD+Bp5rcPcYTGec4WApZoouSZw== X-Received: by 2002:ad4:4aac:: with SMTP id i12mr41126120qvx.10.1608136017737; Wed, 16 Dec 2020 08:26:57 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id c14sm1145434qtc.90.2020.12.16.08.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:26:57 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 01/38] btrfs: convert BUG_ON()'s in relocate_tree_block Date: Wed, 16 Dec 2020 11:26:17 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have a couple of BUG_ON()'s in relocate_tree_block() that can be tripped if we have file system corruption. Convert these to ASSERT()'s so developers still get yelled at when they break the backref code, but error out nicely for users so the whole box doesn't go down. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 8cb9a7b364d8..08ffaa93b78f 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2454,8 +2454,28 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, if (root) { if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) { - BUG_ON(node->new_bytenr); - BUG_ON(!list_empty(&node->list)); + /* + * This block was the root block of a root, and this is + * the first time we're processing the block and thus it + * should not have had the ->new_bytenr modified and + * should have not been included on the changed list. + * + * However in the case of corruption we could have + * multiple refs pointing to the same block improperly, + * and thus we would trip over these checks. ASSERT() + * for the developer case, because it could indicate a + * bug in the backref code, however error out for a + * normal user in the case of corruption. + */ + ASSERT(node->new_bytenr == 0); + ASSERT(list_empty(&node->list)); + if (node->new_bytenr || !list_empty(&node->list)) { + btrfs_err(root->fs_info, + "bytenr %llu has improper references to it", + node->bytenr); + ret = -EUCLEAN; + goto out; + } btrfs_record_root_in_trans(trans, root); root = root->reloc_root; node->new_bytenr = root->node->start; From patchwork Wed Dec 16 16:26:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977899 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADB95C4361B for ; Wed, 16 Dec 2020 16:27:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7CF95233E2 for ; Wed, 16 Dec 2020 16:27:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726715AbgLPQ1l (ORCPT ); Wed, 16 Dec 2020 11:27:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726708AbgLPQ1k (ORCPT ); Wed, 16 Dec 2020 11:27:40 -0500 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 618DFC0617A6 for ; Wed, 16 Dec 2020 08:27:00 -0800 (PST) Received: by mail-qv1-xf2c.google.com with SMTP id d11so11605690qvo.11 for ; Wed, 16 Dec 2020 08:27:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2Tc7UX3QkyM4l8FuzTGvqDpXQ+G7Xq2NkIAj1kVTTYI=; b=2N2QuP2INskalegcFzTMHk33hocqrw0wkJRVOdkQ9K5R5qH58f4n5qWMuKhoYr0mSF t26gJc2P3D31Cpo6Gz0/izgGzxqKmxCfTrfJBADseP2fLAzTGO7g3kXRIpLZ3QSzXK35 JMWp8SuYx1kG3bzPWb0/gWw+Ff7jrxyQXwdvq1rAN6UzHviFDbvRj8yvQXB/cxYQj7YC cr5FVwTFgjSKgltvGE9IFy0mRnczrM/SgbXJLwQnfwgQ/e7c02xnNANHcUYz7g7lq5cZ xYl8jrloVP95UHxcvpvxA6q3iuKIizLq2OfSY1Y0K5BBv71XuCRww3gIJF3JGFcUwwLX VMqw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=2Tc7UX3QkyM4l8FuzTGvqDpXQ+G7Xq2NkIAj1kVTTYI=; b=WaW2GBsY5zKWBMX042hHNT0qStNJqpqZeHFOT9jSAfhjIF/t2a6qHIARr5saEWk7GW hF7Yi5oHDSVZvcPSI1hYk2R48okfEMPNkFUiAU5bP8GCx7YCjDrUmPej3pddYK1s/u0K YqCZZpYICAyKqvOAp1nngTzqLuZs0OzKoT8dBQ0XnlZ7+wUtArypauB5A7RWJRndxvCx YMQHy/rWM1+JRASTtXeVtaz/Ruge7ex2OVAYJ7FQ5wNvrHstr1fO5LWMirRKtdswI/0T XqcDDLuScFen7CrV8kkEf11D+oBfFApCyPPHSbLXEEuzh5nqABJEXaSS9i6UONinGzRv 18MQ== X-Gm-Message-State: AOAM530NeEbx1/WaP6O3oyszj9rkQVy2tHnUUkGFWbLHV2oUVFpP3xmc lU6bMuo6QysedO0bOHyLEq+75r3RvZ16B5ck X-Google-Smtp-Source: ABdhPJx1SwrwXVikHYC9BEP1G5lr21SHuL7VHZ5FQDjt6r7TtdnPSGnrxUidOBJhV33iHMCvhPYGEg== X-Received: by 2002:ad4:5904:: with SMTP id ez4mr18554293qvb.30.1608136019396; Wed, 16 Dec 2020 08:26:59 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id u26sm1330421qkm.69.2020.12.16.08.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:26:58 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo , Johannes Thumshirn Subject: [PATCH v7 02/38] btrfs: return an error from btrfs_record_root_in_trans Date: Wed, 16 Dec 2020 11:26:18 -0500 Message-Id: <0b7c322b530735e98a2c6e9db4fc024c9e137546.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We can create a reloc root when we record the root in the trans, which can fail for all sorts of different reasons. Propagate this error up the chain of callers. Future patches will fix the callers of btrfs_record_root_in_trans() to handle the error. Reviewed-by: Qu Wenruo Reviewed-by: Johannes Thumshirn Signed-off-by: Josef Bacik --- fs/btrfs/transaction.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index f51f9e39bcee..eba48578159e 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -400,6 +400,7 @@ static int record_root_in_trans(struct btrfs_trans_handle *trans, int force) { struct btrfs_fs_info *fs_info = root->fs_info; + int ret = 0; if ((test_bit(BTRFS_ROOT_SHAREABLE, &root->state) && root->last_trans < trans->transid) || force) { @@ -448,11 +449,11 @@ static int record_root_in_trans(struct btrfs_trans_handle *trans, * lock. smp_wmb() makes sure that all the writes above are * done before we pop in the zero below */ - btrfs_init_reloc_root(trans, root); + ret = btrfs_init_reloc_root(trans, root); smp_mb__before_atomic(); clear_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state); } - return 0; + return ret; } From patchwork Wed Dec 16 16:26:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977901 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76298C0018C for ; Wed, 16 Dec 2020 16:27:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D044233E2 for ; Wed, 16 Dec 2020 16:27:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726719AbgLPQ1m (ORCPT ); Wed, 16 Dec 2020 11:27:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726716AbgLPQ1m (ORCPT ); Wed, 16 Dec 2020 11:27:42 -0500 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A4B7C0617A7 for ; Wed, 16 Dec 2020 08:27:02 -0800 (PST) Received: by mail-qk1-x729.google.com with SMTP id z11so23040901qkj.7 for ; Wed, 16 Dec 2020 08:27:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=vzKO5a5BS15XQXu7afxbO40tSG9l7H7GGI1WZ9vnPW0=; b=p0Rida9KjPH6gubhHbfl/OkfxwdgQrXKHgfycDK1BxlCOcQqE55Wdw4+Za42GX9as/ 2dCf1CDWNi/lPqeoYvZCWhNmdFPS+rkIL84NfV9RAOl726UZ3uVtMCZlaUd70h91XVZP SaiJToci/RYOtGuqrDmfpo9QcUE/7yB2NX9KwHeIbil2Hcb7E/uy1WaHnAYtqutjPItY kTJyCD/ADrjbpoHEkrY2Gn2kh+3J+n/P717kwBY/x9iKFi/UrpH2f3FIm4Fm3jhqB9RU DGp3fhGpPmbRJV6JmLDh3ZEoFTQUDpGXNo68LLbL9ckiWFC0rO8zKH2oasB+H4X+re1q /85w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vzKO5a5BS15XQXu7afxbO40tSG9l7H7GGI1WZ9vnPW0=; b=eCU2ZZOYt0LdwmUoyeFNbSWDCqxnviUT+fkudLKdMngOOh8DfMipc32/6oEiIBtSp9 TmYrsFgzLV6Kzb+yi8UfDjccKM36T8UmdELbg9dIiKyNlw5ib+rzVcFBIkxON2JPfZ6r +7YlstkjiQ8dzSzUxnOPAdJct2rvP1bn5pAfi378Q3O3GDa9GoY+X5eZbefUfE+Q5hmY nTGniZW25h0xYBTQ49WUKM2y8wUtrgnzM3Ya9EkP2MeBWKg5zns2WOUsXGt9Jncuvv5x EMNre9w44c9/C0kQmTqVB99iM5jzS6/bjAF8JnOLPFxeujPaevZRfYeijQMTILmBLM2d 4gKg== X-Gm-Message-State: AOAM533lqYNmvku6tpmx5vN/JdhsBdJFU478EiRGFOVUqJEtURYUQiQI 59VvVEp3j4nRCgKz1KcDOpRCyGdqw5cFco1s X-Google-Smtp-Source: ABdhPJzfhvy0FcVFUH5uAtXblLC/j487NHDDq1H3WwMW57I1bWIHIwo2Aa+qwYmazEPQ823G3K4Xgg== X-Received: by 2002:a37:668e:: with SMTP id a136mr36730793qkc.221.1608136021044; Wed, 16 Dec 2020 08:27:01 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id f185sm1342494qkb.119.2020.12.16.08.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:00 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 03/38] btrfs: handle errors from select_reloc_root() Date: Wed, 16 Dec 2020 11:26:19 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Currently select_reloc_root() doesn't return an error, but followup patches will make it possible for it to return an error. We do have proper error recovery in do_relocation however, so handle the possibility of select_reloc_root() having an error properly instead of BUG_ON(!root). I've also adjusted select_reloc_root() to return ERR_PTR(-ENOENT) if we don't find a root, instead of NULL, to make the error case easier to deal with. I've replaced the BUG_ON(!root) with an ASSERT(0) for this case as it indicates we messed up the backref walking code, but it could also indicate corruption. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 08ffaa93b78f..741068580455 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2024,8 +2024,14 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans, if (!next || next->level <= node->level) break; } - if (!root) - return NULL; + if (!root) { + /* + * This can happen if there's fs corruption or if there's a bug + * in the backref lookup code. + */ + ASSERT(0); + return ERR_PTR(-ENOENT); + } next = node; /* setup backref node path for btrfs_reloc_cow_block */ @@ -2196,7 +2202,10 @@ static int do_relocation(struct btrfs_trans_handle *trans, upper = edge->node[UPPER]; root = select_reloc_root(trans, rc, upper, edges); - BUG_ON(!root); + if (IS_ERR(root)) { + ret = PTR_ERR(root); + goto next; + } if (upper->eb && !upper->locked) { if (!lowest) { From patchwork Wed Dec 16 16:26:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977903 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85A03C4361B for ; Wed, 16 Dec 2020 16:27:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F39A233E2 for ; Wed, 16 Dec 2020 16:27:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726721AbgLPQ1o (ORCPT ); Wed, 16 Dec 2020 11:27:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726716AbgLPQ1o (ORCPT ); Wed, 16 Dec 2020 11:27:44 -0500 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D181FC0617B0 for ; Wed, 16 Dec 2020 08:27:03 -0800 (PST) Received: by mail-qt1-x830.google.com with SMTP id 2so7750402qtt.10 for ; Wed, 16 Dec 2020 08:27:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=I711wKf496QPXYtatYNw2NmJZyOAIyKrwNlVnuL+q/o=; b=MA1OsGl2v9Mmh9CxcHVAEJuiJqW9byULv9nkXBZ+FHvDn9BgV3QvQnYfzoAtgvXiA1 ktW5eFyIMexfHHFS4hLOZQGZ8kqRf/+KE8RiB8EPcf0ZYQlP8lmG8yfxADIW1ww+7MB3 zYa1cZ5C0NJBo6FGuGhEmS2XsfmSQSiUvangB9ZNUOBfYzihp9TPa+r+kq1mWz+80GVj 1ucnkBUOcV7pmAZC8c/Nbk4hdxCeTQJWLwQVoxqBoASWWx9yIEOPikD2HGNaWrQmygJD He+LHNOBNnSNXJZQyOTS1HrQQoc3kGC3uDqzzGPyj0jxLPUTviYuiAi6vSgbdXu7ddWp ljzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I711wKf496QPXYtatYNw2NmJZyOAIyKrwNlVnuL+q/o=; b=iPD8noO7ZUBiCLybZh5YHjSEClyfg13vQKyvd+nzRGVsj8onPli1fTn9/tTENreh+O IiQKhD4QMy/dxM7DRKzqv2lecUST03A0io9/Qu2eSv/iv9yjQLknPHev/cgjo8y7bgZO CV0ZfvA7Dr54K9jnP5YdWVL2C0bEV793Ej/wYi7n0MdN6oy4WETmD+QEBvOO/HvOXZQD miYBiQPU8wqlsK88a2m2Z+rnmJpY9TqZfmLJKHwyT+ymGEdlHf7ZqpJ+eNtZMB1A7lGy C4HwuhNMMjdKwL6zxJ4RsPVtvQYlEnYPacjf/0t76NPezNB9PKpkUAKja0413F2dpB/H 5itw== X-Gm-Message-State: AOAM530iebzEelHTiCJ1RvpfC/STQD0v0o4ESCJ6GdjcSXWL7PyqyBKA WIHhSoA7U+9yB7MRN0u7Byp8Ea/VOXEpQWbB X-Google-Smtp-Source: ABdhPJw/Urf//cS4inNdK7rxzDk22BfikgRJjMLkr6gMg1sEPrp5PlOO/iuLdWjtoXOZKAPlzGzX+g== X-Received: by 2002:ac8:5a01:: with SMTP id n1mr23311256qta.227.1608136022717; Wed, 16 Dec 2020 08:27:02 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id o21sm1417818qko.9.2020.12.16.08.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:02 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 04/38] btrfs: convert BUG_ON()'s in select_reloc_root() to proper errors Date: Wed, 16 Dec 2020 11:26:20 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have several BUG_ON()'s in select_reloc_root() that can be tripped if you have extent tree corruption. Convert these to ASSERT()'s, because if we hit it during testing it really is bad, or could indicate a problem with the backref walking code. However if users hit these problems it generally indicates corruption, I've hit a few machines in the fleet that trip over these with clearly corrupted extent trees, so be nice and spit out an error message and return an error instead of bringing the whole box down. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 47 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 741068580455..2a0f3c0dbbc0 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1994,8 +1994,33 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans, cond_resched(); next = walk_up_backref(next, edges, &index); root = next->root; - BUG_ON(!root); - BUG_ON(!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)); + + /* + * If there is no root, then our references for this block are + * incomplete, as we should be able to walk all the way up to a + * block that is owned by a root. + * + * This path is only for SHAREABLE roots, so if we come upon a + * non-SHAREABLE root then we have backrefs that resolve + * improperly. + * + * Both of these cases indicate file system corruption, or a bug + * in the backref walking code. + */ + if (!root) { + ASSERT(0); + btrfs_err(trans->fs_info, + "bytenr %llu doesn't have a backref path ending in a root", + node->bytenr); + return ERR_PTR(-EUCLEAN); + } + if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) { + ASSERT(0); + btrfs_err(trans->fs_info, +"bytenr %llu has multiple refs with one ending in a non shareable root", + node->bytenr); + return ERR_PTR(-EUCLEAN); + } if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) { record_reloc_root_in_trans(trans, root); @@ -2006,8 +2031,22 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans, root = root->reloc_root; if (next->new_bytenr != root->node->start) { - BUG_ON(next->new_bytenr); - BUG_ON(!list_empty(&next->list)); + /* + * We just created the reloc root, so we shouldn't have + * ->new_bytenr set and this shouldn't be in the changed + * list. If it is then we have multiple roots pointing + * at the same bytenr which indicates corruption, or + * we've made a mistake in the backref walking code. + */ + ASSERT(next->new_bytenr == 0); + ASSERT(list_empty(&next->list)); + if (next->new_bytenr || !list_empty(&next->list)) { + btrfs_err(trans->fs_info, +"bytenr %llu possibly has multiple roots pointing at the same bytenr %llu", + node->bytenr, next->bytenr); + return ERR_PTR(-EUCLEAN); + } + next->new_bytenr = root->node->start; btrfs_put_root(next->root); next->root = btrfs_grab_root(root); From patchwork Wed Dec 16 16:26:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13AE3C4361B for ; Wed, 16 Dec 2020 16:28:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1F64233F9 for ; Wed, 16 Dec 2020 16:28:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726716AbgLPQ2S (ORCPT ); Wed, 16 Dec 2020 11:28:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726705AbgLPQ2R (ORCPT ); Wed, 16 Dec 2020 11:28:17 -0500 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E4B2C06138C for ; Wed, 16 Dec 2020 08:27:05 -0800 (PST) Received: by mail-qv1-xf2c.google.com with SMTP id a13so11593877qvv.0 for ; Wed, 16 Dec 2020 08:27:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NTzuJtm30OfFhLvIQZavh2mDl4CzhSzLQaF3f51kQio=; b=GPSdHJFZXlxNAOdvJyhmApI+CLD0l9RGNqS4AydzwZmEstWja7cKIsYhZmDQG9fpFL du4fo7TBf6pmxRchvLiJHqbzyuCRqxsEk/gZje5/iM3NmhoOZ4flsw8HUvzTq4uKkWy6 K4IKyILvkz33aJdFb1YVpuvXJNYyMTUnW5bXJ3bUP2ZwCLLFYslcP0zBZg4imJipfAPb FlfxBcDkJWa0dzNUFxQ6v2Uq9qHLIL1ZhnATA9305uDBmenAfpBY2JsG9fbukguF8Me0 Q4iIJNdUXLWt+e20cOYWm47hTrkvRBIkES8VhNl0hFPZeHmXIHq3EZq9HLApePUA1EO4 rCTw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=NTzuJtm30OfFhLvIQZavh2mDl4CzhSzLQaF3f51kQio=; b=s98pQwIYEF7+M4QUtgc1e4AlW7uB/vQdzChjtInE6G9d8P1fAgGlOzLd2zhdqO2ktb lET6anqbavzFq6TTCnpgs+TU2TBV3AeZTmvgD0VewGt1rBk1xkS8uPbWJQu/EX/JsdBz s9mplckt80HWycCIzZ3Ejj60gYqR8g25DWfDjll0ihs5phBJsiAGmlwk/1QF2Cd/fRUZ AGEupbzpQHso+855XKVXe1GA1MAjyyOyaLuk5wo5IwmTYfodel+iYvxxS+doHsBnrQAe ivUTiLbeXCDupvk53yvKPR0IIjoJzJpECDohTP+FHqNfjJbxMz+/FjbHNohXX0pKNuv7 s0lA== X-Gm-Message-State: AOAM530WMVO6P8rXZlytzuDAvOQlR9x4njSd2nP95a+kUMLbiXHfk0Wb 9YQu73HtQ7Vrr09hbdjd/egPxGlSQg5v8MIh X-Google-Smtp-Source: ABdhPJyljYOXl3KAqewIOBiafBl0GNKvIR/Ze9syzyWdMnPu+E0E7TJOZjubFPHX/YfYg230JkkvTQ== X-Received: by 2002:ad4:4c50:: with SMTP id cs16mr43674069qvb.33.1608136024473; Wed, 16 Dec 2020 08:27:04 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id n188sm1427755qke.17.2020.12.16.08.27.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:03 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 05/38] btrfs: check record_root_in_trans related failures in select_reloc_root Date: Wed, 16 Dec 2020 11:26:21 -0500 Message-Id: <42bb8fda7ad569b8b3ea4ed21655bb8abba40792.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We will record the fs root or the reloc root in the trans in select_reloc_root. These will actually return errors in the following patches, so check their return value here and return it up the stack. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 2a0f3c0dbbc0..1c36b10fdd02 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1988,6 +1988,7 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans, struct btrfs_backref_node *next; struct btrfs_root *root; int index = 0; + int ret; next = node; while (1) { @@ -2023,11 +2024,15 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans, } if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) { - record_reloc_root_in_trans(trans, root); + ret = record_reloc_root_in_trans(trans, root); + if (ret) + return ERR_PTR(ret); break; } - btrfs_record_root_in_trans(trans, root); + ret = btrfs_record_root_in_trans(trans, root); + if (ret) + return ERR_PTR(ret); root = root->reloc_root; if (next->new_bytenr != root->node->start) { From patchwork Wed Dec 16 16:26:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3E23C0018C for ; Wed, 16 Dec 2020 16:28:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 988E0233E2 for ; Wed, 16 Dec 2020 16:28:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726727AbgLPQ2T (ORCPT ); Wed, 16 Dec 2020 11:28:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726707AbgLPQ2T (ORCPT ); Wed, 16 Dec 2020 11:28:19 -0500 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7312AC061285 for ; Wed, 16 Dec 2020 08:27:07 -0800 (PST) Received: by mail-qv1-xf30.google.com with SMTP id a13so11593956qvv.0 for ; Wed, 16 Dec 2020 08:27:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ughAcqu5UTXiwMw2asTgzY7G+SQWjtfjcNc/+0aEZU4=; b=moK4LA6V2ybTNgA5rkCvUBtERVPLtB6nu77Y55Re1j+8Fe9vLXI80PBt55NVoJr0xp H3ovjC8YiUoFvklS4hodLdgmoTS8nDnG8DjDfqIzDYUW+iTZsVdpeBBRGravLwz8T+sH /DmfMbXvlAhP4jBFafKS8rm7xM5PAzSzgrqtIsObLsw0XUx2JBAYdpfSJwjDSwtEi0MT jMDWEST650gn3+OkIvYEGUDJbpVdI8JLp+IYTqztJWe2Zn4q20I0SgHCXxgmd0kJhwoy VeT3E+uEmkphZJMPFAx/CRXZMDQTNOCZWbclRzRh1jZQPq52t0VpJyhgx13fbud5xqk3 lkIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ughAcqu5UTXiwMw2asTgzY7G+SQWjtfjcNc/+0aEZU4=; b=maHOqzQIjzrjPGmKA19kXKefLj+0MxCwgbsNsvzrutvdKiV5cX206kiPtRHrEGsxIT zW0+CjTg72ixY4kKVl0QALGWaqxNxPD+sBoGftGYT3RVYMZqroXKMBL3hLvg4zT+uDIV 8tJ8wh+V2/yCTpZnbuch4ZfeJsHifmSSdHLSQh6AHi5uvxh+wis22ipjNqgxOIBRVEfU 3/HQcbICQzJMAAcAOob5GnxiNXf+Wt46uPC/qUeBrqZAmBK6gOOnIf9ACY2onigD40lZ V7VlYZAcmWwc8gYdnIaacIaNcSvk9P+xVgct0Dp6y0XwWXw5vhudoWUkXmRbvKtfJSyp xhqw== X-Gm-Message-State: AOAM530wPP7OdMOCzVthiIaUITRJcDIObdfh5lJ9bC9JkVEmCaAr0FO4 5TrUSgRz8V2robr3jRAMGRxKbuOkQQH0kpO8 X-Google-Smtp-Source: ABdhPJzcyW0JOvz+UHpOW5ycWqFJpnuY9lea6LHo3+WJZzuqSIqv0bdGRqXrqnlG7UJm9dRJJM9UUg== X-Received: by 2002:ad4:42a5:: with SMTP id e5mr23875120qvr.37.1608136026358; Wed, 16 Dec 2020 08:27:06 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id q27sm1344626qkj.131.2020.12.16.08.27.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:05 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 06/38] btrfs: do proper error handling in record_reloc_root_in_trans Date: Wed, 16 Dec 2020 11:26:22 -0500 Message-Id: <0ce7243af178dae7f029f5a2513a230bf8859328.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Generally speaking this shouldn't ever fail, the corresponding fs root for the reloc root will already be in memory, so we won't get -ENOMEM here. However if there is no corresponding root for the reloc root then we could get -ENOMEM when we try to allocate it or we could get -ENOENT when we look it up and see that it doesn't exist. Convert these BUG_ON()'s into ASSERT()'s + proper error handling for the case of corruption. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 1c36b10fdd02..0eea27d9e3cf 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1971,8 +1971,27 @@ static int record_reloc_root_in_trans(struct btrfs_trans_handle *trans, return 0; root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, false); - BUG_ON(IS_ERR(root)); - BUG_ON(root->reloc_root != reloc_root); + + /* + * This should succeed, since we can't have a reloc root without having + * already looked up the actual root and created the reloc root for this + * root. + * + * However if there's some sort of corruption where we have a ref to a + * reloc root without a corresponding root this could return -ENOENT. + */ + if (IS_ERR(root)) { + ASSERT(0); + return PTR_ERR(root); + } + if (root->reloc_root != reloc_root) { + ASSERT(0); + btrfs_err(fs_info, + "root %llu has two reloc roots associated with it", + reloc_root->root_key.offset); + btrfs_put_root(root); + return -EUCLEAN; + } ret = btrfs_record_root_in_trans(trans, root); btrfs_put_root(root); From patchwork Wed Dec 16 16:26:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BDECC2BBCD for ; Wed, 16 Dec 2020 16:28:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 29F3A233F8 for ; Wed, 16 Dec 2020 16:28:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726725AbgLPQ2T (ORCPT ); Wed, 16 Dec 2020 11:28:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726723AbgLPQ2T (ORCPT ); Wed, 16 Dec 2020 11:28:19 -0500 Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4129FC061248 for ; Wed, 16 Dec 2020 08:27:09 -0800 (PST) Received: by mail-qk1-x734.google.com with SMTP id 22so12826952qkf.9 for ; Wed, 16 Dec 2020 08:27:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q72SsyFPmd92BdpyPLFGmykrVJ0f82G1Rus+LCwtD6s=; b=jJxOsCRxgjoaueUI9LC1VAdtHooNzzJDi2oDRzNof0dIwFZ6Qs9nz9YUvfaXoHXHnQ zV9khHLU/UW17JjEOuHCEGFFouYeeYUc7DZv1JxqJMLmKtbHWYX5/dVqhMR40u1JJ1UY mB6wDRugrMYpqJzf1LEtFs52zS/YONwIy6tZ8vG+D9ZpDsGg8tsqxmbEVwQh7httpKzv 7dcOO+yzgF2QOKWNcaFUQvB8+V97j3vm7v3uilmVFtlTIvO1jWL7N+eJLAYkjM/+LVox CinuXJH5eA0fYhXH/X9PMOjKi3gU53ASoju9MIh5nbXiVnwmw72j7NEAl7SHA2XsS2Xe bFrg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=q72SsyFPmd92BdpyPLFGmykrVJ0f82G1Rus+LCwtD6s=; b=MmauwYKFBjKL014LVkM3LIkcJAuA4C/KkoA0CLUIzxPyvM7Iduc/LXIqF3977sSPDj ZPeXg89YxeFkiqOZEEKm7v/65lExmEuTjXRrak8WPCFHsAOYsbxQ65xtC/Sp1eGT0Eju CHOKM9YE5322dYpukkkR1X0r/8KJqcT/L+o/M1ezvlLGWXXFfnF13QteJYFx/z1kqjlx nc5/b8aXbufFDH0lFJ7kDTKP2StHMQBZbPS7YXdVMR5orO8EEeLZB9UUFsyqHZcoz7J4 ofjqKoNjMiHlT5QzMpd4xXzLLvcTxYEdzr++E3V8UZ7cZNoYdJ+rhPNaonCIf4PRteW8 tByA== X-Gm-Message-State: AOAM531G4w4yNUbq5RLj8KGpFFg93V69qp9OkSEj0E6WjpG5UCqzxw+7 FvIz/IBpZ7aGdJqdPD3IrHbFrvPDVYuSldjW X-Google-Smtp-Source: ABdhPJxlhV36m4PwNJbTMzsXWzw5uVLYFXuMk6Tx8Ud3UGmD+WSReTo431L7cYApKWPU68bWBBE+Ag== X-Received: by 2002:a37:8d01:: with SMTP id p1mr24526965qkd.31.1608136028178; Wed, 16 Dec 2020 08:27:08 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id v1sm1381390qki.96.2020.12.16.08.27.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:07 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 07/38] btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename_exchange Date: Wed, 16 Dec 2020 11:26:23 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_record_root_in_trans will return errors in the future, so handle the error properly in btrfs_rename_exchange. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/inode.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 070716650df8..2f8bb8405ac6 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8897,8 +8897,11 @@ static int btrfs_rename_exchange(struct inode *old_dir, goto out_notrans; } - if (dest != root) - btrfs_record_root_in_trans(trans, dest); + if (dest != root) { + ret = btrfs_record_root_in_trans(trans, dest); + if (ret) + goto out_fail; + } /* * We need to find a free sequence number both in the source and From patchwork Wed Dec 16 16:26:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4802C4361B for ; Wed, 16 Dec 2020 16:28:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B38C8233F6 for ; Wed, 16 Dec 2020 16:28:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726733AbgLPQ2V (ORCPT ); Wed, 16 Dec 2020 11:28:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726707AbgLPQ2U (ORCPT ); Wed, 16 Dec 2020 11:28:20 -0500 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58D07C061257 for ; Wed, 16 Dec 2020 08:27:11 -0800 (PST) Received: by mail-qt1-x836.google.com with SMTP id a6so17599264qtw.6 for ; Wed, 16 Dec 2020 08:27:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=41DzNviF+cXvKLLpMN146LL13hp9ctwVOiWwtInzkqY=; b=OJ3erirXzpjnjFIXcPpxPuS/WsGUVGwJIHA7Wt4UXKFtTRcAcHarrrU+J2IPjlzIw3 r8KhTSaMEbyBKjNdb2HOdjQVuyECA3K9tC9cNNGR2V8bkhKZE2LXbQ5/JPlSWjero7G/ F9flg9ffJwme8W10bss2cp1Rem7EpO5p0upaeetmTwCJZko43bWau4AYAManiPiqqD83 NmfaYWL60i8RnprPXooUulcSKFYBtnoS/nFgaXbGaMOFnhgkVnSS8UUZY3ZE0KTCV7xV pr0p8jSNhfRVuwaJpqsrK4Z1jjaVXA2cflYMSbHui3d91LtLyRuGfKH6Tt6wdGnPT0bt FI0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=41DzNviF+cXvKLLpMN146LL13hp9ctwVOiWwtInzkqY=; b=jgl+SYKAiaUS5srgWpSJceISUseREXIfzBfgtUFLuLuxB0UnrPQPibq4+tqOf9oB7V vT6zwXT1QaksnssUyNfjv1tU43hXHz5HbyKX9zisDPGJ6rs3mtkNqjeizDS21ZPuz/Lc BGEyWvc8joWQ+2Nx8U9FjlatmkR0SSnBwHY1Xvod9QeSlFORqDE5tTEPy3m28hm6B5+J K7QZpSGW1evu6gKmutOEU0gMYihQI7AkRNgUhkNwcpcW59eUwBCWVRW+xOtZYDXU24XI FMV+UbssHnNGHKeASKzZ9as2OpUKskIKxC5Z3GSX8zcnXygcvLx/4B5BDkZmJejhKPI9 8beg== X-Gm-Message-State: AOAM531tZIfbG2kcSvz40K8/zL2IRqiVYMqyj6G6FqPKB3RIvN6VG0oX e+2yomdjUibBNvnIINHcfRE1/Oe94xoI2fwp X-Google-Smtp-Source: ABdhPJw8+QV+oFKFg6NNDcIOi31v5qYy4ANQAP5GB/GiQKUv4Kzm0wTy70+Kv3trp69XOYFN9XiO2Q== X-Received: by 2002:ac8:5d03:: with SMTP id f3mr42779538qtx.229.1608136030323; Wed, 16 Dec 2020 08:27:10 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id g18sm1207198qtv.79.2020.12.16.08.27.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:09 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 08/38] btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename Date: Wed, 16 Dec 2020 11:26:24 -0500 Message-Id: <4ebf0017342ebf0810de73039da233791b7386d9.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_record_root_in_trans will return errors in the future, so handle the error properly in btrfs_rename. Signed-off-by: Josef Bacik --- fs/btrfs/inode.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 2f8bb8405ac6..bcbae8b460c0 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -9205,8 +9205,11 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, goto out_notrans; } - if (dest != root) - btrfs_record_root_in_trans(trans, dest); + if (dest != root) { + ret = btrfs_record_root_in_trans(trans, dest); + if (ret) + goto out_fail; + } ret = btrfs_set_inode_index(BTRFS_I(new_dir), &index); if (ret) From patchwork Wed Dec 16 16:26:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AC41C2BBCA for ; Wed, 16 Dec 2020 16:28:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 363E7233F6 for ; Wed, 16 Dec 2020 16:28:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726736AbgLPQ2V (ORCPT ); Wed, 16 Dec 2020 11:28:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726730AbgLPQ2U (ORCPT ); Wed, 16 Dec 2020 11:28:20 -0500 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 210C8C0611CA for ; Wed, 16 Dec 2020 08:27:13 -0800 (PST) Received: by mail-qt1-x829.google.com with SMTP id v5so8357791qtv.7 for ; Wed, 16 Dec 2020 08:27:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xGNUuifwBsvHD2zCYX/FZac+Jy1QnxNpjtDrlcuIIEE=; b=ROO13qR7/At/U4xipRVJyHXi1h/LoawKvJ5FCeAow6qiUArgEDuc8A+Kju9t2Sfp/c mS92M/GoSLEmvXhGUuXah8Xs0qErrxtFu+rBB+NDC3VEYt1XohT+SxKm2MY0arafH57/ xOxDPiL9eBy/AKlPvveFu/nlXxmCKWyYnfr70xvloS3uHP+ofmfy85tUrg1kjFL2l+4B b1TIm0VNBidf+st4j7rmAIC9eODn0COIOUJxH23o8EMw4FZXlPyyO+mfepmZQmH9G1lj okB5X/V5WrhOowD8pSr5kwyAn7xHns95I10jeqb6bdWm+lYmnPypOl4WrFyFzOwbDdOz kzqA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=xGNUuifwBsvHD2zCYX/FZac+Jy1QnxNpjtDrlcuIIEE=; b=mjWgtyvn91Rj9efwkEGlCksHfpgfCUORQYFvGkoolEUbPn/sDpwSSXCb0exldq6kwX +xdwcNiZcRRVjy0yNr3oofA2EpkuayE6XIw+VD3KO0USnTUxvtlmuvyDmXZcO90WboQO SJA1wbgYjHJEroqthQmTnTCYvxpfQ7etm81FesSQUlxPp3tz+w2BNRHdnjEgEmQ3raGL IoJdb4ALvW8QZcrpWAsSccF2aWQ5M9YKpNsvcofrVI1jbwmvDf9U4uHMOI9FGmVPtX3E zILwHQ4VMM4CFH5UuttnE6zFOen87U9xEoZ7eOagLhKp2QPeJwjbi7Z3dfpNAXclslwY HAPg== X-Gm-Message-State: AOAM530g98a1ymmieHCuqsOOXA8Ipcyur/xD5HdQLfi9SPgrn60Mqy8o DLykIiCzXpasVo7yr/Tt/YCroOQVRL9PuYpf X-Google-Smtp-Source: ABdhPJwKlveNO5sNK7VtbmPgvWjp8x5bOOo2W31NsmxEPmMk0zWS68LadXBgMqQNamWgPiYkZ/DEgA== X-Received: by 2002:ac8:6f12:: with SMTP id g18mr43654876qtv.335.1608136032073; Wed, 16 Dec 2020 08:27:12 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id v137sm1406257qka.110.2020.12.16.08.27.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:11 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 09/38] btrfs: handle btrfs_record_root_in_trans failure in btrfs_delete_subvolume Date: Wed, 16 Dec 2020 11:26:25 -0500 Message-Id: <9acda92afbbba43a3b0185da96ea3b9c12b1750e.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_record_root_in_trans will return errors in the future, so handle the error properly in btrfs_delete_subvolume. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/inode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index bcbae8b460c0..7a8d89e1b73f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4175,7 +4175,11 @@ int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry) goto out_end_trans; } - btrfs_record_root_in_trans(trans, dest); + ret = btrfs_record_root_in_trans(trans, dest); + if (ret) { + btrfs_abort_transaction(trans, ret); + goto out_end_trans; + } memset(&dest->root_item.drop_progress, 0, sizeof(dest->root_item.drop_progress)); From patchwork Wed Dec 16 16:26:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD851C2BBCA for ; Wed, 16 Dec 2020 16:28:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B06A233F6 for ; Wed, 16 Dec 2020 16:28:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726741AbgLPQ2X (ORCPT ); Wed, 16 Dec 2020 11:28:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726730AbgLPQ2W (ORCPT ); Wed, 16 Dec 2020 11:28:22 -0500 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCDE9C0611C5 for ; Wed, 16 Dec 2020 08:27:14 -0800 (PST) Received: by mail-qt1-x835.google.com with SMTP id z20so17597954qtq.3 for ; Wed, 16 Dec 2020 08:27:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UP22N1wW4BouddiNGmO6P25lyeEkJRg0GBlKgir49N8=; b=G3dx9LVFAG3YfG1c08cw07KodN+3pH3sOFE0w5beBS1yCG3mckSey8eL5nlIS2nDQ2 fK6QdKgR1QxR5Migs1kOlH8xVregs4bEDaxYW/S1Ye11yGjVe1cwFg4UiiOdMh91yVNf TDh4xWMJa0AMQR1FISuLnX59rZTAfKj4jsFRkFOskblsSVztiJPFy2+8cR7IGu3FDFr1 5QPt9ujcYEJ8HKOX7Yg7WXiqnaHal0JhCsntufR9d+jVA8U4leW8ESOfupFZmxtOMSi/ UIFGayHuZd9LT7voedBGtB92ZWLDkg08JXC5r0lln1oD9JR8FfWIVzc/kA4vLW/M1RFn 6WkQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=UP22N1wW4BouddiNGmO6P25lyeEkJRg0GBlKgir49N8=; b=drRi/9J+4DXadnn5kIYMH5p5RiEu/ASUGbMGFEvQ1d5dg1Y7xJRW9R1Y0p+HX8H1Qx 12SN2YL1CYr8z0LBbRNdr+WtFtLQ2osbkS1GFVY+ujBiiwm5SeDX2KJIhPjdVtPBoibM 5+ZVHtwpCw4SK1NaLWd587l8Rp2MiaUdrIMJq2hXCBU4rhDeqmt+uBQUlhI+gnqtPXa/ U5PNyLXq13l8jYn+q4D9WfFeNE4YtFiM5Qh4b4wiB/htEd7etoFd74uiF2Jh6p97cjED zd39fNTu7T4GNHfRwYmnMDXAB3VH3Ea9rPRa7hlZzy5V+5CjbzEgSqUiseHzlyHkauo3 oUyw== X-Gm-Message-State: AOAM531J3FTYIH1FzbOoedP42fOi/tdRLL1g4GOuuoDWlezjlGUxmnbj sMPhtCuUc/D2Ue8rkjMH9XnkvV/8eO8UYykM X-Google-Smtp-Source: ABdhPJwgxm2x5L8rUbUr58LUUqqGk/6etlx+qBAXMdAG1Xure58B1hT+UhtKAeV0NAAgUKxa++0ujw== X-Received: by 2002:a05:622a:14e:: with SMTP id v14mr43867447qtw.298.1608136033816; Wed, 16 Dec 2020 08:27:13 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id a206sm1360542qkc.30.2020.12.16.08.27.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:13 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 10/38] btrfs: handle btrfs_record_root_in_trans failure in btrfs_recover_log_trees Date: Wed, 16 Dec 2020 11:26:26 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_record_root_in_trans will return errors in the future, so handle the error properly in btrfs_recover_log_trees. This appears tricky, however we have a reference count on the destination root, so if this fails we need to continue on in the loop to make sure the properly cleanup is done. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/tree-log.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 254c2ee43aae..77adeb3c988d 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -6286,8 +6286,12 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree) } wc.replay_dest->log_root = log; - btrfs_record_root_in_trans(trans, wc.replay_dest); - ret = walk_log_tree(trans, log, &wc); + ret = btrfs_record_root_in_trans(trans, wc.replay_dest); + if (ret) + btrfs_handle_fs_error(fs_info, ret, + "Couldn't record the root in the transaction."); + else + ret = walk_log_tree(trans, log, &wc); if (!ret && wc.stage == LOG_WALK_REPLAY_ALL) { ret = fixup_inode_link_counts(trans, wc.replay_dest, From patchwork Wed Dec 16 16:26:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA5A9C2BBCA for ; Wed, 16 Dec 2020 16:28:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 86E16233F6 for ; Wed, 16 Dec 2020 16:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726745AbgLPQ2Z (ORCPT ); Wed, 16 Dec 2020 11:28:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726737AbgLPQ2Y (ORCPT ); Wed, 16 Dec 2020 11:28:24 -0500 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70CDFC0611CC for ; Wed, 16 Dec 2020 08:27:16 -0800 (PST) Received: by mail-qt1-x834.google.com with SMTP id g24so5194498qtq.12 for ; Wed, 16 Dec 2020 08:27:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=rXkllivM/LlDIU6qMHpbw+hMYUQ5EKZq1LEuGXDx7tg=; b=Bk5S592a/a6bstIEbfiRCoS0ZX1xLA/M+YU7KdaMzwfQv9NUeX054gXdVbHcKLLA1A Nra3r30YjgiOAhtCjsRbsGpe5lDF7cByBrTgp3SBoreOD1viqVdze5P/hhYG7qzgwZ5X xTXyWSYaBGHDXUj2OxItVoO5PlEjWfYuWzrReNX0AUU2Js56xQBJSvOtFmgqCR/LRFLE eKDKl7mDqj1Tuy9cK0fZBfhGnsASXCGQkaTQFTr+e8XaVB2qK+rcuv0LmLMMZ+QZ1+FJ dgiWlMJaLFXGXFsD/RsovbIhQMfcC8szeMpHeuAHFsUn2btye6AaERqaqTpp0OeecxFV apog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rXkllivM/LlDIU6qMHpbw+hMYUQ5EKZq1LEuGXDx7tg=; b=BLZlvA8AjTWLdr4OSIWhGzGjPRcjNup1CJDn8QVX/7uyJyzZN6nYC2Z8UB1GDC5Jof VbH0q0p7dkihYDx28XPFTx32I0GlxynjBfADu4QX05qOpfEbf0k1yrzn5wLPzb2kDgeH IOy1cvm1RY/ZmPF8yqSQMAkgJVw0k48P+m64V0+atmkUtOTVEo62JsFW/iLiSfPJdbRY nty8M/E8CLr+uYYLBay2Y+wrnsmdV7RpJ1bC/WnxDVi23Zw+wJuw/hI0TEVr+NMXEcjE llaD9PQSuHh+YTKt03IvY9sR1MywvYHZIGHKFqt4SuTSsk54EaZFpUFZ8XvuT8+8Gx59 jIrA== X-Gm-Message-State: AOAM531rKbj/i/D/7jBE6g9qxnYXxaMjtEzB5iUkBA5uwnn8EcXzGPL4 fiYvF5OOS7VaO6p4zKB0j5/ycyRlBtlFM5jB X-Google-Smtp-Source: ABdhPJyw3bAlny92qrLpd9ag4M86Ul2Jc9EVR12oUJiqy0lQ8i/x3IoD6YuSitBqmFTZgHHBdL+Qqw== X-Received: by 2002:ac8:6f12:: with SMTP id g18mr43655127qtv.335.1608136035443; Wed, 16 Dec 2020 08:27:15 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id o4sm513851qkc.93.2020.12.16.08.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:14 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 11/38] btrfs: handle btrfs_record_root_in_trans failure in create_subvol Date: Wed, 16 Dec 2020 11:26:27 -0500 Message-Id: <15ada5c3cf18400d11eb0ae0c0fa2e54f4b9c87c.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_record_root_in_trans will return errors in the future, so handle the error properly in create_subvol. Signed-off-by: Josef Bacik --- fs/btrfs/ioctl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index af8d01659562..2d0782f7e0e0 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -714,7 +714,12 @@ static noinline int create_subvol(struct inode *dir, /* Freeing will be done in btrfs_put_root() of new_root */ anon_dev = 0; - btrfs_record_root_in_trans(trans, new_root); + ret = btrfs_record_root_in_trans(trans, new_root); + if (ret) { + btrfs_put_root(new_root); + btrfs_abort_transaction(trans, ret); + goto fail; + } ret = btrfs_create_subvol_root(trans, new_root, root, new_dirid); if (!ret) { From patchwork Wed Dec 16 16:26:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A43D4C4361B for ; Wed, 16 Dec 2020 16:28:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B834233E2 for ; Wed, 16 Dec 2020 16:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726744AbgLPQ2Z (ORCPT ); Wed, 16 Dec 2020 11:28:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726738AbgLPQ2Y (ORCPT ); Wed, 16 Dec 2020 11:28:24 -0500 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1445BC0611CD for ; Wed, 16 Dec 2020 08:27:18 -0800 (PST) Received: by mail-qt1-x830.google.com with SMTP id z3so17577156qtw.9 for ; Wed, 16 Dec 2020 08:27:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o1a/i2ebfj7XryAaYFFfCcSOcCjKuzkVEMBMoJ5ESD8=; b=WA96J8ZPIWDVsQYRymZqh2avDdyUeCX7XAoZmcrkOlcoi09q58tIfddj38loWwWgzY XboInPm2fntYyKDy8g/w6bLtA3+zXT1JvBL3O1gPjdSX94FO41vTEn/eLYegVw14oCy6 dnJH43xOqg60V8CB3Tk5NPwsEgTv8Exk6E6VoEP3/HA/zQXd8AyfMStCLf+GQRj0eSwQ SsZyIR0z7EvQyW+Ul6poohUxWu5P1mzbKW/h8cqjSMYE7/SgW9zUamnYjOTADef+mTuc 18gxGgL8zuxw0tzL+De4R/nrxQveqeptsWT/D9B5F5iqSGgb65DwhsyEOiNahk+/4ZIN TfTQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=o1a/i2ebfj7XryAaYFFfCcSOcCjKuzkVEMBMoJ5ESD8=; b=eYWpGKuWSn0Vqd3+MSFTuRv7lOGvSW4SpWa/2byz4SXzUITOKjy5lqstzQw9wWWp2a jrQ/DRDYoVCGDzcWwpZVijsBFLcVHUU83NTlsJALs67pGNb6OAr4hZFOy/OdgoXT5Mp+ m7KYAQnenVZTVKvsKxkltk/4+ImmW1IxGNvIFWnysJalaGxRQc0oUBXQ9aKLGF+j+BW7 DA58bFuKuZC4tRDi1hQtDUcmjaFDSyAEbk7FH/jO8qmxOK+Q4riWTnkexyovHTpJ8gvM 7FfnNRNuJp0YQKAgx7gmA76yrdMJHL97vPskjQD795k77JC15ieDc+eO1CpooQXyyTWX UiYQ== X-Gm-Message-State: AOAM532n6JpOK8PRsbFjJWLa34FKhTOYT6pKVZE4Y5epb9+biZX8WRlx GBnbNh7XGqQRB1ZGKz6/d6S8Fw4UObO5dxMs X-Google-Smtp-Source: ABdhPJwzw7swUbl/AmpOkJhe3WPo5R1QZakPp4FDSXu68LQMhHpBn+oAY2RltWKXU1AOsb4TSGXFWw== X-Received: by 2002:ac8:4648:: with SMTP id f8mr42708666qto.5.1608136037005; Wed, 16 Dec 2020 08:27:17 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id l1sm1247927qtb.42.2020.12.16.08.27.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:16 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 12/38] btrfs: btrfs: handle btrfs_record_root_in_trans failure in relocate_tree_block Date: Wed, 16 Dec 2020 11:26:28 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_record_root_in_trans will return errors in the future, so handle the error properly in relocate_tree_block. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 0eea27d9e3cf..7e3305aca6ac 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2548,7 +2548,9 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, ret = -EUCLEAN; goto out; } - btrfs_record_root_in_trans(trans, root); + ret = btrfs_record_root_in_trans(trans, root); + if (ret) + goto out; root = root->reloc_root; node->new_bytenr = root->node->start; btrfs_put_root(node->root); From patchwork Wed Dec 16 16:26:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F2EAC2BBCA for ; Wed, 16 Dec 2020 16:28:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C9A9233F8 for ; Wed, 16 Dec 2020 16:28:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726722AbgLPQ2S (ORCPT ); Wed, 16 Dec 2020 11:28:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726707AbgLPQ2S (ORCPT ); Wed, 16 Dec 2020 11:28:18 -0500 Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB025C0611CE for ; Wed, 16 Dec 2020 08:27:19 -0800 (PST) Received: by mail-qt1-x82c.google.com with SMTP id g24so5194655qtq.12 for ; Wed, 16 Dec 2020 08:27:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CoE53/nmnjHVbpSZTX5nmeCiKBp2mQN7wYzsWW/xfp4=; b=fsI/CBfVTtpQ/10tkRTwziqvZjuWuKCUVAcDoxpzYf9qyYHya1ubafnYWBL14gVZTC lOktcvngdfksWZyoyjD0t+SqAfoMAgVFFVc1JZvR3T4FVxpIfSZiMcJaGJZgOEFVcxEz C28Yh878xbUh8uIE2wXp7PaBE5+uCO63PdzV3P/VEabi201VipTANbLMPfWc735noyTL oOzrUaCC+nbLbonnc24fSDNUaVvK8XqTpmsIiEhnRdhOwX+su3FhijmNhtjQftDEkXhK cKQ2DfvwzJwi5ZlNFzqRvgeK4RArDvCHrkTiwgcHmI5I6wEX6xxzcXoVz45UGdflsFTm XqrA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=CoE53/nmnjHVbpSZTX5nmeCiKBp2mQN7wYzsWW/xfp4=; b=qbjWBwB+b6yGD/v6UkD8OvFuXlb8insPjdUAJK6TNpVll6SatokoZOkkVIoGLU9aex v3xgP47UGmgWc7NHfnQjXTeY5kZWczCBk+TvH2608mOdESsSN1ndrKwegxRnKuknnlbg u841MmaxknzXC8XXaQXR4glclbSYqBsttpyNBBZih4PCV2e6UPXkYJZJU6QGCrKphxcy Ru5edKqY1Bm61vedvA79+PtfZS5ptb4vBjw7F9TmAqp6wlb8gXjMpaidtoer2ivfjkGX a4e0oKiFCP40+HWEP8HpZq5UIR4zFirbYqQ2rby0VJmyvyhj2Hk7+km28tn2xks7bAWA cJhQ== X-Gm-Message-State: AOAM530E74O5SxGUDL23TEVuOfDMTtqWAXx5hc8LyLJITKqvpDt/abbX GKqwHF+LV7+HfN/qe4k+7k8lTJ4zcShJf4dx X-Google-Smtp-Source: ABdhPJyZxyM1s+ktUSpQVcEReGcy7S0eqEoELrTEjVT0liEBqAerWrEifvdHjm21HO/duWp3oKISJA== X-Received: by 2002:ac8:6947:: with SMTP id n7mr44440131qtr.83.1608136038780; Wed, 16 Dec 2020 08:27:18 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id d190sm1380071qkf.112.2020.12.16.08.27.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:18 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 13/38] btrfs: handle btrfs_record_root_in_trans failure in start_transaction Date: Wed, 16 Dec 2020 11:26:29 -0500 Message-Id: <33513c6f189db9338a71550fa93a3ca729fe3c40.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_record_root_in_trans will return errors in the future, so handle the error properly in start_transaction. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/transaction.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index eba48578159e..307a73abe86d 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -734,7 +734,11 @@ start_transaction(struct btrfs_root *root, unsigned int num_items, * Thus it need to be called after current->journal_info initialized, * or we can deadlock. */ - btrfs_record_root_in_trans(h, root); + ret = btrfs_record_root_in_trans(h, root); + if (ret) { + btrfs_end_transaction(h); + return ERR_PTR(ret); + } return h; From patchwork Wed Dec 16 16:26:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90586C3526F for ; Wed, 16 Dec 2020 16:28:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62FBA233E2 for ; Wed, 16 Dec 2020 16:28:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726769AbgLPQ2n (ORCPT ); Wed, 16 Dec 2020 11:28:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726763AbgLPQ2n (ORCPT ); Wed, 16 Dec 2020 11:28:43 -0500 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D436C0611CF for ; Wed, 16 Dec 2020 08:27:21 -0800 (PST) Received: by mail-qt1-x832.google.com with SMTP id 2so7751418qtt.10 for ; Wed, 16 Dec 2020 08:27:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9hOXGC3DnsDO3Kd/HEm9Zs86pTFCYvHzCaxadXwdWVw=; b=DjhYC+2XCpoXR8NUqSNphVIeBagZnVgJ3q4SuPCcmMwBeiccQBeeQFQd5KQ5qp2cGI 0KytnGLVkCZ6J9+FZyPQjF8qNNlbcWLl1s8MeLpvWaeb3kJbxoKbFDGOhvI10xyF/KCD M65sBY3vT9eMkIPMkpxAKunmWqJDx+wSUOsxhr4kWOVMmWFgEwSwrA8Wcb/7vzBNGdlV hjJWT8Uy+CJhYFWWJtDu5U8FE8yHRYQ8+UM/wBDDkcXRmZUR/k8lbPboxQt9byLZwj4O YbnCQNo3a4B/aY67VncFhoIj1YpQmweDmbsQRcKgJaAwthCc61VDd7dfA0chYlcCYP7R wr6A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=9hOXGC3DnsDO3Kd/HEm9Zs86pTFCYvHzCaxadXwdWVw=; b=lja2xYmukfkeeY/bKtexrh4hC8R0CtwqyjTw2zVKpnxVNU/76hB8aD29godH0QyVOB caBbBD1asitF2+JXVCrQvHDyldc3FlF4CEB1a1W4BGV2oqg6JZblLcMJa/av4R+05dkY Dy357yMQP5GWQ/ct33XGkzPEGJXu/9oZyZT3fAigkPpM4vDMlgEC2BWgW3XSI6VmkPE9 2aCFVn17TEK9r6Q2d00WW72LglSse6EUtw5IO6xOPj708MDCOtksRTyRjOoPSVbQ8UI/ sqagpFH1oOEECUo9VrmGtq+9pLyX1eWFaKf6RzFtBr4Ve3PnwTMclezQ2Hx5UVuPhJie 67Tw== X-Gm-Message-State: AOAM532wjnem0jxqHyYzq64DwLJMIhQacVfI7fGs2kqdDU3d3LctOipT /C9gPaV1XTs7w6GeWltLt76UXdQRBP2v5krU X-Google-Smtp-Source: ABdhPJz+Znlk5UrAi4TGbWc6U1u4I4Qljj3+PSA4NkcoqKZmYuSYubEjXCZGeneCunscmG1h/HNFOA== X-Received: by 2002:ac8:6bcc:: with SMTP id b12mr30210928qtt.55.1608136040399; Wed, 16 Dec 2020 08:27:20 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id m8sm1418983qkn.41.2020.12.16.08.27.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:19 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 14/38] btrfs: handle record_root_in_trans failure in qgroup_account_snapshot Date: Wed, 16 Dec 2020 11:26:30 -0500 Message-Id: <07dce3dd12b43dd0d6860c54e1eec87543cd7212.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org record_root_in_trans can fail currently, so handle this failure properly. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/transaction.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 307a73abe86d..5b3008ec4e13 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1436,7 +1436,9 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, * recorded root will never be updated again, causing an outdated root * item. */ - record_root_in_trans(trans, src, 1); + ret = record_root_in_trans(trans, src, 1); + if (ret) + return ret; /* * We are going to commit transaction, see btrfs_commit_transaction() @@ -1488,7 +1490,7 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, * insert_dir_item() */ if (!ret) - record_root_in_trans(trans, parent, 1); + ret = record_root_in_trans(trans, parent, 1); return ret; } From patchwork Wed Dec 16 16:26:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D9DCC2BBCD for ; Wed, 16 Dec 2020 16:28:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC49E233F6 for ; Wed, 16 Dec 2020 16:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726747AbgLPQ2d (ORCPT ); Wed, 16 Dec 2020 11:28:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726535AbgLPQ2d (ORCPT ); Wed, 16 Dec 2020 11:28:33 -0500 Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B2E0C0611D0 for ; Wed, 16 Dec 2020 08:27:23 -0800 (PST) Received: by mail-qv1-xf2d.google.com with SMTP id l7so11606487qvt.4 for ; Wed, 16 Dec 2020 08:27:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=57E4O92Kk5NHxfOb+zeLfEAGt+8uI+0goGLtIs7kD/I=; b=xx3AZSHJXeJU77DZleUvpxyxC0SMl3AQIXcJVoJO5x557POI0/NTtflwcbNVwaBY2U Vk+Xr8WmueB6xdmfgQmyPZzvmstRiAG8xMd5eNfYKNQVU0N0ENV5b5v9tNdxAu2wfJiB FYgJxcz+HSk/KNF4FeQ1QINZ4JNqgG+dhJzkWm+YpSPAKMGxpslw57xun1baWp/Rt83d WD4gs926x+agwMEQ3jqSS76N5r0wtqf6n/d/nEkzHhIVEvWEUlH6ELxpbKMXRzOhlENY ZociVMXDyqgYL7aJ/XoOTORxGBL8sdUzlqf31mWThmvsObWBdGLDcGWBLIPc8wgJQMbO UZxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=57E4O92Kk5NHxfOb+zeLfEAGt+8uI+0goGLtIs7kD/I=; b=Hsp1sUj2RfJsaoPNA4I/ZUi0lHQOmLkdwSUf3t0mxts8oWucKvHau8p/ixuDPGwq2H uqlWmGE7RzQKifbdF8docoLTysHfp/ohcGn0pthDPdGlIsiu5dRRsEmO6mMihCqph+va 2haS0VQ+gHOGw5xIGmevclYJQt1Qlj/PFwJGZ9+NitamhwGNxCe2kdYcefochFTQU4ul MZgB3sOMjUYmJrY6fgkVoSREO6JRN5ZPvKELu1AdBW7R4AGx4/SVYg/6E25F8ec6o+DR 38FCW9bcI7xZqk3m8PibJu8EHnfVkK8dNJnsF73Z1RdP5WpBgYd/ILZbxJ5isn58OHXf 1sIg== X-Gm-Message-State: AOAM533XAqb4jJY+5mKYVPhLQu4DLkzc436RSx2fPvl/iKTUWmnk2Cwg hC63zjT6udufWDVh0PbOGiYZGluw2lp0hk6u X-Google-Smtp-Source: ABdhPJxxQDfYDdoQZQZcsCsCX3QbCRutfBKX+v7GoDgI/FO9cFyBStmiTKouoBZGnO50FXjDDsvsww== X-Received: by 2002:a05:6214:10c6:: with SMTP id r6mr43252446qvs.44.1608136042289; Wed, 16 Dec 2020 08:27:22 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id o4sm1205193qta.26.2020.12.16.08.27.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:21 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 15/38] btrfs: handle record_root_in_trans failure in btrfs_record_root_in_trans Date: Wed, 16 Dec 2020 11:26:31 -0500 Message-Id: <5aa1ecd6b47f366cf145d10944f02bace7a337e3.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org record_root_in_trans can fail currently, handle this failure properly. Signed-off-by: Josef Bacik --- fs/btrfs/transaction.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 5b3008ec4e13..4efdb87df27d 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -480,6 +480,7 @@ int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, struct btrfs_root *root) { struct btrfs_fs_info *fs_info = root->fs_info; + int ret; if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) return 0; @@ -494,10 +495,10 @@ int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, return 0; mutex_lock(&fs_info->reloc_mutex); - record_root_in_trans(trans, root, 0); + ret = record_root_in_trans(trans, root, 0); mutex_unlock(&fs_info->reloc_mutex); - return 0; + return ret; } static inline int is_transaction_blocked(struct btrfs_transaction *trans) From patchwork Wed Dec 16 16:26:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977955 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C63CC4361B for ; Wed, 16 Dec 2020 16:28:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24CBC233E2 for ; Wed, 16 Dec 2020 16:28:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbgLPQ26 (ORCPT ); Wed, 16 Dec 2020 11:28:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726780AbgLPQ26 (ORCPT ); Wed, 16 Dec 2020 11:28:58 -0500 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15051C0611E4 for ; Wed, 16 Dec 2020 08:27:25 -0800 (PST) Received: by mail-qv1-xf33.google.com with SMTP id h16so7179927qvu.8 for ; Wed, 16 Dec 2020 08:27:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U3ibYZhMwxw/1VXxtPFoqzKcxQU4zMIzevD0bFWZZbw=; b=lzvHphS9Nt989SsoyE4Z4be6A1mdMZSjDERMKnaIAwDtq7PBl4IetlMjMKgn786/6N loBcsnt5Ya+AuELdjVHEDVCaa+ESHd3Coo9KJg4QSKs0F9dgK4CzThxrbGyZxw5QfsTg u+qvuGXZDU7xAp8dul+mzXS6Eg4vOHHMkJ8reDd9Pt9jgn5VFzF6JcNlf/Lne7nHTFEw mMAFoByvpl0FAPLfLYQ6TClWV2iDiMlyqqgcblYhw1KK9EaGcf4/ourEgBa12VTWXBfA b7QsjUAaNUldRRhwn0eJhnFuFGAe2y++H4fPjTUhSD0ZnD+cnntXGzSV02qp+PgFgEWc ZMBw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=U3ibYZhMwxw/1VXxtPFoqzKcxQU4zMIzevD0bFWZZbw=; b=WH7gjJ24yWBSEwrlYYqdgRTuUOLNxK7gEtpwitm0TR35UlvJMO6QBHL2tqbromPsWM qnmzVSputZySIayixsZn/kmhRhJuB3GqNfDOtvfXmi8Wxr9C9EfFlip/zGOOWeGwahPr hkS8n4wZ7/reYygVyuToDh8WtBi4PmUdwe9KDiy9qdlbEUzNb2y/1FGySNchy48krHYY dnp2j7iP9MwiufPWCdeRSTz9EqmnOVhWRT+1cu4NYhbI3jTeAaVyzBl4d8zNIzx43Ipm kWiwAx38z+IdSkZLlD4r/X/kW4hD1ruVQCKXBfEyVJ/9BBsPjLd3EvzyOOBAlCxnluRK i8jQ== X-Gm-Message-State: AOAM532WeLt/UVrw7bbk2zfphkN9HyzSmeMauzWdlAsSp0nme9HfA9Na xxXyfeetQXSFJxEuyH/Xjg+ATEZDjJkDybqQ X-Google-Smtp-Source: ABdhPJy82sXLTZ+EPlDqitPHKuoD4xOyws52J5FaGtdbCj8TnSn9omPWFnJ5aWRIIKPQAZqRzPLkOg== X-Received: by 2002:ad4:4f11:: with SMTP id fb17mr13087291qvb.46.1608136043976; Wed, 16 Dec 2020 08:27:23 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id z15sm1378493qkz.103.2020.12.16.08.27.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:23 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 16/38] btrfs: handle record_root_in_trans failure in create_pending_snapshot Date: Wed, 16 Dec 2020 11:26:32 -0500 Message-Id: <5a0847d1968a6bc91ba995d6c7ce389915715544.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org record_root_in_trans can currently fail, so handle this failure properly. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/transaction.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 4efdb87df27d..0663675354a2 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1568,8 +1568,9 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, dentry = pending->dentry; parent_inode = pending->dir; parent_root = BTRFS_I(parent_inode)->root; - record_root_in_trans(trans, parent_root, 0); - + ret = record_root_in_trans(trans, parent_root, 0); + if (ret) + goto fail; cur_time = current_time(parent_inode); /* @@ -1605,7 +1606,11 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, goto fail; } - record_root_in_trans(trans, root, 0); + ret = record_root_in_trans(trans, root, 0); + if (ret) { + btrfs_abort_transaction(trans, ret); + goto fail; + } btrfs_set_root_last_snapshot(&root->root_item, trans->transid); memcpy(new_root_item, &root->root_item, sizeof(*new_root_item)); btrfs_check_and_init_root_item(new_root_item); From patchwork Wed Dec 16 16:26:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06D57C0018C for ; Wed, 16 Dec 2020 16:28:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B11D3233E2 for ; Wed, 16 Dec 2020 16:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726746AbgLPQ2d (ORCPT ); Wed, 16 Dec 2020 11:28:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726734AbgLPQ2d (ORCPT ); Wed, 16 Dec 2020 11:28:33 -0500 Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5B3CC0611BB for ; Wed, 16 Dec 2020 08:27:26 -0800 (PST) Received: by mail-qk1-x734.google.com with SMTP id 186so23039602qkj.3 for ; Wed, 16 Dec 2020 08:27:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9X57lIxzhlDydEpNT+8ap17OnJ/IJCL7guXADYlfNQw=; b=zO9fERGbDJUobwzC0D86WqLKU2xmltJdBbNElEPp07OT41AQzOHDteIAIL/nYhWEqS 1GCL0DpD9wP6BgGwag+amwicbQINZTbUzs2thbTz3kkjSXCOsroxHzzgKNWdK4f8ExRC igQN3Na4Pkhn4cBDsLciZfY5Y2j3Xkv5cTA8jd6Do6pNKOgC5I6hzmNH+pO3Gjeoabpe AWVsHxW/m7zWhY09N+Vv3SJ6gcTeWQyBFVZpwq12JuEv/c2kIzD35GDBdTlI4CkmGUC+ 4C/Q2MRywndczZgmKSKkNDN9758YnQeLZ7Rz1iNs+MRptWBX8BgzNDglJm7unMvM/kJT C4ew== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=9X57lIxzhlDydEpNT+8ap17OnJ/IJCL7guXADYlfNQw=; b=KYQWCKGy68GfXk9K+jmEYuyyj93cLK+42ViREym3AOCm3K7zqMhEVYGwLUJztTy51b IMG1fwiw7WYMjblNoGIwVZ6NvoL96Ao8zIkINA4lQdn61lrPiCXV4O6DDj5gCZ99S3+c LHVMNfl/UyuDivwosK5YUlox3Pji3xm7RsIfzGgG51WmIgKUFz3Tsi1jkdBbZIYHYD2R +nwhPkE2K0xoMs0Ovm8pjYNJStBHc2VjdnIH3QUXWj9txPJwOujPMSW8734cy3RTI1gb 4J2TCj7HJ6fB9dMu2BZKYi2yZ3MiTZRK9YpCjZ6nrT+s+cgJr9RjD0TZ0jLLvDVwBpxA SqWw== X-Gm-Message-State: AOAM530MTsKYNd9r0u/cWYgSczJcQdPShtwQTya6e1xVKxhI/TOtBGys jaC7yIk1Po3d4yggYIpqZPvupJr/++9x4vLL X-Google-Smtp-Source: ABdhPJxR36BerU97zWgccfXSOVCUF5EJeCf0nY9yAeChQG5lSkHLZ7rdVM3DbAs9VqsyWDLFM7ztdg== X-Received: by 2002:a05:620a:673:: with SMTP id a19mr28434937qkh.353.1608136045780; Wed, 16 Dec 2020 08:27:25 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id b4sm1192989qtb.33.2020.12.16.08.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:25 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 17/38] btrfs: do not panic in __add_reloc_root Date: Wed, 16 Dec 2020 11:26:33 -0500 Message-Id: <576c883b5f869a3d3915691b4d1c00299119739a.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If we have a duplicate entry for a reloc root then we could have fs corruption that resulted in a double allocation. This shouldn't happen generally so leave an ASSERT() for this case, but return an error instead of panicing in the normal user case. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 7e3305aca6ac..410e779af1ed 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -638,9 +638,11 @@ static int __must_check __add_reloc_root(struct btrfs_root *root) node->bytenr, &node->rb_node); spin_unlock(&rc->reloc_root_tree.lock); if (rb_node) { - btrfs_panic(fs_info, -EEXIST, + ASSERT(0); + btrfs_err(fs_info, "Duplicate root found for start=%llu while inserting into relocation tree", node->bytenr); + return -EEXIST; } list_add_tail(&root->root_list, &rc->reloc_roots); From patchwork Wed Dec 16 16:26:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977957 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA146C2BBCA for ; Wed, 16 Dec 2020 16:28:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9DE84233E2 for ; Wed, 16 Dec 2020 16:28:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726787AbgLPQ26 (ORCPT ); Wed, 16 Dec 2020 11:28:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726784AbgLPQ26 (ORCPT ); Wed, 16 Dec 2020 11:28:58 -0500 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D177C0619D2 for ; Wed, 16 Dec 2020 08:27:28 -0800 (PST) Received: by mail-qt1-x830.google.com with SMTP id v5so8358636qtv.7 for ; Wed, 16 Dec 2020 08:27:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=V4IlVz0nB0vCl1dD9Ex9gLIurv5gPoDmMqxx9hpzPIY=; b=Qn38nhBG010LW3d9m2VcGR6M6c92WpMmch1ggH9vyieJRfuXV4bPJYBY43nEnkAWfq TRgpGeVfoduyOHjvRV3KFcpmWz3C8KPwQL0GgjA9e9vL4yOYUGm5JerNkzyxSKQazzRv iOkgsqt0BF0mEurFuPRG9TuePoIN7cbGKY28LyoXAvQQ6DQzzxY7WDpkI9KUo0/cXlsw 4AiiS2w/o9AOthOJJQfsW14wO1+VvQdUoqrzkid4KyNGXzZ02mRBmbLbVEiX5cw8Z2tt u8xQDy6OWREKPS0I9bPcIbv6CeNEjadNKtFbbcoTPavf/FGPVrvhGWKLF4e3TNaFxHII Db9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V4IlVz0nB0vCl1dD9Ex9gLIurv5gPoDmMqxx9hpzPIY=; b=K/qsFdGjcDxR5QXrJHMpBoWOhpcGrAhHohgSJ5c2SNkTYqk3y84nOlmQRekGPkwkBk l2B+pn+XttQSR3KssTaH2nHNN74NHENjp4LuCXGwHbTIlDLVAbv4BIJuhQOr0cQ6idgC sfh04nKmfUgq7w1/p00MyiA99he/vxLjawDFvIrjRvzmTx8fcF2GA9CL1xa+KetPCDwZ JPac6UD14pNVDMakatBN0B/LGX1VBe5NthTqxKSIIZw34VplUF+ERl45lPo7dOvx58gn osNGJwAZw34oiyHYTZoAuTmmNJ6aPeDbVwNbKAuT5Sc/FtHl59H/Q4XJSV1zDkxX4w63 axAA== X-Gm-Message-State: AOAM530T2kE8alIDTq6cd1aip3imtOVQ9FUjW5hxlzrEX0ybgUwiB9Ll qFrjdKHU5uuTF6Er94VcIBM0NlgICvFEGXbJ X-Google-Smtp-Source: ABdhPJytauHFVnfDxqmHF3BtDZy5w8Si1b6dqBg4RrAjsfVuAyF0AAsizsxm7aKrQmSxS5dP5CDWLw== X-Received: by 2002:ac8:6f77:: with SMTP id u23mr44188442qtv.118.1608136047606; Wed, 16 Dec 2020 08:27:27 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id y22sm1366660qkj.129.2020.12.16.08.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:26 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 18/38] btrfs: have proper error handling in btrfs_init_reloc_root Date: Wed, 16 Dec 2020 11:26:34 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org create_reloc_root will return errors in the future, and __add_reloc_root can return -ENOMEM or -EEXIST, so handle these errors properly. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 410e779af1ed..126655b199df 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -858,9 +858,14 @@ int btrfs_init_reloc_root(struct btrfs_trans_handle *trans, reloc_root = create_reloc_root(trans, root, root->root_key.objectid); if (clear_rsv) trans->block_rsv = rsv; + if (IS_ERR(reloc_root)) + return PTR_ERR(reloc_root); ret = __add_reloc_root(reloc_root); - BUG_ON(ret < 0); + if (ret) { + btrfs_put_root(reloc_root); + return ret; + } root->reloc_root = btrfs_grab_root(reloc_root); return 0; } From patchwork Wed Dec 16 16:26:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64FD7C2BBCF for ; Wed, 16 Dec 2020 16:28:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 366B5233F7 for ; Wed, 16 Dec 2020 16:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726752AbgLPQ2f (ORCPT ); Wed, 16 Dec 2020 11:28:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726748AbgLPQ2e (ORCPT ); Wed, 16 Dec 2020 11:28:34 -0500 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C480C0619D4 for ; Wed, 16 Dec 2020 08:27:30 -0800 (PST) Received: by mail-qk1-x72e.google.com with SMTP id 186so23039904qkj.3 for ; Wed, 16 Dec 2020 08:27:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LGBWNIae8x0J9BTYl7NZFiSo+OeiK7hMCei4zljFakQ=; b=vJ1Q/+AH1FkZU/iBgIylOyB7LGseiqU5wIiIpvWd/YynMmFzErY/GZY463GoSUdFg4 cYqVbpsXgBacmDbgvfkwTNWfPF8SgYWma/dqrnL1/T2+5IIqWwQzd5qqHgwQQNGjlVy7 b9DqhlygMgahz9JJCe8ouzo2pnkrKdv1+YMRfJDB/jvKp0TBGMmm4Bh8wvw3fh64ksQY a4vSIDy37fGAuQvrFdT57/1NCKlQ4sr9mzsxtVlVWJ8vSc/3nlH8Ej+eQUe3FyzSjF8T JrPfI36txUR3Ci/wvlznewjclmU2rVmo0BTuEli0UHGBScSZNNDYnwgSJ5XDM58DJ5OA YyMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LGBWNIae8x0J9BTYl7NZFiSo+OeiK7hMCei4zljFakQ=; b=rVhnBmtKUtw3tOWZEKQz7fsIj1/xCfhM4plUwDWvc/f9nIB/zeE4U1vFQV8ix+dXZF FFefjtdq8pPHkBlIYw16TEPKU8MJ4sBMzeVn97PO3rBJNqG3vL1aDWayPaO8c4R1Nori 0lynhazkUDJHF2boUn46jnEZFklbPwlCcMqBI2RM6Q7G2GAltFaJ0iLL1B0sQrxHWUbP Un6R1A5Bk6bZFOzza3SNV5q6nR8s5DxkIqCLU9o+ll6Q52dCVYDS5sf+g3z7kEymIE8F ew/e0LtoxKohCb7W4MmGtZFeuLdn1zL7zygceU1cZbAu1R+dg+ksdXh9s6j2GdGukYOq +xuw== X-Gm-Message-State: AOAM530IWxaTAOvIF2jBtjm82oszBlf+vs8FGANz+zRY7gsMqlxpOcTW BiKqT2pOXd83xatknU0CoQwtbWGIMfTcYNV6 X-Google-Smtp-Source: ABdhPJwZpA2CIzpIYH8NIKdDYJPTC3avK2G48b68tb/L6x0/TFHdo/NHlJDdCgTB0qEzOeVsKbwsCg== X-Received: by 2002:a37:7bc1:: with SMTP id w184mr46143537qkc.190.1608136049317; Wed, 16 Dec 2020 08:27:29 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id d9sm1284064qtm.66.2020.12.16.08.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:28 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 19/38] btrfs: do proper error handling in create_reloc_root Date: Wed, 16 Dec 2020 11:26:35 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We do memory allocations here, read blocks from disk, all sorts of operations that could easily fail at any given point. Instead of panicing the box, simply return the error back up the chain, all callers at this point have proper error handling. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 126655b199df..d5740acaaddf 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -735,10 +735,12 @@ static struct btrfs_root *create_reloc_root(struct btrfs_trans_handle *trans, struct extent_buffer *eb; struct btrfs_root_item *root_item; struct btrfs_key root_key; - int ret; + int ret = 0; + bool must_abort = false; root_item = kmalloc(sizeof(*root_item), GFP_NOFS); - BUG_ON(!root_item); + if (!root_item) + return ERR_PTR(-ENOMEM); root_key.objectid = BTRFS_TREE_RELOC_OBJECTID; root_key.type = BTRFS_ROOT_ITEM_KEY; @@ -750,7 +752,9 @@ static struct btrfs_root *create_reloc_root(struct btrfs_trans_handle *trans, /* called by btrfs_init_reloc_root */ ret = btrfs_copy_root(trans, root, root->commit_root, &eb, BTRFS_TREE_RELOC_OBJECTID); - BUG_ON(ret); + if (ret) + goto fail; + /* * Set the last_snapshot field to the generation of the commit * root - like this ctree.c:btrfs_block_can_be_shared() behaves @@ -771,9 +775,16 @@ static struct btrfs_root *create_reloc_root(struct btrfs_trans_handle *trans, */ ret = btrfs_copy_root(trans, root, root->node, &eb, BTRFS_TREE_RELOC_OBJECTID); - BUG_ON(ret); + if (ret) + goto fail; } + /* + * We have changed references at this point, we must abort the + * transaction if anything fails. + */ + must_abort = true; + memcpy(root_item, &root->root_item, sizeof(*root_item)); btrfs_set_root_bytenr(root_item, eb->start); btrfs_set_root_level(root_item, btrfs_header_level(eb)); @@ -791,14 +802,25 @@ static struct btrfs_root *create_reloc_root(struct btrfs_trans_handle *trans, ret = btrfs_insert_root(trans, fs_info->tree_root, &root_key, root_item); - BUG_ON(ret); + if (ret) + goto fail; + kfree(root_item); reloc_root = btrfs_read_tree_root(fs_info->tree_root, &root_key); - BUG_ON(IS_ERR(reloc_root)); + if (IS_ERR(reloc_root)) { + ret = PTR_ERR(reloc_root); + goto abort; + } set_bit(BTRFS_ROOT_SHAREABLE, &reloc_root->state); reloc_root->last_trans = trans->transid; return reloc_root; +fail: + kfree(root_item); +abort: + if (must_abort) + btrfs_abort_transaction(trans, ret); + return ERR_PTR(ret); } /* From patchwork Wed Dec 16 16:26:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44CFBC2BBD4 for ; Wed, 16 Dec 2020 16:28:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11F42233E2 for ; Wed, 16 Dec 2020 16:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726751AbgLPQ2e (ORCPT ); Wed, 16 Dec 2020 11:28:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726535AbgLPQ2e (ORCPT ); Wed, 16 Dec 2020 11:28:34 -0500 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0935EC0619D5 for ; Wed, 16 Dec 2020 08:27:32 -0800 (PST) Received: by mail-qt1-x829.google.com with SMTP id 7so17648976qtp.1 for ; Wed, 16 Dec 2020 08:27:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nqCBwEZJcP9oKXydIwojoncE9VQDvOpfyVCaDqYEQyQ=; b=rBUYEswJoRc1WggdgD3LFLj61pGqarC9InIQdYCUI4P3fn09Rx06xnSpuUinw+8fLR V4DLOg4AxBObGyff8Ma333zMYO3MuV8r1euW+UemaNj+c+1Xb4tJptzXEedsOe0xlL1d z0Ji0wws1dvzqzvmDlNxRV9LWBKzBGzIKi1zirh4p1WKAykQnk5SuuT7Hy+XuYzqi7b0 dFL6Bu1xsJ4R+Fe0PaqgxgQsdhZPNHsVSpk9PM9T0hitCnaeFaWq7cMYKULIn09sJao3 PCe02Z86QGkJ9Vr/qrN2+kUkQ89D4wuaw2UoAvmHmj9+YNZLOJryOT1d/LAgva1IwqZ1 PjqA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=nqCBwEZJcP9oKXydIwojoncE9VQDvOpfyVCaDqYEQyQ=; b=XOx/2+UN7GPt1UCb1InjEsV3l5XaakDX55F7Sc7XAqTqrZv1ifBJsgymg1JZ0RyDfg apvrsR4OX9bo7lrAmJ4Kj2sGy6YrqOQ0aKmB/NxqjIEpiSP9IUjb4yBud8fvyI+sYR7f lvPK4kmHeIqFPNF7ITY3gbY4sJ3YChHmfSh30s8kSxied34K0idHnhxS3q4MGxBd+jvu 4NexInYg+BHBQsu4XnTTQf+8+0MY1OuaK27aZuOw6k+fMM1YkSyvJvpBqRLWeJLhX6M/ R77xos2bEqsCSJAL3Q4Ba4N9IHnHDFZMRpzg27nEhNU1Z0uMwtBwHr30/uzrPDtY6p5d 2qlg== X-Gm-Message-State: AOAM533Wn9UrTSG8ExzZBxTI36kqVIeB3YXZFgAshhXWjx7MFkkkFBYi gg/5ZaS+ihB0JmM1/VCcwylSORtYC3F7fYit X-Google-Smtp-Source: ABdhPJxCbLH0+7yP6oE7uR1kEok7h36zR4B6zBQsLhtuT2lf7e3ipuU5/lhAuPjJEnlj89FzxXO1EQ== X-Received: by 2002:ac8:2bd2:: with SMTP id n18mr44486778qtn.260.1608136050962; Wed, 16 Dec 2020 08:27:30 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id k7sm1278796qtg.65.2020.12.16.08.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:30 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Zygo Blaxell Subject: [PATCH v7 20/38] btrfs: validate ->reloc_root after recording root in trans Date: Wed, 16 Dec 2020 11:26:36 -0500 Message-Id: <68fee71b3bc3bd34cf433cc1ea6cf5d9f8dd4b82.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If we fail to setup a ->reloc_root in a different thread that path will error out, however it still leaves root->reloc_root NULL but would still appear set up in the transaction. Subsequent calls to btrfs_record_root_in_transaction would succeed without attempting to create the reloc root, as the transid has already been update. Handle this case by making sure we have a root->reloc_root set after a btrfs_record_root_in_transaction call so we don't end up deref'ing a NULL pointer. Reported-by: Zygo Blaxell Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index d5740acaaddf..918fee55bc30 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2083,6 +2083,13 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans, return ERR_PTR(ret); root = root->reloc_root; + /* + * We could have raced with another thread which failed, so + * ->reloc_root may not be set, return -ENOENT in this case. + */ + if (!root) + return ERR_PTR(-ENOENT); + if (next->new_bytenr != root->node->start) { /* * We just created the reloc root, so we shouldn't have @@ -2580,6 +2587,14 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, ret = btrfs_record_root_in_trans(trans, root); if (ret) goto out; + /* + * Another thread could have failed, need to check if we + * have ->reloc_root actually set. + */ + if (!root->reloc_root) { + ret = -ENOENT; + goto out; + } root = root->reloc_root; node->new_bytenr = root->node->start; btrfs_put_root(node->root); From patchwork Wed Dec 16 16:26:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977959 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB1B3C2BBCD for ; Wed, 16 Dec 2020 16:29:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 93D89233E2 for ; Wed, 16 Dec 2020 16:29:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726791AbgLPQ3A (ORCPT ); Wed, 16 Dec 2020 11:29:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726784AbgLPQ27 (ORCPT ); Wed, 16 Dec 2020 11:28:59 -0500 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA1CDC0619D6 for ; Wed, 16 Dec 2020 08:27:33 -0800 (PST) Received: by mail-qt1-x836.google.com with SMTP id c14so17619756qtn.0 for ; Wed, 16 Dec 2020 08:27:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2szEeDBy6YIpoBNDjP9rMSOrwKTMScKSxDHHb/Sb9H4=; b=ZcX83MAsRwZ+wLgPOeFDwcqrbWWK8M44EzD8U6dUYzj/PmVYwULE3kgVmcH7OUoWKW seIun/0PQttpd24QJhbKitUtavEZoj1S/LZYvcw/ylIjBbwZ3G2BtyAk06KpGM9+4poy iajOnh8A1ZfmR69ocuSZ+zM9aXSy9NHMiu3ELE1g0CEoj1PtF1AZgUzmi9EDTaqiShc+ gZyLbjkrpsQhhubLsQsCyRUwDVntYuJVaucGoa8aus6A3+IdZpZ+Ekj127MgXZOzHUay s32AqIWMmoJIq3W5GVClFU38ZMcaKl+8Nz26fgq8t5plw9z+OTdrP7Jds/09ocgksdrj bsFg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=2szEeDBy6YIpoBNDjP9rMSOrwKTMScKSxDHHb/Sb9H4=; b=A7bcoU2brg7fym9cnQHC0pjYOqfhJTFlnYzBpuE2Ys0r0wvFiam99lCUqslm0EUd9L iBufCUthHnFRGVa4RDrIldasTfsUomBVRp2S2OBPvPaEuw8D36dDuaWbGToHm+AkrGKj 6NF+f/6kSi8x/8vdU01trhFNW9k7wZtbIDfgmR3xuCvQzV5duJ6lywT1K62X65l8i28u VsFe3S2wrfbjkHwoGs+1l8JWrlnvIF8625MCwlA0qGu6JLiZXlMOiqDs5SEq+TRexNcs qu8bMhVISJvhSILbgTXoL3SiB4rZIqRTY5IsE7JuhC6OGsrlc6K2WE/qts4nCbXbgM8u 2ffQ== X-Gm-Message-State: AOAM5314eig84Xz/8PGFUhcTsQysjPkdvDDhhIlEIb99wsYjIUaAFhBB nssCoyjWrfq2aiBkqBBUgNdU8TJJiJ6j8N+/ X-Google-Smtp-Source: ABdhPJygHcL4Iby0mHLRztpENZdd7+yr09BIkii/Qe+o8ZV4JkdSgowHFxm2xjld0zrArRrLZFrDkA== X-Received: by 2002:ac8:4c8c:: with SMTP id j12mr43575152qtv.133.1608136052640; Wed, 16 Dec 2020 08:27:32 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id g26sm1366368qkl.60.2020.12.16.08.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:32 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 21/38] btrfs: handle btrfs_update_reloc_root failure in commit_fs_roots Date: Wed, 16 Dec 2020 11:26:37 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_update_reloc_root will will return errors in the future, so handle the error properly in commit_fs_roots. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/transaction.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 0663675354a2..1e1587290955 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1344,7 +1344,9 @@ static noinline int commit_fs_roots(struct btrfs_trans_handle *trans) spin_unlock(&fs_info->fs_roots_radix_lock); btrfs_free_log(trans, root); - btrfs_update_reloc_root(trans, root); + ret2 = btrfs_update_reloc_root(trans, root); + if (ret2) + return ret2; /* see comments in should_cow_block() */ clear_bit(BTRFS_ROOT_FORCE_COW, &root->state); From patchwork Wed Dec 16 16:26:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977961 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62D2CC4361B for ; Wed, 16 Dec 2020 16:29:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 214D2233ED for ; Wed, 16 Dec 2020 16:29:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726794AbgLPQ3A (ORCPT ); Wed, 16 Dec 2020 11:29:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726789AbgLPQ27 (ORCPT ); Wed, 16 Dec 2020 11:28:59 -0500 Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EF3BC0619D7 for ; Wed, 16 Dec 2020 08:27:35 -0800 (PST) Received: by mail-qt1-x82c.google.com with SMTP id 2so7752214qtt.10 for ; Wed, 16 Dec 2020 08:27:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=QQbrd456nBkuUbJ1aFby5rqk1Xys8TS3UaspirWlPYg=; b=AuI+mcDO/sg2K4oXSCLT6Rq4Gl4uxg0WO6QXmpKoPmQl1JDEqQL0DuUb+yyHSztn7F i1ZaozW3G0zC6HJDoWSFv28u2jIZL90WAwaevIWVkyOnzCGGu1gLvKkRtNygVumknlyJ 9N7R07TRBvN9o5AJBNKG4JF4GwjtZucI5nNZdM+zicrV+X5KoxpSXtdbdA0ZGukyXKwj Y9vXyTmJFA3eezweo+Pf5mL9FLTJM4Q941ZIOaXvgGsrwiXFTc8E5dSL/P6gknqNVI5k 4WhySusjpNl0fhx+77hiM8BJZhVdKgExc+LIH10SyRle9OQWOaZeLncJR8Ub/1j6KoYz CEbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QQbrd456nBkuUbJ1aFby5rqk1Xys8TS3UaspirWlPYg=; b=cWakJec33ypRJIGHw2/5ejxI1Gfad7n1zyIXIVytZEsDCVKaoenDr0Gl02VJiPDr5R LHOeEebtogv9wwNVlPztrNgSnSXnJ289+ULXogjiNyyDrXnphP2cMt0a7cIQ2Rou6ZOg M9/bkqAm5WXJegPcMXLs1n0GmQxOQZIyRc/7ioQG8XMswI6fp0t3dAL1BlLtwwKuygrS mBT1BLuCks2s44Z3SsExpLehzGuj1eHUU8buAW2mT+MFT4+IB7ToWoNrChXQk2kKWORy qGlz9VUZ1kmG4vvEVyoH6el7utMB/B0Ht1RuMcb35+p9PDP4BGBF+qqObz6vNDv9ll+V 4Vqw== X-Gm-Message-State: AOAM5322WG/XysA37LnA/nC9XcUaNw8U4YY7LFxwqlnO9qD2U1kViUwL LjmtV8iAqhiohKy3m2HbgjIDANlfvaNffgoX X-Google-Smtp-Source: ABdhPJwra0MsBOlFqlQHKFvcdQ8HyTGycXN1cd1kR2HlZdPyyfUf+r4fuxpOBniEKZG+KTyS26I1BA== X-Received: by 2002:a05:622a:243:: with SMTP id c3mr43458255qtx.202.1608136054467; Wed, 16 Dec 2020 08:27:34 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id y15sm1249558qto.51.2020.12.16.08.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:33 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 22/38] btrfs: change insert_dirty_subvol to return errors Date: Wed, 16 Dec 2020 11:26:38 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This will be able to return errors in the future, so change it to return an error and handle the error appropriately. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 918fee55bc30..13d5fd74e745 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1566,9 +1566,9 @@ static int find_next_key(struct btrfs_path *path, int level, /* * Insert current subvolume into reloc_control::dirty_subvol_roots */ -static void insert_dirty_subvol(struct btrfs_trans_handle *trans, - struct reloc_control *rc, - struct btrfs_root *root) +static int insert_dirty_subvol(struct btrfs_trans_handle *trans, + struct reloc_control *rc, + struct btrfs_root *root) { struct btrfs_root *reloc_root = root->reloc_root; struct btrfs_root_item *reloc_root_item; @@ -1588,6 +1588,7 @@ static void insert_dirty_subvol(struct btrfs_trans_handle *trans, btrfs_grab_root(root); list_add_tail(&root->reloc_dirty_list, &rc->dirty_subvol_roots); } + return 0; } static int clean_dirty_subvols(struct reloc_control *rc) @@ -1789,8 +1790,11 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc, out: btrfs_free_path(path); - if (ret == 0) - insert_dirty_subvol(trans, rc, root); + if (ret == 0) { + ret = insert_dirty_subvol(trans, rc, root); + if (ret) + btrfs_abort_transaction(trans, ret); + } if (trans) btrfs_end_transaction_throttle(trans); From patchwork Wed Dec 16 16:26:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C287C2BBD5 for ; Wed, 16 Dec 2020 16:28:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D972233E2 for ; Wed, 16 Dec 2020 16:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726757AbgLPQ2g (ORCPT ); Wed, 16 Dec 2020 11:28:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726748AbgLPQ2g (ORCPT ); Wed, 16 Dec 2020 11:28:36 -0500 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 986CBC0619D8 for ; Wed, 16 Dec 2020 08:27:37 -0800 (PST) Received: by mail-qk1-x733.google.com with SMTP id i67so15509799qkf.11 for ; Wed, 16 Dec 2020 08:27:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=RB3ZVAwErcd97s2dhyLnYsI1ypCe4zlqd+anJuxPtEY=; b=uyyiI/z0ZVJh5IsbTrA7UlEUmYFlTOLjC9JqCU4A5YqYMR/JjCZsp1fg5DVht06yru HRM24YtfCiyDj96Ba2F/EihAOWpFsx+vnf+/raLKgBIhcXq8kuSqISbglzxAtlCSqXdS nVo2iZ9sPcIaj5Ftbsk0+FljhP0KrSBiPsxkxgL+BRa1rTW54w7eLyVJGqEYKjrU905j RbMH/4hvwrhemVzPCfaO2tRfruZcqZk6JG81F6H2VVUHoB3gCMjERDbbcJwsPXX6yBLH /+BHzdRuUi9A0Q6OOAd36vFMc9AbaP55xXpcKDWPtDCJvnYDR42P4E017BfqBtTPi6jA 0zcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RB3ZVAwErcd97s2dhyLnYsI1ypCe4zlqd+anJuxPtEY=; b=R8y6CqRcBHjPworbvBdg4dg7PsizjQ55kWXmXI/8DNKqfmFss/9zF8J5wZnioXhQXz d1La5imOdFjwm/wmltkHKyEnJGuVTFZe382h5Rjs+97cah4BS6g6foDA3+vJxQ7KLXYd yqRzB6fDJgBlQxDRJaw62lzm8obvcrdh7tD40MOnOFbx4oF9mwSeVU7iQrReRs480T29 Joy02l3/Koof8ZaIQvsotDo/9H1Qm7GhMpFazZP3WFgYymoQ6jdPEsBunmfrsAFuuBAu 0pWnBcuQsDvRFAAhyCiTgIKbM1LJjyQX/kNI4nhPcd7D/anx37IDZxDniyvY2t4z/nXS WHZg== X-Gm-Message-State: AOAM533ub4RFcUb2oVIT8g+wpDDwi4C3wwHcDA8d4N5Zp4h0oMFoA8g3 QPhrDOc/e9GDRnNE/9OZt+CrYbbYRGfEo0H3 X-Google-Smtp-Source: ABdhPJw76tvN6UPWxAbm+2PEDzaeoxyAZtHdPRnWd5TLPnn618KhmvS7G9CCebR6fDP5TmgL99ncaA== X-Received: by 2002:a37:994:: with SMTP id 142mr26149474qkj.257.1608136056277; Wed, 16 Dec 2020 08:27:36 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id n2sm1440275qkf.37.2020.12.16.08.27.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:35 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 23/38] btrfs: handle btrfs_update_reloc_root failure in insert_dirty_subvol Date: Wed, 16 Dec 2020 11:26:39 -0500 Message-Id: <3358ffdae439bd9dbaa7fa6af47b00c11090572d.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_update_reloc_root will will return errors in the future, so handle the error properly in insert_dirty_subvol. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 13d5fd74e745..dde383477f5f 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1572,6 +1572,7 @@ static int insert_dirty_subvol(struct btrfs_trans_handle *trans, { struct btrfs_root *reloc_root = root->reloc_root; struct btrfs_root_item *reloc_root_item; + int ret; /* @root must be a subvolume tree root with a valid reloc tree */ ASSERT(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID); @@ -1582,7 +1583,9 @@ static int insert_dirty_subvol(struct btrfs_trans_handle *trans, sizeof(reloc_root_item->drop_progress)); btrfs_set_root_drop_level(reloc_root_item, 0); btrfs_set_root_refs(reloc_root_item, 0); - btrfs_update_reloc_root(trans, root); + ret = btrfs_update_reloc_root(trans, root); + if (ret) + return ret; if (list_empty(&root->reloc_dirty_list)) { btrfs_grab_root(root); From patchwork Wed Dec 16 16:26:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C864BC2D0E4 for ; Wed, 16 Dec 2020 16:28:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8561A233F6 for ; Wed, 16 Dec 2020 16:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726758AbgLPQ2g (ORCPT ); Wed, 16 Dec 2020 11:28:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726753AbgLPQ2g (ORCPT ); Wed, 16 Dec 2020 11:28:36 -0500 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A96BC061794 for ; Wed, 16 Dec 2020 08:27:39 -0800 (PST) Received: by mail-qv1-xf29.google.com with SMTP id l7so11607008qvt.4 for ; Wed, 16 Dec 2020 08:27:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=b01JWLS+ZGwWe1HCXpnCOoP6ehEw+zjYvdkDqEwbXts=; b=piLbORJk2hYbHdHGRAbKmKxbDcDJVKToAPo7nGpInp5xLD0CCOJZ/2tqyeTK4ejJpb lzWD+nlxz3qJZNh7fZDRWROwPnprSrKM+FSzY8KxmHaepmc23ghdy2GNSO5WTeTySsVA 0o9/ZQSQzLsDeJd/jfmG4tr8gKpepedRlUP+8f6mMPGP6jxzkEwXaDILadYt5lclLamx V2A7RTBMlPJZBohB6DdBLnE0XX7q30Xq3dpSdCbMwy6FnaH0yTDi5TFi3PIpoJo3lHZd q47Nt+bkGlYAUvTmbLujPT5nVdcV1jnRQPjRYRRcBt9AX3/SzXAJscP6HsAMebG+96L1 2V9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b01JWLS+ZGwWe1HCXpnCOoP6ehEw+zjYvdkDqEwbXts=; b=noeKqTEuetCCBDmP2jsp0P5n688ewow7YS8ggiy3/BAT2V276ssI8QSz0rCVQ/kZkl D7j5PI/uqXZYj43YJ3Cv2H6oFQ8KaeNqO1C45DepAvDhb/KrENOEaFSKO1jK7jscCWQY VnA2yvRpTU9rwIG7WGtNPiO/Af435xiCvol1f6GWlz0PsqA5t4+m2ruZwIPY0dNZrbVq V6qaAFl+GSpJqfvpyqFdhVL8ulk1ZZhtsSAVNgWOvicF6bD3dnDx0l2Qw4qlvGfEtg/Z F10UFG/Nv9nUrKt1MlIyE3K2cO0BArXTLqRTKiJjcnaHmm3+bQRPRys+Zs0J7l3U01Fl nXWA== X-Gm-Message-State: AOAM532Peaw4ZO1hvcULYTnUmb7FKx5zS8i7gPCmCGvbOX3F8KStuInL 1oKT2uUlDcC9xsYgNVKZcalVQ6oTWSX1RJM5 X-Google-Smtp-Source: ABdhPJxp/3+xQ/sNnS0TsH0FP0cVgSu0b7No6xBzczjb29JCJWyfSuWuhvSfQW+Oc8mzpAdr2/EqUQ== X-Received: by 2002:a05:6214:140d:: with SMTP id n13mr40723105qvx.45.1608136058244; Wed, 16 Dec 2020 08:27:38 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id b67sm1319245qkc.44.2020.12.16.08.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:37 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 24/38] btrfs: handle btrfs_update_reloc_root failure in prepare_to_merge Date: Wed, 16 Dec 2020 11:26:40 -0500 Message-Id: <41fae34742970a8373ed4e817c1833a57212a163.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_update_reloc_root will will return errors in the future, so handle an error properly in prepare_to_merge. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index dde383477f5f..3a207548edde 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1870,10 +1870,21 @@ int prepare_to_merge(struct reloc_control *rc, int err) */ if (!err) btrfs_set_root_refs(&reloc_root->root_item, 1); - btrfs_update_reloc_root(trans, root); + ret = btrfs_update_reloc_root(trans, root); + /* + * Even if we have an error we need this reloc root back on our + * list so we can clean up properly. + */ list_add(&reloc_root->root_list, &reloc_roots); btrfs_put_root(root); + + if (ret) { + btrfs_abort_transaction(trans, ret); + if (!err) + err = ret; + break; + } } list_splice(&reloc_roots, &rc->reloc_roots); From patchwork Wed Dec 16 16:26:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977963 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38785C4361B for ; Wed, 16 Dec 2020 16:29:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC333233F6 for ; Wed, 16 Dec 2020 16:29:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726789AbgLPQ3C (ORCPT ); Wed, 16 Dec 2020 11:29:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726795AbgLPQ3B (ORCPT ); Wed, 16 Dec 2020 11:29:01 -0500 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FCECC06179C for ; Wed, 16 Dec 2020 08:27:41 -0800 (PST) Received: by mail-qk1-x72b.google.com with SMTP id i67so15510073qkf.11 for ; Wed, 16 Dec 2020 08:27:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J9iPzHWw4NV9MR+ZDl9yTYR1+aMXrodjsoMwwshDHzE=; b=qEmrSdbuVmrJQTkcyX/g/5cMIOSjTtMrtvx6ogTUBZgFOac/qxEuSJd1l9PrH5hN27 5h7RN3oTImVtyP7jUVxnE6umVdRx2vzWiYSD4qJ2Jq8ZTlH/1S4uB7Zpe+xyFmZdgsfh 11IOJd0WYmfgNrs7l3MFZfHZKSstxn0tdMvh98Eu/QbG6HuBR/VAmpVOhA5r2bvtZtDs ZhhN1H79mEf0U7237mLjFLLx1/Y9MdWxnYNcBo8y3UNfTTDd5U2jwnwg6HH9jFmx4JRV /kLB8znUSNMsW4mnQAWqj3Xnt+Hb8Bs4hIrE7lnHIV06QLuoWFlZnz3Nlq+9Zi8uXtvb 1kwA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=J9iPzHWw4NV9MR+ZDl9yTYR1+aMXrodjsoMwwshDHzE=; b=WEbtPrvupiq08GAqlr3ljB572IJmEmkoj11z1eW9c87pquYLiFtv4aUU19kHLJwWSy BN6anPRtYdRxZ8YOcF+mbNoYfSELGsNUaNFJO4vzE5juqIrtjJKCXZg3O1rKRh+WqwX8 hVwo58lUEB1vj8yhg27C0TqPrnj5Eoe1xGnBD8QPSCD941YkCFND0N5lkxCuZeLQxwlu s29VAebEbHTgIIYaFR9OwOwpCcc1np+7dTqog3H6bzh5wTNL5P+1khec/dtNqyONCsS4 5qHqacxos9ESHaRj0nJl7vFY56GO36Hpw5ekeEAwEAzmdD6KpXN1IaEqVeWDHPhzwc1e NTqw== X-Gm-Message-State: AOAM5307+G8JhIClIqalsH/0dCAKra82tCSn2oY48gITnlR8G/lBN+48 XF1XmtIJc0PQG3WaUOhsip6L1QeppR+t8z1Z X-Google-Smtp-Source: ABdhPJzbU/4bYwa+KhK0mo46dHf+zkqeKH6otgbked3RfI3soPUp5kfIvaoEkkPH4Ytgyx3YimiSxw== X-Received: by 2002:a37:5084:: with SMTP id e126mr44037517qkb.148.1608136060001; Wed, 16 Dec 2020 08:27:40 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id x20sm1404909qkj.18.2020.12.16.08.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:39 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 25/38] btrfs: do proper error handling in btrfs_update_reloc_root Date: Wed, 16 Dec 2020 11:26:41 -0500 Message-Id: <8c7b7107775ffafac71bc90e28f9b88518cf8968.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We call btrfs_update_root in btrfs_update_reloc_root, which can fail for all sorts of reasons, including IO errors. Instead of panicing the box lets return the error, now that all callers properly handle those errors. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 3a207548edde..73c8cc502b07 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -904,7 +904,7 @@ int btrfs_update_reloc_root(struct btrfs_trans_handle *trans, int ret; if (!have_reloc_root(root)) - goto out; + return 0; reloc_root = root->reloc_root; root_item = &reloc_root->root_item; @@ -937,10 +937,8 @@ int btrfs_update_reloc_root(struct btrfs_trans_handle *trans, ret = btrfs_update_root(trans, fs_info->tree_root, &reloc_root->root_key, root_item); - BUG_ON(ret); btrfs_put_root(reloc_root); -out: - return 0; + return ret; } /* From patchwork Wed Dec 16 16:26:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977965 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBB82C2BBCA for ; Wed, 16 Dec 2020 16:29:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A0C80233E2 for ; Wed, 16 Dec 2020 16:29:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726784AbgLPQ3B (ORCPT ); Wed, 16 Dec 2020 11:29:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726796AbgLPQ3B (ORCPT ); Wed, 16 Dec 2020 11:29:01 -0500 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B93BEC0617A6 for ; Wed, 16 Dec 2020 08:27:42 -0800 (PST) Received: by mail-qk1-x730.google.com with SMTP id 143so23034906qke.10 for ; Wed, 16 Dec 2020 08:27:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4fUKDCc8CueRAdMqhIUwECuXtti47UXT5Jx1635pIaU=; b=mbCJP+OkepipsqXPPn9kzVJ5yxCPI/rIrddIl+UETYPTJ2V3aOiIz/09NIPGItdHsC sFjbjltYGH1qR5OiwMl/XCJMXHIiTjFVt45j/R2zgkToClWUrov+5MqC5k2f597WHvHK Tx6Z9I8WtMcO6dt/2hAaos7INQG+DqRy2qIP6kYuzRsNvGJ0pE3oYzFyHBLWy+H4ysLN n9xTIRRruNC0Uh7uxIUc26YxQme8gNcI4/OUdQh8easjXNNIOaj0ftWe16rEJPfmPSZc K6mfyzefxoW+1vwCSCPly2GoTmfthfiIJBRYuv/+mXtfBCJxkcZYS5q9wYL37X0a21T0 dmqg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=4fUKDCc8CueRAdMqhIUwECuXtti47UXT5Jx1635pIaU=; b=TaRYtmguRYHFHqpiZcReIG8PWAEoYORlpbm+2um/Xq4KYKVxFCgQpPjAF+q8ctA5Wd dP0c9DVGEtFKwo0R0NTnuer1j8r/eH2/iJdIVkV0jVXtEoj1DCsXDZ9fdau6A7SfX9Iq z23KTbCqhmFL1x1epURXoifWtabsgxb0QrNUnx4+wPAhOlCS8PrZdqVOSiHNQqY49u/9 EzMDR9NXn6NpUnTVMVHZ0/FDZ7Bo4LZJDj3ko1Uz9+Qz3F5FHgtSEjedvQnK2nOX8+64 2jVe//lrDoRPHYYyzhnMck5KpL2BDItkdwRrv5EU1etpP79BlSP/PccY2+iuoekRKpkC neCg== X-Gm-Message-State: AOAM532InHSWbk8DmP/CT1TSfCYXb8bxaLll6ivSN4NcXFtMwe8kZCEo n7RT46C5myjvryjg/rlMG/1y57pYzwhmDwZ1 X-Google-Smtp-Source: ABdhPJxj6ZdEStcu0v9iL0s0kjf0gxQlAZjT2Yvnp/vHUXLq0wi3F21ijTy88GO+2idEQ+ASabjzzg== X-Received: by 2002:a37:a651:: with SMTP id p78mr44014709qke.293.1608136061698; Wed, 16 Dec 2020 08:27:41 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id y187sm1393511qkc.120.2020.12.16.08.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:41 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 26/38] btrfs: convert logic BUG_ON()'s in replace_path to ASSERT()'s Date: Wed, 16 Dec 2020 11:26:42 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org A few BUG_ON()'s in replace_path are purely to keep us from making logical mistakes, so replace them with ASSERT()'s. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 73c8cc502b07..574ae3f43e33 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1212,8 +1212,8 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc, int ret; int slot; - BUG_ON(src->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID); - BUG_ON(dest->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID); + ASSERT(src->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID); + ASSERT(dest->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID); last_snapshot = btrfs_root_last_snapshot(&src->root_item); again: @@ -1244,7 +1244,7 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc, parent = eb; while (1) { level = btrfs_header_level(parent); - BUG_ON(level < lowest_level); + ASSERT(level >= lowest_level); ret = btrfs_bin_search(parent, &key, &slot); if (ret < 0) From patchwork Wed Dec 16 16:26:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE000C3526B for ; Wed, 16 Dec 2020 16:28:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AFAD6233E2 for ; Wed, 16 Dec 2020 16:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726761AbgLPQ2i (ORCPT ); Wed, 16 Dec 2020 11:28:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726753AbgLPQ2h (ORCPT ); Wed, 16 Dec 2020 11:28:37 -0500 Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2C1CC0617A7 for ; Wed, 16 Dec 2020 08:27:44 -0800 (PST) Received: by mail-qt1-x82c.google.com with SMTP id y15so17586499qtv.5 for ; Wed, 16 Dec 2020 08:27:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+/BDcdy5VY4Xg0QOPj7UvOhTBKSZwTZcS0NwFAeBbLc=; b=BGxW5R11GZ5cLz2ufFKn55RBzP1hV9/I1+zXrDl2pV5K0GpkwZ1DGBbbxTmhxQSXFi 91O2sdBaVSfn69MaAQ1ctnxAMvSkNE7nX0CSEqHrix3wTSq7SQ1WX4OvCBh511RxwBQ6 46HWsajvfAFbswtHe5vlUU+dTNjBB6Kh6DI+20jrlZeSYqQA0V64wfsXnzk8h52jxU82 5tHfLtFMlwGKmVoyb8MMckNZmIXm461ELrrp+gmibprcxm7e73O/Wh6jw2dGcapf7p4s NvBqgn671tclwpIXDX0qdUsTEIEv3qFwWik/TmCV90lNvdvpv+a+GWqKOjhQBZ9FdiQB CRiw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=+/BDcdy5VY4Xg0QOPj7UvOhTBKSZwTZcS0NwFAeBbLc=; b=nDQcLrZ/2ZfFg5VkzLxK33cNEAENmjnJiYMBPQBkU5Tgky6n7i3WTXBkIIHMKVqWZw Wa/8bBBkwGbNGWoY1Fu2Fd0HE7FbvJADNodCQBdFf1s3+imlzx3euJmKaxGtc8cNAlut 8TafHx28gWrGJWpg/zB77ha6WqIaj0oWn83EpRBuu1SIQQGq1L59uJ+Kqsi0YKJbvfWX uqXNno+5NfnlNy1Sf6U7Q8qJ0T1bVWNsieC2k1zSZLRw6UKeppEEKUDiJudtAByzYMMI ncMHCkxW1dECV4PdEV1cLeh7pNtzxyiL6a5FivatwqJa3CUI/QzVQz4qdc17NIH3ZBO1 OIYw== X-Gm-Message-State: AOAM531xUGP2zhUHz/Otl3DvZX/IDcXpozRGEe09YdFsBjbKaII1RKyz jDBCshfhOit4Hg9Z7u+vXTmHZiOfqjMKvVbb X-Google-Smtp-Source: ABdhPJxi8lWJXwrmt0g/j2+jP4rw7INLEmzMFnFjNt2QFzAC9H/JNw8TvAHdXSwSLAeuom7JYwgojg== X-Received: by 2002:ac8:7141:: with SMTP id h1mr42321689qtp.211.1608136063658; Wed, 16 Dec 2020 08:27:43 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id h125sm1363614qkc.36.2020.12.16.08.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:42 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 27/38] btrfs: handle btrfs_cow_block errors in replace_path Date: Wed, 16 Dec 2020 11:26:43 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If we error out cow'ing the root node when doing a replace_path then we simply unlock and free the buffer and return the error. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 574ae3f43e33..d43603ae5570 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1232,7 +1232,11 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc, if (cow) { ret = btrfs_cow_block(trans, dest, eb, NULL, 0, &eb, BTRFS_NESTING_COW); - BUG_ON(ret); + if (ret) { + btrfs_tree_unlock(eb); + free_extent_buffer(eb); + return ret; + } } if (next_key) { @@ -1292,7 +1296,11 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc, ret = btrfs_cow_block(trans, dest, eb, parent, slot, &eb, BTRFS_NESTING_COW); - BUG_ON(ret); + if (ret) { + btrfs_tree_unlock(eb); + free_extent_buffer(eb); + break; + } } btrfs_tree_unlock(parent); From patchwork Wed Dec 16 16:26:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD65FC2BBCF for ; Wed, 16 Dec 2020 16:29:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC8FF233E2 for ; Wed, 16 Dec 2020 16:29:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726799AbgLPQ3D (ORCPT ); Wed, 16 Dec 2020 11:29:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726793AbgLPQ3C (ORCPT ); Wed, 16 Dec 2020 11:29:02 -0500 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7136EC0617B0 for ; Wed, 16 Dec 2020 08:27:46 -0800 (PST) Received: by mail-qv1-xf2c.google.com with SMTP id 4so11588234qvh.1 for ; Wed, 16 Dec 2020 08:27:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qBxhSXf0g0tkUWQgt8A8W+l2b0PLsImw4twm29Ha+i0=; b=hk7o7ShR1ZvicwFYVjq6p0rsm5TceOT6GU+WAQEvzKkhXuqPB2jnpQ0LN50E39rUQY A0rtjK1cM94rtLTtrepO1ulwddoDfXehCgnXOruUni6xIGO8lORWea2nVfUb1xOD2tS6 X4HfNwDuYgcPsp0W3BS8HeteWxUsFynwkU/xdaX1cba2mMA9I7nTx7KhJ1f6Ez1NHe0m H99GbHWusWU/SGEDXg8aF2PbBwtNozWAkvE2/P8d+11vaMN7wEsVU9dQ9uYrCq1inn8j cLU6n2rFNW6ijmiy9lQod8GlwzNLtbJ+yy1I0mN/5ggzrmM98rKfbQ7/B9lzPbYEER+j fjpg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=qBxhSXf0g0tkUWQgt8A8W+l2b0PLsImw4twm29Ha+i0=; b=rLiCslEAi5R8MzyWoCzCQbz6dZBk1B9Fsm3ca5R7dX41bVpdodoFcFjMjygRIftzZZ IMoux+QsiB91rkCpBc7TgFsJAzl+u4udphlnrzMwV1h2SGC8cCcaQwVOUA9d3zYzwwY/ E7mPBoLLVpT7BPxGzqZXYhKt5ogdZ7O+80vdegvtKBjF0GqZVKFHDFfywHispnxOO6bU DGi3s6koLd3XnjD6+UQtK96n5rC5MiRrXO9/GCfRqEWHFXorWCHK0qsCHPQ0UPIWiN0f c1Ogt3wn8zosM0HNVup0voWVmihOteb2xMvfYnHCxKBhMegqShtM7c2yfDn29lWs6A3C xZBw== X-Gm-Message-State: AOAM5330DeaPybaCdN8vyKGBXl9Nki5TTcXOJ9+mQrf/jkdnTeJfWZey 1Fno+TRktJHsWAA/JDwhY3Y6E490hPSuCV1+ X-Google-Smtp-Source: ABdhPJx8K+3jFzSvuCljlm1uKsKdJUBwTT0K54TMMmN0J8tV6z8w7RI57lWC4aEXjsHZJvpD7Z0oNw== X-Received: by 2002:ad4:4c44:: with SMTP id cs4mr29093057qvb.25.1608136065419; Wed, 16 Dec 2020 08:27:45 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id k73sm1438265qke.63.2020.12.16.08.27.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:44 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 28/38] btrfs: handle btrfs_search_slot failure in replace_path Date: Wed, 16 Dec 2020 11:26:44 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This can fail for any number of reasons, why bring the whole box down with it? Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index d43603ae5570..8101cae374cf 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1324,7 +1324,8 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc, path->lowest_level = level; ret = btrfs_search_slot(trans, src, &key, path, 0, 1); path->lowest_level = 0; - BUG_ON(ret); + if (ret) + break; /* * Info qgroup to trace both subtrees. From patchwork Wed Dec 16 16:26:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1889FC3526A for ; Wed, 16 Dec 2020 16:28:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D726C233F6 for ; Wed, 16 Dec 2020 16:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726762AbgLPQ2i (ORCPT ); Wed, 16 Dec 2020 11:28:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726759AbgLPQ2h (ORCPT ); Wed, 16 Dec 2020 11:28:37 -0500 Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38495C0619D9 for ; Wed, 16 Dec 2020 08:27:48 -0800 (PST) Received: by mail-qv1-xf2d.google.com with SMTP id u16so11597320qvl.7 for ; Wed, 16 Dec 2020 08:27:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f+NX7Y69cTQL1QdVUPKQbwVhZ9YixdVO71sPyw/CMSM=; b=d6TFA0OkHo6gAuvCSo/M1bchQBkeL4BNHVkurNpDf1x19j6awcEA/Se5lgOMUYQQo7 87baKROmK+4hSYj7DV5K2E0yD/jlhOQf2JK4GbIHaoTSqtVbI1QgkTqINDfMeqLIqkaW EE6/5IStYJMQoe3dIiY5tWCQ/VrPsxFci/WFDbLplH0ZDEr+tcXlsmhJRKYD3xR3XB03 MwbDYn9Kj9h0kZL2mrDXcNFAg4gACe4idn0dNEX5i/YcKYPWL8KJ+TB+MjUMynxWNC0H zjNVwFWg5ylhZBFtO/ZnH9QpshTLa4e7lrprFFWaNXZUsrj7Sgzky5oMwP2ngx+wpbJs LLKA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=f+NX7Y69cTQL1QdVUPKQbwVhZ9YixdVO71sPyw/CMSM=; b=jhknALdp3bITUeuYk4ndW3QgEhKKLmyTZa605y8zEhYZVyURyEjhhJSbQHHk3g7dYV ITv12oGf1XZBvzsl7kXYylBHSxMOqmQnJ2rmFUVPVdahd2L+xgTNwUH36Uc8L6B4XMxB ZPwW9ciQYpU3zZxdedkBc7t90agCkYd4d+MYcqdjWbLVLKBptHIzz5UUXPNfr2jOUgSF Z1wPHhIuS8HI4+426t/vRLr0ri3NnWApVMoNURNwOKYJmvjTtAiY7du/N0I6c/j0EAHb 3S8neAdQ7aNxO96C0DedSSBvfJsMUHiPY6H0ixR3xi11HmRXvHT13dR9AWLyeAiG2B12 A3WQ== X-Gm-Message-State: AOAM533BcHEIx9QbzwYbmfHBW9PDUNPMXQDZqH8q+DIX0eDjDsjD2lnz 7zodi8XvcWS+Mizs8bH2qYVeoAHxdK+i8Qoh X-Google-Smtp-Source: ABdhPJxHK3xcebM95VOzAb98Mki1ICLLXibp/1yV90MBHCKRw2xeWfAZkdwyolpwP37fkcRN+WM0ZA== X-Received: by 2002:a05:6214:a14:: with SMTP id dw20mr43485349qvb.43.1608136067138; Wed, 16 Dec 2020 08:27:47 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id m51sm369979qtm.34.2020.12.16.08.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:46 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 29/38] btrfs: handle errors in reference count manipulation in replace_path Date: Wed, 16 Dec 2020 11:26:45 -0500 Message-Id: <72fbcf1a72c88b49a43ae552df09d9965cb9518b.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If any of the reference count manipulation stuff fails in replace_path we need to abort the transaction, as we've modified the blocks already. We can simply break at this point and everything will be cleaned up. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 8101cae374cf..e60353980942 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1365,27 +1365,39 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc, ref.skip_qgroup = true; btrfs_init_tree_ref(&ref, level - 1, src->root_key.objectid); ret = btrfs_inc_extent_ref(trans, &ref); - BUG_ON(ret); + if (ret) { + btrfs_abort_transaction(trans, ret); + break; + } btrfs_init_generic_ref(&ref, BTRFS_ADD_DELAYED_REF, new_bytenr, blocksize, 0); ref.skip_qgroup = true; btrfs_init_tree_ref(&ref, level - 1, dest->root_key.objectid); ret = btrfs_inc_extent_ref(trans, &ref); - BUG_ON(ret); + if (ret) { + btrfs_abort_transaction(trans, ret); + break; + } btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, new_bytenr, blocksize, path->nodes[level]->start); btrfs_init_tree_ref(&ref, level - 1, src->root_key.objectid); ref.skip_qgroup = true; ret = btrfs_free_extent(trans, &ref); - BUG_ON(ret); + if (ret) { + btrfs_abort_transaction(trans, ret); + break; + } btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, old_bytenr, blocksize, 0); btrfs_init_tree_ref(&ref, level - 1, dest->root_key.objectid); ref.skip_qgroup = true; ret = btrfs_free_extent(trans, &ref); - BUG_ON(ret); + if (ret) { + btrfs_abort_transaction(trans, ret); + break; + } btrfs_unlock_up_safe(path, 0); From patchwork Wed Dec 16 16:26:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977967 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8253AC2BBCD for ; Wed, 16 Dec 2020 16:29:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B753233E2 for ; Wed, 16 Dec 2020 16:29:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726798AbgLPQ3D (ORCPT ); Wed, 16 Dec 2020 11:29:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726795AbgLPQ3C (ORCPT ); Wed, 16 Dec 2020 11:29:02 -0500 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E33EFC0619DA for ; Wed, 16 Dec 2020 08:27:49 -0800 (PST) Received: by mail-qk1-x730.google.com with SMTP id d14so22368141qkc.13 for ; Wed, 16 Dec 2020 08:27:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=pqiQ7UvF4uruee0h+EDKupFEUyvfZkyzSQxdS1uiU1U=; b=cF5Ug0inDS2p1rrQ3abfJmihaxhJwkP+QOWpk8LnouwLKRlwgttJNkokI1ep40VkYs 9/3OcTvabqJeZclwJyNrFY8PfaEYo+eEyZqvuLEMQSyk+bnAOxyhqwu6h9UjCwFAQC0c mDxAYbHu86cSGWqR1Bh4MB1Stxk+nif4YsqdqyqbPmVWIwbQmxSui9Os3642iIlAXW33 xCOwO6FgvXAYn3xpdMCHi4GuWTGgFPSvDDDiyAoV46ct9lHCzQPELG0GuWXCYM3gDaHt v1l8A7gIrUNN2dP4qD/45ngJTXcvEmTCPNjxDm2aF1r+vJBYZZYCzhmmWIMrb9NN6flx YdIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pqiQ7UvF4uruee0h+EDKupFEUyvfZkyzSQxdS1uiU1U=; b=W2ZeEScPpFncRvrIhCIyw0IifjqIPtziZ1anOJLdhnXXgIujW2jqcvmQuf9eRWsXOC f9btFIWc6uHVqu9QRyQGkIdUHRgcoBx5VNVqs4wlOkekx/CLVOZp1U7BfNTDyB/o/ezo 6QK6NaqHBCvs10DbHTki7XjSsW02pytLSitzltzrXaHYFzjpfwAcccIyNc6z6tjHus0n uTZEYI84UkR0hSxjqoO/wVF4sn1qIvdKlFAEnmIq2eHHLa6Gj96gC38i+2y0lG5e/+Rg GB6ojd7myDABcLxurYU0dvNdQNqTOlDeFWcUo0FIRbaEtMGd4GtVd5pFnB0Z+h2TNRXr uE5g== X-Gm-Message-State: AOAM5313Cjo/XQQVDI2uZClMH16RWjYM/xI4aKA5uUtS0PugHxMIk5X6 ttHWszNij3rZ82BGAjjb6adFkDUIlUrXGctJ X-Google-Smtp-Source: ABdhPJxPerALsoCE5zIFZnSlyxJlKVYcGtCas9XSw07dz5zZ+YzN5t66oWZTGs5p77FXR3zCr15Igw== X-Received: by 2002:a37:2e05:: with SMTP id u5mr34051976qkh.228.1608136068885; Wed, 16 Dec 2020 08:27:48 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id n66sm1388675qkn.136.2020.12.16.08.27.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:48 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 30/38] btrfs: handle extent reference errors in do_relocation Date: Wed, 16 Dec 2020 11:26:46 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We can already deal with errors appropriately from do_relocation, simply handle any errors that come from changing the refs at this point cleanly. We have to abort the transaction if we fail here as we've modified metadata at this point. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index e60353980942..67df6ae6d13f 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2434,10 +2434,11 @@ static int do_relocation(struct btrfs_trans_handle *trans, btrfs_init_tree_ref(&ref, node->level, btrfs_header_owner(upper->eb)); ret = btrfs_inc_extent_ref(trans, &ref); - BUG_ON(ret); - - ret = btrfs_drop_subtree(trans, root, eb, upper->eb); - BUG_ON(ret); + if (!ret) + ret = btrfs_drop_subtree(trans, root, eb, + upper->eb); + if (ret) + btrfs_abort_transaction(trans, ret); } next: if (!upper->pending) From patchwork Wed Dec 16 16:26:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41A1FC3526C for ; Wed, 16 Dec 2020 16:28:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1081E233E2 for ; Wed, 16 Dec 2020 16:28:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726766AbgLPQ2k (ORCPT ); Wed, 16 Dec 2020 11:28:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726759AbgLPQ2j (ORCPT ); Wed, 16 Dec 2020 11:28:39 -0500 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9043FC0619DB for ; Wed, 16 Dec 2020 08:27:51 -0800 (PST) Received: by mail-qk1-x72c.google.com with SMTP id 19so23043115qkm.8 for ; Wed, 16 Dec 2020 08:27:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=L8fTlPURwi1njot0TAiCWtZWFXAYhGZrv+pY5V3rdfo=; b=NkVZEB5dr7kaHHC215UjcKswFVnJtD0LtWcqkItwcZDcYoZWW5vmmxhC+zgNHWpaHd pKffOtJwscm8/OMX8FPsfz+azEJG24ho+7ynuHXl1J5D/qoi8Zg8JEfUXwIoEMBZrild 42PIMVBtVmCS9zKUmG7879Psxgs1/Ou6J9Cks8Jcj/eCdYwQPCeWLVQd2DG9LDjZW0d9 H2WcdaQrmqfGbNjzhpKrhfI+VipeFkvDheLuA0KcWX+SNxbUEQC18csmmrg9BqnScOZx TtR5SqM7LoLtoqozD3WgDP9lsWXrJKxmLBvroEnyuOfw0rVvTn3u5xrIJf3XMRVdfT47 ucpA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=L8fTlPURwi1njot0TAiCWtZWFXAYhGZrv+pY5V3rdfo=; b=VpZOE7T/4IHpFZBGHR76/brsPyjVx45PT6WqqAC7wbwS32h/9nhVI7W8rdl3SmufP7 owfBYMIC5vshN62ha7uizKKsbXoT5T5rwjbq5WIQcI6SYg/adQZHZx+sGnwrjohNFBg+ kcXYtwKmfoxaB8frH5aeX0vAOpuiBYFW2yod0glp5FalyR7ryy4sGuzMOnnKOl2CWKnB uUICw8zJFihHNVj+ewrrl/H8lhb+r7DHu/jGp5R7FKGAHviVkxh4k/oUwOv7oBGHph5K ZMUk/tvaEQj8U2RsCxrVjm457VWNL2UFOvw1n1RPP6ODJV15y84naDg35MQLdElfNeGR 0qIw== X-Gm-Message-State: AOAM533BqvRGKaYvtiOU9mwMz+DiitexpHbNQrBXdogdgvh5WHBVCU34 sbSWc0v90j9CW4wQx/2X+Fq0LKWEt/4tFEsb X-Google-Smtp-Source: ABdhPJzHMaK+mmX12Q8nBNCjiXcY6uILp9WdJVpF7qK/SNq2XJkS7Mi/QKAYY5jDlYQGEpFJI3QudA== X-Received: by 2002:a37:8341:: with SMTP id f62mr46533489qkd.93.1608136070517; Wed, 16 Dec 2020 08:27:50 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id d123sm1427394qke.95.2020.12.16.08.27.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:50 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 31/38] btrfs: check for BTRFS_BLOCK_FLAG_FULL_BACKREF being set improperly Date: Wed, 16 Dec 2020 11:26:47 -0500 Message-Id: <4fb851bdc44ef89ece4afad51082e0b9eaf71eec.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We need to validate that a data extent item does not have the FULL_BACKREF flag set on it's flags. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/tree-checker.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index 028e733e42f3..39714aeb9b36 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -1283,6 +1283,11 @@ static int check_extent_item(struct extent_buffer *leaf, key->offset, fs_info->sectorsize); return -EUCLEAN; } + if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) { + extent_err(leaf, slot, + "invalid extent flag, data has full backref set"); + return -EUCLEAN; + } } ptr = (unsigned long)(struct btrfs_extent_item *)(ei + 1); From patchwork Wed Dec 16 16:26:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977941 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B606C3526E for ; Wed, 16 Dec 2020 16:28:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3BE28233F7 for ; Wed, 16 Dec 2020 16:28:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726759AbgLPQ2k (ORCPT ); Wed, 16 Dec 2020 11:28:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726763AbgLPQ2j (ORCPT ); Wed, 16 Dec 2020 11:28:39 -0500 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57DC3C0619DC for ; Wed, 16 Dec 2020 08:27:53 -0800 (PST) Received: by mail-qk1-x732.google.com with SMTP id h4so18167837qkk.4 for ; Wed, 16 Dec 2020 08:27:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=s/Sz8cWPtTfUa+Wl4786/qmcO33KzJmrjnJNHWLp8ek=; b=HaUyAMap9VFha6/kSomaLKK0FIS0d8Vlhjk9SeMJZh6wtMNhKfTFe+2HuPKtXDPno3 nnWf+JNdzFLyv2Xe0W+PVPcAfMG5ATH85KZmuwgpmRUHq5qqbxTFyFNfBfrGg1z6x+x0 1/uGzR+65jI4D79hVpYy6oFoAPJRL+17OhN3cycD6drMBJ+sn9coTlGGY7yY2QMrwDSs F+lTEppjlVN6KbX8JhNfa95sOQ+Yji5B32Meo5kGDWPRkHulH2JYRCOTM7IDuzXhippY BPtM6TuPdfZxiTU3WUAyIp4tA89OmLI8GPuStVv9ozCo32C/0ARETbDYlr4i7dRNSHcV +8Yw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=s/Sz8cWPtTfUa+Wl4786/qmcO33KzJmrjnJNHWLp8ek=; b=EMyN2qBsrPHcPPovVgJhhR8LmBQ+B+CC0nCs3yNBhNSMFL9mZ18lbgZY9pnNaOfG1F WJQBIe0SPQ8BEr6s/6oXgPlRRpEyyzluc1OYldrCb73MmojBW4+U2Jvcgv+1mErSz04/ 8dH7eniUZKGWHiEgPrhkFoYgYpyy0szw+y05/tqqNHFMzfqg6sVxKEcpbzbZem29GXKq DlwrNcnOtCLOboCtfbJby8enxTl/1sESn/H24Re1FGxdCYhN5MMKf3t3HlDNmHJ36tyh OEJdBSsAZ2dN2fH/X/BHWt7ykq4kABlSqSwZyoXv0t/RKi4cG5jdyRkddvQDx2cfCgvK ZIFg== X-Gm-Message-State: AOAM530P7kO57U38HJy/tCr8GFobjP1tDSux0xBVaxokBUbGW9NVqB2u g+Q6UO+lkX1l9A3CWr8bcG6svpqyzL5FQWIV X-Google-Smtp-Source: ABdhPJzI15yJ3cHStb2JEptMXTMmWrdpL9OQveJBmvRdwY30l7S9+kYIWHDobjIbpYGcpiqb5fxeTQ== X-Received: by 2002:a37:c442:: with SMTP id h2mr30494028qkm.283.1608136072238; Wed, 16 Dec 2020 08:27:52 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id c14sm1241077qtg.85.2020.12.16.08.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:51 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 32/38] btrfs: remove the extent item sanity checks in relocate_block_group Date: Wed, 16 Dec 2020 11:26:48 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org These checks are all taken care of for us by the tree checker code. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 67df6ae6d13f..93446ec5bcd9 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3371,20 +3371,6 @@ static void unset_reloc_control(struct reloc_control *rc) mutex_unlock(&fs_info->reloc_mutex); } -static int check_extent_flags(u64 flags) -{ - if ((flags & BTRFS_EXTENT_FLAG_DATA) && - (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK)) - return 1; - if (!(flags & BTRFS_EXTENT_FLAG_DATA) && - !(flags & BTRFS_EXTENT_FLAG_TREE_BLOCK)) - return 1; - if ((flags & BTRFS_EXTENT_FLAG_DATA) && - (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)) - return 1; - return 0; -} - static noinline_for_stack int prepare_to_relocate(struct reloc_control *rc) { @@ -3436,7 +3422,6 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc) struct btrfs_path *path; struct btrfs_extent_item *ei; u64 flags; - u32 item_size; int ret; int err = 0; int progress = 0; @@ -3485,19 +3470,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc) ei = btrfs_item_ptr(path->nodes[0], path->slots[0], struct btrfs_extent_item); - item_size = btrfs_item_size_nr(path->nodes[0], path->slots[0]); - if (item_size >= sizeof(*ei)) { - flags = btrfs_extent_flags(path->nodes[0], ei); - ret = check_extent_flags(flags); - BUG_ON(ret); - } else if (unlikely(item_size == sizeof(struct btrfs_extent_item_v0))) { - err = -EINVAL; - btrfs_print_v0_err(trans->fs_info); - btrfs_abort_transaction(trans, err); - break; - } else { - BUG(); - } + flags = btrfs_extent_flags(path->nodes[0], ei); if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) { ret = add_tree_block(rc, &key, path, &blocks); From patchwork Wed Dec 16 16:26:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977971 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42346C4361B for ; Wed, 16 Dec 2020 16:29:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08ABA233E2 for ; Wed, 16 Dec 2020 16:29:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726803AbgLPQ3F (ORCPT ); Wed, 16 Dec 2020 11:29:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726793AbgLPQ3F (ORCPT ); Wed, 16 Dec 2020 11:29:05 -0500 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A70CC0619DD for ; Wed, 16 Dec 2020 08:27:55 -0800 (PST) Received: by mail-qk1-x736.google.com with SMTP id h4so18167948qkk.4 for ; Wed, 16 Dec 2020 08:27:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=q3ZFkc4fZopbKKht4JgMg7mSZw6aGECg8+ejGJXrEGM=; b=vzLf3OO/MJA+uooK0qmLotMVo+n9OgvbbCWsvQosTYja+SZkq4NUCbbuoQhBXLWerv j7fDDQHpDwm/3NH4hmESnwEPVEXqs0fKy1/PX7k5dLaX78SJXen41Xu3fc4XjxBRvCCT PPYqPLWSe4XktEJeOns6fA/MC65hTYKJsTdJz8CdrQMEH338TMYclpuk//wlj/QMfpu1 a7o5vgnHxYNYw6dNb9VXYfS8Yjvi9qs2674R2p3QZXlUfjd9yl9yXUjjkqqD4rPmvlzo QTiEnU7dC19nIglBTVDySg8cpYcie6ImUEEOfShFyZopKO4u5XRvaV7Io7vlmpOwiGYz PgVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=q3ZFkc4fZopbKKht4JgMg7mSZw6aGECg8+ejGJXrEGM=; b=s+aQ3qso+br7f6xvw8/Po8OyzjVjvUlCvkgjDiFJ1tUDIDewo6RsGzOLgMx5eeav27 G0exFO8843bVYIqLX+2+4M5ju0KHGia+hj4UfQSXM+e9YyrrTGrietz/fWx2hftBzp0O RXG3cVtk/0RRP2r9NabD8nYi12lbQJcbpkPNZEZnXff3kpw+iL0o0Qzm6KzF0oTwxSk8 Lo5LeEmjqqxUP0AkCcfDj1LIF1ZgbrOpmB5q9a4AM4vBm/tiAp2gN3TSqs1G1/daFIzr /WWbvAyuF1QULKSvWOqwMc3Cy/W2VIbIDSeAZd9fvnHL/zJLFp8DVn6s5+eAoPy5ILMK +xhw== X-Gm-Message-State: AOAM530jpNLoaFic6f4FxC5eFfwFXpSmnVIXu+LHrk5gAKEfhWop467W 6PIspEZ/n0I1sqD62T3l6+vtfP5TeDMifoey X-Google-Smtp-Source: ABdhPJzYoCGLGUsW5Z/ewTG/wOk2fPamvB5VVHUoGpLBaX4QF2Nm2ZfVLgqOg06MDXpKt/+Cf+JTZg== X-Received: by 2002:a05:620a:38b:: with SMTP id q11mr18232108qkm.239.1608136073967; Wed, 16 Dec 2020 08:27:53 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id c7sm1195499qtw.70.2020.12.16.08.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:53 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 33/38] btrfs: do proper error handling in create_reloc_inode Date: Wed, 16 Dec 2020 11:26:49 -0500 Message-Id: <0635eb64208e5b6ddcebf6fea00d4928376c14c2.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We already handle some errors in this function, and the callers do the correct error handling, so clean up the rest of the function to do the appropriate error handling. There's a little extra work that needs to be done here, as we create the inode item before we create the orphan item. We could potentially add the orphan item, but if we failed to create the inode item we would have to abort the transaction. Instead add a helper to delete the inode item we created in the case that we're unable to look up the inode (this would likely be caused by an ENOMEM), which if it succeeds means we can avoid a transaction abort in this particular error case. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 93446ec5bcd9..26b85ab4b295 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3609,6 +3609,35 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans, return ret; } +static void delete_orphan_inode(struct btrfs_trans_handle *trans, + struct btrfs_root *root, u64 objectid) +{ + struct btrfs_path *path; + struct btrfs_key key; + int ret = 0; + + path = btrfs_alloc_path(); + if (!path) { + ret = -ENOMEM; + goto out; + } + + key.objectid = objectid; + key.type = BTRFS_INODE_ITEM_KEY; + key.offset = 0; + ret = btrfs_search_slot(trans, root, &key, path, -1, 1); + if (ret) { + if (ret > 0) + ret = -ENOENT; + goto out; + } + ret = btrfs_del_item(trans, root, path); +out: + if (ret) + btrfs_abort_transaction(trans, ret); + btrfs_free_path(path); +} + /* * helper to create inode for data relocation. * the inode is in data relocation tree and its link count is 0 @@ -3635,10 +3664,16 @@ struct inode *create_reloc_inode(struct btrfs_fs_info *fs_info, goto out; err = __insert_orphan_inode(trans, root, objectid); - BUG_ON(err); + if (err) + goto out; inode = btrfs_iget(fs_info->sb, objectid, root); - BUG_ON(IS_ERR(inode)); + if (IS_ERR(inode)) { + delete_orphan_inode(trans, root, objectid); + err = PTR_ERR(inode); + inode = NULL; + goto out; + } BTRFS_I(inode)->index_cnt = group->start; err = btrfs_orphan_add(trans, BTRFS_I(inode)); From patchwork Wed Dec 16 16:26:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977945 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9417C4361B for ; Wed, 16 Dec 2020 16:28:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77E7E233ED for ; Wed, 16 Dec 2020 16:28:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726772AbgLPQ2s (ORCPT ); Wed, 16 Dec 2020 11:28:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726763AbgLPQ2s (ORCPT ); Wed, 16 Dec 2020 11:28:48 -0500 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C85B4C0619DE for ; Wed, 16 Dec 2020 08:27:56 -0800 (PST) Received: by mail-qt1-x829.google.com with SMTP id y15so17587181qtv.5 for ; Wed, 16 Dec 2020 08:27:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TGT1uQEPkXlGSsuy+GeVOlQWvLE7GDlWh9fH5azgYjI=; b=ERkp9UYBxT0EmqE+N8zUrmlqwStrJC0ru8WcONwyYuVC5Xvah9u8wBeeYCME9vuMcj 630o31BDHT4vyoj1gjDj+hl68DujTA+3Ye2YCd3iYZMa9qy0p3YkrpHSx8+Tk5D33L12 7zF1FOd5NRvb3RgFvucSGo0Q2O5UedhBF94jtjOjA9MgSBdagPIDEUFsSBE48dQeYFZk VVJGuX5268CSVhsAj7HomkuMRdAc6i/I+uonaHNrspJrriaeINgIjFs700tPsAcF1hJQ Hr6KE39CfsIEH4e1FXPvU+nHq2oR9wnOaW/AhPsR8AwV0+NhFsulSCWuMQ40hDq5IGX8 zA2w== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=TGT1uQEPkXlGSsuy+GeVOlQWvLE7GDlWh9fH5azgYjI=; b=AFhNhnFBcscv3XaFEx/X6RUl8MAB6Dj9xrmRGbE2oJUGQv00gTrSciZ223tmp7JYiS 8nuLgwjhKdfBTOXASXk72jxLv9aI/xP7mmpvN1Vq3EoGAsgiQu4Qnni81uaQmdG16Cbf eeZlMXUibVKkra3LBZOfMMQFL+YBtFPLsc0EUMuvcIFCxxj8eA1XII1/dOUCBQbNGYNC DYJJRMWCTfG9zsbexOiGpVK0rRVo5adgUQA5vxn2qFOq8H641j7Qqq5v3a2u8Cktptvf igvnEdgl+W5hMH3pZmDuWCXP+EfCzUSL1iPlWDs1iql9RF9e7BI9KDfEoaaB8KiQx8Mp QVPg== X-Gm-Message-State: AOAM5335ZIeZ8cj1YxVYKjaFHEtAUXuJ9qPTi9GUZXPKJvdKm0I4Z3l6 tmjMcOoq9TXooqxSqHUCHTqrUUxuHyYeavfj X-Google-Smtp-Source: ABdhPJwKlD+EjT/7vjWbvo/Me09NMJ72DbNWfDFujGgIQrNef8B4VBrD5P2HxsJeZgkeShqyVDI0Qg== X-Received: by 2002:aed:3b13:: with SMTP id p19mr116198qte.302.1608136075749; Wed, 16 Dec 2020 08:27:55 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id x17sm109237qts.59.2020.12.16.08.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:55 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 34/38] btrfs: handle __add_reloc_root failures in btrfs_recover_relocation Date: Wed, 16 Dec 2020 11:26:50 -0500 Message-Id: <2cbb558f593e693a176d489d6e3c4d704718a347.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We can already handle errors appropriately from this function, deal with an error coming from __add_reloc_root appropriately. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 26b85ab4b295..39d5cb9360a2 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -4015,7 +4015,12 @@ int btrfs_recover_relocation(struct btrfs_root *root) } err = __add_reloc_root(reloc_root); - BUG_ON(err < 0); /* -ENOMEM or logic error */ + if (err) { + list_add_tail(&reloc_root->root_list, &reloc_roots); + btrfs_put_root(fs_root); + btrfs_end_transaction(trans); + goto out_unset; + } fs_root->reloc_root = btrfs_grab_root(reloc_root); btrfs_put_root(fs_root); } @@ -4230,7 +4235,10 @@ int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans, return PTR_ERR(reloc_root); ret = __add_reloc_root(reloc_root); - BUG_ON(ret < 0); + if (ret) { + btrfs_put_root(reloc_root); + return ret; + } new_root->reloc_root = btrfs_grab_root(reloc_root); if (rc->create_reloc_tree) From patchwork Wed Dec 16 16:26:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977947 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 344D6C0018C for ; Wed, 16 Dec 2020 16:28:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0A48D233E2 for ; Wed, 16 Dec 2020 16:28:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726773AbgLPQ2t (ORCPT ); Wed, 16 Dec 2020 11:28:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726770AbgLPQ2s (ORCPT ); Wed, 16 Dec 2020 11:28:48 -0500 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64775C0619DF for ; Wed, 16 Dec 2020 08:27:58 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id y15so17587332qtv.5 for ; Wed, 16 Dec 2020 08:27:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ur6ox4iL1o9MVeHXdYEjmLMvBsofMGEAupRdEsR8x8M=; b=wmv9q1p4FwH6Qb24vIzzak4sPILbj1fd8rHojC4lpYM3LjueuK7QVtjBzoxawnvbIH Ialnzvam2EgCpWqcgomRGKeADy1iYjMSrdR8h/HZlAxM10Q9PQ3VfD+d6BSE4bFBV1NK rgOZ34zSckbwl/bTWyvtyRAdiTZzKWmqgBxtWtSDGU+VQXHVzAOEocfhzo6Me1c5uE2T ctGwa41J4ZdeNuFN+v8WwkapXD/peeiWpJ8y2G4q7WeHxrrEu7G4cx3ZUYRPRwPMlJjL QwEx3z7mJwNyjc5eL9ZnKk2RavxmGi+bUNnqrjbz8LStAL6N4ZRMlw6tjFVM5luXbcqW 8ukQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=ur6ox4iL1o9MVeHXdYEjmLMvBsofMGEAupRdEsR8x8M=; b=gwiLIgtIdOe/mp/QvdeokcdRVFpjgahYMU5Qee/g3aj4RqvI70+nhwpdlAR32QKTej Qh70GwP8zGpfs4NZo3128gyowxcuA1m+2uKOw6eZ3XR8CPo81XbDXJDTN+lSsObn+dbt cXJBxuc7OQv03MrWxTzG/6jgQUWjXXD1n5efPYT5HWfu5PxU8uLGbQ+3ngLyPGVfbYel +Gx0A2NW6sdEjx/rB7XB2yPc3OXwCZLVXk5+u+GX8L8K/Hs5EJzqwjLy4+J99S7uaed4 +OK/Rj5w27xcHwTCWFdn70IMH4AhKO5Gib7twbRa/K4VDmVetKCfNhdcXYLSWQO7FPfB +sxw== X-Gm-Message-State: AOAM531hcEI6H3fKl4kzRgM8CTSQWssVtPFWHntqQGN0hoFohLQKrhgY JGfBQBhFlGzCcN+I43w1ply6xn0UoMpze1rC X-Google-Smtp-Source: ABdhPJw4SUbjLwrmU3Vgg6Rftmr4wgmv7AyV730pFoJV0VQaADYsWF65pbfcNPkC42Pfxe6oAHLaGg== X-Received: by 2002:aed:29c2:: with SMTP id o60mr43227293qtd.253.1608136077339; Wed, 16 Dec 2020 08:27:57 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id u26sm1332231qkm.69.2020.12.16.08.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:56 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 35/38] btrfs: cleanup error handling in prepare_to_merge Date: Wed, 16 Dec 2020 11:26:51 -0500 Message-Id: <1d9d1340374c0f463015ff251884aefc16dfb752.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This probably can't happen even with a corrupt file system, because we would have failed much earlier on than here. However there's no reason we can't just check and bail out as appropriate, so do that and convert the correctness BUG_ON() to an ASSERT(). Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 39d5cb9360a2..56f1fce7c746 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1880,8 +1880,14 @@ int prepare_to_merge(struct reloc_control *rc, int err) root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, false); - BUG_ON(IS_ERR(root)); - BUG_ON(root->reloc_root != reloc_root); + if (IS_ERR(root)) { + list_add(&reloc_root->root_list, &reloc_roots); + btrfs_abort_transaction(trans, (int)PTR_ERR(root)); + if (!err) + err = PTR_ERR(root); + break; + } + ASSERT(root->reloc_root == reloc_root); /* * set reference count to 1, so btrfs_recover_relocation From patchwork Wed Dec 16 16:26:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977949 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44652C2BBCA for ; Wed, 16 Dec 2020 16:28:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3CA3233E2 for ; Wed, 16 Dec 2020 16:28:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726776AbgLPQ2u (ORCPT ); Wed, 16 Dec 2020 11:28:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726774AbgLPQ2t (ORCPT ); Wed, 16 Dec 2020 11:28:49 -0500 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14EFCC0619E0 for ; Wed, 16 Dec 2020 08:28:00 -0800 (PST) Received: by mail-qk1-x731.google.com with SMTP id u5so10081370qkf.0 for ; Wed, 16 Dec 2020 08:28:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=89BqtHxNiNTkmRvwCnTOM7oyBg+jooBmj6s+FRkuRHI=; b=1NWh0cEL5/4iGJ8Q3EiYeVBoM6h3SYnwRG2ktITexgNEKIuL57jYJ1mhnfoeyvJ3mu HJ0wF9FlOKZuf+HE0VjMqHATB9qWl6zanYneb7xokSwH0F8ZBZzu/xuHwy5nUHv4hPwI Yb2IfKkjPN/PUsf5UsMx2DK157juCBMje6iEcFJXzbPiJm+PaBMV3MoUtEJEJa7s96Bo pD77q0Pr2kZalJlb+wFTgieqVZq4U8n5nAU9TI+igylw3M9Dzj9J9pU6/86HdbcqdBEn Uq08+F5idTZAYS6d48y6ZOC8onQ9TlSsSzNd3wIoLCs8iyaOho/PMiF/3n7Jk9jpRjto Isjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=89BqtHxNiNTkmRvwCnTOM7oyBg+jooBmj6s+FRkuRHI=; b=ICbCbJ3b51/n3RG6KFylUFlKZjwSJpF8G0M1pI89avVuuLr+27vFEAr1U0lSUZXY9B VayAHaoPIkwhBdzRMtc777MIN4JYyIpUwYwWEb2rBES2xifVhRf+YJeak0JmhMxcrduP 3nRzruw6hcRcB5A4hWikDrxqNdrDJAK2zv76z7OZId1Erb/72ldDxXZRYOLI8xx2NOww 0FhHEz/5JW2nyQwlMmyR1+XRnR6ZUZmDjosU4S8c79pBK8QXzgenTO68y605RqQuhyuP fLpGINTObzuOAPIxkeotUjyKabQgjFq59U8ibeVMg4DI63iAQ03gJmhYyXfgJ7yBki09 PPug== X-Gm-Message-State: AOAM532IvYo/Eu3KYufyrMHfWDl9bcL3wehg8ft+Mv7AG+9Nlb6mCXjW 75AUM2Qx7sivEw25VO/35nHOdkfpxf78tfCi X-Google-Smtp-Source: ABdhPJyn0utmCQMfrfT6k5wnFz6IKTwI+G9L/9PdWQFyq6fhE1TASwlUQacbvAMt37XL5qtAUtXp0g== X-Received: by 2002:a37:9687:: with SMTP id y129mr42324420qkd.104.1608136079012; Wed, 16 Dec 2020 08:27:59 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id x2sm1188435qtw.3.2020.12.16.08.27.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:27:58 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 36/38] btrfs: handle extent corruption with select_one_root properly Date: Wed, 16 Dec 2020 11:26:52 -0500 Message-Id: <438040a2d88f949f782f0a2f7e3460e1f98abc8e.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In corruption cases we could have paths from a block up to no root at all, and thus we'll BUG_ON(!root) in select_one_root. Handle this by adding an ASSERT() for developers, and returning an error for normal users. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 56f1fce7c746..3f71fbb5ea18 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2209,7 +2209,17 @@ struct btrfs_root *select_one_root(struct btrfs_backref_node *node) cond_resched(); next = walk_up_backref(next, edges, &index); root = next->root; - BUG_ON(!root); + + /* + * This can occur if we have incomplete extent refs leading all + * the way up a particular path, in this case return -EUCLEAN. + * However leave as an ASSERT() for developers, because it could + * indicate a bug in the backref code. + */ + if (!root) { + ASSERT(0); + return ERR_PTR(-EUCLEAN); + } /* No other choice for non-shareable tree */ if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) @@ -2599,8 +2609,12 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, BUG_ON(node->processed); root = select_one_root(node); - if (root == ERR_PTR(-ENOENT)) { - update_processed_blocks(rc, node); + if (IS_ERR(root)) { + ret = PTR_ERR(root); + if (ret == -ENOENT) { + ret = 0; + update_processed_blocks(rc, node); + } goto out; } From patchwork Wed Dec 16 16:26:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977951 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C135C4361B for ; Wed, 16 Dec 2020 16:28:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 703C4233E2 for ; Wed, 16 Dec 2020 16:28:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726777AbgLPQ2u (ORCPT ); Wed, 16 Dec 2020 11:28:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726770AbgLPQ2t (ORCPT ); Wed, 16 Dec 2020 11:28:49 -0500 Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6282C0619E1 for ; Wed, 16 Dec 2020 08:28:01 -0800 (PST) Received: by mail-qv1-xf2d.google.com with SMTP id 4so11588781qvh.1 for ; Wed, 16 Dec 2020 08:28:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=cc6c3zhNeg5+5Kz0Fi9vo893I9mz5REcSDVo1P5BB9A=; b=PJqIYvDzgEJFIyyoxVcg2wkCndKBM6VM7pXxJv53+PW1wcuybLjJ6Q7vrx7GXWMTlE WR90r+nNMwHVCvbYI/6rOwkmXP11apOe16qmLh2MNNSSs2CO9aKauBu/OxsutUsPKuau 1h65WvOlpjj+KVEgO0kPx6pjPhQfzM0G5jbtrWK+I2srj7spm4a6qFUOj5Bn1pBLsY8R GPXZdKnqaXoxUD2potXLaQO/mnDGAAPjO5lz/ydqQXtX5Miv3xMIVuk9YAPvGdoLk5eQ ZWGQxwzi6B3FM6jXklqXOmP+b3Wy/v0vkgDOHB+WYb/8TbnV4yWruQ7qEFAqX25UmM/L iEXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cc6c3zhNeg5+5Kz0Fi9vo893I9mz5REcSDVo1P5BB9A=; b=DU1TQFaui39/Gxj8JXvPlZ7eGDKAKeEGkzCri8DqrAq67dXh40MpDe2iNhmj+0FMId HK+W9tVJWCOeKB31H+PVtwzzZ39EYIGoQnVvSADfeQ//EzCH9S+Ayo3ewr08M3BIeauD mX3vksjWJzDSd5rRYOwEcpi7Krab65hprG+qNRtc0OGNuK4aQuJsQKC1dDlEw6uEx+Ns rbNwcDpHTvT7ZnNrnGrj5o0dUj/706a9uhoCn1Vb18l8uNLBVP8mkfDp6exY6UHcNKsO xm+NjcQBLMBA+o8S3wUIXRURLQHkQF2SmRYGEI7bXbe0ikA/YxzS9y8RbS1G0fD6kVXb u0yQ== X-Gm-Message-State: AOAM530ypn6L7wOljV+2E5+mR5BgbH42AghAJiXMkxRPIxAcprrsCEFJ 8gqmyGt8NeO52cfqw911HbUyeZRDTnTAVcir X-Google-Smtp-Source: ABdhPJz9YFwPBjfxLpte5HNdd5l/69PLv5MEs/87vZUSIcUFMmo0/WW1zNYyCiSKvpnDXzflsruFEQ== X-Received: by 2002:a0c:dc11:: with SMTP id s17mr28998460qvk.19.1608136080781; Wed, 16 Dec 2020 08:28:00 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id s30sm1256432qte.44.2020.12.16.08.27.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:28:00 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 37/38] btrfs: do proper error handling in merge_reloc_roots Date: Wed, 16 Dec 2020 11:26:53 -0500 Message-Id: <9af73ba5d4672c235ce5c4ae5033c026e3f57a73.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have a BUG_ON() if we get an error back from btrfs_get_fs_root(). This honestly should never fail, as at this point we have a solid coordination of fs root to reloc root, and these roots will all be in memory. But in the name of killing BUG_ON()'s remove these and handle the error condition properly, ASSERT()'ing for developers. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 3f71fbb5ea18..44743d1fe414 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1960,8 +1960,29 @@ void merge_reloc_roots(struct reloc_control *rc) root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, false); if (btrfs_root_refs(&reloc_root->root_item) > 0) { - BUG_ON(IS_ERR(root)); - BUG_ON(root->reloc_root != reloc_root); + if (IS_ERR(root)) { + /* + * For recovery we read the fs roots on mount, + * and if we didn't find the root then we marked + * the reloc root as a garbage root. For normal + * relocation obviously the root should exist in + * memory. However there's no reason we can't + * handle the error properly here just in case. + */ + ASSERT(0); + ret = PTR_ERR(root); + goto out; + } + if (root->reloc_root != reloc_root) { + /* + * This is actually impossible without something + * going really wrong (like weird race condition + * or cosmic rays). + */ + ASSERT(0); + ret = -EINVAL; + goto out; + } ret = merge_reloc_root(rc, root); btrfs_put_root(root); if (ret) { From patchwork Wed Dec 16 16:26:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11977953 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C08AFC0018C for ; Wed, 16 Dec 2020 16:28:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 855EB233E2 for ; Wed, 16 Dec 2020 16:28:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726779AbgLPQ2v (ORCPT ); Wed, 16 Dec 2020 11:28:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726770AbgLPQ2v (ORCPT ); Wed, 16 Dec 2020 11:28:51 -0500 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74FD4C061282 for ; Wed, 16 Dec 2020 08:28:03 -0800 (PST) Received: by mail-qv1-xf33.google.com with SMTP id s6so11599385qvn.6 for ; Wed, 16 Dec 2020 08:28:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=08eHlwv1HFrRUWzwFWY8rmWFXTfTj0GvVO545rzAiVQ=; b=kvzWb6GSDyOjhCR8+w1ir4ZWLdIhgcSN6qkknr5QtRpaAlQjI7ghT1jLcF9E9qVhGt Yr0fUP965dgCwii0Iivyf8GVapSXsRwmZKY91iE3qrJ0CLichMMA4+yI0s3bKTWNIMUv uEgd4ZKDHJt67d0xf8F5u4DVlh24936d1a7kCi1r8gIyLE1DhEHw+HO4vPblIDQ/gPRH vIE/SOgXxJ1atSSXMgfKzKYFzCJmYzWndv67rm48uunJAiHrws/0n027i4WFC3+qiyzT MtyfStOj4r7123Zq8J7phwFvh4GgrN0K208GyxoJpFVzzPxP6pskx3bisiDH+obnCvaM DW6Q== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=08eHlwv1HFrRUWzwFWY8rmWFXTfTj0GvVO545rzAiVQ=; b=TIuyZdWlWeS84OsWg3mXKH6ir8DFKuns+giPZwCNCvknt113MpTnFulLazjUcl62xG dezV5mtk5ZKv6qItJhwocYvOqjJhNX25aUlpM+krV3nZGD14Y0vOQWE7CbuTbOqMMtaW ktPmsZkZwQHlrCBxuW1dEbR0zYYZxTm1DhBdaIj9wQmzEMNzoJV68Zi208csOFmuSHji bOQUE+OH83AVCa1rg4EkyGSEQlLHKu89SIrjHC/7SPUjRS7BQMkX6QB5TWvln2Pz5alw Tl+3KCf1mJtVimLZetsA6UoqpkuWCXXf6+t+8ZF6B+V4YlcSx5hSHw9+Ga9urvaweSnQ 5UdA== X-Gm-Message-State: AOAM530P+gYg9fhounpaIlDfz6xVmEfHU9J7LYa7lceFFGQpPC5N5bQ3 dl8RrZ9Lmn9fZ6ZtWUhsl9YSibitLA+VfiKg X-Google-Smtp-Source: ABdhPJygSpbUch8mKUURubL+O6r0KD9QzvC6WfiYonx4OoCM/q9enbpdiD2tAcVt+A0kQBJxzcy07Q== X-Received: by 2002:a0c:fa4c:: with SMTP id k12mr43670533qvo.16.1608136082397; Wed, 16 Dec 2020 08:28:02 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id w187sm1419194qkb.81.2020.12.16.08.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Dec 2020 08:28:01 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v7 38/38] btrfs: check return value of btrfs_commit_transaction in relocation Date: Wed, 16 Dec 2020 11:26:54 -0500 Message-Id: <1a52fe84b41022f24cea283cbc621e2bbde2183b.1608135849.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org There's a few places where we don't check the return value of btrfs_commit_transaction in relocation.c. Thankfully all these places have straightforward error handling, so simply change all of the sites at once. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 44743d1fe414..26ecc55e9f59 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1915,7 +1915,7 @@ int prepare_to_merge(struct reloc_control *rc, int err) list_splice(&reloc_roots, &rc->reloc_roots); if (!err) - btrfs_commit_transaction(trans); + err = btrfs_commit_transaction(trans); else btrfs_end_transaction(trans); return err; @@ -3450,8 +3450,7 @@ int prepare_to_relocate(struct reloc_control *rc) */ return PTR_ERR(trans); } - btrfs_commit_transaction(trans); - return 0; + return btrfs_commit_transaction(trans); } static noinline_for_stack int relocate_block_group(struct reloc_control *rc) @@ -3610,7 +3609,9 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc) err = PTR_ERR(trans); goto out_free; } - btrfs_commit_transaction(trans); + ret = btrfs_commit_transaction(trans); + if (ret && !err) + err = ret; out_free: ret = clean_dirty_subvols(rc); if (ret < 0 && !err)