From patchwork Fri Jul 21 09:49:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13321786 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CB66EB64DC for ; Fri, 21 Jul 2023 09:51:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231978AbjGUJvg (ORCPT ); Fri, 21 Jul 2023 05:51:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231977AbjGUJvK (ORCPT ); Fri, 21 Jul 2023 05:51:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF00D44A7 for ; Fri, 21 Jul 2023 02:49:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 996CD60C66 for ; Fri, 21 Jul 2023 09:49:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53E04C433C8 for ; Fri, 21 Jul 2023 09:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689932969; bh=nlcCIRRu/CDBbsa4CPZBOy4p+CdLWsq4kXcNRDqUo+I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Hzd3Ho/dBBtrf9bKJ7ps0ZFBggmvKguErNB2bprwlzF3TsUwU17KKubKJV545P9tt tLmBaoT2lsG7fvckWhCv1q1bvpkDFHj34nfoBOXnMYQewFUgfQVfMQfXIxcDeenYg8 NkVNOgJ+QeTNHbfBVUcV7vdaDkzNTQtXLbMNVO7TMOfwgYM8k6cbmn9v3yFjgMfoqY esdojSg42OgXTUk/vDMhPfhaYz4TMl+IF50BaacuMDHsL+lfA4dtqcnE14a7zeCXuD nDCQ27nPJJ0LpdiGIMF2QRYh0dm1kbQFofrqJjT2Ih/URMS5Hg6tl/64u4RhRZxupx eWu0UriGojogg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/2] btrfs: check if the transaction was aborted at btrfs_wait_for_commit() Date: Fri, 21 Jul 2023 10:49:20 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana At btrfs_wait_for_commit() we wait for a transaction to finish and then always return 0 (success) without checking if it was aborted, in which case the transaction didn't happen due to some critical error. Fix this by checking if the transaction was aborted. Fixes: 462045928bda ("Btrfs: add START_SYNC, WAIT_SYNC ioctls") Signed-off-by: Filipe Manana Reviewed-by: Qu Wenruo --- fs/btrfs/transaction.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 4743882fa94b..8ab85465cdaa 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -931,6 +931,7 @@ int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid) } wait_for_commit(cur_trans, TRANS_STATE_COMPLETED); + ret = cur_trans->aborted; btrfs_put_transaction(cur_trans); out: return ret; From patchwork Fri Jul 21 09:49:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13321787 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C993EB64DC for ; Fri, 21 Jul 2023 09:52:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231968AbjGUJw1 (ORCPT ); Fri, 21 Jul 2023 05:52:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231881AbjGUJwE (ORCPT ); Fri, 21 Jul 2023 05:52:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2D0749C8 for ; Fri, 21 Jul 2023 02:50:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8FFCB60C6E for ; Fri, 21 Jul 2023 09:49:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D487C433C7 for ; Fri, 21 Jul 2023 09:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689932970; bh=szIdt3W4siF2P0GK26m8ELcnIOxzFkVK+I2zokgs1YI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=j+xvGqAEIRH6B1uG+09rWJLbIxZZh+C+UENa0TMrgOUJg0CAAL6HPHq5q7x9ugS1A cmE7DBPPyqNbsdBE2PLu6BsfOFM8Bajv6BncXjjwJIWcXvc5+6S/vinq56htcxVlEa rmlatmyP7KrF7Wjb/TCuHBfFR/W3l6NJr0uWlc9lf4fzmxyRvXBg9qrJd3IUCEiC3N zYOJqzrS5BJpts+sCKnW/uRpf6EYQ+FAN6R8qaALQZWwxqfALkBwnf7uKjruSd+omR 6/seWH2mfyqLzIPT9M2V68niZ1MN1g2VMKHyv/Vwv+x1+1X9ElsIvoUBsbW+jc6kUm ZnJmw9XCBHs6Q== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] btrfs: check for commit error at btrfs_attach_transaction_barrier() Date: Fri, 21 Jul 2023 10:49:21 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana btrfs_attach_transaction_barrier() is used to get a handle pointing to the current running transaction if the transaction has not started its commit yet (its state is < TRANS_STATE_COMMIT_START). If the transaction commit has started, then we wait for the transaction to commit and finish before returning - however we completely ignore if the transaction was aborted due to some error during its commit, we simply return ERR_PT(-ENOENT), which makes the caller assume everything is fine and no errors happened. This could make an fsync return success (0) to user space when in fact we had a transaction abort and the target inode changes were therefore not persisted. Fix this by checking for the return value from btrfs_wait_for_commit(), and if it returned an error, return it back to the caller. Fixes: d4edf39bd5db ("Btrfs: fix uncompleted transaction") Signed-off-by: Filipe Manana Reviewed-by: Qu Wenruo --- fs/btrfs/transaction.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 8ab85465cdaa..4bb9716ad24a 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -826,8 +826,13 @@ btrfs_attach_transaction_barrier(struct btrfs_root *root) trans = start_transaction(root, 0, TRANS_ATTACH, BTRFS_RESERVE_NO_FLUSH, true); - if (trans == ERR_PTR(-ENOENT)) - btrfs_wait_for_commit(root->fs_info, 0); + if (trans == ERR_PTR(-ENOENT)) { + int ret; + + ret = btrfs_wait_for_commit(root->fs_info, 0); + if (ret) + return ERR_PTR(ret); + } return trans; }