From: Christoph Hellwig <hch@lst.de>
To: James Bottomley <James.Bottomley@SteelEye.com>
Cc: linux-scsi@vger.kernel.org
Subject: [PATCH] serialize bus scanning
Date: Mon, 25 Aug 2003 14:24:16 +0200 [thread overview]
Message-ID: <20030825122416.GE15506@lst.de> (raw)
Synchronize all scanning activity, this fixes long-standing races
vs /proc/scsi/scsi and sysfs addition and deletion of devices.
Note that this does not serialize removing, the lists will get
their own locking soon.
diff -Nru a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
--- a/drivers/scsi/scsi_scan.c Mon Aug 25 13:37:29 2003
+++ b/drivers/scsi/scsi_scan.c Mon Aug 25 13:37:29 2003
@@ -30,6 +30,7 @@
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/blkdev.h>
+#include <asm/semaphore.h>
#include "scsi.h"
#include "hosts.h"
@@ -94,6 +95,13 @@
" between 1 and 16384)");
#endif
+/*
+ * This mutex serializes all scsi scanning activity from kernel- and
+ * userspace. It could easily be made per-host but I'd like to avoid
+ * the overhead for now.
+ */
+static DECLARE_MUTEX(scsi_scan_mutex);
+
/**
* scsi_unlock_floptical - unlock device via a special MODE SENSE command
* @sreq: used to send the command
@@ -1067,9 +1075,12 @@
struct scsi_device *sdev;
int res;
+ down(&scsi_scan_mutex);
res = scsi_probe_and_add_lun(shost, channel, id, lun, NULL, &sdev, 1);
if (res != SCSI_SCAN_LUN_PRESENT)
sdev = ERR_PTR(-ENODEV);
+ up(&scsi_scan_mutex);
+
return sdev;
}
@@ -1191,11 +1202,14 @@
((lun != SCAN_WILD_CARD) && (lun > shost->max_lun)))
return -EINVAL;
+ down(&scsi_scan_mutex);
if (channel == SCAN_WILD_CARD)
for (channel = 0; channel <= shost->max_channel; channel++)
scsi_scan_channel(shost, channel, id, lun, rescan);
else
scsi_scan_channel(shost, channel, id, lun, rescan);
+ up(&scsi_scan_mutex);
+
return 0;
}
next reply other threads:[~2003-08-25 12:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-25 12:24 Christoph Hellwig [this message]
2003-08-27 20:29 ` [PATCH] serialize bus scanning Anton Blanchard
2003-08-27 20:35 ` Christoph Hellwig
2003-09-10 7:57 ` Anton Blanchard
2003-09-11 20:34 ` Patrick Mansfield
2003-09-15 7:13 ` Anton Blanchard
2003-09-15 9:10 ` Christoph Hellwig
2003-08-27 22:32 ` Mike Anderson
2003-08-27 22:59 ` Anton Blanchard
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=20030825122416.GE15506@lst.de \
--to=hch@lst.de \
--cc=James.Bottomley@SteelEye.com \
--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