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
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?
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.
Can you please retest with the latest code from 4.10 branch?
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
Also, plasma-desktop now uses 100% cpu sometimes. I'm not sure if it's related to your changes.
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.
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.
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.
> 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()
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()?
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.
This is weird... it all works correctly here... what udisks2 version are you using?
I just want to say that today I updated to kdelibs 4.10.1 and now it works.
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.
Created attachment 77912 [details] Possible fix However I have fix for that.
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
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.
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.
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.
Why do you call driveBackend->allProperties(), this is overkill
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.
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.
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?
Done. https://git.reviewboard.kde.org/r/109418/ And please take a look at this request also: https://git.reviewboard.kde.org/r/109384/
Since the review has been submitted, should we close this bug?