FreeBSD kernel /amd64 XEN device code
|
XenStore interface. More...
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/sx.h>
#include <sys/syslog.h>
#include <sys/malloc.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/kthread.h>
#include <sys/sbuf.h>
#include <sys/sysctl.h>
#include <sys/uio.h>
#include <sys/unistd.h>
#include <sys/queue.h>
#include <sys/taskqueue.h>
#include <machine/stdarg.h>
#include <xen/xen-os.h>
#include <xen/hypervisor.h>
#include <xen/xen_intr.h>
#include <contrib/xen/hvm/params.h>
#include <xen/hvm.h>
#include <xen/xenstore/xenstorevar.h>
#include <xen/xenstore/xenstore_internal.h>
#include <vm/vm.h>
#include <vm/pmap.h>
Go to the source code of this file.
Data Structures | |
struct | xs_stored_msg |
struct | xs_softc |
Macros | |
#define | xsd_error_count (sizeof(xsd_errors) / sizeof(xsd_errors[0])) |
Functions | |
__FBSDID ("$FreeBSD$") | |
static struct xs_watch * | find_watch (const char *token) |
MALLOC_DEFINE (M_XENSTORE, "xenstore", "XenStore data and results") | |
TAILQ_HEAD (xs_stored_msg_list, xs_stored_msg) | |
static u_int | extract_strings (const char *strings, const char **dest, u_int len) |
static const char ** | split (char *strings, u_int len, u_int *num) |
struct sbuf * | xs_join (const char *dir, const char *name) |
static void | xs_intr (void *arg __unused) |
static int | xs_check_indexes (XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod) |
static void * | xs_get_output_chunk (XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod, char *buf, uint32_t *len) |
static const void * | xs_get_input_chunk (XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod, const char *buf, uint32_t *len) |
static int | xs_write_store (const void *tdata, unsigned len) |
static int | xs_read_store (void *tdata, unsigned len) |
static int | xs_process_msg (enum xsd_sockmsg_type *type) |
static void | xs_rcv_thread (void *arg __unused) |
static int | xs_get_error (const char *errorstring) |
static int | xs_read_reply (enum xsd_sockmsg_type *type, u_int *len, void **result) |
int | xs_dev_request_and_reply (struct xsd_sockmsg *msg, void **result) |
static int | xs_talkv (struct xs_transaction t, enum xsd_sockmsg_type request_type, const struct iovec *iovec, u_int num_vecs, u_int *len, void **result) |
static int | xs_single (struct xs_transaction t, enum xsd_sockmsg_type request_type, const char *body, u_int *len, void **result) |
static int | xs_watch (const char *path, const char *token) |
static int | xs_unwatch (const char *path, const char *token) |
static void | xenwatch_thread (void *unused) |
static int | xs_init_comms (void) |
static void | xs_identify (driver_t *driver, device_t parent) |
static int | xs_probe (device_t dev) |
static void | xs_attach_deferred (void *arg) |
static void | xs_attach_late (void *arg, int pending) |
static int | xs_attach (device_t dev) |
static int | xs_suspend (device_t dev) |
static int | xs_resume (device_t dev __unused) |
DEFINE_CLASS_0 (xenstore, xenstore_driver, xenstore_methods, 0) | |
DRIVER_MODULE (xenstore, xenpv, xenstore_driver, xenstore_devclass, 0, 0) | |
SYSCTL_NODE (_dev, OID_AUTO, xen, CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, "Xen") | |
SYSCTL_INT (_dev_xen, OID_AUTO, xsd_port, CTLFLAG_RD, &xs.evtchn, 0, "") | |
SYSCTL_ULONG (_dev_xen, OID_AUTO, xsd_kva, CTLFLAG_RD,(u_long *) &xen_store, 0, "") | |
bool | xs_initialized (void) |
evtchn_port_t | xs_evtchn (void) |
vm_paddr_t | xs_address (void) |
int | xs_directory (struct xs_transaction t, const char *dir, const char *node, u_int *num, const char ***result) |
int | xs_exists (struct xs_transaction t, const char *dir, const char *node) |
int | xs_read (struct xs_transaction t, const char *dir, const char *node, u_int *len, void **result) |
int | xs_write (struct xs_transaction t, const char *dir, const char *node, const char *string) |
int | xs_mkdir (struct xs_transaction t, const char *dir, const char *node) |
int | xs_rm (struct xs_transaction t, const char *dir, const char *node) |
int | xs_rm_tree (struct xs_transaction xbt, const char *base, const char *node) |
int | xs_transaction_start (struct xs_transaction *t) |
int | xs_transaction_end (struct xs_transaction t, int abort) |
int | xs_scanf (struct xs_transaction t, const char *dir, const char *node, int *scancountp, const char *fmt,...) |
int | xs_vprintf (struct xs_transaction t, const char *dir, const char *node, const char *fmt, va_list ap) |
int | xs_printf (struct xs_transaction t, const char *dir, const char *node, const char *fmt,...) |
int | xs_gather (struct xs_transaction t, const char *dir,...) |
int | xs_register_watch (struct xs_watch *watch) |
void | xs_unregister_watch (struct xs_watch *watch) |
void | xs_lock (void) |
void | xs_unlock (void) |
Variables | |
static struct xenstore_domain_interface * | xen_store |
static struct xs_softc | xs |
static device_method_t | xenstore_methods [] |
static devclass_t | xenstore_devclass |
XenStore interface.
The XenStore interface is a simple storage system that is a means of communicating state and configuration data between the Xen Domain 0 and the various guest domains. All configuration data other than a small amount of essential information required during the early boot process of launching a Xen aware guest, is managed using the XenStore.
The XenStore is ASCII string based, and has a structure and semantics similar to a filesystem. There are files and directories, the directories able to contain files or other directories. The depth of the hierarchy is only limited by the XenStore's maximum path length.
The communication channel between the XenStore service and other domains is via two, guest specific, ring buffers in a shared memory area. One ring buffer is used for communicating in each direction. The grant table references for this shared memory are given to the guest either via the xen_start_info structure for a fully para- virtualized guest, or via HVM hypercalls for a hardware virtualized guest.
The XenStore communication relies on an event channel and thus interrupts. For this reason, the attachment of the XenStore relies on an interrupt driven configuration hook to hold off boot processing until communication with the XenStore service can be established.
Several Xen services depend on the XenStore, most notably the XenBus used to discover and manage Xen devices. These services are implemented as NewBus child attachments to a bus exported by this XenStore driver.
Definition in file xenstore.c.
#define xsd_error_count (sizeof(xsd_errors) / sizeof(xsd_errors[0])) |
Definition at line 705 of file xenstore.c.
__FBSDID | ( | "$FreeBSD$" | ) |
DEFINE_CLASS_0 | ( | xenstore | , |
xenstore_driver | , | ||
xenstore_methods | , | ||
0 | |||
) |
DRIVER_MODULE | ( | xenstore | , |
xenpv | , | ||
xenstore_driver | , | ||
xenstore_devclass | , | ||
0 | , | ||
0 | |||
) |
|
static |
Count and optionally record pointers to a number of NUL terminated strings in a buffer.
strings | A pointer to a contiguous buffer of NUL terminated strings. |
dest | An array to store pointers to each string found in strings. |
len | The length of the buffer pointed to by strings. |
Definition at line 273 of file xenstore.c.
Referenced by split().
|
static |
Convert from watch token (unique identifier) to the associated internal tracking structure for this watch.
tocken | The unique identifier for the watch to find. |
Definition at line 953 of file xenstore.c.
References xs_softc::registered_watches, xs, and xs_watch().
Referenced by xs_process_msg(), xs_register_watch(), and xs_unregister_watch().
MALLOC_DEFINE | ( | M_XENSTORE | , |
"xenstore" | , | ||
"XenStore data and results" | |||
) |
|
static |
Convert a contiguous buffer containing a series of NUL terminated strings into an array of pointers to strings.
The returned pointer references the array of string pointers which is followed by the storage for the string data. It is the client's responsibility to free this storage.
The storage addressed by strings is free'd prior to split returning.
strings | A pointer to a contiguous buffer of NUL terminated strings. |
len | The length of the buffer pointed to by strings. |
num | The number of strings found and returned in the strings array. |
Definition at line 305 of file xenstore.c.
References extract_strings().
Referenced by xs_directory(), and xs_process_msg().
SYSCTL_INT | ( | _dev_xen | , |
OID_AUTO | , | ||
xsd_port | , | ||
CTLFLAG_RD | , | ||
&xs. | evtchn, | ||
0 | , | ||
"" | |||
) |
SYSCTL_NODE | ( | _dev | , |
OID_AUTO | , | ||
xen | , | ||
CTLFLAG_RD| | CTLFLAG_MPSAFE, | ||
NULL | , | ||
"Xen" | |||
) |
SYSCTL_ULONG | ( | _dev_xen | , |
OID_AUTO | , | ||
xsd_kva | , | ||
CTLFLAG_RD | , | ||
(u_long *) & | xen_store, | ||
0 | , | ||
"" | |||
) |
TAILQ_HEAD | ( | xs_stored_msg_list | , |
xs_stored_msg | |||
) |
|
static |
Thread body of the XenStore watch event dispatch thread.
Definition at line 970 of file xenstore.c.
References xs_stored_msg::u, xs_softc::watch_events, xs_softc::watch_events_lock, xs_softc::xenwatch_mutex, and xs.
Referenced by xs_attach().
vm_paddr_t xs_address | ( | void | ) |
Definition at line 1268 of file xenstore.c.
References xs_softc::gpfn, and xs.
Referenced by xsd_dev_mmap().
|
static |
Attach to the XenStore.
This routine also prepares for the probe/attach of drivers that rely on the XenStore.
Definition at line 1096 of file xenstore.c.
References xs_softc::evtchn, xs_softc::gpfn, xs_softc::initialized, xs_softc::registered_watches_lock, xs_softc::reply_list, xs_softc::reply_lock, xs_softc::request_mutex, xs_softc::ring_lock, xs_softc::watch_events, xs_softc::watch_events_lock, xen_store, xs_softc::xenwatch_mutex, xs_softc::xenwatch_pid, xenwatch_thread(), xs, xs_attach_deferred(), xs_attach_late(), xs_softc::xs_attachcb, xs_softc::xs_dev, xs_init_comms(), xs_softc::xs_late_init, and xs_rcv_thread().
|
static |
Definition at line 1071 of file xenstore.c.
References xs, xs_softc::xs_attachcb, and xs_softc::xs_dev.
Referenced by xs_attach().
|
static |
Definition at line 1081 of file xenstore.c.
References xs, and xs_softc::xs_dev.
Referenced by xs_attach().
|
static |
Verify that the indexes for a ring are valid.
The difference between the producer and consumer cannot exceed the size of the ring.
cons | The consumer index for the ring to test. |
prod | The producer index for the ring to test. |
1 | If indexes are in range. |
0 | If the indexes are out of range. |
Definition at line 390 of file xenstore.c.
Referenced by xs_read_store(), and xs_write_store().
int xs_dev_request_and_reply | ( | struct xsd_sockmsg * | msg, |
void ** | result | ||
) |
Pass-thru interface for XenStore access by userland processes via the XenStore device.
Reply type and length data are returned by overwriting these fields in the passed in request message.
msg | A properly formatted message to transmit to the XenStore service. |
result | The returned body of the reply. |
Definition at line 788 of file xenstore.c.
References xs_softc::request_mutex, xs, xs_read_reply(), and xs_write_store().
Referenced by xs_dev_write().
int xs_directory | ( | struct xs_transaction | t, |
const char * | dir, | ||
const char * | node, | ||
u_int * | num, | ||
const char *** | result | ||
) |
Definition at line 1275 of file xenstore.c.
References split(), xs_join(), and xs_single().
Referenced by xs_exists(), and xs_rm_tree().
evtchn_port_t xs_evtchn | ( | void | ) |
Definition at line 1261 of file xenstore.c.
References xs_softc::evtchn, and xs.
Referenced by xsd_dev_read().
int xs_exists | ( | struct xs_transaction | t, |
const char * | dir, | ||
const char * | node | ||
) |
Definition at line 1296 of file xenstore.c.
References xs_directory().
int xs_gather | ( | struct xs_transaction | t, |
const char * | dir, | ||
... | |||
) |
Definition at line 1548 of file xenstore.c.
References xs_read().
Referenced by xbb_attach_cb(), xbb_collect_frontend_info(), xbd_connect(), and xnb_collect_xenstore_info().
|
static |
Convert a XenStore error string into an errno number.
errorstring | The error string to convert. |
Definition at line 717 of file xenstore.c.
References xsd_error_count.
Referenced by xs_talkv().
|
static |
Return a pointer to, and the length of, the contiguous data available to read from a ring buffer.
cons | The consumer index for the ring. |
prod | The producer index for the ring. |
buf | The base address of the ring's storage. |
len | The amount of contiguous data available to read. |
Definition at line 430 of file xenstore.c.
References buf.
Referenced by xs_read_store().
|
static |
Return a pointer to, and the length of, the contiguous free region available for output in a ring buffer.
cons | The consumer index for the ring. |
prod | The producer index for the ring. |
buf | The base address of the ring's storage. |
len | The amount of contiguous storage available. |
Definition at line 408 of file xenstore.c.
References buf.
Referenced by xs_write_store().
|
static |
Definition at line 1046 of file xenstore.c.
|
static |
Setup communication channels with the XenStore service.
Definition at line 1020 of file xenstore.c.
References xs_softc::evtchn, xs_softc::xen_intr_handle, xen_store, xs, xs_softc::xs_dev, and xs_intr().
Referenced by xs_attach(), and xs_resume().
bool xs_initialized | ( | void | ) |
Definition at line 1254 of file xenstore.c.
References xs_softc::initialized, and xs.
Referenced by xsd_dev_identify().
|
static |
Interrupt handler for the XenStore event channel.
XenStore reads and writes block on "xen_store" for buffer space. Wakeup any blocking operations when the XenStore service has modified the queues.
Definition at line 355 of file xenstore.c.
References xs_softc::initialized, xs_softc::ring_lock, xen_store, xs, and xs_softc::xs_late_init.
Referenced by xs_init_comms().
struct sbuf * xs_join | ( | const char * | dir, |
const char * | name | ||
) |
Definition at line 331 of file xenstore.c.
Referenced by xbb_attach(), xs_directory(), xs_mkdir(), xs_read(), xs_rm(), xs_rm_tree(), and xs_write().
void xs_lock | ( | void | ) |
Definition at line 1648 of file xenstore.c.
References xs_softc::request_mutex, and xs.
int xs_mkdir | ( | struct xs_transaction | t, |
const char * | dir, | ||
const char * | node | ||
) |
Definition at line 1347 of file xenstore.c.
References xs_join(), and xs_single().
int xs_printf | ( | struct xs_transaction | t, |
const char * | dir, | ||
const char * | node, | ||
const char * | fmt, | ||
... | |||
) |
Definition at line 1534 of file xenstore.c.
References xs_vprintf().
Referenced by talk_to_backend(), write_queue_xenstore_keys(), xbb_attach(), xbb_attach_disk(), xbb_attach_failed(), xbb_publish_backend_info(), xbd_alloc_ring(), xbd_initialize(), xnb_attach(), xnb_attach_failed(), and xnb_publish_backend_info().
|
static |
|
static |
Block reading the next message from the XenStore service and process the result.
type | The returned type of the XenStore message received. |
Definition at line 628 of file xenstore.c.
References find_watch(), xs_softc::registered_watches_lock, xs_softc::reply_list, xs_softc::reply_lock, split(), xs_stored_msg::u, xs_softc::watch_events, xs_softc::watch_events_lock, xs, and xs_read_store().
Referenced by xs_rcv_thread().
|
static |
Thread body of the XenStore receive thread.
This thread blocks waiting for data from the XenStore service and processes and received messages.
Definition at line 691 of file xenstore.c.
References xs_process_msg().
Referenced by xs_attach().
int xs_read | ( | struct xs_transaction | t, |
const char * | dir, | ||
const char * | node, | ||
u_int * | len, | ||
void ** | result | ||
) |
Definition at line 1309 of file xenstore.c.
References xs_join(), and xs_single().
Referenced by xbd_probe(), xctrl_on_watch_event(), xen_net_read_mac(), xnb_collect_xenstore_info(), xs_gather(), and xs_scanf().
|
static |
Block waiting for a reply to a message request.
type | The returned type of the reply. |
len | The returned body length of the reply. |
result | The returned body of the reply. |
Definition at line 741 of file xenstore.c.
References xs_softc::reply_list, xs_softc::reply_lock, xs_stored_msg::u, and xs.
Referenced by xs_dev_request_and_reply(), and xs_talkv().
|
static |
Receive data from the XenStore service.
tdata | A pointer to the contiguous buffer to receive the data. |
len | The amount of data to receive. |
Definition at line 544 of file xenstore.c.
References xs_softc::ring_lock, xs_softc::xen_intr_handle, xen_store, xs, xs_check_indexes(), and xs_get_input_chunk().
Referenced by xs_process_msg().
int xs_register_watch | ( | struct xs_watch * | watch | ) |
Definition at line 1578 of file xenstore.c.
References find_watch(), xs_softc::registered_watches, xs_softc::registered_watches_lock, xs, and xs_watch().
Referenced by xbb_attach(), xctrl_attach(), xenballoon_attach(), and xs_dev_write().
|
static |
Resume XenStore operations after this VM is resumed.
Definition at line 1192 of file xenstore.c.
References xs_softc::registered_watches, xs_softc::request_mutex, xs, xs_init_comms(), and xs_watch().
int xs_rm | ( | struct xs_transaction | t, |
const char * | dir, | ||
const char * | node | ||
) |
Definition at line 1360 of file xenstore.c.
References xs_join(), and xs_single().
Referenced by xn_ioctl(), and xs_rm_tree().
int xs_rm_tree | ( | struct xs_transaction | xbt, |
const char * | base, | ||
const char * | node | ||
) |
Definition at line 1373 of file xenstore.c.
References xs_directory(), xs_join(), xs_rm(), xs_transaction_end(), and xs_transaction_start().
int xs_scanf | ( | struct xs_transaction | t, |
const char * | dir, | ||
const char * | node, | ||
int * | scancountp, | ||
const char * | fmt, | ||
... | |||
) |
Definition at line 1494 of file xenstore.c.
References xs_read().
Referenced by create_netdev(), talk_to_backend(), watch_target(), xbb_collect_frontend_info(), xbd_attach(), xbd_initialize(), xn_connect(), xn_query_features(), and xnb_collect_xenstore_info().
|
static |
Wrapper for xs_talkv allowing easy transmission of a message with a single, contiguous, message body.
t | The transaction to use for this request. |
request_type | The type of message to send. |
body | The body of the request. |
len | The returned length of the reply. |
result | The returned body of the reply. |
Definition at line 888 of file xenstore.c.
References xs_talkv().
Referenced by xs_directory(), xs_mkdir(), xs_read(), xs_rm(), xs_transaction_end(), and xs_transaction_start().
|
static |
Prepare for suspension of this VM by halting XenStore access after all transactions and individual requests have completed.
Definition at line 1174 of file xenstore.c.
References xs_softc::request_mutex, and xs.
|
static |
Send a message with an optionally muti-part body to the XenStore service.
t | The transaction to use for this request. |
request_type | The type of message to send. |
iovec | Pointers to the body sections of the request. |
num_vecs | The number of body sections in the request. |
len | The returned length of the reply. |
result | The returned body of the reply. |
Definition at line 817 of file xenstore.c.
References xs_softc::request_mutex, xs, xs_get_error(), xs_read_reply(), and xs_write_store().
Referenced by xs_single(), xs_unwatch(), xs_watch(), and xs_write().
int xs_transaction_end | ( | struct xs_transaction | t, |
int | abort | ||
) |
Definition at line 1481 of file xenstore.c.
References xs_single().
Referenced by talk_to_backend(), xbb_publish_backend_info(), xnb_publish_backend_info(), xs_dev_dtor(), and xs_rm_tree().
int xs_transaction_start | ( | struct xs_transaction * | t | ) |
Definition at line 1466 of file xenstore.c.
References xs_single().
Referenced by talk_to_backend(), xbb_publish_backend_info(), xnb_publish_backend_info(), and xs_rm_tree().
void xs_unlock | ( | void | ) |
Definition at line 1656 of file xenstore.c.
References xs_softc::request_mutex, and xs.
void xs_unregister_watch | ( | struct xs_watch * | watch | ) |
Definition at line 1608 of file xenstore.c.
References find_watch(), xs_softc::registered_watches_lock, xs_stored_msg::u, xs_softc::watch_events, xs_softc::watch_events_lock, xs_softc::xenwatch_mutex, xs_softc::xenwatch_pid, xs, and xs_unwatch().
Referenced by xbb_attach_cb(), xbb_shutdown(), xctrl_detach(), xs_dev_dtor(), and xs_dev_write().
|
static |
Transmit an uwatch request to the XenStore service.
path | The path in the XenStore to watch. |
tocken | A unique identifier for this watch. |
Definition at line 932 of file xenstore.c.
References xs_talkv().
Referenced by xs_unregister_watch().
int xs_vprintf | ( | struct xs_transaction | t, |
const char * | dir, | ||
const char * | node, | ||
const char * | fmt, | ||
va_list | ap | ||
) |
Definition at line 1518 of file xenstore.c.
References xs_write().
Referenced by xbb_attach_failed(), xnb_attach_failed(), and xs_printf().
|
static |
Transmit a watch request to the XenStore service.
path | The path in the XenStore to watch. |
tocken | A unique identifier for this watch. |
Definition at line 910 of file xenstore.c.
References xs_talkv().
Referenced by find_watch(), xs_register_watch(), and xs_resume().
int xs_write | ( | struct xs_transaction | t, |
const char * | dir, | ||
const char * | node, | ||
const char * | string | ||
) |
Definition at line 1326 of file xenstore.c.
References xs_join(), and xs_talkv().
Referenced by xctrl_on_watch_event(), and xs_vprintf().
|
static |
Transmit data to the XenStore service.
tdata | A pointer to the contiguous data to send. |
len | The amount of data to send. |
Definition at line 455 of file xenstore.c.
References xs_softc::request_mutex, xs_softc::ring_lock, xs_softc::xen_intr_handle, xen_store, xs, xs_check_indexes(), and xs_get_output_chunk().
Referenced by xs_dev_request_and_reply(), and xs_talkv().
|
static |
Pointer to shared memory communication structures allowing us to communicate with the XenStore service.
When operating in full PV mode, this pointer is set early in kernel startup from within xen_machdep.c. In HVM mode, we use hypercalls to get the guest frame number for the shared page and then map it into kva. See xs_init() for details.
Definition at line 117 of file xenstore.c.
Referenced by xs_attach(), xs_init_comms(), xs_intr(), xs_read_store(), and xs_write_store().
|
static |
Definition at line 1240 of file xenstore.c.
|
static |
Definition at line 1219 of file xenstore.c.
|
static |
Definition at line 258 of file xenstore.c.
Referenced by find_watch(), xenwatch_thread(), xs_address(), xs_attach(), xs_attach_deferred(), xs_attach_late(), xs_dev_request_and_reply(), xs_evtchn(), xs_init_comms(), xs_initialized(), xs_intr(), xs_lock(), xs_process_msg(), xs_read_reply(), xs_read_store(), xs_register_watch(), xs_resume(), xs_suspend(), xs_talkv(), xs_unlock(), xs_unregister_watch(), and xs_write_store().