* SCSI host numbers?
@ 2002-01-02 1:19 Itai Nahshon
2002-01-02 11:32 ` Alan Cox
0 siblings, 1 reply; 13+ messages in thread
From: Itai Nahshon @ 2002-01-02 1:19 UTC (permalink / raw)
To: linux-kernel
Hello,
Under some scenarios Linux assigns the same
host_no to more than one scsi device.
Can someone tell me what is the intended behavior?
The problem is that a newly registered device gets
its host_no from max_scsi_host. max_scsi_host is
decremented when a device driver is unregistered
(see drivers/scsi/host.c) allowing a second new
host to reuse the same host_no.
A device that was already in use (but the module
was unloaded and reloaded gets its old host_no that
was kept in scsi_host_no_list. host_id's in scsi_host_no_list
can also be reserved at boot time (though I never tried that).
This rarely happens except when there are two or more
dynamic scsi hosts (I had i with ide-scsi and usb-storage).
I could mount devices even when they were on conflicting
host numbers (/dev/sda on usb-storage and /dev/scd0
on ide-scsi). I could access only one of the devices
via the generic-scsi interface (/dev/sgX). I do not know
what other things can get broken if scsi host get conflicting
host id.
This was tried on linux-2.4.9 (RedHat). I looked at newer
kernels but did not see an obvious fix.
Similar bug reported also to redhat. See:
http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=55876
Thanks,
-- Itai
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: SCSI host numbers?
[not found] <mailman.1009934881.4099.linux-kernel2news@redhat.com>
@ 2002-01-02 2:07 ` Pete Zaitcev
0 siblings, 0 replies; 13+ messages in thread
From: Pete Zaitcev @ 2002-01-02 2:07 UTC (permalink / raw)
To: nahshon, linux-kernel
> Under some scenarios Linux assigns the same
> host_no to more than one scsi device.
> Similar bug reported also to redhat. See:
> http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=55876
Curious, I'll look into it.
-- Pete
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: SCSI host numbers?
2002-01-02 1:19 Itai Nahshon
@ 2002-01-02 11:32 ` Alan Cox
2002-01-02 19:31 ` Richard Gooch
2002-01-02 23:35 ` Itai Nahshon
0 siblings, 2 replies; 13+ messages in thread
From: Alan Cox @ 2002-01-02 11:32 UTC (permalink / raw)
To: nahshon; +Cc: linux-kernel
> Under some scenarios Linux assigns the same
> host_no to more than one scsi device.
>
> Can someone tell me what is the intended behavior?
A number should never be reissued.
> The problem is that a newly registered device gets
> its host_no from max_scsi_host. max_scsi_host is
> decremented when a device driver is unregistered
> (see drivers/scsi/host.c) allowing a second new
> host to reuse the same host_no.
I guess it needs to either only decrement the count if we are the highest one
(trivial hack) or scan for a free number/keep a free bitmap. The devfs code
has a handy little unique_id function for that
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: SCSI host numbers?
2002-01-02 11:32 ` Alan Cox
@ 2002-01-02 19:31 ` Richard Gooch
2002-01-02 21:01 ` Alan Cox
2002-01-02 23:35 ` Itai Nahshon
1 sibling, 1 reply; 13+ messages in thread
From: Richard Gooch @ 2002-01-02 19:31 UTC (permalink / raw)
To: Alan Cox; +Cc: nahshon, linux-kernel
Alan Cox writes:
> > Under some scenarios Linux assigns the same
> > host_no to more than one scsi device.
> >
> > Can someone tell me what is the intended behavior?
>
> A number should never be reissued.
>
> > The problem is that a newly registered device gets
> > its host_no from max_scsi_host. max_scsi_host is
> > decremented when a device driver is unregistered
> > (see drivers/scsi/host.c) allowing a second new
> > host to reuse the same host_no.
>
> I guess it needs to either only decrement the count if we are the
> highest one (trivial hack) or scan for a free number/keep a free
> bitmap. The devfs code has a handy little unique_id function for
> that
Yeah, I was going to get around to submitting a patch to change the
SCSI host allocation code to use devfs_alloc_unique_number(), but
right now that function is only functional if CONFIG_DEVFS_FS=y
(otherwise you get a stub function which returns -1). So really this
should be turned into a generic function, which was my plan all along,
but I didn't want to fight that battle back then. Now that it's in
the tree, I can look at doing this.
Comments? Got a suggestion for which file the generic function should
go into? I figure on stripping the leading "devfs_" part of the
function names.
Regards,
Richard....
Permanent: rgooch@atnf.csiro.au
Current: rgooch@ras.ucalgary.ca
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: SCSI host numbers?
2002-01-02 19:31 ` Richard Gooch
@ 2002-01-02 21:01 ` Alan Cox
2002-01-02 21:18 ` Richard Gooch
0 siblings, 1 reply; 13+ messages in thread
From: Alan Cox @ 2002-01-02 21:01 UTC (permalink / raw)
To: Richard Gooch; +Cc: Alan Cox, nahshon, linux-kernel
> Comments? Got a suggestion for which file the generic function should
> go into? I figure on stripping the leading "devfs_" part of the
> function names.
Sounds sensible to me. I guess it belongs in lib/ somewhere ?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: SCSI host numbers?
2002-01-02 21:01 ` Alan Cox
@ 2002-01-02 21:18 ` Richard Gooch
0 siblings, 0 replies; 13+ messages in thread
From: Richard Gooch @ 2002-01-02 21:18 UTC (permalink / raw)
To: Alan Cox; +Cc: nahshon, linux-kernel
Alan Cox writes:
> > Comments? Got a suggestion for which file the generic function should
> > go into? I figure on stripping the leading "devfs_" part of the
> > function names.
>
> Sounds sensible to me. I guess it belongs in lib/ somewhere ?
I was thinking perhaps lib/unique.c
Regards,
Richard....
Permanent: rgooch@atnf.csiro.au
Current: rgooch@ras.ucalgary.ca
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: SCSI host numbers?
2002-01-02 11:32 ` Alan Cox
2002-01-02 19:31 ` Richard Gooch
@ 2002-01-02 23:35 ` Itai Nahshon
2002-01-06 1:44 ` Richard Gooch
1 sibling, 1 reply; 13+ messages in thread
From: Itai Nahshon @ 2002-01-02 23:35 UTC (permalink / raw)
To: Alan Cox, Richard Gooch; +Cc: linux-kernel
On Wednesday 02 January 2002 01:32 pm, Alan Cox wrote:
> > Under some scenarios Linux assigns the same
> > host_no to more than one scsi device.
> >
> > Can someone tell me what is the intended behavior?
>
> A number should never be reissued.
>
> > The problem is that a newly registered device gets
> > its host_no from max_scsi_host. max_scsi_host is
> > decremented when a device driver is unregistered
> > (see drivers/scsi/host.c) allowing a second new
> > host to reuse the same host_no.
>
> I guess it needs to either only decrement the count if we are the highest
I'll argue that it should never decrement. The host that was just
unregisrtered already has its host_id reserved and if we decrement,
this number will be reasigned to the next new scsi host.
Unless if the code for reservation that causes the conflicts
is removed (but I guess it has a reason).
> one (trivial hack) or scan for a free number/keep a free bitmap. The devfs
> code has a handy little unique_id function for that
That would not solve it. The problem is that one piece of code
tries to allocate unique numbers (and get them back to the pool
when they are not in use), another piece of code remembers the
old number that a scsi host had and whan it re-registers gives
it back its old host_no regardless if this number was re-assigned
to a new host.
Is there a function that given a string returns a unique number
for this string? That would do the job.
-- Itai
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: SCSI host numbers?
2002-01-02 23:35 ` Itai Nahshon
@ 2002-01-06 1:44 ` Richard Gooch
2002-01-13 20:41 ` Itai Nahshon
0 siblings, 1 reply; 13+ messages in thread
From: Richard Gooch @ 2002-01-06 1:44 UTC (permalink / raw)
To: nahshon; +Cc: Alan Cox, linux-kernel
Itai Nahshon writes:
> On Wednesday 02 January 2002 01:32 pm, Alan Cox wrote:
> > > Under some scenarios Linux assigns the same
> > > host_no to more than one scsi device.
> > >
> > > Can someone tell me what is the intended behavior?
> >
> > A number should never be reissued.
> >
> > > The problem is that a newly registered device gets
> > > its host_no from max_scsi_host. max_scsi_host is
> > > decremented when a device driver is unregistered
> > > (see drivers/scsi/host.c) allowing a second new
> > > host to reuse the same host_no.
> >
> > I guess it needs to either only decrement the count if we are the highest
>
> I'll argue that it should never decrement. The host that was just
> unregisrtered already has its host_id reserved and if we decrement,
> this number will be reasigned to the next new scsi host.
>
> Unless if the code for reservation that causes the conflicts
> is removed (but I guess it has a reason).
>
> > one (trivial hack) or scan for a free number/keep a free bitmap. The devfs
> > code has a handy little unique_id function for that
>
> That would not solve it. The problem is that one piece of code
> tries to allocate unique numbers (and get them back to the pool
> when they are not in use), another piece of code remembers the
> old number that a scsi host had and whan it re-registers gives
> it back its old host_no regardless if this number was re-assigned
> to a new host.
Where exactly is the host_id for an unregistered host being
remembered?
Regards,
Richard....
Permanent: rgooch@atnf.csiro.au
Current: rgooch@ras.ucalgary.ca
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: SCSI host numbers?
2002-01-06 1:44 ` Richard Gooch
@ 2002-01-13 20:41 ` Itai Nahshon
2002-01-14 6:36 ` Richard Gooch
0 siblings, 1 reply; 13+ messages in thread
From: Itai Nahshon @ 2002-01-13 20:41 UTC (permalink / raw)
To: Richard Gooch; +Cc: Alan Cox, linux-kernel
On Sunday 06 January 2002 03:44 am, Richard Gooch wrote:
> Where exactly is the host_id for an unregistered host being
> remembered?
Sorry for the late reply. I was away from Email for the whole week.
Scsi host numbers (for both regstered and unregistered hosts)
are preserved in scsi_host_no_list.
The list is used in the function scsi_register (in drivers/scsi/hosts.c).
Same function also adds new hosts to the list.
The list can be initialized (from boot parameters ?) by
the function scsi_host_no_init (drivers/scsi/scsi.c).
-- Itai
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: SCSI host numbers?
2002-01-13 20:41 ` Itai Nahshon
@ 2002-01-14 6:36 ` Richard Gooch
2002-01-15 12:19 ` Itai Nahshon
0 siblings, 1 reply; 13+ messages in thread
From: Richard Gooch @ 2002-01-14 6:36 UTC (permalink / raw)
To: nahshon; +Cc: Alan Cox, linux-kernel
Itai Nahshon writes:
> On Sunday 06 January 2002 03:44 am, Richard Gooch wrote:
> > Where exactly is the host_id for an unregistered host being
> > remembered?
>
> Sorry for the late reply. I was away from Email for the whole week.
>
> Scsi host numbers (for both regstered and unregistered hosts)
> are preserved in scsi_host_no_list.
>
> The list is used in the function scsi_register (in drivers/scsi/hosts.c).
> Same function also adds new hosts to the list.
>
> The list can be initialized (from boot parameters ?) by
> the function scsi_host_no_init (drivers/scsi/scsi.c).
Ah, yes. That was a patch someone sent to me years ago, and got
included in the jumbo devfs patch. There's a boot parameter which
allows you to control the allocation of host numbers.
So how about in scsi_host_no_init() we call alloc_unique_number() N
times until we've allocated the required number of host numbers for
manual control. These will never be freed. Then all other host
allocations can be done dynamically. We would just need a flag in the
host structure to disable deallocation of the number if it's one of
the reserved numbers.
Regards,
Richard....
Permanent: rgooch@atnf.csiro.au
Current: rgooch@ras.ucalgary.ca
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: SCSI host numbers?
2002-01-14 6:36 ` Richard Gooch
@ 2002-01-15 12:19 ` Itai Nahshon
2002-01-16 7:03 ` Richard Gooch
0 siblings, 1 reply; 13+ messages in thread
From: Itai Nahshon @ 2002-01-15 12:19 UTC (permalink / raw)
To: Richard Gooch; +Cc: Alan Cox, linux-kernel
On Monday 14 January 2002 08:36 am, Richard Gooch wrote:
> So how about in scsi_host_no_init() we call alloc_unique_number() N
> times until we've allocated the required number of host numbers for
> manual control. These will never be freed. Then all other host
> allocations can be done dynamically. We would just need a flag in the
> host structure to disable deallocation of the number if it's one of
> the reserved numbers.
See that dynamic hosts are also added to the list and *never* removed
from it (even when the host is unregistered). With that behaviour your
unique number functions would be an overkill because we must never
free host nubers.
I suggest these changes:
max_scsi_host initialized in scsi_host_no_init.
max_scsi_host never decremented.
That would fix the problem that I reported.
Than (cosmetic):
rename next_scsi_host to count_scsi_hosts (or num_scsi_hosts)
because it actually just counts the number of registered scsi hosts.
The current name for that variable is confusing...
-- Itai
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: SCSI host numbers?
2002-01-15 12:19 ` Itai Nahshon
@ 2002-01-16 7:03 ` Richard Gooch
2002-01-16 9:47 ` Itai Nahshon
0 siblings, 1 reply; 13+ messages in thread
From: Richard Gooch @ 2002-01-16 7:03 UTC (permalink / raw)
To: nahshon; +Cc: Alan Cox, linux-kernel
Itai Nahshon writes:
> On Monday 14 January 2002 08:36 am, Richard Gooch wrote:
> > So how about in scsi_host_no_init() we call alloc_unique_number() N
> > times until we've allocated the required number of host numbers for
> > manual control. These will never be freed. Then all other host
> > allocations can be done dynamically. We would just need a flag in the
> > host structure to disable deallocation of the number if it's one of
> > the reserved numbers.
>
> See that dynamic hosts are also added to the list and *never* removed
> from it (even when the host is unregistered). With that behaviour your
> unique number functions would be an overkill because we must never
> free host nubers.
>
> I suggest these changes:
> max_scsi_host initialized in scsi_host_no_init.
> max_scsi_host never decremented.
> That would fix the problem that I reported.
But if you load, unload and reload a host driver, and it's not listed
in scsihosts=, then won't it get a different host number each time?
Regards,
Richard....
Permanent: rgooch@atnf.csiro.au
Current: rgooch@ras.ucalgary.ca
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: SCSI host numbers?
2002-01-16 7:03 ` Richard Gooch
@ 2002-01-16 9:47 ` Itai Nahshon
0 siblings, 0 replies; 13+ messages in thread
From: Itai Nahshon @ 2002-01-16 9:47 UTC (permalink / raw)
To: Richard Gooch; +Cc: Alan Cox, linux-kernel
On Wednesday 16 January 2002 09:03 am, Richard Gooch wrote:
> But if you load, unload and reload a host driver, and it's not listed
> in scsihosts=, then won't it get a different host number each time?
In the fist time that it registers it is added to scsi_host_no_list
(see code under "if (flag_new) {" in scsi/host.c).
Than it will get the same number again every time.
scsi_host_no_list is discarded only when scsi_mod
gets unloaded (that is if compiled as module).
-- Itai
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2002-01-16 9:48 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.1009934881.4099.linux-kernel2news@redhat.com>
2002-01-02 2:07 ` SCSI host numbers? Pete Zaitcev
2002-01-02 1:19 Itai Nahshon
2002-01-02 11:32 ` Alan Cox
2002-01-02 19:31 ` Richard Gooch
2002-01-02 21:01 ` Alan Cox
2002-01-02 21:18 ` Richard Gooch
2002-01-02 23:35 ` Itai Nahshon
2002-01-06 1:44 ` Richard Gooch
2002-01-13 20:41 ` Itai Nahshon
2002-01-14 6:36 ` Richard Gooch
2002-01-15 12:19 ` Itai Nahshon
2002-01-16 7:03 ` Richard Gooch
2002-01-16 9:47 ` Itai Nahshon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox