From e07d3cd9acf14219f33e12375fb8c2e3fe02ad0c Mon Sep 17 00:00:00 2001 From: Vivek Goyal Date: Thu, 2 Apr 2015 16:47:14 -0400 Subject: [PATCH] devmapper: Fix libdm logging There are issues with libdm logging. Right now if docker daemon is run in debug mode, logging by libdm is too verbose. And if a device can't be removed, thousands of messages fill the console and one can not see what's going on. This patch removes devicemapper.LogInitVerbose() call as that call will only work if docker was not registering its own log handler with libdm. For some reason docker registers one with libdm and libdm hands over all the messages to docker (including debug ones). And now it is up to devmapper backend to figure out which ones should go to console and which ones should not. So by default log only fatal messages from libdm. One can easily modify the code to change it for debugging purposes. Signed-off-by: Vivek Goyal --- daemon/graphdriver/devmapper/deviceset.go | 27 ++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/daemon/graphdriver/devmapper/deviceset.go b/daemon/graphdriver/devmapper/deviceset.go index 4d35adabc0..5515df9960 100644 --- a/daemon/graphdriver/devmapper/deviceset.go +++ b/daemon/graphdriver/devmapper/deviceset.go @@ -33,6 +33,10 @@ var ( DefaultThinpBlockSize uint32 = 128 // 64K = 128 512b sectors MaxDeviceId int = 0xffffff // 24 bit, pool limit DeviceIdMapSz int = (MaxDeviceId + 1) / 8 + // We retry device removal so many a times that even error messages + // will fill up console during normal operation. So only log Fatal + // messages by default. + DMLogLevel int = devicemapper.LogLevelFatal ) const deviceSetMetaFile string = "deviceset-metadata" @@ -723,14 +727,22 @@ func setCloseOnExec(name string) { } func (devices *DeviceSet) DMLog(level int, file string, line int, dmError int, message string) { - if level >= devicemapper.LogLevelDebug { - // (vbatts) libdm debug is very verbose. If you're debugging libdm, you can - // comment out this check yourself - level = devicemapper.LogLevelInfo + // By default libdm sends us all the messages including debug ones. + // We need to filter out messages here and figure out which one + // should be printed. + if level > DMLogLevel { + return } // FIXME(vbatts) push this back into ./pkg/devicemapper/ - logrus.Debugf("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message) + if level <= devicemapper.LogLevelErr { + logrus.Errorf("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message) + } else if level <= devicemapper.LogLevelInfo { + logrus.Infof("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message) + } else { + // FIXME(vbatts) push this back into ./pkg/devicemapper/ + logrus.Debugf("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message) + } } func major(device uint64) uint64 { @@ -947,11 +959,6 @@ func (devices *DeviceSet) closeTransaction() error { } func (devices *DeviceSet) initDevmapper(doInit bool) error { - if os.Getenv("DEBUG") != "" { - devicemapper.LogInitVerbose(devicemapper.LogLevelDebug) - } else { - devicemapper.LogInitVerbose(devicemapper.LogLevelWarn) - } // give ourselves to libdm as a log handler devicemapper.LogInit(devices)