linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* cold-plugged usb flash drive not handled correctly in embedded
@ 2010-08-20 14:42 Wolfgang Wegner
  2010-08-20 14:51 ` cold-plugged usb flash drive not handled correctly in embedded system Kay Sievers
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Wolfgang Wegner @ 2010-08-20 14:42 UTC (permalink / raw)
  To: linux-hotplug

Hi list,

I am having a problem with udev on an embedded system and
am asking for advice on how to track this down. The system is
an ARM (kirkwood) platform with a busybox-based init. I cross-
compiled udev-161, made a simple udev start script (basically
ripped off from debian and stripped from most of the config
stuff) and a very basic rules file in
/etc/udev/rules.d/50-udev.rules:
ACTION="add", KERNEL="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,flush,quiet,nodev,nosuid,exec,noatime,dmask\00,fmask\x111 /dev/%k /mnt/usbdisk", OPTIONS="last_rule"
ACTION="remove", KERNEL="sd[a-z][0-9]", RUN+="/bin/umount -l /mnt/usbdisk"

It does not matter if I leave the standard rules in
/libexec/rules.d/ or if I remove them altogether, in either
case the USB flash drive is correctly mounted when plugged
into the running system but not when it is already present when
the system boots up.

I enabled debugging in udev, but have to admit I am a bit
overwhelmed by all the logging then. Here some parts which
seem to show that I did not make an obvious mistake:

udev reads correct rules file:
7.953380 [578] parse_file: reading '/etc/udev/rules.d/50-udev.rules' as rules file

Triggered by udevadm trigger, the device is correctly enumerated:
18.530148 [586] udev_device_new_from_syspath: device 0x40770 has devpath '/devices/platform/orion-ehci.0/usb1/1-1/1-1:1.0/host2/target2:0:0/2:0:0:0/block/sda/sda1'
18.530268 [586] udev_rules_apply_to_event: LINK 'block/8:1' //libexec/rules.d/50-udev-default.rules:3
18.530343 [586] udev_rules_apply_to_event: GROUP 0 //libexec/rules.d/50-udev-default.rules:72
18.530490 [586] udev_device_new_from_syspath: device 0x3eb40 has devpath '/devices/platform/orion-ehci.0/usb1/1-1/1-1:1.0/host2/target2:0:0/2:0:0:0/block/sda'
18.530894 [586] udev_device_read_db: device 0x3eb40 filled with db file data

But the mount is not executed.


When checking what would have to be done for this device manually,
the actions are correctly shown:

udevadm_test: DEVPATH=/devices/platform/orion-ehci.0/usb1/1-1/1-1:1.0/host2/target2:0:0/2:0:0:0/block/sda/sda1
[...]
udevadm_test: /dev/sda1: UUID\b56-17AE
udevadm_test: run: '/bin/mount -t auto -o rw,noauto,flush,quiet,nodev,nosuid,exec,noatime,dmask\00,fmask\x111 /dev/sda1 /mnt/usbdisk'


And removing the device also triggers the unmount:

405.042924 [623] udev_device_read_db: device 0x2b068 filled with db file data
405.043050 [623] udev_rules_apply_to_event: RUN '/bin/umount -l /mnt/usbdisk' /etc/udev/rules.d/50-udev.rules:8

while re-inserting finally also runs the mount:

417.490164 [623] udev_device_new_from_syspath: device 0x30148 has devpath '/devices/platform/orion-ehci.0/usb1/1-1/1-1:1.0/host3/target3:0:0/3:0:0:0/block/sda/sda1'
417.490282 [623] udev_rules_apply_to_event: LINK 'block/8:1' //libexec/rules.d/50-udev-default.rules:3
417.490358 [623] udev_rules_apply_to_event: GROUP 0 //libexec/rules.d/50-udev-default.rules:72
417.490408 [623] udev_rules_apply_to_event: RUN '/bin/mount -t auto -o rw,noauto,flush,quiet,nodev,nosuid,exec,noatime,dmask\00,fmask\x111 /dev/%k /mnt/usbdisk' /etc/udev/rules.d/50-udev.rules:6
417.490554 [623] udev_device_new_from_syspath: device 0x304a0 has devpath '/devices/platform/orion-ehci.0/usb1/1-1/1-1:1.0/host3/target3:0:0/3:0:0:0/block/sda'
417.490987 [623] udev_device_read_db: device 0x304a0 filled with db file data

Can anybody point me to where I have to look for the problem?
Which additional information is needed - if any - to give a
hint?

Thank you and best regards,
Wolfgang


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: cold-plugged usb flash drive not handled correctly in embedded system
  2010-08-20 14:42 cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
@ 2010-08-20 14:51 ` Kay Sievers
  2010-08-20 15:00 ` cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Kay Sievers @ 2010-08-20 14:51 UTC (permalink / raw)
  To: linux-hotplug

On Fri, Aug 20, 2010 at 16:42, Wolfgang Wegner <ww-ml@gmx.de> wrote:
> /etc/udev/rules.d/50-udev.rules:
> ACTION="add", KERNEL="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,flush,quiet,nodev,nosuid,exec,noatime,dmask\00,fmask\x111 /dev/%k /mnt/usbdisk", OPTIONS="last_rule"

udev 161 has no "last_rule" thing anymore.

You mount all devices, the possibly built-in ,and the plugged-in
devices at the same place? :)

> It does not matter if I leave the standard rules in
> /libexec/rules.d/ or if I remove them altogether, in either
> case the USB flash drive is correctly mounted when plugged
> into the running system but not when it is already present when
> the system boots up.

The event for the device happens during early boot where you have no
chance to mount. Do you run 'udevadm trigger' at bootup? It will
re-generate all events so that they can be handled when userspace is
running. It would need --action­d for your current rule to match.

Kay

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: cold-plugged usb flash drive not handled correctly in embedded
  2010-08-20 14:42 cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
  2010-08-20 14:51 ` cold-plugged usb flash drive not handled correctly in embedded system Kay Sievers
@ 2010-08-20 15:00 ` Wolfgang Wegner
  2010-08-20 15:19 ` Wolfgang Wegner
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Wolfgang Wegner @ 2010-08-20 15:00 UTC (permalink / raw)
  To: linux-hotplug

Hi,

On Fri, Aug 20, 2010 at 04:51:44PM +0200, Kay Sievers wrote:
> On Fri, Aug 20, 2010 at 16:42, Wolfgang Wegner <ww-ml@gmx.de> wrote:
> > /etc/udev/rules.d/50-udev.rules:
> > ACTION="add", KERNEL="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,flush,quiet,nodev,nosuid,exec,noatime,dmask\00,fmask\x111 /dev/%k /mnt/usbdisk", OPTIONS="last_rule"
> 
> udev 161 has no "last_rule" thing anymore.

ok, but I guess this does not change anything, especially in the
case when I use this as the only rule. ;-)

> You mount all devices, the possibly built-in ,and the plugged-in
> devices at the same place? :)

Yes, currently I do, because only one USB device is "supported".

> > It does not matter if I leave the standard rules in
> > /libexec/rules.d/ or if I remove them altogether, in either
> > case the USB flash drive is correctly mounted when plugged
> > into the running system but not when it is already present when
> > the system boots up.
> 
> The event for the device happens during early boot where you have no
> chance to mount. Do you run 'udevadm trigger' at bootup? It will
> re-generate all events so that they can be handled when userspace is
> running. It would need --action­d for your current rule to match.

The busybox start script (/etc/init.d/rcS) runs my udev start script
(/etc/init.d/start_udev.sh) which in turn runs udevadm trigger as
one of the last steps:

[...]
udevd --daemon --debug

mkdir -p /dev/.udev/queue/ /dev/.udev/rules.d/
create_dev_root_rule /dev/.udev/

udevadm trigger

create_dev_makedev

udevadm settle

exit 0

Again, I have to admit I do not really understand what
create_dev_makedev is for (copied from debian), but I am quite
sure it can do no harm...

From my understanding, this should generate all the events -
and I see the event is there, because of this:
18.530148 [586] udev_device_new_from_syspath: device 0x40770 has devpath '/devices/platform/orion-ehci.0/usb1/1-1/1-1:1.0/host2/target2:0:0/2:0:0:0/block/sda/sda1'
18.530268 [586] udev_rules_apply_to_event: LINK 'block/8:1' //libexec/rules.d/50-udev-default.rules:3
18.530343 [586] udev_rules_apply_to_event: GROUP 0 //libexec/rules.d/50-udev-default.rules:72
18.530490 [586] udev_device_new_from_syspath: device 0x3eb40 has devpath '/devices/platform/orion-ehci.0/usb1/1-1/1-1:1.0/host2/target2:0:0/2:0:0:0/block/sda'
18.530894 [586] udev_device_read_db: device 0x3eb40 filled with db file data

All I am missing is the "RUN" line here.

BTW, amazing response time! :-)

Regards,
Wolfgang


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: cold-plugged usb flash drive not handled correctly in embedded
  2010-08-20 14:42 cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
  2010-08-20 14:51 ` cold-plugged usb flash drive not handled correctly in embedded system Kay Sievers
  2010-08-20 15:00 ` cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
@ 2010-08-20 15:19 ` Wolfgang Wegner
  2010-08-20 15:29 ` Greg KH
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Wolfgang Wegner @ 2010-08-20 15:19 UTC (permalink / raw)
  To: linux-hotplug

On Fri, Aug 20, 2010 at 04:51:44PM +0200, Kay Sievers wrote:
> On Fri, Aug 20, 2010 at 16:42, Wolfgang Wegner <ww-ml@gmx.de> wrote:
> > /etc/udev/rules.d/50-udev.rules:
> > ACTION="add", KERNEL="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,flush,quiet,nodev,nosuid,exec,noatime,dmask\00,fmask\x111 /dev/%k /mnt/usbdisk", OPTIONS="last_rule"
> 
> udev 161 has no "last_rule" thing anymore.
> 
> You mount all devices, the possibly built-in ,and the plugged-in
> devices at the same place? :)

sorry, I should have made this clear: there is no built-in sd*
device, all internal filesystems reside in UBIFS.
(But I agree that I should make a real mount script for the
release version, just in case somebody comes up with an USB
hub or a multi card reader. ;-) )

Regards,
Wolfgang


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: cold-plugged usb flash drive not handled correctly in embedded
  2010-08-20 14:42 cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
                   ` (2 preceding siblings ...)
  2010-08-20 15:19 ` Wolfgang Wegner
@ 2010-08-20 15:29 ` Greg KH
  2010-08-20 15:31 ` cold-plugged usb flash drive not handled correctly in embedded system Kay Sievers
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Greg KH @ 2010-08-20 15:29 UTC (permalink / raw)
  To: linux-hotplug

On Fri, Aug 20, 2010 at 04:42:36PM +0200, Wolfgang Wegner wrote:
> Hi list,
> 
> I am having a problem with udev on an embedded system and
> am asking for advice on how to track this down. The system is
> an ARM (kirkwood) platform with a busybox-based init. I cross-
> compiled udev-161, made a simple udev start script (basically
> ripped off from debian and stripped from most of the config
> stuff) and a very basic rules file in
> /etc/udev/rules.d/50-udev.rules:
> ACTION="add", KERNEL="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,flush,quiet,nodev,nosuid,exec,noatime,dmask\00,fmask\x111 /dev/%k /mnt/usbdisk", OPTIONS="last_rule"
> ACTION="remove", KERNEL="sd[a-z][0-9]", RUN+="/bin/umount -l /mnt/usbdisk"
> 
> It does not matter if I leave the standard rules in
> /libexec/rules.d/ or if I remove them altogether, in either
> case the USB flash drive is correctly mounted when plugged
> into the running system but not when it is already present when
> the system boots up.

Perhaps because you do not have a 'mount' executable when the device is
found during the boot process?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: cold-plugged usb flash drive not handled correctly in embedded system
  2010-08-20 14:42 cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
                   ` (3 preceding siblings ...)
  2010-08-20 15:29 ` Greg KH
@ 2010-08-20 15:31 ` Kay Sievers
  2010-08-20 16:02 ` cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Kay Sievers @ 2010-08-20 15:31 UTC (permalink / raw)
  To: linux-hotplug

On Fri, Aug 20, 2010 at 17:00, Wolfgang Wegner <ww-ml@gmx.de> wrote:
> On Fri, Aug 20, 2010 at 04:51:44PM +0200, Kay Sievers wrote:
>> The event for the device happens during early boot where you have no
>> chance to mount. Do you run 'udevadm trigger' at bootup? It will
>> re-generate all events so that they can be handled when userspace is
>> running. It would need --action­d for your current rule to match.
>
> The busybox start script (/etc/init.d/rcS) runs my udev start script
> (/etc/init.d/start_udev.sh) which in turn runs udevadm trigger as
> one of the last steps:
>
> [...]
> udevd --daemon --debug
>
> mkdir -p /dev/.udev/queue/ /dev/.udev/rules.d/
> create_dev_root_rule /dev/.udev/
>
> udevadm trigger

As mentioned, add --action­d. Or make the rule match on 'change' too.

Kay

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: cold-plugged usb flash drive not handled correctly in embedded
  2010-08-20 14:42 cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
                   ` (4 preceding siblings ...)
  2010-08-20 15:31 ` cold-plugged usb flash drive not handled correctly in embedded system Kay Sievers
@ 2010-08-20 16:02 ` Wolfgang Wegner
  2010-08-20 16:12 ` Wolfgang Wegner
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Wolfgang Wegner @ 2010-08-20 16:02 UTC (permalink / raw)
  To: linux-hotplug

On Fri, Aug 20, 2010 at 08:29:22AM -0700, Greg KH wrote:
> 
> Perhaps because you do not have a 'mount' executable when the device is
> found during the boot process?

/bin/mount is called (successfully) by busybox' init script at the
very beginning, before udev is started.

Thanks for the hint, though.

Regards,
Wolfgang


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: cold-plugged usb flash drive not handled correctly in embedded
  2010-08-20 14:42 cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
                   ` (5 preceding siblings ...)
  2010-08-20 16:02 ` cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
@ 2010-08-20 16:12 ` Wolfgang Wegner
  2010-08-20 16:25 ` Karl O. Pinc
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Wolfgang Wegner @ 2010-08-20 16:12 UTC (permalink / raw)
  To: linux-hotplug

On Fri, Aug 20, 2010 at 05:31:12PM +0200, Kay Sievers wrote:
> On Fri, Aug 20, 2010 at 17:00, Wolfgang Wegner <ww-ml@gmx.de> wrote:
> > On Fri, Aug 20, 2010 at 04:51:44PM +0200, Kay Sievers wrote:
> >> The event for the device happens during early boot where you have no
> >> chance to mount. Do you run 'udevadm trigger' at bootup? It will
> >> re-generate all events so that they can be handled when userspace is
> >> running. It would need --action­d for your current rule to match.
> >
> > The busybox start script (/etc/init.d/rcS) runs my udev start script
> > (/etc/init.d/start_udev.sh) which in turn runs udevadm trigger as
> > one of the last steps:
> >
> > [...]
> > udevd --daemon --debug
> >
> > mkdir -p /dev/.udev/queue/ /dev/.udev/rules.d/
> > create_dev_root_rule /dev/.udev/
> >
> > udevadm trigger
> 
> As mentioned, add --action­d. Or make the rule match on 'change' too.

Thanks, that helped!

I was reading the manpage on my debian box, which is using
udev-125 and thus the documentation is horribly outdated
in some parts, i.e. I was still under the impression --action­d
was the default.

Thanks for the help, now everything works like a charm and I
can think about the proper mount script/command.

Best regards,
Wolfgang


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: cold-plugged usb flash drive not handled correctly in embedded
  2010-08-20 14:42 cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
                   ` (6 preceding siblings ...)
  2010-08-20 16:12 ` Wolfgang Wegner
@ 2010-08-20 16:25 ` Karl O. Pinc
  2010-08-20 16:32 ` cold-plugged usb flash drive not handled correctly in embedded system Bryan Kadzban
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Karl O. Pinc @ 2010-08-20 16:25 UTC (permalink / raw)
  To: linux-hotplug

On 08/20/2010 11:12:09 AM, Wolfgang Wegner wrote:


> Thanks for the help, now everything works like a charm and I
> can think about the proper mount script/command.

You may wish to look at the latest debian version of
the usbmount package, which uses udev and invokes scripts.
(IIRC)



Karl <kop@meme.com>
Free Software:  "You don't pay back, you pay forward."
                 -- Robert A. Heinlein


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: cold-plugged usb flash drive not handled correctly in embedded system
  2010-08-20 14:42 cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
                   ` (7 preceding siblings ...)
  2010-08-20 16:25 ` Karl O. Pinc
@ 2010-08-20 16:32 ` Bryan Kadzban
  2010-08-23  7:20 ` cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
  2010-08-23  7:24 ` Wolfgang Wegner
  10 siblings, 0 replies; 12+ messages in thread
From: Bryan Kadzban @ 2010-08-20 16:32 UTC (permalink / raw)
  To: linux-hotplug

On Fri, Aug 20, 2010 at 04:42:36PM +0200, Wolfgang Wegner wrote:
> ACTION="remove", KERNEL="sd[a-z][0-9]", RUN+="/bin/umount -l /mnt/usbdisk"

Hmm.  You are aware that this won't save you, right?  :-)

If someone writes a file into /mnt/usbdisk/... somewhere, and then
unplugs the USB device, this umount call will *not* flush the write out
to disk, and the file will most likely be either lost, or corrupt.

The remove event gets handed to udev *after* the device is already gone.
(And for that matter, the USB hub doesn't provide an event to the host
system until the device is already gone.  Once it's gone, you can't
delay its removal, or start any USB transactions, or anything like that:
there's no way to cleanly unmount the FS, or flush out writes, unless
the user tells you beforehand that they're going to be removing the
device.)

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: cold-plugged usb flash drive not handled correctly in embedded
  2010-08-20 14:42 cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
                   ` (8 preceding siblings ...)
  2010-08-20 16:32 ` cold-plugged usb flash drive not handled correctly in embedded system Bryan Kadzban
@ 2010-08-23  7:20 ` Wolfgang Wegner
  2010-08-23  7:24 ` Wolfgang Wegner
  10 siblings, 0 replies; 12+ messages in thread
From: Wolfgang Wegner @ 2010-08-23  7:20 UTC (permalink / raw)
  To: linux-hotplug

On Fri, Aug 20, 2010 at 11:25:07AM -0500, Karl O. Pinc wrote:
> On 08/20/2010 11:12:09 AM, Wolfgang Wegner wrote:
> 
> > Thanks for the help, now everything works like a charm and I
> > can think about the proper mount script/command.
> 
> You may wish to look at the latest debian version of
> the usbmount package, which uses udev and invokes scripts.
> (IIRC)

Thanks, I will give it a look!

Regards,
Wolfgang


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: cold-plugged usb flash drive not handled correctly in embedded
  2010-08-20 14:42 cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
                   ` (9 preceding siblings ...)
  2010-08-23  7:20 ` cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
@ 2010-08-23  7:24 ` Wolfgang Wegner
  10 siblings, 0 replies; 12+ messages in thread
From: Wolfgang Wegner @ 2010-08-23  7:24 UTC (permalink / raw)
  To: linux-hotplug

On Fri, Aug 20, 2010 at 09:32:18AM -0700, Bryan Kadzban wrote:
> On Fri, Aug 20, 2010 at 04:42:36PM +0200, Wolfgang Wegner wrote:
> > ACTION="remove", KERNEL="sd[a-z][0-9]", RUN+="/bin/umount -l /mnt/usbdisk"
> 
> Hmm.  You are aware that this won't save you, right?  :-)

Yes, I am - once more you got me for simply copying something
without a deeper look into it. The scripts/commands were simply
copied from either a script formerly used with mdev and from
some udev example I found on the internet. I can only guess that
the intention was to not block udev with the umount in case some
data would have needed to be flushed out. As long as the device
does not work wireless, it is clear there can be no transaction
after the unplug = remove event. :-)

Regards,
Wolfgang


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2010-08-23  7:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-20 14:42 cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
2010-08-20 14:51 ` cold-plugged usb flash drive not handled correctly in embedded system Kay Sievers
2010-08-20 15:00 ` cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
2010-08-20 15:19 ` Wolfgang Wegner
2010-08-20 15:29 ` Greg KH
2010-08-20 15:31 ` cold-plugged usb flash drive not handled correctly in embedded system Kay Sievers
2010-08-20 16:02 ` cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
2010-08-20 16:12 ` Wolfgang Wegner
2010-08-20 16:25 ` Karl O. Pinc
2010-08-20 16:32 ` cold-plugged usb flash drive not handled correctly in embedded system Bryan Kadzban
2010-08-23  7:20 ` cold-plugged usb flash drive not handled correctly in embedded Wolfgang Wegner
2010-08-23  7:24 ` Wolfgang Wegner

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).