Skip to contentSkip to conversation

erofs: Fallback to normal access if DAX is not supported on extra device

PATCH In review Yuezhang Mo 3 participants 3 messages Aug 4, 2025 EROFS file system

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 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.

---

Changes of v3:
- uniformly use erofs_info() to output the logs of turning off DAX

Changes of v2:
- fix the indentation alignment of dif->path
- remove the unnecessary comment

 fs/erofs/super.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
fs/erofs/super.c +14 -10
index e1020aa60771..8c7a5985b4ee 100644
@@ -174,6 +174,11 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
 		if (!erofs_is_fileio_mode(sbi)) {
 			dif->dax_dev = fs_dax_get_by_bdev(file_bdev(file),
 					&dif->dax_part_off, NULL, NULL);
+			if (!dif->dax_dev && test_opt(&sbi->opt, DAX_ALWAYS)) {
+				erofs_info(sb, "DAX unsupported by %s. Turning off DAX.",
+					   dif->path);
+				clear_opt(&sbi->opt, DAX_ALWAYS);
+			}
 		} else if (!S_ISREG(file_inode(file)->i_mode)) {
 			fput(file);
 			return -EINVAL;
@@ -210,8 +215,13 @@ static int erofs_scan_devices(struct super_block *sb,
 			  ondisk_extradevs, sbi->devs->extra_devices);
 		return -EINVAL;
 	}
-	if (!ondisk_extradevs)
+	if (!ondisk_extradevs) {
+		if (test_opt(&sbi->opt, DAX_ALWAYS) && !sbi->dif0.dax_dev) {
+			erofs_info(sb, "DAX unsupported by block device. Turning off DAX.");
+			clear_opt(&sbi->opt, DAX_ALWAYS);
+		}
 		return 0;
+	}
 
 	if (!sbi->devs->extra_devices && !erofs_is_fscache_mode(sb))
 		sbi->devs->flatdev = true;
@@ -338,7 +348,6 @@ static int erofs_read_superblock(struct super_block *sb)
 	if (ret < 0)
 		goto out;
 
-	/* handle multiple devices */
 	ret = erofs_scan_devices(sb, dsb);
 
 	if (erofs_sb_has_48bit(sbi))
@@ -671,14 +680,9 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
 			return invalfc(fc, "cannot use fsoffset in fscache mode");
 	}
 
-	if (test_opt(&sbi->opt, DAX_ALWAYS)) {
-		if (!sbi->dif0.dax_dev) {
-			errorfc(fc, "DAX unsupported by block device. Turning off DAX.");
-			clear_opt(&sbi->opt, DAX_ALWAYS);
-		} else if (sbi->blkszbits != PAGE_SHIFT) {
-			errorfc(fc, "unsupported blocksize for DAX");
-			clear_opt(&sbi->opt, DAX_ALWAYS);
-		}
+	if (test_opt(&sbi->opt, DAX_ALWAYS) && sbi->blkszbits != PAGE_SHIFT) {
+		erofs_info(sb, "unsupported blocksize for DAX");
+		clear_opt(&sbi->opt, DAX_ALWAYS);
 	}
 
 	sb->s_time_gran = 1;
Signature · 1 line
2.43.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 11 lines · Yuezhang Mo

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.

Still looks good to me, will apply after -rc1 is out:

Thanks,
Gao Xiang

Reviewed-by on v3 1/1
#2 lore raw
In reply to Yuezhang Mo
Quoted 11 lines · Yuezhang Mo

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.

Thanks,
Hongbo

Quoted 69 lines

---

Changes of v3:
- uniformly use erofs_info() to output the logs of turning off DAX

Changes of v2:
- fix the indentation alignment of dif->path
- remove the unnecessary comment

  fs/erofs/super.c | 24 ++++++++++++++----------
  1 file changed, 14 insertions(+), 10 deletions(-)
fs/erofs/super.c +14 -10
index e1020aa60771..8c7a5985b4ee 100644
@@ -174,6 +174,11 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
  		if (!erofs_is_fileio_mode(sbi)) {
  			dif->dax_dev = fs_dax_get_by_bdev(file_bdev(file),
  					&dif->dax_part_off, NULL, NULL);
+			if (!dif->dax_dev && test_opt(&sbi->opt, DAX_ALWAYS)) {
+				erofs_info(sb, "DAX unsupported by %s. Turning off DAX.",
+					   dif->path);
+				clear_opt(&sbi->opt, DAX_ALWAYS);
+			}
  		} else if (!S_ISREG(file_inode(file)->i_mode)) {
  			fput(file);
  			return -EINVAL;
@@ -210,8 +215,13 @@ static int erofs_scan_devices(struct super_block *sb,
  			  ondisk_extradevs, sbi->devs->extra_devices);
  		return -EINVAL;
  	}
-	if (!ondisk_extradevs)
+	if (!ondisk_extradevs) {
+		if (test_opt(&sbi->opt, DAX_ALWAYS) && !sbi->dif0.dax_dev) {
+			erofs_info(sb, "DAX unsupported by block device. Turning off DAX.");
+			clear_opt(&sbi->opt, DAX_ALWAYS);
+		}
  		return 0;
+	}
 
  	if (!sbi->devs->extra_devices && !erofs_is_fscache_mode(sb))
  		sbi->devs->flatdev = true;
@@ -338,7 +348,6 @@ static int erofs_read_superblock(struct super_block *sb)
  	if (ret < 0)
  		goto out;
 
-	/* handle multiple devices */
  	ret = erofs_scan_devices(sb, dsb);
 
  	if (erofs_sb_has_48bit(sbi))
@@ -671,14 +680,9 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
  			return invalfc(fc, "cannot use fsoffset in fscache mode");
  	}
 
-	if (test_opt(&sbi->opt, DAX_ALWAYS)) {
-		if (!sbi->dif0.dax_dev) {
-			errorfc(fc, "DAX unsupported by block device. Turning off DAX.");
-			clear_opt(&sbi->opt, DAX_ALWAYS);
-		} else if (sbi->blkszbits != PAGE_SHIFT) {
-			errorfc(fc, "unsupported blocksize for DAX");
-			clear_opt(&sbi->opt, DAX_ALWAYS);
-		}
+	if (test_opt(&sbi->opt, DAX_ALWAYS) && sbi->blkszbits != PAGE_SHIFT) {
+		erofs_info(sb, "unsupported blocksize for DAX");
+		clear_opt(&sbi->opt, DAX_ALWAYS);
  	}
 
  	sb->s_time_gran = 1;