Re: [Xen-devel] [PATCH 3/5] libxc: Split off xc_netbsd_user.c
On Mon, Mar 02, 2015 at 05:33:13PM +, Ian Campbell wrote: On Thu, 2015-02-26 at 11:56 +, Wei Liu wrote: From: Ian Jackson ian.jack...@eu.citrix.com 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. ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH 3/5] libxc: Split off xc_netbsd_user.c
On Thu, 2015-02-26 at 11:56 +, Wei Liu wrote: From: Ian Jackson ian.jack...@eu.citrix.com 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? But we also have to alter the Makefile, and rename some symbols, as with xc_minios*.c. Signed-off-by: Ian Jackson ian.jack...@eu.citrix.com --- 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, 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) ) -
[Xen-devel] [PATCH 3/5] libxc: Split off xc_netbsd_user.c
From: Ian Jackson ian.jack...@eu.citrix.com 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.jack...@eu.citrix.com --- 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, 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.