xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: tim@xen.org, Ian.Campbell@citrix.com,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH 5/5] xcbuild: add console and xenstore support
Date: Fri, 22 Jun 2012 17:09:33 +0100	[thread overview]
Message-ID: <1340381373-22177-5-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <1340381373-22177-1-git-send-email-stefano.stabellini@eu.citrix.com>

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 tools/xcutils/Makefile  |    4 +-
 tools/xcutils/xcbuild.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/tools/xcutils/Makefile b/tools/xcutils/Makefile
index 92c5a68..c88f286 100644
--- a/tools/xcutils/Makefile
+++ b/tools/xcutils/Makefile
@@ -20,7 +20,7 @@ CFLAGS_xc_save.o    := $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxe
 CFLAGS_readnotes.o  := $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest)
 CFLAGS_lsevtchn.o   := $(CFLAGS_libxenctrl)
 CFLAGS_xcversion.o  := $(CFLAGS_libxenctrl)
-CFLAGS_xcbuild.o    := $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest)
+CFLAGS_xcbuild.o    := $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore)
 
 .PHONY: all
 all: build
@@ -35,7 +35,7 @@ xc_save: xc_save.o
 	$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS)
 
 xcbuild: xcbuild.o
-	$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS)
 
 readnotes: readnotes.o
 	$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS)
diff --git a/tools/xcutils/xcbuild.c b/tools/xcutils/xcbuild.c
index a70c3ca..7b5c0f8 100644
--- a/tools/xcutils/xcbuild.c
+++ b/tools/xcutils/xcbuild.c
@@ -1,6 +1,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <errno.h>
 
@@ -8,6 +9,7 @@
 //#include <xenguest.h>
 #include <xentoollog.h>
 #include <xc_dom.h>
+#include <xenstore.h>
 
 int main(int argc, char **argv)
 {
@@ -15,11 +17,19 @@ int main(int argc, char **argv)
 	xc_interface *xch;
 	int rv;
 	const char *image;
-	uint32_t domid;
+	uint32_t domid = 1;
 	xen_domain_handle_t handle;
 	int maxmem = 128; /* MB */ //atoi(argv[2]);
 	int memory_kb = 2*(maxmem + 1)*1024; /* bit of slack... */
 	struct xc_dom_image *dom;
+	unsigned long console_mfn;
+	unsigned long console_port;
+	unsigned long store_mfn;
+	unsigned long store_port;
+	struct xs_handle *xs;
+	char *dom_path;
+	char path[256];
+	char val[256];
 
 	image = (argc < 2) ? "guest.img" : argv[1];
 	printf("Image: %s\n", image);
@@ -103,6 +113,52 @@ int main(int argc, char **argv)
 	if (rv) return rv;
 	rv = xc_dom_build_image(dom);
 	if (rv) return rv;
+
+	xc_get_hvm_param(xch, domid, HVM_PARAM_CONSOLE_PFN, &console_mfn);
+	console_port = xc_evtchn_alloc_unbound(xch, domid, 0);
+	xc_set_hvm_param(xch, domid, HVM_PARAM_CONSOLE_EVTCHN, console_port);
+
+	xc_get_hvm_param(xch, domid, HVM_PARAM_STORE_PFN, &store_mfn);
+	store_port = xc_evtchn_alloc_unbound(xch, domid, 0);
+	xc_set_hvm_param(xch, domid, HVM_PARAM_STORE_EVTCHN, store_port);
+	xs = xs_daemon_open();
+	if (xs == NULL) {
+		printf("Could not contact XenStore");
+		return errno;
+	}
+	dom_path = xs_get_domain_path(xs, domid);
+
+	snprintf(path, sizeof(path), "%s/console/port", dom_path);
+	snprintf(val, sizeof(val), "%lu", console_port);
+	xs_write(xs, XBT_NULL, path, val, strlen(val));
+
+	snprintf(path, sizeof(path), "%s/console/ring-ref", dom_path);
+	snprintf(val, sizeof(val), "%lu", console_mfn);
+	xs_write(xs, XBT_NULL, path, val, strlen(val));
+
+	snprintf(path, sizeof(path), "%s/console/type", dom_path);
+	snprintf(val, sizeof(val), "xenconsoled");
+	xs_write(xs, XBT_NULL, path, val, strlen(val));
+
+	snprintf(path, sizeof(path), "%s/console/output", dom_path);
+	snprintf(val, sizeof(val), "pty");
+	xs_write(xs, XBT_NULL, path, val, strlen(val));
+
+	snprintf(path, sizeof(path), "%s/console/limit", dom_path);
+	snprintf(val, sizeof(val), "%d", 1048576);
+	xs_write(xs, XBT_NULL, path, val, strlen(val));
+
+	snprintf(path, sizeof(path), "%s/store/port", dom_path);
+	snprintf(val, sizeof(val), "%lu", store_port);
+	xs_write(xs, XBT_NULL, path, val, strlen(val));
+
+	snprintf(path, sizeof(path), "%s/store/ring-ref", dom_path);
+	snprintf(val, sizeof(val), "%lu", store_mfn);
+	xs_write(xs, XBT_NULL, path, val, strlen(val));
+	xs_introduce_domain(xs, domid, store_mfn, store_port);
+
+	xs_daemon_close(xs);
+
 	rv = xc_dom_boot_image(dom);
 	if (rv) return rv;
 
-- 
1.7.2.5

  parent reply	other threads:[~2012-06-22 16:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-22 16:08 [PATCH 0/5] xen/arm: dom1 PV console up and running Stefano Stabellini
2012-06-22 16:09 ` [PATCH 1/5] xen/arm: implement do_hvm_op for ARM Stefano Stabellini
2012-06-22 16:09   ` [PATCH 2/5] xen/arm: gic and vgic fixes Stefano Stabellini
2012-06-26 14:28     ` Ian Campbell
2012-06-26 17:23       ` Stefano Stabellini
2012-06-22 16:09   ` [PATCH 3/5] xen/arm: disable the event optimization in the gic Stefano Stabellini
2012-06-26 14:29     ` Ian Campbell
2012-06-22 16:09   ` [PATCH 4/5] libxc/arm: allocate xenstore and console pages Stefano Stabellini
2012-06-26 14:34     ` Ian Campbell
2012-06-26 18:05       ` Stefano Stabellini
2012-06-27  8:59         ` Ian Campbell
2012-06-27 12:42           ` Stefano Stabellini
2012-06-22 16:09   ` Stefano Stabellini [this message]
2012-06-26 13:50     ` [PATCH 5/5] xcbuild: add console and xenstore support Ian Campbell
2012-06-26 17:58       ` Stefano Stabellini
2012-06-27  8:55         ` Ian Campbell
2012-06-27 11:02           ` Stefano Stabellini
2012-06-26 14:27   ` [PATCH 1/5] xen/arm: implement do_hvm_op for ARM Ian Campbell
2012-06-26 18:29     ` Stefano Stabellini
2012-06-27  9:02       ` Ian Campbell
2012-06-27 11:04         ` Stefano Stabellini

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=1340381373-22177-5-git-send-email-stefano.stabellini@eu.citrix.com \
    --to=stefano.stabellini@eu.citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=tim@xen.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).