Skip to contentSkip to conversation

/dev/root: which approach ? [PATCH]

PATCH Miquel van Smoorenburg 5 participants 7 messages Mar 10, 2004 – Mar 12, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Currently if you boot from a blockdevice with a dynamically allocated major number (such as LVM or partitionable raid), there is no way to check the root filesystem. The root fs is still read-only, so you cannot create a device node anywhere to point fsck at.

This was discussed on the linux-raid mailinglist, and I proposed (as proof of concept) a simple check in bdget() to see if the device is being opened is the /dev/root node and if so redirect it to the current root device. This is a 8-line patch, the only disadvantage I can think of is that for an open file, inode->i_rdev is then different from blockdevice->bd_dev. Shouldn't be a problem.

Neil Brown also proposed 2 potential solutions; one is making rootfs remountable so that you can mount -t rootfs rootfs /mnt/root and then fsck /mnt/root/dev/root (below as remount_rootfs.patch).

His second one is a patch that adds a /proc/pid/rootdev blockdevice, below as proc_pid_rootdev.patch (partially rewritten by me). This should probably be optimized to move the i_rdev resolving out of init_proc_pid_rootdev_inode() and into open() / getattr().

My question to the FS hackers: which one is the preferred approach?

dev_root_alias.patch

fs/block_dev.c +10 -0
@@ -338,6 +338,16 @@ struct block_device *bdget(dev_t dev)
 {
 	struct block_device *bdev;
 	struct inode *inode;
+	struct vfsmount *mnt;
+
+	/* See if device is the /dev/root alias. */
+	if (dev == MKDEV(4, 1)) {
+		read_lock(&current->fs->lock);
+		mnt = mntget(current->fs->rootmnt);
+		dev = mnt->mnt_sb->s_dev;
+		mntput(mnt);
+		read_unlock(&current->fs->lock);
+	}
 
 	inode = iget5_locked(bd_mnt->mnt_sb, hash(dev),
 			bdev_test, bdev_set, &dev);

remount_rootfs.patch

fs/ramfs/inode.c renamed from fs/ramfs/inode.c~current~ +1 -1
@@ -207,7 +207,7 @@ static struct super_block *ramfs_get_sb(
 static struct super_block *rootfs_get_sb(struct file_system_type *fs_type,
 	int flags, const char *dev_name, void *data)
 {
-	return get_sb_nodev(fs_type, flags|MS_NOUSER, data, ramfs_fill_super);
+	return get_sb_single(fs_type, flags, data, ramfs_fill_super);
 }
 
 static struct file_system_type ramfs_fs_type = {

proc_rootdev.patch

fs/proc/base.c +41 -2

91 lines not on this page · raw message

#1 lore raw
Quoted 7 lines · Miquel van Smoorenburg

Currently if you boot from a blockdevice with a dynamically allocated major number (such as LVM or partitionable raid), there is no way to check the root filesystem. The root fs is still read-only, so you cannot create a device node anywhere to point fsck at.

Quoted 6 lines

This was discussed on the linux-raid mailinglist, and I proposed (as proof of concept) a simple check in bdget() to see if the device is being opened is the /dev/root node and if so redirect it to the current root device. This is a 8-line patch, the only disadvantage I can think of is that for an open file, inode->i_rdev is then different from blockdevice->bd_dev.

The /dev/root alias resolution looks nice to me, which probably means that it has a fatal flaw.

Is it not possible to create a device node on ramfs or ramdisk and point fsck at that?

#3 lore raw
In reply to Miquel van Smoorenburg
Quoted 17 lines

My question to the FS hackers: which one is the preferred approach?

dev_root_alias.patch

fs/block_dev.c +3 -0
@@ -338,6 +338,16 @@ struct block_device *bdget(dev_t dev)
 {
 	struct block_device *bdev;
 	struct inode *inode;
+	struct vfsmount *mnt;
+
+	/* See if device is the /dev/root alias. */

fs/block_dev.c struct block_device *bdget(dev_t dev) · line 353

Quoted 10 lines
fs/block_dev.c +7 -0
+	if (dev == MKDEV(4, 1)) {
+		read_lock(&current->fs->lock);
+		mnt = mntget(current->fs->rootmnt);
+		dev = mnt->mnt_sb->s_dev;
+		mntput(mnt);
+		read_unlock(&current->fs->lock);
+	}
 
 	inode = iget5_locked(bd_mnt->mnt_sb, hash(dev),
 			bdev_test, bdev_set, &dev);

what is this 4,1, a tty???

--Mika

#2 lore raw
In reply to Andrew Morton

In article <[email protected]>,

Quoted 15 lines · Andrew Morton
Quoted 7 lines · Miquel van Smoorenburg

Currently if you boot from a blockdevice with a dynamically allocated major number (such as LVM or partitionable raid), there is no way to check the root filesystem. The root fs is still read-only, so you cannot create a device node anywhere to point fsck at.

Quoted 6 lines

This was discussed on the linux-raid mailinglist, and I proposed (as proof of concept) a simple check in bdget() to see if the device is being opened is the /dev/root node and if so redirect it to the current root device. This is a 8-line patch, the only disadvantage I can think of is that for an open file, inode->i_rdev is then different from blockdevice->bd_dev.

Quoted 5 lines

The /dev/root alias resolution looks nice to me, which probably means that it has a fatal flaw.

Is it not possible to create a device node on ramfs or ramdisk and point fsck at that?

Yes, I thought of that too. But that wouldn't be trivial for existing installations, unless you're the maintainer of the distributions init package. Oh wait .. ;)

Anyway, it seemed to me to be very useful, and since /proc/mounts already refers to /dev/root it seemed to fit in naturally hence the proposed patches. If the definitive answer is "do it in userspace" then that's OK too.

Mike.

#4 lore raw
In reply to Mika Penttilä

In article <[email protected]>,

Quoted 9 lines · Mika Penttilä

fs/block_dev.c struct block_device *bdget(dev_t dev) · line 344

Quoted 7 lines

My question to the FS hackers: which one is the preferred approach?

dev_root_alias.patch

fs/block_dev.c +2 -0
+	/* See if device is the /dev/root alias. */
+	if (dev == MKDEV(4, 1)) {

what is this 4,1, a tty???

If it was a character device, yes. But it's a block device, and major 4 isn't used yet. I just made it up, a major would need to be allocated by LANANA ofcourse.

Mike.

#5 lore raw
In reply to Miquel van Smoorenburg
Followup to:  <[email protected]>
By author:    "Miquel van Smoorenburg" <[email protected]>
In newsgroup: linux.dev.kernel
Quoted 8 lines

In article <[email protected]>,

Quoted 5 lines · Mika Penttilä
Quoted 5 lines

My question to the FS hackers: which one is the preferred approach?

dev_root_alias.patch

Quoted 9 lines
Quoted 4 lines

fs/block_dev.c struct block_device *bdget(dev_t dev) · line 344

Quoted 2 lines
fs/block_dev.c +2 -0
+	/* See if device is the /dev/root alias. */
+	if (dev == MKDEV(4, 1)) {

what is this 4,1, a tty???

If it was a character device, yes. But it's a block device, and major 4 isn't used yet. I just made it up, a major would need to be allocated by LANANA ofcourse.

Please contact John Cagle <[email protected]>.

-hpa