Bug 314778 - DeviceNotifier doesn't emit events for optical disks
Summary: DeviceNotifier doesn't emit events for optical disks
Status: RESOLVED FIXED
Alias: None
Product: solid
Classification: Frameworks and Libraries
Component: libsolid-udisks2 (show other bugs)
Version: 4.10.0
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Lukáš Tinkl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-09 17:43 UTC by Alexander Mezin
Modified: 2013-03-24 06:20 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 4.10.1


Attachments
Test code (710 bytes, text/x-c++src)
2013-02-10 02:39 UTC, Alexander Mezin
Details
Patch that partially HIDES the bug (551 bytes, patch)
2013-02-11 01:46 UTC, Alexander Mezin
Details
Possible fix (2.37 KB, patch)
2013-03-10 11:11 UTC, Alexander Mezin
Details
Fix v2 (2.25 KB, patch)
2013-03-11 09:42 UTC, Alexander Mezin
Details
Fix v3 (4.46 KB, patch)
2013-03-11 13:02 UTC, Alexander Mezin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Mezin 2013-02-09 17:43:42 UTC
DeviceNotifier doesn't emit DeviceAdded/DeviceRemoved events when I insert/eject optical disk.
However, if I make a call to Device::listFromType or listFromQuery, it starts emitting events.

Reproducible: Always
Comment 1 Lukáš Tinkl 2013-02-09 19:43:21 UTC
How do you check for the events? Or you mean that you don't get the Device Notifier popup when inserting the media? And last, does it happen only with blank/audio CDs or any type, like data as well?
Comment 2 Alexander Mezin 2013-02-09 20:36:13 UTC
I'm writing application. I have this line of code:

connect(Solid::DeviceNotifier::instance(), SIGNAL(deviceRemoved(QString)), this, SLOT(deviceRemoved(QString)));

And have qDebug() statement in deviceRemoved slot. However, when I run my application and eject cd from drive, I don't see output of qDebug in console. Also, I don't see "media changed" message (from libsolid's udisksmanager.cpp). But if I add somewhere these lines:

    //Temporary workaround for bug #314778
    QList<Solid::Device> disks = Solid::Device::listFromType(Solid::DeviceInterface::OpticalDisc);
    foreach (Solid::Device dev, disks) {
        qDebug() << "Optical disk found: " << dev.udi();
    }

then I see my debug output, and libsolid prints "media changed" messages too. USB stick is handled correctly without these lines.
Comment 3 Lukáš Tinkl 2013-02-09 20:39:46 UTC
Can you please retest with the latest code from 4.10 branch?
Comment 4 Alexander Mezin 2013-02-10 02:39:25 UTC
Created attachment 77075 [details]
Test code

Version from git emits signals correctly. But added/removed devices are reported as StorageVolumes, but not OpticalDisks.
Attached code outputs this:
"/org/freedesktop/UDisks2/block_devices/sr0" lost interfaces: ("org.freedesktop.UDisks2.Filesystem") 
Removed  "/org/freedesktop/UDisks2/block_devices/sr0"  is optical disk:  true 
MEDIA CHANGED in "/org/freedesktop/UDisks2/block_devices/sr0" ; size is: 0 
"/org/freedesktop/UDisks2/block_devices/sr0" has new interfaces: ("org.freedesktop.UDisks2.Filesystem") 
Added  "/org/freedesktop/UDisks2/block_devices/sr0"  is optical disk:  false 
MEDIA CHANGED in "/org/freedesktop/UDisks2/block_devices/sr0" ; size is: 1174405120 

With commented line "//Solid::Device::allDevices();":
"/org/freedesktop/UDisks2/block_devices/sr0" lost interfaces: ("org.freedesktop.UDisks2.Filesystem") 
Removed  "/org/freedesktop/UDisks2/block_devices/sr0"  is optical disk:  false 
"/org/freedesktop/UDisks2/block_devices/sr0" has new interfaces: ("org.freedesktop.UDisks2.Filesystem") 
Added  "/org/freedesktop/UDisks2/block_devices/sr0"  is optical disk:  false 
MEDIA CHANGED in "/org/freedesktop/UDisks2/block_devices/sr0" ; size is: 1174405120
Comment 5 Alexander Mezin 2013-02-11 00:08:19 UTC
Also, plasma-desktop now uses 100% cpu sometimes. I'm not sure if it's related to your changes.
Comment 6 Alexander Mezin 2013-02-11 01:27:05 UTC
No, it's not related to this changes. But it's related to this bug. Plasma starts eating 100% cpu only when I insert cd and my test program with "//Solid::Device::allDevices();" commented is running. This happens with 4.10.0, this also happens with kdelibs from git.
Comment 7 Alexander Mezin 2013-02-11 01:46:33 UTC
Created attachment 77119 [details]
Patch that partially HIDES the bug

This patch makes following problems disappear:
- plasma eating 100% cpu
- no notifications about added/removed devices
I can't say that it solves them. I don't understand why they happen and why they gone. Optical disks still aren't detected.
Comment 8 Alexander Mezin 2013-02-12 06:46:20 UTC
Sorry for making too much noise, bug in plasma-desktop is completely unrelated, it happens with and without any patches and updates. I'll report it separately.
Comment 9 Lukáš Tinkl 2013-02-14 14:38:31 UTC
> Version from git emits signals correctly. But added/removed devices are reported as StorageVolumes, but not OpticalDisks.

Well, an OpticalDisc _is_ a StorageVolume by inheritance, so you have to cast it to the right type or check with Device::queryDeviceInterface()
Comment 10 Alexander Mezin 2013-02-15 06:37:25 UTC
I mean isOpticalDisc() returns "false". Sometimes. Sometimes it returns "true" (when Device::allDevices() is called before, for example). So I must use queryDeviceInterface and can't trust isOpticalDrive()?
Comment 11 Sergio Tridente 2013-03-02 04:32:00 UTC
I think this might be related: I am experiencing what seems to be the same problem with Optical devices and udisks2 backend. Whenever I insert optical media, it does not seem to be recognized: only Dolphin action is showed in notification area but no optical related one (k3b, kaffeine, etc). It even offers to open blank media on daulphin!

If I regenerate kdelibs without udisks2 support and I use udisks, the problem disappears.

I am on Arch Linux and kdelibs version is 4.10.0.
Comment 12 Lukáš Tinkl 2013-03-05 12:11:22 UTC
This is weird... it all works correctly here... what udisks2 version are you using?
Comment 13 Sergio Tridente 2013-03-06 01:21:13 UTC
I just want to say that today I updated to kdelibs 4.10.1 and now it works.
Comment 14 Alexander Mezin 2013-03-10 11:10:54 UTC
Not fixed. KDE 4.10.1.
1) Open Dolphin window
2) Insert some optical disk
3) See "CD-ROM" with wrong icon in places panel and device notifier. Also, device notifier shows that it's generic storage volume, not optical disk.
Comment 15 Alexander Mezin 2013-03-10 11:11:32 UTC
Created attachment 77912 [details]
Possible fix

However I have fix for that.
Comment 16 Lukáš Tinkl 2013-03-10 11:37:34 UTC
I can't reproduce, most likely a bug in your udisks2/udev package. Furthermore, the patch is wrong, the "double" emitting of signals is needed in special cases (so called 2-stage storage devices), see https://bugs.kde.org/show_bug.cgi?id=315065
Comment 17 Alexander Mezin 2013-03-10 11:44:28 UTC
But double emitting isn't needed for optical disks, right? The "don't emit signals twice" is only for them, these two-stage storage devices aren't recorded in m_mediaChangedSources. 
Also, without this patch, slotMediaChanged will never be called if application didn't called allDevices() somehow (so, no deviceAdded for disks without filesystem recognized by udisks). And with only "allDevices" line, deviceAdded/deviceRemoved would be emitted twice for optical disks.
Comment 18 Alexander Mezin 2013-03-11 06:03:44 UTC
Tested with udisks 2.0.1, 2.0.91, 2.0.92 - same behavior.
To be sure that it's not udisks bug I even wrote a simple test application that communicates with Udisks directly using QtDBus. And seems that it's bug in solid.
Comment 19 Alexander Mezin 2013-03-11 09:42:06 UTC
Created attachment 77941 [details]
Fix v2

There was race between InterfacesAdded/PropertiesChanged for disk and PropertiesChanged for drive. As OpticalDisc actually reads properties of drive, this caused problems that sometimes appeared and sometimes not.
Comment 20 Lukáš Tinkl 2013-03-11 11:29:36 UTC
Why do you call driveBackend->allProperties(), this is overkill
Comment 21 Alexander Mezin 2013-03-11 12:12:42 UTC
Properties may be added in future. And someone will forget to update them. And this bug will appear again. I don't think that optimisation is needed here, there is only one dbus call. It can be even better than getting 3 properties one by one.
Comment 22 Alexander Mezin 2013-03-11 13:02:44 UTC
Created attachment 77953 [details]
Fix v3

Additional testing shows that there's race between Manager and DeviceBackend of the disk too. Also, I made some optimizations.
I don't limit this only to disk devices because other types of devices can be affected to.
Comment 23 Lukáš Tinkl 2013-03-11 13:07:58 UTC
Ok, since this is getting a bit offtopic here, could you post a regular review request so that the patch gets more exposure and discussion?
Comment 24 Alexander Mezin 2013-03-11 13:53:51 UTC
Done. https://git.reviewboard.kde.org/r/109418/
And please take a look at this request also: https://git.reviewboard.kde.org/r/109384/
Comment 25 Alex Fiestas 2013-03-24 03:59:13 UTC
Since the review has been submitted, should we close this bug?