From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Stabellini Subject: Re: [PATCH 5/5] xcbuild: add console and xenstore support Date: Tue, 26 Jun 2012 18:58:27 +0100 Message-ID: References: <1340381373-22177-1-git-send-email-stefano.stabellini@eu.citrix.com> <1340381373-22177-5-git-send-email-stefano.stabellini@eu.citrix.com> <1340718633.3832.118.camel@zakaz.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1340718633.3832.118.camel@zakaz.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: "xen-devel@lists.xensource.com" , "Tim (Xen.org)" , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org On Tue, 26 Jun 2012, Ian Campbell wrote: > Do you not have libxl and friends up and running sufficiently to use? > This xcbuild was really just intended to tide us over until that stuff > worked, not to be an actual thing... xl/libxl works well enough for basic commands like "xl list", however in order to support something like "xl create" I expect that some more refactoring is needed as well as code motion to arch specific files. Considering that we are in code freeze right now, I thought it wouldn't be acceptable for 4.2, so I didn't even try. > On Fri, 2012-06-22 at 17:09 +0100, Stefano Stabellini wrote: > > Signed-off-by: Stefano Stabellini > > --- > > 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 > > #include > > #include > > +#include > > > > #include > > > > @@ -8,6 +9,7 @@ > > //#include > > #include > > #include > > +#include > > > > 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; > > > > >