block/blk-sysfs.c
Source file repositories/reference/linux-study-clean/block/blk-sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
block/blk-sysfs.c- Extension
.c- Size
- 30061 bytes
- Lines
- 1077
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: implementation source
- Status
- source implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/slab.hlinux/module.hlinux/bio.hlinux/blkdev.hlinux/backing-dev.hlinux/blktrace_api.hlinux/debugfs.hblk.hblk-mq.hblk-mq-debugfs.hblk-mq-sched.hblk-rq-qos.hblk-wbt.hblk-cgroup.hblk-throttle.herror-injection.h
Detected Declarations
struct queue_sysfs_entryfunction queue_var_showfunction queue_var_storefunction queue_requests_showfunction queue_requests_storefunction queue_async_depth_showfunction queue_async_depth_storefunction queue_ra_showfunction queue_ra_storefunction queue_max_discard_sectors_storefunction queue_max_wzeroes_unmap_sectors_storefunction queue_max_sectors_storefunction queue_feature_storefunction queue_poll_showfunction queue_zoned_showfunction queue_nr_zones_showfunction queue_zoned_qd1_writes_showfunction queue_zoned_qd1_writes_storefunction queue_iostats_passthrough_showfunction queue_iostats_passthrough_storefunction queue_nomerges_showfunction queue_nomerges_storefunction queue_rq_affinity_showfunction queue_rq_affinity_storefunction queue_poll_delay_storefunction queue_poll_storefunction queue_io_timeout_showfunction queue_io_timeout_storefunction queue_wc_showfunction queue_wc_storefunction queue_var_store64function queue_wb_lat_showfunction queue_wb_lat_storefunction queue_attr_visiblefunction blk_mq_queue_attr_visiblefunction queue_attr_showfunction queue_attr_storefunction blk_queue_releasefunction blk_debugfs_removefunction blk_register_queuefunction blk_register_queue
Annotated Snippet
struct queue_sysfs_entry {
struct attribute attr;
ssize_t (*show)(struct gendisk *disk, char *page);
ssize_t (*show_limit)(struct gendisk *disk, char *page);
ssize_t (*store)(struct gendisk *disk, const char *page, size_t count);
int (*store_limit)(struct gendisk *disk, const char *page,
size_t count, struct queue_limits *lim);
};
static ssize_t
queue_var_show(unsigned long var, char *page)
{
return sysfs_emit(page, "%lu\n", var);
}
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;
}
static ssize_t queue_requests_show(struct gendisk *disk, char *page)
{
ssize_t ret;
mutex_lock(&disk->queue->elevator_lock);
ret = queue_var_show(disk->queue->nr_requests, page);
mutex_unlock(&disk->queue->elevator_lock);
return ret;
}
static ssize_t
queue_requests_store(struct gendisk *disk, const char *page, size_t count)
{
struct request_queue *q = disk->queue;
struct blk_mq_tag_set *set = q->tag_set;
struct elevator_tags *et = NULL;
unsigned int memflags;
unsigned long nr;
int ret;
ret = queue_var_store(&nr, page, count);
if (ret < 0)
return ret;
/*
* Serialize updating nr_requests with concurrent queue_requests_store()
* and switching elevator.
*
* Use trylock to avoid circular lock dependency with kernfs active
* reference during concurrent disk deletion:
* update_nr_hwq_lock -> kn->active (via del_gendisk -> kobject_del)
* kn->active -> update_nr_hwq_lock (via this sysfs write path)
*/
if (!down_write_trylock(&set->update_nr_hwq_lock))
return -EBUSY;
if (nr == q->nr_requests)
goto unlock;
if (nr < BLKDEV_MIN_RQ)
nr = BLKDEV_MIN_RQ;
/*
* Switching elevator is protected by update_nr_hwq_lock:
* - read lock is held from elevator sysfs attribute;
* - write lock is held from updating nr_hw_queues;
* Hence it's safe to access q->elevator here with write lock held.
*/
if (nr <= set->reserved_tags ||
(q->elevator && nr > MAX_SCHED_RQ) ||
(!q->elevator && nr > set->queue_depth)) {
ret = -EINVAL;
goto unlock;
}
if (!blk_mq_is_shared_tags(set->flags) && q->elevator &&
nr > q->elevator->et->nr_requests) {
/*
* Tags will grow, allocate memory before freezing queue to
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/slab.h`, `linux/module.h`, `linux/bio.h`, `linux/blkdev.h`, `linux/backing-dev.h`, `linux/blktrace_api.h`, `linux/debugfs.h`.
- Detected declarations: `struct queue_sysfs_entry`, `function queue_var_show`, `function queue_var_store`, `function queue_requests_show`, `function queue_requests_store`, `function queue_async_depth_show`, `function queue_async_depth_store`, `function queue_ra_show`, `function queue_ra_store`, `function queue_max_discard_sectors_store`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.