mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
device-mapper: Move all devicemapper spew to log through utils.Debugf().
This commit is contained in:
parent
c77697a45c
commit
b440ec0136
3 changed files with 57 additions and 0 deletions
|
@ -327,7 +327,18 @@ func setCloseOnExec(name string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (devices *DeviceSetDM) log(level int, file string, line int, dmError int, message string) {
|
||||||
|
if level >= 7 {
|
||||||
|
return // Ignore _LOG_DEBUG
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.Debugf("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func (devices *DeviceSetDM) initDevmapper() error {
|
func (devices *DeviceSetDM) initDevmapper() error {
|
||||||
|
logInit(devices)
|
||||||
|
|
||||||
info, err := getInfo(devices.getPoolName())
|
info, err := getInfo(devices.getPoolName())
|
||||||
if info == nil {
|
if info == nil {
|
||||||
utils.Debugf("Error device getInfo: %s", err)
|
utils.Debugf("Error device getInfo: %s", err)
|
||||||
|
|
|
@ -114,6 +114,28 @@ get_block_size(int fd)
|
||||||
return (int64_t)size;
|
return (int64_t)size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern void DevmapperLogCallback(int level, char *file, int line, int dm_errno_or_class, char *str);
|
||||||
|
|
||||||
|
static void
|
||||||
|
log_cb(int level, const char *file, int line,
|
||||||
|
int dm_errno_or_class, const char *f, ...)
|
||||||
|
{
|
||||||
|
char buffer[256];
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, f);
|
||||||
|
vsnprintf(buffer, 256, f, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
DevmapperLogCallback(level, (char *)file, line, dm_errno_or_class, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
log_with_errno_init ()
|
||||||
|
{
|
||||||
|
dm_log_with_errno_init(log_cb);
|
||||||
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
@ -127,6 +149,10 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type DevmapperLogger interface {
|
||||||
|
log(level int, file string, line int, dmError int, message string)
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DeviceCreate TaskType = iota
|
DeviceCreate TaskType = iota
|
||||||
DeviceReload
|
DeviceReload
|
||||||
|
@ -351,6 +377,13 @@ func LogInitVerbose(level int) {
|
||||||
C.dm_log_init_verbose(C.int(level))
|
C.dm_log_init_verbose(C.int(level))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dmLogger DevmapperLogger = nil
|
||||||
|
|
||||||
|
func logInit(logger DevmapperLogger) {
|
||||||
|
dmLogger = logger
|
||||||
|
C.log_with_errno_init()
|
||||||
|
}
|
||||||
|
|
||||||
func SetDevDir(dir string) error {
|
func SetDevDir(dir string) error {
|
||||||
c_dir := C.CString(dir)
|
c_dir := C.CString(dir)
|
||||||
defer free(c_dir)
|
defer free(c_dir)
|
||||||
|
|
13
devmapper/devmapper_log.go
Normal file
13
devmapper/devmapper_log.go
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package devmapper
|
||||||
|
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
// Due to the way cgo works this has to be in a separate file, as devmapper.go has
|
||||||
|
// definitions in the cgo block, which is incompatible with using "//export"
|
||||||
|
|
||||||
|
//export DevmapperLogCallback
|
||||||
|
func DevmapperLogCallback(level C.int, file *C.char, line C.int, dm_errno_or_class C.int, message *C.char) {
|
||||||
|
if dmLogger != nil {
|
||||||
|
dmLogger.log(int(level), C.GoString(file), int(line), int(dm_errno_or_class), C.GoString(message))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue