libxc: Fix xc_tmem_control to return proper error.
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Thu, 19 Mar 2015 00:24:13 +0000 (20:24 -0400)
committerIan Campbell <ian.campbell@citrix.com>
Fri, 20 Mar 2015 16:06:42 +0000 (16:06 +0000)
The API returns now negative values on error and stashes
the error in errno. Fix the user of this API.

The 'xc_hypercall_bounce_pre' can fail - and if so it will
stash its errno values - no need to over-write it.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxc/xc_tmem.c
tools/xenstat/libxenstat/src/xenstat.c

index 3261e10d8efa24df914b6a0c9b1ce00ef7fe313d..02797bffb0069fdb50f3b8f212a2b09d44e62a7a 100644 (file)
@@ -73,11 +73,14 @@ int xc_tmem_control(xc_interface *xch,
     if ( subop == TMEMC_LIST && arg1 != 0 )
     {
         if ( buf == NULL )
-            return -EINVAL;
+        {
+            errno = EINVAL;
+            return -1;
+        }
         if ( xc_hypercall_bounce_pre(xch, buf) )
         {
             PERROR("Could not bounce buffer for tmem control hypercall");
-            return -ENOMEM;
+            return -1;
         }
     }
 
@@ -118,11 +121,14 @@ int xc_tmem_control_oid(xc_interface *xch,
     if ( subop == TMEMC_LIST && arg1 != 0 )
     {
         if ( buf == NULL )
-            return -EINVAL;
+        {
+            errno = EINVAL;
+            return -1;
+        }
         if ( xc_hypercall_bounce_pre(xch, buf) )
         {
             PERROR("Could not bounce buffer for tmem control (OID) hypercall");
-            return -ENOMEM;
+            return -1;
         }
     }
 
index 8072a90047aced2c1a0e4fce7de2c83a23321e05..c1f6511622a47a1df706c22a1c8c642bea358b99 100644 (file)
@@ -166,6 +166,7 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags)
        xc_domaininfo_t domaininfo[DOMAIN_CHUNK_SIZE];
        int new_domains;
        unsigned int i;
+       int rc;
 
        /* Create the node */
        node = (xenstat_node *) calloc(1, sizeof(xenstat_node));
@@ -189,9 +190,9 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags)
        node->free_mem = ((unsigned long long)physinfo.free_pages)
            * handle->page_size;
 
-       node->freeable_mb = (long)xc_tmem_control(handle->xc_handle, -1,
-                               TMEMC_QUERY_FREEABLE_MB, -1, 0, 0, 0, NULL);
-
+       rc = xc_tmem_control(handle->xc_handle, -1,
+                         TMEMC_QUERY_FREEABLE_MB, -1, 0, 0, 0, NULL);
+       node->freeable_mb = (rc < 0) ? 0 : rc;
        /* malloc(0) is not portable, so allocate a single domain.  This will
         * be resized below. */
        node->domains = malloc(sizeof(xenstat_domain));