From 79cda3bac992055caa1ebe331155f974fe59125b Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Mon, 1 Jun 2009 14:08:58 +0100 Subject: [PATCH] Export page offline hypercalls to user space tools. Signed-off-by: Jiang, Yunhong --- tools/libxc/Makefile | 1 + tools/libxc/xc_offline_page.c | 100 ++++++++++++++++++++++++++++++++++ tools/libxc/xenguest.h | 9 +++ 3 files changed, 110 insertions(+) create mode 100644 tools/libxc/xc_offline_page.c diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile index e984df9088..95e51ac58d 100644 --- a/tools/libxc/Makefile +++ b/tools/libxc/Makefile @@ -32,6 +32,7 @@ CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c GUEST_SRCS-y := GUEST_SRCS-y += xg_private.c xc_suspend.c GUEST_SRCS-$(CONFIG_MIGRATE) += xc_domain_restore.c xc_domain_save.c +GUEST_SRCS-y += xc_offline_page.c GUEST_SRCS-$(CONFIG_HVM) += xc_hvm_build.c vpath %.c ../../xen/common/libelf diff --git a/tools/libxc/xc_offline_page.c b/tools/libxc/xc_offline_page.c new file mode 100644 index 0000000000..5561f5c96f --- /dev/null +++ b/tools/libxc/xc_offline_page.c @@ -0,0 +1,100 @@ +/****************************************************************************** + * xc_offline_page.c + * + * Helper functions to offline/online one page + * + * Copyright (c) 2003, K A Fraser. + * Copyright (c) 2009, Intel Corporation. + */ + +#include +#include +#include +#include +#include + +#include "xc_private.h" +#include "xc_dom.h" +#include "xg_private.h" +#include "xg_save_restore.h" + +int xc_mark_page_online(int xc, unsigned long start, + unsigned long end, uint32_t *status) +{ + DECLARE_SYSCTL; + int ret = -1; + + if ( !status || (end < start) ) + return -EINVAL; + + if (lock_pages(status, sizeof(uint32_t)*(end - start + 1))) + { + ERROR("Could not lock memory for xc_mark_page_online\n"); + return -EINVAL; + } + + sysctl.cmd = XEN_SYSCTL_page_offline_op; + sysctl.u.page_offline.start = start; + sysctl.u.page_offline.cmd = sysctl_page_online; + sysctl.u.page_offline.end = end; + set_xen_guest_handle(sysctl.u.page_offline.status, status); + ret = xc_sysctl(xc, &sysctl); + + unlock_pages(status, sizeof(uint32_t)*(end - start + 1)); + + return ret; +} + +int xc_mark_page_offline(int xc, unsigned long start, + unsigned long end, uint32_t *status) +{ + DECLARE_SYSCTL; + int ret = -1; + + if ( !status || (end < start) ) + return -EINVAL; + + if (lock_pages(status, sizeof(uint32_t)*(end - start + 1))) + { + ERROR("Could not lock memory for xc_mark_page_offline"); + return -EINVAL; + } + + sysctl.cmd = XEN_SYSCTL_page_offline_op; + sysctl.u.page_offline.start = start; + sysctl.u.page_offline.cmd = sysctl_page_offline; + sysctl.u.page_offline.end = end; + set_xen_guest_handle(sysctl.u.page_offline.status, status); + ret = xc_sysctl(xc, &sysctl); + + unlock_pages(status, sizeof(uint32_t)*(end - start + 1)); + + return ret; +} + +int xc_query_page_offline_status(int xc, unsigned long start, + unsigned long end, uint32_t *status) +{ + DECLARE_SYSCTL; + int ret = -1; + + if ( !status || (end < start) ) + return -EINVAL; + + if (lock_pages(status, sizeof(uint32_t)*(end - start + 1))) + { + ERROR("Could not lock memory for xc_query_page_offline_status\n"); + return -EINVAL; + } + + sysctl.cmd = XEN_SYSCTL_page_offline_op; + sysctl.u.page_offline.start = start; + sysctl.u.page_offline.cmd = sysctl_query_page_offline; + sysctl.u.page_offline.end = end; + set_xen_guest_handle(sysctl.u.page_offline.status, status); + ret = xc_sysctl(xc, &sysctl); + + unlock_pages(status, sizeof(uint32_t)*(end - start + 1)); + + return ret; +} diff --git a/tools/libxc/xenguest.h b/tools/libxc/xenguest.h index e8ebeb1ca2..32de5bdd93 100644 --- a/tools/libxc/xenguest.h +++ b/tools/libxc/xenguest.h @@ -154,4 +154,13 @@ int xc_suspend_evtchn_init(int xc, int xce, int domid, int port); int xc_await_suspend(int xce, int suspend_evtchn); +int xc_mark_page_online(int xc, unsigned long start, + unsigned long end, uint32_t *status); + +int xc_mark_page_offline(int xc, unsigned long start, + unsigned long end, uint32_t *status); + +int xc_query_page_offline_status(int xc, unsigned long start, + unsigned long end, uint32_t *status); + #endif /* XENGUEST_H */ -- 2.39.5