2009-04-22 19:19:15 +04:00
|
|
|
/*
|
|
|
|
* xen backend driver infrastructure
|
|
|
|
* (c) 2008 Gerd Hoffmann <kraxel@redhat.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; under version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2009-07-17 00:47:01 +04:00
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
2012-01-13 20:44:23 +04:00
|
|
|
*
|
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
2009-04-22 19:19:15 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: add some xenbus / xenstore concepts overview here.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:06 +03:00
|
|
|
#include "qemu/osdep.h"
|
2009-04-22 19:19:15 +04:00
|
|
|
#include <sys/signal.h>
|
|
|
|
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/hw.h"
|
2016-06-13 12:12:21 +03:00
|
|
|
#include "hw/sysbus.h"
|
2013-04-08 18:55:25 +04:00
|
|
|
#include "sysemu/char.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/log.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/xen/xen_backend.h"
|
2009-04-22 19:19:15 +04:00
|
|
|
|
2012-06-21 15:43:59 +04:00
|
|
|
#include <xen/grant_table.h>
|
|
|
|
|
2016-06-13 12:12:21 +03:00
|
|
|
#define TYPE_XENSYSDEV "xensysdev"
|
|
|
|
|
|
|
|
DeviceState *xen_sysdev;
|
|
|
|
|
2009-04-22 19:19:15 +04:00
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* public */
|
2016-02-10 14:07:03 +03:00
|
|
|
xc_interface *xen_xc = NULL;
|
xen: Switch uses of xc_map_foreign_{pages,bulk} to use libxenforeignmemory API.
In Xen 4.7 we are refactoring parts libxenctrl into a number of
separate libraries which will provide backward and forward API and ABI
compatiblity.
One such library will be libxenforeignmemory which provides access to
privileged foreign mappings and which will provide an interface
equivalent to xc_map_foreign_{pages,bulk}.
The new xenforeignmemory_map() function behaves like
xc_map_foreign_pages() when the err argument is NULL and like
xc_map_foreign_bulk() when err is non-NULL, which maps into the shim
here onto checking err == NULL and calling the appropriate old
function.
Note that xenforeignmemory_map() takes the number of pages before the
arrays themselves, in order to support potentially future use of
variable-length-arrays in the prototype (in the future, when Xen's
baseline toolchain requirements are new enough to ensure VLAs are
supported).
In preparation for adding support for libxenforeignmemory add support
to the <=4.0 and <=4.6 compat code in xen_common.h to allow us to
switch to using the new API. These shims will disappear for versions
of Xen which include libxenforeignmemory.
Since libxenforeignmemory will have its own handle type but for <= 4.6
the functionality is provided by using a libxenctrl handle we
introduce a new global xen_fmem alongside the existing xen_xc. In fact
we make xen_fmem a pointer to the existing xen_xc, which then works
correctly with both <=4.0 (xc handle is an int) and <=4.6 (xc handle
is a pointer). In the latter case xen_fmem is actually a double
indirect pointer, but it all falls out in the wash.
Unlike libxenctrl libxenforeignmemory has an explicit unmap function,
rather than just specifying that munmap should be used, so the unmap
paths are updated to use xenforeignmemory_unmap, which is a shim for
munmap on these versions of xen. The mappings in xen-hvm.c do not
appear to be unmapped (which makes sense for a qemu-dm process)
In fb_disconnect this results in a change from simply mmap over the
existing mapping (with an implicit munmap) to expliclty unmapping with
xenforeignmemory_unmap and then mapping the required anonymous memory
in the same hole. I don't think this is a problem since any other
thread which was racily touching this region would already be running
the risk of hitting the mapping halfway through the call. If this is
thought to be a problem then we could consider adding an extra API to
the libxenforeignmemory interface to replace a foreign mapping with
anonymous shared memory, but I'd prefer not to.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
2016-01-15 16:23:41 +03:00
|
|
|
xenforeignmemory_handle *xen_fmem = NULL;
|
2009-04-22 19:19:15 +04:00
|
|
|
struct xs_handle *xenstore = NULL;
|
2009-04-22 19:19:39 +04:00
|
|
|
const char *xen_protocol;
|
2009-04-22 19:19:15 +04:00
|
|
|
|
|
|
|
/* private */
|
2016-05-12 17:13:40 +03:00
|
|
|
struct xs_dirs {
|
|
|
|
char *xs_dir;
|
|
|
|
QTAILQ_ENTRY(xs_dirs) list;
|
|
|
|
};
|
|
|
|
static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup =
|
|
|
|
QTAILQ_HEAD_INITIALIZER(xs_cleanup);
|
|
|
|
|
2009-09-12 11:36:22 +04:00
|
|
|
static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = QTAILQ_HEAD_INITIALIZER(xendevs);
|
2009-04-22 19:19:15 +04:00
|
|
|
static int debug = 0;
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
2016-05-12 17:13:40 +03:00
|
|
|
static void xenstore_cleanup_dir(char *dir)
|
|
|
|
{
|
|
|
|
struct xs_dirs *d;
|
|
|
|
|
|
|
|
d = g_malloc(sizeof(*d));
|
|
|
|
d->xs_dir = dir;
|
|
|
|
QTAILQ_INSERT_TAIL(&xs_cleanup, d, list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void xen_config_cleanup(void)
|
|
|
|
{
|
|
|
|
struct xs_dirs *d;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(d, &xs_cleanup, list) {
|
|
|
|
xs_rm(xenstore, 0, d->xs_dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-22 19:19:15 +04:00
|
|
|
int xenstore_write_str(const char *base, const char *node, const char *val)
|
|
|
|
{
|
|
|
|
char abspath[XEN_BUFSIZE];
|
|
|
|
|
|
|
|
snprintf(abspath, sizeof(abspath), "%s/%s", base, node);
|
2010-09-23 15:28:45 +04:00
|
|
|
if (!xs_write(xenstore, 0, abspath, val, strlen(val))) {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *xenstore_read_str(const char *base, const char *node)
|
|
|
|
{
|
|
|
|
char abspath[XEN_BUFSIZE];
|
|
|
|
unsigned int len;
|
|
|
|
char *str, *ret = NULL;
|
|
|
|
|
|
|
|
snprintf(abspath, sizeof(abspath), "%s/%s", base, node);
|
|
|
|
str = xs_read(xenstore, 0, abspath, &len);
|
|
|
|
if (str != NULL) {
|
|
|
|
/* move to qemu-allocated memory to make sure
|
2011-08-21 07:09:37 +04:00
|
|
|
* callers can savely g_free() stuff. */
|
|
|
|
ret = g_strdup(str);
|
2009-04-22 19:19:15 +04:00
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-12 17:13:40 +03:00
|
|
|
int xenstore_mkdir(char *path, int p)
|
|
|
|
{
|
|
|
|
struct xs_permissions perms[2] = {
|
|
|
|
{
|
|
|
|
.id = 0, /* set owner: dom0 */
|
|
|
|
}, {
|
|
|
|
.id = xen_domid,
|
|
|
|
.perms = p,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!xs_mkdir(xenstore, 0, path)) {
|
|
|
|
xen_be_printf(NULL, 0, "xs_mkdir %s: failed\n", path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
xenstore_cleanup_dir(g_strdup(path));
|
|
|
|
|
|
|
|
if (!xs_set_permissions(xenstore, 0, path, perms, 2)) {
|
|
|
|
xen_be_printf(NULL, 0, "xs_set_permissions %s: failed\n", path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-22 19:19:15 +04:00
|
|
|
int xenstore_write_int(const char *base, const char *node, int ival)
|
|
|
|
{
|
2013-04-05 19:37:32 +04:00
|
|
|
char val[12];
|
2009-04-22 19:19:15 +04:00
|
|
|
|
|
|
|
snprintf(val, sizeof(val), "%d", ival);
|
|
|
|
return xenstore_write_str(base, node, val);
|
|
|
|
}
|
|
|
|
|
2013-04-05 19:37:32 +04:00
|
|
|
int xenstore_write_int64(const char *base, const char *node, int64_t ival)
|
|
|
|
{
|
|
|
|
char val[21];
|
|
|
|
|
|
|
|
snprintf(val, sizeof(val), "%"PRId64, ival);
|
|
|
|
return xenstore_write_str(base, node, val);
|
|
|
|
}
|
|
|
|
|
2009-04-22 19:19:15 +04:00
|
|
|
int xenstore_read_int(const char *base, const char *node, int *ival)
|
|
|
|
{
|
|
|
|
char *val;
|
|
|
|
int rc = -1;
|
|
|
|
|
|
|
|
val = xenstore_read_str(base, node);
|
2010-09-23 15:28:45 +04:00
|
|
|
if (val && 1 == sscanf(val, "%d", ival)) {
|
|
|
|
rc = 0;
|
|
|
|
}
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(val);
|
2009-04-22 19:19:15 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-12-18 23:17:31 +04:00
|
|
|
int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval)
|
|
|
|
{
|
|
|
|
char *val;
|
|
|
|
int rc = -1;
|
|
|
|
|
|
|
|
val = xenstore_read_str(base, node);
|
|
|
|
if (val && 1 == sscanf(val, "%"SCNu64, uval)) {
|
|
|
|
rc = 0;
|
|
|
|
}
|
|
|
|
g_free(val);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2009-04-22 19:19:15 +04:00
|
|
|
int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val)
|
|
|
|
{
|
|
|
|
return xenstore_write_str(xendev->be, node, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
int xenstore_write_be_int(struct XenDevice *xendev, const char *node, int ival)
|
|
|
|
{
|
|
|
|
return xenstore_write_int(xendev->be, node, ival);
|
|
|
|
}
|
|
|
|
|
2013-04-05 19:37:32 +04:00
|
|
|
int xenstore_write_be_int64(struct XenDevice *xendev, const char *node, int64_t ival)
|
|
|
|
{
|
|
|
|
return xenstore_write_int64(xendev->be, node, ival);
|
|
|
|
}
|
|
|
|
|
2009-04-22 19:19:15 +04:00
|
|
|
char *xenstore_read_be_str(struct XenDevice *xendev, const char *node)
|
|
|
|
{
|
|
|
|
return xenstore_read_str(xendev->be, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
int xenstore_read_be_int(struct XenDevice *xendev, const char *node, int *ival)
|
|
|
|
{
|
|
|
|
return xenstore_read_int(xendev->be, node, ival);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *xenstore_read_fe_str(struct XenDevice *xendev, const char *node)
|
|
|
|
{
|
|
|
|
return xenstore_read_str(xendev->fe, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int *ival)
|
|
|
|
{
|
|
|
|
return xenstore_read_int(xendev->fe, node, ival);
|
|
|
|
}
|
|
|
|
|
2013-12-18 23:17:31 +04:00
|
|
|
int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, uint64_t *uval)
|
|
|
|
{
|
|
|
|
return xenstore_read_uint64(xendev->fe, node, uval);
|
|
|
|
}
|
|
|
|
|
2009-04-22 19:19:15 +04:00
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
const char *xenbus_strstate(enum xenbus_state state)
|
|
|
|
{
|
2010-09-23 15:28:45 +04:00
|
|
|
static const char *const name[] = {
|
|
|
|
[ XenbusStateUnknown ] = "Unknown",
|
|
|
|
[ XenbusStateInitialising ] = "Initialising",
|
|
|
|
[ XenbusStateInitWait ] = "InitWait",
|
|
|
|
[ XenbusStateInitialised ] = "Initialised",
|
|
|
|
[ XenbusStateConnected ] = "Connected",
|
|
|
|
[ XenbusStateClosing ] = "Closing",
|
|
|
|
[ XenbusStateClosed ] = "Closed",
|
|
|
|
};
|
|
|
|
return (state < ARRAY_SIZE(name)) ? name[state] : "INVALID";
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = xenstore_write_be_int(xendev, "state", state);
|
2010-09-23 15:28:45 +04:00
|
|
|
if (rc < 0) {
|
|
|
|
return rc;
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
xen_be_printf(xendev, 1, "backend state: %s -> %s\n",
|
2010-09-23 15:28:45 +04:00
|
|
|
xenbus_strstate(xendev->be_state), xenbus_strstate(state));
|
2009-04-22 19:19:15 +04:00
|
|
|
xendev->be_state = state;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev)
|
|
|
|
{
|
|
|
|
struct XenDevice *xendev;
|
|
|
|
|
2009-09-12 11:36:22 +04:00
|
|
|
QTAILQ_FOREACH(xendev, &xendevs, next) {
|
2010-09-23 15:28:45 +04:00
|
|
|
if (xendev->dom != dom) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (xendev->dev != dev) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(xendev->type, type) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return xendev;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get xen backend device, allocate a new one if it doesn't exist.
|
|
|
|
*/
|
|
|
|
static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
|
|
|
|
struct XenDevOps *ops)
|
|
|
|
{
|
|
|
|
struct XenDevice *xendev;
|
|
|
|
|
|
|
|
xendev = xen_be_find_xendev(type, dom, dev);
|
2010-09-23 15:28:45 +04:00
|
|
|
if (xendev) {
|
|
|
|
return xendev;
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
|
|
|
|
/* init new xendev */
|
2011-08-21 07:09:37 +04:00
|
|
|
xendev = g_malloc0(ops->size);
|
2009-04-22 19:19:15 +04:00
|
|
|
xendev->type = type;
|
|
|
|
xendev->dom = dom;
|
|
|
|
xendev->dev = dev;
|
|
|
|
xendev->ops = ops;
|
|
|
|
|
2013-10-10 18:25:52 +04:00
|
|
|
snprintf(xendev->be, sizeof(xendev->be), "backend/%s/%d/%d",
|
|
|
|
xendev->type, xendev->dom, xendev->dev);
|
2009-04-22 19:19:15 +04:00
|
|
|
snprintf(xendev->name, sizeof(xendev->name), "%s-%d",
|
2010-09-23 15:28:45 +04:00
|
|
|
xendev->type, xendev->dev);
|
2009-04-22 19:19:15 +04:00
|
|
|
|
|
|
|
xendev->debug = debug;
|
|
|
|
xendev->local_port = -1;
|
|
|
|
|
2016-01-15 16:23:38 +03:00
|
|
|
xendev->evtchndev = xenevtchn_open(NULL, 0);
|
|
|
|
if (xendev->evtchndev == NULL) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_printf(NULL, 0, "can't open evtchn device\n");
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(xendev);
|
2010-09-23 15:28:45 +04:00
|
|
|
return NULL;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
2016-01-15 16:23:38 +03:00
|
|
|
fcntl(xenevtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC);
|
2009-04-22 19:19:15 +04:00
|
|
|
|
|
|
|
if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
|
2016-01-15 16:23:39 +03:00
|
|
|
xendev->gnttabdev = xengnttab_open(NULL, 0);
|
|
|
|
if (xendev->gnttabdev == NULL) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_printf(NULL, 0, "can't open gnttab device\n");
|
2016-01-15 16:23:38 +03:00
|
|
|
xenevtchn_close(xendev->evtchndev);
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(xendev);
|
2010-09-23 15:28:45 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
} else {
|
2016-01-15 16:23:39 +03:00
|
|
|
xendev->gnttabdev = NULL;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 11:36:22 +04:00
|
|
|
QTAILQ_INSERT_TAIL(&xendevs, xendev, next);
|
2009-04-22 19:19:15 +04:00
|
|
|
|
2010-09-23 15:28:45 +04:00
|
|
|
if (xendev->ops->alloc) {
|
|
|
|
xendev->ops->alloc(xendev);
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
|
|
|
|
return xendev;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* release xen backend device.
|
|
|
|
*/
|
|
|
|
static struct XenDevice *xen_be_del_xendev(int dom, int dev)
|
|
|
|
{
|
|
|
|
struct XenDevice *xendev, *xnext;
|
|
|
|
|
|
|
|
/*
|
2009-09-12 11:36:22 +04:00
|
|
|
* This is pretty much like QTAILQ_FOREACH(xendev, &xendevs, next) but
|
2009-04-22 19:19:15 +04:00
|
|
|
* we save the next pointer in xnext because we might free xendev.
|
|
|
|
*/
|
|
|
|
xnext = xendevs.tqh_first;
|
|
|
|
while (xnext) {
|
|
|
|
xendev = xnext;
|
|
|
|
xnext = xendev->next.tqe_next;
|
|
|
|
|
2010-09-23 15:28:45 +04:00
|
|
|
if (xendev->dom != dom) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (xendev->dev != dev && dev != -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xendev->ops->free) {
|
|
|
|
xendev->ops->free(xendev);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xendev->fe) {
|
|
|
|
char token[XEN_BUFSIZE];
|
|
|
|
snprintf(token, sizeof(token), "fe:%p", xendev);
|
|
|
|
xs_unwatch(xenstore, xendev->fe, token);
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(xendev->fe);
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
|
|
|
|
2016-01-15 16:23:38 +03:00
|
|
|
if (xendev->evtchndev != NULL) {
|
|
|
|
xenevtchn_close(xendev->evtchndev);
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2016-01-15 16:23:39 +03:00
|
|
|
if (xendev->gnttabdev != NULL) {
|
|
|
|
xengnttab_close(xendev->gnttabdev);
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
QTAILQ_REMOVE(&xendevs, xendev, next);
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(xendev);
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sync internal data structures on xenstore updates.
|
|
|
|
* Node specifies the changed field. node = NULL means
|
|
|
|
* update all fields (used for initialization).
|
|
|
|
*/
|
|
|
|
static void xen_be_backend_changed(struct XenDevice *xendev, const char *node)
|
|
|
|
{
|
|
|
|
if (node == NULL || strcmp(node, "online") == 0) {
|
2010-09-23 15:28:45 +04:00
|
|
|
if (xenstore_read_be_int(xendev, "online", &xendev->online) == -1) {
|
|
|
|
xendev->online = 0;
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (node) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_printf(xendev, 2, "backend update: %s\n", node);
|
|
|
|
if (xendev->ops->backend_changed) {
|
|
|
|
xendev->ops->backend_changed(xendev, node);
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_be_frontend_changed(struct XenDevice *xendev, const char *node)
|
|
|
|
{
|
|
|
|
int fe_state;
|
|
|
|
|
|
|
|
if (node == NULL || strcmp(node, "state") == 0) {
|
2010-09-23 15:28:45 +04:00
|
|
|
if (xenstore_read_fe_int(xendev, "state", &fe_state) == -1) {
|
|
|
|
fe_state = XenbusStateUnknown;
|
|
|
|
}
|
|
|
|
if (xendev->fe_state != fe_state) {
|
|
|
|
xen_be_printf(xendev, 1, "frontend state: %s -> %s\n",
|
|
|
|
xenbus_strstate(xendev->fe_state),
|
|
|
|
xenbus_strstate(fe_state));
|
|
|
|
}
|
|
|
|
xendev->fe_state = fe_state;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
if (node == NULL || strcmp(node, "protocol") == 0) {
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(xendev->protocol);
|
2010-09-23 15:28:45 +04:00
|
|
|
xendev->protocol = xenstore_read_fe_str(xendev, "protocol");
|
|
|
|
if (xendev->protocol) {
|
|
|
|
xen_be_printf(xendev, 1, "frontend protocol: %s\n", xendev->protocol);
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (node) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_printf(xendev, 2, "frontend update: %s\n", node);
|
|
|
|
if (xendev->ops->frontend_changed) {
|
|
|
|
xendev->ops->frontend_changed(xendev, node);
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
/* Check for possible state transitions and perform them. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initial xendev setup. Read frontend path, register watch for it.
|
|
|
|
* Should succeed once xend finished setting up the backend device.
|
|
|
|
*
|
|
|
|
* Also sets initial state (-> Initializing) when done. Which
|
|
|
|
* only affects the xendev->be_state variable as xenbus should
|
|
|
|
* already be put into that state by xend.
|
|
|
|
*/
|
|
|
|
static int xen_be_try_setup(struct XenDevice *xendev)
|
|
|
|
{
|
|
|
|
char token[XEN_BUFSIZE];
|
|
|
|
int be_state;
|
|
|
|
|
|
|
|
if (xenstore_read_be_int(xendev, "state", &be_state) == -1) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_printf(xendev, 0, "reading backend state failed\n");
|
|
|
|
return -1;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (be_state != XenbusStateInitialising) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_printf(xendev, 0, "initial backend state is wrong (%s)\n",
|
|
|
|
xenbus_strstate(be_state));
|
|
|
|
return -1;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
xendev->fe = xenstore_read_be_str(xendev, "frontend");
|
|
|
|
if (xendev->fe == NULL) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_printf(xendev, 0, "reading frontend path failed\n");
|
|
|
|
return -1;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* setup frontend watch */
|
|
|
|
snprintf(token, sizeof(token), "fe:%p", xendev);
|
|
|
|
if (!xs_watch(xenstore, xendev->fe, token)) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_printf(xendev, 0, "watching frontend path (%s) failed\n",
|
|
|
|
xendev->fe);
|
|
|
|
return -1;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
xen_be_set_state(xendev, XenbusStateInitialising);
|
|
|
|
|
|
|
|
xen_be_backend_changed(xendev, NULL);
|
|
|
|
xen_be_frontend_changed(xendev, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try initialize xendev. Prepare everything the backend can do
|
|
|
|
* without synchronizing with the frontend. Fakes hotplug-status. No
|
|
|
|
* hotplug involved here because this is about userspace drivers, thus
|
|
|
|
* there are kernel backend devices which could invoke hotplug.
|
|
|
|
*
|
|
|
|
* Goes to InitWait on success.
|
|
|
|
*/
|
|
|
|
static int xen_be_try_init(struct XenDevice *xendev)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (!xendev->online) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_printf(xendev, 1, "not online\n");
|
|
|
|
return -1;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
2010-09-23 15:28:45 +04:00
|
|
|
if (xendev->ops->init) {
|
|
|
|
rc = xendev->ops->init(xendev);
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
if (rc != 0) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_printf(xendev, 1, "init() failed\n");
|
|
|
|
return rc;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
xenstore_write_be_str(xendev, "hotplug-status", "connected");
|
|
|
|
xen_be_set_state(xendev, XenbusStateInitWait);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-06-17 16:15:35 +04:00
|
|
|
* Try to initialise xendev. Depends on the frontend being ready
|
2009-04-22 19:19:15 +04:00
|
|
|
* for it (shared ring and evtchn info in xenstore, state being
|
|
|
|
* Initialised or Connected).
|
|
|
|
*
|
|
|
|
* Goes to Connected on success.
|
|
|
|
*/
|
2011-06-17 16:15:35 +04:00
|
|
|
static int xen_be_try_initialise(struct XenDevice *xendev)
|
2009-04-22 19:19:15 +04:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (xendev->fe_state != XenbusStateInitialised &&
|
2010-09-23 15:28:45 +04:00
|
|
|
xendev->fe_state != XenbusStateConnected) {
|
|
|
|
if (xendev->ops->flags & DEVOPS_FLAG_IGNORE_STATE) {
|
|
|
|
xen_be_printf(xendev, 2, "frontend not ready, ignoring\n");
|
|
|
|
} else {
|
|
|
|
xen_be_printf(xendev, 2, "frontend not ready (yet)\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
2011-06-17 16:15:35 +04:00
|
|
|
if (xendev->ops->initialise) {
|
|
|
|
rc = xendev->ops->initialise(xendev);
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
if (rc != 0) {
|
2011-06-17 16:15:35 +04:00
|
|
|
xen_be_printf(xendev, 0, "initialise() failed\n");
|
2010-09-23 15:28:45 +04:00
|
|
|
return rc;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
xen_be_set_state(xendev, XenbusStateConnected);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-17 16:15:35 +04:00
|
|
|
/*
|
|
|
|
* Try to let xendev know that it is connected. Depends on the
|
|
|
|
* frontend being Connected. Note that this may be called more
|
|
|
|
* than once since the backend state is not modified.
|
|
|
|
*/
|
|
|
|
static void xen_be_try_connected(struct XenDevice *xendev)
|
|
|
|
{
|
|
|
|
if (!xendev->ops->connected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xendev->fe_state != XenbusStateConnected) {
|
|
|
|
if (xendev->ops->flags & DEVOPS_FLAG_IGNORE_STATE) {
|
|
|
|
xen_be_printf(xendev, 2, "frontend not ready, ignoring\n");
|
|
|
|
} else {
|
|
|
|
xen_be_printf(xendev, 2, "frontend not ready (yet)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xendev->ops->connected(xendev);
|
|
|
|
}
|
|
|
|
|
2009-04-22 19:19:15 +04:00
|
|
|
/*
|
|
|
|
* Teardown connection.
|
|
|
|
*
|
|
|
|
* Goes to Closed when done.
|
|
|
|
*/
|
|
|
|
static void xen_be_disconnect(struct XenDevice *xendev, enum xenbus_state state)
|
|
|
|
{
|
|
|
|
if (xendev->be_state != XenbusStateClosing &&
|
|
|
|
xendev->be_state != XenbusStateClosed &&
|
2010-09-23 15:28:45 +04:00
|
|
|
xendev->ops->disconnect) {
|
|
|
|
xendev->ops->disconnect(xendev);
|
|
|
|
}
|
|
|
|
if (xendev->be_state != state) {
|
2009-04-22 19:19:15 +04:00
|
|
|
xen_be_set_state(xendev, state);
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to reset xendev, for reconnection by another frontend instance.
|
|
|
|
*/
|
|
|
|
static int xen_be_try_reset(struct XenDevice *xendev)
|
|
|
|
{
|
2010-09-23 15:28:45 +04:00
|
|
|
if (xendev->fe_state != XenbusStateInitialising) {
|
2009-04-22 19:19:15 +04:00
|
|
|
return -1;
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
|
|
|
|
xen_be_printf(xendev, 1, "device reset (for re-connect)\n");
|
|
|
|
xen_be_set_state(xendev, XenbusStateInitialising);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* state change dispatcher function
|
|
|
|
*/
|
|
|
|
void xen_be_check_state(struct XenDevice *xendev)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
/* frontend may request shutdown from almost anywhere */
|
|
|
|
if (xendev->fe_state == XenbusStateClosing ||
|
2010-09-23 15:28:45 +04:00
|
|
|
xendev->fe_state == XenbusStateClosed) {
|
|
|
|
xen_be_disconnect(xendev, xendev->fe_state);
|
|
|
|
return;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check for possible backend state transitions */
|
|
|
|
for (;;) {
|
2010-09-23 15:28:45 +04:00
|
|
|
switch (xendev->be_state) {
|
|
|
|
case XenbusStateUnknown:
|
|
|
|
rc = xen_be_try_setup(xendev);
|
|
|
|
break;
|
|
|
|
case XenbusStateInitialising:
|
|
|
|
rc = xen_be_try_init(xendev);
|
|
|
|
break;
|
|
|
|
case XenbusStateInitWait:
|
2011-06-17 16:15:35 +04:00
|
|
|
rc = xen_be_try_initialise(xendev);
|
|
|
|
break;
|
|
|
|
case XenbusStateConnected:
|
|
|
|
/* xendev->be_state doesn't change */
|
|
|
|
xen_be_try_connected(xendev);
|
|
|
|
rc = -1;
|
2010-09-23 15:28:45 +04:00
|
|
|
break;
|
2009-04-22 19:19:15 +04:00
|
|
|
case XenbusStateClosed:
|
|
|
|
rc = xen_be_try_reset(xendev);
|
|
|
|
break;
|
2010-09-23 15:28:45 +04:00
|
|
|
default:
|
|
|
|
rc = -1;
|
|
|
|
}
|
|
|
|
if (rc != 0) {
|
|
|
|
break;
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops)
|
|
|
|
{
|
|
|
|
struct XenDevice *xendev;
|
|
|
|
char path[XEN_BUFSIZE], token[XEN_BUFSIZE];
|
2013-10-10 18:25:52 +04:00
|
|
|
char **dev = NULL;
|
2009-04-22 19:19:15 +04:00
|
|
|
unsigned int cdev, j;
|
|
|
|
|
|
|
|
/* setup watch */
|
|
|
|
snprintf(token, sizeof(token), "be:%p:%d:%p", type, dom, ops);
|
2013-10-10 18:25:52 +04:00
|
|
|
snprintf(path, sizeof(path), "backend/%s/%d", type, dom);
|
2009-04-22 19:19:15 +04:00
|
|
|
if (!xs_watch(xenstore, path, token)) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_printf(NULL, 0, "xen be: watching backend path (%s) failed\n", path);
|
|
|
|
return -1;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* look for backends */
|
|
|
|
dev = xs_directory(xenstore, 0, path, &cdev);
|
2010-09-23 15:28:45 +04:00
|
|
|
if (!dev) {
|
|
|
|
return 0;
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
for (j = 0; j < cdev; j++) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xendev = xen_be_get_xendev(type, dom, atoi(dev[j]), ops);
|
|
|
|
if (xendev == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
xen_be_check_state(xendev);
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
free(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xenstore_update_be(char *watch, char *type, int dom,
|
2010-09-23 15:28:45 +04:00
|
|
|
struct XenDevOps *ops)
|
2009-04-22 19:19:15 +04:00
|
|
|
{
|
|
|
|
struct XenDevice *xendev;
|
2013-10-10 18:25:52 +04:00
|
|
|
char path[XEN_BUFSIZE], *bepath;
|
2009-04-22 19:19:15 +04:00
|
|
|
unsigned int len, dev;
|
|
|
|
|
2013-10-10 18:25:52 +04:00
|
|
|
len = snprintf(path, sizeof(path), "backend/%s/%d", type, dom);
|
2010-09-23 15:28:45 +04:00
|
|
|
if (strncmp(path, watch, len) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
if (sscanf(watch+len, "/%u/%255s", &dev, path) != 2) {
|
2010-09-23 15:28:45 +04:00
|
|
|
strcpy(path, "");
|
|
|
|
if (sscanf(watch+len, "/%u", &dev) != 1) {
|
|
|
|
dev = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dev == -1) {
|
|
|
|
return;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
xendev = xen_be_get_xendev(type, dom, dev, ops);
|
|
|
|
if (xendev != NULL) {
|
2012-03-30 18:33:03 +04:00
|
|
|
bepath = xs_read(xenstore, 0, xendev->be, &len);
|
|
|
|
if (bepath == NULL) {
|
|
|
|
xen_be_del_xendev(dom, dev);
|
|
|
|
} else {
|
|
|
|
free(bepath);
|
|
|
|
xen_be_backend_changed(xendev, path);
|
|
|
|
xen_be_check_state(xendev);
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xenstore_update_fe(char *watch, struct XenDevice *xendev)
|
|
|
|
{
|
|
|
|
char *node;
|
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
len = strlen(xendev->fe);
|
2010-09-23 15:28:45 +04:00
|
|
|
if (strncmp(xendev->fe, watch, len) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (watch[len] != '/') {
|
|
|
|
return;
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
node = watch + len + 1;
|
|
|
|
|
|
|
|
xen_be_frontend_changed(xendev, node);
|
|
|
|
xen_be_check_state(xendev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xenstore_update(void *unused)
|
|
|
|
{
|
|
|
|
char **vec = NULL;
|
|
|
|
intptr_t type, ops, ptr;
|
|
|
|
unsigned int dom, count;
|
|
|
|
|
|
|
|
vec = xs_read_watch(xenstore, &count);
|
2010-09-23 15:28:45 +04:00
|
|
|
if (vec == NULL) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
|
|
|
|
if (sscanf(vec[XS_WATCH_TOKEN], "be:%" PRIxPTR ":%d:%" PRIxPTR,
|
2010-09-23 15:28:45 +04:00
|
|
|
&type, &dom, &ops) == 3) {
|
|
|
|
xenstore_update_be(vec[XS_WATCH_PATH], (void*)type, dom, (void*)ops);
|
|
|
|
}
|
|
|
|
if (sscanf(vec[XS_WATCH_TOKEN], "fe:%" PRIxPTR, &ptr) == 1) {
|
|
|
|
xenstore_update_fe(vec[XS_WATCH_PATH], (void*)ptr);
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
|
|
|
|
cleanup:
|
2009-11-15 21:18:19 +03:00
|
|
|
free(vec);
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_be_evtchn_event(void *opaque)
|
|
|
|
{
|
|
|
|
struct XenDevice *xendev = opaque;
|
|
|
|
evtchn_port_t port;
|
|
|
|
|
2016-01-15 16:23:38 +03:00
|
|
|
port = xenevtchn_pending(xendev->evtchndev);
|
2009-04-22 19:19:15 +04:00
|
|
|
if (port != xendev->local_port) {
|
2016-01-15 16:23:38 +03:00
|
|
|
xen_be_printf(xendev, 0,
|
|
|
|
"xenevtchn_pending returned %d (expected %d)\n",
|
2010-09-23 15:28:45 +04:00
|
|
|
port, xendev->local_port);
|
|
|
|
return;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
2016-01-15 16:23:38 +03:00
|
|
|
xenevtchn_unmask(xendev->evtchndev, port);
|
2009-04-22 19:19:15 +04:00
|
|
|
|
2010-09-23 15:28:45 +04:00
|
|
|
if (xendev->ops->event) {
|
|
|
|
xendev->ops->event(xendev);
|
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int xen_be_init(void)
|
|
|
|
{
|
|
|
|
xenstore = xs_daemon_open();
|
|
|
|
if (!xenstore) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_printf(NULL, 0, "can't connect to xenstored\n");
|
|
|
|
return -1;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
2015-06-04 09:45:22 +03:00
|
|
|
qemu_set_fd_handler(xs_fileno(xenstore), xenstore_update, NULL, NULL);
|
2009-04-22 19:19:15 +04:00
|
|
|
|
2016-02-10 14:07:03 +03:00
|
|
|
if (xen_xc == NULL || xen_fmem == NULL) {
|
2010-08-19 15:27:56 +04:00
|
|
|
/* Check if xen_init() have been called */
|
2010-09-23 15:28:45 +04:00
|
|
|
goto err;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
2016-06-13 12:12:21 +03:00
|
|
|
|
|
|
|
xen_sysdev = qdev_create(NULL, TYPE_XENSYSDEV);
|
|
|
|
qdev_init_nofail(xen_sysdev);
|
|
|
|
|
2009-04-22 19:19:15 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
qemu_set_fd_handler(xs_fileno(xenstore), NULL, NULL, NULL);
|
|
|
|
xs_daemon_close(xenstore);
|
|
|
|
xenstore = NULL;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xen_be_register(const char *type, struct XenDevOps *ops)
|
|
|
|
{
|
2016-05-12 17:13:40 +03:00
|
|
|
char path[50];
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (ops->backend_register) {
|
|
|
|
rc = ops->backend_register();
|
|
|
|
if (rc) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(path, sizeof(path), "device-model/%u/backends/%s", xen_domid,
|
|
|
|
type);
|
|
|
|
xenstore_mkdir(path, XS_PERM_NONE);
|
|
|
|
|
2009-04-22 19:19:15 +04:00
|
|
|
return xenstore_scan(type, xen_domid, ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
int xen_be_bind_evtchn(struct XenDevice *xendev)
|
|
|
|
{
|
2010-09-23 15:28:45 +04:00
|
|
|
if (xendev->local_port != -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-01-15 16:23:38 +03:00
|
|
|
xendev->local_port = xenevtchn_bind_interdomain
|
2010-09-23 15:28:45 +04:00
|
|
|
(xendev->evtchndev, xendev->dom, xendev->remote_port);
|
2009-04-22 19:19:15 +04:00
|
|
|
if (xendev->local_port == -1) {
|
2016-01-15 16:23:38 +03:00
|
|
|
xen_be_printf(xendev, 0, "xenevtchn_bind_interdomain failed\n");
|
2010-09-23 15:28:45 +04:00
|
|
|
return -1;
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
xen_be_printf(xendev, 2, "bind evtchn port %d\n", xendev->local_port);
|
2016-01-15 16:23:38 +03:00
|
|
|
qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev),
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_evtchn_event, NULL, xendev);
|
2009-04-22 19:19:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void xen_be_unbind_evtchn(struct XenDevice *xendev)
|
|
|
|
{
|
2010-09-23 15:28:45 +04:00
|
|
|
if (xendev->local_port == -1) {
|
|
|
|
return;
|
|
|
|
}
|
2016-01-15 16:23:38 +03:00
|
|
|
qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), NULL, NULL, NULL);
|
|
|
|
xenevtchn_unbind(xendev->evtchndev, xendev->local_port);
|
2009-04-22 19:19:15 +04:00
|
|
|
xen_be_printf(xendev, 2, "unbind evtchn port %d\n", xendev->local_port);
|
|
|
|
xendev->local_port = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xen_be_send_notify(struct XenDevice *xendev)
|
|
|
|
{
|
2016-01-15 16:23:38 +03:00
|
|
|
return xenevtchn_notify(xendev->evtchndev, xendev->local_port);
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* msg_level:
|
|
|
|
* 0 == errors (stderr + logfile).
|
|
|
|
* 1 == informative debug messages (logfile only).
|
|
|
|
* 2 == noisy debug messages (logfile only).
|
|
|
|
* 3 == will flood your log (logfile only).
|
|
|
|
*/
|
|
|
|
void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (xendev) {
|
2010-09-23 15:28:45 +04:00
|
|
|
if (msg_level > xendev->debug) {
|
2009-04-22 19:19:15 +04:00
|
|
|
return;
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
qemu_log("xen be: %s: ", xendev->name);
|
2010-09-23 15:28:45 +04:00
|
|
|
if (msg_level == 0) {
|
2009-04-22 19:19:15 +04:00
|
|
|
fprintf(stderr, "xen be: %s: ", xendev->name);
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
} else {
|
2010-09-23 15:28:45 +04:00
|
|
|
if (msg_level > debug) {
|
2009-04-22 19:19:15 +04:00
|
|
|
return;
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
qemu_log("xen be core: ");
|
2010-09-23 15:28:45 +04:00
|
|
|
if (msg_level == 0) {
|
2009-04-22 19:19:15 +04:00
|
|
|
fprintf(stderr, "xen be core: ");
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:15 +04:00
|
|
|
}
|
|
|
|
va_start(args, fmt);
|
|
|
|
qemu_log_vprintf(fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
if (msg_level == 0) {
|
|
|
|
va_start(args, fmt);
|
|
|
|
vfprintf(stderr, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
qemu_log_flush();
|
|
|
|
}
|
2016-06-13 12:12:21 +03:00
|
|
|
|
|
|
|
static int xen_sysdev_init(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Property xen_sysdev_properties[] = {
|
|
|
|
{/* end of property list */},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void xen_sysdev_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
k->init = xen_sysdev_init;
|
|
|
|
dc->props = xen_sysdev_properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo xensysdev_info = {
|
|
|
|
.name = TYPE_XENSYSDEV,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(SysBusDevice),
|
|
|
|
.class_init = xen_sysdev_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void xenbe_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&xensysdev_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(xenbe_register_types);
|