[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] libxc: make xc_memory_op library private
# HG changeset patch # User Ian Campbell <ian.campbell@xxxxxxxxxx> # Date 1287419759 -3600 # Node ID ba91258502025fbfdfd3b2e1deaf0b013474be47 # Parent 65da9d68bf8b95650f6e3cdb8acbcf33f4ee3e22 libxc: make xc_memory_op library private Now that all XENMEM_* callers go via an op specific function make xc_memory_op private to libxc (and rename to do_memory_op for consistency with other private functions). Also change the interface to take a size parameter so that do_memory_op knows how much memory to lock for the top-level argument, removing some of the introspection. [ Compatibility note: this breaks qemu-xen before 706bc8c588cb ] Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> --- tools/libxc/xc_domain.c | 19 ++++++++--------- tools/libxc/xc_private.c | 51 +++++++++++------------------------------------ tools/libxc/xc_private.h | 2 + tools/libxc/xenctrl.h | 3 -- 4 files changed, 23 insertions(+), 52 deletions(-) diff -r 65da9d68bf8b -r ba9125850202 tools/libxc/xc_domain.c --- a/tools/libxc/xc_domain.c Mon Oct 18 17:35:35 2010 +0100 +++ b/tools/libxc/xc_domain.c Mon Oct 18 17:35:59 2010 +0100 @@ -488,17 +488,16 @@ int xc_domain_set_memmap_limit(xc_interf set_xen_guest_handle(fmap.map.buffer, &e820); - if ( lock_pages(xch, &fmap, sizeof(fmap)) || lock_pages(xch, &e820, sizeof(e820)) ) + if ( lock_pages(xch, &e820, sizeof(e820)) ) { PERROR("Could not lock memory for Xen hypercall"); rc = -1; goto out; } - rc = xc_memory_op(xch, XENMEM_set_memory_map, &fmap); + rc = do_memory_op(xch, XENMEM_set_memory_map, &fmap, sizeof(fmap)); out: - unlock_pages(xch, &fmap, sizeof(fmap)); unlock_pages(xch, &e820, sizeof(e820)); return rc; } @@ -581,7 +580,7 @@ int xc_domain_get_tsc_info(xc_interface int xc_domain_maximum_gpfn(xc_interface *xch, domid_t domid) { - return xc_memory_op(xch, XENMEM_maximum_gpfn, &domid); + return do_memory_op(xch, XENMEM_maximum_gpfn, &domid, sizeof(domid)); } int xc_domain_increase_reservation(xc_interface *xch, @@ -602,7 +601,7 @@ int xc_domain_increase_reservation(xc_in /* may be NULL */ set_xen_guest_handle(reservation.extent_start, extent_start); - err = xc_memory_op(xch, XENMEM_increase_reservation, &reservation); + err = do_memory_op(xch, XENMEM_increase_reservation, &reservation, sizeof(reservation)); return err; } @@ -657,7 +656,7 @@ int xc_domain_decrease_reservation(xc_in return -1; } - err = xc_memory_op(xch, XENMEM_decrease_reservation, &reservation); + err = do_memory_op(xch, XENMEM_decrease_reservation, &reservation, sizeof(reservation)); return err; } @@ -699,7 +698,7 @@ int xc_domain_add_to_physmap(xc_interfac .idx = idx, .gpfn = gpfn, }; - return xc_memory_op(xch, XENMEM_add_to_physmap, &xatp); + return do_memory_op(xch, XENMEM_add_to_physmap, &xatp, sizeof(xatp)); } int xc_domain_populate_physmap(xc_interface *xch, @@ -718,7 +717,7 @@ int xc_domain_populate_physmap(xc_interf }; set_xen_guest_handle(reservation.extent_start, extent_start); - err = xc_memory_op(xch, XENMEM_populate_physmap, &reservation); + err = do_memory_op(xch, XENMEM_populate_physmap, &reservation, sizeof(reservation)); return err; } @@ -774,7 +773,7 @@ int xc_domain_memory_exchange_pages(xc_i set_xen_guest_handle(exchange.in.extent_start, in_extents); set_xen_guest_handle(exchange.out.extent_start, out_extents); - rc = xc_memory_op(xch, XENMEM_exchange, &exchange); + rc = do_memory_op(xch, XENMEM_exchange, &exchange, sizeof(exchange)); return rc; } @@ -794,7 +793,7 @@ static int xc_domain_pod_target(xc_inter .target_pages = target_pages }; - err = xc_memory_op(xch, op, &pod_target); + err = do_memory_op(xch, op, &pod_target, sizeof(pod_target)); if ( err < 0 ) { diff -r 65da9d68bf8b -r ba9125850202 tools/libxc/xc_private.c --- a/tools/libxc/xc_private.c Mon Oct 18 17:35:35 2010 +0100 +++ b/tools/libxc/xc_private.c Mon Oct 18 17:35:59 2010 +0100 @@ -421,9 +421,7 @@ int xc_flush_mmu_updates(xc_interface *x return flush_mmu_updates(xch, mmu); } -int xc_memory_op(xc_interface *xch, - int cmd, - void *arg) +int do_memory_op(xc_interface *xch, int cmd, void *arg, size_t len) { DECLARE_HYPERCALL; struct xen_memory_reservation *reservation = arg; @@ -435,16 +433,17 @@ int xc_memory_op(xc_interface *xch, hypercall.arg[0] = (unsigned long)cmd; hypercall.arg[1] = (unsigned long)arg; + if ( len && lock_pages(xch, arg, len) != 0 ) + { + PERROR("Could not lock memory for XENMEM hypercall"); + goto out1; + } + switch ( cmd ) { case XENMEM_increase_reservation: case XENMEM_decrease_reservation: case XENMEM_populate_physmap: - if ( lock_pages(xch, reservation, sizeof(*reservation)) != 0 ) - { - PERROR("Could not lock"); - goto out1; - } get_xen_guest_handle(extent_start, reservation->extent_start); if ( (extent_start != NULL) && (lock_pages(xch, extent_start, @@ -456,11 +455,6 @@ int xc_memory_op(xc_interface *xch, } break; case XENMEM_machphys_mfn_list: - if ( lock_pages(xch, xmml, sizeof(*xmml)) != 0 ) - { - PERROR("Could not lock"); - goto out1; - } get_xen_guest_handle(extent_start, xmml->extent_start); if ( lock_pages(xch, extent_start, xmml->max_extents * sizeof(xen_pfn_t)) != 0 ) @@ -471,61 +465,40 @@ int xc_memory_op(xc_interface *xch, } break; case XENMEM_add_to_physmap: - if ( lock_pages(xch, arg, sizeof(struct xen_add_to_physmap)) ) - { - PERROR("Could not lock"); - goto out1; - } - break; case XENMEM_current_reservation: case XENMEM_maximum_reservation: case XENMEM_maximum_gpfn: - if ( lock_pages(xch, arg, sizeof(domid_t)) ) - { - PERROR("Could not lock"); - goto out1; - } - break; case XENMEM_set_pod_target: case XENMEM_get_pod_target: - if ( lock_pages(xch, arg, sizeof(struct xen_pod_target)) ) - { - PERROR("Could not lock"); - goto out1; - } break; } ret = do_xen_hypercall(xch, &hypercall); + + if ( len ) + unlock_pages(xch, arg, len); switch ( cmd ) { case XENMEM_increase_reservation: case XENMEM_decrease_reservation: case XENMEM_populate_physmap: - unlock_pages(xch, reservation, sizeof(*reservation)); get_xen_guest_handle(extent_start, reservation->extent_start); if ( extent_start != NULL ) unlock_pages(xch, extent_start, reservation->nr_extents * sizeof(xen_pfn_t)); break; case XENMEM_machphys_mfn_list: - unlock_pages(xch, xmml, sizeof(*xmml)); get_xen_guest_handle(extent_start, xmml->extent_start); unlock_pages(xch, extent_start, xmml->max_extents * sizeof(xen_pfn_t)); break; case XENMEM_add_to_physmap: - unlock_pages(xch, arg, sizeof(struct xen_add_to_physmap)); - break; case XENMEM_current_reservation: case XENMEM_maximum_reservation: case XENMEM_maximum_gpfn: - unlock_pages(xch, arg, sizeof(domid_t)); - break; case XENMEM_set_pod_target: case XENMEM_get_pod_target: - unlock_pages(xch, arg, sizeof(struct xen_pod_target)); break; } @@ -535,7 +508,7 @@ int xc_memory_op(xc_interface *xch, long xc_maximum_ram_page(xc_interface *xch) { - return xc_memory_op(xch, XENMEM_maximum_ram_page, NULL); + return do_memory_op(xch, XENMEM_maximum_ram_page, NULL, 0); } long long xc_domain_get_cpu_usage( xc_interface *xch, domid_t domid, int vcpu ) @@ -562,7 +535,7 @@ int xc_machphys_mfn_list(xc_interface *x .max_extents = max_extents, }; set_xen_guest_handle(xmml.extent_start, extent_start); - rc = xc_memory_op(xch, XENMEM_machphys_mfn_list, &xmml); + rc = do_memory_op(xch, XENMEM_machphys_mfn_list, &xmml, sizeof(xmml)); if (rc || xmml.nr_extents != max_extents) return -1; return 0; diff -r 65da9d68bf8b -r ba9125850202 tools/libxc/xc_private.h --- a/tools/libxc/xc_private.h Mon Oct 18 17:35:35 2010 +0100 +++ b/tools/libxc/xc_private.h Mon Oct 18 17:35:59 2010 +0100 @@ -206,6 +206,8 @@ static inline int do_sysctl(xc_interface return ret; } +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 */ diff -r 65da9d68bf8b -r ba9125850202 tools/libxc/xenctrl.h --- a/tools/libxc/xenctrl.h Mon Oct 18 17:35:35 2010 +0100 +++ b/tools/libxc/xenctrl.h Mon Oct 18 17:35:59 2010 +0100 @@ -980,9 +980,6 @@ int xc_mmuext_op(xc_interface *xch, stru /* System wide memory properties */ long xc_maximum_ram_page(xc_interface *xch); - -int xc_memory_op(xc_interface *xch, int cmd, void *arg); - /* Get current total pages allocated to a domain. */ long xc_get_tot_pages(xc_interface *xch, uint32_t domid); _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |