[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 3/5] libxc: Split off xc_netbsd_user.c
From: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> 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. Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> --- 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 diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile index 4ace2b6..0f3396c 100644 --- a/tools/libxc/Makefile +++ b/tools/libxc/Makefile @@ -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 := diff --git a/tools/libxc/xc_netbsd.c b/tools/libxc/xc_netbsd.c index 8a90ef3..f940607 100644 --- a/tools/libxc/xc_netbsd.c +++ b/tools/libxc/xc_netbsd.c @@ -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, ¬ify); -} - -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; } diff --git a/tools/libxc/xc_netbsd_user.c b/tools/libxc/xc_netbsd_user.c new file mode 100644 index 0000000..b5c2491 --- /dev/null +++ b/tools/libxc/xc_netbsd_user.c @@ -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 <Derek.Murray@xxxxxxxxxxxx> + * + * 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, ¬ify); +} + +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); +} -- 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |