blob: 6678eb79707eab1b0e83984cdd444a8e69199cb4 [file] [log] [blame]
Peter Pentchev38b9cec2022-06-23 14:05:52 +03001From 37a2ad8ba2de741e90421e4d0590af02a69e4ba9 Mon Sep 17 00:00:00 2001
2From: Peter Penchev <openstack-dev@storpool.com>
3Date: Wed, 15 Jun 2022 16:07:34 +0300
4Subject: [PATCH 4/8] StorPool: really detach after copy to/from image.
5
6When copying a volume to an image, detach the temporary snapshot after
7the copy operation, otherwise the attempt to delete it immediately
8afterwards will fail. When copying an image to a volume, detach
9the volume after the copy operation.
10
11This only matters when Cinder is not used as a backing store for Glance
12images; otherwise, these functions are never invoked and volumes are
13cloned instead (modulo other bugs in these workflows).
14
15Change-Id: Id93d578763bcd444e093cac4bd91b6fe68ffd12f
16Closes-bug: #1978825
17---
18 cinder/volume/drivers/storpool.py | 34 +++++++++++++++----
19 ...ach-after-image-copy-6c4dff727583fe17.yaml | 7 ++++
20 2 files changed, 34 insertions(+), 7 deletions(-)
21 create mode 100644 releasenotes/notes/bug-1978825-storpool-detach-after-image-copy-6c4dff727583fe17.yaml
22
23diff --git a/cinder/volume/drivers/storpool.py b/cinder/volume/drivers/storpool.py
24index 4d79a82f8..56b4070bc 100644
25--- a/cinder/volume/drivers/storpool.py
26+++ b/cinder/volume/drivers/storpool.py
27@@ -93,6 +93,8 @@ class StorPoolDriver(driver.VolumeDriver):
28 1.2.3 - Advertise some more driver capabilities.
29 2.0.0 - Drop _attach_volume() and _detach_volume(), our os-brick
30 connector will handle this.
31+ - Detach temporary snapshots and volumes after copying data
32+ to or from from Glance images.
33 """
34
35 VERSION = '2.0.0'
36@@ -351,20 +353,28 @@ class StorPoolDriver(driver.VolumeDriver):
37 name = self._attach.volsnapName(volume['id'], req_id)
38 try:
39 self._attach.api().snapshotCreate(volname, {'name': name})
40+ self._attach.add(req_id, {
41+ 'volume': name,
42+ 'type': 'copy-from',
43+ 'id': req_id,
44+ 'rights': 1,
45+ 'volsnap': True
46+ })
47+ self._attach.sync(req_id, None)
48 except spapi.ApiError as e:
49 raise self._backendException(e)
50- self._attach.add(req_id, {
51- 'volume': name,
52- 'type': 'copy-from',
53- 'id': req_id,
54- 'rights': 1,
55- 'volsnap': True
56- })
57 try:
58 return super(StorPoolDriver, self).copy_volume_to_image(
59 context, volume, image_service, image_meta)
60 finally:
61 self._attach.remove(req_id)
62+ try:
63+ self._attach.sync(req_id, name)
64+ except spapi.ApiError as e:
65+ LOG.error(
66+ 'Could not detach the temp snapshot %(name)s for '
67+ '%(vol)s: %(err)s',
68+ {'name': name, 'vol': volname, 'err': e})
69 try:
70 self._attach.api().snapshotDelete(name)
71 except spapi.ApiError as e:
72@@ -382,11 +392,21 @@ class StorPoolDriver(driver.VolumeDriver):
73 'id': req_id,
74 'rights': 2
75 })
76+ try:
77+ self._attach.sync(req_id, None)
78+ except spapi.ApiError as e:
79+ raise self._backendException(e)
80 try:
81 return super(StorPoolDriver, self).copy_image_to_volume(
82 context, volume, image_service, image_id)
83 finally:
84 self._attach.remove(req_id)
85+ try:
86+ self._attach.sync(req_id, name)
87+ except spapi.ApiError as e:
88+ LOG.error(
89+ 'Could not detach the %(name)s volume: %(err)s',
90+ {'name': name, 'err': e})
91
92 def extend_volume(self, volume, new_size):
93 size = int(new_size) * units.Gi
94diff --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
95new file mode 100644
96index 000000000..bfc6ef3dc
97--- /dev/null
98+++ b/releasenotes/notes/bug-1978825-storpool-detach-after-image-copy-6c4dff727583fe17.yaml
99@@ -0,0 +1,7 @@
100+---
101+fixes:
102+ - |
103+ StorPool driver `bug #1978825
104+ <https://bugs.launchpad.net/cinder/+bug/1978825>`_: Fixed
105+ stale StorPool volume and snapshot attachments persisting after
106+ copying a volume to/from a Glance image.
107--
1082.35.1
109