Bug 261552 - Dolphin reads CD or DVD with every folder change
Summary: Dolphin reads CD or DVD with every folder change
Status: RESOLVED FIXED
Alias: None
Product: solid
Classification: Frameworks and Libraries
Component: libsolid-udisks (show other bugs)
Version: unspecified
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: Lukáš Tinkl
URL:
Keywords:
: 184449 264487 268103 270220 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-12-29 19:37 UTC by Todd
Modified: 2013-07-26 14:17 UTC (History)
20 users (show)

See Also:
Latest Commit:
Version Fixed In: 4.9.2


Attachments
remove the hack, that works around udisks/udev-shortcomings (1.85 KB, patch)
2011-12-22 19:53 UTC, Franz Trischberger
Details
Adds a global cache, so advancedDiskDetect calls occour less frequently (2.66 KB, patch)
2012-09-18 11:23 UTC, Alexander Mezin
Details
Use SOLID_GLOBAL_STATIC instead of global variables (2.37 KB, patch)
2012-09-18 23:47 UTC, Alexander Mezin
Details
Final (?) fix (9.76 KB, patch)
2013-07-26 14:17 UTC, Alexander Mezin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Todd 2010-12-29 19:37:14 UTC
Version:           unspecified (using KDE 4.5.90) 
OS:                Linux

Ever time I change to a new folder in Dolphin with a CD or DVD in my drive, the light and the drive comes on and the drive spins up.  Dolphin then locks up until it is finished with whatever it is doing with the drive.

Reproducible: Always
Comment 1 Peter Penz 2010-12-30 20:03:26 UTC
So you are entering folders that are *not* from the CD or DVD, right? Could you please let us know which panels you have enabled in Dolphin (Information Panel, Places Panel, Folders Panel, Terminal Panel)?
Comment 2 Todd 2011-01-11 19:03:50 UTC
On further investigation, it only happens when opening a new window or a new tab.  It does NOT happen on every folder change, but it does happen every time I open a window or tab no matter what folder is being view, and it locks up Dolphin until it is done.  It also happens every time I open a save or open dialog (locking up the dialog), but not when I change the folder in the dialog.  

It happens even when the new window or tab I am opening is not in any CD or DVD driver.  It even happens if it is just my home folder.

It happens even when I have closed all the panels.
Comment 3 Todd 2011-01-15 20:20:36 UTC
There is a related, but not identical, issue: when I change focus to or from dolphin with the places panel open, it also reads from my CD and DVD drives.  This once again locks up dolphin for a few seconds, but it does so every time I click on another window (any window from any program) then back on the dolphin window.

I can submit a second bug report if this helps.

To re-iterate: 

The issue with the driver reading when opening new dolphin windows or tabs happens even if no panels are open.

The issue with the driver reading when changing window focus only happens when the places panel is open.

Both happen even when when viewing a folder that is not on any CD or DVD, and both completely lock up dolphin for several seconds.

There are two separate issues here:

1. Reading from the CD or DVD drive locks up the dolphin window.  I don't think this should happen when you are not browsing a CD or DVD.  It should be able to look up the information it needs without blocking the UI.

2. Dolphin reads from the CD or DVD drive a lot, even when it is not necessary.  I would think it needs to read the CD or DVD drive when the disk is inserted, perhaps when it is mounted.  CDs and DVDs do not change that often, so it should not need to read from them very often, certainly not on a focus change or every time you open a new tab.
Comment 4 Todd 2011-01-15 20:31:00 UTC
Sorry for the double-post, but I realized something else.  both of these issues only happen when the disc is inserted but not mounted.  So if the disc is mounted, both of these problems seem to stop.  So it seems to be something dealing specifically with non-mounted discs.
Comment 5 Franz Trischberger 2011-02-05 10:56:53 UTC
I can confirm this behaviour. This slowed down dolphin-startup extremely, took ~3 seconds. Could it be that solid queries all devices, when the places-view triggers a repaint? Could this info be cached somewhere?
Comment 6 Kai Uwe Broulik 2011-03-22 14:07:49 UTC
Confirmed here on KDE 4.6.1.
When I have a CD in my drive (curiously the Driving School CD did not do anything, the Star Trek Armada 2 CD causes those issues) and launch anything that has the Places bar in it, i.e. a Dolphin window or a Save/Open dialog, the CD starts up spinning and until the CD has reached its full speed, nothing responds or opens. After that everything works just fine.
This does not happen alway if the CD is already stopped but I think after some time when the CD is really idling then.
Comment 7 Kai Uwe Broulik 2011-03-25 14:55:17 UTC
Even if the CD has went to idle and Dolphin just gets FOCUS, i.e. you click on the Dolphin window it locks up until the CD is fully spinning. This is so annoying, I just want to “park” my CD in the drive since I play the game sometimes and don‘t want to insert the disc since it‘s the only game I am playing at the moment (that requires a CD). But it is just impossible working fluently if every Open dialog, ever Dolphin window is just slow and unresponsive because of that behavior.
I would even appreciate Dolphin not getting the CD title or CD icon if it would just make it stop lagging.
Comment 8 Kai Uwe Broulik 2011-03-30 08:52:59 UTC
It gets even stuck completely when you‘re accessing an external hdd (which is currently busy because of some copy action) and thus does not respond quickly or just went to idle…
Comment 9 Ivan Andrianov 2011-03-30 12:14:32 UTC
It's really annoying.
Comment 10 Alex 2011-03-30 14:08:05 UTC
*** This bug has been confirmed by popular vote. ***
Comment 11 Peter Penz 2011-04-06 14:58:05 UTC
*** Bug 270220 has been marked as a duplicate of this bug. ***
Comment 12 Peter Penz 2011-04-06 15:01:33 UTC
For assigning this to the correct sub component it would be helpful to check:
- Does something change if the Places Panel of Dolphin is hidden (see comment #1)?
- Is the issue reproducible also when changing directories inside the file-dialog (e.g. when opening a document in kwrite)?
Thanks!
Comment 13 Kai Uwe Broulik 2011-04-07 23:51:30 UTC
It even gets Plasma to hang if you are browsing the desktop widget…
Hiding the Places panel did not help here.
Yes, file dialog is also affected, when opening it hangs.
Or if the CD has gone to idle then it also hangs when changing directories just like dolphin does.
Comment 14 Peter Penz 2011-04-08 11:17:04 UTC
Thanks for the update. I've added Kevin Ottens and David Faure to CC as this issue is not related to Dolphin. But I don't know whether it is related to Solid or something in KFilePlacesView...
Comment 15 Kevin Ottens 2011-04-08 11:52:50 UTC
Looks like the UDisks backend hits the advanced content probe too easily.
Comment 16 Franz Trischberger 2011-07-16 08:39:17 UTC
Is there some progress in fixing this? Or is it that hard? It really sucks, having a helicopter starting beside your desk (and a lag for several seconds) every time you open/save/browse files.
Even hiding the DVD-device in places-view does not help (why is it neccessary to query non-visible devices?)

If i can help fixing, please tell me where to look at. I browsed the sources, but really did not know, where to find the "advanced content probe".
Comment 17 Kai Uwe Broulik 2011-07-16 10:51:45 UTC
Hm, I think the problem lies in:
kdelibs/solid/solid/backends/udisks/udisksopticaldisc.cpp

The behavior of m_needsReprobe seems outrageous. I think I will temporarily force-false this variable since I do know what kind of optical media I have in my drive ^^
Comment 18 Franz Trischberger 2011-07-30 09:59:38 UTC
Hmmm...
There are 2 points, where m_needsReprobe is set to true:
* initialization list (l. 165, kde-4.7.0)
* OpticalDisc::slotChanged() [private] (l.254)

slotChanged gets called whenever UDisksDevice::changed() ist emitted.
This is done solely in UDisksDevice::slotChanged() [private], which gets called only when the UDisks-DBus-Service says "Changed()!"
This is what i can see from the sources, so probably it is no Solid-problem, but one in UDisks. Or a config-issue :/
Comment 19 Todd 2011-07-30 10:22:12 UTC
How does udisks know when you click on a folder in Dolphin?
Comment 20 Franz Trischberger 2011-07-31 06:40:08 UTC
(In reply to comment #19)
> How does udisks know when you click on a folder in Dolphin?

That's not what I meant.
I thought, that somehow UDisks emits a Changed() too easily, so that m_needsReprobe get's true, and the next time e.g. the places-view queries the disc-contents, the advanced content probe is triggered -> disc spin.

But I really don't know enough about solid, udisks or dbus. I just looked, where m_needsReprobe is set to true, and followed the way up...
Comment 21 Franz Trischberger 2011-11-16 14:14:02 UTC
OK, it's not a problem with UDisks. Missing AVX-Support in valgrind threw stones in my way, but finally I got callgrind running on another PC.
The problem seems to be, that OpticalDiscs-Objects get instantiated much too often. Each object gets constructed with m_needsReprobe set to true, and querying content triggers the advanvedContentsProbe.
CallGrind tells me, that 1 call came from UDisksDevice::createDeviceInterface(), 20 calls from UDiscsDevice::icon().
Filtering for "advancedDiscDetect" does not return a result (probably the function gets inlined), Searching for "QFile::encodeName" gives me one entry with 20 calls (among 7000 others): OpticalDisc::availableContent() which gets called 20 times by UDiscsDevice::icon().
Comment 22 Franz Trischberger 2011-12-22 19:53:34 UTC
Created attachment 67030 [details]
remove the hack, that works around udisks/udev-shortcomings

The patch also applies fine to kdelibs-4.7.4.

I don't know, who to blame, but it really seems to be a problem within either udisks or udev.

==============
$ udisks --show-info /dev/sr0
[...]
mounted by uid:              0
  presentation hide:           0
  presentation nopolicy:       0
  presentation name:           
  presentation icon:           
  automount hint:              
  size:                        8268341248
[...]
=====================
udisks tries to get the icon through the udev-DB. As even udisks says "I don't have an icon", I think KDE should not try to be smarter. nautilus also doesn't.
Somehow I thought, Gentoo just forgot to install some dependencies, that would automagically make PresentationIcons appear in udisks. So I installed Gnome. And - no - even when running a Gnome-Session, there is no PresentationIcon in udisks. Nautilus also just shows the plain "media-optical"-Icon.

So I removed the "we want to be exact and smart"-Code, that creates UDisks::OpticalDisc-objects again and again, just to show the best icon. In my opinion, this is just a hack.

For those of you that don't suffer from this problem, please could you look into your udev-rules, if there are some hints that could fix the root of this problem.
Comment 23 Johannes Huber 2012-03-21 08:43:56 UTC
Ping, any news on this?
Comment 24 Alexander Mezin 2012-09-18 11:23:06 UTC
Created attachment 73997 [details]
Adds a global cache, so advancedDiskDetect calls occour less frequently

Commenting out the line
m_cachedContent |= advancedDiscDetect(m_device->prop("DeviceFile").toString());
in "solid/solid/backends/udisks/udisksopticaldisc.cpp" fixes the problem for me. But maybe it's not the best solution possible.

It seems that OpticalDisk instances are recreated frequently, so m_needReprobe almost always is set to true.
I created a patch that adds global cache for availableContent(), and now dvd drive spins up only when I open a new Dolphin window. Sadly I don't know how to make such cache shared between processes. Maybe advancedDiskDetect just shouldn't be called for non-mounted disks.
Comment 25 Lukáš Tinkl 2012-09-18 15:24:04 UTC
OpticaIDisc instances are indeed recreated on demand by Dolphin or the Device Notifier so adding a global cache like this is a good idea, not so much with commenting out the advancedDiscDetect line ;)

Going to give the patch a try and submit, thanks a lot!
Comment 26 Lukáš Tinkl 2012-09-18 15:40:33 UTC
Git commit 9177a643eb5bd3208b3c6c7a15097fb11b32bf48 by Lukas Tinkl.
Committed on 18/09/2012 at 17:39.
Pushed by lukas into branch 'KDE/4.10'.

Fix 261552 - Dolphin reads CD or DVD with every folder change

by introducing a QMutexLocker around the sensitive part

M  +22   -2    solid/solid/backends/udisks/udisksopticaldisc.cpp

http://commits.kde.org/kdelibs/9177a643eb5bd3208b3c6c7a15097fb11b32bf48
Comment 27 Lukáš Tinkl 2012-09-18 15:41:24 UTC
Git commit 9b8a0ef5fd6cf3e9334d69f8ee458c1895a42394 by Lukas Tinkl.
Committed on 18/09/2012 at 17:39.
Pushed by lukas into branch 'KDE/4.9'.

Fix 261552 - Dolphin reads CD or DVD with every folder change

by introducing a QMutexLocker around the sensitive part

M  +22   -2    solid/solid/backends/udisks/udisksopticaldisc.cpp

http://commits.kde.org/kdelibs/9b8a0ef5fd6cf3e9334d69f8ee458c1895a42394
Comment 28 Lukáš Tinkl 2012-09-18 15:51:34 UTC
Git commit 05d37a921b85e3bf1b3983f758bd1bce61242252 by Lukas Tinkl.
Committed on 18/09/2012 at 17:50.
Pushed by lukas into branch 'KDE/4.10'.

similar mutex locker fix for udisks2 backend

M  +21   -1    solid/solid/backends/udisks2/udisksopticaldisc.cpp

http://commits.kde.org/kdelibs/05d37a921b85e3bf1b3983f758bd1bce61242252
Comment 29 Alexander Mezin 2012-09-18 23:47:28 UTC
Created attachment 74014 [details]
Use SOLID_GLOBAL_STATIC instead of global variables

Please apply this patch too
Comment 30 Lukáš Tinkl 2012-09-19 08:14:15 UTC
*** Bug 264487 has been marked as a duplicate of this bug. ***
Comment 31 Lukáš Tinkl 2012-09-19 08:21:26 UTC
Git commit 3f07cb578e2c62a498f313cbc7b0249d0c841abd by Lukas Tinkl.
Committed on 19/09/2012 at 10:20.
Pushed by lukas into branch 'KDE/4.10'.

use SOLID_GLOBAL_STATIC for the mutex

M  +10   -10   solid/solid/backends/udisks2/udisksopticaldisc.cpp

http://commits.kde.org/kdelibs/3f07cb578e2c62a498f313cbc7b0249d0c841abd
Comment 32 Alexander Mezin 2012-09-19 17:38:01 UTC
I don't think that this bug is completely fixed. I still experience unnecessary disk spin-ups. They happen less frequent than without patch, but they are still unnecessary. This happens because cache isn't synchronized between processes. It is much better to move the caching to some daemon, or share the cache somehow. Does solid have any daemon?

Also, advancedDiskDetect looks too low-level. Is scanning of non-mounted disks really needed? It seems that other DEs don't do this.
Comment 33 Lukáš Tinkl 2012-09-26 10:35:32 UTC
*** Bug 184449 has been marked as a duplicate of this bug. ***
Comment 34 Lukáš Tinkl 2012-09-26 10:36:01 UTC
*** Bug 268103 has been marked as a duplicate of this bug. ***
Comment 35 Franz Trischberger 2013-01-24 15:02:45 UTC
No comment since more than 4 months, not even assistance in fixing this issue. Seems to be really hard to tell people where such a global cache should be put...

This bug REALLY made KDE unusable for me: Many apps (gwenview, all calligra-apps, kdevelop, digikam, kile and many more) add a view on the filesystem in the mainwindow. Those apps need several seconds to start up making it unusable to work.
I like kde, but it's time to leave... This is the main issue, though there are some others.
Comment 36 Lukáš Tinkl 2013-01-24 15:06:00 UTC
This bug should be completely fixed in 4.9.5 and 4.10, what version are you using?
Comment 37 Franz Trischberger 2013-01-24 15:57:29 UTC
4.9.5 on one PC, 4.9.98 on the other one.
Also tried most recent fedora-patches to incorporate udisks2-backend, when updating to 4.9.5 still showed this issue.
Comment 38 Martin Bednar 2013-01-24 20:18:15 UTC
Franz : Your issue is that upon application startup your drive is scanned, which is true and, when combined with a slow drive, is a nuisance. This bug is about the scan occuring on every folder change/tab creation (which is truly fixed).
Comment 39 Franz Trischberger 2013-01-25 14:30:04 UTC
Martin: Read comments #2 and #3 - "On further investigation". From that point the "DVD spin up on new window" was one of the central points. At that time the summary should have been changed to something more appropriate.
Furthermore, comment #32 even mentioned the "global cache" and the willingness to help - no response.
Comment 40 Franz Trischberger 2013-01-31 15:51:54 UTC
short update:
4.9.98 with udisks2-backend indeed seems to have fixed the issue, but not udisks1.
I also had a look at the CMakeLists.txt: it is not possible to build WITHOUT ANY udisks when on linux:
if ( WITH_SOLID_UDISKS2 )
    # add usidks2-sources
else ( WITH_SOLID_UDISKS2 )
    # add udisks1-sources
endif ( WITH_SOLID_UDISKS2 )

Is that really by intention?
Comment 41 Lukáš Tinkl 2013-01-31 16:01:25 UTC
Yes, building w/o udisks(2) on Linux doesn't make sense these days, HAL has been dead for a long time
Comment 42 Franz Trischberger 2013-01-31 16:13:14 UTC
May be, but think of the people who don't need such device-managers.
Or people who are happy that they still can have a decent desktop without all that polkit/consolekit (sorry, dead - systemd...) stuff.
Comment 43 Franz Trischberger 2013-02-04 11:18:59 UTC
GRRRR!
When I claimed this finally was fixed I was running gnome3.
This morning I started kde desktop - and spinning optical disks start driving me crazy again! I even created a test user (in case it is borked config related) and still the same issue.
So please could someone tell me
* where the fix (cache, whatsoever) was introduced (best would be a link to the commit)
* if there is an option one has to set (systemsettings,etc.)
* some special group I have to be in (as all works fine with gnome3 I don't think so)
* some "hidden" service has to be started (All services in "kdmshell4 kcmkded" are checked)

I realized that when running gnome3 I get a dbus service "org.gtk.Private.UDisks2DeviceMonitor" registered - might that be related?
Comment 44 Rex Dieter 2013-02-04 13:07:46 UTC
see comment #26 through comment #31 for the related commits (with links).
Comment 45 Franz Trischberger 2013-02-04 13:12:55 UTC
(In reply to comment #44)
> see comment #26 through comment #31 for the related commits (with links).
see comment #32 why it's not.
Those commits linked here just introduced a cache for each client (dolphin application, other apps using filedialog). This still does not prevent the disk spinning for the very first infvocation (dolphin start/open,save file in calligra/...)
Comment 46 Rex Dieter 2013-02-04 13:18:51 UTC
true, that may be as good as it gets for now.  Certainly better than what bug $SUBJECT suggests
Comment 47 Alexander Mezin 2013-02-04 13:33:10 UTC
If you want to stop drive spin-ups, just enable automounting. It seems that mounted filesystem's contents are cached by kernel.

My fix couldn't be enabled/disabled, so no options, no groups, no hidden services.
Also this fix possibly introduces another problem - if disk is changed when there is no UDisksOpticalDisk class instances, corresponding cache item won't be invalidated, and won't be updated later. It's strange that nobody noticed this.

And again: This disk probing code must be moved to a daemon, like automounter, and applications should only request information from it. Maybe I'll try to write it in near future.
Comment 48 Franz Trischberger 2013-02-04 14:08:44 UTC
> If you want to stop drive spin-ups, just enable automounting.
I know that this might fix the issue. But my discs are Video DVDs and Audio CDs - there is no need to mount them in order to read them. I had big trouble in the past when I mounted optical discs (that's why I don't interact with the Device Manager-plasmoid, as it mounts every time even if it is not neccessarily needed!) - I could not eject the disc anymore by pressing the button on the drive. Even worse after pressing it was not possible anymore to eject using the GUI - I had to eject --force as root, which did work in some but not all cases, forcing me to reboot if I wanted to eject the disc...

> And again: This disk probing code must be moved to a daemon, like
> automounter, and applications should only request information from it. Maybe
> I'll try to write it in near future.
But that would break every single client that makes use of Solid!
Wouldn't it be better to simply store plain data in the daemon. Daemon listens for UDisks-events (new device, device removed, ... don't know what UDisks exposes) and update the data. Solid UDisks-Backend simply queries that daemon.
Comment 49 Alexander Mezin 2013-02-05 03:58:02 UTC
(In reply to comment #48)

> Wouldn't it be better to simply store plain data in the daemon. Daemon
> listens for UDisks-events (new device, device removed, ... don't know what
> UDisks exposes) and update the data. Solid UDisks-Backend simply queries
> that daemon.

I meant exactly that
Comment 50 Alexander Mezin 2013-02-09 22:07:01 UTC
My first attempt at creating daemon: https://github.com/sanya-m/solid-disk-prober
Could someone test it? I have only data cd's, so can't test that I didn't broke video cd detection etc. KDE 4.10 and udisks2 required, patch included. 

For me, drive spin-ups are gone, didn't found any regressions.

Commenting here, because it seems that all interested people are subscribed to this bug.
Comment 51 Franz Trischberger 2013-02-10 09:59:14 UTC
Thx! A! LOT!
Works fine here, disc type is recoginzed correctly. (tested with Video DVD and Audio CD).

Gentoo users can test this with packages from my overlay:
https://github.com/ff2000/gentoo-overlay
Comment 52 Elián Hanisch 2013-05-13 00:04:18 UTC
was this fixed in 4.9.2? I'm using 4.9.5 and my cdrom always spins up whenever I open dolphin.
Comment 53 Frank Steinmetzger 2013-05-13 15:32:35 UTC
I’m running 4.10.2 and now that you reminded me of this bug, I checked again and the issue has gone. Yay! (I’ve had my optical drive open ever since it began, so I never noticed a fix being implemented).
Comment 54 Alexander Mezin 2013-07-26 14:17:59 UTC
Created attachment 81359 [details]
Final (?) fix

Today I committed this change. It should finally fix the problem. Please test it. Should apply without problems to 4.10 and 4.11 rc, but it works only for UDisks 2. It would be good to be sure that it doesn't break anything for anyone.