devmapper_log.go 817 B

1234567891011121314151617181920212223242526272829303132333435
  1. // +build linux,cgo
  2. package devicemapper
  3. import "C"
  4. import (
  5. "strings"
  6. )
  7. // Due to the way cgo works this has to be in a separate file, as devmapper.go has
  8. // definitions in the cgo block, which is incompatible with using "//export"
  9. // DevmapperLogCallback exports the devmapper log callback for cgo.
  10. //export DevmapperLogCallback
  11. func DevmapperLogCallback(level C.int, file *C.char, line C.int, dmErrnoOrClass C.int, message *C.char) {
  12. msg := C.GoString(message)
  13. if level < 7 {
  14. if strings.Contains(msg, "busy") {
  15. dmSawBusy = true
  16. }
  17. if strings.Contains(msg, "File exists") {
  18. dmSawExist = true
  19. }
  20. if strings.Contains(msg, "No such device or address") {
  21. dmSawEnxio = true
  22. }
  23. }
  24. if dmLogger != nil {
  25. dmLogger.DMLog(int(level), C.GoString(file), int(line), int(dmErrnoOrClass), msg)
  26. }
  27. }