From: Konrad Rzeszutek Wilk Subject: [PATCH RFC 05/14] libxl: Return negative value and stash error in errno for xc_offline_page API Date: Fri, 13 Mar 2015 15:31:14 -0400 Message-ID: <1426275083-8454-6-git-send-email-konrad.wilk@oracle.com> References: <1426275083-8454-1-git-send-email-konrad.wilk@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YWVJN-0006h7-PP for xen-devel@lists.xenproject.org; Fri, 13 Mar 2015 19:31:58 +0000 In-Reply-To: <1426275083-8454-1-git-send-email-konrad.wilk@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org, ian.jackson@eu.citrix.com, stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com, wei.liu2@citrix.com Cc: Konrad Rzeszutek Wilk List-Id: xen-devel@lists.xenproject.org And also fix the user of it to print the proper error value. Signed-off-by: Konrad Rzeszutek Wilk --- tools/libxc/xc_offline_page.c | 42 ++++++++++++++++++++++++++++-------------- tools/libxc/xc_private.c | 3 ++- tools/misc/xen-hptool.c | 6 +++--- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/tools/libxc/xc_offline_page.c b/tools/libxc/xc_offline_page.c index 3147203..e255dd9 100644 --- a/tools/libxc/xc_offline_page.c +++ b/tools/libxc/xc_offline_page.c @@ -58,12 +58,15 @@ int xc_mark_page_online(xc_interface *xch, unsigned long start, int ret = -1; if ( !status || (end < start) ) - return -EINVAL; - + { + errno = EINVAL; + return -1; + } if ( xc_hypercall_bounce_pre(xch, status) ) { ERROR("Could not bounce memory for xc_mark_page_online\n"); - return -EINVAL; + errno = EINVAL; + return -1; } sysctl.cmd = XEN_SYSCTL_page_offline_op; @@ -86,12 +89,15 @@ int xc_mark_page_offline(xc_interface *xch, unsigned long start, int ret = -1; if ( !status || (end < start) ) - return -EINVAL; - + { + errno = EINVAL; + return -1; + } if ( xc_hypercall_bounce_pre(xch, status) ) { ERROR("Could not bounce memory for xc_mark_page_offline"); - return -EINVAL; + errno = EINVAL; + return -1; } sysctl.cmd = XEN_SYSCTL_page_offline_op; @@ -114,12 +120,15 @@ int xc_query_page_offline_status(xc_interface *xch, unsigned long start, int ret = -1; if ( !status || (end < start) ) - return -EINVAL; - + { + errno = EINVAL; + return -1; + } if ( xc_hypercall_bounce_pre(xch, status) ) { ERROR("Could not bounce memory for xc_query_page_offline_status\n"); - return -EINVAL; + errno = EINVAL; + return -1; } sysctl.cmd = XEN_SYSCTL_page_offline_op; @@ -411,19 +420,22 @@ int xc_exchange_page(xc_interface *xch, int domid, xen_pfn_t mfn) if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 ) { ERROR("Could not get domain info"); - return -EFAULT; + errno = EFAULT; + return -1; } if (!info.shutdown || info.shutdown_reason != SHUTDOWN_suspend) { ERROR("Can't exchange page unless domain is suspended\n"); - return -EINVAL; + errno = EINVAL; + return -1; } if (!is_page_exchangable(xch, domid, mfn, &info)) { ERROR("Could not exchange page\n"); - return -EINVAL; + errno = EINVAL; + return -1; } /* Map M2P and obtain gpfn */ @@ -431,7 +443,8 @@ int xc_exchange_page(xc_interface *xch, int domid, xen_pfn_t mfn) if ( !(m2p_table = xc_map_m2p(xch, max_mfn, PROT_READ, NULL)) ) { PERROR("Failed to map live M2P table"); - return -EFAULT; + errno = EFAULT; + return -1; } gpfn = m2p_table[mfn]; @@ -440,7 +453,8 @@ int xc_exchange_page(xc_interface *xch, int domid, xen_pfn_t mfn) if ( xc_map_domain_meminfo(xch, domid, &minfo) ) { PERROR("Could not map domain's memory information\n"); - return -EFAULT; + errno = EFAULT; + return -1; } /* For translation macros */ diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c index df6cd9b..394338a 100644 --- a/tools/libxc/xc_private.c +++ b/tools/libxc/xc_private.c @@ -427,11 +427,12 @@ int xc_mmuext_op( { DECLARE_HYPERCALL; DECLARE_HYPERCALL_BOUNCE(op, nr_ops*sizeof(*op), XC_HYPERCALL_BUFFER_BOUNCE_BOTH); - long ret = -EINVAL; + long ret = -1; if ( xc_hypercall_bounce_pre(xch, op) ) { PERROR("Could not bounce memory for mmuext op hypercall"); + errno = ENOMEM; goto out1; } diff --git a/tools/misc/xen-hptool.c b/tools/misc/xen-hptool.c index 1134603..c7561a9 100644 --- a/tools/misc/xen-hptool.c +++ b/tools/misc/xen-hptool.c @@ -49,7 +49,7 @@ static int hp_mem_online_func(int argc, char *argv[]) ret = xc_mark_page_online(xch, mfn, mfn, &status); if (ret < 0) - fprintf(stderr, "Onlining page mfn %lx failed, error %x", mfn, ret); + fprintf(stderr, "Onlining page mfn %lx failed, error %x", mfn, errno); else if (status & (PG_ONLINE_FAILED |PG_ONLINE_BROKEN)) { fprintf(stderr, "Onlining page mfn %lx is broken, " "Memory online failed\n", mfn); @@ -80,7 +80,7 @@ static int hp_mem_query_func(int argc, char *argv[]) ret = xc_query_page_offline_status(xch, mfn, mfn, &status); if (ret < 0) - fprintf(stderr, "Querying page mfn %lx failed, error %x", mfn, ret); + fprintf(stderr, "Querying page mfn %lx failed, error %x", mfn, errno); else { printf("Memory Status %x: [", status); @@ -160,7 +160,7 @@ static int hp_mem_offline_func(int argc, char *argv[]) printf("Prepare to offline MEMORY mfn %lx\n", mfn); ret = xc_mark_page_offline(xch, mfn, mfn, &status); if (ret < 0) { - fprintf(stderr, "Offlining page mfn %lx failed, error %x\n", mfn, ret); + fprintf(stderr, "Offlining page mfn %lx failed, error %x\n", mfn, errno); if (status & (PG_OFFLINE_XENPAGE | PG_OFFLINE_FAILED)) fprintf(stderr, "XEN_PAGE is not permitted be offlined\n"); else if (status & (PG_OFFLINE_FAILED | PG_OFFLINE_NOT_CONV_RAM)) -- 2.1.0