LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 11-05-2023, 01:59 AM   #1
stoorky
Member
 
Registered: Sep 2015
Posts: 63

Rep: Reputation: Disabled
Modules "uas" or "usb_storage" still in use after USB drive has been unplugged


TLDR;
(see below, "The whole story", as for the reason this bothers me)
After a fresh start, module uas is used by nothing (0) :
Code:
$ lsmod | grep -e ^Module -e ^uas
Module                  Size  Used by
uas                    32768  0
If then I plug a USB drive, it's used by that drive (1) :
Code:
$ lsmod | grep -e ^Module -e ^uas
Module                  Size  Used by
uas                    32768  1
But after unmounting and unplugging that same USB drive, the uas module is still used by something (still 1), which prevents me of unloading that module, even using --force :
Code:
$ lsmod | grep -e ^Module -e ^uas
Module                  Size  Used by
uas                    32768  1

$ sudo modprobe --remove --force uas
modprobe: FATAL: Module uas is in use.
Why is that ? How can I unload the uas module ?

THE WHOLE STORY
I have a Seagate USB drive. Those USB drives are known for not being able to retrieve SMART data on Linux, due to some compatibility problems with Linux's implementation of the UAS protocol (for more infos, see https://www.smartmontools.org/ticket/971).

The drive works fine though with UAS, it's just the SMART infos that can not be retrieved.
An easy workaround is to disable UAS for that specific drive, and so to fall back to the older USB mass storage protocol. Obviously I don't want to do that on a permanent basis, because UAS is much faster than the previous protocol (see https://en.wikipedia.org/wiki/USB_Attached_SCSI). Given that I only need to check my SMART data once in a while, the solution would be to disable UAS only when I need to retrieve SMART data, which is only once in a while, and to keep using UAS the rest of the time. Doing that should be straightforward :
  • unplug all USB drives
  • unload uas and usb_storage modules
  • load usb_storage with a quirk (ignore that specific Seagate USB drive)
  • plug in that Seagate drive
  • retrieve SMART data
  • unplug the drive
  • unload usb_storage
  • reload usb_storage (without the quirk)
  • plug in the drive again (which will use UAS again), and go on with my life
But, like I mentioned in the first section of this post, once the drive has been plugged in and then unmounted and plugged out, I'm unable to unload the uas module. Note that I checked that --force unload is supported :
Code:
$ grep CONFIG_MODULE_FORCE_UNLOAD /boot/config-`uname -r`
CONFIG_MODULE_FORCE_UNLOAD=y
The only workaround I am left with at this point is to reboot my computer, unload the uas module before it has ever been used, and then reload the usb_storage module with the aforementioned quirk. In other words, if I want to check the SMART data of my Seagate drive I need to reboot the computer. It works, but it's cumbersome (and as you can see below, it requires not one but two reboots).
Code:
$ sudo modprobe --remove uas
$ lsmod | grep uas
$ lsmod | grep usb_storage

$ sudo modprobe usb-storage quirks=0bc2:ab28:u
I then :
  • plug in the drive
  • check SMART data
  • unplug the drive
At this point, to be able to use the drive again with UAS, I try to remove the usb_storage module. But same thing, it refuses to do so, because it's still used by something :
Code:
$ sudo modprobe --remove --force usb_storage
modprobe: FATAL: Module usb_storage is in use.

$ lsmod | grep -e ^Module -e ^usb_storage
Module                  Size  Used by
usb_storage            81920  2 uas

$ sudo modprobe --remove uas

$ lsmod | grep -e ^Module -e ^usb_storage
Module                  Size  Used by
usb_storage            81920  1

$ sudo modprobe --remove --force usb_storage 
modprobe: FATAL: Module usb_storage is in use.
So at this point I need to reboot once more, in order to be able to use my Seagate drive with the UAS module again.

Any idea why those modules (both uas and usb_storage) seem still in use after all USB drives have been unplugged ?

[EDIT]
I am using kernel 5.10, on Debian 11 :
Code:
$ cat /etc/debian_version 
11.6
$ uname -a
Linux hostname 5.10.0-21-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21) x86_64 GNU/Linux

Last edited by stoorky; 11-05-2023 at 04:56 AM.
 
Old 11-05-2023, 08:41 PM   #2
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 1,967

Rep: Reputation: 271Reputation: 271Reputation: 271
/boot/config- is a promise; /proc/config.gz is a report.

Does rmmod -f work?

I've had similar problems that I get around by unloading all the modules that use USB. I wrote a script, usbunload, and another, usbload, to reload them. This can be a drag if the only keyboard is USB. I wrote a similar pair of scripts for all my audio modules.

Last edited by RandomTroll; 11-06-2023 at 12:24 AM. Reason: More.
 
1 members found this post helpful.
Old 11-06-2023, 04:20 AM   #3
stoorky
Member
 
Registered: Sep 2015
Posts: 63

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by RandomTroll View Post
Does rmmod -f work?
YES !
Great, thanks. I forgot about rmmod ! Seems to be more powerfull than modprobe -r :
Code:
$ lsmod | grep -e ^Module -e ^uas
Module                  Size  Used by
uas                    32768  1

$ sudo modprobe --remove --force uas
modprobe: FATAL: Module uas is in use.

$ sudo rmmod -f uas

$ lsmod | grep -e ^Module -e ^uas
Module                  Size  Used by
 
  


Reply

Tags
module, usb drive



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
USB drive controller connects as usb-storage rather than uas bubbagump Linux - Hardware 13 03-18-2021 09:55 PM
USB Storage and UAS kgoosie 4MLinux 4 09-30-2018 12:14 PM
[SOLVED] Kernel panic - LFS Not recognizing UAS device cellsheet Linux From Scratch 7 11-08-2016 11:52 AM
UAS driver on USB 2.0 Hardware? DiskChris Linux - Hardware 1 12-22-2012 01:07 PM
Can't unmount after I unplugged usb drive on accident xmrkite Linux - Software 2 10-26-2010 11:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 05:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration