Commit 5cce1780 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: use a negative value for BTRFS_LOG_FORCE_COMMIT

Currently we use the value 1 for BTRFS_LOG_FORCE_COMMIT, but that value
has a few inconveniences:

1) If it's ever used by btrfs_log_inode(), or any function down the call
   chain, we have to remember to btrfs_set_log_full_commit(), which is
   repetitive and has a chance to be forgotten in future use cases.
   btrfs_log_inode_parent() only calls btrfs_set_log_full_commit() when
   it gets a negative value from btrfs_log_inode();

2) Down the call chain of btrfs_log_inode(), we may have functions that
   need to force a log commit, but can return either an error (negative
   value), false (0) or true (1). So they are forced to return some
   random negative to force a log commit - using BTRFS_LOG_FORCE_COMMIT
   would make the intention more clear. Currently the only example is
   flush_dir_items_batch().

So turn BTRFS_LOG_FORCE_COMMIT into a negative value. The chosen value
is -(MAX_ERRNO + 1), so that it does not overlap any errno value and makes
it easier to debug.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent ce394a7f
...@@ -3652,11 +3652,10 @@ static int flush_dir_items_batch(struct btrfs_trans_handle *trans, ...@@ -3652,11 +3652,10 @@ static int flush_dir_items_batch(struct btrfs_trans_handle *trans,
/* /*
* If for some unexpected reason the last item's index is not greater * If for some unexpected reason the last item's index is not greater
* than the last index we logged, warn and return an error to fallback * than the last index we logged, warn and force a transaction commit.
* to a transaction commit.
*/ */
if (WARN_ON(last_index <= inode->last_dir_index_offset)) if (WARN_ON(last_index <= inode->last_dir_index_offset))
ret = -EUCLEAN; ret = BTRFS_LOG_FORCE_COMMIT;
else else
inode->last_dir_index_offset = last_index; inode->last_dir_index_offset = last_index;
out: out:
...@@ -5604,10 +5603,8 @@ static int add_conflicting_inode(struct btrfs_trans_handle *trans, ...@@ -5604,10 +5603,8 @@ static int add_conflicting_inode(struct btrfs_trans_handle *trans,
* LOG_INODE_EXISTS mode) and slow down other fsyncs or transaction * LOG_INODE_EXISTS mode) and slow down other fsyncs or transaction
* commits. * commits.
*/ */
if (ctx->num_conflict_inodes >= MAX_CONFLICT_INODES) { if (ctx->num_conflict_inodes >= MAX_CONFLICT_INODES)
btrfs_set_log_full_commit(trans);
return BTRFS_LOG_FORCE_COMMIT; return BTRFS_LOG_FORCE_COMMIT;
}
inode = btrfs_iget(root->fs_info->sb, ino, root); inode = btrfs_iget(root->fs_info->sb, ino, root);
/* /*
...@@ -6466,7 +6463,6 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, ...@@ -6466,7 +6463,6 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
* result in losing the file after a log replay. * result in losing the file after a log replay.
*/ */
if (full_dir_logging && inode->last_unlink_trans >= trans->transid) { if (full_dir_logging && inode->last_unlink_trans >= trans->transid) {
btrfs_set_log_full_commit(trans);
ret = BTRFS_LOG_FORCE_COMMIT; ret = BTRFS_LOG_FORCE_COMMIT;
goto out_unlock; goto out_unlock;
} }
......
...@@ -13,8 +13,13 @@ ...@@ -13,8 +13,13 @@
/* return value for btrfs_log_dentry_safe that means we don't need to log it at all */ /* return value for btrfs_log_dentry_safe that means we don't need to log it at all */
#define BTRFS_NO_LOG_SYNC 256 #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) * We can't use the tree log for whatever reason, force a transaction commit.
* We use a negative value because there are functions through the logging code
* that need to return an error (< 0 value), false (0) or true (1). Any negative
* value will do, as it will cause the log to be marked for a full sync.
*/
#define BTRFS_LOG_FORCE_COMMIT (-(MAX_ERRNO + 1))
struct btrfs_log_ctx { struct btrfs_log_ctx {
int log_ret; int log_ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment