[lxc-devel] [lxd/master] storage: don't fail on non existent storage entities
brauner on Github
lxc-bot at linuxcontainers.org
Wed Sep 20 11:37:57 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170920/4ea3253a/attachment.bin>
-------------- next part --------------
From dc647553d1094f426ec68ed1337a6e23841efd84 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 12:37:52 +0200
Subject: [PATCH 01/15] zfs: existence check before delete for pools
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_zfs.go | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index a2f6445f3..3e4ee465b 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -323,9 +323,12 @@ func (s *storageZfs) zfsPoolCreate() error {
func (s *storageZfs) StoragePoolDelete() error {
logger.Infof("Deleting ZFS storage pool \"%s\".", s.pool.Name)
- err := zfsFilesystemEntityDelete(s.pool.Config["source"], s.getOnDiskPoolName())
- if err != nil {
- return err
+ poolName := s.getOnDiskPoolName()
+ if zfsFilesystemEntityExists(poolName, "") {
+ err := zfsFilesystemEntityDelete(s.pool.Config["source"], poolName)
+ if err != nil {
+ return err
+ }
}
storagePoolMntPoint := getStoragePoolMountPoint(s.pool.Name)
From 35f6d813e964d3f861636fdd1a1cf760af6a6076 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 12:41:38 +0200
Subject: [PATCH 02/15] zfs: existence check before custom delete
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_zfs.go | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index 3e4ee465b..0776d0f02 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -406,9 +406,12 @@ func (s *storageZfs) StoragePoolVolumeDelete() error {
fs := fmt.Sprintf("custom/%s", s.volume.Name)
customPoolVolumeMntPoint := getStoragePoolVolumeMountPoint(s.pool.Name, s.volume.Name)
- err := zfsPoolVolumeDestroy(s.getOnDiskPoolName(), fs)
- if err != nil {
- return err
+ poolName := s.getOnDiskPoolName()
+ if zfsFilesystemEntityExists(poolName, fs) {
+ err := zfsPoolVolumeDestroy(s.getOnDiskPoolName(), fs)
+ if err != nil {
+ return err
+ }
}
if shared.PathExists(customPoolVolumeMntPoint) {
@@ -418,7 +421,7 @@ func (s *storageZfs) StoragePoolVolumeDelete() error {
}
}
- err = db.StoragePoolVolumeDelete(
+ err := db.StoragePoolVolumeDelete(
s.s.DB,
s.volume.Name,
storagePoolVolumeTypeCustom,
From 1def4ffba5d73ca8a838af20527fbbb5bf740be7 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 12:46:36 +0200
Subject: [PATCH 03/15] btrfs: existence check before custom delete
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_btrfs.go | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index b78b415ad..b6216bd87 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -548,9 +548,11 @@ func (s *storageBtrfs) StoragePoolVolumeDelete() error {
// Delete subvolume.
customSubvolumeName := getStoragePoolVolumeMountPoint(s.pool.Name, s.volume.Name)
- err = btrfsSubVolumesDelete(customSubvolumeName)
- if err != nil {
- return err
+ if shared.PathExists(customSubvolumeName) && isBtrfsSubVolume(customSubvolumeName) {
+ err = btrfsSubVolumesDelete(customSubvolumeName)
+ if err != nil {
+ return err
+ }
}
// Delete the mountpoint.
From f4cae1384524710b24d93fc3760a94a25f90374b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 12:48:00 +0200
Subject: [PATCH 04/15] btrfs: existence check before container delete
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_btrfs.go | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index b6216bd87..7e38d3311 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -778,9 +778,11 @@ func (s *storageBtrfs) ContainerDelete(container container) error {
// Delete the subvolume.
containerSubvolumeName := getContainerMountPoint(s.pool.Name, container.Name())
- err = btrfsSubVolumesDelete(containerSubvolumeName)
- if err != nil {
- return err
+ if shared.PathExists(containerSubvolumeName) && isBtrfsSubVolume(containerSubvolumeName) {
+ err = btrfsSubVolumesDelete(containerSubvolumeName)
+ if err != nil {
+ return err
+ }
}
// Delete the container's symlink to the subvolume.
From 563fe49a18a10d0c18a26092f90f546fcd902840 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 12:49:49 +0200
Subject: [PATCH 05/15] btrfs: existence check before snapshot delete
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_btrfs.go | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index 7e38d3311..e3d7c59e3 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -1159,9 +1159,11 @@ func (s *storageBtrfs) ContainerSnapshotDelete(snapshotContainer container) erro
}
snapshotSubvolumeName := getSnapshotMountPoint(s.pool.Name, snapshotContainer.Name())
- err = btrfsSubVolumesDelete(snapshotSubvolumeName)
- if err != nil {
- return err
+ if shared.PathExists(snapshotSubvolumeName) && isBtrfsSubVolume(snapshotSubvolumeName) {
+ err = btrfsSubVolumesDelete(snapshotSubvolumeName)
+ if err != nil {
+ return err
+ }
}
sourceSnapshotMntPoint := shared.VarPath("snapshots", snapshotContainer.Name())
@@ -1224,9 +1226,11 @@ func (s *storageBtrfs) ContainerSnapshotStop(container container) (bool, error)
return false, nil
}
- err = btrfsSubVolumesDelete(snapshotSubvolumeName)
- if err != nil {
- return false, err
+ if shared.PathExists(snapshotSubvolumeName) && isBtrfsSubVolume(snapshotSubvolumeName) {
+ err = btrfsSubVolumesDelete(snapshotSubvolumeName)
+ if err != nil {
+ return false, err
+ }
}
err = os.Rename(roSnapshotSubvolumeName, snapshotSubvolumeName)
From 75d6a616bd90f12df8816f5ff64cada6df6bb735 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 12:55:32 +0200
Subject: [PATCH 06/15] btrfs: existence check before image delete
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_btrfs.go | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index e3d7c59e3..815fc653f 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -1398,9 +1398,11 @@ func (s *storageBtrfs) ImageDelete(fingerprint string) error {
// Delete the btrfs subvolume. The path with which we
// do this is ${LXD_DIR}/storage-pools/<pool>/images/<fingerprint>.
imageSubvolumeName := getImageMountPoint(s.pool.Name, fingerprint)
- err = btrfsSubVolumesDelete(imageSubvolumeName)
- if err != nil {
- return err
+ if shared.PathExists(imageSubvolumeName) && isBtrfsSubVolume(imageSubvolumeName) {
+ err = btrfsSubVolumesDelete(imageSubvolumeName)
+ if err != nil {
+ return err
+ }
}
err = s.deleteImageDbPoolVolume(fingerprint)
From b68dd63deb02522e9e206cf084a34affda364ced Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 13:02:56 +0200
Subject: [PATCH 07/15] lvm: existence check before pool delete
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_lvm.go | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index ece80e331..336a5b1cc 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -331,8 +331,10 @@ func (s *storageLvm) StoragePoolDelete() error {
}
poolName := s.getOnDiskPoolName()
+ poolExists, _ := storageVGExists(poolName)
+
// Delete the thinpool.
- if s.useThinpool {
+ if s.useThinpool && poolExists {
// Check that the thinpool actually exists. For example, it
// won't when the user has never created a storage volume in the
// storage pool.
@@ -357,7 +359,7 @@ func (s *storageLvm) StoragePoolDelete() error {
}
// Remove the volume group.
- if count == 0 {
+ if count == 0 && poolExists {
output, err := shared.TryRunCommand("vgremove", "-f", poolName)
if err != nil {
logger.Errorf("failed to destroy the volume group for the lvm storage pool: %s", output)
From 559c04677c2f328313359686d225b0188319068d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 13:06:48 +0200
Subject: [PATCH 08/15] lvm: existence check before custom delete
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_lvm.go | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index 336a5b1cc..710d71994 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -523,10 +523,16 @@ func (s *storageLvm) StoragePoolVolumeCreate() error {
func (s *storageLvm) StoragePoolVolumeDelete() error {
logger.Infof("Deleting LVM storage volume \"%s\" on storage pool \"%s\".", s.volume.Name, s.pool.Name)
- customPoolVolumeMntPoint := getStoragePoolVolumeMountPoint(s.pool.Name, s.volume.Name)
- _, err := s.StoragePoolVolumeUmount()
- if err != nil {
- return err
+ poolName := s.getOnDiskPoolName()
+ customLvmDevPath := getLvmDevPath(poolName,
+ storagePoolVolumeAPIEndpointCustom, s.volume.Name)
+ lvExists, _ := storageLVExists(customLvmDevPath)
+
+ if lvExists {
+ _, err := s.StoragePoolVolumeUmount()
+ if err != nil {
+ return err
+ }
}
volumeType, err := storagePoolVolumeTypeNameToAPIEndpoint(s.volume.Type)
@@ -534,12 +540,14 @@ func (s *storageLvm) StoragePoolVolumeDelete() error {
return err
}
- poolName := s.getOnDiskPoolName()
- err = s.removeLV(poolName, volumeType, s.volume.Name)
- if err != nil {
- return err
+ if lvExists {
+ err = s.removeLV(poolName, volumeType, s.volume.Name)
+ if err != nil {
+ return err
+ }
}
+ customPoolVolumeMntPoint := getStoragePoolVolumeMountPoint(s.pool.Name, s.volume.Name)
if shared.PathExists(customPoolVolumeMntPoint) {
err := os.Remove(customPoolVolumeMntPoint)
if err != nil {
From 24b9aca92bd10ec04c04bc34bfa11d609159d8f2 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 13:11:42 +0200
Subject: [PATCH 09/15] lvm: existence check before container delete
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_lvm.go | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index 710d71994..98d053c9d 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -1008,21 +1008,27 @@ func (s *storageLvm) ContainerDelete(container container) error {
}
poolName := s.getOnDiskPoolName()
- err := s.removeLV(poolName, storagePoolVolumeAPIEndpointContainers, containerLvmName)
- if err != nil {
- return err
+ containerLvmDevPath := getLvmDevPath(poolName,
+ storagePoolVolumeAPIEndpointContainers, containerLvmName)
+ lvExists, _ := storageLVExists(containerLvmDevPath)
+
+ if lvExists {
+ err := s.removeLV(poolName, storagePoolVolumeAPIEndpointContainers, containerLvmName)
+ if err != nil {
+ return err
+ }
}
if container.IsSnapshot() {
sourceName, _, _ := containerGetParentAndSnapshotName(containerName)
snapshotMntPointSymlinkTarget := shared.VarPath("storage-pools", s.pool.Name, "snapshots", sourceName)
snapshotMntPointSymlink := shared.VarPath("snapshots", sourceName)
- err = deleteSnapshotMountpoint(containerMntPoint, snapshotMntPointSymlinkTarget, snapshotMntPointSymlink)
+ err := deleteSnapshotMountpoint(containerMntPoint, snapshotMntPointSymlinkTarget, snapshotMntPointSymlink)
if err != nil {
return err
}
} else {
- err = deleteContainerMountpoint(containerMntPoint, container.Path(), s.GetStorageTypeName())
+ err := deleteContainerMountpoint(containerMntPoint, container.Path(), s.GetStorageTypeName())
if err != nil {
return err
}
From 05f5a82c64fcaa4c776fc7c1cca4f9335f02b2f6 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 13:13:59 +0200
Subject: [PATCH 10/15] lvm: existence check before image delete
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_lvm.go | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index 98d053c9d..871e2ce26 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -1583,15 +1583,21 @@ func (s *storageLvm) ImageDelete(fingerprint string) error {
logger.Debugf("Deleting LVM storage volume for image \"%s\" on storage pool \"%s\".", fingerprint, s.pool.Name)
if s.useThinpool {
- _, err := s.ImageUmount(fingerprint)
- if err != nil {
- return err
- }
-
poolName := s.getOnDiskPoolName()
- err = s.removeLV(poolName, storagePoolVolumeAPIEndpointImages, fingerprint)
- if err != nil {
- return err
+ imageLvmDevPath := getLvmDevPath(poolName,
+ storagePoolVolumeAPIEndpointImages, fingerprint)
+ lvExists, _ := storageLVExists(imageLvmDevPath)
+
+ if lvExists {
+ _, err := s.ImageUmount(fingerprint)
+ if err != nil {
+ return err
+ }
+
+ err = s.removeLV(poolName, storagePoolVolumeAPIEndpointImages, fingerprint)
+ if err != nil {
+ return err
+ }
}
}
From 6ecf25a3905d2bf700d5e3397eb5ca0bc95f3eb3 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 13:17:17 +0200
Subject: [PATCH 11/15] ceph: existence check before pool delete
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_ceph.go | 41 ++++++++++++++++++++++-------------------
1 file changed, 22 insertions(+), 19 deletions(-)
diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index c73a4b4d8..589d9133e 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -270,11 +270,10 @@ func (s *storageCeph) StoragePoolDelete() error {
s.pool.Name, s.ClusterName)
// test if pool exists
- if !cephOSDPoolExists(s.ClusterName, s.OSDPoolName, s.UserName) {
- msg := fmt.Sprintf(`CEPH osd storage pool "%s" does not exist `+
+ poolExists := cephOSDPoolExists(s.ClusterName, s.OSDPoolName, s.UserName)
+ if !poolExists {
+ logger.Warnf(`CEPH osd storage pool "%s" does not exist `+
`in cluster "%s"`, s.OSDPoolName, s.ClusterName)
- logger.Errorf(msg)
- return fmt.Errorf(msg)
}
// Check whether we own the pool and only remove in this case.
@@ -285,13 +284,15 @@ func (s *storageCeph) StoragePoolDelete() error {
s.OSDPoolName, s.ClusterName)
// Delete the osd pool.
- err := cephOSDPoolDestroy(s.ClusterName, s.OSDPoolName,
- s.UserName)
- if err != nil {
- logger.Errorf(`Failed to delete CEPH OSD storage pool `+
- `"%s" in cluster "%s": %s`, s.pool.Name,
- s.ClusterName, err)
- return err
+ if poolExists {
+ err := cephOSDPoolDestroy(s.ClusterName, s.OSDPoolName,
+ s.UserName)
+ if err != nil {
+ logger.Errorf(`Failed to delete CEPH OSD storage pool `+
+ `"%s" in cluster "%s": %s`, s.pool.Name,
+ s.ClusterName, err)
+ return err
+ }
}
logger.Debugf(`Deleted CEPH OSD storage pool "%s" in cluster "%s"`,
s.pool.Name, s.ClusterName)
@@ -299,15 +300,17 @@ func (s *storageCeph) StoragePoolDelete() error {
// Delete the mountpoint for the storage pool.
poolMntPoint := getStoragePoolMountPoint(s.pool.Name)
- err := os.RemoveAll(poolMntPoint)
- if err != nil {
- logger.Errorf(`Failed to delete mountpoint "%s" for CEPH osd `+
- `storage pool "%s" in cluster "%s": %s`, poolMntPoint,
- s.OSDPoolName, s.ClusterName, err)
- return err
+ if shared.PathExists(poolMntPoint) {
+ err := os.RemoveAll(poolMntPoint)
+ if err != nil {
+ logger.Errorf(`Failed to delete mountpoint "%s" for CEPH osd `+
+ `storage pool "%s" in cluster "%s": %s`, poolMntPoint,
+ s.OSDPoolName, s.ClusterName, err)
+ return err
+ }
+ logger.Debugf(`Deleted mountpoint "%s" for CEPH osd storage pool "%s" `+
+ `in cluster "%s"`, poolMntPoint, s.OSDPoolName, s.ClusterName)
}
- logger.Debugf(`Deleted mountpoint "%s" for CEPH osd storage pool "%s" `+
- `in cluster "%s"`, poolMntPoint, s.OSDPoolName, s.ClusterName)
logger.Infof(`Deleted CEPH OSD storage pool "%s" in cluster "%s"`,
s.pool.Name, s.ClusterName)
From c96077ac97ba329f0173ca734fa08372623d14db Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 13:21:58 +0200
Subject: [PATCH 12/15] ceph: existence check before custom delete
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_ceph.go | 48 +++++++++++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 21 deletions(-)
diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index 589d9133e..7ac397bf5 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -494,27 +494,31 @@ func (s *storageCeph) StoragePoolVolumeDelete() error {
`pool "%s"`, s.volume.Name, s.pool.Name)
}
+ rbdVolumeExists := cephRBDVolumeExists(s.ClusterName, s.OSDPoolName,
+ s.volume.Name, storagePoolVolumeTypeNameCustom, s.UserName)
// unmap
err := cephRBDVolumeUnmap(s.ClusterName, s.OSDPoolName, s.volume.Name,
storagePoolVolumeTypeNameCustom, s.UserName, true)
if err != nil {
- logger.Errorf(`Failed to unmap RBD storage volume "%s" on `+
+ logger.Warnf(`Failed to unmap RBD storage volume "%s" on `+
`storage pool "%s": %s`, s.volume.Name, s.pool.Name, err)
- return err
+ } else {
+ logger.Debugf(`Unmapped RBD storage volume "%s" on storage `+
+ `pool "%s"`, s.volume.Name, s.pool.Name)
}
- logger.Debugf(`Unmapped RBD storage volume "%s" on storage pool "%s"`,
- s.volume.Name, s.pool.Name)
// delete
- err = cephRBDVolumeDelete(s.ClusterName, s.OSDPoolName, s.volume.Name,
- storagePoolVolumeTypeNameCustom, s.UserName)
- if err != nil {
- logger.Errorf(`Failed to delete RBD storage volume "%s" on `+
- `storage pool "%s": %s`, s.volume.Name, s.pool.Name, err)
- return err
+ if rbdVolumeExists {
+ err := cephRBDVolumeDelete(s.ClusterName, s.OSDPoolName, s.volume.Name,
+ storagePoolVolumeTypeNameCustom, s.UserName)
+ if err != nil {
+ logger.Errorf(`Failed to delete RBD storage volume "%s" on `+
+ `storage pool "%s": %s`, s.volume.Name, s.pool.Name, err)
+ return err
+ }
+ logger.Debugf(`Deleted RBD storage volume "%s" on storage pool "%s"`,
+ s.volume.Name, s.pool.Name)
}
- logger.Debugf(`Deleted RBD storage volume "%s" on storage pool "%s"`,
- s.volume.Name, s.pool.Name)
err = db.StoragePoolVolumeDelete(
s.s.DB,
@@ -529,16 +533,18 @@ func (s *storageCeph) StoragePoolVolumeDelete() error {
logger.Debugf(`Deleted database entry for RBD storage volume "%s" on `+
`storage pool "%s"`, s.volume.Name, s.pool.Name)
- err = os.Remove(volumeMntPoint)
- if err != nil {
- logger.Errorf(`Failed to delete mountpoint "%s" for RBD `+
- `storage volume "%s" on storage pool "%s": %s"`,
- volumeMntPoint, s.volume.Name, s.pool.Name, err)
- return err
+ if shared.PathExists(volumeMntPoint) {
+ err = os.Remove(volumeMntPoint)
+ if err != nil {
+ logger.Errorf(`Failed to delete mountpoint "%s" for RBD `+
+ `storage volume "%s" on storage pool "%s": %s"`,
+ volumeMntPoint, s.volume.Name, s.pool.Name, err)
+ return err
+ }
+ logger.Debugf(`Deleted mountpoint "%s" for RBD storage volume "%s" `+
+ `on storage pool "%s"`, volumeMntPoint, s.volume.Name,
+ s.pool.Name)
}
- logger.Debugf(`Deleted mountpoint "%s" for RBD storage volume "%s" `+
- `on storage pool "%s"`, volumeMntPoint, s.volume.Name,
- s.pool.Name)
logger.Debugf(`Deleted RBD storage volume "%s" on storage pool "%s"`,
s.volume.Name, s.pool.Name)
From dea3a1a23d81f025563512483fe1ca9f8a09479f Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 13:24:51 +0200
Subject: [PATCH 13/15] ceph: existence check before container delete
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_ceph.go | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index 7ac397bf5..55554e9d7 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -1065,18 +1065,24 @@ func (s *storageCeph) ContainerDelete(container container) error {
return err
}
+ rbdVolumeExists := cephRBDVolumeExists(s.ClusterName, s.OSDPoolName,
+ containerName, storagePoolVolumeTypeNameContainer, s.UserName)
+
// delete
- ret := cephContainerDelete(s.ClusterName, s.OSDPoolName, containerName,
- storagePoolVolumeTypeNameContainer, s.UserName)
- if ret < 0 {
- msg := fmt.Sprintf(`Failed to delete RBD storage volume for `+
- `container "%s" on storage pool "%s"`, containerName, s.pool.Name)
- logger.Errorf(msg)
- return fmt.Errorf(msg)
+ if rbdVolumeExists {
+ ret := cephContainerDelete(s.ClusterName, s.OSDPoolName, containerName,
+ storagePoolVolumeTypeNameContainer, s.UserName)
+ if ret < 0 {
+ msg := fmt.Sprintf(`Failed to delete RBD storage volume for `+
+ `container "%s" on storage pool "%s"`, containerName, s.pool.Name)
+ logger.Errorf(msg)
+ return fmt.Errorf(msg)
+ }
}
containerMntPoint := getContainerMountPoint(s.pool.Name, containerName)
- err = deleteContainerMountpoint(containerMntPoint, containerPath, s.GetStorageTypeName())
+ err = deleteContainerMountpoint(containerMntPoint, containerPath,
+ s.GetStorageTypeName())
if err != nil {
logger.Errorf(`Failed to delete mountpoint %s for RBD storage `+
`volume of container "%s" for RBD storage volume on `+
From 8bdec212fd4141cbe1a1063509b461991525e83d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 13:28:37 +0200
Subject: [PATCH 14/15] ceph: existence check before snapshot delete
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_ceph.go | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index 55554e9d7..174f69990 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -1812,15 +1812,21 @@ func (s *storageCeph) ContainerSnapshotDelete(snapshotContainer container) error
sourceContainerName, sourceContainerSnapOnlyName, _ :=
containerGetParentAndSnapshotName(snapshotContainerName)
snapshotName := fmt.Sprintf("snapshot_%s", sourceContainerSnapOnlyName)
- ret := cephContainerSnapshotDelete(s.ClusterName, s.OSDPoolName,
- sourceContainerName, storagePoolVolumeTypeNameContainer,
- snapshotName, s.UserName)
- if ret < 0 {
- msg := fmt.Sprintf(`Failed to delete RBD storage volume for `+
- `snapshot "%s" on storage pool "%s"`,
- snapshotContainerName, s.pool.Name)
- logger.Errorf(msg)
- return fmt.Errorf(msg)
+
+ rbdVolumeExists := cephRBDVolumeExists(s.ClusterName, s.OSDPoolName,
+ snapshotName, storagePoolVolumeTypeNameContainer, s.UserName)
+
+ if rbdVolumeExists {
+ ret := cephContainerSnapshotDelete(s.ClusterName, s.OSDPoolName,
+ sourceContainerName, storagePoolVolumeTypeNameContainer,
+ snapshotName, s.UserName)
+ if ret < 0 {
+ msg := fmt.Sprintf(`Failed to delete RBD storage volume for `+
+ `snapshot "%s" on storage pool "%s"`,
+ snapshotContainerName, s.pool.Name)
+ logger.Errorf(msg)
+ return fmt.Errorf(msg)
+ }
}
snapshotContainerMntPoint := getSnapshotMountPoint(s.pool.Name,
From e24af92b39c4bbc22f4ffa06239f93dc91d7fdf0 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 20 Sep 2017 13:32:52 +0200
Subject: [PATCH 15/15] ceph: existence check before snapshot delete
Closes #3775.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_ceph.go | 49 ++++++++++++++++++++++++++++---------------------
1 file changed, 28 insertions(+), 21 deletions(-)
diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index 174f69990..444eca592 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -2079,39 +2079,46 @@ func (s *storageCeph) ContainerSnapshotStop(c container) (bool, error) {
`storage pool "%s"`, containerName, s.pool.Name)
containerMntPoint := getSnapshotMountPoint(s.pool.Name, containerName)
- err := tryUnmount(containerMntPoint, syscall.MNT_DETACH)
- if err != nil {
- logger.Errorf("Failed to unmount %s: %s", containerMntPoint,
- err)
- return false, err
+ if shared.IsMountPoint(containerMntPoint) {
+ err := tryUnmount(containerMntPoint, syscall.MNT_DETACH)
+ if err != nil {
+ logger.Errorf("Failed to unmount %s: %s", containerMntPoint,
+ err)
+ return false, err
+ }
+ logger.Debugf("Unmounted %s", containerMntPoint)
}
- logger.Debugf("Unmounted %s", containerMntPoint)
containerOnlyName, snapOnlyName, _ := containerGetParentAndSnapshotName(containerName)
cloneName := fmt.Sprintf("%s_%s_start_clone", containerOnlyName, snapOnlyName)
// unmap
- err = cephRBDVolumeUnmap(s.ClusterName, s.OSDPoolName, cloneName,
+ err := cephRBDVolumeUnmap(s.ClusterName, s.OSDPoolName, cloneName,
"snapshots", s.UserName, true)
if err != nil {
- logger.Errorf(`Failed to unmap RBD storage volume for `+
+ logger.Warnf(`Failed to unmap RBD storage volume for `+
`container "%s" on storage pool "%s": %s`,
containerName, s.pool.Name, err)
- return false, err
+ } else {
+ logger.Debugf(`Unmapped RBD storage volume for container "%s" `+
+ `on storage pool "%s"`, containerName, s.pool.Name)
}
- logger.Debugf(`Unmapped RBD storage volume for container "%s" on `+
- `storage pool "%s"`, containerName, s.pool.Name)
- // delete
- err = cephRBDVolumeDelete(s.ClusterName, s.OSDPoolName, cloneName,
- "snapshots", s.UserName)
- if err != nil {
- logger.Errorf(`Failed to delete clone of RBD storage volume `+
- `for container "%s" on storage pool "%s": %s`,
- containerName, s.pool.Name, err)
- return false, err
+ rbdVolumeExists := cephRBDVolumeExists(s.ClusterName, s.OSDPoolName,
+ containerName, storagePoolVolumeTypeNameContainer, s.UserName)
+
+ if rbdVolumeExists {
+ // delete
+ err = cephRBDVolumeDelete(s.ClusterName, s.OSDPoolName, cloneName,
+ "snapshots", s.UserName)
+ if err != nil {
+ logger.Errorf(`Failed to delete clone of RBD storage volume `+
+ `for container "%s" on storage pool "%s": %s`,
+ containerName, s.pool.Name, err)
+ return false, err
+ }
+ logger.Debugf(`Deleted clone of RBD storage volume for container "%s" `+
+ `on storage pool "%s"`, containerName, s.pool.Name)
}
- logger.Debugf(`Deleted clone of RBD storage volume for container "%s" `+
- `on storage pool "%s"`, containerName, s.pool.Name)
logger.Debugf(`Stopped RBD storage volume for snapshot "%s" on `+
`storage pool "%s"`, containerName, s.pool.Name)
More information about the lxc-devel
mailing list