block: add ability to flag write back caching on a device

Add an internal helper and flag for setting whether a queue has
write back caching, or write through (or none). Add a sysfs file
to show this as well, and make it changeable from user space.

This will replace the (awkward) blk_queue_flush() interface that
drivers currently use to inform the block layer of write cache state
and capabilities.

Signed-off-by: Jens Axboe <axboe@fb.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
Jens Axboe
2016-04-12 12:32:46 -06:00
parent e0489487ec
commit 93e9d8e836
4 changed files with 77 additions and 0 deletions
+26
View File
@@ -846,6 +846,32 @@ void blk_queue_flush_queueable(struct request_queue *q, bool queueable)
}
EXPORT_SYMBOL_GPL(blk_queue_flush_queueable);
/**
* blk_queue_write_cache - configure queue's write cache
* @q: the request queue for the device
* @wc: write back cache on or off
* @fua: device supports FUA writes, if true
*
* Tell the block layer about the write cache of @q.
*/
void blk_queue_write_cache(struct request_queue *q, bool wc, bool fua)
{
spin_lock_irq(q->queue_lock);
if (wc) {
queue_flag_set(QUEUE_FLAG_WC, q);
q->flush_flags = REQ_FLUSH;
} else
queue_flag_clear(QUEUE_FLAG_WC, q);
if (fua) {
if (wc)
q->flush_flags |= REQ_FUA;
queue_flag_set(QUEUE_FLAG_FUA, q);
} else
queue_flag_clear(QUEUE_FLAG_FUA, q);
spin_unlock_irq(q->queue_lock);
}
EXPORT_SYMBOL_GPL(blk_queue_write_cache);
static int __init blk_settings_init(void)
{
blk_max_low_pfn = max_low_pfn - 1;