From: Konrad Rzeszutek Wilk Subject: [PATCH RFC 12/14] libxl: Check xc_sharing_* for proper return values. Date: Fri, 13 Mar 2015 15:31:21 -0400 Message-ID: <1426275083-8454-13-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.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YWVJR-0006mj-5G for xen-devel@lists.xenproject.org; Fri, 13 Mar 2015 19:32:01 +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 If there is a negative return value - check for that and also use errno for the proper error value. Signed-off-by: Konrad Rzeszutek Wilk --- tools/libxl/libxl.c | 4 ++-- tools/tests/mem-sharing/memshrtool.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 94b4d59..99a99e9 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -5024,7 +5024,7 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo) physinfo->scrub_pages = xcphysinfo.scrub_pages; physinfo->outstanding_pages = xcphysinfo.outstanding_pages; l = xc_sharing_freed_pages(ctx->xch); - if (l == -ENOSYS) { + if (l < 0 && errno == ENOSYS) { l = 0; } else if (l < 0) { LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, l, @@ -5033,7 +5033,7 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo) } physinfo->sharing_freed_pages = l; l = xc_sharing_used_frames(ctx->xch); - if (l == -ENOSYS) { + if (l < 0 && errno == ENOSYS) { l = 0; } else if (l < 0) { LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, l, diff --git a/tools/tests/mem-sharing/memshrtool.c b/tools/tests/mem-sharing/memshrtool.c index db44294..d1dd8a2 100644 --- a/tools/tests/mem-sharing/memshrtool.c +++ b/tools/tests/mem-sharing/memshrtool.c @@ -55,11 +55,19 @@ int main(int argc, const char** argv) if( !strcasecmp(cmd, "info") ) { + long rc; if( argc != 2 ) return usage(argv[0]); - printf("used = %ld\n", xc_sharing_used_frames(xch)); - printf("freed = %ld\n", xc_sharing_freed_pages(xch)); + rc = xc_sharing_freed_pages(xch); + if ( rc < 0 ) + return errno; + + printf("used = %ld\n", rc); + rc = xc_sharing_used_frames(xch); + if ( rc < 0 ) + return errno; + printf("freed = %ld\n", rc); } else if( !strcasecmp(cmd, "enable") ) { -- 2.1.0