Skip to content

Commit

Permalink
sd: notify block layer when using temporary change to cache_type
Browse files Browse the repository at this point in the history
This is a fix for commit 39c60a0

  "sd: fix array cache flushing bug causing performance problems"

We must notify the block layer via q->flush_flags after a temporary change
of the cache_type to write through.  Without this, a SYNCHRONIZE CACHE
command will still be generated.  This patch factors out a helper that
can be called from sd_revalidate_disk and cache_type_store.

Signed-off-by: Vaughan Cao <vaughan.cao@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Vaughan Cao authored and Christoph Hellwig committed Jul 17, 2014
1 parent 6bb5e6e commit cb2fb68
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions drivers/scsi/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ static const char *sd_cache_types[] = {
"write back, no read (daft)"
};

static void sd_set_flush_flag(struct scsi_disk *sdkp)
{
unsigned flush = 0;

if (sdkp->WCE) {
flush |= REQ_FLUSH;
if (sdkp->DPOFUA)
flush |= REQ_FUA;
}

blk_queue_flush(sdkp->disk->queue, flush);
}

static ssize_t
cache_type_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
Expand Down Expand Up @@ -177,6 +190,7 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
if (sdkp->cache_override) {
sdkp->WCE = wce;
sdkp->RCD = rcd;
sd_set_flush_flag(sdkp);
return count;
}

Expand Down Expand Up @@ -2698,7 +2712,6 @@ static int sd_revalidate_disk(struct gendisk *disk)
struct scsi_disk *sdkp = scsi_disk(disk);
struct scsi_device *sdp = sdkp->device;
unsigned char *buffer;
unsigned flush = 0;

SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp,
"sd_revalidate_disk\n"));
Expand Down Expand Up @@ -2744,13 +2757,7 @@ static int sd_revalidate_disk(struct gendisk *disk)
* We now have all cache related info, determine how we deal
* with flush requests.
*/
if (sdkp->WCE) {
flush |= REQ_FLUSH;
if (sdkp->DPOFUA)
flush |= REQ_FUA;
}

blk_queue_flush(sdkp->disk->queue, flush);
sd_set_flush_flag(sdkp);

set_capacity(disk, sdkp->capacity);
sd_config_write_same(sdkp);
Expand Down

0 comments on commit cb2fb68

Please sign in to comment.