Skip to content

Commit 15e8cc0

Browse files
YuezhangMogregkh
authored andcommitted
erofs: Fallback to normal access if DAX is not supported on extra device
[ Upstream commit c6993c4 ] If using multiple devices, we should check if the extra device support DAX instead of checking the primary device when deciding if to use DAX to access a file. If an extra device does not support DAX we should fallback to normal access otherwise the data on that device will be inaccessible. Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com> Reviewed-by: Friendy Su <friendy.su@sony.com> Reviewed-by: Jacky Cao <jacky.cao@sony.com> Reviewed-by: Daniel Palmer <daniel.palmer@sony.com> Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com> Reviewed-by: Hongbo Li <lihongbo22@huawei.com> Link: https://lore.kernel.org/r/20250804082030.3667257-2-Yuezhang.Mo@sony.com Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1e46ce7 commit 15e8cc0

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

fs/erofs/super.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
174174
if (!erofs_is_fileio_mode(sbi)) {
175175
dif->dax_dev = fs_dax_get_by_bdev(file_bdev(file),
176176
&dif->dax_part_off, NULL, NULL);
177+
if (!dif->dax_dev && test_opt(&sbi->opt, DAX_ALWAYS)) {
178+
erofs_info(sb, "DAX unsupported by %s. Turning off DAX.",
179+
dif->path);
180+
clear_opt(&sbi->opt, DAX_ALWAYS);
181+
}
177182
} else if (!S_ISREG(file_inode(file)->i_mode)) {
178183
fput(file);
179184
return -EINVAL;
@@ -210,8 +215,13 @@ static int erofs_scan_devices(struct super_block *sb,
210215
ondisk_extradevs, sbi->devs->extra_devices);
211216
return -EINVAL;
212217
}
213-
if (!ondisk_extradevs)
218+
if (!ondisk_extradevs) {
219+
if (test_opt(&sbi->opt, DAX_ALWAYS) && !sbi->dif0.dax_dev) {
220+
erofs_info(sb, "DAX unsupported by block device. Turning off DAX.");
221+
clear_opt(&sbi->opt, DAX_ALWAYS);
222+
}
214223
return 0;
224+
}
215225

216226
if (!sbi->devs->extra_devices && !erofs_is_fscache_mode(sb))
217227
sbi->devs->flatdev = true;
@@ -330,7 +340,6 @@ static int erofs_read_superblock(struct super_block *sb)
330340
if (ret < 0)
331341
goto out;
332342

333-
/* handle multiple devices */
334343
ret = erofs_scan_devices(sb, dsb);
335344

336345
if (erofs_sb_has_48bit(sbi))
@@ -661,14 +670,9 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
661670
return invalfc(fc, "cannot use fsoffset in fscache mode");
662671
}
663672

664-
if (test_opt(&sbi->opt, DAX_ALWAYS)) {
665-
if (!sbi->dif0.dax_dev) {
666-
errorfc(fc, "DAX unsupported by block device. Turning off DAX.");
667-
clear_opt(&sbi->opt, DAX_ALWAYS);
668-
} else if (sbi->blkszbits != PAGE_SHIFT) {
669-
errorfc(fc, "unsupported blocksize for DAX");
670-
clear_opt(&sbi->opt, DAX_ALWAYS);
671-
}
673+
if (test_opt(&sbi->opt, DAX_ALWAYS) && sbi->blkszbits != PAGE_SHIFT) {
674+
erofs_info(sb, "unsupported blocksize for DAX");
675+
clear_opt(&sbi->opt, DAX_ALWAYS);
672676
}
673677

674678
sb->s_time_gran = 1;

0 commit comments

Comments
 (0)