From patchwork Mon Sep 27 18:05:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12520549 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96B1CC433EF for ; Mon, 27 Sep 2021 18:05:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A93460EE2 for ; Mon, 27 Sep 2021 18:05:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235699AbhI0SG5 (ORCPT ); Mon, 27 Sep 2021 14:06:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234406AbhI0SG4 (ORCPT ); Mon, 27 Sep 2021 14:06:56 -0400 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85590C061575 for ; Mon, 27 Sep 2021 11:05:18 -0700 (PDT) Received: by mail-qt1-x832.google.com with SMTP id r1so17441448qta.12 for ; Mon, 27 Sep 2021 11:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QtogRrVq3vXzSD+4o74FGhm0GYNF2lRVr3ezibxXP90=; b=FihfNDmCmYoG4++vjKTuaCG4nDuVy+zx1s9a+boG3wni0IEOSf9F4/Ql4yGea3L0kb 3+4hwdGXepgUEswj6Gg/3mZB1ML3T7bgCg82ZXqlX/WyDFVlXj+TB74pityB9jrHiu5q Z7f8BaxYbIkjOSHyS4cQ1zwEK+10BRnkoW77f8BD3oshx+IGp2hF0JyzhV2DO+c1tmYh EWD4R9U+P0G8hH5LQSpDyJdVnODoAzdPdPzGcXzOpFMoh7WsRSXD8pGOCo85BZ40Ywjg gjLJmEC2DZSaX7saLZptbq84Uf7CjJ3tfoenvzgJ9u5PgeU6IiSlsRV/JBc/6LXXpBzY R7ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QtogRrVq3vXzSD+4o74FGhm0GYNF2lRVr3ezibxXP90=; b=ttfAWaTlIt5zcji2uU7U6bRrfEeY4xz2KUZLOxWJdp4hE1KMnJS01H2S4F4HPMWd3d u1QYHqo3XwElX2P7eDVuf5B8QXfv8vwP0UkzKDoqWyB4jYdeLo04sCrbWjWpEOIXEO7F UOdd4zkIEOcwP2KYLsaIhfAu7MQX42U2EMI68blnSLlpmVdB8qO125ygE81qbritTjBi CifIybnvT4GUwOQJ29Z2RxA2EHV3H12iujTbIEpNoh6xQkMp+d51Pi/5iMv+Qa7RKjhS aVH5IEr79/RgAdWzNkAnt/OsaH1RYWjAGR1r7fTFPpD10mXC1sreJBz92niSQkiQnmLa c/FQ== X-Gm-Message-State: AOAM532wkrRSTERYlyABAou5QSgVvnlQc/F0pytgF7X6EHEppcCE+e77 2vNz8a8+4024t67IDAMWYD9rI9zLqOjnyA== X-Google-Smtp-Source: ABdhPJyrfBKjHjnC0/2egPihqzm9AgrE4calOz6TjTuLdoPEojtVR0RElW8+E4RGilyHFL76F0w7jw== X-Received: by 2002:ac8:13c5:: with SMTP id i5mr1244630qtj.68.1632765917442; Mon, 27 Sep 2021 11:05:17 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id x9sm7861780qkm.102.2021.09.27.11.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 11:05:17 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Johannes Thumshirn Subject: [PATCH v3 1/5] btrfs: change handle_fs_error in recover_log_trees to aborts Date: Mon, 27 Sep 2021 14:05:10 -0400 Message-Id: <5c30fe9cce106cf33e5d0b3ce74ff628a90724c3.1632765815.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org During inspection of the return path for replay I noticed that we don't actually abort the transaction if we get a failure during replay. This isn't a problem necessarily, as we properly return the error and will fail to mount. However we still leave this dangling transaction that could conceivably be committed without thinking there was an error. We were using btrfs_handle_fs_error() here, but that pre-dates the transaction abort code. Simply replace the btrfs_handle_fs_error() calls with transaction aborts, so we still know where exactly things went wrong, and add a few in some other un-handled error cases. Reviewed-by: Johannes Thumshirn Signed-off-by: Josef Bacik --- fs/btrfs/tree-log.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 30590ddd69ac..e0c2d4c7f939 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -6527,8 +6527,7 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree) ret = btrfs_search_slot(NULL, log_root_tree, &key, path, 0, 0); if (ret < 0) { - btrfs_handle_fs_error(fs_info, ret, - "Couldn't find tree log root."); + btrfs_abort_transaction(trans, ret); goto error; } if (ret > 0) { @@ -6545,8 +6544,7 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree) log = btrfs_read_tree_root(log_root_tree, &found_key); if (IS_ERR(log)) { ret = PTR_ERR(log); - btrfs_handle_fs_error(fs_info, ret, - "Couldn't read tree log root."); + btrfs_abort_transaction(trans, ret); goto error; } @@ -6574,8 +6572,7 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree) if (!ret) goto next; - btrfs_handle_fs_error(fs_info, ret, - "Couldn't read target root for tree log recovery."); + btrfs_abort_transaction(trans, ret); goto error; } @@ -6583,14 +6580,15 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree) ret = btrfs_record_root_in_trans(trans, wc.replay_dest); if (ret) /* The loop needs to continue due to the root refs */ - btrfs_handle_fs_error(fs_info, ret, - "failed to record the log root in transaction"); + btrfs_abort_transaction(trans, ret); 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, path); + if (ret) + btrfs_abort_transaction(trans, ret); } if (!ret && wc.stage == LOG_WALK_REPLAY_ALL) { @@ -6607,6 +6605,8 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree) * could only happen during mount. */ ret = btrfs_init_root_free_objectid(root); + if (ret) + btrfs_abort_transaction(trans, ret); } wc.replay_dest->log_root = NULL; From patchwork Mon Sep 27 18:05:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12520551 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3981EC433FE for ; Mon, 27 Sep 2021 18:05:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D8B860F11 for ; Mon, 27 Sep 2021 18:05:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235790AbhI0SG7 (ORCPT ); Mon, 27 Sep 2021 14:06:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234406AbhI0SG6 (ORCPT ); Mon, 27 Sep 2021 14:06:58 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FBB0C061575 for ; Mon, 27 Sep 2021 11:05:20 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id d207so38118499qkg.0 for ; Mon, 27 Sep 2021 11:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=XPAAGt6vzR3g6/CYC2JpBnQJOx1u0gYDwy+73WsVB4o=; b=FNg4QsTuhfjdoYR4LhefjuptR6OEHQVf8xeWchyIdWAJh6MxPO/rde9ndAt1y/XrRR BB/63qPcxUDMAJR0f6GGsA7BSiLYUw5u1fxiCAtZtdOCcrvcoAdRH8gRnER+oTvVhU4s p0BiT+5+5WyzfcYbTrFu6QtBlA/2jnyaKd9r9EIxVqrD7S9+4ONr1o9kQfarJDEDKePT f2qteEYe2UGfW2Mcp8T40F5lB+JlB/0LEPs5sbU0x0BV1BZf7n7f1uO+yqfXGLvSYlzh 3g5d94VGC4/hnHtkEtD1LjsYni+8Te2Relaj5afxVPuHKVY7cm/wkSnaQxckR4hUhCz6 ZGDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XPAAGt6vzR3g6/CYC2JpBnQJOx1u0gYDwy+73WsVB4o=; b=qFQ8CYqFXuVIE6C6DL/506CauMDPOZvsBiHJ+HSX6RC1AoNOjZeiwioeDNMvttOQQS pbNKCRS3rhiRczEt7Q1lMbiSUrCtzUjyVGeuXP1Y4/6P0Kfk0BEWAk1UgqUWw9MWSUDL 1nV6drQGWAqWPI7iU8tzym6oc6kLAyCf3+uHtoWTCva6Txbjyz/lrq8pvBXP+O9WG0/R /IBruBIcWc+AfoSS8dHETb5rf10JvZ59olou5sAduFgQlKwI3+g9XBFjfK16NyZRhNdf oR6ByzkXcwNX2a8rCDN4WsNWjU+p/UehZ9H/B3B5JSSuncs75zgqyfyKSxIuQVItM0cf RPOA== X-Gm-Message-State: AOAM531jebyrnJFj3u2gsEzjrKVX1leKx8iRE29Z5GnkShOozjnbhfgc TFsP4Bdz8HNHjJt4f4lZZsPluDmMSiQhXw== X-Google-Smtp-Source: ABdhPJzbux48hRUpgICHYo2EGVEljeURBDb8wmprlGbtjKeRcC7RdUJ0f7p3zzDqb//Yv/r9bfEvkw== X-Received: by 2002:a05:620a:430c:: with SMTP id u12mr1283087qko.439.1632765918988; Mon, 27 Sep 2021 11:05:18 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id u12sm11143446qtw.73.2021.09.27.11.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 11:05:18 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 2/5] btrfs: change error handling for btrfs_delete_*_in_log Date: Mon, 27 Sep 2021 14:05:11 -0400 Message-Id: <4df6bd8d64bf81e098101e35a0c7482485ef4e67.1632765815.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Currently we will abort the transaction if we get a random error (like -EIO) while trying to remove the directory entries from the root log during rename. However the log sync stuff doesn't actually honor the transaction abort flag, it'll happily commit the log even if we've aborted the transaction for reasons related to the log, which is a pretty bad problem. Fix this by making these functions void, as we don't actually care if this fails. Instead mark the log as requiring a full commit on error. This will keep us from committing this bad log, and if we fsync we'll force a full transaction commit and have a consistent file system. Signed-off-by: Josef Bacik --- fs/btrfs/inode.c | 16 +++------------- fs/btrfs/tree-log.c | 41 ++++++++++++++--------------------------- fs/btrfs/tree-log.h | 16 ++++++++-------- 3 files changed, 25 insertions(+), 48 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index a643be30c18a..03a843b9659b 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4108,19 +4108,9 @@ static int __btrfs_unlink_inode(struct btrfs_trans_handle *trans, goto err; } - ret = btrfs_del_inode_ref_in_log(trans, root, name, name_len, inode, - dir_ino); - if (ret != 0 && ret != -ENOENT) { - btrfs_abort_transaction(trans, ret); - goto err; - } - - ret = btrfs_del_dir_entries_in_log(trans, root, name, name_len, dir, - index); - if (ret == -ENOENT) - ret = 0; - else if (ret) - btrfs_abort_transaction(trans, ret); + btrfs_del_inode_ref_in_log(trans, root, name, name_len, inode, + dir_ino); + btrfs_del_dir_entries_in_log(trans, root, name, name_len, dir, index); /* * If we have a pending delayed iput we could end up with the final iput diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index e0c2d4c7f939..720723611875 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -3500,10 +3500,10 @@ static bool inode_logged(struct btrfs_trans_handle *trans, * This optimizations allows us to avoid relogging the entire inode * or the entire directory. */ -int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - const char *name, int name_len, - struct btrfs_inode *dir, u64 index) +void btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + const char *name, int name_len, + struct btrfs_inode *dir, u64 index) { struct btrfs_root *log; struct btrfs_dir_item *di; @@ -3513,11 +3513,11 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, u64 dir_ino = btrfs_ino(dir); if (!inode_logged(trans, dir)) - return 0; + return; ret = join_running_log_trans(root); if (ret) - return 0; + return; mutex_lock(&dir->log_mutex); @@ -3565,49 +3565,36 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, btrfs_free_path(path); out_unlock: mutex_unlock(&dir->log_mutex); - if (err == -ENOSPC) { + if (err < 0 && err != -ENOENT) btrfs_set_log_full_commit(trans); - err = 0; - } else if (err < 0 && err != -ENOENT) { - /* ENOENT can be returned if the entry hasn't been fsynced yet */ - btrfs_abort_transaction(trans, err); - } - btrfs_end_log_trans(root); - - return err; } /* see comments for btrfs_del_dir_entries_in_log */ -int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - const char *name, int name_len, - struct btrfs_inode *inode, u64 dirid) +void btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + const char *name, int name_len, + struct btrfs_inode *inode, u64 dirid) { struct btrfs_root *log; u64 index; int ret; if (!inode_logged(trans, inode)) - return 0; + return; ret = join_running_log_trans(root); if (ret) - return 0; + return; log = root->log_root; mutex_lock(&inode->log_mutex); ret = btrfs_del_inode_ref(trans, log, name, name_len, btrfs_ino(inode), dirid, &index); mutex_unlock(&inode->log_mutex); - if (ret == -ENOSPC) { + if (ret < 0 && ret != -ENOENT) btrfs_set_log_full_commit(trans); - ret = 0; - } else if (ret < 0 && ret != -ENOENT) - btrfs_abort_transaction(trans, ret); btrfs_end_log_trans(root); - - return ret; } /* diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h index 3ce6bdb76009..f6811c3df38a 100644 --- a/fs/btrfs/tree-log.h +++ b/fs/btrfs/tree-log.h @@ -70,14 +70,14 @@ int btrfs_recover_log_trees(struct btrfs_root *tree_root); int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans, struct dentry *dentry, struct btrfs_log_ctx *ctx); -int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - const char *name, int name_len, - struct btrfs_inode *dir, u64 index); -int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - const char *name, int name_len, - struct btrfs_inode *inode, u64 dirid); +void btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + const char *name, int name_len, + struct btrfs_inode *dir, u64 index); +void btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + const char *name, int name_len, + struct btrfs_inode *inode, u64 dirid); void btrfs_end_log_trans(struct btrfs_root *root); void btrfs_pin_log_trans(struct btrfs_root *root); void btrfs_record_unlink_dir(struct btrfs_trans_handle *trans, From patchwork Mon Sep 27 18:05:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12520553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 033BFC433F5 for ; Mon, 27 Sep 2021 18:05:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF2A760EE2 for ; Mon, 27 Sep 2021 18:05:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235838AbhI0SHM (ORCPT ); Mon, 27 Sep 2021 14:07:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234406AbhI0SG7 (ORCPT ); Mon, 27 Sep 2021 14:06:59 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A2F7C061575 for ; Mon, 27 Sep 2021 11:05:21 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id c20so17486084qtb.2 for ; Mon, 27 Sep 2021 11:05:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=C+sRnEFpAnxheHvTzwYujbZH0DCNCRodpEoYDZA+Zp4=; b=e/q7+d0qd4yJ8NMFrFPNOoRRVeoiDHNqQu6423XkKMm3Sw317OeqCUsXReqITu9WSz vFf0lZ5JLdbS0OA3LHJrG9T9hdscUkHSHVatOUT1+kvKX5165neDXuUfwPNgVeB8BSVf 3w3BLY0ySHN2sFPMrg27kZTEN68tUPqU+IQ06blzj9TaGfmIz3o9W4P0y1Z6g0GCaJx6 JJRhyI/RNLAO8s+aqE67eCFP4tHp/uXBlWWS7Im7I4L5yxZN0WtdP64WYx3kdaYU8+Hy C7SV3RRqErQ9xUMg9y7kOWPMDJ0dG4Fn2Ln55UiSWaAefqhpI9UbNF1Ej2ALMhUJgyX8 Zcmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C+sRnEFpAnxheHvTzwYujbZH0DCNCRodpEoYDZA+Zp4=; b=OaJXI2CAyKyYVQnmafbjbUWoIbZ0PJ+ygMnMMVsmYurylKvmmDGK+Kc6ImPu5IIGUW 5YbJDj381SFOyJ5GrxGmw8fNaZ31VTyh0Yvl2+Ik6jr3xe8XW2gycI2J00a1OoVJ0Bt7 qqMWDWPrK1uOa2jOnk2VIAKLE9b7DR9xxes3Otl3aEjzN6mp3v7orX4ifQGelZsY3AmG LjJi/zxRAYfUzXPY+nSvQQsFUOtwtvNe8nEQ7L23gr9xN7xsI0IXmJ3zk3iIAYtLKWTN 8kPaZkdffv3FACP6e/59QjBcrWi2sJK1UkkNdOTUvXzuxC+kQbClqdtpTy/uVzwVGkTO Wkpg== X-Gm-Message-State: AOAM531LwR20z/aBhg46JfkzL653tGW3YRBuCWDNRimPCbpEDKg+a9UM FFhosiaLD0hpeQWLcut0qZGJx9Yhh0oWRg== X-Google-Smtp-Source: ABdhPJwHhqPc/HevZLcZERVDonbMGXDVF1rHAr823t8XQrKF5EVyaEOxIP2TZdTkj9TB9Vacb/p3TA== X-Received: by 2002:ac8:59cb:: with SMTP id f11mr1203529qtf.321.1632765920264; Mon, 27 Sep 2021 11:05:20 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id m68sm13155385qkb.105.2021.09.27.11.05.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 11:05:19 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 3/5] btrfs: add a BTRFS_FS_ERROR helper Date: Mon, 27 Sep 2021 14:05:12 -0400 Message-Id: <4790be90bba87904294617bec93c5dfe586bbd58.1632765815.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have a few flags that are inconsistently used to describe the fs in different states of failure. As of btrfs: always abort the transaction if we abort a trans handle we will always set BTRFS_FS_STATE_ERROR if we abort, so we don't have to check both ABORTED and ERROR to see if things have gone wrong. Add a helper to check BTRFS_FS_STATE_HELPER and then convert all checkers of FS_STATE_ERROR to use the helper. Signed-off-by: Josef Bacik Reviewed-by: Anand Jain --- fs/btrfs/ctree.h | 3 +++ fs/btrfs/disk-io.c | 8 +++----- fs/btrfs/extent_io.c | 2 +- fs/btrfs/file.c | 2 +- fs/btrfs/inode.c | 6 +++--- fs/btrfs/scrub.c | 2 +- fs/btrfs/super.c | 2 +- fs/btrfs/transaction.c | 11 +++++------ fs/btrfs/tree-log.c | 2 +- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 522ded06fd85..53f15decb523 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3576,6 +3576,9 @@ do { \ (errno), fmt, ##args); \ } while (0) +#define BTRFS_FS_ERROR(fs_info) (unlikely(test_bit(BTRFS_FS_STATE_ERROR, \ + &(fs_info)->fs_state))) + __printf(5, 6) __cold void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function, diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 37637539c5ab..1ae30b29f2b5 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1954,8 +1954,7 @@ static int transaction_kthread(void *arg) wake_up_process(fs_info->cleaner_kthread); mutex_unlock(&fs_info->transaction_kthread_mutex); - if (unlikely(test_bit(BTRFS_FS_STATE_ERROR, - &fs_info->fs_state))) + if (BTRFS_FS_ERROR(fs_info)) btrfs_cleanup_transaction(fs_info); if (!kthread_should_stop() && (!btrfs_transaction_blocked(fs_info) || @@ -4232,7 +4231,7 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, drop_ref = true; spin_unlock(&fs_info->fs_roots_radix_lock); - if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { + if (BTRFS_FS_ERROR(fs_info)) { ASSERT(root->log_root == NULL); if (root->reloc_root) { btrfs_put_root(root->reloc_root); @@ -4383,8 +4382,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info) btrfs_err(fs_info, "commit super ret %d", ret); } - if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state) || - test_bit(BTRFS_FS_STATE_TRANS_ABORTED, &fs_info->fs_state)) + if (BTRFS_FS_ERROR(fs_info)) btrfs_error_commit_super(fs_info); kthread_stop(fs_info->transaction_kthread); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index c56973f7daae..f6f004d673a0 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -4876,7 +4876,7 @@ int btree_write_cache_pages(struct address_space *mapping, * extent io tree. Thus we don't want to submit such wild eb * if the fs already has error. */ - if (!test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { + if (!BTRFS_FS_ERROR(fs_info)) { ret = flush_write_bio(&epd); } else { ret = -EROFS; diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 7ff577005d0f..fdceab28587e 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2013,7 +2013,7 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb, * have opened a file as writable, we have to stop this write operation * to ensure consistency. */ - if (test_bit(BTRFS_FS_STATE_ERROR, &inode->root->fs_info->fs_state)) + if (BTRFS_FS_ERROR(inode->root->fs_info)) return -EROFS; if (!(iocb->ki_flags & IOCB_DIRECT) && diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 03a843b9659b..26d155e72152 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4368,7 +4368,7 @@ static void btrfs_prune_dentries(struct btrfs_root *root) struct inode *inode; u64 objectid = 0; - if (!test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) + if (!BTRFS_FS_ERROR(fs_info)) WARN_ON(btrfs_root_refs(&root->root_item) != 0); spin_lock(&root->inode_lock); @@ -9981,7 +9981,7 @@ int btrfs_start_delalloc_snapshot(struct btrfs_root *root, bool in_reclaim_conte }; struct btrfs_fs_info *fs_info = root->fs_info; - if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) + if (BTRFS_FS_ERROR(fs_info)) return -EROFS; return start_delalloc_inodes(root, &wbc, true, in_reclaim_context); @@ -10000,7 +10000,7 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr, struct list_head splice; int ret; - if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) + if (BTRFS_FS_ERROR(fs_info)) return -EROFS; INIT_LIST_HEAD(&splice); diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index bd3cd7427391..b1c26a90243b 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -3955,7 +3955,7 @@ static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx, int ret; struct btrfs_fs_info *fs_info = sctx->fs_info; - if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) + if (BTRFS_FS_ERROR(fs_info)) return -EROFS; /* Seed devices of a new filesystem has their own generation. */ diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 7f91d62c2225..a1c54a2c787c 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2006,7 +2006,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data) if (ret) goto restore; } else { - if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { + if (BTRFS_FS_ERROR(fs_info)) { btrfs_err(fs_info, "Remounting read-write after error is not allowed"); ret = -EINVAL; diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 14b9fdc8aaa9..1c3a1189c0bd 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -283,7 +283,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info, spin_lock(&fs_info->trans_lock); loop: /* The file system has been taken offline. No new transactions. */ - if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { + if (BTRFS_FS_ERROR(fs_info)) { spin_unlock(&fs_info->trans_lock); return -EROFS; } @@ -331,7 +331,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info, */ kfree(cur_trans); goto loop; - } else if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { + } else if (BTRFS_FS_ERROR(fs_info)) { spin_unlock(&fs_info->trans_lock); kfree(cur_trans); return -EROFS; @@ -579,7 +579,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items, bool do_chunk_alloc = false; int ret; - if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) + if (BTRFS_FS_ERROR(fs_info)) return ERR_PTR(-EROFS); if (current->journal_info) { @@ -991,8 +991,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, if (throttle) btrfs_run_delayed_iputs(info); - if (TRANS_ABORTED(trans) || - test_bit(BTRFS_FS_STATE_ERROR, &info->fs_state)) { + if (TRANS_ABORTED(trans) || BTRFS_FS_ERROR(info)) { wake_up_process(info->transaction_kthread); if (TRANS_ABORTED(trans)) err = trans->aborted; @@ -2155,7 +2154,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans) * abort to prevent writing a new superblock that reflects a * corrupt state (pointing to trees with unwritten nodes/leafs). */ - if (test_bit(BTRFS_FS_STATE_TRANS_ABORTED, &fs_info->fs_state)) { + if (BTRFS_FS_ERROR(fs_info)) { ret = -EROFS; goto cleanup_transaction; } diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 720723611875..9e5937685896 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -3335,7 +3335,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, * writing the super here would result in transid mismatches. If there * is an error here just bail. */ - if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { + if (BTRFS_FS_ERROR(fs_info)) { ret = -EIO; btrfs_set_log_full_commit(trans); btrfs_abort_transaction(trans, ret); From patchwork Mon Sep 27 18:05:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12520555 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92957C433EF for ; Mon, 27 Sep 2021 18:05:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77F9360EE2 for ; Mon, 27 Sep 2021 18:05:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235867AbhI0SHN (ORCPT ); Mon, 27 Sep 2021 14:07:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235816AbhI0SHC (ORCPT ); Mon, 27 Sep 2021 14:07:02 -0400 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 129E2C061714 for ; Mon, 27 Sep 2021 11:05:24 -0700 (PDT) Received: by mail-qk1-x72c.google.com with SMTP id c7so38009725qka.2 for ; Mon, 27 Sep 2021 11:05:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=f2R/OkwismCzwR3LRjxYhNy8immU4DsVoIq2J6589Yc=; b=qcneTljw/fdM8OWaAfHnnxtf84yQvXV/A9xHrCQgZQEuDGCyOIOVpajTwdUy6qPl+U 2/sETXfFsH/SvHgEn7G3Smfa2rs1hpxa4Z8DSyU/6iwWJEZFae/x/FAd4rXZq9l3b6Cf EwXPXvJAV+MnxMkEfv099Uqp2uDEvwddxMrXaOigg3mwIE+L6W0dOrd9LkGbbF9e6L33 wdcW13A8OaxE9bo/ysU1tVhdzjr6D4CZ6V0r1Rp/6/7dSFHeCbESyB9rZU6WnkU7bu6o 9QzPIWXJDvdM3IbkiQuVPFYMZ7LmFPyEU1LGbHEGT84CKohI82A7scqjspxiW2aGWkM4 PxAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f2R/OkwismCzwR3LRjxYhNy8immU4DsVoIq2J6589Yc=; b=JIjwvK+RLaeCSNiDfhi2BiVNRLI4P0DQS/BuPIDOyQipoKHM8ciVPgaAlJulvXZqYH d8Qg48Gg8wHW+4+58QflszzGIPUo0qKh8Xe0naQhcWgjHlKPQXd6ej2NrJHF1oumv2GM u0xPpOkdFLRDGrJm3a172/KHEJfqAmJvgKgoqMxmH+sPLGpZWozJMm3aFnELyttk5l1R ksFkhT98pfejJFsWerWskeOiU0BinpFx2gcDNvg7xLcUC4USEsvhhuT3PTiFab7jyn0H hZjXFW8IiKg31W4ty1SCas3puKlVjoTKUAD2jwXGTITjJOIiN5KDUr7nMVnPnjL5w5Pg gsrw== X-Gm-Message-State: AOAM533oamv0bRWAGLAGk8H2K7GrvphzSkZua5bqMp4Mp+EOxAZR3MFX 7hgMZt7o0gvrksu289edtHb2HfUqdSCa0A== X-Google-Smtp-Source: ABdhPJyYygJYvM3SzKEywZ01gvpcgfrliO5H1vfZuZTYgRIXS2SbHm3+nT2MgmvHfPdNSjKXgX8foA== X-Received: by 2002:a05:620a:5ae:: with SMTP id q14mr1345426qkq.246.1632765922945; Mon, 27 Sep 2021 11:05:22 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id y11sm11860298qtm.27.2021.09.27.11.05.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 11:05:22 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 4/5] btrfs: do not infinite loop in data reclaim if we aborted Date: Mon, 27 Sep 2021 14:05:13 -0400 Message-Id: <03b2f64b3acc918b67c2fef6d4bfce70ab12ce3b.1632765815.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Error injection stressing uncovered a busy loop in our data reclaim loop. There are two cases here, one where we loop creating block groups until space_info->full is set, or in the main loop we will skip erroring out any tickets if space_info->full == 0. Unfortunately if we aborted the transaction then we will never allocate chunks or reclaim any space and thus never get ->full, and you'll see stack traces like this watchdog: BUG: soft lockup - CPU#0 stuck for 26s! [kworker/u4:4:139] CPU: 0 PID: 139 Comm: kworker/u4:4 Tainted: G W 5.13.0-rc1+ #328 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014 Workqueue: events_unbound btrfs_async_reclaim_data_space RIP: 0010:btrfs_join_transaction+0x12/0x20 RSP: 0018:ffffb2b780b77de0 EFLAGS: 00000246 RAX: ffffb2b781863d58 RBX: 0000000000000000 RCX: 0000000000000000 RDX: 0000000000000801 RSI: ffff987952b57400 RDI: ffff987940aa3000 RBP: ffff987954d55000 R08: 0000000000000001 R09: ffff98795539e8f0 R10: 000000000000000f R11: 000000000000000f R12: ffffffffffffffff R13: ffff987952b574c8 R14: ffff987952b57400 R15: 0000000000000008 FS: 0000000000000000(0000) GS:ffff9879bbc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f0703da4000 CR3: 0000000113398004 CR4: 0000000000370ef0 Call Trace: flush_space+0x4a8/0x660 btrfs_async_reclaim_data_space+0x55/0x130 process_one_work+0x1e9/0x380 worker_thread+0x53/0x3e0 ? process_one_work+0x380/0x380 kthread+0x118/0x140 ? __kthread_bind_mask+0x60/0x60 ret_from_fork+0x1f/0x30 Fix this by checking to see if we have a btrfs fs error in either of the reclaim loops, and if so fail the tickets and bail. In addition to this, fix maybe_fail_all_tickets() to not try to grant tickets if we've aborted, simply fail everything. Signed-off-by: Josef Bacik Reviewed-by: Filipe Manana Reported-by: kernel test robot --- fs/btrfs/space-info.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index aa5be0b24987..63423f9729c5 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -885,6 +885,7 @@ static bool maybe_fail_all_tickets(struct btrfs_fs_info *fs_info, { struct reserve_ticket *ticket; u64 tickets_id = space_info->tickets_id; + const bool aborted = btrfs_has_fs_error(fs_info); trace_btrfs_fail_all_tickets(fs_info, space_info); @@ -898,16 +899,19 @@ static bool maybe_fail_all_tickets(struct btrfs_fs_info *fs_info, ticket = list_first_entry(&space_info->tickets, struct reserve_ticket, list); - if (ticket->steal && + if (!aborted && ticket->steal && steal_from_global_rsv(fs_info, space_info, ticket)) return true; - if (btrfs_test_opt(fs_info, ENOSPC_DEBUG)) + if (!aborted && btrfs_test_opt(fs_info, ENOSPC_DEBUG)) btrfs_info(fs_info, "failing ticket with %llu bytes", ticket->bytes); remove_ticket(space_info, ticket); - ticket->error = -ENOSPC; + if (aborted) + ticket->error = -EIO; + else + ticket->error = -ENOSPC; wake_up(&ticket->wait); /* @@ -916,7 +920,8 @@ static bool maybe_fail_all_tickets(struct btrfs_fs_info *fs_info, * here to see if we can make progress with the next ticket in * the list. */ - btrfs_try_granting_tickets(fs_info, space_info); + if (!aborted) + btrfs_try_granting_tickets(fs_info, space_info); } return (tickets_id != space_info->tickets_id); } @@ -1172,6 +1177,10 @@ static void btrfs_async_reclaim_data_space(struct work_struct *work) spin_unlock(&space_info->lock); return; } + + /* Something happened, fail everything and bail. */ + if (btrfs_has_fs_error(fs_info)) + goto aborted_fs; last_tickets_id = space_info->tickets_id; spin_unlock(&space_info->lock); } @@ -1202,9 +1211,19 @@ static void btrfs_async_reclaim_data_space(struct work_struct *work) } else { flush_state = 0; } + + /* Something happened, fail everything and bail. */ + if (btrfs_has_fs_error(fs_info)) + goto aborted_fs; + } spin_unlock(&space_info->lock); } + return; +aborted_fs: + maybe_fail_all_tickets(fs_info, space_info); + space_info->flush = 0; + spin_unlock(&space_info->lock); } void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info) From patchwork Mon Sep 27 18:05:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12520557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2530C433FE for ; Mon, 27 Sep 2021 18:05:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E84760F9B for ; Mon, 27 Sep 2021 18:05:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235909AbhI0SHR (ORCPT ); Mon, 27 Sep 2021 14:07:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235694AbhI0SHJ (ORCPT ); Mon, 27 Sep 2021 14:07:09 -0400 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D48EDC061740 for ; Mon, 27 Sep 2021 11:05:30 -0700 (PDT) Received: by mail-qk1-x731.google.com with SMTP id m7so20940946qke.8 for ; Mon, 27 Sep 2021 11:05:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=KeItr4l2pcJk3E61qcbEVPtp48CLKSQAvi6b14/8UF4=; b=s4hSyvyf6XNOL9/p8QcnDITEyUQ0bizBInmgaNJr92pWg3G7j3SCSTv5zZFbuJrBaB 2gWVoUvET8cmM2goeVuuRFefjK0YqGnnIuI5w6fBW5FTm12SIfQaQGfEIDLdtcFKiWX8 snS5Eh/xEj2x0jSdKGeUL6Y73VSEjlUd/62lLOLXwKEE8+4wDBpvpkvxgYxO/6xBfz/4 UTS7sJxMwMGUMPXZ/SHk99vGVc1N/PlZHI1QHZBYAecPuHiFdSgxSmCp9a9RPUx25tBp Ii7HXwXQRVFs6S3i2xm+RJF0MdNIYoVZmqeCaoDuxjgNbDmt84Voe4aNnVaZiGzdWByE 26Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KeItr4l2pcJk3E61qcbEVPtp48CLKSQAvi6b14/8UF4=; b=zeV1Fo04MFxLZFiYDosO692gYSCIC2QrsL+SxHrFTEGW1xdd4HeKItzwW33Xgn7AHs fiCYazWromKo8OgyKKS30bmlWvBMwb/0nwb0bs5JfAgIt7khUdVhSadCR6Ht5eSuLRXB HNv0cM1DCy9EU5+PCuvZ6LAvor8afBqjR939sHLcf/QLjK2p2RaLbI2EVUoa5Pn5/PEW beKlnF9wOZ2iY0NO5ffNFhMLZxkl5IRttewbPp2c5uesUYey+aF8WCT1vG/OZTbjJNbT bdIbR8bwgYCRPOBFt1pVGN6FrH2qf3G1nZ0kptk8K5FleWpE70eTYcJJRgEwopi9hiWP C3XA== X-Gm-Message-State: AOAM531uxEIFkBQ3LlbgNza8HZESxjR4gmJeUf56W0j04VBoC0C5tgR2 khCwUxDVW39ZMO9wBDqhHIk5u7YtYuiq+g== X-Google-Smtp-Source: ABdhPJzLAmrhsBUo6vs8CJxPG/8Xsg6+eg4HE7Zt8KeHf9ArPaoQ9FzIDtupELkLKgoME040TuXQpg== X-Received: by 2002:a37:746:: with SMTP id 67mr1268416qkh.465.1632765929788; Mon, 27 Sep 2021 11:05:29 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id l28sm12827279qkl.127.2021.09.27.11.05.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 11:05:29 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 5/5] btrfs: fix abort logic in btrfs_replace_file_extents Date: Mon, 27 Sep 2021 14:05:14 -0400 Message-Id: <6d8adc363ee08747d4e5ee2f521b1e0e155516a1.1632765815.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Error injection testing uncovered a case where we'd end up with a corrupt file system with a missing extent in the middle of a file. This occurs because the if statement to decide if we should abort is wrong. The only way we would abort in this case is if we got a ret != -EOPNOTSUPP and we called from the file clone code. However the prealloc code uses this path too. Instead we need to abort if there is an error, and the only error we _don't_ abort on is -EOPNOTSUPP and only if we came from the clone file code. Signed-off-by: Josef Bacik --- fs/btrfs/file.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index fdceab28587e..f9a1498cf030 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2710,8 +2710,9 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode, * returned by __btrfs_drop_extents() without having * changed anything in the file. */ - if (extent_info && !extent_info->is_new_extent && - ret && ret != -EOPNOTSUPP) + if (ret && + (ret != -EOPNOTSUPP || + (extent_info && extent_info->is_new_extent))) btrfs_abort_transaction(trans, ret); break; }