From: Vincent Hanquez Subject: [PATCH 05/11] hide internal logging from client Date: Tue, 29 Dec 2009 18:06:53 +0000 Message-ID: <1262110019-31072-6-git-send-email-vincent.hanquez@eu.citrix.com> References: <1262110019-31072-1-git-send-email-vincent.hanquez@eu.citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1.6.5.6" Return-path: In-Reply-To: <1262110019-31072-1-git-send-email-vincent.hanquez@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Vincent Hanquez List-Id: xen-devel@lists.xenproject.org --------------1.6.5.6 Content-Type: text/plain; charset="UTF-8"; format=fixed Content-Transfer-Encoding: quoted-printable 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 --- tools/libxl/libxl.h | 21 --------------------- tools/libxl/libxl_internal.h | 22 ++++++++++++++++++++++ tools/libxl/xl.c | 27 +++++++++++++++++++++------ 3 files changed, 43 insertions(+), 27 deletions(-) --------------1.6.5.6 Content-Type: text/x-patch; name="0005-hide-internal-logging-from-client.patch" Content-Disposition: attachment; filename="0005-hide-internal-logging-from-client.patch" Content-Transfer-Encoding: quoted-printable diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 1e50911..2d82829 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -23,8 +23,6 @@ =20 #include "xen_uuid.h" =20 -#define XL_LOGGING_ENABLED - typedef void (*libxl_log_callback)(void *userdata, int loglevel, const c= har *file, int line, const char *func, char *s); struct libxl_dominfo { @@ -230,25 +228,6 @@ typedef struct { #define ERROR_NOMEM (-1032) #define ERROR_INVAL (-1245) =20 -/* logging */ -void xl_logv(struct libxl_ctx *ctx, int errnoval, int loglevel, const ch= ar *file, int line, const char *func, char *fmt, va_list al); -void xl_log(struct libxl_ctx *ctx, int errnoval, int loglevel, const cha= r *file, int line, const char *func, char *fmt, ...); - -#ifdef XL_LOGGING_ENABLED -#define XL_LOG(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, -1, __F= ILE__, __LINE__, __func__, _f, ##_a) -#define XL_LOG_ERRNO(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, e= rrno, __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 --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 23d6ee4..39eb2dc 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -36,6 +36,28 @@ =20 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) =20 +#define XL_LOGGING_ENABLED + +#ifdef XL_LOGGING_ENABLED +#define XL_LOG(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, -1, __F= ILE__, __LINE__, __func__, _f, ##_a) +#define XL_LOG_ERRNO(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, e= rrno, __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 ch= ar *file, int line, const char *func, char *fmt, va_list al); +void xl_log(struct libxl_ctx *ctx, int errnoval, int loglevel, const cha= r *file, int line, const char *func, char *fmt, ...); + + typedef enum { DEVICE_VIF, DEVICE_VBD, diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c index a8a21e3..6577457 100644 --- a/tools/libxl/xl.c +++ b/tools/libxl/xl.c @@ -46,6 +46,21 @@ void log_callback(void *userdata, int loglevel, const = char *file, int line, cons write(logfile, str, strlen(str)); } =20 +#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 =3D vasprintf(&s, fmt, ap); + va_end(ap); + if (rc >=3D 0) + write(logfile, s, rc); +} + static void init_create_info(libxl_domain_create_info *c_info) { memset(c_info, '\0', sizeof(*c_info)); @@ -784,7 +799,7 @@ start: daemon(0, 0); need_daemon =3D 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 =3D (libxl_waiter*) malloc(sizeof(libxl_waiter) * num_disks); w2 =3D (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, &even= t, &info)) { - XL_LOG(&ctx, XL_LOG_DEBUG, "Domain %d is dead", domi= d); + LOG("Domain %d is dead", domid); if (info.crashed || info.dying || (info.shutdown && = (info.shutdown_reason !=3D SHUTDOWN_suspend))) { - XL_LOG(&ctx, XL_LOG_DEBUG, "Domain %d needs to b= e 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 =3D=3D= 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 no= w", domid); exit(0); } break; --------------1.6.5.6 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------1.6.5.6--