Commit 956bcb7c authored by Jens Axboe's avatar Jens Axboe

block: add helpers for the trivial queue flag sysfs show/store entries

The code for nonrot, random, and io stats are completely identical.
Signed-off-by: default avatarJens Axboe <jaxboe@fusionio.com>
parent e2e1a148
...@@ -180,26 +180,36 @@ static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page) ...@@ -180,26 +180,36 @@ static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page)
return queue_var_show(max_hw_sectors_kb, (page)); return queue_var_show(max_hw_sectors_kb, (page));
} }
static ssize_t queue_nonrot_show(struct request_queue *q, char *page) #define QUEUE_SYSFS_BIT_FNS(name, flag, neg) \
{ static ssize_t \
return queue_var_show(!blk_queue_nonrot(q), page); queue_show_##name(struct request_queue *q, char *page) \
} { \
int bit; \
static ssize_t queue_nonrot_store(struct request_queue *q, const char *page, bit = test_bit(QUEUE_FLAG_##flag, &q->queue_flags); \
size_t count) return queue_var_show(neg ? !bit : bit, page); \
{ } \
unsigned long nm; static ssize_t \
ssize_t ret = queue_var_store(&nm, page, count); queue_store_##name(struct request_queue *q, const char *page, size_t count) \
{ \
spin_lock_irq(q->queue_lock); unsigned long val; \
if (nm) ssize_t ret; \
queue_flag_clear(QUEUE_FLAG_NONROT, q); ret = queue_var_store(&val, page, count); \
else if (neg) \
queue_flag_set(QUEUE_FLAG_NONROT, q); val = !val; \
spin_unlock_irq(q->queue_lock); \
spin_lock_irq(q->queue_lock); \
return ret; if (val) \
} queue_flag_set(QUEUE_FLAG_##flag, q); \
else \
queue_flag_clear(QUEUE_FLAG_##flag, q); \
spin_unlock_irq(q->queue_lock); \
return ret; \
}
QUEUE_SYSFS_BIT_FNS(nonrot, NONROT, 1);
QUEUE_SYSFS_BIT_FNS(random, ADD_RANDOM, 0);
QUEUE_SYSFS_BIT_FNS(iostats, IO_STAT, 0);
#undef QUEUE_SYSFS_BIT_FNS
static ssize_t queue_nomerges_show(struct request_queue *q, char *page) static ssize_t queue_nomerges_show(struct request_queue *q, char *page)
{ {
...@@ -250,48 +260,6 @@ queue_rq_affinity_store(struct request_queue *q, const char *page, size_t count) ...@@ -250,48 +260,6 @@ queue_rq_affinity_store(struct request_queue *q, const char *page, size_t count)
return ret; return ret;
} }
static ssize_t queue_random_show(struct request_queue *q, char *page)
{
return queue_var_show(blk_queue_add_random(q), page);
}
static ssize_t queue_random_store(struct request_queue *q, const char *page,
size_t count)
{
unsigned long val;
ssize_t ret = queue_var_store(&val, page, count);
spin_lock_irq(q->queue_lock);
if (val)
queue_flag_set(QUEUE_FLAG_ADD_RANDOM, q);
else
queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q);
spin_unlock_irq(q->queue_lock);
return ret;
}
static ssize_t queue_iostats_show(struct request_queue *q, char *page)
{
return queue_var_show(blk_queue_io_stat(q), page);
}
static ssize_t queue_iostats_store(struct request_queue *q, const char *page,
size_t count)
{
unsigned long stats;
ssize_t ret = queue_var_store(&stats, page, count);
spin_lock_irq(q->queue_lock);
if (stats)
queue_flag_set(QUEUE_FLAG_IO_STAT, q);
else
queue_flag_clear(QUEUE_FLAG_IO_STAT, q);
spin_unlock_irq(q->queue_lock);
return ret;
}
static struct queue_sysfs_entry queue_requests_entry = { static struct queue_sysfs_entry queue_requests_entry = {
.attr = {.name = "nr_requests", .mode = S_IRUGO | S_IWUSR }, .attr = {.name = "nr_requests", .mode = S_IRUGO | S_IWUSR },
.show = queue_requests_show, .show = queue_requests_show,
...@@ -373,8 +341,8 @@ static struct queue_sysfs_entry queue_discard_zeroes_data_entry = { ...@@ -373,8 +341,8 @@ static struct queue_sysfs_entry queue_discard_zeroes_data_entry = {
static struct queue_sysfs_entry queue_nonrot_entry = { static struct queue_sysfs_entry queue_nonrot_entry = {
.attr = {.name = "rotational", .mode = S_IRUGO | S_IWUSR }, .attr = {.name = "rotational", .mode = S_IRUGO | S_IWUSR },
.show = queue_nonrot_show, .show = queue_show_nonrot,
.store = queue_nonrot_store, .store = queue_store_nonrot,
}; };
static struct queue_sysfs_entry queue_nomerges_entry = { static struct queue_sysfs_entry queue_nomerges_entry = {
...@@ -391,14 +359,14 @@ static struct queue_sysfs_entry queue_rq_affinity_entry = { ...@@ -391,14 +359,14 @@ static struct queue_sysfs_entry queue_rq_affinity_entry = {
static struct queue_sysfs_entry queue_iostats_entry = { static struct queue_sysfs_entry queue_iostats_entry = {
.attr = {.name = "iostats", .mode = S_IRUGO | S_IWUSR }, .attr = {.name = "iostats", .mode = S_IRUGO | S_IWUSR },
.show = queue_iostats_show, .show = queue_show_iostats,
.store = queue_iostats_store, .store = queue_store_iostats,
}; };
static struct queue_sysfs_entry queue_random_entry = { static struct queue_sysfs_entry queue_random_entry = {
.attr = {.name = "add_random", .mode = S_IRUGO | S_IWUSR }, .attr = {.name = "add_random", .mode = S_IRUGO | S_IWUSR },
.show = queue_random_show, .show = queue_show_random,
.store = queue_random_store, .store = queue_store_random,
}; };
static struct attribute *default_attrs[] = { static struct attribute *default_attrs[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment