Skip to contentSkip to conversation

Build libxc on rump kernels

PATCH Superseded Wei Liu 4 participants 23 messages Feb 26, 2015 – Mar 3, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

cover Build libxc on rump kernels

This is a series done by Ian Jackson. I only changed a few macros and rewrote some commit logs.

With this series we can build libxc with rump kernels.

Wei.

Ian Jackson (5):
NetBSDRump: provide evtchn.h
libxc: Split off xc_minios_privcmd.c
libxc: Split off xc_netbsd_user.c
libxc: minios: Introduce abstraction for files[]
libxc: rumpxen: Provide xc_osdep_info

 tools/include/xen-sys/NetBSDRump/evtchn.h |  86 ++++++++
 tools/libxc/Makefile                      |   6 +-
 tools/libxc/xc_minios.c                   | 243 +---------------------
 tools/libxc/xc_minios_privcmd.c           | 322 ++++++++++++++++++++++++++++++
 tools/libxc/xc_netbsd.c                   | 168 +---------------
 tools/libxc/xc_netbsd_rumpkern.c          |  62 ++++++
 tools/libxc/xc_netbsd_user.c              | 196 ++++++++++++++++++
 tools/libxc/xc_private.h                  |   3 +
 8 files changed, 678 insertions(+), 408 deletions(-)
 create mode 100644 tools/include/xen-sys/NetBSDRump/evtchn.h
 create mode 100644 tools/libxc/xc_minios_privcmd.c
 create mode 100644 tools/libxc/xc_netbsd_rumpkern.c
 create mode 100644 tools/libxc/xc_netbsd_user.c
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 1/5 NetBSDRump: provide evtchn.h

From: Ian Jackson <[email protected]>

[ wei: write commit message ]

---
 tools/include/xen-sys/NetBSDRump/evtchn.h | 86 +++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)
 create mode 100644 tools/include/xen-sys/NetBSDRump/evtchn.h
tools/include/xen-sys/NetBSDRump/evtchn.h new file +86 -0
new file mode 100644
index 0000000..2d8a1f9
@@ -0,0 +1,86 @@
+/* $NetBSD: evtchn.h,v 1.1.1.1 2007/06/14 19:39:45 bouyer Exp $ */
+/******************************************************************************
+ * evtchn.h
+ * 
+ * Interface to /dev/xen/evtchn.
+ * 
+ * Copyright (c) 2003-2005, K A Fraser
+ * 
+ * This file may be distributed separately from the Linux kernel, or
+ * incorporated into other software packages, subject to the following license:
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this source file (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef __NetBSD_EVTCHN_H__
+#define __NetBSD_EVTCHN_H__
+
+/*
+ * Bind a fresh port to VIRQ @virq.
+ */
+#define IOCTL_EVTCHN_BIND_VIRQ				\
+	_IOWR('E', 4, struct ioctl_evtchn_bind_virq)
+struct ioctl_evtchn_bind_virq {
+	unsigned int virq;
+	unsigned int port;
+};
+
+/*
+ * Bind a fresh port to remote <@remote_domain, @remote_port>.
+ */
+#define IOCTL_EVTCHN_BIND_INTERDOMAIN			\
+	_IOWR('E', 5, struct ioctl_evtchn_bind_interdomain)
+struct ioctl_evtchn_bind_interdomain {
+	unsigned int remote_domain, remote_port;
+	unsigned int port;
+};
+
+/*
+ * Allocate a fresh port for binding to @remote_domain.
+ */
+#define IOCTL_EVTCHN_BIND_UNBOUND_PORT			\
+	_IOWR('E', 6, struct ioctl_evtchn_bind_unbound_port)
+struct ioctl_evtchn_bind_unbound_port {
+	unsigned int remote_domain;
+	unsigned int port;
+};
+
+/*
+ * Unbind previously allocated @port.
+ */
+#define IOCTL_EVTCHN_UNBIND				\
+	_IOW('E', 7, struct ioctl_evtchn_unbind)
+struct ioctl_evtchn_unbind {
+	unsigned int port;
+};
+
+/*
+ * Send event to previously allocated @port.
+ */
+#define IOCTL_EVTCHN_NOTIFY				\
+	_IOW('E', 8, struct ioctl_evtchn_notify)
+struct ioctl_evtchn_notify {
+	unsigned int port;
+};
+
+/* Clear and reinitialise the event buffer. Clear error condition. */
+#define IOCTL_EVTCHN_RESET				\
+	_IO('E', 9)
+
+#endif /* __NetBSD_EVTCHN_H__ */
Signature · 1 line
1.9.1
author
#3 lore raw

Re: [PATCH 1/5] NetBSDRump: provide evtchn.h

Quoted 9 lines · Ian Campbell
Quoted 5 lines · Wei Liu

From: Ian Jackson <[email protected]>

[ wei: write commit message ]

How long did that take ;-)

Less than 20 seconds.

Quoted 2 lines

Or did the intended text go missing?

No. I added Ian's SoB and a proper title to this changeset. That's all. :-)

Wei.

#4 lore raw

Re: [PATCH 1/5] NetBSDRump: provide evtchn.h

Quoted 11 lines · Wei Liu
Quoted 9 lines · Ian Campbell
Quoted 5 lines · Wei Liu

From: Ian Jackson <[email protected]>

[ wei: write commit message ]

How long did that take ;-)

Quoted 7 lines

Less than 20 seconds.

Quoted 2 lines

Or did the intended text go missing?

No. I added Ian's SoB and a proper title to this changeset. That's all. :-)

;-)

Can you describe the background of the file a bit. In particular where does it come from, is it just a copy of the NetBSD one? Or is it somehow RumpKernel specific (or expected to become so)? Where does the "otherend" (i.e. the implementation) live.

Ian.

author
#5 lore raw

Re: [PATCH 1/5] NetBSDRump: provide evtchn.h

Quoted 20 lines · Ian Campbell
Quoted 11 lines · Wei Liu
Quoted 9 lines · Ian Campbell
Quoted 5 lines · Wei Liu

From: Ian Jackson <[email protected]>

[ wei: write commit message ]

How long did that take ;-)

Quoted 7 lines

Less than 20 seconds.

Quoted 2 lines

Or did the intended text go missing?

No. I added Ian's SoB and a proper title to this changeset. That's all. :-)

Quoted 7 lines

;-)

Can you describe the background of the file a bit. In particular where does it come from, is it just a copy of the NetBSD one? Or is it somehow RumpKernel specific (or expected to become so)? Where does the "otherend" (i.e. the implementation) live.

No problem. I will do that in next version.

Wei.

Quoted 1 line

Ian.

author
#6 lore raw

PATCH 2/5 libxc: Split off xc_minios_privcmd.c

In reply to Wei Liu

From: Ian Jackson <[email protected]>

We are going to want to use some but not all of the machinery previously in xc_minios.c. Split the privcmd and gnttab code into its own file. This part is pure code motion.

But we also have to:

- Alter the Makefile to build and link xc_minios_privcmd.c too.

- Rename some of the minios_*_ops symbols to have proper namespaceing and make them have external linkage, so that the init code (which remains in xc_minios.c) can reference them.

- Call these *_ops symbols xc_*_ops so that we can mix and match in the future. This does not impede the existing mechanisms for run-time overriding. (But leave a comment next to the new declarations in xc_private.h saying not to use these.)

- Change map_frames_ex to minios_map_frames_ex if compiling on rump kernel.

[ wei: wrap long lines, use __RUMPRUN__ and define macro for map_frames_ex ]

---
 tools/libxc/Makefile            |   2 +-
 tools/libxc/xc_minios.c         | 243 +--------------------------------
 tools/libxc/xc_minios_privcmd.c | 291 ++++++++++++++++++++++++++++++++++++++++
 tools/libxc/xc_private.h        |   3 +
 4 files changed, 299 insertions(+), 240 deletions(-)
 create mode 100644 tools/libxc/xc_minios_privcmd.c
tools/libxc/Makefile +1 -1
index 6fa88c7..4ace2b6 100644
@@ -47,7 +47,7 @@ CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c
 CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c
 CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
 CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
-CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c
+CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c xc_minios_privcmd.c
 
 GUEST_SRCS-y :=
 GUEST_SRCS-y += xg_private.c xc_suspend.c
tools/libxc/xc_minios.c +4 -239

272 lines not on this page · raw message

tools/libxc/xc_minios_privcmd.c new file +291 -0

291 lines not on this page · raw message

tools/libxc/xc_private.h +3 -0
index 45b8644..152465f 100644
@@ -111,6 +111,9 @@ struct xc_interface_core {
     xc_osdep_handle  ops_handle; /* opaque data for xc_osdep_ops */
 };
 
+/* Do not use these directly; go via the handle you already have. */
+extern struct xc_osdep_ops xc_privcmd_ops, xc_evtchn_ops, xc_gnttab_ops;
+
 void xc_report_error(xc_interface *xch, int code, const char *fmt, ...)
     __attribute__((format(printf,3,4)));
 void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
Signature · 1 line
1.9.1
author
#7 lore raw

Re: [PATCH 2/5] libxc: Split off xc_minios_privcmd.c

Quoted 367 lines · Wei Liu

From: Ian Jackson <[email protected]>

We are going to want to use some but not all of the machinery previously in xc_minios.c. Split the privcmd and gnttab code into its own file. This part is pure code motion.

But we also have to:

- Alter the Makefile to build and link xc_minios_privcmd.c too.

- Rename some of the minios_*_ops symbols to have proper namespaceing and make them have external linkage, so that the init code (which remains in xc_minios.c) can reference them.

- Call these *_ops symbols xc_*_ops so that we can mix and match in the future. This does not impede the existing mechanisms for run-time overriding. (But leave a comment next to the new declarations in xc_private.h saying not to use these.)

- Change map_frames_ex to minios_map_frames_ex if compiling on rump kernel.

[ wei: wrap long lines, use __RUMPRUN__ and define macro for map_frames_ex ]

---
 tools/libxc/Makefile            |   2 +-
 tools/libxc/xc_minios.c         | 243 +--------------------------------
 tools/libxc/xc_minios_privcmd.c | 291 ++++++++++++++++++++++++++++++++++++++++
 tools/libxc/xc_private.h        |   3 +
 4 files changed, 299 insertions(+), 240 deletions(-)
 create mode 100644 tools/libxc/xc_minios_privcmd.c
tools/libxc/Makefile +1 -1
index 6fa88c7..4ace2b6 100644
@@ -47,7 +47,7 @@ CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c
 CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c
 CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
 CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
-CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c
+CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c xc_minios_privcmd.c
 
 GUEST_SRCS-y :=
 GUEST_SRCS-y += xg_private.c xc_suspend.c
tools/libxc/xc_minios.c +4 -239
index e703684..90e3363 100644
@@ -41,164 +41,10 @@
 
 #include "xc_private.h"
 
-void minios_interface_close_fd(int fd);
 void minios_evtchn_close_fd(int fd);
-void minios_gnttab_close_fd(int fd);
-
-extern void minios_interface_close_fd(int fd);
-extern void minios_evtchn_close_fd(int fd);
 
 extern struct wait_queue_head event_queue;
 
-static xc_osdep_handle minios_privcmd_open(xc_interface *xch)
-{
-    int fd = alloc_fd(FTYPE_XC);
-
-    if ( fd == -1)
-        return XC_OSDEP_OPEN_ERROR;
-
-    return (xc_osdep_handle)fd;
-}
-
-static int minios_privcmd_close(xc_interface *xch, xc_osdep_handle h)
-{
-    int fd = (int)h;
-    return close(fd);
-}
-
-void minios_interface_close_fd(int fd)
-{
-    files[fd].type = FTYPE_NONE;
-}
-
-static void *minios_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
-{
-    return xc_memalign(xch, PAGE_SIZE, npages * PAGE_SIZE);
-}
-
-static void minios_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages)
-{
-    free(ptr);
-}
-
-static int minios_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
-{
-    multicall_entry_t call;
-    int i, ret;
-
-    call.op = hypercall->op;
-    for (i = 0; i < ARRAY_SIZE(hypercall->arg); i++)
-	call.args[i] = hypercall->arg[i];
-
-    ret = HYPERVISOR_multicall(&call, 1);
-
-    if (ret < 0) {
-	errno = -ret;
-	return -1;
-    }
-    if ((long) call.result < 0) {
-        errno = - (long) call.result;
-        return -1;
-    }
-    return call.result;
-}
-
-static void *minios_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h,
-                                             uint32_t dom, int prot,
-                                             const xen_pfn_t *arr, int *err, unsigned int num)
-{
-    unsigned long pt_prot = 0;
-    if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
-    if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
-    return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);    
-}
-
-static void *minios_privcmd_map_foreign_batch(xc_interface *xch,  xc_osdep_handle h,
-                                              uint32_t dom, int prot,
-                                              xen_pfn_t *arr, int num)
-{
-    unsigned long pt_prot = 0;
-    int err[num];
-    int i;
-    unsigned long addr;
-
-    if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
-    if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
-
-    addr = (unsigned long) map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
-    for (i = 0; i < num; i++) {
-        if (err[i])
-            arr[i] |= 0xF0000000;
-    }
-    return (void *) addr;
-}
-
-static void *minios_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h,
-                                              uint32_t dom,
-                                              int size, int prot,
-                                              unsigned long mfn)
-{
-    unsigned long pt_prot = 0;
-
-    if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
-    if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
-
-    assert(!(size % getpagesize()));
-    return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom, NULL, pt_prot);
-}
-
-static void *minios_privcmd_map_foreign_ranges(xc_interface *xch, xc_osdep_handle h,
-                                               uint32_t dom,
-                                               size_t size, int prot, size_t chunksize,
-                                               privcmd_mmap_entry_t entries[], int nentries)
-{
-    unsigned long *mfns;
-    int i, j, n;
-    unsigned long pt_prot = 0;
-    void *ret;
-
-    if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
-    if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
-
-    mfns = malloc((size / XC_PAGE_SIZE) * sizeof(*mfns));
-
-    n = 0;
-    for (i = 0; i < nentries; i++)
-        for (j = 0; j < chunksize / XC_PAGE_SIZE; j++)
-            mfns[n++] = entries[i].mfn + j;
-
-    ret = map_frames_ex(mfns, n, 1, 0, 1, dom, NULL, pt_prot);
-    free(mfns);
-    return ret;
-}
-
-
-static struct xc_osdep_ops minios_privcmd_ops = {
-    .open = &minios_privcmd_open,
-    .close = &minios_privcmd_close,
-
-    .u.privcmd = {
-        .alloc_hypercall_buffer = &minios_privcmd_alloc_hypercall_buffer,
-        .free_hypercall_buffer = &minios_privcmd_free_hypercall_buffer,
-
-        .hypercall = &minios_privcmd_hypercall,
-
-        .map_foreign_batch = &minios_privcmd_map_foreign_batch,
-        .map_foreign_bulk = &minios_privcmd_map_foreign_bulk,
-        .map_foreign_range = &minios_privcmd_map_foreign_range,
-        .map_foreign_ranges = &minios_privcmd_map_foreign_ranges,
-    },
-};
-
-
 /* XXX Note: This is not threadsafe */
 static struct evtchn_port_info* port_alloc(int fd) {
     struct evtchn_port_info *port_info;
@@ -409,7 +255,7 @@ static int minios_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t
     return 0;
 }
 
-static struct xc_osdep_ops minios_evtchn_ops = {
+struct xc_osdep_ops xc_evtchn_ops = {
     .open = &minios_evtchn_open,
     .close = &minios_evtchn_close,
 
@@ -437,97 +283,16 @@ void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
     return memalign(alignment, size);
 }
 
-static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
-{
-    int fd = alloc_fd(FTYPE_GNTMAP);
-    if ( fd == -1 )
-        return XC_OSDEP_OPEN_ERROR;
-    gntmap_init(&files[fd].gntmap);
-    return (xc_osdep_handle)fd;
-}
-
-static int minios_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h)
-{
-    int fd = (int)h;
-    return close(fd);
-}
-
-void minios_gnttab_close_fd(int fd)
-{
-    gntmap_fini(&files[fd].gntmap);
-    files[fd].type = FTYPE_NONE;
-}
-
-static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
-                                     uint32_t count, int flags, int prot,
-                                     uint32_t *domids, uint32_t *refs,
-                                     uint32_t notify_offset,
-                                     evtchn_port_t notify_port)
-{
-    int fd = (int)h;
-    int stride = 1;
-    if (flags & XC_GRANT_MAP_SINGLE_DOMAIN)
-        stride = 0;
-    if (notify_offset != -1 || notify_port != -1) {
-        errno = ENOSYS;
-        return NULL;
-    }
-    return gntmap_map_grant_refs(&files[fd].gntmap,
-                                 count, domids, stride,
-                                 refs, prot & PROT_WRITE);
-}
-
-static int minios_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
-                                void *start_address,
-                                uint32_t count)
-{
-    int fd = (int)h;
-    int ret;
-    ret = gntmap_munmap(&files[fd].gntmap,
-                        (unsigned long) start_address,
-                        count);
-    if (ret < 0) {
-        errno = -ret;
-        return -1;
-    }
-    return ret;
-}
-
-static int minios_gnttab_set_max_grants(xc_gnttab *xcg, xc_osdep_handle h,
-                             uint32_t count)
-{
-    int fd = (int)h;
-    int ret;
-    ret = gntmap_set_max_grants(&files[fd].gntmap,
-                                count);
-    if (ret < 0) {
-        errno = -ret;
-        return -1;
-    }
-    return ret;
-}
-
-static struct xc_osdep_ops minios_gnttab_ops = {
-    .open = &minios_gnttab_open,
-    .close = &minios_gnttab_close,
-
-    .u.gnttab = {
-        .grant_map = &minios_gnttab_grant_map,
-        .munmap = &minios_gnttab_munmap,
-        .set_max_grants = &minios_gnttab_set_max_grants,
-    },
-};
-
 static struct xc_osdep_ops *minios_osdep_init(xc_interface *xch, enum xc_osdep_type type)
 {
     switch ( type )
     {
     case XC_OSDEP_PRIVCMD:
-        return &minios_privcmd_ops;
+        return &xc_privcmd_ops;
     case XC_OSDEP_EVTCHN:
-        return &minios_evtchn_ops;
+        return &xc_evtchn_ops;
     case XC_OSDEP_GNTTAB:
-        return &minios_gnttab_ops;
+        return &xc_gnttab_ops;
     default:
         return NULL;
     }
tools/libxc/xc_minios_privcmd.c new file +34 -0
new file mode 100644
index 0000000..7766b86
@@ -0,0 +1,291 @@
+/******************************************************************************
+ *
+ * Copyright 2007-2008 Samuel Thibault <[email protected]>.
+ * All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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;
+ * version 2.1 of the License.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#undef NDEBUG
+#include "xen-external/bsd-sys-queue.h"
+#include <mini-os/types.h>
+#include <mini-os/os.h>
+#include <mini-os/mm.h>
+#include <mini-os/lib.h>
+#include <mini-os/gntmap.h>
+#include <mini-os/events.h>
+#include <mini-os/wait.h>
+#include <sys/mman.h>
+
+#include <xen/memory.h>
+#include <unistd.h>

tools/libxc/xc_minios_privcmd.c line 44

Quoted 10 lines
tools/libxc/xc_minios_privcmd.c new file +10 -0
+#include <fcntl.h>
+#include <stdio.h>
+#include <assert.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <malloc.h>
+
+#include "xc_private.h"
+
+#ifdef __RUMPRUN___

There is one formatting error here, I will fix it in next round.

Acked-by on v1 2/5
#8 lore raw

Re: [PATCH 2/5] libxc: Split off xc_minios_privcmd.c

In reply to Wei Liu
Quoted 17 lines · Wei Liu, le Thu 26 Feb 2015 11:56:18 +0000, a écrit :

We are going to want to use some but not all of the machinery previously in xc_minios.c. Split the privcmd and gnttab code into its own file. This part is pure code motion.

But we also have to:

- Alter the Makefile to build and link xc_minios_privcmd.c too.

- Rename some of the minios_*_ops symbols to have proper namespaceing and make them have external linkage, so that the init code (which remains in xc_minios.c) can reference them.

- Call these *_ops symbols xc_*_ops so that we can mix and match in the future. This does not impede the existing mechanisms for run-time overriding. (But leave a comment next to the new declarations in xc_private.h saying not to use these.)

Quoted 8 lines

- Change map_frames_ex to minios_map_frames_ex if compiling on rump kernel.

[ wei: wrap long lines, use __RUMPRUN__ and define macro for map_frames_ex ]

Quoted 620 lines
---
 tools/libxc/Makefile            |   2 +-
 tools/libxc/xc_minios.c         | 243 +--------------------------------
 tools/libxc/xc_minios_privcmd.c | 291 ++++++++++++++++++++++++++++++++++++++++
 tools/libxc/xc_private.h        |   3 +
 4 files changed, 299 insertions(+), 240 deletions(-)
 create mode 100644 tools/libxc/xc_minios_privcmd.c
tools/libxc/Makefile +1 -1
index 6fa88c7..4ace2b6 100644
@@ -47,7 +47,7 @@ CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c
 CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c
 CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
 CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
-CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c
+CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c xc_minios_privcmd.c
 
 GUEST_SRCS-y :=
 GUEST_SRCS-y += xg_private.c xc_suspend.c
tools/libxc/xc_minios.c +4 -239
index e703684..90e3363 100644
@@ -41,164 +41,10 @@
 
 #include "xc_private.h"
 
-void minios_interface_close_fd(int fd);
 void minios_evtchn_close_fd(int fd);
-void minios_gnttab_close_fd(int fd);
-
-extern void minios_interface_close_fd(int fd);
-extern void minios_evtchn_close_fd(int fd);
 
 extern struct wait_queue_head event_queue;
 
-static xc_osdep_handle minios_privcmd_open(xc_interface *xch)
-{
-    int fd = alloc_fd(FTYPE_XC);
-
-    if ( fd == -1)
-        return XC_OSDEP_OPEN_ERROR;
-
-    return (xc_osdep_handle)fd;
-}
-
-static int minios_privcmd_close(xc_interface *xch, xc_osdep_handle h)
-{
-    int fd = (int)h;
-    return close(fd);
-}
-
-void minios_interface_close_fd(int fd)
-{
-    files[fd].type = FTYPE_NONE;
-}
-
-static void *minios_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
-{
-    return xc_memalign(xch, PAGE_SIZE, npages * PAGE_SIZE);
-}
-
-static void minios_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages)
-{
-    free(ptr);
-}
-
-static int minios_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
-{
-    multicall_entry_t call;
-    int i, ret;
-
-    call.op = hypercall->op;
-    for (i = 0; i < ARRAY_SIZE(hypercall->arg); i++)
-	call.args[i] = hypercall->arg[i];
-
-    ret = HYPERVISOR_multicall(&call, 1);
-
-    if (ret < 0) {
-	errno = -ret;
-	return -1;
-    }
-    if ((long) call.result < 0) {
-        errno = - (long) call.result;
-        return -1;
-    }
-    return call.result;
-}
-
-static void *minios_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h,
-                                             uint32_t dom, int prot,
-                                             const xen_pfn_t *arr, int *err, unsigned int num)
-{
-    unsigned long pt_prot = 0;
-    if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
-    if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
-    return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);    
-}
-
-static void *minios_privcmd_map_foreign_batch(xc_interface *xch,  xc_osdep_handle h,
-                                              uint32_t dom, int prot,
-                                              xen_pfn_t *arr, int num)
-{
-    unsigned long pt_prot = 0;
-    int err[num];
-    int i;
-    unsigned long addr;
-
-    if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
-    if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
-
-    addr = (unsigned long) map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
-    for (i = 0; i < num; i++) {
-        if (err[i])
-            arr[i] |= 0xF0000000;
-    }
-    return (void *) addr;
-}
-
-static void *minios_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h,
-                                              uint32_t dom,
-                                              int size, int prot,
-                                              unsigned long mfn)
-{
-    unsigned long pt_prot = 0;
-
-    if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
-    if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
-
-    assert(!(size % getpagesize()));
-    return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom, NULL, pt_prot);
-}
-
-static void *minios_privcmd_map_foreign_ranges(xc_interface *xch, xc_osdep_handle h,
-                                               uint32_t dom,
-                                               size_t size, int prot, size_t chunksize,
-                                               privcmd_mmap_entry_t entries[], int nentries)
-{
-    unsigned long *mfns;
-    int i, j, n;
-    unsigned long pt_prot = 0;
-    void *ret;
-
-    if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
-    if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
-
-    mfns = malloc((size / XC_PAGE_SIZE) * sizeof(*mfns));
-
-    n = 0;
-    for (i = 0; i < nentries; i++)
-        for (j = 0; j < chunksize / XC_PAGE_SIZE; j++)
-            mfns[n++] = entries[i].mfn + j;
-
-    ret = map_frames_ex(mfns, n, 1, 0, 1, dom, NULL, pt_prot);
-    free(mfns);
-    return ret;
-}
-
-
-static struct xc_osdep_ops minios_privcmd_ops = {
-    .open = &minios_privcmd_open,
-    .close = &minios_privcmd_close,
-
-    .u.privcmd = {
-        .alloc_hypercall_buffer = &minios_privcmd_alloc_hypercall_buffer,
-        .free_hypercall_buffer = &minios_privcmd_free_hypercall_buffer,
-
-        .hypercall = &minios_privcmd_hypercall,
-
-        .map_foreign_batch = &minios_privcmd_map_foreign_batch,
-        .map_foreign_bulk = &minios_privcmd_map_foreign_bulk,
-        .map_foreign_range = &minios_privcmd_map_foreign_range,
-        .map_foreign_ranges = &minios_privcmd_map_foreign_ranges,
-    },
-};
-
-
 /* XXX Note: This is not threadsafe */
 static struct evtchn_port_info* port_alloc(int fd) {
     struct evtchn_port_info *port_info;
@@ -409,7 +255,7 @@ static int minios_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t
     return 0;
 }
 
-static struct xc_osdep_ops minios_evtchn_ops = {
+struct xc_osdep_ops xc_evtchn_ops = {
     .open = &minios_evtchn_open,
     .close = &minios_evtchn_close,
 
@@ -437,97 +283,16 @@ void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
     return memalign(alignment, size);
 }
 
-static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
-{
-    int fd = alloc_fd(FTYPE_GNTMAP);
-    if ( fd == -1 )
-        return XC_OSDEP_OPEN_ERROR;
-    gntmap_init(&files[fd].gntmap);
-    return (xc_osdep_handle)fd;
-}
-
-static int minios_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h)
-{
-    int fd = (int)h;
-    return close(fd);
-}
-
-void minios_gnttab_close_fd(int fd)
-{
-    gntmap_fini(&files[fd].gntmap);
-    files[fd].type = FTYPE_NONE;
-}
-
-static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
-                                     uint32_t count, int flags, int prot,
-                                     uint32_t *domids, uint32_t *refs,
-                                     uint32_t notify_offset,
-                                     evtchn_port_t notify_port)
-{
-    int fd = (int)h;
-    int stride = 1;
-    if (flags & XC_GRANT_MAP_SINGLE_DOMAIN)
-        stride = 0;
-    if (notify_offset != -1 || notify_port != -1) {
-        errno = ENOSYS;
-        return NULL;
-    }
-    return gntmap_map_grant_refs(&files[fd].gntmap,
-                                 count, domids, stride,
-                                 refs, prot & PROT_WRITE);
-}
-
-static int minios_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
-                                void *start_address,
-                                uint32_t count)
-{
-    int fd = (int)h;
-    int ret;
-    ret = gntmap_munmap(&files[fd].gntmap,
-                        (unsigned long) start_address,
-                        count);
-    if (ret < 0) {
-        errno = -ret;
-        return -1;
-    }
-    return ret;
-}
-
-static int minios_gnttab_set_max_grants(xc_gnttab *xcg, xc_osdep_handle h,
-                             uint32_t count)
-{
-    int fd = (int)h;
-    int ret;
-    ret = gntmap_set_max_grants(&files[fd].gntmap,
-                                count);
-    if (ret < 0) {
-        errno = -ret;
-        return -1;
-    }
-    return ret;
-}
-
-static struct xc_osdep_ops minios_gnttab_ops = {
-    .open = &minios_gnttab_open,
-    .close = &minios_gnttab_close,
-
-    .u.gnttab = {
-        .grant_map = &minios_gnttab_grant_map,
-        .munmap = &minios_gnttab_munmap,
-        .set_max_grants = &minios_gnttab_set_max_grants,
-    },
-};
-
 static struct xc_osdep_ops *minios_osdep_init(xc_interface *xch, enum xc_osdep_type type)
 {
     switch ( type )
     {
     case XC_OSDEP_PRIVCMD:
-        return &minios_privcmd_ops;
+        return &xc_privcmd_ops;
     case XC_OSDEP_EVTCHN:
-        return &minios_evtchn_ops;
+        return &xc_evtchn_ops;
     case XC_OSDEP_GNTTAB:
-        return &minios_gnttab_ops;
+        return &xc_gnttab_ops;
     default:
         return NULL;
     }
tools/libxc/xc_minios_privcmd.c new file +291 -0
new file mode 100644
index 0000000..7766b86
@@ -0,0 +1,291 @@
+/******************************************************************************
+ *
+ * Copyright 2007-2008, 2015 Samuel Thibault <[email protected]>.
+ * All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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;
+ * version 2.1 of the License.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#undef NDEBUG
+#include "xen-external/bsd-sys-queue.h"
+#include <mini-os/types.h>
+#include <mini-os/os.h>
+#include <mini-os/mm.h>
+#include <mini-os/lib.h>
+#include <mini-os/gntmap.h>
+#include <mini-os/events.h>
+#include <mini-os/wait.h>
+#include <sys/mman.h>
+
+#include <xen/memory.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <assert.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <malloc.h>
+
+#include "xc_private.h"
+
+#ifdef __RUMPRUN___
+# define map_frames_ex minios_map_frames_ex
+#endif /* __RUMPRUN__ */
+
+void minios_interface_close_fd(int fd);
+void minios_gnttab_close_fd(int fd);
+
+static xc_osdep_handle minios_privcmd_open(xc_interface *xch)
+{
+    int fd = alloc_fd(FTYPE_XC);
+
+    if ( fd == -1)
+        return XC_OSDEP_OPEN_ERROR;
+
+    return (xc_osdep_handle)fd;
+}
+
+static int minios_privcmd_close(xc_interface *xch, xc_osdep_handle h)
+{
+    int fd = (int)h;
+    return close(fd);
+}
+
+void minios_interface_close_fd(int fd)
+{
+    files[fd].type = FTYPE_NONE;
+}
+
+static void *minios_privcmd_alloc_hypercall_buffer(xc_interface *xch,
+						   xc_osdep_handle h,
+						   int npages)
+{
+    return xc_memalign(xch, PAGE_SIZE, npages * PAGE_SIZE);
+}
+
+static void minios_privcmd_free_hypercall_buffer(xc_interface *xch,
+						 xc_osdep_handle h,
+						 void *ptr, int npages)
+{
+    free(ptr);
+}
+
+static int minios_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h,
+				    privcmd_hypercall_t *hypercall)
+{
+    multicall_entry_t call;
+    int i, ret;
+
+    call.op = hypercall->op;
+    for (i = 0; i < ARRAY_SIZE(hypercall->arg); i++)
+	call.args[i] = hypercall->arg[i];
+
+    ret = HYPERVISOR_multicall(&call, 1);
+
+    if (ret < 0) {
+	errno = -ret;
+	return -1;
+    }
+    if ((long) call.result < 0) {
+        errno = - (long) call.result;
+        return -1;
+    }
+    return call.result;
+}
+
+static void *minios_privcmd_map_foreign_bulk(xc_interface *xch,
+					     xc_osdep_handle h,
+                                             uint32_t dom, int prot,
+                                             const xen_pfn_t *arr,
+					     int *err, unsigned int num)
+{
+    unsigned long pt_prot = 0;
+    if (prot & PROT_READ)
+	pt_prot = L1_PROT_RO;
+    if (prot & PROT_WRITE)
+	pt_prot = L1_PROT;
+    return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);    
+}
+
+static void *minios_privcmd_map_foreign_batch(xc_interface *xch,
+					      xc_osdep_handle h,
+                                              uint32_t dom, int prot,
+                                              xen_pfn_t *arr, int num)
+{
+    unsigned long pt_prot = 0;
+    int err[num];
+    int i;
+    unsigned long addr;
+
+    if (prot & PROT_READ)
+	pt_prot = L1_PROT_RO;
+    if (prot & PROT_WRITE)
+	pt_prot = L1_PROT;
+
+    addr = (unsigned long) map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
+    for (i = 0; i < num; i++) {
+        if (err[i])
+            arr[i] |= 0xF0000000;
+    }
+    return (void *) addr;
+}
+
+static void *minios_privcmd_map_foreign_range(xc_interface *xch,
+					      xc_osdep_handle h,
+                                              uint32_t dom,
+                                              int size, int prot,
+                                              unsigned long mfn)
+{
+    unsigned long pt_prot = 0;
+
+    if (prot & PROT_READ)
+	pt_prot = L1_PROT_RO;
+    if (prot & PROT_WRITE)
+	pt_prot = L1_PROT;
+
+    assert(!(size % getpagesize()));
+    return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom,
+			 NULL, pt_prot);
+}
+
+static void *minios_privcmd_map_foreign_ranges(xc_interface *xch,
+					       xc_osdep_handle h,
+                                               uint32_t dom,
+                                               size_t size, int prot,
+					       size_t chunksize,
+                                               privcmd_mmap_entry_t entries[],
+					       int nentries)
+{
+    unsigned long *mfns;
+    int i, j, n;
+    unsigned long pt_prot = 0;
+    void *ret;
+
+    if (prot & PROT_READ)
+	pt_prot = L1_PROT_RO;
+    if (prot & PROT_WRITE)
+	pt_prot = L1_PROT;
+
+    mfns = malloc((size / XC_PAGE_SIZE) * sizeof(*mfns));
+
+    n = 0;
+    for (i = 0; i < nentries; i++)
+        for (j = 0; j < chunksize / XC_PAGE_SIZE; j++)
+            mfns[n++] = entries[i].mfn + j;
+
+    ret = map_frames_ex(mfns, n, 1, 0, 1, dom, NULL, pt_prot);
+    free(mfns);
+    return ret;
+}
+
+struct xc_osdep_ops xc_privcmd_ops = {
+    .open = &minios_privcmd_open,
+    .close = &minios_privcmd_close,
+
+    .u.privcmd = {
+        .alloc_hypercall_buffer = &minios_privcmd_alloc_hypercall_buffer,
+        .free_hypercall_buffer = &minios_privcmd_free_hypercall_buffer,
+
+        .hypercall = &minios_privcmd_hypercall,
+
+        .map_foreign_batch = &minios_privcmd_map_foreign_batch,
+        .map_foreign_bulk = &minios_privcmd_map_foreign_bulk,
+        .map_foreign_range = &minios_privcmd_map_foreign_range,
+        .map_foreign_ranges = &minios_privcmd_map_foreign_ranges,
+    },
+};
+
+static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
+{
+    int fd = alloc_fd(FTYPE_GNTMAP);
+    if ( fd == -1 )
+        return XC_OSDEP_OPEN_ERROR;
+    gntmap_init(&files[fd].gntmap);
+    return (xc_osdep_handle)fd;
+}
+
+static int minios_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h)
+{
+    int fd = (int)h;
+    return close(fd);
+}
+
+void minios_gnttab_close_fd(int fd)
+{
+    gntmap_fini(&files[fd].gntmap);
+    files[fd].type = FTYPE_NONE;
+}
+
+static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
+                                     uint32_t count, int flags, int prot,
+                                     uint32_t *domids, uint32_t *refs,
+                                     uint32_t notify_offset,
+                                     evtchn_port_t notify_port)
+{
+    int fd = (int)h;
+    int stride = 1;
+    if (flags & XC_GRANT_MAP_SINGLE_DOMAIN)
+        stride = 0;
+    if (notify_offset != -1 || notify_port != -1) {
+        errno = ENOSYS;
+        return NULL;
+    }
+    return gntmap_map_grant_refs(&files[fd].gntmap,
+                                 count, domids, stride,
+                                 refs, prot & PROT_WRITE);
+}
+
+static int minios_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
+                                void *start_address,
+                                uint32_t count)
+{
+    int fd = (int)h;
+    int ret;
+    ret = gntmap_munmap(&files[fd].gntmap,
+                        (unsigned long) start_address,
+                        count);
+    if (ret < 0) {
+        errno = -ret;
+        return -1;
+    }
+    return ret;
+}
+
+static int minios_gnttab_set_max_grants(xc_gnttab *xcg, xc_osdep_handle h,
+                             uint32_t count)
+{
+    int fd = (int)h;
+    int ret;
+    ret = gntmap_set_max_grants(&files[fd].gntmap,
+                                count);
+    if (ret < 0) {
+        errno = -ret;
+        return -1;
+    }
+    return ret;
+}
+
+struct xc_osdep_ops xc_gnttab_ops = {
+    .open = &minios_gnttab_open,
+    .close = &minios_gnttab_close,
+
+    .u.gnttab = {
+        .grant_map = &minios_gnttab_grant_map,
+        .munmap = &minios_gnttab_munmap,
+        .set_max_grants = &minios_gnttab_set_max_grants,
+    },
+};
+
tools/libxc/xc_private.h +3 -0
index 45b8644..152465f 100644
@@ -111,6 +111,9 @@ struct xc_interface_core {
     xc_osdep_handle  ops_handle; /* opaque data for xc_osdep_ops */
 };
 
+/* Do not use these directly; go via the handle you already have. */
+extern struct xc_osdep_ops xc_privcmd_ops, xc_evtchn_ops, xc_gnttab_ops;
+
 void xc_report_error(xc_interface *xch, int code, const char *fmt, ...)
     __attribute__((format(printf,3,4)));
 void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Signature · 6 lines
Samuel
<Y> C'ETAIT PAS UN BUG !
<y> :ppp
<y> c ce qu'on dit ;)
<Y> (j'ai appuye sur ON, ca peut arriver, non ?)
 -+- #hp debuggue IRCprime -+-
#9 lore raw

Re: [PATCH 2/5] libxc: Split off xc_minios_privcmd.c

In reply to Wei Liu
Quoted 5 lines · Wei Liu

From: Ian Jackson <[email protected]>

We are going to want to use some but not all of the machinery previously in xc_minios.c. Split the privcmd and gnttab code into its own file.

Does it make sense to put gnttab code in a file called privcmd.c?

I don't think there is much of a link between the two, is there?

I'm not sure which half of this rump libxc is going to want but perhaps either _common or _standalone would be a better suffix, depending which way it goes?

Quoted 634 lines

This part is pure code motion.

But we also have to:

- Alter the Makefile to build and link xc_minios_privcmd.c too.

- Rename some of the minios_*_ops symbols to have proper namespaceing and make them have external linkage, so that the init code (which remains in xc_minios.c) can reference them.

- Call these *_ops symbols xc_*_ops so that we can mix and match in the future. This does not impede the existing mechanisms for run-time overriding. (But leave a comment next to the new declarations in xc_private.h saying not to use these.)

- Change map_frames_ex to minios_map_frames_ex if compiling on rump kernel.

[ wei: wrap long lines, use __RUMPRUN__ and define macro for map_frames_ex ]

---
 tools/libxc/Makefile            |   2 +-
 tools/libxc/xc_minios.c         | 243 +--------------------------------
 tools/libxc/xc_minios_privcmd.c | 291 ++++++++++++++++++++++++++++++++++++++++
 tools/libxc/xc_private.h        |   3 +
 4 files changed, 299 insertions(+), 240 deletions(-)
 create mode 100644 tools/libxc/xc_minios_privcmd.c
tools/libxc/Makefile +1 -1
index 6fa88c7..4ace2b6 100644
@@ -47,7 +47,7 @@ CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c
 CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c
 CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
 CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
-CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c
+CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c xc_minios_privcmd.c
 
 GUEST_SRCS-y :=
 GUEST_SRCS-y += xg_private.c xc_suspend.c
tools/libxc/xc_minios.c +4 -239
index e703684..90e3363 100644
@@ -41,164 +41,10 @@
 
 #include "xc_private.h"
 
-void minios_interface_close_fd(int fd);
 void minios_evtchn_close_fd(int fd);
-void minios_gnttab_close_fd(int fd);
-
-extern void minios_interface_close_fd(int fd);
-extern void minios_evtchn_close_fd(int fd);
 
 extern struct wait_queue_head event_queue;
 
-static xc_osdep_handle minios_privcmd_open(xc_interface *xch)
-{
-    int fd = alloc_fd(FTYPE_XC);
-
-    if ( fd == -1)
-        return XC_OSDEP_OPEN_ERROR;
-
-    return (xc_osdep_handle)fd;
-}
-
-static int minios_privcmd_close(xc_interface *xch, xc_osdep_handle h)
-{
-    int fd = (int)h;
-    return close(fd);
-}
-
-void minios_interface_close_fd(int fd)
-{
-    files[fd].type = FTYPE_NONE;
-}
-
-static void *minios_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
-{
-    return xc_memalign(xch, PAGE_SIZE, npages * PAGE_SIZE);
-}
-
-static void minios_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages)
-{
-    free(ptr);
-}
-
-static int minios_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
-{
-    multicall_entry_t call;
-    int i, ret;
-
-    call.op = hypercall->op;
-    for (i = 0; i < ARRAY_SIZE(hypercall->arg); i++)
-	call.args[i] = hypercall->arg[i];
-
-    ret = HYPERVISOR_multicall(&call, 1);
-
-    if (ret < 0) {
-	errno = -ret;
-	return -1;
-    }
-    if ((long) call.result < 0) {
-        errno = - (long) call.result;
-        return -1;
-    }
-    return call.result;
-}
-
-static void *minios_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h,
-                                             uint32_t dom, int prot,
-                                             const xen_pfn_t *arr, int *err, unsigned int num)
-{
-    unsigned long pt_prot = 0;
-    if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
-    if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
-    return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);    
-}
-
-static void *minios_privcmd_map_foreign_batch(xc_interface *xch,  xc_osdep_handle h,
-                                              uint32_t dom, int prot,
-                                              xen_pfn_t *arr, int num)
-{
-    unsigned long pt_prot = 0;
-    int err[num];
-    int i;
-    unsigned long addr;
-
-    if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
-    if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
-
-    addr = (unsigned long) map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
-    for (i = 0; i < num; i++) {
-        if (err[i])
-            arr[i] |= 0xF0000000;
-    }
-    return (void *) addr;
-}
-
-static void *minios_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h,
-                                              uint32_t dom,
-                                              int size, int prot,
-                                              unsigned long mfn)
-{
-    unsigned long pt_prot = 0;
-
-    if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
-    if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
-
-    assert(!(size % getpagesize()));
-    return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom, NULL, pt_prot);
-}
-
-static void *minios_privcmd_map_foreign_ranges(xc_interface *xch, xc_osdep_handle h,
-                                               uint32_t dom,
-                                               size_t size, int prot, size_t chunksize,
-                                               privcmd_mmap_entry_t entries[], int nentries)
-{
-    unsigned long *mfns;
-    int i, j, n;
-    unsigned long pt_prot = 0;
-    void *ret;
-
-    if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
-    if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
-
-    mfns = malloc((size / XC_PAGE_SIZE) * sizeof(*mfns));
-
-    n = 0;
-    for (i = 0; i < nentries; i++)
-        for (j = 0; j < chunksize / XC_PAGE_SIZE; j++)
-            mfns[n++] = entries[i].mfn + j;
-
-    ret = map_frames_ex(mfns, n, 1, 0, 1, dom, NULL, pt_prot);
-    free(mfns);
-    return ret;
-}
-
-
-static struct xc_osdep_ops minios_privcmd_ops = {
-    .open = &minios_privcmd_open,
-    .close = &minios_privcmd_close,
-
-    .u.privcmd = {
-        .alloc_hypercall_buffer = &minios_privcmd_alloc_hypercall_buffer,
-        .free_hypercall_buffer = &minios_privcmd_free_hypercall_buffer,
-
-        .hypercall = &minios_privcmd_hypercall,
-
-        .map_foreign_batch = &minios_privcmd_map_foreign_batch,
-        .map_foreign_bulk = &minios_privcmd_map_foreign_bulk,
-        .map_foreign_range = &minios_privcmd_map_foreign_range,
-        .map_foreign_ranges = &minios_privcmd_map_foreign_ranges,
-    },
-};
-
-
 /* XXX Note: This is not threadsafe */
 static struct evtchn_port_info* port_alloc(int fd) {
     struct evtchn_port_info *port_info;
@@ -409,7 +255,7 @@ static int minios_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t
     return 0;
 }
 
-static struct xc_osdep_ops minios_evtchn_ops = {
+struct xc_osdep_ops xc_evtchn_ops = {
     .open = &minios_evtchn_open,
     .close = &minios_evtchn_close,
 
@@ -437,97 +283,16 @@ void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
     return memalign(alignment, size);
 }
 
-static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
-{
-    int fd = alloc_fd(FTYPE_GNTMAP);
-    if ( fd == -1 )
-        return XC_OSDEP_OPEN_ERROR;
-    gntmap_init(&files[fd].gntmap);
-    return (xc_osdep_handle)fd;
-}
-
-static int minios_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h)
-{
-    int fd = (int)h;
-    return close(fd);
-}
-
-void minios_gnttab_close_fd(int fd)
-{
-    gntmap_fini(&files[fd].gntmap);
-    files[fd].type = FTYPE_NONE;
-}
-
-static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
-                                     uint32_t count, int flags, int prot,
-                                     uint32_t *domids, uint32_t *refs,
-                                     uint32_t notify_offset,
-                                     evtchn_port_t notify_port)
-{
-    int fd = (int)h;
-    int stride = 1;
-    if (flags & XC_GRANT_MAP_SINGLE_DOMAIN)
-        stride = 0;
-    if (notify_offset != -1 || notify_port != -1) {
-        errno = ENOSYS;
-        return NULL;
-    }
-    return gntmap_map_grant_refs(&files[fd].gntmap,
-                                 count, domids, stride,
-                                 refs, prot & PROT_WRITE);
-}
-
-static int minios_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
-                                void *start_address,
-                                uint32_t count)
-{
-    int fd = (int)h;
-    int ret;
-    ret = gntmap_munmap(&files[fd].gntmap,
-                        (unsigned long) start_address,
-                        count);
-    if (ret < 0) {
-        errno = -ret;
-        return -1;
-    }
-    return ret;
-}
-
-static int minios_gnttab_set_max_grants(xc_gnttab *xcg, xc_osdep_handle h,
-                             uint32_t count)
-{
-    int fd = (int)h;
-    int ret;
-    ret = gntmap_set_max_grants(&files[fd].gntmap,
-                                count);
-    if (ret < 0) {
-        errno = -ret;
-        return -1;
-    }
-    return ret;
-}
-
-static struct xc_osdep_ops minios_gnttab_ops = {
-    .open = &minios_gnttab_open,
-    .close = &minios_gnttab_close,
-
-    .u.gnttab = {
-        .grant_map = &minios_gnttab_grant_map,
-        .munmap = &minios_gnttab_munmap,
-        .set_max_grants = &minios_gnttab_set_max_grants,
-    },
-};
-
 static struct xc_osdep_ops *minios_osdep_init(xc_interface *xch, enum xc_osdep_type type)
 {
     switch ( type )
     {
     case XC_OSDEP_PRIVCMD:
-        return &minios_privcmd_ops;
+        return &xc_privcmd_ops;
     case XC_OSDEP_EVTCHN:
-        return &minios_evtchn_ops;
+        return &xc_evtchn_ops;
     case XC_OSDEP_GNTTAB:
-        return &minios_gnttab_ops;
+        return &xc_gnttab_ops;
     default:
         return NULL;
     }
tools/libxc/xc_minios_privcmd.c new file +291 -0
new file mode 100644
index 0000000..7766b86
@@ -0,0 +1,291 @@
+/******************************************************************************
+ *
+ * Copyright 2007-2008 Samuel Thibault <[email protected]>.
+ * All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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;
+ * version 2.1 of the License.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#undef NDEBUG
+#include "xen-external/bsd-sys-queue.h"
+#include <mini-os/types.h>
+#include <mini-os/os.h>
+#include <mini-os/mm.h>
+#include <mini-os/lib.h>
+#include <mini-os/gntmap.h>
+#include <mini-os/events.h>
+#include <mini-os/wait.h>
+#include <sys/mman.h>
+
+#include <xen/memory.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <assert.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <malloc.h>
+
+#include "xc_private.h"
+
+#ifdef __RUMPRUN___
+# define map_frames_ex minios_map_frames_ex
+#endif /* __RUMPRUN__ */
+
+void minios_interface_close_fd(int fd);
+void minios_gnttab_close_fd(int fd);
+
+static xc_osdep_handle minios_privcmd_open(xc_interface *xch)
+{
+    int fd = alloc_fd(FTYPE_XC);
+
+    if ( fd == -1)
+        return XC_OSDEP_OPEN_ERROR;
+
+    return (xc_osdep_handle)fd;
+}
+
+static int minios_privcmd_close(xc_interface *xch, xc_osdep_handle h)
+{
+    int fd = (int)h;
+    return close(fd);
+}
+
+void minios_interface_close_fd(int fd)
+{
+    files[fd].type = FTYPE_NONE;
+}
+
+static void *minios_privcmd_alloc_hypercall_buffer(xc_interface *xch,
+						   xc_osdep_handle h,
+						   int npages)
+{
+    return xc_memalign(xch, PAGE_SIZE, npages * PAGE_SIZE);
+}
+
+static void minios_privcmd_free_hypercall_buffer(xc_interface *xch,
+						 xc_osdep_handle h,
+						 void *ptr, int npages)
+{
+    free(ptr);
+}
+
+static int minios_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h,
+				    privcmd_hypercall_t *hypercall)
+{
+    multicall_entry_t call;
+    int i, ret;
+
+    call.op = hypercall->op;
+    for (i = 0; i < ARRAY_SIZE(hypercall->arg); i++)
+	call.args[i] = hypercall->arg[i];
+
+    ret = HYPERVISOR_multicall(&call, 1);
+
+    if (ret < 0) {
+	errno = -ret;
+	return -1;
+    }
+    if ((long) call.result < 0) {
+        errno = - (long) call.result;
+        return -1;
+    }
+    return call.result;
+}
+
+static void *minios_privcmd_map_foreign_bulk(xc_interface *xch,
+					     xc_osdep_handle h,
+                                             uint32_t dom, int prot,
+                                             const xen_pfn_t *arr,
+					     int *err, unsigned int num)
+{
+    unsigned long pt_prot = 0;
+    if (prot & PROT_READ)
+	pt_prot = L1_PROT_RO;
+    if (prot & PROT_WRITE)
+	pt_prot = L1_PROT;
+    return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);    
+}
+
+static void *minios_privcmd_map_foreign_batch(xc_interface *xch,
+					      xc_osdep_handle h,
+                                              uint32_t dom, int prot,
+                                              xen_pfn_t *arr, int num)
+{
+    unsigned long pt_prot = 0;
+    int err[num];
+    int i;
+    unsigned long addr;
+
+    if (prot & PROT_READ)
+	pt_prot = L1_PROT_RO;
+    if (prot & PROT_WRITE)
+	pt_prot = L1_PROT;
+
+    addr = (unsigned long) map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
+    for (i = 0; i < num; i++) {
+        if (err[i])
+            arr[i] |= 0xF0000000;
+    }
+    return (void *) addr;
+}
+
+static void *minios_privcmd_map_foreign_range(xc_interface *xch,
+					      xc_osdep_handle h,
+                                              uint32_t dom,
+                                              int size, int prot,
+                                              unsigned long mfn)
+{
+    unsigned long pt_prot = 0;
+
+    if (prot & PROT_READ)
+	pt_prot = L1_PROT_RO;
+    if (prot & PROT_WRITE)
+	pt_prot = L1_PROT;
+
+    assert(!(size % getpagesize()));
+    return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom,
+			 NULL, pt_prot);
+}
+
+static void *minios_privcmd_map_foreign_ranges(xc_interface *xch,
+					       xc_osdep_handle h,
+                                               uint32_t dom,
+                                               size_t size, int prot,
+					       size_t chunksize,
+                                               privcmd_mmap_entry_t entries[],
+					       int nentries)
+{
+    unsigned long *mfns;
+    int i, j, n;
+    unsigned long pt_prot = 0;
+    void *ret;
+
+    if (prot & PROT_READ)
+	pt_prot = L1_PROT_RO;
+    if (prot & PROT_WRITE)
+	pt_prot = L1_PROT;
+
+    mfns = malloc((size / XC_PAGE_SIZE) * sizeof(*mfns));
+
+    n = 0;
+    for (i = 0; i < nentries; i++)
+        for (j = 0; j < chunksize / XC_PAGE_SIZE; j++)
+            mfns[n++] = entries[i].mfn + j;
+
+    ret = map_frames_ex(mfns, n, 1, 0, 1, dom, NULL, pt_prot);
+    free(mfns);
+    return ret;
+}
+
+struct xc_osdep_ops xc_privcmd_ops = {
+    .open = &minios_privcmd_open,
+    .close = &minios_privcmd_close,
+
+    .u.privcmd = {
+        .alloc_hypercall_buffer = &minios_privcmd_alloc_hypercall_buffer,
+        .free_hypercall_buffer = &minios_privcmd_free_hypercall_buffer,
+
+        .hypercall = &minios_privcmd_hypercall,
+
+        .map_foreign_batch = &minios_privcmd_map_foreign_batch,
+        .map_foreign_bulk = &minios_privcmd_map_foreign_bulk,
+        .map_foreign_range = &minios_privcmd_map_foreign_range,
+        .map_foreign_ranges = &minios_privcmd_map_foreign_ranges,
+    },
+};
+
+static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
+{
+    int fd = alloc_fd(FTYPE_GNTMAP);
+    if ( fd == -1 )
+        return XC_OSDEP_OPEN_ERROR;
+    gntmap_init(&files[fd].gntmap);
+    return (xc_osdep_handle)fd;
+}
+
+static int minios_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h)
+{
+    int fd = (int)h;
+    return close(fd);
+}
+
+void minios_gnttab_close_fd(int fd)
+{
+    gntmap_fini(&files[fd].gntmap);
+    files[fd].type = FTYPE_NONE;
+}
+
+static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
+                                     uint32_t count, int flags, int prot,
+                                     uint32_t *domids, uint32_t *refs,
+                                     uint32_t notify_offset,
+                                     evtchn_port_t notify_port)
+{
+    int fd = (int)h;
+    int stride = 1;
+    if (flags & XC_GRANT_MAP_SINGLE_DOMAIN)
+        stride = 0;
+    if (notify_offset != -1 || notify_port != -1) {
+        errno = ENOSYS;
+        return NULL;
+    }
+    return gntmap_map_grant_refs(&files[fd].gntmap,
+                                 count, domids, stride,
+                                 refs, prot & PROT_WRITE);
+}
+
+static int minios_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
+                                void *start_address,
+                                uint32_t count)
+{
+    int fd = (int)h;
+    int ret;
+    ret = gntmap_munmap(&files[fd].gntmap,
+                        (unsigned long) start_address,
+                        count);
+    if (ret < 0) {
+        errno = -ret;
+        return -1;
+    }
+    return ret;
+}
+
+static int minios_gnttab_set_max_grants(xc_gnttab *xcg, xc_osdep_handle h,
+                             uint32_t count)
+{
+    int fd = (int)h;
+    int ret;
+    ret = gntmap_set_max_grants(&files[fd].gntmap,
+                                count);
+    if (ret < 0) {
+        errno = -ret;
+        return -1;
+    }
+    return ret;
+}
+
+struct xc_osdep_ops xc_gnttab_ops = {
+    .open = &minios_gnttab_open,
+    .close = &minios_gnttab_close,
+
+    .u.gnttab = {
+        .grant_map = &minios_gnttab_grant_map,
+        .munmap = &minios_gnttab_munmap,
+        .set_max_grants = &minios_gnttab_set_max_grants,
+    },
+};
+
tools/libxc/xc_private.h +3 -0
index 45b8644..152465f 100644
@@ -111,6 +111,9 @@ struct xc_interface_core {
     xc_osdep_handle  ops_handle; /* opaque data for xc_osdep_ops */
 };
 
+/* Do not use these directly; go via the handle you already have. */
+extern struct xc_osdep_ops xc_privcmd_ops, xc_evtchn_ops, xc_gnttab_ops;
+
 void xc_report_error(xc_interface *xch, int code, const char *fmt, ...)
     __attribute__((format(printf,3,4)));
 void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
author
#10 lore raw

Re: [PATCH 2/5] libxc: Split off xc_minios_privcmd.c

Quoted 7 lines · Ian Campbell
Quoted 5 lines · Wei Liu

From: Ian Jackson <[email protected]>

We are going to want to use some but not all of the machinery previously in xc_minios.c. Split the privcmd and gnttab code into its own file.

Quoted 8 lines

Does it make sense to put gnttab code in a file called privcmd.c?

I don't think there is much of a link between the two, is there?

I'm not sure which half of this rump libxc is going to want but perhaps either _common or _standalone would be a better suffix, depending which way it goes?

I will name it xc_minios_common.c because the factored out code will be used by both mini-os and rump kernel.

Wei.

author
#11 lore raw

PATCH 3/5 libxc: Split off xc_netbsd_user.c

In reply to Wei Liu

From: Ian Jackson <[email protected]>

We are going to want to use some but not all of the machinery previously in xc_netbsd.c Split the evtchn and ancillary code into its own file. This part is pure code motion.

But we also have to alter the Makefile, and rename some symbols, as with xc_minios*.c.

---
 tools/libxc/Makefile         |   2 +-
 tools/libxc/xc_netbsd.c      | 168 +------------------------------------
 tools/libxc/xc_netbsd_user.c | 196 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 198 insertions(+), 168 deletions(-)
 create mode 100644 tools/libxc/xc_netbsd_user.c
tools/libxc/Makefile +1 -1
index 4ace2b6..0f3396c 100644
@@ -46,7 +46,7 @@ CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
 CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c
 CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c
 CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
-CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
+CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c xc_netbsd_user.c
 CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c xc_minios_privcmd.c
 
 GUEST_SRCS-y :=
tools/libxc/xc_netbsd.c +1 -167

180 lines not on this page · raw message

tools/libxc/xc_netbsd_user.c new file +196 -0

196 lines not on this page · raw message

Signature · 1 line
1.9.1
#12 lore raw

Re: [PATCH 3/5] libxc: Split off xc_netbsd_user.c

Quoted 5 lines · Wei Liu

From: Ian Jackson <[email protected]>

We are going to want to use some but not all of the machinery previously in xc_netbsd.c Split the evtchn and ancillary code into its own file. This part is pure code motion.

Why not xc_netbsd_evtchn?

Quoted 412 lines

But we also have to alter the Makefile, and rename some symbols, as with xc_minios*.c.

---
 tools/libxc/Makefile         |   2 +-
 tools/libxc/xc_netbsd.c      | 168 +------------------------------------
 tools/libxc/xc_netbsd_user.c | 196 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 198 insertions(+), 168 deletions(-)
 create mode 100644 tools/libxc/xc_netbsd_user.c
tools/libxc/Makefile +1 -1
index 4ace2b6..0f3396c 100644
@@ -46,7 +46,7 @@ CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
 CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c
 CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c
 CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
-CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
+CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c xc_netbsd_user.c
 CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c xc_minios_privcmd.c
 
 GUEST_SRCS-y :=
tools/libxc/xc_netbsd.c +1 -167
index 8a90ef3..f940607 100644
@@ -224,172 +224,6 @@ static struct xc_osdep_ops netbsd_privcmd_ops = {
     },
 };
 
-#define EVTCHN_DEV_NAME  "/dev/xenevt"
-
-static xc_osdep_handle netbsd_evtchn_open(xc_evtchn *xce)
-{
-    int fd = open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR);
-    if ( fd == -1 )
-        return XC_OSDEP_OPEN_ERROR;
-
-    return (xc_osdep_handle)fd;
-}
-
-static int netbsd_evtchn_close(xc_evtchn *xce, xc_osdep_handle h)
-{
-    int fd = (int)h;
-    return close(fd);
-}
-
-static int netbsd_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h)
-{
-    return (int)h;
-}
-
-static int netbsd_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port)
-{
-    int fd = (int)h;
-    struct ioctl_evtchn_notify notify;
-
-    notify.port = port;
-
-    return ioctl(fd, IOCTL_EVTCHN_NOTIFY, &notify);
-}
-
-static evtchn_port_or_error_t
-netbsd_evtchn_bind_unbound_port(xc_evtchn * xce, xc_osdep_handle h, int domid)
-{
-    int fd = (int)h;
-    struct ioctl_evtchn_bind_unbound_port bind;
-    int ret;
-
-    bind.remote_domain = domid;
-
-    ret = ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
-    if (ret == 0)
-	return bind.port;
-    else
-	return -1;
-}
-
-static evtchn_port_or_error_t
-netbsd_evtchn_bind_interdomain(xc_evtchn *xce, xc_osdep_handle h, int domid,
-                               evtchn_port_t remote_port)
-{
-    int fd = (int)h;
-    struct ioctl_evtchn_bind_interdomain bind;
-    int ret;
-
-    bind.remote_domain = domid;
-    bind.remote_port = remote_port;
-
-    ret = ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
-    if (ret == 0)
-	return bind.port;
-    else
-	return -1;
-}
-
-static int netbsd_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port)
-{
-    int fd = (int)h;
-    struct ioctl_evtchn_unbind unbind;
-
-    unbind.port = port;
-
-    return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind);
-}
-
-static evtchn_port_or_error_t
-netbsd_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq)
-{
-    int fd = (int)h;
-    struct ioctl_evtchn_bind_virq bind;
-    int err;
-
-    bind.virq = virq;
-
-    err = ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
-    if (err)
-	return -1;
-    else
-	return bind.port;
-}
-
-static evtchn_port_or_error_t
-netbsd_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h)
-{
-    int fd = (int)h;
-    evtchn_port_t port;
-
-    if ( read_exact(fd, (char *)&port, sizeof(port)) == -1 )
-        return -1;
-
-    return port;
-}
-
-static int netbsd_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port)
-{
-    int fd = (int)h;
-    return write_exact(fd, (char *)&port, sizeof(port));
-}
-
-static struct xc_osdep_ops netbsd_evtchn_ops = {
-    .open = &netbsd_evtchn_open,
-    .close = &netbsd_evtchn_close,
-
-    .u.evtchn = {
-         .fd = &netbsd_evtchn_fd,
-         .notify = &netbsd_evtchn_notify,
-         .bind_unbound_port = &netbsd_evtchn_bind_unbound_port,
-         .bind_interdomain = &netbsd_evtchn_bind_interdomain,
-         .bind_virq = &netbsd_evtchn_bind_virq,
-         .unbind = &netbsd_evtchn_unbind,
-         .pending = &netbsd_evtchn_pending,
-         .unmask = &netbsd_evtchn_unmask,
-    },
-};
-
-/* Optionally flush file to disk and discard page cache */
-void discard_file_cache(xc_interface *xch, int fd, int flush) 
-{
-    off_t cur = 0;
-    int saved_errno = errno;
-
-    if ( flush && (fsync(fd) < 0) )
-    {
-        /*PERROR("Failed to flush file: %s", strerror(errno));*/
-        goto out;
-    }
-
-    /*
-     * Calculate last page boundry of amount written so far
-     * unless we are flushing in which case entire cache
-     * is discarded.
-     */
-    if ( !flush )
-    {
-        if ( ( cur = lseek(fd, 0, SEEK_CUR)) == (off_t)-1 )
-            cur = 0;
-        cur &= ~(PAGE_SIZE - 1);
-    }
-
-    /* Discard from the buffer cache. */
-    if ( posix_fadvise(fd, 0, cur, POSIX_FADV_DONTNEED) < 0 )
-    {
-        /*PERROR("Failed to discard cache: %s", strerror(errno));*/
-        goto out;
-    }
-
- out:
-    errno = saved_errno;
-}
-
-void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
-{
-    return valloc(size);
-}
-
 static struct xc_osdep_ops *netbsd_osdep_init(xc_interface *xch, enum xc_osdep_type type)
 {
     switch ( type )
@@ -397,7 +231,7 @@ static struct xc_osdep_ops *netbsd_osdep_init(xc_interface *xch, enum xc_osdep_t
     case XC_OSDEP_PRIVCMD:
         return &netbsd_privcmd_ops;
     case XC_OSDEP_EVTCHN:
-        return &netbsd_evtchn_ops;
+        return &xc_evtchn_ops;
     default:
         return NULL;
     }
tools/libxc/xc_netbsd_user.c new file +196 -0
new file mode 100644
index 0000000..b5c2491
@@ -0,0 +1,196 @@
+/******************************************************************************
+ *
+ * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * xc_gnttab functions:
+ * Copyright (c) 2007-2008, D G Murray <[email protected]>
+ *
+ * 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;
+ * version 2.1 of the License.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "xc_private.h"
+
+#include <xen/sys/evtchn.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <malloc.h>
+#include <sys/mman.h>
+
+#define EVTCHN_DEV_NAME  "/dev/xenevt"
+
+static xc_osdep_handle netbsd_evtchn_open(xc_evtchn *xce)
+{
+    int fd = open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR);
+    if ( fd == -1 )
+        return XC_OSDEP_OPEN_ERROR;
+
+    return (xc_osdep_handle)fd;
+}
+
+static int netbsd_evtchn_close(xc_evtchn *xce, xc_osdep_handle h)
+{
+    int fd = (int)h;
+    return close(fd);
+}
+
+static int netbsd_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h)
+{
+    return (int)h;
+}
+
+static int netbsd_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port)
+{
+    int fd = (int)h;
+    struct ioctl_evtchn_notify notify;
+
+    notify.port = port;
+
+    return ioctl(fd, IOCTL_EVTCHN_NOTIFY, &notify);
+}
+
+static evtchn_port_or_error_t
+netbsd_evtchn_bind_unbound_port(xc_evtchn * xce, xc_osdep_handle h, int domid)
+{
+    int fd = (int)h;
+    struct ioctl_evtchn_bind_unbound_port bind;
+    int ret;
+
+    bind.remote_domain = domid;
+
+    ret = ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
+    if (ret == 0)
+	return bind.port;
+    else
+	return -1;
+}
+
+static evtchn_port_or_error_t
+netbsd_evtchn_bind_interdomain(xc_evtchn *xce, xc_osdep_handle h, int domid,
+                               evtchn_port_t remote_port)
+{
+    int fd = (int)h;
+    struct ioctl_evtchn_bind_interdomain bind;
+    int ret;
+
+    bind.remote_domain = domid;
+    bind.remote_port = remote_port;
+
+    ret = ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
+    if (ret == 0)
+	return bind.port;
+    else
+	return -1;
+}
+
+static int netbsd_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port)
+{
+    int fd = (int)h;
+    struct ioctl_evtchn_unbind unbind;
+
+    unbind.port = port;
+
+    return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind);
+}
+
+static evtchn_port_or_error_t
+netbsd_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq)
+{
+    int fd = (int)h;
+    struct ioctl_evtchn_bind_virq bind;
+    int err;
+
+    bind.virq = virq;
+
+    err = ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
+    if (err)
+	return -1;
+    else
+	return bind.port;
+}
+
+static evtchn_port_or_error_t
+netbsd_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h)
+{
+    int fd = (int)h;
+    evtchn_port_t port;
+
+    if ( read_exact(fd, (char *)&port, sizeof(port)) == -1 )
+        return -1;
+
+    return port;
+}
+
+static int netbsd_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port)
+{
+    int fd = (int)h;
+    return write_exact(fd, (char *)&port, sizeof(port));
+}
+
+struct xc_osdep_ops xc_evtchn_ops = {
+    .open = &netbsd_evtchn_open,
+    .close = &netbsd_evtchn_close,
+
+    .u.evtchn = {
+         .fd = &netbsd_evtchn_fd,
+         .notify = &netbsd_evtchn_notify,
+         .bind_unbound_port = &netbsd_evtchn_bind_unbound_port,
+         .bind_interdomain = &netbsd_evtchn_bind_interdomain,
+         .bind_virq = &netbsd_evtchn_bind_virq,
+         .unbind = &netbsd_evtchn_unbind,
+         .pending = &netbsd_evtchn_pending,
+         .unmask = &netbsd_evtchn_unmask,
+    },
+};
+
+/* Optionally flush file to disk and discard page cache */
+void discard_file_cache(xc_interface *xch, int fd, int flush) 
+{
+    off_t cur = 0;
+    int saved_errno = errno;
+
+    if ( flush && (fsync(fd) < 0) )
+    {
+        /*PERROR("Failed to flush file: %s", strerror(errno));*/
+        goto out;
+    }
+
+    /*
+     * Calculate last page boundry of amount written so far
+     * unless we are flushing in which case entire cache
+     * is discarded.
+     */
+    if ( !flush )
+    {
+        if ( ( cur = lseek(fd, 0, SEEK_CUR)) == (off_t)-1 )
+            cur = 0;
+        cur &= ~(PAGE_SIZE - 1);
+    }
+
+    /* Discard from the buffer cache. */
+    if ( posix_fadvise(fd, 0, cur, POSIX_FADV_DONTNEED) < 0 )
+    {
+        /*PERROR("Failed to discard cache: %s", strerror(errno));*/
+        goto out;
+    }
+
+ out:
+    errno = saved_errno;
+}
+
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+    return valloc(size);
+}
author
#13 lore raw

Re: [PATCH 3/5] libxc: Split off xc_netbsd_user.c

Quoted 9 lines · Ian Campbell
Quoted 5 lines · Wei Liu

From: Ian Jackson <[email protected]>

We are going to want to use some but not all of the machinery previously in xc_netbsd.c Split the evtchn and ancillary code into its own file. This part is pure code motion.

Why not xc_netbsd_evtchn?

Ack.

author
#14 lore raw

PATCH 4/5 libxc: minios: Introduce abstraction for files[]

In reply to Wei Liu

From: Ian Jackson <[email protected]>

We are going to want to reuse this code for NetBSD rump kernels, where there is no gntmap device and we just want to call the MiniOS gntmap code directly.

As part of this we want to abstract away the use of files[] inside the actual functions. Do this with a #define whose definition we are going to make conditional in just a moment.

No functional change in this patch.

---
 tools/libxc/xc_minios_privcmd.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
tools/libxc/xc_minios_privcmd.c +7 -8
index 7766b86..27d9076 100644
@@ -208,12 +208,14 @@ struct xc_osdep_ops xc_privcmd_ops = {
     },
 };
 
+#define GNTMAP(h) (files[(int)(h)].gntmap)
+
 static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
 {
     int fd = alloc_fd(FTYPE_GNTMAP);
     if ( fd == -1 )
         return XC_OSDEP_OPEN_ERROR;
-    gntmap_init(&files[fd].gntmap);
+    gntmap_init(&GNTMAP(h));
     return (xc_osdep_handle)fd;
 }
 
@@ -225,7 +227,7 @@ static int minios_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h)
 
 void minios_gnttab_close_fd(int fd)
 {
-    gntmap_fini(&files[fd].gntmap);
+    gntmap_fini(&GNTMAP(h));
     files[fd].type = FTYPE_NONE;
 }
 
@@ -235,7 +237,6 @@ static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
                                      uint32_t notify_offset,
                                      evtchn_port_t notify_port)
 {
-    int fd = (int)h;
     int stride = 1;
     if (flags & XC_GRANT_MAP_SINGLE_DOMAIN)
         stride = 0;
@@ -243,7 +244,7 @@ static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
         errno = ENOSYS;
         return NULL;
     }
-    return gntmap_map_grant_refs(&files[fd].gntmap,
+    return gntmap_map_grant_refs(&GNTMAP(h),
                                  count, domids, stride,
                                  refs, prot & PROT_WRITE);
 }
@@ -252,9 +253,8 @@ static int minios_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
                                 void *start_address,
                                 uint32_t count)
 {
-    int fd = (int)h;
     int ret;
-    ret = gntmap_munmap(&files[fd].gntmap,
+    ret = gntmap_munmap(&GNTMAP(h),
                         (unsigned long) start_address,
                         count);
     if (ret < 0) {
@@ -267,9 +267,8 @@ static int minios_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
 static int minios_gnttab_set_max_grants(xc_gnttab *xcg, xc_osdep_handle h,
                              uint32_t count)
 {
-    int fd = (int)h;
     int ret;
-    ret = gntmap_set_max_grants(&files[fd].gntmap,
+    ret = gntmap_set_max_grants(&GNTMAP(h),
                                 count);
     if (ret < 0) {
         errno = -ret;
Signature · 1 line
1.9.1
#15 lore raw

Re: [PATCH 4/5] libxc: minios: Introduce abstraction for files[]

Quoted 24 lines · Wei Liu

From: Ian Jackson <[email protected]>

We are going to want to reuse this code for NetBSD rump kernels, where there is no gntmap device and we just want to call the MiniOS gntmap code directly.

As part of this we want to abstract away the use of files[] inside the actual functions. Do this with a #define whose definition we are going to make conditional in just a moment.

No functional change in this patch.

---
  tools/libxc/xc_minios_privcmd.c | 15 +++++++--------
  1 file changed, 7 insertions(+), 8 deletions(-)
tools/libxc/xc_minios_privcmd.c +0 -0
index 7766b86..27d9076 100644
@@ -208,12 +208,14 @@ struct xc_osdep_ops xc_privcmd_ops = {
      },
  };

tools/libxc/xc_minios_privcmd.c struct xc_osdep_ops xc_privcmd_ops = { · line 218

Quoted 10 lines
tools/libxc/xc_minios_privcmd.c +3 -1
 
+#define GNTMAP(h) (files[(int)(h)].gntmap)
+
  static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
  {
      int fd = alloc_fd(FTYPE_GNTMAP);
      if ( fd == -1 )
          return XC_OSDEP_OPEN_ERROR;
-    gntmap_init(&files[fd].gntmap);
+    gntmap_init(&GNTMAP(h));

GNTMAP(fd)?

Same multiple times below.

Juergen

Quoted 52 lines
tools/libxc/xc_minios_privcmd.c +4 -7
      return (xc_osdep_handle)fd;
  }
 
@@ -225,7 +227,7 @@ static int minios_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h)
 
  void minios_gnttab_close_fd(int fd)
  {
-    gntmap_fini(&files[fd].gntmap);
+    gntmap_fini(&GNTMAP(h));
      files[fd].type = FTYPE_NONE;
  }
 
@@ -235,7 +237,6 @@ static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
                                       uint32_t notify_offset,
                                       evtchn_port_t notify_port)
  {
-    int fd = (int)h;
      int stride = 1;
      if (flags & XC_GRANT_MAP_SINGLE_DOMAIN)
          stride = 0;
@@ -243,7 +244,7 @@ static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
          errno = ENOSYS;
          return NULL;
      }
-    return gntmap_map_grant_refs(&files[fd].gntmap,
+    return gntmap_map_grant_refs(&GNTMAP(h),
                                   count, domids, stride,
                                   refs, prot & PROT_WRITE);
  }
@@ -252,9 +253,8 @@ static int minios_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
                                  void *start_address,
                                  uint32_t count)
  {
-    int fd = (int)h;
      int ret;
-    ret = gntmap_munmap(&files[fd].gntmap,
+    ret = gntmap_munmap(&GNTMAP(h),
                          (unsigned long) start_address,
                          count);
      if (ret < 0) {
@@ -267,9 +267,8 @@ static int minios_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
  static int minios_gnttab_set_max_grants(xc_gnttab *xcg, xc_osdep_handle h,
                               uint32_t count)
  {
-    int fd = (int)h;
      int ret;
-    ret = gntmap_set_max_grants(&files[fd].gntmap,
+    ret = gntmap_set_max_grants(&GNTMAP(h),
                                  count);
      if (ret < 0) {
          errno = -ret;
author
#16 lore raw

Re: [PATCH 4/5] libxc: minios: Introduce abstraction for files[]

Quoted 38 lines · Jürgen Groß
Quoted 24 lines · Wei Liu

From: Ian Jackson <[email protected]>

We are going to want to reuse this code for NetBSD rump kernels, where there is no gntmap device and we just want to call the MiniOS gntmap code directly.

As part of this we want to abstract away the use of files[] inside the actual functions. Do this with a #define whose definition we are going to make conditional in just a moment.

No functional change in this patch.

---
 tools/libxc/xc_minios_privcmd.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
tools/libxc/xc_minios_privcmd.c +0 -0
index 7766b86..27d9076 100644
@@ -208,12 +208,14 @@ struct xc_osdep_ops xc_privcmd_ops = {
     },
 };

tools/libxc/xc_minios_privcmd.c struct xc_osdep_ops xc_privcmd_ops = { · line 218

Quoted 10 lines
tools/libxc/xc_minios_privcmd.c +3 -1
 
+#define GNTMAP(h) (files[(int)(h)].gntmap)
+
 static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
 {
     int fd = alloc_fd(FTYPE_GNTMAP);
     if ( fd == -1 )
         return XC_OSDEP_OPEN_ERROR;
-    gntmap_init(&files[fd].gntmap);
+    gntmap_init(&GNTMAP(h));

GNTMAP(fd)?

Quoted 2 lines

Same multiple times below.

Good catch. I will fix this, thanks.

Wei.

Acked-by on v1 4/5
#17 lore raw

Re: [PATCH 4/5] libxc: minios: Introduce abstraction for files[]

In reply to Wei Liu
Quoted 6 lines · Wei Liu, le Thu 26 Feb 2015 11:56:20 +0000, a écrit :

From: Ian Jackson <[email protected]>

We are going to want to reuse this code for NetBSD rump kernels, where there is no gntmap device and we just want to call the MiniOS gntmap code directly.

Quoted 7 lines

As part of this we want to abstract away the use of files[] inside the actual functions. Do this with a #define whose definition we are going to make conditional in just a moment.

No functional change in this patch.

Quoted 81 lines
---
 tools/libxc/xc_minios_privcmd.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
tools/libxc/xc_minios_privcmd.c +7 -8
index 7766b86..27d9076 100644
@@ -208,12 +208,14 @@ struct xc_osdep_ops xc_privcmd_ops = {
     },
 };
 
+#define GNTMAP(h) (files[(int)(h)].gntmap)
+
 static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
 {
     int fd = alloc_fd(FTYPE_GNTMAP);
     if ( fd == -1 )
         return XC_OSDEP_OPEN_ERROR;
-    gntmap_init(&files[fd].gntmap);
+    gntmap_init(&GNTMAP(h));
     return (xc_osdep_handle)fd;
 }
 
@@ -225,7 +227,7 @@ static int minios_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h)
 
 void minios_gnttab_close_fd(int fd)
 {
-    gntmap_fini(&files[fd].gntmap);
+    gntmap_fini(&GNTMAP(h));
     files[fd].type = FTYPE_NONE;
 }
 
@@ -235,7 +237,6 @@ static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
                                      uint32_t notify_offset,
                                      evtchn_port_t notify_port)
 {
-    int fd = (int)h;
     int stride = 1;
     if (flags & XC_GRANT_MAP_SINGLE_DOMAIN)
         stride = 0;
@@ -243,7 +244,7 @@ static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
         errno = ENOSYS;
         return NULL;
     }
-    return gntmap_map_grant_refs(&files[fd].gntmap,
+    return gntmap_map_grant_refs(&GNTMAP(h),
                                  count, domids, stride,
                                  refs, prot & PROT_WRITE);
 }
@@ -252,9 +253,8 @@ static int minios_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
                                 void *start_address,
                                 uint32_t count)
 {
-    int fd = (int)h;
     int ret;
-    ret = gntmap_munmap(&files[fd].gntmap,
+    ret = gntmap_munmap(&GNTMAP(h),
                         (unsigned long) start_address,
                         count);
     if (ret < 0) {
@@ -267,9 +267,8 @@ static int minios_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
 static int minios_gnttab_set_max_grants(xc_gnttab *xcg, xc_osdep_handle h,
                              uint32_t count)
 {
-    int fd = (int)h;
     int ret;
-    ret = gntmap_set_max_grants(&files[fd].gntmap,
+    ret = gntmap_set_max_grants(&GNTMAP(h),
                                 count);
     if (ret < 0) {
         errno = -ret;
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Signature · 3 lines
Samuel
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This email was infected under the terms of the GNU General Public License.
Acked-by on v1 4/5
#18 lore raw

Re: [PATCH 4/5] libxc: minios: Introduce abstraction for files[]

In reply to Wei Liu
Quoted 6 lines · Wei Liu

From: Ian Jackson <[email protected]>

We are going to want to reuse this code for NetBSD rump kernels, where there is no gntmap device and we just want to call the MiniOS gntmap code directly.

Quoted 7 lines

As part of this we want to abstract away the use of files[] inside the actual functions. Do this with a #define whose definition we are going to make conditional in just a moment.

No functional change in this patch.

Wei -- did you not want to Ack- or S-o-b this yourself?

Quoted 72 lines
---
 tools/libxc/xc_minios_privcmd.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
tools/libxc/xc_minios_privcmd.c +7 -8
index 7766b86..27d9076 100644
@@ -208,12 +208,14 @@ struct xc_osdep_ops xc_privcmd_ops = {
     },
 };
 
+#define GNTMAP(h) (files[(int)(h)].gntmap)
+
 static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
 {
     int fd = alloc_fd(FTYPE_GNTMAP);
     if ( fd == -1 )
         return XC_OSDEP_OPEN_ERROR;
-    gntmap_init(&files[fd].gntmap);
+    gntmap_init(&GNTMAP(h));
     return (xc_osdep_handle)fd;
 }
 
@@ -225,7 +227,7 @@ static int minios_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h)
 
 void minios_gnttab_close_fd(int fd)
 {
-    gntmap_fini(&files[fd].gntmap);
+    gntmap_fini(&GNTMAP(h));
     files[fd].type = FTYPE_NONE;
 }
 
@@ -235,7 +237,6 @@ static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
                                      uint32_t notify_offset,
                                      evtchn_port_t notify_port)
 {
-    int fd = (int)h;
     int stride = 1;
     if (flags & XC_GRANT_MAP_SINGLE_DOMAIN)
         stride = 0;
@@ -243,7 +244,7 @@ static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
         errno = ENOSYS;
         return NULL;
     }
-    return gntmap_map_grant_refs(&files[fd].gntmap,
+    return gntmap_map_grant_refs(&GNTMAP(h),
                                  count, domids, stride,
                                  refs, prot & PROT_WRITE);
 }
@@ -252,9 +253,8 @@ static int minios_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
                                 void *start_address,
                                 uint32_t count)
 {
-    int fd = (int)h;
     int ret;
-    ret = gntmap_munmap(&files[fd].gntmap,
+    ret = gntmap_munmap(&GNTMAP(h),
                         (unsigned long) start_address,
                         count);
     if (ret < 0) {
@@ -267,9 +267,8 @@ static int minios_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h,
 static int minios_gnttab_set_max_grants(xc_gnttab *xcg, xc_osdep_handle h,
                              uint32_t count)
 {
-    int fd = (int)h;
     int ret;
-    ret = gntmap_set_max_grants(&files[fd].gntmap,
+    ret = gntmap_set_max_grants(&GNTMAP(h),
                                 count);
     if (ret < 0) {
         errno = -ret;
author
#19 lore raw

Re: [PATCH 4/5] libxc: minios: Introduce abstraction for files[]

Quoted 11 lines · Ian Campbell
Quoted 10 lines · Wei Liu

From: Ian Jackson <[email protected]>

We are going to want to reuse this code for NetBSD rump kernels, where there is no gntmap device and we just want to call the MiniOS gntmap code directly.

As part of this we want to abstract away the use of files[] inside the actual functions. Do this with a #define whose definition we are going to make conditional in just a moment.

Quoted 8 lines
Quoted 3 lines

No functional change in this patch.

Wei -- did you not want to Ack- or S-o-b this yourself?

I forgot to do that. Sorry.

It will have my S-o-B in next version because I will fix a bug in this patch.

Wei.

author
#20 lore raw

PATCH 5/5 libxc: rumpxen: Provide xc_osdep_info

In reply to Wei Liu

From: Ian Jackson <[email protected]>

This allows programs which use the bulk of libxc to link. We use /dev/xenevt for event channels, the raw minios functions for privcmd and gnttab, and the netbsd versions of discard_file_cache and xc_memalign.

[ wei: wrap long lines, adapt to changes in previous patch ]

---
 tools/libxc/Makefile             |  2 ++
 tools/libxc/xc_minios_privcmd.c  | 36 +++++++++++++++++++++--
 tools/libxc/xc_netbsd_rumpkern.c | 62 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 98 insertions(+), 2 deletions(-)
 create mode 100644 tools/libxc/xc_netbsd_rumpkern.c
tools/libxc/Makefile +2 -0
index 0f3396c..bce2dd2 100644
@@ -48,6 +48,8 @@ CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c
 CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
 CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c xc_netbsd_user.c
 CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c xc_minios_privcmd.c
+CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd_rumpkern.c xc_netbsd_user.c
+CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_minios_privcmd.c
 
 GUEST_SRCS-y :=
 GUEST_SRCS-y += xg_private.c xc_suspend.c
tools/libxc/xc_minios_privcmd.c +34 -2
index 27d9076..a8b1102 100644
@@ -41,9 +41,19 @@
 
 #include "xc_private.h"
 
-#ifdef __RUMPRUN___
+#ifdef __RUMPRUN__
 # define map_frames_ex minios_map_frames_ex
-#endif /* __RUMPRUN__ */
+
+static xc_osdep_handle minios_privcmd_open(xc_interface *xch)
+{
+    return 1;
+}
+static int minios_privcmd_close(xc_interface *xch, xc_osdep_handle h)
+{
+    return 0;
+}
+
+#else /* !__RUMPRUN__ */
 
 void minios_interface_close_fd(int fd);
 void minios_gnttab_close_fd(int fd);
@@ -69,6 +79,8 @@ void minios_interface_close_fd(int fd)
     files[fd].type = FTYPE_NONE;
 }
 
+#endif /* !__RUMPRUN__ */
+
 static void *minios_privcmd_alloc_hypercall_buffer(xc_interface *xch,
 						   xc_osdep_handle h,
 						   int npages)
@@ -208,6 +220,24 @@ struct xc_osdep_ops xc_privcmd_ops = {
     },
 };
 
+#ifdef __RUMPRUN__
+
+static struct gntmap static_gntmap;
+
+#define GNTMAP(h) static_gntmap
+
+static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
+{
+    return 1;
+}
+
+static int minios_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h)
+{
+    return 0;
+}
+
+#else /* !__RUMPRUN__ */
+
 #define GNTMAP(h) (files[(int)(h)].gntmap)
 
 static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
@@ -231,6 +261,8 @@ void minios_gnttab_close_fd(int fd)
     files[fd].type = FTYPE_NONE;
 }
 
+#endif /* !__RUMPRUN__ */
+
 static void *minios_gnttab_grant_map(xc_gnttab *xcg, xc_osdep_handle h,
                                      uint32_t count, int flags, int prot,
                                      uint32_t *domids, uint32_t *refs,
tools/libxc/xc_netbsd_rumpkern.c new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
1.9.1
#21 lore raw

Re: [PATCH 5/5] libxc: rumpxen: Provide xc_osdep_info

tools/libxc/xc_netbsd_rumpkern.c line 7

Quoted 13 lines · Wei Liu
tools/libxc/xc_netbsd_rumpkern.c new file +7 -0
new file mode 100644
index 0000000..11d4a63
@@ -0,0 +1,62 @@
+/******************************************************************************
+ *
+ * Copyright 2013 Citrix.
+ * Use is subject to license terms.
+ *
+ * xc_gnttab functions:
+ * Copyright (c) 2007-2008, D G Murray <[email protected]>

It doesn't seem like any of that remains. In fact I suspect this is just a cut-and-paste error?

author
#22 lore raw

Re: [PATCH 5/5] libxc: rumpxen: Provide xc_osdep_info

Quoted 18 lines · Ian Campbell

tools/libxc/xc_netbsd_rumpkern.c line 7

Quoted 13 lines · Wei Liu
tools/libxc/xc_netbsd_rumpkern.c new file +7 -0
new file mode 100644
index 0000000..11d4a63
@@ -0,0 +1,62 @@
+/******************************************************************************
+ *
+ * Copyright 2013 Citrix.
+ * Use is subject to license terms.
+ *
+ * xc_gnttab functions:
+ * Copyright (c) 2007-2008, D G Murray <[email protected]>

It doesn't seem like any of that remains. In fact I suspect this is just a cut-and-paste error?

Yes, cut-and-paste error. Deleted now.

Wei.