linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* udev causing stale device nodes
@ 2004-02-23 13:20 Arnd Bergmann
  2004-02-23 21:05 ` Olaf Hering
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Arnd Bergmann @ 2004-02-23 13:20 UTC (permalink / raw)
  To: linux-hotplug

I got a report about symlinks in /udev pointing to the wrong disks.
It turned out that the system had crashed and during the next
reboot the disks were detected in a different order. The symlinks
were created with the disk label but pointing to the device nodes
from the previous boot:

/udev/dasda
/udev/dasda1
/udev/dasdb
/udev/dasdb1
/udev/dasd/label/0X1000/disc -> ../../dasda
/udev/dasd/label/0X1000/part1 -> ../../dasda1
/udev/dasd/label/0X1001/disc -> ../../dasdb
/udev/dasd/label/0X1001/part1 -> ../../dasdb1
/udev/dasd/label/0X1002/disc -> ../../dasdb
/udev/dasd/label/0X1002/part1 -> ../../dasdb1

When the 0X1002 device appeared, the 0X1001 symlink still pointed
to the old device node. 
The worst thing that can happen is that two devices are added
in reverse order so both symlinks point to a wrong device.
The two solutions I could come up with are 
a) Always remove all udev-created nodes before udev starts
b) When a device appears, remove everything previously associated
   with that kernel name.
The patch below implements b) in a simple way, but I'm not sure
if there are some races left where a device node might be on disc
but not yet in udev's database.

	Arnd <><

diff -u udev-018/udev.c udev-018-patched/udev.c
--- udev-018/udev.c	2004-02-13 02:01:37.000000000 +0100
+++ udev-018-patched/udev.c	2004-02-19 14:53:20.000000000 +0100
@@ -163,13 +163,14 @@
 	/* initialize the naming deamon */
 	namedev_init();
 
-	if (strcmp(action, "add") = 0)
+	if (strcmp(action, "add") = 0) {
+		udev_remove_device(devpath, subsystem);
 		retval = udev_add_device(devpath, subsystem, 0);
 
-	else if (strcmp(action, "remove") = 0)
+	} else if (strcmp(action, "remove") = 0) {
 		retval = udev_remove_device(devpath, subsystem);
 
-	else {
+	} else {
 		dbg("unknown action '%s'", action);
 		retval = -EINVAL;
 	}



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
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] 5+ messages in thread

* Re: udev causing stale device nodes
  2004-02-23 13:20 udev causing stale device nodes Arnd Bergmann
@ 2004-02-23 21:05 ` Olaf Hering
  2004-02-23 22:35 ` Greg KH
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Olaf Hering @ 2004-02-23 21:05 UTC (permalink / raw)
  To: linux-hotplug

 On Mon, Feb 23, Arnd Bergmann wrote:

> a) Always remove all udev-created nodes before udev starts

Do you know a good reason to not rm the node and symlink before
creating them? I do it that way.


--- udev-add.c.orig	2004-02-17 18:40:39.000000000 +0000
+++ udev-add.c	2004-02-17 18:53:47.000000000 +0000
@@ -103,6 +103,7 @@ static int make_node(char *filename, int
 {
 	int retval;
 
+	unlink(filename);
 	retval = mknod(filename, mode, makedev(major, minor));
 	if (retval != 0) {
 		dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
@@ -133,7 +134,6 @@ static int make_node(char *filename, int
 
 static int create_node(struct udevice *dev, int fake)
 {
-	struct stat stats;
 	char filename[255];
 	char linktarget[255];
 	char partitionname[255];
@@ -247,18 +247,13 @@ static int create_node(struct udevice *d
 				i++;
 			}
 
-			if (linktarget[0] = '\0')
-				strcpy(linktarget, "./");
 			strcat(linktarget, &dev->name[tail]);
 
 			/* unlink existing files to ensure that our symlink is created */
-			if (!fake && (lstat(filename, &stats) = 0)) {
-				if ((stats.st_mode & S_IFMT) != S_IFDIR) {
+			if (!fake)
 					if (unlink(filename))
 						dbg("unlink(%s) failed with error '%s'",
 						    filename, strerror(errno));
-				}
-			}
 
 			dbg("symlink(%s, %s)", linktarget, filename);
 			if (!fake) {

-- 
USB is for mice, FireWire is for men!

sUse lINUX ag, n√úRNBERG


-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
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] 5+ messages in thread

* Re: udev causing stale device nodes
  2004-02-23 13:20 udev causing stale device nodes Arnd Bergmann
  2004-02-23 21:05 ` Olaf Hering
@ 2004-02-23 22:35 ` Greg KH
  2004-02-23 23:12 ` Kay Sievers
  2004-02-23 23:16 ` Arnd Bergmann
  3 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2004-02-23 22:35 UTC (permalink / raw)
  To: linux-hotplug

On Mon, Feb 23, 2004 at 02:20:17PM +0100, Arnd Bergmann wrote:
> I got a report about symlinks in /udev pointing to the wrong disks.
> It turned out that the system had crashed and during the next
> reboot the disks were detected in a different order. The symlinks
> were created with the disk label but pointing to the device nodes
> from the previous boot:

Why not just put /dev on a ramfs and then this problem would not even
happen?

thanks,

greg k-h


-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
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] 5+ messages in thread

* Re: udev causing stale device nodes
  2004-02-23 13:20 udev causing stale device nodes Arnd Bergmann
  2004-02-23 21:05 ` Olaf Hering
  2004-02-23 22:35 ` Greg KH
@ 2004-02-23 23:12 ` Kay Sievers
  2004-02-23 23:16 ` Arnd Bergmann
  3 siblings, 0 replies; 5+ messages in thread
From: Kay Sievers @ 2004-02-23 23:12 UTC (permalink / raw)
  To: linux-hotplug

On Mon, 2004-02-23 at 23:35, Greg KH wrote:
> On Mon, Feb 23, 2004 at 02:20:17PM +0100, Arnd Bergmann wrote:
> > I got a report about symlinks in /udev pointing to the wrong disks.
> > It turned out that the system had crashed and during the next
> > reboot the disks were detected in a different order. The symlinks
> > were created with the disk label but pointing to the device nodes
> > from the previous boot:
> 
> Why not just put /dev on a ramfs and then this problem would not even
> happen?

And you get a diskless udev-db for free with ramfs. :)

Kay



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
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] 5+ messages in thread

* Re: Re: udev causing stale device nodes
  2004-02-23 13:20 udev causing stale device nodes Arnd Bergmann
                   ` (2 preceding siblings ...)
  2004-02-23 23:12 ` Kay Sievers
@ 2004-02-23 23:16 ` Arnd Bergmann
  3 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2004-02-23 23:16 UTC (permalink / raw)
  To: linux-hotplug


Greg KH <greg@kroah.com> schrieb am 23.02.2004, 23:35:25:

> Why not just put /dev on a ramfs and then this problem would not even
> happen?

Of course, that would fix it. However, I'm not comfortable with
requiring /dev to be on ramfs. If users wants to have /dev on
a writable root file system, they should be able to do this
without risking data corruption by accessing the wrong devices.

After all, having /dev as part of / is the traditional setup.

       Arnd <><


-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
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] 5+ messages in thread

end of thread, other threads:[~2004-02-23 23:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-23 13:20 udev causing stale device nodes Arnd Bergmann
2004-02-23 21:05 ` Olaf Hering
2004-02-23 22:35 ` Greg KH
2004-02-23 23:12 ` Kay Sievers
2004-02-23 23:16 ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).