Skip to contentSkip to conversation

why can't I remove a kernel module (or: what uses a given module)?

DISCUSSION Tomasz Chmielewski 6 participants 10 messages Dec 3, 2006 – Dec 5, 2006

lore
Share & tools
lore
#0 lore raw

There is something I don't understand about loading and unloading kernel modules.

I have a SATA controller, it uses a sata_mv driver.
The drive connected to it is not used; it just "merely exists" - no one touches it. This is why I don't understand why I can't remove such a module:

1.

# rmmod sata_mv
ERROR: Module sata_mv is in use

The module was loaded automatically during the system boot.

mount claims no /dev/sda* partition is mounted.

2.

In a second scenario, I move the kernel:

# mv /lib/modules/2.6.19/kernel/drivers/ata/sata_mv.ko /root
# reboot

And load it later manually:

# insmod ./sata_mv
# dmesg -c
sata_mv 0000:01:00.0: version 0.7
ACPI: PCI Interrupt 0000:01:00.0[A] -> GSI 20 (level, low) -> IRQ 23
(...)
SCSI device sda: drive cache: write back
 sda: sda1
sd 24:0:0:0: Attached scsi disk sda

We can remove the module without problems:

# rmmod sata_mv
# dmesg -c
Synchronizing SCSI cache for disk sda:
ACPI: PCI interrupt for device 0000:01:00.0 disabled

Now I could remove the module without problems.

What was using the module in the first scenario (I couldn't remove the module)?

Signature · 2 lines
Tomasz Chmielewski
http://wpkg.org
#1 lore raw
Quoted 2 lines · Tomasz Chmielewski

What was using the module in the first scenario (I couldn't remove the module)?

Check lsmod for modules depending on this one.

Andreas.

Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#2 lore raw
Quoted 6 lines · Andreas Schwab
Quoted 2 lines · Tomasz Chmielewski

What was using the module in the first scenario (I couldn't remove the module)?

Check lsmod for modules depending on this one.

You mean the "Used by" column? No, it's not used by any other module according to lsmod output.

Any other methods of checking what uses /dev/sda*?

Signature · 2 lines
Tomasz Chmielewski
http://wpkg.org
#3 lore raw
Quoted 4 lines · Tomasz Chmielewski

You mean the "Used by" column? No, it's not used by any other module according to lsmod output.

Any other methods of checking what uses /dev/sda*?

There's a good chance that if it was loaded at system boot, hald or udev may be doing something with it.

When you loaded it manually, you didn't have udev rescan for devices so they didn't notice that you had loaded up a new disk.

Signature · 8 lines
Ross Vandegrift
[email protected]

"The good Christian should beware of mathematicians, and all those who
make empty prophecies. The danger already exists that the mathematicians
have made a covenant with the devil to darken the spirit and to confine
man in the bonds of Hell."
	--St. Augustine, De Genesi ad Litteram, Book II, xviii, 37
#4 lore raw
Quoted 7 lines · Ross Vandegrift
Quoted 3 lines · Tomasz Chmielewski

You mean the "Used by" column? No, it's not used by any other module according to lsmod output.

Any other methods of checking what uses /dev/sda*?

There's a good chance that if it was loaded at system boot, hald or udev may be doing something with it.

This machine doesn't have hal; when I kill udevd still doesn't help.

Yes, something's using that drive, be it a program, a module (unlikely), or something that is compiled directly in the kernel (for example, md/raid1). But what is it?

Kernel knows it, as it refuses to remove the module (via rmmod), but how to tell kernel to share this knowledge with me?

Signature · 2 lines
Tomasz Chmielewski
http://wpkg.org
#5 lore raw
Quoted 12 lines · Tomasz Chmielewski
Quoted 8 lines · Ross Vandegrift
Quoted 4 lines · Tomasz Chmielewski

You mean the "Used by" column? No, it's not used by any other module according to lsmod output.

Any other methods of checking what uses /dev/sda*?

There's a good chance that if it was loaded at system boot, hald or udev may be doing something with it.

This machine doesn't have hal; when I kill udevd still doesn't help.

Quoted 8 lines

Yes, something's using that drive, be it a program, a module (unlikely), or something that is compiled directly in the kernel (for example, md/raid1).
But what is it?

Kernel knows it, as it refuses to remove the module (via rmmod), but how to tell kernel to share this knowledge with me?

Have you checked to make sure there's no swap partitions on it being automatically activated at boot? Also, have you checked the output of lsof?

Jim.

#6 lore raw
Quoted 10 lines · Jim Crilly
Quoted 9 lines · Tomasz Chmielewski
Quoted 6 lines · Ross Vandegrift
Quoted 3 lines · Tomasz Chmielewski

You mean the "Used by" column? No, it's not used by any other module according to lsmod output.

Any other methods of checking what uses /dev/sda*?

There's a good chance that if it was loaded at system boot, hald or udev may be doing something with it.

This machine doesn't have hal; when I kill udevd still doesn't help.

Quoted 8 lines
Quoted 5 lines

Yes, something's using that drive, be it a program, a module (unlikely), or something that is compiled directly in the kernel (for example, md/raid1). But what is it?

Kernel knows it, as it refuses to remove the module (via rmmod), but how to tell kernel to share this knowledge with me?

Have you checked to make sure there's no swap partitions on it being automatically activated at boot? Also, have you checked the output of lsof?

The machine doesn't even have swap, so no, no swap on that device (confirmed by th output of free with 0 swap). The device doesn't also show up in /etc/fstab.

And "lsof -n | grep sd" doesn't show anything.

Signature · 2 lines
Tomasz Chmielewski
http://wpkg.org
#7 lore raw
In reply to Tomasz Chmielewski
Quoted 10 lines · Tomasz Chmielewski
Quoted 8 lines · Ross Vandegrift
Quoted 4 lines · Tomasz Chmielewski

You mean the "Used by" column? No, it's not used by any other module according to lsmod output.

Any other methods of checking what uses /dev/sda*?

There's a good chance that if it was loaded at system boot, hald or udev may be doing something with it.

Quoted 6 lines

This machine doesn't have hal; when I kill udevd still doesn't help.

Yes, something's using that drive, be it a program, a module (unlikely), or something that is compiled directly in the kernel (for example, md/raid1).
But what is it?

Since you mention md, dm comes to mind. I have seen a couple of drives that were previously attached to fake raid controllers becoming unavailable when moved to a normal controller. I haven't found the one size workaround for the problem yet. Can you check
/sys/block/sda/holders ?
Also /sys/bus/ide/whoevertheholderis/[bind|unbind] are 'curious' but I'm not sure how one is supposed to use them.
Tobias

#8 lore raw
Quoted 17 lines · Tobias Oed
Quoted 6 lines · Tomasz Chmielewski
Quoted 5 lines · Ross Vandegrift
Quoted 4 lines · Tomasz Chmielewski

You mean the "Used by" column? No, it's not used by any other module according to lsmod output.

Any other methods of checking what uses /dev/sda*?

Quoted 8 lines
Quoted 2 lines

There's a good chance that if it was loaded at system boot, hald or udev may be doing something with it.

This machine doesn't have hal; when I kill udevd still doesn't help.

Yes, something's using that drive, be it a program, a module (unlikely), or something that is compiled directly in the kernel (for example, md/raid1).
But what is it?

Quoted 5 lines

Since you mention md, dm comes to mind. I have seen a couple of drives that were previously attached to fake raid controllers becoming unavailable when moved to a normal controller. I haven't found the one size workaround for the problem yet. Can you check
/sys/block/sda/holders ?

Yes, that was the right answer.
On a system with sata_mv (machine_1) I indeed had RAID, and that's why I suspected I couldn't remove the module. It was confirmed by checking /sys/block/sda/sda1/holders:

# ls /sys/block/sda/sda1/holders
md0@

On yet another system (machine_2), with sata_via module, I didn't set up RAID, but still, I couldn't remove the module. Inspecting /sys/block/sda/sda1/holders revealed why:

# ls /sys/block/sda/sda1/holders
dm-0@  dm-1@  dm-2@

The drive was taken from the machine_1; it had LVM2 on it.

Thanks!

Signature · 2 lines
Tomasz Chmielewski
http://wpkg.org
#9 lore raw
In reply to Tobias Oed
Quoted 10 lines · Tobias Oed
Quoted 3 lines · Tomasz Chmielewski

Yes, something's using that drive, be it a program, a module (unlikely), or something that is compiled directly in the kernel (for example, md/raid1).

Since you mention md, dm comes to mind. I have seen a couple of drives that were previously attached to fake raid controllers becoming unavailable when moved to a normal controller. I haven't found the one size workaround for the problem yet.

dmraid -r -E <device_in_question>

Yes, I was hit by this in a different context. A command is described on 'man dmraid' but figuring out what was the issue took me a long while.

Michal