Discussion:
[OpenWrt-Devel] detecting USB sd card removal ("block info")
Karl Palsson
2016-01-28 09:31:14 UTC
Permalink
Given that OpenWrt doesn't have a daemon like udisks to
mount/umount things automatically, I was trying to build it
myself by something like "block info" in a crontab.

"block info" correctly identifies when I insert an sd card into
slot on a fixed USB card reader on my device, and creates device
nodes, and if I remove the card, "block info" correctly notes
that the card is gone and removes the device nodes.

However, after "block mount" has mounted the sdcard (based on
config in /etc/config/fstab) "block info" now no longer notices
if the card has been removed. As far as I have been able to find,
the only way to make anything update is to explicitly "block
umount" which works correctly if the card _has_ been removed, but
if the card hasn't been removed, I've now unmounted for no reason
at all.

Should "block info" actually be detecting this properly? Is there
some other tool that is meant to be used for this?

This was with "block" from fstools version
2016-01-10-96415afecef35766332067f4205ef3b2c7561d21

Cheers,
Karl P

- --
Sent using Mailpile, Free Software from www.mailpile.is
Daniel Golle
2016-01-28 10:36:25 UTC
Permalink
Hi Karl,
Post by Karl Palsson
Given that OpenWrt doesn't have a daemon like udisks to
mount/umount things automatically, I was trying to build it
myself by something like "block info" in a crontab.
Well, there is mountd which can be used to maintain autofs for
hot-plugable block devices.
It will only mount things when they are actually being accessed
(rather than mounting them once inserted/plugged-in) but at least
unmounting on hot-removal doesn't need any extra care...
I don't know your excact usage scenario, however, it guess that's
already a better place to start from than having a cron-job...

Cheers

Daniel
Karl Palsson
2016-01-28 12:35:05 UTC
Permalink
Post by Daniel Golle
Hi Karl,
Post by Karl Palsson
Given that OpenWrt doesn't have a daemon like udisks to
mount/umount things automatically, I was trying to build it
myself by something like "block info" in a crontab.
Well, there is mountd which can be used to maintain autofs for
hot-plugable block devices. It will only mount things when they
are actually being accessed (rather than mounting them once
inserted/plugged-in) but at least unmounting on hot-removal
doesn't need any extra care... I don't know your excact usage
scenario, however, it guess that's already a better place to
start from than having a cron-job...
I'll have a play with mountd, it seemed to be very very old
untouched code, so I wasn't really excited about even trying, but
sure.

Are you saying that mountd will automatically unmount the
filesystem if the device goes away or what? The problem is that
the device does _not_ go away on hotplug. (It doesn't get created
on hotplug either)

I have to explicitly run "block info" to get the system to notice that the card is inserted (and it creates the devices) and that also works for noticing that the card has been removed (and removing the devices) but it _doesn't_ work after the device has been mounted. Until I explicitly unmount (block umount or manual umount) block info doesn't detect that the card has been removed.

I want to _somehow_ catch and cleanup up if the card has been
removed. At present, I can keep writing to a card that doesn't
exist and all I get is a steady stream of failures on the
console. Having to unmount just to _test_ if the card is still
there isn't very helpful.

Timelines, maybe that helps: paste these two into
websequencediagrams.com

- ------------
title USB SD Card detect without mounting

note over devs: no /dev/sda*
SD->USB-reader: inserted
note over devs: no /dev/sda*
Bob->console: block info
console->devs: ??
note over devs:
/dev/sda* created
dmesg log about size ~xGb
end note
Bob->console: block info
console->Bob: no change
SD->USB-reader: removed
Bob->console: block info
console->devs: ??
note over devs:
/dev/sda* removed
dmesg log about size changed to 0
end note
- --------------

- ------
title USB SD Card detect WITH mounting

note over mounts: no mounts
note over devs: no /dev/sda*
SD->USB-reader: inserted
note over devs: no /dev/sda*
Bob->console: block info
console->devs: ??
note over devs:
/dev/sda* created
dmesg log about size ~xGb
end note
Bob->console: block detect
Bob->console: edit and enable /etc/config/fstab
Bob->console: block mount
note over mounts: /mnt/sda1 working
Bob->console: block info
console->Bob: no change
SD->USB-reader: removed
Bob->console: block info
console->Bob: no change!! no longer notices card gone!
note over devs,mounts:
/dev/sda* and mounts still EXIST
end note
- -------

Loading...