* hotplug and "rw" on kernel command line
@ 2004-05-30 14:01 Alexander E. Patrakov
2004-05-31 19:28 ` Kevin P. Fleming
2004-06-01 8:59 ` Alex Galakhov
0 siblings, 2 replies; 3+ messages in thread
From: Alexander E. Patrakov @ 2004-05-30 14:01 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 1891 bytes --]
This is a trouble report forwarded from a Linux From Scratch CVS HEAD user.
=====================================================
[Bug 842] New: udev bootscript can fail to run udevstart if hotplug
is installed.
In the LFS-specific udev bootscript, a check is made to see if
/dev/.udev.tdb exists, and if it does the remainder of the script is not
run. This was added to handle the situation where an initrd or initramfs
had already run udevstart and created the "extra" nodes, so the script
would not generate errors.
However, now that hotplug is in the unstable book, there is a problem:
if the root filesystem is mounted read-write when the kernel mounts it
(the first mount) AND a hotplug event occurs before this script runs
(small window), then udev will get run by the hotplug scripts and this
file will get created. The result is that when the script runs it does
not do what is needed.
=====================================================
I understand that this is mostly LFS-specific, and the report can be in
fact treated as invalid since we don't officially support the "rw" flag
on the kernel command line, but I have a question.
Is this normal that a hotplug event somehow managed to fire up in that
small time window? The udev initscript is the second one that actually
runs in LFS, and it just mounts ramfs on /dev, calls udevstart and
creates extra nodes in /dev like /dev/fd symlink. The first initscript
is called mountkernfs and it just mounts /proc, /sys and probably
/proc/bus/usb. Both bootscripts are attached. You see that none of them
does things that can lead to a hotplug event, so the source of that
bogus event is a mystery for me.
Another question is: how are other distros supposed to deal with such
unexpected hotplug events, when the root filesystem is mounted read-only
and /usr is not mounted at all?
--
Alexander E. Patrakov
[-- Attachment #2: functions --]
[-- Type: text/plain, Size: 6589 bytes --]
#!/bin/sh
# Begin $rc_base/init.d/functions - Run Level Control Functions
# Based on functions script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
# With code based on Matthias Benkmann's simpleinit-msb @
# http://winterdrache.de/linux/newboot/index.html
# Number of seconds between term signal and kill signal when stopping processes
KILLDELAY=3
umask 022
export PATH="/bin:/usr/bin:/sbin:/usr/sbin"
# Width of the Screen
COLUMNS=$(stty size)
COLUMNS=${COLUMNS##* }
# When using remote connections, such as a serial port, stty size returns 0
if [ "$COLUMNS" = "0" ]; then COLUMNS=80; fi
# Measurements for positioning result messages
COL=$(($COLUMNS - 10))
WCOL=$(($COLUMNS - 30))
# Set Cursur Position Commands, used via echo -e
SET_COL="\\033[${COL}G"
SET_WCOL="\\033[${WCOL}G"
CURS_UP="\\033[A"
# Set color commands, used via echo -e
NORMAL="\\033[0;39m"
SUCCESS="\\033[1;32m"
WARNING="\\033[1;33m"
FAILURE="\\033[1;31m"
echo_ok()
{
echo -e "$CURS_UP$SET_COL"["$SUCCESS"" OK ""$NORMAL"]
}
echo_failure()
{
echo -e "$CURS_UP$SET_COL"["$FAILURE"FAILED"$NORMAL"]
}
echo_warning()
{
echo -e "$CURS_UP$SET_WCOL$@$SET_COL"["$WARNING" WARN "$NORMAL"]
}
# $i is inherited by the rc script
print_error_msg()
{
echo -e -n $FAILURE
echo
echo "You should not be reading this error message. It means"
echo "that an unforseen error took place in $i,"
echo "which exited with a return value of $error_value"
echo
echo "If you're able to track this error down to a bug in one"
echo "of the files provided by the LFS book, please be so kind"
echo "to inform us at lfs-dev@linuxfromscratch.org"
echo -e -n $NORMAL
echo
echo
echo "Press Enter to continue..."
read ENTER
}
# $i is inherited by the rc script
check_script_status()
{
if [ ! -f $i ]
then
echo "$i is not a valid symlink"
continue
fi
if [ ! -x $i ]
then
echo "$i is not executable, skipping"
continue
fi
}
evaluate_retval()
{
error_value=$?
if [ $error_value = 0 ]
then
print_status success
else
print_status failure
sleep 5
fi
return 0
#return $error_value
}
print_status()
{
if [ $# = 0 ]
then
echo "Usage: $0 {success|warning|failure}"
return 1
fi
case "$1" in
success)
echo_ok
;;
warning)
case "$2" in
running)
echo_warning "Already running"
;;
not_running)
echo_warning "Not running"
;;
esac
;;
failure)
echo_failure
;;
esac
}
# Returns all of the pid #'s for $1 process
getpids()
{
base=${1##*/}
local lpids=""
local pid
pidlist=""
lpids=$(pidof $base)
for pid in $lpids
do
if [ $pid -ne $$ ] && [ $pid -ne $PPID ]
then
pidlist="$pidlist $pid"
fi
done
}
# Starts a program if it is currently not running
loadproc()
{
if [ $# = 0 ]
then
echo "Usage: loadproc {program}"
exit 1
fi
if [ -n "$PIDFILE" -a -r "$PIDFILE" ]; then
pidlist=`cat $PIDFILE`
else
getpids $1
fi
if [ -z "$pidlist" ]
then
"$@"
evaluate_retval
else
print_status warning running
fi
}
# Stops a process if it is running
killproc()
{
if [ $# = 0 ]
then
echo "Usage: killproc {program} [signal]"
exit 1
fi
if [ -z "$2" ]; then
signal=TERM
fallback=KILL
else
signal=${2##-}
signal=${signal##SIG}
fallback=""
fi
if [ -n "$PIDFILE" -a -r "$PIDFILE" ]; then
pidlist=`cat $PIDFILE`
else
getpids $1
fi
if [ -n "$pidlist" ]; then
local i=0
for pid in $pidlist
do
kill -$signal $pid 2>/dev/null
while [ $i -lt $KILLDELAY ]; do
kill -0 $pid 2>/dev/null || break
sleep 1
i=$(($i+1))
done
if [ -n "$fallback" ]; then
kill -$fallback $pid 2>/dev/null
fi
done
getpids $1
base=${1##*/}
if [ -n "$pidlist" ]; then
failure=1
else
failure=0
if [ ! -z $PIDFILE ]; then
rm -f $PIDFILE
else
rm -f /var/run/$base.pid
fi
fi
(exit $failure)
evaluate_retval
else
print_status warning not_running
fi
}
reloadproc()
{
if [ $# = 0 ]
then
echo "Usage: reloadproc {program} [signal]"
exit 1
fi
if [ -z "$2" ]; then
signal=HUP
else
signal=${2##-}
signal=${signal##SIG}
fi
getpids $1
if [ -n "$pidlist" ]
then
failure=0
for pid in $pidlist
do
kill -$signal $pid || failure=1
done
(exit $failure)
evaluate_retval
else
print_status warning not_running
fi
}
statusproc()
{
if [ $# = 0 ]
then
echo "Usage: statusproc {program}"
exit 1
fi
base=${1##*/}
getpids $base
if [ -n "$pidlist" ]
then
echo "$base is running with Process ID(s) $pidlist"
else
if [ -s /var/run/$base.pid ]
then
echo "$1 is not running but /var/run/$base.pid exists"
return 1
else
echo "$1 is not running"
fi
fi
}
# End $rc_base/init.d/functions
[-- Attachment #3: mountkernfs --]
[-- Type: text/plain, Size: 746 bytes --]
#!/bin/sh
# Begin $rc_base/init.d/mountkernfs
# Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
. /etc/sysconfig/rc
. $rc_functions
case "$1" in
start)
if [ ! -e /proc/mounts ]; then
echo "Mounting proc file system..."
mount -n /proc
evaluate_retval
fi
# This should be mounted on a 2.6 kernel.
if grep -q '[[:space:]]sysfs' /proc/filesystems; then
if [ -d /sys -a ! -d /sys/block ]; then
echo "Mounting sysfs file system..."
mount -n /sys
evaluate_retval
fi
fi
if grep -q '[[:space:]]usbfs' /proc/filesystems; then
echo "Mounting USB filesystem"
mount -n /proc/bus/usb
evaluate_retval
fi
;;
*)
echo "Usage $0 {start}"
exit 1
;;
esac
# End $rc_base/init.d/mountkernfs
[-- Attachment #4: udev --]
[-- Type: text/plain, Size: 1767 bytes --]
#!/bin/sh
# Begin $rc_base/init.d/udev - Udev cold-plugging script
# Written by Zack Winkles - winkie@linuxfromscratch.org
. /etc/sysconfig/rc
. $rc_functions
# Assure that sysfs is mounted and that udev is present.
[ -d /sys/block -a -x /sbin/udev ] || exit 0
# Create some things that sysfs does not, and should not export for us. Feel
# free to add devices to this list.
make_extra_nodes() {
ln -s /proc/self/fd /dev/fd
ln -s /proc/self/fd/0 /dev/stdin
ln -s /proc/self/fd/1 /dev/stdout
ln -s /proc/self/fd/2 /dev/stderr
ln -s /proc/kcore /dev/core
mkdir /dev/pts
mkdir /dev/shm
}
case "$1" in
start)
# When the hotplug package isn't installed, make sure that udev
# still gets hotplug events.
if [ ! -x /sbin/hotplug ]; then
echo /sbin/udev > /proc/sys/kernel/hotplug
fi
# Don't attempt to populate the /dev directory when something
# else has already set it up.
[ -f /dev/.udev.tdb ] && exit 0
echo "Populating /dev with device nodes..."
# Mount a temporary file system over /dev, so that any devices
# made or removed during this boot don't affect the next one.
# The reason we don't write to mtab is because we don't ever
# want /dev to be unavailable (such as by `umount -a').
mount -n -t ramfs ramfs /dev
# Populate /dev with all the devices that are already available,
# and save it's status so we can report failures.
udevstart || failed=1
# Now, create some required files/directories/devices that sysfs
# doesn't export for us.
make_extra_nodes
# When reporting the status, base it on the success or failure
# of the `udevstart' command, since that's the most important.
(exit $failed)
evaluate_retval
;;
*)
echo "Usage $0 {start}"
exit 1
;;
esac
# End $rc_base/init.d/udev
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: hotplug and "rw" on kernel command line
2004-05-30 14:01 hotplug and "rw" on kernel command line Alexander E. Patrakov
@ 2004-05-31 19:28 ` Kevin P. Fleming
2004-06-01 8:59 ` Alex Galakhov
1 sibling, 0 replies; 3+ messages in thread
From: Kevin P. Fleming @ 2004-05-31 19:28 UTC (permalink / raw)
To: linux-hotplug
Alexander E. Patrakov wrote:
> /proc/bus/usb. Both bootscripts are attached. You see that none of them
> does things that can lead to a hotplug event, so the source of that
> bogus event is a mystery for me.
Speaking as the original bug reporter, I'll jump in here: I am not
suggesting that the unexpected hotplug event is bogus at all. Hotplug
events are not only caused by the actions taken by the bootscripts, they
can be caused by almost anything at all.
Consider the possibility that the user has a USB storage device that
takes some time to respond to USB enumeration... the kernel could easily
have finished its own initialization mounted the root filesystem
read-write before this device is finally found and accepted by the USB
storage driver. At the instant the driver binds to the device, one or
more hotplug events will be generated. If the system's boot scripts have
not yet had a chance to finish their work, the hotplug event will occur
at an inopportune time and things can get weird.
The only solution I can see for this (well, proper solution that works
in all cases I can think of) is to _not_ have the kernel default to
calling /sbin/hotplug, but rather have the system bootscripts have to
forcibly set /proc/sys/kernel/hotplug to that value. Alternatively, the
/sbin/hotplug script from the hotplug package could be renamed after
installation and then appropriate script could set
/proc/sys/kernel/hotplug to /sbin/hotplug.real.
Either of these changes will get around this problem, because the boot
scripts can handle the appropriate cold-plugging when ready, and they
can very closely control when userspace will actually start to receive
hotplug events.
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id149&alloc_idÅ66&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] 3+ messages in thread
* Re: hotplug and "rw" on kernel command line
2004-05-30 14:01 hotplug and "rw" on kernel command line Alexander E. Patrakov
2004-05-31 19:28 ` Kevin P. Fleming
@ 2004-06-01 8:59 ` Alex Galakhov
1 sibling, 0 replies; 3+ messages in thread
From: Alex Galakhov @ 2004-06-01 8:59 UTC (permalink / raw)
To: linux-hotplug
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> The only solution I can see for this (well, proper solution that works
> in all cases I can think of) is to _not_ have the kernel default to
> calling /sbin/hotplug, but rather have the system bootscripts have to
> forcibly set /proc/sys/kernel/hotplug to that value.
I absolutely agree. The initscripts should have a way to tell the kernel that
the system is ready to handle hotplug events. We DO have such a way already,
that's the /proc filesystem, exactlier, /proc/sys/kernel/hotplug. It were
nice to have it disabled by default. No problem to add "echo /sbin/hotplug"
somewhere in the initscripts.
If you are afraid of backward compatibility, one could add one more
configuration option to the kernel, like that:
[x] /proc/sys/kernel/hotplug defaults to /sbin/hotplug [DEPRECATED]
I suggest to make it deprecated in order to avoid any possible misreadings.
IMHO, the user always has the right to misconfigure his system :)
> Alternatively, the
> /sbin/hotplug script from the hotplug package could be renamed after
> installation and then appropriate script could set
> /proc/sys/kernel/hotplug to /sbin/hotplug.real.
Hmmm... not a very nice kludge... in fact, this heavily raises the chances for
nonintentional misconfiguration. However, this kludge may work for now for
the users who do not want to wait for next kernel release.
IMHO, for this hack, /sbin/hotplug should be a script that calls
real /sbin/hotplug.real if the system is ready in a distribution-specific
manner (i.e., reads /proc/sys/kernel/hotplug and checks if it is set
to /sbin/hotplug.real). It is necessary because some scripts may rely on the
existance of /sbin/hotplug. Again, don't do that if you can patch the kernel
instead.
Regards,
Alex
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAvEWOaA+H7vY+1kURAoXdAJ4yCOn63hf8Hcx/rPYkONhYmfrYwQCeNhC5
hfwvZ3rkbflFhQnu0KM+Qtc=M+mD
-----END PGP SIGNATURE-----
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id149&alloc_idÅ66&opÃk
_______________________________________________
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] 3+ messages in thread
end of thread, other threads:[~2004-06-01 8:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-30 14:01 hotplug and "rw" on kernel command line Alexander E. Patrakov
2004-05-31 19:28 ` Kevin P. Fleming
2004-06-01 8:59 ` Alex Galakhov
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).