* Re: [PATCH] creating link /dev/root to device / is mounted from
2007-04-20 10:46 [PATCH] creating link /dev/root to device / is mounted from Matthias Schwarzott
@ 2007-04-20 14:55 ` Kay Sievers
2007-04-21 9:35 ` Matthias Schwarzott
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Kay Sievers @ 2007-04-20 14:55 UTC (permalink / raw)
To: linux-hotplug
On 4/20/07, Matthias Schwarzott <zzam@gentoo.org> wrote:
> Some software (like hal) needs the /dev/root link (as /proc/mounts can contain
> it).
Right, but HAL doesn't need it, it just assumes that device-file
entries in /proc/mounts are also available in /dev.
The "/dev/root missing but in /proc/mounts" only happens for people
who run their own compiled kernels without an initramfs.
> The attached patch contains one program which compares the major/minor number
> supplied to it on the command-line with the numbers of the device / is
> located on.
> It is used with this rule (see 60-root_link.rules):
> SUBSYSTEM="block", PROGRAM="blockdev_is_root $major $minor", SYMLINK+="root"
Why do we want to run a program for _every_ block device, just to
create /dev/root? It's an operation you only need to do once at
bootup, and the root-device is obviously already there, before you
start udev out of the rootfs. :)
The udev init-script checks if /dev is already mounted with tmpfs from
initramfs, if not, it will need to do it, and at that point, we can
just mknod /dev/root, can't we?
Kay
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] creating link /dev/root to device / is mounted from
2007-04-20 10:46 [PATCH] creating link /dev/root to device / is mounted from Matthias Schwarzott
2007-04-20 14:55 ` Kay Sievers
@ 2007-04-21 9:35 ` Matthias Schwarzott
2007-04-21 10:29 ` Andrey Borzenkov
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Matthias Schwarzott @ 2007-04-21 9:35 UTC (permalink / raw)
To: linux-hotplug
On Freitag, 20. April 2007, Kay Sievers wrote:
> On 4/20/07, Matthias Schwarzott <zzam@gentoo.org> wrote:
> > Some software (like hal) needs the /dev/root link (as /proc/mounts can
> > contain it).
>
> Right, but HAL doesn't need it, it just assumes that device-file
> entries in /proc/mounts are also available in /dev.
>
> The "/dev/root missing but in /proc/mounts" only happens for people
> who run their own compiled kernels without an initramfs.
>
> > The attached patch contains one program which compares the major/minor
> > number supplied to it on the command-line with the numbers of the device
> > / is located on.
> > It is used with this rule (see 60-root_link.rules):
> > SUBSYSTEM="block", PROGRAM="blockdev_is_root $major $minor",
> > SYMLINK+="root"
>
> Why do we want to run a program for _every_ block device, just to
> create /dev/root? It's an operation you only need to do once at
> bootup, and the root-device is obviously already there, before you
> start udev out of the rootfs. :)
>
I think this is not too bad, as the program itself is only around 3k size.
> The udev init-script checks if /dev is already mounted with tmpfs from
> initramfs, if not, it will need to do it, and at that point, we can
> just mknod /dev/root, can't we?
Well, our initramfs does not move its /dev to new mounted root filesystem, but
we get a completely fresh tmpfs.
We also can just have a program to write out major/minor of "/" and then mknod
it (outside of udev)
But I really like a link better.
Here I also can search udev-database (or whatever)
For example when /usr is already mounted (for udevinfo):
dev_nr=$(root_get_dev_nr)
dev_path=$(udevtrigger --verbose --attr-matchfiv=${dev_nr})
dev_name=$(udevinfo -q name --path ${dev_path})
ln -s /dev/${dev_name} /dev/root
Or inject some rule into udev like
ATTR{dev}="${dev_nr}", SYMLINK+="root"
But how to inject? /etc is read-only at udevd starting. Or can rule-files
include other rule files? Like in /dev/.udev/
Matthias
--
Matthias Schwarzott (zzam)
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] creating link /dev/root to device / is mounted from
2007-04-20 10:46 [PATCH] creating link /dev/root to device / is mounted from Matthias Schwarzott
2007-04-20 14:55 ` Kay Sievers
2007-04-21 9:35 ` Matthias Schwarzott
@ 2007-04-21 10:29 ` Andrey Borzenkov
2007-04-21 10:41 ` Kay Sievers
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Andrey Borzenkov @ 2007-04-21 10:29 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1.1: Type: text/plain, Size: 2449 bytes --]
On Saturday 21 April 2007, Matthias Schwarzott wrote:
> On Freitag, 20. April 2007, Kay Sievers wrote:
> > On 4/20/07, Matthias Schwarzott <zzam@gentoo.org> wrote:
> > > Some software (like hal) needs the /dev/root link (as /proc/mounts can
> > > contain it).
> >
> > Right, but HAL doesn't need it, it just assumes that device-file
> > entries in /proc/mounts are also available in /dev.
> >
> > The "/dev/root missing but in /proc/mounts" only happens for people
> > who run their own compiled kernels without an initramfs.
> >
> > > The attached patch contains one program which compares the major/minor
> > > number supplied to it on the command-line with the numbers of the
> > > device / is located on.
> > > It is used with this rule (see 60-root_link.rules):
> > > SUBSYSTEM=="block", PROGRAM=="blockdev_is_root $major $minor",
> > > SYMLINK+="root"
> >
> > Why do we want to run a program for _every_ block device, just to
> > create /dev/root? It's an operation you only need to do once at
> > bootup, and the root-device is obviously already there, before you
> > start udev out of the rootfs. :)
>
> I think this is not too bad, as the program itself is only around 3k size.
>
> > The udev init-script checks if /dev is already mounted with tmpfs from
> > initramfs, if not, it will need to do it, and at that point, we can
> > just mknod /dev/root, can't we?
>
> Well, our initramfs does not move its /dev to new mounted root filesystem,
> but we get a completely fresh tmpfs.
>
I believe, most iplementations do. Actually how you solve the issue
with /dev/null & Co. without it?
> We also can just have a program to write out major/minor of "/" and then
> mknod it (outside of udev)
> But I really like a link better.
> Here I also can search udev-database (or whatever)
>
Yes that is nice. What about a simple program that can manupulate udev
database? I am not sure if the format allows it though.
-andrey
> For example when /usr is already mounted (for udevinfo):
> dev_nr=$(root_get_dev_nr)
> dev_path=$(udevtrigger --verbose --attr-match=dev=${dev_nr})
> dev_name=$(udevinfo -q name --path ${dev_path})
> ln -s /dev/${dev_name} /dev/root
>
>
> Or inject some rule into udev like
> ATTR{dev}=="${dev_nr}", SYMLINK+="root"
> But how to inject? /etc is read-only at udevd starting. Or can rule-files
> include other rule files? Like in /dev/.udev/
>
> Matthias
[-- Attachment #1.2: Type: application/pgp-signature, Size: 189 bytes --]
[-- Attachment #2: Type: text/plain, Size: 286 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
[-- Attachment #3: Type: text/plain, Size: 226 bytes --]
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] creating link /dev/root to device / is mounted from
2007-04-20 10:46 [PATCH] creating link /dev/root to device / is mounted from Matthias Schwarzott
` (2 preceding siblings ...)
2007-04-21 10:29 ` Andrey Borzenkov
@ 2007-04-21 10:41 ` Kay Sievers
2007-04-21 13:31 ` Matthias Schwarzott
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Kay Sievers @ 2007-04-21 10:41 UTC (permalink / raw)
To: linux-hotplug
On 4/21/07, Matthias Schwarzott <zzam@gentoo.org> wrote:
> On Freitag, 20. April 2007, Kay Sievers wrote:
> > On 4/20/07, Matthias Schwarzott <zzam@gentoo.org> wrote:
> > > Some software (like hal) needs the /dev/root link (as /proc/mounts can
> > > contain it).
> >
> > Right, but HAL doesn't need it, it just assumes that device-file
> > entries in /proc/mounts are also available in /dev.
> >
> > The "/dev/root missing but in /proc/mounts" only happens for people
> > who run their own compiled kernels without an initramfs.
> >
> > > The attached patch contains one program which compares the major/minor
> > > number supplied to it on the command-line with the numbers of the device
> > > / is located on.
> > > It is used with this rule (see 60-root_link.rules):
> > > SUBSYSTEM="block", PROGRAM="blockdev_is_root $major $minor",
> > > SYMLINK+="root"
> >
> > Why do we want to run a program for _every_ block device, just to
> > create /dev/root? It's an operation you only need to do once at
> > bootup, and the root-device is obviously already there, before you
> > start udev out of the rootfs. :)
> >
> I think this is not too bad, as the program itself is only around 3k size.
Sure, but it's just not really needed, when all you need to do is to
run something like this _once_ at bootup:
if [ ! -e /dev/root ]; then
rootcpio=`echo / | /bin/cpio --quiet -o -H newc`
major=0x${rootcpio:62:8}
minor=0x${rootcpio:70:8}
if [ $((major)) -ne 0 ] ; then
/bin/mknod -m640 /dev/root b $major $minor
fi
fi
> > The udev init-script checks if /dev is already mounted with tmpfs from
> > initramfs, if not, it will need to do it, and at that point, we can
> > just mknod /dev/root, can't we?
>
> Well, our initramfs
Hmm, the issue should only occur _without_ an initramfs-image, right?
It's a different code path in the kernel, that should not happen when
initramfs code mounts /, then /proc/mounts has matching entries.
> does not move its /dev to new mounted root filesystem,but
> we get a completely fresh tmpfs.
Sure, we all just mount an empty tmpfs without any moving of nodes.
The thing is, the kernel does not create /dev/root in /dev of the root
on disk, it's in the kernel's initramfs, which every kernel has, even
when you don't use an cpio-image to pupulate it during bootup.
> We also can just have a program to write out major/minor of "/" and then mknod
> it (outside of udev)
> But I really like a link better.
> Here I also can search udev-database (or whatever)
>
> For example when /usr is already mounted (for udevinfo):
> dev_nr=$(root_get_dev_nr)
> dev_path=$(udevtrigger --verbose --attr-matchÞv=${dev_nr})
> dev_name=$(udevinfo -q name --path ${dev_path})
> ln -s /dev/${dev_name} /dev/root
Yeah, sure, a link looks a bit nicer, but I'm not sure that it's worth
all this effort.
Btw, how is your system doing an fsck on the rootfs? What device node
is it using?
Kay
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] creating link /dev/root to device / is mounted from
2007-04-20 10:46 [PATCH] creating link /dev/root to device / is mounted from Matthias Schwarzott
` (3 preceding siblings ...)
2007-04-21 10:41 ` Kay Sievers
@ 2007-04-21 13:31 ` Matthias Schwarzott
2007-04-21 17:47 ` Doug Goldstein
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Matthias Schwarzott @ 2007-04-21 13:31 UTC (permalink / raw)
To: linux-hotplug
On Samstag, 21. April 2007, Kay Sievers wrote:
> On 4/21/07, Matthias Schwarzott <zzam@gentoo.org> wrote:
> > On Freitag, 20. April 2007, Kay Sievers wrote:
> >
> > Well, our initramfs
>
> Hmm, the issue should only occur _without_ an initramfs-image, right?
> It's a different code path in the kernel, that should not happen when
> initramfs code mounts /, then /proc/mounts has matching entries.
>
> > does not move its /dev to new mounted root filesystem,but
> > we get a completely fresh tmpfs.
>
> Sure, we all just mount an empty tmpfs without any moving of nodes.
> The thing is, the kernel does not create /dev/root in /dev of the root
> on disk, it's in the kernel's initramfs, which every kernel has, even
> when you don't use an cpio-image to pupulate it during bootup.
Yeah - but I meant some initramfs images do mount a tmpfs - and /dev/root on
it, and later move that mounted fs onto the its final position.
>
> > We also can just have a program to write out major/minor of "/" and then
> > mknod it (outside of udev)
> > But I really like a link better.
> > Here I also can search udev-database (or whatever)
> >
> > For example when /usr is already mounted (for udevinfo):
> > dev_nr=$(root_get_dev_nr)
> > dev_path=$(udevtrigger --verbose --attr-matchÞv=${dev_nr})
> > dev_name=$(udevinfo -q name --path ${dev_path})
> > ln -s /dev/${dev_name} /dev/root
>
> Yeah, sure, a link looks a bit nicer, but I'm not sure that it's worth
> all this effort.
>
Depends :)
Only thing that I dislike on this solution is that it needs udevinfo that is
in /usr/bin, make it impossible to do it right after udev has been started,
but in another init-script.
> Btw, how is your system doing an fsck on the rootfs? What device node
> is it using?
It just uses the device node listed in fstab :)
Yeah, that is the other possibility - if fstab has a entry for "/" just create
a symlink there. (But here it can differ from the real used device.)
Matthias
--
Matthias Schwarzott (zzam)
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] creating link /dev/root to device / is mounted from
2007-04-20 10:46 [PATCH] creating link /dev/root to device / is mounted from Matthias Schwarzott
` (4 preceding siblings ...)
2007-04-21 13:31 ` Matthias Schwarzott
@ 2007-04-21 17:47 ` Doug Goldstein
2007-04-22 12:01 ` Kay Sievers
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Doug Goldstein @ 2007-04-21 17:47 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1.1.1: Type: text/plain, Size: 754 bytes --]
I honestly feel that this is a kernel issue. Since according to the
mount man page, /proc/mounts and /etc/mtab should be relatively in sync
and /etc/mtab can technically be a symlink of /proc/mounts. It states
that /proc/mounts should update quicker and as such should technically
be more reliable. Which I feel contradicts some people's opinions that
the kernel and /proc/mounts can not be trusted. I think this is bogus
because with an initramfs, the kernel does the right thing. Without one,
it hardcodes itself to /dev/root when the kernel knows via the root=
option what the proper dev node should be.
As a result, here's a kernel patch to correct this issue.
--
Doug Goldstein <cardoe@gentoo.org>
http://dev.gentoo.org/~cardoe/
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: dev-root-real-root.patch --]
[-- Type: text/x-patch; name="dev-root-real-root.patch", Size: 913 bytes --]
--- linux-2.6.20-gentoo-r6/init/do_mounts.c 2007-04-17 01:27:27.000000000 -0400
+++ linux-dev-root/init/do_mounts.c 2007-04-21 13:00:32.000000000 -0400
@@ -354,7 +354,10 @@
va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);
- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
+ if (saved_root_name[0])
+ fd = sys_open(saved_root_name, O_RDWR | O_NDELAY, 0);
+ else
+ fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
if (fd >= 0) {
sys_ioctl(fd, FDEJECT, 0);
sys_close(fd);
@@ -397,8 +400,13 @@
}
#endif
#ifdef CONFIG_BLOCK
- create_dev("/dev/root", ROOT_DEV);
- mount_block_root("/dev/root", root_mountflags);
+ if (saved_root_name[0]) {
+ create_dev(saved_root_name, ROOT_DEV);
+ mount_block_root(saved_root_name, root_mountflags);
+ } else {
+ create_dev("/dev/root", ROOT_DEV);
+ mount_block_root("/dev/root", root_mountflags);
+ }
#endif
}
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]
[-- Attachment #2: Type: text/plain, Size: 286 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
[-- Attachment #3: Type: text/plain, Size: 226 bytes --]
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] creating link /dev/root to device / is mounted from
2007-04-20 10:46 [PATCH] creating link /dev/root to device / is mounted from Matthias Schwarzott
` (5 preceding siblings ...)
2007-04-21 17:47 ` Doug Goldstein
@ 2007-04-22 12:01 ` Kay Sievers
2007-04-23 17:58 ` David Zeuthen
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Kay Sievers @ 2007-04-22 12:01 UTC (permalink / raw)
To: linux-hotplug
On 4/21/07, Doug Goldstein <cardoe@gentoo.org> wrote:
> I honestly feel that this is a kernel issue. Since according to the
> mount man page, /proc/mounts and /etc/mtab should be relatively in sync
> and /etc/mtab can technically be a symlink of /proc/mounts. It states
> that /proc/mounts should update quicker and as such should technically
> be more reliable. Which I feel contradicts some people's opinions that
> the kernel and /proc/mounts can not be trusted. I think this is bogus
> because with an initramfs, the kernel does the right thing. Without one,
> it hardcodes itself to /dev/root when the kernel knows via the root> option what the proper dev node should be.
>
> As a result, here's a kernel patch to correct this issue.
Right, that solves the most common case, but you can also pass:
root=8:5
as the major/minor which will not exist in the real root, just like
/dev/root doesn't exist. It's very likely, but there is still no
guarantee, that the device node will exist in the real root.
We are running in circles here. It's kind of ugly, sure, that the
kernel uses a name, that doesn't exist in /dev, but it's still only a
name, and in the past nothing required it to be an existing
device-name.
HAL makes the assumption that the names are existing devices-names,
which is kind of optimistic. Earlier versions of HAL just ignored the
name and used to stat() the mount-point which is theoretically the
better approach, but that broke the stupid autofs-like setups, so it
got changed to use the name again.
But we may just want to change HAL to handle mnt_dir = "/" as a
special case, instead of assuming the name to be a device-node. That
should solve the real problem we are seeing here.
We could also just check once at bootup, that the name for the
root-mount in /proc/mounts exists in /dev, and if not, just mknod an
entry with that name.
That would work with _all_ possible names that have been used to mount
the rootfs and don't exist later (simple example pasted at the end of
this mail).
I prefer changing HAL, or just create the node as a workaround - as
the kernel change will not be able to catch all use cases.
Thanks,
Kay
while read fsname dir type opts; do
case "$dir" in
/)
case "$fsname" in
/dev/*)
if [ ! -e "$fsname" ]; then
rootcpio=$(echo / | cpio --quiet -o -H newc)
major=0x${rootcpio:62:8}
minor=0x${rootcpio:70:8}
if [ $((major)) -ne 0 ] ; then
mknod -m640 $fsname b $major $minor
fi
fi
break;
;;
esac
break
;;
esac
done < /proc/mounts
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] creating link /dev/root to device / is mounted from
2007-04-20 10:46 [PATCH] creating link /dev/root to device / is mounted from Matthias Schwarzott
` (6 preceding siblings ...)
2007-04-22 12:01 ` Kay Sievers
@ 2007-04-23 17:58 ` David Zeuthen
2007-04-24 9:37 ` Kay Sievers
2007-05-03 5:56 ` David Zeuthen
9 siblings, 0 replies; 11+ messages in thread
From: David Zeuthen @ 2007-04-23 17:58 UTC (permalink / raw)
To: linux-hotplug
On Sun, 2007-04-22 at 14:01 +0200, Kay Sievers wrote:
> But we may just want to change HAL to handle mnt_dir = "/" as a
> special case, instead of assuming the name to be a device-node. That
> should solve the real problem we are seeing here.
I'm fine taking a patch to do that. Thanks!
David
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] creating link /dev/root to device / is mounted from
2007-04-20 10:46 [PATCH] creating link /dev/root to device / is mounted from Matthias Schwarzott
` (7 preceding siblings ...)
2007-04-23 17:58 ` David Zeuthen
@ 2007-04-24 9:37 ` Kay Sievers
2007-05-03 5:56 ` David Zeuthen
9 siblings, 0 replies; 11+ messages in thread
From: Kay Sievers @ 2007-04-24 9:37 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 393 bytes --]
On 4/23/07, David Zeuthen <david@fubar.dk> wrote:
> On Sun, 2007-04-22 at 14:01 +0200, Kay Sievers wrote:
> > But we may just want to change HAL to handle mnt_dir == "/" as a
> > special case, instead of assuming the name to be a device-node. That
> > should solve the real problem we are seeing here.
>
> I'm fine taking a patch to do that. Thanks!
Does this work for you Doug?
Thanks,
Kay
[-- Attachment #2: dev-root-is-mounted.patch --]
[-- Type: text/x-patch, Size: 5535 bytes --]
diff --git a/hald/linux/blockdev.c b/hald/linux/blockdev.c
index a8e64f6..f0c6eba 100644
--- a/hald/linux/blockdev.c
+++ b/hald/linux/blockdev.c
@@ -165,9 +165,6 @@ blockdev_refresh_mount_state (HalDevice
struct mntent mnt;
struct mntent *mnte;
char buf[1024];
- unsigned int major;
- unsigned int minor;
- dev_t devt = makedev(0, 0);
GSList *volumes = NULL;
GSList *volume;
@@ -189,43 +186,53 @@ blockdev_refresh_mount_state (HalDevice
/* loop over /proc/mounts */
while ((mnte = getmntent_r (f, &mnt, buf, sizeof(buf))) != NULL) {
struct stat statbuf;
- gboolean use_device_name_for_match;
+ dev_t devt;
- /*HAL_INFO ((" * /proc/mounts contain dev %s - type %s", mnt.mnt_fsname, mnt.mnt_type));*/
+ /* HAL_INFO ((" * /proc/mounts contain dev %s - type %s", mnt.mnt_fsname, mnt.mnt_type)); */
- /* If this is a nfs mount (fstype == 'nfs') ignore the mount. Reason:
- * 1. we don't list nfs devices in HAL
- * 2. more problematic: stat on mountpoints with 'stale nfs handle' never come
- * back and block complete HAL and all applications using HAL fail.
+ /* We don't handle nfs mounts in HAL and stat() on mountpoints,
+ * and we would block on 'stale nfs handle'.
*/
if (strcmp(mnt.mnt_type, "nfs") == 0)
continue;
- use_device_name_for_match = FALSE;
- /* get major:minor of special device file */
- if (stat (mnt.mnt_fsname, &statbuf) != 0) {
- /* DING DING DING... device node may have been deleted by udev
- * but device is still mounted and we haven't processed the uevent
- * for that deletion from udev..
- *
- * So in this case... fall back to comparing on device names
- * rather than pretending the device is not mounted as that's
- * what will happen if we just skip this /proc/mounts entry.
- *
- * The reason it's nicer to compare on major:minor is that
- * /proc/mounts is broken - it contains the *device name*
- * passed to mount(2) which in some cases may be a symlink
- * (on many distros it's common to see /proc/mounts contain
- * /dev/root as the device for /). Sigh...
- */
- use_device_name_for_match = TRUE;
- } else {
+ /* skip plain names, we look for device nodes */
+ if (mnt.mnt_fsname[0] != '/')
+ continue;
+
+ /*
+ * We can't just stat() the mountpoint, because it breaks all sorts
+ * non-disk filesystems. So assume, that the names in /proc/mounts
+ * are existing device-files used to mount the filesystem.
+ */
+ devt = makedev(0, 0);
+ if (stat (mnt.mnt_fsname, &statbuf) == 0) {
+ /* not a device node */
if (major (statbuf.st_rdev) == 0)
continue;
+
+ /* found major/minor */
+ devt = statbuf.st_rdev;
+ } else {
+ /* The root filesystem may be mounted by a device name that doesn't
+ * exist in the real root, like /dev/root, which the kernel uses
+ * internally, when no initramfs image is used. For "/", it is safe
+ * to get the major/minor by stat()'ing the mount-point.
+ */
+ if (strcmp (mnt.mnt_dir, "/") == 0 && stat ("/", &statbuf) == 0)
+ devt = statbuf.st_dev;
+
+ /* DING DING DING... the device-node may not exist, or is
+ * already deleted, but the device may be still mounted.
+ *
+ * We will fall back to looking up the device-name, instead
+ * of using major/minor.
+ */
}
- /*HAL_INFO (("* found mounts dev %s (%i:%i)", mnt.mnt_fsname, major (statbuf.st_rdev), minor (statbuf.st_rdev)));*/
- /* match against all hal volumes */
+ /* HAL_INFO (("* found mounts dev %s (%i:%i)", mnt.mnt_fsname,
+ major (devt), minor (devt))); */
+
for (volume = volumes; volume != NULL; volume = g_slist_next (volume)) {
HalDevice *dev;
gboolean is_match;
@@ -233,7 +240,8 @@ blockdev_refresh_mount_state (HalDevice
is_match = FALSE;
dev = HAL_DEVICE (volume->data);
- if (use_device_name_for_match) {
+ /* lookup dev_t or devname of known hal devices */
+ if (major (devt) == 0) {
const char *device_name;
device_name = hal_device_property_get_string (dev, "block.device");
@@ -243,14 +251,16 @@ blockdev_refresh_mount_state (HalDevice
if (strcmp (device_name, mnt.mnt_fsname) == 0)
is_match = TRUE;
} else {
- major = hal_device_property_get_int (dev, "block.major");
- if (major == 0)
+ unsigned int majornum;
+ unsigned int minornum;
+
+ majornum = hal_device_property_get_int (dev, "block.major");
+ if (majornum == 0)
continue;
- minor = hal_device_property_get_int (dev, "block.minor");
- devt = makedev (major, minor);
- /*HAL_INFO ((" match %s (%i:%i)", hal_device_get_udi (dev), major, minor));*/
+ minornum = hal_device_property_get_int (dev, "block.minor");
+ /* HAL_INFO ((" match %s (%i:%i)", hal_device_get_udi (dev), majornum, minornum)); */
- if (statbuf.st_rdev == devt)
+ if (majornum == major (devt) && minornum == minor (devt))
is_match = TRUE;
}
@@ -262,9 +272,8 @@ blockdev_refresh_mount_state (HalDevice
hasmntopt (&mnt, MNTOPT_RO) ? TRUE : FALSE);
hal_device_property_set_string (dev, "volume.mount_point", mnt.mnt_dir);
device_property_atomic_update_end ();
- /*HAL_INFO ((" set %s to be mounted at %s (%s)",
- hal_device_get_udi (dev), mnt.mnt_dir,
- hasmntopt (&mnt, MNTOPT_RO) ? "ro" : "rw"));*/
+ /* HAL_INFO ((" set %s to be mounted at %s (%s)", hal_device_get_udi (dev),
+ mnt.mnt_dir, hasmntopt (&mnt, MNTOPT_RO) ? "ro" : "rw")); */
volumes = g_slist_delete_link (volumes, volume);
break;
}
[-- Attachment #3: Type: text/plain, Size: 286 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
[-- Attachment #4: Type: text/plain, Size: 226 bytes --]
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH] creating link /dev/root to device / is mounted from
2007-04-20 10:46 [PATCH] creating link /dev/root to device / is mounted from Matthias Schwarzott
` (8 preceding siblings ...)
2007-04-24 9:37 ` Kay Sievers
@ 2007-05-03 5:56 ` David Zeuthen
9 siblings, 0 replies; 11+ messages in thread
From: David Zeuthen @ 2007-05-03 5:56 UTC (permalink / raw)
To: linux-hotplug
On Tue, 2007-04-24 at 11:37 +0200, Kay Sievers wrote:
> On 4/23/07, David Zeuthen <david@fubar.dk> wrote:
> > On Sun, 2007-04-22 at 14:01 +0200, Kay Sievers wrote:
> > > But we may just want to change HAL to handle mnt_dir = "/" as a
> > > special case, instead of assuming the name to be a device-node. That
> > > should solve the real problem we are seeing here.
> >
> > I'm fine taking a patch to do that. Thanks!
>
> Does this work for you Doug?
Doug told me on IRC this worked and it looks good to me. Committed,
thanks Kay!
David
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 11+ messages in thread