[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] libxl: hide internal logging from client



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1262176999 0
# Node ID 411a5b79605017b88ce77dbc5f00220956b5597f
# Parent  3e4051dbfd34ced8a9fdc14c4c7905f46a93d94a
libxl: hide internal logging from client

reimplement simple logging in xl, the XL_LOG facilities are a
means for the library to communicate back to the client, not
for a logging library that may be redundant with what the client
use.

Signed-off-by: Vincent Hanquez <vincent.hanquez@xxxxxxxxxxxxx>
---
 tools/libxl/libxl.h          |   21 ---------------------
 tools/libxl/libxl_internal.h |   22 ++++++++++++++++++++++
 tools/libxl/xl.c             |   27 +++++++++++++++++++++------
 3 files changed, 43 insertions(+), 27 deletions(-)

diff -r 3e4051dbfd34 -r 411a5b796050 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Wed Dec 30 12:42:41 2009 +0000
+++ b/tools/libxl/libxl.h       Wed Dec 30 12:43:19 2009 +0000
@@ -22,8 +22,6 @@
 #include <xs.h>
 
 #include "xen_uuid.h"
-
-#define XL_LOGGING_ENABLED
 
 typedef void (*libxl_log_callback)(void *userdata, int loglevel, const char 
*file,
                                    int line, const char *func, char *s);
@@ -230,25 +228,6 @@ typedef struct  {
 #define ERROR_NOMEM (-1032)
 #define ERROR_INVAL (-1245)
 
-/* logging */
-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, ...);
-
-#ifdef XL_LOGGING_ENABLED
-#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
-#define XL_LOG_INFO 2
-#define XL_LOG_WARNING 1
-#define XL_LOG_ERROR 0
-
 /* context functions */
 int libxl_ctx_init(struct libxl_ctx *ctx);
 int libxl_ctx_free(struct libxl_ctx *ctx);
diff -r 3e4051dbfd34 -r 411a5b796050 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Wed Dec 30 12:42:41 2009 +0000
+++ b/tools/libxl/libxl_internal.h      Wed Dec 30 12:43:19 2009 +0000
@@ -35,6 +35,28 @@
 #define QEMU_SIGNATURE "QemuDeviceModelRecord"
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+
+#define XL_LOGGING_ENABLED
+
+#ifdef XL_LOGGING_ENABLED
+#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
+#define XL_LOG_INFO 2
+#define XL_LOG_WARNING 1
+#define XL_LOG_ERROR 0
+
+/* logging */
+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, ...);
+
 
 typedef enum {
     DEVICE_VIF,
diff -r 3e4051dbfd34 -r 411a5b796050 tools/libxl/xl.c
--- a/tools/libxl/xl.c  Wed Dec 30 12:42:41 2009 +0000
+++ b/tools/libxl/xl.c  Wed Dec 30 12:43:19 2009 +0000
@@ -44,6 +44,21 @@ void log_callback(void *userdata, int lo
 
     snprintf(str, sizeof(str), "[%d] %s:%d:%s: %s\n", loglevel, file, line, 
func, s);
     write(logfile, str, strlen(str));
+}
+
+#define LOG(_f, _a...)   dolog(__FILE__, __LINE__, __func__, _f, ##_a)
+
+void dolog(const char *file, int line, const char *func, char *fmt, ...)
+{
+    va_list ap;
+    char *s;
+    int rc;
+
+    va_start(ap, fmt);
+    rc = vasprintf(&s, fmt, ap);
+    va_end(ap);
+    if (rc >= 0)
+        write(logfile, s, rc);
 }
 
 static void init_create_info(libxl_domain_create_info *c_info)
@@ -784,7 +799,7 @@ start:
         daemon(0, 0);
         need_daemon = 0;
     }
-    XL_LOG(&ctx, XL_LOG_DEBUG, "Waiting for domain %s (domid %d) to die", 
info1.name, domid);
+    LOG("Waiting for domain %s (domid %d) to die", info1.name, domid);
     w1 = (libxl_waiter*) malloc(sizeof(libxl_waiter) * num_disks);
     w2 = (libxl_waiter*) malloc(sizeof(libxl_waiter));
     libxl_wait_for_disk_ejects(&ctx, domid, disks, num_disks, w1);
@@ -808,9 +823,9 @@ start:
         switch (event.type) {
             case DOMAIN_DEATH:
                 if (libxl_event_get_domain_death_info(&ctx, domid, &event, 
&info)) {
-                    XL_LOG(&ctx, XL_LOG_DEBUG, "Domain %d is dead", domid);
+                    LOG("Domain %d is dead", domid);
                     if (info.crashed || info.dying || (info.shutdown && 
(info.shutdown_reason != SHUTDOWN_suspend))) {
-                        XL_LOG(&ctx, XL_LOG_DEBUG, "Domain %d needs to be 
clean: destroying the domain", domid);
+                        LOG("Domain %d needs to be clean: destroying the 
domain", domid);
                         libxl_domain_destroy(&ctx, domid, 0);
                         if (info.shutdown && (info.shutdown_reason == 
SHUTDOWN_reboot)) {
                             libxl_free_waiter(w1);
@@ -818,12 +833,12 @@ start:
                             free(w1);
                             free(w2);
                             libxl_ctx_free(&ctx);
-                            XL_LOG(&ctx, XL_LOG_DEBUG, "Done. Rebooting now");
+                            LOG("Done. Rebooting now");
                             goto start;
                         }
-                        XL_LOG(&ctx, XL_LOG_DEBUG, "Done. Exiting now");
+                        LOG("Done. Exiting now");
                     }
-                    XL_LOG(&ctx, XL_LOG_DEBUG, "Domain %d does not need to be 
clean, exiting now", domid);
+                    LOG("Domain %d does not need to be clean, exiting now", 
domid);
                     exit(0);
                 }
                 break;

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.