drivers/block/null_blk/zoned.c
Source file repositories/reference/linux-study-clean/drivers/block/null_blk/zoned.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/null_blk/zoned.c- Extension
.c- Size
- 20383 bytes
- Lines
- 814
- Domain
- Driver Families
- Bucket
- drivers/block
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/vmalloc.hlinux/bitmap.hnull_blk.htrace.h
Detected Declarations
function mb_to_sectsfunction null_zone_nofunction null_init_zone_lockfunction null_lock_zonefunction null_unlock_zonefunction null_init_zoned_devfunction null_register_zoned_devfunction null_free_zoned_devfunction null_report_zonesfunction null_process_cmdfunction null_close_imp_open_zonefunction null_check_activefunction null_check_openfunction supportfunction null_zone_writefunction null_open_zonefunction null_close_zonefunction null_finish_zonefunction null_reset_zonefunction null_zone_mgmtfunction null_process_zoned_cmdfunction null_set_zone_condfunction zone_cond_store
Annotated Snippet
if (dev->zone_full) {
zone->cond = BLK_ZONE_COND_FULL;
zone->wp = zone->start + zone->capacity;
} else{
zone->cond = BLK_ZONE_COND_EMPTY;
zone->wp = zone->start;
}
sector += dev->zone_size_sects;
}
lim->features |= BLK_FEAT_ZONED;
lim->chunk_sectors = dev->zone_size_sects;
lim->max_hw_zone_append_sectors = dev->zone_append_max_sectors;
lim->max_open_zones = dev->zone_max_open;
lim->max_active_zones = dev->zone_max_active;
return 0;
}
int null_register_zoned_dev(struct nullb *nullb)
{
struct request_queue *q = nullb->q;
struct gendisk *disk = nullb->disk;
pr_info("%s: using %s zone append\n",
disk->disk_name,
queue_emulates_zone_append(q) ? "emulated" : "native");
return blk_revalidate_disk_zones(disk);
}
void null_free_zoned_dev(struct nullb_device *dev)
{
kvfree(dev->zones);
dev->zones = NULL;
}
int null_report_zones(struct gendisk *disk, sector_t sector,
unsigned int nr_zones, struct blk_report_zones_args *args)
{
struct nullb *nullb = disk->private_data;
struct nullb_device *dev = nullb->dev;
unsigned int first_zone, i;
struct nullb_zone *zone;
struct blk_zone blkz;
int error;
first_zone = null_zone_no(dev, sector);
if (first_zone >= dev->nr_zones)
return 0;
nr_zones = min(nr_zones, dev->nr_zones - first_zone);
trace_nullb_report_zones(nullb, nr_zones);
memset(&blkz, 0, sizeof(struct blk_zone));
zone = &dev->zones[first_zone];
for (i = 0; i < nr_zones; i++, zone++) {
/*
* Stacked DM target drivers will remap the zone information by
* modifying the zone information passed to the report callback.
* So use a local copy to avoid corruption of the device zone
* array.
*/
null_lock_zone(dev, zone);
blkz.start = zone->start;
blkz.len = zone->len;
blkz.wp = zone->wp;
blkz.type = zone->type;
blkz.cond = zone->cond;
blkz.capacity = zone->capacity;
null_unlock_zone(dev, zone);
error = disk_report_zone(disk, &blkz, i, args);
if (error)
return error;
}
return nr_zones;
}
/*
* This is called in the case of memory backing from null_process_cmd()
* with the target zone already locked.
*/
size_t null_zone_valid_read_len(struct nullb *nullb,
sector_t sector, unsigned int len)
{
struct nullb_device *dev = nullb->dev;
struct nullb_zone *zone = &dev->zones[null_zone_no(dev, sector)];
unsigned int nr_sectors = DIV_ROUND_UP(len, SECTOR_SIZE);
Annotation
- Immediate include surface: `linux/vmalloc.h`, `linux/bitmap.h`, `null_blk.h`, `trace.h`.
- Detected declarations: `function mb_to_sects`, `function null_zone_no`, `function null_init_zone_lock`, `function null_lock_zone`, `function null_unlock_zone`, `function null_init_zoned_dev`, `function null_register_zoned_dev`, `function null_free_zoned_dev`, `function null_report_zones`, `function null_process_cmd`.
- Atlas domain: Driver Families / drivers/block.
- 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.