summaryrefslogtreecommitdiffstats
path: root/block/blk-sysfs.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@fb.com>2016-04-12 14:32:46 -0400
committerJens Axboe <axboe@fb.com>2016-04-12 17:46:27 -0400
commit93e9d8e836cb1a9a58b33eb6643bf061c6119ef2 (patch)
tree17a50abdadaa58686983510230932323bf5d123c /block/blk-sysfs.c
parente0489487ec9cd79ee1fa0dc5d3789c08b0e51a2c (diff)
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>
Diffstat (limited to 'block/blk-sysfs.c')
-rw-r--r--block/blk-sysfs.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 995b58d46ed1..99205965f559 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -347,6 +347,38 @@ static ssize_t queue_poll_store(struct request_queue *q, const char *page,
347 return ret; 347 return ret;
348} 348}
349 349
350static ssize_t queue_wc_show(struct request_queue *q, char *page)
351{
352 if (test_bit(QUEUE_FLAG_WC, &q->queue_flags))
353 return sprintf(page, "write back\n");
354
355 return sprintf(page, "write through\n");
356}
357
358static ssize_t queue_wc_store(struct request_queue *q, const char *page,
359 size_t count)
360{
361 int set = -1;
362
363 if (!strncmp(page, "write back", 10))
364 set = 1;
365 else if (!strncmp(page, "write through", 13) ||
366 !strncmp(page, "none", 4))
367 set = 0;
368
369 if (set == -1)
370 return -EINVAL;
371
372 spin_lock_irq(q->queue_lock);
373 if (set)
374 queue_flag_set(QUEUE_FLAG_WC, q);
375 else
376 queue_flag_clear(QUEUE_FLAG_WC, q);
377 spin_unlock_irq(q->queue_lock);
378
379 return count;
380}
381
350static struct queue_sysfs_entry queue_requests_entry = { 382static struct queue_sysfs_entry queue_requests_entry = {
351 .attr = {.name = "nr_requests", .mode = S_IRUGO | S_IWUSR }, 383 .attr = {.name = "nr_requests", .mode = S_IRUGO | S_IWUSR },
352 .show = queue_requests_show, 384 .show = queue_requests_show,
@@ -478,6 +510,12 @@ static struct queue_sysfs_entry queue_poll_entry = {
478 .store = queue_poll_store, 510 .store = queue_poll_store,
479}; 511};
480 512
513static struct queue_sysfs_entry queue_wc_entry = {
514 .attr = {.name = "write_cache", .mode = S_IRUGO | S_IWUSR },
515 .show = queue_wc_show,
516 .store = queue_wc_store,
517};
518
481static struct attribute *default_attrs[] = { 519static struct attribute *default_attrs[] = {
482 &queue_requests_entry.attr, 520 &queue_requests_entry.attr,
483 &queue_ra_entry.attr, 521 &queue_ra_entry.attr,
@@ -503,6 +541,7 @@ static struct attribute *default_attrs[] = {
503 &queue_iostats_entry.attr, 541 &queue_iostats_entry.attr,
504 &queue_random_entry.attr, 542 &queue_random_entry.attr,
505 &queue_poll_entry.attr, 543 &queue_poll_entry.attr,
544 &queue_wc_entry.attr,
506 NULL, 545 NULL,
507}; 546};
508 547