John Levon
2006-Apr-26 19:22 UTC
[Xen-devel] [PATCH] make privcmd interface private to libxc
As discussed, this is the first part to cleaning up the explicit use of the kernel/dom0 interface that should be private to libxc. This only deals with privcmd stuff; later patches will add new interfaces for /dev/xen/evtchn, and the remaining bits of xenstore interfaces. regards john # HG changeset patch # User john.levon@sun.com # Node ID 8e9e3a38536a6044eddeb4890347e73ded27edf2 # Parent 9df603eff58a6e5126b0eb82906b961a684575a7 Move Linux-specific privcmd code into private libxc implementations. Make header path for kernel''s privcmd/evtchn headers generic. Remove pointless xi_*() interface that was using private libxc interfaces. Signed-off-by: John Levon <john.levon@sun.com> diff -r 9df603eff58a -r 8e9e3a38536a tools/Rules.mk --- a/tools/Rules.mk Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/Rules.mk Wed Apr 26 02:45:22 2006 -0700 @@ -23,15 +23,23 @@ %.o: %.cc $(CC) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< -.PHONY: mk-symlinks -mk-symlinks: LINUX_ROOT=$(XEN_ROOT)/linux-2.6-xen-sparse -mk-symlinks: +OS = $(shell uname -s) + +.PHONY: mk-symlinks mk-symlinks-xen mk-symlinks-$(OS) + +mk-symlinks-Linux: LINUX_ROOT=$(XEN_ROOT)/linux-2.6-xen-sparse +mk-symlinks-Linux: + mkdir -p xen/linux + ( cd xen/linux && \ + ln -sf ../../$(LINUX_ROOT)/include/xen/public/*.h . ) + ( cd xen && rm -f sys && ln -sf linux sys ) + +mk-symlinks-xen: mkdir -p xen ( cd xen && ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . ) mkdir -p xen/hvm ( cd xen/hvm && ln -sf ../../$(XEN_ROOT)/xen/include/public/hvm/*.h . ) mkdir -p xen/io ( cd xen/io && ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . ) - mkdir -p xen/linux - ( cd xen/linux && \ - ln -sf ../../$(LINUX_ROOT)/include/xen/public/*.h . ) + +mk-symlinks: mk-symlinks-xen mk-symlinks-$(OS) diff -r 9df603eff58a -r 8e9e3a38536a tools/debugger/pdb/pdb_caml_process.c --- a/tools/debugger/pdb/pdb_caml_process.c Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/debugger/pdb/pdb_caml_process.c Wed Apr 26 02:45:22 2006 -0700 @@ -18,7 +18,6 @@ #include <xenctrl.h> #include <xen/xen.h> #include <xen/io/domain_controller.h> -#include <xen/linux/privcmd.h> #include "pdb_module.h" #include "pdb_caml_xen.h" diff -r 9df603eff58a -r 8e9e3a38536a tools/debugger/pdb/pdb_caml_xcs.c --- a/tools/debugger/pdb/pdb_caml_xcs.c Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/debugger/pdb/pdb_caml_xcs.c Wed Apr 26 02:45:22 2006 -0700 @@ -21,7 +21,6 @@ #include <xen/xen.h> #include <xen/io/domain_controller.h> -#include <xen/linux/privcmd.h> #include <arpa/inet.h> #include <xcs_proto.h> diff -r 9df603eff58a -r 8e9e3a38536a tools/libxc/Makefile --- a/tools/libxc/Makefile Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/libxc/Makefile Wed Apr 26 02:45:22 2006 -0700 @@ -16,6 +16,7 @@ SRCS += xc_domain.c SRCS += xc_evtchn.c SRCS += xc_misc.c +SRCS += xc_acm.c SRCS += xc_physdev.c SRCS += xc_private.c SRCS += xc_sedf.c @@ -26,6 +27,10 @@ SRCS += xc_ptrace_core.c SRCS += xc_pagetab.c endif + +SRCS_Linux += xc_linux.c + +SRCS += $(SRCS_$(shell uname -s)) BUILD_SRCS : BUILD_SRCS += xc_linux_build.c diff -r 9df603eff58a -r 8e9e3a38536a tools/libxc/xc_linux_save.c --- a/tools/libxc/xc_linux_save.c Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/libxc/xc_linux_save.c Wed Apr 26 02:45:22 2006 -0700 @@ -12,6 +12,7 @@ #include <unistd.h> #include <sys/time.h> +#include "xc_private.h" #include "xg_private.h" #include "xg_save_restore.h" @@ -505,7 +506,6 @@ int prot) { struct xen_machphys_mfn_list xmml; - privcmd_mmap_t ioctlx; privcmd_mmap_entry_t *entries; unsigned long m2p_chunks, m2p_size; unsigned long *m2p; @@ -537,18 +537,15 @@ return NULL; } - ioctlx.num = m2p_chunks; - ioctlx.dom = DOMID_XEN; - ioctlx.entry = entries; - for (i=0; i < m2p_chunks; i++) { entries[i].va = (unsigned long)(((void *)m2p) + (i * M2P_CHUNK_SIZE)); entries[i].mfn = xmml.extent_start[i]; entries[i].npages = M2P_CHUNK_SIZE >> PAGE_SHIFT; } - if ((rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx)) < 0) { - ERR("ioctl_mmap failed (rc = %d)", rc); + if ((rc = xc_map_foreign_ranges(xc_handle, DOMID_XEN, + entries, m2p_chunks)) < 0) { + ERR("xc_mmap_foreign_ranges failed (rc = %d)", rc); return NULL; } diff -r 9df603eff58a -r 8e9e3a38536a tools/libxc/xc_misc.c --- a/tools/libxc/xc_misc.c Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/libxc/xc_misc.c Wed Apr 26 02:45:22 2006 -0700 @@ -5,19 +5,6 @@ */ #include "xc_private.h" - -int xc_interface_open(void) -{ - int fd = open("/proc/xen/privcmd", O_RDWR); - if ( fd == -1 ) - PERROR("Could not obtain handle on privileged command interface"); - return fd; -} - -int xc_interface_close(int xc_handle) -{ - return close(xc_handle); -} int xc_readconsolering(int xc_handle, char **pbuffer, diff -r 9df603eff58a -r 8e9e3a38536a tools/libxc/xc_private.c --- a/tools/libxc/xc_private.c Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/libxc/xc_private.c Wed Apr 26 02:45:22 2006 -0700 @@ -5,63 +5,6 @@ */ #include "xc_private.h" -#include <xen/memory.h> - -void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot, - unsigned long *arr, int num ) -{ - privcmd_mmapbatch_t ioctlx; - void *addr; - addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0); - if ( addr == MAP_FAILED ) - return NULL; - - ioctlx.num=num; - ioctlx.dom=dom; - ioctlx.addr=(unsigned long)addr; - ioctlx.arr=arr; - if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx ) < 0 ) - { - int saved_errno = errno; - perror("XXXXXXXX"); - (void)munmap(addr, num*PAGE_SIZE); - errno = saved_errno; - return NULL; - } - return addr; - -} - -/*******************/ - -void *xc_map_foreign_range(int xc_handle, uint32_t dom, - int size, int prot, - unsigned long mfn ) -{ - privcmd_mmap_t ioctlx; - privcmd_mmap_entry_t entry; - void *addr; - addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0); - if ( addr == MAP_FAILED ) - return NULL; - - ioctlx.num=1; - ioctlx.dom=dom; - ioctlx.entry=&entry; - entry.va=(unsigned long) addr; - entry.mfn=mfn; - entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT; - if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx ) < 0 ) - { - int saved_errno = errno; - (void)munmap(addr, size); - errno = saved_errno; - return NULL; - } - return addr; -} - -/*******************/ /* NB: arr must be mlock''ed */ int xc_get_pfn_type_batch(int xc_handle, diff -r 9df603eff58a -r 8e9e3a38536a tools/libxc/xc_private.h --- a/tools/libxc/xc_private.h Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/libxc/xc_private.h Wed Apr 26 02:45:22 2006 -0700 @@ -15,7 +15,7 @@ #include "xenctrl.h" -#include <xen/linux/privcmd.h> +#include <xen/sys/privcmd.h> /* valgrind cannot see when a hypercall has filled in some values. For this reason, we must zero the privcmd_hypercall_t or dom0_op_t instance before a @@ -56,20 +56,7 @@ errno = saved_errno; } -static inline int do_privcmd(int xc_handle, - unsigned int cmd, - unsigned long data) -{ - return ioctl(xc_handle, cmd, data); -} - -static inline int do_xen_hypercall(int xc_handle, - privcmd_hypercall_t *hypercall) -{ - return do_privcmd(xc_handle, - IOCTL_PRIVCMD_HYPERCALL, - (unsigned long)hypercall); -} +int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall); static inline int do_xen_version(int xc_handle, int cmd, void *dest) { @@ -111,23 +98,7 @@ return ret; } - -/* - * ioctl-based mfn mapping interface - */ - -/* -typedef struct privcmd_mmap_entry { - unsigned long va; - unsigned long mfn; - unsigned long npages; -} privcmd_mmap_entry_t; - -typedef struct privcmd_mmap { - int num; - domid_t dom; - privcmd_mmap_entry_t *entry; -} privcmd_mmap_t; -*/ +int xc_map_foreign_ranges(int xc_handle, uint32_t dom, + privcmd_mmap_entry_t *entries, int nr); #endif /* __XC_PRIVATE_H__ */ diff -r 9df603eff58a -r 8e9e3a38536a tools/libxc/xc_tbuf.c --- a/tools/libxc/xc_tbuf.c Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/libxc/xc_tbuf.c Wed Apr 26 02:45:22 2006 -0700 @@ -4,6 +4,14 @@ * API for manipulating and accessing trace buffer parameters * * Copyright (c) 2005, Rob Gardner + * + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2 of the + * License. */ #include "xc_private.h" @@ -49,3 +57,41 @@ return rc; } +int xc_tbuf_get_mfn(int xc_handle, unsigned long *mfn) +{ + int rc; + DECLARE_DOM0_OP; + + op.cmd = DOM0_TBUFCONTROL; + op.interface_version = DOM0_INTERFACE_VERSION; + op.u.tbufcontrol.op = DOM0_TBUF_GET_INFO; + + rc = xc_dom0_op(xc_handle, &op); + if ( rc == 0 ) + *mfn = op.u.tbufcontrol.buffer_mfn; + return rc; +} + +int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask) +{ + DECLARE_DOM0_OP; + + op.cmd = DOM0_TBUFCONTROL; + op.interface_version = DOM0_INTERFACE_VERSION; + op.u.tbufcontrol.op = DOM0_TBUF_SET_CPU_MASK; + op.u.tbufcontrol.cpu_mask = mask; + + return do_dom0_op(xc_handle, &op); +} + +int xc_tbuf_set_evt_mask(int xc_handle, uint32_t mask) +{ + DECLARE_DOM0_OP; + + op.cmd = DOM0_TBUFCONTROL; + op.interface_version = DOM0_INTERFACE_VERSION; + op.u.tbufcontrol.op = DOM0_TBUF_SET_EVT_MASK; + op.u.tbufcontrol.evt_mask = mask; + + return do_dom0_op(xc_handle, &op); +} diff -r 9df603eff58a -r 8e9e3a38536a tools/libxc/xenctrl.h --- a/tools/libxc/xenctrl.h Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/libxc/xenctrl.h Wed Apr 26 02:45:22 2006 -0700 @@ -19,6 +19,7 @@ #include <xen/sched_ctl.h> #include <xen/memory.h> #include <xen/acm.h> +#include <xen/acm_ops.h> #ifdef __ia64__ #define XC_PAGE_SHIFT 14 @@ -560,6 +561,18 @@ */ int xc_tbuf_get_size(int xc_handle, uint32_t *size); +/** + * This function retrieves the machine frame of the trace buffer. + + * @parm xc_handle a handle to an open hypervisor interface + * @parm mfn will contain the machine frame of the buffer. + * @return 0 on success, -1 on failure. + */ +int xc_tbuf_get_mfn(int xc_handle, unsigned long *mfn); + +int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask); + +int xc_tbuf_set_evt_mask(int xc_handle, uint32_t mask); /* Execute a privileged dom0 operation. */ int xc_dom0_op(int xc_handle, dom0_op_t *op); @@ -581,4 +594,6 @@ unsigned long long ptr, unsigned long long val); int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu); +int xc_acm_op(int xc_handle, struct acm_op *op); + #endif diff -r 9df603eff58a -r 8e9e3a38536a tools/libxc/xg_private.h --- a/tools/libxc/xg_private.h Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/libxc/xg_private.h Wed Apr 26 02:45:22 2006 -0700 @@ -13,7 +13,7 @@ #include "xenctrl.h" #include "xenguest.h" -#include <xen/linux/privcmd.h> +#include <xen/sys/privcmd.h> #include <xen/memory.h> /* valgrind cannot see when a hypercall has filled in some values. For this diff -r 9df603eff58a -r 8e9e3a38536a tools/python/xen/lowlevel/acm/acm.c --- a/tools/python/xen/lowlevel/acm/acm.c Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/python/xen/lowlevel/acm/acm.c Wed Apr 26 02:45:22 2006 -0700 @@ -28,51 +28,22 @@ #include <netinet/in.h> #include <xen/acm.h> #include <xen/acm_ops.h> -#include <xen/linux/privcmd.h> + +#include <xenctrl.h> #define PERROR(_m, _a...) \ fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \ errno, strerror(errno)) - - -static inline int do_acm_op(int xc_handle, struct acm_op *op) -{ - int ret = -1; - privcmd_hypercall_t hypercall; - - op->interface_version = ACM_INTERFACE_VERSION; - - hypercall.op = __HYPERVISOR_acm_op; - hypercall.arg[0] = (unsigned long) op; - - if (mlock(op, sizeof(*op)) != 0) { - PERROR("Could not lock memory for Xen policy hypercall"); - goto out1; - } - ret = ioctl(xc_handle, IOCTL_PRIVCMD_HYPERCALL, &hypercall); - if (ret < 0) { - if (errno == EACCES) - PERROR("ACM operation failed."); - goto out2; - } - out2: - munlock(op, sizeof(*op)); - out1: - return ret; -} - - - /* generic shared function */ void * __getssid(int domid, uint32_t *buflen) { struct acm_op op; - int acm_cmd_fd; + int xc_handle; #define SSID_BUFFER_SIZE 4096 void *buf = NULL; - if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) < 0) { + if ((xc_handle = xc_interface_open()) < 0) { goto out1; } if ((buf = malloc(SSID_BUFFER_SIZE)) == NULL) { @@ -87,7 +58,9 @@ op.u.getssid.get_ssid_by = DOMAINID; op.u.getssid.id.domainid = domid; - if (do_acm_op(acm_cmd_fd, &op) < 0) { + if (xc_acm_op(xc_handle, &op) < 0) { + if (errno == EACCES) + PERROR("ACM operation failed."); free(buf); buf = NULL; goto out2; @@ -96,7 +69,7 @@ goto out2; } out2: - close(acm_cmd_fd); + xc_interface_close(xc_handle); out1: return buf; } @@ -175,13 +148,13 @@ { char *arg1_name, *arg1, *arg2_name, *arg2, *decision = NULL; struct acm_op op; - int acm_cmd_fd, ret; + int xc_handle; if (!PyArg_ParseTuple(args, "ssss", &arg1_name, &arg1, &arg2_name, &arg2)) { return NULL; } - if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0) { + if ((xc_handle = xc_interface_open()) <= 0) { PERROR("Could not open xen privcmd device!\n"); return NULL; } @@ -208,8 +181,12 @@ op.u.getdecision.id2.ssidref = atol(arg2); } - ret = do_acm_op(acm_cmd_fd, &op); - close(acm_cmd_fd); + if (xc_acm_op(xc_handle, &op) < 0) { + if (errno == EACCES) + PERROR("ACM operation failed."); + } + + xc_interface_close(xc_handle); if (op.u.getdecision.acm_decision == ACM_ACCESS_PERMITTED) decision = "PERMITTED"; diff -r 9df603eff58a -r 8e9e3a38536a tools/security/secpol_tool.c --- a/tools/security/secpol_tool.c Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/security/secpol_tool.c Wed Apr 26 02:45:22 2006 -0700 @@ -14,7 +14,7 @@ * * sHype policy management tool. This code runs in a domain and * manages the Xen security policy by interacting with the - * Xen access control module via a /proc/xen/privcmd proc-ioctl, + * Xen access control module via the privcmd device, * which is translated into a acm_op hypercall into Xen. * * indent -i4 -kr -nut @@ -36,7 +36,8 @@ #include <stdint.h> #include <xen/acm.h> #include <xen/acm_ops.h> -#include <xen/linux/privcmd.h> + +#include <xenctrl.h> #define PERROR(_m, _a...) \ fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \ @@ -50,47 +51,6 @@ "\t dumpstats\n" "\t loadpolicy <binary policy file>\n", progname); exit(-1); -} - -static inline int do_policycmd(int xc_handle, unsigned int cmd, - unsigned long data) -{ - return ioctl(xc_handle, cmd, data); -} - -static inline int do_xen_hypercall(int xc_handle, - privcmd_hypercall_t * hypercall) -{ - return do_policycmd(xc_handle, - IOCTL_PRIVCMD_HYPERCALL, - (unsigned long) hypercall); -} - -static inline int do_acm_op(int xc_handle, struct acm_op *op) -{ - int ret = -1; - privcmd_hypercall_t hypercall; - - op->interface_version = ACM_INTERFACE_VERSION; - - hypercall.op = __HYPERVISOR_acm_op; - hypercall.arg[0] = (unsigned long) op; - - if (mlock(op, sizeof(*op)) != 0) { - PERROR("Could not lock memory for Xen policy hypercall"); - goto out1; - } - - if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0) { - printf("ACM operation failed: errno=%d\n", errno); - if (errno == EACCES) - fprintf(stderr, "ACM operation failed -- need to" - " rebuild the user-space tool set?\n"); - goto out2; - } - - out2:(void) munlock(op, sizeof(*op)); - out1:return ret; } /*************************** DUMPS *******************************/ @@ -276,10 +236,15 @@ memset(pull_buffer, 0x00, sizeof(pull_buffer)); op.cmd = ACM_GETPOLICY; - op.interface_version = ACM_INTERFACE_VERSION; op.u.getpolicy.pullcache = (void *) pull_buffer; op.u.getpolicy.pullcache_size = sizeof(pull_buffer); - ret = do_acm_op(xc_handle, &op); + if ((ret = xc_acm_op(xc_handle, &op)) < 0) { + printf("ACM operation failed: errno=%d\n", errno); + if (errno == EACCES) + fprintf(stderr, "ACM operation failed -- need to" + " rebuild the user-space tool set?\n"); + } + /* dump policy */ acm_dump_policy_buffer(pull_buffer, sizeof(pull_buffer)); return ret; @@ -314,10 +279,9 @@ /* dump it and then push it down into xen/acm */ acm_dump_policy_buffer(buffer, len); op.cmd = ACM_SETPOLICY; - op.interface_version = ACM_INTERFACE_VERSION; op.u.setpolicy.pushcache = (void *) buffer; op.u.setpolicy.pushcache_size = len; - ret = do_acm_op(xc_handle, &op); + ret = xc_acm_op(xc_handle, &op); if (ret) printf @@ -364,10 +328,9 @@ memset(stats_buffer, 0x00, sizeof(stats_buffer)); op.cmd = ACM_DUMPSTATS; - op.interface_version = ACM_INTERFACE_VERSION; op.u.dumpstats.pullcache = (void *) stats_buffer; op.u.dumpstats.pullcache_size = sizeof(stats_buffer); - ret = do_acm_op(xc_handle, &op); + ret = xc_acm_op(xc_handle, &op); if (ret < 0) { printf @@ -426,12 +389,12 @@ int main(int argc, char **argv) { - int acm_cmd_fd, ret = 0; + int xc_handle, ret = 0; if (argc < 2) usage(argv[0]); - if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0) { + if ((xc_handle = xc_interface_open()) <= 0) { printf("ERROR: Could not open xen privcmd device!\n"); exit(-1); } @@ -439,18 +402,18 @@ if (!strcmp(argv[1], "getpolicy")) { if (argc != 2) usage(argv[0]); - ret = acm_domain_getpolicy(acm_cmd_fd); + ret = acm_domain_getpolicy(xc_handle); } else if (!strcmp(argv[1], "loadpolicy")) { if (argc != 3) usage(argv[0]); - ret = acm_domain_loadpolicy(acm_cmd_fd, argv[2]); + ret = acm_domain_loadpolicy(xc_handle, argv[2]); } else if (!strcmp(argv[1], "dumpstats")) { if (argc != 2) usage(argv[0]); - ret = acm_domain_dumpstats(acm_cmd_fd); + ret = acm_domain_dumpstats(xc_handle); } else usage(argv[0]); - close(acm_cmd_fd); + xc_interface_close(xc_handle); return ret; } diff -r 9df603eff58a -r 8e9e3a38536a tools/xenmon/xenbaked.c --- a/tools/xenmon/xenbaked.c Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/xenmon/xenbaked.c Wed Apr 26 02:45:22 2006 -0700 @@ -410,14 +410,13 @@ struct t_buf *map_tbufs(unsigned long tbufs_mfn, unsigned int num, unsigned long size) { - int xc_handle; /* file descriptor for /proc/xen/privcmd */ + int xc_handle; struct t_buf *tbufs_mapped; xc_handle = xc_interface_open(); if ( xc_handle < 0 ) { - PERROR("Open /proc/xen/privcmd when mapping trace buffers\n"); exit(EXIT_FAILURE); } diff -r 9df603eff58a -r 8e9e3a38536a tools/xenstat/libxenstat/Makefile --- a/tools/xenstat/libxenstat/Makefile Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/xenstat/libxenstat/Makefile Wed Apr 26 02:45:22 2006 -0700 @@ -33,28 +33,26 @@ LIB=src/libxenstat.a SHLIB=src/libxenstat.so.$(MAJOR).$(MINOR) SHLIB_LINKS=src/libxenstat.so.$(MAJOR) src/libxenstat.so -OBJECTS=src/xenstat.o src/xen-interface.o +OBJECTS=src/xenstat.o SONAME_FLAGS=-Wl,-soname -Wl,libxenstat.so.$(MAJOR) WARN_FLAGS=-Wall -Werror CFLAGS+=-Isrc -I$(XEN_LIBXC) -I$(XEN_XENSTORE) -LDFLAGS+=-Lsrc +LDFLAGS+=-Lsrc -L$(XEN_XENSTORE)/ -L$(XEN_LIBXC)/ .PHONY: all all: $(LIB) $(LIB): $(OBJECTS) - $(AR) rc $@ $^ $(XEN_XENSTORE)/libxenstore.so + $(AR) rc $@ $^ $(XEN_XENSTORE)/libxenstore.so $(XEN_LIBXC)/libxenctrl.so $(RANLIB) $@ $(SHLIB): $(OBJECTS) - $(CC) $(CFLAGS) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $(OBJECTS) + $(CC) $(CFLAGS) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $(OBJECTS) \ + -lxenstore -lxenctrl -src/xenstat.o: src/xenstat.c src/xenstat.h src/xen-interface.h - $(CC) $(CFLAGS) $(WARN_FLAGS) -c -o $@ $< - -src/xen-interface.o: src/xen-interface.c src/xen-interface.h +src/xenstat.o: src/xenstat.c src/xenstat.h $(CC) $(CFLAGS) $(WARN_FLAGS) -c -o $@ $< src/libxenstat.so.$(MAJOR): $(LIB) diff -r 9df603eff58a -r 8e9e3a38536a tools/xenstat/libxenstat/src/xenstat.c --- a/tools/xenstat/libxenstat/src/xenstat.c Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/xenstat/libxenstat/src/xenstat.c Wed Apr 26 02:45:22 2006 -0700 @@ -20,9 +20,10 @@ #include <stdio.h> #include <string.h> #include <unistd.h> -#include <xen-interface.h> #include <xs.h> #include "xenstat.h" + +#include "xenctrl.h" /* * Types @@ -31,7 +32,7 @@ #define VERSION_SIZE (2 * SHORT_ASC_LEN + 1 + sizeof(xen_extraversion_t) + 1) struct xenstat_handle { - xi_handle *xihandle; + int xc_handle; struct xs_handle *xshandle; /* xenstore handle */ int page_size; FILE *procnetdev; @@ -150,9 +151,9 @@ } #endif - handle->xihandle = xi_init(); - if (handle->xihandle == NULL) { - perror("xi_init"); + handle->xc_handle = xc_interface_open(); + if (handle->xc_handle == -1) { + perror("xc_interface_open"); free(handle); return NULL; } @@ -160,6 +161,7 @@ handle->xshandle = xs_daemon_open_readonly(); /* open handle to xenstore*/ if (handle->xshandle == NULL) { perror("unable to open xenstore\n"); + xc_interface_close(handle->xc_handle); free(handle); return NULL; } @@ -173,7 +175,7 @@ if (handle) { for (i = 0; i < NUM_COLLECTORS; i++) collectors[i].uninit(handle); - xi_uninit(handle->xihandle); + xc_interface_close(handle->xc_handle); xs_daemon_close(handle->xshandle); free(handle); } @@ -197,7 +199,7 @@ node->handle = handle; /* Get information about the physical system */ - if (xi_get_physinfo(handle->xihandle, &physinfo) < 0) { + if (xc_physinfo(handle->xc_handle, &physinfo) < 0) { free(node); return NULL; } @@ -223,9 +225,8 @@ do { xenstat_domain *domain; - new_domains = xi_get_domaininfolist(handle->xihandle, - domaininfo, num_domains, - DOMAIN_CHUNK_SIZE); + new_domains = xc_domain_getinfolist(handle->xc_handle, + num_domains, DOMAIN_CHUNK_SIZE, domaininfo); node->domains = realloc(node->domains, (num_domains + new_domains) @@ -467,8 +468,8 @@ /* FIXME: need to be using a more efficient mechanism*/ dom0_getvcpuinfo_t info; - if (xi_get_domain_vcpu_info(node->handle->xihandle, - node->domains[i].id, vcpu, &info) != 0) + if (xc_vcpu_getinfo(node->handle->xc_handle, + node->domains[i].id, vcpu, &info) != 0) return 0; node->domains[i].vcpus[vcpu].online = info.online; @@ -677,8 +678,14 @@ /* Collect Xen version information if not already collected */ if (node->handle->xen_version[0] == ''\0'') { /* Get the Xen version number and extraversion string */ - if (xi_get_xen_version(node->handle->xihandle, - &vnum, &version) < 0) + vnum = xc_version(node->handle->xc_handle, + XENVER_version, NULL); + + if (vnum < 0) + return 0; + + if (xc_version(node->handle->xc_handle, XENVER_extraversion, + &version) < 0) return 0; /* Format the version information as a string and store it */ snprintf(node->handle->xen_version, VERSION_SIZE, "%ld.%ld%s", diff -r 9df603eff58a -r 8e9e3a38536a tools/xentrace/xentrace.c --- a/tools/xentrace/xentrace.c Wed Apr 26 10:43:16 2006 +0100 +++ b/tools/xentrace/xentrace.c Wed Apr 26 02:45:22 2006 -0700 @@ -20,10 +20,21 @@ #include <errno.h> #include <argp.h> #include <signal.h> - -#include "xc_private.h" - +#include <inttypes.h> +#include <string.h> + +#include <xen/xen.h> #include <xen/trace.h> + +#include <xenctrl.h> + +#define PERROR(_m, _a...) \ +do { \ + int __saved_errno = errno; \ + fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \ + __saved_errno, strerror(__saved_errno)); \ + errno = __saved_errno; \ +} while (0) extern FILE *stderr; @@ -100,26 +111,22 @@ */ void get_tbufs(unsigned long *mfn, unsigned long *size) { - int ret; - dom0_op_t op; /* dom0 op we''ll build */ + uint32_t size32; int xc_handle = xc_interface_open(); /* for accessing control interface */ - op.cmd = DOM0_TBUFCONTROL; - op.interface_version = DOM0_INTERFACE_VERSION; - op.u.tbufcontrol.op = DOM0_TBUF_GET_INFO; - - ret = do_dom0_op(xc_handle, &op); + if (xc_tbuf_get_size(xc_handle, &size32) != 0) + goto fail; + *size = size32; + + if (xc_tbuf_get_mfn(xc_handle, mfn) != 0) + goto fail; xc_interface_close(xc_handle); - - if ( ret != 0 ) - { - PERROR("Failure to get trace buffer pointer from Xen"); - exit(EXIT_FAILURE); - } - - *mfn = op.u.tbufcontrol.buffer_mfn; - *size = op.u.tbufcontrol.size; + return; + +fail: + PERROR("Failure to get trace buffer pointer from Xen"); + exit(EXIT_FAILURE); } /** @@ -133,14 +140,13 @@ struct t_buf *map_tbufs(unsigned long tbufs_mfn, unsigned int num, unsigned long size) { - int xc_handle; /* file descriptor for /proc/xen/privcmd */ + int xc_handle; struct t_buf *tbufs_mapped; xc_handle = xc_interface_open(); if ( xc_handle < 0 ) { - PERROR("Open /proc/xen/privcmd when mapping trace buffers\n"); exit(EXIT_FAILURE); } @@ -167,24 +173,17 @@ */ void set_mask(uint32_t mask, int type) { - int ret; - dom0_op_t op; /* dom0 op we''ll build */ + int ret = 0; int xc_handle = xc_interface_open(); /* for accessing control interface */ - op.cmd = DOM0_TBUFCONTROL; - op.interface_version = DOM0_INTERFACE_VERSION; - if (type == 1) { /* cpu mask */ - op.u.tbufcontrol.op = DOM0_TBUF_SET_CPU_MASK; - op.u.tbufcontrol.cpu_mask = mask; + if (type == 1) { + ret = xc_tbuf_set_cpu_mask(xc_handle, mask); fprintf(stderr, "change cpumask to 0x%x\n", mask); - }else if (type == 0) { /* event mask */ - op.u.tbufcontrol.op = DOM0_TBUF_SET_EVT_MASK; - op.u.tbufcontrol.evt_mask = mask; + } else if (type == 0) { + ret = xc_tbuf_set_evt_mask(xc_handle, mask); fprintf(stderr, "change evtmask to 0x%x\n", mask); } - ret = do_dom0_op(xc_handle, &op); - xc_interface_close(xc_handle); if ( ret != 0 ) @@ -192,7 +191,6 @@ PERROR("Failure to get trace buffer pointer from Xen and set the new mask"); exit(EXIT_FAILURE); } - } /** @@ -260,14 +258,11 @@ */ unsigned int get_num_cpus(void) { - dom0_op_t op; + xc_physinfo_t physinfo; int xc_handle = xc_interface_open(); int ret; - op.cmd = DOM0_PHYSINFO; - op.interface_version = DOM0_INTERFACE_VERSION; - - ret = do_dom0_op(xc_handle, &op); + ret = xc_physinfo(xc_handle, &physinfo); if ( ret != 0 ) { @@ -277,10 +272,10 @@ xc_interface_close(xc_handle); - return (op.u.physinfo.threads_per_core * - op.u.physinfo.cores_per_socket * - op.u.physinfo.sockets_per_node * - op.u.physinfo.nr_nodes); + return (physinfo.threads_per_core * + physinfo.cores_per_socket * + physinfo.sockets_per_node * + physinfo.nr_nodes); } diff -r 9df603eff58a -r 8e9e3a38536a tools/libxc/xc_acm.c --- /dev/null Thu Jan 1 00:00:00 1970 +0000 +++ b/tools/libxc/xc_acm.c Wed Apr 26 02:45:22 2006 -0700 @@ -0,0 +1,54 @@ +/****************************************************************************** + * + * Copyright (C) 2005 IBM Corporation + * + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * Authors: + * Reiner Sailer <sailer@watson.ibm.com> + * Stefan Berger <stefanb@watson.ibm.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2 of the + * License. + */ + +#include "xc_private.h" + +int xc_acm_op(int xc_handle, struct acm_op *op) +{ + int ret = -1; + DECLARE_HYPERCALL; + + op->interface_version = ACM_INTERFACE_VERSION; + + hypercall.op = __HYPERVISOR_acm_op; + hypercall.arg[0] = (unsigned long) op; + + if (mlock(op, sizeof(*op)) != 0) { + PERROR("Could not lock memory for Xen policy hypercall"); + goto out1; + } + + ret = do_xen_hypercall(xc_handle, &hypercall); + ret = ioctl(xc_handle, IOCTL_PRIVCMD_HYPERCALL, &hypercall); + if (ret < 0) { + goto out2; + } + out2: + safe_munlock(op, sizeof(*op)); + out1: + return ret; +} + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r 9df603eff58a -r 8e9e3a38536a tools/libxc/xc_linux.c --- /dev/null Thu Jan 1 00:00:00 1970 +0000 +++ b/tools/libxc/xc_linux.c Wed Apr 26 02:45:22 2006 -0700 @@ -0,0 +1,114 @@ +/****************************************************************************** + * + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2 of the + * License. + */ + +#include "xc_private.h" + +#include <xen/memory.h> +#include <xen/sys/evtchn.h> + +int xc_interface_open(void) +{ + int fd = open("/proc/xen/privcmd", O_RDWR); + if ( fd == -1 ) + PERROR("Could not obtain handle on privileged command interface"); + return fd; +} + +int xc_interface_close(int xc_handle) +{ + return close(xc_handle); +} + +void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot, + unsigned long *arr, int num) +{ + privcmd_mmapbatch_t ioctlx; + void *addr; + addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0); + if ( addr == MAP_FAILED ) + return NULL; + + ioctlx.num=num; + ioctlx.dom=dom; + ioctlx.addr=(unsigned long)addr; + ioctlx.arr=arr; + if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 ) + { + int saved_errno = errno; + perror("XXXXXXXX"); + (void)munmap(addr, num*PAGE_SIZE); + errno = saved_errno; + return NULL; + } + return addr; + +} + +void *xc_map_foreign_range(int xc_handle, uint32_t dom, + int size, int prot, + unsigned long mfn) +{ + privcmd_mmap_t ioctlx; + privcmd_mmap_entry_t entry; + void *addr; + addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0); + if ( addr == MAP_FAILED ) + return NULL; + + ioctlx.num=1; + ioctlx.dom=dom; + ioctlx.entry=&entry; + entry.va=(unsigned long) addr; + entry.mfn=mfn; + entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT; + if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 ) + { + int saved_errno = errno; + (void)munmap(addr, size); + errno = saved_errno; + return NULL; + } + return addr; +} + +int xc_map_foreign_ranges(int xc_handle, uint32_t dom, + privcmd_mmap_entry_t *entries, int nr) +{ + privcmd_mmap_t ioctlx; + + ioctlx.num = nr; + ioctlx.dom = dom; + ioctlx.entry = entries; + + return ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx); +} + +static int do_privcmd(int xc_handle, unsigned int cmd, unsigned long data) +{ + return ioctl(xc_handle, cmd, data); +} + +int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall) +{ + return do_privcmd(xc_handle, + IOCTL_PRIVCMD_HYPERCALL, + (unsigned long)hypercall); +} + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r 9df603eff58a -r 8e9e3a38536a tools/xenstat/libxenstat/src/xen-interface.c --- a/tools/xenstat/libxenstat/src/xen-interface.c Wed Apr 26 10:43:16 2006 +0100 +++ /dev/null Thu Jan 1 00:00:00 1970 +0000 @@ -1,201 +0,0 @@ -/* xen-interface.c - * - * Copyright (C) International Business Machines Corp., 2005 - * Authors: Josh Triplett <josht@us.ibm.com> - * Judy Fischbach <jfisch@us.ibm.com> - * - * This library 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; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 "xen-interface.h" -#include <fcntl.h> -#include <sys/ioctl.h> -#include <sys/mman.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <xen/linux/privcmd.h> - -struct xi_handle { - int fd; -}; - -/* Initialize for xen-interface. Returns a handle to be used with subsequent - * calls to the xen-interface functions or NULL if an error occurs. */ -xi_handle *xi_init(void) -{ - xi_handle *handle; - - handle = (xi_handle *)calloc(1, sizeof(xi_handle)); - if (handle == NULL) - return NULL; - - handle->fd = open("/proc/xen/privcmd", O_RDWR); - if (handle->fd < 0) { - perror("Couldn''t open /proc/xen/privcmd"); - free(handle); - return NULL; - } - - return handle; -} - -/* Release the handle to libxc, free resources, etc. */ -void xi_uninit(xi_handle *handle) -{ - close (handle->fd); - free (handle); -} - -/* Make simple xen version hypervisor calls */ -static int xi_make_xen_version_hypercall(xi_handle *handle, long *vnum, - xen_extraversion_t *ver) -{ - privcmd_hypercall_t privcmd; - int ret = 0; - - if (mlock(&privcmd, sizeof(privcmd)) < 0) { - perror("Failed to mlock privcmd structure"); - return -1; - } - - if (mlock(ver, sizeof(*ver)) < 0) { - perror("Failed to mlock extraversion structure"); - munlock(&privcmd, sizeof(privcmd)); - return -1; - } - - privcmd.op = __HYPERVISOR_xen_version; - privcmd.arg[0] = (unsigned long)XENVER_version; - privcmd.arg[1] = 0; - - *vnum = ioctl(handle->fd, IOCTL_PRIVCMD_HYPERCALL, &privcmd); - if (*vnum < 0) { - perror("Hypercall failed"); - ret = -1; - } - - privcmd.op = __HYPERVISOR_xen_version; - privcmd.arg[0] = (unsigned long)XENVER_extraversion; - privcmd.arg[1] = (unsigned long)ver; - - if (ioctl(handle->fd, IOCTL_PRIVCMD_HYPERCALL, &privcmd) < 0) { - perror("Hypercall failed"); - ret = -1; - } - - munlock(&privcmd, sizeof(privcmd)); - munlock(ver, sizeof(*ver)); - - return ret; -} - -/* Make Xen Dom0 op hypervisor call */ -static int xi_make_dom0_op(xi_handle *handle, dom0_op_t *dom_op, - int dom_opcode) -{ - privcmd_hypercall_t privcmd; - int ret = 0; - - /* set up for doing hypercall */ - privcmd.op = __HYPERVISOR_dom0_op; - privcmd.arg[0] = (unsigned long)dom_op; - dom_op->cmd = dom_opcode; - dom_op->interface_version = DOM0_INTERFACE_VERSION; - - if (mlock( &privcmd, sizeof(privcmd_hypercall_t)) < 0) { - perror("Failed to mlock privcmd structure"); - return -1; - } - - if (mlock( dom_op, sizeof(dom0_op_t)) < 0) { - perror("Failed to mlock dom0_op structure"); - munlock( &privcmd, sizeof(privcmd_hypercall_t)); - return -1; - } - - if (ioctl( handle->fd, IOCTL_PRIVCMD_HYPERCALL, &privcmd) < 0) { - perror("Hypercall failed"); - ret = -1; - } - - munlock( &privcmd, sizeof(privcmd_hypercall_t)); - munlock( dom_op, sizeof(dom0_op_t)); - - return ret; -} - -/* Obtain domain data from dom0 */ -int xi_get_physinfo(xi_handle *handle, dom0_physinfo_t *physinfo) -{ - dom0_op_t op; - - if (xi_make_dom0_op(handle, &op, DOM0_PHYSINFO) < 0) { - perror("DOM0_PHYSINFO Hypercall failed"); - return -1; - } - - *physinfo = op.u.physinfo; - return 0; -} - -/* Obtain domain data from dom0 */ -int xi_get_domaininfolist(xi_handle *handle, dom0_getdomaininfo_t *info, - unsigned int first_domain, unsigned int max_domains) -{ - dom0_op_t op; - op.u.getdomaininfolist.first_domain = first_domain; - op.u.getdomaininfolist.max_domains = max_domains; - op.u.getdomaininfolist.buffer = info; - - if (mlock( info, max_domains * sizeof(dom0_getdomaininfo_t)) < 0) { - perror("Failed to mlock domaininfo array"); - return -1; - } - - if (xi_make_dom0_op(handle, &op, DOM0_GETDOMAININFOLIST) < 0) { - perror("DOM0_GETDOMAININFOLIST Hypercall failed"); - return -1; - } - - return op.u.getdomaininfolist.num_domains; -} - -/* Get vcpu info from a domain */ -int xi_get_domain_vcpu_info(xi_handle *handle, unsigned int domain, - unsigned int vcpu, dom0_getvcpuinfo_t *info) -{ - dom0_op_t op; - op.u.getvcpuinfo.domain = domain; - op.u.getvcpuinfo.vcpu = vcpu; - - if (xi_make_dom0_op(handle, &op, DOM0_GETVCPUINFO) < 0) { - perror("DOM0_GETVCPUINFO Hypercall failed"); - return -1; - } - - memcpy(info, &op.u.getvcpuinfo, sizeof(dom0_getvcpuinfo_t)); - - return 0; -} - -/* gets xen version information from hypervisor */ -int xi_get_xen_version(xi_handle *handle, long *vnum, xen_extraversion_t *ver) -{ - /* gets the XENVER_version and XENVER_extraversion */ - if (xi_make_xen_version_hypercall( handle, vnum, ver) < 0) { - perror("XEN VERSION Hypercall failed"); - return -1; - } - - return 0; -} diff -r 9df603eff58a -r 8e9e3a38536a tools/xenstat/libxenstat/src/xen-interface.h --- a/tools/xenstat/libxenstat/src/xen-interface.h Wed Apr 26 10:43:16 2006 +0100 +++ /dev/null Thu Jan 1 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* xen-interface.h - * - * Copyright (C) International Business Machines Corp., 2005 - * Authors: Josh Triplett <josht@us.ibm.com> - * Judy Fischbach <jfisch@us.ibm.com> - * - * This library 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; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 <stdint.h> -#include <xen/xen.h> -#include <xen/dom0_ops.h> -#include <xen/sched.h> -#include <xen/version.h> - -/* Opaque handles */ -typedef struct xi_handle xi_handle; - -/* Initialize for xen-interface. Returns a handle to be used with subsequent - * calls to the xen-interface functions or NULL if an error occurs. */ -xi_handle *xi_init(void); - -/* Release the handle to libxc, free resources, etc. */ -void xi_uninit(xi_handle *handle); - -/* Obtain xen version information from hypervisor */ -int xi_get_xen_version(xi_handle *, long *vnum, xen_extraversion_t *ver); - -/* Obtain physinfo data from dom0 */ -int xi_get_physinfo(xi_handle *, dom0_physinfo_t *); - -/* Obtain domain data from dom0 */ -int xi_get_domaininfolist(xi_handle *, dom0_getdomaininfo_t *, unsigned int, - unsigned int); - -/* Get vcpu info from a domain */ -int xi_get_domain_vcpu_info(xi_handle *, unsigned int, unsigned int, - dom0_getvcpuinfo_t *); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
John Levon
2006-May-02 13:32 UTC
[Xen-devel] [PATCH][RESEND] make privcmd interface private to libxc
On Wed, Apr 26, 2006 at 08:22:03PM +0100, John Levon wrote:> As discussed, this is the first part to cleaning up the explicit use of > the kernel/dom0 interface that should be private to libxc. This only > deals with privcmd stuff; later patches will add new interfaces for > /dev/xen/evtchn, and the remaining bits of xenstore interfaces.Sent again. It seems the previous patch didn''t actually apply (I thought I''d tested applying it to a clean tip, but apparently not). regards john # HG changeset patch # User john.levon@sun.com # Node ID e276e89e24ae8744f9313869b45114e0effbfcb9 # Parent a95e677073c1fa420f10c572e0a2f6925e6853fa Move Linux-specific privcmd code into private libxc implementations. Make header path for kernel''s privcmd/evtchn headers generic. Remove pointless xi_*() interface that was using private libxc interfaces. Signed-off-by: John Levon <john.levon@sun.com> diff -r a95e677073c1 -r e276e89e24ae tools/Rules.mk --- a/tools/Rules.mk Tue May 02 09:18:55 2006 +0100 +++ b/tools/Rules.mk Tue May 02 12:22:35 2006 +0000 @@ -23,15 +23,23 @@ CFLAGS += -D__XEN_TOOLS__ %.o: %.cc $(CC) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< -.PHONY: mk-symlinks -mk-symlinks: LINUX_ROOT=$(XEN_ROOT)/linux-2.6-xen-sparse -mk-symlinks: +OS = $(shell uname -s) + +.PHONY: mk-symlinks mk-symlinks-xen mk-symlinks-$(OS) + +mk-symlinks-Linux: LINUX_ROOT=$(XEN_ROOT)/linux-2.6-xen-sparse +mk-symlinks-Linux: + mkdir -p xen/linux + ( cd xen/linux && \ + ln -sf ../../$(LINUX_ROOT)/include/xen/public/*.h . ) + ( cd xen && rm -f sys && ln -sf linux sys ) + +mk-symlinks-xen: mkdir -p xen ( cd xen && ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . ) mkdir -p xen/hvm ( cd xen/hvm && ln -sf ../../$(XEN_ROOT)/xen/include/public/hvm/*.h . ) mkdir -p xen/io ( cd xen/io && ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . ) - mkdir -p xen/linux - ( cd xen/linux && \ - ln -sf ../../$(LINUX_ROOT)/include/xen/public/*.h . ) + +mk-symlinks: mk-symlinks-xen mk-symlinks-$(OS) diff -r a95e677073c1 -r e276e89e24ae tools/debugger/pdb/pdb_caml_process.c --- a/tools/debugger/pdb/pdb_caml_process.c Tue May 02 09:18:55 2006 +0100 +++ b/tools/debugger/pdb/pdb_caml_process.c Tue May 02 12:22:35 2006 +0000 @@ -18,7 +18,6 @@ #include <xenctrl.h> #include <xen/xen.h> #include <xen/io/domain_controller.h> -#include <xen/linux/privcmd.h> #include "pdb_module.h" #include "pdb_caml_xen.h" diff -r a95e677073c1 -r e276e89e24ae tools/debugger/pdb/pdb_caml_xcs.c --- a/tools/debugger/pdb/pdb_caml_xcs.c Tue May 02 09:18:55 2006 +0100 +++ b/tools/debugger/pdb/pdb_caml_xcs.c Tue May 02 12:22:35 2006 +0000 @@ -21,7 +21,6 @@ #include <xen/xen.h> #include <xen/io/domain_controller.h> -#include <xen/linux/privcmd.h> #include <arpa/inet.h> #include <xcs_proto.h> diff -r a95e677073c1 -r e276e89e24ae tools/libxc/Makefile --- a/tools/libxc/Makefile Tue May 02 09:18:55 2006 +0100 +++ b/tools/libxc/Makefile Tue May 02 12:22:35 2006 +0000 @@ -16,6 +16,7 @@ SRCS += xc_domain.c SRCS += xc_domain.c SRCS += xc_evtchn.c SRCS += xc_misc.c +SRCS += xc_acm.c SRCS += xc_physdev.c SRCS += xc_private.c SRCS += xc_sedf.c @@ -26,6 +27,10 @@ SRCS += xc_ptrace_core.c SRCS += xc_ptrace_core.c SRCS += xc_pagetab.c endif + +SRCS_Linux += xc_linux.c + +SRCS += $(SRCS_$(shell uname -s)) BUILD_SRCS : BUILD_SRCS += xc_linux_build.c diff -r a95e677073c1 -r e276e89e24ae tools/libxc/xc_linux_save.c --- a/tools/libxc/xc_linux_save.c Tue May 02 09:18:55 2006 +0100 +++ b/tools/libxc/xc_linux_save.c Tue May 02 12:22:35 2006 +0000 @@ -12,6 +12,7 @@ #include <unistd.h> #include <sys/time.h> +#include "xc_private.h" #include "xg_private.h" #include "xg_save_restore.h" @@ -505,7 +506,6 @@ static unsigned long *xc_map_m2p(int xc_ int prot) { struct xen_machphys_mfn_list xmml; - privcmd_mmap_t ioctlx; privcmd_mmap_entry_t *entries; unsigned long m2p_chunks, m2p_size; unsigned long *m2p; @@ -539,18 +539,15 @@ static unsigned long *xc_map_m2p(int xc_ return NULL; } - ioctlx.num = m2p_chunks; - ioctlx.dom = DOMID_XEN; - ioctlx.entry = entries; - for (i=0; i < m2p_chunks; i++) { entries[i].va = (unsigned long)(((void *)m2p) + (i * M2P_CHUNK_SIZE)); entries[i].mfn = extent_start[i]; entries[i].npages = M2P_CHUNK_SIZE >> PAGE_SHIFT; } - if ((rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx)) < 0) { - ERR("ioctl_mmap failed (rc = %d)", rc); + if ((rc = xc_map_foreign_ranges(xc_handle, DOMID_XEN, + entries, m2p_chunks)) < 0) { + ERR("xc_mmap_foreign_ranges failed (rc = %d)", rc); return NULL; } diff -r a95e677073c1 -r e276e89e24ae tools/libxc/xc_misc.c --- a/tools/libxc/xc_misc.c Tue May 02 09:18:55 2006 +0100 +++ b/tools/libxc/xc_misc.c Tue May 02 12:22:35 2006 +0000 @@ -5,19 +5,6 @@ */ #include "xc_private.h" - -int xc_interface_open(void) -{ - int fd = open("/proc/xen/privcmd", O_RDWR); - if ( fd == -1 ) - PERROR("Could not obtain handle on privileged command interface"); - return fd; -} - -int xc_interface_close(int xc_handle) -{ - return close(xc_handle); -} int xc_readconsolering(int xc_handle, char **pbuffer, diff -r a95e677073c1 -r e276e89e24ae tools/libxc/xc_private.c --- a/tools/libxc/xc_private.c Tue May 02 09:18:55 2006 +0100 +++ b/tools/libxc/xc_private.c Tue May 02 12:22:35 2006 +0000 @@ -5,63 +5,6 @@ */ #include "xc_private.h" -#include <xen/memory.h> - -void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot, - unsigned long *arr, int num ) -{ - privcmd_mmapbatch_t ioctlx; - void *addr; - addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0); - if ( addr == MAP_FAILED ) - return NULL; - - ioctlx.num=num; - ioctlx.dom=dom; - ioctlx.addr=(unsigned long)addr; - ioctlx.arr=arr; - if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx ) < 0 ) - { - int saved_errno = errno; - perror("XXXXXXXX"); - (void)munmap(addr, num*PAGE_SIZE); - errno = saved_errno; - return NULL; - } - return addr; - -} - -/*******************/ - -void *xc_map_foreign_range(int xc_handle, uint32_t dom, - int size, int prot, - unsigned long mfn ) -{ - privcmd_mmap_t ioctlx; - privcmd_mmap_entry_t entry; - void *addr; - addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0); - if ( addr == MAP_FAILED ) - return NULL; - - ioctlx.num=1; - ioctlx.dom=dom; - ioctlx.entry=&entry; - entry.va=(unsigned long) addr; - entry.mfn=mfn; - entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT; - if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx ) < 0 ) - { - int saved_errno = errno; - (void)munmap(addr, size); - errno = saved_errno; - return NULL; - } - return addr; -} - -/*******************/ /* NB: arr must be mlock''ed */ int xc_get_pfn_type_batch(int xc_handle, diff -r a95e677073c1 -r e276e89e24ae tools/libxc/xc_private.h --- a/tools/libxc/xc_private.h Tue May 02 09:18:55 2006 +0100 +++ b/tools/libxc/xc_private.h Tue May 02 12:22:35 2006 +0000 @@ -15,7 +15,7 @@ #include "xenctrl.h" -#include <xen/linux/privcmd.h> +#include <xen/sys/privcmd.h> /* valgrind cannot see when a hypercall has filled in some values. For this reason, we must zero the privcmd_hypercall_t or dom0_op_t instance before a @@ -56,20 +56,7 @@ static inline void safe_munlock(const vo errno = saved_errno; } -static inline int do_privcmd(int xc_handle, - unsigned int cmd, - unsigned long data) -{ - return ioctl(xc_handle, cmd, data); -} - -static inline int do_xen_hypercall(int xc_handle, - privcmd_hypercall_t *hypercall) -{ - return do_privcmd(xc_handle, - IOCTL_PRIVCMD_HYPERCALL, - (unsigned long)hypercall); -} +int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall); static inline int do_xen_version(int xc_handle, int cmd, void *dest) { @@ -111,23 +98,7 @@ static inline int do_dom0_op(int xc_hand return ret; } - -/* - * ioctl-based mfn mapping interface - */ - -/* -typedef struct privcmd_mmap_entry { - unsigned long va; - unsigned long mfn; - unsigned long npages; -} privcmd_mmap_entry_t; - -typedef struct privcmd_mmap { - int num; - domid_t dom; - privcmd_mmap_entry_t *entry; -} privcmd_mmap_t; -*/ +int xc_map_foreign_ranges(int xc_handle, uint32_t dom, + privcmd_mmap_entry_t *entries, int nr); #endif /* __XC_PRIVATE_H__ */ diff -r a95e677073c1 -r e276e89e24ae tools/libxc/xc_tbuf.c --- a/tools/libxc/xc_tbuf.c Tue May 02 09:18:55 2006 +0100 +++ b/tools/libxc/xc_tbuf.c Tue May 02 12:22:35 2006 +0000 @@ -4,6 +4,14 @@ * API for manipulating and accessing trace buffer parameters * * Copyright (c) 2005, Rob Gardner + * + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2 of the + * License. */ #include "xc_private.h" @@ -49,3 +57,41 @@ int xc_tbuf_get_size(int xc_handle, uint return rc; } +int xc_tbuf_get_mfn(int xc_handle, unsigned long *mfn) +{ + int rc; + DECLARE_DOM0_OP; + + op.cmd = DOM0_TBUFCONTROL; + op.interface_version = DOM0_INTERFACE_VERSION; + op.u.tbufcontrol.op = DOM0_TBUF_GET_INFO; + + rc = xc_dom0_op(xc_handle, &op); + if ( rc == 0 ) + *mfn = op.u.tbufcontrol.buffer_mfn; + return rc; +} + +int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask) +{ + DECLARE_DOM0_OP; + + op.cmd = DOM0_TBUFCONTROL; + op.interface_version = DOM0_INTERFACE_VERSION; + op.u.tbufcontrol.op = DOM0_TBUF_SET_CPU_MASK; + op.u.tbufcontrol.cpu_mask = mask; + + return do_dom0_op(xc_handle, &op); +} + +int xc_tbuf_set_evt_mask(int xc_handle, uint32_t mask) +{ + DECLARE_DOM0_OP; + + op.cmd = DOM0_TBUFCONTROL; + op.interface_version = DOM0_INTERFACE_VERSION; + op.u.tbufcontrol.op = DOM0_TBUF_SET_EVT_MASK; + op.u.tbufcontrol.evt_mask = mask; + + return do_dom0_op(xc_handle, &op); +} diff -r a95e677073c1 -r e276e89e24ae tools/libxc/xenctrl.h --- a/tools/libxc/xenctrl.h Tue May 02 09:18:55 2006 +0100 +++ b/tools/libxc/xenctrl.h Tue May 02 12:22:35 2006 +0000 @@ -19,6 +19,7 @@ #include <xen/sched_ctl.h> #include <xen/memory.h> #include <xen/acm.h> +#include <xen/acm_ops.h> #ifdef __ia64__ #define XC_PAGE_SHIFT 14 @@ -560,6 +561,18 @@ int xc_tbuf_set_size(int xc_handle, uint */ int xc_tbuf_get_size(int xc_handle, uint32_t *size); +/** + * This function retrieves the machine frame of the trace buffer. + + * @parm xc_handle a handle to an open hypervisor interface + * @parm mfn will contain the machine frame of the buffer. + * @return 0 on success, -1 on failure. + */ +int xc_tbuf_get_mfn(int xc_handle, unsigned long *mfn); + +int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask); + +int xc_tbuf_set_evt_mask(int xc_handle, uint32_t mask); /* Execute a privileged dom0 operation. */ int xc_dom0_op(int xc_handle, dom0_op_t *op); @@ -581,4 +594,6 @@ int xc_add_mmu_update(int xc_handle, xc_ unsigned long long ptr, unsigned long long val); int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu); +int xc_acm_op(int xc_handle, struct acm_op *op); + #endif diff -r a95e677073c1 -r e276e89e24ae tools/libxc/xg_private.h --- a/tools/libxc/xg_private.h Tue May 02 09:18:55 2006 +0100 +++ b/tools/libxc/xg_private.h Tue May 02 12:22:35 2006 +0000 @@ -13,7 +13,7 @@ #include "xenctrl.h" #include "xenguest.h" -#include <xen/linux/privcmd.h> +#include <xen/sys/privcmd.h> #include <xen/memory.h> /* valgrind cannot see when a hypercall has filled in some values. For this diff -r a95e677073c1 -r e276e89e24ae tools/python/xen/lowlevel/acm/acm.c --- a/tools/python/xen/lowlevel/acm/acm.c Tue May 02 09:18:55 2006 +0100 +++ b/tools/python/xen/lowlevel/acm/acm.c Tue May 02 12:22:35 2006 +0000 @@ -28,51 +28,22 @@ #include <netinet/in.h> #include <xen/acm.h> #include <xen/acm_ops.h> -#include <xen/linux/privcmd.h> + +#include <xenctrl.h> #define PERROR(_m, _a...) \ fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \ errno, strerror(errno)) - - -static inline int do_acm_op(int xc_handle, struct acm_op *op) -{ - int ret = -1; - privcmd_hypercall_t hypercall; - - op->interface_version = ACM_INTERFACE_VERSION; - - hypercall.op = __HYPERVISOR_acm_op; - hypercall.arg[0] = (unsigned long) op; - - if (mlock(op, sizeof(*op)) != 0) { - PERROR("Could not lock memory for Xen policy hypercall"); - goto out1; - } - ret = ioctl(xc_handle, IOCTL_PRIVCMD_HYPERCALL, &hypercall); - if (ret < 0) { - if (errno == EACCES) - PERROR("ACM operation failed."); - goto out2; - } - out2: - munlock(op, sizeof(*op)); - out1: - return ret; -} - - - /* generic shared function */ void * __getssid(int domid, uint32_t *buflen) { struct acm_op op; - int acm_cmd_fd; + int xc_handle; #define SSID_BUFFER_SIZE 4096 void *buf = NULL; - if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) < 0) { + if ((xc_handle = xc_interface_open()) < 0) { goto out1; } if ((buf = malloc(SSID_BUFFER_SIZE)) == NULL) { @@ -87,7 +58,9 @@ void * __getssid(int domid, uint32_t *bu op.u.getssid.get_ssid_by = DOMAINID; op.u.getssid.id.domainid = domid; - if (do_acm_op(acm_cmd_fd, &op) < 0) { + if (xc_acm_op(xc_handle, &op) < 0) { + if (errno == EACCES) + PERROR("ACM operation failed."); free(buf); buf = NULL; goto out2; @@ -96,7 +69,7 @@ void * __getssid(int domid, uint32_t *bu goto out2; } out2: - close(acm_cmd_fd); + xc_interface_close(xc_handle); out1: return buf; } @@ -175,13 +148,13 @@ static PyObject *getdecision(PyObject * { char *arg1_name, *arg1, *arg2_name, *arg2, *decision = NULL; struct acm_op op; - int acm_cmd_fd, ret; + int xc_handle; if (!PyArg_ParseTuple(args, "ssss", &arg1_name, &arg1, &arg2_name, &arg2)) { return NULL; } - if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0) { + if ((xc_handle = xc_interface_open()) <= 0) { PERROR("Could not open xen privcmd device!\n"); return NULL; } @@ -208,8 +181,12 @@ static PyObject *getdecision(PyObject * op.u.getdecision.id2.ssidref = atol(arg2); } - ret = do_acm_op(acm_cmd_fd, &op); - close(acm_cmd_fd); + if (xc_acm_op(xc_handle, &op) < 0) { + if (errno == EACCES) + PERROR("ACM operation failed."); + } + + xc_interface_close(xc_handle); if (op.u.getdecision.acm_decision == ACM_ACCESS_PERMITTED) decision = "PERMITTED"; diff -r a95e677073c1 -r e276e89e24ae tools/security/secpol_tool.c --- a/tools/security/secpol_tool.c Tue May 02 09:18:55 2006 +0100 +++ b/tools/security/secpol_tool.c Tue May 02 12:22:35 2006 +0000 @@ -14,7 +14,7 @@ * * sHype policy management tool. This code runs in a domain and * manages the Xen security policy by interacting with the - * Xen access control module via a /proc/xen/privcmd proc-ioctl, + * Xen access control module via the privcmd device, * which is translated into a acm_op hypercall into Xen. * * indent -i4 -kr -nut @@ -36,7 +36,8 @@ #include <stdint.h> #include <xen/acm.h> #include <xen/acm_ops.h> -#include <xen/linux/privcmd.h> + +#include <xenctrl.h> #define PERROR(_m, _a...) \ fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \ @@ -50,47 +51,6 @@ void usage(char *progname) "\t dumpstats\n" "\t loadpolicy <binary policy file>\n", progname); exit(-1); -} - -static inline int do_policycmd(int xc_handle, unsigned int cmd, - unsigned long data) -{ - return ioctl(xc_handle, cmd, data); -} - -static inline int do_xen_hypercall(int xc_handle, - privcmd_hypercall_t * hypercall) -{ - return do_policycmd(xc_handle, - IOCTL_PRIVCMD_HYPERCALL, - (unsigned long) hypercall); -} - -static inline int do_acm_op(int xc_handle, struct acm_op *op) -{ - int ret = -1; - privcmd_hypercall_t hypercall; - - op->interface_version = ACM_INTERFACE_VERSION; - - hypercall.op = __HYPERVISOR_acm_op; - hypercall.arg[0] = (unsigned long) op; - - if (mlock(op, sizeof(*op)) != 0) { - PERROR("Could not lock memory for Xen policy hypercall"); - goto out1; - } - - if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0) { - printf("ACM operation failed: errno=%d\n", errno); - if (errno == EACCES) - fprintf(stderr, "ACM operation failed -- need to" - " rebuild the user-space tool set?\n"); - goto out2; - } - - out2:(void) munlock(op, sizeof(*op)); - out1:return ret; } /*************************** DUMPS *******************************/ @@ -276,10 +236,15 @@ int acm_domain_getpolicy(int xc_handle) memset(pull_buffer, 0x00, sizeof(pull_buffer)); op.cmd = ACM_GETPOLICY; - op.interface_version = ACM_INTERFACE_VERSION; op.u.getpolicy.pullcache = (void *) pull_buffer; op.u.getpolicy.pullcache_size = sizeof(pull_buffer); - ret = do_acm_op(xc_handle, &op); + if ((ret = xc_acm_op(xc_handle, &op)) < 0) { + printf("ACM operation failed: errno=%d\n", errno); + if (errno == EACCES) + fprintf(stderr, "ACM operation failed -- need to" + " rebuild the user-space tool set?\n"); + } + /* dump policy */ acm_dump_policy_buffer(pull_buffer, sizeof(pull_buffer)); return ret; @@ -314,10 +279,9 @@ int acm_domain_loadpolicy(int xc_handle, /* dump it and then push it down into xen/acm */ acm_dump_policy_buffer(buffer, len); op.cmd = ACM_SETPOLICY; - op.interface_version = ACM_INTERFACE_VERSION; op.u.setpolicy.pushcache = (void *) buffer; op.u.setpolicy.pushcache_size = len; - ret = do_acm_op(xc_handle, &op); + ret = xc_acm_op(xc_handle, &op); if (ret) printf @@ -364,10 +328,9 @@ int acm_domain_dumpstats(int xc_handle) memset(stats_buffer, 0x00, sizeof(stats_buffer)); op.cmd = ACM_DUMPSTATS; - op.interface_version = ACM_INTERFACE_VERSION; op.u.dumpstats.pullcache = (void *) stats_buffer; op.u.dumpstats.pullcache_size = sizeof(stats_buffer); - ret = do_acm_op(xc_handle, &op); + ret = xc_acm_op(xc_handle, &op); if (ret < 0) { printf @@ -426,12 +389,12 @@ int main(int argc, char **argv) int main(int argc, char **argv) { - int acm_cmd_fd, ret = 0; + int xc_handle, ret = 0; if (argc < 2) usage(argv[0]); - if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0) { + if ((xc_handle = xc_interface_open()) <= 0) { printf("ERROR: Could not open xen privcmd device!\n"); exit(-1); } @@ -439,18 +402,18 @@ int main(int argc, char **argv) if (!strcmp(argv[1], "getpolicy")) { if (argc != 2) usage(argv[0]); - ret = acm_domain_getpolicy(acm_cmd_fd); + ret = acm_domain_getpolicy(xc_handle); } else if (!strcmp(argv[1], "loadpolicy")) { if (argc != 3) usage(argv[0]); - ret = acm_domain_loadpolicy(acm_cmd_fd, argv[2]); + ret = acm_domain_loadpolicy(xc_handle, argv[2]); } else if (!strcmp(argv[1], "dumpstats")) { if (argc != 2) usage(argv[0]); - ret = acm_domain_dumpstats(acm_cmd_fd); + ret = acm_domain_dumpstats(xc_handle); } else usage(argv[0]); - close(acm_cmd_fd); + xc_interface_close(xc_handle); return ret; } diff -r a95e677073c1 -r e276e89e24ae tools/xenmon/xenbaked.c --- a/tools/xenmon/xenbaked.c Tue May 02 09:18:55 2006 +0100 +++ b/tools/xenmon/xenbaked.c Tue May 02 12:22:35 2006 +0000 @@ -410,14 +410,13 @@ struct t_buf *map_tbufs(unsigned long tb struct t_buf *map_tbufs(unsigned long tbufs_mfn, unsigned int num, unsigned long size) { - int xc_handle; /* file descriptor for /proc/xen/privcmd */ + int xc_handle; struct t_buf *tbufs_mapped; xc_handle = xc_interface_open(); if ( xc_handle < 0 ) { - PERROR("Open /proc/xen/privcmd when mapping trace buffers\n"); exit(EXIT_FAILURE); } diff -r a95e677073c1 -r e276e89e24ae tools/xenstat/libxenstat/Makefile --- a/tools/xenstat/libxenstat/Makefile Tue May 02 09:18:55 2006 +0100 +++ b/tools/xenstat/libxenstat/Makefile Tue May 02 12:22:35 2006 +0000 @@ -33,28 +33,26 @@ LIB=src/libxenstat.a LIB=src/libxenstat.a SHLIB=src/libxenstat.so.$(MAJOR).$(MINOR) SHLIB_LINKS=src/libxenstat.so.$(MAJOR) src/libxenstat.so -OBJECTS=src/xenstat.o src/xen-interface.o +OBJECTS=src/xenstat.o SONAME_FLAGS=-Wl,-soname -Wl,libxenstat.so.$(MAJOR) WARN_FLAGS=-Wall -Werror CFLAGS+=-Isrc -I$(XEN_LIBXC) -I$(XEN_XENSTORE) -LDFLAGS+=-Lsrc +LDFLAGS+=-Lsrc -L$(XEN_XENSTORE)/ -L$(XEN_LIBXC)/ .PHONY: all all: $(LIB) $(LIB): $(OBJECTS) - $(AR) rc $@ $^ $(XEN_XENSTORE)/libxenstore.so + $(AR) rc $@ $^ $(XEN_XENSTORE)/libxenstore.so $(XEN_LIBXC)/libxenctrl.so $(RANLIB) $@ $(SHLIB): $(OBJECTS) - $(CC) $(CFLAGS) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $(OBJECTS) + $(CC) $(CFLAGS) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $(OBJECTS) \ + -lxenstore -lxenctrl -src/xenstat.o: src/xenstat.c src/xenstat.h src/xen-interface.h - $(CC) $(CFLAGS) $(WARN_FLAGS) -c -o $@ $< - -src/xen-interface.o: src/xen-interface.c src/xen-interface.h +src/xenstat.o: src/xenstat.c src/xenstat.h $(CC) $(CFLAGS) $(WARN_FLAGS) -c -o $@ $< src/libxenstat.so.$(MAJOR): $(LIB) diff -r a95e677073c1 -r e276e89e24ae tools/xenstat/libxenstat/src/xenstat.c --- a/tools/xenstat/libxenstat/src/xenstat.c Tue May 02 09:18:55 2006 +0100 +++ b/tools/xenstat/libxenstat/src/xenstat.c Tue May 02 12:22:35 2006 +0000 @@ -20,9 +20,10 @@ #include <stdio.h> #include <string.h> #include <unistd.h> -#include <xen-interface.h> #include <xs.h> #include "xenstat.h" + +#include "xenctrl.h" /* * Types @@ -31,7 +32,7 @@ #define VERSION_SIZE (2 * SHORT_ASC_LEN + 1 + sizeof(xen_extraversion_t) + 1) struct xenstat_handle { - xi_handle *xihandle; + int xc_handle; struct xs_handle *xshandle; /* xenstore handle */ int page_size; FILE *procnetdev; @@ -150,9 +151,9 @@ xenstat_handle *xenstat_init(void) } #endif - handle->xihandle = xi_init(); - if (handle->xihandle == NULL) { - perror("xi_init"); + handle->xc_handle = xc_interface_open(); + if (handle->xc_handle == -1) { + perror("xc_interface_open"); free(handle); return NULL; } @@ -160,6 +161,7 @@ xenstat_handle *xenstat_init(void) handle->xshandle = xs_daemon_open_readonly(); /* open handle to xenstore*/ if (handle->xshandle == NULL) { perror("unable to open xenstore\n"); + xc_interface_close(handle->xc_handle); free(handle); return NULL; } @@ -173,7 +175,7 @@ void xenstat_uninit(xenstat_handle * han if (handle) { for (i = 0; i < NUM_COLLECTORS; i++) collectors[i].uninit(handle); - xi_uninit(handle->xihandle); + xc_interface_close(handle->xc_handle); xs_daemon_close(handle->xshandle); free(handle); } @@ -197,7 +199,7 @@ xenstat_node *xenstat_get_node(xenstat_h node->handle = handle; /* Get information about the physical system */ - if (xi_get_physinfo(handle->xihandle, &physinfo) < 0) { + if (xc_physinfo(handle->xc_handle, &physinfo) < 0) { free(node); return NULL; } @@ -223,9 +225,8 @@ xenstat_node *xenstat_get_node(xenstat_h do { xenstat_domain *domain; - new_domains = xi_get_domaininfolist(handle->xihandle, - domaininfo, num_domains, - DOMAIN_CHUNK_SIZE); + new_domains = xc_domain_getinfolist(handle->xc_handle, + num_domains, DOMAIN_CHUNK_SIZE, domaininfo); node->domains = realloc(node->domains, (num_domains + new_domains) @@ -467,8 +468,8 @@ static int xenstat_collect_vcpus(xenstat /* FIXME: need to be using a more efficient mechanism*/ dom0_getvcpuinfo_t info; - if (xi_get_domain_vcpu_info(node->handle->xihandle, - node->domains[i].id, vcpu, &info) != 0) + if (xc_vcpu_getinfo(node->handle->xc_handle, + node->domains[i].id, vcpu, &info) != 0) return 0; node->domains[i].vcpus[vcpu].online = info.online; @@ -677,8 +678,14 @@ static int xenstat_collect_xen_version(x /* Collect Xen version information if not already collected */ if (node->handle->xen_version[0] == ''\0'') { /* Get the Xen version number and extraversion string */ - if (xi_get_xen_version(node->handle->xihandle, - &vnum, &version) < 0) + vnum = xc_version(node->handle->xc_handle, + XENVER_version, NULL); + + if (vnum < 0) + return 0; + + if (xc_version(node->handle->xc_handle, XENVER_extraversion, + &version) < 0) return 0; /* Format the version information as a string and store it */ snprintf(node->handle->xen_version, VERSION_SIZE, "%ld.%ld%s", diff -r a95e677073c1 -r e276e89e24ae tools/xentrace/xentrace.c --- a/tools/xentrace/xentrace.c Tue May 02 09:18:55 2006 +0100 +++ b/tools/xentrace/xentrace.c Tue May 02 12:22:35 2006 +0000 @@ -20,10 +20,21 @@ #include <errno.h> #include <argp.h> #include <signal.h> - -#include "xc_private.h" - +#include <inttypes.h> +#include <string.h> + +#include <xen/xen.h> #include <xen/trace.h> + +#include <xenctrl.h> + +#define PERROR(_m, _a...) \ +do { \ + int __saved_errno = errno; \ + fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \ + __saved_errno, strerror(__saved_errno)); \ + errno = __saved_errno; \ +} while (0) extern FILE *stderr; @@ -100,26 +111,22 @@ void write_rec(unsigned int cpu, struct */ void get_tbufs(unsigned long *mfn, unsigned long *size) { - int ret; - dom0_op_t op; /* dom0 op we''ll build */ + uint32_t size32; int xc_handle = xc_interface_open(); /* for accessing control interface */ - op.cmd = DOM0_TBUFCONTROL; - op.interface_version = DOM0_INTERFACE_VERSION; - op.u.tbufcontrol.op = DOM0_TBUF_GET_INFO; - - ret = do_dom0_op(xc_handle, &op); + if (xc_tbuf_get_size(xc_handle, &size32) != 0) + goto fail; + *size = size32; + + if (xc_tbuf_get_mfn(xc_handle, mfn) != 0) + goto fail; xc_interface_close(xc_handle); - - if ( ret != 0 ) - { - PERROR("Failure to get trace buffer pointer from Xen"); - exit(EXIT_FAILURE); - } - - *mfn = op.u.tbufcontrol.buffer_mfn; - *size = op.u.tbufcontrol.size; + return; + +fail: + PERROR("Failure to get trace buffer pointer from Xen"); + exit(EXIT_FAILURE); } /** @@ -133,14 +140,13 @@ struct t_buf *map_tbufs(unsigned long tb struct t_buf *map_tbufs(unsigned long tbufs_mfn, unsigned int num, unsigned long size) { - int xc_handle; /* file descriptor for /proc/xen/privcmd */ + int xc_handle; struct t_buf *tbufs_mapped; xc_handle = xc_interface_open(); if ( xc_handle < 0 ) { - PERROR("Open /proc/xen/privcmd when mapping trace buffers\n"); exit(EXIT_FAILURE); } @@ -167,24 +173,17 @@ struct t_buf *map_tbufs(unsigned long tb */ void set_mask(uint32_t mask, int type) { - int ret; - dom0_op_t op; /* dom0 op we''ll build */ + int ret = 0; int xc_handle = xc_interface_open(); /* for accessing control interface */ - op.cmd = DOM0_TBUFCONTROL; - op.interface_version = DOM0_INTERFACE_VERSION; - if (type == 1) { /* cpu mask */ - op.u.tbufcontrol.op = DOM0_TBUF_SET_CPU_MASK; - op.u.tbufcontrol.cpu_mask = mask; + if (type == 1) { + ret = xc_tbuf_set_cpu_mask(xc_handle, mask); fprintf(stderr, "change cpumask to 0x%x\n", mask); - }else if (type == 0) { /* event mask */ - op.u.tbufcontrol.op = DOM0_TBUF_SET_EVT_MASK; - op.u.tbufcontrol.evt_mask = mask; + } else if (type == 0) { + ret = xc_tbuf_set_evt_mask(xc_handle, mask); fprintf(stderr, "change evtmask to 0x%x\n", mask); } - ret = do_dom0_op(xc_handle, &op); - xc_interface_close(xc_handle); if ( ret != 0 ) @@ -192,7 +191,6 @@ void set_mask(uint32_t mask, int type) PERROR("Failure to get trace buffer pointer from Xen and set the new mask"); exit(EXIT_FAILURE); } - } /** @@ -260,14 +258,11 @@ struct t_rec **init_rec_ptrs(struct t_bu */ unsigned int get_num_cpus(void) { - dom0_op_t op; + xc_physinfo_t physinfo; int xc_handle = xc_interface_open(); int ret; - op.cmd = DOM0_PHYSINFO; - op.interface_version = DOM0_INTERFACE_VERSION; - - ret = do_dom0_op(xc_handle, &op); + ret = xc_physinfo(xc_handle, &physinfo); if ( ret != 0 ) { @@ -277,10 +272,10 @@ unsigned int get_num_cpus(void) xc_interface_close(xc_handle); - return (op.u.physinfo.threads_per_core * - op.u.physinfo.cores_per_socket * - op.u.physinfo.sockets_per_node * - op.u.physinfo.nr_nodes); + return (physinfo.threads_per_core * + physinfo.cores_per_socket * + physinfo.sockets_per_node * + physinfo.nr_nodes); } diff -r a95e677073c1 -r e276e89e24ae tools/libxc/xc_acm.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxc/xc_acm.c Tue May 02 12:22:35 2006 +0000 @@ -0,0 +1,54 @@ +/****************************************************************************** + * + * Copyright (C) 2005 IBM Corporation + * + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * Authors: + * Reiner Sailer <sailer@watson.ibm.com> + * Stefan Berger <stefanb@watson.ibm.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2 of the + * License. + */ + +#include "xc_private.h" + +int xc_acm_op(int xc_handle, struct acm_op *op) +{ + int ret = -1; + DECLARE_HYPERCALL; + + op->interface_version = ACM_INTERFACE_VERSION; + + hypercall.op = __HYPERVISOR_acm_op; + hypercall.arg[0] = (unsigned long) op; + + if (mlock(op, sizeof(*op)) != 0) { + PERROR("Could not lock memory for Xen policy hypercall"); + goto out1; + } + + ret = do_xen_hypercall(xc_handle, &hypercall); + ret = ioctl(xc_handle, IOCTL_PRIVCMD_HYPERCALL, &hypercall); + if (ret < 0) { + goto out2; + } + out2: + safe_munlock(op, sizeof(*op)); + out1: + return ret; +} + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r a95e677073c1 -r e276e89e24ae tools/libxc/xc_linux.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxc/xc_linux.c Tue May 02 12:22:35 2006 +0000 @@ -0,0 +1,114 @@ +/****************************************************************************** + * + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2 of the + * License. + */ + +#include "xc_private.h" + +#include <xen/memory.h> +#include <xen/sys/evtchn.h> + +int xc_interface_open(void) +{ + int fd = open("/proc/xen/privcmd", O_RDWR); + if ( fd == -1 ) + PERROR("Could not obtain handle on privileged command interface"); + return fd; +} + +int xc_interface_close(int xc_handle) +{ + return close(xc_handle); +} + +void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot, + unsigned long *arr, int num) +{ + privcmd_mmapbatch_t ioctlx; + void *addr; + addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0); + if ( addr == MAP_FAILED ) + return NULL; + + ioctlx.num=num; + ioctlx.dom=dom; + ioctlx.addr=(unsigned long)addr; + ioctlx.arr=arr; + if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 ) + { + int saved_errno = errno; + perror("XXXXXXXX"); + (void)munmap(addr, num*PAGE_SIZE); + errno = saved_errno; + return NULL; + } + return addr; + +} + +void *xc_map_foreign_range(int xc_handle, uint32_t dom, + int size, int prot, + unsigned long mfn) +{ + privcmd_mmap_t ioctlx; + privcmd_mmap_entry_t entry; + void *addr; + addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0); + if ( addr == MAP_FAILED ) + return NULL; + + ioctlx.num=1; + ioctlx.dom=dom; + ioctlx.entry=&entry; + entry.va=(unsigned long) addr; + entry.mfn=mfn; + entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT; + if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 ) + { + int saved_errno = errno; + (void)munmap(addr, size); + errno = saved_errno; + return NULL; + } + return addr; +} + +int xc_map_foreign_ranges(int xc_handle, uint32_t dom, + privcmd_mmap_entry_t *entries, int nr) +{ + privcmd_mmap_t ioctlx; + + ioctlx.num = nr; + ioctlx.dom = dom; + ioctlx.entry = entries; + + return ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx); +} + +static int do_privcmd(int xc_handle, unsigned int cmd, unsigned long data) +{ + return ioctl(xc_handle, cmd, data); +} + +int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall) +{ + return do_privcmd(xc_handle, + IOCTL_PRIVCMD_HYPERCALL, + (unsigned long)hypercall); +} + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r a95e677073c1 -r e276e89e24ae tools/xenstat/libxenstat/src/xen-interface.c --- a/tools/xenstat/libxenstat/src/xen-interface.c Tue May 02 09:18:55 2006 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,201 +0,0 @@ -/* xen-interface.c - * - * Copyright (C) International Business Machines Corp., 2005 - * Authors: Josh Triplett <josht@us.ibm.com> - * Judy Fischbach <jfisch@us.ibm.com> - * - * This library 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; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 "xen-interface.h" -#include <fcntl.h> -#include <sys/ioctl.h> -#include <sys/mman.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <xen/linux/privcmd.h> - -struct xi_handle { - int fd; -}; - -/* Initialize for xen-interface. Returns a handle to be used with subsequent - * calls to the xen-interface functions or NULL if an error occurs. */ -xi_handle *xi_init(void) -{ - xi_handle *handle; - - handle = (xi_handle *)calloc(1, sizeof(xi_handle)); - if (handle == NULL) - return NULL; - - handle->fd = open("/proc/xen/privcmd", O_RDWR); - if (handle->fd < 0) { - perror("Couldn''t open /proc/xen/privcmd"); - free(handle); - return NULL; - } - - return handle; -} - -/* Release the handle to libxc, free resources, etc. */ -void xi_uninit(xi_handle *handle) -{ - close (handle->fd); - free (handle); -} - -/* Make simple xen version hypervisor calls */ -static int xi_make_xen_version_hypercall(xi_handle *handle, long *vnum, - xen_extraversion_t *ver) -{ - privcmd_hypercall_t privcmd; - int ret = 0; - - if (mlock(&privcmd, sizeof(privcmd)) < 0) { - perror("Failed to mlock privcmd structure"); - return -1; - } - - if (mlock(ver, sizeof(*ver)) < 0) { - perror("Failed to mlock extraversion structure"); - munlock(&privcmd, sizeof(privcmd)); - return -1; - } - - privcmd.op = __HYPERVISOR_xen_version; - privcmd.arg[0] = (unsigned long)XENVER_version; - privcmd.arg[1] = 0; - - *vnum = ioctl(handle->fd, IOCTL_PRIVCMD_HYPERCALL, &privcmd); - if (*vnum < 0) { - perror("Hypercall failed"); - ret = -1; - } - - privcmd.op = __HYPERVISOR_xen_version; - privcmd.arg[0] = (unsigned long)XENVER_extraversion; - privcmd.arg[1] = (unsigned long)ver; - - if (ioctl(handle->fd, IOCTL_PRIVCMD_HYPERCALL, &privcmd) < 0) { - perror("Hypercall failed"); - ret = -1; - } - - munlock(&privcmd, sizeof(privcmd)); - munlock(ver, sizeof(*ver)); - - return ret; -} - -/* Make Xen Dom0 op hypervisor call */ -static int xi_make_dom0_op(xi_handle *handle, dom0_op_t *dom_op, - int dom_opcode) -{ - privcmd_hypercall_t privcmd; - int ret = 0; - - /* set up for doing hypercall */ - privcmd.op = __HYPERVISOR_dom0_op; - privcmd.arg[0] = (unsigned long)dom_op; - dom_op->cmd = dom_opcode; - dom_op->interface_version = DOM0_INTERFACE_VERSION; - - if (mlock( &privcmd, sizeof(privcmd_hypercall_t)) < 0) { - perror("Failed to mlock privcmd structure"); - return -1; - } - - if (mlock( dom_op, sizeof(dom0_op_t)) < 0) { - perror("Failed to mlock dom0_op structure"); - munlock( &privcmd, sizeof(privcmd_hypercall_t)); - return -1; - } - - if (ioctl( handle->fd, IOCTL_PRIVCMD_HYPERCALL, &privcmd) < 0) { - perror("Hypercall failed"); - ret = -1; - } - - munlock( &privcmd, sizeof(privcmd_hypercall_t)); - munlock( dom_op, sizeof(dom0_op_t)); - - return ret; -} - -/* Obtain domain data from dom0 */ -int xi_get_physinfo(xi_handle *handle, dom0_physinfo_t *physinfo) -{ - dom0_op_t op; - - if (xi_make_dom0_op(handle, &op, DOM0_PHYSINFO) < 0) { - perror("DOM0_PHYSINFO Hypercall failed"); - return -1; - } - - *physinfo = op.u.physinfo; - return 0; -} - -/* Obtain domain data from dom0 */ -int xi_get_domaininfolist(xi_handle *handle, dom0_getdomaininfo_t *info, - unsigned int first_domain, unsigned int max_domains) -{ - dom0_op_t op; - op.u.getdomaininfolist.first_domain = first_domain; - op.u.getdomaininfolist.max_domains = max_domains; - set_xen_guest_handle(op.u.getdomaininfolist.buffer, info); - - if (mlock( info, max_domains * sizeof(dom0_getdomaininfo_t)) < 0) { - perror("Failed to mlock domaininfo array"); - return -1; - } - - if (xi_make_dom0_op(handle, &op, DOM0_GETDOMAININFOLIST) < 0) { - perror("DOM0_GETDOMAININFOLIST Hypercall failed"); - return -1; - } - - return op.u.getdomaininfolist.num_domains; -} - -/* Get vcpu info from a domain */ -int xi_get_domain_vcpu_info(xi_handle *handle, unsigned int domain, - unsigned int vcpu, dom0_getvcpuinfo_t *info) -{ - dom0_op_t op; - op.u.getvcpuinfo.domain = domain; - op.u.getvcpuinfo.vcpu = vcpu; - - if (xi_make_dom0_op(handle, &op, DOM0_GETVCPUINFO) < 0) { - perror("DOM0_GETVCPUINFO Hypercall failed"); - return -1; - } - - memcpy(info, &op.u.getvcpuinfo, sizeof(dom0_getvcpuinfo_t)); - - return 0; -} - -/* gets xen version information from hypervisor */ -int xi_get_xen_version(xi_handle *handle, long *vnum, xen_extraversion_t *ver) -{ - /* gets the XENVER_version and XENVER_extraversion */ - if (xi_make_xen_version_hypercall( handle, vnum, ver) < 0) { - perror("XEN VERSION Hypercall failed"); - return -1; - } - - return 0; -} diff -r a95e677073c1 -r e276e89e24ae tools/xenstat/libxenstat/src/xen-interface.h --- a/tools/xenstat/libxenstat/src/xen-interface.h Tue May 02 09:18:55 2006 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* xen-interface.h - * - * Copyright (C) International Business Machines Corp., 2005 - * Authors: Josh Triplett <josht@us.ibm.com> - * Judy Fischbach <jfisch@us.ibm.com> - * - * This library 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; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 <stdint.h> -#include <xen/xen.h> -#include <xen/dom0_ops.h> -#include <xen/sched.h> -#include <xen/version.h> - -/* Opaque handles */ -typedef struct xi_handle xi_handle; - -/* Initialize for xen-interface. Returns a handle to be used with subsequent - * calls to the xen-interface functions or NULL if an error occurs. */ -xi_handle *xi_init(void); - -/* Release the handle to libxc, free resources, etc. */ -void xi_uninit(xi_handle *handle); - -/* Obtain xen version information from hypervisor */ -int xi_get_xen_version(xi_handle *, long *vnum, xen_extraversion_t *ver); - -/* Obtain physinfo data from dom0 */ -int xi_get_physinfo(xi_handle *, dom0_physinfo_t *); - -/* Obtain domain data from dom0 */ -int xi_get_domaininfolist(xi_handle *, dom0_getdomaininfo_t *, unsigned int, - unsigned int); - -/* Get vcpu info from a domain */ -int xi_get_domain_vcpu_info(xi_handle *, unsigned int, unsigned int, - dom0_getvcpuinfo_t *); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel