From patchwork Tue Feb 7 16:57:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13131861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1F53C636D6 for ; Tue, 7 Feb 2023 16:57:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232039AbjBGQ5e (ORCPT ); Tue, 7 Feb 2023 11:57:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232018AbjBGQ5c (ORCPT ); Tue, 7 Feb 2023 11:57:32 -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 D0B293B667 for ; Tue, 7 Feb 2023 08:57:30 -0800 (PST) Received: by mail-qv1-xf33.google.com with SMTP id d7so4415947qvz.3 for ; Tue, 07 Feb 2023 08:57:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=v63YSZhIQDpIEPGHplK+l0eE5SS7UivVhunGpiRXEXY=; b=Czp9nkP5X/3PkK/sUAF/UZegXG6Mmryw33orB9D1dTl9/8l2HXIeAWikiNKxBCjSVF qg3ywE+fPT1K745FCw8kVurrK3MlX862lBkz+TOR0qA17VT4SDwmc9bfYMn2A1ex+Xkv 0WZkRmtDxb9nBqb28o+BXCSoS4IKGj8eM68pByLisR+RmGPZ1dd7IFT4gDTJqxAcL5fX 6kXnn1vfNtX8MG3WMzKw3Sv32r5DuwRddJuS5IDqAGusAfXjKQ3hFbt6ZomCggfXsMQC uPrw4Ch38sKIW41wvEUpJXzROgvlioGtMs0rbxPVvge7spD5u7Ksycv5ta1afeY1D/FI 8rew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v63YSZhIQDpIEPGHplK+l0eE5SS7UivVhunGpiRXEXY=; b=WyrGCkVlDa68xszW+B6/hVCVEiuWnq5FRnTsOs8qqOUm8UjhnVrVJKt/0Oc/ryYpIo YoBAiET/NqHHEjYZBb/fl5dsbTVDhyusCYqTA6d1rgVlsCowLFCEQA8c9KMV5bvy09h/ z3yc85KRUAFHqFRcXavjCR3hWiwyDf7Fzq32oDwp9B5nBK5cdSjlDVy7u+V1/vGBdyeg mpDZe6HSjiEDywUFIuHM8Ro1vAsCYO6mQQR3Q+UW2JDIRo72VSzCLWvUrE0aiv7Ickhp wIcALnCN78fhQbLT/Pkug8eYamhg/0MTRF/Zg0CF9RHF4zgPnplXusixQ49FUvH8rq/Y EyJQ== X-Gm-Message-State: AO0yUKWMxEpMUl8oJ4gkJCeOeiUmxtWNQbtgEDs4RkXnC4CrWg2/0U1O fBvww6nV76FhPJvM2yCPuAyYTO8vfSCtHU2W/oo= X-Google-Smtp-Source: AK7set84uodc52li5f7V7J1XpV6zu4xReubDCh29vWDYwrKqd0MWMVMv9xZ3l4zDIt6X+NySvW303Q== X-Received: by 2002:a05:6214:ace:b0:539:d8ce:57d5 with SMTP id g14-20020a0562140ace00b00539d8ce57d5mr7168168qvi.9.1675789049096; Tue, 07 Feb 2023 08:57:29 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id b19-20020a05620a271300b0071a291f0a4asm9923224qkp.27.2023.02.07.08.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 08:57:28 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 1/7] btrfs: use btrfs_handle_fs_error in btrfs_fill_super Date: Tue, 7 Feb 2023 11:57:19 -0500 Message-Id: <74dfb92d8d80f082f64ddb0e3b3e073f0ae24e9d.1675787102.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org While trying to track down a lost EIO problem I hit the following assertion while doing my error injection testing BTRFS warning (device nvme1n1): transaction 1609 (with 180224 dirty metadata bytes) is not committed assertion failed: !found, in fs/btrfs/disk-io.c:4456 ------------[ cut here ]------------ kernel BUG at fs/btrfs/messages.h:169! invalid opcode: 0000 [#1] PREEMPT SMP NOPTI CPU: 0 PID: 1445 Comm: mount Tainted: G W 6.2.0-rc5+ #3 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.1-2.fc37 04/01/2014 RIP: 0010:btrfs_assertfail.constprop.0+0x18/0x1a RSP: 0018:ffffb95fc3b0bc68 EFLAGS: 00010286 RAX: 0000000000000034 RBX: ffff9941c2ac2000 RCX: 0000000000000000 RDX: 0000000000000001 RSI: ffffffffb6741f7d RDI: 00000000ffffffff RBP: ffff9941c2ac2428 R08: 0000000000000000 R09: ffffb95fc3b0bb38 R10: 0000000000000003 R11: ffffffffb71438a8 R12: ffff9941c2ac2428 R13: ffff9941c2ac2450 R14: ffff9941c2ac2450 R15: 000000000002c000 FS: 00007fcea2d07800(0000) GS:ffff9941fbc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f00cc7c83a8 CR3: 000000010c686000 CR4: 0000000000350ef0 Call Trace: close_ctree+0x426/0x48f btrfs_mount_root.cold+0x7e/0xee ? legacy_parse_param+0x2b/0x220 legacy_get_tree+0x2b/0x50 vfs_get_tree+0x29/0xc0 vfs_kern_mount.part.0+0x73/0xb0 btrfs_mount+0x11d/0x3d0 ? legacy_parse_param+0x2b/0x220 legacy_get_tree+0x2b/0x50 vfs_get_tree+0x29/0xc0 path_mount+0x438/0xa40 __x64_sys_mount+0xe9/0x130 do_syscall_64+0x3e/0x90 entry_SYSCALL_64_after_hwframe+0x72/0xdc This is because the error injection did an EIO for the root inode lookup and we simply jumped to closing the ctree. However because we didn't mark the file system as having an error we skipped all of the broken transaction cleanup stuff, and thus triggered this ASSERT(). Fix this by calling btrfs_handle_fs_error() in this case so we have the error set on the file system. Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/super.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 581845bc206a..d8885966e801 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1158,6 +1158,7 @@ static int btrfs_fill_super(struct super_block *sb, inode = btrfs_iget(sb, BTRFS_FIRST_FREE_OBJECTID, fs_info->fs_root); if (IS_ERR(inode)) { err = PTR_ERR(inode); + btrfs_handle_fs_error(fs_info, err, NULL); goto fail_close; } From patchwork Tue Feb 7 16:57:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13131862 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CEBFC636D4 for ; Tue, 7 Feb 2023 16:57:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232033AbjBGQ5f (ORCPT ); Tue, 7 Feb 2023 11:57:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232086AbjBGQ5d (ORCPT ); Tue, 7 Feb 2023 11:57:33 -0500 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D04B43BD8F for ; Tue, 7 Feb 2023 08:57:31 -0800 (PST) Received: by mail-qv1-xf2c.google.com with SMTP id c5so3850944qvk.13 for ; Tue, 07 Feb 2023 08:57:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=2LuUeP9+Pd3M5rK1yWMfDkXRBAfb7ahdfkB5gJojv/0=; b=uIj8QO9Lj4xqZIu70EpIh5aBeHF24wWg4s0v3Hm5xLO/buhH5vnBKAUFPSFyD5IgFn 955nGSdH7/hIIMaV77tLfq41kt55dCIog8K+RlgI64z5UgGai6DxLMkyYJqp7YQPcOyB izBGo5fc1ouVK7M/ZMRX+cVq+jSVIjT5txvs5H8l2f3MPhkeFUE82qm3+w3jFK3sFtRt qDUjyivk9yk/O/1tNbbzpI7wpyIt9xaNM9wU7uD+8OykvegLubWtdwuhEdRomPwiq5wg cvAnwlnVdqQw1M596RwfhE6/9zemvuSSH9WG8yRGIbSNEgv7rQa4MDvzVSlOp2hwx8jV L3VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2LuUeP9+Pd3M5rK1yWMfDkXRBAfb7ahdfkB5gJojv/0=; b=BZaJaIw54uFdjqbMc3RB5wtDDTEhV/RWnBtQxCQbHq2BVp08lujASHEqVBTWB87H8V fm50iIJATvap5LAKPrdk3dkvd0KdfzAYUpCSknAwApk4yGkS8jpcyBJVdN5d77q3fLZz g5C4QUmDdWi3rSO9F2jJnrKAd0AF2pZH2Q46jWVLK48hXT+A1rxbn3CJdr32ylNL1aeg qghJtcVgn7PnGOpy2/YzqI+Nbm76scJj9fUw4+iTAEoeMgMPaBOXtUVVlQQq9f2/F1G6 K0oPg5aewncfJ13SibkEVWl4Hs2tz3KXGex7vnXKXvjfiqZsnAZWHalIHqh2mAP/eN0N 3MSg== X-Gm-Message-State: AO0yUKWPbiaQq8ClykPkobShRhBPV2/RMYnXQzo1E3Mcx0GxOp0mNghV QHx4ucJi/lpAbXv4fO7JgPucnSUixSpib0ir61g= X-Google-Smtp-Source: AK7set9duHgAeQkXsY3LmIbKaRpfoIhFZDINibWEUKjI+RKoZ2HVzVuTix6+NmWAnB5RoufqTmzWwg== X-Received: by 2002:a05:6214:240b:b0:568:f263:1c0c with SMTP id fv11-20020a056214240b00b00568f2631c0cmr7174398qvb.21.1675789050518; Tue, 07 Feb 2023 08:57:30 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id x10-20020a05620a12aa00b0071d57a0eb17sm9595034qki.136.2023.02.07.08.57.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 08:57:30 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 2/7] btrfs: replace BUG_ON(level == 0) with ASSERT(level) Date: Tue, 7 Feb 2023 11:57:20 -0500 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In btrfs_read_node_slot() we have a BUG_ON() that can be converted to an ASSERT(). Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/ctree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 118440857f33..484d750df4c6 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -964,7 +964,7 @@ struct extent_buffer *btrfs_read_node_slot(struct extent_buffer *parent, if (slot < 0 || slot >= btrfs_header_nritems(parent)) return ERR_PTR(-ENOENT); - BUG_ON(level == 0); + ASSERT(level); check.level = level - 1; check.transid = btrfs_node_ptr_generation(parent, slot); From patchwork Tue Feb 7 16:57:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13131863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE40BC636D6 for ; Tue, 7 Feb 2023 16:57:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232060AbjBGQ5h (ORCPT ); Tue, 7 Feb 2023 11:57:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232021AbjBGQ5f (ORCPT ); Tue, 7 Feb 2023 11:57:35 -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 327613B667 for ; Tue, 7 Feb 2023 08:57:33 -0800 (PST) Received: by mail-qt1-x830.google.com with SMTP id cr22so17406915qtb.10 for ; Tue, 07 Feb 2023 08:57:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=HAZBp3SfPqPNz+uqZs8QZxXxNaZt+/4AFGgxJ5FUXvg=; b=ccUHvBZAVraIY+YlW89wPbN2w5yscDcmZI6449q4lvWwH2jLMLeg8UUhV7rIsOJ2kc us6aU0Ki8b/ZWyALVqRW5qum02IGeClfQFVYiyG7qS85qVKaasTn8d/pbuQJpzi/vUFf JFyEscpRMv+WpyXitp6it6R6TsRtz9yiB8tsaVVwUKVNgeoaqRI/L4GumKHZarpdNAv4 k/no/odeP3+SmIr3CI7lYB6k2U+vCASaGsNgP1jfmTsCFqGlW+q5eU5H/PsT+F7+YvOO dsYNXe/HBhdxwBSqh9mXVZl5uo7FGWXzmap31Lr40trnQ7w/UDxVDlWc3DEsdlxCWqB5 7+PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HAZBp3SfPqPNz+uqZs8QZxXxNaZt+/4AFGgxJ5FUXvg=; b=4lv2Debhx0vt0zq6sdlq7LPD6UNvEcrIe/raWHF2eMn/tqmDM1TKlNbMoHxU/J1BHQ 9ExhwU/vUt0ieItKqGteH+LzmhnVtSpIbRuPvGqrbN5OC3q5DZKngwJ+Axl3bry+fwIL eL5OvTkqwlNtjyWrF9tkHdqFJXMpFbUzGu3eae/3LKTHDq6uq70I3xJEw/QllKS2gQNx Ygwuk/wz/HafUUmUikqRMqiYcd2IM7vFTrow2f9c0uqlUn4ZYEzLxfHQSJZJlVe55J39 1JHaTXOojTHEW8hQNW7lbYuLAJSOVoJV+v2IZ89LFCpyV0Cevw5MwmC0DPTyLysRLsQr NQeQ== X-Gm-Message-State: AO0yUKXocsphkA8ZByBQdydllrSrT3o0F22m0NZZxU2wuGIvp3t3uE1b k1XgBuTyLvAJykU/NVN9+IxuLLVP2gP0frSBPh0= X-Google-Smtp-Source: AK7set9MUo5LIycpJAMEBzpoLhbZTYS1QKXJVN4z63FPEjCMAsTsk3unLokEKKhNT7RA4vdrHvS/+w== X-Received: by 2002:a05:622a:11ca:b0:3b8:33b5:a7ec with SMTP id n10-20020a05622a11ca00b003b833b5a7ecmr6969939qtk.22.1675789051948; Tue, 07 Feb 2023 08:57:31 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id y18-20020ac87c92000000b003b630ea0ea1sm9630265qtv.19.2023.02.07.08.57.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 08:57:31 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 3/7] btrfs: handle errors from btrfs_read_node_slot in split Date: Tue, 7 Feb 2023 11:57:21 -0500 Message-Id: <180cdbe61c2a59e939d1ff285519ed93fc5d1ab6.1675787102.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org While investigating a problem with error injection I tripped over curious behavior in the node/leaf splitting code. If we get an EIO when trying to read either the left or right leaf/node for splitting we'll simply treat the node as if it were full and continue on. The end result of this isn't too bad, we simply end up allocating a block when we may have pushed items into the adjacent blocks. However this does essentially allow us to continue to modify a file system that we've gotten errors on, either from a bad disk or csum mismatch or other corruption. This isn't particularly safe, so instead handle these btrfs_read_node_slot() usages differently. We allow you to pass in any slot, the idea being that we save some code if the slot number is outside of the range of the parent. This means we treat all errors the same, when in reality we only want to ignore -ENOENT. Fix this by changing how we call btrfs_read_node_slot(), which is to only call it for slots we know are valid. This way if we get an error back from reading the block we can properly pass the error up the chain. This was validated with the error injection testing I was doing. Signed-off-by: Josef Bacik --- fs/btrfs/ctree.c | 53 ++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 484d750df4c6..ed042b541326 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -1069,11 +1069,14 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, BTRFS_NODEPTRS_PER_BLOCK(fs_info) / 4) return 0; - left = btrfs_read_node_slot(parent, pslot - 1); - if (IS_ERR(left)) - left = NULL; + if (pslot) { + left = btrfs_read_node_slot(parent, pslot - 1); + if (IS_ERR(left)) { + ret = PTR_ERR(left); + left = NULL; + goto enospc; + } - if (left) { __btrfs_tree_lock(left, BTRFS_NESTING_LEFT); wret = btrfs_cow_block(trans, root, left, parent, pslot - 1, &left, @@ -1084,11 +1087,14 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, } } - right = btrfs_read_node_slot(parent, pslot + 1); - if (IS_ERR(right)) - right = NULL; + if (pslot + 1 < btrfs_header_nritems(parent)) { + right = btrfs_read_node_slot(parent, pslot + 1); + if (IS_ERR(right)) { + ret = PTR_ERR(right); + right = NULL; + goto enospc; + } - if (right) { __btrfs_tree_lock(right, BTRFS_NESTING_RIGHT); wret = btrfs_cow_block(trans, root, right, parent, pslot + 1, &right, @@ -1245,14 +1251,14 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans, if (!parent) return 1; - left = btrfs_read_node_slot(parent, pslot - 1); - if (IS_ERR(left)) - left = NULL; - /* first, try to make some room in the middle buffer */ - if (left) { + if (pslot) { u32 left_nr; + left = btrfs_read_node_slot(parent, pslot - 1); + if (IS_ERR(left)) + return PTR_ERR(left); + __btrfs_tree_lock(left, BTRFS_NESTING_LEFT); left_nr = btrfs_header_nritems(left); @@ -1297,16 +1303,17 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans, btrfs_tree_unlock(left); free_extent_buffer(left); } - right = btrfs_read_node_slot(parent, pslot + 1); - if (IS_ERR(right)) - right = NULL; /* * then try to empty the right most buffer into the middle */ - if (right) { + if (pslot + 1 < btrfs_header_nritems(parent)) { u32 right_nr; + right = btrfs_read_node_slot(parent, pslot + 1); + if (IS_ERR(right)) + return PTR_ERR(right); + __btrfs_tree_lock(right, BTRFS_NESTING_RIGHT); right_nr = btrfs_header_nritems(right); @@ -3203,12 +3210,8 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root btrfs_assert_tree_write_locked(path->nodes[1]); right = btrfs_read_node_slot(upper, slot + 1); - /* - * slot + 1 is not valid or we fail to read the right node, - * no big deal, just return. - */ if (IS_ERR(right)) - return 1; + return PTR_ERR(right); __btrfs_tree_lock(right, BTRFS_NESTING_RIGHT); @@ -3422,12 +3425,8 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root btrfs_assert_tree_write_locked(path->nodes[1]); left = btrfs_read_node_slot(path->nodes[1], slot - 1); - /* - * slot - 1 is not valid or we fail to read the left node, - * no big deal, just return. - */ if (IS_ERR(left)) - return 1; + return PTR_ERR(left); __btrfs_tree_lock(left, BTRFS_NESTING_LEFT); From patchwork Tue Feb 7 16:57:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13131864 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F7A6C6379F for ; Tue, 7 Feb 2023 16:57:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231128AbjBGQ5i (ORCPT ); Tue, 7 Feb 2023 11:57:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbjBGQ5g (ORCPT ); Tue, 7 Feb 2023 11:57:36 -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 991073B678 for ; Tue, 7 Feb 2023 08:57:34 -0800 (PST) Received: by mail-qt1-x835.google.com with SMTP id g7so17425200qto.11 for ; Tue, 07 Feb 2023 08:57:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=iU4Wd8H0qlqydpKRcgz3tyHJ6o0cE0TQGgQrfV9/uDk=; b=6iKTSF72Jcy4tbHhdctu2N2tTIShdsABoc1wFnR3ha7xD4/oaxTXMi60SUsBCCJ07m aB1U2k6xHC9V4Oq/kbqyDNwxPva3x0sQnGIbXpUy+KrhNv/Bj7RJ0JNgtj7WmgGlNdAw DH/+bmMHsQQI52xfC+R1YLgX2g+5jd4d1woURwktLakRyIag8j4c2Lb0iA8B/o36qcnP 0dfGcjIhQWoHxsWTEbpXQbRvgCC64Xkuh7hRihv/if7j4aItbpe3pilhErcdE3SjUe8o 4OKSJhw4ECpvise18MoEcYujVZ8Fd7zqEI1ayquoUaRDfLlzNfIblpkVBUR0TEQurX1S wWzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iU4Wd8H0qlqydpKRcgz3tyHJ6o0cE0TQGgQrfV9/uDk=; b=NRr+yHZrSAGNCzvH42Wc1fRlINbH5LFAXM4WH5mgzDdE5eUKWyuB/X0DMGomwFWq3Y SZP5e5/jZdLar832yYvTC1p3ik91205Yl6t9H6UO+PBUbmBzEq3s8rfHmij9TDg/12uF 1tP7nSdnhomzY5aZVwQprdkn71BxzS2utIwLm+xt4YR55HOc3ZuAXM8R1Xcv/6ndWnqn QiC6S8XKaBPzksyGEOIR7E0SFx+daPJlBUg0GyCooo8j9gdz1IKHl2aQSEDf9rv7Ihnu 37p0tgcAbhSQPID78P9L3JQ/0J1DyOiDVlzrqq/lyd9h7BYswpxNOq1v1r4IiBZ+bRxI CvIg== X-Gm-Message-State: AO0yUKVb0mRhKt8Ctymjhc3M9W2h34DN+o3nMVf8elJsjqAqOaKIq41f O8/UwPyCKgYMgdgjqxb4EbYTCOLfg3GkdbO7aHQ= X-Google-Smtp-Source: AK7set/Xa+CQnFEASzkN4sLlHD5kDaQsGM8XagDaDxiR90pWdIQ93eeRZJPDTssqko3bPUllgg/aYA== X-Received: by 2002:a05:622a:3d0:b0:3b6:3ad0:5470 with SMTP id k16-20020a05622a03d000b003b63ad05470mr6508845qtx.31.1675789053255; Tue, 07 Feb 2023 08:57:33 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id l16-20020ac84cd0000000b003b9bf862c04sm9633770qtv.55.2023.02.07.08.57.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 08:57:32 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 4/7] btrfs: iput on orphan cleanup failure Date: Tue, 7 Feb 2023 11:57:22 -0500 Message-Id: <9544841f53fef72784c0ec3f62c746063eb9ffb1.1675787102.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We missed a couple of iput()'s in the orphan cleanup failure paths, add them so we don't get refcount errors. Signed-off-by: Josef Bacik --- fs/btrfs/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 2fd518afc4f3..09a3f7836400 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3691,6 +3691,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root) trans = btrfs_start_transaction(root, 1); if (IS_ERR(trans)) { ret = PTR_ERR(trans); + iput(inode); goto out; } btrfs_debug(fs_info, "auto deleting %Lu", @@ -3698,8 +3699,10 @@ int btrfs_orphan_cleanup(struct btrfs_root *root) ret = btrfs_del_orphan_item(trans, root, found_key.objectid); btrfs_end_transaction(trans); - if (ret) + if (ret) { + iput(inode); goto out; + } continue; } From patchwork Tue Feb 7 16:57:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13131865 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DA4BC636D4 for ; Tue, 7 Feb 2023 16:57:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232099AbjBGQ5k (ORCPT ); Tue, 7 Feb 2023 11:57:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232018AbjBGQ5h (ORCPT ); Tue, 7 Feb 2023 11:57:37 -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 26BB43BDAB for ; Tue, 7 Feb 2023 08:57:36 -0800 (PST) Received: by mail-qt1-x830.google.com with SMTP id m12so17453536qth.4 for ; Tue, 07 Feb 2023 08:57:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=HK+Ex40ZiEXKMIyDURmGZHb8DUO5Bzdj8gJ1yfSnltQ=; b=Gr4FYeR7Z6bki4yFRL5TJAQf7MyXG4L33sY42DYeDjnGESJ3+O57DBZalOnDy802lx nZ0NrC5McvJ4cfPyLY2hy1iI/a0QBz7EKKG0GsgKZ0eZz/ssKEeeWPO+fvm5iELuL5EZ +Uw0SUctRE/Btq72anJwWW0HH97sQJ0g6yTFG6AmVFXRUQUCk4fVWoBM83PGgjxJR/qM xUzjuwkWuWdZ0eZ7nXfkRlUtKV+wpcH8mVirPI9Y61EpzQz2zB3RcCboRR7X8oAQJ9Lw 1fC0OmiUE+MaeqSBVJzIVFg6RCgmZ+NYNBQdkNeGWuNUmMmZcGYr1VFiRsnC9z1I3Qb6 aplw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HK+Ex40ZiEXKMIyDURmGZHb8DUO5Bzdj8gJ1yfSnltQ=; b=vkijrCnaehRWH4cRKFjt+oyMxkkzFwox0V6xcuxtNpfZJf5nP4i7kBPsp1RGnCzg2p 7ToadKIQu8htaUr8vi246N7BqgCILqSbI5n+mGgxFbJefe0xmhSULoHgh2Zu4Pq5Vy0F BC2G/9/H1u8Ak8EjoPy2viKWz7i+hhzygbLtOHwDFWu8dZghBymPRRoVwLLVs5zTrun5 g4GIw8O+wdBGSvCWq1NNBWaKaTheak7fSx9R97DkKIBarCl8LFEUjE0unfp3gYw9RZTu dIeCXE/gGAtKcQmjQDg8m4k+ZWItOqxnSL9/1JQhDghFsKDFnGEu2LbqA/Rdun/zInjw vCgw== X-Gm-Message-State: AO0yUKXLrhMSGMroCTlpGISL/q5Tj2BaehBQr/vDDYj/fJqbEcVB3t8A 6qgNmhf8ELTJiV2am2oses8R8t5HrsJi5yWUk0Q= X-Google-Smtp-Source: AK7set94BQ3QGRBabriPKMoZQD1nGNwzY0UevKBXZRyhVdvc9wZn7NEGBxAtIoWf4IBpAiPTFZBmmw== X-Received: by 2002:ac8:5b4d:0:b0:3b5:87db:f99e with SMTP id n13-20020ac85b4d000000b003b587dbf99emr7324650qtw.39.1675789054710; Tue, 07 Feb 2023 08:57:34 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id d136-20020a37688e000000b006fa4ac86bfbsm9869962qkc.55.2023.02.07.08.57.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 08:57:34 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 5/7] btrfs: drop root refs properly when orphan cleanup fails Date: Tue, 7 Feb 2023 11:57:23 -0500 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When we mount the file system we do something like this while (1) { lookup fs roots; for (i = 0; i < num_roots; i++) { ret = btrfs_orphan_cleanup(roots[i]); if (ret) break; btrfs_put_root(roots[i]); } } for (; i < num_roots; i++) btrfs_put_root(roots[i]); As you can see if we break in that inner loop we just go back to the outer loop and lose the fact that we have to drop references on the remaining roots we looked up. Fix this by making an out label and jumping to that on error so we don't leak a reference to the roots we looked up. Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/disk-io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index b9a02163a891..c828bd987c23 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4380,12 +4380,12 @@ int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info) root_objectid = gang[i]->root_key.objectid; err = btrfs_orphan_cleanup(gang[i]); if (err) - break; + goto out; btrfs_put_root(gang[i]); } root_objectid++; } - +out: /* release the uncleaned roots due to error */ for (; i < ret; i++) { if (gang[i]) From patchwork Tue Feb 7 16:57:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13131866 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CCCBC636D6 for ; Tue, 7 Feb 2023 16:57:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232106AbjBGQ5k (ORCPT ); Tue, 7 Feb 2023 11:57:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232088AbjBGQ5i (ORCPT ); Tue, 7 Feb 2023 11:57:38 -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 867573B66F for ; Tue, 7 Feb 2023 08:57:37 -0800 (PST) Received: by mail-qt1-x82d.google.com with SMTP id z5so17425808qtn.8 for ; Tue, 07 Feb 2023 08:57:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=t/8Ov+EXfWkaiUuJFcvyiTin0ayVA6iKg40H/7pfVLg=; b=DqrJD5sqwItz/3PI3aJMAkOLVxnP+pSgyMHj30izKbxTL3KpUjBKoThy9lLj+y09b9 13ksEHueWEF8vOVm4u5eMQC9SbmVegeuCUAbFldrPfx00Q9bLp1y8Qvx6XZCk4B6q+iA Vi/iLtEwxFPmN/C7bCkhH7utzFGihRPkwURpfADezqngNDu5dsAM6fcfJtu1FF90hLm6 6Pa8xuFb4La1+8x3XXOI9bwxt7+tWjc6cqatMgNDCU7g2w5j0LW1pYoK42VDKFMKFVf/ tHlHsMJzFRS3Weg9iHAf1TfUcM/HiwIwdIaQlUcBc8GYIo7OKmswKVotWDxT0GLHwDED /03A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t/8Ov+EXfWkaiUuJFcvyiTin0ayVA6iKg40H/7pfVLg=; b=OBx4Zl4ruDSfPsEOxsHT0qzdAK+m60wp9Cg0zcYUiBPn/+BO8F7fJPvGhlz3LckWYJ 5jB+qX2+Y9PfepZXx/lbLDWyuFmoF+GBKSfWwde9cAAgc5XKZhGd6lxipwTGLAmY2G6G 7pWP8V81BZHbqJxTPIcpOaV3Xxxza75pPmHoCokLxYbYokD41v9o2D5f1t5BotK3Ztjh pibqydsS7/0ZfXyHy3ApDBhL4Dhs/nuJeC1b/yEoo+OIS07x0RWyC0F84hUxrKvX71tU eb32UZyBAgPmr30zjNEjLmEEthR4IqtmizL9+GNCKQJP8RF25dVcrPtgcMagC1VsxidS WsJA== X-Gm-Message-State: AO0yUKVteAtZU8f7SYux9UQZuugHT+D0G4ylt9JHu9uBJI3TyGMGwTwf ToMqq2FBJeChSMb/cQKrmSOgXe24rBjZc5+EcAI= X-Google-Smtp-Source: AK7set+x4KsFdcoDx78XXuNCXyuItTlsxkvYK7FyjiRvKQ3L3bXnrcg5r/YbJltZikClXC/VTym9Ew== X-Received: by 2002:a05:622a:1aa2:b0:3b8:1723:6d15 with SMTP id s34-20020a05622a1aa200b003b817236d15mr6664278qtc.58.1675789056264; Tue, 07 Feb 2023 08:57:36 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id ga17-20020a05622a591100b003b68ea3d5c8sm9896115qtb.41.2023.02.07.08.57.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 08:57:35 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 6/7] btrfs: handle errors in walk_down_tree properly Date: Tue, 7 Feb 2023 11:57:24 -0500 Message-Id: <759ff5e0931e0f2ceb836daf48e84fb7f7c8fe4e.1675787102.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We can get errors in walk_down_proc as we try and lookup extent info for the snapshot dropping to act on. However if we get an error we simply return 1 which indicates we're done with walking down, which will lead us to improperly continue with the snapshot drop with the incorrect information. Instead break if we get any error from walk_down_proc or do_walk_down, and handle the case of ret == 1 by returning 0, otherwise return the ret value that we have. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 824c657f59e8..30720ea94a82 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5509,11 +5509,11 @@ static noinline int walk_down_tree(struct btrfs_trans_handle *trans, { int level = wc->level; int lookup_info = 1; - int ret; + int ret = 0; while (level >= 0) { ret = walk_down_proc(trans, root, path, wc, lookup_info); - if (ret > 0) + if (ret) break; if (level == 0) @@ -5528,10 +5528,10 @@ static noinline int walk_down_tree(struct btrfs_trans_handle *trans, path->slots[level]++; continue; } else if (ret < 0) - return ret; + break; level = wc->level; } - return 0; + return (ret == 1) ? 0 : ret; } static noinline int walk_up_tree(struct btrfs_trans_handle *trans, From patchwork Tue Feb 7 16:57:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13131867 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DE03C636CC for ; Tue, 7 Feb 2023 16:57:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232018AbjBGQ5l (ORCPT ); Tue, 7 Feb 2023 11:57:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232096AbjBGQ5j (ORCPT ); Tue, 7 Feb 2023 11:57:39 -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 0514F3BDB5 for ; Tue, 7 Feb 2023 08:57:38 -0800 (PST) Received: by mail-qt1-x831.google.com with SMTP id h24so17408958qta.12 for ; Tue, 07 Feb 2023 08:57:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=l2YbcoN8YV/XQsKA7gpTxKVkd9miB4Uv7B6yf7bvslg=; b=BWce36AqfV65NuV3ORa7O4yxM2zJmxjUY2Xas8zlVpDWYeiqa8e2GVm66Xl+qdHY62 wp10j9+9PPn1UKa9xxyncijqOd8Zyg6ERMtO90Q69NLsbCzGzZyfH1eaXnFQ10SdRRYH F5yVFoCgYQ0RIxxoefjiXL3LqbmoHBoVRx2+IWSTuEgtLuLetJMkxas7gKkhB9Gqogyp QRFSJd/VnPf2EodRRAbO7ScmRofu3Q9f53cFQNvowgL5Yn4dq3UQ8mhhgiPL6PTzzauq CIuZcXy7Q1vE/VC5re7WWbrmc8ARyvxqR8je3Oq2s6QtdALpZv6zy8eJiBE+vtQ/78+f UfpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l2YbcoN8YV/XQsKA7gpTxKVkd9miB4Uv7B6yf7bvslg=; b=LKMZ8P9/Gy/UJHnFsa47kfXmSLdp/c4wG/wU0bcNq8Vkl8U+S6aC4BDig+N0its4u3 weDal0eLhg2XoE4qyP23phPQTaj/0VN1DF7wK5So96JmCQ59H1TPgN2JpE63UotaMBmw TyGdCnCZGw5HE+Cu794oiGf0LYDrvPP0msLajoEy4Aa4QWKfnAFEJ95pryM//gGWuFPu 7yk36iYM1QGosMHyPgvISRoEzjzcItprmKjPlukyVR+B8f6xnRqLO9levWwP+KwiYe5I vt6PcGUZ9/jBJAOLUx+nZavynD2J/Gzty4MyoOBtNEP2Fvcz8cKSaviGp3rz6o21no5o z1vA== X-Gm-Message-State: AO0yUKUH1I8URbxzWL7BwEmRxLy0O4rOtX+PviH7lyy8f4r4oOv5Yd1/ H7QZbfAobSaVseyPIq2Pt4xyQEGIIdE8heTF6dQ= X-Google-Smtp-Source: AK7set/XXMEDVPR3RYJ2qKo2o12tacUjyfFwFHLq6QxZslP0V3+2Zk0NSzXTH5Obc0Mc18Kt67gO2g== X-Received: by 2002:a05:622a:1653:b0:3b8:2a6c:d1e3 with SMTP id y19-20020a05622a165300b003b82a6cd1e3mr5871647qtj.21.1675789057664; Tue, 07 Feb 2023 08:57:37 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id j24-20020a37ef18000000b0072396cb73cdsm9735874qkk.13.2023.02.07.08.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 08:57:37 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 7/7] btrfs: abort the transaction if we get an error during snapshot drop Date: Tue, 7 Feb 2023 11:57:25 -0500 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We were seeing weird errors when we were testing our btrfs backports before we had the incorrect level check fix. These errors appeared to be improper error handling, but error injection testing uncovered that the errors were a result of corruption that occurred from improper error handling during snapshot delete. With snapshot delete if we encounter any errors during walk_down or walk_up we'll simply return an error, we won't abort the transaction. This is problematic because we will be dropping references for nodes and leaves along the way, and if we fail in the middle we will leave the file system corrupt because we don't know where we left off in the drop. Fix this by making sure we abort if we hit any errors during the walk down or walk up operations, as we have no idea what operations could have been left half done at this point. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 30720ea94a82..6b6c59e6805c 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5708,12 +5708,14 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc) ret = walk_down_tree(trans, root, path, wc); if (ret < 0) { + btrfs_abort_transaction(trans, ret); err = ret; break; } ret = walk_up_tree(trans, root, path, wc, BTRFS_MAX_LEVEL); if (ret < 0) { + btrfs_abort_transaction(trans, ret); err = ret; break; }