From: Andrew Morton <akpm@osdl.org>
To: Mike Anderson <andmike@us.ibm.com>
Cc: bcollins@debian.org, James.Bottomley@steeleye.com,
linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org
Subject: Re: [BK PATCH] SCSI host num allocation improvement
Date: Fri, 27 Feb 2004 14:30:33 -0800 [thread overview]
Message-ID: <20040227143033.731e20df.akpm@osdl.org> (raw)
In-Reply-To: <20040227163341.GB1424@beaverton.ibm.com>
Mike Anderson <andmike@us.ibm.com> wrote:
>
> Ben Collins [bcollins@debian.org] wrote:
> > static void scsi_host_cls_release(struct class_device *class_dev)
> > {
> > + down(&host_num_lock);
> > + idr_remove(&allocated_hosts, class_to_shost(class_dev)->host_no);
> > + up(&host_num_lock);
> > put_device(&class_to_shost(class_dev)->shost_gendev);
> > }
> >
>
> Should the idr_remove be done in scsi_host_dev_release instead? We
> really should not make this number available until everyone is done with
> this host.
Beats me. If you're right, this is the patch.
diff -puN drivers/scsi/hosts.c~scsi-host-allocation-fix drivers/scsi/hosts.c
--- 25/drivers/scsi/hosts.c~scsi-host-allocation-fix Fri Feb 27 14:11:47 2004
+++ 25-akpm/drivers/scsi/hosts.c Fri Feb 27 14:29:01 2004
@@ -30,6 +30,7 @@
#include <linux/list.h>
#include <linux/completion.h>
#include <linux/unistd.h>
+#include <linux/idr.h>
#include <scsi/scsi_host.h>
#include "scsi.h"
@@ -37,9 +38,26 @@
#include "scsi_priv.h"
#include "scsi_logging.h"
+static DECLARE_MUTEX(host_num_lock);
+static struct idr allocated_hosts;
-static int scsi_host_next_hn; /* host_no for next new host */
+static int alloc_host_no(void)
+{
+ int ret = -ENOMEM;
+
+ down(&host_num_lock);
+ if (idr_pre_get(&allocated_hosts, GFP_KERNEL))
+ ret = idr_get_new(&allocated_hosts, NULL);
+ up(&host_num_lock);
+ return ret;
+}
+static void free_host_no(int host_no)
+{
+ down(&host_num_lock);
+ idr_remove(&allocated_hosts, host_no);
+ up(&host_num_lock);
+}
static void scsi_host_cls_release(struct class_device *class_dev)
{
@@ -163,9 +181,11 @@ static void scsi_host_dev_release(struct
*/
if (parent)
put_device(parent);
+ free_host_no(shost->host_no);
kfree(shost);
}
+
/**
* scsi_host_alloc - register a scsi host adapter instance.
* @sht: pointer to scsi host template
@@ -184,6 +204,7 @@ struct Scsi_Host *scsi_host_alloc(struct
struct Scsi_Host *shost;
int gfp_mask = GFP_KERNEL, rval;
DECLARE_COMPLETION(complete);
+ int host_no;
if (sht->unchecked_isa_dma && privsize)
gfp_mask |= __GFP_DMA;
@@ -214,7 +235,6 @@ struct Scsi_Host *scsi_host_alloc(struct
init_MUTEX(&shost->scan_mutex);
- shost->host_no = scsi_host_next_hn++; /* XXX(hch): still racy */
shost->dma_channel = 0xff;
/* These three are default values which can be overridden */
@@ -259,6 +279,11 @@ struct Scsi_Host *scsi_host_alloc(struct
else
shost->dma_boundary = 0xffffffff;
+ host_no = alloc_host_no();
+ if (host_no < 0)
+ goto fail_kfree;
+ shost->host_no = host_no;
+
rval = scsi_setup_command_freelist(shost);
if (rval)
goto fail_kfree;
@@ -361,6 +386,7 @@ void scsi_host_put(struct Scsi_Host *sho
int scsi_init_hosts(void)
{
+ idr_init(&allocated_hosts);
return class_register(&shost_class);
}
_
prev parent reply other threads:[~2004-02-27 22:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20040226235412.GA819@phunnypharm.org>
[not found] ` <20040226171928.750f5f6f.akpm@osdl.org>
[not found] ` <20040226173743.2bf473b4.akpm@osdl.org>
2004-02-27 2:50 ` [BK PATCH] SCSI host num allocation improvement Ben Collins
2004-02-27 3:04 ` Ben Collins
2004-02-27 16:33 ` Mike Anderson
2004-02-27 22:30 ` Andrew Morton [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040227143033.731e20df.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=James.Bottomley@steeleye.com \
--cc=andmike@us.ibm.com \
--cc=bcollins@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox