Skip to content

Commit

Permalink
xenbus: Add support for xenbus backend in stub domain
Browse files Browse the repository at this point in the history
Add an ioctl to the /dev/xen/xenbus_backend device allowing the xenbus
backend to be started after the kernel has booted. This allows xenstore
to run in a different domain from the dom0.

Signed-off-by: Daniel De Graaf <[email protected]>
Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
  • Loading branch information
dgdegraaf authored and konradwilk committed May 21, 2012
1 parent 2f1bd67 commit d2fb4c5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/xen/xenbus/xenbus_comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,9 @@ int xb_init_comms(void)

return 0;
}

void xb_deinit_comms(void)
{
unbind_from_irqhandler(xenbus_irq, &xb_waitq);
xenbus_irq = 0;
}
1 change: 1 addition & 0 deletions drivers/xen/xenbus/xenbus_comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

int xs_init(void);
int xb_init_comms(void);
void xb_deinit_comms(void);

/* Low level routines. */
int xb_write(const void *data, unsigned len);
Expand Down
51 changes: 51 additions & 0 deletions drivers/xen/xenbus/xenbus_dev_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

#include <xen/xen.h>
#include <xen/page.h>
#include <xen/xenbus.h>
#include <xen/xenbus_dev.h>
#include <xen/grant_table.h>
#include <xen/events.h>
#include <asm/xen/hypervisor.h>

#include "xenbus_comms.h"

Expand All @@ -22,6 +26,50 @@ static int xenbus_backend_open(struct inode *inode, struct file *filp)
return nonseekable_open(inode, filp);
}

static long xenbus_alloc(domid_t domid)
{
struct evtchn_alloc_unbound arg;
int err = -EEXIST;

xs_suspend();

/* If xenstored_ready is nonzero, that means we have already talked to
* xenstore and set up watches. These watches will be restored by
* xs_resume, but that requires communication over the port established
* below that is not visible to anyone until the ioctl returns.
*
* This can be resolved by splitting the ioctl into two parts
* (postponing the resume until xenstored is active) but this is
* unnecessarily complex for the intended use where xenstored is only
* started once - so return -EEXIST if it's already running.
*/
if (xenstored_ready)
goto out_err;

gnttab_grant_foreign_access_ref(GNTTAB_RESERVED_XENSTORE, domid,
virt_to_mfn(xen_store_interface), 0 /* writable */);

arg.dom = DOMID_SELF;
arg.remote_dom = domid;

err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &arg);
if (err)
goto out_err;

if (xen_store_evtchn > 0)
xb_deinit_comms();

xen_store_evtchn = arg.port;

xs_resume();

return arg.port;

out_err:
xs_suspend_cancel();
return err;
}

static long xenbus_backend_ioctl(struct file *file, unsigned int cmd, unsigned long data)
{
if (!capable(CAP_SYS_ADMIN))
Expand All @@ -33,6 +81,9 @@ static long xenbus_backend_ioctl(struct file *file, unsigned int cmd, unsigned l
return xen_store_evtchn;
return -ENODEV;

case IOCTL_XENBUS_BACKEND_SETUP:
return xenbus_alloc(data);

default:
return -ENOTTY;
}
Expand Down
2 changes: 2 additions & 0 deletions include/xen/grant_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

#include <xen/features.h>

#define GNTTAB_RESERVED_XENSTORE 1

/* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */
#define NR_GRANT_FRAMES 4

Expand Down
3 changes: 3 additions & 0 deletions include/xen/xenbus_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@
#define IOCTL_XENBUS_BACKEND_EVTCHN \
_IOC(_IOC_NONE, 'B', 0, 0)

#define IOCTL_XENBUS_BACKEND_SETUP \
_IOC(_IOC_NONE, 'B', 1, 0)

#endif /* __LINUX_XEN_XENBUS_DEV_H__ */

0 comments on commit d2fb4c5

Please sign in to comment.