From patchwork Tue Dec 8 16:23:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958895 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,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 6E468C4167B for ; Tue, 8 Dec 2020 16:25:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FB2A23A75 for ; Tue, 8 Dec 2020 16:25:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730125AbgLHQYp (ORCPT ); Tue, 8 Dec 2020 11:24:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729035AbgLHQYp (ORCPT ); Tue, 8 Dec 2020 11:24:45 -0500 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B893DC0613D6 for ; Tue, 8 Dec 2020 08:24:04 -0800 (PST) Received: by mail-qk1-x742.google.com with SMTP id z188so16421510qke.9 for ; Tue, 08 Dec 2020 08:24:04 -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=QMa7bV9M06CL/jmsCalzp9jQP6wxpAhOdiQ2gxt0798=; b=Ncg/4UArxyhEnZD9J3wptTXF0pAT68y2RWknOnHJYOYznCLe0Xwhri5KwKsB/AfOJS KeYSj1BHLbF1QqqkK+xP/GYicEq5qk6qhucgfJg6PTm5HOy8cNC0xzfYGt7YKBYquIAQ Vh/pvrc3rVywGWski76AEZb24N3cVHO8yt2W7BkEG8ESrYKy1X/rVNWeYV9pEi20tovM nGLeuCKv1LWb90hw9ohorubDdhGgR+vL7RPOuflZ86H8IU981gkIXfu5bbPfp+iI1XBz OT4qUAmeaoXmruNNVbTQ0B6m38C1mGc7Ou35czwdNQANbmcSeD+FyI4LXxYFt9SiXqxB cFoQ== 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=QMa7bV9M06CL/jmsCalzp9jQP6wxpAhOdiQ2gxt0798=; b=kEFV6rKajNq0JgDPUoStSnTvnzw+Y0jSyiptx0YQ+ke4H8UVSUjxdnMbdz9f289215 aNEz7V4uUfmLHng8R9I3cF4qfCYG0CGxWxkSl3S+b56KyujKVaWgPSHF+hYKGant8oZq ADC7TGYGukZi4hJ1UwWVoM181OT0tphkofAb252lRZobRgbVyTk29Nr6ZEoNMtV2Uauq 6K39OkBMkzZ9qztX/frsnU83GA6u3HdT+U0hbS40A9FRPmS14AY3WjJSRYCkiGbouoty hIcXcP+9n7axMD7h4NiONv8+/KxZNvsIKf/Md6WirAZEuJpOXi4kwqnAooUzVDP4cRHV TkIA== X-Gm-Message-State: AOAM532CWRJVAJL92Ux7MhxJkQLRdSP/IQoY/UqYHA8oTqcOAt3YWeEN 1BS2TSAWft+8jzNX/OzJ5n0QrYe033k0exqm X-Google-Smtp-Source: ABdhPJwU8dTzKKUBuPGgVmG/8B2/Scum4XP6RZJkkh7DlbaR0QWKE8K+CGRMNL5T/1r/2mMqc3uSeg== X-Received: by 2002:a37:66d4:: with SMTP id a203mr30718606qkc.362.1607444643673; Tue, 08 Dec 2020 08:24:03 -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 p27sm14231877qkp.70.2020.12.08.08.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:02 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo , Johannes Thumshirn Subject: [PATCH v6 01/52] btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block Date: Tue, 8 Dec 2020 11:23:08 -0500 Message-Id: <19dc35ed62b15274a23dcfe78639d18b1cf120af.1607444471.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 The following patches are going to address error handling in relocation, in order to test those patches I need to be able to inject errors in btrfs_search_slot and btrfs_cow_block, as we call both of these pretty often in different cases during relocation. Reviewed-by: Qu Wenruo Reviewed-by: Johannes Thumshirn Signed-off-by: Josef Bacik --- fs/btrfs/ctree.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index cc89b63d65a4..56e132d825a2 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -1494,6 +1494,7 @@ noinline int btrfs_cow_block(struct btrfs_trans_handle *trans, return ret; } +ALLOW_ERROR_INJECTION(btrfs_cow_block, ERRNO); /* * helper function for defrag to decide if two blocks pointed to by a @@ -2821,6 +2822,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, btrfs_release_path(p); return ret; } +ALLOW_ERROR_INJECTION(btrfs_search_slot, ERRNO); /* * Like btrfs_search_slot, this looks for a key in the given tree. It uses the From patchwork Tue Dec 8 16:23:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958901 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,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 95DC3C433FE for ; Tue, 8 Dec 2020 16:25:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6427623A6C for ; Tue, 8 Dec 2020 16:25:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730237AbgLHQYv (ORCPT ); Tue, 8 Dec 2020 11:24:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729035AbgLHQYr (ORCPT ); Tue, 8 Dec 2020 11:24:47 -0500 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B960DC061793 for ; Tue, 8 Dec 2020 08:24:06 -0800 (PST) Received: by mail-qk1-x741.google.com with SMTP id h20so16448597qkk.4 for ; Tue, 08 Dec 2020 08:24: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=6Meqz591s/ZyFD9Md6tWZufYHS4nUbySwYA7AhCwTDI=; b=HLdx/BBvNHzbaVuPj081mpvZpqDOfziRyEAoJcx6XBplWOumksfdsIWKw3w+8J+aWE wl1cKxVDGi3Yf7NHPqUQdpJN1kPs9/+I6vjX4WDuYLnldlRzb1q3Cuo8IAFV7E/6qzC7 iJCFFJCRJiKyH7vnASJfEZksJZZnjqfSX2tus8FMmcb4RB5m1HtcVQ1bkJ9CcmivRfmT uTEPz4ZUooVFiB5W7t07cQ323jCCUYOn47jCRRwjJKMaUQOb67NLBtcYalYPIv6GogAQ WHyVdBVf7wP2sJQMpdA0smXKxJYIOBgHEhPPQ+FP/TWpA2TGGkzdh7Bow5bMmcB2IIZX Yxhg== 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=6Meqz591s/ZyFD9Md6tWZufYHS4nUbySwYA7AhCwTDI=; b=lNyMlHPjMZT8ygOFmn9gvgIGSsFOPSofJ5V6MkmiJTi2iFFM16GYgNb+aYB4QjtlvE Z/+OUvYxLk6uqW7R1IsLkuSOL9QYccv3JCQwrWDssLxSFDggjf9EhHDpI4As6DLJmFef NkjCeKBovUqqb4uUzrhHXCpcgzTCW1LAaFbcl2SDL+ctdVJ59+izGHYgM4RWQq5il2+r hnRzdMBWBNLtNXhJvy959R/030kajNcXcEMrUWRhgXznvfRERCqw0Um4gv3KkdOY/u5r 6RxJSDK7GaMlvciFd+eBLBWifc/BB8cVqfXUlNp18AA10vQRpNIoqwaRGCp97XwU0Dk7 9umg== X-Gm-Message-State: AOAM530REjPh/wy62S2KwPq+OCOJwT84pA/ZqqlNrwfyDTcRYMrxwbjp vesGZmFemfM1aqiaXTPa5edpetjyu8qoaJBj X-Google-Smtp-Source: ABdhPJx6oYiYW/wBuMPgrS2rP/cAcmhkzoqmiYqWcq+lbIFwJuJrY5OwYiAAuRTo9C4WUh5jwisnHQ== X-Received: by 2002:a37:801:: with SMTP id 1mr14831429qki.475.1607444645701; Tue, 08 Dec 2020 08:24: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 w22sm4354128qtt.76.2020.12.08.08.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:05 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 02/52] btrfs: modify the new_root highest_objectid under a ref count Date: Tue, 8 Dec 2020 11:23: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 Qu pointed out a bug in one of my error handling patches, which made me notice that we modify the new_root->highest_objectid _after_ we've dropped the ref to the new_root. This could lead to a possible UAF, fix this by modifying the ->highest_objectid before we drop our reference to the new_root. Signed-off-by: Josef Bacik --- fs/btrfs/ioctl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index dde49a791f3e..af8d01659562 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -717,6 +717,12 @@ static noinline int create_subvol(struct inode *dir, btrfs_record_root_in_trans(trans, new_root); ret = btrfs_create_subvol_root(trans, new_root, root, new_dirid); + if (!ret) { + mutex_lock(&new_root->objectid_mutex); + new_root->highest_objectid = new_dirid; + mutex_unlock(&new_root->objectid_mutex); + } + btrfs_put_root(new_root); if (ret) { /* We potentially lose an unused inode item here */ @@ -724,10 +730,6 @@ static noinline int create_subvol(struct inode *dir, goto fail; } - mutex_lock(&new_root->objectid_mutex); - new_root->highest_objectid = new_dirid; - mutex_unlock(&new_root->objectid_mutex); - /* * insert the directory item */ From patchwork Tue Dec 8 16:23:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958897 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.7 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 A03FAC19437 for ; Tue, 8 Dec 2020 16:25:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D57823A75 for ; Tue, 8 Dec 2020 16:25:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730157AbgLHQYv (ORCPT ); Tue, 8 Dec 2020 11:24:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730144AbgLHQYt (ORCPT ); Tue, 8 Dec 2020 11:24:49 -0500 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D353C061794 for ; Tue, 8 Dec 2020 08:24:09 -0800 (PST) Received: by mail-qk1-x744.google.com with SMTP id z188so16421725qke.9 for ; Tue, 08 Dec 2020 08:24:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3MBAVyNUqf/0LMFLeiGY+TpoYSaKveLLXpRtIg0JpiI=; b=egdYZHRJk9WNe5kc1p1Bsn8j7Ib1oBep0v14CKbEV2hFMNRo8e39+M+MAPQCzk4YDa /hMakPIdDIhZEylnmIxfVmnYKCOV47z/o2h8TO/+X/u39/SGVlbUwVIjlGvwaTWcj7SW bgeAgdvWI/Ct13bpAY/W1mTP0PJSTJo6RzOlzxieApuXKl2WWE3B3Ox/AmdTc/HLXNH9 Aa8jLbUovufJIhc97xlMLm0BZMdguv/XfvyUUe1tlxNPG5P+g54rmCzdv9GBV3WIo7Dv 0QBf5DBDVfB9+tWMmUOJ1nIjnY2uXTaS8Ur1IQz5GccTVbVu4d1PR4kyP/BT5piRTIMj 1HFg== 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=3MBAVyNUqf/0LMFLeiGY+TpoYSaKveLLXpRtIg0JpiI=; b=Edj/6ujSiTIgDRRHMOrC9si3RtQ68VwiyMyurJAVsjIRP/Xw+iRP7bJKdNPNpSEMdz mZY3HmqMDGmtm//HraGqoPQh66i68WeZqt9gNuJcv25+Xz/LFPk3659TUCYMfSHqMXi8 bwNXmiL2k9rXOFEkQyxm8R2ocNIZ+IYXoU7Oa35cYSeASKcRY4fkGZyc91whcRlgwGa5 lY4vIMw1wlY7r+QEpi+JKdwUJbTze3BSlOMxal+0Zf7dVrnh4ONAhS0G/T8HXFRiN4Nu 8YtKS4aBozfpyw94Smh+7vxxeLOxXLTbKsXwoRDNSAm0MFDQaV5DsYUI8UYKC/2f4opf AoWw== X-Gm-Message-State: AOAM530se9YdT6clGkGzQuN/nkxnXT/qQOrNey0GvcgydjqKsuYVccmx TU26pgN8m6bNMIe/2NdDDQXiqTbGEVXWq4U2 X-Google-Smtp-Source: ABdhPJxk6CyPZefzxnytVL77hdk2iYFKZQB8Hs+BMrF1DHEWWIMYPXY5CwQVYpGeCXo5nbmdKZiYfQ== X-Received: by 2002:a37:6697:: with SMTP id a145mr29807391qkc.296.1607444647969; Tue, 08 Dec 2020 08:24: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 u72sm15225753qka.15.2020.12.08.08.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:07 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo , Johannes Thumshirn Subject: [PATCH v6 03/52] btrfs: fix lockdep splat in btrfs_recover_relocation Date: Tue, 8 Dec 2020 11:23:10 -0500 Message-Id: <921347f2c777c0e213cb80cb00c6c3487c2f4907.1607444471.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 While testing the error paths of relocation I hit the following lockdep splat ====================================================== WARNING: possible circular locking dependency detected 5.10.0-rc6+ #217 Not tainted ------------------------------------------------------ mount/779 is trying to acquire lock: ffffa0e676945418 (&fs_info->balance_mutex){+.+.}-{3:3}, at: btrfs_recover_balance+0x2f0/0x340 but task is already holding lock: ffffa0e60ee31da8 (btrfs-root-00){++++}-{3:3}, at: __btrfs_tree_read_lock+0x27/0x100 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #2 (btrfs-root-00){++++}-{3:3}: down_read_nested+0x43/0x130 __btrfs_tree_read_lock+0x27/0x100 btrfs_read_lock_root_node+0x31/0x40 btrfs_search_slot+0x462/0x8f0 btrfs_update_root+0x55/0x2b0 btrfs_drop_snapshot+0x398/0x750 clean_dirty_subvols+0xdf/0x120 btrfs_recover_relocation+0x534/0x5a0 btrfs_start_pre_rw_mount+0xcb/0x170 open_ctree+0x151f/0x1726 btrfs_mount_root.cold+0x12/0xea legacy_get_tree+0x30/0x50 vfs_get_tree+0x28/0xc0 vfs_kern_mount.part.0+0x71/0xb0 btrfs_mount+0x10d/0x380 legacy_get_tree+0x30/0x50 vfs_get_tree+0x28/0xc0 path_mount+0x433/0xc10 __x64_sys_mount+0xe3/0x120 do_syscall_64+0x33/0x40 entry_SYSCALL_64_after_hwframe+0x44/0xa9 -> #1 (sb_internal#2){.+.+}-{0:0}: start_transaction+0x444/0x700 insert_balance_item.isra.0+0x37/0x320 btrfs_balance+0x354/0xf40 btrfs_ioctl_balance+0x2cf/0x380 __x64_sys_ioctl+0x83/0xb0 do_syscall_64+0x33/0x40 entry_SYSCALL_64_after_hwframe+0x44/0xa9 -> #0 (&fs_info->balance_mutex){+.+.}-{3:3}: __lock_acquire+0x1120/0x1e10 lock_acquire+0x116/0x370 __mutex_lock+0x7e/0x7b0 btrfs_recover_balance+0x2f0/0x340 open_ctree+0x1095/0x1726 btrfs_mount_root.cold+0x12/0xea legacy_get_tree+0x30/0x50 vfs_get_tree+0x28/0xc0 vfs_kern_mount.part.0+0x71/0xb0 btrfs_mount+0x10d/0x380 legacy_get_tree+0x30/0x50 vfs_get_tree+0x28/0xc0 path_mount+0x433/0xc10 __x64_sys_mount+0xe3/0x120 do_syscall_64+0x33/0x40 entry_SYSCALL_64_after_hwframe+0x44/0xa9 other info that might help us debug this: Chain exists of: &fs_info->balance_mutex --> sb_internal#2 --> btrfs-root-00 Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(btrfs-root-00); lock(sb_internal#2); lock(btrfs-root-00); lock(&fs_info->balance_mutex); *** DEADLOCK *** 2 locks held by mount/779: #0: ffffa0e60dc040e0 (&type->s_umount_key#47/1){+.+.}-{3:3}, at: alloc_super+0xb5/0x380 #1: ffffa0e60ee31da8 (btrfs-root-00){++++}-{3:3}, at: __btrfs_tree_read_lock+0x27/0x100 stack backtrace: CPU: 0 PID: 779 Comm: mount Not tainted 5.10.0-rc6+ #217 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014 Call Trace: dump_stack+0x8b/0xb0 check_noncircular+0xcf/0xf0 ? trace_call_bpf+0x139/0x260 __lock_acquire+0x1120/0x1e10 lock_acquire+0x116/0x370 ? btrfs_recover_balance+0x2f0/0x340 __mutex_lock+0x7e/0x7b0 ? btrfs_recover_balance+0x2f0/0x340 ? btrfs_recover_balance+0x2f0/0x340 ? rcu_read_lock_sched_held+0x3f/0x80 ? kmem_cache_alloc_trace+0x2c4/0x2f0 ? btrfs_get_64+0x5e/0x100 btrfs_recover_balance+0x2f0/0x340 open_ctree+0x1095/0x1726 btrfs_mount_root.cold+0x12/0xea ? rcu_read_lock_sched_held+0x3f/0x80 legacy_get_tree+0x30/0x50 vfs_get_tree+0x28/0xc0 vfs_kern_mount.part.0+0x71/0xb0 btrfs_mount+0x10d/0x380 ? __kmalloc_track_caller+0x2f2/0x320 legacy_get_tree+0x30/0x50 vfs_get_tree+0x28/0xc0 ? capable+0x3a/0x60 path_mount+0x433/0xc10 __x64_sys_mount+0xe3/0x120 do_syscall_64+0x33/0x40 entry_SYSCALL_64_after_hwframe+0x44/0xa9 This is thankfully straightforward to fix, simply release the path before we setup the reloc_ctl. Reviewed-by: Qu Wenruo Reviewed-by: Johannes Thumshirn Signed-off-by: Josef Bacik --- fs/btrfs/volumes.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 7930e1c78c45..49ba941f0314 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4318,6 +4318,8 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info) btrfs_warn(fs_info, "balance: cannot set exclusive op status, resume manually"); + btrfs_release_path(path); + mutex_lock(&fs_info->balance_mutex); BUG_ON(fs_info->balance_ctl); spin_lock(&fs_info->balance_lock); From patchwork Tue Dec 8 16:23:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958903 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,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 C79FEC2BB48 for ; Tue, 8 Dec 2020 16:25:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98D2623AFA for ; Tue, 8 Dec 2020 16:25:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730285AbgLHQYx (ORCPT ); Tue, 8 Dec 2020 11:24:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729035AbgLHQYw (ORCPT ); Tue, 8 Dec 2020 11:24:52 -0500 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B09C5C06179C for ; Tue, 8 Dec 2020 08:24:11 -0800 (PST) Received: by mail-qk1-x741.google.com with SMTP id n142so6264768qkn.2 for ; Tue, 08 Dec 2020 08:24: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=f34mcb9XXh/cL7nrpP5fwhxQKsWJY1NBHrErhfZO+94=; b=bhI8v3Q2VFj5O+TB0acVdqHadkZdGNspoasf5I9IGTeny6n1MmdXmyLXys6WVBjaZS 0OuaOh3tYA7RCigcDsRDyKRoCt+H1VvbnCDKV6XK/4+V9WbqITTytxcleIwQRJlRENEP 2E0CZvXjP9Znh5F6qdQntCkoVYLhiq8Sht7HUz420mUEPjH49kK0paKiODzUy6uWpCqd HCfJrgiqyughw/uRQslv91HcrAQDMw84sZ0rFYNVELiu0vUddvDYFMpAtxR9RImZbyi8 XFcf4vYPPqslre4Lk9ZTZudE+GrE3mbLD3cRO76Cvz9AzTLDMHilqbC7YchPktIvov1P Mu8Q== 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=f34mcb9XXh/cL7nrpP5fwhxQKsWJY1NBHrErhfZO+94=; b=Ul7pZok3gUNohFYwtCOvS8yd//If+yEtWisYgENmGg5S/ufJRnXGVWkKf6XELU6xyH j6N8bz6z+4bxJLg13c5q6gAbAq2+1pVfRxd12unGszSkCXDo2POnryhdiWeCNsTHWTjB 7qH/VKvQ/8T7ct6Ug6g0V1mcTpOXgptmGKchHlxXM/PAztYt8fBpSCAMJckq9kXi0Ezj JrZuEsuvIjFH1YyhB98OKqIX1vnQ2ltRwjOqtovfRCtJxYNMqxChWR8+v8n1f1/whmsL 0E0O6YELOSh3wHJJnMTytyM/YufhD3iYd+IZPFciqtRvsxXwFz2vfNyPWkFvXNm5jhBe KwSw== X-Gm-Message-State: AOAM532a9hV65GDf2iY0EjdCSSFwJKrym0X6D5s7a4ipLRsIOHkectOP fDqSGH56g43APlyAqSqPF7s9leaSt6M7JUww X-Google-Smtp-Source: ABdhPJwfBrWzU/2UuHOVL2y/7JIs4753GzWCQPLB0rpF6jTPcJuBCPKGuVasCXyzHYcqfKZZkI1DvA== X-Received: by 2002:a37:584:: with SMTP id 126mr16759507qkf.332.1607444649979; Tue, 08 Dec 2020 08:24: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 m8sm13946655qkn.41.2020.12.08.08.24.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:09 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 04/52] btrfs: keep track of the root owner for relocation reads Date: Tue, 8 Dec 2020 11:23:11 -0500 Message-Id: <221913dc929a47264a360b62abddece08ac3254a.1607444471.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 While testing the error paths in relocation, I hit the following lockdep splat ====================================================== WARNING: possible circular locking dependency detected 5.10.0-rc3+ #206 Not tainted ------------------------------------------------------ btrfs-balance/1571 is trying to acquire lock: ffff8cdbcc8f77d0 (&head_ref->mutex){+.+.}-{3:3}, at: btrfs_lookup_extent_info+0x156/0x3b0 but task is already holding lock: ffff8cdbc54adbf8 (btrfs-tree-00){++++}-{3:3}, at: __btrfs_tree_lock+0x27/0x100 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #2 (btrfs-tree-00){++++}-{3:3}: down_write_nested+0x43/0x80 __btrfs_tree_lock+0x27/0x100 btrfs_search_slot+0x248/0x890 relocate_tree_blocks+0x490/0x650 relocate_block_group+0x1ba/0x5d0 kretprobe_trampoline+0x0/0x50 -> #1 (btrfs-csum-01){++++}-{3:3}: down_read_nested+0x43/0x130 __btrfs_tree_read_lock+0x27/0x100 btrfs_read_lock_root_node+0x31/0x40 btrfs_search_slot+0x5ab/0x890 btrfs_del_csums+0x10b/0x3c0 __btrfs_free_extent+0x49d/0x8e0 __btrfs_run_delayed_refs+0x283/0x11f0 btrfs_run_delayed_refs+0x86/0x220 btrfs_start_dirty_block_groups+0x2ba/0x520 kretprobe_trampoline+0x0/0x50 -> #0 (&head_ref->mutex){+.+.}-{3:3}: __lock_acquire+0x1167/0x2150 lock_acquire+0x116/0x3e0 __mutex_lock+0x7e/0x7b0 btrfs_lookup_extent_info+0x156/0x3b0 walk_down_proc+0x1c3/0x280 walk_down_tree+0x64/0xe0 btrfs_drop_subtree+0x182/0x260 do_relocation+0x52e/0x660 relocate_tree_blocks+0x2ae/0x650 relocate_block_group+0x1ba/0x5d0 kretprobe_trampoline+0x0/0x50 other info that might help us debug this: Chain exists of: &head_ref->mutex --> btrfs-csum-01 --> btrfs-tree-00 Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(btrfs-tree-00); lock(btrfs-csum-01); lock(btrfs-tree-00); lock(&head_ref->mutex); *** DEADLOCK *** 5 locks held by btrfs-balance/1571: #0: ffff8cdb89749ff8 (&fs_info->delete_unused_bgs_mutex){+.+.}-{3:3}, at: btrfs_balance+0x563/0xf40 #1: ffff8cdb89748838 (&fs_info->cleaner_mutex){+.+.}-{3:3}, at: btrfs_relocate_block_group+0x156/0x300 #2: ffff8cdbc2c16650 (sb_internal#2){.+.+}-{0:0}, at: start_transaction+0x413/0x5c0 #3: ffff8cdbc135f538 (btrfs-treloc-01){+.+.}-{3:3}, at: __btrfs_tree_lock+0x27/0x100 #4: ffff8cdbc54adbf8 (btrfs-tree-00){++++}-{3:3}, at: __btrfs_tree_lock+0x27/0x100 stack backtrace: CPU: 1 PID: 1571 Comm: btrfs-balance Not tainted 5.10.0-rc3+ #206 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014 Call Trace: dump_stack+0x8b/0xb0 check_noncircular+0xcf/0xf0 ? trace_call_bpf+0x139/0x260 __lock_acquire+0x1167/0x2150 lock_acquire+0x116/0x3e0 ? btrfs_lookup_extent_info+0x156/0x3b0 __mutex_lock+0x7e/0x7b0 ? btrfs_lookup_extent_info+0x156/0x3b0 ? btrfs_lookup_extent_info+0x156/0x3b0 ? release_extent_buffer+0x124/0x170 ? _raw_spin_unlock+0x1f/0x30 ? release_extent_buffer+0x124/0x170 btrfs_lookup_extent_info+0x156/0x3b0 walk_down_proc+0x1c3/0x280 walk_down_tree+0x64/0xe0 btrfs_drop_subtree+0x182/0x260 do_relocation+0x52e/0x660 relocate_tree_blocks+0x2ae/0x650 ? add_tree_block+0x149/0x1b0 relocate_block_group+0x1ba/0x5d0 elfcorehdr_read+0x40/0x40 ? elfcorehdr_read+0x40/0x40 ? btrfs_balance+0x796/0xf40 ? __kthread_parkme+0x66/0x90 ? btrfs_balance+0xf40/0xf40 ? balance_kthread+0x37/0x50 ? kthread+0x137/0x150 ? __kthread_bind_mask+0x60/0x60 ? ret_from_fork+0x1f/0x30 As you can see this is bogus, we never take another tree's lock under the csum lock. This happens because sometimes we have to read tree blocks from disk without knowing which root they belong to during relocation. We defaulted to an owner of 0, which translates to an fs tree. This is fine as all fs trees have the same class, but obviously isn't fine if the block belongs to a cow only tree. Thankfully cow only trees only have their owners root as a reference to them, and since we already look up the extent information during relocation, go ahead and check and see if this block might belong to a cow only tree, and if so save the owner in the struct tree_block. This allows us to read_tree_block with the proper owner, which gets rid of this lockdep splat. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 47 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 19b7db8b2117..2b30e39e922a 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -98,6 +98,7 @@ struct tree_block { u64 bytenr; }; /* Use rb_simple_node for search/insert */ struct btrfs_key key; + u64 owner; unsigned int level:8; unsigned int key_ready:1; }; @@ -2393,8 +2394,8 @@ static int get_tree_block_key(struct btrfs_fs_info *fs_info, { struct extent_buffer *eb; - eb = read_tree_block(fs_info, block->bytenr, 0, block->key.offset, - block->level, NULL); + eb = read_tree_block(fs_info, block->bytenr, block->owner, + block->key.offset, block->level, NULL); if (IS_ERR(eb)) { return PTR_ERR(eb); } else if (!extent_buffer_uptodate(eb)) { @@ -2493,7 +2494,8 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans, /* Kick in readahead for tree blocks with missing keys */ rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) { if (!block->key_ready) - btrfs_readahead_tree_block(fs_info, block->bytenr, 0, 0, + btrfs_readahead_tree_block(fs_info, block->bytenr, + block->owner, 0, block->level); } @@ -2801,21 +2803,59 @@ static int add_tree_block(struct reloc_control *rc, u32 item_size; int level = -1; u64 generation; + u64 owner = 0; eb = path->nodes[0]; item_size = btrfs_item_size_nr(eb, path->slots[0]); if (extent_key->type == BTRFS_METADATA_ITEM_KEY || item_size >= sizeof(*ei) + sizeof(*bi)) { + unsigned long ptr = 0, end; + ei = btrfs_item_ptr(eb, path->slots[0], struct btrfs_extent_item); + end = (unsigned long)ei + item_size; if (extent_key->type == BTRFS_EXTENT_ITEM_KEY) { bi = (struct btrfs_tree_block_info *)(ei + 1); level = btrfs_tree_block_level(eb, bi); + ptr = (unsigned long)(bi + 1); } else { level = (int)extent_key->offset; + ptr = (unsigned long)(ei + 1); } generation = btrfs_extent_generation(eb, ei); + + /* + * We're reading random blocks without knowing their owner ahead + * of time. This is ok most of the time, as all reloc roots and + * fs roots have the same lock type. However normal trees do + * not, and the only way to know ahead of time is to read the + * inline ref offset. We know it's an fs root if + * + * 1. There's more than one ref. + * 2. There's a SHARED_DATA_REF_KEY set. + * 3. FULL_BACKREF is set on the flags. + * + * Otherwise it's safe to assume that the ref offset == the + * owner of this block, so we can use that when calling + * read_tree_block. + */ + if (btrfs_extent_refs(eb, ei) == 1 && + !(btrfs_extent_flags(eb, ei) & + BTRFS_BLOCK_FLAG_FULL_BACKREF) && + ptr < end) { + struct btrfs_extent_inline_ref *iref; + int type; + + iref = (struct btrfs_extent_inline_ref *)ptr; + type = btrfs_get_extent_inline_ref_type(eb, iref, + BTRFS_REF_TYPE_BLOCK); + if (type == BTRFS_REF_TYPE_INVALID) + return -EINVAL; + if (type == BTRFS_TREE_BLOCK_REF_KEY) + owner = btrfs_extent_inline_ref_offset(eb, + iref); + } } else if (unlikely(item_size == sizeof(struct btrfs_extent_item_v0))) { btrfs_print_v0_err(eb->fs_info); btrfs_handle_fs_error(eb->fs_info, -EINVAL, NULL); @@ -2837,6 +2877,7 @@ static int add_tree_block(struct reloc_control *rc, block->key.offset = generation; block->level = level; block->key_ready = 0; + block->owner = owner; rb_node = rb_simple_insert(blocks, block->bytenr, &block->rb_node); if (rb_node) From patchwork Tue Dec 8 16:23:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958915 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.7 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 B0CB6C2BB9A for ; Tue, 8 Dec 2020 16:25:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90A8723A75 for ; Tue, 8 Dec 2020 16:25:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730353AbgLHQZf (ORCPT ); Tue, 8 Dec 2020 11:25:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730325AbgLHQZb (ORCPT ); Tue, 8 Dec 2020 11:25:31 -0500 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5E16C0617A6 for ; Tue, 8 Dec 2020 08:24:12 -0800 (PST) Received: by mail-qk1-x743.google.com with SMTP id z188so16421921qke.9 for ; Tue, 08 Dec 2020 08:24:12 -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=EJCA1WFu34YlfNRq8jOTmY3WvoNsmIlp/39i55U+He4=; b=dST9IEESIEc0UI0UcbwlbIFykKlMlbnyVnEXtSq97swEjyoSPxqQltk4q6+Cr6DWu9 CFdcOhPYf+7zw0Sa24PlJQ+n8B2ecufMeC95mBlNNVDa43wHYMBGNbIVuhI8ojTDzXzr hJ+nDmSOvPaQguejKFtFb4QS8UepEzN085VRTJH2lPpriSkAcdUFNHv9tYvQlR93TCVk flgLY1+o+EMoemTZlMCn0DpLKixHeQ8yAxJ3BOUnYvoKZgfmcQIzXLeRgKliWm67hsNz 0ns4ypJfKJ0Zp6Do8gmHByks46WeU8jq78vxbh1AvwdZlAdKX0oIbZwYEy71qp+LQbsq ykNA== 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=EJCA1WFu34YlfNRq8jOTmY3WvoNsmIlp/39i55U+He4=; b=ePa2Qv+EdEuLeDQKS5CpR4FcxvJaRGcTszb0K442BlDk//ux7eFu1Sc3BoGIsF3EFl +f9W8VowBeXxpE9TjIJdFj1DkkWhV9d7Ni1GecM6AMCIS1WBqkNnpRnkspP8lTD60YFK yEyJDwotCx2NvXLOkdIvmBg2vQTk5expqcCcVY3zpUwE+go96U7dBWlwRWO/EQAQJpuy cuDthVU2APpwRmEjIDPTezodgGv1GtY6afOExX7YofgKfLh5kaHCe1Be43lT+AjykJuA LChhUGWcYStBFWyc6mevZvyKjfuvyyBZROhaWMSHPBcp4llOnRcNalRHDMFcUCeb1uyM NmsQ== X-Gm-Message-State: AOAM530G3/FfySknykb6/7KiHWQz4WXQaL/oFQK0GX3TwfPA2y0060Ma HSusLMZS2lQOpbzHiVl+VpV3taMRPHKQpLL/ X-Google-Smtp-Source: ABdhPJxpSW6Tng9OpztK+BxRWhKe7lZGj0OLNjRnlvUzVwFlsI/dKGC2wp7b1ip1CMTSry2ild8Rbg== X-Received: by 2002:a37:498b:: with SMTP id w133mr23157812qka.383.1607444651796; Tue, 08 Dec 2020 08:24:11 -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 y9sm995825qtm.96.2020.12.08.08.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:11 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo , Johannes Thumshirn Subject: [PATCH v6 05/52] btrfs: noinline btrfs_should_cancel_balance Date: Tue, 8 Dec 2020 11:23:12 -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 I was attempting to reproduce a problem that Zygo hit, but my error injection wasn't firing for a few of the common calls to btrfs_should_cancel_balance. This is because the compiler decided to inline it at these spots. Keep this from happening by explicitly noinline'ing the function so that error injection will always work. Reviewed-by: Qu Wenruo Reviewed-by: Johannes Thumshirn Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 2b30e39e922a..ce935139d87b 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2617,7 +2617,7 @@ int setup_extent_mapping(struct inode *inode, u64 start, u64 end, /* * Allow error injection to test balance cancellation */ -int btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info) +noinline int btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info) { return atomic_read(&fs_info->balance_cancel_req) || fatal_signal_pending(current); From patchwork Tue Dec 8 16:23:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958907 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.7 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 D5A91C4361B for ; Tue, 8 Dec 2020 16:25:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E1D523A6C for ; Tue, 8 Dec 2020 16:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730293AbgLHQZZ (ORCPT ); Tue, 8 Dec 2020 11:25:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730210AbgLHQZZ (ORCPT ); Tue, 8 Dec 2020 11:25:25 -0500 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27370C0617A7 for ; Tue, 8 Dec 2020 08:24:15 -0800 (PST) Received: by mail-qv1-xf42.google.com with SMTP id s6so738536qvn.6 for ; Tue, 08 Dec 2020 08:24:15 -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/ZltL4YxiXvMtQIs4ID4XcnLkWVuTx7SSXbu0ywjvI=; b=eoqqp9PK3r9icGwCZpi7mJ/WmnPAkorKJX0TPSc9zzwwV4/ehtMQKOVm8yjySB4PgD phpQe74g+1w0aufyhDHXGJSA1DtKFuj9q9spFHRAgfKXU326afsf5botJ6Q/OgQZtESM 6HqxO/mUd0QN6uyECeFdeAMg6zM8XrmtJqCjaN/U0Fqph40Wjv2YR5DLU4Xma6DBCoWE CHrGBhpe2x3pNU26QaRCZCz48eTxKOJ/HNJEwZDfV94EQDYkXqxFyuKGo1cTkdH2ErZ7 KSeNcocswwhUQlV/Y/XJJ8KEyX6EP+0GY43/IeaMh5yj629Txgp0dpa3OriXzoTLJnoT 273A== 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/ZltL4YxiXvMtQIs4ID4XcnLkWVuTx7SSXbu0ywjvI=; b=jVnzR40nzcmQIHwd/NlU97rW5NtHh2hkhRVsXbOhA61rv1lTriAos/AqRg/w2ksHIb UrWi6XX0uVEl37U9UdyJAIlSmHmYeNsfS7tXQbS2X7xqhVCEOfiyPte/nXVUM9i3cZBf /pnHxhmBblwmYwKSNUiGRyrquj9XTm0PUXkw6lrG3FOisWdU3mmuV+bFtLrFwzOUzhI0 giCfhNB7COGB7rlKxEUpV7640/moHwQ4Pyyr+crIxYcDnysd6eYdZBlXAjwn7D79OkZg /mRFFa/5eSz8RGu+aITAGtMZcIiF7ptx5S14EURk2LhTTlUA7mCvKFC6uRA8Eqeigxsa /uow== X-Gm-Message-State: AOAM530trwiJeRgCm6zlP7tzBZBMCQvNAKdTjG2FYq/kwVcEU7It9DNX q29JBUGYsjhLdfj0eT98xU/RROe1Ame+DtRU X-Google-Smtp-Source: ABdhPJyPKREGfC9Ek07V3hKuVh6Sg1WhEebOLVrbK77ghhTPuyTuNc7JLYCL7mRqi0dHDUml350JVQ== X-Received: by 2002:ad4:5ba7:: with SMTP id 7mr5706971qvq.31.1607444653792; Tue, 08 Dec 2020 08:24: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 f1sm13769034qtj.73.2020.12.08.08.24.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:13 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 06/52] btrfs: do not cleanup upper nodes in btrfs_backref_cleanup_node Date: Tue, 8 Dec 2020 11:23: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 Zygo reported the following panic when testing my error handling patches for relocation ------------[ cut here ]------------ kernel BUG at fs/btrfs/backref.c:2545! invalid opcode: 0000 [#1] SMP KASAN PTI CPU: 3 PID: 8472 Comm: btrfs Tainted: G W 14 Hardware name: QEMU Standard PC (i440FX + PIIX, Call Trace: btrfs_backref_error_cleanup+0x4df/0x530 build_backref_tree+0x1a5/0x700 ? _raw_spin_unlock+0x22/0x30 ? release_extent_buffer+0x225/0x280 ? free_extent_buffer.part.52+0xd7/0x140 relocate_tree_blocks+0x2a6/0xb60 ? kasan_unpoison_shadow+0x35/0x50 ? do_relocation+0xc10/0xc10 ? kasan_kmalloc+0x9/0x10 ? kmem_cache_alloc_trace+0x6a3/0xcb0 ? free_extent_buffer.part.52+0xd7/0x140 ? rb_insert_color+0x342/0x360 ? add_tree_block.isra.36+0x236/0x2b0 relocate_block_group+0x2eb/0x780 ? merge_reloc_roots+0x470/0x470 btrfs_relocate_block_group+0x26e/0x4c0 btrfs_relocate_chunk+0x52/0x120 btrfs_balance+0xe2e/0x18f0 ? pvclock_clocksource_read+0xeb/0x190 ? btrfs_relocate_chunk+0x120/0x120 ? lock_contended+0x620/0x6e0 ? do_raw_spin_lock+0x1e0/0x1e0 ? do_raw_spin_unlock+0xa8/0x140 btrfs_ioctl_balance+0x1f9/0x460 btrfs_ioctl+0x24c8/0x4380 ? __kasan_check_read+0x11/0x20 ? check_chain_key+0x1f4/0x2f0 ? __asan_loadN+0xf/0x20 ? btrfs_ioctl_get_supported_features+0x30/0x30 ? kvm_sched_clock_read+0x18/0x30 ? check_chain_key+0x1f4/0x2f0 ? lock_downgrade+0x3f0/0x3f0 ? handle_mm_fault+0xad6/0x2150 ? do_vfs_ioctl+0xfc/0x9d0 ? ioctl_file_clone+0xe0/0xe0 ? check_flags.part.50+0x6c/0x1e0 ? check_flags.part.50+0x6c/0x1e0 ? check_flags+0x26/0x30 ? lock_is_held_type+0xc3/0xf0 ? syscall_enter_from_user_mode+0x1b/0x60 ? do_syscall_64+0x13/0x80 ? rcu_read_lock_sched_held+0xa1/0xd0 ? __kasan_check_read+0x11/0x20 ? __fget_light+0xae/0x110 __x64_sys_ioctl+0xc3/0x100 do_syscall_64+0x37/0x80 entry_SYSCALL_64_after_hwframe+0x44/0xa9 This occurs because of this check if (RB_EMPTY_NODE(&upper->rb_node)) BUG_ON(!list_empty(&node->upper)); As we are dropping the backref node, if we discover that our upper node in the edge we just cleaned up isn't linked into the cache that we are now done with this node, thus the BUG_ON(). However this is an erroneous assumption, as we will look up all the references for a node first, and then process the pending edges. All of the 'upper' nodes in our pending edges won't be in the cache's rb_tree yet, because they haven't been processed. We could very well have many edges still left to cleanup on this node. The fact is we simply do not need this check, we can just process all of the edges only for this node, because below this check we do the following if (list_empty(&upper->lower)) { list_add_tail(&upper->lower, &cache->leaves); upper->lowest = 1; } If the upper node truly isn't used yet, then we add it to the cache->leaves list to be cleaned up later. If it is still used then the last child node that has it linked into its node will add it to the leaves list and then it will be cleaned up. Fix this problem by dropping this logic altogether. With this fix I no longer see the panic when testing with error injection in the backref code. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/backref.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 02d7d7b2563b..56f7c840031e 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -2541,13 +2541,6 @@ void btrfs_backref_cleanup_node(struct btrfs_backref_cache *cache, list_del(&edge->list[UPPER]); btrfs_backref_free_edge(cache, edge); - if (RB_EMPTY_NODE(&upper->rb_node)) { - BUG_ON(!list_empty(&node->upper)); - btrfs_backref_drop_node(cache, node); - node = upper; - node->lowest = 1; - continue; - } /* * Add the node to leaf node list if no other child block * cached. From patchwork Tue Dec 8 16:23:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958913 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.7 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 67AE3C1B0D8 for ; Tue, 8 Dec 2020 16:25:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B49A23A6C for ; Tue, 8 Dec 2020 16:25:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730348AbgLHQZe (ORCPT ); Tue, 8 Dec 2020 11:25:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730223AbgLHQZd (ORCPT ); Tue, 8 Dec 2020 11:25:33 -0500 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32001C0617B0 for ; Tue, 8 Dec 2020 08:24:18 -0800 (PST) Received: by mail-qt1-x843.google.com with SMTP id l7so12282297qtp.8 for ; Tue, 08 Dec 2020 08:24:18 -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=mPX5Za2NooXPbg+T4vFkZbU7CR5nDWX/OvCiwKAeGGo=; b=MXkPsSHyX0p1LGx6a+DTXZLkTJmKNkShd68hA3XPI9Yq3j+EsUvAOzrfstUv3wYP8w RZHRdxZESIF4zq66mcMR/uANM3XbV40Bb7hGtKHWso+vPQ0b17zcqn8++I7IT0wPPYCP LAxAwTpiXP1DusLh9yZZ79+/Nt0/IPxyfOO3F+YD3htsIWBxIWh0B+d5QOuQViDOzpCG 421CzSQgLHTFLeoh9hQdEcpQEBWR9uBKICbPN9xMzIUdvx6qQuDjUYAdLYJJ+DY2hvo0 xoX4wwBSKAVyRKj0IiE9C3QT7fZhN5ejVl7uo4MAKIGV1AWHBA4L9XmvLvZ/C6N7wRT4 paSA== 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=mPX5Za2NooXPbg+T4vFkZbU7CR5nDWX/OvCiwKAeGGo=; b=rH4dyEP2dch/+K1WQDbqX4gsN5/nLwdx/1AGjG4C5N7qg2FmCnbsWhLMMq1oQCKVbl 6XPETSCYssb/DG4LXpn7iTfvw29XyEYBwjcOe6PcrMFWq3pyqBJqVaUwgddRDfrQdYxw XxcmE2u+yD3TDHJXCeUyg18dlMpaQABuSqGQir3SWdZSjv6vZrZQOznb9bjrnFu7u+5J DQsdy/jlB9L0PSLVKKSkn+G1eSGLnXHaT/5xMu1ikyrjTOuVD9+XFduK3bJfG8C5TXsv 9wycpFX4VAT7XyRQXQ5690/c5B04oEt2aECUQVOi7aagzh8cjyLfKfBg2nv4tn0XCHc1 H+Vw== X-Gm-Message-State: AOAM530JkNk2OThBwR1gr1BQJ5cliVi68LJtbXDgzCxxVWkPKQ+YZXtO IYpM+ANi82Vw30cjspA6fvgAW1DPdf77Tt4N X-Google-Smtp-Source: ABdhPJw9RQuCg7CykLqU66E69g/UBJqVOdgTZRKAbwzzkYbxQp4FpNg0z7iFlnXNeDhmbf+uqWxliA== X-Received: by 2002:a05:622a:303:: with SMTP id q3mr30323807qtw.24.1607444657029; Tue, 08 Dec 2020 08:24:17 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id u7sm4573454qke.116.2020.12.08.08.24.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:15 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 07/52] btrfs: pass down the tree block level through ref-verify Date: Tue, 8 Dec 2020 11:23:14 -0500 Message-Id: <55f116a3d3f00ad045ed8cd4f5cd8f05ae80e113.1607444471.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 I noticed that sometimes I would have the wrong level printed out with ref-verify while testing some error injection related problems. This is because we only get the level from the main extent item, but our references could go off the current leaf into another, and at that point we lose our level. Fix this by keeping track of the last tree block level that we found, the same way we keep track of our bytenr and num_bytes, in case we happen to wander into another leaf while still processing the references for a bytenr. Signed-off-by: Josef Bacik --- fs/btrfs/ref-verify.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c index 4b9b6c52a83b..409b02566b25 100644 --- a/fs/btrfs/ref-verify.c +++ b/fs/btrfs/ref-verify.c @@ -495,14 +495,15 @@ static int process_extent_item(struct btrfs_fs_info *fs_info, } static int process_leaf(struct btrfs_root *root, - struct btrfs_path *path, u64 *bytenr, u64 *num_bytes) + struct btrfs_path *path, u64 *bytenr, u64 *num_bytes, + int *tree_block_level) { struct btrfs_fs_info *fs_info = root->fs_info; struct extent_buffer *leaf = path->nodes[0]; struct btrfs_extent_data_ref *dref; struct btrfs_shared_data_ref *sref; u32 count; - int i = 0, tree_block_level = 0, ret = 0; + int i = 0, ret = 0; struct btrfs_key key; int nritems = btrfs_header_nritems(leaf); @@ -515,15 +516,15 @@ static int process_leaf(struct btrfs_root *root, case BTRFS_METADATA_ITEM_KEY: *bytenr = key.objectid; ret = process_extent_item(fs_info, path, &key, i, - &tree_block_level); + tree_block_level); break; case BTRFS_TREE_BLOCK_REF_KEY: ret = add_tree_block(fs_info, key.offset, 0, - key.objectid, tree_block_level); + key.objectid, *tree_block_level); break; case BTRFS_SHARED_BLOCK_REF_KEY: ret = add_tree_block(fs_info, 0, key.offset, - key.objectid, tree_block_level); + key.objectid, *tree_block_level); break; case BTRFS_EXTENT_DATA_REF_KEY: dref = btrfs_item_ptr(leaf, i, @@ -549,7 +550,8 @@ static int process_leaf(struct btrfs_root *root, /* Walk down to the leaf from the given level */ static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path, - int level, u64 *bytenr, u64 *num_bytes) + int level, u64 *bytenr, u64 *num_bytes, + int *tree_block_level) { struct extent_buffer *eb; int ret = 0; @@ -565,7 +567,8 @@ static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path, path->slots[level-1] = 0; path->locks[level-1] = BTRFS_READ_LOCK; } else { - ret = process_leaf(root, path, bytenr, num_bytes); + ret = process_leaf(root, path, bytenr, num_bytes, + tree_block_level); if (ret) break; } @@ -974,6 +977,7 @@ int btrfs_build_ref_tree(struct btrfs_fs_info *fs_info) { struct btrfs_path *path; struct extent_buffer *eb; + int tree_block_level = 0; u64 bytenr = 0, num_bytes = 0; int ret, level; @@ -998,7 +1002,7 @@ int btrfs_build_ref_tree(struct btrfs_fs_info *fs_info) * different leaf from the original extent item. */ ret = walk_down_tree(fs_info->extent_root, path, level, - &bytenr, &num_bytes); + &bytenr, &num_bytes, &tree_block_level); if (ret) break; ret = walk_up_tree(path, &level); From patchwork Tue Dec 8 16:23:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958905 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.7 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 EEAEDC433FE for ; Tue, 8 Dec 2020 16:25:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD4F623A75 for ; Tue, 8 Dec 2020 16:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730297AbgLHQZ1 (ORCPT ); Tue, 8 Dec 2020 11:25:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730210AbgLHQZ1 (ORCPT ); Tue, 8 Dec 2020 11:25:27 -0500 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8890C06138C for ; Tue, 8 Dec 2020 08:24:20 -0800 (PST) Received: by mail-qk1-x741.google.com with SMTP id 1so16481530qka.0 for ; Tue, 08 Dec 2020 08:24:20 -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=DMvNnOrRtu4yLJxhDVPBS7UDJWnYlz36sTOfG9aJkV8=; b=hA433fFe3SsJc4KO3meV0Y8DmXxvrbP/9oHcgevrIcUFPipsTCpLlOnqs/0SpmoLEQ Tto4zOF7xBlPBLl9aN3X0jbEGjkMFzbI6GzTWfvLVu2qCKR1Fi47aUSR1qUzVqZJ7O6x gbd6pznqqvjMyQJyhnMHFQO2Jj4ejkXIcWwLHi1VkB1PD+Wjaz0XroJApp2CDanl9H2g xVvETkGx2bAnPb5H/geL9ekrDlURqomGQOFbzqGGlmYy10ZwefLHMnoI+FeIsKNu3aHk Lv+sHz+2/lwg/xbdZu6eMm/tNMANW5TLH96F5hQBX2oSTkK2HItbfP4opWPqRDPF150o j0GQ== 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=DMvNnOrRtu4yLJxhDVPBS7UDJWnYlz36sTOfG9aJkV8=; b=ODdOYLHgN0wBGtFujySq1fBMAO0akLGFzYGemd08MTmxiqGD8I70dShaTNM8H8F8Mw rT1Y1CChHnQF4iuCjiv7+iEVzflmuFev2Dj54BOIL03Dcf0ZpjAHj8AdV357dwuIzCbg vC6KAbinPT/ShICYDBeAPFBJQ60Vw/p22aqq8j1W27bKKx3/76FZ0yhS07LnKDmxDCJC 1043RJxa0Bdf9UdCsOEE8rnEXddhyRh14c7k5IexK/FpIsUbpE7KSshBrX5ej9uGnInA iqaKWG1UT8CTIbVQGI6TFtY87YrQRZx+C4oIofaLjowufIPME1YPCJVhCF7IPjJF1bKZ Vnaw== X-Gm-Message-State: AOAM531PryOmHiw/aHdCeyD2xVGsDErNW+zLgyqpHpG4VqJq0qqhLsct SX+q21SBCgAH6tTxdhvA5iN0SYaJHsl1/zid X-Google-Smtp-Source: ABdhPJwOrse3m91UkeOSdg6sgN9TkzSvLHEOABSgWjVI3ZHBpU/0TrjcPQJA3BAkvI8E9mSKD+hIDQ== X-Received: by 2002:a37:a297:: with SMTP id l145mr12664666qke.344.1607444659602; Tue, 08 Dec 2020 08:24: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 n66sm8055925qkn.136.2020.12.08.08.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:18 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 08/52] btrfs: make sure owner is set in ref-verify Date: Tue, 8 Dec 2020 11:23:15 -0500 Message-Id: <2c33a26a51ab7c14f2b9d97a5dabbc2061ef0586.1607444471.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 I noticed that shared ref entries in ref-verify didn't have the proper owner set, which caused me to think there was something seriously wrong. However the problem is if we have a parent we simply weren't filling out the owner part of the reference, even though we have it. Fix this by making sure we set all the proper fields when we modify a reference, this way we'll have the proper owner if a problem happens and we don't waste time thinking we're updating the wrong level. Signed-off-by: Josef Bacik --- fs/btrfs/ref-verify.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c index 409b02566b25..2b490becbe67 100644 --- a/fs/btrfs/ref-verify.c +++ b/fs/btrfs/ref-verify.c @@ -669,18 +669,18 @@ int btrfs_ref_tree_mod(struct btrfs_fs_info *fs_info, u64 bytenr = generic_ref->bytenr; u64 num_bytes = generic_ref->len; u64 parent = generic_ref->parent; - u64 ref_root; - u64 owner; - u64 offset; + u64 ref_root = 0; + u64 owner = 0; + u64 offset = 0; if (!btrfs_test_opt(fs_info, REF_VERIFY)) return 0; if (generic_ref->type == BTRFS_REF_METADATA) { - ref_root = generic_ref->tree_ref.root; + if (!parent) + ref_root = generic_ref->tree_ref.root; owner = generic_ref->tree_ref.level; - offset = 0; - } else { + } else if (!parent) { ref_root = generic_ref->data_ref.ref_root; owner = generic_ref->data_ref.ino; offset = generic_ref->data_ref.offset; @@ -696,13 +696,10 @@ int btrfs_ref_tree_mod(struct btrfs_fs_info *fs_info, goto out; } - if (parent) { - ref->parent = parent; - } else { - ref->root_objectid = ref_root; - ref->owner = owner; - ref->offset = offset; - } + ref->parent = parent; + ref->owner = owner; + ref->root_objectid = ref_root; + ref->offset = offset; ref->num_refs = (action == BTRFS_DROP_DELAYED_REF) ? -1 : 1; memcpy(&ra->ref, ref, sizeof(struct ref_entry)); From patchwork Tue Dec 8 16:23:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958921 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.7 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 C8B7EC2BBCD for ; Tue, 8 Dec 2020 16:25:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA1DC23A6C for ; Tue, 8 Dec 2020 16:25:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730305AbgLHQZ3 (ORCPT ); Tue, 8 Dec 2020 11:25:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730210AbgLHQZ3 (ORCPT ); Tue, 8 Dec 2020 11:25:29 -0500 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A848C061285 for ; Tue, 8 Dec 2020 08:24:23 -0800 (PST) Received: by mail-qk1-x744.google.com with SMTP id z11so7250524qkj.7 for ; Tue, 08 Dec 2020 08:24:23 -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=Pg4Rs440j7qytVG8dQXueQyKh7OJmkNUbqs81SrLs48=; b=hkcpAIm2qE6pwXMGDDKXeRM+T3NKXGuHdAnLGVtQ6/Alp2F3WW3QM31RVxG26eJnGk zfutMpFtMAvPMG5oqTbvxRHs5SQ8j3vjZTuS2qVBNReHn/tcDU9qmIBtbBDOTK9IzpYP HOOkxTbXW3iCMI8ncH46PXoXMpdNJgwBahWtTc5lgFka9Lsnf3NKNbnFJjtOyaNC4CD3 4YP3uC87kE+OXESvWuhfNjMETdrtjsnSPdf2zNxlraMSE+JFncbLzjKQvbIxzm39pGuT LST+8pEKphl+vNeHk+gwCDsoGvSD0NBYhaRrTGGlaEd7AJbVuF6JTJz3aTig5znaCe+o 84pA== 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=Pg4Rs440j7qytVG8dQXueQyKh7OJmkNUbqs81SrLs48=; b=IAdRR3bdcxTACtW+enPHZpSuGOywiW04WAIqOHU2ZeZoYP5wx8hvnB/xBEF0pukFVP 8JGf0mOePlaifQ0sKQGYH+G67VQhIulh5xzJp234LrBUWZ3X1S31x4l7yJfinxHit4ar BntqOcDKGZiUDbSCqpak0Qm8FB3bTaRD2PzBmNFkQyiaLiRzbBz2DO4DEsN2D76qpkW6 czSvpd1/QImpkN/Oby2Ae6RQNTkxTVYtB/F1lmtcEIFo9ZoTO54I39Aytz1rVtayouE2 Kz+ccVKOYXkErW1LwfZg8FmK84OrH5cGa6BDE6qOTMBhBJnlGvIlARctS7bDv9UYaF+c MnUQ== X-Gm-Message-State: AOAM531Wr/T6sxymXEmNBm5qT+EvoxPlypl8V1CNc1+6ubo5qLBjlm7a cTHeQDU89GeGy+RTwi7Fg98g8kf4FCPiOVkc X-Google-Smtp-Source: ABdhPJwHsE4gcclr+Et3k41OQ55bua5KTNbwTnbcmkpV3nu27cW7JHa0opSPLK+BJ1mdHszL5G/zig== X-Received: by 2002:a37:6403:: with SMTP id y3mr31092036qkb.204.1607444662000; Tue, 08 Dec 2020 08:24: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 o68sm9054547qkf.84.2020.12.08.08.24.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:21 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo , Johannes Thumshirn Subject: [PATCH v6 09/52] btrfs: don't clear ret in btrfs_start_dirty_block_groups Date: Tue, 8 Dec 2020 11:23:16 -0500 Message-Id: <3531541c898a12776c7770d70bb4887b738b2e57.1607444471.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 update a block group item in the loop we'll break, however we'll do btrfs_run_delayed_refs and lose our error value in ret, and thus not clean up properly. Fix this by only running the delayed refs if there was no failure. Reviewed-by: Qu Wenruo Reviewed-by: Johannes Thumshirn Signed-off-by: Josef Bacik --- fs/btrfs/block-group.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 52f2198d44c9..0886e81e5540 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2669,7 +2669,8 @@ int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans) * Go through delayed refs for all the stuff we've just kicked off * and then loop back (just once) */ - ret = btrfs_run_delayed_refs(trans, 0); + if (!ret) + ret = btrfs_run_delayed_refs(trans, 0); if (!ret && loops == 0) { loops++; spin_lock(&cur_trans->dirty_bgs_lock); From patchwork Tue Dec 8 16:23:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958911 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,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 166EBC4167B for ; Tue, 8 Dec 2020 16:25:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D77A123AFA for ; Tue, 8 Dec 2020 16:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730309AbgLHQZ3 (ORCPT ); Tue, 8 Dec 2020 11:25:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730301AbgLHQZ3 (ORCPT ); Tue, 8 Dec 2020 11:25:29 -0500 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51236C061257 for ; Tue, 8 Dec 2020 08:24:25 -0800 (PST) Received: by mail-qk1-x743.google.com with SMTP id q22so16437567qkq.6 for ; Tue, 08 Dec 2020 08:24: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=k1hxcsJJMk0pDGd/bRGloTbtUHmPw3bnputB8RyBCEY=; b=XsVLAHo4jSbB+2k+HFNoWPed6VhWtVHX3QNHy14f+Eols/1RiA1w8VF2VO+nXp3Z9o NWoh0/mzT9m3/SSZ7GOtbZgdycjjZGjWbJqfGxLfbGFjntTZdzo+yRSz6axgyRdGRWOQ PUmjxqTMS6+6WbrHe6TnDcE94vzNH1IfBqhVR0DpWo0Ppe3uCFazyNPhBeHlI3kct2/G GuY6HB5VJrWWdxlm/n+SGvFb9R/6IIBpYyhzaBz327rPvCYpNpjvBdfUVwK/pnI8ZtrB nsrW+dzQHjJo9sMNG4UkwvpZzN45awfG/Jmkh+tWKbQehe+37sfn4wukmue8Ifib9qgV HTQQ== 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=k1hxcsJJMk0pDGd/bRGloTbtUHmPw3bnputB8RyBCEY=; b=KmlQcxxBLhLPGUUYFrBqSwVRmAWWkdvjJMu0oYuNbaoq3xLyStUJuptbtQGTDig0DI l+im7I9nHHPF2LlR7U+KZWv0YDXKaZQHPB+mH4744HXxSJdt3WFtbbFwcQQDSfEBX5YG WzizyJpLFV22UzHpuaQ4vt/vcpNePbdhzqWNMl+TcD2lSL9iY3/VOva6FXGTS9pD40V4 RHYvSznkYHZE7r87bw41u3/n6sJydlzr++Ov9pzVQ80c043U8uXInoku8g+loqc6G+F9 +ByeU5ahmFzQQ/Av/45GTtqGxVnsu6zXVZ9bVS+PYw5hsL/VCk8Q7X9AVwvPbs1jvAMC PNyg== X-Gm-Message-State: AOAM533s1XsnqHIenr+kx0tB6ZYmZc+PpeZjG1fiwHFVYD5k3jZlFdtp E/ljd41nBc+Ze8dh2XCJJIMPn60FT5vuJuB/ X-Google-Smtp-Source: ABdhPJw8SmvUpL/OsvnSJl5xnloluHz5ZByzrPRfOrfzY2Yw95ElZCgGzbspEPRC7LQMUNulNdaRZQ== X-Received: by 2002:a05:620a:22ab:: with SMTP id p11mr8257704qkh.237.1607444664234; Tue, 08 Dec 2020 08:24: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 131sm13516391qkg.69.2020.12.08.08.24.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:23 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 10/52] btrfs: convert some BUG_ON()'s to ASSERT()'s in do_relocation Date: Tue, 8 Dec 2020 11:23:17 -0500 Message-Id: <428478482260461d4960bf798f163fe5195e347b.1607444471.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 ce935139d87b..d0ce771a2a8d 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2183,7 +2183,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; @@ -2268,7 +2272,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); @@ -2304,7 +2312,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 Tue Dec 8 16:23:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958919 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.7 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 97D43C2BBCA for ; Tue, 8 Dec 2020 16:25:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7426D23A6C for ; Tue, 8 Dec 2020 16:25:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730320AbgLHQZa (ORCPT ); Tue, 8 Dec 2020 11:25:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730301AbgLHQZ3 (ORCPT ); Tue, 8 Dec 2020 11:25:29 -0500 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62684C0611C5 for ; Tue, 8 Dec 2020 08:24:27 -0800 (PST) Received: by mail-qk1-x744.google.com with SMTP id q22so16437684qkq.6 for ; Tue, 08 Dec 2020 08:24:27 -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=vx6FQGPAtVmSplymEMoDA9sA2iSVI0CL70LRafsPBms=; b=J/WlXtf3QCM8Eq3RyKuvVelx8MAHO66kGJB6x2Hi8wdmwuax1jmT89cIPYMzeFn1ga PjZunewi9D3tVUYj66+cirNBN9UE2rDeXaLCqfSqstCZaED4cDwSigbNNRSSctWLjTGQ hRxEY6NzL/gSQxW9yJQb7HOcvfFp/kBFCpXZNJUJiY85YMqojKEsOBBFtFLyPMPhZ56m HnhG36ofebufuflVCRpfrrDsKpsp7JLJiSCRFkEncaIvgcn92zo1L8JxKyRg4jc1R3u6 UTP7rx73txV1PRAAJViPd0kYdZmhA2WTGLALwLejDSbftvFDBnc5939t/5NURKNE3BK2 acxA== 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=vx6FQGPAtVmSplymEMoDA9sA2iSVI0CL70LRafsPBms=; b=rYue+517dp+W6QAcUna7iqjDYo+ID1OrH7XnRgXTPRfUULjlhoTwABX/2Y2PMupgwj 4cNO+1bmGN8J1SCUlqUoY7oOYOTgrdlUSaZDMHc+SQSR5MYqbKxK2Ejhn+okx57WzIN6 HYypTSLuR26HF1es8eAADEmEQDCHO1zmsW0cS7zCpSjl8ia4X2F5UsPqfH1egOdp7Rr7 u2zXWESdkgcUTRyLnIYs7MKOtIxUnu3hMZ1CYib43ItmqGyjwCPF2PmJ37SWWweULebg rS/Q3LNZJjePfjwHzVceBuKBCnDZE/WB0y7XEm3kwQc7/HsKVR2NTgUR5C7OBuDI0xXN CKgw== X-Gm-Message-State: AOAM531ttlCv/BeZAhLMBiyO+VR8SFTVf0oo6rW5FwMiYj9JOxu6BCgv cDPXzeS+9ADA0p4s+QJAW4pYYgr/N+fshsAX X-Google-Smtp-Source: ABdhPJxKPTP76CvNrGc2iSyGVS8CWhPBHXd+nzO79Kgx3XpsEVYbLkSjSVPybQ6w4IsHN5phsV4V9w== X-Received: by 2002:a05:620a:630:: with SMTP id 16mr7510909qkv.230.1607444666175; Tue, 08 Dec 2020 08:24:26 -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 x65sm748119qkc.130.2020.12.08.08.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:25 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 11/52] btrfs: convert BUG_ON()'s in relocate_tree_block Date: Tue, 8 Dec 2020 11:23:18 -0500 Message-Id: <1d90d8f0b061d0b009a753a6f51b648e0b41ebcb.1607444471.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 d0ce771a2a8d..4333ee329290 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2456,8 +2456,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 Tue Dec 8 16:23:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958909 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.7 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 2A354C19437 for ; Tue, 8 Dec 2020 16:25:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01F6B23A6C for ; Tue, 8 Dec 2020 16:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730324AbgLHQZa (ORCPT ); Tue, 8 Dec 2020 11:25:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730311AbgLHQZa (ORCPT ); Tue, 8 Dec 2020 11:25:30 -0500 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39629C0611CB for ; Tue, 8 Dec 2020 08:24:30 -0800 (PST) Received: by mail-qk1-x742.google.com with SMTP id q22so16437842qkq.6 for ; Tue, 08 Dec 2020 08:24:30 -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=3dyOAnzBCzfv8RtBEClH5V06XMnw7y3H299tlnVJ1FM=; b=MFc8XKwlJrI61AQo2Fh2J0CdPhQSKJjg16TkJx7QedW1/NjLnDJ/BvAl/lkedHsQ0J H3DuA+dnq9xPiMUusDO8gr1qClfQkTxnRKvyFnWfLB2yKb62YUiCxcECyO4IjPVVJawV NkXdX9jY9HbW12wFADAoBVKc/hSpcy2eH25Q6iTaVzYTpHWDZj4hDvh1uqqXuaGmefmA 7KXH+7ZkHM8Ffyz1QLrMt/esPnn4HYjFVHv+7rw0ygHmwoTyhMK6YnUxiU0625TrtVbP R84zIsM7oL9awNGXBugAF6epCQP0YDSsST7aI4iMIHdO1h5eH3seW5EsdBXw9Uq5tFry O6/A== 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=3dyOAnzBCzfv8RtBEClH5V06XMnw7y3H299tlnVJ1FM=; b=OUNh1kHtvDmZPKVbFV6R1FhRW1R7zip6jnfebxnxKfrTD+Q90keow1SJWwkOtbK65V rkv8FqpOxNxCFAy83gcmkqVc1yjUCHNwqkDDu2AtyLYpx4TCUdYJAopjF8luKDaqWdG0 Hj6XiA7ebV652rnJ9VVUdsmvFP45EgxXFuPLNOBTH0SlE18I2DAP6ew+RUl1u3Jl2aXQ M7DWrkBjQwCGkLZtRHl7axWLMS3SKXVCNYLq8xuSUC1n91meImblIacsuApNogI9apkp 7eQ+QmBCF00Lsn/J2CKCwh4tp2EQLuVi0O7kCjUEyK5gXhMRI+Sps1frTBjb6ozFJuOG B5gA== X-Gm-Message-State: AOAM533RSZW5GvLAzVECQQfkQQo/GN/msH9TN0/mxFTfITCAbPoQbcHu Jjw8pBHtYZ3+I8HEL/Y9TLh3PiRFPutJLunW X-Google-Smtp-Source: ABdhPJzBUTPu+xhD2RKt0u3qvIeiDBeFjg9mJwRJabc1ZAekseA+luKHpJzxhaJv2DKMo/DnpIRuwA== X-Received: by 2002:a37:dcc3:: with SMTP id v186mr31155339qki.446.1607444667950; Tue, 08 Dec 2020 08:24: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 i7sm13795763qkl.94.2020.12.08.08.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:27 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo , Johannes Thumshirn Subject: [PATCH v6 12/52] btrfs: return an error from btrfs_record_root_in_trans Date: Tue, 8 Dec 2020 11:23:19 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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 e51ff63c8408..5cc368fede19 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -400,6 +400,7 @@ static int record_root_in_trans(struct btrfs_trans_handle *trans, int force) { struct btrfs_fs_info *fs_info = root->fs_info; + int ret = 0; if ((test_bit(BTRFS_ROOT_SHAREABLE, &root->state) && root->last_trans < trans->transid) || force) { @@ -448,11 +449,11 @@ static int record_root_in_trans(struct btrfs_trans_handle *trans, * lock. smp_wmb() makes sure that all the writes above are * done before we pop in the zero below */ - btrfs_init_reloc_root(trans, root); + ret = btrfs_init_reloc_root(trans, root); smp_mb__before_atomic(); clear_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state); } - return 0; + return ret; } From patchwork Tue Dec 8 16:23:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958917 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.7 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 884DBC2BB48 for ; Tue, 8 Dec 2020 16:25:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5838223A75 for ; Tue, 8 Dec 2020 16:25:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730343AbgLHQZe (ORCPT ); Tue, 8 Dec 2020 11:25:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729035AbgLHQZc (ORCPT ); Tue, 8 Dec 2020 11:25:32 -0500 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9BF8C0611CA for ; Tue, 8 Dec 2020 08:24:30 -0800 (PST) Received: by mail-qt1-x841.google.com with SMTP id y15so4739855qtv.5 for ; Tue, 08 Dec 2020 08:24:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=OnmUXMW6kDqwsfKiHlT00zEoGulW1fyuMJCTpZgbSj4=; b=0/+FZTjZq4HASyjUnCIDZ9bb3AA722ri3TowE+UrbuCfGKClmaxfrTVy0MutT+kJ98 +N2M27lj7g7gVdVcHQNFwT9WV7ZK4YInFdTUmvogKGKqJMMtgVMlnlrCZCVs9xi5HGcU 9FVOM2DYOaw/liwtMPoFm/YtmuWy3nHN/dlOdy2jXIX/+VRJtgZ0TEnpCdLOyG+MEgdP wJcnulJmQicOCSC7gxVeQREIcZDoslxX4skj15FkvUthS29CHqGFx/2NrRbt5i7Fmvkk ToIx6uKvbteV6I1tMIIGc0KlGfVBFrZKnaEXjMauvKFYMH5sBkafDAwHATyyk1colevA nMeg== 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=OnmUXMW6kDqwsfKiHlT00zEoGulW1fyuMJCTpZgbSj4=; b=VNi3xdoie33hqKitxCX5ooT3y8/H1JBGZu1XHDo2WVMOQxhtaR2z9M7CJl8tQYQe0c F3QwLCh39/zzLldxKGfdk88C612kxfd6cXWVH9SddR9AAibiS6v9Tx5S67IDELW80HvD q62GQ77XtFEbihwAxBlfsealNyrlcVOJ2P9bGo3TzjZfP0SE+iljuRSR6XfOjIR0bQyK y1JaWnAV2NNo6o9DZegB+Ej6GrO3+JiTB/YxtPZY8MiuzvLrpyiVsd7d4rtLQHQdLzq2 2mLqR3U6mOfxz4MHFk2muNTATm8s33OP2d6/au56HKzUREC+s4ZfO9YljvlId4qS+GY3 LHPg== X-Gm-Message-State: AOAM531Ek0hYhBlPNhYf6NrWoyTtyyRYVh9WHpieG37kXHPrUWfFWNr7 w+yVa8UCSJnx0VrkBcm+Wb2iN1t+2xtf/Ept X-Google-Smtp-Source: ABdhPJwHUBnvM9A1jz9RK1nUqKQagVL2jcOD2UjJHSvABXgu8DwSla8b1Yjood5ooDjXKBD6F4uJhQ== X-Received: by 2002:aed:2824:: with SMTP id r33mr17007688qtd.137.1607444669779; Tue, 08 Dec 2020 08:24:29 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id j13sm15819804qtc.81.2020.12.08.08.24.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:29 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 13/52] btrfs: handle errors from select_reloc_root() Date: Tue, 8 Dec 2020 11:23: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 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 4333ee329290..9a5293efe695 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2026,8 +2026,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 */ @@ -2198,7 +2204,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 Tue Dec 8 16:23:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958925 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.7 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 013ABC2BBCF for ; Tue, 8 Dec 2020 16:25:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C712C23A75 for ; Tue, 8 Dec 2020 16:25:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730358AbgLHQZi (ORCPT ); Tue, 8 Dec 2020 11:25:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730325AbgLHQZi (ORCPT ); Tue, 8 Dec 2020 11:25:38 -0500 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0638EC0611CC for ; Tue, 8 Dec 2020 08:24:33 -0800 (PST) Received: by mail-qk1-x744.google.com with SMTP id z11so7251118qkj.7 for ; Tue, 08 Dec 2020 08:24:32 -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=c/EeopVBpvJsFnN/RzjRSQSr/uhaS1KTGxGHh5R/LH0=; b=iN7vUMcIDtX75ymI2RE97HgJXfu9JalN70fcMa4oVqiOFcs+8smCYL44ea1V4XFyq2 akxS0bTxyFyRfIEW1mSgnvIU2v5eEloAOzu/1sju4nTK/ccZ3Vrx1GuMerQ8WKvoe4E8 Cr4g6tamtQ059dqdRxmj3VqxjoDUA8B/fSPjEaCWaRJ0/tr3k7qAbS7ShKUiTgdlkwvT SPJlI1VMS0IzQfOxD0FI6wWLraqNI0EhP7Jm/gpPNLl5yIAlB7VqaehvbAwt1vj/QoIC UT35AHFeh57yCWLGGvbvbrL4jSrY6xzRxQ0ale4NjLp4qXl/99LXg7deDK3rpgWU+Mys bqYg== 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=c/EeopVBpvJsFnN/RzjRSQSr/uhaS1KTGxGHh5R/LH0=; b=lvMzCJ3aQUE6HrtzjQ6dBngBq1z2ABaYSJg1UYof8Xoh6HHc5xgQ5X3J9NkRjMFHB6 0YnXlra2jBiGKzV87qy5kSp/mXhnujyklnrlqF6EYBlacKxxsEKTwBTdqvMMDnZy4OoV YY9DM//19DDmmX2b4/vLhI390KWpCDKxecX94m2/C57hceMSy1p9Xk0aVlnF8rnuQHtb O0ZU9fRQOdZy988yzBKtjUdwkNV1GUlzpuTK5rhHb2dwEIXaZZmIXwDQdGEAHEdI0MuE k12eMPGNsbbuomZpW55lCPq6dGDR1hLnpJrNRY621XBs00wYShztWvghTXcTxd2En8Pe 2OEw== X-Gm-Message-State: AOAM530NT6wy5agwrYI20MVCgCOJSBpTmA4bXa1J7ncztI2N1O5f4HkO cYSxp6wZamXp7TRVtHHlMjUW2ztYHPtg7jE1 X-Google-Smtp-Source: ABdhPJwgSOO7RZF6qUdnGrJA+6vbywBXeho73VhufbcfTV16UVCg3e/XJVU/57OAe+sLPY4QbTYzBw== X-Received: by 2002:a37:a80f:: with SMTP id r15mr9697948qke.84.1607444671859; Tue, 08 Dec 2020 08:24: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 x22sm13688500qts.53.2020.12.08.08.24.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:31 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 14/52] btrfs: convert BUG_ON()'s in select_reloc_root() to proper errors Date: Tue, 8 Dec 2020 11:23:21 -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 9a5293efe695..0d4c4e250a89 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1996,8 +1996,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); @@ -2008,8 +2033,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 Tue Dec 8 16:23:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958923 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,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 16BEBC2BBD4 for ; Tue, 8 Dec 2020 16:25:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E370323A6C for ; Tue, 8 Dec 2020 16:25:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730361AbgLHQZl (ORCPT ); Tue, 8 Dec 2020 11:25:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730193AbgLHQZk (ORCPT ); Tue, 8 Dec 2020 11:25:40 -0500 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 643C3C0611CD for ; Tue, 8 Dec 2020 08:24:36 -0800 (PST) Received: by mail-qk1-x744.google.com with SMTP id 1so16482375qka.0 for ; Tue, 08 Dec 2020 08:24: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=PNC/AlSaqkc4ae1+oHV65u8CN7lipZOahlMhp2uAjF4=; b=iPnsvjVMl6KCLApSn6mMTczOJB4Xb8or+R6hHyAkIuVJ9/IdfPDoBSHxKnwh6ZmFn2 o2dKnQTregLyRZ/ljwbQVOMEsgfzHL3A5C8y6DZ5luHqUGt884LSYfCvwY44E/3Xx7g4 M9fPZa7efbLyT0iP/W154f4MSWx/85+WRjFHZAkroZTN854CwZsus8HCewoIb5YTzNYj TjjYFh6z8aya8JS9itdb43dkIYzGnBN3O3+w6rQZUBa+4oXkChmEXTjeg6F8xsm6vRIc YKHFeTK5RtohGafTIvFuyx3Lbj3qXXpT99MmuMgXtF94nmn/Fl0rErt18E+xAiPnaxGH q8kw== 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=PNC/AlSaqkc4ae1+oHV65u8CN7lipZOahlMhp2uAjF4=; b=nUCCHnHa04MliNlZfh74MXYK1hPkLBLCxW6nW3tlBmuG8FoL1dT7MXf5XkmPR9rkNX 9bsdrZZk1DGdNYf+7Zmg1RWG5F9Ut5RZZBpuygyS23s5Ph5amU6ntMgOEDnlAV5HALPF HuxzZcVjZLiKbiDXJMwt/jfakWkdzj4Mvu1/lEPNA3tgKSpaLL55/BrdhdgVjZVazakX HP3xRTFkkUPPlpeI41AL7DdFaZTFhikh9oUScUt8CG1CuhDPem4GQCTsE5kLorkE0ZBD Ajtw1F42enlGQmvK+OJxbAY/9CTrxDrE5PV0XGndYqUj9WN1PLw+i+vDfufQ4TdBvXLI HkwA== X-Gm-Message-State: AOAM530Fr6fnMBciwXH7dfT8dFUmOO5b9bmhg/F2owIPmI+1hc/FhMuC kucROM0OpVnUWV77K2D3MVKBUtagRIN8zHYU X-Google-Smtp-Source: ABdhPJzt1CGlTXXiTsxP5jOzlP7ueuyBPykVDPZ2i+gX1q8kX2xAdc6KXDRf00kNOJg6m0hDwwUkwA== X-Received: by 2002:a37:490a:: with SMTP id w10mr23239511qka.487.1607444674925; Tue, 08 Dec 2020 08:24: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 f59sm14125114qtd.84.2020.12.08.08.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:34 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 15/52] btrfs: check record_root_in_trans related failures in select_reloc_root Date: Tue, 8 Dec 2020 11:23:22 -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 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 0d4c4e250a89..fd00517fb0f6 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1990,6 +1990,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) { @@ -2025,11 +2026,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 Tue Dec 8 16:23:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958969 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.7 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 38534C3527E for ; Tue, 8 Dec 2020 16:26:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1035623A6C for ; Tue, 8 Dec 2020 16:26:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730466AbgLHQ0M (ORCPT ); Tue, 8 Dec 2020 11:26:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730454AbgLHQ0L (ORCPT ); Tue, 8 Dec 2020 11:26:11 -0500 Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1356C0611CE for ; Tue, 8 Dec 2020 08:24:38 -0800 (PST) Received: by mail-qv1-xf43.google.com with SMTP id 4so8487979qvh.1 for ; Tue, 08 Dec 2020 08:24:38 -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=LVjoueG7DPYL2gpBJdejG2XQObibV0Zvbm2kyS3mBis=; b=rn+AwlSp5cc5or+oVoHAMRNyalegjcsro547y4UCfRE8DRuR9PAHNQXQkF4lhhRvf9 r88lyKTgzt6Oj+TgrS3gQ8dhUAKL9fKKIVDw/vnyQ8x1VUhRqxDI+lg/nZGg7D+DBfxi teOtiBvKEZODgAx1WwS5rOQTDiLj+V7O1zU/0RnJx4r5luAn/QlSGvbsTVVYec0/aFHv qKiW85coio85/7MbY6nLQvwnFn78lR6I7Q1CwTtTKQgerboWXYxGkXzoKbbVYYNgZR6j tT+Zl+inPs4wpWAq1RSO03/UNI7qyuhSz59daWdIEiR/O+yGCyRPo10GT/nmVIzd9xpy 8v1Q== 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=LVjoueG7DPYL2gpBJdejG2XQObibV0Zvbm2kyS3mBis=; b=eBkLev6hLV2cwHhiZBP0ejy/ynSX55mlcuB1CQtx8uF2Htn+ong1YzpSOpzgFBFHQi gBftOWM+SsLCxdTBE4v082XXf+/bnchun99wBmORhfwDVBcwYJMqW7kmSTpSBxzb3jsb xvONenr9Yz8HLxAPx6g9Fn4/iqH5qrsH1S4Xss2RiOuL/7KOV+gvJ3BQYn9Oq4VKbCoB AqF+4kbEdfI1DqY1Qoxean4rOL0GwZOSrPsxFApVSjDVW+a+5HOlovN42MnmCM2/fgka QIG6eaziqwpBeGimTfPSEeskwkk7j5i2ukqwtoP3Cc3taS4bGp7HAQYNaZCZ7DJjrKzW WP+w== X-Gm-Message-State: AOAM533kfsDig3C9BDswE3mg5FB9NxJvVFuIz7cU7jRusjOMo4/jbyq9 OFvXDz1PyEUYxcj7962hlPoUp2rh14iRLgUc X-Google-Smtp-Source: ABdhPJwoKkQfKn9xpzVtX8C/j8Ka+BMRDxZ0UOkU0kcKde9iQiDJOHXwJESKc2GNHPUDPBQr/DmpTg== X-Received: by 2002:a0c:f809:: with SMTP id r9mr27579127qvn.17.1607444677521; Tue, 08 Dec 2020 08:24: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 n95sm14764002qte.43.2020.12.08.08.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:36 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 16/52] btrfs: do proper error handling in record_reloc_root_in_trans Date: Tue, 8 Dec 2020 11:23:23 -0500 Message-Id: <276b6b304133163e72e11bf908fd5c5958316439.1607444471.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 fd00517fb0f6..bc676c11a2f4 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1973,8 +1973,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 Tue Dec 8 16:23:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958939 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.7 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 969B2C2BB48 for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7989E23A75 for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730396AbgLHQZt (ORCPT ); Tue, 8 Dec 2020 11:25:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730371AbgLHQZs (ORCPT ); Tue, 8 Dec 2020 11:25:48 -0500 Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97A4CC0611CF for ; Tue, 8 Dec 2020 08:24:41 -0800 (PST) Received: by mail-qv1-xf41.google.com with SMTP id l14so153435qvh.2 for ; Tue, 08 Dec 2020 08:24:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q72SsyFPmd92BdpyPLFGmykrVJ0f82G1Rus+LCwtD6s=; b=cOHCq7nNZ+jG1sc6O19ZY/3XEpUMfAFl17mOpr84Had+ziL891rfkqmzVCigDKwH/9 6ANWiss3tuFoapHp5wosM8vkXkaNMnirrPB8rkd5beuokwDWmqThdmkKtnykpQ3LYgTK r64++XI1kAJLCwvxlsaxm+yyiOpn8ubd3rIL+T6JPemCBfVd0s/GRfKF0PBPxoGfIFAk //teYu96T7NIDRMevEi+HtuUTT5hUNwCfd58LFEoNevrwo56/SZp6yzpvKIM/KYo+gyM y7BVPjm8mdFs5xYl95kmsGVYBdJRi0jD4lerYg/rV5Fk+Z0hExiZi5sUXCjyRFL2+46K ZiZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=q72SsyFPmd92BdpyPLFGmykrVJ0f82G1Rus+LCwtD6s=; b=BWh3nQujEWcdrOxMR61YOTMWdccjniz8yG6tkkXHB9Bn1P+ZvIJShA7SfYMysZGw0F /hmm5UHaYBiBXUXwOCB08S4Tv5xJQ/jVRMLdOshVNDiFwVVK+JUFT2dbMrRh0O7+DD9T w4lTF414DdN+SgpNTkqJ1XpG0OqjT4qIAHZmxx0dNKeRyvhIaNpulFD7bRv4fdd/Gtmd yfjEYDO/Q27aYdbzykZ2GWl16uvO02xg+vcKUMgem/V/aKb+k2JoPYkubWil+m0S2Ppb gJSPCio9Rzevt4B65MhAMc7nAL+j7QRNVC5rsIF5FrxmyQ3ug/tIEExQEliFj/e0VdzX pNyA== X-Gm-Message-State: AOAM533tOUZAJlH9SCpQyzAOm13QukMm64LHj3G5CPHY2wBkoetyzO2A 841u2zY/K4P+PzyQpExbI3XKUBAfGTXuCYE/ X-Google-Smtp-Source: ABdhPJx3SwpcrapTSm1J/Zth2ZbB0WnUV7Pfp0dwCInFs+Z3xZwmpz1+NCncKQkSM0t3nXE9LR/heg== X-Received: by 2002:a0c:916d:: with SMTP id q100mr28947821qvq.29.1607444680177; Tue, 08 Dec 2020 08:24: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 r127sm6109474qkf.75.2020.12.08.08.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:39 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 17/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename_exchange Date: Tue, 8 Dec 2020 11:23:24 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_record_root_in_trans will return errors in the future, so handle the error properly in btrfs_rename_exchange. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/inode.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 070716650df8..2f8bb8405ac6 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8897,8 +8897,11 @@ static int btrfs_rename_exchange(struct inode *old_dir, goto out_notrans; } - if (dest != root) - btrfs_record_root_in_trans(trans, dest); + if (dest != root) { + ret = btrfs_record_root_in_trans(trans, dest); + if (ret) + goto out_fail; + } /* * We need to find a free sequence number both in the source and From patchwork Tue Dec 8 16:23:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958947 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.7 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 A0306C3526B for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7807923A6C for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730446AbgLHQ0H (ORCPT ); Tue, 8 Dec 2020 11:26:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730427AbgLHQ0H (ORCPT ); Tue, 8 Dec 2020 11:26:07 -0500 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C898FC0611D0 for ; Tue, 8 Dec 2020 08:24:43 -0800 (PST) Received: by mail-qk1-x743.google.com with SMTP id z11so7251754qkj.7 for ; Tue, 08 Dec 2020 08:24: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=41DzNviF+cXvKLLpMN146LL13hp9ctwVOiWwtInzkqY=; b=1rRiP1y/QDNjajD6y0jp4HNnBEmYLfuV0j0ubNRj5S4fpJkO+a2Jai6s/xViZx8aRR KDBHaXnHSV7/oOiKZIu9dAAUGfm+R9R6Hk49iQa4gkr8gOLxm2/mND8WJtexKESKy6CV HfTUvkmU/s2zpaDw43bc84zf8Vgur4cHyvnoy9wPAfC6602BU9C4N/iARQrWN90VZaW/ we5H7SyERu8PmpB2aHWU7l3Hv0HLYP11rHkxAgNr+gQiwb1l/CuLlZUbP6TLXqXi82Vz 1K6Nsx8Jg5vWE800GMbB2pUObxTBylUr+CESMGth8bx5tIxD6xFf3nMDtgARFbdCMF7k ZLhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=41DzNviF+cXvKLLpMN146LL13hp9ctwVOiWwtInzkqY=; b=FQcm45E6Lsw45W5yIi6LvnM1JLsRcz5jzWgipJ81WjpVFc7dOBPcx67kz8eM8zcDW+ A0C2QN+jr6GKuQ8OIrRJqYjIwH7uguXZM19nwTAzilS3PWSU3qGl9cmiYCHqi0qhpQkB 6Lg2YuZ1UViCTCjB+3Cbfe4//GIW8aYcIPSSFNOGNoviKA/Q1dBLG0PslRpLszfkPSuO Pg+hoibQIIWo7mVxMW6KHzrAbzMZgXHqzhALALFYDQuUSjv4SyXWAl8RMB14ZsNakNM0 lYlztCGcMlrfvKMuOgm0nANTXbchu0dxI+k1gGDCE45V3nMVSbq/mKQBYlbuM+Jo+y7j rvWA== X-Gm-Message-State: AOAM531mRfRrHwlh6ecUPfGmo7t0E3daPubQpnNascZWLePEJc899mcg lNlYFbL9Je/CC1fwbP56RJO3cApwWLuEdJDO X-Google-Smtp-Source: ABdhPJzy6x/2wFwrkH2B2fU83+nOiDVMOTlGBZCeK2+kDzAJUM+8iGtkdT5++8RuxexrYtz2KTiIeQ== X-Received: by 2002:a37:e109:: with SMTP id c9mr8965109qkm.370.1607444682767; Tue, 08 Dec 2020 08:24: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 9sm13128075qty.30.2020.12.08.08.24.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:41 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 18/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename Date: Tue, 8 Dec 2020 11:23:25 -0500 Message-Id: <11b5534d1b697cd69bb322f8a7b863bbdcf9170c.1607444471.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_record_root_in_trans will return errors in the future, so handle the error properly in btrfs_rename. Signed-off-by: Josef Bacik --- fs/btrfs/inode.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 2f8bb8405ac6..bcbae8b460c0 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -9205,8 +9205,11 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, goto out_notrans; } - if (dest != root) - btrfs_record_root_in_trans(trans, dest); + if (dest != root) { + ret = btrfs_record_root_in_trans(trans, dest); + if (ret) + goto out_fail; + } ret = btrfs_set_inode_index(BTRFS_I(new_dir), &index); if (ret) From patchwork Tue Dec 8 16:23:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958929 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.7 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 3EFDFC433FE for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0262F23A6C for ; Tue, 8 Dec 2020 16:26:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730368AbgLHQZo (ORCPT ); Tue, 8 Dec 2020 11:25:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730193AbgLHQZo (ORCPT ); Tue, 8 Dec 2020 11:25:44 -0500 Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99547C0613D6 for ; Tue, 8 Dec 2020 08:24:45 -0800 (PST) Received: by mail-qv1-xf43.google.com with SMTP id u16so1996673qvl.7 for ; Tue, 08 Dec 2020 08:24: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=xGNUuifwBsvHD2zCYX/FZac+Jy1QnxNpjtDrlcuIIEE=; b=NDMofWSJ2Jdj9L5cslVnoc52HZRp2U+GtIO7wA45UEmqRi6c7T8IEOqEo7krhkn5kg infngxQCV8UKCecCCuWZ8ra/ZcgfhXCKxgq+2ie4AXSxQXSp4tL6nCqxD+icI9iYbxk+ m3xSWjfErdGF7htVsWtIO/yd57D4mPHL2Uf3sXR6NThz5tgqTJnOLHOaMon69g0+u4Zt 65GwkpmJ591GQAuDYCXjlz54serIjCMTrMKXZdqXFQ9aEYNNPd7izUTV01hJk4MSv3QY kvjXDq7T7/XwfXGYbjr17AMeRoBPjcflfsma/fqB2dwcOc8/j8vyczwb+7UsgY44j/8h ubKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xGNUuifwBsvHD2zCYX/FZac+Jy1QnxNpjtDrlcuIIEE=; b=MNZL4p1Y8Vdx34G/T4R0KQqe/6Pz8wCgbmnJkDcl8ZDuwmga9uG4j36RXo//j08zAG ixWDShKEp7bjMao6LciZziEH6KTTLv1GNzGkNPb+S0Sfa2fHEh95fV2aSyNhcd4cC1z5 swwYh4BPJcro+TfhFqRMmoc6+BgA3E8FrwJAaGC1b3fhyXX/67g6UVpMDkybPNhzrpJ8 NKjACtHdi67IWfeA0PivbuhN73dfVPCAlvgNdIZWeUfAFTS5/sFjCEKaT+uIzdEgKFBw cqRJMYtWW0Zdg/GrYpUe0PZbPTJBSS46s4k5v96ryy3diYuElai4Liu50t3Fz3F/1/2A aXrw== X-Gm-Message-State: AOAM530jgmhdGt1fptsjskCb5zgvMuEwB+8yrQPcfJ45TnrLnWv5qVrh FV+nCEtKCZEmmGQgFB+6rcCDIAZzrbiiapd8 X-Google-Smtp-Source: ABdhPJy2STwqNGo/i38Kc75GNH7J6cNdM8lWP1290wzy74dQq8gGaJ8qRqcZCGmOdrL7hnLHC/D5lg== X-Received: by 2002:a0c:8e42:: with SMTP id w2mr28433745qvb.4.1607444684560; Tue, 08 Dec 2020 08:24: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 l20sm4558631qkj.19.2020.12.08.08.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:43 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 19/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_delete_subvolume Date: Tue, 8 Dec 2020 11:23:26 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_record_root_in_trans will return errors in the future, so handle the error properly in btrfs_delete_subvolume. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/inode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index bcbae8b460c0..7a8d89e1b73f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4175,7 +4175,11 @@ int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry) goto out_end_trans; } - btrfs_record_root_in_trans(trans, dest); + ret = btrfs_record_root_in_trans(trans, dest); + if (ret) { + btrfs_abort_transaction(trans, ret); + goto out_end_trans; + } memset(&dest->root_item.drop_progress, 0, sizeof(dest->root_item.drop_progress)); From patchwork Tue Dec 8 16:23:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958953 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.7 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 D1B09C3526F for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF20B23A6C for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730452AbgLHQ0J (ORCPT ); Tue, 8 Dec 2020 11:26:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730427AbgLHQ0J (ORCPT ); Tue, 8 Dec 2020 11:26:09 -0500 Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CBDCC061793 for ; Tue, 8 Dec 2020 08:24:47 -0800 (PST) Received: by mail-qv1-xf41.google.com with SMTP id j13so1078443qvi.8 for ; Tue, 08 Dec 2020 08:24:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UP22N1wW4BouddiNGmO6P25lyeEkJRg0GBlKgir49N8=; b=oU73JLOoGsob5K1k3oBA67JNS+g+hU81cYLXZIW1JhVNr15fe51FuQymamEVN4mDEz thZiNMncfjR90/XXfp3SmibBpigIDMSkJTw64SUAT+s+JY09hUAB3b/rAxIJrudvTJWg OWedrp5gbVvfS7cXeG9eJt+EIPLW/0LXE/OFOw26fD1715tBooK04RhtUPLFMHiwyVHQ C0HMZJsJ7YIJ5AqQ9VYC9liA++fBIVyvXvJlP7uwHgbN5simMboeqTJ9SFm4Ip4A2VuC btJ+Ktb8AKv8mYJiWj3VMODtsmAUGsM0lDeYST4WnZugjdj3+gLnL5QsqISXCbKXVmyc TD7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UP22N1wW4BouddiNGmO6P25lyeEkJRg0GBlKgir49N8=; b=ozTRd2xInQ8+bqFNcGRlKN9eo78mbgFGH+UWOxv0sW7y4tS1W/jZYOiWwpr9CdBhu4 43+9x9Zpyxtpnt2qQJFBaXx5bO+JWPGg418zUxU6ihjogZ3dYsvx34SSa+j422kJe6Nx h1gHO43Sy906mQz6K9kFtQyZ45iR2a05vhnPMskFbr+UMsPTJizokNNdj4yUvD7lQUYA nGq5lIvH82LOcygU+pPnQnO9aNvCXTD9HOwpNO+f32S0KgmKXtUuipRMecq7CqisrFDm tLQYg/J+KCwDuhNgampqwXjLl1pISLB1FkKnFuzqrWdgaFaJN+qUj3bnVLcHQQI1eghY kcWw== X-Gm-Message-State: AOAM530NYxC/XZZ1EtcvKNzC8U2LS6IgF7/T9Lhmdg2zZwh8B6SpPkWI z12CsoXfG0F4vCbp9yXsL0RNg/kIj10FWnlT X-Google-Smtp-Source: ABdhPJxiv2jUuG03kvlDGBbT2SXew9879uIQsjG7ejJwAj9JPbD6QdKGl6SIk9SP+BaCoEhCxqLvmQ== X-Received: by 2002:a0c:b629:: with SMTP id f41mr11115153qve.58.1607444686570; Tue, 08 Dec 2020 08:24:46 -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 o13sm13585964qkm.78.2020.12.08.08.24.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:45 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 20/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_recover_log_trees Date: Tue, 8 Dec 2020 11:23:27 -0500 Message-Id: <3ec7f04c56621f60973bfd9293729b5748f003ea.1607444471.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_recover_log_trees. This appears tricky, however we have a reference count on the destination root, so if this fails we need to continue on in the loop to make sure the properly cleanup is done. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/tree-log.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 254c2ee43aae..77adeb3c988d 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -6286,8 +6286,12 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree) } wc.replay_dest->log_root = log; - btrfs_record_root_in_trans(trans, wc.replay_dest); - ret = walk_log_tree(trans, log, &wc); + ret = btrfs_record_root_in_trans(trans, wc.replay_dest); + if (ret) + btrfs_handle_fs_error(fs_info, ret, + "Couldn't record the root in the transaction."); + else + ret = walk_log_tree(trans, log, &wc); if (!ret && wc.stage == LOG_WALK_REPLAY_ALL) { ret = fixup_inode_link_counts(trans, wc.replay_dest, From patchwork Tue Dec 8 16:23:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958927 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.7 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 4C024C4361B for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 172C423A75 for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730375AbgLHQZp (ORCPT ); Tue, 8 Dec 2020 11:25:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730364AbgLHQZo (ORCPT ); Tue, 8 Dec 2020 11:25:44 -0500 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79519C061749 for ; Tue, 8 Dec 2020 08:24:49 -0800 (PST) Received: by mail-qk1-x744.google.com with SMTP id w79so5385458qkb.5 for ; Tue, 08 Dec 2020 08:24: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=rXkllivM/LlDIU6qMHpbw+hMYUQ5EKZq1LEuGXDx7tg=; b=k2mwtnk0YmfpvaLaaeSVY1GCyXk0xVSdHjbeKlnnWO2hy7ntfy9SnsFcYb1+ugigzI tQdOqf3xafjoEFtjC+ZksFtKGhTMxDiwqlWX77WwqFuPcTLFyAKm/VNGUTAEXvt0f+6r ZvoKC8tj+rptfPdSvapHG90N0+Y19QiqU/vH4uB5NHOnXxK7ZfZwfYVjn/LH6wcaTF8t xtof3IstJcAXxDnZCjXGFzWpF8iGQgeWLyBVN8p6Q/979jH7CR71h05crLMxDaD0VixB h1uxOuD++03FHUWPa00YGseCgIj0L0TTEcS3+rOrdfZce29WQw2AxBmPH/oCV+/3Gz6n njEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rXkllivM/LlDIU6qMHpbw+hMYUQ5EKZq1LEuGXDx7tg=; b=fSDc96X5kozb5N0jtv1W9gsL/CvrPowm5mfmeAjDV79jG8EhIBhk7N3TSUHIl/Gewz iOc256xKw23fIQvl6CRbHhXjN5tfCTQ75VZHg+vouzE+MBCAC36+KVKidqCBZwBga/pO DSuAQYlWMTw1USATDXMsswuBbnzl+w9/YlyJeCUTfnXLTrnjIRYGR8n4CpF8ZDuEhga8 f0MNsJ5K/EMX0Zej58y+tJ4IlMvnERzMrUgqu7Vbl+B1oPPXRCZJRWdzd2jVyf3TbmFx uLSTTzxeAXbXiEgEz5H1a5YgE52Z/oGsnfVKf1zORukERHEp0hJFgY1c/aiI7JeD+gin Mb3w== X-Gm-Message-State: AOAM533yDCtaapydeO9noNGaVNLkhlFhU5jbdGJMt+ZPQ6yelCYyMukd PglAqg4AgNCriR2mBa60nSkB6Qn299G/rrMB X-Google-Smtp-Source: ABdhPJzNpIezimQz4bYkMJp/6TWD0cl61thThW13NX/I98EkvESZXoovAqwqKMuvRtKpnHdEVoSvwA== X-Received: by 2002:a37:458:: with SMTP id 85mr22326373qke.61.1607444688439; Tue, 08 Dec 2020 08:24: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 n2sm2018054qkf.37.2020.12.08.08.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:47 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 21/52] btrfs: handle btrfs_record_root_in_trans failure in create_subvol Date: Tue, 8 Dec 2020 11:23:28 -0500 Message-Id: <84a86e27e5966f58688f05a277c412358e0b9d08.1607444471.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_record_root_in_trans will return errors in the future, so handle the error properly in create_subvol. Signed-off-by: Josef Bacik --- fs/btrfs/ioctl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index af8d01659562..2d0782f7e0e0 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -714,7 +714,12 @@ static noinline int create_subvol(struct inode *dir, /* Freeing will be done in btrfs_put_root() of new_root */ anon_dev = 0; - btrfs_record_root_in_trans(trans, new_root); + ret = btrfs_record_root_in_trans(trans, new_root); + if (ret) { + btrfs_put_root(new_root); + btrfs_abort_transaction(trans, ret); + goto fail; + } ret = btrfs_create_subvol_root(trans, new_root, root, new_dirid); if (!ret) { From patchwork Tue Dec 8 16:23:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958975 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.7 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 31C8DC433FE for ; Tue, 8 Dec 2020 16:26:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0DAF723A6C for ; Tue, 8 Dec 2020 16:26:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730476AbgLHQ0P (ORCPT ); Tue, 8 Dec 2020 11:26:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730231AbgLHQ0P (ORCPT ); Tue, 8 Dec 2020 11:26:15 -0500 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15A03C061794 for ; Tue, 8 Dec 2020 08:24:52 -0800 (PST) Received: by mail-qt1-x841.google.com with SMTP id l7so12283594qtp.8 for ; Tue, 08 Dec 2020 08:24: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=ctG5OJgA4JZGZ1K7sXn7NXcWoMXX6vMm3B7fMlYwpLE=; b=f47qdFYbjoavoN3uo4U7rCjy6NtukDlKy3eyqivPvsZTW/MGX5O8VWe/6bPn7VtXCU s6Sqghhehuo+F4Tvi7XA2cBqRf/EGBLoNzB4rrU/d+VZElHrbwz8IzPw2IdmwoSnf299 neCSYXf9vmrJTsQM3s8Yf4ejTFniv/HF9R03WpenqZNaTq+AVVcGqgW2+wXvRpG5UNF4 Q5oVaGz9wbYYzWzbgHaOibCHsWWL0V5KMsJj1K8pEEoIi+pFPEpQCEEauG0ln1U8SUsI xpISEvro2OVXYPMpaTl87JupMA/Xf4QnW2jfZ+AfsV5knp3YkGoWsJ3zVxh4WP6jVBMu fbXA== 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=ctG5OJgA4JZGZ1K7sXn7NXcWoMXX6vMm3B7fMlYwpLE=; b=k7lGIbJV0aaIoPDW7VhnKQjBZ8MR/yGohSxN706jFsfAhlcswuXQNp3zhGWld07Shy yF12v9wh2gSocVSXTwU8LJ5OaPQRvSlZf0vEv34vBKsGqVle8gVHIzjRL7woRhOJXcjU VLNTeDSyiBXauvSXeLi4GR2vnoTR+lBKoxa7JX8Jm05AzxXA1xCVMmzedgSpC61apQTm Yh45fz1LaHW6hxRITXilyYkWWsva9Au/pUdd/C3PlKWFQke8sobAOJsOlFbmzvuJH4G2 hoDYy/SV3PwemK5j6xCQhypsMUBD+P4tENIKJmbGlu63oyt7K4AsoIeyPlrx4KeOF9G0 50YQ== X-Gm-Message-State: AOAM530/CTgMMEURfAe3mhgqRaJXedPmScDJNqQT8kEsJX36UynOx8sr wHgkiDAwpNTXoc+ztuOzMHCLVQE5Y40RxbZ/ X-Google-Smtp-Source: ABdhPJzUa9da22i/IhgEPPLo+V54jSi2uDwoo0dEvxTnr/36BhuHStbj4v9WSmeQIzZlte6I4g31Ug== X-Received: by 2002:ac8:71c7:: with SMTP id i7mr22312066qtp.47.1607444691044; Tue, 08 Dec 2020 08:24: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 b197sm14627504qkg.65.2020.12.08.08.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:49 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 22/52] btrfs: btrfs: handle btrfs_record_root_in_trans failure in relocate_tree_block Date: Tue, 8 Dec 2020 11:23:29 -0500 Message-Id: <8f0e919db0d6d294e2385453e5a81ef18ea2e6f9.1607444471.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 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 bc676c11a2f4..a0453d67749a 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2550,7 +2550,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 Tue Dec 8 16:23:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958933 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.7 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 538D6C19437 for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D17123AFA for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730381AbgLHQZp (ORCPT ); Tue, 8 Dec 2020 11:25:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730371AbgLHQZp (ORCPT ); Tue, 8 Dec 2020 11:25:45 -0500 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46F89C06179C for ; Tue, 8 Dec 2020 08:24:54 -0800 (PST) Received: by mail-qt1-x843.google.com with SMTP id z3so12284334qtw.9 for ; Tue, 08 Dec 2020 08:24:54 -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=RU1H8MQ+4NOfYfTiKPHWw/9l/yKpcFXfnObQ5jomNVc=; b=fsY1JJw+3Y0QbN3Bp0UekzCaoulXnQ1bX7pd3FqguTL2hZOD9jFsZ9TUDLPp1zqm8y mTtZnHT1l+ZRkB0iv3wNyWQb3zpPETNl1gfJNkMzccNb4/PhJ8LzmP0E0cAJgfHs01Td etHeroSLbC1N7b81EQoDuhHNk405G0K0Hw11q2SHq+eI5SoVajNBM4WMYARM7QVIZlH4 PatgLGnlm1s2HukjGL5imzr2Qwpu9O/EsDpDRodt449fBo5yeRCWgv/QnQtKzIisW2KS n8cAPg0flgCcPWOSBCLS6dB/990MvqUdYPuiy2l+wrkLJpsAywRKItLHiB61a7KDtzuQ b6bQ== 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=RU1H8MQ+4NOfYfTiKPHWw/9l/yKpcFXfnObQ5jomNVc=; b=TiNuvY3LIK49j84fAPyd5FfTRbLfsNaQor6z+fLRx6pPG7bMqanlFywSXGA6TxY7f2 /dH+BwirAOlhSBe6YoE0LB7Sv8KJS+jhCC8IYj0oF6VEYuMqMQeRXIZtZqy0waJHaywH 2Wl+9yVaudviCCOgJfuhkMSMnH9SQjSbE8WwF51J/eEM+sqlnXZM2uyw3KY7d6xawPxs eB9nkIggswB0EWKoGOhvhGlCqugIiE+J/HF/5891Mw8sG7WvzSOXBMEXGS1ks+UOD+in ST/e/hns6HSOgCT8QFSPR4u61cqKcKHGyNcb+Nt97uuJzt0gG+snypyqi7fj8fFljJXj nVIg== X-Gm-Message-State: AOAM530s1GC1YzHh9R5DcafX3aQeG4BqJHTNw5aRCjljmMSgUuujAzBJ IMg/F5GdeIN5UJOb09uC6KCYLPKNOzHUpZM4 X-Google-Smtp-Source: ABdhPJxz4lf6CaXy1EgcJ4dpMJOWSDXyBq6vmPdYZxBNmMgWBIjdZVVQ4zQKQoGt2n4s452QDmLCIg== X-Received: by 2002:ac8:6651:: with SMTP id j17mr31110744qtp.176.1607444693224; Tue, 08 Dec 2020 08:24: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 70sm4013173qkk.10.2020.12.08.08.24.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:52 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 23/52] btrfs: handle btrfs_record_root_in_trans failure in start_transaction Date: Tue, 8 Dec 2020 11:23:30 -0500 Message-Id: <90766a86c5e5ac96c9494d2f3e8a149fd4719dc4.1607444471.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 5cc368fede19..df9b9c1a8831 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -734,7 +734,11 @@ start_transaction(struct btrfs_root *root, unsigned int num_items, * Thus it need to be called after current->journal_info initialized, * or we can deadlock. */ - btrfs_record_root_in_trans(h, root); + ret = btrfs_record_root_in_trans(h, root); + if (ret) { + btrfs_end_transaction(h); + return ERR_PTR(ret); + } return h; From patchwork Tue Dec 8 16:23:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958959 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.7 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 26BBEC35270 for ; Tue, 8 Dec 2020 16:26:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F00A223A75 for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730463AbgLHQ0L (ORCPT ); Tue, 8 Dec 2020 11:26:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730427AbgLHQ0K (ORCPT ); Tue, 8 Dec 2020 11:26:10 -0500 Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 137C7C0611E4 for ; Tue, 8 Dec 2020 08:24:56 -0800 (PST) Received: by mail-qv1-xf43.google.com with SMTP id a13so3377246qvv.0 for ; Tue, 08 Dec 2020 08:24: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=xNOx2Jjr74+wLTtBDiv3gKClZYDo3iFpbDcFDbIYh4s=; b=tUgOkhPBiafqIbSdFBgsCZrw3Id4LIO30SBXoO8cKKTB2060mpKK//ndumc1yPrnrX Bmto8p0QZYHZ6l4zkBNp0ftFAdwKFt4/9OhfWleAROhJJrENCq5lIGx1L0nNQ1keXvJ+ 4lSdhK+5EnKKux1dkuJ9xHYXm53px5IxufYjMbfU5dEJk3co4lBL87OjLLTRv5bl/c7k SP6PNh8jery1xtH2nyaipWItRAOrjb5UmcYDGRdF/pcw+637lFDSkAQW03uGrZQdqoQM 4p1Y30G4S+PA94iJ2BElpHzzY23PL5fBvUtMyqjfXGFq3uZ4YqzrTky4qs4MoTZbhVHJ X+Xw== 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=xNOx2Jjr74+wLTtBDiv3gKClZYDo3iFpbDcFDbIYh4s=; b=jaK22tyfMQbwiVL9Q38jnM2FhRZaJUTjTU/hskjNOVNmgM8sYQWdYlPZlcZXWt5ApD /ckKh4BD/KyR5gRCS1kKfzlaqjByUrpnVxga2YdENIgLlJLAfsPHfme+5MezK3CPCjkm bBLBXu8RX8y8W2iMcv17/8LOWEItBYz1JUvFsTBjBFSF4h1nK9UOx45pLmMVssL6Bek+ 4F+bF4fkfxKCm/3GtQo431oOr6XvTVggYwwbcB0VULYkeaqOl6uqyJ4UmoRjJtGZKFLt Qk6dGrl9+MG4vERvylgF8MwW005bvrAvpmQmZn9IC+tTGZv16rKD4KtoTr2qck3k/dVE 3bZA== X-Gm-Message-State: AOAM530e+Ya/77ewRcHTMxSbDxqz3vt8slpxfYC9W1jHlChwNvQMmmA4 ikKb6RlhQ2saJEQjBxBi4FqtnGODYjfHKvf1 X-Google-Smtp-Source: ABdhPJwmMvTDnUN8k+J+B6e8S5Da5J6ZxhHr5Mm/uJA1E+8ByhinlowWeqHCUtyEpKip4usfkcLPUA== X-Received: by 2002:ad4:4426:: with SMTP id e6mr16967455qvt.51.1607444695028; Tue, 08 Dec 2020 08:24:55 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id p24sm6421860qkh.73.2020.12.08.08.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:54 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 24/52] btrfs: handle record_root_in_trans failure in qgroup_account_snapshot Date: Tue, 8 Dec 2020 11:23: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 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 df9b9c1a8831..77feead2a324 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1435,7 +1435,9 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, * recorded root will never be updated again, causing an outdated root * item. */ - record_root_in_trans(trans, src, 1); + ret = record_root_in_trans(trans, src, 1); + if (ret) + return ret; /* * We are going to commit transaction, see btrfs_commit_transaction() @@ -1487,7 +1489,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 Tue Dec 8 16:23:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958943 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,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 CB92BC1B0D8 for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A31EA23AFA for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730405AbgLHQZv (ORCPT ); Tue, 8 Dec 2020 11:25:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730391AbgLHQZv (ORCPT ); Tue, 8 Dec 2020 11:25:51 -0500 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4DA0C0619D2 for ; Tue, 8 Dec 2020 08:24:58 -0800 (PST) Received: by mail-qv1-xf44.google.com with SMTP id p12so8448058qvj.13 for ; Tue, 08 Dec 2020 08:24:58 -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=spjabu9k22U8QvInYIw0gNrlCBCJU+aYdbwhJP3xbSw=; b=jBtW0t8fpavFo/tY92kocFln6D7zI/NPcsdeKicUBllcWn25ulXy7znOZVN4ohbwrG caIjvZn5gcAyJ8zoc26TQ8TMX4CBrw7KvvwOVYrgk9THTLVyAqCp1geTEfd0cZrSwcsf 5zanYEmWYroCh48W8tLDgBrxCvmJ6O/TcKBLI0xUAbroVldqVAyfNcUJu3MybrFWXIyl 2L6gwI8qaHMQdg+56rhvfQoAviVUjyqGirrVQQQbZ5vfvVQ9Dv8VgRaZMsk0/minjq8O uuwoIJBlgWCHvrwuLjh55jkV3IcBUmmQ54zaHdD/83huV9MSh66UsnUEC0qsnn3LxR8s Nd+A== 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=spjabu9k22U8QvInYIw0gNrlCBCJU+aYdbwhJP3xbSw=; b=D+mILL7WK2pp1HpARpGVX7qOF+6Zg1VSglMxZPXKs32XrnIgMDk4S0s68fmXPuKUL7 5HxYVGsng2VTLIkXcionqDTnfz+FIGp8R1/KZA3bZT+WENLbTOOMSe6Hb0hJLrvpXe9Y 9xN+3RVmPa2jfPjvY/sCrrUmQb2i8dckPyF2rjp1EHVr5OrZp0yhCwvMZiZDu/pQ7Gbz xHvu4MH5N+u3E5maWj4L3AlRwYto91OLTxENUCyuob2yB4aCB0VlePCpso9mt5lR+Nc9 Zhlu+OlHwQlV78HeZR20uSSOKq1lpjNvSu1FRySK0ej1wtXOPjr7tEmASN1xgY2EOeFq 7CZA== X-Gm-Message-State: AOAM531lX52ojArTLDHWKwKJXDbEx05itfjszjcuGwmq/ze8Oo6rMwTO PZPjFO2Qe0Yxt7YxWMijQ0YMZkcHZ3EJByye X-Google-Smtp-Source: ABdhPJw0b20XGhN5xP87EvrBNHhAtsKH9gvySLgG1C5f3FOnwH2vzjoE7Wd1MpWjL9p9rco28ztIrg== X-Received: by 2002:a0c:c30d:: with SMTP id f13mr28343072qvi.29.1607444697208; Tue, 08 Dec 2020 08:24: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 j17sm13801881qtn.2.2020.12.08.08.24.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:56 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 25/52] btrfs: handle record_root_in_trans failure in btrfs_record_root_in_trans Date: Tue, 8 Dec 2020 11:23:32 -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, 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 77feead2a324..7404d88e6201 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -480,6 +480,7 @@ int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, struct btrfs_root *root) { struct btrfs_fs_info *fs_info = root->fs_info; + int ret; if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) return 0; @@ -494,10 +495,10 @@ int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, return 0; mutex_lock(&fs_info->reloc_mutex); - record_root_in_trans(trans, root, 0); + ret = record_root_in_trans(trans, root, 0); mutex_unlock(&fs_info->reloc_mutex); - return 0; + return ret; } static inline int is_transaction_blocked(struct btrfs_transaction *trans) From patchwork Tue Dec 8 16:23:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958961 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.7 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 DD790C3526E for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4E6A23AFA for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730458AbgLHQ0K (ORCPT ); Tue, 8 Dec 2020 11:26:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730454AbgLHQ0K (ORCPT ); Tue, 8 Dec 2020 11:26:10 -0500 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 157BDC0619D4 for ; Tue, 8 Dec 2020 08:25:01 -0800 (PST) Received: by mail-qv1-xf44.google.com with SMTP id n9so8480343qvp.5 for ; Tue, 08 Dec 2020 08:25: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=CFQS5oJ0NcfqH76o4PTWikteEs7+zX/hm+AegtBD5x0=; b=IzN2euUfLfrW+IWsMBY+nKe1fCaVFXAO1AbhEu9kqpvALQpyhbOW3jObJi4tQhrIRU 70Vs/rvvSyJpu5XxSSPq/WcLwjng5iM2N8XKvLAmjtNlaGkHBW5OLLGfdcYL+VNeYORQ Qh+IIGpATZu4ASDR4sopp1X+mQQ0eXgZwvYfBTOhxbUpAmNc1QOlUvTf89MjkcJ+UefE QZbwcqozHdyY2QHnv9SB4WGrLrgfZBX6NOOM9oYs6SjRyHwZdLnuFEmJMoCeuQytEKxW Mv0avrL92Am2w4pQG9r4xsYXPGuZ0T1OOUVLTVIn4SUxS4+lY/l8QHLhbSqObaYvV/k7 egZQ== 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=CFQS5oJ0NcfqH76o4PTWikteEs7+zX/hm+AegtBD5x0=; b=Cm16LOFH6+v8277ygKMxABC61YuQDWLFduvWv2MWDQYwvI4PXK+9XT/vXB9/fizWGd f4DYlYvmDi1MOXkGhBqd0eNZg2DCtCmKwMrZdFEYT59lJQTYgYzdLRPdiIQ0vUutMR6Y tvMHitCa/dTyo6RdMjxviS34iDmk15co8yyXfIGKupk9VxjTi7uAv3tNYP5pcI9DBa86 s4qboMhf4o+rDrvlK8w5ce838qqbglDjGANYqtAeXYV6VMEbGF4e5KexvL46DnNhIkb6 XCcGts/HuiCaffu7kAaIL4fbhfKgkVS1CT5X0e8AeGHvsLdPCExDY9puUo3shf5SiO1K SzIA== X-Gm-Message-State: AOAM532jrJUcVfbFWnVQeolou/FwbPQxLADUhHYTsJVyLmJyW3QvojBi iY1l9RcInawvPMCBTtWRXCw2jD3WixQZMDIM X-Google-Smtp-Source: ABdhPJxE5o2UWtIzce9Sj91R/F0qr3iU8ZnZHCcbJU4d+/dyKIhHFTW8ZbJoUXPUSXx13dPCOHyIYQ== X-Received: by 2002:a0c:a181:: with SMTP id e1mr27949454qva.53.1607444699774; Tue, 08 Dec 2020 08:24: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 c2sm9218096qke.109.2020.12.08.08.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:24:59 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 26/52] btrfs: handle record_root_in_trans failure in create_pending_snapshot Date: Tue, 8 Dec 2020 11:23:33 -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 7404d88e6201..375aa2bed36d 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1567,8 +1567,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); /* @@ -1604,7 +1605,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 Tue Dec 8 16:23:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958935 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.7 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 77F89C4167B for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4435023B00 for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730385AbgLHQZq (ORCPT ); Tue, 8 Dec 2020 11:25:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730371AbgLHQZq (ORCPT ); Tue, 8 Dec 2020 11:25:46 -0500 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD399C0619D5 for ; Tue, 8 Dec 2020 08:25:02 -0800 (PST) Received: by mail-qt1-x843.google.com with SMTP id u21so12273494qtw.11 for ; Tue, 08 Dec 2020 08:25:02 -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=yH1zhl8oIh4YApB9HRlV1LmZwfiJDb6Ea6cl0tkUsaU=; b=YSo/93yGGQNYDYE2Dm0L+KLu+85My0sEOBsIqKcdG/DQXkBbrUjyy6nQIWjBd31Sri 5A6X5mt6RBqjjrhEqKfTYx3l7Y4lPHWINDFXYNvfRtPS5i2srz6OJ/yuqIvqbr4nb1Vu nBRCE+o9rQkONzJEChMiCOmPFpyHxTu/SMeOs5j7iKGmI6+sg4JQAXEdEJmaJ3jtPIXh LA7oN7QF4T8lhU+Ni+YuT3BJBKk7awQTIb5UGkniFK93hjCQS2EEyKvjaESq924eCMn+ WpZRe30ok2xN0jI4ljRpKnI9Fn9ujVTHV1+OEiAIqaj10Ons0D5vwQKagD1npfbR7t9G aaTA== 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=yH1zhl8oIh4YApB9HRlV1LmZwfiJDb6Ea6cl0tkUsaU=; b=GYsHz/i5Ic6wCmSU91ATHI2oyTZ6AK5ZkyJpBa9mYNYCFmoyrk34F42kaUp+ALWYrG 9ZfKxNU+uYgKawgLCnTt8ZEIJiunvw/2bwC7ebT+p1EKW0v4i3g1Eia1b4vqsPNcr8Lp fvbSg6/Ir+hmjnNjPYMfakBKXRSEVjMYR2AVVupU/nT6FG1BKMKkxoYhuQl8juK6ubSL XiEx+Q+J3eHF4n7Ak45spEc38s7DOcGprqvi9Y/XpW/Iky55OnTHF5TJUT3aWY7PeOUs j8dNGX4HbmnlkweFW7lpSTlQ9N1XMH0LrIq7HSBA7kjaelHZpsNbDsko5jTp1IFuy0FS TUXA== X-Gm-Message-State: AOAM532QkuS7KXMD4+jo3k3NuWJo6Kb9VFs0Bm72ToJeBDgi4creicwr gnAMRDd7dgGWsFGMy7+IwZcb4MVa9vLq9kpM X-Google-Smtp-Source: ABdhPJzUR+RS7eoqYir103kQ5Gqw+fYVpivoNY4s3GJo4RSU0L2br0nJqz2XtkndLtd1KT0bI1mUGg== X-Received: by 2002:ac8:7754:: with SMTP id g20mr11854231qtu.27.1607444701648; Tue, 08 Dec 2020 08:25:01 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id v204sm14946999qka.4.2020.12.08.08.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:01 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 27/52] btrfs: do not panic in __add_reloc_root Date: Tue, 8 Dec 2020 11:23:34 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If we have a duplicate entry for a reloc root then we could have fs corruption that resulted in a double allocation. This shouldn't happen generally so leave an ASSERT() for this case, but return an error instead of panicing in the normal user case. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index a0453d67749a..36323cd08bc8 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -638,9 +638,11 @@ static int __must_check __add_reloc_root(struct btrfs_root *root) node->bytenr, &node->rb_node); spin_unlock(&rc->reloc_root_tree.lock); if (rb_node) { - btrfs_panic(fs_info, -EEXIST, + ASSERT(0); + btrfs_err(fs_info, "Duplicate root found for start=%llu while inserting into relocation tree", node->bytenr); + return -EEXIST; } list_add_tail(&root->root_list, &rc->reloc_roots); From patchwork Tue Dec 8 16:23:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958979 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,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 C02D5C4167B for ; Tue, 8 Dec 2020 16:26:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 921BB23AFA for ; Tue, 8 Dec 2020 16:26:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730479AbgLHQ0R (ORCPT ); Tue, 8 Dec 2020 11:26:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730477AbgLHQ0R (ORCPT ); Tue, 8 Dec 2020 11:26:17 -0500 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB656C0619D6 for ; Tue, 8 Dec 2020 08:25:04 -0800 (PST) Received: by mail-qk1-x741.google.com with SMTP id w79so5386328qkb.5 for ; Tue, 08 Dec 2020 08:25:04 -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=/nQwiagWOgqRM+nMIeb0R2gQ6YgS/wzwB6kYT/kd+8w=; b=wf/hMBxTD5xN6Fa+U/808xpqR09TcSyoCcMmFyf7Q/d+K2UAK+9/BgKyUkW044odJE GVsAxlrUcjcsI3CN4zsonvS0L3aWkZGEUtnX2/EP+bZnrUb0NA47wm7XbLTZtW3Z4J7p AXYyhyfJNV2j/9pctUQdychZk45TBuT5BS/intLPwt/8S7H1/1pu7H2df3C8TmmcRFyq m4bHEOgjH4Y3uumJrhPjlVL0UemCfzU6rlE6nzwhY/01nrAT7ygt+pWVGj3m14w9Mxfk BxHxxXjJI4uuj33ZkaIVSyxfPoQ7xAQ3h36qJQl9+5I8Cb8RKIbvJDEb0g7l4Nc99nIZ 3WZA== 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=/nQwiagWOgqRM+nMIeb0R2gQ6YgS/wzwB6kYT/kd+8w=; b=AWgGiugKR8En6ubmBvybF+flm7pzKGw2betTIZUedqsjdxHRDj1DBZiIASOAYmmx6P XCFRIACeA0k81SyEovxgfHOh+c7+Z3S6KMx5ZShmjHn4KYYftVBTRsZsWnxlRWk0gFmi E2LDHvVFlugmfnhwbGOyTINso/jfzY2TaDwSf3FSw3Ribp4QEYhee+fwscWKL3sNmZCD Wi9VEw4r3Y4gNkEbZ2qUQVqV5WaxoAbWU8lA7mW8qlBv9XDc6ScX/Ap5+E3AMRYfZJYO KV04+IeeFk2TclERxg9dTqriDnKZzkbU0Tbn3MyIn7gEFn0Y2HJjGw0LGrIf/P+e+EGz 3ZzQ== X-Gm-Message-State: AOAM532W7nNJjWvC3v5CULi0D9yoFaXXs/qL3uq9156kfha7D6kJdHbT 0Pt5CSd72PQLNmKreQ1D7dMujP9p+GbWBdUE X-Google-Smtp-Source: ABdhPJw+IP3JOqz83gJUT5wx0WW4yPWztd9kcMj1BTZqy8YLJmFU3np70Hn7eUqpxNMvLZctS90eKQ== X-Received: by 2002:a05:620a:95d:: with SMTP id w29mr30541867qkw.147.1607444703637; Tue, 08 Dec 2020 08:25:03 -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 y15sm4718800qto.51.2020.12.08.08.25.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:02 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 28/52] btrfs: have proper error handling in btrfs_init_reloc_root Date: Tue, 8 Dec 2020 11:23:35 -0500 Message-Id: <179c8306435d684a075019ef359f4727679ef018.1607444471.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 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 36323cd08bc8..692a24ec7d83 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -860,9 +860,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 Tue Dec 8 16:23:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958931 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.7 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 8577DC2BB40 for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A73B23A6C for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730390AbgLHQZs (ORCPT ); Tue, 8 Dec 2020 11:25:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730371AbgLHQZr (ORCPT ); Tue, 8 Dec 2020 11:25:47 -0500 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DC84C0619D7 for ; Tue, 8 Dec 2020 08:25:08 -0800 (PST) Received: by mail-qk1-x741.google.com with SMTP id q5so16404395qkc.12 for ; Tue, 08 Dec 2020 08:25: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=LpWi/X+1K+7odj8BZYJv8IiBknPW3ri/S4w43bwDSwg=; b=QHuTOrW/sQafGO8NLTJtqLwz+QgnN2Bq7psiLHnCz2npaMJ+NzxbcLzDK6zoDvZApi 2bFrxyxylIPN0/QS+G9lYtntM8gjA3qLh08/hklum4C+Q5m5P+mX95dfFv5kixEhMrFp VU7INd4tpbLjTmwEWZENNnvWn9Wm95DWZY1v593b3lkX5vHOMZwd+M33flCeiNimVhiY xJBpvKUPkLoxy93mWh8ZiXnRgSYkKJ0BZ5qdV/dLDyEYu8LugsZHJUmM1MOE6WWTcUjZ mQ4JuA8ZhEifaJ3SOg3/BTCMTE5o3lKLJEq+aBhEGKKYf4jgEtez/B1UDV4qhgU6pQ4h amWA== 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=LpWi/X+1K+7odj8BZYJv8IiBknPW3ri/S4w43bwDSwg=; b=Q0Sa5Qj9D4EMP0nt4ss+IhDN+/wbAiTCun9v5Xej5tzpVA+xMiGyCsrfB4stVU103/ 6J6fWNmqISiH1jKIji3S6Dh59lPv5AM/jlLBXDSFaPHtsQwNN1IiEwOQBB7/61mjz3HK J3XQU3z1kcyYphgpkjXL84b0CFhLjfdjwfzKDxiFXUvrtZH1kbtq1zob959ZK+lz4P3r +qWOiFHPSTz1BMhO//C1jVfQzSbLTg6GDaS8zh1XXRtEXk8ew1E37cH5EFiJHG5r4Yq2 AxiHn4Puqk/3exXTPohCwbklEv1XQEDPto4aa65+oli8As7+Ix8td14tUV/K1VMfAcwL +dWA== X-Gm-Message-State: AOAM531bK+YbdfooM6v7IkBQ0e+SZNY1LUu5oDMc4myM1ErJHh4BSC0W +w9yjPksSn5wjIQ3/COXGeFoySVxlGNYdIJB X-Google-Smtp-Source: ABdhPJz529IMexSG4s9vXIEghfIP+BTyovyNw40ktVnwhhkgpyrvH/dt5h2wRtg1GNYzygX1DB8dcw== X-Received: by 2002:a05:620a:4113:: with SMTP id j19mr31361359qko.301.1607444705460; Tue, 08 Dec 2020 08:25: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 i11sm13934292qkg.45.2020.12.08.08.25.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:04 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 29/52] btrfs: do proper error handling in create_reloc_root Date: Tue, 8 Dec 2020 11:23:36 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We do memory allocations here, read blocks from disk, all sorts of operations that could easily fail at any given point. Instead of panicing the box, simply return the error back up the chain, all callers at this point have proper error handling. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 692a24ec7d83..b7a8a5b44a16 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -737,10 +737,11 @@ 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; 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; @@ -752,7 +753,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 @@ -773,7 +776,8 @@ 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; } memcpy(root_item, &root->root_item, sizeof(*root_item)); @@ -793,14 +797,20 @@ 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)) + return reloc_root; set_bit(BTRFS_ROOT_SHAREABLE, &reloc_root->state); reloc_root->last_trans = trans->transid; return reloc_root; +fail: + kfree(root_item); + return ERR_PTR(ret); } /* From patchwork Tue Dec 8 16:23:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958965 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.7 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 54932C3527A for ; Tue, 8 Dec 2020 16:26:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3ADF023A75 for ; Tue, 8 Dec 2020 16:26:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730469AbgLHQ0N (ORCPT ); Tue, 8 Dec 2020 11:26:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730231AbgLHQ0M (ORCPT ); Tue, 8 Dec 2020 11:26:12 -0500 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA2FCC0619D8 for ; Tue, 8 Dec 2020 08:25:08 -0800 (PST) Received: by mail-qt1-x843.google.com with SMTP id b9so12314412qtr.2 for ; Tue, 08 Dec 2020 08:25: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=KAQN+81eOnjviSSky8UvHmPeO2GHWKjMNJPnZAMOWAA=; b=rMvB4g6f7xYo968A32MVLe59h4S/yD6jDkf9v/RRIs+fFX+Xm7rnciZSWly6u8QMYy lB+ylG4cNIC0npVURDE/BfqXelraKd9dCAoLXdqDWY2kp2Iw5HG0BOrWgjEKz8kTBs2n KE3CS5ITISFTbfLmQIXPig5jw4koWbwIBsLEFR5NPNe3VrTqtBk3c8l1RkKDDifYn4VT UQ3ywOjtolTUdR7cZxbwOsH8/6ZZ2qCUvKH3YKgLoaRBRSAaBiYeEEsQQ0dgNc4wmyCt sA1/6+O7SBazQE2uhqOW/lbr1Iy0Qqoy5y5VkUc0ql9rf1Jtm8ey57a7dcuq8/J2BmZ9 Sspw== 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=KAQN+81eOnjviSSky8UvHmPeO2GHWKjMNJPnZAMOWAA=; b=VRcU5t4SgTc8gYNr6Y7hZuoR9y9zI2jEnOhbnOzoHDX28YD7pOTz8xSf967P5nB72S 0tmF4VQIYhppieJio+sr9ZGwJLiKgkuV0CmYXWILWHEaCnZ9FKsSKpNKZ/J+7rwRLWjT nR2+/9t987U3+tjwBSL2x0oJhnaYqx16mzrK7CGClLA3i/zLNhEnyP6MP38Its0qgbve Ezvzn6k02LPd2QPuZYyp5+FuYsK8gYKV/21PH5xi5R7TJlfkmmaz3AKvLDy/mydI9p5f Xf6qwCI4d4AhWY61xyD8WR3Ut6uPp+YpLUgJL/9SIM2LCPbocglXFU5NaCp8dVyn7ec3 3uWg== X-Gm-Message-State: AOAM5306QlPfJ5ml8Su+I9PlOeFovH/PecE+rlYRgUx2GwixB4kxjaYj yUO+zGGPzGuyAug7ozwqRug1i7V54NVWN0tb X-Google-Smtp-Source: ABdhPJxVyq057Vjl/9aOCxPSDgp1qw9WO+/6Ghkw0yORb6iSWJIWnk4yk3VsK4sfxtYBaoyd/lrDVQ== X-Received: by 2002:ac8:7083:: with SMTP id y3mr30338184qto.267.1607444707629; Tue, 08 Dec 2020 08:25: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 k128sm14811252qkd.48.2020.12.08.08.25.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:06 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Zygo Blaxell Subject: [PATCH v6 30/52] btrfs: validate ->reloc_root after recording root in trans Date: Tue, 8 Dec 2020 11:23:37 -0500 Message-Id: <35218dbcddd916f169601b25ba62ce2879956d90.1607444471.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 b7a8a5b44a16..ac5350dfb33a 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2073,6 +2073,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 @@ -2570,6 +2577,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 Tue Dec 8 16:23:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958937 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,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 B7885C2BB9A for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8ECC523A6C for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730402AbgLHQZu (ORCPT ); Tue, 8 Dec 2020 11:25:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730391AbgLHQZt (ORCPT ); Tue, 8 Dec 2020 11:25:49 -0500 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEAC4C0619D9 for ; Tue, 8 Dec 2020 08:25:10 -0800 (PST) Received: by mail-qk1-x742.google.com with SMTP id b144so16362702qkc.13 for ; Tue, 08 Dec 2020 08:25: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=lFR7IwzsHyxbv/o7Xs8uDIZ/0NitB4dQ6UU0EzUVYVc=; b=MCoTk0lUO5a5aUO/uD+6QKg1OSTs5CFamVrUx2/I/wEEq3hGMkV/OEhf1c9tDFRfTV M1ngKSmuOqHFt5VBpYMJzuNwuoU1SiY+eVvblHiEAbkLM5bOToWFAmCG6iBosF+qyeMM wRMaDiNcgqt7EA6CZVOpzxfiMJffHmLOVIcvcDnpRRjzRwUBsZ5DsTK6ImnnO8/cZiUp 9aLSqP3BhsNGzvw95zJEOnHgAxe3RImS1tgQzlKPrjMx0sE/kF3KmBzkF/18cM+g7XKr eb109gBBs2/uPXQGj9F8xuaz7FfPs98JVa2Fb3oGU1QZQa03LfPgyMngPpO/jRJ/xxgK A5iA== 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=lFR7IwzsHyxbv/o7Xs8uDIZ/0NitB4dQ6UU0EzUVYVc=; b=Qzk/L+hOEPcgMlPiGmQR5YpHLE6Sr1KkPr+OdobEsPUiTHEpcJ5hNXkj7Y28UnZIea xTLTOKnpm+MfsfFglD/tZmav4RVsBqB1eWAj3jZELTrFHftKIbzUmDvxMui5x2EeGKgp roM2j5H15KbCsDGKbYGJdyCfI4UKB0ABVFOMsgk/mFJ7sshJK4gBRlZJFumjZuolytNL F7v024eTPM4JMm71t/ToPW8KlOKW05CuNVQvI3b8xGokPT3f8bg6YBLFcQmUWIN1SGhO fAOMx/usgnKiFCBn/uGC4asnvJ3w+N0gbtfKo/wZPRFmEylkLLjfl1EEDxwNi/SViT4g i4AQ== X-Gm-Message-State: AOAM530L7S7Is146Qfz7LJuZCrSaMji66EMjNAAvQv+20Au5IksOhNTI h+0WzWVb3JeURrsxHz530UxNW/nOQw+j2Rot X-Google-Smtp-Source: ABdhPJwBSGaczYBYvRDUJITFNi+ARBp3CdpbyngPp7JoqqQ65OOpI6xT8s/w6o7vekhzfu5EKea66w== X-Received: by 2002:a37:4c05:: with SMTP id z5mr31654108qka.245.1607444709788; Tue, 08 Dec 2020 08:25: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 h24sm13938504qkj.85.2020.12.08.08.25.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:09 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 31/52] btrfs: handle btrfs_update_reloc_root failure in commit_fs_roots Date: Tue, 8 Dec 2020 11:23:38 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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 375aa2bed36d..dd60590685c0 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1343,7 +1343,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); + err = btrfs_update_reloc_root(trans, root); + if (err) + return err; /* see comments in should_cow_block() */ clear_bit(BTRFS_ROOT_FORCE_COW, &root->state); From patchwork Tue Dec 8 16:23:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958977 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.7 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 725CCC4361B for ; Tue, 8 Dec 2020 16:26:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E81123A6C for ; Tue, 8 Dec 2020 16:26:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730473AbgLHQ0O (ORCPT ); Tue, 8 Dec 2020 11:26:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730231AbgLHQ0N (ORCPT ); Tue, 8 Dec 2020 11:26:13 -0500 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2EB1C0619DA for ; Tue, 8 Dec 2020 08:25:12 -0800 (PST) Received: by mail-qt1-x841.google.com with SMTP id l7so12284385qtp.8 for ; Tue, 08 Dec 2020 08:25:12 -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=5tGgAU0fytAuCT9HyuGI8SUEESboZkA97zkxEHIqkMs=; b=CMnOnobNj9vJ3C7kAP6lMP7SlKIWxwcowGvy/+OPHXwm1oXGwFG2SJ8C6AuS3RJoTM xXQQN1wquB7IkIlVLIftfIpJPPjjjeMpTkfTqVxv66Ziddz2coy6QAZPjyJE103hiyI1 biAiR1iEUkgxQq/EPR6TOw3PTJO1AxGtIBcslDTTsCIDldt50YI8BNkG/DzO2P389q5X OUSH7YbSOmaZmT1Yhf40HiCe85lQ9pyDtojge9iVFZpEaE2zbuVuCaYd+OdcdT94PuQW amld6Jj/IuRB9DBMtYphUp9WI3D/ShrzTT3HZGLul8J+QC2M3Wzq41XK91/p2DfZUsZ9 gaWQ== 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=5tGgAU0fytAuCT9HyuGI8SUEESboZkA97zkxEHIqkMs=; b=bfhzGKtwZoktfC05YrtSFSiUzpAAdk7EDGfY3Mw4VXPoffoa95xxn8Wf6/lY5HIQLI yS4T991koExsvG6zhbRXvlLE+5LyWC1kFtHPFSnpE61qyEIH1ITuThwJo5tMsU5X8Ft7 G8oLl2UEdrA+Jg7gdMqqaDyxwMJrw42EeRK2c39Q545pTE1+j1ILfdRwq4CCCn/1J9oZ 7cMn77Xlj6e7jO1eJvDAZlU6w+NETiQgu2bNGxDM1iAKMRaaauHKe6cmM5jXvg3dXBOh VwjOeJ5ttWebGUFAoQLW0rADQ+irkHuScAbl96W3m9lnkdKw2Gi8Ej/PhFZv/HRHTh/b 2oBw== X-Gm-Message-State: AOAM530PN9HKJkfPjJbiU+2MInr6iy4GJq6xSy4TyKbEMxdmpUHLibLt fBTp00nuzQK1VrdOSQp46jTV2rNT4oqDfCEc X-Google-Smtp-Source: ABdhPJzC+vUaPjacKpHTuzo662E3u5qQn8XWq+JpqPw0SJrwubSRav7qkMLbz5P1HPs7hQIg1NFqJA== X-Received: by 2002:aed:2393:: with SMTP id j19mr30416539qtc.23.1607444711902; Tue, 08 Dec 2020 08:25:11 -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 p62sm14220212qkf.50.2020.12.08.08.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:11 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 32/52] btrfs: change insert_dirty_subvol to return errors Date: Tue, 8 Dec 2020 11:23:39 -0500 Message-Id: <64a96d50f7bd536840e8ce9f6f6b32a97b4d0262.1607444471.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 ac5350dfb33a..17bb2bb9a507 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1556,9 +1556,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; @@ -1578,6 +1578,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) @@ -1779,8 +1780,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 Tue Dec 8 16:23:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958941 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,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 DAB17C2BBCD for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B970A23A75 for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730412AbgLHQZx (ORCPT ); Tue, 8 Dec 2020 11:25:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730391AbgLHQZx (ORCPT ); Tue, 8 Dec 2020 11:25:53 -0500 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE248C0619DB for ; Tue, 8 Dec 2020 08:25:14 -0800 (PST) Received: by mail-qk1-x742.google.com with SMTP id c7so8155507qke.1 for ; Tue, 08 Dec 2020 08:25: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=qwL5s84QZDmX7sSsP0yjbdBzGtv5WBBR/E9NoqSDiN4=; b=STDb+Vvk7wZFViR4wWAfqYcJCbX2KJyKrneZZhj2z3mP2JWXvUDl1FXroNE3XUs5Aq TC9ACs9J1aux+9B9YA8HOElj/qxbs+TBKUBTa1mdxMxKPsi8SgZVZrk8oOYvF+JSfXAK uv1u4O5XBkqHEWr9dKrEf3IP1lHKDPxRC8YG1CipH+yqmZgu1JOqFt4tU/X28i9a6Ch8 cCjqauehOgWtLo4y3U5P/+iEpkT6j/PYgZJoEcl35nZuQJRYyY2NH0Xx9TXw4sUqpKw3 Rl6zvP63oCF5YbJbUCuntck55T0xQ1WOukx73aRElrhWXTp4Pq3acaXTxThXXs7JgNk4 ferg== 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=qwL5s84QZDmX7sSsP0yjbdBzGtv5WBBR/E9NoqSDiN4=; b=eWM5Iq0bBA8pIiGZLAoxUERAziPyqY8eCx75ivRV/S5y7E5uhIC8EsZfM5x8Zm4eqo D8BRR5GFvzDaZNKiR5Reo3v8LW89daAHFaGycbpvaIzqNIYjvqbvRuV8XqfJua/p7LY4 zNfsme/n6+nSVko0ngpNB8vxS8nTFZG1tJnPnfgKGLxRq5ufhfHNC1ecZ8zhZVcbiC+T UBg6LACzHwfHbLVw0IUp63y2RnyR7BWUw+O7loQNkOfDPWbf+WPE3VwLCbie883XUBXw ZyPsItL1IaFKifzgKKaS9KP68HJbjymia5lq5yVim5ae+dGDPho6TJ34P63w1CDO9kCD W7ag== X-Gm-Message-State: AOAM531hGedjiZb132t3Lb7EHyJmhe/U1F38fJr+Xjc4RiInctalKbjV ziZWJestTU4mbMFC4kzfKjg6QBuTQSY6Si2d X-Google-Smtp-Source: ABdhPJxo9ZNZbuRuDqPIOTUrT6XLCLIWAFD/zB7OPy2zOddPIsahQVyqhd3cCQSUmog8DQD7FVBnBg== X-Received: by 2002:a37:b94:: with SMTP id 142mr18322374qkl.318.1607444713711; Tue, 08 Dec 2020 08:25: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 y35sm15818777qty.58.2020.12.08.08.25.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:13 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 33/52] btrfs: handle btrfs_update_reloc_root failure in insert_dirty_subvol Date: Tue, 8 Dec 2020 11:23:40 -0500 Message-Id: <42df8df431a89627f6f640ac69726f3585697815.1607444471.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 17bb2bb9a507..916f9ebedc8b 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1562,6 +1562,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); @@ -1572,7 +1573,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 Tue Dec 8 16:23:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958993 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.7 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 A8D84C2BB48 for ; Tue, 8 Dec 2020 16:26:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F29A23AFA for ; Tue, 8 Dec 2020 16:26:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730496AbgLHQ0Z (ORCPT ); Tue, 8 Dec 2020 11:26:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730492AbgLHQ0Y (ORCPT ); Tue, 8 Dec 2020 11:26:24 -0500 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9FD6C0619DC for ; Tue, 8 Dec 2020 08:25:16 -0800 (PST) Received: by mail-qk1-x743.google.com with SMTP id y18so16395405qki.11 for ; Tue, 08 Dec 2020 08:25:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ahctvAGM6XY64zu2BVGUKBwiv00peOLEBIhqPgdaxkM=; b=qnEVL9OxNdOPpgDkuOO3cs0FR+sCPu5+pvUhJ+05s8pIArGGwPLJO02FADbatKLCO6 tWg3aT+GkR0Bj91SkbXhH/+thn//w0zFjf8RyDfOWwo71u7JMYU25v8sLxv/IaG4Y9+a dURZ+6fdQlOAhqUGxIa9dZIwn/xfmD2HJgXMr15wYcfXaZXSFcbGrMhHp33VLuT0qGaF nqnFi4kLLqk/e2rXCHYcB9wsDLrX9dSfm/tNICByNF8amPcc1C8QJoOGjCG323pR0kOi wl/Q1aOuOcJu4oAzezlljsQdcPIhX20ZQOpSOtZwLD3T9y0dCoBtV7WVCuTyDHllikxC EhGA== 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=ahctvAGM6XY64zu2BVGUKBwiv00peOLEBIhqPgdaxkM=; b=njO5ktG6Hvb3FwCB96Jk73RM2tHuiGQ1fY+dc2CQN7BNVa/fmHRQJZpOeybsmrviQB 5I0DSOGZYhmsAI+e1+An20Tdi7Amk7TZhSfQ853WZk1JCNw7Sn3o83LUQc7whubRCuAo 775y9VKIPqe8TvlNxME9HZuLfrKvlv3GT+G8za4ZLBwgODUAh1ZhteE038IDy6SwvSBQ kyml09Lkw7MlVqGoWae0e6VGCTSZbU6yuQZem8ua+360l4NLqR202jXpIAEh5IFQmnXc +9W8VSebqdEFRXRItyVwNhIrS9vlzTlODUtCjidT2ILBxfsKGM48CO1MQiAbkuAUA89J Nkkw== X-Gm-Message-State: AOAM533KUZfn4Ymo+gtL7ZNxrVKZPYKUD5AdoGgB6JZZ46BYZAmzelTm 8rYSlANRREJeL4Ia5aImdO9UI4oWUGr1VXjU X-Google-Smtp-Source: ABdhPJxK/V7QxdATzECBp+pzO1QaQl1dh3nPyFkmAl1CgrFladhsoMKe25diUyoaOmA+t9LTr+zUNA== X-Received: by 2002:a37:4c4a:: with SMTP id z71mr31852399qka.2.1607444715885; Tue, 08 Dec 2020 08:25: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 u20sm13491715qtw.88.2020.12.08.08.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:15 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 34/52] btrfs: handle btrfs_update_reloc_root failure in prepare_to_merge Date: Tue, 8 Dec 2020 11:23:41 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_update_reloc_root will will return errors in the future, so handle 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 916f9ebedc8b..c99f50969e24 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1860,10 +1860,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 Tue Dec 8 16:23:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958955 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.7 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 20BA7C2BBD5 for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0563723AFA for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730428AbgLHQ0E (ORCPT ); Tue, 8 Dec 2020 11:26:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730421AbgLHQ0B (ORCPT ); Tue, 8 Dec 2020 11:26:01 -0500 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADC3CC0619DD for ; Tue, 8 Dec 2020 08:25:19 -0800 (PST) Received: by mail-qk1-x741.google.com with SMTP id 186so2511443qkj.3 for ; Tue, 08 Dec 2020 08:25: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=4yGA6i5eUcurMkTIS9etR8PmmZIrcDt3XNSYNKFX/Uw=; b=2FwKmIaGF0xwn1FAHq84uTQDh+5ZRMdVRpwGg2WcyCgybbYq+BCl5OGX5/ZcJ+yjpf 0JC5KfujWHNXPieMbt5yrIEcazX9fRz7wS5zF1O9U9flg4qjDpL4snkSG+ImzgGceajb Mk5Hu1HHbdM/oSa7eG0/aadw22TNrWv++JKX8fm+rSUpqKIPWBSkoMVRi5qod0sjBbY6 /cvjuKmyLbjTKn0dkwwZcbR2vA5vF3EShBGtkl8rWgGb4Fd8yFk7Iws07cUCu+KTbAwC lV1nVFuTI5L4h5B5urNHP5etqJYInkVIwrRFYhS78mjc/AOS9VozaZmS9dTCQbW3PpOP gygg== 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=4yGA6i5eUcurMkTIS9etR8PmmZIrcDt3XNSYNKFX/Uw=; b=HP8UsDijyy9w7eLkhm7LZS414wzXZrK7cA3jl4pDrZ8z9T6crllNiwice+WkOQZkRZ tpu4KyL1vLOSYaKKHEli5aUgrJ8kT+ln7qbFT8GRz32M+0pUMF9x+PEzSEOJjyMftmoB jFJXji+FHY9X/j215h9hL8HIFxL8cKkun78gzaUjoAFlrkckEiwSgQBrlNXgQcF/ZxqD duyjW03iAkax5lkiJFNlpg3cOnOJyFdEQ6Q3p6tmWCxibppar5pqghDqt2v+IIrZNfLd 8/+v7FM6epc8lpaol+5Gf3Awv0V50zGjg88HLPQxCkcinKVNe3K6zpV+Is729OjIAjm7 Kv7Q== X-Gm-Message-State: AOAM5314qp8MWogRlEHDXtI/tWcyhyvBs25QTrg9DkngEUNH/+y++KVV OMecK+xAUB+xG8dRNrWqfRlamxY978gNLY1l X-Google-Smtp-Source: ABdhPJztYSNOTaa1H4vYvE+C/pQzy7klnEUetat4KYM5yWJeZwR3tSQ1PdZ2HV8oTQ0SADY2nf6J+Q== X-Received: by 2002:a37:9b8a:: with SMTP id d132mr13801467qke.81.1607444718604; Tue, 08 Dec 2020 08:25: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 x22sm13690089qts.53.2020.12.08.08.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:17 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 35/52] btrfs: do proper error handling in btrfs_update_reloc_root Date: Tue, 8 Dec 2020 11:23:42 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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 c99f50969e24..49caecd897d4 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -894,7 +894,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; @@ -927,10 +927,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 Tue Dec 8 16:23:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958973 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.7 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 65C1AC3526A for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4584123A6C for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730439AbgLHQ0G (ORCPT ); Tue, 8 Dec 2020 11:26:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730435AbgLHQ0F (ORCPT ); Tue, 8 Dec 2020 11:26:05 -0500 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74EDEC0619DE for ; Tue, 8 Dec 2020 08:25:21 -0800 (PST) Received: by mail-qk1-x741.google.com with SMTP id w79so5387222qkb.5 for ; Tue, 08 Dec 2020 08:25:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+LR/EgxO8kjgzxcJtus24AZos3z4J2yhdfKJsApHJ3M=; b=wUxlpcnynRaUKV/3+JQrBh0bDBrsnHGgOu1uK4yPLtQyRuz6LDNZtcpyZRGm27FKPS w7ROUXDLK7qjy5GjwYs6c7IoWjPo/wdlb8xKm+Jmmg4DPyF2hEHqqytNGBm4kLuHTG64 6XVDsXmLdGorn8LZrqf8Ow1YKnbz38hHgMBKU9EHsIE6aBRzUwkSwLNIH7wt8VIHNHzy UTUJXumHR4hHkvGx2PMYIoApD/BDIOOKAXNZmba9ozEoznkjLryalxqDG0h4L7iydlR6 ngSXTwvteDV09dKQ6v7kKlDefZhCQBN2RuKShSJfOHL3zWtZmsV4N6PQSXjrb4VjfUW2 LkkQ== 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=+LR/EgxO8kjgzxcJtus24AZos3z4J2yhdfKJsApHJ3M=; b=CGT7nhlDeadp/0JSD1/aymZw77f9fyhzOCXaFdIM924px5maUnbXCaZU7SAnBAPZhZ 9A9Rv2hBxhtAbHof1yfJ6Nt4on9couI3APVLpUqTQ1aEOgPkAX/8bWox5FOvg6ZqVKpj Mcj6ebmyXypi47pSFDxF84avgLFzwWgsghaZXjnhQpY9T5Tqa+e+VoXMl1DAOUr7H8UY pra+QFxas7TcHoMZz5XH/p1WIpRaTg0UqJsz42pkRXCpLbrwmOvVZJRUar12suSvLKi7 8iiHKGRUgaxMutILfRbxe6+08alenHtBQRahcQ7usOrJN7fLk11ccaGxzMlSb4s8ySBz h9Cg== X-Gm-Message-State: AOAM5303PU5c7X5iJ/1ikJlajp8lPrY7T13W62nIpY2ZozMML9ZpKD6T ffL4K1sND3BUGrylV8Q2xfAW2l6pEMV43LA0 X-Google-Smtp-Source: ABdhPJyAl6mBy6TVnUnPQxt9SAPt8IKXgs2GS/ZOfVfUTn4IGvLeVAd8qCXXX9D41GRWAwTrwVmuxA== X-Received: by 2002:a05:620a:13ea:: with SMTP id h10mr19459897qkl.125.1607444720430; Tue, 08 Dec 2020 08:25:20 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id y35sm15819004qty.58.2020.12.08.08.25.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:19 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 36/52] btrfs: convert logic BUG_ON()'s in replace_path to ASSERT()'s Date: Tue, 8 Dec 2020 11:23:43 -0500 Message-Id: <5a7133ad782b52bc2798107df24cf5d7a8c41329.1607444471.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 49caecd897d4..1f1dfa9c74be 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1202,8 +1202,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: @@ -1234,7 +1234,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 Tue Dec 8 16:23:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958945 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.7 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 EA121C2BBCA for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D061923A6C for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730416AbgLHQZ7 (ORCPT ); Tue, 8 Dec 2020 11:25:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730391AbgLHQZ7 (ORCPT ); Tue, 8 Dec 2020 11:25:59 -0500 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 191C6C0619DF for ; Tue, 8 Dec 2020 08:25:24 -0800 (PST) Received: by mail-qt1-x841.google.com with SMTP id p12so12288521qtp.7 for ; Tue, 08 Dec 2020 08:25:24 -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=VEzLYaBG29Bs0WZipCBmBLrRirwLPPLrrLuktteeRZE=; b=bP8nr53bw/xQ6Uk0k1aaayS1CAU/vkdvQhgTWdtxUaZ5YDCgDkxpWnx10yUlmAdcdi 2XmuA1uTH4PZCCK4Lft46LcIb99A01R5lu56rt9lvdRm5ivEB7tQnxhq8amcnQfBjAL6 ieThDEbR4BfCgfcY+y1E7rpNnxueRPyKFNzxoutrQJjzISKOaZ5/tahHemeoZtaUbIH5 nYPa9aN+YB3BL37Kpa2VLL3CD3l16vlKuWzgbPYlzXcqF0Z/pnEJuz3BGvW77SRFkdJQ EQER8mc/HHQnGHtpEYiSnXOx90SkVBf2BrC07vrPnd8tDENraymxkGhe1GGb2ujdfylB SROA== 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=VEzLYaBG29Bs0WZipCBmBLrRirwLPPLrrLuktteeRZE=; b=KxTXBFPnvnX//Cr0n9gaerPWg/AkxNQlWRJDNa36aCAApvDUNbJD9Lbv26aHThK14F 2+3OKW4pGXCdrAj4rPoW0cuxK4Ddx1mLGzhSAXMD2eNBiAc0xjQGitdaXD48v9Kvy5YK S7gWl3gSPdvhYhIfM4NVHJ+a/8hrLKhl3Nj76ehIFvxvBuwJAiInmP6x7BZwyEqqcdqZ MeIlLSsVmtR+bBFhVgLiCMl4PepK1lMQ+2dgKuc2wSDEeynTc2Cn8Y47sqsE8pZvplPp mWWVxMt0vBX4JuRd5cPtavF9lZ2i2GyAxv7kaSkKvZ7roscyoloHjRJLu6e4JQ4PNQlM +sAA== X-Gm-Message-State: AOAM533TVvEbEB2iqXFyaHnUJ/s81bM1W3z1g735FKD2q4C0RsL0HSuw mShSAos5yGUaFtNRtMXNmpkNbs7V68UsWpsM X-Google-Smtp-Source: ABdhPJwPFtk3kHGbmDrGcGQbHXhgoI88JNik4W97DMhwEkcAcIKwo/gy349/ZL0kC6TAL2ZCD+TAAA== X-Received: by 2002:ac8:5bd5:: with SMTP id b21mr17417487qtb.392.1607444722981; Tue, 08 Dec 2020 08:25: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 p62sm14220521qkf.50.2020.12.08.08.25.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:21 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 37/52] btrfs: handle btrfs_cow_block errors in replace_path Date: Tue, 8 Dec 2020 11:23:44 -0500 Message-Id: <22f2fcf516321dee8d3543e295756505784c43a4.1607444471.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 1f1dfa9c74be..8d683056fd9e 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1222,7 +1222,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) { @@ -1282,7 +1286,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 Tue Dec 8 16:23:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958951 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.7 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 771D2C3526C for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CAA423AFA for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730441AbgLHQ0H (ORCPT ); Tue, 8 Dec 2020 11:26:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730427AbgLHQ0G (ORCPT ); Tue, 8 Dec 2020 11:26:06 -0500 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23F58C0617A7 for ; Tue, 8 Dec 2020 08:25:26 -0800 (PST) Received: by mail-qv1-xf42.google.com with SMTP id b18so4935635qvt.10 for ; Tue, 08 Dec 2020 08:25: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=qcBvIWEBjxi5epMisBQCJPIJ9nknseBSr1K0c7sI5Fs=; b=DuSG89NXmk8WYpbSGNgQtmRLkUlH7LESqG8y5BioJOFDXNT8mcHc6E5W12SPD1Ol1g UmBcYAcQOO9TW43dikXQc20Scf/Zj7Dmfe4QQrfR4kxhEALQlVjMnBGSbZdOAtJGzEBo gQlh8e4IkzXqGncwAriMu1dGsD5pHv6EFmawyo2hN2TmimMTlVJVQpi32B+qUYZKZrXy paPym8jHJ6DdOl8vzsfWJEFe7NT5JGSLXhhaiEtC9Fu+bmp6D9mAj7j29ac279eWyd41 vPFvLVWfYn2C2e92NZxDOMaL7iZoGUwwfrQmo2Bm6c0ns71gsFmYNCR2Oway5yBEeyEh DrnA== 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=qcBvIWEBjxi5epMisBQCJPIJ9nknseBSr1K0c7sI5Fs=; b=XI+giLl4gbR4abKG4q49sbp8Sy/fsEU0MxBllJ4siYoBldONs0GaJmpImtTe4os6pn pg2G6wSw3e/DLZHPaLnoZZOppZJFvLgGuxVZNHeZF6n4XPtQmj7mQrNVKmrml4LZ5A0M 0ZCUsPWwZaGouqpVkVaR259kEFLEwOUgc8b2dPEitUTpL5H91k1M2KlIz7XW1tkCHy1t ihg2K4d4uZdkBZimDOxZ5nQhJwKixc9ssWBGJBDYVoaoemUSGYIfDNg1ZiOEK/p6ek9u 95hd/xlUt0qN3nJSrApqM8n30Ga2O74zUXPqvdyqvUPPY0RhIkhCMj0hY2AKtAbJhKPn dZRA== X-Gm-Message-State: AOAM5316Oqk2s9W1Wg7mbTIWP+amcImRRYuiHnFcRgD0C3WoBqMxkj3V 650mCjwLR6gigF/Rvg+J+yTv7mZ0LZtMUEpM X-Google-Smtp-Source: ABdhPJy0np0/wWbeed3Yrn1TymTA1g70oiRB7YdlVFWFiFeW5JSD3OTuw2Op41DQrU8YmEkj1MozSA== X-Received: by 2002:a0c:a802:: with SMTP id w2mr28543821qva.9.1607444725067; Tue, 08 Dec 2020 08:25: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 x28sm12690905qtv.8.2020.12.08.08.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:24 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 38/52] btrfs: handle btrfs_search_slot failure in replace_path Date: Tue, 8 Dec 2020 11:23:45 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This can fail for any number of reasons, why bring the whole box down with it? Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 8d683056fd9e..01085952059b 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1314,7 +1314,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 Tue Dec 8 16:23:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958957 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.7 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 0AA93C2BBCF for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E42F823A75 for ; Tue, 8 Dec 2020 16:26:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730419AbgLHQ0B (ORCPT ); Tue, 8 Dec 2020 11:26:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730391AbgLHQ0B (ORCPT ); Tue, 8 Dec 2020 11:26:01 -0500 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01CF1C06138C for ; Tue, 8 Dec 2020 08:25:29 -0800 (PST) Received: by mail-qk1-x743.google.com with SMTP id z11so7254262qkj.7 for ; Tue, 08 Dec 2020 08:25:28 -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=uKvPcsxjeyDkOX+k5ouYvcOYkRacPuRTIWcN48+peYU=; b=AUE3QbO41aKzocKM4tgbmKpioM9U7CIVy1dRMVLu1s/ApFFZKmB4Kcp0czojkY9+wQ PZcAvcACuqctqBnmIiQojKeuEU2CHe7QM+5mdaXN5Jr/XaJTgF5j3pRctEQKZYa9Kl3G FQQPMa0X4Qlzq6stXZ2+pepU5l3N7A37TU//WG0YMxChbiIEUIhVrZLEWZRrZL4FpvGS XnNN1Z77SLSCiVWg6mA3H/bjyeZB0fx5UQkzeWlxZhtpBI8EpLstztjbzvoFKcPO1bJe csC/pmh2HvhBlL5b1Wm7jqIA18NTg9gyIiwiV4o4udA+ccpvAw5KQNT2GNvr0v8oMMda peRg== 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=uKvPcsxjeyDkOX+k5ouYvcOYkRacPuRTIWcN48+peYU=; b=aKYHOq3KB+qOU/IojCfwW4OQxq4dYIo1shv08V/SwrNdSzJrExDwDIpUTclYdBwWQL hnmLO95LTUSmh4s5FYpL51NieWZtdqrhvGACHf33aQIkQ0bkWLAlJj9yno+1pc33rUF0 O9w/qCztGD9TalBmKD6//1xjayBUaU8gXh7RYMl1E6oDcSGW4xnNbvDKxGQbYbxYjt20 JXSWl9zMNqU6p8Ldso+YG/NAAlSLF7tFtsUB3ZvOwIjS3fIcbXmty0pPuKA+xCGMc2iz Oeq7qq15dUblcxelsRPh5HJIEV+rXGapa0QS4tYWbF00tVS0rjM/2nyK4WROsYOzkO+E 0xWg== X-Gm-Message-State: AOAM5334Cc9addDk7frIcWXWKfi+KgXp6lxoXvprUPX+NLaSamyrDqh8 WNVdkCm3NpIoXwrLkPqRyY8j4tAQtacyt/SI X-Google-Smtp-Source: ABdhPJzlJpUCDdGpS5lhAjZDauGnOM4SQB6bMZC4qIdDEucyuYRZPhRmRGtek1DIJA++q0npZO1XBw== X-Received: by 2002:a05:620a:148d:: with SMTP id w13mr29899128qkj.299.1607444727888; Tue, 08 Dec 2020 08:25: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 k188sm14526383qkd.98.2020.12.08.08.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:26 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 39/52] btrfs: handle errors in reference count manipulation in replace_path Date: Tue, 8 Dec 2020 11:23:46 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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 01085952059b..5ddd9e6e354c 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1355,27 +1355,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 Tue Dec 8 16:23:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958949 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.7 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 33493C2BBD4 for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A1D423A6C for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729585AbgLHQ0E (ORCPT ); Tue, 8 Dec 2020 11:26:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730424AbgLHQ0C (ORCPT ); Tue, 8 Dec 2020 11:26:02 -0500 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5612C061285 for ; Tue, 8 Dec 2020 08:25:30 -0800 (PST) Received: by mail-qk1-x744.google.com with SMTP id 19so8854996qkm.8 for ; Tue, 08 Dec 2020 08:25:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=rDzKVwtkiSahpWv8OJlNI4e3Gr8IwTzTfIZwdt7++HU=; b=JOa8FI5V9gNVGjrnXMd+YUp3IZi+D67HVBWphNvQ/s4EPnsRxWK3ViDR0oalU8YrBO vf4nPH4Kd+fJvIqjOkql8e7kh5UT9sDnFhdhPHUSZC/cscDCvbb8uyhrcQeCd+2FHua+ IWUNKCeZgZH2fLVNVA1MGWKz6n3qAl/4x0eMPG7d7m707TjkEeV51WBRe3tEOaMISMuW ThLWdpfWz/lMEVFPAnlMYpmgnwCU9F9yuWxAzdhcelrkAUwmrPGCOD7ZW7930WJKWWmP 4DVz/taYoZqoe9ZUlV+KH0EJhH8lpu2SOL+UIBUNimvcKbIaQM5UlT5O99yiQSCj0/Xb 9kgA== 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=rDzKVwtkiSahpWv8OJlNI4e3Gr8IwTzTfIZwdt7++HU=; b=MijxxNzagCnXewuJeOA7zD+EmBrIIaqHbWx3/IYljNkSdzIGTA5v4Q4/QtmX6wEXk9 XnaXoHMK/pL9kmrNHzMnM7T2Of2Awuf9DjYVLGBez9tHHkOEAvMrv+OW/DfgbFuFgXhU 9cAbodr5GYefrdoaHAOxBZws1QFvtV6eslC/MTVKIzG66XMCYiOUgOafO4nVEkNLg/pT dIIP70a2bxkDZhEmzsCHwA6xoFy8W82aR48wa2YyR/jqE5FFG8G6TozjhDLr6OOhzRQ3 VvAyaGQoLHJkEVi29Xj8AdtyM0qgXTmb2mvLm2QzLgx6xgFSjSMtCDST7WeBXZAJVsdA g1UQ== X-Gm-Message-State: AOAM530l38+5LTxt8Wdn5aH/NH8nUkRrUKfJa0K+0Pj32wa3G14vNUT9 vjlN832su/aEoYDaWG9/6St1VA8sRn0/ybcG X-Google-Smtp-Source: ABdhPJwubhLfTgk3oJxY9NQmH1kMy5yQaW3U6o8bI66p2Zm9LCms/Qx+4JZvBhN2K64e/aXlbkwTlQ== X-Received: by 2002:a37:b6c6:: with SMTP id g189mr11059339qkf.10.1607444729707; Tue, 08 Dec 2020 08:25:29 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id v4sm15234624qth.16.2020.12.08.08.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:29 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 40/52] btrfs: handle extent reference errors in do_relocation Date: Tue, 8 Dec 2020 11:23:47 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We can already deal with errors appropriately from do_relocation, simply handle any errors that come from changing the refs at this point cleanly. We have to abort the transaction if we fail here as we've modified metadata at this point. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 5ddd9e6e354c..1097d1b3c492 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2424,10 +2424,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 Tue Dec 8 16:23:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958971 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.7 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 5A441C2D0E4 for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E6BA23A75 for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730433AbgLHQ0F (ORCPT ); Tue, 8 Dec 2020 11:26:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730427AbgLHQ0E (ORCPT ); Tue, 8 Dec 2020 11:26:04 -0500 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7F1EC0617A6 for ; Tue, 8 Dec 2020 08:25:32 -0800 (PST) Received: by mail-qk1-x741.google.com with SMTP id h20so16453083qkk.4 for ; Tue, 08 Dec 2020 08:25: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=L8fTlPURwi1njot0TAiCWtZWFXAYhGZrv+pY5V3rdfo=; b=pUc0YpsHiMbggfobjchJGpmEfcW4hCDcFlALBLL7N5uAC5Ymiyxqn9Z2R+aBtyHENk O8Hy1ph3521oyZUCf7FHAuiIjqHUZ/4mzm5tXf9CbMOADaNomtupGISLjpfnbolNjsqB l7Z7Fppju8FblwoOaMq39N8g+0UDSczMt9luI9YzVSY0Qx83pfhF3LcT7IYBNE74E5yx LJWsYEDmRKL4h5t1oy8e2sCtVlAG96mcc6E2Ro7vx+aF6ScPOuAym50Jq/A+gn/nbXxO x1Z9B16VBfL9JGGjyDYhwYzpDvoUj2xC6GrreIEflQ1ki/RArXVgChM4vO2HSCk5eU84 2aZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=L8fTlPURwi1njot0TAiCWtZWFXAYhGZrv+pY5V3rdfo=; b=s9VACiJ/BJpmdgh6XrY2GlnuDlCph1Hp+xOQCiGNWTxTCUOFw9leOx2VibvzYyh83c 8BYaItFBicuconHKa0buIxbnA0HLCIkezONu5TMdDbdmOQeQYMe3gWfHlxfGzG3kvW6U 7qbEquNZGxSbUIOODhW3zfNuxDf0iLY81GVUVE3+ps+v0nJJZb32fhb4NylPTkN+Mfhj 4K33ukM8Rrxd+OwQESkBqJsQ36J9mMDstrPF3wDzbzqWJwmDpNPqJPJbq579WayNPbTq 1H+cwWqthhfkYLPtuOl0WVb3ANgWhPO0EdMlUv87PFblgr2ZZSjOY6A0IwEzEamqpbUF EFKA== X-Gm-Message-State: AOAM532a+TimQJkzrRzpOpUvP1Qs/8oIGvlRGG0pfCLABK7lBNhy6o0Y 98YUxCkhs8dmZzRdpX5kHrpJcEmc4CiXzUxs X-Google-Smtp-Source: ABdhPJy61a0ErtAsRtdA1og/Va2H31OgCX+8UxY+n2lxQ9ny0dJV9NCUTnuIVYTV+ZPZ95/a5FM59Q== X-Received: by 2002:a05:620a:14a:: with SMTP id e10mr13575584qkn.103.1607444731628; Tue, 08 Dec 2020 08:25: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 r1sm13187632qta.32.2020.12.08.08.25.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:30 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 41/52] btrfs: check for BTRFS_BLOCK_FLAG_FULL_BACKREF being set improperly Date: Tue, 8 Dec 2020 11:23:48 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We need to validate that a data extent item does not have the FULL_BACKREF flag set on it's flags. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/tree-checker.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index 028e733e42f3..39714aeb9b36 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -1283,6 +1283,11 @@ static int check_extent_item(struct extent_buffer *leaf, key->offset, fs_info->sectorsize); return -EUCLEAN; } + if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) { + extent_err(leaf, slot, + "invalid extent flag, data has full backref set"); + return -EUCLEAN; + } } ptr = (unsigned long)(struct btrfs_extent_item *)(ei + 1); From patchwork Tue Dec 8 16:23:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958963 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.7 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 F1F9EC35273 for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D9DDF23A6C for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730461AbgLHQ0L (ORCPT ); Tue, 8 Dec 2020 11:26:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730453AbgLHQ0K (ORCPT ); Tue, 8 Dec 2020 11:26:10 -0500 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A13DDC0617B0 for ; Tue, 8 Dec 2020 08:25:34 -0800 (PST) Received: by mail-qt1-x842.google.com with SMTP id l7so12285274qtp.8 for ; Tue, 08 Dec 2020 08:25:34 -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=AiRItZbDfX3OPAKhq48UaEMQcc2QWJynBHjm1/PoRdg=; b=d14pXTXqFBS6yM6rW/x3ql+nLp0F9uzo9IK4bFtplUVSj9eTT5DyXQPchdq8GnMHF3 JcwAwiVVDgjJizVxRe6zm03Z5BeK7d+bJRvhEAHwp9w2UShSPnbYUSnhT9q3z/8IBNEX U6hLFETITmkOXXeXzs7eHP380TCKlX8idqtTaN7vA4ROz19r87Wgxr9V2POvrFs/gXF4 gF+WcdzUq35Am5aWp9jRJ00a6WIAKenUU5Gn0FkVu7JN9TdZAoZqU+GXOWULMhAyp+WV cDmCfPnnu0pghbt9IjTpaBwy/5JgcNI/67NznFGO2WdTatGU4I77Ay8Ijb79jPd82EI0 mxOw== 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=AiRItZbDfX3OPAKhq48UaEMQcc2QWJynBHjm1/PoRdg=; b=H7xWB8jzNJgA5SLDoPV4p+3ORCQRD+ZugrLFBGLpgjD6QcnPMPcmsvjxY8kP3cbnNu 8vgYyId+kZY9xiuI7JgKiUoljhP9yW6wteHT89RJW37Q55hkptwNUGMGxVq3TOeXKpmZ bJHnBDjxi+TktjYhzp1xBVUw+n5I1Jj52GUiJXkEYurfb4dPiSW9Mbsn8SpI6txl7Zqi BcJdNseh9r1p1MfMaTpNM1iqEyiIfLOBX+TFJ/J/seJ0jhlpQmDrIWhpMyZjpuQRQlJH hNStS3PDD0gEnRcT4FJSFqNvjljBd/EBZxsePQHzTN0KFGe6y27izkXKiAjN93/kvt+h U+RA== X-Gm-Message-State: AOAM5338RmR2fr0tFRl9lukXxT7E1z2yKm1oEVvuUTvjWQpU3/rdaaDt T8N4+b9OJEmE6q2x+SOa5J5psFqo9U9cYsII X-Google-Smtp-Source: ABdhPJwS4PVvha9eBZUU/OOYqHcPf3ungOkHOE6UDBAKYG5EZlBqMs86sfx00RKJuax4K7fUt7blKA== X-Received: by 2002:aed:3668:: with SMTP id e95mr30877352qtb.69.1607444733503; Tue, 08 Dec 2020 08:25: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 17sm14218310qtb.17.2020.12.08.08.25.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:32 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 42/52] btrfs: remove the extent item sanity checks in relocate_block_group Date: Tue, 8 Dec 2020 11:23:49 -0500 Message-Id: <8d747afa22269b0ca24b4c635c3ed900f422f23f.1607444471.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 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 1097d1b3c492..328a78399ddb 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3361,20 +3361,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) { @@ -3426,7 +3412,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; @@ -3475,19 +3460,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 Tue Dec 8 16:23:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958967 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.7 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 43E92C35296 for ; Tue, 8 Dec 2020 16:26:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2647923AFA for ; Tue, 8 Dec 2020 16:26:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730467AbgLHQ0N (ORCPT ); Tue, 8 Dec 2020 11:26:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730427AbgLHQ0M (ORCPT ); Tue, 8 Dec 2020 11:26:12 -0500 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A847C061257 for ; Tue, 8 Dec 2020 08:25:36 -0800 (PST) Received: by mail-qk1-x743.google.com with SMTP id 143so1351081qke.10 for ; Tue, 08 Dec 2020 08:25:36 -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=oA3hm6Lz9XJnQgK6Q6/s2qKe4ojAA4p4PR7GlNhtccg=; b=yNj8eThT+J7UNauo4bIe+avOGulx5iqdHXcqBStErqI9ZEALFClSyfddPj3vD1Ge5n xjdqmjqhnsJ3UZx8gZX3IWuhmClDfdWSyScP1FSJmVxRyDAaMXEmg0Nuve7PsHos0wec o4gHm0wTz4jnZNlF6+ZGGiZfzc/pxnU4BBbAUV2bMc51SdSB8tIRBKy4RBf/lT0TkPzm Ugj9svbe9VdIg+9hg4hBOMgTq9i76itt81j4S+rIi6vyP3JCjJjqWygihv3aQ0R1b95e Tuqaqa9wvnwRXRRyYt1VdtF9psRP12ypTM3lupVEkLE9SIEXSQmN9tUDccPNAEIKRUnZ 7zWQ== 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=oA3hm6Lz9XJnQgK6Q6/s2qKe4ojAA4p4PR7GlNhtccg=; b=tg+yZw8TBAIV8uOnPn2eR7AGeeJiNOAFfklkMUjlZ/9bLUDIYxgN+uGIMFZ6PXEY0N /6NNqiNi6rIg3zVkUhljx+iQBxUTN6+C1MJAufzKgOn+nXCiXLCB+plyy83zboFkft2n n12XT4/F3JAefjdPczv0H4MRhEP/fPdNdAy1DigepeYJAB2MmbM+BwNmTSy0SEfjQq80 dwt3otVnBrtSIhGS7MDzCmAIKKfRu1v7T9X0YHGtxpcovtuWwuRYXKD2XzKqMp2R+t0o sUg/cB6K01qkMJxwqpb+VCquvMLev3YzV95sUdg2O/PLGCUxSrVZRHLNCIH+3FN5ACCi KpvQ== X-Gm-Message-State: AOAM5328kS/ijM9OL27+XOvFvLAJqVg3Wg+1AozHTMMyt53DloXQrX/d B61ftIjIobkdAz6bewCsR3pXBp6N/pk43BZ/ X-Google-Smtp-Source: ABdhPJytYMWZMW9aTN4Vjtz8jQpXJqUQkwrpRA6NtB4dg1VUMDHsDZh0H9ClHaZHOAWk4yZf8miQsw== X-Received: by 2002:a05:620a:113b:: with SMTP id p27mr30288216qkk.29.1607444735487; Tue, 08 Dec 2020 08:25:35 -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 u15sm13685987qkj.122.2020.12.08.08.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:34 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 43/52] btrfs: do proper error handling in create_reloc_inode Date: Tue, 8 Dec 2020 11:23:50 -0500 Message-Id: <7c658b951087cc905e2f6821348f2cb3998e506d.1607444471.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We already handle some errors in this function, and the callers do the correct error handling, so clean up the rest of the function to do the appropriate error handling. There's a little extra work that needs to be done here, as we create the inode item before we create the orphan item. We could potentially add the orphan item, but if we failed to create the inode item we would have to abort the transaction. Instead add a helper to delete the inode item we created in the case that we're unable to look up the inode (this would likely be caused by an ENOMEM), which if it succeeds means we can avoid a transaction abort in this particular error case. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 328a78399ddb..b5d644a87dcf 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3599,6 +3599,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 @@ -3625,10 +3654,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 Tue Dec 8 16:23:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958983 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.7 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 C6B93C3526D for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9286523A75 for ; Tue, 8 Dec 2020 16:26:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730448AbgLHQ0I (ORCPT ); Tue, 8 Dec 2020 11:26:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730427AbgLHQ0I (ORCPT ); Tue, 8 Dec 2020 11:26:08 -0500 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 925B8C0611C5 for ; Tue, 8 Dec 2020 08:25:38 -0800 (PST) Received: by mail-qt1-x842.google.com with SMTP id 7so12326058qtp.1 for ; Tue, 08 Dec 2020 08: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=VafAFhu13jV10oTVJpICh9ERQ6Z0ZUmUtNXN5qZwDpo=; b=Rv8QwBAaDDx7No1VJp21b2uAc0NQVkPF1ZViKtJ+0HXoVIM76yc0bLyFyMUaGhcr+i YDUUfnNj66r47uA3O7v3fg8BBEr4pm/mAIiXlIlDB53f7oRluTLZQVj5yvc4Zt5k0rLZ 6aZG0dt1pOp9ZIwbd/3T4Sy+OXprX005yR8l/ADvGehRPqhEJeFHVbK1wD6hVYotFPL4 vsGRuLYFcIPxDVjTXWyml1iBKnSDNpU1ajFLLjGmLXW7sNXpyn/EhlvJry3/QHMjFwmz OO9iRvMqfiHL9BRfpLWbHL1tROVWBAMWom/SCDiS0d/dVxniqghqqL2JCB0ZII3IaoUI 8tuw== 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=VafAFhu13jV10oTVJpICh9ERQ6Z0ZUmUtNXN5qZwDpo=; b=N6yGI9EI9OEfK8ZmPOl8Vb83aUBXnfudVwbrfqv5P4aZuvECPhpSsgK0Bb15lrWXtD 8xRbQegHVQMYq2xFB/2B+SK4TkrweZsD+EhYGGw8DuCo7lvkpKx0XIq/QHkg1eu4inAh Zg2g8BolbmAPklXwMctIhk+wnCKAa/S/6JrWXkmrN8UHECmudHY92cTLC+Azj3jX6GqA WyuHpBM5VSPsqwwFCoz0ZtTs4DUFrhN2+wYVL9M4td4eFh0gO4S+BBwJpJbbap9bmCX6 d669IR29lkspF7vw8Qp6D9DdfKuvvFwln9p/pncFAHT37inAHxye+/6uuVO7UzRE41a8 Tjdg== X-Gm-Message-State: AOAM5323q5Xp9NRXFwyYWI+BOauG5rcvMFOuGbQgoC4cexq5EYQARqJe MGBjFcqY1bJ+6ghBqM8dFWYLzfw0TMZ6MUqA X-Google-Smtp-Source: ABdhPJzj3om4vT4pNEAc21PvcOtWN8YR+xLq8Tw+olza1JfnJFKZpdHXJEd4zL/b8MyiEouO4eWApw== X-Received: by 2002:ac8:4801:: with SMTP id g1mr29405083qtq.44.1607444737425; Tue, 08 Dec 2020 08: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 n81sm13526736qka.76.2020.12.08.08.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:36 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 44/52] btrfs: handle __add_reloc_root failures in btrfs_recover_relocation Date: Tue, 8 Dec 2020 11:23:51 -0500 Message-Id: <591c0c9447f6d82de6ba142cfbf6d7e762382df9.1607444471.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 b5d644a87dcf..af9008a71ff4 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -4005,7 +4005,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); } @@ -4220,7 +4225,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 Tue Dec 8 16:23:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958981 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.7 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 0FD49C1B0D8 for ; Tue, 8 Dec 2020 16:26:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D809F23A6C for ; Tue, 8 Dec 2020 16:26:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730481AbgLHQ0V (ORCPT ); Tue, 8 Dec 2020 11:26:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726810AbgLHQ0U (ORCPT ); Tue, 8 Dec 2020 11:26:20 -0500 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B867CC0611CA for ; Tue, 8 Dec 2020 08:25:40 -0800 (PST) Received: by mail-qt1-x843.google.com with SMTP id 7so12326154qtp.1 for ; Tue, 08 Dec 2020 08: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=Dl/Aw2BmPy+Fr31OlV+WjvuybjetsFQpW6bH+5Wn9dY=; b=QUY08Avelz2ymYlxm/fMtVYQsYuzqJQxQwUc17txIZwi1GSyDgrI4u2GMoxWxdpo2b RTuKEISBaROx3lkuFYat4nq05hlACrDKK5fErZ/snRxPj7yvQ87gUoM7Br3OfKtXsGny rvQIFSjujRDvo9OcEe8XdqjEW5AXBl+/0VtmDBkZ8WZMUHYWGQARBs7p5rgt/zMSabLS NU1ZmKk5nlvovQmHZhDBmPUQg8lz5uU8Xf2G6yuEJg+/CmOa8YzHpf7zHKg9Fpu3aduM Gl+21ZotCDOJGSzcsLvULEjx5LWqHbG55sx51HG0BX6g2CW2/PnGdEHxWYKO8xoKzJIS sZJg== 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=Dl/Aw2BmPy+Fr31OlV+WjvuybjetsFQpW6bH+5Wn9dY=; b=hG3fP/5u1M9w/aot30ZHTVDnSp8IZ0SdV1ECmqFANx3blrXw3ctnmm+hUosHUbGPkx QjhnJ0rdo1Zhi0JxWBDHYvVq2jaxb02yMOFB8egpOTH3GG0adozGVSSdgxu1gXp5msmh 8BA+PIF3nkX4gpKogK5RcAiTxtwzK7dFTjmS8HPmUlqWAsS46mOLwOfgCm/UcxWXDzJ2 kP7G956zJ0HmPdGQsTL5glymZudPzT5ZaCmnXZ0yl/l1RvfbwfionrqzzGpItT2f7Mer N/JEgLBeXQdLfKWsmfbHRfZZX9DPc0O+k/RW4GrobPErOL3lxFVGpP8ZOe2riOxbfrrc a0Yg== X-Gm-Message-State: AOAM5334hc9fB5u8HT5pa/9zYYKJ9KsawLtqsPTAm1mJrZ0MJEril17p Ohb56sA+AK1N+cb8Y6QRvVsQfxkPsa0B5RcR X-Google-Smtp-Source: ABdhPJzwt0n/8dO6sbrEjpaej1C7uOnF4cpPfwMTrNYZeLLP3hehvjZ59/UrcFYRfJ8xr1YCNb65bg== X-Received: by 2002:ac8:4cde:: with SMTP id l30mr13252721qtv.144.1607444739594; Tue, 08 Dec 2020 08: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 y6sm5085897qkj.60.2020.12.08.08.25.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:38 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 45/52] btrfs: cleanup error handling in prepare_to_merge Date: Tue, 8 Dec 2020 11:23:52 -0500 Message-Id: <4f6363129586caea2cdfb84c1594c76ff713a773.1607444471.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This probably can't happen even with a corrupt file system, because we would have failed much earlier on than here. However there's no reason we can't just check and bail out as appropriate, so do that and convert the correctness BUG_ON() to an ASSERT(). Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index af9008a71ff4..b824ef069ac5 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1870,8 +1870,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 Tue Dec 8 16:23:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958987 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.7 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 988B2C2BB9A for ; Tue, 8 Dec 2020 16:26:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 758EB23A6C for ; Tue, 8 Dec 2020 16:26:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730494AbgLHQ0Y (ORCPT ); Tue, 8 Dec 2020 11:26:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730485AbgLHQ0W (ORCPT ); Tue, 8 Dec 2020 11:26:22 -0500 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABD90C0611CB for ; Tue, 8 Dec 2020 08:25:42 -0800 (PST) Received: by mail-qt1-x844.google.com with SMTP id y15so4742948qtv.5 for ; Tue, 08 Dec 2020 08: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=BL08xEovqds+clZTIcSTxCiWrXZFm6JdXsxnv9ahPRM=; b=E+mM1spaPfgGBJdxaXqO9qYXaIe8g9SiKzU+6JJkTvp3zKhEKCfaqxRE2PTDdWTNMB T2AYFSHI4QK8YWCnbDohNvn/7298l2lV6t4eeVp3Q42bOkqXiEk4BWpX6w2me3b41ffy agChP+/IylZegfU/d9LYldau11dVCI+yI0+W2KeagAe7LzxEBUREa97mCCAhMJ71SsS4 A5vdHPeuY5Y1iy3COI2rjUfV6AQXXImABEpnx4fnetrKNaZjlv6om86o6G+Cwno0PmwU D9EgvW9VpzyTBu63Ik1HzYyU3aApefhIJ2HCUZwdxHBVubMpFSrOe0qyPO400OB5xjW/ IzNg== 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=BL08xEovqds+clZTIcSTxCiWrXZFm6JdXsxnv9ahPRM=; b=OJgCSq8r+Ox8rIxT1mY7nUeLVjH2awOO5042j+BxQYuv44J+whFhmh9bS2aNpRrD2B iIoPo3wVsZrJSwB/Hm018ew3eJVnXxZL6C1qa3NAJI9kKpOvD++nCas46C9Xbni0xeS+ rLmdKUoEhHzanb0n6kcWAhMhGhQhKfHVFexpTQNy7dVcAD9+6c5AeGjV5tks+Ds0beFU 6KPIN7QxNWwbRb+iKWZHHXlW6Qcq2CouSSYStVAhk6NvmFodl6F4F0luIcLQXrhFnDSn 5R5ILXYNuJPvEpM+rrMiTtgjl2EZPApMfCVEt92HF7IPF9boSoIjpO54nNk77inf4vd3 A33A== X-Gm-Message-State: AOAM533fkyP2sepxLq9fRLHxT8cScPycuC8awmiXjcNYWnFHf+Y2NFbi yLe9WeoI4r/cGhg2DQEfThwfbfmFnpMbcK22 X-Google-Smtp-Source: ABdhPJzeArBPSFRrImTt5lqQboOX8AN2BEQBXgaYiJjiTOmMaABKv013OdnSj/ovio3G+RKck3N5Xw== X-Received: by 2002:ac8:3417:: with SMTP id u23mr30748384qtb.80.1607444741571; Tue, 08 Dec 2020 08:25:41 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id z20sm15207660qtb.31.2020.12.08.08.25.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:40 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 46/52] btrfs: handle extent corruption with select_one_root properly Date: Tue, 8 Dec 2020 11:23:53 -0500 Message-Id: <95f9219dcb2a42c448fc5ff4badeac6d6f8fa61a.1607444471.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In corruption cases we could have paths from a block up to no root at all, and thus we'll BUG_ON(!root) in select_one_root. Handle this by adding an ASSERT() for developers, and returning an error for normal users. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index b824ef069ac5..9a59adaf178c 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2199,7 +2199,17 @@ struct btrfs_root *select_one_root(struct btrfs_backref_node *node) cond_resched(); next = walk_up_backref(next, edges, &index); root = next->root; - BUG_ON(!root); + + /* + * This can occur if we have incomplete extent refs leading all + * the way up a particular path, in this case return -EUCLEAN. + * However leave as an ASSERT() for developers, because it could + * indicate a bug in the backref code. + */ + if (!root) { + ASSERT(0); + return ERR_PTR(-EUCLEAN); + } /* No other choice for non-shareable tree */ if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) @@ -2589,8 +2599,12 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, BUG_ON(node->processed); root = select_one_root(node); - if (root == ERR_PTR(-ENOENT)) { - update_processed_blocks(rc, node); + if (IS_ERR(root)) { + ret = PTR_ERR(root); + if (ret == -ENOENT) { + ret = 0; + update_processed_blocks(rc, node); + } goto out; } From patchwork Tue Dec 8 16:23:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958991 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.7 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 CCFFFC2BBCA for ; Tue, 8 Dec 2020 16:26:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A66F123AFA for ; Tue, 8 Dec 2020 16:26:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730489AbgLHQ0X (ORCPT ); Tue, 8 Dec 2020 11:26:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730486AbgLHQ0W (ORCPT ); Tue, 8 Dec 2020 11:26:22 -0500 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3647EC061749 for ; Tue, 8 Dec 2020 08:25:45 -0800 (PST) Received: by mail-qv1-xf2f.google.com with SMTP id j13so1080208qvi.8 for ; Tue, 08 Dec 2020 08: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:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ks8S6fmIdnffRKk53DpIusthhK43EixCopiMTYjdIP8=; b=xhy/crMWK4unVhTccoVAusOyAYeC0TZRyR+WoIDMmng04Vw5q8e8FMLuwjqEJHHGhW 0CUey8iA9MGmVPF2av3do2KW9SLbiueYLx1yrOCR8slEsSHli42BxXfUQTZCORPrEnji xn70a0/wdw83mf1PQ/jFtE/Ai5wu3R98muUoLW5+L4UiJFRiFvAVJGPpOEbAM+rgMruH QG6703PJb2lTNi9MF9uth2iN4GfUNl6qQ4pn6+8/N3/3Bn1QxE/dypnUD0czHIq2sqdX 7vnM797Cd/poUltNy0iIhgYilcpZfikI85Hjqo1ZF78d8i/cvfzv9pUL3XrAwqyqwux6 9BVA== 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=ks8S6fmIdnffRKk53DpIusthhK43EixCopiMTYjdIP8=; b=ihP6zlFUFYAAWHcG11fNuhVsj6s/wbY7tHVT1hcF1OmEsqU6q3CU6j/ami5YUrKVkb ukiyzjLZFi9Xg6acplrXJXK59ONHO2hi2/tiPQeSMa4N5JDf9q5fm0lTpLh13e68RJdW JABfr39WFOmWs75Wm38XHNUOMk1DRR1+PWbGLKWWUVILAV/Vf6N71QiSQpzNP8lDiRHC AKZfShxeYHB8ZVNCXvsn6DjCwhAhwee4PQWfI9+JV9wDKq4vOugkW5iEiX8WfCRCSbRA BklU+R2HdcODK4+/Mgq7ejl8G9unQIHz6Zn2l6UL1Y3IOdQQr4NSSyr0Fc16eR3GqVe/ 1F6g== X-Gm-Message-State: AOAM530FE02qZJ/39QggIBnsuib1cMOOZUoJSei65ukpLAQlq0miqaxu SI/j/XR889Y1Nz0PZYmksip7BeJMQwztncIl X-Google-Smtp-Source: ABdhPJwdtvBxxVr5S+DDJvR7MCdhYcgM+NWdEVhnYLm9KCmlGKDPuuBOVthnY7k5vQe5sMMihIJLhg== X-Received: by 2002:a0c:f2cd:: with SMTP id c13mr5794099qvm.11.1607444744110; Tue, 08 Dec 2020 08: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 b197sm14629480qkg.65.2020.12.08.08.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:42 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 47/52] btrfs: do proper error handling in merge_reloc_roots Date: Tue, 8 Dec 2020 11:23:54 -0500 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have a 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 9a59adaf178c..066d06575dbc 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1950,8 +1950,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 Tue Dec 8 16:23:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958989 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.7 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 35A20C19437 for ; Tue, 8 Dec 2020 16:26:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F413C23A6C for ; Tue, 8 Dec 2020 16:26:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729966AbgLHQ0U (ORCPT ); Tue, 8 Dec 2020 11:26:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726810AbgLHQ0T (ORCPT ); Tue, 8 Dec 2020 11:26:19 -0500 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02CBFC0613D6 for ; Tue, 8 Dec 2020 08:25:48 -0800 (PST) Received: by mail-qt1-x841.google.com with SMTP id f14so3768081qto.12 for ; Tue, 08 Dec 2020 08: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:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XJHfHNumCZ2vGouH5r+eUjB1N5c26k5zGROq6O6ca+o=; b=aLSIwvcN9TP1R25+ii5rVw7Cn+4gm35cNalOX5TQPssfyJd7DdJe2CXg6K97jcVuau zB9o9AybeVkGcV3nMw3Aym9v6x8OkuIa9FF36IvmvE2ll7hdZolmwgMBqllJdxB8/lA8 YUPUxWaZMLnTLg0s3YY7AMgCrvsJGE367aKwgOPVV0RLGtk0vKGGYtuBb8aVmteAzCMV nNyfr3BQHDeBFcNTU87X1g6LCO5AzYEv/G79S9W22iHcYKaFT6OseWBVvJOpHLDPqcU2 GnkpGI3s7RtTtj628///5MiiLhu92WCfrM87lyD8pEYwDa6xBZgumuzd7wfaMp05IcnN brcw== 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=XJHfHNumCZ2vGouH5r+eUjB1N5c26k5zGROq6O6ca+o=; b=R1IHoyEujXvVF8bPz0gUntmqxIZSi8PGbGGym1VR26jjvG9VxhNi7opWjfn3+g4TTN YGrSQJ3yQgRDoJoJeEzqs2S8iYgyn+W05x7UFVby/rvQDoQIkdopFjWT5KG0ijHsvZqf ps7bWoIF8rWIDkVZmmOrjS/ui9nuS7hLvRg2leA1dWFmI/Ydko24Z91q7h2vhywSbQHq oQE44oQKL/Bm1BDwpKC1N/3/vqU4sFrdehcErqr+OEEVacxTw2uv5db0JFm7g/hWH5Cs TFsYMC+EnPOCOpKyv9yzmnb18q36JUY+myP2nE3YDO8U1rI+DVDcGg8KwZLOolrzWNHW lTQg== X-Gm-Message-State: AOAM5305iID1sALFgS2uy/PtOT9sCTKONxX3J+CCIy7Plmay+uwYUP7A LAdnB1zM741NhhnIjvZm1TzESzh4HtCmXktc X-Google-Smtp-Source: ABdhPJwmE56W7Hq1DSfKxBx9kh8ym68CfPNF8A1uA0jq/GFqg3/zozbHfgkixZ7mTba8HcK+0RqBKQ== X-Received: by 2002:ac8:4e0e:: with SMTP id c14mr9788158qtw.71.1607444746925; Tue, 08 Dec 2020 08:25:46 -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 c13sm758139qtm.37.2020.12.08.08.25.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:46 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 48/52] btrfs: check return value of btrfs_commit_transaction in relocation Date: Tue, 8 Dec 2020 11:23:55 -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 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 066d06575dbc..3ecb09c5d65f 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1905,7 +1905,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; @@ -3440,8 +3440,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) @@ -3600,7 +3599,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) From patchwork Tue Dec 8 16:23:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958995 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.7 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 85F41C433FE for ; Tue, 8 Dec 2020 16:26:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F5EA23A75 for ; Tue, 8 Dec 2020 16:26:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730500AbgLHQ00 (ORCPT ); Tue, 8 Dec 2020 11:26:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730492AbgLHQ0Z (ORCPT ); Tue, 8 Dec 2020 11:26:25 -0500 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D7ACC06179C for ; Tue, 8 Dec 2020 08:25:51 -0800 (PST) Received: by mail-qk1-x741.google.com with SMTP id z188so16427525qke.9 for ; Tue, 08 Dec 2020 08: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=kNOtAisk0hN8omuiH6mLCn6ZjHq8m2odxb3m+HFyoKQ=; b=dmzcHZQdj4y8kD1Pgv8kWgTgRjcXiUl03R2p85ersx2/w9+dVe8Sz0hdMABzlnRvcx aXOBQ2Ga2tMVS4DJMbtpIINstatgdo8mVmd31ahvGZj2ZjdQ7G+55maL54HkUxSt9QYA tPrwF/SmxSYBfD0PpSVGRv35RP5kSQ3GFOSY0oGBrGEI1mnsorRTkziaXHBq6kwKOSGC XLvJvMfI/egtGny74q/N2Kc75tM/SJ/KLzZ5DI92wS8OEt/2UC6/rr6jK7reMMBMGzG/ q0CeNcbRZvbe0mQj68YCqd7ZTb/SNdY9dyJbF7UDb1UNIuWL9gjyMKlu+EGxxlRNs8zU tQsQ== 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=kNOtAisk0hN8omuiH6mLCn6ZjHq8m2odxb3m+HFyoKQ=; b=V7gyRN7/EA4gbYWUxA3aWudQzOEOvfm5esKmKx9SkYBDb/mRkpImosjjVnzAXfWnGU oqdg1lca41YuhQ2ATo97GTPb3FvMs14Gxd2vPVdcR5viUrvLy6/BHLOxGldj/N36TTvl fgJ3mGEz+Eb4QJfxjO7ALA0cPGo6XONi2lBfZQy8Zp22ucuaMPsPxmx0QuZvTb4lBwtM 4P8wYyPS/rcY7JV2AJ3G9n01insca28Lhdu9c4RyY1o9A76qspG/LUWqqTLe8ikgf5dg tvzAM26xSWwn2117PzxkNXe8/n2cDNvAtL9QuxxXGMJZ/XtEfBZkUwjCX9HT1YoTUFJX n3ew== X-Gm-Message-State: AOAM530mbQqNrpDo6eQVZwu4ejcvFc5Kk7yn5ZhjsIbHyv5niQwEipGE qHN3dNwoxfB89rsGKxk7tJt38lT9x0S4b4db X-Google-Smtp-Source: ABdhPJwppF1YBjkZXLsiZlg/o6yRzZzADqr3nbOdtmTWGG2VJACPMt8RaPe1tZC3q1V3su+Zgjbc8g== X-Received: by 2002:a05:620a:6c8:: with SMTP id 8mr5577454qky.176.1607444750527; Tue, 08 Dec 2020 08: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 z125sm14778802qke.18.2020.12.08.08.25.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:49 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Zygo Blaxell Subject: [PATCH v6 49/52] btrfs: do not WARN_ON() if we can't find the reloc root Date: Tue, 8 Dec 2020 11:23:56 -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 Any number of things could have gone wrong, like ENOMEM or EIO, so don't WARN_ON() if we're unable to find the reloc root in the backref code. Reported-by: Zygo Blaxell Signed-off-by: Josef Bacik --- fs/btrfs/backref.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 56f7c840031e..525815d2914b 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -2617,7 +2617,7 @@ static int handle_direct_tree_backref(struct btrfs_backref_cache *cache, /* Only reloc backref cache cares about a specific root */ if (cache->is_reloc) { root = find_reloc_root(cache->fs_info, cur->bytenr); - if (WARN_ON(!root)) + if (!root) return -ENOENT; cur->root = root; } else { From patchwork Tue Dec 8 16:23:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958997 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.7 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 35994C4361B for ; Tue, 8 Dec 2020 16:26:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1562323A6C for ; Tue, 8 Dec 2020 16:26:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730501AbgLHQ02 (ORCPT ); Tue, 8 Dec 2020 11:26:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730499AbgLHQ00 (ORCPT ); Tue, 8 Dec 2020 11:26:26 -0500 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B480DC0611CC for ; Tue, 8 Dec 2020 08:25:54 -0800 (PST) Received: by mail-qk1-x743.google.com with SMTP id z188so16427723qke.9 for ; Tue, 08 Dec 2020 08: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:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HfzjWbCJlAt1M6Gp5Xa+5CFjYIiFZggMzPSt43v5UTI=; b=HBY2eiOUxu8XZk3IBqldMAM9+Wc6IWRchVeK8PL7UhcxSbDFLSpezVi7Lh0yjyHGkz RQ07c/uCcdbhXD71TsLwzPSDvh3ORj3HqTvzIUi1f5p7HgvI+fOpns0bMJAoMdVY8EQy gbLZqVF3bbMp1l/vVunmnFl8qt8qIEFU8oHRGgOisVzkgPdiECcAe3hWC5zug2GzP84B kNtCmzPKhgApdjX1tFxAGwmJmAw1w2pkCqlIG7OZ8FWugjuKj3QcTDNA9odA+KthzwwN ziO97qmwgfH30WWkUacIb/YjVWdqUiIo6jGayzRr2ytvXHm0BreQRoMCZf5wkSF7V2Bc y3yw== 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=HfzjWbCJlAt1M6Gp5Xa+5CFjYIiFZggMzPSt43v5UTI=; b=C1QFZE0wHITb21MFGjP+hkRnbf1zWbUP4QbNKEm+uUuwovKANj87L2+p+COcdoDG0o LPmYTD0dUW8AL7lLMVoS70mN9M20d2jHYmr8NTfaA0HyOeeoG0VvmTmhUpQ2GCFJi2bd qiYUswZawPZOqNGgAN21tGQYssMGJnimh3eYDj1rfjmxmUSX9ofUkcwCafEDw1/s6jrC P3fMxFRULdPhv9yDj3eOStVs836HaMCouWTPIORMr7IYbCCYd7OIwaLXkGZMhcija7bA /YOlVzXTr2mx0t5aW7fE98Uz9I5rSmxGjmyMQmAh1DGpQybwbUhxS/DPm1ZYdcGkB4nj 4wdA== X-Gm-Message-State: AOAM530okfpVkcVqaRTskVeRlmDoE1lLxgtJv6jIcUmXMK2tAxGxz5JX nVh3ECOtCgQYPFxpRcrCd9lA5y/ErA852ts+ X-Google-Smtp-Source: ABdhPJzLTqXapQp9oM8zI7LkGBfFG+X8TOEg6xs7Pvp3tkfngVJJF4l9O2m34efgAJuQYmoxKl95WQ== X-Received: by 2002:a37:9b04:: with SMTP id d4mr6160625qke.408.1607444753631; Tue, 08 Dec 2020 08: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 h1sm12809019qtr.1.2020.12.08.08.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:52 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 50/52] btrfs: print the actual offset in btrfs_root_name Date: Tue, 8 Dec 2020 11:23:57 -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're supposed to print the root_key.offset in btrfs_root_name in the case of a reloc root, not the objectid. Fix this helper to take the key so we have access to the offset when we need it. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 2 +- fs/btrfs/print-tree.c | 10 +++++----- fs/btrfs/print-tree.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 765deefda92b..0eeadf624dfb 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1457,7 +1457,7 @@ void btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info) root = list_first_entry(&fs_info->allocated_roots, struct btrfs_root, leak_list); btrfs_err(fs_info, "leaked root %s refcount %d", - btrfs_root_name(root->root_key.objectid, buf), + btrfs_root_name(&root->root_key, buf), refcount_read(&root->refs)); while (refcount_read(&root->refs) > 1) btrfs_put_root(root); diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c index fe5e0026129d..b8137dbf6a3a 100644 --- a/fs/btrfs/print-tree.c +++ b/fs/btrfs/print-tree.c @@ -26,22 +26,22 @@ static const struct root_name_map root_map[] = { { BTRFS_DATA_RELOC_TREE_OBJECTID, "DATA_RELOC_TREE" }, }; -const char *btrfs_root_name(u64 objectid, char *buf) +const char *btrfs_root_name(struct btrfs_key *key, char *buf) { int i; - if (objectid == BTRFS_TREE_RELOC_OBJECTID) { + if (key->objectid == BTRFS_TREE_RELOC_OBJECTID) { snprintf(buf, BTRFS_ROOT_NAME_BUF_LEN, - "TREE_RELOC offset=%llu", objectid); + "TREE_RELOC offset=%llu", key->offset); return buf; } for (i = 0; i < ARRAY_SIZE(root_map); i++) { - if (root_map[i].id == objectid) + if (root_map[i].id == key->objectid) return root_map[i].name; } - snprintf(buf, BTRFS_ROOT_NAME_BUF_LEN, "%llu", objectid); + snprintf(buf, BTRFS_ROOT_NAME_BUF_LEN, "%llu", key->objectid); return buf; } diff --git a/fs/btrfs/print-tree.h b/fs/btrfs/print-tree.h index 78b99385a503..802628dd1a6e 100644 --- a/fs/btrfs/print-tree.h +++ b/fs/btrfs/print-tree.h @@ -11,6 +11,6 @@ void btrfs_print_leaf(struct extent_buffer *l); void btrfs_print_tree(struct extent_buffer *c, bool follow); -const char *btrfs_root_name(u64 objectid, char *buf); +const char *btrfs_root_name(struct btrfs_key *key, char *buf); #endif From patchwork Tue Dec 8 16:23:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958985 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.7 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 53FEFC2BB40 for ; Tue, 8 Dec 2020 16:26:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24E5C23A6C for ; Tue, 8 Dec 2020 16:26:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730484AbgLHQ0W (ORCPT ); Tue, 8 Dec 2020 11:26:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726810AbgLHQ0V (ORCPT ); Tue, 8 Dec 2020 11:26:21 -0500 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BA41C0611CD for ; Tue, 8 Dec 2020 08:25:56 -0800 (PST) Received: by mail-qk1-x743.google.com with SMTP id c7so8157925qke.1 for ; Tue, 08 Dec 2020 08: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:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=xDWc0fpV3efm1xVsQoYUGj3PoMHicnjEzg/gWc5cKb8=; b=CBbE5pY9qhdk0lUB+Bm04YU9PDNg2/zCpuPmzHtWL3YGaYN0A60Xd341QvU9jtIHry BbKtjN5wvRUkVYq9WzpUT6b48DoA2111S9TmxC7hVutx4X7JGACtxagk5yi4clL7Gig4 jAwTmkFCTGCdzQ3qnRLfC6xFZ3D8Cwp7VVVwnFAZrcI6KY1JlwF5Ok66fMUJKYeI53a0 eYymBVcNfuadTkj5zYoBzlbZ5QEPUyOkJhMC8uUgejAS2leuhKz6OHXBUyzLq/1bceik iEus518YIOVxlrW9q11YarqVQ7nKua1VkmsDa+gI8Zf2oqMqwQjktEY6E+4Oni0murWg OFHw== 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=xDWc0fpV3efm1xVsQoYUGj3PoMHicnjEzg/gWc5cKb8=; b=Ko97nZ+BGGRCIl10PJDHiJcaL7Fs1qOoNBpoDoMEpkFZosh+o2BQeLR2cLWrY5HU8Q xdN3O+h7EAbTQlvNsX3tF9zIC1OAmci8+/vQUcNp7iJvxNbNzDwQuZgjySu7vk89Wv3y EN3AD/giAzJ2iGVw/o7xf5SnLh65rr2oSFkIMXAcR8cMX1URQFMtEKUF2jkR0JB90f7d JmPKL6+BGIV2g3OqfBQLsgr2c3QlTVKZILekITRxR57wki1EaB6e5DdlZU9+BbK1kHvY 35Sv8Tg4Uwi5KX2alfHliVzurz3VRzGUet6pnHa2G/ohD7oqIwk+3U9yLXksRI7LgGCV DcJQ== X-Gm-Message-State: AOAM5329F69GR4FZOkSaRa3Omhy0ya0f/pdkX/pvCj1K2bAiufONyByq 7oJTjHMtosErze7aEXPHD3Vq7hRzQhvqPaPH X-Google-Smtp-Source: ABdhPJxcoBchCx6ZGRiGJD8OT0r3xJtuxXSwJIXPHsFZ9KkpdzzRlzGe1rag6EXaTChLVSb4bT1dMg== X-Received: by 2002:a37:b642:: with SMTP id g63mr30898085qkf.297.1607444755554; Tue, 08 Dec 2020 08:25:55 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id l20sm1273808qtu.25.2020.12.08.08.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:54 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 51/52] btrfs: fix reloc root leak with 0 ref reloc roots on recovery Date: Tue, 8 Dec 2020 11:23:58 -0500 Message-Id: <171de0b5ee4bc8aabf463fc0ed759da0559e3781.1607444471.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 When recovering a relocation, if we run into a reloc root that has 0 refs we simply add it to the reloc_control->reloc_roots list, and then clean it up later. The problem with this is __del_reloc_root() doesn't do anything if the root isn't in the radix tree, which in this case it won't be because we never call __add_reloc_root() on the reloc_root. This exit condition simply isn't correct really. During normal operation we can remove ourselves from the rb tree and then we're meant to clean up later at merge_reloc_roots() time, and this happens correctly. During recovery we're depending on free_reloc_roots() to drop our references, but we're short-circuiting. Fix this by continuing to check if we're on the list and dropping ourselves from the reloc_control root list and dropping our reference appropriately. Change the corresponding BUG_ON() to an ASSERT() that does the correct thing if we aren't in the rb tree. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 3ecb09c5d65f..9f16e9932595 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -671,9 +671,7 @@ static void __del_reloc_root(struct btrfs_root *root) RB_CLEAR_NODE(&node->rb_node); } spin_unlock(&rc->reloc_root_tree.lock); - if (!node) - return; - BUG_ON((struct btrfs_root *)node->data != root); + ASSERT(!node || (struct btrfs_root *)node->data == root); } /* From patchwork Tue Dec 8 16:23:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11958999 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.7 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 BA39FC2BBCD for ; Tue, 8 Dec 2020 16:26:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F4F323A75 for ; Tue, 8 Dec 2020 16:26:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730491AbgLHQ0X (ORCPT ); Tue, 8 Dec 2020 11:26:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730487AbgLHQ0W (ORCPT ); Tue, 8 Dec 2020 11:26:22 -0500 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00EC9C0619D2 for ; Tue, 8 Dec 2020 08:25:59 -0800 (PST) Received: by mail-qk1-x743.google.com with SMTP id q22so16442864qkq.6 for ; Tue, 08 Dec 2020 08: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=7YyqnduuKqEUVKiAG3eGPq7ah87Sv4iF9G8iHqvfpig=; b=kZNVCHmfBXa3eBOPxkXQE9CHd6tVspJKyVihTChcvPzDfP3UHL1/xAOwKZ5qCkKbiD ETxqmDi0KOjwfzStGxTh0MNjkKCSQ5ojd7w6XakB6LyMqNdISRMv6bM6xCtQj7l9SSkU sEWAUNkTvnOKN2C46s9fhQfAZ7YgrzWNMuiIqkQCyO84KKyRw+0VYKuLESzkJT/MbyoV ujGTzqD4aCPrk+mTKSRplsuHOstjCtFT03V2QEAGi5psSmcDWieRSdCTLdRAgx/hDS/p L1Y/NTKgl+wuZFHDxdFpl/UGfesCcvJJeiO69aOLF24QQc5kYEUdYY7INz3V7JlO+A11 6ldQ== 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=7YyqnduuKqEUVKiAG3eGPq7ah87Sv4iF9G8iHqvfpig=; b=TvOhMvMw6PMKhngPrlvtZ5cKBm6bAcMw1y0cVhfssiIKkIyNPFYRjI3es4znWTYL5T O/tv5HnWJ9wiROC0FG+ByULCwx4RV1HrU+eW+pVqb2XdFmbLls2OoCBR8IzjRZGrmfse 1d5WK0rb2RY80KMpBE75cFRfbujwgsZKT/r1qMsO0QKJkD+qNZsuYqqTacmKE8qsGNeu vK2XsHA7ruYOthHv2U/NrQZ3kf+tq4LufH6MVZ04bHMQA4d+aCSGFa/1ctJQ/rgbAbTV ZRiwgwe0YpPkVtb/VJazhlTbbItrQcOMZY0FdV0RsXj3jlNHBI7qL7+J1LqjIao6dO+x Z6sQ== X-Gm-Message-State: AOAM532nqNX510iTkZ563tB/P2D1eyeqUvLaBf/zmnFY6nNIJyZ42Kx+ 9sWPT4hmfyknMZd+6asDrFzXrp0MQbm/WV2q X-Google-Smtp-Source: ABdhPJwfSRmLivK7AXrO3CLSNX/YIunBFpUJ2TG5tcXMaMmLrbTWkLep5D1hCA1koOa2W4YihzBNhA== X-Received: by 2002:a37:45d2:: with SMTP id s201mr15347318qka.326.1607444757576; Tue, 08 Dec 2020 08: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 97sm14003466qte.34.2020.12.08.08.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 08:25:56 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v6 52/52] btrfs: splice remaining dirty_bg's onto the transaction dirty bg list Date: Tue, 8 Dec 2020 11:23:59 -0500 Message-Id: <8ea7a419e6f6070d3e85583dc225bb710a61492e.1607444471.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 While doing error injection testing with my relocation patches I hit the following ASSERT() assertion failed: list_empty(&block_group->dirty_list), in fs/btrfs/block-group.c:3356 ------------[ cut here ]------------ kernel BUG at fs/btrfs/ctree.h:3357! invalid opcode: 0000 [#1] SMP NOPTI CPU: 0 PID: 24351 Comm: umount Tainted: G W 5.10.0-rc3+ #193 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014 RIP: 0010:assertfail.constprop.0+0x18/0x1a RSP: 0018:ffffa09b019c7e00 EFLAGS: 00010282 RAX: 0000000000000056 RBX: ffff8f6492c18000 RCX: 0000000000000000 RDX: ffff8f64fbc27c60 RSI: ffff8f64fbc19050 RDI: ffff8f64fbc19050 RBP: ffff8f6483bbdc00 R08: 0000000000000000 R09: 0000000000000000 R10: ffffa09b019c7c38 R11: ffffffff85d70928 R12: ffff8f6492c18100 R13: ffff8f6492c18148 R14: ffff8f6483bbdd70 R15: dead000000000100 FS: 00007fbfda4cdc40(0000) GS:ffff8f64fbc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fbfda666fd0 CR3: 000000013cf66002 CR4: 0000000000370ef0 Call Trace: btrfs_free_block_groups.cold+0x55/0x55 close_ctree+0x2c5/0x306 ? fsnotify_destroy_marks+0x14/0x100 generic_shutdown_super+0x6c/0x100 kill_anon_super+0x14/0x30 btrfs_kill_super+0x12/0x20 deactivate_locked_super+0x36/0xa0 cleanup_mnt+0x12d/0x190 task_work_run+0x5c/0xa0 exit_to_user_mode_prepare+0x1b1/0x1d0 syscall_exit_to_user_mode+0x54/0x280 entry_SYSCALL_64_after_hwframe+0x44/0xa9 This happened because I injected an error in btrfs_cow_block() while running the dirty block groups. When we run the dirty block groups, we splice the list onto a local list to process. However if an error occurs, we only cleanup the transactions dirty block group list, not any pending block groups we have on our locally spliced list. Fix this by splicing the list back onto the transactions dirty block group list, so any remaining block groups are cleaned up. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/block-group.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 0886e81e5540..5cfa52b1a3b8 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2685,6 +2685,9 @@ int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans) } spin_unlock(&cur_trans->dirty_bgs_lock); } else if (ret < 0) { + spin_lock(&cur_trans->dirty_bgs_lock); + list_splice_init(&dirty, &cur_trans->dirty_bgs); + spin_unlock(&cur_trans->dirty_bgs_lock); btrfs_cleanup_dirty_bgs(cur_trans, fs_info); }