]> xenbits.xensource.com Git - qemu-xen-4.0-testing.git/commitdiff
qemu xen upstream synch (Gerd): [PATCH 5/7] logging fixups.
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 19 May 2009 14:41:04 +0000 (15:41 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 19 May 2009 14:41:04 +0000 (15:41 +0100)
Use new logging API.
Kill a few fprintf(stderr, "...") calls.

[This is] a series of patches for qemu-xen, making the code identical
to the xen support patches being submitted to upstream qemu.  The review
process on qemu-devel resulted in a number of fixes and cleanups in the
backend code, this is where most of the changes come from.

There are also some xenfb changes due to displaystate reorganization and
xenfb being merged in steps due to that.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
hw/xen_backend.c
hw/xen_console.c
hw/xenfb.c

index bb02634c03ceb81e8b5493a0f940cf5c5ca78e60..2f2ec7ffe003e3e946b5e8f98224e4ebe9d2194f 100644 (file)
@@ -209,7 +209,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
 
     xendev->evtchndev = xc_evtchn_open();
     if (xendev->evtchndev < 0) {
-       fprintf(stderr, "can't open evtchn device\n");
+       xen_be_printf(NULL, 0, "can't open evtchn device\n");
        qemu_free(xendev);
        return NULL;
     }
@@ -218,7 +218,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
     if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
        xendev->gnttabdev = xc_gnttab_open();
        if (xendev->gnttabdev < 0) {
-           fprintf(stderr, "can't open gnttab device\n");
+           xen_be_printf(NULL, 0, "can't open gnttab device\n");
            xc_evtchn_close(xendev->evtchndev);
            qemu_free(xendev);
            return NULL;
@@ -511,7 +511,7 @@ static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops)
     snprintf(path, sizeof(path), "%s/backend/%s/%d", dom0, type, dom);
     free(dom0);
     if (!xs_watch(xenstore, path, token)) {
-       fprintf(stderr, "xen be: watching backend path (%s) failed\n", path);
+       xen_be_printf(NULL, 0, "xen be: watching backend path (%s) failed\n", path);
        return -1;
     }
 
@@ -620,7 +620,7 @@ int xen_be_init(void)
 {
     xenstore = xs_daemon_open();
     if (!xenstore) {
-       fprintf(stderr, "can't connect to xenstored\n");
+       xen_be_printf(NULL, 0, "can't connect to xenstored\n");
        return -1;
     }
 
@@ -629,7 +629,7 @@ int xen_be_init(void)
 
     xen_xc = xc_interface_open();
     if (xen_xc == -1) {
-       fprintf(stderr, "can't open xen interface\n");
+       xen_be_printf(NULL, 0, "can't open xen interface\n");
        goto err;
     }
     return 0;
@@ -680,19 +680,35 @@ int xen_be_send_notify(struct XenDevice *xendev)
 
 /*
  * msg_level:
- *  0 == errors.
- *  1 == informative debug messages.
- *  2 == noisy debug messages.
- *  3 == will flood your log.
+ *  0 == errors (stderr + logfile).
+ *  1 == informative debug messages (logfile only).
+ *  2 == noisy debug messages (logfile only).
+ *  3 == will flood your log (logfile only).
  */
 void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...)
 {
     va_list args;
 
-    if (msg_level > xendev->debug)
-       return;
-    fprintf(stderr, "xen be: %s: ", xendev->name);
+    if (xendev) {
+        if (msg_level > xendev->debug)
+            return;
+        qemu_log("xen be: %s: ", xendev->name);
+        if (msg_level == 0)
+            fprintf(stderr, "xen be: %s: ", xendev->name);
+    } else {
+        if (msg_level > debug)
+            return;
+        qemu_log("xen be core: ");
+        if (msg_level == 0)
+            fprintf(stderr, "xen be core: ");
+    }
     va_start(args, fmt);
-    vfprintf(stderr, fmt, args);
+    qemu_log_vprintf(fmt, args);
     va_end(args);
+    if (msg_level == 0) {
+        va_start(args, fmt);
+        vfprintf(stderr, fmt, args);
+        va_end(args);
+    }
+    qemu_log_flush();
 }
index 707075eef301eaa61af48d2a725d332de8cd5c52..27f809df6a018f833b8ba6ddee9ea6c63783549a 100644 (file)
@@ -38,8 +38,6 @@
 #include "qemu-char.h"
 #include "xen_backend.h"
 
-#define dolog(val, fmt, ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
-
 struct buffer {
     uint8_t *data;
     size_t consumed;
@@ -75,10 +73,6 @@ static void buffer_append(struct XenConsole *con)
     if ((buffer->capacity - buffer->size) < size) {
        buffer->capacity += (size + 1024);
        buffer->data = qemu_realloc(buffer->data, buffer->capacity);
-       if (buffer->data == NULL) {
-           dolog(LOG_ERR, "Memory allocation failed");
-           exit(ENOMEM);
-       }
     }
 
     while (cons != prod)
index 1764ac2c148f4f76f2f1906c7901087736a449bc..d9e5c33db6e2523c45af72fd8ee5fa4f5953d8e0 100644 (file)
@@ -813,15 +813,14 @@ static void xenfb_handle_events(struct XenFB *xenfb)
            w = MIN(event->update.width, xenfb->width - x);
            h = MIN(event->update.height, xenfb->height - y);
            if (w < 0 || h < 0) {
-               fprintf(stderr, "xen be: %s: bogus update ignored\n",
-                       xenfb->c.xendev.name);
+                xen_be_printf(&xenfb->c.xendev, 1, "bogus update ignored\n");
                break;
            }
-           if (x != event->update.x || y != event->update.y
-               || w != event->update.width
-               || h != event->update.height) {
-               fprintf(stderr, "xen be: %s: bogus update clipped\n",
-                       xenfb->c.xendev.name);
+           if (x != event->update.x ||
+                y != event->update.y ||
+               w != event->update.width ||
+               h != event->update.height) {
+                xen_be_printf(&xenfb->c.xendev, 1, "bogus update clipped\n");
            }
            if (w == xenfb->width && h > xenfb->height / 2) {
                /* scroll detector: updated more than 50% of the lines,
@@ -993,7 +992,7 @@ wait_more:
     if (!xfb || !xin) {
         if (i < 256)
             goto wait_more;
-        fprintf(stderr, "%s: displaystate setup failed\n", __FUNCTION__);
+        xen_be_printf(NULL, 1, "displaystate setup failed\n");
         return;
     }