Browse code

Devicemapper: ignore Nodata errors when delete thin device

if thin device is deteled and the metadata exists, you can not
delete related containers. This patch ignore Nodata errors for
thin device deletion

Signed-off-by: Liu Hua <sdu.liu@huawei.com>

Liu Hua authored on 2017/10/23 22:00:22
Showing 2 changed files
... ...
@@ -67,12 +67,14 @@ var (
67 67
 	ErrBusy                 = errors.New("Device is Busy")
68 68
 	ErrDeviceIDExists       = errors.New("Device Id Exists")
69 69
 	ErrEnxio                = errors.New("No such device or address")
70
+	ErrEnoData              = errors.New("No data available")
70 71
 )
71 72
 
72 73
 var (
73
-	dmSawBusy  bool
74
-	dmSawExist bool
75
-	dmSawEnxio bool // No Such Device or Address
74
+	dmSawBusy    bool
75
+	dmSawExist   bool
76
+	dmSawEnxio   bool // No Such Device or Address
77
+	dmSawEnoData bool // No data available
76 78
 )
77 79
 
78 80
 type (
... ...
@@ -708,10 +710,15 @@ func DeleteDevice(poolName string, deviceID int) error {
708 708
 	}
709 709
 
710 710
 	dmSawBusy = false
711
+	dmSawEnoData = false
711 712
 	if err := task.run(); err != nil {
712 713
 		if dmSawBusy {
713 714
 			return ErrBusy
714 715
 		}
716
+		if dmSawEnoData {
717
+			logrus.Debugf("devicemapper: Device(id: %d) from pool(%s) does not exist", deviceID, poolName)
718
+			return nil
719
+		}
715 720
 		return fmt.Errorf("devicemapper: Error running DeleteDevice %s", err)
716 721
 	}
717 722
 	return nil
... ...
@@ -55,6 +55,9 @@ func DevmapperLogCallback(level C.int, file *C.char, line, dmErrnoOrClass C.int,
55 55
 		if strings.Contains(msg, "No such device or address") {
56 56
 			dmSawEnxio = true
57 57
 		}
58
+		if strings.Contains(msg, "No data available") {
59
+			dmSawEnoData = true
60
+		}
58 61
 	}
59 62
 
60 63
 	if dmLogger != nil {