xen: add xenstore watcher infrastructure
A Xen PV frontend communicates its state to the PV backend by writing to the 'state' key in the frontend area in xenstore. It is therefore necessary for a XenDevice implementation to be notified whenever the value of this key changes. This patch adds code to do this as follows: - an 'fd handler' is registered on the libxenstore handle which will be triggered whenever a 'watch' event occurs - primitives are added to xen-bus-helper to add or remove watch events - a list of Notifier objects is added to XenBus to provide a mechanism to call the appropriate 'watch handler' when its associated event occurs The xen-block implementation is extended with a 'frontend_changed' method, which calls as-yet stub 'connect' and 'disconnect' functions when the relevant frontend state transitions occur. A subsequent patch will supply a full implementation for these functions. Signed-off-by: Paul Durrant <paul.durrant@citrix.com> Reviewed-by: Anthony Perard <anthony.perard@citrix.com> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
This commit is contained in:
parent
094a22399f
commit
82a29e3048
7 changed files with 342 additions and 2 deletions
|
|
@ -36,4 +36,10 @@ int xs_node_scanf(struct xs_handle *xsh, xs_transaction_t tid,
|
|||
const char *node, const char *key, Error **errp,
|
||||
const char *fmt, ...);
|
||||
|
||||
/* Watch node/key unless node is empty, in which case watch key */
|
||||
void xs_node_watch(struct xs_handle *xsh, const char *node, const char *key,
|
||||
char *token, Error **errp);
|
||||
void xs_node_unwatch(struct xs_handle *xsh, const char *node, const char *key,
|
||||
const char *token, Error **errp);
|
||||
|
||||
#endif /* HW_XEN_BUS_HELPER_H */
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@
|
|||
|
||||
#include "hw/xen/xen_common.h"
|
||||
#include "hw/sysbus.h"
|
||||
#include "qemu/notify.h"
|
||||
|
||||
typedef void (*XenWatchHandler)(void *opaque);
|
||||
|
||||
typedef struct XenWatch XenWatch;
|
||||
|
||||
typedef struct XenDevice {
|
||||
DeviceState qdev;
|
||||
|
|
@ -18,10 +23,14 @@ typedef struct XenDevice {
|
|||
char *backend_path, *frontend_path;
|
||||
enum xenbus_state backend_state, frontend_state;
|
||||
Notifier exit;
|
||||
XenWatch *frontend_state_watch;
|
||||
} XenDevice;
|
||||
|
||||
typedef char *(*XenDeviceGetName)(XenDevice *xendev, Error **errp);
|
||||
typedef void (*XenDeviceRealize)(XenDevice *xendev, Error **errp);
|
||||
typedef void (*XenDeviceFrontendChanged)(XenDevice *xendev,
|
||||
enum xenbus_state frontend_state,
|
||||
Error **errp);
|
||||
typedef void (*XenDeviceUnrealize)(XenDevice *xendev, Error **errp);
|
||||
|
||||
typedef struct XenDeviceClass {
|
||||
|
|
@ -32,6 +41,7 @@ typedef struct XenDeviceClass {
|
|||
const char *device;
|
||||
XenDeviceGetName get_name;
|
||||
XenDeviceRealize realize;
|
||||
XenDeviceFrontendChanged frontend_changed;
|
||||
XenDeviceUnrealize unrealize;
|
||||
} XenDeviceClass;
|
||||
|
||||
|
|
@ -47,6 +57,7 @@ typedef struct XenBus {
|
|||
BusState qbus;
|
||||
domid_t backend_id;
|
||||
struct xs_handle *xsh;
|
||||
NotifierList watch_notifiers;
|
||||
} XenBus;
|
||||
|
||||
typedef struct XenBusClass {
|
||||
|
|
@ -64,4 +75,8 @@ typedef struct XenBusClass {
|
|||
|
||||
void xen_bus_init(void);
|
||||
|
||||
void xen_device_backend_set_state(XenDevice *xendev,
|
||||
enum xenbus_state state);
|
||||
enum xenbus_state xen_device_backend_get_state(XenDevice *xendev);
|
||||
|
||||
#endif /* HW_XEN_BUS_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue