Skip to content

Commit c6993c4

Browse files
YuezhangMohsiangkao
authored andcommitted
erofs: Fallback to normal access if DAX is not supported on extra device
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 <[email protected]> Reviewed-by: Friendy Su <[email protected]> Reviewed-by: Jacky Cao <[email protected]> Reviewed-by: Daniel Palmer <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Reviewed-by: Hongbo Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Gao Xiang <[email protected]>
1 parent 8f5ae30 commit c6993c4

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;
@@ -338,7 +348,6 @@ static int erofs_read_superblock(struct super_block *sb)
338348
if (ret < 0)
339349
goto out;
340350

341-
/* handle multiple devices */
342351
ret = erofs_scan_devices(sb, dsb);
343352

344353
if (erofs_sb_has_48bit(sbi))
@@ -671,14 +680,9 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
671680
return invalfc(fc, "cannot use fsoffset in fscache mode");
672681
}
673682

674-
if (test_opt(&sbi->opt, DAX_ALWAYS)) {
675-
if (!sbi->dif0.dax_dev) {
676-
errorfc(fc, "DAX unsupported by block device. Turning off DAX.");
677-
clear_opt(&sbi->opt, DAX_ALWAYS);
678-
} else if (sbi->blkszbits != PAGE_SHIFT) {
679-
errorfc(fc, "unsupported blocksize for DAX");
680-
clear_opt(&sbi->opt, DAX_ALWAYS);
681-
}
683+
if (test_opt(&sbi->opt, DAX_ALWAYS) && sbi->blkszbits != PAGE_SHIFT) {
684+
erofs_info(sb, "unsupported blocksize for DAX");
685+
clear_opt(&sbi->opt, DAX_ALWAYS);
682686
}
683687

684688
sb->s_time_gran = 1;

0 commit comments

Comments
 (0)