Skip to contentSkip to conversation

Possible udev bug and some questions

PATCH Martin Schlemmer 3 participants 10 messages Dec 24, 2003 – Dec 25, 2003

lore
Share & tools
lore
#0 lore raw

Hi

I know its not good form to post so many issues in one, but I am currently on dialup, and not for more than a few hours. Also please CC me, as I am not on this list.

1) if you look at the following code in namedev.c (in function do_callout()):

--

                if (sysfs_device) {
                        dbg("dev->bus='%s' sysfs_device->bus='%s'",
dev->bus, sysfs_device->bus);
                        if (strcasecmp(dev->bus, sysfs_device->bus) !=
0)
                                continue;

                }

--

there is a slight problem - if sysfs_device = NULL, then the 'strcasecmp(dev->bus, sysfs_device->bus) != 0' test will never be evaluated, and result in the callout to run for all non-phisical (?) devices.

Attached is a possible patch, and this also brings me to second question:

2) If I understand the udev manual correct, all 'methods' should have a suitable 'key'. If I now look again at namedev.c, then whenever we
work with a non-phisical (?) (or not attached to a phisical bus?) device, then non of the 'keys' used with 'methods' are available, as get_sysfs_device() fails. Should any of the 'methods' then be run? Or more to the code, should any of the do_* (do_callout, etc) functions then be called for a device for which get_sysfs_device() failed?

Reference code for above (function namedev_name_device()):

--

        /* find the sysfs_device associated with this class device */
        sysfs_device = get_sysfs_device(class_dev);
        if (sysfs_device) {
                dbg("sysfs_device->path='%s'", sysfs_device->path);
                dbg("sysfs_device->bus_id='%s'", sysfs_device->bus_id);
                dbg("sysfs_device->bus='%s'", sysfs_device->bus);
                strfieldcpy(udev->bus_id, sysfs_device->bus_id);
                wait_for_device_to_initialize(sysfs_device);
        } else {
                dbg("class_dev->name = '%s'", class_dev->name);
        }

--

3) After looking at ide-devfs.sh, I converted it to create the 'compat' symlinks (/dev/{cdroms,discs}/* stuff) if anybody is interested (as ide-devfs-compat.sh). Also, it would be nice if somebody could have a look for holes - I am not sure what will happen with modular ide setups ...

I would however like to extend it to scsi disks, but not sure what is the most generic and easy way to try and figure out how many disks there is ... any ideas?

This sorda brings me to point four:

4) Is there any reason why only one 'method' (meaning only one of the callouts I may have for ide devices - I may want to use both the ide-devfs.sh and ide-devfs-compat.sh to have multiple symlinks for on device ...) is done for each device and/or hotplug event (beside lack of time to implement) ? Same for why only 'type' of 'method' is done for each (if a CALLOUT is done, the rest is skipped) ?

If no other reason that time, is anybody working on it, and if not, any pointers to not clash with future plans (meaning I might want to take a shot at implementing it)?

5) I use a devfs-less setup with udev, 2.6.0 kernel with most of the sysfs patches from Greg, if not all, and a pre 2.3.3 glibc. Also have devpts compiled in, and mounted to /dev/pts. I now have the following 'w' output:

--

 $ w
 00:22:22 up  1:15, 13 users,  load average: 0.98, 0.28, 0.14
USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT
azarah   tty4      23:07    1:14m  1.19s  0.00s /bin/sh
/usr/X11R6/bin/startx
azarah   ttyp0     23:08     ?     0.00s  0.00s -bash
azarah   ttyp1     23:08     ?     0.00s  0.00s -bash
...
--

where I would rather expect something like this (devfs box):

--

 $ w
 00:35:38 up 32 days,  8:01,  1 user,  load average: 0.19, 0.26, 0.20
USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT
azarah   pts/0     00:35    1.00s  0.04s  0.02s w
--

Just me, or somebody else have this as well? I know this could be a few things (glibc, etc), but I want to try and get a 'starting point' for debugging (if it should list 'pts/*' as TTY in the first place ...).

Thanks,

Signature · 1 line
Martin Schlemmer
namedev.c renamed from namedev.c.orig +3 -0
@@ -402,6 +402,9 @@
 			dbg("dev->bus='%s' sysfs_device->bus='%s'", dev->bus, sysfs_device->bus);
 			if (strcasecmp(dev->bus, sysfs_device->bus) != 0)
 				continue;
+		/* for this CALLOUT we need a valid sysfs_device */
+		} else if ((dev->bus != NULL) || (strlen(dev->bus) != 0)) {
+			continue;
 		}
 
 		/* substitute anything that needs to be in the program name */

#!/bin/sh

# udev CALLOUT script
# return compat devfs-names for ide-devices
# CALLOUT, BUS="ide", PROGRAM="/etc/udev/ide-devfs-compat.sh %k %b %n", ID="hd*", NAME="%1c", SYMLINK="%2c"

HOST=${2%\.[0-9]}
TARGET=${2#[0-9]\.}

if [ -z ${HOST#[13579]} ]; then

	HOST=`expr $HOST - 1`
	BUS="1"
else
	BUS="0"

fi

get_dev_number() {
	local x=
	local num=0
	local MEDIA=
	
	for x in /proc/ide/*/media; do
		if [ -e "$x" ]; then
			MEDIA=`cat $x`
			if [ "$MEDIA" = "$2" ]; then
				num=`expr $num + 1`
			fi
			if [ "$x" = "/proc/ide/$1/media" ]; then
				break
			fi
		fi
	done
	
	echo `expr $num - 1`
}

if [ -z "$3" ]; then

	MEDIA=`cat /proc/ide/$1/media`
	if [ "$MEDIA" = "cdrom" ]; then
		echo $1 cdroms/cdrom`get_dev_number $1 cdrom`
	elif [ "$MEDIA" = "disk" ]; then
		echo $1 discs/disc`get_dev_number $1 disk`/disc
	fi

else
echo $1 discs/discget_dev_number $1 disk/part$3
fi

#1 lore raw
Quoted 17 lines · Martin Schlemmer

Hi

I know its not good form to post so many issues in one, but I am currently on dialup, and not for more than a few hours. Also please CC me, as I am not on this list.

1) if you look at the following code in namedev.c (in function do_callout()):

--

                if (sysfs_device) {
                        dbg("dev->bus='%s' sysfs_device->bus='%s'",
dev->bus, sysfs_device->bus);
                        if (strcasecmp(dev->bus, sysfs_device->bus) !> 0)
                                continue;

                }
Quoted 6 lines

--

there is a slight problem - if sysfs_device = NULL, then the 'strcasecmp(dev->bus, sysfs_device->bus) != 0' test will never be evaluated, and result in the callout to run for all non-phisical (?) devices.

Ah, good catch. I've put a test in the udev-test.pl script to catch this bug, and added the following patch:

namedev.c +4 -1
@@ -399,7 +399,10 @@
 		if (dev->type != CALLOUT)
 			continue;
 
-		if (sysfs_device) {
+		if (dev->bus[0] != '\0') {
+			/* as the user specified a bus, we must match it up */
+			if (!sysfs_device)
+				continue;
 			dbg("dev->bus='%s' sysfs_device->bus='%s'", dev->bus, sysfs_device->bus);
 			if (strcasecmp(dev->bus, sysfs_device->bus) != 0)
 				continue;

I also made the BUS key optional for the CALLOUT rule. If the BUS value is not present, then the CALLOUT rule is always called. Does this work for you?

Quoted 7 lines

2) If I understand the udev manual correct, all 'methods' should have a suitable 'key'. If I now look again at namedev.c, then whenever we
work with a non-phisical (?) (or not attached to a phisical bus?) device, then non of the 'keys' used with 'methods' are available, as get_sysfs_device() fails. Should any of the 'methods' then be run? Or more to the code, should any of the do_* (do_callout, etc) functions then be called for a device for which get_sysfs_device() failed?

Yeah, I've been thinking about this too. There are a lot of devices in sysfs that do not have a "device" symlink right now (for one reason or another...) When the device symlink is present, we can get a lot more information about the device, and use it in udev.

Right now, if we can not find a sysfs_device, we can still run most of the rules. LABEL works, CALLOUT now works, NUMBER makes no sense at all without a sysfs_device and does not work. Same thing for TOPOLOGY. Then REPLACE works too.

So without that link, we do the best that we can.

Is there something about the way devices without a sysfs_device works in udev today that you do not like (except for the above bug...)

Quoted 6 lines

4) Is there any reason why only one 'method' (meaning only one of the callouts I may have for ide devices - I may want to use both the ide-devfs.sh and ide-devfs-compat.sh to have multiple symlinks for on device ...) is done for each device and/or hotplug event (beside lack of time to implement) ? Same for why only 'type' of 'method' is done for each (if a CALLOUT is done, the rest is skipped) ?

We stop comparing when we find the first rule that succeeds. Otherwise how are we going to handle "catchall rules"? I don't want to have to come up with a situation of weighting rules, and if more than one matches, determing what needs to be done (both, none, one, etc.)

If you want to call two callout scripts, just make a new script that calls them both :)

Quoted 4 lines

5) I use a devfs-less setup with udev, 2.6.0 kernel with most of the sysfs patches from Greg, if not all, and a pre 2.3.3 glibc. Also have devpts compiled in, and mounted to /dev/pts. I now have the following 'w' output:

Are you using udev to manage your /dev tree?

'w' works for me without using udev to manage my /dev tree. Try that to see if it's a udev issue or not.

thanks,

greg k-h

-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#2 lore raw
In reply to Martin Schlemmer
Quoted 20 lines · Greg KH
Quoted 19 lines · Martin Schlemmer

Hi

I know its not good form to post so many issues in one, but I am currently on dialup, and not for more than a few hours. Also please CC me, as I am not on this list.

1) if you look at the following code in namedev.c (in function do_callout()):

--

                if (sysfs_device) {
                        dbg("dev->bus='%s' sysfs_device->bus='%s'",
dev->bus, sysfs_device->bus);
                        if (strcasecmp(dev->bus, sysfs_device->bus) !> > 0)
                                continue;

                }

--

Quoted 7 lines
Quoted 4 lines

there is a slight problem - if sysfs_device = NULL, then the 'strcasecmp(dev->bus, sysfs_device->bus) != 0' test will never be evaluated, and result in the callout to run for all non-phisical (?) devices.

Ah, good catch. I've put a test in the udev-test.pl script to catch this bug, and added the following patch:

I made the same patch for the LABEL rule, as that also could trigger wrong acceptances.

thanks again.

greg k-h

-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#3 lore raw
In reply to Martin Schlemmer
Quoted 3 lines · Martin Schlemmer

3) After looking at ide-devfs.sh, I converted it to create the 'compat' symlinks (/dev/{cdroms,discs}/* stuff) if anybody is interested (as ide-devfs-compat.sh).

[...]

Quoted 6 lines

4) Is there any reason why only one 'method' (meaning only one of the callouts I may have for ide devices - I may want to use both the ide-devfs.sh and ide-devfs-compat.sh to have multiple symlinks for on device ...) is done for each device and/or hotplug event (beside lack of time to implement) ? Same for why only 'type' of 'method' is done for each (if a CALLOUT is done, the rest is skipped) ?

Why not merge the two callout scripts in one, so that it returns the two symlinks at once?
We support multiple symlinks separated by spaces.

...,NAME="%k", SYMLINK="%2c %3c"

Quoted 5 lines

5) I use a devfs-less setup with udev, 2.6.0 kernel with most of the sysfs patches from Greg, if not all, and a pre 2.3.3 glibc. Also have devpts compiled in, and mounted to /dev/pts. I now have the following 'w' output:

Quoted 8 lines

--

 $ w
 00:22:22 up  1:15, 13 users,  load average: 0.98, 0.28, 0.14
USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT
azarah   tty4      23:07    1:14m  1.19s  0.00s /bin/sh
/usr/X11R6/bin/startx
azarah   ttyp0     23:08     ?     0.00s  0.00s -bash
azarah   ttyp1     23:08     ?     0.00s  0.00s -bash

No problem here, my glibc package is 2.3.2.

kay@pim:~/src/udev.kay$ w
10:55:19 up 4 days, 22:53,  4 users,  load average: 0.00, 0.02, 0.05
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
kay      tty1     -                Sat12    4days 38.78s  0.00s /bin/sh /usr/bin/X11/startx
kay      pts/0    :0.0             10:12    0.00s  0.07s  0.00s w
kay      pts/1    :0.0             10:43   24.00s  0.23s  0.22s ssh puk
kay      pts/2    :0.0             10:20   28:38   0.04s  0.04s bash

thanks,
Kay

-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#4 lore raw
In reply to Martin Schlemmer
Quoted 9 lines · Greg KH
Quoted 8 lines

1) if you look at the following code in namedev.c (in function do_callout()):

there is a slight problem - if sysfs_device = NULL, then the 'strcasecmp(dev->bus, sysfs_device->bus) != 0' test will never be evaluated, and result in the callout to run for all non-phisical (?) devices.

Quoted 7 lines

Ah, good catch. I've put a test in the udev-test.pl script to catch this bug, and added the following patch:

I also made the BUS key optional for the CALLOUT rule. If the BUS value is not present, then the CALLOUT rule is always called. Does this work for you?

Seems Ok, thanks.

Quoted 9 lines
Quoted 7 lines

2) If I understand the udev manual correct, all 'methods' should have a suitable 'key'. If I now look again at namedev.c, then whenever we
work with a non-phisical (?) (or not attached to a phisical bus?) device, then non of the 'keys' used with 'methods' are available, as get_sysfs_device() fails. Should any of the 'methods' then be run? Or more to the code, should any of the do_* (do_callout, etc) functions then be called for a device for which get_sysfs_device() failed?

Quoted 7 lines

Right now, if we can not find a sysfs_device, we can still run most of the rules. LABEL works, CALLOUT now works, NUMBER makes no sense at all without a sysfs_device and does not work. Same thing for TOPOLOGY. Then REPLACE works too.

So without that link, we do the best that we can.

Ok, makes sense - just wanted to verify if I should look deeper or not.

Quoted 3 lines

Is there something about the way devices without a sysfs_device works in udev today that you do not like (except for the above bug...)

No. Once again, I was not sure about CALLOUT, LABEL, NUMBER and TOPOLOGY, but CALLOUT is fixed, and according to your other mail, so is LABEL, and NUMBER and TOPOLOGY have sufficient checks for valid sysfs_device.

Quoted 8 lines
Quoted 7 lines

4) Is there any reason why only one 'method' (meaning only one of the callouts I may have for ide devices - I may want to use both the ide-devfs.sh and ide-devfs-compat.sh to have multiple symlinks for on device ...) is done for each device and/or hotplug event (beside lack of time to implement) ? Same for why only 'type' of 'method' is done for each (if a CALLOUT is done, the rest is skipped) ?

Quoted 5 lines

We stop comparing when we find the first rule that succeeds. Otherwise how are we going to handle "catchall rules"? I don't want to have to come up with a situation of weighting rules, and if more than one matches, determing what needs to be done (both, none, one, etc.)

I was thinking more of 'find one, do whatever, find next, do whatever'. I can see however that this could get messy.

Quoted 3 lines

If you want to call two callout scripts, just make a new script that calls them both :)

I do not see how to do that, except if you let the scripts create the symlinks/whatever, which is not entirely what I want.

Let me give an example that do not use CALLOUT:

LABEL BUS="scsi", SYSFS_type="5", SYMLINK="cdroms/cdrom%n" LABEL BUS="scsi", SYSFS_type="5", SYMLINK="sr/%n"

Silly/may_not_work example, but it basically shows that I want two symlinks for the same thing ...

The only other logical way I can think of, is to be able to stack SYMLINK like so:

LABEL BUS="scsi", SYSFS_type="5", SYMLINK="cdroms/cdrom%n", SYMLINK="sr/%n"

which does not work currently. That Ok with you?

A note though - I tried a quick hack for above with the help of the list.h stuff (needs some more work to not actually segfault :/), but then I got to the db stuff, and realized that it will be a slight issue to a link list saved with the tdb stuff - much hacking. Other ideas that may be easier?

Quoted 10 lines
Quoted 4 lines

5) I use a devfs-less setup with udev, 2.6.0 kernel with most of the sysfs patches from Greg, if not all, and a pre 2.3.3 glibc. Also have devpts compiled in, and mounted to /dev/pts. I now have the following 'w' output:

Are you using udev to manage your /dev tree?

'w' works for me without using udev to manage my /dev tree. Try that to see if it's a udev issue or not.

Bah, my udev.permissions was too gracious with test for /dev/pt* (parallel tape drives), and set /dev/ptmx with 0600 permissions as well :/ Thanks anyhow for looking.

Last question - with the pending libsysfs fixes, will there still be the need for the second or so delay? Why I am asking, is because if I want to generate devices in initramfs or such, it still will take a long time ...

Thanks,

Signature · 1 line
Martin Schlemmer
#5 lore raw
In reply to Martin Schlemmer
Quoted 17 lines · Martin Schlemmer
Quoted 16 lines · Kay Sievers
Quoted 3 lines · Martin Schlemmer

3) After looking at ide-devfs.sh, I converted it to create the 'compat' symlinks (/dev/{cdroms,discs}/* stuff) if anybody is interested (as ide-devfs-compat.sh).

[...]

Quoted 6 lines

4) Is there any reason why only one 'method' (meaning only one of the callouts I may have for ide devices - I may want to use both the ide-devfs.sh and ide-devfs-compat.sh to have multiple symlinks for on device ...) is done for each device and/or hotplug event (beside lack of time to implement) ? Same for why only 'type' of 'method' is done for each (if a CALLOUT is done, the rest is skipped) ?

Why not merge the two callout scripts in one, so that it returns the two symlinks at once?
We support multiple symlinks separated by spaces.

Quoted 5 lines
Quoted 2 lines

...,NAME="%k", SYMLINK="%2c %3c"

Right, now why isn't that in the docs? Unfortunately I also missed it while trying at hacking multiple SYMLINK=foo, SYMLINK=bar support.

it's in a man page example :)
here is a patch for the script and a small fix for namedev to work with...

thanks,
Kay

extras/ide-devfs.sh +23 -4
diff -Nru a/extras/ide-devfs.sh b/extras/ide-devfs.sh
@@ -2,7 +2,7 @@
 
 # udev CALLOUT script
 # return devfs-names for ide-devices
-# CALLOUT, BUS="ide", PROGRAM="/etc/udev/ide-devfs.sh %k %b %n", ID="hd*", NAME="%1c", SYMLINK="%2c"
+# CALLOUT, PROGRAM="/etc/udev/ide-devfs.sh %k %b %n", ID="hd*", NAME="%1c", SYMLINK="%2c %3c"
 
 HOST=${2%\.[0-9]}
 TARGET=${2#[0-9]\.}
@@ -14,14 +14,33 @@
 	BUS="0"
 fi
 
+get_dev_number() {
+	local x=
+	local num=0
+	local MEDIA=
+	
+	for x in /proc/ide/*/media; do
+		if [ -e "$x" ]; then
+			MEDIA=`cat $x`
+			if [ "$MEDIA" = "$2" ]; then
+				num=`expr $num + 1`
+			fi
+			if [ "$x" = "/proc/ide/$1/media" ]; then
+				break
+			fi
+		fi
+	done
+	
+	echo `expr $num - 1`
+}
+
 if [ -z "$3" ]; then
 	MEDIA=`cat /proc/ide/$1/media`
 	if [ "$MEDIA" = "cdrom" ]; then
-		echo $1 ide/host$HOST/bus$BUS/target$TARGET/lun0/cd
+		echo $1 ide/host$HOST/bus$BUS/target$TARGET/lun0/cd cdroms/cdrom`get_dev_number $1 cdrom`
 	elif [ "$MEDIA" = "disk" ]; then
-		echo $1 ide/host$HOST/bus$BUS/target$TARGET/lun0/disc
+		echo $1 ide/host$HOST/bus$BUS/target$TARGET/lun0/disc discs/disc`get_dev_number $1 disc`
 	fi
 else
 	echo $1 ide/host$HOST/bus$BUS/target$TARGET/lun0/part$3
 fi
-
namedev.c +7 -4
diff -Nru a/namedev.c b/namedev.c
@@ -200,11 +200,12 @@
 			case 'D':
 				if (strlen(udev->kernel_number) == 0) {
 					strcat(pos, "disc");
+					dbg("substitute devfs disc");
 					break;
 				}
 				strcat(pos, "part");
 				strcat(pos, udev->kernel_number);
-				dbg("substitute kernel number '%s'", udev->kernel_number);
+				dbg("substitute devfs part number '%s'", udev->kernel_number);
 				break;
 			case 'm':
 				sprintf(pos, "%u", udev->minor);
@@ -225,12 +226,14 @@
 						num--;
 						pos3 = strsep(&pos2, " ");
 						if (pos3 == NULL) {
-							dbg("requested part of callout string not found");
+							dbg("requested part of callout string is empty");
 							break;
 						}
 					}
-					strcat(pos, pos3);
-					dbg("substitute partial callout output '%s'", pos3);
+					if (pos3) {
+						strcat(pos, pos3);
+						dbg("substitute partial callout output '%s'", pos3);
+					}
 				} else {
 					strcat(pos, udev->callout_value);
 					dbg("substitute callout output '%s'", udev->callout_value);
#6 lore raw
In reply to Martin Schlemmer
Quoted 5 lines · Martin Schlemmer
Quoted 2 lines

here is a patch for the script and a small fix for namedev to work with...

BTW, there is a slight issue with your version of the script - it drops the /dev/discs/part* symlinks. Patch against your version attached.

Are you sure devfs does partitions in there?
It only lists the discs on my machine:

  kay@pim:~/src/udev.kay$ tree /devfs/discs/
  /devfs/discs/
  |-- disc0 -> ../ide/host0/bus0/target0/lun0
  |-- disc1 -> ../ide/host0/bus0/target1/lun0
  `-- disc2 -> ../ide/host2/bus0/target0/lun0

Kay

-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#7 lore raw
In reply to Martin Schlemmer
Quoted 23 lines · Martin Schlemmer
Quoted 7 lines · Kay Sievers
Quoted 5 lines · Martin Schlemmer
Quoted 2 lines

here is a patch for the script and a small fix for namedev to work with...

BTW, there is a slight issue with your version of the script - it drops the /dev/discs/part* symlinks. Patch against your version attached.

Quoted 9 lines

Are you sure devfs does partitions in there?
It only lists the discs on my machine:

  kay@pim:~/src/udev.kay$ tree /devfs/discs/
  /devfs/discs/
  |-- disc0 -> ../ide/host0/bus0/target0/lun0
  |-- disc1 -> ../ide/host0/bus0/target1/lun0
  `-- disc2 -> ../ide/host2/bus0/target0/lun0

Well, seems like you modified some other things to the script as well. Here is a 2.4 box (and we have been using /dev/discs/*/disc to call hdparm for ages on 2.4 boxes):

--

Quoted 10 lines
$ ls -l /dev/discs/disc0/
total 0
brw-------    1 root     root       3,   0 Jan  1  1970 disc
brw-------    1 root     root       3,   1 Jan  1  1970 part1
brw-------    1 root     root       3,   2 Jan  1  1970 part2
brw-------    1 root     root       3,   3 Jan  1  1970 part3
azarah@gateway azarah $ uname -a
Linux gateway.lan 2.4.17 #2 Wed Aug 20 22:32:11 SAST 2003 i686 Pentium
III (Katmai) GenuineIntel GNU/Linux
azarah@gateway azarah $

What the hell is this?
Is it something in your devfs.conf, that creates this? On 2.4.20 I get:

  puk:~# tree /devfs/discs/
  /devfs/discs/
  `-- disc0 -> ../ide/host0/bus0/target0/lun0
Quoted 4 lines

Patch is attached to fix the other issue. It is a new version of previous patch. Also note that /proc/ide/*/media contain 'disk' for hdd's, so the call to get_dev_number() should have 'disk' as second argument, and not 'disc' ...

Yes, it should be 'disk' - i'm confused now :)

If you call get_dev_number() with hda1 it will newer break at the current device, cause there is is no hda1 in the iterated list. So it's ever the last dis[ck]

pim:/home/kay# ls -la /proc/ide/*/media
-r--r--r--    1 root     root            0 Dec 25 21:54 /proc/ide/hda/media
-r--r--r--    1 root     root            0 Dec 25 21:54 /proc/ide/hdb/media
-r--r--r--    1 root     root            0 Dec 25 21:54 /proc/ide/hdc/media
-r--r--r--    1 root     root            0 Dec 25 21:54 /proc/ide/hde/media

thanks,
Kay

-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#8 lore raw
In reply to Martin Schlemmer
Quoted 9 lines · Kay Sievers
Quoted 8 lines · Martin Schlemmer
Quoted 7 lines · Kay Sievers
Quoted 5 lines · Martin Schlemmer
Quoted 2 lines

here is a patch for the script and a small fix for namedev to work with...

BTW, there is a slight issue with your version of the script - it drops the /dev/discs/part* symlinks. Patch against your version attached.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Are you sure devfs does partitions in there?
It only lists the discs on my machine:

  kay@pim:~/src/udev.kay$ tree /devfs/discs/
  /devfs/discs/
  |-- disc0 -> ../ide/host0/bus0/target0/lun0
  |-- disc1 -> ../ide/host0/bus0/target1/lun0
  `-- disc2 -> ../ide/host2/bus0/target0/lun0

Oh, i see these are symlinks. Sorry, I misinterpreted the tree output. Sure, there is part and disk in there...

Kay

-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#9 lore raw
In reply to Martin Schlemmer
Quoted 4 lines · Martin Schlemmer

'../ide/host0/bus0/target0/lun0/*' should be the real devices with /dev/hd* and /dev/{cdroms,discs}/* the symlinks to 'ide/....'. I just cannot see how to do it easy with udev currently - correct me if I am wrong.

You're right, sorry for the confusion.

Quoted 1 line

Here is once again a replacement on that previous

Please have a look at this patch against clean v011. It seems to work now :)

thanks,
Kay

/udev/

|-- cdroms
|   `-- cdrom0 -> ../hdc
|-- discs
|   |-- disc0
|   |   |-- disc -> ../../hda
|   |   |-- part1 -> ../../hda1
|   |   |-- part2 -> ../../hda2
|   |   `-- part4 -> ../../hda4
|   |-- disc1
|   |   |-- disc -> ../../hdb
|   |   `-- part1 -> ../../hdb1
|   `-- disc2
|       |-- disc -> ../../hde
|       `-- part1 -> ../../hde1
|-- hda
|-- hda1
|-- hda2
|-- hda4
|-- hdb
|-- hdb1
|-- hdc
|-- hde
|-- hde1
`-- ide
    |-- host0
    |   |-- bus0
    |   |   |-- target0
    |   |   |   `-- lun0
    |   |   |       |-- disc -> ../../../../../hda
    |   |   |       |-- part1 -> ../../../../../hda1
    |   |   |       |-- part2 -> ../../../../../hda2
    |   |   |       `-- part4 -> ../../../../../hda4
    |   |   `-- target1
    |   |       `-- lun0
    |   |           |-- disc -> ../../../../../hdb
    |   |           `-- part1 -> ../../../../../hdb1
    |   `-- bus1
    |       `-- target0
    |           `-- lun0
    |               `-- cd -> ../../../../../hdc
    `-- host2
        `-- bus0
            `-- target0
                `-- lun0
                    |-- disc -> ../../../../../hde
                    `-- part1 -> ../../../../../hde1
extras/ide-devfs.sh +25 -5
diff -Nru a/extras/ide-devfs.sh b/extras/ide-devfs.sh
@@ -2,7 +2,7 @@
 
 # udev CALLOUT script
 # return devfs-names for ide-devices
-# CALLOUT, BUS="ide", PROGRAM="/etc/udev/ide-devfs.sh %k %b %n", ID="hd*", NAME="%1c", SYMLINK="%2c"
+# CALLOUT, BUS="ide", PROGRAM="/etc/udev/ide-devfs.sh %k %b %n", ID="hd*", NAME="%1c", SYMLINK="%2c %3c"
 
 HOST=${2%\.[0-9]}
 TARGET=${2#[0-9]\.}
@@ -14,14 +14,34 @@
 	BUS="0"
 fi
 
+get_dev_number() {
+	local x=
+	local num=0
+	local MEDIA=
+	local DRIVE=${1%[0-9]*}
+
+	for x in /proc/ide/*/media; do
+		if [ -e "$x" ]; then
+			MEDIA=`cat $x`
+			if [ "$MEDIA" = "$2" ]; then
+				num=`expr $num + 1`
+			fi
+			if [ "$x" = "/proc/ide/$DRIVE/media" ]; then
+				break
+			fi
+		fi
+	done
+	
+	echo `expr $num - 1`
+}
+
 if [ -z "$3" ]; then
 	MEDIA=`cat /proc/ide/$1/media`
 	if [ "$MEDIA" = "cdrom" ]; then
-		echo $1 ide/host$HOST/bus$BUS/target$TARGET/lun0/cd
+		echo $1 ide/host$HOST/bus$BUS/target$TARGET/lun0/cd cdroms/cdrom`get_dev_number $1 cdrom`
 	elif [ "$MEDIA" = "disk" ]; then
-		echo $1 ide/host$HOST/bus$BUS/target$TARGET/lun0/disc
+		echo $1 ide/host$HOST/bus$BUS/target$TARGET/lun0/disc discs/disc`get_dev_number $1 disk`/disc
 	fi
 else
-	echo $1 ide/host$HOST/bus$BUS/target$TARGET/lun0/part$3
+	echo $1 ide/host$HOST/bus$BUS/target$TARGET/lun0/part$3 discs/disc`get_dev_number $1 disk`/part$3
 fi
-