Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sd: notify block layer when using temporary change to cache_type

This is a fix for commit 39c60a0948cc06139e2fbfe084f83cb7e7deae3b

"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>

authored by

Vaughan Cao and committed by
Christoph Hellwig
cb2fb68d 6bb5e6e7

+15 -8
+15 -8
drivers/scsi/sd.c
··· 134 134 "write back, no read (daft)" 135 135 }; 136 136 137 + static void sd_set_flush_flag(struct scsi_disk *sdkp) 138 + { 139 + unsigned flush = 0; 140 + 141 + if (sdkp->WCE) { 142 + flush |= REQ_FLUSH; 143 + if (sdkp->DPOFUA) 144 + flush |= REQ_FUA; 145 + } 146 + 147 + blk_queue_flush(sdkp->disk->queue, flush); 148 + } 149 + 137 150 static ssize_t 138 151 cache_type_store(struct device *dev, struct device_attribute *attr, 139 152 const char *buf, size_t count) ··· 190 177 if (sdkp->cache_override) { 191 178 sdkp->WCE = wce; 192 179 sdkp->RCD = rcd; 180 + sd_set_flush_flag(sdkp); 193 181 return count; 194 182 } 195 183 ··· 2712 2698 struct scsi_disk *sdkp = scsi_disk(disk); 2713 2699 struct scsi_device *sdp = sdkp->device; 2714 2700 unsigned char *buffer; 2715 - unsigned flush = 0; 2716 2701 2717 2702 SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp, 2718 2703 "sd_revalidate_disk\n")); ··· 2757 2744 * We now have all cache related info, determine how we deal 2758 2745 * with flush requests. 2759 2746 */ 2760 - if (sdkp->WCE) { 2761 - flush |= REQ_FLUSH; 2762 - if (sdkp->DPOFUA) 2763 - flush |= REQ_FUA; 2764 - } 2765 - 2766 - blk_queue_flush(sdkp->disk->queue, flush); 2747 + sd_set_flush_flag(sdkp); 2767 2748 2768 2749 set_capacity(disk, sdkp->capacity); 2769 2750 sd_config_write_same(sdkp);