cregit-Linux how code gets into the kernel

Release 4.17 block/blk-sysfs.c

Directory: block
// SPDX-License-Identifier: GPL-2.0
/*
 * Functions related to sysfs handling
 */
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/bio.h>
#include <linux/blkdev.h>
#include <linux/backing-dev.h>
#include <linux/blktrace_api.h>
#include <linux/blk-mq.h>
#include <linux/blk-cgroup.h>

#include "blk.h"
#include "blk-mq.h"
#include "blk-mq-debugfs.h"
#include "blk-wbt.h"


struct queue_sysfs_entry {
	
struct attribute attr;
	
ssize_t (*show)(struct request_queue *, char *);
	
ssize_t (*store)(struct request_queue *, const char *, size_t);
};


static ssize_t queue_var_show(unsigned long var, char *page) { return sprintf(page, "%lu\n", var); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe2291.67%150.00%
Xiaotian Feng28.33%150.00%
Total24100.00%2100.00%


static ssize_t queue_var_store(unsigned long *var, const char *page, size_t count) { int err; unsigned long v; err = kstrtoul(page, 10, &v); if (err || v > UINT_MAX) return -EINVAL; *var = v; return count; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe2950.00%133.33%
Dave Reisner2848.28%133.33%
Jingoo Han11.72%133.33%
Total58100.00%3100.00%


static ssize_t queue_var_store64(s64 *var, const char *page) { int err; s64 v; err = kstrtos64(page, 10, &v); if (err < 0) return err; *var = v; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe50100.00%2100.00%
Total50100.00%2100.00%


static ssize_t queue_requests_show(struct request_queue *q, char *page) { return queue_var_show(q->nr_requests, (page)); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe27100.00%1100.00%
Total27100.00%1100.00%


static ssize_t queue_requests_store(struct request_queue *q, const char *page, size_t count) { unsigned long nr; int ret, err; if (!q->request_fn && !q->mq_ops) return -EINVAL; ret = queue_var_store(&nr, page, count); if (ret < 0) return ret; if (nr < BLKDEV_MIN_RQ) nr = BLKDEV_MIN_RQ; if (q->request_fn) err = blk_update_nr_requests(q, nr); else err = blk_mq_update_nr_requests(q, nr); if (err) return err; return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe9990.00%350.00%
Dave Reisner98.18%116.67%
Tejun Heo10.91%116.67%
Tao Ma10.91%116.67%
Total110100.00%6100.00%


static ssize_t queue_ra_show(struct request_queue *q, char *page) { unsigned long ra_kb = q->backing_dev_info->ra_pages << (PAGE_SHIFT - 10); return queue_var_show(ra_kb, (page)); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe3790.24%125.00%
Xiaotian Feng24.88%125.00%
Jan Kara12.44%125.00%
Kirill A. Shutemov12.44%125.00%
Total41100.00%4100.00%


static ssize_t queue_ra_store(struct request_queue *q, const char *page, size_t count) { unsigned long ra_kb; ssize_t ret = queue_var_store(&ra_kb, page, count); if (ret < 0) return ret; q->backing_dev_info->ra_pages = ra_kb >> (PAGE_SHIFT - 10); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe5182.26%125.00%
Dave Reisner914.52%125.00%
Kirill A. Shutemov11.61%125.00%
Jan Kara11.61%125.00%
Total62100.00%4100.00%


static ssize_t queue_max_sectors_show(struct request_queue *q, char *page) { int max_sectors_kb = queue_max_sectors(q) >> 1; return queue_var_show(max_sectors_kb, (page)); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe3291.43%150.00%
Martin K. Petersen38.57%150.00%
Total35100.00%2100.00%


static ssize_t queue_max_segments_show(struct request_queue *q, char *page) { return queue_var_show(queue_max_segments(q), (page)); }

Contributors

PersonTokensPropCommitsCommitProp
Martin K. Petersen28100.00%1100.00%
Total28100.00%1100.00%


static ssize_t queue_max_discard_segments_show(struct request_queue *q, char *page) { return queue_var_show(queue_max_discard_segments(q), (page)); }

Contributors

PersonTokensPropCommitsCommitProp
Christoph Hellwig28100.00%1100.00%
Total28100.00%1100.00%


static ssize_t queue_max_integrity_segments_show(struct request_queue *q, char *page) { return queue_var_show(q->limits.max_integrity_segments, (page)); }

Contributors

PersonTokensPropCommitsCommitProp
Martin K. Petersen29100.00%1100.00%
Total29100.00%1100.00%


static ssize_t queue_max_segment_size_show(struct request_queue *q, char *page) { if (blk_queue_cluster(q)) return queue_var_show(queue_max_segment_size(q), (page)); return queue_var_show(PAGE_SIZE, (page)); }

Contributors

PersonTokensPropCommitsCommitProp
Martin K. Petersen4497.78%266.67%
Kirill A. Shutemov12.22%133.33%
Total45100.00%3100.00%


static ssize_t queue_logical_block_size_show(struct request_queue *q, char *page) { return queue_var_show(queue_logical_block_size(q), page); }

Contributors

PersonTokensPropCommitsCommitProp
Martin K. Petersen26100.00%2100.00%
Total26100.00%2100.00%


static ssize_t queue_physical_block_size_show(struct request_queue *q, char *page) { return queue_var_show(queue_physical_block_size(q), page); }

Contributors

PersonTokensPropCommitsCommitProp
Martin K. Petersen26100.00%1100.00%
Total26100.00%1100.00%


static ssize_t queue_chunk_sectors_show(struct request_queue *q, char *page) { return queue_var_show(q->limits.chunk_sectors, page); }

Contributors

PersonTokensPropCommitsCommitProp
Hannes Reinecke27100.00%1100.00%
Total27100.00%1100.00%


static ssize_t queue_io_min_show(struct request_queue *q, char *page) { return queue_var_show(queue_io_min(q), page); }

Contributors

PersonTokensPropCommitsCommitProp
Martin K. Petersen26100.00%1100.00%
Total26100.00%1100.00%


static ssize_t queue_io_opt_show(struct request_queue *q, char *page) { return queue_var_show(queue_io_opt(q), page); }

Contributors

PersonTokensPropCommitsCommitProp
Martin K. Petersen26100.00%2100.00%
Total26100.00%2100.00%


static ssize_t queue_discard_granularity_show(struct request_queue *q, char *page) { return queue_var_show(q->limits.discard_granularity, page); }

Contributors

PersonTokensPropCommitsCommitProp
Martin K. Petersen27100.00%1100.00%
Total27100.00%1100.00%


static ssize_t queue_discard_max_hw_show(struct request_queue *q, char *page) { return sprintf(page, "%llu\n", (unsigned long long)q->limits.max_hw_discard_sectors << 9); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe2775.00%150.00%
Alan One Thousand Gnomes925.00%150.00%
Total36100.00%2100.00%


static ssize_t queue_discard_max_show(struct request_queue *q, char *page) { return sprintf(page, "%llu\n", (unsigned long long)q->limits.max_discard_sectors << 9); }

Contributors

PersonTokensPropCommitsCommitProp
Martin K. Petersen36100.00%2100.00%
Total36100.00%2100.00%


static ssize_t queue_discard_max_store(struct request_queue *q, const char *page, size_t count) { unsigned long max_discard; ssize_t ret = queue_var_store(&max_discard, page, count); if (ret < 0) return ret; if (max_discard & (q->limits.discard_granularity - 1)) return -EINVAL; max_discard >>= 9; if (max_discard > UINT_MAX) return -EINVAL; if (max_discard > q->limits.max_hw_discard_sectors) max_discard = q->limits.max_hw_discard_sectors; q->limits.max_discard_sectors = max_discard; return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe106100.00%1100.00%
Total106100.00%1100.00%


static ssize_t queue_discard_zeroes_data_show(struct request_queue *q, char *page) { return queue_var_show(0, page); }

Contributors

PersonTokensPropCommitsCommitProp
Martin K. Petersen2295.65%150.00%
Christoph Hellwig14.35%150.00%
Total23100.00%2100.00%


static ssize_t queue_write_same_max_show(struct request_queue *q, char *page) { return sprintf(page, "%llu\n", (unsigned long long)q->limits.max_write_same_sectors << 9); }

Contributors

PersonTokensPropCommitsCommitProp
Martin K. Petersen36100.00%1100.00%
Total36100.00%1100.00%


static ssize_t queue_write_zeroes_max_show(struct request_queue *q, char *page) { return sprintf(page, "%llu\n", (unsigned long long)q->limits.max_write_zeroes_sectors << 9); }

Contributors

PersonTokensPropCommitsCommitProp
Chaitanya Kulkarni36100.00%1100.00%
Total36100.00%1100.00%


static ssize_t queue_max_sectors_store(struct request_queue *q, const char *page, size_t count) { unsigned long max_sectors_kb, max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1, page_kb = 1 << (PAGE_SHIFT - 10); ssize_t ret = queue_var_store(&max_sectors_kb, page, count); if (ret < 0) return ret; max_hw_sectors_kb = min_not_zero(max_hw_sectors_kb, (unsigned long) q->limits.max_dev_sectors >> 1); if (max_sectors_kb > max_hw_sectors_kb || max_sectors_kb < page_kb) return -EINVAL; spin_lock_irq(q->queue_lock); q->limits.max_sectors = max_sectors_kb << 1; q->backing_dev_info->io_pages = max_sectors_kb >> (PAGE_SHIFT - 10); spin_unlock_irq(q->queue_lock); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe10072.46%225.00%
Martin K. Petersen2215.94%225.00%
Dave Reisner96.52%112.50%
Nikanth Karthikesan53.62%112.50%
Jan Kara10.72%112.50%
Kirill A. Shutemov10.72%112.50%
Total138100.00%8100.00%


static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page) { int max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1; return queue_var_show(max_hw_sectors_kb, (page)); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe3291.43%150.00%
Martin K. Petersen38.57%150.00%
Total35100.00%2100.00%

#define QUEUE_SYSFS_BIT_FNS(name, flag, neg) \ static ssize_t \ queue_show_##name(struct request_queue *q, char *page) \ { \ int bit; \ bit = test_bit(QUEUE_FLAG_##flag, &q->queue_flags); \ return queue_var_show(neg ? !bit : bit, page); \ } \ static ssize_t \ queue_store_##name(struct request_queue *q, const char *page, size_t count) \ { \ unsigned long val; \ ssize_t ret; \ ret = queue_var_store(&val, page, count); \ if (ret < 0) \ return ret; \ if (neg) \ val = !val; \ \ if (val) \ blk_queue_flag_set(QUEUE_FLAG_##flag, q); \ else \ blk_queue_flag_clear(QUEUE_FLAG_##flag, q); \ 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_zoned_show(struct request_queue *q, char *page) { switch (blk_queue_zoned_model(q)) { case BLK_ZONED_HA: return sprintf(page, "host-aware\n"); case BLK_ZONED_HM: return sprintf(page, "host-managed\n"); default: return sprintf(page, "none\n"); } }

Contributors

PersonTokensPropCommitsCommitProp
Damien Le Moal55100.00%1100.00%
Total55100.00%1100.00%


static ssize_t queue_nomerges_show(struct request_queue *q, char *page) { return queue_var_show((blk_queue_nomerges(q) << 1) | blk_queue_noxmerges(q), page); }

Contributors

PersonTokensPropCommitsCommitProp
Alan D. Brunelle35100.00%2100.00%
Total35100.00%2100.00%


static ssize_t queue_nomerges_store(struct request_queue *q, const char *page, size_t count) { unsigned long nm; ssize_t ret = queue_var_store(&nm, page, count); if (ret < 0) return ret; spin_lock_irq(q->queue_lock); queue_flag_clear(QUEUE_FLAG_NOMERGES, q); queue_flag_clear(QUEUE_FLAG_NOXMERGES, q); if (nm == 2) queue_flag_set(QUEUE_FLAG_NOMERGES, q); else if (nm) queue_flag_set(QUEUE_FLAG_NOXMERGES, q); spin_unlock_irq(q->queue_lock); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Alan D. Brunelle7877.23%250.00%
Jens Axboe1413.86%125.00%
Dave Reisner98.91%125.00%
Total101100.00%4100.00%


static ssize_t queue_rq_affinity_show(struct request_queue *q, char *page) { bool set = test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags); bool force = test_bit(QUEUE_FLAG_SAME_FORCE, &q->queue_flags); return queue_var_show(set << force, page); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe3568.63%133.33%
Dan J Williams1529.41%133.33%
Xiaotian Feng11.96%133.33%
Total51100.00%3100.00%


static ssize_t queue_rq_affinity_store(struct request_queue *q, const char *page, size_t count) { ssize_t ret = -EINVAL; #ifdef CONFIG_SMP unsigned long val; ret = queue_var_store(&val, page, count); if (ret < 0) return ret; spin_lock_irq(q->queue_lock); if (val == 2) { queue_flag_set(QUEUE_FLAG_SAME_COMP, q); queue_flag_set(QUEUE_FLAG_SAME_FORCE, q); } else if (val == 1) { queue_flag_set(QUEUE_FLAG_SAME_COMP, q); queue_flag_clear(QUEUE_FLAG_SAME_FORCE, q); } else if (val == 0) { queue_flag_clear(QUEUE_FLAG_SAME_COMP, q); queue_flag_clear(QUEUE_FLAG_SAME_FORCE, q); } spin_unlock_irq(q->queue_lock); #endif return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe7855.71%120.00%
Eric Seppanen2719.29%120.00%
Dan J Williams2316.43%120.00%
Dave Reisner96.43%120.00%
Christoph Hellwig32.14%120.00%
Total140100.00%5100.00%


static ssize_t queue_poll_delay_show(struct request_queue *q, char *page) { int val; if (q->poll_nsec == -1) val = -1; else val = q->poll_nsec / 1000; return sprintf(page, "%d\n", val); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe51100.00%3100.00%
Total51100.00%3100.00%


static ssize_t queue_poll_delay_store(struct request_queue *q, const char *page, size_t count) { int err, val; if (!q->mq_ops || !q->mq_ops->poll) return -EINVAL; err = kstrtoint(page, 10, &val); if (err < 0) return err; if (val == -1) q->poll_nsec = -1; else q->poll_nsec = val * 1000; return count; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe89100.00%3100.00%
Total89100.00%3100.00%


static ssize_t queue_poll_show(struct request_queue *q, char *page) { return queue_var_show(test_bit(QUEUE_FLAG_POLL, &q->queue_flags), page); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe31100.00%1100.00%
Total31100.00%1100.00%


static ssize_t queue_poll_store(struct request_queue *q, const char *page, size_t count) { unsigned long poll_on; ssize_t ret; if (!q->mq_ops || !q->mq_ops->poll) return -EINVAL; ret = queue_var_store(&poll_on, page, count); if (ret < 0) return ret; if (poll_on) blk_queue_flag_set(QUEUE_FLAG_POLL, q); else blk_queue_flag_clear(QUEUE_FLAG_POLL, q); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe8597.70%150.00%
Bart Van Assche22.30%150.00%
Total87100.00%2100.00%


static ssize_t queue_wb_lat_show(struct request_queue *q, char *page) { if (!q->rq_wb) return -EINVAL; return sprintf(page, "%llu\n", div_u64(q->rq_wb->min_lat_nsec, 1000)); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe45100.00%1100.00%
Total45100.00%1100.00%


static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page, size_t count) { struct rq_wb *rwb; ssize_t ret; s64 val; ret = queue_var_store64(&val, page); if (ret < 0) return ret; if (val < -1) return -EINVAL; rwb = q->rq_wb; if (!rwb) { ret = wbt_init(q); if (ret) return ret; } rwb = q->rq_wb; if (val == -1) rwb->min_lat_nsec = wbt_default_latency_nsec(q); else if (val >= 0) rwb->min_lat_nsec = val * 1000ULL; if (rwb->enable_state == WBT_STATE_ON_DEFAULT) rwb->enable_state = WBT_STATE_ON_MANUAL; wbt_update_limits(rwb); return count; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe14599.32%375.00%
weiping zhang10.68%125.00%
Total146100.00%4100.00%


static ssize_t queue_wc_show(struct request_queue *q, char *page) { if (test_bit(QUEUE_FLAG_WC, &q->queue_flags)) return sprintf(page, "write back\n"); return sprintf(page, "write through\n"); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe43100.00%1100.00%
Total43100.00%1100.00%


static ssize_t queue_wc_store(struct request_queue *q, const char *page, size_t count) { int set = -1; if (!strncmp(page, "write back", 10)) set = 1; else if (!strncmp(page, "write through", 13) || !strncmp(page, "none", 4)) set = 0; if (set == -1) return -EINVAL; if (set) blk_queue_flag_set(QUEUE_FLAG_WC, q); else blk_queue_flag_clear(QUEUE_FLAG_WC, q); return count; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe9998.02%150.00%
Bart Van Assche21.98%150.00%
Total101100.00%2100.00%


static ssize_t queue_dax_show(struct request_queue *q, char *page) { return queue_var_show(blk_queue_dax(q), page); }

Contributors

PersonTokensPropCommitsCommitProp
Yigal Korman26100.00%1100.00%
Total26100.00%1100.00%

static struct queue_sysfs_entry queue_requests_entry = { .attr = {.name = "nr_requests", .mode = S_IRUGO | S_IWUSR }, .show = queue_requests_show, .store = queue_requests_store, }; static struct queue_sysfs_entry queue_ra_entry = { .attr = {.name = "read_ahead_kb", .mode = S_IRUGO | S_IWUSR }, .show = queue_ra_show, .store = queue_ra_store, }; static struct queue_sysfs_entry queue_max_sectors_entry = { .attr = {.name = "max_sectors_kb", .mode = S_IRUGO | S_IWUSR }, .show = queue_max_sectors_show, .store = queue_max_sectors_store, }; static struct queue_sysfs_entry queue_max_hw_sectors_entry = { .attr = {.name = "max_hw_sectors_kb", .mode = S_IRUGO }, .show = queue_max_hw_sectors_show, }; static struct queue_sysfs_entry queue_max_segments_entry = { .attr = {.name = "max_segments", .mode = S_IRUGO }, .show = queue_max_segments_show, }; static struct queue_sysfs_entry queue_max_discard_segments_entry = { .attr = {.name = "max_discard_segments", .mode = S_IRUGO }, .show = queue_max_discard_segments_show, }; static struct queue_sysfs_entry queue_max_integrity_segments_entry = { .attr = {.name = "max_integrity_segments", .mode = S_IRUGO }, .show = queue_max_integrity_segments_show, }; static struct queue_sysfs_entry queue_max_segment_size_entry = { .attr = {.name = "max_segment_size", .mode = S_IRUGO }, .show = queue_max_segment_size_show, }; static struct queue_sysfs_entry queue_iosched_entry = { .attr = {.name = "scheduler", .mode = S_IRUGO | S_IWUSR }, .show = elv_iosched_show, .store = elv_iosched_store, }; static struct queue_sysfs_entry queue_hw_sector_size_entry = { .attr = {.name = "hw_sector_size", .mode = S_IRUGO }, .show = queue_logical_block_size_show, }; static struct queue_sysfs_entry queue_logical_block_size_entry = { .attr = {.name = "logical_block_size", .mode = S_IRUGO }, .show = queue_logical_block_size_show, }; static struct queue_sysfs_entry queue_physical_block_size_entry = { .attr = {.name = "physical_block_size", .mode = S_IRUGO }, .show = queue_physical_block_size_show, }; static struct queue_sysfs_entry queue_chunk_sectors_entry = { .attr = {.name = "chunk_sectors", .mode = S_IRUGO }, .show = queue_chunk_sectors_show, }; static struct queue_sysfs_entry queue_io_min_entry = { .attr = {.name = "minimum_io_size", .mode = S_IRUGO }, .show = queue_io_min_show, }; static struct queue_sysfs_entry queue_io_opt_entry = { .attr = {.name = "optimal_io_size", .mode = S_IRUGO }, .show = queue_io_opt_show, }; static struct queue_sysfs_entry queue_discard_granularity_entry = { .attr = {.name = "discard_granularity", .mode = S_IRUGO }, .show = queue_discard_granularity_show, }; static struct queue_sysfs_entry queue_discard_max_hw_entry = { .attr = {