FreeBSD xen subsystem code
xenbus.c File Reference

Client-facing interface for the Xenbus driver. More...

#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/types.h>
#include <sys/malloc.h>
#include <sys/libkern.h>
#include <sys/sbuf.h>
#include <xen/xen-os.h>
#include <xen/hypervisor.h>
#include <xen/evtchn.h>
#include <xen/gnttab.h>
#include <xen/xenbus/xenbusvar.h>
#include <machine/stdarg.h>
Include dependency graph for xenbus.c:

Go to the source code of this file.

Macros

#define DPRINTK(fmt, args...)   ((void)0)
 
#define PRINTF_BUFFER_SIZE   4096
 

Functions

 __FBSDID ("$FreeBSD: head/sys/xen/xenbus/xenbus.c 255040 2013-08-29 19:52:18Z gibbs $")
 
 MALLOC_DEFINE (M_XENBUS, "xenbus", "XenBus Support")
 
static char * error_path (device_t dev)
 Construct the error path corresponding to the given XenBus device. More...
 
const char * xenbus_strstate (XenbusState state)
 
int xenbus_watch_path (device_t dev, char *path, struct xs_watch *watch, xs_watch_cb_t *callback, uintptr_t callback_data)
 
int xenbus_watch_path2 (device_t dev, const char *path, const char *path2, struct xs_watch *watch, xs_watch_cb_t *callback, uintptr_t callback_data)
 
void xenbus_dev_verror (device_t dev, int err, const char *fmt, va_list ap)
 
void xenbus_dev_error (device_t dev, int err, const char *fmt,...)
 
void xenbus_dev_vfatal (device_t dev, int err, const char *fmt, va_list ap)
 
void xenbus_dev_fatal (device_t dev, int err, const char *fmt,...)
 
int xenbus_grant_ring (device_t dev, unsigned long ring_mfn, grant_ref_t *refp)
 
XenbusState xenbus_read_driver_state (const char *path)
 
int xenbus_dev_is_online (device_t dev)
 
void xenbus_localend_changed (device_t dev, const char *path)
 

Detailed Description

Client-facing interface for the Xenbus driver.

In other words, the interface between the Xenbus and the device-specific code, be it the frontend or the backend of that driver.

Definition in file xenbus.c.

Function Documentation

◆ error_path()

static char* error_path ( device_t  dev)
static

Construct the error path corresponding to the given XenBus device.

Parameters
devThe XenBus device for which we are constructing an error path.
Returns
On success, the contructed error path. Otherwise NULL.

It is the caller's responsibility to free any returned error path node using the M_XENBUS malloc type.

Definition at line 76 of file xenbus.c.

◆ xenbus_dev_is_online()

int xenbus_dev_is_online ( device_t  dev)

Return the value of a XenBus device's "online" node within the XenStore.

Parameters
devThe XenBus device to query.
Returns
The value of the "online" node for the device. If the node does not exist, 0 (offline) is returned.

Definition at line 240 of file xenbus.c.

Referenced by xenbusb_back_localend_changed(), and xenbusb_back_otherend_changed().

Here is the caller graph for this function:

◆ xenbus_grant_ring()

int xenbus_grant_ring ( device_t  dev,
unsigned long  ring_mfn,
grant_ref_t *  refp 
)

Grant access to the given ring_mfn to the peer of the given device.

Parameters
devThe device granting access to the ring page.
ring_mfnThe guest machine page number of the page to grant peer access rights.
refp[out]The grant reference for the page.
Returns
On success, 0. Otherwise an errno value indicating the type of failure.

A successful call to xenbus_grant_ring should be paired with a call to gnttab_end_foreign_access() when foregn access to this page is no longer requried.

Note
On error, dev will be switched to the XenbusStateClosing state and the returned error is saved in the per-device error node for dev in the XenStore.

Definition at line 212 of file xenbus.c.

References xenbus_dev_fatal().

Here is the call graph for this function:

◆ xenbus_localend_changed()

void xenbus_localend_changed ( device_t  dev,
const char *  path 
)

Default callback invoked when a change to the local XenStore sub-tree for a device is modified.

Parameters
devThe XenBus device whose tree was modified.
pathThe tree relative sub-path to the modified node. The empty string indicates the root of the tree was destroyed.

Definition at line 257 of file xenbus.c.

◆ xenbus_read_driver_state()

XenbusState xenbus_read_driver_state ( const char *  path)

Return the state of a XenBus device.

Parameters
pathThe root XenStore path for the device.
Returns
The current state of the device or XenbusStateClosed if no state can be read.

Definition at line 227 of file xenbus.c.

Referenced by xenbus_get_otherend_state(), xenbusb_add_device(), xenbusb_localend_changed(), and xenbusb_otherend_watch_cb().

Here is the caller graph for this function:

◆ xenbus_watch_path()

int xenbus_watch_path ( device_t  dev,
char *  path,
struct xs_watch watch,
xs_watch_cb_t *  callback,
uintptr_t  cb_data 
)

Initialize and register a watch on the given path (client suplied storage).

Parameters
devThe XenBus device requesting the watch service.
pathThe XenStore path of the object to be watched. The storage for this string must be stable for the lifetime of the watch.
watchThe watch object to use for this request. This object must be stable for the lifetime of the watch.
callbackThe function to call when XenStore objects at or below path are modified.
cb_dataClient data that can be retrieved from the watch object during the callback.
Returns
On success, 0. Otherwise an errno value indicating the type of failure.
Note
On error, the device 'dev' will be switched to the XenbusStateClosing state and the returned error is saved in the per-device error node for dev in the XenStore.

Definition at line 106 of file xenbus.c.

References xenbus_dev_fatal().

Referenced by xenbus_watch_path2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xenbus_watch_path2()

int xenbus_watch_path2 ( device_t  dev,
const char *  path,
const char *  path2,
struct xs_watch watch,
xs_watch_cb_t *  callback,
uintptr_t  cb_data 
)

Initialize and register a watch at path/path2 in the XenStore.

Parameters
devThe XenBus device requesting the watch service.
pathThe base XenStore path of the object to be watched.
path2The tail XenStore path of the object to be watched.
watchThe watch object to use for this request. This object must be stable for the lifetime of the watch.
callbackThe function to call when XenStore objects at or below path are modified.
cb_dataClient data that can be retrieved from the watch object during the callback.
Returns
On success, 0. Otherwise an errno value indicating the type of failure.
Note
On error, dev will be switched to the XenbusStateClosing state and the returned error is saved in the per-device error node for dev in the XenStore.

Similar to xenbus_watch_path, however the storage for the path to the watched object is allocated from the heap and filled with "path '/' path2". Should a call to this function succeed, it is the callers responsibility to free watch->node using the M_XENBUS malloc type.

Definition at line 127 of file xenbus.c.

References xenbus_watch_path().

Here is the call graph for this function: