devicemapper: Create helpers to cancel deferred deactivation

If a device has been scheduled for deferred deactivation and container
is started again and we need to activate device again, we need to cancel
the deferred deactivation which is already scheduled on the device.

Create a method for the same.

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
This commit is contained in:
Vivek Goyal 2015-04-21 18:14:59 -04:00
parent 64ffdbc701
commit 48536e29e5
2 changed files with 36 additions and 0 deletions

View file

@ -70,9 +70,11 @@ var (
ErrLoopbackSetCapacity = errors.New("Unable set loopback capacity") ErrLoopbackSetCapacity = errors.New("Unable set loopback capacity")
ErrBusy = errors.New("Device is Busy") ErrBusy = errors.New("Device is Busy")
ErrDeviceIdExists = errors.New("Device Id Exists") ErrDeviceIdExists = errors.New("Device Id Exists")
ErrEnxio = errors.New("No such device or address")
dmSawBusy bool dmSawBusy bool
dmSawExist bool dmSawExist bool
dmSawEnxio bool // No Such Device or Address
) )
type ( type (
@ -391,6 +393,36 @@ func RemoveDeviceDeferred(name string) error {
return nil return nil
} }
// Useful helper for cleanup
func CancelDeferredRemove(deviceName string) error {
task, err := TaskCreateNamed(DeviceTargetMsg, deviceName)
if task == nil {
return err
}
if err := task.SetSector(0); err != nil {
return fmt.Errorf("Can't set sector %s", err)
}
if err := task.SetMessage(fmt.Sprintf("@cancel_deferred_remove")); err != nil {
return fmt.Errorf("Can't set message %s", err)
}
dmSawBusy = false
dmSawEnxio = false
if err := task.Run(); err != nil {
// A device might be being deleted already
if dmSawBusy {
return ErrBusy
} else if dmSawEnxio {
return ErrEnxio
}
return fmt.Errorf("Error running CancelDeferredRemove %s", err)
}
return nil
}
func GetBlockDeviceSize(file *os.File) (uint64, error) { func GetBlockDeviceSize(file *os.File) (uint64, error) {
size, err := ioctlBlkGetSize64(file.Fd()) size, err := ioctlBlkGetSize64(file.Fd())
if err != nil { if err != nil {

View file

@ -22,6 +22,10 @@ func DevmapperLogCallback(level C.int, file *C.char, line C.int, dm_errno_or_cla
if strings.Contains(msg, "File exists") { if strings.Contains(msg, "File exists") {
dmSawExist = true dmSawExist = true
} }
if strings.Contains(msg, "No such device or address") {
dmSawEnxio = true
}
} }
if dmLogger != nil { if dmLogger != nil {