if initDevmapper failed after creating thin-pool, the thin-pool will not be removed,
this would cause we can't use the same lvm to create another thin-pool.
Signed-off-by: Lei Jitang <leijitang@huawei.com>
| ... | ... |
@@ -1686,7 +1686,7 @@ func (devices *DeviceSet) enableDeferredRemovalDeletion() error {
|
| 1686 | 1686 |
return nil |
| 1687 | 1687 |
} |
| 1688 | 1688 |
|
| 1689 |
-func (devices *DeviceSet) initDevmapper(doInit bool) error {
|
|
| 1689 |
+func (devices *DeviceSet) initDevmapper(doInit bool) (retErr error) {
|
|
| 1690 | 1690 |
// give ourselves to libdm as a log handler |
| 1691 | 1691 |
devicemapper.LogInit(devices) |
| 1692 | 1692 |
|
| ... | ... |
@@ -1840,6 +1840,14 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
|
| 1840 | 1840 |
if err := devicemapper.CreatePool(devices.getPoolName(), dataFile, metadataFile, devices.thinpBlockSize); err != nil {
|
| 1841 | 1841 |
return err |
| 1842 | 1842 |
} |
| 1843 |
+ defer func() {
|
|
| 1844 |
+ if retErr != nil {
|
|
| 1845 |
+ err = devices.deactivatePool() |
|
| 1846 |
+ if err != nil {
|
|
| 1847 |
+ logrus.Warnf("devmapper: Failed to deactivatePool: %v", err)
|
|
| 1848 |
+ } |
|
| 1849 |
+ } |
|
| 1850 |
+ }() |
|
| 1843 | 1851 |
} |
| 1844 | 1852 |
|
| 1845 | 1853 |
// Pool already exists and caller did not pass us a pool. That means |