2006-12-03 11:21:07

by Tomasz Chmielewski

[permalink] [raw]
Subject: why can't I remove a kernel module (or: what uses a given module)?

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)?


--
Tomasz Chmielewski
http://wpkg.org


2006-12-03 11:34:39

by Andreas Schwab

[permalink] [raw]
Subject: Re: why can't I remove a kernel module (or: what uses a given module)?

Tomasz Chmielewski <[email protected]> writes:

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

Check lsmod for modules depending on this one.

Andreas.

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

2006-12-03 11:58:42

by Tomasz Chmielewski

[permalink] [raw]
Subject: Re: why can't I remove a kernel module (or: what uses a given module)?

Andreas Schwab wrote:
> Tomasz Chmielewski <[email protected]> writes:
>
>> 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*?


--
Tomasz Chmielewski
http://wpkg.org

2006-12-03 15:50:30

by Ross Vandegrift

[permalink] [raw]
Subject: Re: why can't I remove a kernel module (or: what uses a given module)?

On Sun, Dec 03, 2006 at 12:58:24PM +0100, Tomasz Chmielewski wrote:
> 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.

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

2006-12-03 19:59:33

by Tomasz Chmielewski

[permalink] [raw]
Subject: Re: why can't I remove a kernel module (or: what uses a given module)?

Ross Vandegrift wrote:
> On Sun, Dec 03, 2006 at 12:58:24PM +0100, Tomasz Chmielewski wrote:
>> 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?


--
Tomasz Chmielewski
http://wpkg.org

2006-12-03 23:42:34

by Jim Crilly

[permalink] [raw]
Subject: Re: why can't I remove a kernel module (or: what uses a given module)?

On 12/03/06 08:59:10PM +0100, Tomasz Chmielewski wrote:
> Ross Vandegrift wrote:
> >On Sun, Dec 03, 2006 at 12:58:24PM +0100, Tomasz Chmielewski wrote:
> >>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?
>

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.

2006-12-04 08:02:45

by Tomasz Chmielewski

[permalink] [raw]
Subject: Re: why can't I remove a kernel module (or: what uses a given module)?

Jim Crilly wrote:
> On 12/03/06 08:59:10PM +0100, Tomasz Chmielewski wrote:
>> Ross Vandegrift wrote:
>>> On Sun, Dec 03, 2006 at 12:58:24PM +0100, Tomasz Chmielewski wrote:
>>>> 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?
>>
>
> 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.


--
Tomasz Chmielewski
http://wpkg.org

2006-12-04 10:15:09

by Tobias Oed

[permalink] [raw]
Subject: Re: why can't I remove a kernel module (or: what uses a given module)?

Tomasz Chmielewski wrote:

> Ross Vandegrift wrote:
>> On Sun, Dec 03, 2006 at 12:58:24PM +0100, Tomasz Chmielewski wrote:
>>> 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?

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



2006-12-04 10:40:10

by Tomasz Chmielewski

[permalink] [raw]
Subject: Re: why can't I remove a kernel module (or: what uses a given module)?

Tobias Oed wrote:
> Tomasz Chmielewski wrote:
>
>> Ross Vandegrift wrote:
>>> On Sun, Dec 03, 2006 at 12:58:24PM +0100, Tomasz Chmielewski wrote:
>>>> 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?
>
> 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!


--
Tomasz Chmielewski
http://wpkg.org


2006-12-05 00:15:21

by Michal Jaegermann

[permalink] [raw]
Subject: Re: why can't I remove a kernel module (or: what uses a given module)?

On Mon, Dec 04, 2006 at 11:10:01AM +0100, Tobias Oed wrote:
> Tomasz Chmielewski wrote:
>
> > 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