CD Symlinks Solution Idea
I know a lot of people have been trying to figure out the cdrom sylinks issue. I think I've come up with a simple solution, if anyone see's any limitations or issues let me know.
Rules for symlinks
# check cdrom helper BUS="ide", KERNEL="hd[a-z]", ACTION="add", IMPORT="cdrom_id --export $tempnode" BUS="scsi", KERNEL="sr[0-9]*", ACTION="add", IMPORT="cdrom_id --export $tempnode" BUS="scsi", KERNEL="scd[a-z]", ACTION="add", IMPORT="cdrom_id --export $tempnode" BUS="scsi", KERNEL="sg[0-9]*", ACTION="add", DRIVER="sr", GROUP="cdrom"
BUS="ide", ENV{ID_CDROM}="?*", PROGRAM="cdsymlink_helper.sh
%k", SYMLINK+="cdrom%c", GROUP="cdrom"
BUS="ide", ENV{ID_CDROM_CD_R}="?*", PROGRAM="cdsymlink_helper.sh
%k", SYMLINK+="cdr%c"
BUS="ide", ENV{ID_CDROM_CD_RW}="?*", PROGRAM="cdsymlink_helper.sh %k", SYMLINK+="cdrw%c"
BUS="ide", ENV{ID_CDROM_DVD}="?*", PROGRAM="cdsymlink_helper.sh
%k", SYMLINK+="dvd%c"
BUS="ide", ENV{ID_CDROM_DVD_R}="?*", PROGRAM="cdsymlink_helper.sh %k", SYMLINK+="dvdrw%c"
BUS="scsi", ENV{ID_CDROM}="?*", SYMLINK+="cdrom%n", GROUP="cdrom"
BUS="scsi", ENV{ID_CDROM_CD_R}="?*", SYMLINK+="cdr%n" BUS="scsi", ENV{ID_CDROM_CD_RW}="?*", SYMLINK+="cdrw%n"
BUS="scsi", ENV{ID_CDROM_DVD}="?*", SYMLINK+="dvd%n"
BUS="scsi", ENV{ID_CDROM_DVD_R}="?*", SYMLINK+="dvdrw%n"
A small program in /lib/udev called cdsymlinks.sh this program is for IDE only a different solution
Begin of file----
#!/bin/sh
KERN_NAME="$1"
if [ "$KERN_NAME" = "" ]; then
mesg Bad invocation: \$1 is not set
exit 1
fi
FILES="ls /sys/bus/ide/drivers/ide-cdrom | grep 1."
for file in $FILES; do
TEST="`ls /sys/bus/ide/drivers/ide-cdrom/$file | grep -c
$KERN_NAME`"
if [ "$TEST" = "1" ]; then
link="`echo $file | cut -f2 -d.`"
echo $link
fi
doneEnd of file---
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
I had a typo in what I said in the last email.
A small program in /lib/udev called cdsymlinks.sh this program is for IDE only a different solution
Should be
A small program in /lib/udev called cdsymlinks.sh this program is for IDE only a different solution was used for SCSI.
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
After some feedback received from this list and my peers, a small issue now has been fixed. Thank you all for your ideas.
The solution will be persistent on the IDE side, but not sure on the SCSI side of the house.
Here is the complete solution.
Udev Rules
BUS="ide", KERNEL="hd[a-z]", ACTION="add", IMPORT="cdrom_id
--export $tempnode"
BUS="scsi", KERNEL="sr[0-9]*", ACTION="add", IMPORT="cdrom_id
--export $tempnode"
BUS="scsi", KERNEL="scd[a-z]", ACTION="add", IMPORT="cdrom_id
--export $tempnode"
BUS="scsi", KERNEL="sg[0-9]*", ACTION="add", DRIVER="sr",
GROUP="cdrom"
BUS="ide", ENV{ID_CDROM}="?*", PROGRAM="cdsymlink_helper.sh %k
ide", SYMLINK+="cdrom%c"
BUS="ide", ENV{ID_CDROM_CD_R}="?*", PROGRAM="cdsymlink_helper.sh %k
ide", SYMLINK+="cdr%c"
BUS="ide", ENV{ID_CDROM_CD_RW}="?*", PROGRAM="cdsymlink_helper.sh %k ide", SYMLINK+="cdrw%c"
BUS="ide", ENV{ID_CDROM_DVD}="?*", PROGRAM="cdsymlink_helper.sh %k
ide", SYMLINK+="dvd%c"
BUS="ide", ENV{ID_CDROM_DVD_R}="?*", PROGRAM="cdsymlink_helper.sh %k ide", SYMLINK+="dvdrw%c"
BUS="scsi", ENV{ID_CDROM}="?*", PROGRAM="cdsymlink_helper.sh %n
scsi", SYMLINK+="cdrom%c"
BUS="scsi", ENV{ID_CDROM_CD_R}="?*", PROGRAM="cdsymlink_helper.sh %n scsi", SYMLINK+="cdr%c"
BUS="scsi", ENV{ID_CDROM_CD_RW}="?*", PROGRAM="cdsymlink_helper.sh %n scsi", SYMLINK+="cdrw%c"
BUS="scsi", ENV{ID_CDROM_DVD}="?*", PROGRAM="cdsymlink_helper.sh %n
scsi", SYMLINK+="dvd%c"
BUS="scsi", ENV{ID_CDROM_DVD_R}="?*", PROGRAM="cdsymlink_helper.sh %n scsi", SYMLINK+="dvdrw%c"
cdsymlink_helper.sh
#!/bin/sh
KERN_NAME="$1"
BUS="$2"
test=0
if [ "$KERN_NAME" = "" ]; then
mesg Bad invocation: \$1 is not set
exit 1
fi
if [ "$BUS" = "ide" ]; then
FILES="ls /sys/bus/ide/drivers/ide-cdrom | grep '\.' "
for file in $FILES; do
TEST="`ls /sys/bus/ide/drivers/ide-cdrom/$file |
grep -c $KERN_NAME`"
if [ "$TEST" = "1" ]; then
link="`echo $file | cut -f2 -d.`"
while [ $test -lt 1 ] ; do
if [ -e /dev/cdrom$link ]; then
link=$[$link+1]
else
test=1
echo $link
fi
done
fi
donefi
if [ "$BUS" = "SCSI" ]; then
link=$KERN_NAME
while [ $test -lt 1 ] ; do
if [ -e /dev/cdrom$link ]; then
link=$[$link+1]
else
test=1
echo $link
fi
done
fi
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoting Jim Gifford <[email protected]>:
Quoted 7 lines
After some feedback received from this list and my peers, a small issue now has been fixed. Thank you all for your ideas.
The solution will be persistent on the IDE side, but not sure on the SCSI side of the house.
Here is the complete solution.
Thanks for your script, I've "bashified" it and am testing it now. I already found a bug in it: the scsi part of the script has 'if [ "$BUS" = "SCSI" ]' while the rule is 'PROGRAM="cdsymlink_helper.sh %n scsi"'.
And why do you use 'mesg', btw, is that a typo?
There's also a bigger problem with the script.
I have only one cdrom device, and on boot the rules+script create /dev/cdrom0. If I then run udevstart after boot, the link will be renamed to /dev/cdrom1. The reason is simple: The script sees /dev/cdrom0 (which hasn't yet been removed at the time it is called), and returns "1". Udevstart then removes /dev/cdrom0, leaving only /dev/cdrom1. If I then run udevstart again, the link will again be /dev/cdrom0. So if I run udevstart several times, the link name alternates between /dev/cdrom0 and /dev/cdrom1.
Juuso Alasuutari
----------------------------------------------------------------
This mail sent through L-secure: http://www.l-secure.net/
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 3 lines · Jim Gifford
I know a lot of people have been trying to figure out the cdrom sylinks issue. I think I've come up with a simple solution, if anyone see's any limitations or issues let me know.
Look at the debian package, it contains scripts to generate persistent symlinks for CD readers and network interfaces.
Signature · 13 lines
ciao, Marco ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642 _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 5 lines · Jim Gifford
if [ -e /dev/cdrom$link ]; then
link=$[$link+1]
else
test=1
echo $linkDoes not really work, because everything can be run in parallel, what you need is some semaphore like "test and create device" operation, which has to be atomic :)
Quoting Harald Hoyer <[email protected]>:
Quoted 11 lines
Quoted 5 lines · Jim Gifford
if [ -e /dev/cdrom$link ]; then link=$[$link+1] else test=1 echo $linkDoes not really work, because everything can be run in parallel, what you need is some semaphore like "test
and create device" operation, which has to be atomic :)
Can you be more specific? I'm also working on a symlink naming helper (based on Jim Gifford's script), but i'm afraif I can't understand the terms you use.
Juuso
----------------------------------------------------------------
This mail sent through L-secure: http://www.l-secure.net/
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 2 lines · [email protected] wrote:
I'm also working on a symlink naming helper (based on Jim Gifford's script),
Please don't. It is a 1:1 reimplementation of the old "%e" idea that was dropped for a good reason: it doesn't work consistently.
I.e., sometimes you will get /dev/cdrom -> sr0 and /dev/cdrom1 -> sr1, and sometimes the other way round. That happens because udev processes uevents in parallel, and thus in random order (and this can't be changed). In order for the symlinks to be persistent, some on-disk database must be present, and that's what Marco's script does (but it doesn't work with more than two CD-ROMs due to an easily-fixable bug - or is that already fixed?).
Signature · 12 lines
Alexander E. Patrakov ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642 _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 8 lines · Alexander E. Patrakov
Quoted 2 lines · [email protected] wrote:
I'm also working on a symlink naming helper (based on Jim Gifford's script),
Please don't. It is a 1:1 reimplementation of the old "%e" idea that was dropped for a good reason: it doesn't work consistently.
Quoted 8 lines
I.e., sometimes you will get
/dev/cdrom-> sr0 and/dev/cdrom1-> sr1, and sometimes the other way round. That happens because udev processes uevents in parallel, and thus in random order (and this can't be changed). In order for the symlinks to be persistent, some on-disk database must be present, and that's what Marco's script does (but it doesn't work with more than two CD-ROMs due to an easily-fixable bug - or is that already fixed?).
The point is that not everyone is worried about consistency, if they need a specific drive associated, then they need to use the SYSFS rules and create persistent naming. But for people who only have one cdrom. This is a simple solution.
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
I demand that Jim Gifford may or may not have written...
[snip]
Quoted 4 lines
The point is that not everyone is worried about consistency, if they need a specific drive associated, then they need to use the SYSFS rules and create persistent naming. But for people who only have one cdrom. This is a simple solution.
Have a look in older versions of udev (try around 058) - you'll find my cdsymlinks script there. It'll work so long as /proc/sys/dev/cdrom/info remains present *but* it's subject to device registration races, although I seem to be consistently getting hdd registered before hdc these days...
Signature · 16 lines
| Darren Salt | linux or ds at | nr. Ashington, | Toon | RISC OS, Linux | youmustbejoking,demon,co,uk | Northumberland | Army | + Buy less and make it last longer. INDUSTRY CAUSES GLOBAL WARMING. I need all of your money. ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642 _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Continuing on the subject of cdrom symlinks creation.
I looked at the debian script and copied its use of a lock directory to enforce a queue for parallel processes. Otherwise my script just normally looks in /dev to see whether e.g. a symlink named cdrom already exists, and if so, checks if cdrom1 exists, etc. until the first available name comes up.
I didn't find a way to make the link names persistent, so that e.g. cdrom would always point at the same device. But on the other hand, I've never heard of cdrom devices being loaded in random order during boot. Is it nevertheless possible that this might happen, like it does with network devices? I can't test it, because I only have one cdrom drive.
I'm posting this so that all those interested can evaluate and point out possible bugs in the script. Thank you for your help and your time. :)
Juuso
== Begin script ==
#!/bin/bash
if [[ -z "$1" ]]; then
echo "Not enough input!"
echo "Usage: $@ %k"
exit 1
fi
# Prevent conflicts between parallel processes by creating a lock dir
# and using it as a queue ticket. Only the process that can create it
# (meaning it doesn't already exist from another process) is allowed to
# proceed, others have to wait. Maximum queue time is 5 seconds, queue
# check happens every 20 milliseconds.
lock()
{
[[ -d /dev/.udev ]] ||
if ! mkdir -p /dev/.udev; then
echo "Cannot create /dev/.udev!"
exit 1
fi
LOCK_DIR=/dev/.udev/.lock-cdsymlink
local retry%0
while ! mkdir $LOCK_DIR 2>/dev/null; do
if ((retry=0)); then
echo "Cannot lock $LOCK_DIR!" >&2
exit 2
fi
sleep 0.02
((retry-=1))
done
}# Once the process is finished, delete lock dir so that the next process
# may step forward in queue.
unlock()
{
[[ "$LOCK_DIR" ]] || return 0
rm -r $LOCK_DIR 2>/dev/null || return 0
}# Find the next available symlink name for device. $1 is the device name
# from kernel (udev's %k value), $2 is the desired symlink basename
# (e.g. basename "cdrom" will be used to create symlinks /dev/cdrom,
# /dev/cdrom1, etc.)
echo_link()
{
local num
while [[ -e /dev/$2$num ]] &&
[[ "$(readlink /dev/$2$num)" != "$1" ]]; do
((num+=1))
done
echo -n "$2$num "
}lock
# Output symlink name for cdrom, and then for dvd if needed. echo_link $1 cdrom
[[ "$ID_CDROM_DVD" ]] && echo_link $1 dvd
unlock
----------------------------------------------------------------
This mail sent through L-secure: http://www.l-secure.net/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Noticed an (almost) meaningless bug. This line:
Quoted 1 line
echo "Usage: $@ %k"
..should of course be:
echo "Usage: $0 %k"
Juuso
----------------------------------------------------------------
This mail sent through L-secure: http://www.l-secure.net/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 3 lines · On Jun 12, [email protected] wrote:
always point at the same device. But on the other hand, I've never heard of cdrom devices being loaded in random order during boot. Is it nevertheless possible that this might happen, like it does with network devices? I can't
Every time.
Signature · 8 lines
ciao, Marco _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel