All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel De Graaf <dgdegra@tycho.nsa.gov>
To: xen-devel@lists.xensource.com
Cc: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Subject: [PATCH 18/18] xenstored: Add stub domain builder
Date: Thu, 12 Jan 2012 18:35:30 -0500	[thread overview]
Message-ID: <1326411330-7915-19-git-send-email-dgdegra@tycho.nsa.gov> (raw)
In-Reply-To: <1326411330-7915-1-git-send-email-dgdegra@tycho.nsa.gov>

Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
 tools/include/xen-sys/Linux/xenbus_dev.h |   55 +++++++++++++++++
 tools/xenstore/Makefile                  |    9 ++-
 tools/xenstore/init-xenstore-domain.c    |   96 ++++++++++++++++++++++++++++++
 3 files changed, 158 insertions(+), 2 deletions(-)
 create mode 100644 tools/include/xen-sys/Linux/xenbus_dev.h
 create mode 100644 tools/xenstore/init-xenstore-domain.c

diff --git a/tools/include/xen-sys/Linux/xenbus_dev.h b/tools/include/xen-sys/Linux/xenbus_dev.h
new file mode 100644
index 0000000..b107be9
--- /dev/null
+++ b/tools/include/xen-sys/Linux/xenbus_dev.h
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * evtchn.h
+ *
+ * Interface to /dev/xen/xenbus_backend.
+ *
+ * Copyright (c) 2011 Bastian Blank <waldi@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation; or, when distributed
+ * separately from the Linux kernel or incorporated into other
+ * software packages, subject to the following license:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this source file (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef __LINUX_XEN_XENBUS_DEV_H__
+#define __LINUX_XEN_XENBUS_DEV_H__
+
+#include <linux/ioctl.h>
+
+#define IOCTL_XENBUS_BACKEND_EVTCHN			\
+	_IOC(_IOC_NONE, 'B', 0, 0)
+
+#define IOCTL_XENBUS_ALLOC				\
+	_IOC(_IOC_NONE, 'B', 1, sizeof(struct ioctl_xenbus_alloc))
+struct ioctl_xenbus_alloc {
+	/* IN */
+	/* The domain ID (must exist) for xenstore */
+	uint16_t dom;
+	uint16_t pad;
+	/* OUT */
+	/* The port allocated for xenbus communication */
+	uint32_t port;
+	/* Always set to GNTTAB_RESERVED_XENSTORE */
+	uint32_t grant_ref;
+};
+
+#endif /* __LINUX_XEN_XENBUS_DEV_H__ */
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 3a061d6..9b411a5 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -26,7 +26,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 -DNO_LOCAL_XENBUS=1 -DNO_SYSLOG=1 -DNO_REOPEN_LOG=1
@@ -50,6 +50,11 @@ 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)
 
@@ -85,7 +90,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 0000000..30f6c9b
--- /dev/null
+++ b/tools/xenstore/init-xenstore-domain.c
@@ -0,0 +1,96 @@
+#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;
+	struct ioctl_xenbus_alloc alloc;
+
+	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;
+
+	alloc.dom = domid;
+	rv = ioctl(xs_fd, IOCTL_XENBUS_ALLOC, &alloc);
+	if (rv) return rv;
+	snprintf(cmdline, 512, "--event %d", alloc.port);
+
+	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;
+}
-- 
1.7.7.5

  parent reply	other threads:[~2012-01-12 23:35 UTC|newest]

Thread overview: 128+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-11 17:21 [RFC PATCH 0/18] Xenstore stub domain Daniel De Graaf
2012-01-11 17:21 ` [PATCH 01/18] xen: reinstate previously unused XENMEM_remove_from_physmap hypercall Daniel De Graaf
2012-01-12  8:22   ` Jan Beulich
2012-01-11 17:21 ` [PATCH 02/18] xen: allow global VIRQ handlers to be delegated to other domains Daniel De Graaf
2012-01-12  8:43   ` Jan Beulich
2012-01-11 17:21 ` [PATCH 03/18] xsm: allow use of XEN_DOMCTL_getdomaininfo by non-IS_PRIV domains Daniel De Graaf
2012-01-11 17:27   ` Keir Fraser
2012-01-11 17:36     ` Daniel De Graaf
2012-01-11 17:49     ` Keir Fraser
2012-01-11 17:21 ` [PATCH 04/18] xen: Preserve reserved grant entries when switching versions Daniel De Graaf
2012-01-12  8:53   ` Jan Beulich
2012-01-12  9:49     ` Ian Campbell
2012-01-12  9:56       ` Ian Campbell
2012-01-11 17:21 ` [PATCH 05/18] tools/libxl: Add xenstore and console backend domain IDs to config Daniel De Graaf
2012-01-11 17:21 ` [PATCH 06/18] lib{xc, xl}: Seed grant tables with xenstore and console grants Daniel De Graaf
2012-01-12  9:59   ` Ian Campbell
2012-01-12 15:11     ` Daniel De Graaf
2012-01-12 16:12       ` Ian Campbell
2012-01-12 17:21       ` Ian Jackson
2012-01-12 17:32         ` Daniel De Graaf
2012-01-12 17:35           ` Ian Jackson
2012-01-12 17:38             ` Ian Campbell
2012-01-12 17:47             ` Daniel De Graaf
2012-01-11 17:21 ` [PATCH 07/18] mini-os: avoid crash if no console is provided Daniel De Graaf
2012-01-12 10:03   ` Ian Campbell
2012-01-12 17:56     ` Daniel De Graaf
2012-01-18 10:21       ` Ian Campbell
2012-01-11 17:21 ` [PATCH 08/18] mini-os: avoid crash if no xenstore " Daniel De Graaf
2012-01-11 17:21 ` [PATCH 09/18] mini-os: remove per-fd evtchn limit Daniel De Graaf
2012-01-11 17:21 ` [PATCH 10/18] xenstored: use grant references instead of map_foreign_range Daniel De Graaf
2012-01-11 17:21 ` [PATCH 11/18] xenstored: add NO_SOCKETS compilation option Daniel De Graaf
2012-01-12 10:05   ` Ian Campbell
2012-01-11 17:21 ` [PATCH 12/18] xenstored support for in-memory rather than FS based trivial DB (needed to run on mini-OS) Daniel De Graaf
2012-01-11 17:21 ` [PATCH 13/18] xenstored: support running in minios stubdom Daniel De Graaf
2012-01-11 17:21 ` [PATCH 14/18] xenstored: always use xc_gnttab_munmap in stubdom Daniel De Graaf
2012-01-11 17:21 ` [PATCH 15/18] xenstored: add --event parameter for bootstrapping Daniel De Graaf
2012-01-11 17:21 ` [PATCH 16/18] xenstored: pull dom0 event port from shared page Daniel De Graaf
2012-01-11 17:21 ` [PATCH 17/18] xenstored: use domain_is_unprivileged instead of checking conn->id Daniel De Graaf
2012-01-11 17:21 ` [PATCH 18/18] xenstored: add --priv-domid parameter Daniel De Graaf
2012-01-12 10:20   ` Ian Campbell
2012-01-12 15:37     ` Daniel De Graaf
2012-01-11 17:22 ` [PATCH] xenbus: Add support for xenbus backend in stub domain Daniel De Graaf
2012-01-12  8:59   ` Jan Beulich
2012-01-12 15:28     ` Daniel De Graaf
2012-01-12 15:40       ` Jan Beulich
2012-01-12 15:58         ` Daniel De Graaf
2012-01-12  9:51 ` [RFC PATCH 0/18] Xenstore " Ian Campbell
2012-01-12  9:57 ` Ian Campbell
2012-01-12 23:32   ` Daniel De Graaf
2012-01-12 10:33 ` Joanna Rutkowska
2012-01-12 10:48   ` Tim Deegan
2012-01-12 11:18     ` On Dom0 disaggregation (was: Re: [RFC PATCH 0/18] Xenstore stub domain) Joanna Rutkowska
2012-01-12 12:13       ` Tim Deegan
2012-01-12 13:30         ` On Dom0 disaggregation Joanna Rutkowska
2012-01-12 14:21           ` Tim Deegan
2012-01-12 14:23           ` Mihir Nanavati
2012-01-12 11:27     ` [RFC PATCH 0/18] Xenstore stub domain Ian Campbell
2012-01-12 11:33       ` Vasiliy Tolstov
2012-01-12 11:46         ` Ian Campbell
2012-01-12 11:35       ` Joanna Rutkowska
2012-01-12 11:46         ` Ian Campbell
2012-01-12 11:00   ` Keir Fraser
2012-01-12 16:12   ` Daniel De Graaf
2012-01-12 23:35 ` [PATCH v2 00/18] " Daniel De Graaf
2012-01-12 23:35   ` [PATCH 01/18] xen: reinstate previously unused XENMEM_remove_from_physmap hypercall Daniel De Graaf
2012-01-13  7:56     ` Jan Beulich
2012-01-18 10:36     ` Ian Campbell
2012-01-18 14:56       ` Daniel De Graaf
2012-01-18 16:06         ` Ian Campbell
2012-01-18 19:07           ` Daniel De Graaf
2012-01-19 10:32             ` Ian Campbell
2012-01-12 23:35   ` [PATCH 02/18] xen: allow global VIRQ handlers to be delegated to other domains Daniel De Graaf
2012-01-13  8:03     ` Jan Beulich
2012-01-13 13:58       ` Daniel De Graaf
2012-01-13 15:32         ` Jan Beulich
2012-01-18 10:39     ` Ian Campbell
2012-01-18 11:28       ` Jan Beulich
2012-01-18 11:44         ` Ian Campbell
2012-01-12 23:35   ` [PATCH 03/18] xen: use XSM instead of IS_PRIV for getdomaininfo Daniel De Graaf
2012-01-12 23:35   ` [PATCH 04/18] xen: Preserve reserved grant entries when switching versions Daniel De Graaf
2012-01-13  8:07     ` Jan Beulich
2012-01-18 10:43     ` Ian Campbell
2012-01-12 23:35   ` [PATCH 05/18] tools/libxl: pull xenstore/console domids from xenstore Daniel De Graaf
2012-01-18 10:47     ` Ian Campbell
2012-01-12 23:35   ` [PATCH 06/18] lib{xc, xl}: Seed grant tables with xenstore and console grants Daniel De Graaf
2012-01-18 11:05     ` Ian Campbell
2012-01-20 20:24       ` Daniel De Graaf
2012-01-12 23:35   ` [PATCH 07/18] mini-os: avoid crash if no console is provided Daniel De Graaf
2012-01-18 11:06     ` Ian Campbell
2012-01-12 23:35   ` [PATCH 08/18] mini-os: avoid crash if no xenstore " Daniel De Graaf
2012-01-18 11:08     ` Ian Campbell
2012-01-12 23:35   ` [PATCH 09/18] mini-os: remove per-fd evtchn limit Daniel De Graaf
2012-01-18 11:10     ` Ian Campbell
2012-01-12 23:35   ` [PATCH 10/18] xenstored: use grant references instead of map_foreign_range Daniel De Graaf
2012-01-18 11:15     ` Ian Campbell
2012-01-18 18:18       ` Daniel De Graaf
2012-01-12 23:35   ` [PATCH 11/18] xenstored: add NO_SOCKETS compilation option Daniel De Graaf
2012-01-18 11:23     ` Ian Campbell
2012-01-12 23:35   ` [PATCH 12/18] xenstored support for in-memory rather than FS based trivial DB (needed to run on mini-OS) Daniel De Graaf
2012-01-18 11:27     ` Ian Campbell
2012-01-12 23:35   ` [PATCH 13/18] xenstored: support running in minios stubdom Daniel De Graaf
2012-01-18 11:33     ` Ian Campbell
2012-01-18 17:13       ` Ian Jackson
2012-01-18 17:35         ` Ian Campbell
2012-01-24 16:24           ` Ian Jackson
2012-01-12 23:35   ` [PATCH 14/18] xenstored: always use xc_gnttab_munmap in stubdom Daniel De Graaf
2012-01-12 23:35   ` [PATCH 15/18] xenstored: add --event parameter for bootstrapping Daniel De Graaf
2012-01-18 11:35     ` Ian Campbell
2012-01-12 23:35   ` [PATCH 16/18] xenstored: use domain_is_unprivileged instead of checking conn->id Daniel De Graaf
2012-01-18 11:44     ` Ian Campbell
2012-01-18 18:31       ` Daniel De Graaf
2012-01-12 23:35   ` [PATCH 17/18] xenstored: add --priv-domid parameter Daniel De Graaf
2012-01-18 11:48     ` Ian Campbell
2012-01-18 14:41       ` Daniel De Graaf
2012-01-18 14:47         ` Ian Campbell
2012-01-12 23:35   ` Daniel De Graaf [this message]
2012-01-18 11:50     ` [PATCH 18/18] xenstored: Add stub domain builder Ian Campbell
2012-01-12 23:36   ` [PATCH] xenbus: Add support for xenbus backend in stub domain Daniel De Graaf
2012-01-13  8:20     ` Jan Beulich
2012-01-13 14:06       ` Daniel De Graaf
2012-01-13 15:37         ` Jan Beulich
2012-01-13 15:44           ` Daniel De Graaf
2012-01-13 16:00             ` Jan Beulich
2012-01-13 17:42               ` Daniel De Graaf
2012-01-16  8:19                 ` Jan Beulich
2012-01-18 12:07     ` Ian Campbell
2012-01-18 14:44       ` Daniel De Graaf
2012-01-18 10:23   ` [PATCH v2 00/18] Xenstore " Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1326411330-7915-19-git-send-email-dgdegra@tycho.nsa.gov \
    --to=dgdegra@tycho.nsa.gov \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.