udisks icon indicating copy to clipboard operation
udisks copied to clipboard

"Error looking up object for device" when trying to mount (existing !) device

Open stefanseefeld opened this issue 5 years ago • 5 comments

My application is using the inotify service to detect the appearance of a plugged-in USB key (I have set up a udev rule to generate an entry in a /dev/... sub-folder).

In the handler function I'm running udisksctl mount -b <device-path>, which generates the error "Error looking up object for device ".

Any idea how this is possible ? If I manually run the above mount command after plugging in the USB key, all works as expected, but my application consistently fails to mount the key when it is plugged in.

Is it possible that there is a race, i.e. that I'm receiving the notification before the device is actually ready to be mounted ? Any idea how to debug this ?

stefanseefeld avatar Nov 26 '19 20:11 stefanseefeld

Is it possible that there is a race, i.e. that I'm receiving the notification before the device is actually ready to be mounted ? Any idea how to debug this ?

Yes, that is definitely possible. Both udev and UDisks need some time to process the device (UDisks reacts to a udev event) and I guess inotify is the fastest here.

Debugging is simple, just run udevadm monitor to see if the inotify is faster than UDisks.

Possible solution might be to run udevadm settle before using udisksctl but this only makes sure that udev finished with the device, not UDisks so there is still some room for a race condition. I'd suggest to use UDisks for everything -- instead of using inotify, you could connect to the changed signal from UDisks to be notified when UDisks detects the device and is able to mount it.

vojtechtrefny avatar Nov 26 '19 21:11 vojtechtrefny

I think we've wanted some kind of udisksctl settle at one point in the past. Still it wouldn't guarantee 100% race-free operation, that's impossible with udev.

The right solution here is to react on object appearance on the UDisks object manager (D-Bus).

tbzatek avatar Nov 27 '19 11:11 tbzatek

Could you provide a work around for this problem?

Emmanuel-Messulam avatar Feb 09 '24 17:02 Emmanuel-Messulam

Could you provide a work around for this problem?

There's no workaround for this issue, it's a question of design. As suggested above, use the UDisks object manager to listen for events.

tbzatek avatar Feb 09 '24 17:02 tbzatek

Could you please point me to an example? I am a bit confused trying to get an Ubuntu 16.04 machine to automount USB devices without a UI attached. And stumbled into a solution with udev, but cannot find how to attach events to udisks. Thanks for your speedy response!

Emmanuel-Messulam avatar Feb 09 '24 17:02 Emmanuel-Messulam