Skip to content

Commit 3ddebf2

Browse files
naotakdave
authored andcommitted
btrfs: zoned: reorder log node allocation on zoned filesystem
This is the 3/3 patch to enable tree-log on zoned filesystems. The allocation order of nodes of "fs_info->log_root_tree" and nodes of "root->log_root" is not the same as the writing order of them. So, the writing causes unaligned write errors. Reorder the allocation of them by delaying allocation of the root node of "fs_info->log_root_tree," so that the node buffers can go out sequentially to devices. Cc: Filipe Manana <fdmanana@gmail.com> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent fa1a0f4 commit 3ddebf2

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

fs/btrfs/disk-io.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,16 +1298,18 @@ int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans,
12981298
struct btrfs_fs_info *fs_info)
12991299
{
13001300
struct btrfs_root *log_root;
1301-
int ret;
13021301

13031302
log_root = alloc_log_tree(trans, fs_info);
13041303
if (IS_ERR(log_root))
13051304
return PTR_ERR(log_root);
13061305

1307-
ret = btrfs_alloc_log_tree_node(trans, log_root);
1308-
if (ret) {
1309-
btrfs_put_root(log_root);
1310-
return ret;
1306+
if (!btrfs_is_zoned(fs_info)) {
1307+
int ret = btrfs_alloc_log_tree_node(trans, log_root);
1308+
1309+
if (ret) {
1310+
btrfs_put_root(log_root);
1311+
return ret;
1312+
}
13111313
}
13121314

13131315
WARN_ON(fs_info->log_root_tree);

fs/btrfs/tree-log.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,6 +3162,19 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
31623162
list_add_tail(&root_log_ctx.list, &log_root_tree->log_ctxs[index2]);
31633163
root_log_ctx.log_transid = log_root_tree->log_transid;
31643164

3165+
if (btrfs_is_zoned(fs_info)) {
3166+
mutex_lock(&fs_info->tree_root->log_mutex);
3167+
if (!log_root_tree->node) {
3168+
ret = btrfs_alloc_log_tree_node(trans, log_root_tree);
3169+
if (ret) {
3170+
mutex_unlock(&fs_info->tree_log_mutex);
3171+
mutex_unlock(&log_root_tree->log_mutex);
3172+
goto out;
3173+
}
3174+
}
3175+
mutex_unlock(&fs_info->tree_root->log_mutex);
3176+
}
3177+
31653178
/*
31663179
* Now we are safe to update the log_root_tree because we're under the
31673180
* log_mutex, and we're a current writer so we're holding the commit
@@ -3320,12 +3333,14 @@ static void free_log_tree(struct btrfs_trans_handle *trans,
33203333
.process_func = process_one_buffer
33213334
};
33223335

3323-
ret = walk_log_tree(trans, log, &wc);
3324-
if (ret) {
3325-
if (trans)
3326-
btrfs_abort_transaction(trans, ret);
3327-
else
3328-
btrfs_handle_fs_error(log->fs_info, ret, NULL);
3336+
if (log->node) {
3337+
ret = walk_log_tree(trans, log, &wc);
3338+
if (ret) {
3339+
if (trans)
3340+
btrfs_abort_transaction(trans, ret);
3341+
else
3342+
btrfs_handle_fs_error(log->fs_info, ret, NULL);
3343+
}
33293344
}
33303345

33313346
clear_extent_bits(&log->dirty_log_pages, 0, (u64)-1,

0 commit comments

Comments
 (0)