]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: tree-log: make the return value for log syncing consistent
authorJosef Bacik <josef@toxicpanda.com>
Mon, 13 Jun 2022 19:09:48 +0000 (15:09 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:42:24 +0000 (14:42 +0200)
[ Upstream commit f31f09f6be1c6c1a673e0566e258281a7bbaaa51 ]

Currently we will return 1 or -EAGAIN if we decide we need to commit
the transaction rather than sync the log.  In practice this doesn't
really matter, we interpret any !0 and !BTRFS_NO_LOG_SYNC as needing to
commit the transaction.  However this makes it hard to figure out what
the correct thing to do is.

Fix this up by defining BTRFS_LOG_FORCE_COMMIT and using this in all the
places where we want to force the transaction to be committed.

CC: stable@vger.kernel.org # 5.15+
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/file.c
fs/btrfs/tree-log.c
fs/btrfs/tree-log.h

index 153920acd2269cdeed2f222366a26adc2bddec77..2d24f2dcc0ea474f2d6687a19ae635a45e934a2c 100644 (file)
@@ -2344,7 +2344,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
        btrfs_release_log_ctx_extents(&ctx);
        if (ret < 0) {
                /* Fallthrough and commit/free transaction. */
-               ret = 1;
+               ret = BTRFS_LOG_FORCE_COMMIT;
        }
 
        /* we've logged all the items and now have a consistent
index e65633686378cc8b3ff13d4f6cde9a15dc3548ca..08917069a12548dab69e1d07da4c7d5070d01206 100644 (file)
@@ -171,7 +171,7 @@ again:
                int index = (root->log_transid + 1) % 2;
 
                if (btrfs_need_log_full_commit(trans)) {
-                       ret = -EAGAIN;
+                       ret = BTRFS_LOG_FORCE_COMMIT;
                        goto out;
                }
 
@@ -194,7 +194,7 @@ again:
                 * writing.
                 */
                if (zoned && !created) {
-                       ret = -EAGAIN;
+                       ret = BTRFS_LOG_FORCE_COMMIT;
                        goto out;
                }
 
@@ -3122,7 +3122,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
 
        /* bail out if we need to do a full commit */
        if (btrfs_need_log_full_commit(trans)) {
-               ret = -EAGAIN;
+               ret = BTRFS_LOG_FORCE_COMMIT;
                mutex_unlock(&root->log_mutex);
                goto out;
        }
@@ -3223,7 +3223,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
                }
                btrfs_wait_tree_log_extents(log, mark);
                mutex_unlock(&log_root_tree->log_mutex);
-               ret = -EAGAIN;
+               ret = BTRFS_LOG_FORCE_COMMIT;
                goto out;
        }
 
@@ -3262,7 +3262,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
                blk_finish_plug(&plug);
                btrfs_wait_tree_log_extents(log, mark);
                mutex_unlock(&log_root_tree->log_mutex);
-               ret = -EAGAIN;
+               ret = BTRFS_LOG_FORCE_COMMIT;
                goto out_wake_log_root;
        }
 
@@ -5849,7 +5849,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
            inode_only == LOG_INODE_ALL &&
            inode->last_unlink_trans >= trans->transid) {
                btrfs_set_log_full_commit(trans);
-               ret = 1;
+               ret = BTRFS_LOG_FORCE_COMMIT;
                goto out_unlock;
        }
 
@@ -6563,12 +6563,12 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
        bool log_dentries = false;
 
        if (btrfs_test_opt(fs_info, NOTREELOG)) {
-               ret = 1;
+               ret = BTRFS_LOG_FORCE_COMMIT;
                goto end_no_trans;
        }
 
        if (btrfs_root_refs(&root->root_item) == 0) {
-               ret = 1;
+               ret = BTRFS_LOG_FORCE_COMMIT;
                goto end_no_trans;
        }
 
@@ -6666,7 +6666,7 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
 end_trans:
        if (ret < 0) {
                btrfs_set_log_full_commit(trans);
-               ret = 1;
+               ret = BTRFS_LOG_FORCE_COMMIT;
        }
 
        if (ret)
index 1620f8170629e47c70c0c74e8dc63a0997c619e3..57ab5f3b8dc77e5415d63ef006a588112d5630f5 100644 (file)
@@ -12,6 +12,9 @@
 /* return value for btrfs_log_dentry_safe that means we don't need to log it at all */
 #define BTRFS_NO_LOG_SYNC 256
 
+/* We can't use the tree log for whatever reason, force a transaction commit */
+#define BTRFS_LOG_FORCE_COMMIT                         (1)
+
 struct btrfs_log_ctx {
        int log_ret;
        int log_transid;