Skip to content

Commit 645a829

Browse files
YuKuai-huaweiaxboe
authored andcommitted
blk-wbt: don't create wbt sysfs entry if CONFIG_BLK_WBT is disabled
sysfs entry /sys/block/[device]/queue/wbt_lat_usec will be created even if CONFIG_BLK_WBT is disabled, while read and write will always fail. It doesn't make sense to create a sysfs entry that can't be accessed, so don't create such entry. Signed-off-by: Yu Kuai <yukuai3@huawei.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20230527010644.647900-2-yukuai1@huaweicloud.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c6b7a3a commit 645a829

2 files changed

Lines changed: 74 additions & 88 deletions

File tree

block/blk-sysfs.c

Lines changed: 74 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,6 @@ queue_var_store(unsigned long *var, const char *page, size_t count)
4747
return count;
4848
}
4949

50-
static ssize_t queue_var_store64(s64 *var, const char *page)
51-
{
52-
int err;
53-
s64 v;
54-
55-
err = kstrtos64(page, 10, &v);
56-
if (err < 0)
57-
return err;
58-
59-
*var = v;
60-
return 0;
61-
}
62-
6350
static ssize_t queue_requests_show(struct request_queue *q, char *page)
6451
{
6552
return queue_var_show(q->nr_requests, page);
@@ -451,61 +438,6 @@ static ssize_t queue_io_timeout_store(struct request_queue *q, const char *page,
451438
return count;
452439
}
453440

454-
static ssize_t queue_wb_lat_show(struct request_queue *q, char *page)
455-
{
456-
if (!wbt_rq_qos(q))
457-
return -EINVAL;
458-
459-
if (wbt_disabled(q))
460-
return sprintf(page, "0\n");
461-
462-
return sprintf(page, "%llu\n", div_u64(wbt_get_min_lat(q), 1000));
463-
}
464-
465-
static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page,
466-
size_t count)
467-
{
468-
struct rq_qos *rqos;
469-
ssize_t ret;
470-
s64 val;
471-
472-
ret = queue_var_store64(&val, page);
473-
if (ret < 0)
474-
return ret;
475-
if (val < -1)
476-
return -EINVAL;
477-
478-
rqos = wbt_rq_qos(q);
479-
if (!rqos) {
480-
ret = wbt_init(q->disk);
481-
if (ret)
482-
return ret;
483-
}
484-
485-
if (val == -1)
486-
val = wbt_default_latency_nsec(q);
487-
else if (val >= 0)
488-
val *= 1000ULL;
489-
490-
if (wbt_get_min_lat(q) == val)
491-
return count;
492-
493-
/*
494-
* Ensure that the queue is idled, in case the latency update
495-
* ends up either enabling or disabling wbt completely. We can't
496-
* have IO inflight if that happens.
497-
*/
498-
blk_mq_freeze_queue(q);
499-
blk_mq_quiesce_queue(q);
500-
501-
wbt_set_min_lat(q, val);
502-
503-
blk_mq_unquiesce_queue(q);
504-
blk_mq_unfreeze_queue(q);
505-
506-
return count;
507-
}
508-
509441
static ssize_t queue_wc_show(struct request_queue *q, char *page)
510442
{
511443
if (test_bit(QUEUE_FLAG_WC, &q->queue_flags))
@@ -598,7 +530,6 @@ QUEUE_RW_ENTRY(queue_wc, "write_cache");
598530
QUEUE_RO_ENTRY(queue_fua, "fua");
599531
QUEUE_RO_ENTRY(queue_dax, "dax");
600532
QUEUE_RW_ENTRY(queue_io_timeout, "io_timeout");
601-
QUEUE_RW_ENTRY(queue_wb_lat, "wbt_lat_usec");
602533
QUEUE_RO_ENTRY(queue_virt_boundary_mask, "virt_boundary_mask");
603534
QUEUE_RO_ENTRY(queue_dma_alignment, "dma_alignment");
604535

@@ -617,6 +548,78 @@ QUEUE_RW_ENTRY(queue_iostats, "iostats");
617548
QUEUE_RW_ENTRY(queue_random, "add_random");
618549
QUEUE_RW_ENTRY(queue_stable_writes, "stable_writes");
619550

551+
#ifdef CONFIG_BLK_WBT
552+
static ssize_t queue_var_store64(s64 *var, const char *page)
553+
{
554+
int err;
555+
s64 v;
556+
557+
err = kstrtos64(page, 10, &v);
558+
if (err < 0)
559+
return err;
560+
561+
*var = v;
562+
return 0;
563+
}
564+
565+
static ssize_t queue_wb_lat_show(struct request_queue *q, char *page)
566+
{
567+
if (!wbt_rq_qos(q))
568+
return -EINVAL;
569+
570+
if (wbt_disabled(q))
571+
return sprintf(page, "0\n");
572+
573+
return sprintf(page, "%llu\n", div_u64(wbt_get_min_lat(q), 1000));
574+
}
575+
576+
static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page,
577+
size_t count)
578+
{
579+
struct rq_qos *rqos;
580+
ssize_t ret;
581+
s64 val;
582+
583+
ret = queue_var_store64(&val, page);
584+
if (ret < 0)
585+
return ret;
586+
if (val < -1)
587+
return -EINVAL;
588+
589+
rqos = wbt_rq_qos(q);
590+
if (!rqos) {
591+
ret = wbt_init(q->disk);
592+
if (ret)
593+
return ret;
594+
}
595+
596+
if (val == -1)
597+
val = wbt_default_latency_nsec(q);
598+
else if (val >= 0)
599+
val *= 1000ULL;
600+
601+
if (wbt_get_min_lat(q) == val)
602+
return count;
603+
604+
/*
605+
* Ensure that the queue is idled, in case the latency update
606+
* ends up either enabling or disabling wbt completely. We can't
607+
* have IO inflight if that happens.
608+
*/
609+
blk_mq_freeze_queue(q);
610+
blk_mq_quiesce_queue(q);
611+
612+
wbt_set_min_lat(q, val);
613+
614+
blk_mq_unquiesce_queue(q);
615+
blk_mq_unfreeze_queue(q);
616+
617+
return count;
618+
}
619+
620+
QUEUE_RW_ENTRY(queue_wb_lat, "wbt_lat_usec");
621+
#endif
622+
620623
static struct attribute *queue_attrs[] = {
621624
&queue_requests_entry.attr,
622625
&queue_ra_entry.attr,
@@ -655,7 +658,9 @@ static struct attribute *queue_attrs[] = {
655658
&queue_wc_entry.attr,
656659
&queue_fua_entry.attr,
657660
&queue_dax_entry.attr,
661+
#ifdef CONFIG_BLK_WBT
658662
&queue_wb_lat_entry.attr,
663+
#endif
659664
&queue_poll_delay_entry.attr,
660665
&queue_io_timeout_entry.attr,
661666
#ifdef CONFIG_BLK_DEV_THROTTLING_LOW

block/blk-wbt.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ u64 wbt_default_latency_nsec(struct request_queue *);
1818

1919
#else
2020

21-
static inline int wbt_init(struct gendisk *disk)
22-
{
23-
return -EINVAL;
24-
}
2521
static inline void wbt_disable_default(struct gendisk *disk)
2622
{
2723
}
@@ -31,21 +27,6 @@ static inline void wbt_enable_default(struct gendisk *disk)
3127
static inline void wbt_set_write_cache(struct request_queue *q, bool wc)
3228
{
3329
}
34-
static inline u64 wbt_get_min_lat(struct request_queue *q)
35-
{
36-
return 0;
37-
}
38-
static inline void wbt_set_min_lat(struct request_queue *q, u64 val)
39-
{
40-
}
41-
static inline u64 wbt_default_latency_nsec(struct request_queue *q)
42-
{
43-
return 0;
44-
}
45-
static inline bool wbt_disabled(struct request_queue *q)
46-
{
47-
return true;
48-
}
4930

5031
#endif /* CONFIG_BLK_WBT */
5132

0 commit comments

Comments
 (0)