| ... | ... |
@@ -327,7 +327,18 @@ func setCloseOnExec(name string) {
|
| 327 | 327 |
} |
| 328 | 328 |
} |
| 329 | 329 |
|
| 330 |
+func (devices *DeviceSetDM) log(level int, file string, line int, dmError int, message string) {
|
|
| 331 |
+ if level >= 7 {
|
|
| 332 |
+ return // Ignore _LOG_DEBUG |
|
| 333 |
+ } |
|
| 334 |
+ |
|
| 335 |
+ utils.Debugf("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message)
|
|
| 336 |
+} |
|
| 337 |
+ |
|
| 338 |
+ |
|
| 330 | 339 |
func (devices *DeviceSetDM) initDevmapper() error {
|
| 340 |
+ logInit(devices) |
|
| 341 |
+ |
|
| 331 | 342 |
info, err := getInfo(devices.getPoolName()) |
| 332 | 343 |
if info == nil {
|
| 333 | 344 |
utils.Debugf("Error device getInfo: %s", err)
|
| ... | ... |
@@ -114,6 +114,28 @@ get_block_size(int fd) |
| 114 | 114 |
return (int64_t)size; |
| 115 | 115 |
} |
| 116 | 116 |
|
| 117 |
+extern void DevmapperLogCallback(int level, char *file, int line, int dm_errno_or_class, char *str); |
|
| 118 |
+ |
|
| 119 |
+static void |
|
| 120 |
+log_cb(int level, const char *file, int line, |
|
| 121 |
+ int dm_errno_or_class, const char *f, ...) |
|
| 122 |
+{
|
|
| 123 |
+ char buffer[256]; |
|
| 124 |
+ va_list ap; |
|
| 125 |
+ |
|
| 126 |
+ va_start(ap, f); |
|
| 127 |
+ vsnprintf(buffer, 256, f, ap); |
|
| 128 |
+ va_end(ap); |
|
| 129 |
+ |
|
| 130 |
+ DevmapperLogCallback(level, (char *)file, line, dm_errno_or_class, buffer); |
|
| 131 |
+} |
|
| 132 |
+ |
|
| 133 |
+static void |
|
| 134 |
+log_with_errno_init () |
|
| 135 |
+{
|
|
| 136 |
+ dm_log_with_errno_init(log_cb); |
|
| 137 |
+} |
|
| 138 |
+ |
|
| 117 | 139 |
*/ |
| 118 | 140 |
import "C" |
| 119 | 141 |
|
| ... | ... |
@@ -127,6 +149,10 @@ import ( |
| 127 | 127 |
"unsafe" |
| 128 | 128 |
) |
| 129 | 129 |
|
| 130 |
+type DevmapperLogger interface {
|
|
| 131 |
+ log(level int, file string, line int, dmError int, message string) |
|
| 132 |
+} |
|
| 133 |
+ |
|
| 130 | 134 |
const ( |
| 131 | 135 |
DeviceCreate TaskType = iota |
| 132 | 136 |
DeviceReload |
| ... | ... |
@@ -351,6 +377,13 @@ func LogInitVerbose(level int) {
|
| 351 | 351 |
C.dm_log_init_verbose(C.int(level)) |
| 352 | 352 |
} |
| 353 | 353 |
|
| 354 |
+var dmLogger DevmapperLogger = nil |
|
| 355 |
+ |
|
| 356 |
+func logInit(logger DevmapperLogger) {
|
|
| 357 |
+ dmLogger = logger |
|
| 358 |
+ C.log_with_errno_init() |
|
| 359 |
+} |
|
| 360 |
+ |
|
| 354 | 361 |
func SetDevDir(dir string) error {
|
| 355 | 362 |
c_dir := C.CString(dir) |
| 356 | 363 |
defer free(c_dir) |
| 357 | 364 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,13 @@ |
| 0 |
+package devmapper |
|
| 1 |
+ |
|
| 2 |
+import "C" |
|
| 3 |
+ |
|
| 4 |
+// Due to the way cgo works this has to be in a separate file, as devmapper.go has |
|
| 5 |
+// definitions in the cgo block, which is incompatible with using "//export" |
|
| 6 |
+ |
|
| 7 |
+//export DevmapperLogCallback |
|
| 8 |
+func DevmapperLogCallback(level C.int, file *C.char, line C.int, dm_errno_or_class C.int, message *C.char) {
|
|
| 9 |
+ if dmLogger != nil {
|
|
| 10 |
+ dmLogger.log(int(level), C.GoString(file), int(line), int(dm_errno_or_class), C.GoString(message)) |
|
| 11 |
+ } |
|
| 12 |
+} |