drivers/block/xen-blkback/xenbus.c
Source file repositories/reference/linux-study-clean/drivers/block/xen-blkback/xenbus.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/xen-blkback/xenbus.c- Extension
.c- Size
- 30118 bytes
- Lines
- 1177
- 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/module.hlinux/kthread.hlinux/pagemap.hxen/events.hxen/grant_table.hcommon.h
Detected Declarations
struct backend_infofunction xen_blkif_freefunction blkback_namefunction xen_update_blkif_statusfunction xen_blkif_alloc_ringsfunction xen_blkif_mapfunction xen_blkif_disconnectfunction list_for_each_entry_safefunction xen_blkif_freefunction xen_blkif_interface_initfunction xen_blkif_interface_finifunction xenvbd_sysfs_addiffunction xenvbd_sysfs_deliffunction xen_vbd_freefunction xen_vbd_createfunction xen_blkbk_removefunction xen_blkbk_flush_diskcachefunction xen_blkbk_discardfunction xen_blkbk_barrierfunction xen_blkbk_probefunction backend_changedfunction frontend_changedfunction reclaim_memoryfunction connectfunction read_per_ring_refsfunction connect_ringfunction xen_blkif_xenbus_initfunction xen_blkif_xenbus_fini
Annotated Snippet
struct backend_info {
struct xenbus_device *dev;
struct xen_blkif *blkif;
struct xenbus_watch backend_watch;
unsigned major;
unsigned minor;
char *mode;
};
static struct kmem_cache *xen_blkif_cachep;
static void connect(struct backend_info *);
static int connect_ring(struct backend_info *);
static void backend_changed(struct xenbus_watch *, const char *,
const char *);
static void xen_blkif_free(struct xen_blkif *blkif);
static void xen_vbd_free(struct xen_vbd *vbd);
struct xenbus_device *xen_blkbk_xenbus(struct backend_info *be)
{
return be->dev;
}
/*
* The last request could free the device from softirq context and
* xen_blkif_free() can sleep.
*/
static void xen_blkif_deferred_free(struct work_struct *work)
{
struct xen_blkif *blkif;
blkif = container_of(work, struct xen_blkif, free_work);
xen_blkif_free(blkif);
}
static int blkback_name(struct xen_blkif *blkif, char *buf)
{
char *devpath, *devname;
struct xenbus_device *dev = blkif->be->dev;
devpath = xenbus_read(XBT_NIL, dev->nodename, "dev", NULL);
if (IS_ERR(devpath))
return PTR_ERR(devpath);
devname = strstr(devpath, "/dev/");
if (devname != NULL)
devname += strlen("/dev/");
else
devname = devpath;
snprintf(buf, TASK_COMM_LEN, "%d.%s", blkif->domid, devname);
kfree(devpath);
return 0;
}
static void xen_update_blkif_status(struct xen_blkif *blkif)
{
int err;
char name[TASK_COMM_LEN];
struct xen_blkif_ring *ring;
int i;
/* Not ready to connect? */
if (!blkif->rings || !blkif->rings[0].irq || !blkif->vbd.bdev_file)
return;
/* Already connected? */
if (blkif->be->dev->state == XenbusStateConnected)
return;
/* Attempt to connect: exit if we fail to. */
connect(blkif->be);
if (blkif->be->dev->state != XenbusStateConnected)
return;
err = blkback_name(blkif, name);
if (err) {
xenbus_dev_error(blkif->be->dev, err, "get blkback dev name");
return;
}
err = sync_blockdev(file_bdev(blkif->vbd.bdev_file));
if (err) {
xenbus_dev_error(blkif->be->dev, err, "block flush");
return;
}
invalidate_inode_pages2(blkif->vbd.bdev_file->f_mapping);
for (i = 0; i < blkif->nr_rings; i++) {
ring = &blkif->rings[i];
Annotation
- Immediate include surface: `linux/module.h`, `linux/kthread.h`, `linux/pagemap.h`, `xen/events.h`, `xen/grant_table.h`, `common.h`.
- Detected declarations: `struct backend_info`, `function xen_blkif_free`, `function blkback_name`, `function xen_update_blkif_status`, `function xen_blkif_alloc_rings`, `function xen_blkif_map`, `function xen_blkif_disconnect`, `function list_for_each_entry_safe`, `function xen_blkif_free`, `function xen_blkif_interface_init`.
- 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.