xen: create xenstore areas for XenDevice-s

This patch adds a new source module, xen-bus-helper.c, which builds on
basic libxenstore primitives to provide functions to create (setting
permissions appropriately) and destroy xenstore areas, and functions to
'printf' and 'scanf' nodes therein. The main xen-bus code then uses
these primitives [1] to initialize and destroy the frontend and backend
areas for a XenDevice during realize and unrealize respectively.

The 'xen-block' implementation is extended with a 'get_name' method that
returns the VBD number. This number is required to 'name' the xenstore
areas.

NOTE: An exit handler is also added to make sure the xenstore areas are
      cleaned up if QEMU terminates without devices being unrealized.

[1] The 'scanf' functions are actually not yet needed, but they will be
    needed by code delivered in subsequent patches.

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:
Paul Durrant 2019-01-08 14:48:49 +00:00 committed by Anthony PERARD
parent 1a72d9ae31
commit 094a22399f
7 changed files with 540 additions and 5 deletions

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 2018 Citrix Systems Inc.
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
#ifndef HW_XEN_BUS_HELPER_H
#define HW_XEN_BUS_HELPER_H
#include "hw/xen/xen_common.h"
const char *xs_strstate(enum xenbus_state state);
void xs_node_create(struct xs_handle *xsh, xs_transaction_t tid,
const char *node, struct xs_permissions perms[],
unsigned int nr_perms, Error **errp);
void xs_node_destroy(struct xs_handle *xsh, xs_transaction_t tid,
const char *node, Error **errp);
/* Write to node/key unless node is empty, in which case write to key */
void xs_node_vprintf(struct xs_handle *xsh, xs_transaction_t tid,
const char *node, const char *key, Error **errp,
const char *fmt, va_list ap)
GCC_FMT_ATTR(6, 0);
void xs_node_printf(struct xs_handle *xsh, xs_transaction_t tid,
const char *node, const char *key, Error **errp,
const char *fmt, ...)
GCC_FMT_ATTR(6, 7);
/* Read from node/key unless node is empty, in which case read from key */
int xs_node_vscanf(struct xs_handle *xsh, xs_transaction_t tid,
const char *node, const char *key, Error **errp,
const char *fmt, va_list ap);
int xs_node_scanf(struct xs_handle *xsh, xs_transaction_t tid,
const char *node, const char *key, Error **errp,
const char *fmt, ...);
#endif /* HW_XEN_BUS_HELPER_H */

View file

@ -8,12 +8,19 @@
#ifndef HW_XEN_BUS_H
#define HW_XEN_BUS_H
#include "hw/xen/xen_common.h"
#include "hw/sysbus.h"
typedef struct XenDevice {
DeviceState qdev;
domid_t frontend_id;
char *name;
char *backend_path, *frontend_path;
enum xenbus_state backend_state, frontend_state;
Notifier exit;
} XenDevice;
typedef char *(*XenDeviceGetName)(XenDevice *xendev, Error **errp);
typedef void (*XenDeviceRealize)(XenDevice *xendev, Error **errp);
typedef void (*XenDeviceUnrealize)(XenDevice *xendev, Error **errp);
@ -21,6 +28,9 @@ typedef struct XenDeviceClass {
/*< private >*/
DeviceClass parent_class;
/*< public >*/
const char *backend;
const char *device;
XenDeviceGetName get_name;
XenDeviceRealize realize;
XenDeviceUnrealize unrealize;
} XenDeviceClass;
@ -35,6 +45,8 @@ typedef struct XenDeviceClass {
typedef struct XenBus {
BusState qbus;
domid_t backend_id;
struct xs_handle *xsh;
} XenBus;
typedef struct XenBusClass {