drivers/xen/xenbus/xenbus_client.c
Source file repositories/reference/linux-study-clean/drivers/xen/xenbus/xenbus_client.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/xen/xenbus/xenbus_client.c- Extension
.c- Size
- 25866 bytes
- Lines
- 975
- Domain
- Driver Families
- Bucket
- drivers/xen
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- 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/mm.hlinux/slab.hlinux/types.hlinux/spinlock.hlinux/vmalloc.hlinux/export.hasm/xen/hypervisor.hxen/page.hxen/interface/xen.hxen/interface/event_channel.hxen/balloon.hxen/events.hxen/grant_table.hxen/xenbus.hxen/xen.hxen/features.hxenbus.h
Detected Declarations
struct xenbus_map_nodestruct map_ring_vallocstruct xenbus_ring_opsstruct unmap_ring_hvmfunction xenbus_watch_pathfunction xenbus_watch_pathfmtfunction __xenbus_switch_statefunction xenbus_switch_statefunction xenbus_frontend_closedfunction xenbus_va_dev_errorfunction xenbus_dev_errorfunction xenbus_dev_errorfunction xenbus_dev_fatalfunction xenbus_setup_ringfunction xenbus_teardown_ringfunction xenbus_alloc_evtchnfunction xenbus_free_evtchnfunction xenbus_map_ring_vallocfunction __xenbus_map_ringfunction xenbus_unmap_ringfunction xenbus_map_ring_setup_grant_hvmfunction xenbus_map_ring_hvmfunction xenbus_map_ring_vallocfunction map_ring_applyfunction xenbus_map_ring_pvfunction xenbus_unmap_ring_pvfunction xenbus_unmap_ring_setup_grant_hvmfunction xenbus_unmap_ring_hvmfunction xenbus_read_driver_statefunction xenbus_ring_ops_initexport xenbus_strstateexport xenbus_watch_pathexport xenbus_watch_pathfmtexport xenbus_switch_stateexport xenbus_frontend_closedexport xenbus_dev_errorexport xenbus_dev_fatalexport xenbus_setup_ringexport xenbus_teardown_ringexport xenbus_alloc_evtchnexport xenbus_free_evtchnexport xenbus_map_ring_vallocexport xenbus_unmap_ring_vfreeexport xenbus_read_driver_state
Annotated Snippet
struct xenbus_map_node {
struct list_head next;
union {
struct {
struct vm_struct *area;
} pv;
struct {
struct page *pages[XENBUS_MAX_RING_PAGES];
unsigned long addrs[XENBUS_MAX_RING_GRANTS];
void *addr;
} hvm;
};
grant_handle_t handles[XENBUS_MAX_RING_GRANTS];
unsigned int nr_handles;
};
struct map_ring_valloc {
struct xenbus_map_node *node;
/* Why do we need two arrays? See comment of __xenbus_map_ring */
unsigned long addrs[XENBUS_MAX_RING_GRANTS];
phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS];
struct gnttab_map_grant_ref map[XENBUS_MAX_RING_GRANTS];
struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS];
unsigned int idx;
};
static DEFINE_SPINLOCK(xenbus_valloc_lock);
static LIST_HEAD(xenbus_valloc_pages);
struct xenbus_ring_ops {
int (*map)(struct xenbus_device *dev, struct map_ring_valloc *info,
grant_ref_t *gnt_refs, unsigned int nr_grefs,
void **vaddr);
int (*unmap)(struct xenbus_device *dev, void *vaddr);
};
static const struct xenbus_ring_ops *ring_ops __read_mostly;
const char *xenbus_strstate(enum xenbus_state state)
{
static const char *const name[] = {
[ XenbusStateUnknown ] = "Unknown",
[ XenbusStateInitialising ] = "Initialising",
[ XenbusStateInitWait ] = "InitWait",
[ XenbusStateInitialised ] = "Initialised",
[ XenbusStateConnected ] = "Connected",
[ XenbusStateClosing ] = "Closing",
[ XenbusStateClosed ] = "Closed",
[XenbusStateReconfiguring] = "Reconfiguring",
[XenbusStateReconfigured] = "Reconfigured",
};
return (state < ARRAY_SIZE(name)) ? name[state] : "INVALID";
}
EXPORT_SYMBOL_GPL(xenbus_strstate);
/**
* xenbus_watch_path - register a watch
* @dev: xenbus device
* @path: path to watch
* @watch: watch to register
* @will_handle: events queuing determine callback
* @callback: callback to register
*
* Register a @watch on the given path, using the given xenbus_watch structure
* for storage, @will_handle function as the callback to determine if each
* event need to be queued, and the given @callback function as the callback.
* On success, the given @path will be saved as @watch->node, and remains the
* caller's to free. On error, @watch->node will be NULL, the device will
* switch to %XenbusStateClosing, and the error will be saved in the store.
*
* Returns: %0 on success or -errno on error
*/
int xenbus_watch_path(struct xenbus_device *dev, const char *path,
struct xenbus_watch *watch,
bool (*will_handle)(struct xenbus_watch *,
const char *, const char *),
void (*callback)(struct xenbus_watch *,
const char *, const char *))
{
int err;
watch->node = path;
watch->will_handle = will_handle;
watch->callback = callback;
err = register_xenbus_watch(watch);
Annotation
- Immediate include surface: `linux/mm.h`, `linux/slab.h`, `linux/types.h`, `linux/spinlock.h`, `linux/vmalloc.h`, `linux/export.h`, `asm/xen/hypervisor.h`, `xen/page.h`.
- Detected declarations: `struct xenbus_map_node`, `struct map_ring_valloc`, `struct xenbus_ring_ops`, `struct unmap_ring_hvm`, `function xenbus_watch_path`, `function xenbus_watch_pathfmt`, `function __xenbus_switch_state`, `function xenbus_switch_state`, `function xenbus_frontend_closed`, `function xenbus_va_dev_error`.
- Atlas domain: Driver Families / drivers/xen.
- 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.