/dev/root: which approach ? [PATCH]
Subsystems (2)
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 (¤t->fs->lock); + mnt =mntget (current->fs->rootmnt); + dev = mnt->mnt_sb->s_dev; +mntput (mnt); +read_unlock (¤t->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
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/rootnode 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_rdevis then different fromblockdevice->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?
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/rootnode 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_rdevis then different fromblockdevice->bd_dev.
Quoted 5 lines
The
/dev/rootalias 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.
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 (¤t->fs->lock); + mnt =mntget (current->fs->rootmnt); + dev = mnt->mnt_sb->s_dev; +mntput (mnt); +read_unlock (¤t->fs->lock); + } inode =iget5_locked (bd_mnt->mnt_sb,hash (dev), bdev_test, bdev_set, &dev);
what is this 4,1, a tty???
--Mika
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.
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
Quoted 1 line · Mika Penttilä
what is this 4,1, a tty???
/dev/tty1