Bug 412257 - kiod5 doesn't release usb device when it is not in use
Summary: kiod5 doesn't release usb device when it is not in use
Status: REPORTED
Alias: None
Product: kio-extras
Classification: Unclassified
Component: MTP (show other bugs)
Version: 19.08.1
Platform: Archlinux Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Elvis Angelaccio
URL:
Keywords: efficiency
: 432557 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-09-23 20:01 UTC by hamelg
Modified: 2022-05-10 20:36 UTC (History)
18 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description hamelg 2019-09-23 20:01:21 UTC
As soon as I plug my usb mtp device, udev launches the KIO MTP module. It opens the usb device and doesn't release it when it is not in use.
Other programs which doesn't support KIO can not access it anymore.
See this bug report :
https://bugs.kde.org/show_bug.cgi?id=412255

SOFTWARE/OS VERSIONS
Plasma 5.16
kde Frameworks 5.62
kde-applications 19.08
Comment 1 yuilytg7 2020-12-20 02:46:41 UTC
I still have this problem more than a year later the bug report

Can this be solved?

I cannot use the MTP interface unless I pop up the command line and kill kiod5.

Why does kiod5 hangs my tablet anyway?
Comment 2 Norbert Preining 2021-05-11 01:38:16 UTC
Indeed, same here on Debian with Plasma 5.21.5, Frameworks 5.82, Gears 21.04 - kiod does not release a claimed USB MTP device and blocks all other devices (in particular Calibre in my case).

Killing the kiod process that holds the lock (to be found with fuser /dev/libmtp...) resolves this problem, but is not optimal.
Comment 3 Ralf Jung 2021-07-29 16:01:22 UTC
I am having the same problem: after boot, when I connect my phone, I can access files just fine. When I unplug and replug, I can no longer connect. I am doing a lot of unplugging and replugging since I am migrating from an old to a new phone. I basically have to reboot my entire system each time since KDE refuses to ever let go of that MTP connection.

I hope killing kiod5 does not have too adverse side-effects. I can recommend "android-file-transfer" -- as long as KDE stays out of the way, it is a very reliably tool to access MTP devices.
Comment 4 Grete Mueller 2021-11-22 23:48:46 UTC
Could this be fixed?

Have to manually kill kiod5, then run mtp-detect to mount the device properly.

Device info:
   Manufacturer: Samsung Electronics Co., Ltd.
   Model: SM-T580
Comment 5 Peter Albrecht 2021-12-18 12:58:24 UTC
Another workaround, I have found:
If you do not use KIO MTP at all (since you only use something like "jmtpfs"), you can "disable kmtpd":

# chmod 000 /usr/lib/x86_64-linux-gnu/qt5/plugins/kf5/kiod/kmtpd.so

After restarting, mounting my android mobile phone with jmtpfs (MTP protocol) worked again.

Thanks to user "arkonbob" at reddit for bringing up this solution: https://www.reddit.com/r/kde/comments/mvrtck/restarting_kiod/

I am using Debian 11 (Bullseye):
* KDE Frameworks 5.78.0
* Qt 5.15.2

-----

Another workaround is to switch to a runlevel without graphical desktop. This stops KDE and KIOD. (In my case I want to run some scripts to backup the data on my mobile phone, so I don't need a graphical desktop while these scripts are running.)
I you use systemd, you can do the following:
* log out from KDE session
* go to console (e.g. CTRL + ALT + F2)
* log in at the console as root
* switch the runlevel:  # systemctl isolate multi-user.target
* mount your mobile phone via "jmtpfs"
* run your backup-scripts (or whatever you wanted to do)
* unmount jmtpfs
* switch back to normal runlevel: # systemctl isolate graphical.target
* log out from console
* go back to graphical session with CTRL + ALT + F7

But this is very cumbersome and you have to close all your running graphical programs.
Comment 6 Harald Sitter 2022-01-06 13:01:03 UTC

*** This bug has been marked as a duplicate of bug 432557 ***
Comment 7 Harald Sitter 2022-01-07 13:12:31 UTC
*** Bug 432557 has been marked as a duplicate of this bug. ***
Comment 8 Harald Sitter 2022-01-07 13:14:25 UTC
I'm not quite sure what you expect to happen here. MTP is a single-access kind of protocol. You can either access it through KIO or another app, you cannot access it through both at the same time. Any insight into what you expect to happen?
Comment 9 Ralf Jung 2022-01-07 13:26:13 UTC
In my case, kio seems to even lock itself out -- after unplugging and re-plugging my phone, kio-based applications are unable to access it.

Also, kio will lock the MTP device even without me using any kio app -- if I want to use another app, I always have to kill the KIO daemon, even if I did not open the phone in Dolphin.
Comment 10 Justin 2022-01-07 13:34:00 UTC
(In reply to Harald Sitter from comment #8)
> I'm not quite sure what you expect to happen here. MTP is a single-access
> kind of protocol. You can either access it through KIO or another app, you
> cannot access it through both at the same time. Any insight into what you
> expect to happen?

MTP is a single-access - this I did not know. Interesting.
You can either access it through KIO or another app - that's fine. I only need access to one app at a time.
expect to happen - As it is only accesses one protocol at a time then I would like it to recognise that another protocol has been launched, shut down the current process and then automatically switch to the new process.
Comment 11 Harald Sitter 2022-01-07 13:37:43 UTC
(In reply to Ralf Jung from comment #9)
> In my case, kio seems to even lock itself out -- after unplugging and
> re-plugging my phone, kio-based applications are unable to access it.

The unplugging and plugging back in should be fixed in master. There were caching problems.

> Also, kio will lock the MTP device even without me using any kio app -- if I
> want to use another app, I always have to kill the KIO daemon, even if I did
> not open the phone in Dolphin.

Plasma itself will already trigger the device opening, this isn't particularly related to dolphin. Any file IO application (which is the majority of general purpose KDE apps really - anything with a file open dialog) can ultimately talk to MTP. It's a bit unfortunate that this happens without you even opening anything but from what I can tell changing that is way too complicated for what we gain. Specifically since we already have problems with caching another level of asynchronicity would only serve as an additional source for bugs I fear :(
Comment 12 Harald Sitter 2022-01-07 13:39:22 UTC
Ultimately I think the best solution would be for third party apps to use the XDG desktop portal for file open dialogs. That way we, plasma, control the file IO and can route it through KIO as needed. But that is a bit of a pipe dream probably
Comment 13 Oswald Buddenhagen 2022-01-07 13:54:34 UTC
it should be obvious that kde locking out other frameworks from accessing mtp devices by its mere presence is not acceptable, and deferring to a pipe dream solution just doesn't cut it.
so kde needs to a) claim the device lazily (e.g., the file dialog doesn't really need it to merely show the device's presence) and b) release it eagerly.
(i didn't check the current state of master, so i can't judge what actually still needs being done.)
Comment 14 Harald Sitter 2022-01-07 14:12:08 UTC
It is not.
Comment 15 Oswald Buddenhagen 2022-01-07 14:19:04 UTC
what is (not), and why?
Comment 16 ticket.kde.djr4kjpch5320z5k 2022-01-21 05:03:07 UTC
I would expect a "Release" action in the applet and the context menu in dolphin, "like" the "Safely remove" for a USB key.
Comment 17 Peter Albrecht 2022-01-21 09:56:27 UTC
Additionally to the "release" action (see previous comment), I would be glad to have a "disable" option, too. 

I do not use KIO MTP at all. But I use MTP with other applications a lot, so it would be cumbersome to always click the "release" action before I can use MTP in other applications. Maybe the option "disable kio mtp" can be put in KDE settings dialog.
Comment 18 Bug Janitor Service 2022-02-05 04:37:45 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 19 Oswald Buddenhagen 2022-02-05 11:30:50 UTC
afaict, the question was about expectations, which imo has been adequately answered.
Comment 20 Norbert Preining 2022-03-21 08:19:42 UTC
(In reply to Harald Sitter from comment #11)
> The unplugging and plugging back in should be fixed in master. There were
> caching problems.

Unfortunately it is not. I am running Arch Linux with the latest released KDE packages, and unplugging and replugging a mtp ebook reader does not help. The device contents is shown, but I cannot copy files to the device.

I need to kill the kiod as always to get rw access to the device again.

A typical example is Calibre (which I use a lot) which has a "Release" button for the device. Something similar should be included in Dolphin and "Removable Devices".