Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 00 of 25] libxc: dom0 OS integration cleanup+abstraction.
The following series updates the libxc evtchn and gnttab interfaces to use the same abstract handle type as the primary libxc interface rather than the existing simple integer handle. This is good for consistency and also allows callers to control logging in the same was as they do with the primary interface. I have given each interface a distinct typedef name, in the hopes that in the future some type safety can be introduced. In addition to this series there is two patches to qemu-xen corresponding to the change in the event channel and grant table interface respectively. Following on from this the series then introduces an osdep abstraction which encapsulates the OS specific portions of libxc which interface with the hypervisor via the relevant kernel interfaces. The series then makes it possible to load implementations of this interface dynamically at runtime. Although the series includes a noddy implementation (mainly to validate that such a thing builds ok) the actual primary user will be the "Xen In Userspace" (xiu) simulator used in the XCP SDK VM. The patches to implement this functionality will be included in a followup reposting of my previous "Allow XCP to use ocaml library bindings in Xen unstable" set of series. The series has been tested using xl with PV and HVM guests (with both stub and non-stub qemu) as well as with the XCP series in both real dom0 and an SDK VM. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 01 of 25] libxc: some xc_gnttab_* functions are not Linux specific
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369006 0 # Node ID 7c6e87f167d47b2c0b850806d0e9fa298018ebd4 # Parent 9a40ab7a4347e4c49785d079a598a1bc22477739 libxc: some xc_gnttab_* functions are not Linux specific They simply make hypercalls and perform other operations via the abstract interface. Create xc_gnttab.c and move those functions there. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/Makefile --- a/tools/libxc/Makefile Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/Makefile Fri Dec 03 09:36:46 2010 +0000 @@ -11,6 +11,7 @@ CTRL_SRCS-y += xc_cpupool.c CTRL_SRCS-y += xc_cpupool.c CTRL_SRCS-y += xc_domain.c CTRL_SRCS-y += xc_evtchn.c +CTRL_SRCS-y += xc_gnttab.c CTRL_SRCS-y += xc_misc.c CTRL_SRCS-y += xc_acm.c CTRL_SRCS-y += xc_flask.c diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_gnttab.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxc/xc_gnttab.c Fri Dec 03 09:36:46 2010 +0000 @@ -0,0 +1,147 @@ +/****************************************************************************** + * + * Copyright (c) 2007-2008, D G Murray <Derek.Murray@cl.cam.ac.uk> + * + * 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" + +int xc_gnttab_op(xc_interface *xch, int cmd, void * op, int op_size, int count) +{ + int ret = 0; + DECLARE_HYPERCALL; + DECLARE_HYPERCALL_BOUNCE(op, count * op_size, XC_HYPERCALL_BUFFER_BOUNCE_BOTH); + + if ( xc_hypercall_bounce_pre(xch, op) ) + { + PERROR("Could not bounce buffer for grant table op hypercall"); + goto out1; + } + + hypercall.op = __HYPERVISOR_grant_table_op; + hypercall.arg[0] = cmd; + hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(op); + hypercall.arg[2] = count; + + ret = do_xen_hypercall(xch, &hypercall); + + xc_hypercall_bounce_post(xch, op); + + out1: + return ret; +} + +int xc_gnttab_get_version(xc_interface *xch, int domid) +{ + struct gnttab_get_version query; + int rc; + + query.dom = domid; + rc = xc_gnttab_op(xch, GNTTABOP_get_version, &query, sizeof(query), + 1); + if ( rc < 0 ) + return rc; + else + return query.version; +} + +static void *_gnttab_map_table(xc_interface *xch, int domid, int *gnt_num) +{ + int rc, i; + struct gnttab_query_size query; + struct gnttab_setup_table setup; + DECLARE_HYPERCALL_BUFFER(unsigned long, frame_list); + xen_pfn_t *pfn_list = NULL; + grant_entry_v1_t *gnt = NULL; + + if ( !gnt_num ) + return NULL; + + query.dom = domid; + rc = xc_gnttab_op(xch, GNTTABOP_query_size, &query, sizeof(query), 1); + + if ( rc || (query.status != GNTST_okay) ) + { + ERROR("Could not query dom''s grant size\n", domid); + return NULL; + } + + *gnt_num = query.nr_frames * (PAGE_SIZE / sizeof(grant_entry_v1_t) ); + + frame_list = xc_hypercall_buffer_alloc(xch, frame_list, query.nr_frames * sizeof(unsigned long)); + if ( !frame_list ) + { + ERROR("Could not allocate frame_list in xc_gnttab_map_table\n"); + return NULL; + } + + pfn_list = malloc(query.nr_frames * sizeof(xen_pfn_t)); + if ( !pfn_list ) + { + ERROR("Could not allocate pfn_list in xc_gnttab_map_table\n"); + goto err; + } + + setup.dom = domid; + setup.nr_frames = query.nr_frames; + set_xen_guest_handle(setup.frame_list, frame_list); + + /* XXX Any race with other setup_table hypercall? */ + rc = xc_gnttab_op(xch, GNTTABOP_setup_table, &setup, sizeof(setup), + 1); + + if ( rc || (setup.status != GNTST_okay) ) + { + ERROR("Could not get grant table frame list\n"); + goto err; + } + + for ( i = 0; i < setup.nr_frames; i++ ) + pfn_list[i] = frame_list[i]; + + gnt = xc_map_foreign_pages(xch, domid, PROT_READ, pfn_list, + setup.nr_frames); + if ( !gnt ) + { + ERROR("Could not map grant table\n"); + goto err; + } + +err: + if ( frame_list ) + xc_hypercall_buffer_free(xch, frame_list); + if ( pfn_list ) + free(pfn_list); + + return gnt; +} + +grant_entry_v1_t *xc_gnttab_map_table_v1(xc_interface *xch, int domid, + int *gnt_num) +{ + if (xc_gnttab_get_version(xch, domid) == 2) + return NULL; + return _gnttab_map_table(xch, domid, gnt_num); +} + +grant_entry_v2_t *xc_gnttab_map_table_v2(xc_interface *xch, int domid, + int *gnt_num) +{ + if (xc_gnttab_get_version(xch, domid) != 2) + return NULL; + return _gnttab_map_table(xch, domid, gnt_num); +} + diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:46 2010 +0000 @@ -608,132 +608,6 @@ int xc_gnttab_set_max_grants(xc_interfac return 0; } -int xc_gnttab_op(xc_interface *xch, int cmd, void * op, int op_size, int count) -{ - int ret = 0; - DECLARE_HYPERCALL; - DECLARE_HYPERCALL_BOUNCE(op, count * op_size, XC_HYPERCALL_BUFFER_BOUNCE_BOTH); - - if ( xc_hypercall_bounce_pre(xch, op) ) - { - PERROR("Could not bounce buffer for grant table op hypercall"); - goto out1; - } - - hypercall.op = __HYPERVISOR_grant_table_op; - hypercall.arg[0] = cmd; - hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(op); - hypercall.arg[2] = count; - - ret = do_xen_hypercall(xch, &hypercall); - - xc_hypercall_bounce_post(xch, op); - - out1: - return ret; -} - -int xc_gnttab_get_version(xc_interface *xch, int domid) -{ - struct gnttab_get_version query; - int rc; - - query.dom = domid; - rc = xc_gnttab_op(xch, GNTTABOP_get_version, &query, sizeof(query), - 1); - if ( rc < 0 ) - return rc; - else - return query.version; -} - -static void *_gnttab_map_table(xc_interface *xch, int domid, int *gnt_num) -{ - int rc, i; - struct gnttab_query_size query; - struct gnttab_setup_table setup; - DECLARE_HYPERCALL_BUFFER(unsigned long, frame_list); - xen_pfn_t *pfn_list = NULL; - grant_entry_v1_t *gnt = NULL; - - if ( !gnt_num ) - return NULL; - - query.dom = domid; - rc = xc_gnttab_op(xch, GNTTABOP_query_size, &query, sizeof(query), 1); - - if ( rc || (query.status != GNTST_okay) ) - { - ERROR("Could not query dom''s grant size\n", domid); - return NULL; - } - - *gnt_num = query.nr_frames * (PAGE_SIZE / sizeof(grant_entry_v1_t) ); - - frame_list = xc_hypercall_buffer_alloc(xch, frame_list, query.nr_frames * sizeof(unsigned long)); - if ( !frame_list ) - { - ERROR("Could not allocate frame_list in xc_gnttab_map_table\n"); - return NULL; - } - - pfn_list = malloc(query.nr_frames * sizeof(xen_pfn_t)); - if ( !pfn_list ) - { - ERROR("Could not allocate pfn_list in xc_gnttab_map_table\n"); - goto err; - } - - setup.dom = domid; - setup.nr_frames = query.nr_frames; - set_xen_guest_handle(setup.frame_list, frame_list); - - /* XXX Any race with other setup_table hypercall? */ - rc = xc_gnttab_op(xch, GNTTABOP_setup_table, &setup, sizeof(setup), - 1); - - if ( rc || (setup.status != GNTST_okay) ) - { - ERROR("Could not get grant table frame list\n"); - goto err; - } - - for ( i = 0; i < setup.nr_frames; i++ ) - pfn_list[i] = frame_list[i]; - - gnt = xc_map_foreign_pages(xch, domid, PROT_READ, pfn_list, - setup.nr_frames); - if ( !gnt ) - { - ERROR("Could not map grant table\n"); - goto err; - } - -err: - if ( frame_list ) - xc_hypercall_buffer_free(xch, frame_list); - if ( pfn_list ) - free(pfn_list); - - return gnt; -} - -grant_entry_v1_t *xc_gnttab_map_table_v1(xc_interface *xch, int domid, - int *gnt_num) -{ - if (xc_gnttab_get_version(xch, domid) == 2) - return NULL; - return _gnttab_map_table(xch, domid, gnt_num); -} - -grant_entry_v2_t *xc_gnttab_map_table_v2(xc_interface *xch, int domid, - int *gnt_num) -{ - if (xc_gnttab_get_version(xch, domid) != 2) - return NULL; - return _gnttab_map_table(xch, domid, gnt_num); -} - /* * Local variables: * mode: C diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:46 2010 +0000 @@ -457,18 +457,6 @@ int xc_gnttab_set_max_grants(xc_interfac return ret; } -grant_entry_v1_t *xc_gnttab_map_table_v1( - xc_interface *xch, int domid, int *gnt_num) -{ - return NULL; -} - -grant_entry_v2_t *xc_gnttab_map_table_v2( - xc_interface *xch, int domid, int *gnt_num) -{ - return NULL; -} - /* * Local variables: * mode: C diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:46 2010 +0000 @@ -287,18 +287,6 @@ void discard_file_cache(xc_interface *xc } } -grant_entry_v1_t *xc_gnttab_map_table_v1( - xc_interface *xch, int domid, int *gnt_num) -{ - return NULL; -} - -grant_entry_v2_t *xc_gnttab_map_table_v2( - xc_interface *xch, int domid, int *gnt_num) -{ - return NULL; -} - /* * Local variables: * mode: C diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:46 2010 +0000 @@ -261,15 +261,3 @@ void discard_file_cache(xc_interface *xc { // TODO: Implement for Solaris! } - -grant_entry_v1_t *xc_gnttab_map_table_v1( - xc_interface *xch, int domid, int *gnt_num) -{ - return NULL; -} - -grant_entry_v2_t *xc_gnttab_map_table_v2( - xc_interface *xch, int domid, int *gnt_num) -{ - return NULL; -} _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 02 of 25] libxc: convert evtchn interfaces to use an opaque handle type
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369006 0 # Node ID e82cccb0d9770e51f9785f109ea11d704ae4df45 # Parent 7c6e87f167d47b2c0b850806d0e9fa298018ebd4 libxc: convert evtchn interfaces to use an opaque handle type This makes the interface consistent with the changes made to the main interface in 21483:779c0ef9682c. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 7c6e87f167d4 -r e82cccb0d977 tools/console/daemon/io.c --- a/tools/console/daemon/io.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/console/daemon/io.c Fri Dec 03 09:36:46 2010 +0000 @@ -68,7 +68,7 @@ static int log_hv_fd = -1; static int log_hv_fd = -1; static evtchn_port_or_error_t log_hv_evtchn = -1; static xc_interface *xch; /* why does xenconsoled have two xc handles ? */ -static int xce_handle = -1; +static xc_evtchn *xce_handle = NULL; struct buffer { char *data; @@ -90,7 +90,7 @@ struct domain { int ring_ref; evtchn_port_or_error_t local_port; evtchn_port_or_error_t remote_port; - int xce_handle; + xc_evtchn *xce_handle; struct xencons_interface *interface; int event_count; long long next_period; @@ -547,13 +547,13 @@ static int domain_create_ring(struct dom dom->local_port = -1; dom->remote_port = -1; - if (dom->xce_handle != -1) + if (dom->xce_handle != NULL) xc_evtchn_close(dom->xce_handle); /* Opening evtchn independently for each console is a bit * wasteful, but that''s how the code is structured... */ - dom->xce_handle = xc_evtchn_open(); - if (dom->xce_handle == -1) { + dom->xce_handle = xc_evtchn_open(NULL, 0); + if (dom->xce_handle == NULL) { err = errno; goto out; } @@ -564,7 +564,7 @@ static int domain_create_ring(struct dom if (rc == -1) { err = errno; xc_evtchn_close(dom->xce_handle); - dom->xce_handle = -1; + dom->xce_handle = NULL; goto out; } dom->local_port = rc; @@ -574,7 +574,7 @@ static int domain_create_ring(struct dom if (!domain_create_tty(dom)) { err = errno; xc_evtchn_close(dom->xce_handle); - dom->xce_handle = -1; + dom->xce_handle = NULL; dom->local_port = -1; dom->remote_port = -1; goto out; @@ -655,7 +655,7 @@ static struct domain *create_domain(int dom->local_port = -1; dom->remote_port = -1; dom->interface = NULL; - dom->xce_handle = -1; + dom->xce_handle = NULL; if (!watch_domain(dom, true)) goto out; @@ -722,9 +722,9 @@ static void shutdown_domain(struct domai if (d->interface != NULL) munmap(d->interface, getpagesize()); d->interface = NULL; - if (d->xce_handle != -1) + if (d->xce_handle != NULL) xc_evtchn_close(d->xce_handle); - d->xce_handle = -1; + d->xce_handle = NULL; } void enum_domains(void) @@ -933,8 +933,8 @@ void handle_io(void) errno, strerror(errno)); goto out; } - xce_handle = xc_evtchn_open(); - if (xce_handle == -1) { + xce_handle = xc_evtchn_open(NULL, 0); + if (xce_handle == NULL) { dolog(LOG_ERR, "Failed to open xce handle: %d (%s)", errno, strerror(errno)); goto out; @@ -994,7 +994,7 @@ void handle_io(void) if (!next_timeout || d->next_period < next_timeout) next_timeout = d->next_period; - } else if (d->xce_handle != -1) { + } else if (d->xce_handle != NULL) { if (discard_overflowed_data || !d->buffer.max_capacity || d->buffer.size < d->buffer.max_capacity) { @@ -1055,7 +1055,7 @@ void handle_io(void) for (d = dom_head; d; d = n) { n = d->next; if (d->event_count < RATE_LIMIT_ALLOWANCE) { - if (d->xce_handle != -1 && + if (d->xce_handle != NULL && FD_ISSET(xc_evtchn_fd(d->xce_handle), &readfds)) handle_ring_read(d); @@ -1083,9 +1083,9 @@ void handle_io(void) xc_interface_close(xch); xch = 0; } - if (xce_handle != -1) { + if (xce_handle != NULL) { xc_evtchn_close(xce_handle); - xce_handle = -1; + xce_handle = NULL; } log_hv_evtchn = -1; } diff -r 7c6e87f167d4 -r e82cccb0d977 tools/fs-back/fs-backend.c --- a/tools/fs-back/fs-backend.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/fs-back/fs-backend.c Fri Dec 03 09:36:46 2010 +0000 @@ -228,9 +228,9 @@ static void handle_connection(int fronte FS_DEBUG("ERROR: failed to write backend node on xenbus\n"); goto error; } - mount->evth = -1; - mount->evth = xc_evtchn_open(); - if (mount->evth < 0) { + mount->evth = NULL; + mount->evth = xc_evtchn_open(NULL, 0); + if (mount->evth == NULL) { FS_DEBUG("ERROR: Couldn''t open evtchn!\n"); goto error; } @@ -289,7 +289,7 @@ error: xc_gnttab_close(mount->xch, mount->gnth); if (mount->local_evtchn > 0) xc_evtchn_unbind(mount->evth, mount->local_evtchn); - if (mount->evth > 0) + if (mount->evth != NULL) xc_evtchn_close(mount->evth); if (mount->xch) xc_interface_close(mount->xch); @@ -343,8 +343,8 @@ static void await_connections(void) FD_SET(tfd, &fds); ret = select(tfd + 1, &fds, NULL, NULL, &timeout); if (ret < 0) { - FS_DEBUG("fd %d is bogus, closing the related connection\n", tfd); - pointer->evth = fd; + FS_DEBUG("fd %d is bogus, closing the related connection %p\n", tfd, pointer->evth); + /*pointer->evth = fd;*/ terminate_mount_request(pointer); continue; } diff -r 7c6e87f167d4 -r e82cccb0d977 tools/fs-back/fs-backend.h --- a/tools/fs-back/fs-backend.h Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/fs-back/fs-backend.h Fri Dec 03 09:36:46 2010 +0000 @@ -45,7 +45,7 @@ struct fs_mount grant_ref_t grefs[MAX_RING_SIZE]; evtchn_port_t remote_evtchn; xc_interface *xch; /* just for error logging, so a dummy */ - int evth; /* Handle to the event channel */ + xc_evtchn *evth; /* Handle to the event channel */ evtchn_port_t local_evtchn; int gnth; int shared_ring_size; /* in pages */ diff -r 7c6e87f167d4 -r e82cccb0d977 tools/libxc/xc_dom_elfloader.c --- a/tools/libxc/xc_dom_elfloader.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_dom_elfloader.c Fri Dec 03 09:36:46 2010 +0000 @@ -35,7 +35,7 @@ static void log_callback(struct elf_binary *elf, void *caller_data, int iserr, const char *fmt, va_list al) { - struct xc_interface *xch = caller_data; + xc_interface *xch = caller_data; xc_reportv(xch, xch->dombuild_logger ? xch->dombuild_logger : xch->error_handler, @@ -44,7 +44,7 @@ static void log_callback(struct elf_bina fmt, al); } -void xc_elf_set_logfile(struct xc_interface *xch, struct elf_binary *elf, +void xc_elf_set_logfile(xc_interface *xch, struct elf_binary *elf, int verbose) { elf_set_log(elf, log_callback, xch, verbose); } diff -r 7c6e87f167d4 -r e82cccb0d977 tools/libxc/xc_domain_restore.c --- a/tools/libxc/xc_domain_restore.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_domain_restore.c Fri Dec 03 09:36:46 2010 +0000 @@ -49,7 +49,7 @@ struct restore_ctx { #define HEARTBEAT_MS 1000 #ifndef __MINIOS__ -static ssize_t rdexact(struct xc_interface *xch, struct restore_ctx *ctx, +static ssize_t rdexact(xc_interface *xch, struct restore_ctx *ctx, int fd, void* buf, size_t size) { size_t offset = 0; diff -r 7c6e87f167d4 -r e82cccb0d977 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:46 2010 +0000 @@ -68,9 +68,9 @@ int xc_interface_open_core(xc_interface return -1; } -int xc_interface_close_core(xc_interface *xch, int fd) +int xc_interface_close_core(xc_interface *xch) { - return close(fd); + return close(xch->fd); } static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom, @@ -327,42 +327,42 @@ int do_xen_hypercall(xc_interface *xch, #define DEVXEN "/dev/xen/" -int xc_evtchn_open(void) +int xc_evtchn_open_core(xc_evtchn *xce) { return open(DEVXEN "evtchn", O_RDWR); } -int xc_evtchn_close(int xce_handle) +int xc_evtchn_close_core(xc_evtchn *xce) { - return close(xce_handle); + return close(xce->fd); } -int xc_evtchn_fd(int xce_handle) +int xc_evtchn_fd(xc_evtchn *xce) { - return xce_handle; + return xce->fd; } -int xc_evtchn_notify(int xce_handle, evtchn_port_t port) +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) { struct ioctl_evtchn_notify notify; notify.port = port; - return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, ¬ify); + return ioctl(xce->fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } evtchn_port_or_error_t -xc_evtchn_bind_unbound_port(int xce_handle, int domid) +xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) { struct ioctl_evtchn_bind_unbound_port bind; bind.remote_domain = domid; - return ioctl(xce_handle, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); + return ioctl(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); } evtchn_port_or_error_t -xc_evtchn_bind_interdomain(int xce_handle, int domid, +xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, evtchn_port_t remote_port) { struct ioctl_evtchn_bind_interdomain bind; @@ -370,42 +370,42 @@ xc_evtchn_bind_interdomain(int xce_handl bind.remote_domain = domid; bind.remote_port = remote_port; - return ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); + return ioctl(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); } evtchn_port_or_error_t -xc_evtchn_bind_virq(int xce_handle, unsigned int virq) +xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) { struct ioctl_evtchn_bind_virq bind; bind.virq = virq; - return ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind); + return ioctl(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); } -int xc_evtchn_unbind(int xce_handle, evtchn_port_t port) +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) { struct ioctl_evtchn_unbind unbind; unbind.port = port; - return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind); + return ioctl(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind); } evtchn_port_or_error_t -xc_evtchn_pending(int xce_handle) +xc_evtchn_pending(xc_evtchn *xce) { evtchn_port_t port; - if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 ) + if ( read_exact(xce->fd, (char *)&port, sizeof(port)) == -1 ) return -1; return port; } -int xc_evtchn_unmask(int xce_handle, evtchn_port_t port) +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) { - return write_exact(xce_handle, (char *)&port, sizeof(port)); + return write_exact(xce->fd, (char *)&port, sizeof(port)); } /* Optionally flush file to disk and discard page cache */ diff -r 7c6e87f167d4 -r e82cccb0d977 tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:46 2010 +0000 @@ -44,6 +44,9 @@ void minios_evtchn_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; int xc_interface_open_core(xc_interface *xch) @@ -51,9 +54,9 @@ int xc_interface_open_core(xc_interface return alloc_fd(FTYPE_XC); } -int xc_interface_close_core(xc_interface *xch, int fd) +int xc_interface_close_core(xc_interface *xch) { - return close(fd); + return close(xch->fd); } void minios_interface_close_fd(int fd) @@ -169,7 +172,7 @@ int do_xen_hypercall(xc_interface *xch, return call.result; } -int xc_evtchn_open(void) +int xc_evtchn_open_core(xc_evtchn *xce) { int fd = alloc_fd(FTYPE_EVTCHN), i; for (i = 0; i < MAX_EVTCHN_PORTS; i++) { @@ -180,9 +183,9 @@ int xc_evtchn_open(void) return fd; } -int xc_evtchn_close(int xce_handle) +int xc_evtchn_close_core(xc_evtchn *xce) { - return close(xce_handle); + return close(xce->fd); } void minios_evtchn_close_fd(int fd) @@ -194,12 +197,12 @@ void minios_evtchn_close_fd(int fd) files[fd].type = FTYPE_NONE; } -int xc_evtchn_fd(int xce_handle) +int xc_evtchn_fd(xc_evtchn *xce) { - return xce_handle; + return xce->fd; } -int xc_evtchn_notify(int xce_handle, evtchn_port_t port) +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) { int ret; @@ -213,144 +216,144 @@ int xc_evtchn_notify(int xce_handle, evt } /* XXX Note: This is not threadsafe */ -static int port_alloc(int xce_handle) { +static int port_alloc(int fd) { int i; for (i= 0; i < MAX_EVTCHN_PORTS; i++) - if (files[xce_handle].evtchn.ports[i].port == -1) + if (files[fd].evtchn.ports[i].port == -1) break; if (i == MAX_EVTCHN_PORTS) { printf("Too many ports in xc handle\n"); errno = EMFILE; return -1; } - files[xce_handle].evtchn.ports[i].pending = 0; + files[fd].evtchn.ports[i].pending = 0; return i; } static void evtchn_handler(evtchn_port_t port, struct pt_regs *regs, void *data) { - int xce_handle = (intptr_t) data; + int fd = (int)(intptr_t)data; int i; - assert(files[xce_handle].type == FTYPE_EVTCHN); + assert(files[fd].type == FTYPE_EVTCHN); mask_evtchn(port); for (i= 0; i < MAX_EVTCHN_PORTS; i++) - if (files[xce_handle].evtchn.ports[i].port == port) + if (files[fd].evtchn.ports[i].port == port) break; if (i == MAX_EVTCHN_PORTS) { - printk("Unknown port for handle %d\n", xce_handle); + printk("Unknown port for handle %d\n", fd); return; } - files[xce_handle].evtchn.ports[i].pending = 1; - files[xce_handle].read = 1; + files[fd].evtchn.ports[i].pending = 1; + files[fd].read = 1; wake_up(&event_queue); } -evtchn_port_or_error_t xc_evtchn_bind_unbound_port(int xce_handle, int domid) +evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) { int ret, i; evtchn_port_t port; assert(get_current() == main_thread); - i = port_alloc(xce_handle); + i = port_alloc(xce->fd); if (i == -1) return -1; printf("xc_evtchn_bind_unbound_port(%d)", domid); - ret = evtchn_alloc_unbound(domid, evtchn_handler, (void*)(intptr_t)xce_handle, &port); + ret = evtchn_alloc_unbound(domid, evtchn_handler, (void*)(intptr_t)xce->fd, &port); printf(" = %d\n", ret); if (ret < 0) { errno = -ret; return -1; } - files[xce_handle].evtchn.ports[i].bound = 1; - files[xce_handle].evtchn.ports[i].port = port; + files[xce->fd].evtchn.ports[i].bound = 1; + files[xce->fd].evtchn.ports[i].port = port; unmask_evtchn(port); return port; } -evtchn_port_or_error_t xc_evtchn_bind_interdomain(int xce_handle, int domid, +evtchn_port_or_error_t xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, evtchn_port_t remote_port) { evtchn_port_t local_port; int ret, i; assert(get_current() == main_thread); - i = port_alloc(xce_handle); + i = port_alloc(xce->fd); if (i == -1) return -1; printf("xc_evtchn_bind_interdomain(%d, %"PRId32")", domid, remote_port); - ret = evtchn_bind_interdomain(domid, remote_port, evtchn_handler, (void*)(intptr_t)xce_handle, &local_port); + ret = evtchn_bind_interdomain(domid, remote_port, evtchn_handler, (void*)(intptr_t)xce->fd, &local_port); printf(" = %d\n", ret); if (ret < 0) { errno = -ret; return -1; } - files[xce_handle].evtchn.ports[i].bound = 1; - files[xce_handle].evtchn.ports[i].port = local_port; + files[xce->fd].evtchn.ports[i].bound = 1; + files[xce->fd].evtchn.ports[i].port = local_port; unmask_evtchn(local_port); return local_port; } -int xc_evtchn_unbind(int xce_handle, evtchn_port_t port) +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) { int i; for (i = 0; i < MAX_EVTCHN_PORTS; i++) - if (files[xce_handle].evtchn.ports[i].port == port) { - files[xce_handle].evtchn.ports[i].port = -1; + if (files[xce->fd].evtchn.ports[i].port == port) { + files[xce->fd].evtchn.ports[i].port = -1; break; } if (i == MAX_EVTCHN_PORTS) { - printf("Warning: couldn''t find port %"PRId32" for xc handle %x\n", port, xce_handle); + printf("Warning: couldn''t find port %"PRId32" for xc handle %x\n", port, xce->fd); errno = -EINVAL; return -1; } - files[xce_handle].evtchn.ports[i].bound = 0; + files[xce->fd].evtchn.ports[i].bound = 0; unbind_evtchn(port); return 0; } -evtchn_port_or_error_t xc_evtchn_bind_virq(int xce_handle, unsigned int virq) +evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) { evtchn_port_t port; int i; assert(get_current() == main_thread); - i = port_alloc(xce_handle); + i = port_alloc(xce->fd); if (i == -1) return -1; printf("xc_evtchn_bind_virq(%d)", virq); - port = bind_virq(virq, evtchn_handler, (void*)(intptr_t)xce_handle); + port = bind_virq(virq, evtchn_handler, (void*)(intptr_t)xce->fd); if (port < 0) { errno = -port; return -1; } - files[xce_handle].evtchn.ports[i].bound = 1; - files[xce_handle].evtchn.ports[i].port = port; + files[xce->fd].evtchn.ports[i].bound = 1; + files[xce->fd].evtchn.ports[i].port = port; unmask_evtchn(port); return port; } -evtchn_port_or_error_t xc_evtchn_pending(int xce_handle) +evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce) { int i; unsigned long flags; evtchn_port_t ret = -1; local_irq_save(flags); - files[xce_handle].read = 0; + files[xce->fd].read = 0; for (i = 0; i < MAX_EVTCHN_PORTS; i++) { - evtchn_port_t port = files[xce_handle].evtchn.ports[i].port; - if (port != -1 && files[xce_handle].evtchn.ports[i].pending) { + evtchn_port_t port = files[xce->fd].evtchn.ports[i].port; + if (port != -1 && files[xce->fd].evtchn.ports[i].pending) { if (ret == -1) { ret = port; - files[xce_handle].evtchn.ports[i].pending = 0; + files[xce->fd].evtchn.ports[i].pending = 0; } else { - files[xce_handle].read = 1; + files[xce->fd].read = 1; break; } } @@ -359,7 +362,7 @@ evtchn_port_or_error_t xc_evtchn_pending return ret; } -int xc_evtchn_unmask(int xce_handle, evtchn_port_t port) +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) { unmask_evtchn(port); return 0; diff -r 7c6e87f167d4 -r e82cccb0d977 tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:46 2010 +0000 @@ -60,9 +60,9 @@ int xc_interface_open_core(xc_interface return -1; } -int xc_interface_close_core(xc_interface *xch, int fd) +int xc_interface_close_core(xc_interface *xch) { - return close(fd); + return close(xch->fd); } void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, @@ -181,39 +181,39 @@ int do_xen_hypercall(xc_interface *xch, #define EVTCHN_DEV_NAME "/dev/xenevt" -int xc_evtchn_open(void) +int xc_evtchn_open_core(xc_evtchn *xce) { return open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR); } -int xc_evtchn_close(int xce_handle) +int xc_evtchn_close_core(xc_evtchn *xce) { - return close(xce_handle); + return close(xce->fd); } -int xc_evtchn_fd(int xce_handle) +int xc_evtchn_fd(xc_evtchn *xce) { - return xce_handle; + return xce->fd; } -int xc_evtchn_notify(int xce_handle, evtchn_port_t port) +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) { struct ioctl_evtchn_notify notify; notify.port = port; - return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, ¬ify); + return ioctl(xce->fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } evtchn_port_or_error_t -xc_evtchn_bind_unbound_port(int xce_handle, int domid) +xc_evtchn_bind_unbound_port(xc_evtchn * xce, int domid) { struct ioctl_evtchn_bind_unbound_port bind; int ret; bind.remote_domain = domid; - ret = ioctl(xce_handle, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); + ret = ioctl(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); if (ret == 0) return bind.port; else @@ -221,7 +221,7 @@ xc_evtchn_bind_unbound_port(int xce_hand } evtchn_port_or_error_t -xc_evtchn_bind_interdomain(int xce_handle, int domid, +xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, evtchn_port_t remote_port) { struct ioctl_evtchn_bind_interdomain bind; @@ -230,31 +230,31 @@ xc_evtchn_bind_interdomain(int xce_handl bind.remote_domain = domid; bind.remote_port = remote_port; - ret = ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); + ret = ioctl(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); if (ret == 0) return bind.port; else return -1; } -int xc_evtchn_unbind(int xce_handle, evtchn_port_t port) +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) { struct ioctl_evtchn_unbind unbind; unbind.port = port; - return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind); + return ioctl(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind); } evtchn_port_or_error_t -xc_evtchn_bind_virq(int xce_handle, unsigned int virq) +xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) { struct ioctl_evtchn_bind_virq bind; int err; bind.virq = virq; - err = ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind); + err = ioctl(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); if (err) return -1; else @@ -262,19 +262,19 @@ xc_evtchn_bind_virq(int xce_handle, unsi } evtchn_port_or_error_t -xc_evtchn_pending(int xce_handle) +xc_evtchn_pending(xc_evtchn *xce) { evtchn_port_t port; - if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 ) + if ( read_exact(xce->fd, (char *)&port, sizeof(port)) == -1 ) return -1; return port; } -int xc_evtchn_unmask(int xce_handle, evtchn_port_t port) +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) { - return write_exact(xce_handle, (char *)&port, sizeof(port)); + return write_exact(xce->fd, (char *)&port, sizeof(port)); } /* Optionally flush file to disk and discard page cache */ diff -r 7c6e87f167d4 -r e82cccb0d977 tools/libxc/xc_private.c --- a/tools/libxc/xc_private.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_private.c Fri Dec 03 09:36:46 2010 +0000 @@ -27,11 +27,15 @@ #include <pthread.h> #include <assert.h> -xc_interface *xc_interface_open(xentoollog_logger *logger, - xentoollog_logger *dombuild_logger, - unsigned open_flags) { - xc_interface xch_buf, *xch = &xch_buf; +static struct xc_interface_core *xc_interface_open_common(xentoollog_logger *logger, + xentoollog_logger *dombuild_logger, + unsigned open_flags, + enum xc_interface_type type, + int (*open_core)(struct xc_interface_core *xch)) +{ + struct xc_interface_core xch_buf, *xch = &xch_buf; + xch->type = type; xch->flags = open_flags; xch->fd = -1; xch->dombuild_logger_file = 0; @@ -57,7 +61,7 @@ xc_interface *xc_interface_open(xentooll *xch = xch_buf; if (!(open_flags & XC_OPENFLAG_DUMMY)) { - xch->fd = xc_interface_open_core(xch); + xch->fd = open_core(xch); if (xch->fd < 0) goto err; } @@ -70,7 +74,7 @@ xc_interface *xc_interface_open(xentooll return 0; } -int xc_interface_close(xc_interface *xch) +static int xc_interface_close_common(xc_interface *xch, int (*close_core)(struct xc_interface_core *xch)) { int rc = 0; @@ -78,12 +82,37 @@ int xc_interface_close(xc_interface *xch xtl_logger_destroy(xch->error_handler_tofree); if (xch->fd >= 0) { - rc = xc_interface_close_core(xch, xch->fd); + rc = close_core(xch); if (rc) PERROR("Could not close hypervisor interface"); } free(xch); return rc; +} + +xc_interface *xc_interface_open(xentoollog_logger *logger, + xentoollog_logger *dombuild_logger, + unsigned open_flags) +{ + return xc_interface_open_common(logger, dombuild_logger, open_flags, + XC_INTERFACE_PRIVCMD, &xc_interface_open_core); +} + +int xc_interface_close(xc_interface *xch) +{ + return xc_interface_close_common(xch, &xc_interface_close_core); +} + +xc_evtchn *xc_evtchn_open(xentoollog_logger *logger, + unsigned open_flags) +{ + return xc_interface_open_common(logger, NULL, open_flags, + XC_INTERFACE_EVTCHN, &xc_evtchn_open_core); +} + +int xc_evtchn_close(xc_evtchn *xce) +{ + return xc_interface_close_common(xce, &xc_evtchn_close_core); } static pthread_key_t errbuf_pkey; diff -r 7c6e87f167d4 -r e82cccb0d977 tools/libxc/xc_private.h --- a/tools/libxc/xc_private.h Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_private.h Fri Dec 03 09:36:46 2010 +0000 @@ -65,7 +65,13 @@ */ #define MAX_PAGECACHE_USAGE (4*1024) -struct xc_interface { +enum xc_interface_type { + XC_INTERFACE_PRIVCMD, + XC_INTERFACE_EVTCHN, +}; + +struct xc_interface_core { + enum xc_interface_type type; int fd; int flags; xentoollog_logger *error_handler, *error_handler_tofree; @@ -257,8 +263,11 @@ static inline int do_sysctl(xc_interface int do_memory_op(xc_interface *xch, int cmd, void *arg, size_t len); -int xc_interface_open_core(xc_interface *xch); /* returns fd, logs errors */ -int xc_interface_close_core(xc_interface *xch, int fd); /* no logging */ +int xc_interface_open_core(struct xc_interface_core *xch); /* returns fd, logs errors */ +int xc_interface_close_core(struct xc_interface_core *xch); /* no logging */ + +int xc_evtchn_open_core(struct xc_interface_core *xce); /* returns fd, logs errors */ +int xc_evtchn_close_core(struct xc_interface_core *xce); /* no logging */ void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom, size_t size, int prot, size_t chunksize, diff -r 7c6e87f167d4 -r e82cccb0d977 tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:46 2010 +0000 @@ -167,7 +167,7 @@ int do_xen_hypercall(xc_interface *xch, (unsigned long)hypercall); } -int xc_evtchn_open(void) +int xc_evtchn_open_core(xc_evtchn *xce) { int fd; @@ -180,37 +180,37 @@ int xc_evtchn_open(void) return fd; } -int xc_evtchn_close(int xce_handle) +int xc_evtchn_close_core(xc_evtchn *xce) { - return close(xce_handle); + return close(xce->fd); } -int xc_evtchn_fd(int xce_handle) +int xc_evtchn_fd(xc_evtchn *xce) { - return xce_handle; + return xce->fd; } -int xc_evtchn_notify(int xce_handle, evtchn_port_t port) +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) { struct ioctl_evtchn_notify notify; notify.port = port; - return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, ¬ify); + return ioctl(xce->fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } evtchn_port_or_error_t -xc_evtchn_bind_unbound_port(int xce_handle, int domid) +xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) { struct ioctl_evtchn_bind_unbound_port bind; bind.remote_domain = domid; - return ioctl(xce_handle, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); + return ioctl(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); } evtchn_port_or_error_t -xc_evtchn_bind_interdomain(int xce_handle, int domid, +xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, evtchn_port_t remote_port) { struct ioctl_evtchn_bind_interdomain bind; @@ -218,42 +218,42 @@ xc_evtchn_bind_interdomain(int xce_handl bind.remote_domain = domid; bind.remote_port = remote_port; - return ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); + return ioctl(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); } evtchn_port_or_error_t -xc_evtchn_bind_virq(int xce_handle, unsigned int virq) +xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) { struct ioctl_evtchn_bind_virq bind; bind.virq = virq; - return ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind); + return ioctl(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); } -int xc_evtchn_unbind(int xce_handle, evtchn_port_t port) +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) { struct ioctl_evtchn_unbind unbind; unbind.port = port; - return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind); + return ioctl(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind); } evtchn_port_or_error_t -xc_evtchn_pending(int xce_handle) +xc_evtchn_pending(xc_evtchn *xce) { evtchn_port_t port; - if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 ) + if ( read_exact(xce->fd, (char *)&port, sizeof(port)) == -1 ) return -1; return port; } -int xc_evtchn_unmask(int xce_handle, evtchn_port_t port) +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) { - return write_exact(xce_handle, (char *)&port, sizeof(port)); + return write_exact(xce->fd, (char *)&port, sizeof(port)); } /* Optionally flush file to disk and discard page cache */ diff -r 7c6e87f167d4 -r e82cccb0d977 tools/libxc/xc_suspend.c --- a/tools/libxc/xc_suspend.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_suspend.c Fri Dec 03 09:36:46 2010 +0000 @@ -75,7 +75,7 @@ static int unlock_suspend_event(xc_inter return -EPERM; } -int xc_await_suspend(xc_interface *xch, int xce, int suspend_evtchn) +int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn) { int rc; @@ -94,7 +94,7 @@ int xc_await_suspend(xc_interface *xch, return 0; } -int xc_suspend_evtchn_release(xc_interface *xch, int xce, int domid, int suspend_evtchn) +int xc_suspend_evtchn_release(xc_interface *xch, xc_evtchn *xce, int domid, int suspend_evtchn) { if (suspend_evtchn >= 0) xc_evtchn_unbind(xce, suspend_evtchn); @@ -102,7 +102,7 @@ int xc_suspend_evtchn_release(xc_interfa return unlock_suspend_event(xch, domid); } -int xc_suspend_evtchn_init(xc_interface *xch, int xce, int domid, int port) +int xc_suspend_evtchn_init(xc_interface *xch, xc_evtchn *xce, int domid, int port) { int rc, suspend_evtchn = -1; diff -r 7c6e87f167d4 -r e82cccb0d977 tools/libxc/xenctrl.h --- a/tools/libxc/xenctrl.h Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xenctrl.h Fri Dec 03 09:36:46 2010 +0000 @@ -104,7 +104,8 @@ * the callback. */ -typedef struct xc_interface xc_interface; +typedef struct xc_interface_core xc_interface; +typedef struct xc_interface_core xc_evtchn; typedef enum xc_error_code xc_error_code; @@ -826,38 +827,38 @@ int xc_evtchn_status(xc_interface *xch, * * Before Xen pre-4.1 this function would sometimes report errors with perror. */ -int xc_evtchn_open(void); +xc_evtchn *xc_evtchn_open(xentoollog_logger *logger, + unsigned open_flags); /* * Close a handle previously allocated with xc_evtchn_open(). */ -int xc_evtchn_close(int xce_handle); +int xc_evtchn_close(xc_evtchn *xce); /* - * Return an fd that can be select()ed on for further calls to - * xc_evtchn_pending(). + * Return an fd that can be select()ed on. */ -int xc_evtchn_fd(int xce_handle); +int xc_evtchn_fd(xc_evtchn *xce); /* * Notify the given event channel. Returns -1 on failure, in which case * errno will be set appropriately. */ -int xc_evtchn_notify(int xce_handle, evtchn_port_t port); +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port); /* * Returns a new event port awaiting interdomain connection from the given * domain ID, or -1 on failure, in which case errno will be set appropriately. */ evtchn_port_or_error_t -xc_evtchn_bind_unbound_port(int xce_handle, int domid); +xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid); /* * Returns a new event port bound to the remote port for the given domain ID, * or -1 on failure, in which case errno will be set appropriately. */ evtchn_port_or_error_t -xc_evtchn_bind_interdomain(int xce_handle, int domid, +xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, evtchn_port_t remote_port); /* @@ -865,26 +866,26 @@ xc_evtchn_bind_interdomain(int xce_handl * the VIRQ, or -1 on failure, in which case errno will be set appropriately. */ evtchn_port_or_error_t -xc_evtchn_bind_virq(int xce_handle, unsigned int virq); +xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq); /* * Unbind the given event channel. Returns -1 on failure, in which case errno * will be set appropriately. */ -int xc_evtchn_unbind(int xce_handle, evtchn_port_t port); +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port); /* * Return the next event channel to become pending, or -1 on failure, in which * case errno will be set appropriately. */ evtchn_port_or_error_t -xc_evtchn_pending(int xce_handle); +xc_evtchn_pending(xc_evtchn *xce); /* * Unmask the given event channel. Returns -1 on failure, in which case errno * will be set appropriately. */ -int xc_evtchn_unmask(int xce_handle, evtchn_port_t port); +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port); int xc_physdev_pci_access_modify(xc_interface *xch, uint32_t domid, @@ -1754,7 +1755,7 @@ int xc_flask_setavc_threshold(xc_interfa int xc_flask_setavc_threshold(xc_interface *xc_handle, int threshold); struct elf_binary; -void xc_elf_set_logfile(struct xc_interface *xch, struct elf_binary *elf, +void xc_elf_set_logfile(xc_interface *xch, struct elf_binary *elf, int verbose); /* Useful for callers who also use libelf. */ diff -r 7c6e87f167d4 -r e82cccb0d977 tools/libxc/xenguest.h --- a/tools/libxc/xenguest.h Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xenguest.h Fri Dec 03 09:36:46 2010 +0000 @@ -173,11 +173,11 @@ int xc_hvm_build_mem(xc_interface *xch, const char *image_buffer, unsigned long image_size); -int xc_suspend_evtchn_release(xc_interface *xch, int xce, int domid, int suspend_evtchn); +int xc_suspend_evtchn_release(xc_interface *xch, xc_evtchn *xce, int domid, int suspend_evtchn); -int xc_suspend_evtchn_init(xc_interface *xch, int xce, int domid, int port); +int xc_suspend_evtchn_init(xc_interface *xch, xc_evtchn *xce, int domid, int port); -int xc_await_suspend(xc_interface *xch, int xce, int suspend_evtchn); +int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn); int xc_get_bit_size(xc_interface *xch, const char *image_name, const char *cmdline, diff -r 7c6e87f167d4 -r e82cccb0d977 tools/libxl/libxl_dom.c --- a/tools/libxl/libxl_dom.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxl/libxl_dom.c Fri Dec 03 09:36:46 2010 +0000 @@ -313,7 +313,7 @@ int libxl__domain_restore_common(libxl_c struct suspendinfo { libxl__gc *gc; - int xce; /* event channel handle */ + xc_evtchn *xce; /* event channel handle */ int suspend_eventchn; int domid; int hvm; @@ -417,11 +417,11 @@ int libxl__domain_suspend_common(libxl_c si.gc = &gc; si.suspend_eventchn = -1; - si.xce = xc_evtchn_open(); - if (si.xce < 0) + si.xce = xc_evtchn_open(NULL, 0); + if (si.xce == NULL) goto out; - - if (si.xce > 0) { + else + { port = xs_suspend_evtchn_port(si.domid); if (port >= 0) { @@ -445,7 +445,7 @@ int libxl__domain_suspend_common(libxl_c if (si.suspend_eventchn > 0) xc_suspend_evtchn_release(ctx->xch, si.xce, domid, si.suspend_eventchn); - if (si.xce > 0) + if (si.xce != NULL) xc_evtchn_close(si.xce); out: diff -r 7c6e87f167d4 -r e82cccb0d977 tools/misc/xen-hptool.c --- a/tools/misc/xen-hptool.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/misc/xen-hptool.c Fri Dec 03 09:36:46 2010 +0000 @@ -98,7 +98,7 @@ static int hp_mem_query_func(int argc, c extern int xs_suspend_evtchn_port(int domid); -static int suspend_guest(xc_interface *xch, int xce, int domid, int *evtchn) +static int suspend_guest(xc_interface *xch, xc_evtchn *xce, int domid, int *evtchn) { int port, rc, suspend_evtchn = -1; @@ -192,10 +192,11 @@ static int hp_mem_offline_func(int argc, } else if (status & PG_OFFLINE_OWNED) { - int result, xce, suspend_evtchn = -1; - xce = xc_evtchn_open(); + int result, suspend_evtchn = -1; + xc_evtchn *xce; + xce = xc_evtchn_open(NULL, 0); - if (xce < 0) + if (xce == NULL) { fprintf(stderr, "When exchange page, fail" " to open evtchn\n"); diff -r 7c6e87f167d4 -r e82cccb0d977 tools/python/xen/lowlevel/checkpoint/checkpoint.h --- a/tools/python/xen/lowlevel/checkpoint/checkpoint.h Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/python/xen/lowlevel/checkpoint/checkpoint.h Fri Dec 03 09:36:46 2010 +0000 @@ -19,7 +19,7 @@ typedef enum { typedef struct { xc_interface *xch; - int xce; /* event channel handle */ + xc_evtchn *xce; /* event channel handle */ struct xs_handle* xsh; /* xenstore handle */ int watching_shutdown; /* state of watch on @releaseDomain */ diff -r 7c6e87f167d4 -r e82cccb0d977 tools/python/xen/lowlevel/checkpoint/libcheckpoint.c --- a/tools/python/xen/lowlevel/checkpoint/libcheckpoint.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/python/xen/lowlevel/checkpoint/libcheckpoint.c Fri Dec 03 09:36:46 2010 +0000 @@ -48,7 +48,7 @@ void checkpoint_init(checkpoint_state* s void checkpoint_init(checkpoint_state* s) { s->xch = NULL; - s->xce = -1; + s->xce = NULL; s->xsh = NULL; s->watching_shutdown = 0; @@ -89,8 +89,8 @@ int checkpoint_open(checkpoint_state* s, return -1; } - s->xce = xc_evtchn_open(); - if (s->xce < 0) { + s->xce = xc_evtchn_open(NULL, 0); + if (s->xce == NULL) { checkpoint_close(s); s->errstr = "could not open event channel handle"; @@ -149,9 +149,9 @@ void checkpoint_close(checkpoint_state* xc_interface_close(s->xch); s->xch = NULL; } - if (s->xce >= 0) { + if (s->xce != NULL) { xc_evtchn_close(s->xce); - s->xce = -1; + s->xce = NULL; } if (s->xsh) { xs_daemon_close(s->xsh); @@ -360,7 +360,7 @@ static void release_suspend_evtchn(check static void release_suspend_evtchn(checkpoint_state *s) { /* TODO: teach xen to clean up if port is unbound */ - if (s->xce >= 0 && s->suspend_evtchn >= 0) { + if (s->xce != NULL && s->suspend_evtchn >= 0) { xc_suspend_evtchn_release(s->xch, s->xce, s->domid, s->suspend_evtchn); s->suspend_evtchn = -1; } diff -r 7c6e87f167d4 -r e82cccb0d977 tools/xcutils/xc_save.c --- a/tools/xcutils/xc_save.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/xcutils/xc_save.c Fri Dec 03 09:36:46 2010 +0000 @@ -25,7 +25,7 @@ static struct suspendinfo { xc_interface *xch; - int xce; /* event channel handle */ + xc_evtchn *xce; /* event channel handle */ int suspend_evtchn; int domid; unsigned int flags; @@ -183,13 +183,12 @@ main(int argc, char **argv) max_f = atoi(argv[4]); si.flags = atoi(argv[5]); - si.suspend_evtchn = si.xce = -1; + si.suspend_evtchn = -1; - si.xce = xc_evtchn_open(); - if (si.xce < 0) + si.xce = xc_evtchn_open(NULL, 0); + if (si.xce == NULL) warnx("failed to open event channel handle"); - - if (si.xce > 0) + else { port = xs_suspend_evtchn_port(si.domid); diff -r 7c6e87f167d4 -r e82cccb0d977 tools/xenmon/xenbaked.c --- a/tools/xenmon/xenbaked.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/xenmon/xenbaked.c Fri Dec 03 09:36:46 2010 +0000 @@ -268,7 +268,7 @@ static void log_event(int event_id) } int virq_port; -int xce_handle = -1; +xc_evtchn *xce_handle = NULL; /* Returns the event channel handle. */ /* Stolen from xenstore code */ @@ -280,16 +280,16 @@ static int eventchn_init(void) if (0) return -1; - xce_handle = xc_evtchn_open(); + xce_handle = xc_evtchn_open(NULL, 0); - if (xce_handle < 0) + if (xce_handle == NULL) perror("Failed to open evtchn device"); if ((rc = xc_evtchn_bind_virq(xce_handle, VIRQ_TBUF)) == -1) perror("Failed to bind to domain exception virq port"); virq_port = rc; - return xce_handle; + return xce_handle == NULL ? -1 : 0; } static void wait_for_event(void) @@ -300,7 +300,7 @@ static void wait_for_event(void) struct timeval tv; int evtchn_fd; - if (xce_handle < 0) { + if (xce_handle == NULL) { nanosleep(&opts.poll_sleep, NULL); return; } diff -r 7c6e87f167d4 -r e82cccb0d977 tools/xenpaging/mem_event.h --- a/tools/xenpaging/mem_event.h Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/xenpaging/mem_event.h Fri Dec 03 09:36:46 2010 +0000 @@ -40,7 +40,7 @@ typedef struct mem_event { domid_t domain_id; - int xce_handle; + xc_evtchn *xce_handle; int port; mem_event_back_ring_t back_ring; mem_event_shared_page_t *shared_page; diff -r 7c6e87f167d4 -r e82cccb0d977 tools/xenpaging/xc.c --- a/tools/xenpaging/xc.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/xenpaging/xc.c Fri Dec 03 09:36:46 2010 +0000 @@ -65,9 +65,9 @@ int xc_mem_paging_flush_ioemu_cache(domi return rc; } -int xc_wait_for_event_or_timeout(xc_interface *xch, int xce_handle, unsigned long ms) +int xc_wait_for_event_or_timeout(xc_interface *xch, xc_evtchn *xce, unsigned long ms) { - struct pollfd fd = { .fd = xce_handle, .events = POLLIN | POLLERR }; + struct pollfd fd = { .fd = xc_evtchn_fd(xce), .events = POLLIN | POLLERR }; int port; int rc; @@ -83,14 +83,14 @@ int xc_wait_for_event_or_timeout(xc_inte if ( rc == 1 ) { - port = xc_evtchn_pending(xce_handle); + port = xc_evtchn_pending(xce); if ( port == -1 ) { ERROR("Failed to read port from event channel"); goto err; } - rc = xc_evtchn_unmask(xce_handle, port); + rc = xc_evtchn_unmask(xce, port); if ( rc != 0 ) { ERROR("Failed to unmask event channel port"); @@ -106,9 +106,9 @@ int xc_wait_for_event_or_timeout(xc_inte return -errno; } -int xc_wait_for_event(xc_interface *xch, int xce_handle) +int xc_wait_for_event(xc_interface *xch, xc_evtchn *xce) { - return xc_wait_for_event_or_timeout(xch, xce_handle, -1); + return xc_wait_for_event_or_timeout(xch, xce, -1); } int xc_get_platform_info(xc_interface *xc_handle, domid_t domain_id, diff -r 7c6e87f167d4 -r e82cccb0d977 tools/xenpaging/xc.h --- a/tools/xenpaging/xc.h Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/xenpaging/xc.h Fri Dec 03 09:36:46 2010 +0000 @@ -53,8 +53,8 @@ int alloc_bitmap(unsigned long **bitmap, int alloc_bitmap(unsigned long **bitmap, unsigned long bitmap_size); int xc_mem_paging_flush_ioemu_cache(domid_t domain_id); -int xc_wait_for_event(xc_interface *xch, int xce_handle); -int xc_wait_for_event_or_timeout(xc_interface *xch, int xce_handle, unsigned long ms); +int xc_wait_for_event(xc_interface *xch, xc_evtchn *xce); +int xc_wait_for_event_or_timeout(xc_interface *xch, xc_evtchn *xce, unsigned long ms); int xc_get_platform_info(xc_interface *xc_handle, domid_t domain_id, xc_platform_info_t *platform_info); diff -r 7c6e87f167d4 -r e82cccb0d977 tools/xenpaging/xenpaging.c --- a/tools/xenpaging/xenpaging.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/xenpaging/xenpaging.c Fri Dec 03 09:36:46 2010 +0000 @@ -148,8 +148,8 @@ xenpaging_t *xenpaging_init(xc_interface } /* Open event channel */ - paging->mem_event.xce_handle = xc_evtchn_open(); - if ( paging->mem_event.xce_handle < 0 ) + paging->mem_event.xce_handle = xc_evtchn_open(NULL, 0); + if ( paging->mem_event.xce_handle == NULL ) { ERROR("Failed to open event channel"); goto err; @@ -274,7 +274,7 @@ int xenpaging_teardown(xc_interface *xch { ERROR("Error closing event channel"); } - paging->mem_event.xce_handle = -1; + paging->mem_event.xce_handle = NULL; /* Close connection to Xen */ rc = xc_interface_close(paging->xc_handle); diff -r 7c6e87f167d4 -r e82cccb0d977 tools/xenstore/xenstored_core.c --- a/tools/xenstore/xenstored_core.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/xenstore/xenstored_core.c Fri Dec 03 09:36:46 2010 +0000 @@ -52,7 +52,7 @@ #include "hashtable.h" -extern int xce_handle; /* in xenstored_domain.c */ +extern xc_evtchn *xce_handle; /* in xenstored_domain.c */ static bool verbose = false; LIST_HEAD(connections); @@ -323,7 +323,7 @@ static int initialize_set(fd_set *inset, set_fd(ro_sock, inset, &max); set_fd(reopen_log_pipe[0], inset, &max); - if (xce_handle != -1) + if (xce_handle != NULL) set_fd(xc_evtchn_fd(xce_handle), inset, &max); list_for_each_entry(conn, &connections, list) { @@ -1901,7 +1901,7 @@ int main(int argc, char *argv[]) signal(SIGHUP, trigger_reopen_log); - if (xce_handle != -1) + if (xce_handle != NULL) evtchn_fd = xc_evtchn_fd(xce_handle); /* Get ready to listen to the tools. */ diff -r 7c6e87f167d4 -r e82cccb0d977 tools/xenstore/xenstored_domain.c --- a/tools/xenstore/xenstored_domain.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/xenstore/xenstored_domain.c Fri Dec 03 09:36:46 2010 +0000 @@ -36,7 +36,7 @@ static xc_interface **xc_handle; static xc_interface **xc_handle; static evtchn_port_t virq_port; -int xce_handle = -1; +xc_evtchn *xce_handle = NULL; struct domain { @@ -580,8 +580,7 @@ static int dom0_init(void) return 0; } -/* Returns the event channel handle. */ -int domain_init(void) +void domain_init(void) { int rc; @@ -595,9 +594,9 @@ int domain_init(void) talloc_set_destructor(xc_handle, close_xc_handle); - xce_handle = xc_evtchn_open(); + xce_handle = xc_evtchn_open(NULL, 0); - if (xce_handle < 0) + if (xce_handle == NULL) barf_perror("Failed to open evtchn device"); if (dom0_init() != 0) @@ -606,8 +605,6 @@ int domain_init(void) if ((rc = xc_evtchn_bind_virq(xce_handle, VIRQ_DOM_EXC)) == -1) barf_perror("Failed to bind to domain exception virq port"); virq_port = rc; - - return xce_handle; } void domain_entry_inc(struct connection *conn, struct node *node) diff -r 7c6e87f167d4 -r e82cccb0d977 tools/xenstore/xenstored_domain.h --- a/tools/xenstore/xenstored_domain.h Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/xenstore/xenstored_domain.h Fri Dec 03 09:36:46 2010 +0000 @@ -40,8 +40,7 @@ void do_set_target(struct connection *co /* domid */ void do_get_domain_path(struct connection *conn, const char *domid_str); -/* Returns the event channel handle */ -int domain_init(void); +void domain_init(void); /* Returns the implicit path of a connection (only domains have this) */ const char *get_implicit_path(const struct connection *conn); diff -r 7c6e87f167d4 -r e82cccb0d977 tools/xentrace/xentrace.c --- a/tools/xentrace/xentrace.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/xentrace/xentrace.c Fri Dec 03 09:36:46 2010 +0000 @@ -73,7 +73,7 @@ int interrupted = 0; /* gets set if we g int interrupted = 0; /* gets set if we get a SIGHUP */ static xc_interface *xc_handle; -static int event_fd = -1; +static xc_evtchn *xce_handle = NULL; static int virq_port = -1; static int outfd = 1; @@ -576,14 +576,13 @@ static void event_init(void) { int rc; - rc = xc_evtchn_open(); - if (rc < 0) { + xce_handle = xc_evtchn_open(NULL, 0); + if (xce_handle == NULL) { perror("event channel open"); exit(EXIT_FAILURE); } - event_fd = rc; - rc = xc_evtchn_bind_virq(event_fd, VIRQ_TBUF); + rc = xc_evtchn_bind_virq(xce_handle, VIRQ_TBUF); if (rc == -1) { PERROR("failed to bind to VIRQ port"); exit(EXIT_FAILURE); @@ -598,7 +597,7 @@ static void wait_for_event_or_timeout(un static void wait_for_event_or_timeout(unsigned long milliseconds) { int rc; - struct pollfd fd = { .fd = event_fd, + struct pollfd fd = { .fd = xc_evtchn_fd(xce_handle), .events = POLLIN | POLLERR }; int port; @@ -611,7 +610,7 @@ static void wait_for_event_or_timeout(un } if (rc == 1) { - port = xc_evtchn_pending(event_fd); + port = xc_evtchn_pending(xce_handle); if (port == -1) { PERROR("failed to read port from evtchn"); exit(EXIT_FAILURE); @@ -622,7 +621,7 @@ static void wait_for_event_or_timeout(un port, virq_port); exit(EXIT_FAILURE); } - rc = xc_evtchn_unmask(event_fd, port); + rc = xc_evtchn_unmask(xce_handle, port); if (rc == -1) { PERROR("failed to write port to evtchn"); exit(EXIT_FAILURE); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 03 of 25] libxc: convert gnttab interfaces to use an opaque handle type
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369006 0 # Node ID d210f8cc84b3b228017afcca2158ccf1e06c1430 # Parent e82cccb0d9770e51f9785f109ea11d704ae4df45 libxc: convert gnttab interfaces to use an opaque handle type The xc_interface previously passed to xc_gnttab_* was only used for logging which can now be done via the xc_gnttab handle instead. This makes the interface consistent with the changes made to the main interface in 21483:779c0ef9682c. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r e82cccb0d977 -r d210f8cc84b3 tools/fs-back/fs-backend.c --- a/tools/fs-back/fs-backend.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/fs-back/fs-backend.c Fri Dec 03 09:36:46 2010 +0000 @@ -168,9 +168,8 @@ void terminate_mount_request(struct fs_m } xenbus_write_backend_state(mount, STATE_CLOSED); - xc_gnttab_munmap(mount->xch, mount->gnth, - mount->ring.sring, mount->shared_ring_size); - xc_gnttab_close(mount->xch, mount->gnth); + xc_gnttab_munmap(mount->gnth, mount->ring.sring, mount->shared_ring_size); + xc_gnttab_close(mount->gnth); xc_evtchn_unbind(mount->evth, mount->local_evtchn); xc_evtchn_close(mount->evth); @@ -242,15 +241,15 @@ static void handle_connection(int fronte FS_DEBUG("ERROR: Couldn''t bind evtchn!\n"); goto error; } - mount->gnth = -1; - mount->gnth = xc_gnttab_open(mount->xch); - if (mount->gnth < 0) { + mount->gnth = NULL; + mount->gnth = xc_gnttab_open(NULL, 0); + if (mount->gnth == NULL) { FS_DEBUG("ERROR: Couldn''t open gnttab!\n"); goto error; } for(i=0; i<mount->shared_ring_size; i++) dom_ids[i] = mount->dom_id; - sring = xc_gnttab_map_grant_refs(mount->xch, mount->gnth, + sring = xc_gnttab_map_grant_refs(mount->gnth, mount->shared_ring_size, dom_ids, mount->grefs, @@ -283,10 +282,9 @@ error: error: xenbus_write_backend_state(mount, STATE_CLOSED); if (sring) - xc_gnttab_munmap(mount->xch, mount->gnth, - mount->ring.sring, mount->shared_ring_size); - if (mount->gnth > 0) - xc_gnttab_close(mount->xch, mount->gnth); + xc_gnttab_munmap(mount->gnth, mount->ring.sring, mount->shared_ring_size); + if (mount->gnth != NULL) + xc_gnttab_close(mount->gnth); if (mount->local_evtchn > 0) xc_evtchn_unbind(mount->evth, mount->local_evtchn); if (mount->evth != NULL) diff -r e82cccb0d977 -r d210f8cc84b3 tools/fs-back/fs-backend.h --- a/tools/fs-back/fs-backend.h Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/fs-back/fs-backend.h Fri Dec 03 09:36:46 2010 +0000 @@ -47,7 +47,7 @@ struct fs_mount xc_interface *xch; /* just for error logging, so a dummy */ xc_evtchn *evth; /* Handle to the event channel */ evtchn_port_t local_evtchn; - int gnth; + xc_gnttab *gnth; int shared_ring_size; /* in pages */ struct fsif_back_ring ring; int nr_entries; diff -r e82cccb0d977 -r d210f8cc84b3 tools/fs-back/fs-ops.c --- a/tools/fs-back/fs-ops.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/fs-back/fs-ops.c Fri Dec 03 09:36:46 2010 +0000 @@ -75,7 +75,7 @@ static void dispatch_file_open(struct fs FS_DEBUG("Dispatching file open operation (gref=%d).\n", req->u.fopen.gref); /* Read the request, and open file */ - file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth, + file_name = xc_gnttab_map_grant_ref(mount->gnth, mount->dom_id, req->u.fopen.gref, PROT_READ); @@ -99,7 +99,7 @@ static void dispatch_file_open(struct fs } } out: - if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) { + if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) { FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno); terminate_mount_request(mount); } @@ -159,7 +159,7 @@ static void dispatch_file_read(struct fs assert(req->u.fread.len > 0); count = (req->u.fread.len - 1) / XC_PAGE_SIZE + 1; assert(count <= FSIF_NR_READ_GNTS); - buf = xc_gnttab_map_domain_grant_refs(mount->xch, mount->gnth, + buf = xc_gnttab_map_domain_grant_refs(mount->gnth, count, mount->dom_id, req->u.fread.grefs, @@ -192,8 +192,7 @@ static void dispatch_file_read(struct fs priv_req->aiocb.aio_sigevent.sigev_value.sival_ptr = priv_req; if (aio_read(&priv_req->aiocb) < 0) { FS_DEBUG("ERROR: aio_read failed errno=%d\n", errno); - xc_gnttab_munmap(mount->xch, mount->gnth, - priv_req->page, priv_req->count); + xc_gnttab_munmap(mount->gnth, priv_req->page, priv_req->count); terminate_mount_request(mount); } @@ -209,7 +208,7 @@ static void end_file_read(struct fs_moun uint16_t req_id; /* Release the grant */ - if (xc_gnttab_munmap(mount->xch, mount->gnth, + if (xc_gnttab_munmap(mount->gnth, priv_req->page, priv_req->count) != 0) { FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno); terminate_mount_request(mount); @@ -236,7 +235,7 @@ static void dispatch_file_write(struct f assert(req->u.fwrite.len > 0); count = (req->u.fwrite.len - 1) / XC_PAGE_SIZE + 1; assert(count <= FSIF_NR_WRITE_GNTS); - buf = xc_gnttab_map_domain_grant_refs(mount->xch, mount->gnth, + buf = xc_gnttab_map_domain_grant_refs(mount->gnth, count, mount->dom_id, req->u.fwrite.grefs, @@ -269,7 +268,7 @@ static void dispatch_file_write(struct f priv_req->aiocb.aio_sigevent.sigev_value.sival_ptr = priv_req; if (aio_write(&priv_req->aiocb) < 0) { FS_DEBUG("ERROR: aio_write failed errno=%d\n", errno); - xc_gnttab_munmap(mount->xch, mount->gnth, + xc_gnttab_munmap(mount->gnth, priv_req->page, priv_req->count); terminate_mount_request(mount); } @@ -287,7 +286,7 @@ static void end_file_write(struct fs_mou uint16_t req_id; /* Release the grant */ - if (xc_gnttab_munmap(mount->xch, mount->gnth, + if (xc_gnttab_munmap(mount->gnth, priv_req->page, priv_req->count) != 0) { FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno); terminate_mount_request(mount); @@ -395,7 +394,7 @@ static void dispatch_remove(struct fs_mo FS_DEBUG("Dispatching remove operation (gref=%d).\n", req->u.fremove.gref); /* Read the request, and open file */ - file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth, + file_name = xc_gnttab_map_grant_ref(mount->gnth, mount->dom_id, req->u.fremove.gref, PROT_READ); @@ -409,7 +408,7 @@ static void dispatch_remove(struct fs_mo ret = remove(file_name); } FS_DEBUG("Got ret: %d\n", ret); - if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) { + if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) { FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno); terminate_mount_request(mount); } @@ -437,7 +436,7 @@ static void dispatch_rename(struct fs_mo FS_DEBUG("Dispatching rename operation (gref=%d).\n", req->u.fremove.gref); /* Read the request, and open file */ - buf = xc_gnttab_map_grant_ref(mount->xch, mount->gnth, + buf = xc_gnttab_map_grant_ref(mount->gnth, mount->dom_id, req->u.frename.gref, PROT_READ); @@ -455,7 +454,7 @@ static void dispatch_rename(struct fs_mo ret = rename(old_file_name, new_file_name); } FS_DEBUG("Got ret: %d\n", ret); - if (xc_gnttab_munmap(mount->xch, mount->gnth, buf, 1) != 0) { + if (xc_gnttab_munmap(mount->gnth, buf, 1) != 0) { FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno); terminate_mount_request(mount); } @@ -487,7 +486,7 @@ static void dispatch_create(struct fs_mo /* Read the request, and create file/directory */ mode = req->u.fcreate.mode; directory = req->u.fcreate.directory; - file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth, + file_name = xc_gnttab_map_grant_ref(mount->gnth, mount->dom_id, req->u.fcreate.gref, PROT_READ); @@ -523,7 +522,7 @@ static void dispatch_create(struct fs_mo } } out: - if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) { + if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) { FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno); terminate_mount_request(mount); } @@ -551,7 +550,7 @@ static void dispatch_list(struct fs_moun FS_DEBUG("Dispatching list operation (gref=%d).\n", req->u.flist.gref); /* Read the request, and list directory */ offset = req->u.flist.offset; - buf = file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth, + buf = file_name = xc_gnttab_map_grant_ref(mount->gnth, mount->dom_id, req->u.flist.gref, PROT_READ | PROT_WRITE); @@ -599,7 +598,7 @@ error_out: ret_val = ((nr_files << NR_FILES_SHIFT) & NR_FILES_MASK) | ((error_code << ERROR_SHIFT) & ERROR_MASK) | (dirent != NULL ? HAS_MORE_FLAG : 0); - if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) { + if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) { FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno); terminate_mount_request(mount); } @@ -654,7 +653,7 @@ static void dispatch_fs_space(struct fs_ FS_DEBUG("Dispatching fs space operation (gref=%d).\n", req->u.fspace.gref); /* Read the request, and open file */ - file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth, + file_name = xc_gnttab_map_grant_ref(mount->gnth, mount->dom_id, req->u.fspace.gref, PROT_READ); @@ -670,7 +669,7 @@ static void dispatch_fs_space(struct fs_ if(ret >= 0) ret = stat.f_bsize * stat.f_bfree; - if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) { + if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) { FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno); terminate_mount_request(mount); } diff -r e82cccb0d977 -r d210f8cc84b3 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:46 2010 +0000 @@ -443,18 +443,17 @@ void discard_file_cache(xc_interface *xc errno = saved_errno; } -int xc_gnttab_open(xc_interface *xch) +int xc_gnttab_open_core(xc_gnttab *xcg) { return open(DEVXEN "gntdev", O_RDWR); } -int xc_gnttab_close(xc_interface *xch, int xcg_handle) +int xc_gnttab_close_core(xc_gnttab *xcg) { - return close(xcg_handle); + return close(xcg->fd); } -void *xc_gnttab_map_grant_ref(xc_interface *xch, int xcg_handle, - uint32_t domid, uint32_t ref, int prot) +void *xc_gnttab_map_grant_ref(xc_gnttab *xch, uint32_t domid, uint32_t ref, int prot) { struct ioctl_gntdev_map_grant_ref map; void *addr; @@ -463,13 +462,13 @@ void *xc_gnttab_map_grant_ref(xc_interfa map.refs[0].domid = domid; map.refs[0].ref = ref; - if ( ioctl(xcg_handle, IOCTL_GNTDEV_MAP_GRANT_REF, &map) ) { + if ( ioctl(xch->fd, IOCTL_GNTDEV_MAP_GRANT_REF, &map) ) { PERROR("xc_gnttab_map_grant_ref: ioctl MAP_GRANT_REF failed"); return NULL; } mmap_again: - addr = mmap(NULL, PAGE_SIZE, prot, MAP_SHARED, xcg_handle, map.index); + addr = mmap(NULL, PAGE_SIZE, prot, MAP_SHARED, xch->fd, map.index); if ( addr == MAP_FAILED ) { int saved_errno = errno; @@ -484,7 +483,7 @@ mmap_again: PERROR("xc_gnttab_map_grant_ref: mmap failed"); unmap_grant.index = map.index; unmap_grant.count = 1; - ioctl(xcg_handle, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant); + ioctl(xch->fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant); errno = saved_errno; return NULL; } @@ -492,8 +491,7 @@ mmap_again: return addr; } -static void *do_gnttab_map_grant_refs(xc_interface *xch, - int xcg_handle, uint32_t count, +static void *do_gnttab_map_grant_refs(xc_gnttab *xch, uint32_t count, uint32_t *domids, int domids_stride, uint32_t *refs, int prot) { @@ -514,12 +512,12 @@ static void *do_gnttab_map_grant_refs(xc map->count = count; - if ( ioctl(xcg_handle, IOCTL_GNTDEV_MAP_GRANT_REF, map) ) { + if ( ioctl(xch->fd, IOCTL_GNTDEV_MAP_GRANT_REF, map) ) { PERROR("xc_gnttab_map_grant_refs: ioctl MAP_GRANT_REF failed"); goto out; } - addr = mmap(NULL, PAGE_SIZE * count, prot, MAP_SHARED, xcg_handle, + addr = mmap(NULL, PAGE_SIZE * count, prot, MAP_SHARED, xch->fd, map->index); if ( addr == MAP_FAILED ) { @@ -530,7 +528,7 @@ static void *do_gnttab_map_grant_refs(xc PERROR("xc_gnttab_map_grant_refs: mmap failed"); unmap_grant.index = map->index; unmap_grant.count = count; - ioctl(xcg_handle, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant); + ioctl(xch->fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant); errno = saved_errno; addr = NULL; } @@ -541,22 +539,19 @@ static void *do_gnttab_map_grant_refs(xc return addr; } -void *xc_gnttab_map_grant_refs(xc_interface *xch, - int xcg_handle, uint32_t count, uint32_t *domids, +void *xc_gnttab_map_grant_refs(xc_gnttab *xcg, uint32_t count, uint32_t *domids, uint32_t *refs, int prot) { - return do_gnttab_map_grant_refs(xch, xcg_handle, count, domids, 1, refs, prot); + return do_gnttab_map_grant_refs(xcg, count, domids, 1, refs, prot); } -void *xc_gnttab_map_domain_grant_refs(xc_interface *xch, - int xcg_handle, uint32_t count, +void *xc_gnttab_map_domain_grant_refs(xc_gnttab *xcg, uint32_t count, uint32_t domid, uint32_t *refs, int prot) { - return do_gnttab_map_grant_refs(xch, xcg_handle, count, &domid, 0, refs, prot); + return do_gnttab_map_grant_refs(xcg, count, &domid, 0, refs, prot); } -int xc_gnttab_munmap(xc_interface *xch, - int xcg_handle, void *start_address, uint32_t count) +int xc_gnttab_munmap(xc_gnttab *xcg, void *start_address, uint32_t count) { struct ioctl_gntdev_get_offset_for_vaddr get_offset; struct ioctl_gntdev_unmap_grant_ref unmap_grant; @@ -572,7 +567,7 @@ int xc_gnttab_munmap(xc_interface *xch, * mmap() the pages. */ get_offset.vaddr = (unsigned long)start_address; - if ( (rc = ioctl(xcg_handle, IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR, + if ( (rc = ioctl(xcg->fd, IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR, &get_offset)) ) return rc; @@ -589,20 +584,19 @@ int xc_gnttab_munmap(xc_interface *xch, /* Finally, unmap the driver slots used to store the grant information. */ unmap_grant.index = get_offset.offset; unmap_grant.count = count; - if ( (rc = ioctl(xcg_handle, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant)) ) + if ( (rc = ioctl(xcg->fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant)) ) return rc; return 0; } -int xc_gnttab_set_max_grants(xc_interface *xch, - int xcg_handle, uint32_t count) +int xc_gnttab_set_max_grants(xc_gnttab *xcg, uint32_t count) { struct ioctl_gntdev_set_max_grants set_max; int rc; set_max.count = count; - if ( (rc = ioctl(xcg_handle, IOCTL_GNTDEV_SET_MAX_GRANTS, &set_max)) ) + if ( (rc = ioctl(xcg->fd, IOCTL_GNTDEV_SET_MAX_GRANTS, &set_max)) ) return rc; return 0; diff -r e82cccb0d977 -r d210f8cc84b3 tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:46 2010 +0000 @@ -375,17 +375,17 @@ void discard_file_cache(xc_interface *xc fsync(fd); } -int xc_gnttab_open(xc_interface *xch) +int xc_gnttab_open_core(xc_gnttab *xcg) { - int xcg_handle; - xcg_handle = alloc_fd(FTYPE_GNTMAP); - gntmap_init(&files[xcg_handle].gntmap); - return xcg_handle; + int fd; + fd = alloc_fd(FTYPE_GNTMAP); + gntmap_init(&files[fd].gntmap); + return fd; } -int xc_gnttab_close(xc_interface *xch, int xcg_handle) +int xc_gnttab_close_core(xc_gnttab *xcg) { - return close(xcg_handle); + return close(xcg->fd); } void minios_gnttab_close_fd(int fd) @@ -394,50 +394,50 @@ void minios_gnttab_close_fd(int fd) files[fd].type = FTYPE_NONE; } -void *xc_gnttab_map_grant_ref(xc_interface *xch, int xcg_handle, +void *xc_gnttab_map_grant_ref(xc_gnttab *xcg, uint32_t domid, uint32_t ref, int prot) { - return gntmap_map_grant_refs(&files[xcg_handle].gntmap, + return gntmap_map_grant_refs(&files[xcg->fd].gntmap, 1, &domid, 0, &ref, prot & PROT_WRITE); } -void *xc_gnttab_map_grant_refs(xc_interface *xch, int xcg_handle, +void *xc_gnttab_map_grant_refs(xc_gnttab *xcg, uint32_t count, uint32_t *domids, uint32_t *refs, int prot) { - return gntmap_map_grant_refs(&files[xcg_handle].gntmap, + return gntmap_map_grant_refs(&files[xcg->fd].gntmap, count, domids, 1, refs, prot & PROT_WRITE); } -void *xc_gnttab_map_domain_grant_refs(xc_interface *xch, int xcg_handle, +void *xc_gnttab_map_domain_grant_refs(xc_gnttab *xcg, uint32_t count, uint32_t domid, uint32_t *refs, int prot) { - return gntmap_map_grant_refs(&files[xcg_handle].gntmap, + return gntmap_map_grant_refs(&files[xcg->fd].gntmap, count, &domid, 0, refs, prot & PROT_WRITE); } -int xc_gnttab_munmap(xc_interface *xch, int xcg_handle, +int xc_gnttab_munmap(xc_gnttab *xcg, void *start_address, uint32_t count) { int ret; - ret = gntmap_munmap(&files[xcg_handle].gntmap, + ret = gntmap_munmap(&files[xcg->fd].gntmap, (unsigned long) start_address, count); if (ret < 0) { @@ -447,11 +447,11 @@ int xc_gnttab_munmap(xc_interface *xch, return ret; } -int xc_gnttab_set_max_grants(xc_interface *xch, int xcg_handle, +int xc_gnttab_set_max_grants(xc_gnttab *xcg, uint32_t count) { int ret; - ret = gntmap_set_max_grants(&files[xcg_handle].gntmap, + ret = gntmap_set_max_grants(&files[xcg->fd].gntmap, count); if (ret < 0) { errno = -ret; diff -r e82cccb0d977 -r d210f8cc84b3 tools/libxc/xc_private.c --- a/tools/libxc/xc_private.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_private.c Fri Dec 03 09:36:46 2010 +0000 @@ -113,6 +113,18 @@ int xc_evtchn_close(xc_evtchn *xce) int xc_evtchn_close(xc_evtchn *xce) { return xc_interface_close_common(xce, &xc_evtchn_close_core); +} + +xc_gnttab *xc_gnttab_open(xentoollog_logger *logger, + unsigned open_flags) +{ + return xc_interface_open_common(logger, NULL, open_flags, + XC_INTERFACE_GNTTAB, &xc_gnttab_open_core); +} + +int xc_gnttab_close(xc_gnttab *xcg) +{ + return xc_interface_close_common(xcg, &xc_gnttab_close_core); } static pthread_key_t errbuf_pkey; diff -r e82cccb0d977 -r d210f8cc84b3 tools/libxc/xc_private.h --- a/tools/libxc/xc_private.h Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_private.h Fri Dec 03 09:36:46 2010 +0000 @@ -68,6 +68,7 @@ enum xc_interface_type { enum xc_interface_type { XC_INTERFACE_PRIVCMD, XC_INTERFACE_EVTCHN, + XC_INTERFACE_GNTTAB, }; struct xc_interface_core { @@ -269,6 +270,9 @@ int xc_evtchn_open_core(struct xc_interf int xc_evtchn_open_core(struct xc_interface_core *xce); /* returns fd, logs errors */ int xc_evtchn_close_core(struct xc_interface_core *xce); /* no logging */ +int xc_gnttab_open_core(struct xc_interface_core *xcg); /* returns fd, logs errors */ +int xc_gnttab_close_core(struct xc_interface_core *xcg); /* no logging */ + void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom, size_t size, int prot, size_t chunksize, privcmd_mmap_entry_t entries[], int nentries); diff -r e82cccb0d977 -r d210f8cc84b3 tools/libxc/xenctrl.h --- a/tools/libxc/xenctrl.h Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xenctrl.h Fri Dec 03 09:36:46 2010 +0000 @@ -106,6 +106,7 @@ typedef struct xc_interface_core xc_interface; typedef struct xc_interface_core xc_evtchn; +typedef struct xc_interface_core xc_gnttab; typedef enum xc_error_code xc_error_code; @@ -1239,25 +1240,25 @@ int xc_domain_subscribe_for_suspend( /* * Return an fd onto the grant table driver. Logs errors. */ -int xc_gnttab_open(xc_interface *xch); +xc_gnttab *xc_gnttab_open(xentoollog_logger *logger, + unsigned open_flags); /* * Close a handle previously allocated with xc_gnttab_open(). * Never logs errors. */ -int xc_gnttab_close(xc_interface *xch, int xcg_handle); +int xc_gnttab_close(xc_gnttab *xcg); /* * Memory maps a grant reference from one domain to a local address range. * Mappings should be unmapped with xc_gnttab_munmap. Logs errors. * - * @parm xcg_handle a handle on an open grant table interface + * @parm xcg a handle on an open grant table interface * @parm domid the domain to map memory from * @parm ref the grant reference ID to map * @parm prot same flag as in mmap() */ -void *xc_gnttab_map_grant_ref(xc_interface *xch, - int xcg_handle, +void *xc_gnttab_map_grant_ref(xc_gnttab *xcg, uint32_t domid, uint32_t ref, int prot); @@ -1267,15 +1268,14 @@ void *xc_gnttab_map_grant_ref(xc_interfa * contiguous local address range. Mappings should be unmapped with * xc_gnttab_munmap. Logs errors. * - * @parm xcg_handle a handle on an open grant table interface + * @parm xcg a handle on an open grant table interface * @parm count the number of grant references to be mapped * @parm domids an array of @count domain IDs by which the corresponding @refs * were granted * @parm refs an array of @count grant references to be mapped * @parm prot same flag as in mmap() */ -void *xc_gnttab_map_grant_refs(xc_interface *xch, - int xcg_handle, +void *xc_gnttab_map_grant_refs(xc_gnttab *xcg, uint32_t count, uint32_t *domids, uint32_t *refs, @@ -1286,14 +1286,13 @@ void *xc_gnttab_map_grant_refs(xc_interf * contiguous local address range. Mappings should be unmapped with * xc_gnttab_munmap. Logs errors. * - * @parm xcg_handle a handle on an open grant table interface + * @parm xcg a handle on an open grant table interface * @parm count the number of grant references to be mapped * @parm domid the domain to map memory from * @parm refs an array of @count grant references to be mapped * @parm prot same flag as in mmap() */ -void *xc_gnttab_map_domain_grant_refs(xc_interface *xch, - int xcg_handle, +void *xc_gnttab_map_domain_grant_refs(xc_gnttab *xcg, uint32_t count, uint32_t domid, uint32_t *refs, @@ -1303,8 +1302,7 @@ void *xc_gnttab_map_domain_grant_refs(xc * Unmaps the @count pages starting at @start_address, which were mapped by a * call to xc_gnttab_map_grant_ref or xc_gnttab_map_grant_refs. Never logs. */ -int xc_gnttab_munmap(xc_interface *xch, - int xcg_handle, +int xc_gnttab_munmap(xc_gnttab *xcg, void *start_address, uint32_t count); @@ -1319,8 +1317,7 @@ int xc_gnttab_munmap(xc_interface *xch, * and it may not be possible to satisfy requests up to the maximum number * of grants. */ -int xc_gnttab_set_max_grants(xc_interface *xch, - int xcg_handle, +int xc_gnttab_set_max_grants(xc_gnttab *xcg, uint32_t count); int xc_gnttab_op(xc_interface *xch, int cmd, _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 04 of 25] libxc: osdep: add framework for abstracting access to dom0 OS hypervisor interfaces
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369006 0 # Node ID f6ca48223803053b2d55c5845cc358ddd4cd5743 # Parent d210f8cc84b3b228017afcca2158ccf1e06c1430 libxc: osdep: add framework for abstracting access to dom0 OS hypervisor interfaces. This patch introduces the basic infrastructure and uses it for open and close operations on privcmd, evtchn and gnttab devices. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r d210f8cc84b3 -r f6ca48223803 tools/libxc/Makefile --- a/tools/libxc/Makefile Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/Makefile Fri Dec 03 09:36:46 2010 +0000 @@ -109,7 +109,7 @@ install: build $(INSTALL_DATA) libxenctrl.a $(DESTDIR)$(LIBDIR) ln -sf libxenctrl.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libxenctrl.so.$(MAJOR) ln -sf libxenctrl.so.$(MAJOR) $(DESTDIR)$(LIBDIR)/libxenctrl.so - $(INSTALL_DATA) xenctrl.h xentoollog.h $(DESTDIR)$(INCLUDEDIR) + $(INSTALL_DATA) xenctrl.h xenctrlosdep.h xentoollog.h $(DESTDIR)$(INCLUDEDIR) $(INSTALL_PROG) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR) $(INSTALL_DATA) libxenguest.a $(DESTDIR)$(LIBDIR) ln -sf libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libxenguest.so.$(MAJOR) diff -r d210f8cc84b3 -r f6ca48223803 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:46 2010 +0000 @@ -29,7 +29,7 @@ #include <unistd.h> #include <fcntl.h> -int xc_interface_open_core(xc_interface *xch) +static xc_osdep_handle linux_privcmd_open(xc_interface *xch) { int flags, saved_errno; int fd = open("/proc/xen/privcmd", O_RDWR); @@ -37,7 +37,7 @@ int xc_interface_open_core(xc_interface if ( fd == -1 ) { PERROR("Could not obtain handle on privileged command interface"); - return -1; + return XC_OSDEP_OPEN_ERROR; } /* Although we return the file handle as the ''xc handle'' the API @@ -58,19 +58,21 @@ int xc_interface_open_core(xc_interface goto error; } - return fd; + xch->fd = fd; /* Remove after transition to full xc_osdep_ops. */ + + return (xc_osdep_handle)fd; error: saved_errno = errno; close(fd); errno = saved_errno; - - return -1; + return XC_OSDEP_OPEN_ERROR; } -int xc_interface_close_core(xc_interface *xch) +static int linux_privcmd_close(xc_interface *xch, xc_osdep_handle h) { - return close(xch->fd); + int fd = (int)h; + return close(fd); } static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom, @@ -325,16 +327,27 @@ int do_xen_hypercall(xc_interface *xch, (unsigned long)hypercall); } +static struct xc_osdep_ops linux_privcmd_ops = { + .open = &linux_privcmd_open, + .close = &linux_privcmd_close, +}; + #define DEVXEN "/dev/xen/" -int xc_evtchn_open_core(xc_evtchn *xce) +static xc_osdep_handle linux_evtchn_open(xc_evtchn *xce) { - return open(DEVXEN "evtchn", O_RDWR); + int fd = open(DEVXEN "evtchn", O_RDWR); + if ( fd == -1 ) + return XC_OSDEP_OPEN_ERROR; + + xce->fd = fd; /* Remove after transition to full xc_osdep_ops. */ + return (xc_osdep_handle)fd; } -int xc_evtchn_close_core(xc_evtchn *xce) +static int linux_evtchn_close(xc_evtchn *xce, xc_osdep_handle h) { - return close(xce->fd); + int fd = (int)h; + return close(fd); } int xc_evtchn_fd(xc_evtchn *xce) @@ -408,6 +421,11 @@ int xc_evtchn_unmask(xc_evtchn *xce, evt return write_exact(xce->fd, (char *)&port, sizeof(port)); } +static struct xc_osdep_ops linux_evtchn_ops = { + .open = &linux_evtchn_open, + .close = &linux_evtchn_close, +}; + /* Optionally flush file to disk and discard page cache */ void discard_file_cache(xc_interface *xch, int fd, int flush) { @@ -443,14 +461,21 @@ void discard_file_cache(xc_interface *xc errno = saved_errno; } -int xc_gnttab_open_core(xc_gnttab *xcg) +static xc_osdep_handle linux_gnttab_open(xc_gnttab *xcg) { - return open(DEVXEN "gntdev", O_RDWR); + int fd = open(DEVXEN "gntdev", O_RDWR); + + if ( fd == -1 ) + return XC_OSDEP_OPEN_ERROR; + + xcg->fd = fd; /* Remove after transition to full xc_osdep_ops. */ + return (xc_osdep_handle)fd; } -int xc_gnttab_close_core(xc_gnttab *xcg) +static int linux_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h) { - return close(xcg->fd); + int fd = (int)h; + return close(fd); } void *xc_gnttab_map_grant_ref(xc_gnttab *xch, uint32_t domid, uint32_t ref, int prot) @@ -602,6 +627,31 @@ int xc_gnttab_set_max_grants(xc_gnttab * return 0; } +static struct xc_osdep_ops linux_gnttab_ops = { + .open = &linux_gnttab_open, + .close = &linux_gnttab_close, +}; + +static struct xc_osdep_ops *linux_osdep_init(xc_interface *xch, enum xc_osdep_type type) +{ + switch ( type ) + { + case XC_OSDEP_PRIVCMD: + return &linux_privcmd_ops; + case XC_OSDEP_EVTCHN: + return &linux_evtchn_ops; + case XC_OSDEP_GNTTAB: + return &linux_gnttab_ops; + default: + return NULL; + } +} + +xc_osdep_info_t xc_osdep_info = { + .name = "Linux Native OS interface", + .init = &linux_osdep_init, +}; + /* * Local variables: * mode: C diff -r d210f8cc84b3 -r f6ca48223803 tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:46 2010 +0000 @@ -49,14 +49,21 @@ extern void minios_evtchn_close_fd(int f extern struct wait_queue_head event_queue; -int xc_interface_open_core(xc_interface *xch) +static xc_osdep_handle minios_privcmd_open(xc_interface *xch) { - return alloc_fd(FTYPE_XC); + int fd = alloc_fd(FTYPE_XC); + + if ( fd == -1) + return XC_OSDEP_OPEN_ERROR; + + xch->fd = fd; /* Remove after transition to full xc_osdep_ops. */ + return (xc_osdep_handle)fd; } -int xc_interface_close_core(xc_interface *xch) +static int minios_privcmd_close(xc_interface *xch, xc_osdep_handle h) { - return close(xch->fd); + int fd = (int)h; + return close(fd); } void minios_interface_close_fd(int fd) @@ -172,20 +179,29 @@ int do_xen_hypercall(xc_interface *xch, return call.result; } -int xc_evtchn_open_core(xc_evtchn *xce) +static struct xc_osdep_ops minios_privcmd_ops = { + .open = &minios_privcmd_open, + .close = &minios_privcmd_close, +}; + +static xc_osdep_handle minios_evtchn_open(xc_evtchn *xce) { int fd = alloc_fd(FTYPE_EVTCHN), i; + if ( fd == -1 ) + return XC_OSDEP_OPEN_ERROR; for (i = 0; i < MAX_EVTCHN_PORTS; i++) { files[fd].evtchn.ports[i].port = -1; files[fd].evtchn.ports[i].bound = 0; } printf("evtchn_open() -> %d\n", fd); - return fd; + xce->fd = fd; /* Remove after transition to full xc_osdep_ops. */ + return (xc_osdep_handle)fd; } -int xc_evtchn_close_core(xc_evtchn *xce) +static int minios_evtchn_close(xc_evtchn *xce, xc_osdep_handle h) { - return close(xce->fd); + int fd = (int)h; + return close(fd); } void minios_evtchn_close_fd(int fd) @@ -368,6 +384,11 @@ int xc_evtchn_unmask(xc_evtchn *xce, evt return 0; } +static struct xc_osdep_ops minios_evtchn_ops = { + .open = &minios_evtchn_open, + .close = &minios_evtchn_close, +}; + /* Optionally flush file to disk and discard page cache */ void discard_file_cache(xc_interface *xch, int fd, int flush) { @@ -375,17 +396,20 @@ void discard_file_cache(xc_interface *xc fsync(fd); } -int xc_gnttab_open_core(xc_gnttab *xcg) +static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg) { - int fd; - fd = alloc_fd(FTYPE_GNTMAP); + int fd = alloc_fd(FTYPE_GNTMAP); + if ( fd == -1 ) + return XC_OSDEP_OPEN_ERROR; gntmap_init(&files[fd].gntmap); - return fd; + xcg->fd = fd; /* Remove after transition to full xc_osdep_ops. */ + return (xc_osdep_handle)fd; } -int xc_gnttab_close_core(xc_gnttab *xcg) +static int minios_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h) { - return close(xcg->fd); + int fd = (int)h; + return close(fd); } void minios_gnttab_close_fd(int fd) @@ -460,6 +484,31 @@ int xc_gnttab_set_max_grants(xc_gnttab * return ret; } +static struct xc_osdep_ops minios_gnttab_ops = { + .open = &minios_gnttab_open, + .close = &minios_gnttab_close, +}; + +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; + case XC_OSDEP_EVTCHN: + return &minios_evtchn_ops; + case XC_OSDEP_GNTTAB: + return &minios_gnttab_ops; + default: + return NULL; + } +} + +xc_osdep_info_t xc_osdep_info = { + .name = "Minios Native OS interface", + .init = &minios_osdep_init, +}; + /* * Local variables: * mode: C diff -r d210f8cc84b3 -r f6ca48223803 tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:46 2010 +0000 @@ -24,7 +24,7 @@ #include <unistd.h> #include <fcntl.h> -int xc_interface_open_core(xc_interface *xch) +static xc_osdep_handle netbsd_privcmd_open(xc_interface *xch) { int flags, saved_errno; int fd = open("/kern/xen/privcmd", O_RDWR); @@ -32,7 +32,7 @@ int xc_interface_open_core(xc_interface if ( fd == -1 ) { PERROR("Could not obtain handle on privileged command interface"); - return -1; + return XC_OSDEP_OPEN_ERROR; } /* Although we return the file handle as the ''xc handle'' the API @@ -51,18 +51,21 @@ int xc_interface_open_core(xc_interface goto error; } - return fd; + xch->fd = fd; /* Remove after transition to full xc_osdep_ops. */ + + return (xc_osinteface_handle)fd; error: saved_errno = errno; close(fd); errno = saved_errno; - return -1; + return XC_OSDEP_OPEN_ERROR; } -int xc_interface_close_core(xc_interface *xch) +static int netbsd_privcmd_close(xc_interface *xch, xc_osdep_handle h) { - return close(xch->fd); + int fd = (int)h; + return close(fd); } void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, @@ -179,16 +182,27 @@ int do_xen_hypercall(xc_interface *xch, return (hypercall->retval); } +static struct xc_osdep_ops netbsd_privcmd_ops = { + .open = &netbsd_privcmd_open, + .close = &netbsd_privcmd_close, +}; + #define EVTCHN_DEV_NAME "/dev/xenevt" -int xc_evtchn_open_core(xc_evtchn *xce) +static xc_osdep_handle netbsd_evtchn_open(xc_evtchn *xce) { - return open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR); + int fd = open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR); + if ( fd == -1 ) + return XC_OSDEP_OPEN_ERROR; + + xce->fd = fd; /* Remove after transition to full xc_osdep_ops. */ + return (xc_osdep_handle)fd; } -int xc_evtchn_close_core(xc_evtchn *xce) +static int netbsd_evtchn_close(xc_evtchn *xce, xc_osdep_handle h) { - return close(xce->fd); + int fd = (int)h; + return close(fd); } int xc_evtchn_fd(xc_evtchn *xce) @@ -277,6 +291,11 @@ int xc_evtchn_unmask(xc_evtchn *xce, evt return write_exact(xce->fd, (char *)&port, sizeof(port)); } +static struct xc_osdep_ops netbsd_evtchn_ops = { + .open = &netbsd_evtchn_open, + .close = &netbsd_evtchn_close, +}; + /* Optionally flush file to disk and discard page cache */ void discard_file_cache(xc_interface *xch, int fd, int flush) { @@ -287,6 +306,27 @@ void discard_file_cache(xc_interface *xc } } +static struct xc_osdep_ops *netbsd_osdep_init(xc_interface *xch, enum xc_osdep_type type) +{ + switch ( type ) + { + case XC_OSDEP_PRIVCMD: + return &netbsd_privcmd_ops; + case XC_OSDEP_EVTCHN: + return &netbsd_evtchn_ops; + case XC_OSDEP_GNTTAB: + ERROR("GNTTAB interface not supported on this platform"); + return NULL; + default: + return NULL; + } +} + +xc_osdep_info_t xc_osdep_info = { + .name = "Netbsd Native OS interface", + .init = &netbsd_osdep_init, +}; + /* * Local variables: * mode: C diff -r d210f8cc84b3 -r f6ca48223803 tools/libxc/xc_private.c --- a/tools/libxc/xc_private.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_private.c Fri Dec 03 09:36:46 2010 +0000 @@ -27,11 +27,33 @@ #include <pthread.h> #include <assert.h> +/* + * Returns a (shallow) copy of the xc_osdep_info_t for the + * active OS interface. + * + * Returns: + * 0 - on success + * -1 - on error + */ +static int xc_osdep_get_info(xc_interface *xch, xc_osdep_info_t *info) +{ + int rc = -1; + + *info = xc_osdep_info; + + rc = 0; + + return rc; +} + +static void xc_osdep_put(xc_osdep_info_t *info) +{ +} + static struct xc_interface_core *xc_interface_open_common(xentoollog_logger *logger, - xentoollog_logger *dombuild_logger, - unsigned open_flags, - enum xc_interface_type type, - int (*open_core)(struct xc_interface_core *xch)) + xentoollog_logger *dombuild_logger, + unsigned open_flags, + enum xc_osdep_type type) { struct xc_interface_core xch_buf, *xch = &xch_buf; @@ -43,6 +65,9 @@ static struct xc_interface_core *xc_inte xch->error_handler = logger; xch->error_handler_tofree = 0; xch->dombuild_logger = dombuild_logger; xch->dombuild_logger_tofree = 0; + + xch->ops_handle = XC_OSDEP_OPEN_ERROR; + xch->ops = NULL; if (!xch->error_handler) { xch->error_handler = xch->error_handler_tofree @@ -61,30 +86,37 @@ static struct xc_interface_core *xc_inte *xch = xch_buf; if (!(open_flags & XC_OPENFLAG_DUMMY)) { - xch->fd = open_core(xch); - if (xch->fd < 0) + if ( xc_osdep_get_info(xch, &xch->osdep) < 0 ) goto err; + + xch->ops = xch->osdep.init(xch, type); + if ( xch->ops == NULL ) + goto err_put_iface; + + xch->ops_handle = xch->ops->open(xch); + if (xch->ops_handle == XC_OSDEP_OPEN_ERROR) + goto err_put_iface; } return xch; +err_put_iface: + xc_osdep_put(&xch->osdep); err: if (xch) xtl_logger_destroy(xch->error_handler_tofree); if (xch != &xch_buf) free(xch); - return 0; + return NULL; } -static int xc_interface_close_common(xc_interface *xch, int (*close_core)(struct xc_interface_core *xch)) +static int xc_interface_close_common(xc_interface *xch) { int rc = 0; xtl_logger_destroy(xch->dombuild_logger_tofree); xtl_logger_destroy(xch->error_handler_tofree); - if (xch->fd >= 0) { - rc = close_core(xch); - if (rc) PERROR("Could not close hypervisor interface"); - } + rc = xch->ops->close(xch, xch->ops_handle); + if (rc) PERROR("Could not close hypervisor interface"); free(xch); return rc; @@ -94,37 +126,45 @@ xc_interface *xc_interface_open(xentooll xentoollog_logger *dombuild_logger, unsigned open_flags) { - return xc_interface_open_common(logger, dombuild_logger, open_flags, - XC_INTERFACE_PRIVCMD, &xc_interface_open_core); + xc_interface *xch; + + xch = xc_interface_open_common(logger, dombuild_logger, open_flags, + XC_OSDEP_PRIVCMD); + + return xch; } int xc_interface_close(xc_interface *xch) { - return xc_interface_close_common(xch, &xc_interface_close_core); + return xc_interface_close_common(xch); } xc_evtchn *xc_evtchn_open(xentoollog_logger *logger, unsigned open_flags) { - return xc_interface_open_common(logger, NULL, open_flags, - XC_INTERFACE_EVTCHN, &xc_evtchn_open_core); + xc_evtchn *xce; + + xce = xc_interface_open_common(logger, NULL, open_flags, + XC_OSDEP_EVTCHN); + + return xce; } int xc_evtchn_close(xc_evtchn *xce) { - return xc_interface_close_common(xce, &xc_evtchn_close_core); + return xc_interface_close_common(xce); } xc_gnttab *xc_gnttab_open(xentoollog_logger *logger, unsigned open_flags) { return xc_interface_open_common(logger, NULL, open_flags, - XC_INTERFACE_GNTTAB, &xc_gnttab_open_core); + XC_OSDEP_GNTTAB); } int xc_gnttab_close(xc_gnttab *xcg) { - return xc_interface_close_common(xcg, &xc_gnttab_close_core); + return xc_interface_close_common(xcg); } static pthread_key_t errbuf_pkey; diff -r d210f8cc84b3 -r f6ca48223803 tools/libxc/xc_private.h --- a/tools/libxc/xc_private.h Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_private.h Fri Dec 03 09:36:46 2010 +0000 @@ -30,6 +30,7 @@ #include <sys/ioctl.h> #include "xenctrl.h" +#include "xenctrlosdep.h" #include <xen/sys/privcmd.h> @@ -65,14 +66,8 @@ */ #define MAX_PAGECACHE_USAGE (4*1024) -enum xc_interface_type { - XC_INTERFACE_PRIVCMD, - XC_INTERFACE_EVTCHN, - XC_INTERFACE_GNTTAB, -}; - struct xc_interface_core { - enum xc_interface_type type; + enum xc_osdep_type type; int fd; int flags; xentoollog_logger *error_handler, *error_handler_tofree; @@ -80,6 +75,10 @@ struct xc_interface_core { struct xc_error last_error; /* for xc_get_last_error */ FILE *dombuild_logger_file; const char *currently_progress_reporting; + + xc_osdep_info_t osdep; + xc_osdep_ops *ops; /* backend operations */ + xc_osdep_handle ops_handle; /* opaque data for xc_osdep_ops */ }; void xc_report_error(xc_interface *xch, int code, const char *fmt, ...); @@ -264,15 +263,6 @@ static inline int do_sysctl(xc_interface int do_memory_op(xc_interface *xch, int cmd, void *arg, size_t len); -int xc_interface_open_core(struct xc_interface_core *xch); /* returns fd, logs errors */ -int xc_interface_close_core(struct xc_interface_core *xch); /* no logging */ - -int xc_evtchn_open_core(struct xc_interface_core *xce); /* returns fd, logs errors */ -int xc_evtchn_close_core(struct xc_interface_core *xce); /* no logging */ - -int xc_gnttab_open_core(struct xc_interface_core *xcg); /* returns fd, logs errors */ -int xc_gnttab_close_core(struct xc_interface_core *xcg); /* no logging */ - void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom, size_t size, int prot, size_t chunksize, privcmd_mmap_entry_t entries[], int nentries); diff -r d210f8cc84b3 -r f6ca48223803 tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:46 2010 +0000 @@ -25,7 +25,7 @@ #include <unistd.h> #include <fcntl.h> -int xc_interface_open_core(xc_interface *xch) +static xc_osdep_handle solaris_privcmd_open(xc_interface *xch) { int flags, saved_errno; int fd = open("/dev/xen/privcmd", O_RDWR); @@ -33,7 +33,7 @@ int xc_interface_open_core(xc_interface if ( fd == -1 ) { PERROR("Could not obtain handle on privileged command interface"); - return -1; + return XC_OSDEP_OPEN_ERROR; } /* Although we return the file handle as the ''xc handle'' the API @@ -52,17 +52,19 @@ int xc_interface_open_core(xc_interface goto error; } - return fd; + xch->fd = fd; /* Remove after transition to full xc_osdep_ops. */ + return (xc_osdep_handle)fd; error: saved_errno = errno; close(fd); errno = saved_errno; - return -1; + return XC_OSDEP_OPEN_ERROR; } -int xc_interface_close(xc_interface *xch, int fd) +static int solaris_privcmd_close(xc_interface *xch, xc_osdep_handle h) { + int fd = (int)h; return close(fd); } @@ -154,7 +156,6 @@ mmap_failed: return NULL; } - static int do_privcmd(xc_interface *xch, unsigned int cmd, unsigned long data) { return ioctl(xch->fd, cmd, data); @@ -167,22 +168,29 @@ int do_xen_hypercall(xc_interface *xch, (unsigned long)hypercall); } -int xc_evtchn_open_core(xc_evtchn *xce) +static struct xc_osdep_ops solaris_privcmd_ops = { + .open = &solaris_privcmd_open, + .close = &solaris_privcmd_close, +}; + +static xc_osdep_handle solaris_evtchn_open(xc_evtchn *xce) { int fd; if ( (fd = open("/dev/xen/evtchn", O_RDWR)) == -1 ) { PERROR("Could not open event channel interface"); - return -1; + return XC_OSDEP_OPEN_ERROR; } - return fd; + xce->fd = fd; /* Remove after transition to full xc_osdep_ops. */ + return (xc_osdep_handle)fd; } -int xc_evtchn_close_core(xc_evtchn *xce) +static int solaris_evtchn_close(xc_evtchn *xce, xc_osdep_handle h) { - return close(xce->fd); + int fd = (int)h; + return close(fd); } int xc_evtchn_fd(xc_evtchn *xce) @@ -256,8 +264,44 @@ int xc_evtchn_unmask(xc_evtchn *xce, evt return write_exact(xce->fd, (char *)&port, sizeof(port)); } +static struct xc_osdep_ops solaris_evtchn_ops = { + .open = &solaris_evtchn_open, + .close = &solaris_evtchn_close, +}; + /* Optionally flush file to disk and discard page cache */ void discard_file_cache(xc_interface *xch, int fd, int flush) { // TODO: Implement for Solaris! } + +static struct xc_osdep_ops *solaris_osdep_init(xc_interface *xch, enum xc_osdep_type type) +{ + switch ( type ) + { + case XC_OSDEP_PRIVCMD: + return &solaris_privcmd_ops; + case XC_OSDEP_EVTCHN: + return &solaris_evtchn_ops; + case XC_OSDEP_GNTTAB: + ERROR("GNTTAB interface not supported on this platform"); + return NULL; + default: + return NULL; + } +} + +xc_osdep_info_t xc_osdep_info = { + .name = "Solaris Native OS interface", + .init = &solaris_osdep_init, +}; + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r d210f8cc84b3 -r f6ca48223803 tools/libxc/xenctrlosdep.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:46 2010 +0000 @@ -0,0 +1,90 @@ +/****************************************************************************** + * + * Interface to OS specific low-level operations + * + * Copyright (c) 2010, Citrix Systems Inc. + * + * 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 + */ + +/* + * This interface defines the interactions between the Xen control + * libraries and the OS facilities used to communicate with the + * hypervisor. + */ + +#ifndef XC_OSDEP_H +#define XC_OSDEP_H + +/* Tell the Xen public headers we are a user-space tools build. */ +#ifndef __XEN_TOOLS__ +#define __XEN_TOOLS__ 1 +#endif + +#include <sys/mman.h> +#include <sys/types.h> + +#include <xen/sys/privcmd.h> + +enum xc_osdep_type { + XC_OSDEP_PRIVCMD, + XC_OSDEP_EVTCHN, + XC_OSDEP_GNTTAB, +}; + +/* Opaque handle internal to the backend */ +typedef unsigned long xc_osdep_handle; + +#define XC_OSDEP_OPEN_ERROR ((xc_osdep_handle)-1) + +struct xc_osdep_ops +{ + /* Opens an interface. + * + * Must return an opaque handle on success or + * XC_OSDEP_OPEN_ERROR on failure + */ + xc_osdep_handle (*open)(xc_interface *xch); + + int (*close)(xc_interface *xch, xc_osdep_handle h); +}; +typedef struct xc_osdep_ops xc_osdep_ops; + +typedef xc_osdep_ops *(*xc_osdep_init_fn)(xc_interface *xch, enum xc_osdep_type); + +struct xc_osdep_info +{ + /* Describes this backend. */ + const char *name; + + /* Returns ops function. */ + xc_osdep_init_fn init; +}; +typedef struct xc_osdep_info xc_osdep_info_t; + +/* All backends, including the builtin backend, must supply this structure. */ +extern xc_osdep_info_t xc_osdep_info; + +#endif + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 05 of 25] libxc: osdep: convert do_xen_hypercall()
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369006 0 # Node ID 0d91fce8549eaf0d23a306f2ec7931467c850edd # Parent f6ca48223803053b2d55c5845cc358ddd4cd5743 libxc: osdep: convert do_xen_hypercall() do_privcmd() was only ever used by do_xen_hypercall() so remove it. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r f6ca48223803 -r 0d91fce8549e tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:46 2010 +0000 @@ -73,6 +73,12 @@ static int linux_privcmd_close(xc_interf { int fd = (int)h; return close(fd); +} + +static int linux_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall) +{ + int fd = (int)h; + return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall); } static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom, @@ -316,20 +322,13 @@ void *xc_map_foreign_ranges(xc_interface return ret; } -static int do_privcmd(xc_interface *xch, int cmd, unsigned long data) -{ - return ioctl(xch->fd, cmd, data); -} - -int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall) -{ - return do_privcmd(xch, IOCTL_PRIVCMD_HYPERCALL, - (unsigned long)hypercall); -} - static struct xc_osdep_ops linux_privcmd_ops = { .open = &linux_privcmd_open, .close = &linux_privcmd_close, + + .u.privcmd = { + .hypercall = &linux_privcmd_hypercall, + }, }; #define DEVXEN "/dev/xen/" diff -r f6ca48223803 -r 0d91fce8549e tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:46 2010 +0000 @@ -69,6 +69,28 @@ void minios_interface_close_fd(int fd) void minios_interface_close_fd(int fd) { files[fd].type = FTYPE_NONE; +} + +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 < sizeof(hypercall->arg) / sizeof(*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; } void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot, @@ -157,31 +179,13 @@ void *xc_map_foreign_ranges(xc_interface } -int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall) -{ - multicall_entry_t call; - int i, ret; - - call.op = hypercall->op; - for (i = 0; i < sizeof(hypercall->arg) / sizeof(*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 struct xc_osdep_ops minios_privcmd_ops = { .open = &minios_privcmd_open, .close = &minios_privcmd_close, + + .u.privcmd = { + .hypercall = &minios_privcmd_hypercall, + }, }; static xc_osdep_handle minios_evtchn_open(xc_evtchn *xce) diff -r f6ca48223803 -r 0d91fce8549e tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:46 2010 +0000 @@ -66,6 +66,17 @@ static int netbsd_privcmd_close(xc_inter { int fd = (int)h; return close(fd); +} + +static int netbsd_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall) +{ + int fd = (int)h; + int error = ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall); + + if (error < 0) + return -errno; + else + return hypercall->retval; } void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, @@ -161,30 +172,13 @@ mmap_failed: return NULL; } - -static int do_privcmd(xc_interface *xch, unsigned int cmd, unsigned long data) -{ - int err = ioctl(xch->fd, cmd, data); - if (err == 0) - return 0; - else - return -errno; -} - -int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall) -{ - int error = do_privcmd(xch, - IOCTL_PRIVCMD_HYPERCALL, - (unsigned long)hypercall); - if (error) - return error; - else - return (hypercall->retval); -} - static struct xc_osdep_ops netbsd_privcmd_ops = { .open = &netbsd_privcmd_open, .close = &netbsd_privcmd_close, + + .u.privcmd = { + .hypercall = &netbsd_privcmd_hypercall; + }, }; #define EVTCHN_DEV_NAME "/dev/xenevt" diff -r f6ca48223803 -r 0d91fce8549e tools/libxc/xc_private.c --- a/tools/libxc/xc_private.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_private.c Fri Dec 03 09:36:46 2010 +0000 @@ -137,6 +137,12 @@ int xc_interface_close(xc_interface *xch int xc_interface_close(xc_interface *xch) { return xc_interface_close_common(xch); +} + + +int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall) +{ + return xch->ops->u.privcmd.hypercall(xch, xch->ops_handle, hypercall); } xc_evtchn *xc_evtchn_open(xentoollog_logger *logger, diff -r f6ca48223803 -r 0d91fce8549e tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:46 2010 +0000 @@ -66,6 +66,12 @@ static int solaris_privcmd_close(xc_inte { int fd = (int)h; return close(fd); +} + +static int solaris_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall) +{ + int fd = (int)h; + return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall); } void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, @@ -156,21 +162,13 @@ mmap_failed: return NULL; } -static int do_privcmd(xc_interface *xch, unsigned int cmd, unsigned long data) -{ - return ioctl(xch->fd, cmd, data); -} - -int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall) -{ - return do_privcmd(xch, - IOCTL_PRIVCMD_HYPERCALL, - (unsigned long)hypercall); -} - static struct xc_osdep_ops solaris_privcmd_ops = { .open = &solaris_privcmd_open, .close = &solaris_privcmd_close, + + .u.privcmd = { + .hypercall = &solaris_privcmd_hypercall; + }, }; static xc_osdep_handle solaris_evtchn_open(xc_evtchn *xce) diff -r f6ca48223803 -r 0d91fce8549e tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:46 2010 +0000 @@ -59,6 +59,12 @@ struct xc_osdep_ops xc_osdep_handle (*open)(xc_interface *xch); int (*close)(xc_interface *xch, xc_osdep_handle h); + + union { + struct { + int (*hypercall)(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall); + } privcmd; + } u; }; typedef struct xc_osdep_ops xc_osdep_ops; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 06 of 25] libxc: osdep: convert xc_map_foreign_{batch, bulk}
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID d0214e8537cee3c401e5ba5567d632d386ac5860 # Parent 0d91fce8549eaf0d23a306f2ec7931467c850edd libxc: osdep: convert xc_map_foreign_{batch,bulk} Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 0d91fce8549e -r d0214e8537ce tools/libxc/Makefile --- a/tools/libxc/Makefile Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/Makefile Fri Dec 03 09:36:47 2010 +0000 @@ -30,6 +30,7 @@ CTRL_SRCS-y += xc_mem_paging.c CTRL_SRCS-y += xc_mem_paging.c CTRL_SRCS-y += xc_memshr.c CTRL_SRCS-y += xc_hcall_buf.c +CTRL_SRCS-y += xc_foreign_memory.c CTRL_SRCS-y += xtl_core.c CTRL_SRCS-y += xtl_logger_stdio.c CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c diff -r 0d91fce8549e -r d0214e8537ce tools/libxc/xc_foreign_memory.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxc/xc_foreign_memory.c Fri Dec 03 09:36:47 2010 +0000 @@ -0,0 +1,35 @@ +/****************************************************************************** + * xc_foreign_memory.c + * + * Functions for mapping foreign domain''s memory. + * + * 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" + +void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, + xen_pfn_t *arr, int num ) +{ + return xch->ops->u.privcmd.map_foreign_batch(xch, xch->ops_handle, + dom, prot, arr, num); +} + +void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot, + const xen_pfn_t *arr, int *err, unsigned int num) +{ + return xch->ops->u.privcmd.map_foreign_bulk(xch, xch->ops_handle, + dom, prot, arr, err, num); +} diff -r 0d91fce8549e -r d0214e8537ce tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -81,7 +81,7 @@ static int linux_privcmd_hypercall(xc_in return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall); } -static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom, +static int xc_map_foreign_batch_single(int fd, uint32_t dom, xen_pfn_t *mfn, unsigned long addr) { privcmd_mmapbatch_t ioctlx; @@ -96,21 +96,23 @@ static int xc_map_foreign_batch_single(x { *mfn ^= XEN_DOMCTL_PFINFO_PAGEDTAB; usleep(100); - rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); } while ( (rc < 0) && (errno == ENOENT) ); return rc; } -void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, - xen_pfn_t *arr, int num) +static void *linux_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int prot, + xen_pfn_t *arr, int num) { + int fd = (int)h; privcmd_mmapbatch_t ioctlx; void *addr; int rc; - addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, xch->fd, 0); + addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, fd, 0); if ( addr == MAP_FAILED ) { PERROR("xc_map_foreign_batch: mmap failed"); @@ -122,7 +124,7 @@ void *xc_map_foreign_batch(xc_interface ioctlx.addr = (unsigned long)addr; ioctlx.arr = arr; - rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); if ( (rc < 0) && (errno == ENOENT) ) { int i; @@ -133,7 +135,7 @@ void *xc_map_foreign_batch(xc_interface XEN_DOMCTL_PFINFO_PAGEDTAB ) { unsigned long paged_addr = (unsigned long)addr + (i << PAGE_SHIFT); - rc = xc_map_foreign_batch_single(xch, dom, &arr[i], + rc = xc_map_foreign_batch_single(fd, dom, &arr[i], paged_addr); if ( rc < 0 ) goto out; @@ -154,16 +156,18 @@ void *xc_map_foreign_batch(xc_interface return addr; } -void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot, - const xen_pfn_t *arr, int *err, unsigned int num) +static void *linux_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) { + int fd = (int)h; privcmd_mmapbatch_v2_t ioctlx; void *addr; unsigned int i; int rc; addr = mmap(NULL, (unsigned long)num << PAGE_SHIFT, prot, MAP_SHARED, - xch->fd, 0); + fd, 0); if ( addr == MAP_FAILED ) { PERROR("xc_map_foreign_batch: mmap failed"); @@ -176,7 +180,7 @@ void *xc_map_foreign_bulk(xc_interface * ioctlx.arr = arr; ioctlx.err = err; - rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx); + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx); if ( rc < 0 && errno == ENOENT ) { @@ -192,7 +196,7 @@ void *xc_map_foreign_bulk(xc_interface * ioctlx.err = err + i; do { usleep(100); - rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx); + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx); } while ( rc < 0 && err[i] == -ENOENT ); } } @@ -216,7 +220,7 @@ void *xc_map_foreign_bulk(xc_interface * ioctlx.addr = (unsigned long)addr; ioctlx.arr = pfn; - rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); rc = rc < 0 ? -errno : 0; @@ -236,7 +240,7 @@ void *xc_map_foreign_bulk(xc_interface * err[i] = rc ?: -EINVAL; continue; } - rc = xc_map_foreign_batch_single(xch, dom, pfn + i, + rc = xc_map_foreign_batch_single(fd, dom, pfn + i, (unsigned long)addr + ((unsigned long)i<<PAGE_SHIFT)); if ( rc < 0 ) { @@ -328,6 +332,9 @@ static struct xc_osdep_ops linux_privcmd .u.privcmd = { .hypercall = &linux_privcmd_hypercall, + + .map_foreign_batch = &linux_privcmd_map_foreign_batch, + .map_foreign_bulk = &linux_privcmd_map_foreign_bulk, }, }; diff -r 0d91fce8549e -r d0214e8537ce tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -93,8 +93,9 @@ static int minios_privcmd_hypercall(xc_i return call.result; } -void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot, - const xen_pfn_t *arr, int *err, unsigned int num) +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; #ifdef __ia64__ @@ -108,8 +109,9 @@ void *xc_map_foreign_bulk(xc_interface * return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot); } -void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, - xen_pfn_t *arr, int num) +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]; @@ -185,6 +187,9 @@ static struct xc_osdep_ops minios_privcm .u.privcmd = { .hypercall = &minios_privcmd_hypercall, + + .map_foreign_batch = &minios_privcmd_map_foreign_batch, + .map_foreign_bulk = &minios_privcmd_map_foreign_bulk, }, }; diff -r 0d91fce8549e -r d0214e8537ce tools/libxc/xc_misc.c --- a/tools/libxc/xc_misc.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_misc.c Fri Dec 03 09:36:47 2010 +0000 @@ -513,12 +513,9 @@ int xc_hvm_set_mem_type( /* stub for all not yet converted OSes */ -void * -#ifdef __GNUC__ -__attribute__((__weak__)) -#endif -xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot, - const xen_pfn_t *arr, int *err, unsigned int num) +void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int prot, + const xen_pfn_t *arr, int *err, unsigned int num) { xen_pfn_t *pfn; unsigned int i; diff -r 0d91fce8549e -r d0214e8537ce tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 @@ -79,9 +79,11 @@ static int netbsd_privcmd_hypercall(xc_i return hypercall->retval; } -void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, - xen_pfn_t *arr, int num) +static void *netbsd_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int prot, + xen_pfn_t *arr, int num) { + int fd = (int)h; privcmd_mmapbatch_t ioctlx; void *addr; addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_ANON | MAP_SHARED, -1, 0); @@ -94,7 +96,7 @@ void *xc_map_foreign_batch(xc_interface ioctlx.dom=dom; ioctlx.addr=(unsigned long)addr; ioctlx.arr=arr; - if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 ) + if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 ) { int saved_errno = errno; PERROR("xc_map_foreign_batch: ioctl failed"); @@ -178,6 +180,9 @@ static struct xc_osdep_ops netbsd_privcm .u.privcmd = { .hypercall = &netbsd_privcmd_hypercall; + + .map_foreign_batch = &netbsd_privcmd_map_foreign_batch, + .map_foreign_bulk = &xc_map_foreign_bulk_compat, }, }; diff -r 0d91fce8549e -r d0214e8537ce tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 @@ -74,12 +74,14 @@ static int solaris_privcmd_hypercall(xc_ return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall); } -void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, - xen_pfn_t *arr, int num) +static void *solaris_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int prot, + xen_pfn_t *arr, int num) { + int fd = (int)h; privcmd_mmapbatch_t ioctlx; void *addr; - addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xch->fd, 0); + addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, fd, 0); if ( addr == MAP_FAILED ) return NULL; @@ -87,7 +89,7 @@ void *xc_map_foreign_batch(xc_interface ioctlx.dom=dom; ioctlx.addr=(unsigned long)addr; ioctlx.arr=arr; - if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 ) + if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 ) { int saved_errno = errno; PERROR("XXXXXXXX"); @@ -168,6 +170,9 @@ static struct xc_osdep_ops solaris_privc .u.privcmd = { .hypercall = &solaris_privcmd_hypercall; + + .map_foreign_batch = &solaris_privcmd_map_foreign_batch, + .map_foreign_bulk = &xc_map_foreign_bulk_compat, }, }; diff -r 0d91fce8549e -r d0214e8537ce tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:46 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -63,6 +63,11 @@ struct xc_osdep_ops union { struct { int (*hypercall)(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall); + + void *(*map_foreign_batch)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot, + xen_pfn_t *arr, int num); + void *(*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); } privcmd; } u; }; @@ -83,6 +88,11 @@ typedef struct xc_osdep_info xc_osdep_in /* All backends, including the builtin backend, must supply this structure. */ extern xc_osdep_info_t xc_osdep_info; +/* Stub for not yet converted OSes */ +void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int prot, + const xen_pfn_t *arr, int *err, unsigned int num); + #endif /* _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 07 of 25] libxc: osdep: convert xc_map_foreign_range()
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID 1c71417729377312b82096541adec0bd19e8f2d0 # Parent d0214e8537cee3c401e5ba5567d632d386ac5860 libxc: osdep: convert xc_map_foreign_range() Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r d0214e8537ce -r 1c7141772937 tools/libxc/xc_foreign_memory.c --- a/tools/libxc/xc_foreign_memory.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_foreign_memory.c Fri Dec 03 09:36:47 2010 +0000 @@ -20,8 +20,15 @@ #include "xc_private.h" +void *xc_map_foreign_range(xc_interface *xch, uint32_t dom, + int size, int prot, unsigned long mfn) +{ + return xch->ops->u.privcmd.map_foreign_range(xch, xch->ops_handle, + dom, size, prot, mfn); +} + void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, - xen_pfn_t *arr, int num ) + xen_pfn_t *arr, int num) { return xch->ops->u.privcmd.map_foreign_batch(xch, xch->ops_handle, dom, prot, arr, num); @@ -33,3 +40,13 @@ void *xc_map_foreign_bulk(xc_interface * return xch->ops->u.privcmd.map_foreign_bulk(xch, xch->ops_handle, dom, prot, arr, err, num); } + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r d0214e8537ce -r 1c7141772937 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -283,8 +283,9 @@ static void *linux_privcmd_map_foreign_b return addr; } -void *xc_map_foreign_range(xc_interface *xch, uint32_t dom, int size, int prot, - unsigned long mfn) +static void *linux_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int size, int prot, + unsigned long mfn) { xen_pfn_t *arr; int num; @@ -335,6 +336,7 @@ static struct xc_osdep_ops linux_privcmd .map_foreign_batch = &linux_privcmd_map_foreign_batch, .map_foreign_bulk = &linux_privcmd_map_foreign_bulk, + .map_foreign_range = &linux_privcmd_map_foreign_range, }, }; diff -r d0214e8537ce -r 1c7141772937 tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -134,9 +134,10 @@ static void *minios_privcmd_map_foreign_ return (void *) addr; } -void *xc_map_foreign_range(xc_interface *xch, uint32_t dom, - int size, int prot, - unsigned long mfn) +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; #ifdef __ia64__ @@ -190,6 +191,7 @@ static struct xc_osdep_ops minios_privcm .map_foreign_batch = &minios_privcmd_map_foreign_batch, .map_foreign_bulk = &minios_privcmd_map_foreign_bulk, + .map_foreign_range = &minios_privcmd_map_foreign_range, }, }; diff -r d0214e8537ce -r 1c7141772937 tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 @@ -108,10 +108,12 @@ static void *netbsd_privcmd_map_foreign_ } -void *xc_map_foreign_range(xc_interface *xch, uint32_t dom, - int size, int prot, - unsigned long mfn) +static void *netbsd_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, + int size, int prot, + unsigned long mfn) { + int fd = (int)h; privcmd_mmap_t ioctlx; privcmd_mmap_entry_t entry; void *addr; @@ -127,7 +129,7 @@ void *xc_map_foreign_range(xc_interface entry.va=(unsigned long) addr; entry.mfn=mfn; entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT; - if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 ) + if ( ioctl(fd, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 ) { int saved_errno = errno; PERROR("xc_map_foreign_range: ioctl failed"); @@ -183,6 +185,7 @@ static struct xc_osdep_ops netbsd_privcm .map_foreign_batch = &netbsd_privcmd_map_foreign_batch, .map_foreign_bulk = &xc_map_foreign_bulk_compat, + .map_foreign_range = &netbsd_privcmd_map_foreign_range, }, }; diff -r d0214e8537ce -r 1c7141772937 tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 @@ -101,14 +101,16 @@ static void *solaris_privcmd_map_foreign } -void *xc_map_foreign_range(xc_interface *xch, uint32_t dom, - int size, int prot, - unsigned long mfn) +static void *xc_map_foreign_range(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, + int size, int prot, + unsigned long mfn) { + int fd = (int)fd; privcmd_mmap_t ioctlx; privcmd_mmap_entry_t entry; void *addr; - addr = mmap(NULL, size, prot, MAP_SHARED, xch->fd, 0); + addr = mmap(NULL, size, prot, MAP_SHARED, fd, 0); if ( addr == MAP_FAILED ) return NULL; @@ -118,7 +120,7 @@ void *xc_map_foreign_range(xc_interface entry.va=(unsigned long) addr; entry.mfn=mfn; entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT; - if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 ) + if ( ioctl(fd, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 ) { int saved_errno = errno; (void)munmap(addr, size); @@ -173,6 +175,7 @@ static struct xc_osdep_ops solaris_privc .map_foreign_batch = &solaris_privcmd_map_foreign_batch, .map_foreign_bulk = &xc_map_foreign_bulk_compat, + .map_foreign_range = &solaris_privcmd_map_foreign_range, }, }; diff -r d0214e8537ce -r 1c7141772937 tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -68,6 +68,8 @@ struct xc_osdep_ops xen_pfn_t *arr, int num); void *(*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); + void *(*map_foreign_range)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int size, int prot, + unsigned long mfn); } privcmd; } u; }; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 08 of 25] libxc: osdep: convert xc_map_foreign_ranges()
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID c4d555d68b742405874662bbc57bfe98a9e250dd # Parent 1c71417729377312b82096541adec0bd19e8f2d0 libxc: osdep: convert xc_map_foreign_ranges() Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 1c7141772937 -r c4d555d68b74 tools/libxc/xc_foreign_memory.c --- a/tools/libxc/xc_foreign_memory.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_foreign_memory.c Fri Dec 03 09:36:47 2010 +0000 @@ -27,6 +27,14 @@ void *xc_map_foreign_range(xc_interface dom, size, prot, mfn); } +void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom, + size_t size, int prot, size_t chunksize, + privcmd_mmap_entry_t entries[], int nentries) +{ + return xch->ops->u.privcmd.map_foreign_ranges(xch, xch->ops_handle, + dom, size, prot, chunksize, entries, nentries); +} + void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, xen_pfn_t *arr, int num) { diff -r 1c7141772937 -r c4d555d68b74 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -303,9 +303,10 @@ static void *linux_privcmd_map_foreign_r return ret; } -void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom, size_t size, int prot, - size_t chunksize, privcmd_mmap_entry_t entries[], - int nentries) +static void *linux_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) { xen_pfn_t *arr; int num_per_entry; @@ -337,6 +338,7 @@ static struct xc_osdep_ops linux_privcmd .map_foreign_batch = &linux_privcmd_map_foreign_batch, .map_foreign_bulk = &linux_privcmd_map_foreign_bulk, .map_foreign_range = &linux_privcmd_map_foreign_range, + .map_foreign_ranges = &linux_privcmd_map_foreign_ranges, }, }; diff -r 1c7141772937 -r c4d555d68b74 tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -152,9 +152,10 @@ static void *minios_privcmd_map_foreign_ return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom, NULL, pt_prot); } -void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom, - size_t size, int prot, size_t chunksize, - privcmd_mmap_entry_t entries[], int nentries) +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; @@ -192,6 +193,7 @@ static struct xc_osdep_ops minios_privcm .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, }, }; diff -r 1c7141772937 -r c4d555d68b74 tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 @@ -140,10 +140,12 @@ static void *netbsd_privcmd_map_foreign_ return addr; } -void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom, - size_t size, int prot, size_t chunksize, - privcmd_mmap_entry_t entries[], int nentries) +static void *netbsd_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) { + int fd = (int)h; privcmd_mmap_t ioctlx; int i, rc; void *addr; @@ -161,7 +163,7 @@ void *xc_map_foreign_ranges(xc_interface ioctlx.dom = dom; ioctlx.entry = entries; - rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAP, &ioctlx); + rc = ioctl(fd, IOCTL_PRIVCMD_MMAP, &ioctlx); if (rc) goto ioctl_failed; @@ -186,6 +188,7 @@ static struct xc_osdep_ops netbsd_privcm .map_foreign_batch = &netbsd_privcmd_map_foreign_batch, .map_foreign_bulk = &xc_map_foreign_bulk_compat, .map_foreign_range = &netbsd_privcmd_map_foreign_range, + .map_foreign_ranges = &netbsd_privcmd_map_foreign_ranges, }, }; diff -r 1c7141772937 -r c4d555d68b74 tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 @@ -130,15 +130,17 @@ static void *xc_map_foreign_range(xc_int return addr; } -void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom, - size_t size, int prot, size_t chunksize, - privcmd_mmap_entry_t entries[], int nentries) +static void *solaric_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) { + int fd = (int)fd; privcmd_mmap_t ioctlx; int i, rc; void *addr; - addr = mmap(NULL, size, prot, MAP_SHARED, xch->fd, 0); + addr = mmap(NULL, size, prot, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) goto mmap_failed; @@ -151,7 +153,7 @@ void *xc_map_foreign_ranges(xc_interface ioctlx.dom = dom; ioctlx.entry = entries; - rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAP, &ioctlx); + rc = ioctl(fd, IOCTL_PRIVCMD_MMAP, &ioctlx); if (rc) goto ioctl_failed; @@ -176,6 +178,7 @@ static struct xc_osdep_ops solaris_privc .map_foreign_batch = &solaris_privcmd_map_foreign_batch, .map_foreign_bulk = &xc_map_foreign_bulk_compat, .map_foreign_range = &solaris_privcmd_map_foreign_range, + .map_foreign_ranges = &solaris_privcmd_map_foreign_ranges, }, }; diff -r 1c7141772937 -r c4d555d68b74 tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -70,6 +70,9 @@ struct xc_osdep_ops const xen_pfn_t *arr, int *err, unsigned int num); void *(*map_foreign_range)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int size, int prot, unsigned long mfn); + void *(*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); } privcmd; } u; }; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 09 of 25] libxc: osdep: convert xc_evtchn_fd()
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID 48c16f1810aa383774b6c0e373d24838c7affffc # Parent c4d555d68b742405874662bbc57bfe98a9e250dd libxc: osdep: convert xc_evtchn_fd() Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r c4d555d68b74 -r 48c16f1810aa tools/libxc/xc_evtchn.c --- a/tools/libxc/xc_evtchn.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_evtchn.c Fri Dec 03 09:36:47 2010 +0000 @@ -77,3 +77,8 @@ int xc_evtchn_status(xc_interface *xch, return do_evtchn_op(xch, EVTCHNOP_status, status, sizeof(*status), 1); } + +int xc_evtchn_fd(xc_evtchn *xce) +{ + return xce->ops->u.evtchn.fd(xce, xce->ops_handle); +} diff -r c4d555d68b74 -r 48c16f1810aa tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -360,9 +360,9 @@ static int linux_evtchn_close(xc_evtchn return close(fd); } -int xc_evtchn_fd(xc_evtchn *xce) +static int linux_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h) { - return xce->fd; + return (int)h; } int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) @@ -434,6 +434,10 @@ static struct xc_osdep_ops linux_evtchn_ static struct xc_osdep_ops linux_evtchn_ops = { .open = &linux_evtchn_open, .close = &linux_evtchn_close, + + .u.evtchn = { + .fd = &linux_evtchn_fd, + }, }; /* Optionally flush file to disk and discard page cache */ diff -r c4d555d68b74 -r 48c16f1810aa tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -226,9 +226,9 @@ void minios_evtchn_close_fd(int fd) files[fd].type = FTYPE_NONE; } -int xc_evtchn_fd(xc_evtchn *xce) +static int minios_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h) { - return xce->fd; + return (int)h; } int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) @@ -400,6 +400,10 @@ static struct xc_osdep_ops minios_evtchn static struct xc_osdep_ops minios_evtchn_ops = { .open = &minios_evtchn_open, .close = &minios_evtchn_close, + + .u.evtchn = { + .fd = &minios_evtchn_fd, + }, }; /* Optionally flush file to disk and discard page cache */ diff -r c4d555d68b74 -r 48c16f1810aa tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 @@ -210,9 +210,9 @@ static int netbsd_evtchn_close(xc_evtchn return close(fd); } -int xc_evtchn_fd(xc_evtchn *xce) +static int netbsd_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h) { - return xce->fd; + return (int)h; } int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) @@ -299,6 +299,10 @@ static struct xc_osdep_ops netbsd_evtchn static struct xc_osdep_ops netbsd_evtchn_ops = { .open = &netbsd_evtchn_open, .close = &netbsd_evtchn_close, + + .u.evtchn = { + .fd = &netbsd_evtchn_fd, + }, }; /* Optionally flush file to disk and discard page cache */ diff -r c4d555d68b74 -r 48c16f1810aa tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 @@ -202,9 +202,9 @@ static int solaris_evtchn_close(xc_evtch return close(fd); } -int xc_evtchn_fd(xc_evtchn *xce) +static int solaris_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h) { - return xce->fd; + return (int)h; } int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) @@ -276,6 +276,10 @@ static struct xc_osdep_ops solaris_evtch static struct xc_osdep_ops solaris_evtchn_ops = { .open = &solaris_evtchn_open, .close = &solaris_evtchn_close, + + .u.evtchn = { + .fd = &solaris_evtchn_fd, + }, }; /* Optionally flush file to disk and discard page cache */ diff -r c4d555d68b74 -r 48c16f1810aa tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -74,6 +74,9 @@ struct xc_osdep_ops size_t chunksize, privcmd_mmap_entry_t entries[], int nentries); } privcmd; + struct { + int (*fd)(xc_evtchn *xce, xc_osdep_handle h); + } evtchn; } u; }; typedef struct xc_osdep_ops xc_osdep_ops; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 10 of 25] libxc: osdep: convert xc_evtchn_notify()
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID f8ada96329da34e94ac3a7f4a6c6967aa5d2dd73 # Parent 48c16f1810aa383774b6c0e373d24838c7affffc libxc: osdep: convert xc_evtchn_notify() Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 48c16f1810aa -r f8ada96329da tools/libxc/xc_evtchn.c --- a/tools/libxc/xc_evtchn.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_evtchn.c Fri Dec 03 09:36:47 2010 +0000 @@ -82,3 +82,18 @@ int xc_evtchn_fd(xc_evtchn *xce) { return xce->ops->u.evtchn.fd(xce, xce->ops_handle); } + +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) +{ + return xce->ops->u.evtchn.notify(xce, xce->ops_handle, port); +} + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r 48c16f1810aa -r f8ada96329da tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -365,13 +365,14 @@ static int linux_evtchn_fd(xc_evtchn *xc return (int)h; } -int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) +static int linux_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(xce->fd, IOCTL_EVTCHN_NOTIFY, ¬ify); + return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } evtchn_port_or_error_t @@ -437,6 +438,7 @@ static struct xc_osdep_ops linux_evtchn_ .u.evtchn = { .fd = &linux_evtchn_fd, + .notify = &linux_evtchn_notify, }, }; diff -r 48c16f1810aa -r f8ada96329da tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -231,7 +231,7 @@ static int minios_evtchn_fd(xc_evtchn *x return (int)h; } -int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) +static int minios_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) { int ret; @@ -403,6 +403,7 @@ static struct xc_osdep_ops minios_evtchn .u.evtchn = { .fd = &minios_evtchn_fd, + .notify = &minios_evtchn_notify, }, }; diff -r 48c16f1810aa -r f8ada96329da tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 @@ -215,13 +215,14 @@ static int netbsd_evtchn_fd(xc_evtchn *x return (int)h; } -int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) +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(xce->fd, IOCTL_EVTCHN_NOTIFY, ¬ify); + return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } evtchn_port_or_error_t @@ -301,7 +302,8 @@ static struct xc_osdep_ops netbsd_evtchn .close = &netbsd_evtchn_close, .u.evtchn = { - .fd = &netbsd_evtchn_fd, + .fd = &netbsd_evtchn_fd, + .notify = &netbsd_evtchn_notify, }, }; diff -r 48c16f1810aa -r f8ada96329da tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 @@ -207,13 +207,14 @@ static int solaris_evtchn_fd(xc_evtchn * return (int)h; } -int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port) +static int solaris_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(xce->fd, IOCTL_EVTCHN_NOTIFY, ¬ify); + return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } evtchn_port_or_error_t @@ -279,6 +280,7 @@ static struct xc_osdep_ops solaris_evtch .u.evtchn = { .fd = &solaris_evtchn_fd, + .notify = &solaris_evtchn_notify, }, }; diff -r 48c16f1810aa -r f8ada96329da tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -76,6 +76,8 @@ struct xc_osdep_ops } privcmd; struct { int (*fd)(xc_evtchn *xce, xc_osdep_handle h); + + int (*notify)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port); } evtchn; } u; }; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 11 of 25] libxc: osdep: convert xc_evtchn_bind_unbound_port()
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID 8d07a123c875c57d0b1127d9a0cbd86c27c857d5 # Parent f8ada96329da34e94ac3a7f4a6c6967aa5d2dd73 libxc: osdep: convert xc_evtchn_bind_unbound_port() Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r f8ada96329da -r 8d07a123c875 tools/libxc/xc_evtchn.c --- a/tools/libxc/xc_evtchn.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_evtchn.c Fri Dec 03 09:36:47 2010 +0000 @@ -88,6 +88,12 @@ int xc_evtchn_notify(xc_evtchn *xce, evt return xce->ops->u.evtchn.notify(xce, xce->ops_handle, port); } +evtchn_port_or_error_t +xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) +{ + return xce->ops->u.evtchn.bind_unbound_port(xce, xce->ops_handle, domid); +} + /* * Local variables: * mode: C diff -r f8ada96329da -r 8d07a123c875 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -375,14 +375,15 @@ static int linux_evtchn_notify(xc_evtchn return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } -evtchn_port_or_error_t -xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) +static evtchn_port_or_error_t +linux_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid) { + int fd = (int)h; struct ioctl_evtchn_bind_unbound_port bind; bind.remote_domain = domid; - return ioctl(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); + return ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); } evtchn_port_or_error_t @@ -439,6 +440,7 @@ static struct xc_osdep_ops linux_evtchn_ .u.evtchn = { .fd = &linux_evtchn_fd, .notify = &linux_evtchn_notify, + .bind_unbound_port = &linux_evtchn_bind_unbound_port, }, }; diff -r f8ada96329da -r 8d07a123c875 tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -277,26 +277,27 @@ static void evtchn_handler(evtchn_port_t wake_up(&event_queue); } -evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) +static evtchn_port_or_error_t minios_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid) { + int fd = (int)h; int ret, i; evtchn_port_t port; assert(get_current() == main_thread); - i = port_alloc(xce->fd); + i = port_alloc(fd); if (i == -1) return -1; printf("xc_evtchn_bind_unbound_port(%d)", domid); - ret = evtchn_alloc_unbound(domid, evtchn_handler, (void*)(intptr_t)xce->fd, &port); + ret = evtchn_alloc_unbound(domid, evtchn_handler, (void*)(intptr_t)fd, &port); printf(" = %d\n", ret); if (ret < 0) { errno = -ret; return -1; } - files[xce->fd].evtchn.ports[i].bound = 1; - files[xce->fd].evtchn.ports[i].port = port; + files[fd].evtchn.ports[i].bound = 1; + files[fd].evtchn.ports[i].port = port; unmask_evtchn(port); return port; } @@ -404,6 +405,7 @@ static struct xc_osdep_ops minios_evtchn .u.evtchn = { .fd = &minios_evtchn_fd, .notify = &minios_evtchn_notify, + .bind_unbound_port = &minios_evtchn_bind_unbound_port, }, }; diff -r f8ada96329da -r 8d07a123c875 tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 @@ -225,15 +225,16 @@ static int netbsd_evtchn_notify(xc_evtch return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } -evtchn_port_or_error_t -xc_evtchn_bind_unbound_port(xc_evtchn * xce, int domid) +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(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); + ret = ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); if (ret == 0) return bind.port; else @@ -304,6 +305,7 @@ static struct xc_osdep_ops netbsd_evtchn .u.evtchn = { .fd = &netbsd_evtchn_fd, .notify = &netbsd_evtchn_notify, + .bind_unbound_port = &netbsd_evtchn_bind_unbound_port, }, }; diff -r f8ada96329da -r 8d07a123c875 tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 @@ -217,14 +217,15 @@ static int solaris_evtchn_notify(xc_evtc return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } -evtchn_port_or_error_t -xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) +static evtchn_port_or_error_t +solaris_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid) { + int fd = (int)h; struct ioctl_evtchn_bind_unbound_port bind; bind.remote_domain = domid; - return ioctl(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); + return ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); } evtchn_port_or_error_t @@ -281,6 +282,7 @@ static struct xc_osdep_ops solaris_evtch .u.evtchn = { .fd = &solaris_evtchn_fd, .notify = &solaris_evtchn_notify, + .bind_unbound_port = &solaris_evtchn_bind_unbound_port, }, }; diff -r f8ada96329da -r 8d07a123c875 tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -78,6 +78,8 @@ struct xc_osdep_ops int (*fd)(xc_evtchn *xce, xc_osdep_handle h); int (*notify)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port); + + evtchn_port_or_error_t (*bind_unbound_port)(xc_evtchn *xce, xc_osdep_handle h, int domid); } evtchn; } u; }; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 12 of 25] libxc: osdep: convert xc_evtchn_bind_interdomain()
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID 7a24de957ebbf9ac8681962c0e6dccf4c657a1dc # Parent 8d07a123c875c57d0b1127d9a0cbd86c27c857d5 libxc: osdep: convert xc_evtchn_bind_interdomain() Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 8d07a123c875 -r 7a24de957ebb tools/libxc/xc_evtchn.c --- a/tools/libxc/xc_evtchn.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_evtchn.c Fri Dec 03 09:36:47 2010 +0000 @@ -94,6 +94,13 @@ xc_evtchn_bind_unbound_port(xc_evtchn *x return xce->ops->u.evtchn.bind_unbound_port(xce, xce->ops_handle, domid); } +evtchn_port_or_error_t +xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, + evtchn_port_t remote_port) +{ + return xce->ops->u.evtchn.bind_interdomain(xce, xce->ops_handle, domid, remote_port); +} + /* * Local variables: * mode: C diff -r 8d07a123c875 -r 7a24de957ebb tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -386,16 +386,17 @@ linux_evtchn_bind_unbound_port(xc_evtchn return ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); } -evtchn_port_or_error_t -xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, - evtchn_port_t remote_port) +static evtchn_port_or_error_t +linux_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; bind.remote_domain = domid; bind.remote_port = remote_port; - return ioctl(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); + return ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); } evtchn_port_or_error_t @@ -441,6 +442,7 @@ static struct xc_osdep_ops linux_evtchn_ .fd = &linux_evtchn_fd, .notify = &linux_evtchn_notify, .bind_unbound_port = &linux_evtchn_bind_unbound_port, + .bind_interdomain = &linux_evtchn_bind_interdomain, }, }; diff -r 8d07a123c875 -r 7a24de957ebb tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -302,27 +302,28 @@ static evtchn_port_or_error_t minios_evt return port; } -evtchn_port_or_error_t xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, +static evtchn_port_or_error_t minios_evtchn_bind_interdomain(xc_evtchn *xce, xc_osdep_handle h, int domid, evtchn_port_t remote_port) { + int fd = (int)h; evtchn_port_t local_port; int ret, i; assert(get_current() == main_thread); - i = port_alloc(xce->fd); + i = port_alloc(fd); if (i == -1) return -1; printf("xc_evtchn_bind_interdomain(%d, %"PRId32")", domid, remote_port); - ret = evtchn_bind_interdomain(domid, remote_port, evtchn_handler, (void*)(intptr_t)xce->fd, &local_port); + ret = evtchn_bind_interdomain(domid, remote_port, evtchn_handler, (void*)(intptr_t)fd, &local_port); printf(" = %d\n", ret); if (ret < 0) { errno = -ret; return -1; } - files[xce->fd].evtchn.ports[i].bound = 1; - files[xce->fd].evtchn.ports[i].port = local_port; + files[fd].evtchn.ports[i].bound = 1; + files[fd].evtchn.ports[i].port = local_port; unmask_evtchn(local_port); return local_port; } @@ -406,6 +407,7 @@ static struct xc_osdep_ops minios_evtchn .fd = &minios_evtchn_fd, .notify = &minios_evtchn_notify, .bind_unbound_port = &minios_evtchn_bind_unbound_port, + .bind_interdomain = &minios_evtchn_bind_interdomain, }, }; diff -r 8d07a123c875 -r 7a24de957ebb tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 @@ -241,17 +241,18 @@ netbsd_evtchn_bind_unbound_port(xc_evtch return -1; } -evtchn_port_or_error_t -xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, - evtchn_port_t remote_port) +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(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); + ret = ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); if (ret == 0) return bind.port; else @@ -306,6 +307,7 @@ static struct xc_osdep_ops netbsd_evtchn .fd = &netbsd_evtchn_fd, .notify = &netbsd_evtchn_notify, .bind_unbound_port = &netbsd_evtchn_bind_unbound_port, + .bind_interdomain = &netbsd_evtchn_bind_interdomain, }, }; diff -r 8d07a123c875 -r 7a24de957ebb tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 @@ -229,15 +229,16 @@ solaris_evtchn_bind_unbound_port(xc_evtc } evtchn_port_or_error_t -xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, +solaris_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; bind.remote_domain = domid; bind.remote_port = remote_port; - return ioctl(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); + return ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); } evtchn_port_or_error_t @@ -283,6 +284,7 @@ static struct xc_osdep_ops solaris_evtch .fd = &solaris_evtchn_fd, .notify = &solaris_evtchn_notify, .bind_unbound_port = &solaris_evtchn_bind_unbound_port, + .bind_interdomain = &solaris_evtchn_bind_interdomain, }, }; diff -r 8d07a123c875 -r 7a24de957ebb tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -80,6 +80,8 @@ struct xc_osdep_ops int (*notify)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port); evtchn_port_or_error_t (*bind_unbound_port)(xc_evtchn *xce, xc_osdep_handle h, int domid); + evtchn_port_or_error_t (*bind_interdomain)(xc_evtchn *xce, xc_osdep_handle h, int domid, + evtchn_port_t remote_port); } evtchn; } u; }; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 13 of 25] libxc: osdep: convert xc_evtchn_bind_virq()
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID 32767e7632ccac87a9b0b33ec8a2322a7938af68 # Parent 7a24de957ebbf9ac8681962c0e6dccf4c657a1dc libxc: osdep: convert xc_evtchn_bind_virq() Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 7a24de957ebb -r 32767e7632cc tools/libxc/xc_evtchn.c --- a/tools/libxc/xc_evtchn.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_evtchn.c Fri Dec 03 09:36:47 2010 +0000 @@ -101,6 +101,12 @@ xc_evtchn_bind_interdomain(xc_evtchn *xc return xce->ops->u.evtchn.bind_interdomain(xce, xce->ops_handle, domid, remote_port); } +evtchn_port_or_error_t +xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) +{ + return xce->ops->u.evtchn.bind_virq(xce, xce->ops_handle, virq); +} + /* * Local variables: * mode: C diff -r 7a24de957ebb -r 32767e7632cc tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -399,14 +399,15 @@ linux_evtchn_bind_interdomain(xc_evtchn return ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); } -evtchn_port_or_error_t -xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) +static evtchn_port_or_error_t +linux_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) { + int fd = (int)h; struct ioctl_evtchn_bind_virq bind; bind.virq = virq; - return ioctl(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); + return ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); } int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) @@ -443,6 +444,7 @@ static struct xc_osdep_ops linux_evtchn_ .notify = &linux_evtchn_notify, .bind_unbound_port = &linux_evtchn_bind_unbound_port, .bind_interdomain = &linux_evtchn_bind_interdomain, + .bind_virq = &linux_evtchn_bind_virq, }, }; diff -r 7a24de957ebb -r 32767e7632cc tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -346,25 +346,26 @@ int xc_evtchn_unbind(xc_evtchn *xce, evt return 0; } -evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) +static evtchn_port_or_error_t minios_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) { + int fd = (int)h; evtchn_port_t port; int i; assert(get_current() == main_thread); - i = port_alloc(xce->fd); + i = port_alloc(fd); if (i == -1) return -1; printf("xc_evtchn_bind_virq(%d)", virq); - port = bind_virq(virq, evtchn_handler, (void*)(intptr_t)xce->fd); + port = bind_virq(virq, evtchn_handler, (void*)(intptr_t)fd); if (port < 0) { errno = -port; return -1; } - files[xce->fd].evtchn.ports[i].bound = 1; - files[xce->fd].evtchn.ports[i].port = port; + files[fd].evtchn.ports[i].bound = 1; + files[fd].evtchn.ports[i].port = port; unmask_evtchn(port); return port; } @@ -408,6 +409,7 @@ static struct xc_osdep_ops minios_evtchn .notify = &minios_evtchn_notify, .bind_unbound_port = &minios_evtchn_bind_unbound_port, .bind_interdomain = &minios_evtchn_bind_interdomain, + .bind_virq = &minios_evtchn_bind_virq, }, }; diff -r 7a24de957ebb -r 32767e7632cc tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 @@ -268,15 +268,16 @@ int xc_evtchn_unbind(xc_evtchn *xce, evt return ioctl(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind); } -evtchn_port_or_error_t -xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) +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(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); + err = ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); if (err) return -1; else @@ -308,6 +309,7 @@ static struct xc_osdep_ops netbsd_evtchn .notify = &netbsd_evtchn_notify, .bind_unbound_port = &netbsd_evtchn_bind_unbound_port, .bind_interdomain = &netbsd_evtchn_bind_interdomain, + .bind_virq = &netbsd_evtchn_bind_virq, }, }; diff -r 7a24de957ebb -r 32767e7632cc tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 @@ -241,14 +241,15 @@ solaris_evtchn_bind_interdomain(xc_evtch return ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); } -evtchn_port_or_error_t -xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) +static evtchn_port_or_error_t +solaris_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) { + int fd = (int)h; struct ioctl_evtchn_bind_virq bind; bind.virq = virq; - return ioctl(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); + return ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); } int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) @@ -285,6 +286,7 @@ static struct xc_osdep_ops solaris_evtch .notify = &solaris_evtchn_notify, .bind_unbound_port = &solaris_evtchn_bind_unbound_port, .bind_interdomain = &solaris_evtchn_bind_interdomain, + .bind_virq = &solaris_evtchn_bind_virq, }, }; diff -r 7a24de957ebb -r 32767e7632cc tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -82,6 +82,7 @@ struct xc_osdep_ops evtchn_port_or_error_t (*bind_unbound_port)(xc_evtchn *xce, xc_osdep_handle h, int domid); evtchn_port_or_error_t (*bind_interdomain)(xc_evtchn *xce, xc_osdep_handle h, int domid, evtchn_port_t remote_port); + evtchn_port_or_error_t (*bind_virq)(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq); } evtchn; } u; }; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 14 of 25] libxc: osdep: convert xc_evtchn_unbind()
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID 03b9f81f1f367a2143e2ef48fd7f2a57b0c47643 # Parent 32767e7632ccac87a9b0b33ec8a2322a7938af68 libxc: osdep: convert xc_evtchn_unbind() Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 32767e7632cc -r 03b9f81f1f36 tools/libxc/xc_evtchn.c --- a/tools/libxc/xc_evtchn.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_evtchn.c Fri Dec 03 09:36:47 2010 +0000 @@ -107,6 +107,11 @@ xc_evtchn_bind_virq(xc_evtchn *xce, unsi return xce->ops->u.evtchn.bind_virq(xce, xce->ops_handle, virq); } +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) +{ + return xce->ops->u.evtchn.unbind(xce, xce->ops_handle, port); +} + /* * Local variables: * mode: C diff -r 32767e7632cc -r 03b9f81f1f36 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -410,13 +410,14 @@ linux_evtchn_bind_virq(xc_evtchn *xce, x return ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); } -int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) +static int linux_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(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind); + return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind); } evtchn_port_or_error_t @@ -445,6 +446,7 @@ static struct xc_osdep_ops linux_evtchn_ .bind_unbound_port = &linux_evtchn_bind_unbound_port, .bind_interdomain = &linux_evtchn_bind_interdomain, .bind_virq = &linux_evtchn_bind_virq, + .unbind = &linux_evtchn_unbind, }, }; diff -r 32767e7632cc -r 03b9f81f1f36 tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -328,20 +328,21 @@ static evtchn_port_or_error_t minios_evt return local_port; } -int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) +static int minios_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) { + int fd = (int)h; int i; for (i = 0; i < MAX_EVTCHN_PORTS; i++) - if (files[xce->fd].evtchn.ports[i].port == port) { - files[xce->fd].evtchn.ports[i].port = -1; + if (files[fd].evtchn.ports[i].port == port) { + files[fd].evtchn.ports[i].port = -1; break; } if (i == MAX_EVTCHN_PORTS) { - printf("Warning: couldn''t find port %"PRId32" for xc handle %x\n", port, xce->fd); + printf("Warning: couldn''t find port %"PRId32" for xc handle %x\n", port, fd); errno = -EINVAL; return -1; } - files[xce->fd].evtchn.ports[i].bound = 0; + files[fd].evtchn.ports[i].bound = 0; unbind_evtchn(port); return 0; } @@ -410,6 +411,7 @@ static struct xc_osdep_ops minios_evtchn .bind_unbound_port = &minios_evtchn_bind_unbound_port, .bind_interdomain = &minios_evtchn_bind_interdomain, .bind_virq = &minios_evtchn_bind_virq, + .unbind = &minios_evtchn_unbind, }, }; diff -r 32767e7632cc -r 03b9f81f1f36 tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 @@ -259,13 +259,14 @@ netbsd_evtchn_bind_interdomain(xc_evtchn return -1; } -int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) +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(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind); + return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind); } static evtchn_port_or_error_t @@ -310,6 +311,7 @@ static struct xc_osdep_ops netbsd_evtchn .bind_unbound_port = &netbsd_evtchn_bind_unbound_port, .bind_interdomain = &netbsd_evtchn_bind_interdomain, .bind_virq = &netbsd_evtchn_bind_virq, + .unbind = &netbsd_evtchn_unbind, }, }; diff -r 32767e7632cc -r 03b9f81f1f36 tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 @@ -252,13 +252,14 @@ solaris_evtchn_bind_virq(xc_evtchn *xce, return ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); } -int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port) +static int solaris_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(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind); + return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind); } evtchn_port_or_error_t @@ -287,6 +288,7 @@ static struct xc_osdep_ops solaris_evtch .bind_unbound_port = &solaris_evtchn_bind_unbound_port, .bind_interdomain = &solaris_evtchn_bind_interdomain, .bind_virq = &solaris_evtchn_bind_virq, + .unbind = &solaris_evtchn_unbind, }, }; diff -r 32767e7632cc -r 03b9f81f1f36 tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -83,6 +83,8 @@ struct xc_osdep_ops evtchn_port_or_error_t (*bind_interdomain)(xc_evtchn *xce, xc_osdep_handle h, int domid, evtchn_port_t remote_port); evtchn_port_or_error_t (*bind_virq)(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq); + + int (*unbind)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port); } evtchn; } u; }; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 15 of 25] libxc: osdep: convert xc_evtchn_{pending, unmask}()
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID 3e8cb37144eb01a1ebb843882f4c3f43d0b4bd26 # Parent 03b9f81f1f367a2143e2ef48fd7f2a57b0c47643 libxc: osdep: convert xc_evtchn_{pending,unmask}() Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 03b9f81f1f36 -r 3e8cb37144eb tools/libxc/xc_evtchn.c --- a/tools/libxc/xc_evtchn.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_evtchn.c Fri Dec 03 09:36:47 2010 +0000 @@ -112,6 +112,17 @@ int xc_evtchn_unbind(xc_evtchn *xce, evt return xce->ops->u.evtchn.unbind(xce, xce->ops_handle, port); } +evtchn_port_or_error_t +xc_evtchn_pending(xc_evtchn *xce) +{ + return xce->ops->u.evtchn.pending(xce, xce->ops_handle); +} + +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) +{ + return xce->ops->u.evtchn.unmask(xce, xce->ops_handle, port); +} + /* * Local variables: * mode: C diff -r 03b9f81f1f36 -r 3e8cb37144eb tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -420,20 +420,24 @@ static int linux_evtchn_unbind(xc_evtchn return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind); } -evtchn_port_or_error_t -xc_evtchn_pending(xc_evtchn *xce) +static evtchn_port_or_error_t linux_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) { + int fd = (int)h; evtchn_port_t port; - if ( read_exact(xce->fd, (char *)&port, sizeof(port)) == -1 ) + if ( read(fd, &port, sizeof(port)) != sizeof(port) ) return -1; return port; } -int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) +static int linux_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) { - return write_exact(xce->fd, (char *)&port, sizeof(port)); + int fd = (int)h; + + if ( write(fd, &port, sizeof(port)) != sizeof(port) ) + return -1; + return 0; } static struct xc_osdep_ops linux_evtchn_ops = { @@ -447,6 +451,8 @@ static struct xc_osdep_ops linux_evtchn_ .bind_interdomain = &linux_evtchn_bind_interdomain, .bind_virq = &linux_evtchn_bind_virq, .unbind = &linux_evtchn_unbind, + .pending = &linux_evtchn_pending, + .unmask = &linux_evtchn_unmask, }, }; diff -r 03b9f81f1f36 -r 3e8cb37144eb tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -371,22 +371,23 @@ static evtchn_port_or_error_t minios_evt return port; } -evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce) +static evtchn_port_or_error_t minios_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) { + int fd = (int)h; int i; unsigned long flags; evtchn_port_t ret = -1; local_irq_save(flags); - files[xce->fd].read = 0; + files[fd].read = 0; for (i = 0; i < MAX_EVTCHN_PORTS; i++) { - evtchn_port_t port = files[xce->fd].evtchn.ports[i].port; - if (port != -1 && files[xce->fd].evtchn.ports[i].pending) { + evtchn_port_t port = files[fd].evtchn.ports[i].port; + if (port != -1 && files[fd].evtchn.ports[i].pending) { if (ret == -1) { ret = port; - files[xce->fd].evtchn.ports[i].pending = 0; + files[fd].evtchn.ports[i].pending = 0; } else { - files[xce->fd].read = 1; + files[fd].read = 1; break; } } @@ -395,7 +396,7 @@ evtchn_port_or_error_t xc_evtchn_pending return ret; } -int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) +static int minios_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) { unmask_evtchn(port); return 0; @@ -412,7 +413,9 @@ static struct xc_osdep_ops minios_evtchn .bind_interdomain = &minios_evtchn_bind_interdomain, .bind_virq = &minios_evtchn_bind_virq, .unbind = &minios_evtchn_unbind, - }, + .pending = &minios_evtchn_pending, + .unmask = &minios_evtchn_unmask, + }, }; /* Optionally flush file to disk and discard page cache */ diff -r 03b9f81f1f36 -r 3e8cb37144eb tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 @@ -285,20 +285,22 @@ netbsd_evtchn_bind_virq(xc_evtchn *xce, return bind.port; } -evtchn_port_or_error_t -xc_evtchn_pending(xc_evtchn *xce) +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(xce->fd, (char *)&port, sizeof(port)) == -1 ) + if ( read_exact(fd, (char *)&port, sizeof(port)) == -1 ) return -1; return port; } -int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) +static int netbsd_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) { - return write_exact(xce->fd, (char *)&port, sizeof(port)); + int fd = (int)h; + return write_exact(fd, (char *)&port, sizeof(port)); } static struct xc_osdep_ops netbsd_evtchn_ops = { @@ -312,6 +314,8 @@ static struct xc_osdep_ops netbsd_evtchn .bind_interdomain = &netbsd_evtchn_bind_interdomain, .bind_virq = &netbsd_evtchn_bind_virq, .unbind = &netbsd_evtchn_unbind, + .pending = &netbsd_evtchn_pending, + .unmask = &netbsd_evtchn_unmask, }, }; diff -r 03b9f81f1f36 -r 3e8cb37144eb tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 @@ -262,20 +262,22 @@ static int solaris_evtchn_unbind(xc_evtc return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind); } -evtchn_port_or_error_t -xc_evtchn_pending(xc_evtchn *xce) +static evtchn_port_or_error_t +solaris_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) { + int fd = (int)h; evtchn_port_t port; - if ( read_exact(xce->fd, (char *)&port, sizeof(port)) == -1 ) + if ( read_exact(fd, (char *)&port, sizeof(port)) == -1 ) return -1; return port; } -int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port) +static int solaris_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h,evtchn_port_t port) { - return write_exact(xce->fd, (char *)&port, sizeof(port)); + int fd = (int)h; + return write_exact(fd, (char *)&port, sizeof(port)); } static struct xc_osdep_ops solaris_evtchn_ops = { @@ -289,6 +291,8 @@ static struct xc_osdep_ops solaris_evtch .bind_interdomain = &solaris_evtchn_bind_interdomain, .bind_virq = &solaris_evtchn_bind_virq, .unbind = &solaris_evtchn_unbind, + .pending = &solaris_evtchn_pending, + .unmask = &solaris_evtchn_unmask, }, }; diff -r 03b9f81f1f36 -r 3e8cb37144eb tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -85,6 +85,9 @@ struct xc_osdep_ops evtchn_port_or_error_t (*bind_virq)(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq); int (*unbind)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port); + + evtchn_port_or_error_t (*pending)(xc_evtchn *xce, xc_osdep_handle h); + int (*unmask)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port); } evtchn; } u; }; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 16 of 25] libxc: osdep: convert xc_gnttab_map_{grant_ref, grant_refs, domain_grant_refs}()
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID 68996338758eabdecbdfc5cfb4aa82ab7589b4e6 # Parent 3e8cb37144eb01a1ebb843882f4c3f43d0b4bd26 libxc: osdep: convert xc_gnttab_map_{grant_ref,grant_refs,domain_grant_refs}() Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 3e8cb37144eb -r 68996338758e tools/libxc/xc_gnttab.c --- a/tools/libxc/xc_gnttab.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_gnttab.c Fri Dec 03 09:36:47 2010 +0000 @@ -145,3 +145,41 @@ grant_entry_v2_t *xc_gnttab_map_table_v2 return _gnttab_map_table(xch, domid, gnt_num); } +void *xc_gnttab_map_grant_ref(xc_gnttab *xcg, + uint32_t domid, + uint32_t ref, + int prot) +{ + return xcg->ops->u.gnttab.map_grant_ref(xcg, xcg->ops_handle, + domid, ref, prot); +} + +void *xc_gnttab_map_grant_refs(xc_gnttab *xcg, + uint32_t count, + uint32_t *domids, + uint32_t *refs, + int prot) +{ + return xcg->ops->u.gnttab.map_grant_refs(xcg, xcg->ops_handle, + count, domids, refs, prot); +} + +void *xc_gnttab_map_domain_grant_refs(xc_gnttab *xcg, + uint32_t count, + uint32_t domid, + uint32_t *refs, + int prot) +{ + return xcg->ops->u.gnttab.map_domain_grant_refs(xcg, xcg->ops_handle, + count, domid, refs, prot); +} + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r 3e8cb37144eb -r 68996338758e tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -508,8 +508,10 @@ static int linux_gnttab_close(xc_gnttab return close(fd); } -void *xc_gnttab_map_grant_ref(xc_gnttab *xch, uint32_t domid, uint32_t ref, int prot) +static void *linux_gnttab_map_grant_ref(xc_gnttab *xch, xc_osdep_handle h, + uint32_t domid, uint32_t ref, int prot) { + int fd = (int)h; struct ioctl_gntdev_map_grant_ref map; void *addr; @@ -517,13 +519,13 @@ void *xc_gnttab_map_grant_ref(xc_gnttab map.refs[0].domid = domid; map.refs[0].ref = ref; - if ( ioctl(xch->fd, IOCTL_GNTDEV_MAP_GRANT_REF, &map) ) { + if ( ioctl(fd, IOCTL_GNTDEV_MAP_GRANT_REF, &map) ) { PERROR("xc_gnttab_map_grant_ref: ioctl MAP_GRANT_REF failed"); return NULL; } mmap_again: - addr = mmap(NULL, PAGE_SIZE, prot, MAP_SHARED, xch->fd, map.index); + addr = mmap(NULL, PAGE_SIZE, prot, MAP_SHARED, fd, map.index); if ( addr == MAP_FAILED ) { int saved_errno = errno; @@ -538,7 +540,7 @@ mmap_again: PERROR("xc_gnttab_map_grant_ref: mmap failed"); unmap_grant.index = map.index; unmap_grant.count = 1; - ioctl(xch->fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant); + ioctl(fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant); errno = saved_errno; return NULL; } @@ -546,10 +548,12 @@ mmap_again: return addr; } -static void *do_gnttab_map_grant_refs(xc_gnttab *xch, uint32_t count, +static void *do_gnttab_map_grant_refs(xc_gnttab *xch, xc_osdep_handle h, + uint32_t count, uint32_t *domids, int domids_stride, uint32_t *refs, int prot) { + int fd = (int)h; struct ioctl_gntdev_map_grant_ref *map; void *addr = NULL; int i; @@ -567,12 +571,12 @@ static void *do_gnttab_map_grant_refs(xc map->count = count; - if ( ioctl(xch->fd, IOCTL_GNTDEV_MAP_GRANT_REF, map) ) { + if ( ioctl(fd, IOCTL_GNTDEV_MAP_GRANT_REF, map) ) { PERROR("xc_gnttab_map_grant_refs: ioctl MAP_GRANT_REF failed"); goto out; } - addr = mmap(NULL, PAGE_SIZE * count, prot, MAP_SHARED, xch->fd, + addr = mmap(NULL, PAGE_SIZE * count, prot, MAP_SHARED, fd, map->index); if ( addr == MAP_FAILED ) { @@ -583,7 +587,7 @@ static void *do_gnttab_map_grant_refs(xc PERROR("xc_gnttab_map_grant_refs: mmap failed"); unmap_grant.index = map->index; unmap_grant.count = count; - ioctl(xch->fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant); + ioctl(fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant); errno = saved_errno; addr = NULL; } @@ -594,16 +598,18 @@ static void *do_gnttab_map_grant_refs(xc return addr; } -void *xc_gnttab_map_grant_refs(xc_gnttab *xcg, uint32_t count, uint32_t *domids, - uint32_t *refs, int prot) +static void *linux_gnttab_map_grant_refs(xc_gnttab *xcg, xc_osdep_handle h, + uint32_t count, uint32_t *domids, + uint32_t *refs, int prot) { - return do_gnttab_map_grant_refs(xcg, count, domids, 1, refs, prot); + return do_gnttab_map_grant_refs(xcg, h, count, domids, 1, refs, prot); } -void *xc_gnttab_map_domain_grant_refs(xc_gnttab *xcg, uint32_t count, - uint32_t domid, uint32_t *refs, int prot) +static void *linux_gnttab_map_domain_grant_refs(xc_gnttab *xcg, xc_osdep_handle h, + uint32_t count, + uint32_t domid, uint32_t *refs, int prot) { - return do_gnttab_map_grant_refs(xcg, count, &domid, 0, refs, prot); + return do_gnttab_map_grant_refs(xcg, h, count, &domid, 0, refs, prot); } int xc_gnttab_munmap(xc_gnttab *xcg, void *start_address, uint32_t count) @@ -660,6 +666,12 @@ static struct xc_osdep_ops linux_gnttab_ static struct xc_osdep_ops linux_gnttab_ops = { .open = &linux_gnttab_open, .close = &linux_gnttab_close, + + .u.gnttab = { + .map_grant_ref = &linux_gnttab_map_grant_ref, + .map_grant_refs = &linux_gnttab_map_grant_refs, + .map_domain_grant_refs = &linux_gnttab_map_domain_grant_refs, + }, }; static struct xc_osdep_ops *linux_osdep_init(xc_interface *xch, enum xc_osdep_type type) diff -r 3e8cb37144eb -r 68996338758e tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -447,38 +447,41 @@ void minios_gnttab_close_fd(int fd) files[fd].type = FTYPE_NONE; } -void *xc_gnttab_map_grant_ref(xc_gnttab *xcg, - uint32_t domid, - uint32_t ref, - int prot) +static void *minios_gnttab_map_grant_ref(xc_gnttab *xcg, xc_osdep_handle h, + uint32_t domid, + uint32_t ref, + int prot) { - return gntmap_map_grant_refs(&files[xcg->fd].gntmap, + int fd = (int)h; + return gntmap_map_grant_refs(&files[fd].gntmap, 1, &domid, 0, &ref, prot & PROT_WRITE); } -void *xc_gnttab_map_grant_refs(xc_gnttab *xcg, - uint32_t count, - uint32_t *domids, - uint32_t *refs, - int prot) +static void *minios_gnttab_map_grant_refs(xc_gnttab *xcg, xc_osdep_handle h, + uint32_t count, + uint32_t *domids, + uint32_t *refs, + int prot) { - return gntmap_map_grant_refs(&files[xcg->fd].gntmap, + int fd = (int)h; + return gntmap_map_grant_refs(&files[fd].gntmap, count, domids, 1, refs, prot & PROT_WRITE); } -void *xc_gnttab_map_domain_grant_refs(xc_gnttab *xcg, - uint32_t count, - uint32_t domid, - uint32_t *refs, - int prot) +static void *minios_gnttab_map_domain_grant_refs(xc_gnttab *xcg, xc_osdep_handle h, + uint32_t count, + uint32_t domid, + uint32_t *refs, + int prot) { - return gntmap_map_grant_refs(&files[xcg->fd].gntmap, + int fd = (int)h; + return gntmap_map_grant_refs(&files[fd].gntmap, count, &domid, 0, refs, @@ -516,6 +519,12 @@ static struct xc_osdep_ops minios_gnttab static struct xc_osdep_ops minios_gnttab_ops = { .open = &minios_gnttab_open, .close = &minios_gnttab_close, + + .u.gnttab = { + .map_grant_ref = &minios_gnttab_map_grant_ref, + .map_grant_refs = &minios_gnttab_map_grant_refs, + .map_domain_grant_refs = &minios_gnttab_map_domain_grant_refs, + }, }; static struct xc_osdep_ops *minios_osdep_init(xc_interface *xch, enum xc_osdep_type type) diff -r 3e8cb37144eb -r 68996338758e tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -89,6 +89,22 @@ struct xc_osdep_ops evtchn_port_or_error_t (*pending)(xc_evtchn *xce, xc_osdep_handle h); int (*unmask)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port); } evtchn; + struct { + void *(*map_grant_ref)(xc_gnttab *xcg, xc_osdep_handle h, + uint32_t domid, + uint32_t ref, + int prot); + void *(*map_grant_refs)(xc_gnttab *xcg, xc_osdep_handle h, + uint32_t count, + uint32_t *domids, + uint32_t *refs, + int prot); + void *(*map_domain_grant_refs)(xc_gnttab *xcg, xc_osdep_handle h, + uint32_t count, + uint32_t domid, + uint32_t *refs, + int prot); + } gnttab; } u; }; typedef struct xc_osdep_ops xc_osdep_ops; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 17 of 25] libxc: osdep: convert xc_gnttab_munmap()
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID c5abbf2d6709770c039f2a01712986b1e37ec118 # Parent 68996338758eabdecbdfc5cfb4aa82ab7589b4e6 libxc: osdep: convert xc_gnttab_munmap() Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 68996338758e -r c5abbf2d6709 tools/libxc/xc_gnttab.c --- a/tools/libxc/xc_gnttab.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_gnttab.c Fri Dec 03 09:36:47 2010 +0000 @@ -174,6 +174,15 @@ void *xc_gnttab_map_domain_grant_refs(xc count, domid, refs, prot); } +int xc_gnttab_munmap(xc_gnttab *xcg, + void *start_address, + uint32_t count) +{ + return xcg->ops->u.gnttab.munmap(xcg, xcg->ops_handle, + start_address, count); +} + + /* * Local variables: * mode: C diff -r 68996338758e -r c5abbf2d6709 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -612,8 +612,10 @@ static void *linux_gnttab_map_domain_gra return do_gnttab_map_grant_refs(xcg, h, count, &domid, 0, refs, prot); } -int xc_gnttab_munmap(xc_gnttab *xcg, void *start_address, uint32_t count) +static int linux_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h, + void *start_address, uint32_t count) { + int fd = (int)h; struct ioctl_gntdev_get_offset_for_vaddr get_offset; struct ioctl_gntdev_unmap_grant_ref unmap_grant; int rc; @@ -628,7 +630,7 @@ int xc_gnttab_munmap(xc_gnttab *xcg, voi * mmap() the pages. */ get_offset.vaddr = (unsigned long)start_address; - if ( (rc = ioctl(xcg->fd, IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR, + if ( (rc = ioctl(fd, IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR, &get_offset)) ) return rc; @@ -645,7 +647,7 @@ int xc_gnttab_munmap(xc_gnttab *xcg, voi /* Finally, unmap the driver slots used to store the grant information. */ unmap_grant.index = get_offset.offset; unmap_grant.count = count; - if ( (rc = ioctl(xcg->fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant)) ) + if ( (rc = ioctl(fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant)) ) return rc; return 0; @@ -671,6 +673,7 @@ static struct xc_osdep_ops linux_gnttab_ .map_grant_ref = &linux_gnttab_map_grant_ref, .map_grant_refs = &linux_gnttab_map_grant_refs, .map_domain_grant_refs = &linux_gnttab_map_domain_grant_refs, + .munmap = &linux_gnttab_munmap, }, }; diff -r 68996338758e -r c5abbf2d6709 tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -488,12 +488,13 @@ static void *minios_gnttab_map_domain_gr prot & PROT_WRITE); } -int xc_gnttab_munmap(xc_gnttab *xcg, - void *start_address, - uint32_t count) +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[xcg->fd].gntmap, + ret = gntmap_munmap(&files[fd].gntmap, (unsigned long) start_address, count); if (ret < 0) { @@ -524,6 +525,7 @@ static struct xc_osdep_ops minios_gnttab .map_grant_ref = &minios_gnttab_map_grant_ref, .map_grant_refs = &minios_gnttab_map_grant_refs, .map_domain_grant_refs = &minios_gnttab_map_domain_grant_refs, + .munmap = &minios_gnttab_munmap, }, }; diff -r 68996338758e -r c5abbf2d6709 tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -104,6 +104,9 @@ struct xc_osdep_ops uint32_t domid, uint32_t *refs, int prot); + int (*munmap)(xc_gnttab *xcg, xc_osdep_handle h, + void *start_address, + uint32_t count); } gnttab; } u; }; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 18 of 25] libxc: osdep: convert xc_gnttab_set_max_grants()
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID 384d9d7ca3063a32623cb0d6ccdbc258e3541749 # Parent c5abbf2d6709770c039f2a01712986b1e37ec118 libxc: osdep: convert xc_gnttab_set_max_grants() Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r c5abbf2d6709 -r 384d9d7ca306 tools/libxc/xc_gnttab.c --- a/tools/libxc/xc_gnttab.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_gnttab.c Fri Dec 03 09:36:47 2010 +0000 @@ -182,6 +182,10 @@ int xc_gnttab_munmap(xc_gnttab *xcg, start_address, count); } +int xc_gnttab_set_max_grants(xc_gnttab *xcg, uint32_t count) +{ + return xcg->ops->u.gnttab.set_max_grants(xcg, xcg->ops_handle, count); +} /* * Local variables: diff -r c5abbf2d6709 -r 384d9d7ca306 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -653,13 +653,14 @@ static int linux_gnttab_munmap(xc_gnttab return 0; } -int xc_gnttab_set_max_grants(xc_gnttab *xcg, uint32_t count) +static int linux_gnttab_set_max_grants(xc_gnttab *xcg, xc_osdep_handle h, uint32_t count) { + int fd = (int)h; struct ioctl_gntdev_set_max_grants set_max; int rc; set_max.count = count; - if ( (rc = ioctl(xcg->fd, IOCTL_GNTDEV_SET_MAX_GRANTS, &set_max)) ) + if ( (rc = ioctl(fd, IOCTL_GNTDEV_SET_MAX_GRANTS, &set_max)) ) return rc; return 0; @@ -674,6 +675,7 @@ static struct xc_osdep_ops linux_gnttab_ .map_grant_refs = &linux_gnttab_map_grant_refs, .map_domain_grant_refs = &linux_gnttab_map_domain_grant_refs, .munmap = &linux_gnttab_munmap, + .set_max_grants = &linux_gnttab_set_max_grants, }, }; diff -r c5abbf2d6709 -r 384d9d7ca306 tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -504,11 +504,12 @@ static int minios_gnttab_munmap(xc_gntta return ret; } -int xc_gnttab_set_max_grants(xc_gnttab *xcg, +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[xcg->fd].gntmap, + ret = gntmap_set_max_grants(&files[fd].gntmap, count); if (ret < 0) { errno = -ret; @@ -526,6 +527,7 @@ static struct xc_osdep_ops minios_gnttab .map_grant_refs = &minios_gnttab_map_grant_refs, .map_domain_grant_refs = &minios_gnttab_map_domain_grant_refs, .munmap = &minios_gnttab_munmap, + .set_max_grants = &minios_gnttab_set_max_grants, }, }; diff -r c5abbf2d6709 -r 384d9d7ca306 tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -107,6 +107,7 @@ struct xc_osdep_ops int (*munmap)(xc_gnttab *xcg, xc_osdep_handle h, void *start_address, uint32_t count); + int (*set_max_grants)(xc_gnttab *xcg, xc_osdep_handle h, uint32_t count); } gnttab; } u; }; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 19 of 25] libxc: add ability to query OS interface for "fakeness"
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID 2cca9651106419dc04b2dfebc51da4b3f9143482 # Parent 384d9d7ca3063a32623cb0d6ccdbc258e3541749 libxc: add ability to query OS interface for "fakeness" i.e. not running on a real hypervisor Allows users of the library to adjust behaviour. I don''t especially like this violation of the abstraction but both oxenstored and xapi use this to avoid difficult to simulate operations when running on the simulator. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 384d9d7ca306 -r 2cca96511064 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -697,6 +697,7 @@ xc_osdep_info_t xc_osdep_info = { xc_osdep_info_t xc_osdep_info = { .name = "Linux Native OS interface", .init = &linux_osdep_init, + .fake = 0, }; /* diff -r 384d9d7ca306 -r 2cca96511064 tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -549,6 +549,7 @@ xc_osdep_info_t xc_osdep_info = { xc_osdep_info_t xc_osdep_info = { .name = "Minios Native OS interface", .init = &minios_osdep_init, + .fake = 0, }; /* diff -r 384d9d7ca306 -r 2cca96511064 tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 @@ -348,6 +348,7 @@ xc_osdep_info_t xc_osdep_info = { xc_osdep_info_t xc_osdep_info = { .name = "Netbsd Native OS interface", .init = &netbsd_osdep_init, + .fake = 0, }; /* diff -r 384d9d7ca306 -r 2cca96511064 tools/libxc/xc_private.c --- a/tools/libxc/xc_private.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_private.c Fri Dec 03 09:36:47 2010 +0000 @@ -120,6 +120,19 @@ static int xc_interface_close_common(xc_ free(xch); return rc; +} + +int xc_interface_is_fake(void) +{ + xc_osdep_info_t info; + + if ( xc_osdep_get_info(NULL, &info) < 0 ) + return -1; + + /* Have a copy of info so can release the interface now. */ + xc_osdep_put(&info); + + return info.fake; } xc_interface *xc_interface_open(xentoollog_logger *logger, diff -r 384d9d7ca306 -r 2cca96511064 tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 @@ -321,6 +321,7 @@ xc_osdep_info_t xc_osdep_info = { xc_osdep_info_t xc_osdep_info = { .name = "Solaris Native OS interface", .init = &solaris_osdep_init, + .fake = 0, }; /* diff -r 384d9d7ca306 -r 2cca96511064 tools/libxc/xenctrl.h --- a/tools/libxc/xenctrl.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrl.h Fri Dec 03 09:36:47 2010 +0000 @@ -158,6 +158,15 @@ enum xc_open_flags { * @return 0 on success, -1 otherwise. */ int xc_interface_close(xc_interface *xch); + +/** + * Query the active OS interface (i.e. that which would be returned by + * xc_interface_open) to find out if it is fake (i.e. backends onto + * something other than an actual Xen hypervisor). + * + * @return 0 is "real", >0 if fake, -1 on error. + */ +int xc_interface_is_fake(void); /* * HYPERCALL SAFE MEMORY BUFFER diff -r 384d9d7ca306 -r 2cca96511064 tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -122,6 +122,9 @@ struct xc_osdep_info /* Returns ops function. */ xc_osdep_init_fn init; + + /* True if this interface backs onto a fake Xen. */ + int fake; }; typedef struct xc_osdep_info xc_osdep_info_t; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 20 of 25] libxc: drop fd from xc_interface
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID 379a7ce920c996d3805f88e8ba719e9a543fbc35 # Parent 2cca9651106419dc04b2dfebc51da4b3f9143482 libxc: drop fd from xc_interface Transition to xc_osdep_handle is now complete and nothing uses (or should be using) it. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 2cca96511064 -r 379a7ce920c9 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -57,8 +57,6 @@ static xc_osdep_handle linux_privcmd_ope PERROR("Could not set file handle flags"); goto error; } - - xch->fd = fd; /* Remove after transition to full xc_osdep_ops. */ return (xc_osdep_handle)fd; @@ -350,7 +348,6 @@ static xc_osdep_handle linux_evtchn_open if ( fd == -1 ) return XC_OSDEP_OPEN_ERROR; - xce->fd = fd; /* Remove after transition to full xc_osdep_ops. */ return (xc_osdep_handle)fd; } @@ -498,7 +495,6 @@ static xc_osdep_handle linux_gnttab_open if ( fd == -1 ) return XC_OSDEP_OPEN_ERROR; - xcg->fd = fd; /* Remove after transition to full xc_osdep_ops. */ return (xc_osdep_handle)fd; } diff -r 2cca96511064 -r 379a7ce920c9 tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -56,7 +56,6 @@ static xc_osdep_handle minios_privcmd_op if ( fd == -1) return XC_OSDEP_OPEN_ERROR; - xch->fd = fd; /* Remove after transition to full xc_osdep_ops. */ return (xc_osdep_handle)fd; } @@ -207,7 +206,6 @@ static xc_osdep_handle minios_evtchn_ope files[fd].evtchn.ports[i].bound = 0; } printf("evtchn_open() -> %d\n", fd); - xce->fd = fd; /* Remove after transition to full xc_osdep_ops. */ return (xc_osdep_handle)fd; } @@ -431,7 +429,6 @@ static xc_osdep_handle minios_gnttab_ope if ( fd == -1 ) return XC_OSDEP_OPEN_ERROR; gntmap_init(&files[fd].gntmap); - xcg->fd = fd; /* Remove after transition to full xc_osdep_ops. */ return (xc_osdep_handle)fd; } diff -r 2cca96511064 -r 379a7ce920c9 tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 @@ -50,8 +50,6 @@ static xc_osdep_handle netbsd_privcmd_op PERROR("Could not set file handle flags"); goto error; } - - xch->fd = fd; /* Remove after transition to full xc_osdep_ops. */ return (xc_osinteface_handle)fd; @@ -200,7 +198,6 @@ static xc_osdep_handle netbsd_evtchn_ope if ( fd == -1 ) return XC_OSDEP_OPEN_ERROR; - xce->fd = fd; /* Remove after transition to full xc_osdep_ops. */ return (xc_osdep_handle)fd; } diff -r 2cca96511064 -r 379a7ce920c9 tools/libxc/xc_private.c --- a/tools/libxc/xc_private.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_private.c Fri Dec 03 09:36:47 2010 +0000 @@ -59,7 +59,6 @@ static struct xc_interface_core *xc_inte xch->type = type; xch->flags = open_flags; - xch->fd = -1; xch->dombuild_logger_file = 0; xc_clear_last_error(xch); diff -r 2cca96511064 -r 379a7ce920c9 tools/libxc/xc_private.h --- a/tools/libxc/xc_private.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_private.h Fri Dec 03 09:36:47 2010 +0000 @@ -68,7 +68,6 @@ struct xc_interface_core { enum xc_osdep_type type; - int fd; int flags; xentoollog_logger *error_handler, *error_handler_tofree; xentoollog_logger *dombuild_logger, *dombuild_logger_tofree; diff -r 2cca96511064 -r 379a7ce920c9 tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 @@ -52,7 +52,6 @@ static xc_osdep_handle solaris_privcmd_o goto error; } - xch->fd = fd; /* Remove after transition to full xc_osdep_ops. */ return (xc_osdep_handle)fd; error: @@ -192,7 +191,6 @@ static xc_osdep_handle solaris_evtchn_op return XC_OSDEP_OPEN_ERROR; } - xce->fd = fd; /* Remove after transition to full xc_osdep_ops. */ return (xc_osdep_handle)fd; } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 21 of 25] libxc: allow osdep backends to log via the xc infrastructure
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID ba7854a6f15b606a5285a786597bbdb452c9d360 # Parent 379a7ce920c996d3805f88e8ba719e9a543fbc35 libxc: allow osdep backends to log via the xc infrastructure. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 379a7ce920c9 -r ba7854a6f15b tools/libxc/xc_private.c --- a/tools/libxc/xc_private.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_private.c Fri Dec 03 09:36:47 2010 +0000 @@ -268,6 +268,14 @@ void xc_report_error(xc_interface *xch, va_list args; va_start(args, fmt); xc_reportv(xch, xch->error_handler, XTL_ERROR, code, fmt, args); + va_end(args); +} + +void xc_osdep_log(xc_interface *xch, xentoollog_level level, int code, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + xc_reportv(xch, xch->error_handler, level, code, fmt, args); va_end(args); } diff -r 379a7ce920c9 -r ba7854a6f15b tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -136,6 +136,9 @@ void *xc_map_foreign_bulk_compat(xc_inte uint32_t dom, int prot, const xen_pfn_t *arr, int *err, unsigned int num); +/* Report errors through xc_interface */ +void xc_osdep_log(xc_interface *xch, xentoollog_level level, int code, const char *fmt, ...); + #endif /* _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 22 of 25] libxc: osdep: Use XC_PAGE_{SHIFT, MASK}
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID fd025a5043072ae2684f55e5c4ffdb86f6cda042 # Parent ba7854a6f15b606a5285a786597bbdb452c9d360 libxc: osdep: Use XC_PAGE_{SHIFT,MASK}. Avoid dependency on xc_private.h Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r ba7854a6f15b -r fd025a504307 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -110,7 +110,7 @@ static void *linux_privcmd_map_foreign_b void *addr; int rc; - addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, fd, 0); + addr = mmap(NULL, num << XC_PAGE_SHIFT, prot, MAP_SHARED, fd, 0); if ( addr == MAP_FAILED ) { PERROR("xc_map_foreign_batch: mmap failed"); @@ -132,7 +132,7 @@ static void *linux_privcmd_map_foreign_b if ( (arr[i] & XEN_DOMCTL_PFINFO_LTAB_MASK) = XEN_DOMCTL_PFINFO_PAGEDTAB ) { - unsigned long paged_addr = (unsigned long)addr + (i << PAGE_SHIFT); + unsigned long paged_addr = (unsigned long)addr + (i << XC_PAGE_SHIFT); rc = xc_map_foreign_batch_single(fd, dom, &arr[i], paged_addr); if ( rc < 0 ) @@ -146,7 +146,7 @@ static void *linux_privcmd_map_foreign_b { int saved_errno = errno; PERROR("xc_map_foreign_batch: ioctl failed"); - (void)munmap(addr, num << PAGE_SHIFT); + (void)munmap(addr, num << XC_PAGE_SHIFT); errno = saved_errno; return NULL; } @@ -164,7 +164,7 @@ static void *linux_privcmd_map_foreign_b unsigned int i; int rc; - addr = mmap(NULL, (unsigned long)num << PAGE_SHIFT, prot, MAP_SHARED, + addr = mmap(NULL, (unsigned long)num << XC_PAGE_SHIFT, prot, MAP_SHARED, fd, 0); if ( addr == MAP_FAILED ) { @@ -189,7 +189,7 @@ static void *linux_privcmd_map_foreign_b ioctlx.num = 1; ioctlx.dom = dom; - ioctlx.addr = (unsigned long)addr + ((unsigned long)i<<PAGE_SHIFT); + ioctlx.addr = (unsigned long)addr + ((unsigned long)i<<XC_PAGE_SHIFT); ioctlx.arr = arr + i; ioctlx.err = err + i; do { @@ -239,7 +239,7 @@ static void *linux_privcmd_map_foreign_b continue; } rc = xc_map_foreign_batch_single(fd, dom, pfn + i, - (unsigned long)addr + ((unsigned long)i<<PAGE_SHIFT)); + (unsigned long)addr + ((unsigned long)i<<XC_PAGE_SHIFT)); if ( rc < 0 ) { rc = -errno; @@ -273,7 +273,7 @@ static void *linux_privcmd_map_foreign_b int saved_errno = errno; PERROR("xc_map_foreign_bulk: ioctl failed"); - (void)munmap(addr, (unsigned long)num << PAGE_SHIFT); + (void)munmap(addr, (unsigned long)num << XC_PAGE_SHIFT); errno = saved_errno; return NULL; } @@ -290,7 +290,7 @@ static void *linux_privcmd_map_foreign_r int i; void *ret; - num = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; + num = (size + XC_PAGE_SIZE - 1) >> XC_PAGE_SHIFT; arr = calloc(num, sizeof(xen_pfn_t)); for ( i = 0; i < num; i++ ) @@ -313,7 +313,7 @@ static void *linux_privcmd_map_foreign_r int j; void *ret; - num_per_entry = chunksize >> PAGE_SHIFT; + num_per_entry = chunksize >> XC_PAGE_SHIFT; num = num_per_entry * nentries; arr = calloc(num, sizeof(xen_pfn_t)); @@ -474,7 +474,7 @@ void discard_file_cache(xc_interface *xc { if ( (cur = lseek(fd, 0, SEEK_CUR)) == (off_t)-1 ) cur = 0; - cur &= ~(PAGE_SIZE-1); + cur &= ~(XC_PAGE_SIZE-1); } /* Discard from the buffer cache. */ @@ -521,7 +521,7 @@ static void *linux_gnttab_map_grant_ref( } mmap_again: - addr = mmap(NULL, PAGE_SIZE, prot, MAP_SHARED, fd, map.index); + addr = mmap(NULL, XC_PAGE_SIZE, prot, MAP_SHARED, fd, map.index); if ( addr == MAP_FAILED ) { int saved_errno = errno; @@ -572,7 +572,7 @@ static void *do_gnttab_map_grant_refs(xc goto out; } - addr = mmap(NULL, PAGE_SIZE * count, prot, MAP_SHARED, fd, + addr = mmap(NULL, XC_PAGE_SIZE * count, prot, MAP_SHARED, fd, map->index); if ( addr == MAP_FAILED ) { diff -r ba7854a6f15b -r fd025a504307 tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:47 2010 +0000 @@ -169,11 +169,11 @@ static void *minios_privcmd_map_foreign_ pt_prot = L1_PROT; #endif - mfns = malloc((size / PAGE_SIZE) * sizeof(*mfns)); + mfns = malloc((size / XC_PAGE_SIZE) * sizeof(*mfns)); n = 0; for (i = 0; i < nentries; i++) - for (j = 0; j < chunksize / PAGE_SIZE; j++) + 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); diff -r ba7854a6f15b -r fd025a504307 tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:47 2010 +0000 @@ -84,7 +84,7 @@ static void *netbsd_privcmd_map_foreign_ int fd = (int)h; privcmd_mmapbatch_t ioctlx; void *addr; - addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_ANON | MAP_SHARED, -1, 0); + addr = mmap(NULL, num*XC_PAGE_SIZE, prot, MAP_ANON | MAP_SHARED, -1, 0); if ( addr == MAP_FAILED ) { PERROR("xc_map_foreign_batch: mmap failed"); return NULL; @@ -98,7 +98,7 @@ static void *netbsd_privcmd_map_foreign_ { int saved_errno = errno; PERROR("xc_map_foreign_batch: ioctl failed"); - (void)munmap(addr, num*PAGE_SIZE); + (void)munmap(addr, num*XC_PAGE_SIZE); errno = saved_errno; return NULL; } @@ -126,7 +126,7 @@ static void *netbsd_privcmd_map_foreign_ ioctlx.entry=&entry; entry.va=(unsigned long) addr; entry.mfn=mfn; - entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT; + entry.npages=(size+XC_PAGE_SIZE-1)>>XC_PAGE_SHIFT; if ( ioctl(fd, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 ) { int saved_errno = errno; @@ -154,7 +154,7 @@ static void *netbsd_privcmd_map_foreign_ for (i = 0; i < nentries; i++) { entries[i].va = (uintptr_t)addr + (i * chunksize); - entries[i].npages = chunksize >> PAGE_SHIFT; + entries[i].npages = chunksize >> XC_PAGE_SHIFT; } ioctlx.num = nentries; diff -r ba7854a6f15b -r fd025a504307 tools/libxc/xc_private.h --- a/tools/libxc/xc_private.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_private.h Fri Dec 03 09:36:47 2010 +0000 @@ -53,8 +53,8 @@ #undef PAGE_SIZE #undef PAGE_MASK #define PAGE_SHIFT XC_PAGE_SHIFT -#define PAGE_SIZE (1UL << PAGE_SHIFT) -#define PAGE_MASK (~(PAGE_SIZE-1)) +#define PAGE_SIZE XC_PAGE_SIZE +#define PAGE_MASK XC_PAGE_MASK /* Force a compilation error if condition is true */ #define XC_BUILD_BUG_ON(p) ((void)sizeof(struct { int:-!!(p); })) diff -r ba7854a6f15b -r fd025a504307 tools/libxc/xc_solaris.c --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:47 2010 +0000 @@ -80,7 +80,7 @@ static void *solaris_privcmd_map_foreign int fd = (int)h; privcmd_mmapbatch_t ioctlx; void *addr; - addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, fd, 0); + addr = mmap(NULL, num*XC_PAGE_SIZE, prot, MAP_SHARED, fd, 0); if ( addr == MAP_FAILED ) return NULL; @@ -92,7 +92,7 @@ static void *solaris_privcmd_map_foreign { int saved_errno = errno; PERROR("XXXXXXXX"); - (void)munmap(addr, num*PAGE_SIZE); + (void)munmap(addr, num*XC_PAGE_SIZE); errno = saved_errno; return NULL; } @@ -118,7 +118,7 @@ static void *xc_map_foreign_range(xc_int ioctlx.entry=&entry; entry.va=(unsigned long) addr; entry.mfn=mfn; - entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT; + entry.npages=(size+XC_PAGE_SIZE-1)>>XC_PAGE_SHIFT; if ( ioctl(fd, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 ) { int saved_errno = errno; @@ -145,7 +145,7 @@ static void *solaric_privcmd_map_foreign for (i = 0; i < nentries; i++) { entries[i].va = (uintptr_t)addr + (i * chunksize); - entries[i].npages = chunksize >> PAGE_SHIFT; + entries[i].npages = chunksize >> XC_PAGE_SHIFT; } ioctlx.num = nentries; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 23 of 25] libxc: add abitility to dynamically load osdep
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID a4d3be2e38ea883d3d2404078adc94960692d022 # Parent fd025a5043072ae2684f55e5c4ffdb86f6cda042 libxc: add abitility to dynamically load osdep. Add a dummy backend which always returns ENOSYS. Mainly as a compile time testbed rather than because it is a useful backend. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r fd025a504307 -r a4d3be2e38ea tools/libxc/Makefile --- a/tools/libxc/Makefile Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/Makefile Fri Dec 03 09:36:47 2010 +0000 @@ -92,6 +92,10 @@ LIB += libxenguest.so libxenguest.so.$(M LIB += libxenguest.so libxenguest.so.$(MAJOR) libxenguest.so.$(MAJOR).$(MINOR) endif +ifneq ($(stubdom),y) +LIB += xenctrl_osdep_ENOSYS.so +endif + .PHONY: all all: build @@ -148,7 +152,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$( ln -sf $< $@ libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS) - $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(PTHREAD_LIBS) + $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) -ldl $(SHLIB_LDFLAGS) -o $@ $^ $(PTHREAD_LIBS) # libxenguest @@ -186,5 +190,8 @@ libxenguest.so.$(MAJOR).$(MINOR): $(GUES libxenguest.so.$(MAJOR).$(MINOR): $(GUEST_PIC_OBJS) libxenctrl.so $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(GUEST_PIC_OBJS) $(COMPRESSION_LIBS) -lz -lxenctrl $(PTHREAD_LIBS) +xenctrl_osdep_ENOSYS.so: xenctrl_osdep_ENOSYS.o libxenctrl.so + $(CC) -g $(CFLAGS) $(LDFLAGS) $(SHLIB_LDFLAGS) -o $@ xenctrl_osdep_ENOSYS.o -lxenctrl + -include $(DEPS) diff -r fd025a504307 -r a4d3be2e38ea tools/libxc/xc_private.c --- a/tools/libxc/xc_private.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_private.c Fri Dec 03 09:36:47 2010 +0000 @@ -27,9 +27,21 @@ #include <pthread.h> #include <assert.h> +#ifndef __MINIOS__ +#include <dlfcn.h> +#endif + +#define XENCTRL_OSDEP "XENCTRL_OSDEP" + /* * Returns a (shallow) copy of the xc_osdep_info_t for the * active OS interface. + * + * On success a handle to the relevant library is opened. The user + * must subsequently call xc_osdep_put_info() when it is + * finished with the library. + * + * Logs IFF xch != NULL. * * Returns: * 0 - on success @@ -38,16 +50,65 @@ static int xc_osdep_get_info(xc_interfac static int xc_osdep_get_info(xc_interface *xch, xc_osdep_info_t *info) { int rc = -1; +#ifndef __MINIOS__ + const char *lib = getenv(XENCTRL_OSDEP); + xc_osdep_info_t *pinfo; + void *dl_handle = NULL; - *info = xc_osdep_info; + if ( lib != NULL ) + { + if ( getuid() != geteuid() ) + { + if ( xch ) ERROR("cannot use %s=%s with setuid application", XENCTRL_OSDEP, lib); + abort(); + } + if ( getgid() != getegid() ) + { + if ( xch ) ERROR("cannot use %s=%s with setgid application", XENCTRL_OSDEP, lib); + abort(); + } + + dl_handle = dlopen(lib, RTLD_LAZY|RTLD_LOCAL); + if ( !dl_handle ) + { + if ( xch ) ERROR("unable to open osdep library %s: %s", lib, dlerror()); + goto out; + } + + pinfo = dlsym(dl_handle, "xc_osdep_info"); + if ( !pinfo ) + { + if ( xch ) ERROR("unable to find xc_osinteface_info in %s: %s", lib, dlerror()); + goto out; + } + + *info = *pinfo; + info->dl_handle = dl_handle; + } + else +#endif + { + *info = xc_osdep_info; + info->dl_handle = NULL; + } rc = 0; + +#ifndef __MINIOS__ +out: + if ( dl_handle && rc == -1 ) + dlclose(dl_handle); +#endif return rc; } static void xc_osdep_put(xc_osdep_info_t *info) { +#ifndef __MINIOS__ + if ( info->dl_handle ) + dlclose(info->dl_handle); +#endif } static struct xc_interface_core *xc_interface_open_common(xentoollog_logger *logger, diff -r fd025a504307 -r a4d3be2e38ea tools/libxc/xenctrl_osdep_ENOSYS.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxc/xenctrl_osdep_ENOSYS.c Fri Dec 03 09:36:47 2010 +0000 @@ -0,0 +1,206 @@ +/* Dummy backend which just logs and returns ENOSYS. */ + +#include <errno.h> +#include <inttypes.h> +#include <stdlib.h> + +#include "xenctrl.h" +#include "xenctrlosdep.h" + +#define IPRINTF(_x, _f, _a...) xc_osdep_log(_x,XTL_INFO,0, _f , ## _a) + +#define ERROR(_x, _m, _a...) xc_osdep_log(_x,XTL_ERROR,XC_INTERNAL_ERROR,_m , ## _a ) +#define PERROR(_x, _m, _a...) xc_osdep_log(_x,XTL_ERROR,XC_INTERNAL_ERROR,_m \ + " (%d = %s)", ## _a , errno, xc_strerror(xch, errno)) + +static xc_osdep_handle ENOSYS_privcmd_open(xc_interface *xch) +{ + IPRINTF(xch, "ENOSYS_privcmd: opening handle %p\n", (void *)1); + return (xc_osdep_handle)1; /*dummy*/ +} + +static int ENOSYS_privcmd_close(xc_interface *xch, xc_osdep_handle h) +{ + IPRINTF(xch, "ENOSYS_privcmd: closing handle %p\n", h); + return 0; +} + +static int ENOSYS_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall) +{ + IPRINTF(xch, "ENOSYS_privcmd %p: hypercall: %02lld(%#llx,%#llx,%#llx,%#llx,%#llx,%#llx)\n", + h, hypercall->op, + hypercall->arg[0], hypercall->arg[1], hypercall->arg[2], + hypercall->arg[3], hypercall->arg[4], hypercall->arg[5]); + return -ENOSYS; +} + +static void *ENOSYS_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot, + xen_pfn_t *arr, int num) +{ + IPRINTF(xch, "ENOSYS_privcmd %p: map_foreign_batch: dom%d prot %#x arr %p num %d\n", h, dom, prot, arr, num); + return MAP_FAILED; +} + +static void *ENOSYS_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) +{ + IPRINTF(xch, "ENOSYS_privcmd %p: map_foreign_buld: dom%d prot %#x arr %p err %p num %d\n", h, dom, prot, arr, err, num); + return MAP_FAILED; +} + +static void *ENOSYS_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int size, int prot, + unsigned long mfn) +{ + IPRINTF(xch, "ENOSYS_privcmd %p: map_foreign_range: dom%d size %#x prot %#x mfn %ld\n", h, dom, size, prot, mfn); + return MAP_FAILED; +} + +static void *ENOSYS_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) +{ + IPRINTF(xch, "ENOSYS_privcmd %p: map_foreign_ranges: dom%d size %zd prot %#x chunksize %zd entries %p num %d\n", h, dom, size, prot, chunksize, entries, nentries); + return MAP_FAILED; +} + +static struct xc_osdep_ops ENOSYS_privcmd_ops +{ + .open = &ENOSYS_privcmd_open, + .close = &ENOSYS_privcmd_close, + .u.privcmd = { + .hypercall = &ENOSYS_privcmd_hypercall, + + .map_foreign_batch = &ENOSYS_privcmd_map_foreign_batch, + .map_foreign_bulk = &ENOSYS_privcmd_map_foreign_bulk, + .map_foreign_range = &ENOSYS_privcmd_map_foreign_range, + .map_foreign_ranges = &ENOSYS_privcmd_map_foreign_ranges, + } +}; + +static xc_osdep_handle ENOSYS_evtchn_open(xc_interface *xce) +{ + IPRINTF(xce, "ENOSYS_evtchn: opening handle %p\n", (void *)1); + return (xc_osdep_handle)2; /*dummy*/ +} + +static int ENOSYS_evtchn_close(xc_interface *xce, xc_osdep_handle h) +{ + IPRINTF(xce, "ENOSYS_evtchn: closing handle %p\n", h); + return 0; +} + +static int ENOSYS_evtchn_fd(xc_interface *xce, xc_osdep_handle h) +{ + IPRINTF(xce, "ENOSYS_fd %p: fd\n", h); + return (int)h; +} + +static int ENOSYS_evtchn_notify(xc_interface *xce, xc_osdep_handle h, evtchn_port_t port) +{ + IPRINTF(xce, "ENOSYS_evtchn %p: notify: %d\n", h, port); + return -ENOSYS; +} + +static int ENOSYS_evtchn_bind_unbound_port(xc_interface *xce, xc_osdep_handle h, int domid) +{ + IPRINTF(xce, "ENOSYS_evtchn %p: bind_unbound_port: dom%d\n", h, domid); + return -ENOSYS; +} + + +static int ENOSYS_evtchn_bind_interdomain(xc_interface *xce, xc_osdep_handle h, int domid, evtchn_port_t remote_port) +{ + IPRINTF(xce, "ENOSYS_evtchn %p: bind_interdomain: dmo%d %d\n", h, domid, remote_port); + return -ENOSYS; +} + + +static int ENOSYS_evtchn_bind_virq(xc_interface *xce, xc_osdep_handle h, unsigned int virq) +{ + IPRINTF(xce, "ENOSYS_evtchn %p: bind_virq: %d\n", h, virq); + return -ENOSYS; +} + + +static int ENOSYS_evtchn_unbind(xc_interface *xce, xc_osdep_handle h, evtchn_port_t port) +{ + IPRINTF(xce, "ENOSYS_evtchn %p: unbind: %d\n", h, port); + return -ENOSYS; +} + + +static evtchn_port_or_error_t ENOSYS_evtchn_pending(xc_interface *xce, xc_osdep_handle h) +{ + IPRINTF(xce, "ENOSYS_evtchn %p: pending\n", h); + return -ENOSYS; +} + +static int ENOSYS_evtchn_unmask(xc_interface *xce, xc_osdep_handle h, evtchn_port_t port) +{ + IPRINTF(xce, "ENOSYS_evtchn %p: unmask: %d\n", h, port); + return -ENOSYS; +} + +static struct xc_osdep_ops ENOSYS_evtchn_ops = { + .open = &ENOSYS_evtchn_open, + .close = &ENOSYS_evtchn_close, + + .u.evtchn = { + .fd = &ENOSYS_evtchn_fd, + + .notify = &ENOSYS_evtchn_notify, + + .bind_unbound_port = &ENOSYS_evtchn_bind_unbound_port, + .bind_interdomain = &ENOSYS_evtchn_bind_interdomain, + .bind_virq = &ENOSYS_evtchn_bind_virq, + + .unbind = &ENOSYS_evtchn_unbind, + + .pending = &ENOSYS_evtchn_pending, + .unmask = &ENOSYS_evtchn_unmask, + }, +}; + +static struct xc_osdep_ops * ENOSYS_osdep_init(xc_interface *xch, enum xc_osdep_type type) +{ + struct xc_osdep_ops *ops; + + if (getenv("ENOSYS") == NULL) + { + PERROR(xch, "ENOSYS: not configured\n"); + return NULL; + } + + switch ( type ) + { + case XC_OSDEP_PRIVCMD: + ops = &ENOSYS_privcmd_ops; + break; + case XC_OSDEP_EVTCHN: + ops = &ENOSYS_evtchn_ops; + break; + default: + ops = NULL; + break; + } + + IPRINTF(xch, "ENOSYS_osdep_init: initialising handle ops at %p\n", ops); + + return ops; +} + +xc_osdep_info_t xc_osdep_info = { + .name = "Pessimistic ENOSYS OS interface", + .init = &ENOSYS_osdep_init, + .fake = 1, +}; + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r fd025a504307 -r a4d3be2e38ea tools/libxc/xenctrlosdep.h --- a/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xenctrlosdep.h Fri Dec 03 09:36:47 2010 +0000 @@ -23,6 +23,18 @@ * This interface defines the interactions between the Xen control * libraries and the OS facilities used to communicate with the * hypervisor. + * + * It is possible to override the default (native) implementation by + * setting the XENCTRL_OSDEP environment variable to point to a + * plugin library. Userspace can use this facility to intercept + * hypervisor operations. This can be used e.g. to implement a + * userspace simulator for Xen hypercalls. + * + * The plugin must contain a data structure: + * xc_osdep_info_t xc_osdep_info; + * + * xc_osdep_init: + * Must return a suitable struct xc_osdep_ops pointer or NULL on failure. */ #ifndef XC_OSDEP_H @@ -125,6 +137,9 @@ struct xc_osdep_info /* True if this interface backs onto a fake Xen. */ int fake; + + /* For internal use by loader. */ + void *dl_handle; }; typedef struct xc_osdep_info xc_osdep_info_t; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 24 of 25] libxc: move foreign memory functions to xc_foreign_memory.c
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID 4ffab774457dc03d8956113799076cb173522811 # Parent a4d3be2e38ea883d3d2404078adc94960692d022 libxc: move foreign memory functions to xc_foreign_memory.c Now that this file exists it is a better home for these than xc_misc.c Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r a4d3be2e38ea -r 4ffab774457d tools/libxc/xc_foreign_memory.c --- a/tools/libxc/xc_foreign_memory.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_foreign_memory.c Fri Dec 03 09:36:47 2010 +0000 @@ -19,6 +19,37 @@ */ #include "xc_private.h" + +void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot, + const xen_pfn_t *arr, int num) +{ + void *res; + int i, *err; + + if (num < 0) { + errno = -EINVAL; + return NULL; + } + + err = malloc(num * sizeof(*err)); + if (!err) + return NULL; + + res = xc_map_foreign_bulk(xch, dom, prot, arr, err, num); + if (res) { + for (i = 0; i < num; i++) { + if (err[i]) { + errno = -err[i]; + munmap(res, num * PAGE_SIZE); + res = NULL; + break; + } + } + } + + free(err); + return res; +} void *xc_map_foreign_range(xc_interface *xch, uint32_t dom, int size, int prot, unsigned long mfn) @@ -49,6 +80,47 @@ void *xc_map_foreign_bulk(xc_interface * dom, prot, arr, err, num); } +/* stub for all not yet converted OSes */ +void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int prot, + const xen_pfn_t *arr, int *err, unsigned int num) +{ + xen_pfn_t *pfn; + unsigned int i; + void *ret; + + if ((int)num <= 0) { + errno = EINVAL; + return NULL; + } + + pfn = malloc(num * sizeof(*pfn)); + if (!pfn) { + errno = ENOMEM; + return NULL; + } + + memcpy(pfn, arr, num * sizeof(*arr)); + ret = xc_map_foreign_batch(xch, dom, prot, pfn, num); + + if (ret) { + for (i = 0; i < num; ++i) + switch (pfn[i] ^ arr[i]) { + case 0: + err[i] = 0; + break; + default: + err[i] = -EINVAL; + break; + } + } else + memset(err, 0, num * sizeof(*err)); + + free(pfn); + + return ret; +} + /* * Local variables: * mode: C diff -r a4d3be2e38ea -r 4ffab774457d tools/libxc/xc_misc.c --- a/tools/libxc/xc_misc.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_misc.c Fri Dec 03 09:36:47 2010 +0000 @@ -512,78 +512,6 @@ int xc_hvm_set_mem_type( } -/* stub for all not yet converted OSes */ -void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h, - uint32_t dom, int prot, - const xen_pfn_t *arr, int *err, unsigned int num) -{ - xen_pfn_t *pfn; - unsigned int i; - void *ret; - - if ((int)num <= 0) { - errno = EINVAL; - return NULL; - } - - pfn = malloc(num * sizeof(*pfn)); - if (!pfn) { - errno = ENOMEM; - return NULL; - } - - memcpy(pfn, arr, num * sizeof(*arr)); - ret = xc_map_foreign_batch(xch, dom, prot, pfn, num); - - if (ret) { - for (i = 0; i < num; ++i) - switch (pfn[i] ^ arr[i]) { - case 0: - err[i] = 0; - break; - default: - err[i] = -EINVAL; - break; - } - } else - memset(err, 0, num * sizeof(*err)); - - free(pfn); - - return ret; -} - -void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot, - const xen_pfn_t *arr, int num) -{ - void *res; - int i, *err; - - if (num < 0) { - errno = -EINVAL; - return NULL; - } - - err = malloc(num * sizeof(*err)); - if (!err) - return NULL; - - res = xc_map_foreign_bulk(xch, dom, prot, arr, err, num); - if (res) { - for (i = 0; i < num; i++) { - if (err[i]) { - errno = -err[i]; - munmap(res, num * PAGE_SIZE); - res = NULL; - break; - } - } - } - - free(err); - return res; -} - /* * Local variables: * mode: C _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH 25 of 25] libxc: refactor Linux OS interface into a separate file
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1291369007 0 # Node ID 96554e113aa1b7de6ba5296fcd438d63a6b7179a # Parent 4ffab774457dc03d8956113799076cb173522811 libxc: refactor Linux OS interface into a separate file. This helps ensure that the osdep abstraction is complete by allowing us to avoid including xc_private.h. All the other OS backends could benefit from the same treatment but since I cannot compile test I did not do this. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 4ffab774457d -r 96554e113aa1 tools/libxc/Makefile --- a/tools/libxc/Makefile Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/Makefile Fri Dec 03 09:36:47 2010 +0000 @@ -34,7 +34,7 @@ CTRL_SRCS-y += xtl_core.c CTRL_SRCS-y += xtl_core.c CTRL_SRCS-y += xtl_logger_stdio.c CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c -CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c +CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c diff -r 4ffab774457d -r 96554e113aa1 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:47 2010 +0000 @@ -2,9 +2,6 @@ * * 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@cl.cam.ac.uk> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -22,436 +19,6 @@ */ #include "xc_private.h" - -#include <xen/memory.h> -#include <xen/sys/evtchn.h> -#include <xen/sys/gntdev.h> -#include <unistd.h> -#include <fcntl.h> - -static xc_osdep_handle linux_privcmd_open(xc_interface *xch) -{ - int flags, saved_errno; - int fd = open("/proc/xen/privcmd", O_RDWR); - - if ( fd == -1 ) - { - PERROR("Could not obtain handle on privileged command interface"); - return XC_OSDEP_OPEN_ERROR; - } - - /* Although we return the file handle as the ''xc handle'' the API - does not specify / guarentee that this integer is in fact - a file handle. Thus we must take responsiblity to ensure - it doesn''t propagate (ie leak) outside the process */ - if ( (flags = fcntl(fd, F_GETFD)) < 0 ) - { - PERROR("Could not get file handle flags"); - goto error; - } - - flags |= FD_CLOEXEC; - - if ( fcntl(fd, F_SETFD, flags) < 0 ) - { - PERROR("Could not set file handle flags"); - goto error; - } - - return (xc_osdep_handle)fd; - - error: - saved_errno = errno; - close(fd); - errno = saved_errno; - return XC_OSDEP_OPEN_ERROR; -} - -static int linux_privcmd_close(xc_interface *xch, xc_osdep_handle h) -{ - int fd = (int)h; - return close(fd); -} - -static int linux_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall) -{ - int fd = (int)h; - return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall); -} - -static int xc_map_foreign_batch_single(int fd, uint32_t dom, - xen_pfn_t *mfn, unsigned long addr) -{ - privcmd_mmapbatch_t ioctlx; - int rc; - - ioctlx.num = 1; - ioctlx.dom = dom; - ioctlx.addr = addr; - ioctlx.arr = mfn; - - do - { - *mfn ^= XEN_DOMCTL_PFINFO_PAGEDTAB; - usleep(100); - rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); - } - while ( (rc < 0) && (errno == ENOENT) ); - - return rc; -} - -static void *linux_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h, - uint32_t dom, int prot, - xen_pfn_t *arr, int num) -{ - int fd = (int)h; - privcmd_mmapbatch_t ioctlx; - void *addr; - int rc; - - addr = mmap(NULL, num << XC_PAGE_SHIFT, prot, MAP_SHARED, fd, 0); - if ( addr == MAP_FAILED ) - { - PERROR("xc_map_foreign_batch: mmap failed"); - return NULL; - } - - ioctlx.num = num; - ioctlx.dom = dom; - ioctlx.addr = (unsigned long)addr; - ioctlx.arr = arr; - - rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); - if ( (rc < 0) && (errno == ENOENT) ) - { - int i; - - for ( i = 0; i < num; i++ ) - { - if ( (arr[i] & XEN_DOMCTL_PFINFO_LTAB_MASK) =- XEN_DOMCTL_PFINFO_PAGEDTAB ) - { - unsigned long paged_addr = (unsigned long)addr + (i << XC_PAGE_SHIFT); - rc = xc_map_foreign_batch_single(fd, dom, &arr[i], - paged_addr); - if ( rc < 0 ) - goto out; - } - } - } - - out: - if ( rc < 0 ) - { - int saved_errno = errno; - PERROR("xc_map_foreign_batch: ioctl failed"); - (void)munmap(addr, num << XC_PAGE_SHIFT); - errno = saved_errno; - return NULL; - } - - return addr; -} - -static void *linux_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) -{ - int fd = (int)h; - privcmd_mmapbatch_v2_t ioctlx; - void *addr; - unsigned int i; - int rc; - - addr = mmap(NULL, (unsigned long)num << XC_PAGE_SHIFT, prot, MAP_SHARED, - fd, 0); - if ( addr == MAP_FAILED ) - { - PERROR("xc_map_foreign_batch: mmap failed"); - return NULL; - } - - ioctlx.num = num; - ioctlx.dom = dom; - ioctlx.addr = (unsigned long)addr; - ioctlx.arr = arr; - ioctlx.err = err; - - rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx); - - if ( rc < 0 && errno == ENOENT ) - { - for ( i = rc = 0; rc == 0 && i < num; i++ ) - { - if ( err[i] != -ENOENT ) - continue; - - ioctlx.num = 1; - ioctlx.dom = dom; - ioctlx.addr = (unsigned long)addr + ((unsigned long)i<<XC_PAGE_SHIFT); - ioctlx.arr = arr + i; - ioctlx.err = err + i; - do { - usleep(100); - rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx); - } while ( rc < 0 && err[i] == -ENOENT ); - } - } - - if ( rc < 0 && errno == EINVAL && (int)num > 0 ) - { - /* - * IOCTL_PRIVCMD_MMAPBATCH_V2 is not supported - fall back to - * IOCTL_PRIVCMD_MMAPBATCH. - */ - xen_pfn_t *pfn = malloc(num * sizeof(*pfn)); - - if ( pfn ) - { - privcmd_mmapbatch_t ioctlx; - - memcpy(pfn, arr, num * sizeof(*arr)); - - ioctlx.num = num; - ioctlx.dom = dom; - ioctlx.addr = (unsigned long)addr; - ioctlx.arr = pfn; - - rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); - - rc = rc < 0 ? -errno : 0; - - for ( i = 0; i < num; ++i ) - { - switch ( pfn[i] ^ arr[i] ) - { - case 0: - err[i] = rc != -ENOENT ? rc : 0; - continue; - default: - err[i] = -EINVAL; - continue; - case XEN_DOMCTL_PFINFO_PAGEDTAB: - if ( rc != -ENOENT ) - { - err[i] = rc ?: -EINVAL; - continue; - } - rc = xc_map_foreign_batch_single(fd, dom, pfn + i, - (unsigned long)addr + ((unsigned long)i<<XC_PAGE_SHIFT)); - if ( rc < 0 ) - { - rc = -errno; - break; - } - rc = -ENOENT; - continue; - } - break; - } - - free(pfn); - - if ( rc == -ENOENT && i == num ) - rc = 0; - else if ( rc ) - { - errno = -rc; - rc = -1; - } - } - else - { - errno = -ENOMEM; - rc = -1; - } - } - - if ( rc < 0 ) - { - int saved_errno = errno; - - PERROR("xc_map_foreign_bulk: ioctl failed"); - (void)munmap(addr, (unsigned long)num << XC_PAGE_SHIFT); - errno = saved_errno; - return NULL; - } - - return addr; -} - -static void *linux_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h, - uint32_t dom, int size, int prot, - unsigned long mfn) -{ - xen_pfn_t *arr; - int num; - int i; - void *ret; - - num = (size + XC_PAGE_SIZE - 1) >> XC_PAGE_SHIFT; - arr = calloc(num, sizeof(xen_pfn_t)); - - for ( i = 0; i < num; i++ ) - arr[i] = mfn + i; - - ret = xc_map_foreign_pages(xch, dom, prot, arr, num); - free(arr); - return ret; -} - -static void *linux_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) -{ - xen_pfn_t *arr; - int num_per_entry; - int num; - int i; - int j; - void *ret; - - num_per_entry = chunksize >> XC_PAGE_SHIFT; - num = num_per_entry * nentries; - arr = calloc(num, sizeof(xen_pfn_t)); - - for ( i = 0; i < nentries; i++ ) - for ( j = 0; j < num_per_entry; j++ ) - arr[i * num_per_entry + j] = entries[i].mfn + j; - - ret = xc_map_foreign_pages(xch, dom, prot, arr, num); - free(arr); - return ret; -} - -static struct xc_osdep_ops linux_privcmd_ops = { - .open = &linux_privcmd_open, - .close = &linux_privcmd_close, - - .u.privcmd = { - .hypercall = &linux_privcmd_hypercall, - - .map_foreign_batch = &linux_privcmd_map_foreign_batch, - .map_foreign_bulk = &linux_privcmd_map_foreign_bulk, - .map_foreign_range = &linux_privcmd_map_foreign_range, - .map_foreign_ranges = &linux_privcmd_map_foreign_ranges, - }, -}; - -#define DEVXEN "/dev/xen/" - -static xc_osdep_handle linux_evtchn_open(xc_evtchn *xce) -{ - int fd = open(DEVXEN "evtchn", O_RDWR); - if ( fd == -1 ) - return XC_OSDEP_OPEN_ERROR; - - return (xc_osdep_handle)fd; -} - -static int linux_evtchn_close(xc_evtchn *xce, xc_osdep_handle h) -{ - int fd = (int)h; - return close(fd); -} - -static int linux_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h) -{ - return (int)h; -} - -static int linux_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 -linux_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid) -{ - int fd = (int)h; - struct ioctl_evtchn_bind_unbound_port bind; - - bind.remote_domain = domid; - - return ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); -} - -static evtchn_port_or_error_t -linux_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; - - bind.remote_domain = domid; - bind.remote_port = remote_port; - - return ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); -} - -static evtchn_port_or_error_t -linux_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) -{ - int fd = (int)h; - struct ioctl_evtchn_bind_virq bind; - - bind.virq = virq; - - return ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); -} - -static int linux_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 linux_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) -{ - int fd = (int)h; - evtchn_port_t port; - - if ( read(fd, &port, sizeof(port)) != sizeof(port) ) - return -1; - - return port; -} - -static int linux_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) -{ - int fd = (int)h; - - if ( write(fd, &port, sizeof(port)) != sizeof(port) ) - return -1; - return 0; -} - -static struct xc_osdep_ops linux_evtchn_ops = { - .open = &linux_evtchn_open, - .close = &linux_evtchn_close, - - .u.evtchn = { - .fd = &linux_evtchn_fd, - .notify = &linux_evtchn_notify, - .bind_unbound_port = &linux_evtchn_bind_unbound_port, - .bind_interdomain = &linux_evtchn_bind_interdomain, - .bind_virq = &linux_evtchn_bind_virq, - .unbind = &linux_evtchn_unbind, - .pending = &linux_evtchn_pending, - .unmask = &linux_evtchn_unmask, - }, -}; /* Optionally flush file to disk and discard page cache */ void discard_file_cache(xc_interface *xch, int fd, int flush) @@ -488,214 +55,6 @@ void discard_file_cache(xc_interface *xc errno = saved_errno; } -static xc_osdep_handle linux_gnttab_open(xc_gnttab *xcg) -{ - int fd = open(DEVXEN "gntdev", O_RDWR); - - if ( fd == -1 ) - return XC_OSDEP_OPEN_ERROR; - - return (xc_osdep_handle)fd; -} - -static int linux_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h) -{ - int fd = (int)h; - return close(fd); -} - -static void *linux_gnttab_map_grant_ref(xc_gnttab *xch, xc_osdep_handle h, - uint32_t domid, uint32_t ref, int prot) -{ - int fd = (int)h; - struct ioctl_gntdev_map_grant_ref map; - void *addr; - - map.count = 1; - map.refs[0].domid = domid; - map.refs[0].ref = ref; - - if ( ioctl(fd, IOCTL_GNTDEV_MAP_GRANT_REF, &map) ) { - PERROR("xc_gnttab_map_grant_ref: ioctl MAP_GRANT_REF failed"); - return NULL; - } - -mmap_again: - addr = mmap(NULL, XC_PAGE_SIZE, prot, MAP_SHARED, fd, map.index); - if ( addr == MAP_FAILED ) - { - int saved_errno = errno; - struct ioctl_gntdev_unmap_grant_ref unmap_grant; - - if(saved_errno == EAGAIN) - { - usleep(1000); - goto mmap_again; - } - /* Unmap the driver slots used to store the grant information. */ - PERROR("xc_gnttab_map_grant_ref: mmap failed"); - unmap_grant.index = map.index; - unmap_grant.count = 1; - ioctl(fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant); - errno = saved_errno; - return NULL; - } - - return addr; -} - -static void *do_gnttab_map_grant_refs(xc_gnttab *xch, xc_osdep_handle h, - uint32_t count, - uint32_t *domids, int domids_stride, - uint32_t *refs, int prot) -{ - int fd = (int)h; - struct ioctl_gntdev_map_grant_ref *map; - void *addr = NULL; - int i; - - map = malloc(sizeof(*map) + - (count - 1) * sizeof(struct ioctl_gntdev_map_grant_ref)); - if ( map == NULL ) - return NULL; - - for ( i = 0; i < count; i++ ) - { - map->refs[i].domid = domids[i * domids_stride]; - map->refs[i].ref = refs[i]; - } - - map->count = count; - - if ( ioctl(fd, IOCTL_GNTDEV_MAP_GRANT_REF, map) ) { - PERROR("xc_gnttab_map_grant_refs: ioctl MAP_GRANT_REF failed"); - goto out; - } - - addr = mmap(NULL, XC_PAGE_SIZE * count, prot, MAP_SHARED, fd, - map->index); - if ( addr == MAP_FAILED ) - { - int saved_errno = errno; - struct ioctl_gntdev_unmap_grant_ref unmap_grant; - - /* Unmap the driver slots used to store the grant information. */ - PERROR("xc_gnttab_map_grant_refs: mmap failed"); - unmap_grant.index = map->index; - unmap_grant.count = count; - ioctl(fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant); - errno = saved_errno; - addr = NULL; - } - - out: - free(map); - - return addr; -} - -static void *linux_gnttab_map_grant_refs(xc_gnttab *xcg, xc_osdep_handle h, - uint32_t count, uint32_t *domids, - uint32_t *refs, int prot) -{ - return do_gnttab_map_grant_refs(xcg, h, count, domids, 1, refs, prot); -} - -static void *linux_gnttab_map_domain_grant_refs(xc_gnttab *xcg, xc_osdep_handle h, - uint32_t count, - uint32_t domid, uint32_t *refs, int prot) -{ - return do_gnttab_map_grant_refs(xcg, h, count, &domid, 0, refs, prot); -} - -static int linux_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h, - void *start_address, uint32_t count) -{ - int fd = (int)h; - struct ioctl_gntdev_get_offset_for_vaddr get_offset; - struct ioctl_gntdev_unmap_grant_ref unmap_grant; - int rc; - - if ( start_address == NULL ) - { - errno = EINVAL; - return -1; - } - - /* First, it is necessary to get the offset which was initially used to - * mmap() the pages. - */ - get_offset.vaddr = (unsigned long)start_address; - if ( (rc = ioctl(fd, IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR, - &get_offset)) ) - return rc; - - if ( get_offset.count != count ) - { - errno = EINVAL; - return -1; - } - - /* Next, unmap the memory. */ - if ( (rc = munmap(start_address, count * getpagesize())) ) - return rc; - - /* Finally, unmap the driver slots used to store the grant information. */ - unmap_grant.index = get_offset.offset; - unmap_grant.count = count; - if ( (rc = ioctl(fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant)) ) - return rc; - - return 0; -} - -static int linux_gnttab_set_max_grants(xc_gnttab *xcg, xc_osdep_handle h, uint32_t count) -{ - int fd = (int)h; - struct ioctl_gntdev_set_max_grants set_max; - int rc; - - set_max.count = count; - if ( (rc = ioctl(fd, IOCTL_GNTDEV_SET_MAX_GRANTS, &set_max)) ) - return rc; - - return 0; -} - -static struct xc_osdep_ops linux_gnttab_ops = { - .open = &linux_gnttab_open, - .close = &linux_gnttab_close, - - .u.gnttab = { - .map_grant_ref = &linux_gnttab_map_grant_ref, - .map_grant_refs = &linux_gnttab_map_grant_refs, - .map_domain_grant_refs = &linux_gnttab_map_domain_grant_refs, - .munmap = &linux_gnttab_munmap, - .set_max_grants = &linux_gnttab_set_max_grants, - }, -}; - -static struct xc_osdep_ops *linux_osdep_init(xc_interface *xch, enum xc_osdep_type type) -{ - switch ( type ) - { - case XC_OSDEP_PRIVCMD: - return &linux_privcmd_ops; - case XC_OSDEP_EVTCHN: - return &linux_evtchn_ops; - case XC_OSDEP_GNTTAB: - return &linux_gnttab_ops; - default: - return NULL; - } -} - -xc_osdep_info_t xc_osdep_info = { - .name = "Linux Native OS interface", - .init = &linux_osdep_init, - .fake = 0, -}; - /* * Local variables: * mode: C diff -r 4ffab774457d -r 96554e113aa1 tools/libxc/xc_linux_osdep.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxc/xc_linux_osdep.c Fri Dec 03 09:36:47 2010 +0000 @@ -0,0 +1,685 @@ +/****************************************************************************** + * + * 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@cl.cam.ac.uk> + * + * 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 <errno.h> +#include <fcntl.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <sys/mman.h> +#include <sys/ioctl.h> + +#include <xen/memory.h> +#include <xen/sys/evtchn.h> +#include <xen/sys/gntdev.h> + +#include "xenctrl.h" +#include "xenctrlosdep.h" + +#define ERROR(_m, _a...) xc_osdep_log(xch,XTL_ERROR,XC_INTERNAL_ERROR,_m , ## _a ) +#define PERROR(_m, _a...) xc_osdep_log(xch,XTL_ERROR,XC_INTERNAL_ERROR,_m \ + " (%d = %s)", ## _a , errno, xc_strerror(xch, errno)) + +static xc_osdep_handle linux_privcmd_open(xc_interface *xch) +{ + int flags, saved_errno; + int fd = open("/proc/xen/privcmd", O_RDWR); + + if ( fd == -1 ) + { + PERROR("Could not obtain handle on privileged command interface"); + return XC_OSDEP_OPEN_ERROR; + } + + /* Although we return the file handle as the ''xc handle'' the API + does not specify / guarentee that this integer is in fact + a file handle. Thus we must take responsiblity to ensure + it doesn''t propagate (ie leak) outside the process */ + if ( (flags = fcntl(fd, F_GETFD)) < 0 ) + { + PERROR("Could not get file handle flags"); + goto error; + } + + flags |= FD_CLOEXEC; + + if ( fcntl(fd, F_SETFD, flags) < 0 ) + { + PERROR("Could not set file handle flags"); + goto error; + } + + return (xc_osdep_handle)fd; + + error: + saved_errno = errno; + close(fd); + errno = saved_errno; + return XC_OSDEP_OPEN_ERROR; +} + +static int linux_privcmd_close(xc_interface *xch, xc_osdep_handle h) +{ + int fd = (int)h; + return close(fd); +} + +static int linux_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall) +{ + int fd = (int)h; + return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall); +} + +static int xc_map_foreign_batch_single(int fd, uint32_t dom, + xen_pfn_t *mfn, unsigned long addr) +{ + privcmd_mmapbatch_t ioctlx; + int rc; + + ioctlx.num = 1; + ioctlx.dom = dom; + ioctlx.addr = addr; + ioctlx.arr = mfn; + + do + { + *mfn ^= XEN_DOMCTL_PFINFO_PAGEDTAB; + usleep(100); + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); + } + while ( (rc < 0) && (errno == ENOENT) ); + + return rc; +} + +static void *linux_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int prot, + xen_pfn_t *arr, int num) +{ + int fd = (int)h; + privcmd_mmapbatch_t ioctlx; + void *addr; + int rc; + + addr = mmap(NULL, num << XC_PAGE_SHIFT, prot, MAP_SHARED, fd, 0); + if ( addr == MAP_FAILED ) + { + PERROR("xc_map_foreign_batch: mmap failed"); + return NULL; + } + + ioctlx.num = num; + ioctlx.dom = dom; + ioctlx.addr = (unsigned long)addr; + ioctlx.arr = arr; + + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); + if ( (rc < 0) && (errno == ENOENT) ) + { + int i; + + for ( i = 0; i < num; i++ ) + { + if ( (arr[i] & XEN_DOMCTL_PFINFO_LTAB_MASK) =+ XEN_DOMCTL_PFINFO_PAGEDTAB ) + { + unsigned long paged_addr = (unsigned long)addr + (i << XC_PAGE_SHIFT); + rc = xc_map_foreign_batch_single(fd, dom, &arr[i], + paged_addr); + if ( rc < 0 ) + goto out; + } + } + } + + out: + if ( rc < 0 ) + { + int saved_errno = errno; + PERROR("xc_map_foreign_batch: ioctl failed"); + (void)munmap(addr, num << XC_PAGE_SHIFT); + errno = saved_errno; + return NULL; + } + + return addr; +} + +static void *linux_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) +{ + int fd = (int)h; + privcmd_mmapbatch_v2_t ioctlx; + void *addr; + unsigned int i; + int rc; + + addr = mmap(NULL, (unsigned long)num << XC_PAGE_SHIFT, prot, MAP_SHARED, + fd, 0); + if ( addr == MAP_FAILED ) + { + PERROR("xc_map_foreign_batch: mmap failed"); + return NULL; + } + + ioctlx.num = num; + ioctlx.dom = dom; + ioctlx.addr = (unsigned long)addr; + ioctlx.arr = arr; + ioctlx.err = err; + + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx); + + if ( rc < 0 && errno == ENOENT ) + { + for ( i = rc = 0; rc == 0 && i < num; i++ ) + { + if ( err[i] != -ENOENT ) + continue; + + ioctlx.num = 1; + ioctlx.dom = dom; + ioctlx.addr = (unsigned long)addr + ((unsigned long)i<<XC_PAGE_SHIFT); + ioctlx.arr = arr + i; + ioctlx.err = err + i; + do { + usleep(100); + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx); + } while ( rc < 0 && err[i] == -ENOENT ); + } + } + + if ( rc < 0 && errno == EINVAL && (int)num > 0 ) + { + /* + * IOCTL_PRIVCMD_MMAPBATCH_V2 is not supported - fall back to + * IOCTL_PRIVCMD_MMAPBATCH. + */ + xen_pfn_t *pfn = malloc(num * sizeof(*pfn)); + + if ( pfn ) + { + privcmd_mmapbatch_t ioctlx; + + memcpy(pfn, arr, num * sizeof(*arr)); + + ioctlx.num = num; + ioctlx.dom = dom; + ioctlx.addr = (unsigned long)addr; + ioctlx.arr = pfn; + + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); + + rc = rc < 0 ? -errno : 0; + + for ( i = 0; i < num; ++i ) + { + switch ( pfn[i] ^ arr[i] ) + { + case 0: + err[i] = rc != -ENOENT ? rc : 0; + continue; + default: + err[i] = -EINVAL; + continue; + case XEN_DOMCTL_PFINFO_PAGEDTAB: + if ( rc != -ENOENT ) + { + err[i] = rc ?: -EINVAL; + continue; + } + rc = xc_map_foreign_batch_single(fd, dom, pfn + i, + (unsigned long)addr + ((unsigned long)i<<XC_PAGE_SHIFT)); + if ( rc < 0 ) + { + rc = -errno; + break; + } + rc = -ENOENT; + continue; + } + break; + } + + free(pfn); + + if ( rc == -ENOENT && i == num ) + rc = 0; + else if ( rc ) + { + errno = -rc; + rc = -1; + } + } + else + { + errno = -ENOMEM; + rc = -1; + } + } + + if ( rc < 0 ) + { + int saved_errno = errno; + + PERROR("xc_map_foreign_bulk: ioctl failed"); + (void)munmap(addr, (unsigned long)num << XC_PAGE_SHIFT); + errno = saved_errno; + return NULL; + } + + return addr; +} + +static void *linux_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int size, int prot, + unsigned long mfn) +{ + xen_pfn_t *arr; + int num; + int i; + void *ret; + + num = (size + XC_PAGE_SIZE - 1) >> XC_PAGE_SHIFT; + arr = calloc(num, sizeof(xen_pfn_t)); + + for ( i = 0; i < num; i++ ) + arr[i] = mfn + i; + + ret = xc_map_foreign_pages(xch, dom, prot, arr, num); + free(arr); + return ret; +} + +static void *linux_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) +{ + xen_pfn_t *arr; + int num_per_entry; + int num; + int i; + int j; + void *ret; + + num_per_entry = chunksize >> XC_PAGE_SHIFT; + num = num_per_entry * nentries; + arr = calloc(num, sizeof(xen_pfn_t)); + + for ( i = 0; i < nentries; i++ ) + for ( j = 0; j < num_per_entry; j++ ) + arr[i * num_per_entry + j] = entries[i].mfn + j; + + ret = xc_map_foreign_pages(xch, dom, prot, arr, num); + free(arr); + return ret; +} + +static struct xc_osdep_ops linux_privcmd_ops = { + .open = &linux_privcmd_open, + .close = &linux_privcmd_close, + + .u.privcmd = { + .hypercall = &linux_privcmd_hypercall, + + .map_foreign_batch = &linux_privcmd_map_foreign_batch, + .map_foreign_bulk = &linux_privcmd_map_foreign_bulk, + .map_foreign_range = &linux_privcmd_map_foreign_range, + .map_foreign_ranges = &linux_privcmd_map_foreign_ranges, + }, +}; + +#define DEVXEN "/dev/xen/" + +static xc_osdep_handle linux_evtchn_open(xc_evtchn *xce) +{ + int fd = open(DEVXEN "evtchn", O_RDWR); + if ( fd == -1 ) + return XC_OSDEP_OPEN_ERROR; + + return (xc_osdep_handle)fd; +} + +static int linux_evtchn_close(xc_evtchn *xce, xc_osdep_handle h) +{ + int fd = (int)h; + return close(fd); +} + +static int linux_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h) +{ + return (int)h; +} + +static int linux_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 +linux_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid) +{ + int fd = (int)h; + struct ioctl_evtchn_bind_unbound_port bind; + + bind.remote_domain = domid; + + return ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); +} + +static evtchn_port_or_error_t +linux_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; + + bind.remote_domain = domid; + bind.remote_port = remote_port; + + return ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); +} + +static evtchn_port_or_error_t +linux_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq) +{ + int fd = (int)h; + struct ioctl_evtchn_bind_virq bind; + + bind.virq = virq; + + return ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); +} + +static int linux_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 linux_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) +{ + int fd = (int)h; + evtchn_port_t port; + + if ( read(fd, &port, sizeof(port)) != sizeof(port) ) + return -1; + + return port; +} + +static int linux_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port) +{ + int fd = (int)h; + + if ( write(fd, &port, sizeof(port)) != sizeof(port) ) + return -1; + return 0; +} + +static struct xc_osdep_ops linux_evtchn_ops = { + .open = &linux_evtchn_open, + .close = &linux_evtchn_close, + + .u.evtchn = { + .fd = &linux_evtchn_fd, + .notify = &linux_evtchn_notify, + .bind_unbound_port = &linux_evtchn_bind_unbound_port, + .bind_interdomain = &linux_evtchn_bind_interdomain, + .bind_virq = &linux_evtchn_bind_virq, + .unbind = &linux_evtchn_unbind, + .pending = &linux_evtchn_pending, + .unmask = &linux_evtchn_unmask, + }, +}; + +static xc_osdep_handle linux_gnttab_open(xc_gnttab *xcg) +{ + int fd = open(DEVXEN "gntdev", O_RDWR); + + if ( fd == -1 ) + return XC_OSDEP_OPEN_ERROR; + + return (xc_osdep_handle)fd; +} + +static int linux_gnttab_close(xc_gnttab *xcg, xc_osdep_handle h) +{ + int fd = (int)h; + return close(fd); +} + +static void *linux_gnttab_map_grant_ref(xc_gnttab *xch, xc_osdep_handle h, + uint32_t domid, uint32_t ref, int prot) +{ + int fd = (int)h; + struct ioctl_gntdev_map_grant_ref map; + void *addr; + + map.count = 1; + map.refs[0].domid = domid; + map.refs[0].ref = ref; + + if ( ioctl(fd, IOCTL_GNTDEV_MAP_GRANT_REF, &map) ) { + PERROR("xc_gnttab_map_grant_ref: ioctl MAP_GRANT_REF failed"); + return NULL; + } + +mmap_again: + addr = mmap(NULL, XC_PAGE_SIZE, prot, MAP_SHARED, fd, map.index); + if ( addr == MAP_FAILED ) + { + int saved_errno = errno; + struct ioctl_gntdev_unmap_grant_ref unmap_grant; + + if(saved_errno == EAGAIN) + { + usleep(1000); + goto mmap_again; + } + /* Unmap the driver slots used to store the grant information. */ + PERROR("xc_gnttab_map_grant_ref: mmap failed"); + unmap_grant.index = map.index; + unmap_grant.count = 1; + ioctl(fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant); + errno = saved_errno; + return NULL; + } + + return addr; +} + +static void *do_gnttab_map_grant_refs(xc_gnttab *xch, xc_osdep_handle h, + uint32_t count, + uint32_t *domids, int domids_stride, + uint32_t *refs, int prot) +{ + int fd = (int)h; + struct ioctl_gntdev_map_grant_ref *map; + void *addr = NULL; + int i; + + map = malloc(sizeof(*map) + + (count - 1) * sizeof(struct ioctl_gntdev_map_grant_ref)); + if ( map == NULL ) + return NULL; + + for ( i = 0; i < count; i++ ) + { + map->refs[i].domid = domids[i * domids_stride]; + map->refs[i].ref = refs[i]; + } + + map->count = count; + + if ( ioctl(fd, IOCTL_GNTDEV_MAP_GRANT_REF, map) ) { + PERROR("xc_gnttab_map_grant_refs: ioctl MAP_GRANT_REF failed"); + goto out; + } + + addr = mmap(NULL, XC_PAGE_SIZE * count, prot, MAP_SHARED, fd, + map->index); + if ( addr == MAP_FAILED ) + { + int saved_errno = errno; + struct ioctl_gntdev_unmap_grant_ref unmap_grant; + + /* Unmap the driver slots used to store the grant information. */ + PERROR("xc_gnttab_map_grant_refs: mmap failed"); + unmap_grant.index = map->index; + unmap_grant.count = count; + ioctl(fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant); + errno = saved_errno; + addr = NULL; + } + + out: + free(map); + + return addr; +} + +static void *linux_gnttab_map_grant_refs(xc_gnttab *xcg, xc_osdep_handle h, + uint32_t count, uint32_t *domids, + uint32_t *refs, int prot) +{ + return do_gnttab_map_grant_refs(xcg, h, count, domids, 1, refs, prot); +} + +static void *linux_gnttab_map_domain_grant_refs(xc_gnttab *xcg, xc_osdep_handle h, + uint32_t count, + uint32_t domid, uint32_t *refs, int prot) +{ + return do_gnttab_map_grant_refs(xcg, h, count, &domid, 0, refs, prot); +} + +static int linux_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h, + void *start_address, uint32_t count) +{ + int fd = (int)h; + struct ioctl_gntdev_get_offset_for_vaddr get_offset; + struct ioctl_gntdev_unmap_grant_ref unmap_grant; + int rc; + + if ( start_address == NULL ) + { + errno = EINVAL; + return -1; + } + + /* First, it is necessary to get the offset which was initially used to + * mmap() the pages. + */ + get_offset.vaddr = (unsigned long)start_address; + if ( (rc = ioctl(fd, IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR, + &get_offset)) ) + return rc; + + if ( get_offset.count != count ) + { + errno = EINVAL; + return -1; + } + + /* Next, unmap the memory. */ + if ( (rc = munmap(start_address, count * getpagesize())) ) + return rc; + + /* Finally, unmap the driver slots used to store the grant information. */ + unmap_grant.index = get_offset.offset; + unmap_grant.count = count; + if ( (rc = ioctl(fd, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant)) ) + return rc; + + return 0; +} + +static int linux_gnttab_set_max_grants(xc_gnttab *xcg, xc_osdep_handle h, uint32_t count) +{ + int fd = (int)h; + struct ioctl_gntdev_set_max_grants set_max; + int rc; + + set_max.count = count; + if ( (rc = ioctl(fd, IOCTL_GNTDEV_SET_MAX_GRANTS, &set_max)) ) + return rc; + + return 0; +} + +static struct xc_osdep_ops linux_gnttab_ops = { + .open = &linux_gnttab_open, + .close = &linux_gnttab_close, + + .u.gnttab = { + .map_grant_ref = &linux_gnttab_map_grant_ref, + .map_grant_refs = &linux_gnttab_map_grant_refs, + .map_domain_grant_refs = &linux_gnttab_map_domain_grant_refs, + .munmap = &linux_gnttab_munmap, + .set_max_grants = &linux_gnttab_set_max_grants, + }, +}; + +static struct xc_osdep_ops *linux_osdep_init(xc_interface *xch, enum xc_osdep_type type) +{ + switch ( type ) + { + case XC_OSDEP_PRIVCMD: + return &linux_privcmd_ops; + case XC_OSDEP_EVTCHN: + return &linux_evtchn_ops; + case XC_OSDEP_GNTTAB: + return &linux_gnttab_ops; + default: + return NULL; + } +} + +xc_osdep_info_t xc_osdep_info = { + .name = "Linux Native OS interface", + .init = &linux_osdep_init, + .fake = 0, +}; + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH] qemu-xen: update for libxc evtchn interface change.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com> --- hw/xen_backend.c | 6 +++--- hw/xen_backend.h | 2 +- i386-dm/helper2.c | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hw/xen_backend.c b/hw/xen_backend.c index 537e21f..577f68e 100644 --- a/hw/xen_backend.c +++ b/hw/xen_backend.c @@ -208,8 +208,8 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, xendev->debug = debug; xendev->local_port = -1; - xendev->evtchndev = xc_evtchn_open(); - if (xendev->evtchndev < 0) { + xendev->evtchndev = xc_evtchn_open(NULL, 0); + if (xendev->evtchndev == NULL) { xen_be_printf(NULL, 0, "can''t open evtchn device\n"); qemu_free(xendev); return NULL; @@ -267,7 +267,7 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev) qemu_free(xendev->fe); } - if (xendev->evtchndev >= 0) + if (xendev->evtchndev != NULL) xc_evtchn_close(xendev->evtchndev); if (xendev->gnttabdev >= 0) xc_gnttab_close(xc_handle, xendev->gnttabdev); diff --git a/hw/xen_backend.h b/hw/xen_backend.h index 28e77ac..a68067d 100644 --- a/hw/xen_backend.h +++ b/hw/xen_backend.h @@ -44,7 +44,7 @@ struct XenDevice { int remote_port; int local_port; - int evtchndev; + xc_evtchn *evtchndev; int gnttabdev; struct XenDevOps *ops; diff --git a/i386-dm/helper2.c b/i386-dm/helper2.c index ce73421..4993f1e 100644 --- a/i386-dm/helper2.c +++ b/i386-dm/helper2.c @@ -104,7 +104,7 @@ buffered_iopage_t *buffered_io_page = NULL; QEMUTimer *buffered_io_timer; /* the evtchn fd for polling */ -int xce_handle = -1; +xc_interface *xce_handle = NULL; /* which vcpu we are serving */ int send_vcpu = 0; @@ -138,8 +138,8 @@ CPUX86State *cpu_x86_init(const char *cpu_model) cpu_single_env = env; - xce_handle = xc_evtchn_open(); - if (xce_handle == -1) { + xce_handle = xc_evtchn_open(NULL, 0); + if (xce_handle == NULL) { perror("open"); return NULL; } @@ -553,7 +553,7 @@ int xen_pause_requested; int main_loop(void) { CPUState *env = cpu_single_env; - int evtchn_fd = xce_handle == -1 ? -1 : xc_evtchn_fd(xce_handle); + int evtchn_fd = xce_handle == NULL ? -1 : xc_evtchn_fd(xce_handle); char *qemu_file; fd_set fds; -- 1.5.6.5 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-03 09:57 UTC
[Xen-devel] [PATCH] qemu-xen: update for libxc gnttab interface change.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com> --- hw/xen_backend.c | 10 +++++----- hw/xen_backend.h | 2 +- hw/xen_console.c | 4 ++-- hw/xen_disk.c | 16 ++++++++-------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/hw/xen_backend.c b/hw/xen_backend.c index 577f68e..d9be513 100644 --- a/hw/xen_backend.c +++ b/hw/xen_backend.c @@ -217,15 +217,15 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, fcntl(xc_evtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC); if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) { - xendev->gnttabdev = xc_gnttab_open(xc_handle); - if (xendev->gnttabdev < 0) { + xendev->gnttabdev = xc_gnttab_open(NULL, 0); + if (xendev->gnttabdev == NULL) { xen_be_printf(NULL, 0, "can''t open gnttab device\n"); xc_evtchn_close(xendev->evtchndev); qemu_free(xendev); return NULL; } } else { - xendev->gnttabdev = -1; + xendev->gnttabdev = NULL; } TAILQ_INSERT_TAIL(&xendevs, xendev, next); @@ -269,8 +269,8 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev) if (xendev->evtchndev != NULL) xc_evtchn_close(xendev->evtchndev); - if (xendev->gnttabdev >= 0) - xc_gnttab_close(xc_handle, xendev->gnttabdev); + if (xendev->gnttabdev != NULL) + xc_gnttab_close(xendev->gnttabdev); TAILQ_REMOVE(&xendevs, xendev, next); qemu_free(xendev); diff --git a/hw/xen_backend.h b/hw/xen_backend.h index a68067d..e421391 100644 --- a/hw/xen_backend.h +++ b/hw/xen_backend.h @@ -45,7 +45,7 @@ struct XenDevice { int local_port; xc_evtchn *evtchndev; - int gnttabdev; + xc_gnttab *gnttabdev; struct XenDevOps *ops; TAILQ_ENTRY(XenDevice) next; diff --git a/hw/xen_console.c b/hw/xen_console.c index 54bfc6f..d7099c4 100644 --- a/hw/xen_console.c +++ b/hw/xen_console.c @@ -230,7 +230,7 @@ static int con_initialise(struct XenDevice *xendev) PROT_READ|PROT_WRITE, con->ring_ref); else - con->sring = xc_gnttab_map_grant_ref(xen_xc, xendev->gnttabdev, con->xendev.dom, + con->sring = xc_gnttab_map_grant_ref(xendev->gnttabdev, con->xendev.dom, con->ring_ref, PROT_READ|PROT_WRITE); if (!con->sring) @@ -261,7 +261,7 @@ static void con_disconnect(struct XenDevice *xendev) if (!xendev->gnttabdev) munmap(con->sring, XC_PAGE_SIZE); else - xc_gnttab_munmap(xen_xc, xendev->gnttabdev, con->sring, 1); + xc_gnttab_munmap(xendev->gnttabdev, con->sring, 1); con->sring = NULL; } } diff --git a/hw/xen_disk.c b/hw/xen_disk.c index 38b5fbf..b3870fb 100644 --- a/hw/xen_disk.c +++ b/hw/xen_disk.c @@ -236,7 +236,7 @@ err: static void ioreq_unmap(struct ioreq *ioreq) { - int gnt = ioreq->blkdev->xendev.gnttabdev; + xc_gnttab *gnt = ioreq->blkdev->xendev.gnttabdev; int i; if (ioreq->v.niov == 0) @@ -244,7 +244,7 @@ static void ioreq_unmap(struct ioreq *ioreq) if (batch_maps) { if (!ioreq->pages) return; - if (xc_gnttab_munmap(xen_xc, gnt, ioreq->pages, ioreq->v.niov) != 0) + if (xc_gnttab_munmap(gnt, ioreq->pages, ioreq->v.niov) != 0) xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n", strerror(errno)); ioreq->blkdev->cnt_map -= ioreq->v.niov; @@ -253,7 +253,7 @@ static void ioreq_unmap(struct ioreq *ioreq) for (i = 0; i < ioreq->v.niov; i++) { if (!ioreq->page[i]) continue; - if (xc_gnttab_munmap(xen_xc, gnt, ioreq->page[i], 1) != 0) + if (xc_gnttab_munmap(gnt, ioreq->page[i], 1) != 0) xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n", strerror(errno)); ioreq->blkdev->cnt_map--; @@ -264,14 +264,14 @@ static void ioreq_unmap(struct ioreq *ioreq) static int ioreq_map(struct ioreq *ioreq) { - int gnt = ioreq->blkdev->xendev.gnttabdev; + xc_gnttab *gnt = ioreq->blkdev->xendev.gnttabdev; int i; if (ioreq->v.niov == 0) return 0; if (batch_maps) { ioreq->pages = xc_gnttab_map_grant_refs - (xen_xc, gnt, ioreq->v.niov, ioreq->domids, ioreq->refs, ioreq->prot); + (gnt, ioreq->v.niov, ioreq->domids, ioreq->refs, ioreq->prot); if (ioreq->pages == NULL) { xen_be_printf(&ioreq->blkdev->xendev, 0, "can''t map %d grant refs (%s, %d maps)\n", @@ -285,7 +285,7 @@ static int ioreq_map(struct ioreq *ioreq) } else { for (i = 0; i < ioreq->v.niov; i++) { ioreq->page[i] = xc_gnttab_map_grant_ref - (xen_xc, gnt, ioreq->domids[i], ioreq->refs[i], ioreq->prot); + (gnt, ioreq->domids[i], ioreq->refs[i], ioreq->prot); if (ioreq->page[i] == NULL) { xen_be_printf(&ioreq->blkdev->xendev, 0, "can''t map grant ref %d (%s, %d maps)\n", @@ -684,7 +684,7 @@ static int blk_connect(struct XenDevice *xendev) blkdev->protocol = BLKIF_PROTOCOL_X86_64; } - blkdev->sring = xc_gnttab_map_grant_ref(xen_xc, blkdev->xendev.gnttabdev, + blkdev->sring = xc_gnttab_map_grant_ref(blkdev->xendev.gnttabdev, blkdev->xendev.dom, blkdev->ring_ref, PROT_READ | PROT_WRITE); @@ -737,7 +737,7 @@ static void blk_disconnect(struct XenDevice *xendev) xen_be_unbind_evtchn(&blkdev->xendev); if (blkdev->sring) { - xc_gnttab_munmap(xen_xc, blkdev->xendev.gnttabdev, blkdev->sring, 1); + xc_gnttab_munmap(blkdev->xendev.gnttabdev, blkdev->sring, 1); blkdev->cnt_map--; blkdev->sring = NULL; } -- 1.5.6.5 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Christoph Egger
2010-Dec-22 14:34 UTC
Re: [Xen-devel] [PATCH 01 of 25] libxc: some xc_gnttab_* functions are not Linux specific
Successfully tested with NetBSD. Acked-by: Christoph Egger <Christoph.Egger@amd.com> On Friday 03 December 2010 10:57:05 Ian Campbell wrote:> # HG changeset patch > # User Ian Campbell <ian.campbell@citrix.com> > # Date 1291369006 0 > # Node ID 7c6e87f167d47b2c0b850806d0e9fa298018ebd4 > # Parent 9a40ab7a4347e4c49785d079a598a1bc22477739 > libxc: some xc_gnttab_* functions are not Linux specific > > They simply make hypercalls and perform other operations via the > abstract interface. Create xc_gnttab.c and move those functions there. > > Signed-off-by: Ian Campbell <ian.campbell@citrix.com> > > diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/Makefile > --- a/tools/libxc/Makefile Fri Dec 03 09:36:46 2010 +0000 > +++ b/tools/libxc/Makefile Fri Dec 03 09:36:46 2010 +0000 > @@ -11,6 +11,7 @@ CTRL_SRCS-y += xc_cpupool.c > CTRL_SRCS-y += xc_cpupool.c > CTRL_SRCS-y += xc_domain.c > CTRL_SRCS-y += xc_evtchn.c > +CTRL_SRCS-y += xc_gnttab.c > CTRL_SRCS-y += xc_misc.c > CTRL_SRCS-y += xc_acm.c > CTRL_SRCS-y += xc_flask.c > diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_gnttab.c > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/tools/libxc/xc_gnttab.c Fri Dec 03 09:36:46 2010 +0000 > @@ -0,0 +1,147 @@ > +/************************************************************************* >***** + * > + * Copyright (c) 2007-2008, D G Murray <Derek.Murray@cl.cam.ac.uk> > + * > + * 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" > + > +int xc_gnttab_op(xc_interface *xch, int cmd, void * op, int op_size, int > count) +{ > + int ret = 0; > + DECLARE_HYPERCALL; > + DECLARE_HYPERCALL_BOUNCE(op, count * op_size, > XC_HYPERCALL_BUFFER_BOUNCE_BOTH); + > + if ( xc_hypercall_bounce_pre(xch, op) ) > + { > + PERROR("Could not bounce buffer for grant table op hypercall"); > + goto out1; > + } > + > + hypercall.op = __HYPERVISOR_grant_table_op; > + hypercall.arg[0] = cmd; > + hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(op); > + hypercall.arg[2] = count; > + > + ret = do_xen_hypercall(xch, &hypercall); > + > + xc_hypercall_bounce_post(xch, op); > + > + out1: > + return ret; > +} > + > +int xc_gnttab_get_version(xc_interface *xch, int domid) > +{ > + struct gnttab_get_version query; > + int rc; > + > + query.dom = domid; > + rc = xc_gnttab_op(xch, GNTTABOP_get_version, &query, sizeof(query), > + 1); > + if ( rc < 0 ) > + return rc; > + else > + return query.version; > +} > + > +static void *_gnttab_map_table(xc_interface *xch, int domid, int *gnt_num) > +{ > + int rc, i; > + struct gnttab_query_size query; > + struct gnttab_setup_table setup; > + DECLARE_HYPERCALL_BUFFER(unsigned long, frame_list); > + xen_pfn_t *pfn_list = NULL; > + grant_entry_v1_t *gnt = NULL; > + > + if ( !gnt_num ) > + return NULL; > + > + query.dom = domid; > + rc = xc_gnttab_op(xch, GNTTABOP_query_size, &query, sizeof(query), 1); > + > + if ( rc || (query.status != GNTST_okay) ) > + { > + ERROR("Could not query dom''s grant size\n", domid); > + return NULL; > + } > + > + *gnt_num = query.nr_frames * (PAGE_SIZE / sizeof(grant_entry_v1_t) ); > + > + frame_list = xc_hypercall_buffer_alloc(xch, frame_list, > query.nr_frames * sizeof(unsigned long)); + if ( !frame_list ) > + { > + ERROR("Could not allocate frame_list in xc_gnttab_map_table\n"); > + return NULL; > + } > + > + pfn_list = malloc(query.nr_frames * sizeof(xen_pfn_t)); > + if ( !pfn_list ) > + { > + ERROR("Could not allocate pfn_list in xc_gnttab_map_table\n"); > + goto err; > + } > + > + setup.dom = domid; > + setup.nr_frames = query.nr_frames; > + set_xen_guest_handle(setup.frame_list, frame_list); > + > + /* XXX Any race with other setup_table hypercall? */ > + rc = xc_gnttab_op(xch, GNTTABOP_setup_table, &setup, sizeof(setup), > + 1); > + > + if ( rc || (setup.status != GNTST_okay) ) > + { > + ERROR("Could not get grant table frame list\n"); > + goto err; > + } > + > + for ( i = 0; i < setup.nr_frames; i++ ) > + pfn_list[i] = frame_list[i]; > + > + gnt = xc_map_foreign_pages(xch, domid, PROT_READ, pfn_list, > + setup.nr_frames); > + if ( !gnt ) > + { > + ERROR("Could not map grant table\n"); > + goto err; > + } > + > +err: > + if ( frame_list ) > + xc_hypercall_buffer_free(xch, frame_list); > + if ( pfn_list ) > + free(pfn_list); > + > + return gnt; > +} > + > +grant_entry_v1_t *xc_gnttab_map_table_v1(xc_interface *xch, int domid, > + int *gnt_num) > +{ > + if (xc_gnttab_get_version(xch, domid) == 2) > + return NULL; > + return _gnttab_map_table(xch, domid, gnt_num); > +} > + > +grant_entry_v2_t *xc_gnttab_map_table_v2(xc_interface *xch, int domid, > + int *gnt_num) > +{ > + if (xc_gnttab_get_version(xch, domid) != 2) > + return NULL; > + return _gnttab_map_table(xch, domid, gnt_num); > +} > + > diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_linux.c > --- a/tools/libxc/xc_linux.c Fri Dec 03 09:36:46 2010 +0000 > +++ b/tools/libxc/xc_linux.c Fri Dec 03 09:36:46 2010 +0000 > @@ -608,132 +608,6 @@ int xc_gnttab_set_max_grants(xc_interfac > return 0; > } > > -int xc_gnttab_op(xc_interface *xch, int cmd, void * op, int op_size, int > count) -{ > - int ret = 0; > - DECLARE_HYPERCALL; > - DECLARE_HYPERCALL_BOUNCE(op, count * op_size, > XC_HYPERCALL_BUFFER_BOUNCE_BOTH); - > - if ( xc_hypercall_bounce_pre(xch, op) ) > - { > - PERROR("Could not bounce buffer for grant table op hypercall"); > - goto out1; > - } > - > - hypercall.op = __HYPERVISOR_grant_table_op; > - hypercall.arg[0] = cmd; > - hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(op); > - hypercall.arg[2] = count; > - > - ret = do_xen_hypercall(xch, &hypercall); > - > - xc_hypercall_bounce_post(xch, op); > - > - out1: > - return ret; > -} > - > -int xc_gnttab_get_version(xc_interface *xch, int domid) > -{ > - struct gnttab_get_version query; > - int rc; > - > - query.dom = domid; > - rc = xc_gnttab_op(xch, GNTTABOP_get_version, &query, sizeof(query), > - 1); > - if ( rc < 0 ) > - return rc; > - else > - return query.version; > -} > - > -static void *_gnttab_map_table(xc_interface *xch, int domid, int *gnt_num) > -{ > - int rc, i; > - struct gnttab_query_size query; > - struct gnttab_setup_table setup; > - DECLARE_HYPERCALL_BUFFER(unsigned long, frame_list); > - xen_pfn_t *pfn_list = NULL; > - grant_entry_v1_t *gnt = NULL; > - > - if ( !gnt_num ) > - return NULL; > - > - query.dom = domid; > - rc = xc_gnttab_op(xch, GNTTABOP_query_size, &query, sizeof(query), 1); > - > - if ( rc || (query.status != GNTST_okay) ) > - { > - ERROR("Could not query dom''s grant size\n", domid); > - return NULL; > - } > - > - *gnt_num = query.nr_frames * (PAGE_SIZE / sizeof(grant_entry_v1_t) ); > - > - frame_list = xc_hypercall_buffer_alloc(xch, frame_list, > query.nr_frames * sizeof(unsigned long)); - if ( !frame_list ) > - { > - ERROR("Could not allocate frame_list in xc_gnttab_map_table\n"); > - return NULL; > - } > - > - pfn_list = malloc(query.nr_frames * sizeof(xen_pfn_t)); > - if ( !pfn_list ) > - { > - ERROR("Could not allocate pfn_list in xc_gnttab_map_table\n"); > - goto err; > - } > - > - setup.dom = domid; > - setup.nr_frames = query.nr_frames; > - set_xen_guest_handle(setup.frame_list, frame_list); > - > - /* XXX Any race with other setup_table hypercall? */ > - rc = xc_gnttab_op(xch, GNTTABOP_setup_table, &setup, sizeof(setup), > - 1); > - > - if ( rc || (setup.status != GNTST_okay) ) > - { > - ERROR("Could not get grant table frame list\n"); > - goto err; > - } > - > - for ( i = 0; i < setup.nr_frames; i++ ) > - pfn_list[i] = frame_list[i]; > - > - gnt = xc_map_foreign_pages(xch, domid, PROT_READ, pfn_list, > - setup.nr_frames); > - if ( !gnt ) > - { > - ERROR("Could not map grant table\n"); > - goto err; > - } > - > -err: > - if ( frame_list ) > - xc_hypercall_buffer_free(xch, frame_list); > - if ( pfn_list ) > - free(pfn_list); > - > - return gnt; > -} > - > -grant_entry_v1_t *xc_gnttab_map_table_v1(xc_interface *xch, int domid, > - int *gnt_num) > -{ > - if (xc_gnttab_get_version(xch, domid) == 2) > - return NULL; > - return _gnttab_map_table(xch, domid, gnt_num); > -} > - > -grant_entry_v2_t *xc_gnttab_map_table_v2(xc_interface *xch, int domid, > - int *gnt_num) > -{ > - if (xc_gnttab_get_version(xch, domid) != 2) > - return NULL; > - return _gnttab_map_table(xch, domid, gnt_num); > -} > - > /* > * Local variables: > * mode: C > diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_minios.c > --- a/tools/libxc/xc_minios.c Fri Dec 03 09:36:46 2010 +0000 > +++ b/tools/libxc/xc_minios.c Fri Dec 03 09:36:46 2010 +0000 > @@ -457,18 +457,6 @@ int xc_gnttab_set_max_grants(xc_interfac > return ret; > } > > -grant_entry_v1_t *xc_gnttab_map_table_v1( > - xc_interface *xch, int domid, int *gnt_num) > -{ > - return NULL; > -} > - > -grant_entry_v2_t *xc_gnttab_map_table_v2( > - xc_interface *xch, int domid, int *gnt_num) > -{ > - return NULL; > -} > - > /* > * Local variables: > * mode: C > diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_netbsd.c > --- a/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:46 2010 +0000 > +++ b/tools/libxc/xc_netbsd.c Fri Dec 03 09:36:46 2010 +0000 > @@ -287,18 +287,6 @@ void discard_file_cache(xc_interface *xc > } > } > > -grant_entry_v1_t *xc_gnttab_map_table_v1( > - xc_interface *xch, int domid, int *gnt_num) > -{ > - return NULL; > -} > - > -grant_entry_v2_t *xc_gnttab_map_table_v2( > - xc_interface *xch, int domid, int *gnt_num) > -{ > - return NULL; > -} > - > /* > * Local variables: > * mode: C > diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_solaris.c > --- a/tools/libxc/xc_solaris.c Fri Dec 03 09:36:46 2010 +0000 > +++ b/tools/libxc/xc_solaris.c Fri Dec 03 09:36:46 2010 +0000 > @@ -261,15 +261,3 @@ void discard_file_cache(xc_interface *xc > { > // TODO: Implement for Solaris! > } > - > -grant_entry_v1_t *xc_gnttab_map_table_v1( > - xc_interface *xch, int domid, int *gnt_num) > -{ > - return NULL; > -} > - > -grant_entry_v2_t *xc_gnttab_map_table_v2( > - xc_interface *xch, int domid, int *gnt_num) > -{ > - return NULL; > -} > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel-- ---to satisfy European Law for business letters: Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach b. Muenchen Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2010-Dec-23 15:51 UTC
Re: [Xen-devel] [PATCH 01 of 25] libxc: some xc_gnttab_* functions are not Linux specific
Thanks, I have applied the whole 27-patch series including the two qemu patches with appropriate QEMU_TAG changes. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel