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

[Xen-changelog] Move Linux-specific privcmd code into private libxc implementations.



# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID 24dbb153ab391f9860f05b9044ed18945a0e89fc
# 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@xxxxxxx>

diff -r a95e677073c1 -r 24dbb153ab39 tools/Rules.mk
--- a/tools/Rules.mk    Tue May 02 09:18:55 2006 +0100
+++ b/tools/Rules.mk    Tue May 02 15:12:06 2006 +0100
@@ -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 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 tools/libxc/Makefile
--- a/tools/libxc/Makefile      Tue May 02 09:18:55 2006 +0100
+++ b/tools/libxc/Makefile      Tue May 02 15:12:06 2006 +0100
@@ -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_Linux)
 
 BUILD_SRCS :=
 BUILD_SRCS += xc_linux_build.c
diff -r a95e677073c1 -r 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 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 15:12:06 2006 +0100
@@ -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 24dbb153ab39 tools/libxc/xc_acm.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxc/xc_acm.c      Tue May 02 15:12:06 2006 +0100
@@ -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@xxxxxxxxxxxxxx>
+ * Stefan Berger <stefanb@xxxxxxxxxxxxxx>
+ *
+ * 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 24dbb153ab39 tools/libxc/xc_linux.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxc/xc_linux.c    Tue May 02 15:12:06 2006 +0100
@@ -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:
+ */

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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