From 7f1cdd81f07c29bdf2b9b82bfacddf620e169bf0 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Thu, 13 Nov 2014 17:20:24 -0500 Subject: [PATCH 1/2] pkg/devicemapper: cleanup removeDevice differences Fixes failure on RemoveDevice when host is AUFS, and running devicemapper test docker-in-docker https://gist.github.com/tonistiigi/59559cbfb3f2df26b29c Signed-off-by: Vincent Batts --- devicemapper/devmapper.go | 44 ++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/devicemapper/devmapper.go b/devicemapper/devmapper.go index c0b931c..87f5a1f 100644 --- a/devicemapper/devmapper.go +++ b/devicemapper/devmapper.go @@ -62,7 +62,7 @@ var ( ErrSetDevDir = errors.New("dm_set_dev_dir failed") ErrGetLibraryVersion = errors.New("dm_get_library_version failed") ErrCreateRemoveTask = errors.New("Can't create task of type DeviceRemove") - ErrRunRemoveDevice = errors.New("running removeDevice failed") + ErrRunRemoveDevice = errors.New("running RemoveDevice failed") ErrInvalidAddNode = errors.New("Invalide AddNoce type") ErrGetLoopbackBackingFile = errors.New("Unable to get loopback backing file") ErrLoopbackSetCapacity = errors.New("Unable set loopback capacity") @@ -296,18 +296,27 @@ func GetLibraryVersion() (string, error) { // Useful helper for cleanup func RemoveDevice(name string) error { - // TODO(vbatts) just use the other removeDevice() - task := TaskCreate(DeviceRemove) + log.Debugf("[devmapper] RemoveDevice START") + defer log.Debugf("[devmapper] RemoveDevice END") + task, err := createTask(DeviceRemove, name) if task == nil { - return ErrCreateRemoveTask - } - if err := task.SetName(name); err != nil { - log.Debugf("Can't set task name %s", name) return err } - if err := task.Run(); err != nil { - return ErrRunRemoveDevice + + var cookie uint = 0 + if err := task.SetCookie(&cookie, 0); err != nil { + return fmt.Errorf("Can not set cookie: %s", err) } + + if err = task.Run(); err != nil { + if dmSawBusy { + return ErrBusy + } + return fmt.Errorf("Error running RemoveDevice %s", err) + } + + UdevWait(cookie) + return nil } @@ -568,23 +577,6 @@ func DeleteDevice(poolName string, deviceId int) error { return nil } -func removeDevice(name string) error { - log.Debugf("[devmapper] RemoveDevice START") - defer log.Debugf("[devmapper] RemoveDevice END") - task, err := createTask(DeviceRemove, name) - if task == nil { - return err - } - dmSawBusy = false - if err = task.Run(); err != nil { - if dmSawBusy { - return ErrBusy - } - return fmt.Errorf("Error running RemoveDevice %s", err) - } - return nil -} - func ActivateDevice(poolName string, name string, deviceId int, size uint64) error { task, err := createTask(DeviceCreate, name) if task == nil { From 3bce14e7d02ce2d1ccdb93babb252485d0212cd1 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Fri, 14 Nov 2014 14:18:35 -0500 Subject: [PATCH 2/2] pkg/devicemapper: defer udev wait during removal Signed-off-by: Vincent Batts --- devicemapper/devmapper.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/devicemapper/devmapper.go b/devicemapper/devmapper.go index 87f5a1f..4043da6 100644 --- a/devicemapper/devmapper.go +++ b/devicemapper/devmapper.go @@ -307,7 +307,9 @@ func RemoveDevice(name string) error { if err := task.SetCookie(&cookie, 0); err != nil { return fmt.Errorf("Can not set cookie: %s", err) } + defer UdevWait(cookie) + dmSawBusy = false // reset before the task is run if err = task.Run(); err != nil { if dmSawBusy { return ErrBusy @@ -315,8 +317,6 @@ func RemoveDevice(name string) error { return fmt.Errorf("Error running RemoveDevice %s", err) } - UdevWait(cookie) - return nil } @@ -543,7 +543,7 @@ func CreateDevice(poolName string, deviceId *int) error { return fmt.Errorf("Can't set message %s", err) } - dmSawExist = false + dmSawExist = false // reset before the task is run if err := task.Run(); err != nil { if dmSawExist { // Already exists, try next id @@ -638,7 +638,7 @@ func CreateSnapDevice(poolName string, deviceId *int, baseName string, baseDevic return fmt.Errorf("Can't set message %s", err) } - dmSawExist = false + dmSawExist = false // reset before the task is run if err := task.Run(); err != nil { if dmSawExist { // Already exists, try next id