drivers/block/zloop.c
Source file repositories/reference/linux-study-clean/drivers/block/zloop.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/zloop.c- Extension
.c- Size
- 42519 bytes
- Lines
- 1773
- Domain
- Driver Families
- Bucket
- drivers/block
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/blk-mq.hlinux/blkzoned.hlinux/pagemap.hlinux/miscdevice.hlinux/falloc.hlinux/mutex.hlinux/parser.hlinux/seq_file.hlinux/xattr.h
Detected Declarations
struct zloop_optionsstruct zloop_zonestruct zloop_devicestruct zloop_cmdenum zloop_zone_flagsfunction rq_zone_nofunction zloop_lru_rotate_open_zonefunction zloop_lru_remove_open_zonefunction zloop_can_open_zonefunction zonefunction list_for_each_entryfunction zloop_open_closed_or_empty_zonefunction zloop_do_open_zonefunction zloop_mark_fullfunction zloop_mark_emptyfunction zloop_update_seq_zonefunction zloop_open_zonefunction zloop_close_zonefunction zloop_reset_zonefunction zloop_reset_all_zonesfunction zloop_finish_zonefunction zloop_put_cmdfunction zloop_rw_completefunction zloop_do_rwfunction rq_for_each_bvecfunction zloop_seq_write_prepfunction zloop_queue_rqfunction zloop_rwfunction zloop_zone_is_activefunction zloop_record_safe_wpsfunction zloop_flushfunction zloop_handle_cmdfunction zloop_cmd_workfnfunction zloop_complete_rqfunction zloop_set_zone_append_sectorfunction zloop_queue_rqfunction zloop_openfunction zloop_report_zonesfunction zloop_free_diskfunction zloop_get_block_sizefunction zloop_init_zonefunction zloop_dev_existsfunction zloop_ctl_addfunction zloop_forget_cachefunction zloop_ctl_removefunction zloop_parse_optionsfunction zloop_ctl_writefunction zloop_ctl_show
Annotated Snippet
static const struct blk_mq_ops zloop_mq_ops = {
.queue_rq = zloop_queue_rq,
.complete = zloop_complete_rq,
};
static int zloop_open(struct gendisk *disk, blk_mode_t mode)
{
struct zloop_device *zlo = disk->private_data;
int ret;
ret = mutex_lock_killable(&zloop_ctl_mutex);
if (ret)
return ret;
if (zlo->state != Zlo_live)
ret = -ENXIO;
mutex_unlock(&zloop_ctl_mutex);
return ret;
}
static int zloop_report_zones(struct gendisk *disk, sector_t sector,
unsigned int nr_zones, struct blk_report_zones_args *args)
{
struct zloop_device *zlo = disk->private_data;
struct blk_zone blkz = {};
unsigned int first, i;
int ret;
first = disk_zone_no(disk, sector);
if (first >= zlo->nr_zones)
return 0;
nr_zones = min(nr_zones, zlo->nr_zones - first);
for (i = 0; i < nr_zones; i++) {
unsigned int zone_no = first + i;
struct zloop_zone *zone = &zlo->zones[zone_no];
mutex_lock(&zone->lock);
if (test_and_clear_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags)) {
ret = zloop_update_seq_zone(zlo, zone_no);
if (ret) {
mutex_unlock(&zone->lock);
return ret;
}
}
blkz.start = zone->start;
blkz.len = zlo->zone_size;
spin_lock(&zone->wp_lock);
blkz.wp = zone->wp;
spin_unlock(&zone->wp_lock);
blkz.cond = zone->cond;
if (test_bit(ZLOOP_ZONE_CONV, &zone->flags)) {
blkz.type = BLK_ZONE_TYPE_CONVENTIONAL;
blkz.capacity = zlo->zone_size;
} else {
blkz.type = BLK_ZONE_TYPE_SEQWRITE_REQ;
blkz.capacity = zlo->zone_capacity;
}
mutex_unlock(&zone->lock);
ret = disk_report_zone(disk, &blkz, i, args);
if (ret)
return ret;
}
return nr_zones;
}
static void zloop_free_disk(struct gendisk *disk)
{
struct zloop_device *zlo = disk->private_data;
unsigned int i;
blk_mq_free_tag_set(&zlo->tag_set);
for (i = 0; i < zlo->nr_zones; i++) {
struct zloop_zone *zone = &zlo->zones[i];
mapping_set_gfp_mask(zone->file->f_mapping,
zone->old_gfp_mask);
fput(zone->file);
}
fput(zlo->data_dir);
destroy_workqueue(zlo->workqueue);
kfree(zlo->base_dir);
kvfree(zlo);
Annotation
- Immediate include surface: `linux/module.h`, `linux/blk-mq.h`, `linux/blkzoned.h`, `linux/pagemap.h`, `linux/miscdevice.h`, `linux/falloc.h`, `linux/mutex.h`, `linux/parser.h`.
- Detected declarations: `struct zloop_options`, `struct zloop_zone`, `struct zloop_device`, `struct zloop_cmd`, `enum zloop_zone_flags`, `function rq_zone_no`, `function zloop_lru_rotate_open_zone`, `function zloop_lru_remove_open_zone`, `function zloop_can_open_zone`, `function zone`.
- Atlas domain: Driver Families / drivers/block.
- Implementation status: pattern 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.