kern/186854: mount a ext4 file system with uninit_bg and flex_bg in read-only mode

Zheng Liu gnehzuil at gmail.com
Tue Feb 18 03:40:00 UTC 2014


>Number:         186854
>Category:       kern
>Synopsis:       mount a ext4 file system with uninit_bg and flex_bg in read-only mode
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 18 03:40:00 UTC 2014
>Closed-Date:
>Last-Modified:
>Originator:     Zheng Liu
>Release:        current
>Organization:
>Environment:
FreeBSD lambda 11.0-CURRENT FreeBSD 11.0-CURRENT #2 ab3f62f(master): Fri Feb 14 09:03:24 CST 2014     root at lambda:/usr/obj/home/wenqing/projects/freebsd/sys/GENERIC  amd64
>Description:
Currently ext2fs driver has ability to access a ext4 file system in read-only mode under some specific features.  But it couldn't mount a ext4 file system that is created from scratch because uninit_bg and flex_bg features will be enabled by default.  Hence the user would be trouble with this if he/she wants to access a ext4 file system with default features in read-only mode.

This patch tries to fix this issue.  In the patch, all we need to do is to define a new flag set called 'EXT4F_RO_INCOMPAT_SUPP' in order to prevent the user from trying to mount a ext4 file system in read-write mode and do some sanity check.

uninit_bg is a read-only compatible feature in ext4.  It is used to mark which block group is uninitialised.  This feature can save the time when a user creates a ext4 file system because 'mkfs' doesn't try to zero out inode/block bitmap and inode table.  Meanwhile 'fsck' will skip uninitialised block group for the same purpose.

flex_bg is an incompatible feature in ext4.  It tries to put multiple block groups tie together as one logical block group [1].  After enabling this feature we will get more continuous disk space.

1. https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Flexible_Block_Groups
>How-To-Repeat:
mkfs.ext4 ${DEV}
mount -t ext2fs -ro ${DEV} ${MNT}

The user will get an error message when he/she tries to mount a ext4 file system due to some unsupported features.
>Fix:
The attached patch tries to fix this problem.

Patch attached with submission follows:

>From 94c91af45638cbaba0991f9baacf1483c5be18c4 Mon Sep 17 00:00:00 2001
From: Zheng Liu <gnehzuil at gmail.com>
Date: Tue, 18 Feb 2014 03:08:34 +0800
Subject: [PATCH] patch ext4fs-uninitbg-flexbg

---
 sys/fs/ext2fs/ext2_vfsops.c | 14 +++++++++++---
 sys/fs/ext2fs/ext2fs.h      | 19 ++++++++++++-------
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/sys/fs/ext2fs/ext2_vfsops.c b/sys/fs/ext2fs/ext2_vfsops.c
index a18d5cc1..5c36be9 100644
--- a/sys/fs/ext2fs/ext2_vfsops.c
+++ b/sys/fs/ext2fs/ext2_vfsops.c
@@ -290,9 +290,10 @@ ext2_check_sb_compat(struct ext2fs *es, struct cdev *dev, int ronly)
 		return (1);
 	}
 	if (es->e2fs_rev > E2FS_REV0) {
-		if (es->e2fs_features_incompat & ~EXT2F_INCOMPAT_SUPP) {
-			printf(
-"WARNING: mount of %s denied due to unsupported optional features\n",
+		if (!ronly &&
+		    (es->e2fs_features_incompat & EXT4F_RO_INCOMPAT_SUPP)) {
+			printf("WARNING: R/W mount of %s denied due to "
+			    "ext4fs only can be mounted with R/O\n",
 			    devtoname(dev));
 			return (1);
 		}
@@ -302,6 +303,13 @@ ext2_check_sb_compat(struct ext2fs *es, struct cdev *dev, int ronly)
 			    "unsupported optional features\n", devtoname(dev));
 			return (1);
 		}
+		if (es->e2fs_features_incompat &
+		    ~(EXT2F_INCOMPAT_SUPP | EXT4F_RO_INCOMPAT_SUPP)) {
+			printf("WARNING: mount of %s denied due to "
+			    "unsupported optional features\n",
+			    devtoname(dev));
+			return (1);
+		}
 	}
 	return (0);
 }
diff --git a/sys/fs/ext2fs/ext2fs.h b/sys/fs/ext2fs/ext2fs.h
index b562287..05ab23d 100644
--- a/sys/fs/ext2fs/ext2fs.h
+++ b/sys/fs/ext2fs/ext2fs.h
@@ -201,18 +201,23 @@ struct csum {
  * - EXT2F_ROCOMPAT_SPARSESUPER
  * - EXT2F_ROCOMPAT_LARGEFILE
  * - EXT2F_INCOMPAT_FTYPE
- *
- * We partially (read-only) support the following EXT4 features:
- * - EXT2F_ROCOMPAT_HUGE_FILE
- * - EXT2F_ROCOMPAT_EXTRA_ISIZE
- * - EXT2F_INCOMPAT_EXTENTS
  */
 #define EXT2F_COMPAT_SUPP		0x0000
 #define EXT2F_ROCOMPAT_SUPP		(EXT2F_ROCOMPAT_SPARSESUPER | \
 					 EXT2F_ROCOMPAT_LARGEFILE | \
 					 EXT2F_ROCOMPAT_EXTRA_ISIZE)
-#define EXT2F_INCOMPAT_SUPP		(EXT2F_INCOMPAT_FTYPE |	\
-					 EXT2F_INCOMPAT_EXTENTS)
+#define EXT2F_INCOMPAT_SUPP		(EXT2F_INCOMPAT_FTYPE)
+
+/*
+ * We partially (read-only) support the following EXT4 features:
+ * - EXT2F_ROCOMPAT_HUGE_FILE
+ * - EXT2F_ROCOMPAT_GDT_CSUM
+ * - EXT2F_ROCOMPAT_EXTRA_ISIZE
+ * - EXT2F_INCOMPAT_EXTENTS
+ * - EXT2F_INCOMPAT_FLEX_BG
+ */
+#define EXT4F_RO_INCOMPAT_SUPP		(EXT2F_INCOMPAT_EXTENTS | \
+					 EXT2F_INCOMPAT_FLEX_BG)
 
 /* Assume that user mode programs are passing in an ext2fs superblock, not
  * a kernel struct super_block.  This will allow us to call the feature-test
-- 
1.8.4.2



>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list