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>
... | ... |
@@ -70,9 +70,11 @@ var ( |
70 | 70 |
ErrLoopbackSetCapacity = errors.New("Unable set loopback capacity") |
71 | 71 |
ErrBusy = errors.New("Device is Busy") |
72 | 72 |
ErrDeviceIdExists = errors.New("Device Id Exists") |
73 |
+ ErrEnxio = errors.New("No such device or address") |
|
73 | 74 |
|
74 | 75 |
dmSawBusy bool |
75 | 76 |
dmSawExist bool |
77 |
+ dmSawEnxio bool // No Such Device or Address |
|
76 | 78 |
) |
77 | 79 |
|
78 | 80 |
type ( |
... | ... |
@@ -391,6 +393,36 @@ func RemoveDeviceDeferred(name string) error { |
391 | 391 |
return nil |
392 | 392 |
} |
393 | 393 |
|
394 |
+// Useful helper for cleanup |
|
395 |
+func CancelDeferredRemove(deviceName string) error { |
|
396 |
+ task, err := TaskCreateNamed(DeviceTargetMsg, deviceName) |
|
397 |
+ if task == nil { |
|
398 |
+ return err |
|
399 |
+ } |
|
400 |
+ |
|
401 |
+ if err := task.SetSector(0); err != nil { |
|
402 |
+ return fmt.Errorf("Can't set sector %s", err) |
|
403 |
+ } |
|
404 |
+ |
|
405 |
+ if err := task.SetMessage(fmt.Sprintf("@cancel_deferred_remove")); err != nil { |
|
406 |
+ return fmt.Errorf("Can't set message %s", err) |
|
407 |
+ } |
|
408 |
+ |
|
409 |
+ dmSawBusy = false |
|
410 |
+ dmSawEnxio = false |
|
411 |
+ if err := task.Run(); err != nil { |
|
412 |
+ // A device might be being deleted already |
|
413 |
+ if dmSawBusy { |
|
414 |
+ return ErrBusy |
|
415 |
+ } else if dmSawEnxio { |
|
416 |
+ return ErrEnxio |
|
417 |
+ } |
|
418 |
+ return fmt.Errorf("Error running CancelDeferredRemove %s", err) |
|
419 |
+ |
|
420 |
+ } |
|
421 |
+ return nil |
|
422 |
+} |
|
423 |
+ |
|
394 | 424 |
func GetBlockDeviceSize(file *os.File) (uint64, error) { |
395 | 425 |
size, err := ioctlBlkGetSize64(file.Fd()) |
396 | 426 |
if err != nil { |
... | ... |
@@ -22,6 +22,10 @@ func DevmapperLogCallback(level C.int, file *C.char, line C.int, dm_errno_or_cla |
22 | 22 |
if strings.Contains(msg, "File exists") { |
23 | 23 |
dmSawExist = true |
24 | 24 |
} |
25 |
+ |
|
26 |
+ if strings.Contains(msg, "No such device or address") { |
|
27 |
+ dmSawEnxio = true |
|
28 |
+ } |
|
25 | 29 |
} |
26 | 30 |
|
27 | 31 |
if dmLogger != nil { |