block/genhd.c
Source file repositories/reference/linux-study-clean/block/genhd.c
File Facts
- System
- Linux kernel
- Corpus path
block/genhd.c- Extension
.c- Size
- 41802 bytes
- Lines
- 1589
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/ctype.hlinux/fs.hlinux/kdev_t.hlinux/kernel.hlinux/blkdev.hlinux/backing-dev.hlinux/init.hlinux/spinlock.hlinux/proc_fs.hlinux/seq_file.hlinux/slab.hlinux/kmod.hlinux/major.hlinux/mutex.hlinux/idr.hlinux/log2.hlinux/pm_runtime.hlinux/badblocks.hlinux/part_stat.hlinux/blktrace_api.hblk-throttle.hblk.hblk-mq-sched.hblk-rq-qos.hblk-cgroup.h
Detected Declarations
function set_capacityfunction set_capacity_and_notifyfunction part_stat_read_allfunction bdev_count_inflight_rwfunction for_each_possible_cpufunction bdev_count_inflightfunction major_to_indexfunction blkdev_showfunction add_diskfunction unregister_blkdevfunction blk_alloc_ext_minorfunction blk_free_ext_minorfunction disk_ueventfunction disk_scan_partitionsfunction add_disk_finalfunction __add_diskfunction add_disk_fwnodefunction device_add_diskfunction blk_report_disk_deadfunction __blk_mark_disk_deadfunction deadfunction __del_gendiskfunction disable_elv_switchfunction device_add_diskfunction invalidate_diskfunction disk_badblocks_showfunction disk_badblocks_storefunction blk_probe_devfunction blk_request_modulefunction disk_seqf_stopfunction show_partitionfunction genhd_device_initfunction disk_range_showfunction disk_ext_range_showfunction disk_removable_showfunction disk_hidden_showfunction disk_ro_showfunction part_size_showfunction part_stat_showfunction part_inflight_showfunction disk_capability_showfunction disk_alignment_offset_showfunction disk_discard_alignment_showfunction diskseq_showfunction partscan_showfunction part_fail_showfunction part_fail_storefunction disk_visible
Annotated Snippet
ret = device_add(ddev);
if (ret)
goto out_free_ext_minor;
ret = disk_alloc_events(disk);
if (ret)
goto out_device_del;
ret = sysfs_create_link(block_depr, &ddev->kobj,
kobject_name(&ddev->kobj));
if (ret)
goto out_device_del;
/*
* avoid probable deadlock caused by allocating memory with
* GFP_KERNEL in runtime_resume callback of its all ancestor
* devices
*/
pm_runtime_set_memalloc_noio(ddev, true);
disk->part0->bd_holder_dir =
kobject_create_and_add("holders", &ddev->kobj);
if (!disk->part0->bd_holder_dir) {
ret = -ENOMEM;
goto out_del_block_link;
}
disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
if (!disk->slave_dir) {
ret = -ENOMEM;
goto out_put_holder_dir;
}
ret = blk_register_queue(disk);
if (ret)
goto out_put_slave_dir;
if (!(disk->flags & GENHD_FL_HIDDEN)) {
ret = bdi_register(disk->bdi, "%u:%u",
disk->major, disk->first_minor);
if (ret)
goto out_unregister_queue;
bdi_set_owner(disk->bdi, ddev);
ret = sysfs_create_link(&ddev->kobj,
&disk->bdi->dev->kobj, "bdi");
if (ret)
goto out_unregister_bdi;
} else {
/*
* Even if the block_device for a hidden gendisk is not
* registered, it needs to have a valid bd_dev so that the
* freeing of the dynamic major works.
*/
disk->part0->bd_dev = MKDEV(disk->major, disk->first_minor);
}
return 0;
out_unregister_bdi:
if (!(disk->flags & GENHD_FL_HIDDEN))
bdi_unregister(disk->bdi);
out_unregister_queue:
blk_unregister_queue(disk);
rq_qos_exit(disk->queue);
out_put_slave_dir:
kobject_put(disk->slave_dir);
disk->slave_dir = NULL;
out_put_holder_dir:
kobject_put(disk->part0->bd_holder_dir);
out_del_block_link:
sysfs_remove_link(block_depr, dev_name(ddev));
pm_runtime_set_memalloc_noio(ddev, false);
out_device_del:
device_del(ddev);
out_free_ext_minor:
if (disk->major == BLOCK_EXT_MAJOR)
blk_free_ext_minor(disk->first_minor);
out:
return ret;
}
/**
* add_disk_fwnode - add disk information to kernel list with fwnode
* @parent: parent device for the disk
* @disk: per-device partitioning information
* @groups: Additional per-device sysfs groups
* @fwnode: attached disk fwnode
*
* This function registers the partitioning information in @disk
* with the kernel. Also attach a fwnode to the disk device.
*/
int __must_check add_disk_fwnode(struct device *parent, struct gendisk *disk,
Annotation
- Immediate include surface: `linux/module.h`, `linux/ctype.h`, `linux/fs.h`, `linux/kdev_t.h`, `linux/kernel.h`, `linux/blkdev.h`, `linux/backing-dev.h`, `linux/init.h`.
- Detected declarations: `function set_capacity`, `function set_capacity_and_notify`, `function part_stat_read_all`, `function bdev_count_inflight_rw`, `function for_each_possible_cpu`, `function bdev_count_inflight`, `function major_to_index`, `function blkdev_show`, `function add_disk`, `function unregister_blkdev`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: integration 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.