2007-05-10 10:02:06

by Menny Hamburger

[permalink] [raw]
Subject: [PATCH] interface for doing a full host scsi rescan

Hi,

When we do want to rescan the SCSI host, a userland script needs to be
provided that does add/remove.
This patch adds an interface for doing this inside the kernel - seems
more appropriate:

--- linux-2.6.20/drivers/scsi/scsi_proc.c 2007-02-04
20:44:54.000000000 +0200
+++ linux-2.6.20_patched/drivers/scsi/scsi_proc.c 2007-05-10
12:52:13.353652000 +0300
@@ -227,6 +227,20 @@
return error;
}

+static int scsi_scan_selected_host(uint host, uint rescan)
+{
+ struct Scsi_Host *shost;
+ int error = -ENXIO;
+
+ shost = scsi_host_lookup(host);
+ if (IS_ERR(shost))
+ return PTR_ERR(shost);
+
+ error = scsi_scan_host_selected(shost, SCAN_WILD_CARD,
SCAN_WILD_CARD, SCAN_WILD_CARD, rescan);
+ scsi_host_put(shost);
+ return error;
+}
+
static ssize_t proc_scsi_write(struct file *file, const char __user
*buf,
size_t length, loff_t *ppos)
{
@@ -278,7 +292,24 @@
lun = simple_strtoul(p + 1, &p, 0);

err = scsi_remove_single_device(host, channel, id, lun);
- }
+ /*
+ * Usage: echo "scsi scan-devices 0 1" >/proc/scsi/scsi
+ * where 0 is Host and 1 is whether to rescan (1) or do a full
scan (0).
+ */
+ } else if(!strncmp("scsi scan-devices", buffer, 17)) {
+ p = buffer + 18;
+
+ host = simple_strtoul(p, &p, 0);
+ rescan = simple_strtoul(p + 1, &p, 0);
+
+ if (rescan)
+ printk(KERN_DEBUG "Rescanning SCSI host %d\n",
host);
+ else
+ printk(KERN_DEBUG "Scanning SCSI host %d\n",
host);
+
+ err = scsi_scan_selected_host(host, rescan);
+ }
+

/*
* convert success returns so that we return the


Menny


2007-05-10 10:09:38

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] interface for doing a full host scsi rescan

On Thu, May 10, 2007 at 01:01:55PM +0300, Menny Hamburger wrote:
> Hi,
>
> When we do want to rescan the SCSI host, a userland script needs to be
> provided that does add/remove.
> This patch adds an interface for doing this inside the kernel - seems
> more appropriate:

/proc/scsi/scsi is deprecated, don't use it. But you can do a full
rescan through /sys/.../scan

2007-05-10 11:08:54

by Menny Hamburger

[permalink] [raw]
Subject: RE: [PATCH] interface for doing a full host scsi rescan

Thnx,

I'll check that

M.

-----Original Message-----
From: Christoph Hellwig [mailto:[email protected]]
Sent: Thursday, May 10, 2007 12:10 PM
To: Menny Hamburger
Cc: [email protected]
Subject: Re: [PATCH] interface for doing a full host scsi rescan

On Thu, May 10, 2007 at 01:01:55PM +0300, Menny Hamburger wrote:
> Hi,
>
> When we do want to rescan the SCSI host, a userland script needs to be

> provided that does add/remove.
> This patch adds an interface for doing this inside the kernel - seems
> more appropriate:

/proc/scsi/scsi is deprecated, don't use it. But you can do a full
rescan through /sys/.../scan