drivers/xen/xenbus/xenbus_xs.c
Source file repositories/reference/linux-study-clean/drivers/xen/xenbus/xenbus_xs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/xen/xenbus/xenbus_xs.c- Extension
.c- Size
- 21742 bytes
- Lines
- 928
- 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/unistd.hlinux/errno.hlinux/types.hlinux/uio.hlinux/kernel.hlinux/string.hlinux/err.hlinux/slab.hlinux/fcntl.hlinux/kthread.hlinux/reboot.hlinux/rwsem.hlinux/mutex.hasm/xen/hypervisor.hasm/cpuid/api.hxen/xenbus.hxen/xen.hxenbus.h
Detected Declarations
function xs_suspend_enterfunction xs_suspend_exitfunction xs_free_reqfunction xs_request_enterfunction xs_request_exitfunction get_errorfunction xenbus_okfunction test_replyfunction xs_sendfunction xs_wake_upfunction xenbus_dev_request_and_replyfunction xs_errorfunction count_stringsfunction xenbus_existsfunction xenbus_writefunction xenbus_rmfunction xenbus_transaction_startfunction xenbus_transaction_endfunction xenbus_scanffunction xenbus_read_unsignedfunction xenbus_printffunction xenbus_gatherfunction xs_watchfunction xs_unwatchfunction xs_watch_msgfunction xs_reset_watchesfunction register_xenbus_watchfunction unregister_xenbus_watchfunction list_for_each_entry_safefunction xs_suspendfunction xs_resumefunction xs_suspend_cancelfunction xenwatch_threadfunction xs_reboot_notifyfunction xs_initexport xenbus_dev_request_and_replyexport xenbus_directoryexport xenbus_existsexport xenbus_readexport xenbus_writeexport xenbus_rmexport xenbus_transaction_startexport xenbus_transaction_endexport xenbus_scanfexport xenbus_read_unsignedexport xenbus_printfexport xenbus_gatherexport register_xenbus_watch
Annotated Snippet
if (i == ARRAY_SIZE(xsd_errors) - 1) {
pr_warn("xen store gave: unknown error %s\n",
errorstring);
return EINVAL;
}
}
return xsd_errors[i].errnum;
}
static bool xenbus_ok(void)
{
switch (xen_store_domain_type) {
case XS_LOCAL:
switch (system_state) {
case SYSTEM_POWER_OFF:
case SYSTEM_RESTART:
case SYSTEM_HALT:
return false;
default:
break;
}
return true;
case XS_PV:
case XS_HVM:
/* FIXME: Could check that the remote domain is alive,
* but it is normally initial domain. */
return true;
default:
break;
}
return false;
}
static bool test_reply(struct xb_req_data *req)
{
if (req->state == xb_req_state_got_reply || !xenbus_ok()) {
/* read req->state before all other fields */
virt_rmb();
return true;
}
/* Make sure to reread req->state each time. */
barrier();
return false;
}
static void *read_reply(struct xb_req_data *req)
{
do {
wait_event(req->wq, test_reply(req));
if (!xenbus_ok())
/*
* If we are in the process of being shut-down there is
* no point of trying to contact XenBus - it is either
* killed (xenstored application) or the other domain
* has been killed or is unreachable.
*/
return ERR_PTR(-EIO);
if (req->err)
return ERR_PTR(req->err);
} while (req->state != xb_req_state_got_reply);
return req->body;
}
static void xs_send(struct xb_req_data *req, struct xsd_sockmsg *msg)
{
bool notify;
req->msg = *msg;
req->err = 0;
req->state = xb_req_state_queued;
init_waitqueue_head(&req->wq);
/* Save the caller req_id and restore it later in the reply */
req->caller_req_id = req->msg.req_id;
req->msg.req_id = xs_request_enter(req);
/*
* Take 2nd ref. One for this thread, and the second for the
* xenbus_thread.
*/
kref_get(&req->kref);
mutex_lock(&xb_write_mutex);
list_add_tail(&req->list, &xb_write_list);
notify = list_is_singular(&xb_write_list);
Annotation
- Immediate include surface: `linux/unistd.h`, `linux/errno.h`, `linux/types.h`, `linux/uio.h`, `linux/kernel.h`, `linux/string.h`, `linux/err.h`, `linux/slab.h`.
- Detected declarations: `function xs_suspend_enter`, `function xs_suspend_exit`, `function xs_free_req`, `function xs_request_enter`, `function xs_request_exit`, `function get_error`, `function xenbus_ok`, `function test_reply`, `function xs_send`, `function xs_wake_up`.
- 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.