LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Modules "uas" or "usb_storage" still in use after USB drive has been unplugged (https://www.linuxquestions.org/questions/linux-kernel-70/modules-uas-or-usb_storage-still-in-use-after-usb-drive-has-been-unplugged-4175730592/)

stoorky 11-05-2023 01:59 AM

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


RandomTroll 11-05-2023 08:41 PM

/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.

stoorky 11-06-2023 04:20 AM

Quote:

Originally Posted by RandomTroll (Post 6463095)
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



All times are GMT -5. The time now is 09:55 AM.