From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Campbell Subject: Re: [PATCH 18/18] xenstored: Add stub domain builder Date: Wed, 18 Jan 2012 11:50:40 +0000 Message-ID: <1326887440.14689.217.camel@zakaz.uk.xensource.com> References: <1326302490-19428-1-git-send-email-dgdegra@tycho.nsa.gov> <1326411330-7915-1-git-send-email-dgdegra@tycho.nsa.gov> <1326411330-7915-19-git-send-email-dgdegra@tycho.nsa.gov> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1326411330-7915-19-git-send-email-dgdegra@tycho.nsa.gov> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Daniel De Graaf Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org On Thu, 2012-01-12 at 23:35 +0000, Daniel De Graaf wrote: > Signed-off-by: Daniel De Graaf I think eventually we should aim to have this be a rough drop in replacement for /usr/sbin/*xenstored (similar params where it makes sense etc) but this will do for now: Acked-by: Ian Campbell > --- > 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 > + * > + * 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 > + > +#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 > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +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 \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; > +}