Merge pull request #8232 from vbatts/vbatts-devmapper_getDeps

devmapper: include dm_deps information in debug
This commit is contained in:
Michael Crosby 2014-10-16 14:13:21 -07:00
commit 2f9ffe5b6a
4 changed files with 49 additions and 4 deletions

View file

@ -771,10 +771,15 @@ func (devices *DeviceSet) deactivatePool() error {
log.Debugf("[devmapper] deactivatePool()")
defer log.Debugf("[devmapper] deactivatePool END")
devname := devices.getPoolDevName()
devinfo, err := getInfo(devname)
if err != nil {
return err
}
if d, err := getDeps(devname); err == nil {
// Access to more Debug output
log.Debugf("[devmapper] getDeps() %s: %#v", devname, d)
}
if devinfo.Exists != 0 {
return removeDevice(devname)
}

View file

@ -51,6 +51,7 @@ var (
ErrTaskSetRo = errors.New("dm_task_set_ro failed")
ErrTaskAddTarget = errors.New("dm_task_add_target failed")
ErrTaskSetSector = errors.New("dm_task_set_sector failed")
ErrTaskGetDeps = errors.New("dm_task_get_deps failed")
ErrTaskGetInfo = errors.New("dm_task_get_info failed")
ErrTaskGetDriverVersion = errors.New("dm_task_get_driver_version failed")
ErrTaskSetCookie = errors.New("dm_task_set_cookie failed")
@ -75,6 +76,11 @@ type (
Task struct {
unmanaged *CDmTask
}
Deps struct {
Count uint32
Filler uint32
Device []uint64
}
Info struct {
Exists int
Suspended int
@ -171,6 +177,14 @@ func (t *Task) AddTarget(start, size uint64, ttype, params string) error {
return nil
}
func (t *Task) GetDeps() (*Deps, error) {
var deps *Deps
if deps = DmTaskGetDeps(t.unmanaged); deps == nil {
return nil, ErrTaskGetDeps
}
return deps, nil
}
func (t *Task) GetInfo() (*Info, error) {
info := &Info{}
if res := DmTaskGetInfo(t.unmanaged, info); res != 1 {
@ -392,6 +406,17 @@ func createTask(t TaskType, name string) (*Task, error) {
return task, nil
}
func getDeps(name string) (*Deps, error) {
task, err := createTask(DeviceDeps, name)
if task == nil {
return nil, err
}
if err := task.Run(); err != nil {
return nil, err
}
return task.GetDeps()
}
func getInfo(name string) (*Info, error) {
task, err := createTask(DeviceInfo, name)
if task == nil {

View file

@ -3,8 +3,9 @@
package devmapper
import (
"github.com/docker/docker/daemon/graphdriver/graphtest"
"testing"
"github.com/docker/docker/daemon/graphdriver/graphtest"
)
func init() {

View file

@ -38,9 +38,7 @@ static void log_with_errno_init()
*/
import "C"
import (
"unsafe"
)
import "unsafe"
type (
CDmTask C.struct_dm_task
@ -92,6 +90,7 @@ var (
DmTaskAddTarget = dmTaskAddTargetFct
DmTaskCreate = dmTaskCreateFct
DmTaskDestroy = dmTaskDestroyFct
DmTaskGetDeps = dmTaskGetDepsFct
DmTaskGetInfo = dmTaskGetInfoFct
DmTaskGetDriverVersion = dmTaskGetDriverVersionFct
DmTaskRun = dmTaskRunFct
@ -168,6 +167,21 @@ func dmTaskAddTargetFct(task *CDmTask,
return int(C.dm_task_add_target((*C.struct_dm_task)(task), C.uint64_t(start), C.uint64_t(size), Cttype, Cparams))
}
func dmTaskGetDepsFct(task *CDmTask) *Deps {
Cdeps := C.dm_task_get_deps((*C.struct_dm_task)(task))
if Cdeps == nil {
return nil
}
deps := &Deps{
Count: uint32(Cdeps.count),
Filler: uint32(Cdeps.filler),
}
for _, device := range Cdeps.device {
deps.Device = append(deps.Device, (uint64)(device))
}
return deps
}
func dmTaskGetInfoFct(task *CDmTask, info *Info) int {
Cinfo := C.struct_dm_info{}
defer func() {