summaryrefslogtreecommitdiff
path: root/block/blk-sysfs.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2023-07-07 11:42:39 +0200
committerJens Axboe <axboe@kernel.dk>2023-07-17 08:18:18 -0600
commit43c9835b144c7ce29efe142d662529662a9eb376 (patch)
tree9a76f7e28e76f520ceb20966493710c10bcc49cb /block/blk-sysfs.c
parentc4e21bcd0f9d01f9c5d6c52007f5541871a5b1de (diff)
downloadlwn-43c9835b144c7ce29efe142d662529662a9eb376.tar.gz
lwn-43c9835b144c7ce29efe142d662529662a9eb376.zip
block: don't allow enabling a cache on devices that don't support it
Currently the write_cache attribute allows enabling the QUEUE_FLAG_WC flag on devices that never claimed the capability. Fix that by adding a QUEUE_FLAG_HW_WC flag that is set by blk_queue_write_cache and guards re-enabling the cache through sysfs. Note that any rescan that calls blk_queue_write_cache will still re-enable the write cache as in the current code. Fixes: 93e9d8e836cb ("block: add ability to flag write back caching on a device") Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20230707094239.107968-3-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-sysfs.c')
-rw-r--r--block/blk-sysfs.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 0cde6598fb2f..63e481262336 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -449,13 +449,16 @@ static ssize_t queue_wc_show(struct request_queue *q, char *page)
static ssize_t queue_wc_store(struct request_queue *q, const char *page,
size_t count)
{
- if (!strncmp(page, "write back", 10))
+ if (!strncmp(page, "write back", 10)) {
+ if (!test_bit(QUEUE_FLAG_HW_WC, &q->queue_flags))
+ return -EINVAL;
blk_queue_flag_set(QUEUE_FLAG_WC, q);
- else if (!strncmp(page, "write through", 13) ||
- !strncmp(page, "none", 4))
+ } else if (!strncmp(page, "write through", 13) ||
+ !strncmp(page, "none", 4)) {
blk_queue_flag_clear(QUEUE_FLAG_WC, q);
- else
+ } else {
return -EINVAL;
+ }
return count;
}