----- Original Message -----
From: "Matthew Dharm" <[EMAIL PROTECTED]>
To: "The Linux SCSI list" <[EMAIL PROTECTED]>
Sent: Friday, February 11, 2000 6:08 PM
Subject: determining 'busy' status, and removing devices


> I'm working on USB Mass Storage devices (which appears to the system as a
> SCSI host), and I've run across an interesting two questions:
>
> (o) How do I determine if a device is 'busy'?  That is, if it's mounted or
>     otherwise being accessed?

    Well it depends on how you define busy.  The mid-level keeps track of
usage mainly in terms of how many outstanding commands are out there.  It
tends not to track number of mounts or number of open descriptors.

    The module related code sort of tracks this, but it is tracking usage in
sd_open() and sd_release() (look for __MOD_INC_USE_COUNT and
__MOD_DEC_USE_COUNT).  This probably doesn't have the right granularity -
these usage counts are intended only so that we can know that it is safe to
unload a module.

    If you are concerned with usage counts so that you can track when it is
safe to unload a driver, then you needn't worry.  The usage counting in
sd.c/sr.c/sg.c and st.c should ensure that the usage count is non-zero if
there are open descriptors.

    There is one flaw in the current modules code that we all use, however.
There isn't a way for a module to refuse to allow itself to be unloaded.
There is an assumption that the module related usage counts will correctly
prevent a module from being unloaded when it is actually busy, but from the
point in rmmod where this is checked to the point where cleanup_module is
called a small interval of time has elapsed, and it is theoretically
possible that the module has become busy again.  By the time you get to
cleanup_module, your options aren't good.

> (o) How well does the code to handle adding and removing SCSI devices
>     work?  I know it's possible to add hosts easily (which is the current
>     strategy), but what about removing hosts?  Removing devices?  What are
>     the constraints on these operations?

    Removing hosts also works fairly well.  The usage counts I mentioned
above should protect against a host being removed when busy, and in addition
there are some checks in there which are used when we first start trying to
unload.  There might be some race conditions in there now that I think about
it, but those should be pretty rare.  Someday someone needs to go through
this with a fine tooth comb and and sanitize the thing.

    Adding/removing devices using the /proc interface is a bit more of a
kluge.  It works, but there are probably a few more race conditions for this
sort of thing.  This is another one of those things someone needs to clean
up someday.

    In general the race conditions should only come into play when if you
were fast and furiously adding and removing modules.  Normal usage of other
devices shouldn't be cause for any concern.

-Eric



-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]

Reply via email to