Browse code

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 <vgoyal@redhat.com>

Vivek Goyal authored on 2015/04/03 05:47:14
Showing 1 changed files
... ...
@@ -33,6 +33,10 @@ var (
33 33
 	DefaultThinpBlockSize       uint32 = 128      // 64K = 128 512b sectors
34 34
 	MaxDeviceId                 int    = 0xffffff // 24 bit, pool limit
35 35
 	DeviceIdMapSz               int    = (MaxDeviceId + 1) / 8
36
+	// We retry device removal so many a times that even error messages
37
+	// will fill up console during normal operation. So only log Fatal
38
+	// messages by default.
39
+	DMLogLevel int = devicemapper.LogLevelFatal
36 40
 )
37 41
 
38 42
 const deviceSetMetaFile string = "deviceset-metadata"
... ...
@@ -723,14 +727,22 @@ func setCloseOnExec(name string) {
723 723
 }
724 724
 
725 725
 func (devices *DeviceSet) DMLog(level int, file string, line int, dmError int, message string) {
726
-	if level >= devicemapper.LogLevelDebug {
727
-		// (vbatts) libdm debug is very verbose. If you're debugging libdm, you can
728
-		// comment out this check yourself
729
-		level = devicemapper.LogLevelInfo
726
+	// By default libdm sends us all the messages including debug ones.
727
+	// We need to filter out messages here and figure out which one
728
+	// should be printed.
729
+	if level > DMLogLevel {
730
+		return
730 731
 	}
731 732
 
732 733
 	// FIXME(vbatts) push this back into ./pkg/devicemapper/
733
-	logrus.Debugf("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message)
734
+	if level <= devicemapper.LogLevelErr {
735
+		logrus.Errorf("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message)
736
+	} else if level <= devicemapper.LogLevelInfo {
737
+		logrus.Infof("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message)
738
+	} else {
739
+		// FIXME(vbatts) push this back into ./pkg/devicemapper/
740
+		logrus.Debugf("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message)
741
+	}
734 742
 }
735 743
 
736 744
 func major(device uint64) uint64 {
... ...
@@ -947,11 +959,6 @@ func (devices *DeviceSet) closeTransaction() error {
947 947
 }
948 948
 
949 949
 func (devices *DeviceSet) initDevmapper(doInit bool) error {
950
-	if os.Getenv("DEBUG") != "" {
951
-		devicemapper.LogInitVerbose(devicemapper.LogLevelDebug)
952
-	} else {
953
-		devicemapper.LogInitVerbose(devicemapper.LogLevelWarn)
954
-	}
955 950
 	// give ourselves to libdm as a log handler
956 951
 	devicemapper.LogInit(devices)
957 952