From: Jens Axboe <axboe@suse.de>
To: Christoph Hellwig <hch@infradead.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH 2/3] scsi_forget_host - scsi_debug usage
Date: Mon, 14 Jun 2004 15:06:19 +0200 [thread overview]
Message-ID: <20040614130619.GH1970@suse.de> (raw)
In-Reply-To: <20040614080632.GA7114@infradead.org>
On Mon, Jun 14 2004, Christoph Hellwig wrote:
> On Fri, Jun 11, 2004 at 09:22:32PM -0700, Mike Anderson wrote:
> > DESC
> > scsi_forget_host - scsi_debug usage
> >
> > Use the export scsi_forget_host interface to remove child scsi devices
> > from the scsi_host prior to removal.
>
> Moving this into drivers sounds like a rather bad idea. But with our
Agree
> refcounting in place I wonder whether moving scsi_forget_host first in
> scsi_remove_host wouldn't simply work.
It doesn't, device has already been deleted there. So either that needs
to be reworked if we want to allow devices to talk to themselves from
->remove(), or we just move the sync cache call to sd_release() instead.
The latter is attached.
===== drivers/scsi/sd.c 1.151 vs edited =====
--- 1.151/drivers/scsi/sd.c 2004-05-29 19:50:44 +02:00
+++ edited/drivers/scsi/sd.c 2004-06-14 15:05:34 +02:00
@@ -108,7 +108,6 @@
static int sd_probe(struct device *);
static int sd_remove(struct device *);
-static void sd_shutdown(struct device *dev);
static void sd_rescan(struct device *);
static int sd_init_command(struct scsi_cmnd *);
static void sd_read_capacity(struct scsi_disk *sdkp, char *diskname,
@@ -120,7 +119,6 @@
.name = "sd",
.probe = sd_probe,
.remove = sd_remove,
- .shutdown = sd_shutdown,
},
.rescan = sd_rescan,
.init_command = sd_init_command,
@@ -402,6 +400,50 @@
return 1;
}
+/*
+ * Send a SYNCHRONIZE CACHE instruction down to the device through
+ * the normal SCSI command structure. Wait for the command to
+ * complete.
+ */
+static void sd_sync_cache(struct scsi_device *sdp)
+{
+ struct scsi_request *sreq;
+ int retries, res;
+
+ sreq = scsi_allocate_request(sdp, GFP_KERNEL);
+ if (!sreq) {
+ printk("FAILED\n No memory for request\n");
+ return;
+ }
+
+ sreq->sr_data_direction = DMA_NONE;
+ for (retries = 3; retries > 0; --retries) {
+ unsigned char cmd[10] = { 0 };
+
+ cmd[0] = SYNCHRONIZE_CACHE;
+ /*
+ * Leave the rest of the command zero to indicate
+ * flush everything.
+ */
+ scsi_wait_req(sreq, cmd, NULL, 0, SD_TIMEOUT, SD_MAX_RETRIES);
+ if (sreq->sr_result == 0)
+ break;
+ }
+
+ res = sreq->sr_result;
+ if (res) {
+ printk(KERN_WARNING "FAILED\n status = %x, message = %02x, "
+ "host = %d, driver = %02x\n ",
+ status_byte(res), msg_byte(res),
+ host_byte(res), driver_byte(res));
+ if (driver_byte(res) & DRIVER_SENSE)
+ print_req_sense("sd", sreq);
+ }
+
+ scsi_release_request(sreq);
+ printk("\n");
+}
+
/**
* sd_open - open a scsi disk device
* @inode: only i_rdev member may be used
@@ -498,8 +540,9 @@
SCSI_LOG_HLQUEUE(3, printk("sd_release: disk=%s\n", disk->disk_name));
- if (!--sdkp->openers && sdev->removable) {
- if (scsi_block_when_processing_errors(sdev))
+ if (!--sdkp->openers) {
+ sd_sync_cache(sdev);
+ if (sdev->removable && scsi_block_when_processing_errors(sdev))
scsi_set_medium_removal(sdev, SCSI_REMOVAL_ALLOW);
}
@@ -1460,7 +1503,6 @@
struct scsi_disk *sdkp = dev_get_drvdata(dev);
del_gendisk(sdkp->disk);
- sd_shutdown(dev);
down(&sd_ref_sem);
kref_put(&sdkp->kref);
up(&sd_ref_sem);
@@ -1492,62 +1534,6 @@
kfree(sdkp);
}
-
-/*
- * Send a SYNCHRONIZE CACHE instruction down to the device through
- * the normal SCSI command structure. Wait for the command to
- * complete.
- */
-static void sd_shutdown(struct device *dev)
-{
- struct scsi_device *sdp = to_scsi_device(dev);
- struct scsi_disk *sdkp;
- struct scsi_request *sreq;
- int retries, res;
-
- sdkp = dev_get_drvdata(dev);
- if (!sdkp)
- return; /* this can happen */
-
- if (!scsi_device_online(sdp) || !sdkp->WCE)
- return;
-
- printk(KERN_NOTICE "Synchronizing SCSI cache for disk %s: ",
- sdkp->disk->disk_name);
-
- sreq = scsi_allocate_request(sdp, GFP_KERNEL);
- if (!sreq) {
- printk("FAILED\n No memory for request\n");
- return;
- }
-
- sreq->sr_data_direction = DMA_NONE;
- for (retries = 3; retries > 0; --retries) {
- unsigned char cmd[10] = { 0 };
-
- cmd[0] = SYNCHRONIZE_CACHE;
- /*
- * Leave the rest of the command zero to indicate
- * flush everything.
- */
- scsi_wait_req(sreq, cmd, NULL, 0, SD_TIMEOUT, SD_MAX_RETRIES);
- if (sreq->sr_result == 0)
- break;
- }
-
- res = sreq->sr_result;
- if (res) {
- printk(KERN_WARNING "FAILED\n status = %x, message = %02x, "
- "host = %d, driver = %02x\n ",
- status_byte(res), msg_byte(res),
- host_byte(res), driver_byte(res));
- if (driver_byte(res) & DRIVER_SENSE)
- print_req_sense("sd", sreq);
- }
-
- scsi_release_request(sreq);
- printk("\n");
-}
/**
* init_sd - entry point for this driver (both when built in or when
--
Jens Axboe
next prev parent reply other threads:[~2004-06-14 13:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-12 4:19 [PATCH 0/3] export scsi_forget_host Mike Anderson
2004-06-12 4:21 ` [PATCH 1/3] scsi_forget_host - export function Mike Anderson
2004-06-12 4:22 ` [PATCH 2/3] scsi_forget_host - scsi_debug usage Mike Anderson
2004-06-12 4:24 ` [PATCH 3/3] scsi_forget_host - rename scsi_forget_host to scsi_unscan_host Mike Anderson
2004-06-14 8:06 ` [PATCH 2/3] scsi_forget_host - scsi_debug usage Christoph Hellwig
2004-06-14 13:06 ` Jens Axboe [this message]
2004-06-14 13:23 ` Christoph Hellwig
2004-06-14 13:26 ` Jens Axboe
2004-06-14 13:30 ` Christoph Hellwig
2004-06-14 13:36 ` Jens Axboe
2004-06-14 15:23 ` Mike Anderson
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=20040614130619.GH1970@suse.de \
--to=axboe@suse.de \
--cc=hch@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.