Search
j0ke.net Open Build Service
>
Projects
>
GFS
>
multipath-tools
> multipath-tools-enhance-devmapper-output
Sign Up
|
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File multipath-tools-enhance-devmapper-output of Package multipath-tools
tree 9f2d40a33718e1d34de9c4dc503f885532ff744c parent 311d95211efce0314e197f3c1dc7330e345dc297 author Hannes Reinecke <hare@suse.de> 1175157235 +0200 committer Hannes Reinecke <hare@suse.de> 1175157235 +0200 [libmultipath] Fix debugging output Implement a proper output function for libdevmapper which ties into our verbosity level. This allows us for a finer grained control about the error messages from libdevmapper and we get better debugging output to boot. Fixed flushing of all maps. Signed-off-by: Hannes Reinecke <hare@suse.de> 4df37d60e3322d05b9ff8f8d7135d849611a4981 libmultipath/configure.c | 2 - libmultipath/debug.c | 2 + libmultipath/debug.h | 2 + libmultipath/devmapper.c | 61 ++++++++++++++++++++++++++++++++++---------- libmultipath/devmapper.h | 3 +- libmultipath/log_pthread.c | 2 + libmultipath/log_pthread.h | 2 + libmultipath/structs_vec.c | 35 ++++++++++++++----------- libmultipath/waiter.c | 9 +++--- multipath/main.c | 1 + multipathd/main.c | 3 ++ 11 files changed, 80 insertions(+), 42 deletions(-) diff --git a/libmultipath/configure.c b/libmultipath/configure.c index 9d17022..0d5e405 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -322,7 +322,6 @@ domap (struct multipath * mpp) mpp->alias); return DOMAP_RETRY; } - dm_shut_log(); if (dm_map_present(mpp->alias)) break; @@ -343,7 +342,6 @@ domap (struct multipath * mpp) } lock_multipath(mpp, 0); - dm_restore_log(); break; case ACT_RELOAD: diff --git a/libmultipath/debug.c b/libmultipath/debug.c index fa06cbd..05dfb06 100644 --- a/libmultipath/debug.c +++ b/libmultipath/debug.c @@ -14,7 +14,7 @@ #endif #include "vector.h" #include "config.h" -void dlog (int sink, int prio, char * fmt, ...) +void dlog (int sink, int prio, const char * fmt, ...) { va_list ap; int thres; diff --git a/libmultipath/debug.h b/libmultipath/debug.h index 74ed531..082fff1 100644 --- a/libmultipath/debug.h +++ b/libmultipath/debug.h @@ -1,4 +1,4 @@ -void dlog (int sink, int prio, char * fmt, ...) +void dlog (int sink, int prio, const char * fmt, ...) __attribute__((format(printf, 3, 4))); #if DAEMON diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index b8571ad..b0be110 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -20,6 +20,13 @@ #include "structs.h" #include "debug.h" #include "memory.h" #include "devmapper.h" +#include "config.h" + +#if DAEMON +#include "log_pthread.h" +#include <sys/types.h> +#include <time.h> +#endif #define MAX_WAIT 5 #define LOOPS_PER_SEC 5 @@ -27,23 +34,51 @@ #define LOOPS_PER_SEC 5 #define UUID_PREFIX "mpath-" #define UUID_PREFIX_LEN 6 - static void -dm_dummy_log (int level, const char *file, int line, const char *f, ...) +dm_write_log (int level, const char *file, int line, const char *f, ...) { - return; -} + va_list ap; + int thres; + + if (level > 6) + level = 6; + + thres = (conf) ? conf->verbosity : 0; + if (thres <= 3 || level > thres) + return; + + va_start(ap, f); +#if DAEMON + if (!logsink) { + time_t t = time(NULL); + struct tm *tb = localtime(&t); + char buff[16]; + + strftime(buff, sizeof(buff), "%b %d %H:%M:%S", tb); + buff[sizeof(buff)-1] = '\0'; + + fprintf(stdout, "%s | ", buff); + fprintf(stdout, "libdevmapper: %s(%i): ", file, line); + vfprintf(stdout, f, ap); + fprintf(stdout, "\n"); + } else { + condlog(level, "libdevmapper: %s(%i): ", file, line); + log_safe(level + 3, f, ap); + } +#else + fprintf(stdout, "libdevmapper: %s(%i): ", file, line); + vfprintf(stdout, f, ap); + fprintf(stdout, "\n"); +#endif + va_end(ap); -void -dm_restore_log (void) -{ - dm_log_init(NULL); + return; } -void -dm_shut_log (void) -{ - dm_log_init(&dm_dummy_log); +extern void +dm_init(void) { + dm_log_init(&dm_write_log); + dm_log_init_verbose(conf ? conf->verbosity + 3 : 0); } extern int @@ -723,9 +758,7 @@ dm_mapname(int major, int minor) * daemon uev_trigger -> uev_add_map */ while (--loop) { - dm_shut_log(); r = dm_task_run(dmt); - dm_restore_log(); if (r) break; diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index c7879a7..1628ba3 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -1,5 +1,4 @@ -void dm_shut_log(void); -void dm_restore_log(void); +void dm_init(void); int dm_prereq (char *, int, int, int); int dm_simplecmd (int, const char *); int dm_addmap (int, const char *, const char *, const char *, diff --git a/libmultipath/log_pthread.c b/libmultipath/log_pthread.c index f98cfa4..5a82b6a 100644 --- a/libmultipath/log_pthread.c +++ b/libmultipath/log_pthread.c @@ -12,7 +12,7 @@ #include <memory.h> #include "log_pthread.h" #include "log.h" -void log_safe (int prio, char * fmt, va_list ap) +void log_safe (int prio, const char * fmt, va_list ap) { pthread_mutex_lock(logq_lock); //va_start(ap, fmt); diff --git a/libmultipath/log_pthread.h b/libmultipath/log_pthread.h index 7c902c7..2b18f59 100644 --- a/libmultipath/log_pthread.h +++ b/libmultipath/log_pthread.h @@ -7,7 +7,7 @@ pthread_mutex_t *logq_lock; pthread_mutex_t *logev_lock; pthread_cond_t *logev_cond; -void log_safe(int prio, char * fmt, va_list ap); +void log_safe(int prio, const char * fmt, va_list ap); void log_thread_start(void); void log_thread_stop(void); diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index 304d695..4721f31 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -117,6 +117,8 @@ remove_map (struct multipath * mpp, stru { int i; + condlog(4, "%s: remove multipath map", mpp->alias); + /* * stop the DM event waiter thread */ @@ -244,8 +246,17 @@ extern int setup_multipath (struct vectors * vecs, struct multipath * mpp) { retry: - if (dm_get_info(mpp->alias, &mpp->dmi)) + if (dm_get_info(mpp->alias, &mpp->dmi)) { + /* Error accessing table */ + condlog(3, "%s: cannot access table", mpp->alias); goto out; + } + + if (!dm_map_present(mpp->alias)) { + /* Table has been removed */ + condlog(3, "%s: table does not exist", mpp->alias); + goto out; + } set_multipath_wwid(mpp); mpp->mpe = find_mpe(mpp->wwid); @@ -269,6 +280,7 @@ #if DAEMON #endif goto retry; } + condlog(0, "%s: failed to setup multipath", mpp->alias); goto out; } @@ -280,12 +292,7 @@ #endif return 0; out: - condlog(0, "%s: failed to setup multipath", mpp->alias); -#if DAEMON - remove_map(mpp, vecs, stop_waiter_thread, 1); -#else remove_map(mpp, vecs, NULL, 1); -#endif return 1; } @@ -392,18 +399,19 @@ int update_multipath (struct vectors *ve struct pathgroup *pgp; struct path *pp; int i, j; - int r = 1; mpp = find_mp_by_alias(vecs->mpvec, mapname); - if (!mpp) - goto out; + if (!mpp) { + condlog(3, "%s: multipath map not found\n", mapname); + return 2; + } free_pgvec(mpp->pg, KEEP_PATHS); mpp->pg = NULL; if (setup_multipath(vecs, mpp)) - goto out; /* mpp freed in setup_multipath */ + return 1; /* mpp freed in setup_multipath */ /* * compare checkers states with DM states @@ -431,11 +439,8 @@ int update_multipath (struct vectors *ve } } } - r = 0; -out: - if (r) - condlog(0, "failed to update multipath"); - return r; + + return 0; } /* diff --git a/libmultipath/waiter.c b/libmultipath/waiter.c index 75ed90c..d7af0d1 100644 --- a/libmultipath/waiter.c +++ b/libmultipath/waiter.c @@ -117,15 +117,11 @@ int waiteventloop (struct event_thread * /* accept wait interruption */ set = unblock_signals(); - /* interruption spits messages */ - dm_shut_log(); - /* wait */ r = dm_task_run(waiter->dmt); /* wait is over : event or interrupt */ pthread_sigmask(SIG_SETMASK, &set, NULL); - //dm_restore_log(); if (!r) /* wait interrupted by signal */ return -1; @@ -157,8 +153,11 @@ int waiteventloop (struct event_thread * r = update_multipath(waiter->vecs, waiter->mapname); lock_cleanup_pop(waiter->vecs->lock); - if (r) + if (r) { + condlog(2, "%s: event checker exit", + waiter->mapname); return -1; /* stop the thread */ + } event_nr = dm_geteventnr(waiter->mapname); diff --git a/multipath/main.c b/multipath/main.c index d4ba96d..ee51051 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -365,6 +365,7 @@ main (int argc, char *argv[]) fprintf(stderr, "need to be root\n"); exit(1); } + dm_init(); if (dm_prereq(DEFAULT_TARGET, 1, 0, 3)) exit(1); diff --git a/multipathd/main.c b/multipathd/main.c index 83d1374..1614f52 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -225,6 +225,8 @@ ev_add_map (char * devname, struct vecto int map_present; int r = 1; + /* libsysfs seems to forget to terminate the string... */ + memset(dev_t, 0, BLK_DEV_SIZE); if (sscanf(devname, "dm-%d", &minor) == 1 && !sysfs_get_dev(sysfs_path, devname, dev_t, BLK_DEV_SIZE) && sscanf(dev_t, "%d:%d", &major, &minor) == 2) @@ -1409,6 +1411,7 @@ main (int argc, char *argv[]) int err; logsink = 1; + dm_init(); if (getuid() != 0) { fprintf(stderr, "need to be root\n");