Merge pull request #9164 from vbatts/vbatts-dm_removedevice

pkg/devicemapper: cleanup removeDevice differences
This commit is contained in:
Michael Crosby 2014-11-14 16:56:02 -08:00
commit d246e5f28e

View file

@ -62,7 +62,7 @@ var (
ErrSetDevDir = errors.New("dm_set_dev_dir failed") ErrSetDevDir = errors.New("dm_set_dev_dir failed")
ErrGetLibraryVersion = errors.New("dm_get_library_version failed") ErrGetLibraryVersion = errors.New("dm_get_library_version failed")
ErrCreateRemoveTask = errors.New("Can't create task of type DeviceRemove") 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") ErrInvalidAddNode = errors.New("Invalide AddNoce type")
ErrGetLoopbackBackingFile = errors.New("Unable to get loopback backing file") ErrGetLoopbackBackingFile = errors.New("Unable to get loopback backing file")
ErrLoopbackSetCapacity = errors.New("Unable set loopback capacity") ErrLoopbackSetCapacity = errors.New("Unable set loopback capacity")
@ -296,18 +296,27 @@ func GetLibraryVersion() (string, error) {
// Useful helper for cleanup // Useful helper for cleanup
func RemoveDevice(name string) error { func RemoveDevice(name string) error {
// TODO(vbatts) just use the other removeDevice() log.Debugf("[devmapper] RemoveDevice START")
task := TaskCreate(DeviceRemove) defer log.Debugf("[devmapper] RemoveDevice END")
task, err := createTask(DeviceRemove, name)
if task == nil { if task == nil {
return ErrCreateRemoveTask
}
if err := task.SetName(name); err != nil {
log.Debugf("Can't set task name %s", name)
return err 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)
} }
defer UdevWait(cookie)
dmSawBusy = false // reset before the task is run
if err = task.Run(); err != nil {
if dmSawBusy {
return ErrBusy
}
return fmt.Errorf("Error running RemoveDevice %s", err)
}
return nil return nil
} }
@ -534,7 +543,7 @@ func CreateDevice(poolName string, deviceId *int) error {
return fmt.Errorf("Can't set message %s", err) 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 err := task.Run(); err != nil {
if dmSawExist { if dmSawExist {
// Already exists, try next id // Already exists, try next id
@ -568,23 +577,6 @@ func DeleteDevice(poolName string, deviceId int) error {
return nil 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 { func ActivateDevice(poolName string, name string, deviceId int, size uint64) error {
task, err := createTask(DeviceCreate, name) task, err := createTask(DeviceCreate, name)
if task == nil { if task == nil {
@ -646,7 +638,7 @@ func CreateSnapDevice(poolName string, deviceId *int, baseName string, baseDevic
return fmt.Errorf("Can't set message %s", err) 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 err := task.Run(); err != nil {
if dmSawExist { if dmSawExist {
// Already exists, try next id // Already exists, try next id