aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenstore
diff options
context:
space:
mode:
authorDaniel De Graaf <dgdegra@tycho.nsa.gov>2012-02-09 18:33:36 +0000
committerDaniel De Graaf <dgdegra@tycho.nsa.gov>2012-02-09 18:33:36 +0000
commited4779111f938d38ddc935cbef252784f70c482b (patch)
tree580e1ebf55792aadc71bfa36516d14b1eac0b4de /tools/xenstore
parent062c8ffe82563c0bbb3f5b52dcad0a72d22bf670 (diff)
downloadxen-ed4779111f938d38ddc935cbef252784f70c482b.tar.gz
xen-ed4779111f938d38ddc935cbef252784f70c482b.tar.bz2
xen-ed4779111f938d38ddc935cbef252784f70c482b.zip
xenstored: Add stub domain builder
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> Acked-by: Ian Campbell <ian.campbell@citrix.com> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Diffstat (limited to 'tools/xenstore')
-rw-r--r--tools/xenstore/Makefile11
-rw-r--r--tools/xenstore/init-xenstore-domain.c94
2 files changed, 102 insertions, 3 deletions
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index e510b4f72d..ea1b89b190 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -27,7 +27,7 @@ LIBXENSTORE := libxenstore.a
xenstore xenstore-control: CFLAGS += -static
endif
-ALL_TARGETS = libxenstore.so libxenstore.a clients xs_tdb_dump xenstored
+ALL_TARGETS = libxenstore.so libxenstore.a clients xs_tdb_dump xenstored init-xenstore-domain
ifdef CONFIG_STUBDOM
CFLAGS += -DNO_SOCKETS=1
@@ -50,7 +50,12 @@ xenstored_probes.o: xenstored_solaris.o
CFLAGS += -DHAVE_DTRACE=1
endif
-
+
+init-xenstore-domain.o: CFLAGS += $(CFLAGS_libxenguest)
+
+init-xenstore-domain: init-xenstore-domain.o $(LIBXENSTORE)
+ $(CC) $(LDFLAGS) $^ $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) -o $@ $(APPEND_LDFLAGS)
+
xenstored: $(XENSTORED_OBJS)
$(CC) $(LDFLAGS) $^ $(LDLIBS_libxenctrl) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
@@ -86,7 +91,7 @@ libxenstore.a: xs.o xs_lib.o
clean:
rm -f *.a *.o *.opic *.so* xenstored_probes.h
rm -f xenstored xs_random xs_stress xs_crashme
- rm -f xs_tdb_dump xenstore-control
+ rm -f xs_tdb_dump xenstore-control init-xenstore-domain
rm -f xenstore $(CLIENTS)
$(RM) $(DEPS)
diff --git a/tools/xenstore/init-xenstore-domain.c b/tools/xenstore/init-xenstore-domain.c
new file mode 100644
index 0000000000..f3a4497bcc
--- /dev/null
+++ b/tools/xenstore/init-xenstore-domain.c
@@ -0,0 +1,94 @@
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <xenctrl.h>
+#include <xc_dom.h>
+#include <xs.h>
+#include <xen/sys/xenbus_dev.h>
+
+static uint32_t domid = -1;
+
+static int build(xc_interface *xch, char** argv)
+{
+ char cmdline[512];
+ uint32_t ssid;
+ xen_domain_handle_t handle = { 0 };
+ int rv;
+ int xs_fd = open("/dev/xen/xenbus_backend", O_RDWR);
+ struct xc_dom_image *dom;
+ int maxmem = atoi(argv[2]);
+ int limit_kb = (maxmem + 1)*1024;
+
+ rv = xc_flask_context_to_sid(xch, argv[3], strlen(argv[3]), &ssid);
+ if (rv) return rv;
+ rv = xc_domain_create(xch, ssid, handle, 0, &domid);
+ if (rv) return rv;
+ rv = xc_domain_max_vcpus(xch, domid, 1);
+ if (rv) return rv;
+ rv = xc_domain_setmaxmem(xch, domid, limit_kb);
+ if (rv) return rv;
+ rv = xc_domain_set_memmap_limit(xch, domid, limit_kb);
+ if (rv) return rv;
+
+ rv = ioctl(xs_fd, IOCTL_XENBUS_BACKEND_SETUP, domid);
+ if (rv < 0) return rv;
+ snprintf(cmdline, 512, "--event %d --internal-db", rv);
+
+ dom = xc_dom_allocate(xch, cmdline, NULL);
+ rv = xc_dom_kernel_file(dom, argv[1]);
+ if (rv) return rv;
+ rv = xc_dom_boot_xen_init(dom, xch, domid);
+ if (rv) return rv;
+ rv = xc_dom_parse_image(dom);
+ if (rv) return rv;
+ rv = xc_dom_mem_init(dom, maxmem);
+ if (rv) return rv;
+ rv = xc_dom_boot_mem_init(dom);
+ if (rv) return rv;
+ rv = xc_dom_build_image(dom);
+ if (rv) return rv;
+ rv = xc_dom_boot_image(dom);
+ if (rv) return rv;
+
+ xc_dom_release(dom);
+
+ rv = xc_domain_set_virq_handler(xch, domid, VIRQ_DOM_EXC);
+ if (rv) return rv;
+ rv = xc_domain_unpause(xch, domid);
+ if (rv) return rv;
+
+ return 0;
+}
+
+int main(int argc, char** argv)
+{
+ xc_interface *xch;
+ struct xs_handle *xsh;
+ char buf[16];
+ int rv;
+
+ if (argc != 4) {
+ printf("Use: %s <xenstore-kernel> <memory_mb> <flask-label>\n", argv[0]);
+ return 2;
+ }
+
+ xch = xc_interface_open(NULL, NULL, 0);
+ if (!xch) return 1;
+
+ rv = build(xch, argv);
+
+ xc_interface_close(xch);
+
+ if (rv) return 1;
+
+ xsh = xs_open(0);
+ rv = snprintf(buf, 16, "%d", domid);
+ xs_write(xsh, XBT_NULL, "/tool/xenstored/domid", buf, rv);
+ xs_daemon_close(xsh);
+
+ return 0;
+}