[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 19/21] HACK: add simple xcbuild



Based on init-xenstore-domain.c.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 tools/xcutils/Makefile  |    6 ++-
 tools/xcutils/xcbuild.c |  100 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 1 deletions(-)
 create mode 100644 tools/xcutils/xcbuild.c

diff --git a/tools/xcutils/Makefile b/tools/xcutils/Makefile
index 6c502f1..dcd2c84 100644
--- a/tools/xcutils/Makefile
+++ b/tools/xcutils/Makefile
@@ -11,7 +11,7 @@
 XEN_ROOT       = $(CURDIR)/../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-PROGRAMS = xc_restore xc_save readnotes lsevtchn
+PROGRAMS = xc_restore xc_save readnotes lsevtchn xcbuild
 
 CFLAGS += -Werror
 
@@ -19,6 +19,7 @@ CFLAGS_xc_restore.o := $(CFLAGS_libxenctrl) 
$(CFLAGS_libxenguest)
 CFLAGS_xc_save.o    := $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) 
$(CFLAGS_libxenstore)
 CFLAGS_readnotes.o  := $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest)
 CFLAGS_lsevtchn.o   := $(CFLAGS_libxenctrl)
+CFLAGS_xcbuild.o    := $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest)
 
 .PHONY: all
 all: build
@@ -32,6 +33,9 @@ xc_restore: xc_restore.o
 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)
+
 readnotes: readnotes.o
        $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) 
$(APPEND_LDFLAGS)
 
diff --git a/tools/xcutils/xcbuild.c b/tools/xcutils/xcbuild.c
new file mode 100644
index 0000000..54f5c38
--- /dev/null
+++ b/tools/xcutils/xcbuild.c
@@ -0,0 +1,100 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <errno.h>
+
+#include <xenctrl.h>
+#include <xentoollog.h>
+#include <xc_dom.h>
+
+int main(int argc, char **argv)
+{
+       xentoollog_logger *logger;
+       xc_interface *xch;
+       int rv;
+       const char *image;
+       uint32_t domid;
+       xen_domain_handle_t handle;
+       int maxmem = 128; /* MB */
+       int memory_kb = 2*(maxmem + 1)*1024; /* bit of slack... */
+       struct xc_dom_image *dom;
+
+       image = (argc < 2) ? "guest.img" : argv[1];
+       printf("Image: %s\n", image);
+       printf("Memory: %dKB\n", memory_kb);
+
+       logger = (xentoollog_logger*)
+               xtl_createlogger_stdiostream(stderr, XTL_DEBUG, 0);
+       if ( logger == NULL )
+       {
+               perror("xtl_createlogger_stdiostream");
+               exit(1);
+       }
+
+       xch = xc_interface_open(logger, logger, 0);
+       if ( xch == NULL )
+       {
+               perror("xc_interface_open");
+               exit(1);
+       }
+
+       rv = xc_dom_loginit(xch);
+       if (rv) return rv;
+
+       //rv = xc_flask_context_to_sid(xch, argv[3], strlen(argv[3]), &ssid);
+       //if (rv) return rv;
+
+       rv = xc_domain_create(xch, 0 /* ssid */, handle, 0 /* flags */, &domid);
+       printf("xc_domain_create: %d (%d)\n", rv, errno);
+       if ( rv < 0 )
+       {
+               perror("xc_domain_create");
+               exit(1);
+       }
+
+       printf("building dom%d\n", domid);
+
+       rv = xc_domain_max_vcpus(xch, domid, 1);
+       if ( rv < 0)
+       {
+               perror("xc_domain_max_vcpus");
+               exit(1);
+       }
+
+       rv = xc_domain_setmaxmem(xch, domid, memory_kb);
+       if ( rv < 0)
+       {
+               perror("xc_domain_setmaxmem");
+               exit(1);
+       }
+
+       dom = xc_dom_allocate(xch, "", NULL);
+       rv = xc_dom_kernel_file(dom, image);
+       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, 2*maxmem);/* XXX */
+       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_unpause(xch, domid);
+       if ( rv )
+       {
+               perror("xc_domain_unpause");
+               exit(1);
+       }
+
+       xc_interface_close(xch);
+
+       return 0;
+}
-- 
1.7.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.