From 07ab7b9f75c720e7e2a73436ce679224634697a0 Mon Sep 17 00:00:00 2001 From: Jon Ludlam Date: Thu, 1 Nov 2012 10:55:50 +0000 Subject: [PATCH] Remove xiu Signed-off-by: Jon Ludlam --- OMakefile | 2 - ocaml/OMakefile | 1 - ocaml/xiu/OMakefile | 31 -- ocaml/xiu/marshall.h | 140 ------ ocaml/xiu/xenctrl_xiu.c | 619 ------------------------- ocaml/xiu/xiu.ml | 897 ------------------------------------- scripts/init.d-squeezed | 5 - scripts/init.d-xapi | 5 - scripts/init.d-xenservices | 25 -- xapi.spec.in | 2 - 10 files changed, 1727 deletions(-) delete mode 100644 ocaml/xiu/OMakefile delete mode 100644 ocaml/xiu/marshall.h delete mode 100644 ocaml/xiu/xenctrl_xiu.c delete mode 100644 ocaml/xiu/xiu.ml diff --git a/OMakefile b/OMakefile index c4043e4528..5da08f7456 100644 --- a/OMakefile +++ b/OMakefile @@ -163,8 +163,6 @@ OCAML_PHASE3_XEN = \ ocaml/xenops/cancel_utils_test \ ocaml/xenguest/xenguest \ ocaml/xenguest/dumpcore \ - ocaml/xiu/libxenctrl_xiu.so \ - ocaml/xiu/xiu \ ocaml/xapi/quicktestbin \ ocaml/xapi/sparse_dd \ ocaml/xapi/storage_impl_test \ diff --git a/ocaml/OMakefile b/ocaml/OMakefile index 213305f958..be6d049323 100644 --- a/ocaml/OMakefile +++ b/ocaml/OMakefile @@ -27,7 +27,6 @@ OCamlLibrary(fhs, fhs) database \ toplevel \ xstest \ - xiu \ cdrommon \ gpg \ db_process \ diff --git a/ocaml/xiu/OMakefile b/ocaml/xiu/OMakefile deleted file mode 100644 index 090b0ddaaa..0000000000 --- a/ocaml/xiu/OMakefile +++ /dev/null @@ -1,31 +0,0 @@ -OCAMLPACKS = stdext xenstore netdev log -OCAML_LIBS += ../util/version ../fhs ../idl/ocaml_backend/common ../xenops/xenops -OCAMLINCLUDES += ../xapi ../xenops .. - -CFLAGS = -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-strict-aliasing -std=gnu99 -fPIC -CFLAGS += -mno-tls-direct-seg-refs -CFLAGS += -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -Werror -Wmissing-prototypes -CFLAGS += -D__XEN_TOOLS__ -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -LDFLAGS= - -OCamlProgram(xiu, xiu) -OCamlDocProgram(xiu, xiu) -DynamicCLibrary(libxenctrl_xiu, xenctrl_xiu) - -.PHONY: clean -clean: - rm -rf $(CLEAN_OBJS) xiu libxenctrl_xiu.so - -.PHONY: install -install: - mkdir -p $(DESTDIR)$(LIBEXECDIR) - $(IPROG) xiu $(DESTDIR)$(LIBEXECDIR)/ - mkdir -p $(DESTDIR)$(OPTDIR)/lib - $(IDATA) libxenctrl_xiu.so $(DESTDIR)$(OPTDIR)/lib - -.PHONY: sdk-install -sdk-install: - mkdir -p $(DESTDIR)$(LIBEXECDIR) - $(IPROG) xiu $(DESTDIR)$(LIBEXECDIR)/ - mkdir -p $(DESTDIR)$(OPTDIR)/lib - $(IDATA) libxenctrl_xiu.so $(DESTDIR)$(OPTDIR)/lib diff --git a/ocaml/xiu/marshall.h b/ocaml/xiu/marshall.h deleted file mode 100644 index 25856dd742..0000000000 --- a/ocaml/xiu/marshall.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 2006-2009 Citrix Systems Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; version 2.1 only. with the special - * exception on linking described in file LICENSE. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - */ - -#ifndef FAKE_MARSHALL_H -#define FAKE_MARSHALL_H - -#include -#include -#include - -static int marshall_command(int handle, const char *fmt, ...) -{ - va_list ap; - char buf[256]; - int ret; - - va_start(ap, fmt); - ret = vsnprintf(buf, 256, fmt, ap); - va_end(ap); - - if (ret > 255) - return -1; - if(write(handle, buf, ret) < ret) - return -1; - return 0; -} - -static char ** string_split(const char *s, const char c) -{ - int found, i; - char **ret; - char *end; - - for (found = i = 0; s[i]; i++) - if (s[i] == c) found++; - ret = calloc(found + 2, sizeof(char *)); - if (!ret) - return NULL; - for (i = 0; i < found + 1; i++) { - end = strchr(s, c); - if (!end) { - ret[i] = strdup(s); - break; - } - - ret[i] = strndup(s, end - s); - s = end + 1; - } - return ret; -} - -static void string_split_free(char **ss) -{ - int i; - for (i = 0; ss[i] != NULL; i++) - free(ss[i]); - free(ss); -} - -static int get_line(int handle, char *buf) -{ - int offset = 0; - memset(buf, '\0', 256); - while (1) { - int r = read(handle, buf + offset, 1); - if (r == -1 || r == 0) break; - if (buf[offset] == '\n') - break; - else { - if (offset >= 255) - break; - else - offset += 1; - } - } - return offset; -} - - -static int64_t unmarshall_int64(int handle) -{ - char buf[256]; - int negative; - int64_t ret; - - ret = get_line(handle, buf); - if (ret == 0) - return -EBADF; - negative = (buf[0] == '-'); - ret = atoll(buf + (negative ? 1 : 0)); - return (negative ? -ret : ret); -} - -static int unmarshall_int(int handle) -{ - return (uint32_t) unmarshall_int64(handle); -} - -static int parse_uuid(char *s, int uuid[]) -{ - #define UUID_FMT "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" - sscanf(s, UUID_FMT, uuid + 0, uuid + 1, uuid + 2, uuid + 3, - uuid + 4, uuid + 5, uuid + 6, uuid + 7, - uuid + 8, uuid + 9, uuid + 10, uuid + 11, - uuid + 12, uuid + 13, uuid + 14, uuid + 15); - return 0; -} - -static char **unmarshall_multiple(int handle) -{ - char buf[256]; - int ret; - - ret = get_line(handle, buf); - if (ret == 0) - return NULL; - return string_split(buf, ','); -} - -static int unmarshall_return(int handle) -{ - int ret; - ret = unmarshall_int(handle); - if (ret < 0) - errno = -ret; - return ret; -} - -#endif /* !FAKE_MARSHALL_H */ diff --git a/ocaml/xiu/xenctrl_xiu.c b/ocaml/xiu/xenctrl_xiu.c deleted file mode 100644 index 6647ab1e71..0000000000 --- a/ocaml/xiu/xenctrl_xiu.c +++ /dev/null @@ -1,619 +0,0 @@ -/* - * Copyright (C) 2010 Citrix Systems Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; version 2.1 only. with the special - * exception on linking described in file LICENSE. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - */ - -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include "marshall.h" - -#define IPRINTF(_x, _f, _a...) xc_osdep_log(_x,XTL_INFO,0, _f , ## _a) - -#define ERROR(_x, _m, _a...) xc_osdep_log(_x,XTL_ERROR,XC_INTERNAL_ERROR,_m , ## _a ) -#define PERROR(_x, _m, _a...) xc_osdep_log(_x,XTL_ERROR,XC_INTERNAL_ERROR,_m \ - " (%d = %s)", ## _a , errno, xc_strerror(xch, errno)) - -#define HYPCALLcmd "hypcall" - -static xc_osdep_handle xiu_privcmd_open(xc_interface *xch) -{ - struct sockaddr_un remote; - char *s; - int fd, len; - - s = getenv("XIU"); - if (!s) - { - ERROR(xch, "XIU not found. Set $XIU"); - return XC_OSDEP_OPEN_ERROR; - } - - snprintf(remote.sun_path, sizeof(remote.sun_path), "%s-xc", s); - remote.sun_family = AF_UNIX; - len = strlen(remote.sun_path) + sizeof(remote.sun_family); - - fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (fd == -1) - { - ERROR(xch, "XIU: Cannot open Unix domain socket"); - return XC_OSDEP_OPEN_ERROR; - } - - if (connect(fd, (struct sockaddr *)&remote, len) != 0) - { - ERROR(xch, "XIU: Cannot connect to Unix domain socket %s.", remote.sun_path); - return XC_OSDEP_OPEN_ERROR; - } - - return (xc_osdep_handle)fd; -} - -static int xiu_privcmd_close(xc_interface *xch, xc_osdep_handle h) -{ - int fd = (int)h; - return close(fd); -} - -#define DOMAINHANDLE "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x" - -static int fake_xen_domctl(int fd, struct xen_domctl *domctl) -{ - #define DOMCTLcmd "domctl" - switch (domctl->cmd) { - case XEN_DOMCTL_pausedomain: - case XEN_DOMCTL_unpausedomain: - case XEN_DOMCTL_resumedomain: - case XEN_DOMCTL_destroydomain: - marshall_command(fd, "%s,%d,%d\n", DOMCTLcmd, domctl->cmd, domctl->domain); - return unmarshall_return(fd); - case XEN_DOMCTL_createdomain: /* W ssidref */ - marshall_command(fd, "%s,%d,%d,%d," DOMAINHANDLE "\n", DOMCTLcmd, - domctl->cmd, - (domctl->u.createdomain.flags|XEN_DOMCTL_CDF_hvm_guest)?1:0, - (domctl->u.createdomain.flags|XEN_DOMCTL_CDF_hap)?1:0, - domctl->u.createdomain.handle[0], - domctl->u.createdomain.handle[1], - domctl->u.createdomain.handle[2], - domctl->u.createdomain.handle[3], - domctl->u.createdomain.handle[4], - domctl->u.createdomain.handle[5], - domctl->u.createdomain.handle[6], - domctl->u.createdomain.handle[7], - domctl->u.createdomain.handle[8], - domctl->u.createdomain.handle[9], - domctl->u.createdomain.handle[10], - domctl->u.createdomain.handle[11], - domctl->u.createdomain.handle[12], - domctl->u.createdomain.handle[13], - domctl->u.createdomain.handle[14], - domctl->u.createdomain.handle[15]); - domctl->domain = unmarshall_int(fd); - return unmarshall_return(fd); - case XEN_DOMCTL_max_mem: /* W domid, maxmem */ - marshall_command(fd, "%s,%d,%d,%d\n", DOMCTLcmd, - domctl->cmd, - domctl->domain, domctl->u.max_mem.max_memkb); - return unmarshall_return(fd); - case XEN_DOMCTL_settimeoffset: /* W domid, time */ - marshall_command(fd, "%s,%d,%d,%d\n", DOMCTLcmd, - domctl->cmd, - domctl->domain, - domctl->u.settimeoffset.time_offset_seconds); - return unmarshall_return(fd); -#ifdef XEN_DOMCTL_setvmxassist - case XEN_DOMCTL_setvmxassist: /* W domid, use_vmxassist */ - marshall_command(fd, "%s,%d,%d,%d\n", DOMCTLcmd, - domctl->cmd, - domctl->domain, - domctl->u.setvmxassist.use_vmxassist); - return unmarshall_return(fd); -#endif - case XEN_DOMCTL_max_vcpus: /* W domid, max */ - marshall_command(fd, "%s,%d,%d,%d\n", DOMCTLcmd, - domctl->cmd, - domctl->domain, - domctl->u.max_vcpus.max); - return unmarshall_return(fd); - case XEN_DOMCTL_setdomainhandle: { /* domid, fd */ - marshall_command(fd, "%s,%d,%d," DOMAINHANDLE "\n", DOMCTLcmd, - domctl->cmd, - domctl->domain, - domctl->u.setdomainhandle.handle[0], - domctl->u.setdomainhandle.handle[1], - domctl->u.setdomainhandle.handle[2], - domctl->u.setdomainhandle.handle[3], - domctl->u.setdomainhandle.handle[4], - domctl->u.setdomainhandle.handle[5], - domctl->u.setdomainhandle.handle[6], - domctl->u.setdomainhandle.handle[7], - domctl->u.setdomainhandle.handle[8], - domctl->u.setdomainhandle.handle[9], - domctl->u.setdomainhandle.handle[10], - domctl->u.setdomainhandle.handle[11], - domctl->u.setdomainhandle.handle[12], - domctl->u.setdomainhandle.handle[13], - domctl->u.setdomainhandle.handle[14], - domctl->u.setdomainhandle.handle[15]); - return unmarshall_return(fd); - } - /* just returning success : might need init */ - case XEN_DOMCTL_getvcpucontext: - case XEN_DOMCTL_getvcpuaffinity: - return 0; - /* just returning success */ - case XEN_DOMCTL_scheduler_op: - return 0; - case XEN_DOMCTL_shadow_op: - /* Only fd set/get allocation at the moment */ - marshall_command(fd, "%s,%d,%d,%d,%d,%d\n", DOMCTLcmd, - domctl->cmd, - domctl->domain, - domctl->u.shadow_op.op, - domctl->u.shadow_op.mode, - domctl->u.shadow_op.mb); - if(domctl->u.shadow_op.op == XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION) - domctl->u.shadow_op.mb = unmarshall_int(fd); - - return unmarshall_return(fd); - - /* just return success */ - case XEN_DOMCTL_ioport_permission: - case XEN_DOMCTL_irq_permission: - case XEN_DOMCTL_iomem_permission: - case XEN_DOMCTL_setvcpuaffinity: - case XEN_DOMCTL_setvcpucontext: - case XEN_DOMCTL_getmemlist: - case XEN_DOMCTL_getvcpuinfo: -#ifdef XEN_DOMCTL_get_runstate_info - case XEN_DOMCTL_get_runstate_info: -#endif - case XEN_DOMCTL_set_machine_address_size: -#ifdef XEN_DOMCTL_suppress_spurious_page_faults - case XEN_DOMCTL_suppress_spurious_page_faults: -#endif - return 0; - default: - return -EINVAL; - } -} - -static int fake_xen_sysctl(int fd, struct xen_sysctl *sysctl) -{ - #define SYSCTLcmd "sysctl" - switch (sysctl->cmd) { - case XEN_SYSCTL_getdomaininfolist: { - xc_domaininfo_t *info; int num, i; - - get_xen_guest_handle(info, sysctl->u.getdomaininfolist.buffer); - - marshall_command(fd, "%s,%d,%d,%d\n", SYSCTLcmd, sysctl->cmd, - sysctl->u.getdomaininfolist.first_domain, - sysctl->u.getdomaininfolist.max_domains); - num = unmarshall_int(fd); - for (i = 0; i < num; i++) { - int uuid[16], j, flags; - char **ret; - - ret = unmarshall_multiple(fd); - if (!ret) - return -EBADF; - - /* domid,uuid,flags */ - info->domain = atoi(ret[0]); - - parse_uuid(ret[1], uuid); - for (j = 0; j < 16; j++) - info->handle[j] = uuid[j] & 0xff; - - flags = atoi(ret[2]); - info->flags = 0; - if (flags & 0x1) info->flags |= XEN_DOMINF_dying; - if (flags & 0x2) info->flags |= XEN_DOMINF_shutdown; - if (flags & 0x4) info->flags |= XEN_DOMINF_paused; - if (flags & 0x8) info->flags |= XEN_DOMINF_blocked; - if (flags & 0x10) info->flags |= XEN_DOMINF_running; - if (flags & 0x20) info->flags |= XEN_DOMINF_hvm_guest; - info->flags |= ((flags >> 8) & 0xff) << XEN_DOMINF_shutdownshift; - - info->nr_online_vcpus = atoi(ret[3]); - info->max_vcpu_id = atoi(ret[4]); - - info->tot_pages = atoi(ret[5]); - info->max_pages = atoi(ret[6]); - info->shared_info_frame = atoi(ret[7]); - info->cpu_time = atoi(ret[8]); - info->ssidref = atoi(ret[9]); - - string_split_free(ret); - info++; - - } - sysctl->u.getdomaininfolist.num_domains = num; - return unmarshall_return(fd); - } - case XEN_SYSCTL_readconsole: - case XEN_SYSCTL_debug_keys: - return 0; - case XEN_SYSCTL_physinfo: { - char **ret; - int sockets_per_node; - - marshall_command(fd, "%s,%d\n", SYSCTLcmd, sysctl->cmd); - ret = unmarshall_multiple(fd); - if (!ret) return -EBADF; - - sockets_per_node = atoi(ret[2]); - - sysctl->u.physinfo.threads_per_core = atoi(ret[0]); - sysctl->u.physinfo.cores_per_socket = atoi(ret[1]); -#if XEN_SYSCTL_INTERFACE_VERSION < 6 - sysctl->u.physinfo.sockets_per_node = sockets_per_node; -#endif - sysctl->u.physinfo.nr_nodes = atoi(ret[3]); -#if XEN_SYSCTL_INTERFACE_VERSION >= 6 - sysctl->u.physinfo.nr_cpus = - sysctl->u.physinfo.threads_per_core * - sysctl->u.physinfo.cores_per_socket * - sockets_per_node * - sysctl->u.physinfo.nr_nodes; -#endif - sysctl->u.physinfo.cpu_khz = atoi(ret[4]); - sysctl->u.physinfo.total_pages = atoi(ret[5]); - sysctl->u.physinfo.free_pages = atoi(ret[6]); - sysctl->u.physinfo.scrub_pages = 0; - - string_split_free(ret); - return unmarshall_return(fd); - } - case XEN_SYSCTL_getcpuinfo: { - xen_sysctl_cpuinfo_t *info; - int num, i; - - get_xen_guest_handle(info, sysctl->u.getcpuinfo.info); - marshall_command(fd, "%s,%d,%d\n", SYSCTLcmd, sysctl->cmd, sysctl->u.getcpuinfo.max_cpus); - num = unmarshall_int(fd); - for (i = 0; i < num; i++) { - info[i].idletime = unmarshall_int64(fd); - } - return unmarshall_return(fd); - } - case XEN_SYSCTL_sched_id: - return 0; - default: - return -EINVAL; - } - return 0; -} - -static int fake_xen_eventchn(int fd, unsigned long cmd, unsigned long arg) -{ - switch (cmd) { - case EVTCHNOP_alloc_unbound: - case EVTCHNOP_reset: - return 0; - default: - return -EINVAL; - } - return 0; -} - -static int fake_xen_memoryop(int fd, unsigned long cmd, struct xen_memory_reservation *reservation) -{ - switch (cmd) { - case XENMEM_set_memory_map: - case XENMEM_increase_reservation: - case XENMEM_decrease_reservation: - case XENMEM_populate_physmap: - return 0; - default: - return -EINVAL; - } - return 0; -} - -static int fake_xen_hvmop(int fd, unsigned long cmd, unsigned long arg) -{ - switch (cmd) { - case HVMOP_get_param: - return 0; - default: - return -EINVAL; - } - return 0; -} - -static int fake_xen_schedop(int fd, unsigned long cmd, sched_remote_shutdown_t *arg) -{ - switch (cmd) { - case SCHEDOP_remote_shutdown: - marshall_command(fd, "%s,%d,%d,%d\n", HYPCALLcmd, - 1, - arg->domain_id, - arg->reason); - return unmarshall_return(fd); - default: - return -EINVAL; - } - return 0; -} - -static int fake_xen_versionop(int fd, unsigned long cmd, void * arg) -{ - switch (cmd) { - case XENVER_extraversion: - memset(arg, '\0', sizeof(xen_extraversion_t)); - memcpy(arg, ".0", 2); - return 0; - case XENVER_compile_info: - memset(arg, '\0', sizeof(xen_compile_info_t)); - return 0; - case XENVER_capabilities: - memset(arg, '\0', sizeof(xen_capabilities_info_t)); - #define CAPA "xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64" - memcpy(arg, CAPA, strlen(CAPA)); - #undef CAPA - return 0; - case XENVER_changeset: - memset(arg, '\0', sizeof(xen_changeset_info_t)); - return 0; - case XENVER_platform_parameters: - memset(arg, '\0', sizeof(xen_platform_parameters_t)); - return 0; - case XENVER_version: - return (((3 << 16) & 0xffff0000) + (1 & 0xffff)); /* 3.1 */ - default: - return -EINVAL; - } - return 0; -} - -static int xiu_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall) -{ - int fd = (int)h; - if (!hypercall) return -EINVAL; - switch (hypercall->op) { - case __HYPERVISOR_domctl: - return fake_xen_domctl(fd, (struct xen_domctl *) (intptr_t)hypercall->arg[0]); - case __HYPERVISOR_sysctl: - return fake_xen_sysctl(fd, (struct xen_sysctl *) (intptr_t)hypercall->arg[0]); - case __HYPERVISOR_event_channel_op: - return fake_xen_eventchn(fd, hypercall->arg[0], hypercall->arg[1]); - case __HYPERVISOR_memory_op: - return fake_xen_memoryop(fd, hypercall->arg[0], (struct xen_memory_reservation *) (intptr_t)hypercall->arg[2]); - case __HYPERVISOR_hvm_op: - return fake_xen_hvmop(fd, hypercall->arg[0], hypercall->arg[2]); - case __HYPERVISOR_sched_op: - return fake_xen_schedop(fd, hypercall->arg[0], (sched_remote_shutdown_t *) (intptr_t)hypercall->arg[1]); - case __HYPERVISOR_xen_version: - return fake_xen_versionop(fd, hypercall->arg[0], (void *) (intptr_t)hypercall->arg[1]); - default: - return -EINVAL; - } -} - -static void *xiu_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot, - xen_pfn_t *arr, int num) -{ - return mmap(NULL, num << XC_PAGE_SHIFT, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); -} - -static void *xiu_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot, - const xen_pfn_t *arr, int *err, unsigned int num) -{ - return mmap(NULL, (unsigned long)num << XC_PAGE_SHIFT, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); -} - -static void *xiu_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int size, int prot, - unsigned long mfn) -{ - int num = (size + XC_PAGE_SIZE - 1) >> XC_PAGE_SHIFT; - return mmap(NULL, num, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); -} - -static void *xiu_privcmd_map_foreign_ranges(xc_interface *xch, xc_osdep_handle h, uint32_t dom, size_t size, int prot, - size_t chunksize, privcmd_mmap_entry_t entries[], - int nentries) -{ - int num_per_entry; - int num; - - num_per_entry = chunksize >> XC_PAGE_SHIFT; - num = num_per_entry * nentries; - return mmap(NULL, num, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); -} - -static struct xc_osdep_ops xiu_privcmd_ops = -{ - .open = &xiu_privcmd_open, - .close = &xiu_privcmd_close, - .u.privcmd = - { - .hypercall = &xiu_privcmd_hypercall, - .map_foreign_batch = &xiu_privcmd_map_foreign_batch, - .map_foreign_bulk = &xiu_privcmd_map_foreign_bulk, - .map_foreign_range = &xiu_privcmd_map_foreign_range, - .map_foreign_ranges = &xiu_privcmd_map_foreign_ranges, -#if defined(XENCTRL_HAS_ARCH_IOCTRL) - .arch_ioctl = NULL, -#endif -#if defined(XENCTRL_HAS_RESTRICT_TO) - .restrict_to = NULL, -#endif - } -}; - -static xc_osdep_handle xiu_evtchn_open(xc_evtchn *xce) -{ - struct sockaddr_un remote; - char *s; - int fd, len; - - s = getenv("XIU"); - if (!s) - { - ERROR(xce, "XIU not found. Set $XIU"); - return XC_OSDEP_OPEN_ERROR; - } - snprintf(remote.sun_path, sizeof(remote.sun_path), "%s-ev", s); - remote.sun_family = AF_UNIX; - len = strlen(remote.sun_path) + sizeof(remote.sun_family); - - fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (fd == -1) - { - ERROR(xce, "XIU: Cannot open Unix domain socket"); - return XC_OSDEP_OPEN_ERROR; - } - - if (connect(fd, (struct sockaddr *)&remote, len) != 0) - { - ERROR(xce, "XIU: Cannot connect to Unix domain socket %s.", remote.sun_path); - return XC_OSDEP_OPEN_ERROR; - } - - return (xc_osdep_handle)fd; -} - -static int xiu_evtchn_close(xc_evtchn *xce, xc_osdep_handle h) -{ - int fd = (int)h; - return close(fd); -} - -static int xiu_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h) -{ - return (int)h; -} - -static int xiu_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) -{ - int fd = (int)h; - marshall_command(fd, "ioctl,notify,%d\n", port); - return unmarshall_return(fd); -} - -static evtchn_port_or_error_t -xiu_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid) -{ - return -EINVAL; -} - -static evtchn_port_or_error_t -xiu_evtchn_bind_interdomain(xc_evtchn *xce, xc_osdep_handle h, int domid, - evtchn_port_t remote_port) -{ - int fd = (int)h; - marshall_command(fd, "ioctl,bind_interdomain,%d,%d\n", domid, remote_port); - return unmarshall_return(fd); -} - -static evtchn_port_or_error_t -xiu_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) -{ - int fd = (int)h; - marshall_command(fd, "ioctl,bind_virq,%d\n", virq); - return unmarshall_return(fd); -} - -static int xiu_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) -{ - int fd = (int)h; - marshall_command(fd, "ioctl,unbind,%d\n", port); - return unmarshall_return(fd); -} - -static evtchn_port_or_error_t xiu_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) -{ - int fd = (int)h; - evtchn_port_t port; - - marshall_command(fd, "read\n"); - port = unmarshall_int(fd); - if (unmarshall_return(fd) < 0) - return port; - else - return -1; -} - -static int xiu_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) -{ - int fd = (int)h; - marshall_command(fd, "write,%d\n", port); - return unmarshall_return(fd); -} - -static struct xc_osdep_ops xiu_evtchn_ops = { - .open = &xiu_evtchn_open, - .close = &xiu_evtchn_close, - - .u.evtchn = - { - .fd = &xiu_evtchn_fd, - .notify = &xiu_evtchn_notify, - .bind_unbound_port = &xiu_evtchn_bind_unbound_port, - .bind_interdomain = &xiu_evtchn_bind_interdomain, - .bind_virq = &xiu_evtchn_bind_virq, - .unbind = &xiu_evtchn_unbind, - .pending = &xiu_evtchn_pending, - .unmask = &xiu_evtchn_unmask, -#if defined(XENCTRL_HAS_RESTRICT_TO) - .restrict_to = NULL, -#endif - }, -}; - -static struct xc_osdep_ops * xiu_osdep_init(xc_interface *xch, enum xc_osdep_type type) -{ - if (getenv("XIU") == NULL) - { - ERROR(xch, "XIU not found. Set $XIU"); - return NULL; - } - - switch ( type ) - { - case XC_OSDEP_PRIVCMD: - return &xiu_privcmd_ops; - case XC_OSDEP_EVTCHN: - return &xiu_evtchn_ops; - case XC_OSDEP_GNTTAB: - ERROR(xch, "GNTTAB interface not supported on this platform"); - return NULL; - default: - return NULL; - } -} - -xc_osdep_info_t xc_osdep_info = { - .name = "Xen In Userspace (XIU) Simulator", - .init = &xiu_osdep_init, - .fake = 1, -}; - -/* - * Local variables: - * mode: C - * c-set-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/ocaml/xiu/xiu.ml b/ocaml/xiu/xiu.ml deleted file mode 100644 index f42c3330cd..0000000000 --- a/ocaml/xiu/xiu.ml +++ /dev/null @@ -1,897 +0,0 @@ -(* - * Copyright (C) 2006-2009 Citrix Systems Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; version 2.1 only. with the special - * exception on linking described in file LICENSE. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - *) -open Printf -open Pervasiveext -open Threadext -open Xenbus -open Xenstore - -type inject_error_ty = - | Inject_error_create - | Inject_crash - | Inject_shutdown - -let boot_delay = ref 0. (* seconds per boot *) -let shutdown_delay = ref 0. (* seconds per shutdown *) - -let debug_level = ref 3 -let inject_error = ref [] - -let xiu_path = ref "" (* passed into udev scripts we fork *) - -let random_inject_error ty = (Random.int 1024 > 950) && (List.mem ty !inject_error) - -(* returned in physinfo, and can be set in the config file *) -let nb_cpu_nodes = ref 1 -let nb_cpu_sockets = ref 1 -let nb_cpu_cores = ref 2 -let nb_cpu_threads = ref 1 -let cpu_usage = ref 1000L -let cpu_speed_mhz = ref (1 * 1000) (* by default 1 ghz *) -let physical_free_kib = ref ((16 * 1024 - 1) * 1024) (* by default ~16gb of free memory *) -let physical_memory_kib = ref (16 * 1024 * 1024) (* by default 16gb of memory *) -let host_m = Mutex.create () - -let extra_kib = 512 - -(** utility *) -let create_unix_socket name = - Unixext.unlink_safe name; - Unixext.mkdir_rec (Filename.dirname name) 0o700; - let sockaddr = Unix.ADDR_UNIX(name) in - let sock = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in - Unix.bind sock sockaddr; - Unix.listen sock 1; - sock - -let with_xs f = - let xs = Xs.daemon_open () in - finally (fun () -> f xs) (fun () -> Xs.close xs) - -let with_xs_retry f = - let retry = ref true in - while !retry do - retry := false; - try with_xs f - with - | Xb.End_of_file -> eprintf "xenstored: end of file; retrying in 5s\n%!"; Thread.delay 5.; retry := true - | Xs.Failed_to_connect -> eprintf "xenstored: end of file; retrying in 10s\n%!"; Thread.delay 10.; retry := true - done; - () - -let maybe r f = match r with None -> () | Some r -> f r - -(** xen structures *) -type xenpowerstate = Dying | Shutdown of int | Paused | Blocked | Running - -type xendomain = { - domid: int; - hvm: bool; - mutable tot_mem_kib: int; (* memory in use *) - mutable max_mem_kib: int; (* maximum possible *) - mutable extra_kib: int; - mutable vcpus: int; - mutable uuid: int array; - mutable state: xenpowerstate; - mutable shared_info_frame: int; - mutable cpu_time: int; - mutable ssidref: int; - mutable shadow_allocation: int; -} - -let domflags_to_int dom = - let flag = ref 0 in - let flagset bit = (flag := !flag lor (1 lsl bit)) - in - if dom.hvm then flagset 5; - begin match dom.state with - | Dying -> flagset 0 - | Shutdown i -> flagset 1; flag := !flag lor (i lsl 8) - | Paused -> flagset 2 - | Blocked -> flagset 3 - | Running -> flagset 4 - end; - !flag - -(** exception that will be marshall into nice errnos *) -exception Domain_not_found -exception Cannot_create_domain - -let esrch = 3 -let enomem = 12 -let enodev = 19 -let einval = 22 - -(** domctl values *) -type domctl = Domctl_create | Domctl_destroy | Domctl_pause | Domctl_unpause - | Domctl_resume | Domctl_maxmem | Domctl_settimeoffset - | Domctl_max_vcpus | Domctl_setdomainhandle | Domctl_shadow_op - | Domctl_setvmxassist - | Domctl_unknown of int - -type sysctl = Sysctl_getdomaininfolist | Sysctl_physinfo | Sysctl_getcpuinfo | Sysctl_unknown of int - -type hypcall = Hypcall_domain_shutdown | Hypcall_unknown - -let hypcall_of_int = function - | 1 -> Hypcall_domain_shutdown - | _ -> Hypcall_unknown - -let domctl_of_int = function - | 1 -> Domctl_create | 2 -> Domctl_destroy - | 3 -> Domctl_pause | 4 -> Domctl_unpause - | 5 -> Domctl_resume - | 10 -> Domctl_shadow_op - | 11 -> Domctl_maxmem - | 15 -> Domctl_max_vcpus - | 17 -> Domctl_setdomainhandle - | 98 -> Domctl_setvmxassist - | i -> (Domctl_unknown i) - -let sysctl_of_int = function - | 3 -> Sysctl_physinfo - | 6 -> Sysctl_getdomaininfolist - | 8 -> Sysctl_getcpuinfo - | i -> (Sysctl_unknown i) - -(** xenver values *) -let xenver_extraversion = 2901 -let xenver_compile_info = 2902 -let xenver_capabilities = 2903 -let xenver_changeset = 2904 -let xenver_platform_parameters = 2905 -let xenver_version = 2906 - -(** internals domains data *) -let next_domid = ref 0 -let domains = Hashtbl.create 16 - -(** console stuff *) -let console_ring = String.make 4092 ' ' -let add_console s = if !debug_level >= 1 then eprintf "(XIU) %s\n%!" s -let hypercall_debug s = if !debug_level >= 2 then eprintf "(HYCALL) %s\n%!" s -let hypercall_debug2 s = if !debug_level >= 3 then eprintf "(HYCALL) %s\n%!" s - -(** find a domain in the list *) -let domain_find domid = - try Hashtbl.find domains domid - with Not_found -> raise Domain_not_found - -let round_down_to_page x = (x / 4) * 4 - -(** Add up to [delta_kib] memory to the domain, reducing the host free memory by the same amount *) -let transfer_to_domain dom delta_kib = - Mutex.execute host_m - (fun () -> - let available_kib = min !physical_free_kib delta_kib in - eprintf "(XIU) transfer_to_domain domid = %d; delta_kib = %d\n%!" dom.domid delta_kib; - dom.tot_mem_kib <- dom.tot_mem_kib + available_kib; - physical_free_kib := !physical_free_kib - available_kib - ) - -(** immediately set the tot_mem_kib to the requested balloon target *) -let read_memory_target xs domid = - let path = Printf.sprintf "/local/domain/%d/memory/target" domid in - try - let mem = int_of_string (xs.Xs.read path) in - let dom = domain_find domid in - (* Enforce the max_mem limit *) - if mem > dom.max_mem_kib - then eprintf "(XIU) domid %d target = %d KiB but max_mem = %d KiB\n%!" domid mem dom.max_mem_kib; - let requested = round_down_to_page (min mem dom.max_mem_kib) in - - let delta_kib = requested - dom.tot_mem_kib in - transfer_to_domain dom delta_kib; - if dom.tot_mem_kib <> requested - then eprintf "(XIU) domid %d requested %d KiB but only got %d KiB\n%!" domid requested dom.tot_mem_kib; - with e -> eprintf "(XIU) Failed to parse memory target of domid %d\n%!" domid - -(** Maximum number of dummy devices fixed at module-load time *) -let max_dummy_vifs = 1000 - -(** Perform the module (re)loading *) -let initialise_dummy_devices () = - ignore(Unix.system("/sbin/rmmod dummy")); - ignore(Unix.system(sprintf "/sbin/modprobe dummy numdummies=%d" max_dummy_vifs)) - -(** Free list of dummy devices, used to simulate guest VIF backends *) -let vif_free_list = ref (List.map (fun x -> sprintf "dummy%d" x) (Range.to_list (Range.make 0 max_dummy_vifs))) - -module Udev = struct - (** Simulate a udev event by directly running the script *) - - let run_script filename args env = - let pid = Unix.fork () in - if pid = 0 - then Unix.execve filename (Array.of_list args) (Array.of_list (List.map (fun (k, v) -> k ^ "=" ^ v) env)); - match Unix.waitpid [ ] pid with - | _, Unix.WEXITED 0 -> () - | _, Unix.WEXITED n -> eprintf "(XIU) udev script exited with code %d\n" n - | _, _ -> eprintf "(XIU) unknown error running udev script\n" - - let vif domid devid device action = - let vif_script = Filename.concat Fhs.scriptsdir "vif" in - let env = - [ "DEVPATH", sprintf "/devices/xen-backend/vif-%d-%d" domid devid; - "PHYSDEVBUS", "xen-backend"; - "SUBSYSTEM", "xen-backend"; - "XENBUS_BASE_PATH", "backend"; - "XENBUS_PATH", sprintf "backend/vif/%d/%d" domid devid; - "XENBUS_TYPE", "vif"; - "PATH", Fhs.bindir ^ ":/usr/local/bin:/bin:/usr/bin"; (* added @BINDIR@ for xenstore wrapper *) - "XIU", !xiu_path; (* make sure we pick up the fake list_domains *) - "vif", device - ] in - run_script vif_script [ vif_script; action ] env - -end - -(** thread simulating a domain *) -let thread_domain0 () = - let read_state xs w = try Xenbus_utils.of_int (int_of_string (xs.Xs.read w)) with _ -> Xenbus_utils.Unknown in - - let backend_changed xs w = - let l = Stringext.String.split '/' w in - match l with - | "" :: "local" :: "domain" :: "0" :: "backend" :: ty :: domid :: id :: [ "state" ] -> ( - let state = read_state xs w in - add_console (sprintf "dom0: backend ty=%s id=%s for domid=%s changed" ty id domid); - match state with - | Xenbus_utils.Initialising -> - let hotplugpath = sprintf "/xapi/%s/hotplug/%s/%s/hotplug" domid ty id in - if ty = "vif" then ( - let vifpath = sprintf "/xapi/%s/hotplug/%s/%s/vif" domid ty id in - let mac_path = sprintf "/local/domain/0/backend/vif/%s/%s/mac" domid id in - let mac = xs.Xs.read mac_path in - if List.length !vif_free_list = 0 then begin - eprintf "(XIU) ran out of dummy VIF devices\n"; - xs.Xs.write vifpath "nodummydevicesleft"; - end else begin - let device = List.hd !vif_free_list in - vif_free_list := List.tl !vif_free_list; - - let new_device = sprintf "vif%s.%s" domid id in - eprintf "(XIU) removed device from free list: %s; setting MAC to %s and renaming to %s\n" device mac new_device; - Netdev.Link.down device; - Netdev.Link.set_addr device mac; - Netdev.Link.change_name device new_device; - Netdev.Link.up new_device; - Udev.vif (int_of_string domid) (int_of_string id) new_device "online"; - end - ) else ( - xs.Xs.write hotplugpath "online"; - ); - xs.Xs.write w (Xenbus_utils.string_of Xenbus_utils.InitWait); - | Xenbus_utils.InitWait -> () - | Xenbus_utils.Closing -> - xs.Xs.write w (Xenbus_utils.string_of Xenbus_utils.Closed); - if ty = "vif" then ( - let device_path = sprintf "/xapi/%s/hotplug/vif/%s/vif" domid id in - let device = xs.Xs.read device_path in - if Netdev.network.Netdev.is_on_bridge device then begin - let bridge = Netdev.network.Netdev.get_bridge device in - Netdev.network.Netdev.intf_del bridge device - end; - eprintf "(XIU) Adding device to free list: %s\n" device; - vif_free_list := device :: !vif_free_list; - Udev.vif (int_of_string domid) (int_of_string id) device "remove"; - ) - | _ -> - () - ) - | "" :: "local" :: "domain" :: "0" :: "backend" :: "vif" :: domid :: id :: [ "online" ] -> ( - let online_path = sprintf "/local/domain/0/backend/vif/%s/%s/online" domid id in - let state_path = sprintf "/local/domain/0/backend/vif/%s/%s/state" domid id in - if xs.Xs.read online_path = "0" then xs.Xs.write state_path (Xenbus_utils.string_of Xenbus_utils.Closing) - ) - | "" :: "local" :: "domain" :: "0" :: "backend" :: ty :: domid :: id :: [ "shutdown-request" ] -> ( - let sdone_path = sprintf "/local/domain/0/backend/%s/%s/%s/shutdown-done" ty domid id in - xs.Xs.write sdone_path ""; - let hotplugpath = sprintf "/xapi/%s/hotplug/%s/%s/hotplug" domid ty id in - begin try xs.Xs.rm hotplugpath with _ -> (); end - ) - | _ -> () - in - let device_model_changed xs w = - let l = Stringext.String.split '/' w in - match l with - | "" :: "local" :: "domain" :: "0" :: "device-model" :: domid :: [ "command" ] -> ( - let device_model_transaction = xs.Xs.read (sprintf "/local/domain/0/device-model/%s/command" domid) in - match device_model_transaction with - | "save" -> let file = sprintf Device_common.qemu_save_path (int_of_string domid) in - let fd = Unix.openfile file (Unix.O_RDWR :: [ Unix.O_CREAT ]) 0o640 in - Unix.close fd; - xs.Xs.write (sprintf "/local/domain/0/device-model/%s/state" domid) "paused" - | "continue" -> xs.Xs.write (sprintf "/local/domain/0/device-model/%s/state" domid) "running" - | _ -> () - ) - | _ -> () - in - let frontend_changed xs w = - let l = Stringext.String.split '/' w in - match l with - | "" :: "local" :: "domain" :: domid :: "device" :: ty :: id :: [ "state" ] -> ( - let backend_path = xs.Xs.read (sprintf "/local/domain/%s/device/%s/%s/backend" domid ty id) in - let backend_state_path = backend_path ^ "/state" in - let fstate = read_state xs w in - match fstate with - | Xenbus_utils.Initialised -> xs.Xs.write backend_state_path (Xenbus_utils.string_of Xenbus_utils.Connected) - | Xenbus_utils.Closing -> xs.Xs.write backend_state_path (Xenbus_utils.string_of Xenbus_utils.Closed) - | _ -> () - ) - | _ -> - () - in - with_xs_retry (fun xs -> - let mypath = sprintf "/local/domain/%d/" 0 in - let olds = ref [] in - xs.Xs.watch (mypath ^ "backend") "backend"; - xs.Xs.watch (mypath ^ "memory/target") "balloon"; - xs.Xs.watch "@introduceDomain" "introduce"; - xs.Xs.watch "@releaseDomain" "release"; - - let domains_changed w = - let add_watch_for_newdomain dom = - printf "dom0: new domain %d\n" dom; - xs.Xs.watch (sprintf "/local/domain/%d/device" dom) "frontend"; - xs.Xs.watch (sprintf "/local/domain/0/device-model/%d" dom) "devicemodel" (* add watch for device-model for migrating vms *) - and remove_watch_for_olddomain dom = - printf "dom0: dead domain %d\n" dom; - xs.Xs.unwatch (sprintf "/local/domain/%d/device" dom) "frontend"; - xs.Xs.unwatch (sprintf "/local/domain/0/device-model/%d" dom) "devicemodel" - in - let write_vnc_port dom = - let port = sprintf "%d" (5900 + dom) in - xs.Xs.write (sprintf "/local/domain/%d/serial/0/vnc-port" dom) port; (* PV *) - xs.Xs.write (sprintf "/local/domain/%d/console/vnc-port" dom) port (* HVM *) - in - - (* diff old list and new list *) - let currents = Hashtbl.fold (fun k v acc -> k :: acc) domains [] in - - let news = List.fold_left (fun acc domid -> - if not (List.mem domid !olds) then domid :: acc else acc) [] currents in - let disappeared = List.fold_left (fun acc domid -> - if not (List.mem domid currents) then domid :: acc else acc) [] !olds in - - List.iter (fun old -> remove_watch_for_olddomain old) disappeared; - List.iter (fun n -> add_watch_for_newdomain n) news; - List.iter write_vnc_port news; - olds := currents; - () - in - while true do - let w, v = - if Xs.has_watchevents xs then - Xs.get_watchevent xs - else - Xs.read_watchevent xs in - try - match v with - | "backend" -> backend_changed xs w - | "balloon" -> read_memory_target xs 0 - | "frontend" -> frontend_changed xs w - | "introduce"-> domains_changed w - | "release" -> domains_changed w - | "devicemodel" -> device_model_changed xs w - | _ -> add_console (sprintf "dom0: unknown watch %s,%s" w v) - with exn -> - add_console (sprintf "dom0: %s" (Printexc.to_string exn)); - done - ) - -let thread_domain domid = - let mypath = sprintf "/local/domain/%d/" domid in - let shutdowning = ref None in - - let read_state xs w = try Xenbus_utils.of_int (int_of_string (xs.Xs.read w)) with _ -> Xenbus_utils.Unknown in - let backend_changed xs w = - let l = Stringext.String.split '/' w in - match l with - | "" :: "local" :: "domain" :: "0" :: "backend" :: ty :: domid :: id :: [ "state" ] -> ( - let frontend_path = xs.Xs.read (sprintf "/local/domain/0/backend/%s/%s/%s/frontend" domid ty id) in - let frontend_state_path = frontend_path ^ "/state" in - let bstate = read_state xs w in - match bstate with - | Xenbus_utils.InitWait -> xs.Xs.write frontend_state_path (Xenbus_utils.string_of Xenbus_utils.Initialised) - | Xenbus_utils.Connected -> xs.Xs.write frontend_state_path (Xenbus_utils.string_of Xenbus_utils.Connected) - | Xenbus_utils.Closing -> xs.Xs.write frontend_state_path (Xenbus_utils.string_of Xenbus_utils.Closed) - | _ -> () - ) - | _ -> - () - in - let device_changed xs w = - () - in - let control_changed xs w = - let control = try Some (xs.Xs.read w) with _ -> None in - maybe control (fun control -> - add_console (sprintf "dom%d: controlling %s" domid control); - xs.Xs.write w ""; - match control with - | "halt" -> shutdowning := Some Domain.Halt - | "reboot" -> shutdowning := Some Domain.Reboot - | "suspend" -> shutdowning := Some Domain.Suspend - | _ -> add_console (sprintf "dom%d: unknown control %s" domid control) - ) - in - - let close_devices xs = - let devpath = mypath ^ "device" in - let devices = try xs.Xs.directory devpath with _ -> [] in - List.iter (fun dev -> - let idpath = devpath ^ "/" ^ dev in - let ids = try xs.Xs.directory idpath with _ -> [] in - List.iter (fun id -> - let state_path = idpath ^ "/" ^ id ^ "/state" in - let state = read_state xs state_path in - match state with - | Xenbus_utils.Initialised | Xenbus_utils.InitWait | Xenbus_utils.Initialising | Xenbus_utils.Connected -> - xs.Xs.write state_path (Xenbus_utils.string_of Xenbus_utils.Closing) - | _ -> () - ) ids - ) devices - in - - with_xs_retry (fun xs -> - (* booting *) - Thread.delay !boot_delay; - - let written_feature_balloon = ref false in - - (* install watches *) - xs.Xs.watch (mypath ^ "control/shutdown") "control"; - xs.Xs.watch (mypath ^ "device") "device"; - xs.Xs.watch (mypath ^ "memory/target") "balloon"; - xs.Xs.watch (sprintf "/local/domain/0/backend/vbd/%d" domid) "backend"; - xs.Xs.watch (sprintf "/local/domain/0/backend/vif/%d" domid) "backend"; - - let quit = ref false in - while not !quit do - let w, v = - if Xs.has_watchevents xs then - Xs.get_watchevent xs - else - Xs.read_watchevent xs in - add_console (sprintf "dom%d: watch %s %s" domid w v); - try - begin match v with - | "backend" -> backend_changed xs w - | "device" -> device_changed xs w - | "control" -> control_changed xs w - | "balloon" -> - (* NB normally the domain builder + qemu would allocate memory during boot, then - the PV drivers would write feature-balloon and then we would sample the - memory-offset. In the simulator there is no domain builder and the first time - the memory/target watch fires is when we allocate all the memory. - Make sure we allocate the memory before writing feature-balloon: *) - read_memory_target xs domid; - if not !written_feature_balloon then begin - xs.Xs.write (mypath ^ "control/feature-balloon") "true"; - written_feature_balloon := true - end; - | _ -> add_console (sprintf "dom0: unknown watch %s,%s" w v); - end; - match !shutdowning with - | None -> () - | Some shutdown -> ( - add_console (sprintf "dom%d: shutdowning" domid); - Thread.delay !shutdown_delay; - close_devices xs; - let dom = domain_find domid in - match shutdown with - | Domain.Halt -> dom.state <- Shutdown 4; quit := true - | Domain.Reboot -> dom.state <- Shutdown 1; quit := true - | Domain.Suspend -> dom.state <- Shutdown 2; quit := true - | _ -> () - ) - with exn -> - add_console (sprintf "dom%d: %s" domid (Printexc.to_string exn)); - done; - add_console (sprintf "dom%d: dying" domid); - ); - () - -let domain_chgstate dom newstate = - match newstate with - | Dying | Shutdown _ -> dom.state <- newstate - | Paused -> - (* domain 0 can't be paused *) - if dom.domid <> 0 then ( - match dom.state with - | Running | Blocked -> dom.state <- newstate - | _ -> () - ) - | Running | Blocked -> dom.state <- newstate - -(** domains functions *) -let domain_create hvm uuid = - let newdomid = !next_domid in - incr next_domid; - let newdom = { - domid = newdomid; - hvm = hvm; - max_mem_kib = 0; - tot_mem_kib = 0; - extra_kib = extra_kib; - vcpus = 0; - uuid = uuid; - state = Paused; - shared_info_frame = 0; - cpu_time = 0; - ssidref = 0; - shadow_allocation = 0; - } in - Hashtbl.add domains newdomid newdom; - newdom - -let domain_destroy domid = - let d = domain_find domid in - transfer_to_domain d (-d.tot_mem_kib); - Hashtbl.remove domains domid - -let domain_shutdown domid reason = - let d = domain_find domid in - d.state <- Shutdown reason; - 0 - -let domain_sethandle domid uuid = - let dom = domain_find domid in dom.uuid <- uuid; () - -let domain_unpause domid = - (domain_find domid).state <- Running; ignore(Thread.create thread_domain domid); () - -let domain_pause domid = (domain_find domid).state <- Paused -let domain_resume domid = ignore (domain_find domid) -let domain_maxcpus domid vcpus = let dom = domain_find domid in dom.vcpus <- vcpus -let domain_maxmem domid mem = let dom = domain_find domid in dom.max_mem_kib <- mem -let domain_shadow_allocation domid alloc = let dom = domain_find domid in dom.shadow_allocation <- alloc -let domain_get_shadow_allocation domid = (domain_find domid).shadow_allocation - -let domain_list_from first max = - Mutex.execute host_m - (fun () -> - let domains_at_first = Hashtbl.fold (fun k v acc -> - if k >= first then v :: acc else acc - ) domains [] in - let domains_at_first = List.sort (fun d1 d2 -> compare d1.domid d2.domid) - domains_at_first in - if List.length domains_at_first <= max then - domains_at_first - else ( - let a = Array.create max (List.hd domains_at_first) in - for i = 0 to max - 1 do - a.(i) <- (List.nth domains_at_first i) - done; - Array.to_list a - ) - ) - -let marshall_int fd i = - let buf = sprintf "%d\n" i in - let len = String.length buf in - if Unix.write fd buf 0 len <> len then (failwith "marshall_int wrote short!"); - () - -let marshall_int64 fd i = - let buf = sprintf "%Ld\n" i in - let len = String.length buf in - if Unix.write fd buf 0 len <> len then (failwith "marshall_int64 wrote short!"); - () - -let string_of_uuid uuid = - String.concat "" (Array.to_list (Array.map (fun i -> sprintf "%02x" i) uuid)) - - -let marshall_uuid fd uuid = - let buf = (string_of_uuid uuid) ^ "\n" in - let len = String.length buf in - if Unix.write fd buf 0 len <> len then (failwith "marshall_uuid wrote short!"); - () - -let marshall_multiple fd l = - let buf = String.concat "," l ^ "\n" in - let len = String.length buf in - if Unix.write fd buf 0 (String.length buf) <> len then (failwith "marshall_multiple wrote short!"); - () - -let exn_to_errno f = - try f () with - | Domain_not_found -> -esrch - | Cannot_create_domain -> -enomem - | _ -> -einval - -let int_of_hexstring s = Scanf.sscanf s "%x" (fun a -> a) - -let do_xc_cmd fd cmd = - let do_hypcall _cmd args = - let cmd = hypcall_of_int (int_of_string _cmd) in - match cmd, args with - | Hypcall_domain_shutdown, [domid; reason] -> - let domid = int_of_string domid in - let reason = int_of_string reason in - hypercall_debug (sprintf "domain_shutdown %d %d" domid reason); - exn_to_errno (fun () -> domain_shutdown domid reason) - | _,_ -> - hypercall_debug (sprintf "HYCALL(%s) not implemented or invalid number of args ([%s])" _cmd (String.concat ";" args)); - -einval - in - let do_xc_domctl _cmd args = - let cmd = domctl_of_int (int_of_string _cmd) in - match cmd, args with - | Domctl_create, [hvm; hap; handle] -> - hypercall_debug (sprintf "creating domain (%s, %s, ,%s)" hvm hap handle); - let h = Array.map int_of_hexstring - (Array.of_list (Stringext.String.split '-' handle)) in - - if random_inject_error Inject_error_create then ( - raise Cannot_create_domain - ); - let dom = exn_to_errno (fun () -> (domain_create (hvm = "1") h).domid) in - marshall_int fd (if dom < 0 then 0 else dom); - 0 - | Domctl_destroy, [domid] -> - let domid = int_of_string domid in - hypercall_debug (sprintf "destroying domain (%d)" domid); - exn_to_errno (fun () -> domain_destroy domid; 0) - | Domctl_pause, [domid] -> - let domid = int_of_string domid in - hypercall_debug (sprintf "pausing domain (%d)" domid); - exn_to_errno (fun () -> domain_pause domid; 0) - | Domctl_unpause, [domid] -> - let domid = int_of_string domid in - hypercall_debug (sprintf "unpausing domain (%d)" domid); - exn_to_errno (fun () -> domain_unpause domid; 0) - | Domctl_resume, [domid] -> - let domid = int_of_string domid in - hypercall_debug (sprintf "resuming domain (%d)" domid); - exn_to_errno (fun () -> domain_resume domid; 0) - | Domctl_shadow_op, [domid; op; mode; mb] -> - let domid = int_of_string domid in - let op = int_of_string op in - hypercall_debug (sprintf "shadow_op (domain %d, op %d, mode %s, mb %s" domid op mode mb); - begin - match op with - | 30 (* GET_ALLOCATION *) -> - let res = exn_to_errno (fun () -> domain_get_shadow_allocation domid) in - marshall_int fd (if res < 0 then 0 else res); - if res < 0 then res else 0 - | 31 (* SET ALLOCATION *) -> - exn_to_errno (fun () -> domain_shadow_allocation domid (int_of_string mb); 0) - | _ -> -einval - end - | Domctl_maxmem, [domid; value] -> - let domid = int_of_string domid in - let maxmem = int_of_string value in - hypercall_debug (sprintf "maxmem domain (%d, %d)" domid maxmem); - exn_to_errno (fun () -> domain_maxmem domid maxmem; 0) - | Domctl_max_vcpus, [domid; value] -> - let domid = int_of_string domid in - let vcpus = int_of_string value in - hypercall_debug (sprintf "setting domain vcpus (%d, %d)" domid vcpus); - exn_to_errno (fun () -> domain_maxcpus domid vcpus; 0) - | Domctl_setdomainhandle, [domid; handle] -> - let domid = int_of_string domid in - hypercall_debug (sprintf "set handle (%d, %s)" domid handle); - let h = Array.map int_of_hexstring - (Array.of_list (Stringext.String.split '-' handle)) in - exn_to_errno (fun () -> domain_sethandle domid h; 0) - | Domctl_setvmxassist, [domid; value] -> - 0 - | Domctl_unknown i, _ -> - hypercall_debug (sprintf "DOMCTL(%d) unknown" i); - -einval - | _, _ -> - hypercall_debug (sprintf "DOMCTL(%s) not implemented or invalid number of args ([%s])" _cmd (String.concat ";" args)); - -einval - in - let do_xc_sysctl _cmd args = - let pages_of_kb n = n / 4 in - let cmd = sysctl_of_int (int_of_string _cmd) in - match cmd, args with - | Sysctl_getdomaininfolist, [first; max] -> - let first = int_of_string first and max = int_of_string max in - hypercall_debug2 (sprintf "get domain info list (%d,%d)" first (first + max)); - let domains = domain_list_from first max in - let num = List.length domains in - marshall_int fd num; - List.iter (fun dom -> - marshall_multiple fd [ (string_of_int dom.domid); (string_of_uuid dom.uuid); - (string_of_int (domflags_to_int dom)); - (string_of_int dom.vcpus); (* nr_online_vcpus *) - (string_of_int dom.vcpus); (* max_vcpu_id *) - (string_of_int (pages_of_kb (dom.tot_mem_kib + dom.extra_kib))); - (string_of_int (pages_of_kb dom.max_mem_kib)); - (string_of_int dom.shared_info_frame); - (string_of_int dom.cpu_time); - (string_of_int dom.ssidref); - ]; - ) domains; - 0 - | Sysctl_physinfo, _ -> - hypercall_debug2 (sprintf "physinfo"); - marshall_multiple fd [ string_of_int !nb_cpu_threads; - string_of_int !nb_cpu_cores; - string_of_int !nb_cpu_sockets; - string_of_int !nb_cpu_nodes; - string_of_int (!cpu_speed_mhz * 1000); - string_of_int (pages_of_kb !physical_memory_kib); - string_of_int (pages_of_kb !physical_free_kib); ]; - 0 - | Sysctl_getcpuinfo, [m] -> - let nbcpu = min (int_of_string m) 2 in - marshall_int fd nbcpu; - for i = 0 to nbcpu - 1 do marshall_int64 fd !cpu_usage done; - cpu_usage := Int64.add !cpu_usage 136663L; (* that's the exact cost of doing a getcpuinfo *) - 0 - | Sysctl_unknown i, _ -> - hypercall_debug (sprintf "SYSCTL(%d) unknown" i); - -einval - | _, _ -> - hypercall_debug (sprintf "SYSCTL(%s) not implemented or invalid number or args" _cmd); - -einval - in - let lcmd = Stringext.String.split ',' cmd in - let ret = match lcmd with - | "domctl" :: cmd :: args -> do_xc_domctl cmd args - | "sysctl" :: cmd :: args -> do_xc_sysctl cmd args - | "hypcall" :: cmd :: args -> do_hypcall cmd args - | _ -> -einval in - marshall_int fd ret - -let do_eventchn_cmd fd cmd = - let do_ev_ioctl cmd args = - match cmd with - | "bind_interdomain" -> 0 - | "bind_virq" -> 0 - | "unbind" -> 0 - | "notify" -> 0 - | _ -> failwith (sprintf "Unknown command: %s" cmd) - and do_ev_read () = - marshall_int fd 0; - 0 - and do_ev_write port = - 0 - in - let lcmd = Stringext.String.split ',' cmd in - let ret = match lcmd with - | "ioctl" :: cmd :: args -> do_ev_ioctl cmd args - | "read" :: [] -> do_ev_read () - | "write" :: port :: [] -> do_ev_write port - | _ -> -einval in - marshall_int fd ret - - -let main xiu_path = - let xiu_socket_xc = sprintf "%s-xc" xiu_path - and xiu_socket_ev = sprintf "%s-ev" xiu_path in - - let lsock_xc = create_unix_socket xiu_socket_xc in - let lsock_ev = create_unix_socket xiu_socket_ev in - - let fake_read fd = - let buf = String.create 1024 in - let offset = ref 0 in - let quit = ref false and eof = ref false in - while not !quit && not !eof - do - let rd = Unix.read fd buf !offset 1 in - if rd = 0 then - eof := true - else ( - if buf.[!offset] = '\n' then - quit := true - else - offset := !offset + rd - ) - done; - !eof, String.sub buf 0 !offset - in - - let cons_xc = ref [] and cons_ev = ref [] in - - let do_xc fd = - let eof, cmd = fake_read fd in - if eof then ( - Unix.close fd; - cons_xc := List.filter (fun x -> x <> fd) !cons_xc - ) else ( - do_xc_cmd fd cmd - ); - () - in - let do_ev fd = - let eof, cmd = fake_read fd in - if eof then ( - cons_ev := List.filter (fun x -> x <> fd) !cons_ev; - Unix.close fd; - ) else ( - do_eventchn_cmd fd cmd - ); - in - - let dom = domain_create false (Array.create 16 0) in - dom.state <- Running; - domain_maxcpus 0 1; - ignore(Thread.create thread_domain0 ()); - - while true - do - let inset = [ lsock_xc; lsock_ev ] @ !cons_xc @ !cons_ev in - let outset = [] in - try - let r, w, _ = try Unix.select inset outset [] 0.2 - with Unix.Unix_error(Unix.EINTR, _, _) -> [], [], [] in - - List.iter (fun fd -> - if fd = lsock_ev then ( - let (nfd, _) = Unix.accept lsock_ev in - cons_ev := nfd :: !cons_ev; - ) else if fd = lsock_xc then ( - let (nfd, _) = Unix.accept lsock_xc in - cons_xc := nfd :: !cons_xc; - ) else if List.mem fd !cons_xc then ( - do_xc fd - ) else if List.mem fd !cons_ev then ( - do_ev fd - ) else ( - ) - ) r; - - if random_inject_error Inject_crash then ( - () - ) - with exn -> add_console (Printexc.to_string exn) - done; - () - -let _ = - let config_file = ref (Filename.concat Fhs.etcdir "xiu.conf") in - let other_args = ref [] in - Arg.parse [ "-v", Arg.Unit (fun () -> incr debug_level), "increase debug level"; - "--conf", Arg.Set_string config_file, "set config file"; ] - (fun args -> other_args := args :: !other_args) "usage: xiu [-v] path"; - - let conf_args = [ - "inject", Config.String (fun s -> - match s with - | "crash" -> inject_error := Inject_crash :: !inject_error - | "error-create" -> inject_error := Inject_error_create :: !inject_error - | "shutdown" -> inject_error := Inject_shutdown :: !inject_error - | _ -> ()); - "free-memory", Config.Set_int physical_free_kib; - "total-memory", Config.Set_int physical_memory_kib; - "cpu-nodes", Config.Set_int nb_cpu_nodes; - "cpu-sockets", Config.Set_int nb_cpu_sockets; - "cpu-cores", Config.Set_int nb_cpu_cores; - "cpu-threads", Config.Set_int nb_cpu_threads; - "cpu-speed", Config.Set_int cpu_speed_mhz; - ] in - begin try Config.read !config_file conf_args (fun _ _ -> ()) - with _ -> () end; - - if List.length !other_args < 1 then ( - eprintf "usage: %s path" Sys.argv.(0); - exit 1 - ); - - Random.self_init (); - - initialise_dummy_devices (); - - let path = List.hd !other_args in - xiu_path := path; - - main path diff --git a/scripts/init.d-squeezed b/scripts/init.d-squeezed index 84fcc270de..e3755cf95b 100644 --- a/scripts/init.d-squeezed +++ b/scripts/init.d-squeezed @@ -24,11 +24,6 @@ SUBSYS_FILE="/var/lock/subsys/squeezed" # Source function library. . /etc/init.d/functions -if [ -e /var/xapi/xiu-xc ]; then - export XENCTRL_OSDEP="@OPTDIR@/lib/libxenctrl_xiu.so" - export XIU=/var/xapi/xiu -fi - # Enable core dumping ulimit -c unlimited diff --git a/scripts/init.d-xapi b/scripts/init.d-xapi index 0dd7999c3b..c5cf35a69a 100755 --- a/scripts/init.d-xapi +++ b/scripts/init.d-xapi @@ -15,11 +15,6 @@ if [ -f /etc/sysconfig/xapi ]; then . /etc/sysconfig/xapi fi -if [ -e /var/xapi/xiu-xc ]; then - export XENCTRL_OSDEP="@OPTDIR@/lib/libxenctrl_xiu.so" - export XIU=/var/xapi/xiu -fi - XAPI_STARTUP_COOKIE=/var/run/xapi_startup.cookie XAPI_INIT_COMPLETE_COOKIE=/var/run/xapi_init_complete.cookie XAPI_BLOCK_STARTUP_COOKIE=@ETCDIR@/xapi_block_startup diff --git a/scripts/init.d-xenservices b/scripts/init.d-xenservices index a58d5dd043..e48d358d91 100755 --- a/scripts/init.d-xenservices +++ b/scripts/init.d-xenservices @@ -14,31 +14,6 @@ . /etc/init.d/functions start() { - # If this domain hasn't got sufficient privileges then assume it is a domU - # and start the hypercall simulator - "@BINDIR@/list_domains" 2>/dev/null 1>/dev/null - if [ $? -ne 0 ]; then - echo -n $"Starting simulator: " - rm -f /var/xapi/xiu-xc /var/xapi/xiu-xs - "@LIBEXECDIR@/xiu" /var/xapi/xiu 2>/dev/null 1>/dev/null & - - # wait for unix domain socket to appear - RETRIES=180 - while [ ${RETRIES} -ne 0 ]; do - [ -e /var/xapi/xiu-xc ] && break - RETRIES=$(( ${RETRIES} - 1 )) - sleep 1 - echo -n . - done - if [ -e /var/xapi/xiu-xc ]; then - echo "[ OK ]" - else - failure $"xiu" - exit 1 - fi - export XENCTRL_OSDEP="@OPTDIR@/lib/libxenctrl_xiu.so" - export XIU=/var/xapi/xiu - fi echo -n $"Starting xenstored: " if [ -e /var/lock/subsys/xen ]; then if [ -e /var/run/xenstored.pid ] && [ -e /proc/`cat /var/run/xenstored.pid` ]; then diff --git a/xapi.spec.in b/xapi.spec.in index 3f3efe107c..9c60a4b5b9 100644 --- a/xapi.spec.in +++ b/xapi.spec.in @@ -278,8 +278,6 @@ rm -rf $RPM_BUILD_ROOT @OPTDIR@/libexec/xapi-rolling-upgrade @OPTDIR@/libexec/xenguest @OPTDIR@/libexec/xha-lc -@OPTDIR@/libexec/xiu -@OPTDIR@/lib/libxenctrl_xiu.so @OPTDIR@/libexec/pci-info @OPTDIR@/packages/post-install-scripts/debian-etch @OPTDIR@/packages/post-install-scripts/debug