|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH] xenbus: Add support for xenbus backend in stub domain
This adds two ioctls to the /dev/xen/xenbus_backend device allowing the
xenbus backend to be started after the kernel has booted. This is
intended to allow dom0 to start another domain to run xenstore.
IOCTL_XENBUS_BACKEND_REMOTE_SETUP requires that the xenstore domain be
started; the domain ID is passed as the ioctl argument. This sets up a
listening event channel and grant reference to xenbus, but does not
start using this interface. It returns the local event channel port.
IOCTL_XENBUS_BACKEND_REMOTE_COMMIT causes the kernel to begin using the
event channel set up in the previous ioctl, reregistering all watches
and deallocating the previous xenstored event channel.
Signed-off-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
---
drivers/xen/xenbus/xenbus_comms.c | 6 +++
drivers/xen/xenbus/xenbus_comms.h | 1 +
drivers/xen/xenbus/xenbus_dev_backend.c | 57 +++++++++++++++++++++++++++++++
include/xen/grant_table.h | 2 +
include/xen/xenbus_dev.h | 6 +++
5 files changed, 72 insertions(+), 0 deletions(-)
diff --git a/drivers/xen/xenbus/xenbus_comms.c
b/drivers/xen/xenbus/xenbus_comms.c
index 2eff7a6..52fe7ad 100644
--- a/drivers/xen/xenbus/xenbus_comms.c
+++ b/drivers/xen/xenbus/xenbus_comms.c
@@ -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;
+}
diff --git a/drivers/xen/xenbus/xenbus_comms.h
b/drivers/xen/xenbus/xenbus_comms.h
index 6e42800..c8abd3b 100644
--- a/drivers/xen/xenbus/xenbus_comms.h
+++ b/drivers/xen/xenbus/xenbus_comms.h
@@ -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);
diff --git a/drivers/xen/xenbus/xenbus_dev_backend.c
b/drivers/xen/xenbus/xenbus_dev_backend.c
index 3d3be78..4138ba2 100644
--- a/drivers/xen/xenbus/xenbus_dev_backend.c
+++ b/drivers/xen/xenbus/xenbus_dev_backend.c
@@ -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"
@@ -22,6 +26,53 @@ static int xenbus_backend_open(struct inode *inode, struct
file *filp)
return nonseekable_open(inode, filp);
}
+static int pending_xsd_port;
+
+static long xenbus_backend_remote_setup(domid_t domid)
+{
+ struct evtchn_alloc_unbound arg;
+ int err;
+
+ gnttab_grant_foreign_access_ref(GNTTAB_RESERVED_XENSTORE, domid,
+ virt_to_mfn(xen_store_interface), 0 /* writable */);
+
+ if (pending_xsd_port) {
+ struct evtchn_close close;
+ close.port = pending_xsd_port;
+ err = HYPERVISOR_event_channel_op(EVTCHNOP_close, &close);
+ WARN_ON(err);
+ }
+
+ arg.dom = DOMID_SELF;
+ arg.remote_dom = domid;
+
+ err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &arg);
+ if (err)
+ return err;
+
+ pending_xsd_port = arg.port;
+
+ return arg.port;
+}
+
+static long xenbus_backend_remote_commit(unsigned long data)
+{
+ if (!pending_xsd_port)
+ return -EINVAL;
+
+ xs_suspend();
+
+ if (xen_store_evtchn > 0)
+ xb_deinit_comms();
+
+ xen_store_evtchn = pending_xsd_port;
+ pending_xsd_port = 0;
+
+ xs_resume();
+
+ return 0;
+}
+
static long xenbus_backend_ioctl(struct file *file, unsigned int cmd, unsigned
long data)
{
if (!capable(CAP_SYS_ADMIN))
@@ -33,6 +84,12 @@ static long xenbus_backend_ioctl(struct file *file, unsigned
int cmd, unsigned l
return xen_store_evtchn;
return -ENODEV;
+ case IOCTL_XENBUS_BACKEND_REMOTE_SETUP:
+ return xenbus_backend_remote_setup(data);
+
+ case IOCTL_XENBUS_BACKEND_REMOTE_COMMIT:
+ return xenbus_backend_remote_commit(data);
+
default:
return -ENOTTY;
}
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
index 15f8a00..11e27c3 100644
--- a/include/xen/grant_table.h
+++ b/include/xen/grant_table.h
@@ -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
diff --git a/include/xen/xenbus_dev.h b/include/xen/xenbus_dev.h
index ac5f0fe..24d5028 100644
--- a/include/xen/xenbus_dev.h
+++ b/include/xen/xenbus_dev.h
@@ -38,4 +38,10 @@
#define IOCTL_XENBUS_BACKEND_EVTCHN \
_IOC(_IOC_NONE, 'B', 0, 0)
+#define IOCTL_XENBUS_BACKEND_REMOTE_SETUP \
+ _IOC(_IOC_NONE, 'B', 1, 0)
+
+#define IOCTL_XENBUS_BACKEND_REMOTE_COMMIT \
+ _IOC(_IOC_NONE, 'B', 2, 0)
+
#endif /* __LINUX_XEN_XENBUS_DEV_H__ */
--
1.7.7.5
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |