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: CONFIRMED
Alias: None
Product: kio-extras
Classification: Frameworks and Libraries
Component: MTP (show other bugs)
Version: 19.08.1
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Elvis Angelaccio
URL:
Keywords: efficiency
: 432557 476986 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-09-23 20:01 UTC by hamelg
Modified: 2024-10-13 20:43 UTC (History)
35 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


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 Pussy Boots 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".
Comment 21 Patrick Silva 2022-11-04 23:52:31 UTC
VLC player was failing to play files from my Android phone connected in MTP mode. journal log said:

mtp services discovery: The device seems to be mounted, unmount it first

Then I killed kiod5 process and VLC was able to play the files.


Operating System: Arch Linux
KDE Plasma Version: 5.26.2
KDE Frameworks Version: 5.99.0
Qt Version: 5.15.7
Graphics Platform: Wayland
Comment 22 Lorenzo 2023-01-10 08:52:29 UTC
Hi I am experiencing a similar issue with KDE Plasma 5.26.4 on Manjaro with an Android MTP phone while wanting to use Android File Transfer [1][2] to mount the device and e.g. do rsync or similar (AFT will mount to a 'normal' directory thus allowing terminal operations etc.).

Whenever I plug the phone in and select file transfer (i.e. MTP) on the phone, KDE / Dolphin grab it and it results 'busy' to any other application trying to use it. Also there's no 'unmount' / release option.

The only work-around I've found is, as reported by other users, to kill kiod5 and then after that run aft-mtp-mount

I think it would be great to have either an interface to 'release' a device or maybe have an option in the Removable devices systems setting for this.

[1] https://whoozle.github.io/android-file-transfer-linux/
[2] https://wiki.archlinux.org/title/Media_Transfer_Protocol#Android_File_Transfer
Comment 23 Dimchkin 2023-01-23 20:09:32 UTC
Manjaro KDE user here too and also experiencing annoyance that seems to be connected with KIO issue: inability to properly use MTP device (Android smartphone) with Double Commander.  (Whereas other managers like Krusader and Dolphin can access device fine)

I suspect, from our exchange with one of the doublecmd developers, that my MTP problem might be connected to OP's issue:
https://doublecmd.h1n.ru/viewtopic.php?p=38126#p38126
Quote "Looks like it is a conflict between GIO and KIO. On my system MTP works fine in DC under Xfce/LXQt but does not work under KDE. I guess only one system service can work with MTP at the same time."
Comment 24 Dennis Schridde 2023-07-24 07:04:35 UTC
(In reply to Norbert Preining from comment #2)
> Killing the kiod process that holds the lock (to be found with fuser
> /dev/libmtp...) resolves this problem, but is not optimal.

I do not have a `kiod` process on my system:
```
❯ ^ps aux | rg -i kio
 2156 USER  0:00 {.kioslave5-wrap} /nix/store/56k6avzd8fwihzdgaq8dhzmpzyca18qn-kio-5.106.0/libexec/kf5/kioslave5 /nix/store/r0nmigm87b3psl5n83jid51fpp3910pj-plasma-workspace-5.27.6/lib/qt-5.15.9/plugins/kf5/kio/desktop.so desktop  local:/run/user/1000/plasmashellQDMkBR.1.kioworker.socket
 2634 USER  0:00 {.kioslave5-wrap} /nix/store/56k6avzd8fwihzdgaq8dhzmpzyca18qn-kio-5.106.0/libexec/kf5/kioslave5 /nix/store/p3283shmkk8j6zk9rm6xcbqa8xvzmdwx-baloo-5.106.0/lib/qt-5.15.9/plugins/kf5/kio/tags.so tags  local:/run/user/1000/plasmashellZMjtuQ.2.kioworker.socket
```

And neither `lsof` nor `fuser` find a process that has the USB device opened:
```
❯ sudo lsof /dev/libmtp-9-1
❯ sudo lsof /dev/bus/usb/009/002
❯ sudo fuser /dev/libmtp-9-1
❯ sudo fuser /dev/bus/usb/009/002
```

I am on NixOS 23.05.20230721.6da4bc6:
```
Operating System: NixOS 23.05
KDE Plasma Version: 5.27.6
KDE Frameworks Version: 5.106.0
Qt Version: 5.15.9
Kernel Version: 6.4.4 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 9 6900HS with Radeon Graphics
Memory: 30,6 GiB of RAM
Graphics Processor: AMD Radeon Graphics
```

Do you have another idea how I could unblock the USB device?
Comment 25 Dennis Schridde 2023-07-24 07:16:21 UTC
(In reply to Dennis Schridde from comment #24)
> Do you have another idea how I could unblock the USB device?

This was after a reboot. It appears the device was not blocked by KDE yet. I was able to connect to it using Calibre and manage the ebooks stored on the device without much trouble.
Comment 26 Patrick Silva 2023-11-14 12:17:50 UTC
*** Bug 476986 has been marked as a duplicate of this bug. ***
Comment 27 gustavo.lapido 2024-06-03 13:38:20 UTC
Issue is still present.
I connect my Android phone, set it to FIle Transfer mode then I try to browse and download photos using Rapid Photo Downloader, which tells the device is locked by another program.
As others said, killing  kiod allows me to use it.
Comment 28 gustavo.lapido 2024-06-03 13:40:28 UTC
(In reply to gustavo.lapido from comment #27)
> Issue is still present.
> I connect my Android phone, set it to FIle Transfer mode then I try to
> browse and download photos using Rapid Photo Downloader, which tells the
> device is locked by another program.
> As others said, killing  kiod allows me to use it.

Forgot to show OS info:

Operating System: EndeavourOS 
KDE Plasma Version: 6.0.5
KDE Frameworks Version: 6.2.0
Qt Version: 6.7.1
Kernel Version: 6.6.32-1-lts (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 5800H with Radeon Graphics
Memory: 15,0 GiB of RAM
Graphics Processor: AMD Radeon Graphics
Manufacturer: Dell Inc.
Product Name: Dell G15 5515
System Version: 1.16.0
Comment 29 Houssem 2024-09-20 19:41:46 UTC
I am also encountering this issue when attempting to connect my book reader to Calibre 7.18
killing kio process works but is not an adequate workaround