From patchwork Fri Mar 12 20:24:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12135975 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 1CB31C433E0 for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB48264F9F for ; Fri, 12 Mar 2021 20:26:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234791AbhCLU0G (ORCPT ); Fri, 12 Mar 2021 15:26:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234784AbhCLUZj (ORCPT ); Fri, 12 Mar 2021 15:25: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 E0EA8C061574 for ; Fri, 12 Mar 2021 12:25:38 -0800 (PST) Received: by mail-qk1-x732.google.com with SMTP id a9so25667247qkn.13 for ; Fri, 12 Mar 2021 12:25:38 -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=AJaeunyVJzcV15aBU0izNkv5ehGMAXv98+Ns4qkme24=; b=oi6U4upaDceMCPRoG9qGoyCFDVTh/KrUvtdqdCXR+g7JzwlQnSImHRnukrzUY9AzAX saniQCPvXg/fm/gaPXHonGC/8Te1K7tpLGS9RZ1vOW2tilQuBtWI5sCIHOl/q3Ldf3PP rlAsKu+D552JsvyV2X3LpR6qS6IetgNdg5BEVZuWwwzmxLpI2duq9I1Nc157OBUd7p47 VDzsU5kzBe3H0jrtt31MIbFXFuGzL71M7YlwvYAxWzjVScHAsDUr+YxUE0eFUwIymNrd a0rsc/6tOHTWnmkbAtYKWTYi/eccp7Wq8d9Km0lwmdysnB45rA6PzllMjnrUxP7xH+pS bO1g== 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=AJaeunyVJzcV15aBU0izNkv5ehGMAXv98+Ns4qkme24=; b=RFao5zENTEexSerwG/2RSBqAsIq8MPgbIuEVlNqFMwS+2x53fY0k6n038kGc4R+7Me U66bSvRRU/Oq6uZBjP0wZhvGEZIbeCpVoOlWEKld/YYLpXbhrHM3fMghv+G7HKBhAgfH vatyp6PAJi6DMvYeVPWjl7CrOrHGXBTckBOrrPha+HngfMw6GNKXLrIswGX1cjgbWJg4 SK+rRv8I0pBJuMmTOgsDC5g8ibtXIvPP6PDHkKV9UGSCgSB3OgHZwFX83KtYGcNMGFJl /d+OKLdLfIw+j2GBwC3GStkdt3/fJZnhIpXllHaJUu3PJLP1xBDGC1o2C8fv36ieYdpq cExw== X-Gm-Message-State: AOAM530qDHr3lAFuz9qo3Xq2kaIlbWnFhAxz00YtmbjafHikpC0Fhct5 E1sDjXf9+b1m25edAb/sNBIEcCzURwZpRFAp X-Google-Smtp-Source: ABdhPJzO4fJlh6xWuRKpZWK2aKVDuE9Iblg78XHCql1W4iFs919M4RBgPlyAVScD4zRUhiC6NOQiWA== X-Received: by 2002:a05:620a:806:: with SMTP id s6mr13594950qks.50.1615580737878; Fri, 12 Mar 2021 12:25:37 -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 f2sm5079672qkb.50.2021.03.12.12.25.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:37 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 01/39] btrfs: convert some BUG_ON()'s to ASSERT()'s in do_relocation Date: Fri, 12 Mar 2021 15:24:56 -0500 Message-Id: <7311ecd8203021a84eceaec06afc0b49217032c9.1615580595.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 A few of these are checking for correctness, and won't be triggered by corrupted file systems, so convert them to ASSERT() instead of BUG_ON() and add a comment explaining their existence. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 232d5da7b7be..63e416ac79ae 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2181,7 +2181,11 @@ static int do_relocation(struct btrfs_trans_handle *trans, int slot; int ret = 0; - BUG_ON(lowest && node->eb); + /* + * If we are lowest then this is the first time we're processing this + * block, and thus shouldn't have an eb associated with it yet. + */ + ASSERT(!lowest || !node->eb); path->lowest_level = node->level + 1; rc->backref_cache.path[node->level] = node; @@ -2266,7 +2270,11 @@ static int do_relocation(struct btrfs_trans_handle *trans, free_extent_buffer(eb); if (ret < 0) goto next; - BUG_ON(node->eb != eb); + /* + * We've just cow'ed this block, it should have updated + * the correct backref node entry. + */ + ASSERT(node->eb == eb); } else { btrfs_set_node_blockptr(upper->eb, slot, node->eb->start); @@ -2302,7 +2310,12 @@ static int do_relocation(struct btrfs_trans_handle *trans, } path->lowest_level = 0; - BUG_ON(ret == -ENOSPC); + + /* + * We should have allocated all of our space in the block rsv and thus + * shouldn't ENOSPC. + */ + ASSERT(ret != -ENOSPC); return ret; } From patchwork Fri Mar 12 20:24:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12135979 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 5B984C433E9 for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3899364FEA for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234797AbhCLU0H (ORCPT ); Fri, 12 Mar 2021 15:26:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234785AbhCLUZk (ORCPT ); Fri, 12 Mar 2021 15:25:40 -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 7F785C061574 for ; Fri, 12 Mar 2021 12:25:40 -0800 (PST) Received: by mail-qk1-x730.google.com with SMTP id l132so25715800qke.7 for ; Fri, 12 Mar 2021 12:25:40 -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=WEg5NZ7Z9SwA81D5qtcCbo6KqyrEoQGpeqB3rxmufLs=; b=J9lx4RQLmbUqnjwv2yhF8XdDWU16GOZ8QfZFiHx2sOCq03CRMCCHAVzhPsCaWDPBRt r0uI/ZIyLSL+NyndHQlc7SupWbRSgp/0vMVg9s+XksNs4jrAXq3ICEWo+2NcNam+SgKy 1GIYLXD01aMFtMz4nep5x5ZxLSI9imBM1/68Xr2TDkZXOPkGfjdEdgWrJswdpL6TAQDj WHHBGX1vSq1i11qPsLUvH0x1XGqYEmbxWdeE+HwwYRb7Wr964tAx2HpRxX0eYmLtcW+V ZKYy/86BG23lh0uH1R/r+FFigFf+Bu4R3MbsN4tRmwMAXYY4jGWKeCs5rn6sp/344Qup b7sw== 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=WEg5NZ7Z9SwA81D5qtcCbo6KqyrEoQGpeqB3rxmufLs=; b=qORsJith0wuA6snAWoGbFepqcqs7Sas2klfMjj/pUZ9ReFiQCQhLrXWG7zWGT8sKCN Fl8hf3aAR2rpU4VzzD6b1QHL9k3VMke3I8K/swy/eDjdpgHjcGqepr69KBwIJ9tZJKS7 pent5rXr00ZXKq4GvLZh1aoN+L2yWjpUUzvIApCnNbPoJf3U7/iXRyVxRyCpTgw/OH3e SQG4/cXcc5qAPH9rLLadnRan+R12N2zLKhNgHVPTMUCUNDODxkRxT18Jp+lsksXIcC+T 3ZuEaZ5Ps36pqbAe6G8XTfR6glpVLdFRdeUxf59BV/c18jvMLmJGqnh0SYEsmfbhVagd JDfg== X-Gm-Message-State: AOAM531uRDs5jTj5tctSQe50AQEI7iZE1GvFuNKXSIe1StYVBnxbntlk +F0RuUXDfqwelyNTM7rF/V+eZAAvCHMYhIBY X-Google-Smtp-Source: ABdhPJzcm8KAVJ1RacsVKHGlps1yzYloliZKJkr6KhDmoSEUsNzKkZAD1C3ukEY+AQolRRN4okX+7w== X-Received: by 2002:a05:620a:22f6:: with SMTP id p22mr14818838qki.297.1615580739424; Fri, 12 Mar 2021 12:25:39 -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 f12sm3723647qti.63.2021.03.12.12.25.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:39 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 02/39] btrfs: convert BUG_ON()'s in relocate_tree_block Date: Fri, 12 Mar 2021 15:24:57 -0500 Message-Id: <4b260de8ad7f37a5efdd2c50446e970c3e7f6572.1615580595.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 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 63e416ac79ae..1f371a878831 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 Fri Mar 12 20:24:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12135983 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 534ADC43381 for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26CE564FDC for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234811AbhCLU0I (ORCPT ); Fri, 12 Mar 2021 15:26:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234786AbhCLUZm (ORCPT ); Fri, 12 Mar 2021 15:25:42 -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 0A94AC061574 for ; Fri, 12 Mar 2021 12:25:42 -0800 (PST) Received: by mail-qv1-xf30.google.com with SMTP id t16so4894740qvr.12 for ; Fri, 12 Mar 2021 12:25:42 -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=Lmor2AJUSCuxsJBoEJr6kaL14eqXc0DDeokCLxHSgMM=; b=C9UMBOiWFmAeOOFqvQXFU+dQzsDQ06YUXjXH+phPv/BIhF30yZusYG30E3/lDeLr4D C0idN2uKV/oHU8QJ8FgBVB5kFpO2O70vclXgaLpId/EU6/yD97Nt3KrmH0HeHaW0oyxB zD1nWDTRiXGnA16shw8jksSuUcsTjznTFhVqIGIrHkMi8zqhxPMJa047GVAcgZ/vJ/E3 d8CxtQTDze7WrWHLQ6O31J+mbY3RXFjyJjbm+kRrrTL2NR09HTG3EO5Jeg4/DiTBzhPe F6gfUvutV5AXeZbAX5OvcrumrICnNXWIGqqffFLKSY4mP7Gon9vt2LSwTesxORuuEanN 5c/Q== 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=Lmor2AJUSCuxsJBoEJr6kaL14eqXc0DDeokCLxHSgMM=; b=HBtelCXDzizXPMCUKbskrybcjt0XXvVBE/YU8Ift3MiiaetYpuucXRvJTCYdb/73HM VH+VeGOr8rpQ3Cq3Vg7d8rXa4n1Fj3DiXrXcjxIm4ZBer3CqViCAdo3OpWo5bW5MdzOA E1Izhhzd0RH+CjvyOeWPLlzJXCFp5Dvip3kYw3wp6u3V9XX2wtf9ZyOkiB0qbRt2gvIl oczEiegOurIdTZWgzYhqUbIbgtHgBpZD5BIG+qCdMdcejseAa83448t69SGA3gvDO0O5 /AM3ED0j42vrDYhyWdtvr8lDQ0L1ewbXv9rcNNYUPIrjpa5t70s3+wz42RH1LuiksXCW QcIQ== X-Gm-Message-State: AOAM533d+t+5YGhwBZOO7LBgZGuq9Q9/DgiLfmbQAisFOJ7YlB4dcS8e AuHHI1IjnuM3xTjVNeqEVQGN8ylrp+9YY+A7 X-Google-Smtp-Source: ABdhPJzp6w8fI+jbjJLZIIHY/VENior6yG+5yZ++acWxnoR/49B+BafRow4+7Q/TTerdYVHQrivf2g== X-Received: by 2002:a05:6214:1085:: with SMTP id o5mr69204qvr.5.1615580740957; Fri, 12 Mar 2021 12:25: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 v7sm5199509qkv.86.2021.03.12.12.25.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:40 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 03/39] btrfs: handle errors from select_reloc_root() Date: Fri, 12 Mar 2021 15:24:58 -0500 Message-Id: <3d5aa5f2697cfc8847f344c2bc6d6a9207e4a508.1615580595.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 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 1f371a878831..097fea09e2d2 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 Fri Mar 12 20:24:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12135995 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 846CBC4332E for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 507A864F9E for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234816AbhCLU0I (ORCPT ); Fri, 12 Mar 2021 15:26:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234792AbhCLUZn (ORCPT ); Fri, 12 Mar 2021 15:25:43 -0500 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6D7DC061574 for ; Fri, 12 Mar 2021 12:25:43 -0800 (PST) Received: by mail-qt1-x82b.google.com with SMTP id l13so4848175qtu.9 for ; Fri, 12 Mar 2021 12:25:43 -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=oDj99o19CgBraoO9woQ83s+5ydPsfk+90Aj1I+n3hRQ=; b=I5AUtnSfbj+1NxsAluMUK3lEXnXyG+7ric4LSR3R2jzKTh+qZOHy8drneEYQvc473d T8voIUyGKO+BduX1UwSKBY96mcl2wgx/HXmTFLlWzSpUXj41eTq+M+9cP2Vx9/Lo3dVs 8V5jp5FrxtBxx1p4Ipq0QSwa4Aqq9pH/XPncAjJFJaSR65TYNkuxvI4Gl6AkJsb9HrPm vm4Pohc0zEdVlV4oTJj53kJPj4+fXys8J69v9wb2eyfxNbmhQa+3fNo6uorQJgWv2WPU 46jtrOG2SANRymd2PgUaDXrG73hYZ8+kLdsVZqCH5c2krYzVFA9P40/dSL57YfTbkB1d +tOA== 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=oDj99o19CgBraoO9woQ83s+5ydPsfk+90Aj1I+n3hRQ=; b=XQWbTvtJW8cKdcsu4bP5jc6P6esT13qsoamwTh1gs3IhCs1jQdOUQH16R79/+GwnxG WqoD7g7iBRI854GwkGFYgbm3EZJHSHujSmEUbVKqHPW1hh4A8zfUjtIOIKyqVGNSg9jC Kuciy3FUNbrgnfST2xkfqVJS6QPbqjpBp2yFo5CB+v53ElJikJcyptTK5Q+nyfQ6eq2A wu83YvJiyihvybXaKGnNEaxgPflufrUhsN6ldQr/oIBTqmA5znU5CJZktz/h1Mu0IpXe FEAQHu5VMO8ztxpHeYvjz/edCi9mZ+/Fc0wEh18DsCNR3rh5knd23kOhytjQ42XGPN7l a/fA== X-Gm-Message-State: AOAM530juRJqv0FRD1zOGIjr7LNWi1qu5NZDqOdXeEdA79nbN5S0eAx7 MhivydRtkElIueGaAibfe5bGA30bc1CGcJnq X-Google-Smtp-Source: ABdhPJyqMycniVMATHyT5CKfxvUvwMdQJ6SLrx1sgi5zo7aO1MFNFS9E29Mgsb5DrnN9iaEqArG2jw== X-Received: by 2002:a05:622a:18d:: with SMTP id s13mr13714756qtw.52.1615580742608; Fri, 12 Mar 2021 12:25:42 -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 21sm5191033qkv.12.2021.03.12.12.25.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:42 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 04/39] btrfs: convert BUG_ON()'s in select_reloc_root() to proper errors Date: Fri, 12 Mar 2021 15:24:59 -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 097fea09e2d2..0f2ecf61696e 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 Fri Mar 12 20:25:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12135981 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 79BAEC4332B for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 63BC564F73 for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234821AbhCLU0J (ORCPT ); Fri, 12 Mar 2021 15:26:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234795AbhCLUZp (ORCPT ); Fri, 12 Mar 2021 15:25:45 -0500 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D7CFC061574 for ; Fri, 12 Mar 2021 12:25:45 -0800 (PST) Received: by mail-qk1-x72d.google.com with SMTP id l132so25716024qke.7 for ; Fri, 12 Mar 2021 12:25:45 -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=6ZShPBI7AjyNrxGZbKP3JEKbwG7ciYzPWmjgBbz8TLA=; b=nWdoKbnuDFCHNtP1mGz5ZVyX41VF+1DeD9NM2WHeKV62FGsdcq8rHZwZ5oH7cwYFa4 vx4OQweCWy9H1sJgx9JSVwgBDUHp+9QVsOPEVdXhXe8HQQjYyF9UBYtkgV020OJH6bNI uwp7w7YlFIg5bn+8h/bVwJWWNjnD4g4KS+Q1X2fyTGRR4nQxfiGzOahWPczboa+le8Bp dd4bOdJ44rTuoYqjsLUS84z0ZIsgitCxtO+b8pcsi+kQebTglk0+W96SD+ryflOcGhQk hoFhcUTRGRC65/FwKt+NV4pcQRwVIhD3VweNxslbAHfhPf86yh9innosT76FECw8gyeY zufQ== 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=6ZShPBI7AjyNrxGZbKP3JEKbwG7ciYzPWmjgBbz8TLA=; b=j4gVFkzpBE3Kt8QYEyRD1Scv06yLwXEl++fLACkQWsk+wY5USb5BnZErqnG3HievwK MUDjbGrMkc9OZSj0cZWJF4vps5Ib8wn4n1cAkfCDiAYmyqXyNU+rRB8uttDM/Cr000r6 Y5DdddPi47j+9VxBEC56lNYJOZfEU5Lst7382kU4/vIJboj6C4Q2H9bFLWgKuTenFsYB a7ghn+t5XjHC+63vQDaFesI5kK2F9jdr32EqY3jzjazSMj27j0rWWgFJ2bPP/Cy3aD4L HkYVVLbiPYrCRMlYF3h9iQmpFxVz5o3w/yMNAoT5psQnaAm2cyHlTJlsforzXavMjWI0 +FFQ== X-Gm-Message-State: AOAM530tyT4j6SQUkQII7x9D2jc8ZPj8tyowy1LgNoU0NPORYsuxpamL TDqSUuvKsgi1/bEQ8HzkO5Wf2eyIToJdv1I2 X-Google-Smtp-Source: ABdhPJzGmqiUWNuXONGRmxkYGGYKMq1G0qRbgJeZEo6h/Fd/RwQJcxYQwvTcd22kU4B8rbiSei1abQ== X-Received: by 2002:a37:4743:: with SMTP id u64mr14548286qka.350.1615580744193; Fri, 12 Mar 2021 12:25:44 -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 d24sm5176835qkl.49.2021.03.12.12.25.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:43 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 05/39] btrfs: check record_root_in_trans related failures in select_reloc_root Date: Fri, 12 Mar 2021 15:25:00 -0500 Message-Id: <101e340fc079ffd729abf5913f9bda4cf0c61b05.1615580595.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 0f2ecf61696e..b70a666612a7 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 Fri Mar 12 20:25:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12135987 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 939BCC4332D for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74D7864FDC for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234831AbhCLU0M (ORCPT ); Fri, 12 Mar 2021 15:26:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234796AbhCLUZr (ORCPT ); Fri, 12 Mar 2021 15:25:47 -0500 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 313C2C061574 for ; Fri, 12 Mar 2021 12:25:47 -0800 (PST) Received: by mail-qv1-xf2e.google.com with SMTP id i15so4896745qvr.0 for ; Fri, 12 Mar 2021 12:25:47 -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=i2amck6xZdrsQXUWDvpt+mTCzs5n8YBqBaTJc1sKZog=; b=ktTsLulKa2+co7T8k7CWlu1IbnmBWwGVkw+zFhLyxSIi9wS/LHfZSiQKW/XenI8RWk dve5W11Ly2em03yAEAXSbr3pgSgHrDXEAHO1nYV0ciHDfuxR3FFIkb68R/JTmU9YyD5d eD0vO7Q1Kul91Ii3L/rTowavOwXMs8tG2/suYAvvxqKgXS9ejJAErLyyImVmJ4nUihae Y955IDk2YE8f+5q+48D5nXHC8S280RgDUhJiC1iTKdq6AwqeuG32Kbya6L4NfnlcuiV6 wLFb3+vLed2pnBgr7ppbsixsjDj42tpWS0tSH97kLD9xiQa2EanE8S+E0j/CwD3GU9l9 X+1A== 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=i2amck6xZdrsQXUWDvpt+mTCzs5n8YBqBaTJc1sKZog=; b=Ch5P48mEqIsZTvwuJjA7dLB1aMC1I9nD9RZXwlNzzLuw8aBfKSvS1zYpbMw0hgND3e M7I3H6Y7FbxhOKf/KAIjDYW1L9JXqjX/Q/0Z8430WncZP3lFipSQixYZ2vytkr/OdziW 5UEy587fM+2OVvYrx7ZMQtSQyPiRJeKkNp0tOBfyU7HqdL/unuIqQh12Y4MPilWdrNn0 j7q8V+mAE4vMS3yxZfQlq+YL8+oHQEHhgzUegjGR9CU/QlF+GMWNX2lOYyYX34BwqEmk xahsnSHjn5mfF7A+f85U5WSrg+vC/iviiMCyRMbC8glPvZGiQ5oXWilx1R5/9OjIr7FB FFfQ== X-Gm-Message-State: AOAM53386TyMMhUvVqI9/19P/WhCoKSiS+svY7MV1csSRW201lf0Lcxj TqKf1kIftPAGArIRJr1jcVg45glaDYqSN/kR X-Google-Smtp-Source: ABdhPJwEcGuw19ba1RGsuYLLeBmHyqZtOw28hlnvVDGGWpwnRUb/XameIIazW+B2+N0Dw2v9vDdTOw== X-Received: by 2002:ad4:4cca:: with SMTP id i10mr14062298qvz.49.1615580745674; Fri, 12 Mar 2021 12:25: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 d23sm5131220qka.125.2021.03.12.12.25.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:45 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 06/39] btrfs: do proper error handling in record_reloc_root_in_trans Date: Fri, 12 Mar 2021 15:25:01 -0500 Message-Id: <7ff494825bd0a0b4b67f00c761579c8b8d3c02c5.1615580595.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 b70a666612a7..28d49b14a23a 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 Fri Mar 12 20:25:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12135985 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 AC83FC43332 for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E09264FB5 for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234828AbhCLU0L (ORCPT ); Fri, 12 Mar 2021 15:26:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234798AbhCLUZs (ORCPT ); Fri, 12 Mar 2021 15:25:48 -0500 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EC62C061574 for ; Fri, 12 Mar 2021 12:25:48 -0800 (PST) Received: by mail-qv1-xf35.google.com with SMTP id cx5so4891015qvb.10 for ; Fri, 12 Mar 2021 12:25: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=AOSBjmx/iKdLdD/beCE3Hry8uoKx5iaBLMEn1MI4k+g=; b=yCsvx9Qr4jG9qzN4oSSbVrbwi5jO41dnJvEC0kMnrF2YV74EvC0Odp7CW9HfwGH4aB i/Qni1nRdLqwO0WjDe+YnEu6rZsSajrrKUdv7rp9A4FEVdWp9NEpgw/flm18wzsYOvKy huzYlmLBQDObzBn/3T4iSVq7KSLrdpJMaYuo1kZ9gcKJw/LaOWPp86UJRzWIgojGck+8 pO39FWSouGGtw4cLaPWGg86WnIt7U+kYjJkevMnNyAUoQTG3x7hS0HgMYH3kPr6FSczP PYcvwMwT0Y6ns9Kthh9cSbW9O9+okNYwI5pfbliKfuIZ9lPHYq/MYNRZf2prx1kA6h9w vKRQ== 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=AOSBjmx/iKdLdD/beCE3Hry8uoKx5iaBLMEn1MI4k+g=; b=LrSu48pVKaSPCXBRQhjIcNNzSYUIXen9mm9yR1BnKocaW1+7D/cv3dtKyXEAhgKbTV H4d3AEcz5+0jQUSjgTehKQC8M0toyYJKgWRJNyOKMunkgBMhl6I+8ZBqcbOTJ4mRU2pO 2sYyycimbP2lCtGb99paaFAW3kknPtl+awdctkwroGOImylEFzJdmu//cd/69VgB6Z6c eaTbnJOGgWXAfoth8gzmOE6f2sOUVv4+umjbXBRns8rvOWTAFLqfGt4slJAcPIQvo7Nq +IPY2FJmR0z00oFDvOJieUDDyRCk/QQH7219CaJEMG97BjZYjDu1MIBhwjyCzGi6H4Ep 8ceg== X-Gm-Message-State: AOAM530KHnlXZU7gSBzRPWNpvpscGlBfqZoYiRIiu0Y5/tcN+1Oyri1U G6RTeI5LLHRnlUMp4sSZMCBQ6rW4wml9JKxr X-Google-Smtp-Source: ABdhPJwb9yaJysoR6tCI6CJabJUkwN40770mm84kXP/f5ibgy3HKg3A7kv95hgqDTpXnc0Mf3a7Zbg== X-Received: by 2002:ad4:410d:: with SMTP id i13mr2056qvp.44.1615580747207; Fri, 12 Mar 2021 12:25: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 75sm5264974qkd.114.2021.03.12.12.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:46 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 07/39] btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename_exchange Date: Fri, 12 Mar 2021 15:25:02 -0500 Message-Id: <5c2b128df19473f7d252bcbd9e1d60b763d7a3c0.1615580595.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_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 52dc5f52ea58..a9fde9a22fff 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -9102,8 +9102,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 Fri Mar 12 20:25:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136001 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 BE2B5C43331 for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F88A64FB2 for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234833AbhCLU0M (ORCPT ); Fri, 12 Mar 2021 15:26:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234799AbhCLUZt (ORCPT ); Fri, 12 Mar 2021 15:25:49 -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 A5AC8C061574 for ; Fri, 12 Mar 2021 12:25:49 -0800 (PST) Received: by mail-qk1-x72e.google.com with SMTP id a9so25667739qkn.13 for ; Fri, 12 Mar 2021 12:25: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=yGZq1T84yQVr050eCKw8GJf16/T74xYoC5HGNX6oqj4=; b=jsQ3rS+sOfT2pv7XIOzXxDdTZ9geBGOAoLHPy1Gsgg8h7Onx6Cz1Ccz3nv3vrrAs+r PEaGucKOpKfoK7b3q6YHqmms2kMgl1KuVRp0bT11DXJGK0YT7UhCPmcImb0Y5GDnWvdb ZdMTW2wIhmsK1ZLuSGvO+84ibagQpFoZH9Knqc+SNiSFBaROolC+WhFekuSAjZ2rpPQW KMkzTaeQ4+d5FzgPTzvtECupAMcDbmJVrq3iQCQuDLXaT2423CszvQd9GUcAxbMh1KgY j40D5YPBEedrIBlcJMSqclk1SE9zoYZFaFfjNXOx6jL4Ejfstmfvtxbv5JN8FKnQ2j6i PD+w== 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=yGZq1T84yQVr050eCKw8GJf16/T74xYoC5HGNX6oqj4=; b=ctuSXqerZ2H9A1Uhb8ZliS1dTyQd1FHFIzC3MJ0YmbBr1SJk6TJRYx97Q2UepRH3aV JdRmEaaqMfQ0vN6StEGaPHRIxFGjk3CQMnbf4O46dqjlC4J4MTAZl3siAVQl3QLiiGf1 ACw4lCO/rUZOU56f2//ipee/oKLdSDPg/SMBVI5RTWHqR29RR7wmOF36cqaXqpPQV+U4 B+C+OEAZPRxr/+k2+fvfb6MxU2cStAK17J5p3gMecYM9A25md0EFQorG5HhA73dmtTvW vsVW/1++Ml//ffVOF2bmEZCGsAwp7/qzloOrCFoTTt234bsBEnUejMRsYmWIjWkZSWI6 GZxg== X-Gm-Message-State: AOAM5314ISUXNj8kNO+mN8NTeaotDEqgG12PwikASqXIxDDSDGpWTAd+ zUkWwAjEQWEywTRt5GOyH3JlRWnPjSWCKRJX X-Google-Smtp-Source: ABdhPJxlDlkCJobFot3eiBDTaMpHIbljcDT1AaGrgDRAlqy+M+D+Nnw6jRe4dB2SHezWRjZoJkGOBA== X-Received: by 2002:a37:65d4:: with SMTP id z203mr13946982qkb.254.1615580748649; Fri, 12 Mar 2021 12:25: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 m17sm5212400qkh.82.2021.03.12.12.25.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:48 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 08/39] btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename Date: Fri, 12 Mar 2021 15:25:03 -0500 Message-Id: <7416cf0c51b510cf4b8f5e2505f8684d8c2630a4.1615580595.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 a9fde9a22fff..c64a5e3eca47 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -9410,8 +9410,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 Fri Mar 12 20:25:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12135997 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 0BCFCC4321A for ; Fri, 12 Mar 2021 20:26:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D9D8164F8D for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234835AbhCLU0N (ORCPT ); Fri, 12 Mar 2021 15:26:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234800AbhCLUZv (ORCPT ); Fri, 12 Mar 2021 15:25:51 -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 12A47C061574 for ; Fri, 12 Mar 2021 12:25:51 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id u7so4831599qtq.12 for ; Fri, 12 Mar 2021 12:25: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=ZJxOsvuh1x8H//YwmN29+j5aX5UXFh5/mvrYpeDOYSc=; b=P8MiFZH4kLSOl9CdjYHE8IYw6ylZwvMTE5iGZciKjyu/NMUnRDIjc98D0AuuVpGi5k qGwB0koFVGlAtgMd6TJhtq1y/3SWyGomdP2RaEMehRhv1CHcsTsr92JhoiKkIUQLBod/ UtrdcTNP+dXSr8aH5zXiM7myMt+fVU8ZIIeTAx50Yti5y9HVuiJST/1VVEiVIDOfcS8z xYw00uocu4xkgELF+0JZ2VhdIoEiMh4EY9MQsqYOiW4Cl214j6x4fGojeLKTIY/aG8J6 aZjYxhFb6lHhVeQOZyQqV4I2E17jYHurZAzprIgRa5tAzlcFZvOLRxKXVSEDCz6sIL2y 45EA== 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=ZJxOsvuh1x8H//YwmN29+j5aX5UXFh5/mvrYpeDOYSc=; b=dn6vRZ0mP3jnT59aSCSLBSDeELRGB0wRfa6VrcigiSZPNbybK7MsBu6gtAXdDITplO uZskqcvc7i6C03zs1ZqZiAOXsSXYipmiERfW9OBsDZ085rxqDneYNNMluLtCxVQdn2su +MT7oQtto0DDcqG+JiYgDW+RK0TY43wM5rVKi+fAqF5+JayHMFldyl8feMpHEBGYZWLd OMUEUrGOt2eBF/ZVu/15P55MsdK1cm3vVw9sYhmr+3GBpzuO57wxupA8XFvvuM/SguZj iAx4jT+4uBy77mHmD4KLaPGAQeEOPeahuF3rU8+VvJXTuE2MbylfiMW6sQP7WQoekS/y /q6Q== X-Gm-Message-State: AOAM530a5IHjrI935gb2tWuzcuELe8xzlz3JZU014D5PXD1/Tc5TTkeG NZ7i/of6Qp2VgZGV8wrGaXxvNvWAq32rzqj5 X-Google-Smtp-Source: ABdhPJwwNUNyVh/w78Hz9Cj6YTYHj6N8JyCUjjwmSQg9CqyrYM/KYrxYVPrroxrZR/WSaq0keF/6Ow== X-Received: by 2002:ac8:dc2:: with SMTP id t2mr13328600qti.234.1615580750052; Fri, 12 Mar 2021 12:25: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 e18sm4548549qtr.52.2021.03.12.12.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:49 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 09/39] btrfs: handle btrfs_record_root_in_trans failure in btrfs_delete_subvolume Date: Fri, 12 Mar 2021 15:25:04 -0500 Message-Id: <0a799b56d387f1d9dfefb65c62236b03e8bcdaeb.1615580595.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 c64a5e3eca47..48c953d0dde7 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4317,7 +4317,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 Fri Mar 12 20:25:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136005 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 D98B1C43333 for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B974164F9E for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234839AbhCLU0O (ORCPT ); Fri, 12 Mar 2021 15:26:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234801AbhCLUZw (ORCPT ); Fri, 12 Mar 2021 15:25:52 -0500 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2CC2C061574 for ; Fri, 12 Mar 2021 12:25:52 -0800 (PST) Received: by mail-qt1-x82f.google.com with SMTP id l13so4848520qtu.9 for ; Fri, 12 Mar 2021 12:25:52 -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=U/aDohO5zMMuWf0AmUIAS+Kqci7E8TwpqYGGIn/pZEs=; b=mpJo+7CxNY2yRLIKAUxAaka3qw5VBfI6kkACl3Nd/M31eOb/dU3364LevJlGyc06D1 2qWBv4mQDzV/VajtIpgz/9EmeYYUZVPkKe80MPNoSBCzP77J4PYc+iafkruSs/CdTeD7 xNeqSGTQfkmjKqPgq/5+dGFUrcjbCqEQsOgnifxEs2vAlsLwByjU/4NthPZYxJ/1MzPG WmSWGUYRv+y26v9CBxNWB6yDP5po9blOxRpfi1X7ts67IYONSpni+YM656L3hNfiTdDp fzUCIMGHB7FFVGn51POGnHp0UKiLbXRmKorQuqlcryVqkKab0jggpKMLpy5vS51ZqhUc CzBA== 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=U/aDohO5zMMuWf0AmUIAS+Kqci7E8TwpqYGGIn/pZEs=; b=j2rZ9vMflPoVmHTzal8VGaK+VzD3CzJMcJOpkBxZKFUAi5kjJsqxqpXAZoEdAAt8sb PK8CJUxspkhT2L+50iUlhMo+QcKlP41qV8uaJgSE5mOtc056k5H54NJu+QpecdvQra4U wHIWJ7nREXl0Mjv1aFlc/Ynj5gg+XGw/UwN825rm6TlLXtEFAVnqFgqn6zf+nGAqT8Oi xmjC4bqVEWbSNoo5ZL5z1l4kiZgnMaxHWcrnN9CwrgjEr0DHDrvZS3CNTJAcVeancgxM wy9rRMo0s8fPjK0JvF6oi0PPrq3qVUgbb/Tcs+QStXGq8H8faCfyRnOt3vorhd/PlxUS PEIw== X-Gm-Message-State: AOAM532gyGIyI3sIUSZSI0v3u0AWnvUqBwONaEeCzpjif0Cm7ByfaKlj auyJJwYbuzda4paVEKTrFHWjO9bV4fQQStHf X-Google-Smtp-Source: ABdhPJy6BddcAAOTNMhVDTosnyAm3o25p04ucrKXby/kqlfcuiBOcwuJdwrf0xmRleLYT/0l0fUwqA== X-Received: by 2002:ac8:5c82:: with SMTP id r2mr9990608qta.201.1615580751610; Fri, 12 Mar 2021 12:25:51 -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 l4sm4632001qte.64.2021.03.12.12.25.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:51 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 10/39] btrfs: handle btrfs_record_root_in_trans failure in btrfs_recover_log_trees Date: Fri, 12 Mar 2021 15:25:05 -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 2f1acc9aea9e..941b4dd96dd0 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -6278,8 +6278,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 Fri Mar 12 20:25:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12135993 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 3178BC4360C for ; Fri, 12 Mar 2021 20:26:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 15F5A64F8D for ; Fri, 12 Mar 2021 20:26:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234842AbhCLU0O (ORCPT ); Fri, 12 Mar 2021 15:26:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234802AbhCLUZy (ORCPT ); Fri, 12 Mar 2021 15:25:54 -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 52E73C061574 for ; Fri, 12 Mar 2021 12:25:54 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id f12so4835209qtq.4 for ; Fri, 12 Mar 2021 12:25:54 -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=Z+uodiFjP+HFgtUyY68U8zF2pVNFl8Wi2YW3O8bwUhg=; b=huWeh3KIBnIgq26rR/PgCsFbqIWxzCsVMFqRFnkCvdvuAocbmrFznhKkn9zl/LM7hp C6qR6MzFH8pnSEPoxGynMvepf1+4QX0lk2APTYO5U53SmFCXsRssPNeWTDPDb4T5R8F/ BktsChBpqF0T55EiVTbsJIWObYhb5P3Q0ggRZ4T+NXfdGF1X0PhDZ4DvKsb648VdxGwf fBvThABVr0hfNzfaAwPBMKKKa+cLCoS5Jy9CJAtx/e69eUYaeO5PFrrJxecVQYxyT4Kl 6dwQvMMEBT39s8P49A2w756VRZ+zm4MK1r9rAJ4N7alaLzeWgx1Qwqx4N6AM/pLgkxNh BtNg== 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=Z+uodiFjP+HFgtUyY68U8zF2pVNFl8Wi2YW3O8bwUhg=; b=h30nMfUG3+f68eBdaQeE4KpTqiUKzgceYxqwN04CVb2d92STnhj3PIHKKp5Kt+R1AC vcYTOmcsMLYxsjceX4ciidBowYiHdEfZUAB+LzU9tc8OlhgX7QYOa7LaH4QaV6SPeUEi nSA6yTyVjRKycbtSufHL1ra2MH5/I41SuqvN7EILAH1N2GkI2O/wA6peWwP4zbifUmsM WaGLoxYwq/JSQ7iTAfX+AmqKV6s5FRMWRZMdWijKgshtVWkoAoOj+K4GRnAkZAf8wqWG PSN21cbtPetOS39mBs20ZMQVIcV3ilcAm7wRXHwqL4k159Aj02R+9mmJ9EpHBlMN7WU5 PPRQ== X-Gm-Message-State: AOAM533KQln7LkTA4HzFrxhUrHVWpJFVDdmWZFhb+MNMBOfXb4PU4qwY MO9vkHTh3K8p4B/H0YmpRW/tjC8yDYorrhEL X-Google-Smtp-Source: ABdhPJwEn4sQOjf8ZRxuugKsiA8yHKI83iJi1SC5KPsVkycRhvodJheImfoEPPbzjRfyT5PjtBXqeQ== X-Received: by 2002:ac8:51d6:: with SMTP id d22mr13430748qtn.355.1615580753211; Fri, 12 Mar 2021 12:25: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 j6sm5306106qkm.81.2021.03.12.12.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:52 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 11/39] btrfs: handle btrfs_record_root_in_trans failure in create_subvol Date: Fri, 12 Mar 2021 15:25:06 -0500 Message-Id: <13787b7b2e23314817a592659364e9940b3e17d6.1615580595.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 e8d53fea4c61..29dbb1644935 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -721,7 +721,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); btrfs_put_root(new_root); From patchwork Fri Mar 12 20:25:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12135991 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 20CFCC432C3 for ; Fri, 12 Mar 2021 20:26:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0211F64F9E for ; Fri, 12 Mar 2021 20:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234845AbhCLU0P (ORCPT ); Fri, 12 Mar 2021 15:26:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234803AbhCLUZ4 (ORCPT ); Fri, 12 Mar 2021 15:25:56 -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 0F2FEC061574 for ; Fri, 12 Mar 2021 12:25:56 -0800 (PST) Received: by mail-qk1-x72c.google.com with SMTP id f124so25702661qkj.5 for ; Fri, 12 Mar 2021 12:25: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=JmEVrh7Q4lljkARgjKRDJA0uUhmTBg9BsuVkxoSbppA=; b=ExLvkt2Np2wUfBdBOJpmx2y077drSNwLMdOkLPvtOlrp7JRyZSnZMjmygpSrFQ0m9O oDy3qkuIYQUo4/XXndYgua2So7zROUc0blJzyrlt1fh+sDgCACxNkO+U5Tqxo90ZYZZf YQzbpZJ/UOUNhwuP7bCj/Uj35bExa5RPQVmSCPw9+ILWQdNaF4DUYuh/Du/sVE5YN/eW zl9GOZl4TdO0xZ/CuCt8ip/8YxbgLCVullxCwsIDlKqEE26JRMNc4EYmOYT/faNOkhhM Yx2OgoZqKrohMPpy6S+Jx8+YF5mUEWAnzRYlp0nCWA5C8O/DbJbMHqmYnnaFPwPSfhtK A2VQ== 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=JmEVrh7Q4lljkARgjKRDJA0uUhmTBg9BsuVkxoSbppA=; b=DLqqr1kkbirh1Rmap3Bk6oUviSJ4R/1P+gUPj13OIhtZMM6+L22AihqE7x97TKpx9S aqESq1rZaECeDe8sjqVzrm0ygr/mg+atbHoaGOgW0S33EkL7uqluxsrojERIezdKmSHn k9gmtiA0baIVpEx5CX6o4pngol7XDmwEMb0LvSvomh4rUH5Coosaw9XC9TcBUREOeIO7 VjjJAMyuap915sn14KYCYzOKfdrcS8CwMiXFPvhK/TigWtfg0INDBIzTBqh8l1kTR9x2 6EXQzQWkyBpGoMTzEKE6emnI2QVfUiCY7Hbqw3CykAyZNggOYbVgl03ynSErbKx7oXAb 6V3Q== X-Gm-Message-State: AOAM5308AhiozuTK4WRuW5STPZ/vX6RtddcBiYogefFu8bkZkKPAa0RL nSIhbQ1QMS6c7pvfXuYoIHbMsjg11levSbnT X-Google-Smtp-Source: ABdhPJx/rY3xe2tAxL5ueCKU7Ai7H84pWaJJfotyWWtcCQ8Wad418tOVHcBiVelbR2zhnk274Q32YA== X-Received: by 2002:a05:620a:21ce:: with SMTP id h14mr14099023qka.22.1615580754758; Fri, 12 Mar 2021 12:25:54 -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 d84sm5243995qke.53.2021.03.12.12.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:54 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 12/39] btrfs: btrfs: handle btrfs_record_root_in_trans failure in relocate_tree_block Date: Fri, 12 Mar 2021 15:25:07 -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 28d49b14a23a..7ca7ab3d40e2 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 Fri Mar 12 20:25:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12135989 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 3F055C43603 for ; Fri, 12 Mar 2021 20:26:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 296C364FC9 for ; Fri, 12 Mar 2021 20:26:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234847AbhCLU0P (ORCPT ); Fri, 12 Mar 2021 15:26:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234804AbhCLUZ5 (ORCPT ); Fri, 12 Mar 2021 15:25:57 -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 4ED21C061574 for ; Fri, 12 Mar 2021 12:25:57 -0800 (PST) Received: by mail-qv1-xf33.google.com with SMTP id h13so4900541qvu.6 for ; Fri, 12 Mar 2021 12:25:57 -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=Bj3zOBKirXBULd++EZGtXaDPZZNpxfqcEWV8wJZmz1Y=; b=VoXRS5X+ZhVfnHtrqhG1zBb/Q+hyItvfXonVN9cNezbHk2WDK+KZBPhuf/9v70smQ4 evkZl5xqr6WYh+8L9o5PaBMbEqQHuWGIJ9/Gz8+W//VVbcGMdFmky/CQkYYwR1x+s/Ki NCrc/wMqlUptAzMQXLgHIGSPTwBrBi+8QsbwMRWQO6Mal2aa8nYb7uC577DXLPc8vvvT pzqkxoqi1c9QjtYZ3DoasK79sfEohnNtz2ZYm1wT2XQM8St5cnw8PijxHfKSDmGQ3dRv 2PD3dR3L6BKLXGFvSwunKCUd1wTNHzCiGDCUuoA8779Cvi/tJohctZE4uNl+aY8NuaJk JnIA== 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=Bj3zOBKirXBULd++EZGtXaDPZZNpxfqcEWV8wJZmz1Y=; b=elfAqUiPtQGRpxP/9f/VHQPj/Un6ATtb1ebfFqRkQZA8LEPTFrWHHWh56MF0OSmfZ1 CBh+WuRW5e82IuLsWerxZPKg7Ap1WJQvkRFSxNs6RjpcIPmfIvlDzJxE9KG4wYKD6+EG 0/qwh4g1MAy+pMi4JKs9a8Ad+pkPwMXiTCgDNr+fH9rf+VhNmsGRbUk20mOeu7YMZeZV WyGEDspw6TT/vad3NReeUBK/FQ1UoG366uRh+vcmEP9yr/l6SaGJn5h4YCLe1k47k2t/ wiQY1lh9A+V44+favYUCAUezYnKfjob08H3NAR45cep4R9AQi2zaf7VYwogS79pJq8s+ 6mBg== X-Gm-Message-State: AOAM531NyuPoKjX2qFxvOMrVLe1c/jhRkNaBTaaoGp/VpxRpp7yWYyWj IAG3uOIvY+h65+woTVrMci4fOFjKEYFtFtEa X-Google-Smtp-Source: ABdhPJxDx6XcS5Npy+svWtuyYy4L+liZx0Kqii0H5jcswvniGib9+JezElVuXCWS/RIFymIsewK46g== X-Received: by 2002:a0c:f541:: with SMTP id p1mr24901qvm.14.1615580756306; Fri, 12 Mar 2021 12:25:56 -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 d70sm5311855qkg.30.2021.03.12.12.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:55 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 13/39] btrfs: handle btrfs_record_root_in_trans failure in start_transaction Date: Fri, 12 Mar 2021 15:25:08 -0500 Message-Id: <3e39257bf659d40433b6d348d621d8612cdad1a6.1615580595.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 acff6bb49a97..3a3a582063b4 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -741,7 +741,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 Fri Mar 12 20:25:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136007 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 539BFC4361A for ; Fri, 12 Mar 2021 20:26:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D04164F9F for ; Fri, 12 Mar 2021 20:26:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234849AbhCLU0P (ORCPT ); Fri, 12 Mar 2021 15:26:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234806AbhCLUZ6 (ORCPT ); Fri, 12 Mar 2021 15:25:58 -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 B51F6C061574 for ; Fri, 12 Mar 2021 12:25:58 -0800 (PST) Received: by mail-qt1-x82c.google.com with SMTP id s2so4833908qtx.10 for ; Fri, 12 Mar 2021 12:25: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=UpEwvVrgtX/qmbF7ZoVe+muqS/VaAiIhL2VAalGSYNo=; b=aOCao0vxzuhfGGTdQMpZVGMk8ymaKrYBqYoGb1bnnKTKHVum33MSb3Wga/aPdAPsPB v3m86Uu8e7q0ktfPrkSamH3i+HiuB6idbPZJHh1bQJEXS4K43rFHG0++iMeuc0bjIzfW +ytGrXS0StGN9XCyDRJqV8BtRZqScbERq6MyG8J65YXLcboNWyZp8+pmGuUOa+BX9dQM E16H4JiWtuGmRZQtz4ddQ5YPHSgTNVc9lCbVstTKoeisW2FryoDSsG0JeC8g9DrFBwWl 2odXiygJa2wfbQkxZgJnkYxUWcsH5TQLbHtVOSNbwOSGvpLZpzlvWSt2lhoijTdW5hmv UdXw== 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=UpEwvVrgtX/qmbF7ZoVe+muqS/VaAiIhL2VAalGSYNo=; b=BCLTlte1IX36TVH/J1PJ9thDWSCvg8qFTitejQvPbStDqpdsC6bSnqHofYUM5OZYlV twbs/QgXlq3KbIfJqBsPvWezE11G2eZInr7oibOyyDckAx51GTJvOjLWZycJu7A+ctrO O1rSnCmSfLZ75/C4AOwtvdF9RnswSTxz1b8d/g699dnImEYSv5WEQXrZa2+jt8CZ9Bhg RcHhr6d1MvehfZb6EWEb/7jgD0Rr0sDrHQRMh/Wtbcj4v6cJNZxjQvllyaLHCCN4thAB R1J986MK1cHijzBsX/ddNFLiStVlr5ZbT3j3rOmm1zCipD9dUYs5Z+zutFUChy5MYMmX 6ZVQ== X-Gm-Message-State: AOAM530zy/2dF3UFOpnviMH2njYHrTeFp3AW0b+zvZeo+LIxVYzILcqt 9w5O5/AVOGx5+foXVp3PaBg1cP9QoYF6czOL X-Google-Smtp-Source: ABdhPJxnEZtNBmZT5xdcUDa4Nl0N2z36JE4FiSrGC0N7Nk85pqCJ0vCmrUIrLPVtVY0VZ7pRUwnDaA== X-Received: by 2002:a05:622a:408:: with SMTP id n8mr13832933qtx.64.1615580757723; Fri, 12 Mar 2021 12:25: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 p7sm5295031qkc.75.2021.03.12.12.25.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:57 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 14/39] btrfs: handle record_root_in_trans failure in qgroup_account_snapshot Date: Fri, 12 Mar 2021 15:25:09 -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 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 3a3a582063b4..26c91c4eba89 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1444,7 +1444,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; /* * btrfs_qgroup_inherit relies on a consistent view of the usage for the @@ -1513,7 +1515,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 Fri Mar 12 20:25:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136009 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 6CDBFC43619 for ; Fri, 12 Mar 2021 20:26:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 54BCA64F8D for ; Fri, 12 Mar 2021 20:26:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234853AbhCLU0S (ORCPT ); Fri, 12 Mar 2021 15:26:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234807AbhCLU0A (ORCPT ); Fri, 12 Mar 2021 15:26:00 -0500 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49B9DC061574 for ; Fri, 12 Mar 2021 12:26:00 -0800 (PST) Received: by mail-qt1-x82d.google.com with SMTP id 6so4828931qty.3 for ; Fri, 12 Mar 2021 12:26: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=GnMZDF/O4JZv/4zqXZjtvesTd4a9V1cxhp5IFVF288s=; b=XknyHN5gKkuJ8o6+wiTTuEeEoA3ug0u4zi/2W17VH/WolBTNbwSjxJjvTzjgx9WD9V pdharBYhSNwhvY1XpV+gGAWnCyPQbIFFG+Hs6y/6HTdu9ODhNZ/cjr1Uf/Qek3HqZB0m qpV0dZzwlA6IpW+vJiX9awMmILtpM/aWaUp3wxYH/hUsn/bEz121e67qKggmhcLSic9i s15KuEXoYKXKQuddFAPcGYtJLEfhSlh0To5tQSqbb40cPMNb3VaLPvPnfleS3QqFznhI osI+mR0/YWQ6KpRXUIh9/v4LOjoL2w3hjHoA7dI7i1bWEWxIw/CIcb5Gtz8hca3va3jz Z8bQ== 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=GnMZDF/O4JZv/4zqXZjtvesTd4a9V1cxhp5IFVF288s=; b=sOFkXQG4aMtAVWXHIh3QNV1ixzLe4uscqoRVnLSn7HaRiWs1nLLco71Tv5vUe0QTsc OYNQnXuoErugD/hHHu6PKoiNZhtyK3RVdN+hduhGfPKbv/ZfAH20TNzBFuTMrXr6QOjh 02oSDoZSVuDYNd41HLbR6TOT5C30YTk9MNzHq1FllArwfgui8vl9GSanOoDohh6vRAvU cXtKHFUD4ikw44sJveAG7QG6MF7qtwMLJIylro1xD0uGVm/w/PaCciR0nnKl3pWMDtHt 4IV5Y7k6PyVFusiRVERzt2+MaCVaxR9dGY5vKHd1TycZjtwgONWmjI7cydS7TThcR7/q owmw== X-Gm-Message-State: AOAM532ExSesNtqCerVF9Zhpz7mjN5qHC5n4GsLKlBwu8ShwvjfCt5nx mkqQE6p2f1sGrUjksvK4kn3O2Zb3I3VIzLKD X-Google-Smtp-Source: ABdhPJwEogEb2ne0XqDZtYaOjQQJE0DDn/hdSFifal5mLblC100fzuH+ZVSlBrkqgBLDIvYRCsUexA== X-Received: by 2002:a05:622a:3cf:: with SMTP id k15mr13756028qtx.368.1615580759313; Fri, 12 Mar 2021 12:25: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 z7sm5095739qkf.136.2021.03.12.12.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:25:58 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 15/39] btrfs: handle record_root_in_trans failure in btrfs_record_root_in_trans Date: Fri, 12 Mar 2021 15:25:10 -0500 Message-Id: <13e101dee1ffe75dc455cfa8f290f80f2b176ee5.1615580595.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 26c91c4eba89..7ee0199fbb95 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -487,6 +487,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; @@ -501,10 +502,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 Fri Mar 12 20:25:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136003 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 7DF63C43142 for ; Fri, 12 Mar 2021 20:26:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AF1E64F77 for ; Fri, 12 Mar 2021 20:26:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234863AbhCLU0U (ORCPT ); Fri, 12 Mar 2021 15:26:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234808AbhCLU0C (ORCPT ); Fri, 12 Mar 2021 15:26:02 -0500 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1A11C061574 for ; Fri, 12 Mar 2021 12:26:01 -0800 (PST) Received: by mail-qk1-x72d.google.com with SMTP id 130so25672317qkh.11 for ; Fri, 12 Mar 2021 12:26:01 -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=4FFcEtxwSgtNWqhcRxM+yT++TU/naLF4VcA5kbiH73Y=; b=sN4TSMoI+B7xLo5YICtMkO3Ncj20FrZb8rxKQaoNoP7te6iOd8HOVKyIqlJzFuqLsU u9mC/pYaqkDWIhuWzGaIWRekPJzmCLaVBR7RsDzXy0R9xb9ZMH93N6gdJlUZbot9nJkJ Hos7jWSVghP3m3XuJ6ltb1gWzlwJ+L+AB0SXY2wPmWI1lusxmOYcUqPthRmwlZles+Ak R5nbMfq2kuYd4YkU6Iz6Cei0yR8j/8xME+BewrxiPH/Cu1KwR5X+H+76v03AX9i3aqJq ISkyYdOH6eFWOS1v+P+bDt98kH+DZfw8rgyPWUXt6heY1bZT+fcFQXHMYNJR15pZG0K+ ZQKQ== 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=4FFcEtxwSgtNWqhcRxM+yT++TU/naLF4VcA5kbiH73Y=; b=ZDHFqvV6SlHj7tCwShquK4TEwHYDpAhQBStyl4wxM18h/57z3TmwhreEGT4AMvNjOT VD2/0WqMuwaIwgKnKIsXJq5wLacGyPWCTmlyW283TIPlkB3U/YMvikzVMSbWi4Lg9wL4 XglIW6/+QS0QRM1vUjjbIq9WYn2VjpbUS+9hPir+4urLT5yiY7vx1d02oP+Xm8VhCdiV EqlntW3QM+aCAzQMJBOTxRWjZ0jjqq2HqOOukQhhU8cU+Fe8etlGE8AIHCmUBGP7KOei 89OrTbAl572b8t3pk2ky+cqcEDdi+eHSPUo7YUd3190Bqf7MS7txtXo312FKDEAdiYSP OUEg== X-Gm-Message-State: AOAM531EWSLX7ny6Isgtyxuys5lkkNZHLOo/bi7GIvyrCBDp4kBdzW+P SljzsRMCtxmB/CUUfeBLl16fSwT4U/ELF+Ot X-Google-Smtp-Source: ABdhPJw/opq8sDnkCCoB97qwgKWRatoISdcHbmCV5PnlhBLBBmFTOyHcjG0fbM3xPdFEw4lJgmlOlA== X-Received: by 2002:a05:620a:555:: with SMTP id o21mr14705192qko.207.1615580760908; Fri, 12 Mar 2021 12:26: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 i93sm4690293qtd.48.2021.03.12.12.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:00 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 16/39] btrfs: handle record_root_in_trans failure in create_pending_snapshot Date: Fri, 12 Mar 2021 15:25:11 -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 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 7ee0199fbb95..93464b93ee9d 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1593,8 +1593,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); /* @@ -1630,7 +1631,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 Fri Mar 12 20:25:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12135999 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 96A23C4361B for ; Fri, 12 Mar 2021 20:26:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E4FE64F73 for ; Fri, 12 Mar 2021 20:26:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234865AbhCLU0V (ORCPT ); Fri, 12 Mar 2021 15:26:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234809AbhCLU0D (ORCPT ); Fri, 12 Mar 2021 15:26:03 -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 8893DC061574 for ; Fri, 12 Mar 2021 12:26:03 -0800 (PST) Received: by mail-qt1-x834.google.com with SMTP id 6so4829069qty.3 for ; Fri, 12 Mar 2021 12:26: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=S/NhJOQ1FL+FHgqYsekSsbxVYcnIQpBp0sO03ubl1tI=; b=hMb5wuVY0SFfXCktHAazZGpnkdgSx454xSBbvDfpsSHA0EY1yjHXA3feTan9GSEhLU PreL8WQ/0Ay5JtgXK/cKDoDRw/qPKUDAOA/+WnYGymPpQTbcnT8D3W+ts9MVDoUjdAzF LEm3lhY7w9tjdXw5PZp6w5MMpitmdbueJf5PbGDGVwPE0JL/AjNKugWwFdbvM76s2NN5 KN/A2pUrTPPG6cjnO4tQSKNW0kQGA+IMRJSTxNyj5OHewyf+sqhQiESWzm1Ebe9t69I9 tNkMeM2/rJmS5/yh/vtDHwI795QkWarX21LBgU7pliCOpI0YDvCazZhj/TzsKKZyH3Gg 66Jg== 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/NhJOQ1FL+FHgqYsekSsbxVYcnIQpBp0sO03ubl1tI=; b=fdvFEl5G7du38W5wMK50ico+tZ3dOLefS/Ci+3C2ryQoS5QG303B/St3dZ5NmEo8mv Jp+qdnX8n/ffM+jOP2a+agOVAo51k28ENhh89eeaF+vklndglb/pzBoUwP7xP6SEyw4Y GpoWEsQFo2hIQ+ESgfWLpPllkO5l3BYT7epCpI7pRKJPl4keqlXxkJMckZGh2Ps1ReEt nCbqjhuIpMEUKSfWHms94w04UbyoBbObl3pKKxp19+G4rbQocruirNc45QQuHGT20Rsx YvQ1hJu7YoQm65yibDB1t1Q6jFlIeu4ayFAmm3wIFncuIYk/9Ghg+q9+QCYvtAQyTLiQ GXHQ== X-Gm-Message-State: AOAM532ALZ3IuCKROqdjC8O4T6fIh6i+GvHASMrVtuIoi54s+JT28dvK Vb8J7M2WSLfZG7jywmHigiS6Z/IgXcpNxwgM X-Google-Smtp-Source: ABdhPJxF6ZQlv6xMYhkegl1l1ZF9dlAyKILQ0ge2UGqbbtwYjE8BFkMsxYLlzxMcQsa4UddBWl0jYg== X-Received: by 2002:ac8:57c4:: with SMTP id w4mr13633705qta.215.1615580762478; Fri, 12 Mar 2021 12:26: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 r125sm5045494qkf.132.2021.03.12.12.26.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:02 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo , Johannes Thumshirn Subject: [PATCH v8 17/39] btrfs: return an error from btrfs_record_root_in_trans Date: Fri, 12 Mar 2021 15:25:12 -0500 Message-Id: <5803ac440ab70c1c9bdd1435ee1784115056e787.1615580595.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 93464b93ee9d..c24ffbf0fb74 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -408,6 +408,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) { @@ -456,11 +457,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 Fri Mar 12 20:25:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136011 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 6D9DAC433DB for ; Fri, 12 Mar 2021 20:27:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3231064F88 for ; Fri, 12 Mar 2021 20:27:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234815AbhCLU0g (ORCPT ); Fri, 12 Mar 2021 15:26:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234758AbhCLU0F (ORCPT ); Fri, 12 Mar 2021 15:26:05 -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 10AC5C061574 for ; Fri, 12 Mar 2021 12:26:05 -0800 (PST) Received: by mail-qk1-x731.google.com with SMTP id g185so25702386qkf.6 for ; Fri, 12 Mar 2021 12:26:05 -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=E6Xvr1LrflFwI9jG+01DM44XXVT2pjNp6gb40lzlE3g=; b=x+C7Sd9eYbLTr4Jxp65CF5dS/HkpRQ5OWx6cVDITGn3gyRq9gB55fTMI1yCuGMZ3+C xxwlqgqbunpylzzgfKCJMIOeEeBRVwIVoC8CWD8HeUMSkniVzuJVOiCk6iVCBDy3iqSN 482/g1du07aVY0p6b5kqO1gGyfLxy0IBx/YB4oGDRGKWziDSUX5wS8s5HB59ytUKu7JF c+muvNNQpwOPgTSr/cWVVOaFxY2gm03Kr2n3kJFakKUd3zLuW40DftgGWpGpv/P4fbOq nfT6OjGG0Ry7+AFxoCAmJX7fG/ar5LBxUPBO8TdHFd8ryNevm+FlIZa/2mZ3kANSwJc+ 4emw== 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=E6Xvr1LrflFwI9jG+01DM44XXVT2pjNp6gb40lzlE3g=; b=q8ke2KQejfi7bg1SqgGg4qa67ETg4NMVebjLWptXnLHNdRLmOOi9xAhFYv5UYg0BYR AFosdOdu7iBwFqNpAsZk+LqrB/AyF+Auh6E1Crbi04dop5mosSWsLf8MlDeJlEXtgd3/ xKl7/zd7u4AO8V6HDPCnYCgfjeKc+IhgHvMLiIHwliWqzSiHF2VzYMyIeofvloTQ8WCI wBFuO99PQKQkn4GlxtYLeeMRyfzRHJbFbj2Z5Yl0pNJcVRlb832Ws72bOBl1RGICB2Ao UMyPQMLF3PKPibcXkPDFHlXHYhc2k60oJI1uTpcqbpUKVeFMav1N8ChhZvjIieYK5XTy YBqQ== X-Gm-Message-State: AOAM531VN2xWxXsM+X4Wd7cc+BDLBjJ5kuogJJ8V/4b6xmFTYbaY8xPg Do4W+Pk/41B/z/mkAGLzg80QXIMjYY2sF1MR X-Google-Smtp-Source: ABdhPJyJeTWzt3ukEPek5UfUnFfPkGLwoKO9T5XqiP9plVPJMWgtpDibm+6jey2x2qPvpic3XRzk2Q== X-Received: by 2002:a37:e01:: with SMTP id 1mr14236989qko.286.1615580764035; Fri, 12 Mar 2021 12:26: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 h8sm5225916qkk.116.2021.03.12.12.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:03 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 18/39] btrfs: have proper error handling in btrfs_init_reloc_root Date: Fri, 12 Mar 2021 15:25:13 -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 7ca7ab3d40e2..9a028376f475 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -856,9 +856,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 Fri Mar 12 20:25:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136013 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 F1E06C433E0 for ; Fri, 12 Mar 2021 20:27:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B792664F73 for ; Fri, 12 Mar 2021 20:27:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234807AbhCLU0h (ORCPT ); Fri, 12 Mar 2021 15:26:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234794AbhCLU0G (ORCPT ); Fri, 12 Mar 2021 15:26:06 -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 A17F6C061574 for ; Fri, 12 Mar 2021 12:26:06 -0800 (PST) Received: by mail-qk1-x72b.google.com with SMTP id f124so25703222qkj.5 for ; Fri, 12 Mar 2021 12:26:06 -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=h51HKjvSwZwcjHKwCE1dICIdhxsev+5lZmsHrATpgj0=; b=QyO+Mg9QbsHwfBjSx4s42wO3Bw+d0wTt6fIAZtcwgDNdr67/pHYAzfyPseF3Pi8qTi rbKNWGUYMBgAid4Ebhszl4WH8paRm6/GLnkoLgCDYN/P/JLZRorpxj7cI1H8xJ83j8Br qEP9RlgTGmGx8UfbT37nIUXDn90K+ZQUQpzepMRkNThJ333BF+Ro7bbyPOW6wZXhrKQz rpY6pRp34t7uSyBGGMbv6slD/WFHBLWfxEkAjJIYRku09DNWalTBJd2ytszZE5XA0t15 x8TebWuAsHZF0g/00xFPxGCHPcxdwl0ONS9sY875uFJY/pgxSYrM5cgMhIPK4X/fcil+ 9Ggg== 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=h51HKjvSwZwcjHKwCE1dICIdhxsev+5lZmsHrATpgj0=; b=le73GjcAqqwUFSQehIOAcmUYdCkGeHr+UjN7VSPfsYerSGHji9nKN/TnQ3q4HuIjFX 2vX5dkrS07ig3+PuLxjgVs+sOnveSkuMitNPxMfPEqfkwoHe4DQntQeY5GvrKqTzEzqo ddZ8dg4U/Rhua0rFtABZNNdGCTX7a7XwXy9/fGCVBWYQ32AwIop+HGdJwAVdgM7MsuWy wr/g7taEy+cCOU4CoHoS88rJZrbt/R6GBDSYOG+0B6VBNYd3Y+Vygm8c0hfHs6xkLUEG 6mkF+TBR/n1+mqqGZ/5tWOKFZNs2hxhRF6pMbcDkR5i/qPqyJCpKrUlOyq3UaPlBL1fn WCeg== X-Gm-Message-State: AOAM531g+q1UfLz1RW+2NucswYv2c1ocsfpAZXIhsZgwoTaoSeKvp2EG COH9LVGGrJtJG/ifjrLMf61U/KKCbAqvA56l X-Google-Smtp-Source: ABdhPJyGclaC2weupM3pEFFjwWPliw8XIZqz5cXTWJedIjjI0zhdARFm6SiqJi90A0Sn9ggNIrkMoA== X-Received: by 2002:a05:620a:914:: with SMTP id v20mr14652042qkv.140.1615580765590; Fri, 12 Mar 2021 12:26:05 -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 w197sm5093952qkb.89.2021.03.12.12.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:05 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 19/39] btrfs: do proper error handling in create_reloc_root Date: Fri, 12 Mar 2021 15:25:14 -0500 Message-Id: <2b29546ebb077bccec07015e05bdce675d66d1b7.1615580595.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 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 9a028376f475..df26d6055cc6 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -733,10 +733,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; @@ -748,7 +750,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 @@ -769,9 +773,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)); @@ -789,14 +800,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 Fri Mar 12 20:25:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136019 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 4C893C433E9 for ; Fri, 12 Mar 2021 20:27:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0982864F8F for ; Fri, 12 Mar 2021 20:27:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234806AbhCLU0i (ORCPT ); Fri, 12 Mar 2021 15:26:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234792AbhCLU0J (ORCPT ); Fri, 12 Mar 2021 15:26:09 -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 B65EEC061574 for ; Fri, 12 Mar 2021 12:26:08 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id 73so4837808qtg.13 for ; Fri, 12 Mar 2021 12:26:08 -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=Ak7mkZmAI2IDSIeA3KonQf6HL04ORT5ZdZkXHPcqoxg=; b=1U8gxlV+2KIeZPBsQKBI01jXOdFGdho0ZhsP+SZpD0a9rJ1X3nzNcW/0IayeQHLhsL NueK2UnWBo1UXBqgN1CerZK8xD+UEPcD4zxZe4sbVzM2DKzu3RzDNcnAAP/XCM0fDSxa BR+lgQYwvXuzNF9RmTR7wsUkA5HuHyyXHD7O7PbehhexOy9Q/4Hiw6NSOACryq3iiEJB M4+pqcKqIrcmtEXhIRhEkqgVwiLPt0b/tTKPCVHkaMfPAjZbjDGJCAqYqBUu6vQveDda S2hMhz9vKgEOwJoSfuDkeAm7neK4IvfQ2bCdtCX9AWf8nF0nPXKjxsO/5Dt0vt0acBJv 6LNg== 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=Ak7mkZmAI2IDSIeA3KonQf6HL04ORT5ZdZkXHPcqoxg=; b=cVPUdgQsX6rGmfXc97Jv0/YgBXWjn3113AakJucCThq5QPElhplJhVK3LFOiq2qk6+ ckcFlFFnniepZq/hAb8bx3Gnz5gyRZ/eFqfD+HErKwYS+LRJefiKyuNVkVZDz4WhKFpt lMsEZZkp5adWrzzZrRT0ZW7CYW5ln16hXpik5M3V8n6Ftei1aPFzXpvfsBdYbniF+ctZ TGxFdqhH56BR5ZBinjaE7IGYtBZ6hakDzRE4/2pnvWAZNaSyd+/oP0x7vjhoICGd9+Mk w6b11sxEbmLjBCgHtRkTk1z/gUZ5Op0Me8RoTF9CMeSM6Bt2lbctbABSF4rElcnF2oSX P72Q== X-Gm-Message-State: AOAM531TP2Bn0hgTkSBiY2ko8OuELjkAwPiSc8TrnOo6BFrxg+BFFRts e1Kq3Tl4DerdgH5kIqgAYKafu06q+vLCYAc1 X-Google-Smtp-Source: ABdhPJwBs7pRvCdJrT5c5V2FtDpwTaCsyP6pCzq2kecEj4vbGs8kY5Iozm63wpgGHQ/yU6KwYAAGYw== X-Received: by 2002:ac8:649:: with SMTP id e9mr13618938qth.114.1615580767659; Fri, 12 Mar 2021 12:26:07 -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 c73sm5456016qkg.6.2021.03.12.12.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:07 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Zygo Blaxell Subject: [PATCH v8 20/39] btrfs: validate ->reloc_root after recording root in trans Date: Fri, 12 Mar 2021 15:25:15 -0500 Message-Id: <197e338ecea7071e9e5ea927843eaeb066f5feb3.1615580595.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 df26d6055cc6..4022649e2365 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2081,6 +2081,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 @@ -2578,6 +2585,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 Fri Mar 12 20:25:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136017 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 1CBF1C433E6 for ; Fri, 12 Mar 2021 20:27:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB06764F80 for ; Fri, 12 Mar 2021 20:27:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234825AbhCLU0i (ORCPT ); Fri, 12 Mar 2021 15:26:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234827AbhCLU0K (ORCPT ); Fri, 12 Mar 2021 15:26:10 -0500 Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 803EBC061574 for ; Fri, 12 Mar 2021 12:26:10 -0800 (PST) Received: by mail-qk1-x72a.google.com with SMTP id n79so25708170qke.3 for ; Fri, 12 Mar 2021 12:26:10 -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=fMSXLqXt5M2Fuy9Ykuox+cLE2nnWXMCStFHkmXXP6aE=; b=CTHYOiyH7tJXNAVJMzlJxAOgpI/atRtU8/ugcLRLD06sE0TZBilHLdu8+tlT5pGCYy +EMnQeLGIR9ahLl5tGgR04J02LgbvxfqUgvI7CQ0QSRixA2Zq+2XXHr+NDjTR2LebeWb CWL6ATtydEP+WlwBHG1Cvw7HZEjz8smFjbcXZT3HgsTetOitwaC1q3WzRnVH4caoHZKR Cq1vrynH13uVmsrf9JQcM5HUdVxvU+ynzDmmNR0q2qah19efSTdRC5k87kb3k9QtMR+N QATnF66VC4v66OdHA63h4ONu/BRENB3AupkzCdz6fmdknMSx5I0iAGtL1HsQypjGS73q D5Tw== 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=fMSXLqXt5M2Fuy9Ykuox+cLE2nnWXMCStFHkmXXP6aE=; b=gKsrjP8GavVNMMMTNk7SvRCCYfjWX9Y2U6jH0SrYCDXAh+3oRji0dIBZggguqzXNzI zoQJYnK8Bq4Oyi9rYALwYZsR/jybrGJPzSycPjWct7Cpn+LE/cq0qINs+YTdHJPpLMsH VnAOJC8bBYWn/0SbXhFaNjl0JtvG7c3FSASDWTLIeVe3bNLSjHlxIME+ljoQAldp/MDL HpYpuMw/z1YlhxZJIRoGVOItkkAIL4OnD9d+OY3pq4fs59xp0Yk0+tLOQbr+r2ZuoMJq h5An5wxX7Lxx0qyGoDxUs/zzgRl9D5ovR9BQjr3FYIk5T/2F2QoWmbt39nMmWX/TSG42 d5uA== X-Gm-Message-State: AOAM530+/kHNVbm3PMEV7LfxVvh+G3TohEooslGfPXaLq/dza1bUT+Jq hm08GlYaW7HceIEuuHFNmZDcrzONXUyM6GSn X-Google-Smtp-Source: ABdhPJxiDLYI/X1G82Yy5O1H7965RI5b2KqfeAk38c/HYeRBBQAwYhymHsHk8s5vcC8bKEBkW4s7aw== X-Received: by 2002:a05:620a:2a02:: with SMTP id o2mr14373369qkp.492.1615580769365; Fri, 12 Mar 2021 12:26:09 -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 k24sm4727403qtu.35.2021.03.12.12.26.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:09 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 21/39] btrfs: handle btrfs_update_reloc_root failure in commit_fs_roots Date: Fri, 12 Mar 2021 15:25:16 -0500 Message-Id: <12d91efec7891c92dce4d8fdebe98327968811a4.1615580595.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 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 c24ffbf0fb74..9dbbc354e5ad 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1353,7 +1353,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 Fri Mar 12 20:25:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136015 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 6076CC43381 for ; Fri, 12 Mar 2021 20:27:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E90464F73 for ; Fri, 12 Mar 2021 20:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234837AbhCLU0j (ORCPT ); Fri, 12 Mar 2021 15:26:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234830AbhCLU0M (ORCPT ); Fri, 12 Mar 2021 15:26:12 -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 C0E4FC061574 for ; Fri, 12 Mar 2021 12:26:11 -0800 (PST) Received: by mail-qt1-x835.google.com with SMTP id g24so4839591qts.6 for ; Fri, 12 Mar 2021 12:26: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=aXO4v2hpXzT/esLFhaZmNAjCzSU2PAqamgw/AA/rS8Q=; b=KAwRlYcbTT3zK4jvMZmunM3WmtvhJoN23ovTbBKGb6X8nlPekfEoe3i0yMXO7UN3Ng c/37gdsPC7eaEu5VednfR/Ji4vFyB6CJB43Ki+QlJHSxwPu0+Cl59sBKbqGKAa3AFFuW AOFfkTZsUMtAZOAeAU2Ip+fFtC1UgQEQBkLRGQIWAxMTxH5W8pMd9NWaa/4VsQiznXCL kToVspD3rrCQuPNQR0VVZv/wuDFnK2KDGV1Vm1SJZdum6WKcf38tKrtI9gjPdWFnFBKT Jog5PPI8Wjwsu1Ae61LbeVHmkt8Wee0HAGuro2dK9HdfkjQwyqPFyK4bN+SYY4NQSkaC SJWw== 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=aXO4v2hpXzT/esLFhaZmNAjCzSU2PAqamgw/AA/rS8Q=; b=gdP8LUfL0puSmhPDyptYalhG03X/scsiC7TGtMr4hzUX6B59AIdxY1U0Tiz07aXn7U bBJcPNsLKQzdG/SmPK50auWlAcjc7jatyfEQiMVS/4e9EiT0Z8fMhRAABh0Mbzw5I8QK BftWy23AdwGSsfX3qZLpuGJO303JxPU5TYxRT27PFXrP7DtE6dwgH4W3V6RoXmu1z7gJ BWptFRnT7GLU+pIarwqwc2g/2KtDsJ0U6mkETtpbemyu9aiNYVuhyycCbKX/Xw6OONaY kC02bu8Nzk9RWEyM6ISddXgLZnx/Cq+amnoCTn+wfXQGIe3c+Ab0si9vO2y4VfvrAdnD BmVg== X-Gm-Message-State: AOAM532d0b0UtSmS/dWuy6uyiwte6Xlp9+1G3VWXMlTQvg8q/2tpE4Wa swNVgTrqQDKQBlammCUwUq1XcBUvhOayQTPQ X-Google-Smtp-Source: ABdhPJypzMdPKzbewcoUgDfsk//FgJ6xibISag8onE489OMiUn3zNSELKisMtDVdPTbRNR/zmj67ZQ== X-Received: by 2002:ac8:47cf:: with SMTP id d15mr12187112qtr.288.1615580770827; Fri, 12 Mar 2021 12:26: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 l5sm4528756qtj.21.2021.03.12.12.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:10 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 22/39] btrfs: change insert_dirty_subvol to return errors Date: Fri, 12 Mar 2021 15:25:17 -0500 Message-Id: <871bef6b8f1668f7d94d154e68dfeabae791552e.1615580595.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 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 4022649e2365..2187015fc412 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1564,9 +1564,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; @@ -1586,6 +1586,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) @@ -1787,8 +1788,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 Fri Mar 12 20:25:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136027 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 72E6FC4332B for ; Fri, 12 Mar 2021 20:27:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 47BC664F80 for ; Fri, 12 Mar 2021 20:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234855AbhCLU0k (ORCPT ); Fri, 12 Mar 2021 15:26:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234800AbhCLU0N (ORCPT ); Fri, 12 Mar 2021 15:26:13 -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 4E1C2C061574 for ; Fri, 12 Mar 2021 12:26:13 -0800 (PST) Received: by mail-qt1-x829.google.com with SMTP id m7so4836375qtq.11 for ; Fri, 12 Mar 2021 12:26:13 -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=q1dbXkCl5T04l8kQjp3OaynvG1yvO/2YEvX/tUF9PyI=; b=ZXaEfVO+zBZZM2lDMaTas/tAJaHBae5fdv3ieiUaUMw0XLyt0INC3DXLHqdKTnEFqq geiJFzMg1YRBQAm6I6NmTdYOCysGC99RSw1Ez4fRL5uRvzUiXzSX5Ao3Ha+JSd8nO/Iy XrY880tgGcBlILl9J2V4X3pVtBElJSWpWzkDh4Qy/cdVxuclwgA9guAWRu+HBwUwEshd 8Zu97bb9SgDd+VHwlrKVt3CL7xkUR65230V6FPXzJ3O7nWOngDl2PqTjFhoc6Z0DcYIB UbnmpQXj6SWUICsCGek1nZadbkUA8fYEahi7+a1XyD7++0FoeinvhP7tncxbWwJxmjbc C3Ng== 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=q1dbXkCl5T04l8kQjp3OaynvG1yvO/2YEvX/tUF9PyI=; b=sZCFcnq5TjlyjmnH2T/NpdTQ6+sh+zdqE1zz5tet826San8RcOmfK6JO9UKaGXS0rj h0K7+ie0Brfh4uODgM9Jfs5nj0//+I4KujciMEPIEjlpj6nfToZFobIM6QAii65H+SWv X+uVYjm31DIL6lduSjDROyiJTmc6VFexnN/rNfLBpzBWG0kcjDl13oMAZdJAdCiydG13 Gsn3tNnee5xbE9+Jfv1j9vngbC6QdhFPgsnoADmTOcuGf3bgUjTcCbkB+j2vJfl6hG10 w34VP8MRecXcVfawYmngy95Wsvzvkp4aWeF+szJ2UpvXtSVZNtR5PTT2Yfl9QQHEJCep d2aQ== X-Gm-Message-State: AOAM532K6wzBVQxvs5wIbW2nreyVmfPyKfN55jb8xzeJBxshKSNd1NO3 OAc9URvlOQSLTPvPg5DGBwRDSxA6uad1bx+J X-Google-Smtp-Source: ABdhPJzpv+07kRIUWntftEIqW81t/tLClYYppzrxJisM5oUWx0BvR21CXJn6X5rtGIJyH21zftB8gQ== X-Received: by 2002:a05:622a:d2:: with SMTP id p18mr13551052qtw.365.1615580772318; Fri, 12 Mar 2021 12:26: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 d70sm5312361qkg.30.2021.03.12.12.26.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:12 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 23/39] btrfs: handle btrfs_update_reloc_root failure in insert_dirty_subvol Date: Fri, 12 Mar 2021 15:25:18 -0500 Message-Id: <76c5e64ff98eaf11ed42976c5f9e77b6987f3d73.1615580595.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 2187015fc412..e6f9304d6a29 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1570,6 +1570,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); @@ -1580,7 +1581,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 Fri Mar 12 20:25:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136023 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 DBA99C4332D for ; Fri, 12 Mar 2021 20:27:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9088A64F8E for ; Fri, 12 Mar 2021 20:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234860AbhCLU0l (ORCPT ); Fri, 12 Mar 2021 15:26:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234844AbhCLU0P (ORCPT ); Fri, 12 Mar 2021 15:26:15 -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 CB824C061574 for ; Fri, 12 Mar 2021 12:26:14 -0800 (PST) Received: by mail-qk1-x731.google.com with SMTP id m186so9070264qke.12 for ; Fri, 12 Mar 2021 12:26:14 -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=+taWR5KRsj940Ij5EIrNKIZZtVKjNmXibQ0JT3vmUkQ=; b=Syn4LcZRve/EtUjo9jods65IXC1UTChd4s+W5A/8y5qocpmVLtGl7mWpxMSBUr0H9z f9gDJyfawkCqs/KjMj3C7HMFDL6WNn/0ZsTe+M2H3ED40DPZjxtGKmTfH0CLjYiW5AxS aZ29FZhAIscua4qFOu2avovu+rgPNjMGptBrmUyCwR+4h1QCEBB4UHVKYVLiu0yDmTes kg7myTxLbXZC5py+/S05MGTzkpv6UXDJqcbvaCZRBzHyW4C1cbc2MkHQceZjR58izu18 d8Qb3Un4UaCaNX6Zq1YmBJxw9rUkXDuc2ElG/YBo9VOms9HyWzCfKbkDG1LfbWHfY/DG 6hPg== 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=+taWR5KRsj940Ij5EIrNKIZZtVKjNmXibQ0JT3vmUkQ=; b=i5IX5Kz5vxYkxwJVS5jptSVetd8eRqqMxbu2IZaSSYHkUsejbQ4JyM4MfxHa5iJyie uiMznFw1GgdTbHvFtOswOMht4edeJHhI4DGdqUeyGn4BfOwgQ034zS68n5sZxIN7QLxq 5VGr3rtPFjwo1FA2Hb1JHMX/f4EY+JJ933w//WEhBmOIJpLaNZuWxpWp81IevsOu00NV 38+CxJxMOKYk2Tf0YUWC1PdQIeICQVdclUSk4oZbpHT/iicnj2dZT++tajZohchn1yac ja9vmT7Ef/k1I+fEqrDdu5d9mh8dUCx8OeQd5umMaVEj1ImALZYxxbFV+EkovvNqLNB4 9pnA== X-Gm-Message-State: AOAM531k+wwCN+Q7QwKexaeqO9T41xyQURbioSXvcBiMufCRMtZvow6d lchsGftJyA9C8+nu568Dcorgj8aVGFoEr7A4 X-Google-Smtp-Source: ABdhPJxAh6UcV5567r7Od+HBrB1toH7OgvBwHFeHBpbR+wF29Ey2/qmm1BvkLP+vX2ugsPgLvSCcLQ== X-Received: by 2002:a37:630a:: with SMTP id x10mr14191153qkb.326.1615580773824; Fri, 12 Mar 2021 12:26: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 o21sm4593300qtp.72.2021.03.12.12.26.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:13 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 24/39] btrfs: handle btrfs_update_reloc_root failure in prepare_to_merge Date: Fri, 12 Mar 2021 15:25:19 -0500 Message-Id: <5e1a5fbd0668822fdb5c6bf3ae1ee473d8e5af77.1615580595.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 e6f9304d6a29..b9cc99d4b950 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1868,10 +1868,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 Fri Mar 12 20:25:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136021 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 DCCF0C43332 for ; Fri, 12 Mar 2021 20:27:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB0EF64F8F for ; Fri, 12 Mar 2021 20:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234883AbhCLU0n (ORCPT ); Fri, 12 Mar 2021 15:26:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234852AbhCLU0R (ORCPT ); Fri, 12 Mar 2021 15:26:17 -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 763F6C061574 for ; Fri, 12 Mar 2021 12:26:16 -0800 (PST) Received: by mail-qk1-x729.google.com with SMTP id 130so25673023qkh.11 for ; Fri, 12 Mar 2021 12:26:16 -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=oQoML6oSbZ+u08kLXaeYpQkpl0U3XOHsxglIYPmzeVw=; b=WbbPALtDC9BAssh6VKapYxOumSAbE3TL9U3qdjkM31ywUGnvch+3T06Z9p3o2/9RA2 GvP0ofNvTwSniAOra3NdFfoNnahy5quBnAKEHzG2sg/iP+Qbw6/aSMIOebdyF5dLM17w HqgXK2AhTbqsaLs3unNfdt9BHFwvYVmWsY4Gl5mc5WXufHhxFJRzlO+O3TJ1fEsvz3D+ 5ZCtySiMYordTUC0Y6J/8iYJIXnF2Q4jUMthjmxc4urFVkOZGMmR9PfNKHgszCWMqf6V uvAa86BPr0Ype2a3NpNQ2c8knQcCNEtmC8Ld7lNU4i+YsW0d8hjvquSkUtBjdHZ6Z42M vXgA== 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=oQoML6oSbZ+u08kLXaeYpQkpl0U3XOHsxglIYPmzeVw=; b=QNjMgdWNTvZlde976LKdxTvR1cs75rSk/MvWoWTZHWUOmF8Ru6myMiquTwQI+59naL HuQkYUjOzffBnztq+43yfAjSppr2xWV5OlMHUR1pwy6NOTNS3T458tSm1IPn8z6Qo5N9 9BkP4oauXxxEF+s2BT8yTkjILYWzOT87hGVO/qoob6VVgZuaim+Hi+A3S40bi3GNBcZj POfnrkyPnkn15z6lhHqAxW0DHDP9CSHvIW/pJBzDa8YXBoXMz4hi7GI9c4BgUdwdnk8i MEVLNNY/Ppl5iXTrswlKE7+kkdbNwZpzCewkLxh/FTWMzB9Rsn4At4JW+6bHgNKvm/jn IXlQ== X-Gm-Message-State: AOAM532Hgex0ywa9NJ9nQoCbo6EQugJRf15055U8XZoFe9eDab+zIu+p ensTp3I79TuHtXDP1emJux9kTxy/tFoq3R5u X-Google-Smtp-Source: ABdhPJxUGtj0z2pMPfHWbbn14V6mOKvyxkVdEhwcVM5Hhwq+SSfI3aNv2rYmnvnQahY0/D9b2c1fFQ== X-Received: by 2002:a05:620a:22f5:: with SMTP id p21mr14158086qki.225.1615580775417; Fri, 12 Mar 2021 12:26: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 p12sm4487008qtw.27.2021.03.12.12.26.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:15 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 25/39] btrfs: do proper error handling in btrfs_update_reloc_root Date: Fri, 12 Mar 2021 15:25: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 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 b9cc99d4b950..7b242f527bd8 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -902,7 +902,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; @@ -935,10 +935,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 Fri Mar 12 20:25:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136031 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 05721C43331 for ; Fri, 12 Mar 2021 20:27:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D75EB64F8D for ; Fri, 12 Mar 2021 20:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234881AbhCLU0m (ORCPT ); Fri, 12 Mar 2021 15:26:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234854AbhCLU0S (ORCPT ); Fri, 12 Mar 2021 15:26:18 -0500 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7433C061761 for ; Fri, 12 Mar 2021 12:26:17 -0800 (PST) Received: by mail-qt1-x831.google.com with SMTP id g24so4839794qts.6 for ; Fri, 12 Mar 2021 12:26:17 -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=/gxYb00Bl/qQfwB//81/hEDg2Vk4vMISElHXXqKu7RI=; b=daAUduSQ1/hOc7L2Aze1Bs/lbeQvzC2fiqkz8DrjFB/2dJ4WirJrDqMfC5eONSaFXZ +NP7IQ5QHO75F3Z+JYGGAGbtAtVbymrqRCqe1lTujGhg6gdKSACZhWzzx95pR+hevyl1 bOixG8PQ0GOqx1nO5puERFFpAJVkccPg1erWSaczqB3SNH9RoJj1k3UMaRztjFnBsMoF hp3XgrXK9gK3SAOIfMq1Wtm6T2+tm6OEcax4jaAVDoh59p3ztOvNkUFjSQTuTRiqVdbZ 4e3wxKadLYALGlW/y/FFpZHO/4WkPx5ItxRnH/hA4Wpm0Vdw2z3w1uqqdbJixGl2y4PX oDQQ== 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=/gxYb00Bl/qQfwB//81/hEDg2Vk4vMISElHXXqKu7RI=; b=J2wi9VOQZs/xxaCcws3efXx8vWIdyLwQIoObvbRAKgedWoVo0RN5HFq31vLDO4I2h3 0O0CUeC+X9+P1K2KjaSoCAXhMCTTBeblbIEIsXdR2xzIZ2nhz4YnGk1deTyWB0IQUK33 K2Zqh2u4D6LiDMoEqwBX40q4XBvzA9877zv+tU7N7TtsFntCaHJ9GdTi8Mb8tLEJjEMD 1gvZfFCg4smQbWBL4u9mmf4dd4g9fnlKR/QoirANVv1o2JorHmM8PkiphKTIWrWc00hk VyrCJazZX03s3TG4QmRa59AC1FG/7NGzkbr/L5xw9K4MbcEURLvokrh6PO+3pusozEsf PTUw== X-Gm-Message-State: AOAM531oJ2xdn+U9yn2e2yPA4XkbNk2IniB9Wsj/EuvFoTf28H9CkcNt TI3jQR5qZ6UZmpR012JrsyDhdQTmHW314C/R X-Google-Smtp-Source: ABdhPJwF1/7QIttiNT0KmDe8IM+RpXo9HqM8KHK7l9d3Hx7IOYebv8kwBszavakhE7y142MmY6nvJA== X-Received: by 2002:ac8:5747:: with SMTP id 7mr13805254qtx.274.1615580776836; Fri, 12 Mar 2021 12:26:16 -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 h18sm4645849qtn.49.2021.03.12.12.26.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:16 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 26/39] btrfs: convert logic BUG_ON()'s in replace_path to ASSERT()'s Date: Fri, 12 Mar 2021 15:25:21 -0500 Message-Id: <7306e790c23ea756348c2e955cbe0347ec8c01dd.1615580595.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 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 7b242f527bd8..dfd58fa9f189 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1210,8 +1210,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: @@ -1242,7 +1242,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 Fri Mar 12 20:25:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136025 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 A81D2C4332E for ; Fri, 12 Mar 2021 20:27:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7091664F88 for ; Fri, 12 Mar 2021 20:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234870AbhCLU0m (ORCPT ); Fri, 12 Mar 2021 15:26:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234857AbhCLU0T (ORCPT ); Fri, 12 Mar 2021 15:26:19 -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 388FBC061762 for ; Fri, 12 Mar 2021 12:26:19 -0800 (PST) Received: by mail-qt1-x829.google.com with SMTP id g24so4839841qts.6 for ; Fri, 12 Mar 2021 12:26: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=Y6rZYyY9TvS4LM7RXIQE4ZNZgbl8/f5ImfrFfXAVsb0=; b=NQ7hpSH5AnuGBKszUPZVJT36C+L5FUF2NA6eg0SOv1gcqhg1PR4W85fuIRMXXfY6rS mF2k47CGieAKotW7Wxh8EALbp1SwojYphYYS9DHAPbUkX4uyyuZn1gw5sJAwvbuN/tNL VmriOCsWOIrr71qYFGh1cl4G5HXsw0Q6z7rVyv/NAnag5uw+hbafY/MQxq5wjPsM8y0i 7Np6Vdy/3MCoijxhxmoJcZRsUw5NkRaOHkmfum0uidE9WqoVYqkSIg1OKVhbG3dHpf7u M4zfXpUUKEl7szTr4oTnhlhclmZuqpWYOLtkSgWXJAreFGlOuFGPabBZzTFaM6MupEYh WHuQ== 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=Y6rZYyY9TvS4LM7RXIQE4ZNZgbl8/f5ImfrFfXAVsb0=; b=j9u2ls+HOtwMAagVu/jh6u8uCb+BXYKZjng4Ie1hq0NUPFcmK8rvZL4DJ9EgBnfT5T bQHvlBvOC2gZ2mLMdngcAfsrWrCppPzFtgfSy7Ag+cOwlteWqdZS0L032TjMDJoQJUDU WeNkBJfAmiSogpCW9rRU9iAfWGfwzo0LKFITMCmh5m5io0CnVRyAcek4WZMtD+aEwffI y3RFE9J0KGyVnffxkhWtGLCjC2Y2I5XrXUpU5g4RJCDLqFaW4As/2RRWMd6UWh5qNMRV 4xc9wsbhRUsUXvxX8UGmO/d/HQO43PiCJ/uNNoph9E2L2Jb/hlSm+Kl5bVZUOFqIERto /opQ== X-Gm-Message-State: AOAM532HVGYRlByVzlGbslXRS5kw7F2R+dQ3UG6syj1QD/TXzharoNxu okHp87UEtyhAa4i7wZNAfy3iRp9cmgVUoGY8 X-Google-Smtp-Source: ABdhPJwcQ0h7WRAlQoas0B8tGLoP4f8NmLLgk5k6Yy64q5bG9cBkbij9qOR61ucqVDE1TBBBBGJRBQ== X-Received: by 2002:ac8:1494:: with SMTP id l20mr13705775qtj.151.1615580778247; Fri, 12 Mar 2021 12:26: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 e14sm5086272qka.56.2021.03.12.12.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:17 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 27/39] btrfs: handle btrfs_cow_block errors in replace_path Date: Fri, 12 Mar 2021 15:25:22 -0500 Message-Id: <4e3369f452184885a2af686b90d31b4372bf8ca8.1615580595.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 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 dfd58fa9f189..592b2d156626 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1230,7 +1230,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) { @@ -1290,7 +1294,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 Fri Mar 12 20:25:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136029 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 5E65AC432C3 for ; Fri, 12 Mar 2021 20:27:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2852D64F88 for ; Fri, 12 Mar 2021 20:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234885AbhCLU0n (ORCPT ); Fri, 12 Mar 2021 15:26:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234862AbhCLU0U (ORCPT ); Fri, 12 Mar 2021 15:26:20 -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 B0D2CC061574 for ; Fri, 12 Mar 2021 12:26:20 -0800 (PST) Received: by mail-qk1-x729.google.com with SMTP id a9so25669207qkn.13 for ; Fri, 12 Mar 2021 12:26:20 -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=d84BgaY9R9ceG+dXRonWeoL2a6UDUwP1QEl09QHsrz0=; b=P/TnwCMKQ1CHs+Jm1HxTPXVyRIXHe7Qu3yx3/3JeHvIF3Y5cKUzIsHZrdkLzlgzcom FNoR7utLQguvb/lzduLlFApvBJBmqHFamTR59jKJbNh75A85Id+Ty5vpQ/DUrEiwyu5o OvFAWrNIgPTlojwbWgnxFkTRR7GqJXimuxyXHsAUYKf7d227iSTI6pHRAI6oKk6YQyja hAef+ZuLaDjbSg56GB81QExgcz6R6U9hBTL7PtHMwP3ThLNweMAN4YWyIt/c1xtvtVmg E+URtZTR47+uYeaSO/9CbhnzM8rqEwmxRFF1qyo510ByYRqY9dQCvtF48VxEZWHqYVfu NSUQ== 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=d84BgaY9R9ceG+dXRonWeoL2a6UDUwP1QEl09QHsrz0=; b=Kti08l8yT2XQEqCHNzF7id6NsNKxN+x2Z0ZnpVuhtlPwwmPUv1UmVE11QM9tvF62OZ r/POybcuN8ZRTprOXeMb8/mGzlHfAjwDzYHkH36VBjOi01ZthQJ1OEPXvuXSvgg6I+Gh a1WP2JzwZIBv6/D2L5Dio0L4SCtfsC1PKMB1GPj10GwTieSjREFIkFITic5l4YbJH1OZ I5Ea2+dVc4KEF9yVaWCE+wLVVTJCni1Bft2eTwyobNRrrhD+Qf9qo403X2b/xf8KZg4Q 0izMf0yeOFCM2hDxrPJF9iXFQzq9qrwc7bCrw46i8sCUKEl5bTw+HLK0MP1ZM/lCV8U8 RHTA== X-Gm-Message-State: AOAM5322Srd9oaL1nwU1+ses1qS460FWstVsSDF/zCSbvKSOT7QUCwO6 yjGNUs+44ETWibllAUuWtNGmmJcgvejvcSar X-Google-Smtp-Source: ABdhPJyjHn+pZmT9+aixqAyvGh2+B+GUlz4E1yNeSl467c2otFIGyOF4r96sQKcGuslmZiWEdq5p9w== X-Received: by 2002:a05:620a:2f8:: with SMTP id a24mr14696719qko.124.1615580779679; Fri, 12 Mar 2021 12:26:19 -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 g14sm5126742qkm.98.2021.03.12.12.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:19 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 28/39] btrfs: handle btrfs_search_slot failure in replace_path Date: Fri, 12 Mar 2021 15:25:23 -0500 Message-Id: <1c88a3767122bd97acc2f6370cbd046bee05ff2c.1615580595.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 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 592b2d156626..6e8d89e4733a 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1322,7 +1322,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 Fri Mar 12 20:25:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136039 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 25958C43333 for ; Fri, 12 Mar 2021 20:27:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F37DA64F73 for ; Fri, 12 Mar 2021 20:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234887AbhCLU0o (ORCPT ); Fri, 12 Mar 2021 15:26:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234809AbhCLU0W (ORCPT ); Fri, 12 Mar 2021 15:26:22 -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 35095C061574 for ; Fri, 12 Mar 2021 12:26:22 -0800 (PST) Received: by mail-qt1-x830.google.com with SMTP id 94so4837401qtc.0 for ; Fri, 12 Mar 2021 12:26:22 -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=wSNt10oYjE5osVwWVwIxXuhyrOI5tef1vCJi80oPQw8=; b=DOs1CX1VR43RcJLNeGNOxptFDAoY1bzx2CpWohlgiG65CC53OCHK3l9wyJuhk6MoRe l5yLGIm1A7SvO1s+DxaCFfbz+8+Gpy61gxhjkFXYYFHfC2d4k1D+RWcqOt9hjFuR0f8T spnG5jI1CFIxyyJj11dX8dFhpHF9UY5QH8kmM/QgI3nXGQQLtsy5/mzhPojy9wrB6uW7 YTkhKc+SFlu9k0Ju+umJ0JGRm0eIXEgkali/al63pdN2uyI3qn3EELE+E1Q4EnakdJBW 97TjpD/XB8l8ZwJXv1ekHTv/jCAD4FEjRXnAmVVA2iy/qk6mPYSRCFyzTEbNDMq4vPXo 4F5w== 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=wSNt10oYjE5osVwWVwIxXuhyrOI5tef1vCJi80oPQw8=; b=Kn7RLcGSQDX9yIZC3aDHdRay3sAEyCmUbHGzIUBo89aDgcIiJJg7AM3u2BB5OPElWp 83VSxO/vHfZpmgVlXPp7vThjnDZNsq3sIzzlArlpAG8TdaIWCeX5+HN500/O7+q4OVFM gJDL7UlbWhAmjF+fHJxGHbPVnvoHDxWopBowlsoOaM3tOG9Fh2Snz2VW5zxBXSmypzr+ E2PXn6e4L+f3kcTeb7V/ib2OqLlcvYWWo497b83DvvYTPoaTalyOkc0D1J96+5u1OQ+/ uaGt1xT5lgIxJrNT+TKr/B8LsDgKYMAb0Mfsh1a90LAbLl5uekany0xTGSpj9/o3hHe8 VB0Q== X-Gm-Message-State: AOAM532etIhlagFhWB4/VQn8/nIsJ6Ss5xO9dgB+IS9qpnvUtIanFw4h cCBUl+l5KOk9QrvDUxtzq3dieomG9V05tfGL X-Google-Smtp-Source: ABdhPJyOXyw/5oQmtvxllDy7QjLwds9SUQDoXF04bVKxeeOzjUmcJPkoIG8qGTTJ61lEPaDRQW9yAA== X-Received: by 2002:ac8:738f:: with SMTP id t15mr11392129qtp.26.1615580781171; Fri, 12 Mar 2021 12:26:21 -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 c13sm5080391qkc.99.2021.03.12.12.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:20 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 29/39] btrfs: handle errors in reference count manipulation in replace_path Date: Fri, 12 Mar 2021 15:25:24 -0500 Message-Id: <7fc6a13fc3b70bb55e6dc1a818e73f539ca4e601.1615580595.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 6e8d89e4733a..1a0e07507796 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1363,27 +1363,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 Fri Mar 12 20:25:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136045 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 93DEFC433DB for ; Fri, 12 Mar 2021 20:27:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7276F64F8E for ; Fri, 12 Mar 2021 20:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234890AbhCLU0o (ORCPT ); Fri, 12 Mar 2021 15:26:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234868AbhCLU0X (ORCPT ); Fri, 12 Mar 2021 15:26:23 -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 A1BB2C061574 for ; Fri, 12 Mar 2021 12:26:23 -0800 (PST) Received: by mail-qv1-xf2d.google.com with SMTP id j17so4903571qvo.13 for ; Fri, 12 Mar 2021 12:26: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=Sn4OcrDan8zF8s42MF9N+ux5UFalwxVMfpouWmmTaKY=; b=hX2hyNIWv5cnjqSfiFyXeDaazrJIlf46voTE46B86bshWwMH6Epkh3pmkt4U1e6Z37 aMyLbHhrWGxzO/d64kjtJqyZ7kaW0Mnr2pp/nj2WoKIxbUmbZ2B8bEO7Q+zn57GLpO5y SwFLWgghwy8dnaOe3TjEjFaPLWME5x3nE6BffirfKfWN1AuCfsfJki2mq8yhLnzwGPE0 J86HjzH8fkgWbkAUkzMOhdX4ALwYmMjc4+sVUc/8xDKWVoLwXSDPyIE9v0vMeagyavkt UhRTl37Y4vPnsRhLqjDXhRRpcNO8ovX7LqTgTklxrxwWwQVEmXw1GjM0sqTrbBTPUpUj obrw== 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=Sn4OcrDan8zF8s42MF9N+ux5UFalwxVMfpouWmmTaKY=; b=ZkJhBI3DCioP5feOWnKfMZhNLutCSp1ukAX6Zgc0PMxJiKYGKr82A6TmVJFY/g7m7Z s94wMQC3bIUJ8Y8PSrHNAsYrSn2Nb38wn98dnuKYIkWNw7PAbceXfIYO82EhSvePfRqy PtwfWUCYzl6inyUbPI3uKJcPTemqPDir4ssC4HwfDHXpUiv5wdY74sfIirKEKCRZyDA+ V1oQcj5Q/LR8cZD4qlJFJiFGYt1m8dcGuVRX95JLBWW/tZQi0pojfIhyGdIWft43qB+d TkZ2MozZmYU+z3h2r2RvwBSEsBagT5nnF2rGcOkdrOQoek77Z+apIF4FJ57yPNtDyhPR /0yQ== X-Gm-Message-State: AOAM533r9bqc8Tx4BcH4UcVta0u3YH4MgziCuEEKVJiDL//QSQ9x4Rt/ Frkk7m7qMY3dShe2P9z1Hr7+ukHg5iZ7mPqT X-Google-Smtp-Source: ABdhPJy1zSawBaJB97TYoL/HMdRB2Ho0WuqsCkeGHNfYpr2vAbOUtFcMDNvou3+iW7FBQgCmvlp3Hg== X-Received: by 2002:a0c:c68f:: with SMTP id d15mr24376qvj.20.1615580782614; Fri, 12 Mar 2021 12:26: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 t128sm5312242qka.46.2021.03.12.12.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:22 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 30/39] btrfs: handle extent reference errors in do_relocation Date: Fri, 12 Mar 2021 15:25:25 -0500 Message-Id: <1f31bf3a150a7ca530e91faa03cc12aa5058d2e4.1615580595.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 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 1a0e07507796..71a3db66c1ab 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2432,10 +2432,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 Fri Mar 12 20:25:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136035 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 870A1C43603 for ; Fri, 12 Mar 2021 20:27:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 452A964F80 for ; Fri, 12 Mar 2021 20:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234892AbhCLU0o (ORCPT ); Fri, 12 Mar 2021 15:26:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234869AbhCLU0Z (ORCPT ); Fri, 12 Mar 2021 15:26:25 -0500 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C796C061574 for ; Fri, 12 Mar 2021 12:26:25 -0800 (PST) Received: by mail-qt1-x82b.google.com with SMTP id 6so4829882qty.3 for ; Fri, 12 Mar 2021 12:26: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=g1uEgOSpXoD2jR96iEnRQSqCDRpwYRl1rnc/KDZZlLo=; b=x0pWYXUNTS04QiBA9YeuHplp5zSLbkkASju9tDC9cykoiutJXX9ZbCK7NZEEDKg3Ya xw1/ticop59RXiUp3mzd1M7ae/vsmZy3CTy4JkusCb1uPV0AJpcdWfd1CuENoDWHD74v xUF17ThutCTymFD4/KnxrAw+A3f34WoFf5SYERxTGwgZT+UzOYqRnMFzIXr/x6gyyRrX QvenQB0ne4y45eZ2xK4S1E5YRQ53Srq+CU0IpMUDkj6wiTfOuZlJjMihIUdvDuhzBCz1 GRO3uGtiNUAD9figmGC1hnH3oIH3LriJS8zKPGMTVig0cjRxl0pcqBGXW30AwANsvOVT mfpw== 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=g1uEgOSpXoD2jR96iEnRQSqCDRpwYRl1rnc/KDZZlLo=; b=EUK2H0z2P4Vz0fmlO17c/re/0mnjfadBqGDkIMMZZyHAhcnRYUxSl8tLV+D/ddIaaB 8Z47cTos/mh8IWOlOghH8NICUs31FSfEDSh4ovBt3nQrL/Ps0oj1HBmYsJUp+LR1c7vr Ow64FvvJxn6I8isWh6VS4HpPmP3eWuw8N/zQdOxDIgMeLmUirzLAy2crUx8yha+blDyN ZNiNBVHcfDphVNoocscmy4qh7EK/MTrRjyOVMDx/3nb+gPaqkQIQp1jGEALPVdvDwnQW HLN1Nppd0WCQPXFXYgRrtUHwM7EP7kmAL6PkTN1O8frWrvA+JFnj7DZD31/YiTjNnfrr ryBQ== X-Gm-Message-State: AOAM5302h5fU8HWnpsf/xm+p6N44EQCMt3cYt2NLMWf7PDWpzd/NQNLY qBqCF1CuncK5yGB9C4n2SnMLXXPFo7kml2qH X-Google-Smtp-Source: ABdhPJzWJdwHZ2TGSLuBDPVJr7lKihixFOUeThBX98jzkNyqmt95IIwiqMPlJpbAVO3nSg6A5aQ+jA== X-Received: by 2002:ac8:590c:: with SMTP id 12mr2421979qty.291.1615580784170; Fri, 12 Mar 2021 12:26:24 -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 d70sm5312673qkg.30.2021.03.12.12.26.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:23 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 31/39] btrfs: check for BTRFS_BLOCK_FLAG_FULL_BACKREF being set improperly Date: Fri, 12 Mar 2021 15:25: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 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 f4ade821307d..8e5926232d1e 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -1290,6 +1290,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 Fri Mar 12 20:25:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136033 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 CBB55C4360C for ; Fri, 12 Mar 2021 20:27:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE47B64F73 for ; Fri, 12 Mar 2021 20:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234894AbhCLU0p (ORCPT ); Fri, 12 Mar 2021 15:26:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234871AbhCLU00 (ORCPT ); Fri, 12 Mar 2021 15:26:26 -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 BAB7DC061574 for ; Fri, 12 Mar 2021 12:26:26 -0800 (PST) Received: by mail-qt1-x835.google.com with SMTP id r14so4843611qtt.7 for ; Fri, 12 Mar 2021 12:26: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=0CttJ9njXn1GJ9FxGeLawCa94kwhIkd25rDBMICcOQc=; b=JNoDxT89lNUv309zOYGSGNy1YOBHfJWvpWxDjPyvB793d/562+M7AHcZVXR/VWMUds 8o/LHgJXym+Bs/tRKmoIIizcZ2PUR5A/JWt1TLusnCOVJn7iX5cdMMPiYw/3cZZP80Bu 9VA6yLsJWm1lASmCIsqAGgAfxtShkF9ivoCw34fR56d4xFnuOPafmRMlw/wciWWMwlRu dIwxpaVTD4xst+u3r1XV/jNcyvEwxyAMTzXwtQFcZtCvKgKLhSbedr0oOMTs1Qw+DCxz u2s3O20sna0sNxeezSYw6o4tDo1Zr+OPsHgQ71Gogr0NF5ZCQKkQ0EalPXTEawAIkSGn aWXA== 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=0CttJ9njXn1GJ9FxGeLawCa94kwhIkd25rDBMICcOQc=; b=OjAaG5GSO6GtFSJiVKArQNQGRybH0JBSM9F4bR+Fi0m34XCr0NvheRySofjqh+CNIr wH4rbfweyCC5FIBnJi1QLID5kOE5cy68c8qxamvxNmhIqwCg3sdJq8PGZ84t2UyJ/Oa7 I1tX7Dl6fMhpDDqw2SuwIrrKJtz1kf1I5j6gOQFz6pwXQRMz/8LofevVHo0c9/kznSCv Mtqt+JXOVT+DaR/eiAKgyzncOrImoZDr+g+kH5/i3HI54b4uEwS+oDFuzB1XVx2iTin0 8MqWELCwvG9g+lSqL1tGFhSaRiyLN3AMWX8ALeo564SiS5ab8Ta1Aj4bUjx8J4aYxZjG H+Pg== X-Gm-Message-State: AOAM532DVBDuLcWgmwla0FTDl6t6qPCMMzYc0GjIkNVWQ94/jmkxSbuj U3zicD6iS0uLVX+Y49AI+cC84bC47R9aKyVl X-Google-Smtp-Source: ABdhPJzX84gSadisAcrYqXgjW7qscQTJTWUSRNl/MIp8DRlyehhuVYx/h5gqr0fw3SiYfQkThvl5KQ== X-Received: by 2002:ac8:66c4:: with SMTP id m4mr13743201qtp.374.1615580785743; Fri, 12 Mar 2021 12:26: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 l65sm5160871qkf.113.2021.03.12.12.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:25 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 32/39] btrfs: remove the extent item sanity checks in relocate_block_group Date: Fri, 12 Mar 2021 15:25:27 -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 71a3db66c1ab..288d5df39fa0 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3407,20 +3407,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) { @@ -3472,7 +3458,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; @@ -3521,19 +3506,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 Fri Mar 12 20:25:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136037 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 B7CC7C4321A for ; Fri, 12 Mar 2021 20:27:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F45264F8F for ; Fri, 12 Mar 2021 20:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234896AbhCLU0p (ORCPT ); Fri, 12 Mar 2021 15:26:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234872AbhCLU02 (ORCPT ); Fri, 12 Mar 2021 15:26:28 -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 65DADC061574 for ; Fri, 12 Mar 2021 12:26:28 -0800 (PST) Received: by mail-qt1-x835.google.com with SMTP id u7so4832983qtq.12 for ; Fri, 12 Mar 2021 12:26: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=VJeRDVtsShdZ/YnML0L/8HRbj02FsVdcpDFIMPC6hBg=; b=v+1VGNOgK91dBBpn4B4nERYRw6zVpv9bAzMrFCzw3Wl5N2YTfVYkxMCy3uLQgL8tva XbezOAzOjAsz6oHoB6z6peYgyskY+B+ml30P6y9ulFf4DGkeNJlFniKolfaMxucutx9D lAMWPvD+X4AZHoamfYKbqFn2NSyf23tRl8CnP8xre+poNeDq2NsedPSmuXMMCmk000Q7 DUd0Y8xMFtu+2pIkwUBaNnopqK9BafjZycMxmtlnMFRDC6b8TQv7n8YZgMb/OY8a8W83 mL6vMmSjcv94L9HIPeVLR5NKUUVevr7zP6qQHIDXO7AP3lY0zx+0pbTa3VDQorPYHC3v t7WA== 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=VJeRDVtsShdZ/YnML0L/8HRbj02FsVdcpDFIMPC6hBg=; b=qUbIIEQIvWAZkGiIEmK/tdHBzeeRybl1MK5MSs6wytyUpDHDjPVCf3rhKiFV7CE36T F0a76IViH1kaJAXvySts/aqvSEITiaNxnY+WslCOZU9rMeWSVksdJBC46vHblr6GfsRr dCNOAjOFkNu5t87oq3j9WYNb58z3OIOkLEeNG8HckPPQJm5/exdl0453LZf/g1FOHEyr MgqmIfApOpvJHvtTlhCQ4CYx4BxJB0L1WtSb/wy+YWMVBwekXJvNrY6eYTMuptq9ze0Z yW244zhVGhynI8X2fYY7qdu4bCmjeFqRRp+6x9tT7+8nNUM0SRaPS4ndnxwmhuB3fquT HPDQ== X-Gm-Message-State: AOAM530NIEm6iL89WebKjVK6r8FgI+bt1OzI4db71SX7doxfUie8OANZ 7R4kYTFCSCB4AQ5qlAQA7yKIVrCj/v9pAGDd X-Google-Smtp-Source: ABdhPJw6WQ8X1jF7G0wQaEL/Sri0RM9wYBIW6hGR2Tg2olJlHKq8DeyF8dzBAYfrUuTDLy8FK/6eLA== X-Received: by 2002:ac8:6e85:: with SMTP id c5mr13142795qtv.299.1615580787286; Fri, 12 Mar 2021 12:26: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 m25sm4552198qtq.59.2021.03.12.12.26.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:26 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 33/39] btrfs: do proper error handling in create_reloc_inode Date: Fri, 12 Mar 2021 15:25: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 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 288d5df39fa0..43037cb302fd 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3648,6 +3648,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 @@ -3674,10 +3703,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 Fri Mar 12 20:25:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136051 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 143A5C4361A for ; Fri, 12 Mar 2021 20:27:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C648764F8F for ; Fri, 12 Mar 2021 20:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234898AbhCLU0q (ORCPT ); Fri, 12 Mar 2021 15:26:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234873AbhCLU0a (ORCPT ); Fri, 12 Mar 2021 15:26:30 -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 D075EC061574 for ; Fri, 12 Mar 2021 12:26:29 -0800 (PST) Received: by mail-qk1-x733.google.com with SMTP id n79so25709142qke.3 for ; Fri, 12 Mar 2021 12:26:29 -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=qzmRF3jfxiR858OqDPfYWOrK5vGIDaao1pthditrTgI=; b=iMxdxqFOnitOhTP+XS98QtUMs3xBqq9RPLTnx7lrFbLF+yNGovmdXUbwUJKTrek6TN owNFuU01lZtycmUKP9FD9reNKrIC1vzonIQMI7rhRVBsrvS7dMdBxM8m0fo1/TOGjTQn RwHmfVwLx9rys7FJUD+EtGPfN9oocIl0Yuty9UgwDvoFlNWuHpR9hIxuzzimh8YGIrtl t8vXaFIxjkgH3506xtvNaB2y1xxT7dB6+x2oZPyeDjvk2bQcun5ntVzNb0oPcbPcYnTh Kl+iwsJ8cF69FMynFBaVg+O1faDQwGRhc/b8qlaVPl0IcTpyIfYjhbLqoxyJ6X4PwnOZ 69ew== 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=qzmRF3jfxiR858OqDPfYWOrK5vGIDaao1pthditrTgI=; b=fIqQ7YfGj725Z3Q2BFWmwGfhqpCP1Mx+bsFYCtWSHt/zY9BpIy8IeawYmibmoz2kSh XLxYNmiouGh1mIR4SMdQuhSbIAweJcGZK6t2zRlW4ANFTRHWSAudq1lI+wp7V0zwNoBf 0OJtec/UpbqEEA9XQ6F645ATNOZEi3zCIxWffGJPn2zp9cyI8M72BRryeyYVznjV/frA 2F6nA1RGNzoagryUKcYWy/Q2D/OrXKvxP2QPHlMNmC/GtRe5H1dG9OANTXdH9Y2gQhaJ BiikTaY2dvP93Z01qJ0Zbftp2F7qBftcSEHZQAASwn6sDlVj8kXm4VD4xxuw2C3/oVd7 bnTw== X-Gm-Message-State: AOAM53091KvJP8L2a8xrXQo1fBDbUjwAazG9iwgiZCa8XoTXeseq9PA2 pCKAU+9G8VtX0aYJnUrKiC5Dx4nPQ574kAW4 X-Google-Smtp-Source: ABdhPJy09CLg8M29atjznzJNi0xOfKFa8ZIohbJraElushk1fURpB56Ckh2tygKKYW/JL5kcGRjBmg== X-Received: by 2002:a05:620a:806:: with SMTP id s6mr13598090qks.50.1615580788794; Fri, 12 Mar 2021 12:26:28 -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 k8sm3209414qth.74.2021.03.12.12.26.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:28 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 34/39] btrfs: handle __add_reloc_root failures in btrfs_recover_relocation Date: Fri, 12 Mar 2021 15:25:29 -0500 Message-Id: <49e19eed0473ca291520ea958d557634fde6efe7.1615580595.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 43037cb302fd..2fc04f96294e 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -4054,7 +4054,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); } @@ -4269,7 +4274,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 Fri Mar 12 20:25:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136043 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 28161C43619 for ; Fri, 12 Mar 2021 20:27:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EACC864F88 for ; Fri, 12 Mar 2021 20:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234900AbhCLU0r (ORCPT ); Fri, 12 Mar 2021 15:26:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234874AbhCLU0b (ORCPT ); Fri, 12 Mar 2021 15:26:31 -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 34DEDC061574 for ; Fri, 12 Mar 2021 12:26:31 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id g24so4840308qts.6 for ; Fri, 12 Mar 2021 12:26:31 -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=8xGJ7vSM3h7aAdeJgmEsDdtP0hVwe6Q/BUIZgMIk9Qo=; b=IDjZCgjdAOAw/JbBozoQvvMv9wydcsDwwGaZJkN5J6BsLZJ/oFeW4Ja4VqyvfrVsKh lpyzJ+hsLw/gjz60XzxrZ3X1AZyMMUzgMVXwa0ig7sGTsI/v6Xl3fptLRxQScvOTLXkL hbzWcItEmfvex78CbL+ykB7gAxwHPzX4JQiUEul/COdiYeJe1ymilwC7aFg5A1UYZatT Ns9EF9FwcCY9sFoaazWGERVWoc/Mj+CcYz/aN5JfdXg+UlkrDaYSumMBWM07PTadrDcd ZxcwTeJ/JlSpjdHMIJ4nqqjmJIV2mH2hazcfs3B8Tedb+7KfaJzHYISnKHiFFG9ldolD lmhA== 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=8xGJ7vSM3h7aAdeJgmEsDdtP0hVwe6Q/BUIZgMIk9Qo=; b=kqPiq6MhVbHKZBeNOeVjRYQnjrVVGAgbQMFRd0woCBqka4gqAg7murohFtm7R1ODBT kfYfI310SKvYM9sJ5M74EfvBIZprY6BOyhhhQ85ub68q0jv4FQ15BGNwvUOwxoyzgcQu 8VuW/s6ciQJQBAN/p5phuqZLWbxjR0igKIP8AMpVjM9VNUwbdUpY5dH8iND7LjaO0LaV h9IT6Ue1bZfL8VfVDeSiGghRPaZ5kk0WC4xEcncccLHwuAarzLnYwenOpg9Nu4IMrJ/A X1JvWqatDjb6D3y8bNq6/LhJpJ13eKQ3+n4V0YUejuv552WmXxGxvLpFXLfobajzXUaM Cc8w== X-Gm-Message-State: AOAM533l+h4bLPhC1ELQniveXkF4wx7OyIWmVZ3CT6VfhlnDitQt4dzB acCCEh6RsJDbFy5h5RMIx2lbYBvhkz8SavWO X-Google-Smtp-Source: ABdhPJyWif4jh5JHBGSaJdWG1plVw58/w4if/fPxJBk8YCPIGPLf8HN3Gqp+nz1L2CilHaTozdqVWw== X-Received: by 2002:a05:622a:34f:: with SMTP id r15mr13460197qtw.107.1615580790209; Fri, 12 Mar 2021 12:26: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 k4sm5204014qke.13.2021.03.12.12.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:29 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 35/39] btrfs: do not panic in __add_reloc_root Date: Fri, 12 Mar 2021 15:25:30 -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 have a duplicate entry for a reloc root then we could have fs corruption that resulted in a double allocation. Since this shouldn't happen unless there is corruption, add an ASSERT(ret != -EEXIST) to all of the callers of __add_reloc_root() to catch any logic mistakes for developers, otherwise normal error handling will happen for normal users. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 2fc04f96294e..857da684d415 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -638,9 +638,10 @@ 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, + 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); @@ -882,6 +883,7 @@ int btrfs_init_reloc_root(struct btrfs_trans_handle *trans, return PTR_ERR(reloc_root); ret = __add_reloc_root(reloc_root); + ASSERT(ret != -EEXIST); if (ret) { btrfs_put_root(reloc_root); return ret; @@ -4054,6 +4056,7 @@ int btrfs_recover_relocation(struct btrfs_root *root) } err = __add_reloc_root(reloc_root); + ASSERT(err != -EEXIST); if (err) { list_add_tail(&reloc_root->root_list, &reloc_roots); btrfs_put_root(fs_root); @@ -4274,6 +4277,7 @@ int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans, return PTR_ERR(reloc_root); ret = __add_reloc_root(reloc_root); + ASSERT(ret != -EEXIST); if (ret) { btrfs_put_root(reloc_root); return ret; From patchwork Fri Mar 12 20:25:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136047 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 67EEAC1550B for ; Fri, 12 Mar 2021 20:27:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50ED564F88 for ; Fri, 12 Mar 2021 20:27:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234905AbhCLU0t (ORCPT ); Fri, 12 Mar 2021 15:26:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234876AbhCLU0d (ORCPT ); Fri, 12 Mar 2021 15:26: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 C0834C061574 for ; Fri, 12 Mar 2021 12:26:32 -0800 (PST) Received: by mail-qv1-xf2d.google.com with SMTP id 30so4898989qva.9 for ; Fri, 12 Mar 2021 12:26:32 -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=o8PwcbYLcI09qfDxINxVvRFFpl2xsi4kodsIzZZ1JII=; b=TqN8g9uNjkhLNemyweQ5Gz5RLNOHwSwANe2TolNZ/PD6ftjj648iXeyI8AzkOxQQZv ObvkpGTyZCziD/S5To4X6oFcPM+O583OY8dtUHSx+59hi8MzoajnhHZHV3cPChOGRIX/ 5Be9d1lcwZrezFlVq/WO1AVvFPe/eI1XfHpiRe5gU2knrAt64sipJE8OUGGFEunGLLao 9Up07Pt0gsSLepyqbjQF7CycmeUEIRp0OWyDofaKn7/ZQbKaIWHyaCs3uJzR6xjgJ75g g+jCkLtDNdIFIuZE3ipMS3tx5R0cPfEDnsF58y6KIUI3H8tNn7EyqWSoWf1vtoLjb5b2 0eVg== 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=o8PwcbYLcI09qfDxINxVvRFFpl2xsi4kodsIzZZ1JII=; b=kWTytBZAB2MzZ4dGTMDGQ3lyG5S3pxTIxsbv+tQi7dg6Dz6Y386YgYNtRIMYUNHHUP qqYgULmA+o06InFoAmHEIqmmDxOtZDhTi9R+gTCTsMeTAy+hSZ9Kabg1MbunDuh6xPny u0RV2v3LRIoakG+2c+7CavG83wbNvwf1o5GGe85CrvHfbLXs3qio2a8vqETZeO3ADpUi oiZVH5OrHVpwxsAq5ep89YKyzqf9hzYCzLVs1Oyr/SqZRs8b9ab2Wb+rMTNXoGPwuw31 BWeO/QV1JEapj5Ppt/m6iOn57Dr5evqkM51JDzotQGGjtGwN9VXgyu8RTyLwlPma1R6z BD0Q== X-Gm-Message-State: AOAM532LqzhDCM3xg2KhERfKz9IvBAFVjmaVAsI3pY2IONI/2H7xqPQ0 tV6GbnsHyBemi22qfcoRMHYhdv3796AH4pje X-Google-Smtp-Source: ABdhPJwov7Y+INTtQQIDet83ulQtzAkb49KQzHfpmiQzMPGBwjNdKu1xZBFeG77Ip3GOg8H5nONWqg== X-Received: by 2002:ad4:4dc6:: with SMTP id cw6mr14216786qvb.31.1615580791616; Fri, 12 Mar 2021 12:26:31 -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 g14sm5127137qkm.98.2021.03.12.12.26.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:31 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 36/39] btrfs: cleanup error handling in prepare_to_merge Date: Fri, 12 Mar 2021 15:25:31 -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 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 857da684d415..8f7760f8fcc3 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 Fri Mar 12 20:25:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136041 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 404CAC43142 for ; Fri, 12 Mar 2021 20:27:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 18D5C64F73 for ; Fri, 12 Mar 2021 20:27:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234903AbhCLU0s (ORCPT ); Fri, 12 Mar 2021 15:26:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234877AbhCLU0e (ORCPT ); Fri, 12 Mar 2021 15:26:34 -0500 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 115E6C061761 for ; Fri, 12 Mar 2021 12:26:34 -0800 (PST) Received: by mail-qt1-x82b.google.com with SMTP id f12so4836722qtq.4 for ; Fri, 12 Mar 2021 12:26:34 -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=xkBjKSpFXs9JPkEZ9VDHRBUsRntp4Bg7JxsNWaxGThI=; b=v468QFzgk34CNkjYUcjyuEwEI2kZMLJvxEy5TfnwAwZOjZrUL873F3LMEVa5YpL2/U wLTo52hYeaoI28Q1tJts7mN/1VBM+gyB+RyR/KleOGQX1LHvcDPblb+0aCwVfA6/65Od oBFHXIaGhXS8yb2Xaa+0B/Vu34HPsDZwJDEliwkvn0mNpAOTbOyq3TVIzo5m9oYvZjVj gJVodpNFD0GRipkvrFL3wUFi51cafgJAGmlFQ5Uk85IqUkKiaj0TpxMYNEpELgSekTnN 9mP2a2nNj1i99CWw+f2a/BQd39dt8oqFTdktrE0tq3chyU1ATCHjwsaCUnHEOVURGtcd IgAQ== 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=xkBjKSpFXs9JPkEZ9VDHRBUsRntp4Bg7JxsNWaxGThI=; b=JLjvQ/Nx1/ijOcVFusYwdMPKKGRk3InlcY46n7WDPCAGu1KDbL1nlIyhcbgif9Az1k I0XonrbLFNA1Mjn7aoPzrbxu/Fe1zGp4V70IxeFhgb+yZdJc+uSK3jxQ/d077GhG/rJ8 x0bqQSxPu/oxG7craBJJZmbrSdSpEPR5mhvumEzXR4/eHGMzRlmTZvWgWzcgUVw8I1uU lrL9CTbLGz8vz+PZMBMkUp+GI6zQBBvPP/D1u8MIcwQ6EkZcFfElvAevft0EakEh3FsM K+wy/rSjuq1UuC8fCR7JkrnwviLQLJCJzL31yCgiPTdG3qpmKuCAhMVnIjWdv6DEJgmr oq3g== X-Gm-Message-State: AOAM531dNk5XnbAMRPfdwDLOpUnVlzr6ByTBx/sEG7b2mNgY/yPO9NZr 7IVLT8+FfqF0LGUdvh+FeqXaTbYG9j1E/3an X-Google-Smtp-Source: ABdhPJxNj8BK7ifaFNXeRW8fJp4tSWQdtgPUiV1Sd1uf2I+5GV507s8Ox35IOPgzK0/j9QJmETeG8w== X-Received: by 2002:aed:2b43:: with SMTP id p61mr13065750qtd.46.1615580793057; Fri, 12 Mar 2021 12:26:33 -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 d68sm5137830qkf.93.2021.03.12.12.26.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:32 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 37/39] btrfs: handle extent corruption with select_one_root properly Date: Fri, 12 Mar 2021 15:25:32 -0500 Message-Id: <3c76eb6546378e5bd6b7e3bd96468350ea6fe278.1615580595.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 | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 8f7760f8fcc3..621c4284d158 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2209,7 +2209,13 @@ 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. + */ + if (!root) + return ERR_PTR(-EUCLEAN); /* No other choice for non-shareable tree */ if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) @@ -2599,8 +2605,15 @@ 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); + + /* See explanation in select_one_root for the -EUCLEAN case. */ + ASSERT(ret == -ENOENT); + if (ret == -ENOENT) { + ret = 0; + update_processed_blocks(rc, node); + } goto out; } From patchwork Fri Mar 12 20:25:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136049 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 548A2C4160E for ; Fri, 12 Mar 2021 20:27:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3718064F8D for ; Fri, 12 Mar 2021 20:27:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234907AbhCLU0t (ORCPT ); Fri, 12 Mar 2021 15:26:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234879AbhCLU0f (ORCPT ); Fri, 12 Mar 2021 15:26:35 -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 85EF5C061574 for ; Fri, 12 Mar 2021 12:26:35 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id 94so4838007qtc.0 for ; Fri, 12 Mar 2021 12:26: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=N7PFobv7GOoDGWrv7ZgloXVvkkOJbiEbbF/Z7e/aCP4=; b=Cu9m1IgikktpZ722y8eIVZvXEEkLneUKylIXEKh9MRIxR6130VeAyQRwq+ZVi/c8q/ ZeAdGICu1Kx0zzzObNVjmlJALePMH/fqKGntqRaxvmYrg6cCcHH/coxxGnWeOJqn/F4t XA1/ztseYbCCAc1G7W8npCvGLvDOp0l7XiosycjFXgtDcj/oX2HtrWpqr0cajVRlHRwB n+RxcV/1pUsjrJDp/Vtmz8VLPKuM2vf790vC5N/0thPi2edk8m4KChgBRCDAFvgLi7EH eXRtgJVvVpNjqB0xVkQqQVx9QLyu4dkKSHQl39ohNLRaBMNVUCQG0B3JzP5p29D7hZ/a U4Dg== 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=N7PFobv7GOoDGWrv7ZgloXVvkkOJbiEbbF/Z7e/aCP4=; b=cYAwzHDTdKdq0HiBSxXZYjpx2etTNuOqF+hEO7Gki/keyjgMUaE2B8iFuxS8aPRwn/ owSwzwdys1IuwRKO/ePZ7uTpkPCI2E9y4EQFv8KbwZ1igzbFNH9gFQhfzl3vojEYR74l 519ZaReRzFaVqn8M+aZGKlDg4toQutD6OEDBYWrJ84mBEJkHRwT8zwiO25dgaaAGQgZN yZJa50kqkD3FsY+oub4JNxZHTwZ4Efe0rO3OHT0trdhqoYmBln+Y6hU06bXdtiK6eV/7 Nt6WHi38MbXj+l7H7RcaI3Oh8NsV3dVXIGoCdTtYpQVubIROieL2JEsR5NhgJ4UBGkuA t9vQ== X-Gm-Message-State: AOAM531Sl3BnbwdR8SERx90Xhwm6hVmsX1RVi/ZIe+pZFfEDsxtYKj57 DyndL64gaCXM1wpdtvmN/ea1h580StTVutaC X-Google-Smtp-Source: ABdhPJxMOBjORYk+C2XIxCPb/UmY01j/vwe7DxuhX5DQ7+gfSdQZUzBl1dOukcHIPM/PAHC+PdG2FQ== X-Received: by 2002:ac8:4e51:: with SMTP id e17mr11658347qtw.204.1615580794522; Fri, 12 Mar 2021 12:26: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 a11sm4699893qti.22.2021.03.12.12.26.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:34 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v8 38/39] btrfs: do proper error handling in merge_reloc_roots Date: Fri, 12 Mar 2021 15:25:33 -0500 Message-Id: <23538f3428180bd62d67d961a93822dcff3677d9.1615580595.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 621c4284d158..557d4f09ce7f 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 Fri Mar 12 20:25:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12136053 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 CBCFBC433E0 for ; Fri, 12 Mar 2021 20:27:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 981ED64F8D for ; Fri, 12 Mar 2021 20:27:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234949AbhCLU1I (ORCPT ); Fri, 12 Mar 2021 15:27:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234859AbhCLU0l (ORCPT ); Fri, 12 Mar 2021 15:26:41 -0500 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 029BAC061574 for ; Fri, 12 Mar 2021 12:26:37 -0800 (PST) Received: by mail-qt1-x82f.google.com with SMTP id s2so4835414qtx.10 for ; Fri, 12 Mar 2021 12:26:36 -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=Y8oSBZRXUVWprsp/bA50/MihqamlhtVrIp1ItWvS1fk=; b=G7t3/oHaNfTbufVLXFfP1zuSj7cz6nQFVkx/enbdk4YtzDxoibyogeSws8I9e+mQPZ dv2GA4fSKjX0/xEVJT10gCmTvmOkhA4IQGoeFkSF3yYdzZ15TybYCQ0BWkMdBG3XnOd+ SwskFd4wAZCuQIH8ezu31XsXK28vn5361aG/QB0fHJA4/jTJOQv67CTZ6A9VM42B5hEN 2LKJDvCfIeCWC2I5bp1Oog+lhP4lcZQPX/i93I44oxpsOZJU780vqucV+9nHUJaklnKV g9T0i20Ob2gFGL2ChWH+bOZ03KJUhZbfk0Je1utGXv2eGNPBFVYZiZ78/VwyCDRoIskJ IMIg== 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=Y8oSBZRXUVWprsp/bA50/MihqamlhtVrIp1ItWvS1fk=; b=DdZBOUJ4AqjbWwi5ZlPpD8U2eHzDTrNF+GnyO78EdtNM5XhQXWAQfQ6NmW2Qh0ThlS C9M2UWirw/ZR0AzWr3Gz/ugXCjL0piCF6Rg01mq8PgFNieEnmumT566I/bPhCaV9Y0pq vOyi743CFLPY0vUDLSc64gMqI5PTdd5UwtXBzidk6Z7inRcUvfhMzy7MFvxYj0G0zvjy hOqGvn0VsUZ6oO+6Tq2t9cvEICr7yuimR9F0MLr5CVLLx9QHW97PERwttowZ3pbad88A zpzk6gvGWLvVOMg6Pv4bhwjMuMci6fH4hvjE4mYX0MTeVTK53CyJ+Z34uZh0QdUcBg7G vfrw== X-Gm-Message-State: AOAM5327IiMrZJbDXJVXTZuhsOEdD1Rz61fHtQDQV68wCpui65Wnd+E6 148VOqxTDyXwLDCfBd234Xk2nQrpfT8AfQOn X-Google-Smtp-Source: ABdhPJzPmxnrYW637p0lkPf7PsrMZCeKT0rbj5qpAhDzh8LoJRNQjZb0Rv/KXxO3OxC8M90dkVViqA== X-Received: by 2002:ac8:4a90:: with SMTP id l16mr13335835qtq.33.1615580796002; Fri, 12 Mar 2021 12:26: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 77sm5295344qko.48.2021.03.12.12.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:26:35 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v8 39/39] btrfs: check return value of btrfs_commit_transaction in relocation Date: Fri, 12 Mar 2021 15:25:34 -0500 Message-Id: <4598afc28636ae8d935a64cafcd73d82f76196f9.1615580595.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 557d4f09ce7f..371cd4476daf 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; @@ -3487,8 +3487,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) @@ -3647,7 +3646,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)