Skip to content

Commit e7af4ae

Browse files
committed
fix(linstorvolumemanager): don't allow InUse volumes to be deleted
Check for usage status before deleting a linstor volume and raise an appropriate error if this happens Signed-off-by: Antoine Bartuccio <antoine.bartuccio@vates.tech>
1 parent de309bc commit e7af4ae

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

drivers/linstorvolumemanager.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
#
1717

18-
from sm_typing import override
18+
from sm_typing import Dict, override
1919

2020
import errno
2121
import json
@@ -682,10 +682,16 @@ def destroy_volume(self, volume_uuid):
682682
Destroy a volume.
683683
:param str volume_uuid: The volume uuid to destroy.
684684
"""
685-
686685
self._ensure_volume_exists(volume_uuid)
687686
self.ensure_volume_is_not_locked(volume_uuid)
688687

688+
is_volume_in_use = any(node["in-use"] for node in self.get_resource_info(volume_uuid)["nodes"].values())
689+
if is_volume_in_use:
690+
raise LinstorVolumeManagerError(
691+
f"Could not destroy volume `{volume_uuid}` as it is currently in use",
692+
LinstorVolumeManagerError.ERR_VOLUME_DESTROY
693+
)
694+
689695
# Mark volume as destroyed.
690696
volume_properties = self._get_volume_properties(volume_uuid)
691697
volume_properties[self.PROP_NOT_EXISTS] = self.STATE_NOT_EXISTS
@@ -1741,6 +1747,21 @@ def get_resources_info(self):
17411747

17421748
return resources
17431749

1750+
def get_resource_info(self, volume_uuid: str) -> Dict:
1751+
"""
1752+
Give all resources info with provided uuid on current group name.
1753+
:param: volume_uuid
1754+
:rtype: dict
1755+
"""
1756+
for volume in self.get_resources_info().values():
1757+
if volume["uuid"] == volume_uuid:
1758+
return volume
1759+
1760+
raise LinstorVolumeManagerError(
1761+
f"Could not find info about volume `{volume_uuid}`",
1762+
LinstorVolumeManagerError.ERR_VOLUME_DESTROY
1763+
)
1764+
17441765
def get_database_path(self):
17451766
"""
17461767
Get the database path.

0 commit comments

Comments
 (0)