WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] libxenlight: Clean up logging arrangement

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] libxenlight: Clean up logging arrangements
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Sun, 22 Nov 2009 23:35:34 -0800
Delivery-date: Sun, 22 Nov 2009 23:36:59 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1258959546 0
# Node ID b72f273507030e5c01cd4a5d0d5064011fe30527
# Parent  522ae754787d678ad64fcad7ee951bdce4fe28ce
libxenlight: Clean up logging arrangements

* Introduce new variants of the logging functions which include
  errno values (converted using strerror) in the messages passed to
  the
  application's logging callback.

* Use the new errno-including logging functions everywhere where
  appropriate.  In general, xc_... functions return errno values or 0;
  xs_... functions return 0 or -1 (or some such) setting errno.

* When libxl_xs_get_dompath fails, do not treat it as an allocation
  error.  It isn't: it usually means xenstored failed.

* Remove many spurious \n's from log messages.  (The applications log
  callback is expected to add a \n if it wants to do that, so libxl's
  logging functions should be passed strings without \n.)

Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
 tools/libxl/libxl.c          |   91 ++++++++++++++++++++++++-------------------
 tools/libxl/libxl_device.c   |   33 ++++++++++-----
 tools/libxl/libxl_dom.c      |   11 +++--
 tools/libxl/libxl_exec.c     |    2 
 tools/libxl/libxl_internal.c |   39 +++++++++++++++---
 tools/libxl/libxl_internal.h |   11 +++--
 tools/libxl/libxl_xshelp.c   |    5 ++
 7 files changed, 127 insertions(+), 65 deletions(-)

diff -r 522ae754787d -r b72f27350703 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Mon Nov 23 06:58:19 2009 +0000
+++ b/tools/libxl/libxl.c       Mon Nov 23 06:59:06 2009 +0000
@@ -106,14 +106,17 @@ int libxl_domain_make(struct libxl_ctx *
 
     ret = xc_domain_create(ctx->xch, info->ssidref, handle, flags, domid);
     if (ret < 0) {
-        XL_LOG(ctx, XL_LOG_ERROR, "domain creation fail: %d", ret);
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, ret, "domain creation fail");
         return ERROR_FAIL;
     }
 
     dom_path = libxl_xs_get_dompath(ctx, *domid);
+    if (!dom_path)
+        return ERROR_FAIL;
+
     vm_path = libxl_sprintf(ctx, "/vm/%s", uuid_string);
     vss_path = libxl_sprintf(ctx, "/vss/%s", uuid_string);
-    if (!dom_path || !vm_path || !vss_path) {
+    if (!vm_path || !vss_path) {
         XL_LOG(ctx, XL_LOG_ERROR, "cannot allocate create paths");
         return ERROR_FAIL;
     }
@@ -326,6 +329,9 @@ int libxl_domain_shutdown(struct libxl_c
         return ERROR_INVAL;
 
     dom_path = libxl_xs_get_dompath(ctx, domid);
+    if (!dom_path)
+        return ERROR_FAIL;
+
     shutdown_path = libxl_sprintf(ctx, "%s/control/shutdown", dom_path);
 
     xs_write(ctx->xsh, XBT_NULL, shutdown_path, req_table[req], 
strlen(req_table[req]));
@@ -347,20 +353,21 @@ static int libxl_destroy_device_model(st
 
     pid = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, 
"/local/domain/%d/image/device-model-pid", domid));
     if (!pid) {
-        XL_LOG(ctx, XL_LOG_ERROR, "Couldn't find device model's pid\n");
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Couldn't find device model's pid");
         return -1;
     }
     xs_rm(ctx->xsh, XBT_NULL, libxl_sprintf(ctx, 
"/local/domain/0/device-model/%d", domid));
 
     ret = kill(atoi(pid), SIGHUP);
     if (ret < 0 && errno == ESRCH) {
-        XL_LOG(ctx, XL_LOG_DEBUG, "Device Model already exited\n");
+        XL_LOG(ctx, XL_LOG_DEBUG, "Device Model already exited");
         ret = 0;
     } else if (ret == 0) {
-        XL_LOG(ctx, XL_LOG_DEBUG, "Device Model signaled\n");
+        XL_LOG(ctx, XL_LOG_DEBUG, "Device Model signaled");
         ret = 0;
     } else {
-        XL_LOG(ctx, XL_LOG_ERROR, "kill %d returned %d errno=%d\n", atoi(pid), 
ret, errno);
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "failed to kill Device Model [%d]",
+                     atoi(pid));
     }
     return ret;
 }
@@ -369,38 +376,40 @@ int libxl_domain_destroy(struct libxl_ct
 {
     char *dom_path, vm_path[41];
     xen_uuid_t *uuid;
+    int rc;
 
     dom_path = libxl_xs_get_dompath(ctx, domid);
-    if (!dom_path) {
-        XL_LOG(ctx, XL_LOG_ERROR, "dompath doesn't exist for %d\n", domid);
+    if (!dom_path)
         return -1;
-    }
+
     if (libxl_domid_to_uuid(ctx, &uuid, domid) < 0) {
-        XL_LOG(ctx, XL_LOG_ERROR, "failed ot get uuid for %d\n", domid);
+        XL_LOG(ctx, XL_LOG_ERROR, "failed ot get uuid for %d", domid);
         return -1;
     }
     if (libxl_device_pci_shutdown(ctx, domid) < 0)
-        XL_LOG(ctx, XL_LOG_ERROR, "pci shutdown failed for domid %d\n", domid);
+        XL_LOG(ctx, XL_LOG_ERROR, "pci shutdown failed for domid %d", domid);
     xs_write(ctx->xsh, XBT_NULL,
              libxl_sprintf(ctx, "/local/domain/0/device-model/%d/command", 
domid),
              "shutdown", strlen("shutdown"));
-    if (xc_domain_pause(ctx->xch, domid) < 0) {
-        XL_LOG(ctx, XL_LOG_ERROR, "xc_domain_pause failed for %d\n", domid);
+    rc = xc_domain_pause(ctx->xch, domid);
+    if (rc < 0) {
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "xc_domain_pause failed for 
%d", domid);
         return -1;
     }
-    if (xc_domain_destroy(ctx->xch, domid) < 0) {
-        XL_LOG(ctx, XL_LOG_ERROR, "xc_domain_destroy failed for %d\n", domid);
+    rc = xc_domain_destroy(ctx->xch, domid);
+    if (rc < 0) {
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "xc_domain_destroy failed for 
%d", domid);
         return -1;
     }
     if (libxl_devices_destroy(ctx, domid, force) < 0)
-        XL_LOG(ctx, XL_LOG_ERROR, "libxl_destroy_devices failed for %d\n", 
domid);
+        XL_LOG(ctx, XL_LOG_ERROR, "libxl_destroy_devices failed for %d", 
domid);
     if (libxl_destroy_device_model(ctx, domid) < 0)
-        XL_LOG(ctx, XL_LOG_ERROR, "libxl_destroy_device_model failed for 
%d\n", domid);
+        XL_LOG(ctx, XL_LOG_ERROR, "libxl_destroy_device_model failed for %d", 
domid);
     if (!xs_rm(ctx->xsh, XBT_NULL, dom_path))
-        XL_LOG(ctx, XL_LOG_ERROR, "xs_rm failed for %s\n", dom_path);
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "xs_rm failed for %s", dom_path);
     snprintf(vm_path, sizeof(vm_path), "/vm/%s", libxl_uuid_to_string(ctx, 
uuid));
     if (!xs_rm(ctx->xsh, XBT_NULL, vm_path))
-        XL_LOG(ctx, XL_LOG_ERROR, "xs_rm failed for %s\n", vm_path);
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "xs_rm failed for %s", vm_path);
     return 0;
 }
 
@@ -524,6 +533,8 @@ int libxl_create_device_model(struct lib
         return ERROR_FAIL;
 
     dom_path = libxl_xs_get_dompath(ctx, info->domid);
+    if (!dom_path)
+        return ERROR_FAIL;
 
     path = libxl_sprintf(ctx, "/local/domain/0/device-model/%d", info->domid);
     xs_mkdir(ctx->xsh, XBT_NULL, path);
@@ -1017,7 +1028,7 @@ static int libxl_create_pci_backend(stru
     if (!back)
         return ERROR_NOMEM;
 
-    XL_LOG(ctx, XL_LOG_DEBUG, "Creating pci backend\n");
+    XL_LOG(ctx, XL_LOG_DEBUG, "Creating pci backend");
 
     /* add pci device */
     device.backend_devid = 0;
@@ -1088,7 +1099,7 @@ static int libxl_device_pci_add_xenstore
     if (!back)
         return ERROR_NOMEM;
 
-    XL_LOG(ctx, XL_LOG_DEBUG, "Adding new pci device to xenstore\n");
+    XL_LOG(ctx, XL_LOG_DEBUG, "Adding new pci device to xenstore");
     num = atoi(num_devs);
     flexarray_set(back, boffset++, libxl_sprintf(ctx, "key-%d", num));
     flexarray_set(back, boffset++, libxl_sprintf(ctx, PCI_BDF, pcidev->domain, 
pcidev->bus, pcidev->dev, pcidev->func));
@@ -1140,7 +1151,7 @@ static int libxl_device_pci_remove_xenst
 
     if (!is_hvm(ctx, domid)) {
         if (libxl_wait_for_backend(ctx, be_path, "4") < 0) {
-            XL_LOG(ctx, XL_LOG_DEBUG, "pci backend at %s is not ready\n");
+            XL_LOG(ctx, XL_LOG_DEBUG, "pci backend at %s is not ready");
             return -1;
         }
     }
@@ -1154,7 +1165,7 @@ static int libxl_device_pci_remove_xenst
         }
     }
     if (i == num) {
-        XL_LOG(ctx, XL_LOG_ERROR, "Couldn't find the device on xenstore\n");
+        XL_LOG(ctx, XL_LOG_ERROR, "Couldn't find the device on xenstore");
         return -1;
     }
 
@@ -1196,7 +1207,7 @@ int libxl_device_pci_add(struct libxl_ct
         snprintf(path, sizeof(path), 
"/local/domain/0/device-model/%d/command", domid);
         xs_write(ctx->xsh, XBT_NULL, path, "pci-ins", strlen("pci-ins"));
         if (libxl_wait_for_device_model(ctx, domid, "pci-inserted") < 0)
-            XL_LOG(ctx, XL_LOG_ERROR, "Device Model didn't respond in time\n");
+            XL_LOG(ctx, XL_LOG_ERROR, "Device Model didn't respond in time");
         snprintf(path, sizeof(path), 
"/local/domain/0/device-model/%d/parameter", domid);
         vdevfn = libxl_xs_read(ctx, XBT_NULL, path);
         sscanf(vdevfn + 2, "%x", &pcidev->vdevfn);
@@ -1211,22 +1222,22 @@ int libxl_device_pci_add(struct libxl_ct
         int i;
 
         if (f == NULL) {
-            XL_LOG(ctx, XL_LOG_ERROR, "Couldn't open %s\n", sysfs_path);
+            XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Couldn't open %s", sysfs_path);
             return -1;
         }
         for (i = 0; i < PROC_PCI_NUM_RESOURCES; i++) {
-            fscanf(f, "0x%x 0x%x 0x%x\n", &start, &end, &flags);
+            fscanf(f, "0x%x 0x%x 0x%x", &start, &end, &flags);
             size = end - start + 1;
             if (start) {
                 if (flags & PCI_BAR_IO) {
                     rc = xc_domain_ioport_permission(ctx->xch, domid, start, 
size, 1);
                     if (rc < 0)
-                        XL_LOG(ctx, XL_LOG_ERROR, "Error: 
xc_domain_ioport_permission error 0x%x/0x%x:  %d\n", start, size, rc);
+                        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "Error: 
xc_domain_ioport_permission error 0x%x/0x%x", start, size);
                 } else {
                     rc = xc_domain_iomem_permission(ctx->xch, domid, 
start>>XC_PAGE_SHIFT,
                                                     
(size+(XC_PAGE_SIZE-1))>>XC_PAGE_SHIFT, 1);
                     if (rc < 0)
-                        XL_LOG(ctx, XL_LOG_ERROR, "Error: 
xc_domain_iomem_permission error 0x%x/0x%x:  %d\n", start, size, rc);
+                        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "Error: 
xc_domain_iomem_permission error 0x%x/0x%x", start, size);
                 }
             }
         }
@@ -1235,25 +1246,25 @@ int libxl_device_pci_add(struct libxl_ct
                                    pcidev->bus, pcidev->dev, pcidev->func);
         f = fopen(sysfs_path, "r");
         if (f == NULL) {
-            XL_LOG(ctx, XL_LOG_ERROR, "Couldn't open %s\n", sysfs_path);
+            XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Couldn't open %s", sysfs_path);
             goto out;
         }
         fscanf(f, "%u", &irq);
         if (irq) {
             rc = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq);
             if (rc < 0) {
-                XL_LOG(ctx, XL_LOG_ERROR, "Error: xc_physdev_map_pirq irq=%d: 
%d\n", irq, rc);
+                XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "Error: 
xc_physdev_map_pirq irq=%d", irq);
             }
             rc = xc_domain_irq_permission(ctx->xch, domid, irq, 1);
             if (rc < 0) {
-                XL_LOG(ctx, XL_LOG_ERROR, "Error: xc_domain_irq_permission 
irq=%d: %d\n", irq, rc);
+                XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "Error: 
xc_domain_irq_permission irq=%d", irq);
             }
         }
         fclose(f);
     }
 out:
     if ((rc = xc_assign_device(ctx->xch, domid, pcidev->value)) < 0)
-        XL_LOG(ctx, XL_LOG_ERROR, "Error: xc_assign_device error %d\n", rc);
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "xc_assign_device failed");
 
     libxl_device_pci_add_xenstore(ctx, domid, pcidev);
     return 0;
@@ -1280,7 +1291,7 @@ int libxl_device_pci_remove(struct libxl
         snprintf(path, sizeof(path), 
"/local/domain/0/device-model/%d/command", domid);
         xs_write(ctx->xsh, XBT_NULL, path, "pci-rem", strlen("pci-rem"));
         if (libxl_wait_for_device_model(ctx, domid, "pci-removed") < 0) {
-            XL_LOG(ctx, XL_LOG_ERROR, "Device Model didn't respond in time\n");
+            XL_LOG(ctx, XL_LOG_ERROR, "Device Model didn't respond in time");
             return -1;
         }
         snprintf(path, sizeof(path), "/local/domain/0/device-model/%d/state", 
domid);
@@ -1294,7 +1305,7 @@ int libxl_device_pci_remove(struct libxl
         int i;
 
         if (f == NULL) {
-            XL_LOG(ctx, XL_LOG_ERROR, "Couldn't open %s\n", sysfs_path);
+            XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Couldn't open %s", sysfs_path);
             goto skip1;
         }
         for (i = 0; i < PROC_PCI_NUM_RESOURCES; i++) {
@@ -1304,12 +1315,12 @@ int libxl_device_pci_remove(struct libxl
                 if (flags & PCI_BAR_IO) {
                     rc = xc_domain_ioport_permission(ctx->xch, domid, start, 
size, 0);
                     if (rc < 0)
-                        XL_LOG(ctx, XL_LOG_ERROR, "Error: 
xc_domain_ioport_permission error 0x%x/0x%x:  %d\n", start, size, rc);
+                        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, 
"xc_domain_ioport_permission error 0x%x/0x%x", start, size);
                 } else {
                     rc = xc_domain_iomem_permission(ctx->xch, domid, 
start>>XC_PAGE_SHIFT,
                                                     
(size+(XC_PAGE_SIZE-1))>>XC_PAGE_SHIFT, 0);
                     if (rc < 0)
-                        XL_LOG(ctx, XL_LOG_ERROR, "Error: 
xc_domain_iomem_permission error 0x%x/0x%x:  %d\n", start, size, rc);
+                        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, 
"xc_domain_iomem_permission error 0x%x/0x%x", start, size);
                 }
             }
         }
@@ -1319,18 +1330,18 @@ skip1:
                                    pcidev->bus, pcidev->dev, pcidev->func);
         f = fopen(sysfs_path, "r");
         if (f == NULL) {
-            XL_LOG(ctx, XL_LOG_ERROR, "Couldn't open %s\n", sysfs_path);
+            XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Couldn't open %s", sysfs_path);
             goto out;
         }
         fscanf(f, "%u", &irq);
         if (irq) {
             rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
             if (rc < 0) {
-                XL_LOG(ctx, XL_LOG_ERROR, "Error: xc_physdev_map_pirq irq=%d: 
%d\n", irq, rc);
+                XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "xc_physdev_map_pirq 
irq=%d", irq);
             }
             rc = xc_domain_irq_permission(ctx->xch, domid, irq, 0);
             if (rc < 0) {
-                XL_LOG(ctx, XL_LOG_ERROR, "Error: xc_domain_irq_permission 
irq=%d: %d\n", irq, rc);
+                XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, 
"xc_domain_irq_permission irq=%d", irq);
             }
         }
         fclose(f);
@@ -1341,7 +1352,7 @@ out:
     libxl_device_pci_flr(ctx, pcidev->domain, pcidev->bus, pcidev->dev, 
pcidev->func);
 
     if ((rc = xc_deassign_device(ctx->xch, domid, pcidev->value)) < 0)
-        XL_LOG(ctx, XL_LOG_ERROR, "Error: xc_deassign_device error %d\n", rc);
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "xc_deassign_device failed");
     return 0;
 }
 
diff -r 522ae754787d -r b72f27350703 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c        Mon Nov 23 06:58:19 2009 +0000
+++ b/tools/libxl/libxl_device.c        Mon Nov 23 06:59:06 2009 +0000
@@ -92,7 +92,7 @@ retry_transaction:
         if (errno == EAGAIN)
             goto retry_transaction;
         else
-            XL_LOG(ctx, XL_LOG_ERROR, "xs transaction failed errno=%d\n", 
errno);
+            XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "xs transaction failed");
     }
     return 0;
 }
@@ -213,7 +213,7 @@ int libxl_devices_destroy(struct libxl_c
     path = libxl_sprintf(ctx, "/local/domain/%d/device", domid);
     l1 = libxl_xs_directory(ctx, XBT_NULL, path, &num1);
     if (!l1) {
-        XL_LOG(ctx, XL_LOG_ERROR, "%s is empty\n", path);
+        XL_LOG(ctx, XL_LOG_ERROR, "%s is empty", path);
         return -1;
     }
     for (i = 0; i < num1; i++) {
@@ -248,7 +248,7 @@ int libxl_devices_destroy(struct libxl_c
                     if (!state || atoi(state) == 6) {
                         xs_unwatch(ctx->xsh, l1[0], l1[1]);
                         xs_rm(ctx->xsh, XBT_NULL, l1[1]);
-                        XL_LOG(ctx, XL_LOG_DEBUG, "Destroyed device backend at 
%s\n", l1[1]);
+                        XL_LOG(ctx, XL_LOG_DEBUG, "Destroyed device backend at 
%s", l1[1]);
                         n_watches--;
                     }
                 }
@@ -267,15 +267,20 @@ int libxl_device_pci_flr(struct libxl_ct
 int libxl_device_pci_flr(struct libxl_ctx *ctx, unsigned int domain, unsigned 
int bus,
                          unsigned int dev, unsigned int func)
 {
+    char *do_flr= "/sys/bus/pci/drivers/pciback/do_flr";
     FILE *fd;
 
-    fd = fopen("/sys/bus/pci/drivers/pciback/do_flr", "w");
+    fd = fopen(do_flr, "w");
     if (fd != NULL) {
         fprintf(fd, PCI_BDF, domain, bus, dev, func);
         fclose(fd);
         return 0;
     }
-    XL_LOG(ctx, XL_LOG_ERROR, "Pciback doesn't support do_flr, cannot flr the 
device\n");
+    if (errno == ENOENT) {
+        XL_LOG(ctx, XL_LOG_ERROR, "Pciback doesn't support do_flr, cannot flr 
the device");
+    } else {
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Failed to access pciback path %s", 
do_flr);
+    }
     return -1;
 }
 
@@ -303,7 +308,7 @@ int libxl_wait_for_device_model(struct l
             }
         }
     }
-    XL_LOG(ctx, XL_LOG_ERROR, "Device Model not ready\n");
+    XL_LOG(ctx, XL_LOG_ERROR, "Device Model not ready");
     return -1;
 }
 
@@ -317,7 +322,13 @@ int libxl_wait_for_backend(struct libxl_
     while (watchdog > 0) {
         p = xs_read(ctx->xsh, XBT_NULL, path, &len);
         if (p == NULL) {
-            XL_LOG(ctx, XL_LOG_ERROR, "Backend %s does not exist\n", be_path);
+            if (errno == ENOENT) {
+                XL_LOG(ctx, XL_LOG_ERROR, "Backend %s does not exist",
+                       be_path);
+            } else {
+                XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Failed to access backend %s",
+                       be_path);
+            }
             return -1;
         } else {
             if (!strcmp(p, state)) {
@@ -328,7 +339,7 @@ int libxl_wait_for_backend(struct libxl_
             }
         }
     }
-    XL_LOG(ctx, XL_LOG_ERROR, "Backend %s not ready\n", be_path);
-    return -1;
-}
-
+    XL_LOG(ctx, XL_LOG_ERROR, "Backend %s not ready", be_path);
+    return -1;
+}
+
diff -r 522ae754787d -r b72f27350703 tools/libxl/libxl_dom.c
--- a/tools/libxl/libxl_dom.c   Mon Nov 23 06:58:19 2009 +0000
+++ b/tools/libxl/libxl_dom.c   Mon Nov 23 06:59:06 2009 +0000
@@ -83,6 +83,9 @@ int build_post(struct libxl_ctx *ctx, ui
     ents[9] = libxl_sprintf(ctx, "%lu", state->store_mfn);
 
     dom_path = libxl_xs_get_dompath(ctx, domid);
+    if (!dom_path)
+        return ERROR_FAIL;
+
     vm_path = xs_read(ctx->xsh, XBT_NULL, libxl_sprintf(ctx, "%s/vm", 
dom_path), NULL);
 retry_transaction:
     t = xs_transaction_start(ctx->xsh);
@@ -107,7 +110,7 @@ int build_pv(struct libxl_ctx *ctx, uint
 
     dom = xc_dom_allocate(info->u.pv.cmdline, info->u.pv.features);
     if (!dom) {
-        XL_LOG(ctx, XL_LOG_ERROR, "xc_dom_allocate failed: %d", dom);
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, dom, "xc_dom_allocate failed");
         return -1;
     }
     if ((ret = xc_dom_linux_build(ctx->xch, dom, domid, info->max_memkb / 1024,
@@ -115,7 +118,7 @@ int build_pv(struct libxl_ctx *ctx, uint
                                   state->store_port, &state->store_mfn,
                                   state->console_port, &state->console_mfn)) 
!= 0) {
         xc_dom_release(dom);
-        XL_LOG(ctx, XL_LOG_ERROR, "xc_dom_linux_build failed: %d", ret);
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, ret, "xc_dom_linux_build failed");
         return -2;
     }
     xc_dom_release(dom);
@@ -129,7 +132,7 @@ int build_hvm(struct libxl_ctx *ctx, uin
 
     ret = xc_hvm_build(ctx->xch, domid, info->max_memkb / 1024, info->kernel);
     if (ret) {
-        XL_LOG(ctx, XL_LOG_ERROR, "hvm building failed: %d", ret);
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, ret, "hvm building failed");
         return ERROR_FAIL;
     }
     ret = hvm_build_set_params(ctx->xch, domid, info->u.hvm.apic, 
info->u.hvm.acpi,
@@ -137,7 +140,7 @@ int build_hvm(struct libxl_ctx *ctx, uin
                                info->max_vcpus,
                                state->store_port, &state->store_mfn);
     if (ret) {
-        XL_LOG(ctx, XL_LOG_ERROR, "hvm build set params failed: %d", ret);
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, ret, "hvm build set params failed");
         return ERROR_FAIL;
     }
     xc_cpuid_apply_policy(ctx->xch, domid);
diff -r 522ae754787d -r b72f27350703 tools/libxl/libxl_exec.c
--- a/tools/libxl/libxl_exec.c  Mon Nov 23 06:58:19 2009 +0000
+++ b/tools/libxl/libxl_exec.c  Mon Nov 23 06:59:06 2009 +0000
@@ -28,7 +28,7 @@ int libxl_exec(struct libxl_ctx *ctx, in
 
     pid = fork();
     if (pid == -1) {
-        XL_LOG(ctx, XL_LOG_ERROR, "fork failed");
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "fork failed");
         return -1;
     }
     if (pid == 0) {
diff -r 522ae754787d -r b72f27350703 tools/libxl/libxl_internal.c
--- a/tools/libxl/libxl_internal.c      Mon Nov 23 06:58:19 2009 +0000
+++ b/tools/libxl/libxl_internal.c      Mon Nov 23 06:59:06 2009 +0000
@@ -146,14 +146,41 @@ char *libxl_dirname(struct libxl_ctx *ct
     return ptr;
 }
 
-void xl_log(struct libxl_ctx *ctx, int loglevel, const char *file, int line, 
const char *func, char *fmt, ...)
+void xl_logv(struct libxl_ctx *ctx, int loglevel, int errnoval,
+             const char *file, int line, const char *func,
+             char *fmt, va_list ap)
+{
+    char *enomem = "[out of memory formatting log message]";
+    char *s;
+    int rc;
+
+    rc = vasprintf(&s, fmt, ap);
+    if (rc<0) { s = enomem; goto x; }
+
+    if (errnoval >= 0) {
+        char *errstr, *snew;
+        errstr = strerror(errnoval);
+        if (errstr)
+            rc = asprintf(&snew, "%s: %s", s, errstr);
+        else
+            rc = asprintf(&snew, "%s: unknown error number %d", s, errnoval);
+        free(s);
+        if (rc<0) { s = enomem; goto x; }
+        s = snew;
+    }
+
+ x:
+    ctx->log_callback(ctx->log_userdata, loglevel, file, line, func, s);
+    if (s != enomem)
+        free(s);
+}
+
+void xl_log(struct libxl_ctx *ctx, int loglevel, int errnoval,
+            const char *file, int line,
+            const char *func, char *fmt, ...)
 {
     va_list ap;
-    char *s;
     va_start(ap, fmt);
-    vasprintf(&s, fmt, ap);
+    xl_logv(ctx, loglevel, errnoval, file, line, func, fmt, ap);
     va_end(ap);
-
-    ctx->log_callback(ctx->log_userdata, loglevel, file, line, func, s);
-    free(s);
 }
diff -r 522ae754787d -r b72f27350703 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Mon Nov 23 06:58:19 2009 +0000
+++ b/tools/libxl/libxl_internal.h      Mon Nov 23 06:59:06 2009 +0000
@@ -37,9 +37,13 @@
 #define XL_LOGGING_ENABLED
 
 #ifdef XL_LOGGING_ENABLED
-#define XL_LOG(ctx, loglevel, _f, _a...)   xl_log(ctx, loglevel, __FILE__, 
__LINE__, __func__, _f, ##_a)
+#define XL_LOG(ctx, loglevel, _f, _a...)   xl_log(ctx, loglevel, -1, __FILE__, 
__LINE__, __func__, _f, ##_a)
+#define XL_LOG_ERRNO(ctx, loglevel, _f, _a...)   xl_log(ctx, loglevel, errno, 
__FILE__, __LINE__, __func__, _f, ##_a)
+#define XL_LOG_ERRNOVAL(ctx, errnoval, loglevel, _f, _a...)   xl_log(ctx, 
loglevel, errnoval, __FILE__, __LINE__, __func__, _f, ##_a)
 #else
 #define XL_LOG(ctx, loglevel, _f, _a...)
+#define XL_LOG_ERRNO(ctx, loglevel, _f, _a...)
+#define XL_LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...)
 #endif
 
 #define XL_LOG_DEBUG 3
@@ -47,7 +51,8 @@
 #define XL_LOG_WARNING 1
 #define XL_LOG_ERROR 0
 
-void xl_log(struct libxl_ctx *ctx, int loglevel, const char *file, int line, 
const char *func, char *fmt, ...);
+void xl_logv(struct libxl_ctx *ctx, int errnoval, int loglevel, const char 
*file, int line, const char *func, char *fmt, va_list al);
+void xl_log(struct libxl_ctx *ctx, int errnoval, int loglevel, const char 
*file, int line, const char *func, char *fmt, ...);
 
 struct libxl_domain_build_state_ {
     uint32_t store_port;
@@ -97,7 +102,7 @@ int libxl_xs_writev(struct libxl_ctx *ct
                     char *dir, char **kvs);
 int libxl_xs_write(struct libxl_ctx *ctx, xs_transaction_t t,
                    char *path, char *fmt, ...);
-char *libxl_xs_get_dompath(struct libxl_ctx *ctx, uint32_t domid);
+char *libxl_xs_get_dompath(struct libxl_ctx *ctx, uint32_t domid); // logs errs
 char *libxl_xs_read(struct libxl_ctx *ctx, xs_transaction_t t, char *path);
 char **libxl_xs_directory(struct libxl_ctx *ctx, xs_transaction_t t, char 
*path, unsigned int *nb);
 
diff -r 522ae754787d -r b72f27350703 tools/libxl/libxl_xshelp.c
--- a/tools/libxl/libxl_xshelp.c        Mon Nov 23 06:58:19 2009 +0000
+++ b/tools/libxl/libxl_xshelp.c        Mon Nov 23 06:59:06 2009 +0000
@@ -95,6 +95,11 @@ char *libxl_xs_get_dompath(struct libxl_
 char *libxl_xs_get_dompath(struct libxl_ctx *ctx, uint32_t domid)
 {
     char *s = xs_get_domain_path(ctx->xsh, domid);
+    if (!s) {
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "failed to get dompath for %lu",
+                     domid);
+        return NULL;
+    }
     libxl_ptr_add(ctx, s);
     return s;
 }

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] libxenlight: Clean up logging arrangements, Xen patchbot-unstable <=