* Re: CD Symlinks Solution Idea
2006-05-14 18:58 CD Symlinks Solution Idea Jim Gifford
@ 2006-05-14 19:11 ` Jim Gifford
2006-05-15 0:52 ` Jim Gifford
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Jim Gifford @ 2006-05-14 19:11 UTC (permalink / raw)
To: linux-hotplug
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&kid\x120709&bid&3057&dat\x121642
_______________________________________________
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] 13+ messages in thread* Re: CD Symlinks Solution Idea
2006-05-14 18:58 CD Symlinks Solution Idea Jim Gifford
2006-05-14 19:11 ` Jim Gifford
@ 2006-05-15 0:52 ` Jim Gifford
2006-05-16 8:23 ` juuso.alasuutari
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Jim Gifford @ 2006-05-15 0:52 UTC (permalink / raw)
To: linux-hotplug
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
done
fi
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&kid\x120709&bid&3057&dat\x121642
_______________________________________________
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] 13+ messages in thread* Re: CD Symlinks Solution Idea
2006-05-14 18:58 CD Symlinks Solution Idea Jim Gifford
2006-05-14 19:11 ` Jim Gifford
2006-05-15 0:52 ` Jim Gifford
@ 2006-05-16 8:23 ` juuso.alasuutari
2006-05-16 15:30 ` Marco d'Itri
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: juuso.alasuutari @ 2006-05-16 8:23 UTC (permalink / raw)
To: linux-hotplug
Quoting Jim Gifford <maillist@jg555.com>:
> 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&kid\x120709&bid&3057&dat\x121642
_______________________________________________
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] 13+ messages in thread* Re: CD Symlinks Solution Idea
2006-05-14 18:58 CD Symlinks Solution Idea Jim Gifford
` (2 preceding siblings ...)
2006-05-16 8:23 ` juuso.alasuutari
@ 2006-05-16 15:30 ` Marco d'Itri
2006-05-19 16:03 ` Harald Hoyer
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Marco d'Itri @ 2006-05-16 15:30 UTC (permalink / raw)
To: linux-hotplug
On May 14, Jim Gifford <maillist@jg555.com> wrote:
> 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.
--
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&kid\x120709&bid&3057&dat\x121642
_______________________________________________
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] 13+ messages in thread* Re: CD Symlinks Solution Idea
2006-05-14 18:58 CD Symlinks Solution Idea Jim Gifford
` (3 preceding siblings ...)
2006-05-16 15:30 ` Marco d'Itri
@ 2006-05-19 16:03 ` Harald Hoyer
2006-05-21 1:00 ` juuso.alasuutari
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Harald Hoyer @ 2006-05-19 16:03 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 405 bytes --]
Jim Gifford wrote:
> if [ -e /dev/cdrom$link ]; then
> link=$[$link+1]
> else
> test=1
> echo $link
Does 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 :)
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/x-pkcs7-signature, Size: 3621 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: CD Symlinks Solution Idea
2006-05-14 18:58 CD Symlinks Solution Idea Jim Gifford
` (4 preceding siblings ...)
2006-05-19 16:03 ` Harald Hoyer
@ 2006-05-21 1:00 ` juuso.alasuutari
2006-05-21 4:01 ` Alexander E. Patrakov
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: juuso.alasuutari @ 2006-05-21 1:00 UTC (permalink / raw)
To: linux-hotplug
Quoting Harald Hoyer <harald@redhat.com>:
> Jim Gifford wrote:
> > if [ -e /dev/cdrom$link ]; then
> > link=$[$link+1]
> > else
> > test=1
> > echo $link
>
> Does 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&kid\x120709&bid&3057&dat\x121642
_______________________________________________
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] 13+ messages in thread* Re: CD Symlinks Solution Idea
2006-05-14 18:58 CD Symlinks Solution Idea Jim Gifford
` (5 preceding siblings ...)
2006-05-21 1:00 ` juuso.alasuutari
@ 2006-05-21 4:01 ` Alexander E. Patrakov
2006-05-22 16:20 ` Jim Gifford
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Alexander E. Patrakov @ 2006-05-21 4:01 UTC (permalink / raw)
To: linux-hotplug
juuso.alasuutari@tamperelainen.org 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?).
--
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&kid\x120709&bid&3057&dat\x121642
_______________________________________________
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] 13+ messages in thread* Re: CD Symlinks Solution Idea
2006-05-14 18:58 CD Symlinks Solution Idea Jim Gifford
` (6 preceding siblings ...)
2006-05-21 4:01 ` Alexander E. Patrakov
@ 2006-05-22 16:20 ` Jim Gifford
2006-05-22 17:21 ` Darren Salt
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Jim Gifford @ 2006-05-22 16:20 UTC (permalink / raw)
To: linux-hotplug
Alexander E. Patrakov wrote:
> juuso.alasuutari@tamperelainen.org 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?).
>
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&kid\x120709&bid&3057&dat\x121642
_______________________________________________
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] 13+ messages in thread* Re: CD Symlinks Solution Idea
2006-05-14 18:58 CD Symlinks Solution Idea Jim Gifford
` (7 preceding siblings ...)
2006-05-22 16:20 ` Jim Gifford
@ 2006-05-22 17:21 ` Darren Salt
2006-06-12 0:13 ` juuso.alasuutari
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Darren Salt @ 2006-05-22 17:21 UTC (permalink / raw)
To: linux-hotplug
I demand that Jim Gifford may or may not have written...
[snip]
> 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...
--
| 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&kid\x120709&bid&3057&dat\x121642
_______________________________________________
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] 13+ messages in thread* Re: CD Symlinks Solution Idea
2006-05-14 18:58 CD Symlinks Solution Idea Jim Gifford
` (8 preceding siblings ...)
2006-05-22 17:21 ` Darren Salt
@ 2006-06-12 0:13 ` juuso.alasuutari
2006-06-12 0:17 ` juuso.alasuutari
2006-06-12 7:18 ` Marco d'Itri
11 siblings, 0 replies; 13+ messages in thread
From: juuso.alasuutari @ 2006-06-12 0:13 UTC (permalink / raw)
To: linux-hotplug
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
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: CD Symlinks Solution Idea
2006-05-14 18:58 CD Symlinks Solution Idea Jim Gifford
` (9 preceding siblings ...)
2006-06-12 0:13 ` juuso.alasuutari
@ 2006-06-12 0:17 ` juuso.alasuutari
2006-06-12 7:18 ` Marco d'Itri
11 siblings, 0 replies; 13+ messages in thread
From: juuso.alasuutari @ 2006-06-12 0:17 UTC (permalink / raw)
To: linux-hotplug
Noticed an (almost) meaningless bug. This 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
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: CD Symlinks Solution Idea
2006-05-14 18:58 CD Symlinks Solution Idea Jim Gifford
` (10 preceding siblings ...)
2006-06-12 0:17 ` juuso.alasuutari
@ 2006-06-12 7:18 ` Marco d'Itri
11 siblings, 0 replies; 13+ messages in thread
From: Marco d'Itri @ 2006-06-12 7:18 UTC (permalink / raw)
To: linux-hotplug
On Jun 12, juuso.alasuutari@tamperelainen.org 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.
--
ciao,
Marco
_______________________________________________
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] 13+ messages in thread