Skip to contentSkip to conversation

Accessing device information in REMOVE agent

DISCUSSION Andrey Borzenkov 2 participants 4 messages Nov 8, 2003 – Nov 9, 2003

lore
Share & tools
lore
#0 lore raw

I'd like to be notified when block device goes away (e.g. USB stick unplugged) basically to look if device is in use and possibly initiate clean up. Block hotplug currently is passing only DEVPATH; but it alone is not reliable way to identify it; device may be used under alias names via symbolic links.

Is it safe to access /sys/$DEVPATH in REMOVE agent? Apparently hotplug is called asynchronously i.e. it is possible that /sys entry is already removed?

Would it make sense to add device number? It seems to be natural native "block device ID" :)

TIA

-andrey

-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest developments in Apache, PHP, Perl, XML, Java, MySQL, WebDAV, and more! http://www.apachecon.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw
Quoted 4 lines · Andrey Borzenkov

I'd like to be notified when block device goes away (e.g. USB stick unplugged) basically to look if device is in use and possibly initiate clean up. Block hotplug currently is passing only DEVPATH; but it alone is not reliable way to identify it; device may be used under alias names via symbolic links.

What do you mean? DEVPATH is unique for that point in time. There are no alias's in sysfs.

Quoted 2 lines

Is it safe to access /sys/$DEVPATH in REMOVE agent? Apparently hotplug is called asynchronously i.e. it is possible that /sys entry is already removed?

The /sys entry is probably already removed, but if not, it will disappear any second. So no, it's not safe to try to access it, as it will not work.

Quoted 2 lines

Would it make sense to add device number? It seems to be natural native "block device ID" :)

What "device number"? The major/minor? Why? It's about as unique as DEVPATH is for any point in time.

thanks,

greg k-h

-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest developments in Apache, PHP, Perl, XML, Java, MySQL, WebDAV, and more! http://www.apachecon.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#2 lore raw
In reply to Andrey Borzenkov
Quoted 10 lines · Greg KH
Quoted 5 lines · Andrey Borzenkov

I'd like to be notified when block device goes away (e.g. USB stick unplugged) basically to look if device is in use and possibly initiate clean up. Block hotplug currently is passing only DEVPATH; but it alone is not reliable way to identify it; device may be used under alias names via symbolic links.

What do you mean? DEVPATH is unique for that point in time. There are no alias's in sysfs.

Sorry I had to be more precise.

I'd like to (try to) replace current synchronous media change checks in supermount by mounting device on insert and releasing it on remove. For those cases when it makes sense of course, USB sticks in the first place.

But users are free to use any names or links for their device names i.e. they can do

ln -s sda /de/myflash
mount /dev/myflash

and on remove it is rather hard to match this name against DEVPATH. But I can save (major,minor) when mounting and use it to match mounted filesystem on remove.

Quoted 7 lines
Quoted 3 lines

Would it make sense to add device number? It seems to be natural native "block device ID" :)

What "device number"? The major/minor? Why? It's about as unique as DEVPATH is for any point in time.

Hmm ... probably I can just as well use device name (meaning genhd->disk_name) you are right.

Thank you

-andrey

-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest developments in Apache, PHP, Perl, XML, Java, MySQL, WebDAV, and more! http://www.apachecon.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#3 lore raw
In reply to Andrey Borzenkov
Quoted 8 lines · Andrey Borzenkov

I'd like to (try to) replace current synchronous media change checks in supermount by mounting device on insert and releasing it on remove. For those cases when it makes sense of course, USB sticks in the first place.

But users are free to use any names or links for their device names i.e. they can do

Quoted 6 lines

ln -s sda /de/myflash
mount /dev/myflash

and on remove it is rather hard to match this name against DEVPATH. But I can save (major,minor) when mounting and use it to match mounted filesystem on remove.

You might want to look into what devlabel does, as it sounds like it does much the same thing of what you are wanting to do.

Good luck,

greg k-h

-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest developments in Apache, PHP, Perl, XML, Java, MySQL, WebDAV, and more! http://www.apachecon.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel