Add the "really detach" patch, update the attach/detach one.
Change-Id: I8de05d4d40f7d7f9ee2249b07b421bc031a162a3
diff --git a/patches/openstack/cinder/storpool-do-detach.patch b/patches/openstack/cinder/storpool-do-detach.patch
new file mode 100644
index 0000000..6678eb7
--- /dev/null
+++ b/patches/openstack/cinder/storpool-do-detach.patch
@@ -0,0 +1,109 @@
+From 37a2ad8ba2de741e90421e4d0590af02a69e4ba9 Mon Sep 17 00:00:00 2001
+From: Peter Penchev <openstack-dev@storpool.com>
+Date: Wed, 15 Jun 2022 16:07:34 +0300
+Subject: [PATCH 4/8] StorPool: really detach after copy to/from image.
+
+When copying a volume to an image, detach the temporary snapshot after
+the copy operation, otherwise the attempt to delete it immediately
+afterwards will fail. When copying an image to a volume, detach
+the volume after the copy operation.
+
+This only matters when Cinder is not used as a backing store for Glance
+images; otherwise, these functions are never invoked and volumes are
+cloned instead (modulo other bugs in these workflows).
+
+Change-Id: Id93d578763bcd444e093cac4bd91b6fe68ffd12f
+Closes-bug: #1978825
+---
+ cinder/volume/drivers/storpool.py | 34 +++++++++++++++----
+ ...ach-after-image-copy-6c4dff727583fe17.yaml | 7 ++++
+ 2 files changed, 34 insertions(+), 7 deletions(-)
+ create mode 100644 releasenotes/notes/bug-1978825-storpool-detach-after-image-copy-6c4dff727583fe17.yaml
+
+diff --git a/cinder/volume/drivers/storpool.py b/cinder/volume/drivers/storpool.py
+index 4d79a82f8..56b4070bc 100644
+--- a/cinder/volume/drivers/storpool.py
++++ b/cinder/volume/drivers/storpool.py
+@@ -93,6 +93,8 @@ class StorPoolDriver(driver.VolumeDriver):
+ 1.2.3 - Advertise some more driver capabilities.
+ 2.0.0 - Drop _attach_volume() and _detach_volume(), our os-brick
+ connector will handle this.
++ - Detach temporary snapshots and volumes after copying data
++ to or from from Glance images.
+ """
+
+ VERSION = '2.0.0'
+@@ -351,20 +353,28 @@ class StorPoolDriver(driver.VolumeDriver):
+ name = self._attach.volsnapName(volume['id'], req_id)
+ try:
+ self._attach.api().snapshotCreate(volname, {'name': name})
++ self._attach.add(req_id, {
++ 'volume': name,
++ 'type': 'copy-from',
++ 'id': req_id,
++ 'rights': 1,
++ 'volsnap': True
++ })
++ self._attach.sync(req_id, None)
+ except spapi.ApiError as e:
+ raise self._backendException(e)
+- self._attach.add(req_id, {
+- 'volume': name,
+- 'type': 'copy-from',
+- 'id': req_id,
+- 'rights': 1,
+- 'volsnap': True
+- })
+ try:
+ return super(StorPoolDriver, self).copy_volume_to_image(
+ context, volume, image_service, image_meta)
+ finally:
+ self._attach.remove(req_id)
++ try:
++ self._attach.sync(req_id, name)
++ except spapi.ApiError as e:
++ LOG.error(
++ 'Could not detach the temp snapshot %(name)s for '
++ '%(vol)s: %(err)s',
++ {'name': name, 'vol': volname, 'err': e})
+ try:
+ self._attach.api().snapshotDelete(name)
+ except spapi.ApiError as e:
+@@ -382,11 +392,21 @@ class StorPoolDriver(driver.VolumeDriver):
+ 'id': req_id,
+ 'rights': 2
+ })
++ try:
++ self._attach.sync(req_id, None)
++ except spapi.ApiError as e:
++ raise self._backendException(e)
+ try:
+ return super(StorPoolDriver, self).copy_image_to_volume(
+ context, volume, image_service, image_id)
+ finally:
+ self._attach.remove(req_id)
++ try:
++ self._attach.sync(req_id, name)
++ except spapi.ApiError as e:
++ LOG.error(
++ 'Could not detach the %(name)s volume: %(err)s',
++ {'name': name, 'err': e})
+
+ def extend_volume(self, volume, new_size):
+ size = int(new_size) * units.Gi
+diff --git a/releasenotes/notes/bug-1978825-storpool-detach-after-image-copy-6c4dff727583fe17.yaml b/releasenotes/notes/bug-1978825-storpool-detach-after-image-copy-6c4dff727583fe17.yaml
+new file mode 100644
+index 000000000..bfc6ef3dc
+--- /dev/null
++++ b/releasenotes/notes/bug-1978825-storpool-detach-after-image-copy-6c4dff727583fe17.yaml
+@@ -0,0 +1,7 @@
++---
++fixes:
++ - |
++ StorPool driver `bug #1978825
++ <https://bugs.launchpad.net/cinder/+bug/1978825>`_: Fixed
++ stale StorPool volume and snapshot attachments persisting after
++ copying a volume to/from a Glance image.
+--
+2.35.1
+