|
15 | 15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 | # |
17 | 17 |
|
18 | | -from sm_typing import override |
| 18 | +from sm_typing import Any, Dict, override |
19 | 19 |
|
20 | 20 | import errno |
21 | 21 | import json |
@@ -302,7 +302,8 @@ class LinstorVolumeManager(object): |
302 | 302 | '_base_group_name', '_group_name', '_ha_group_name', |
303 | 303 | '_volumes', '_storage_pools', '_storage_pools_time', |
304 | 304 | '_kv_cache', '_resource_cache', '_volume_info_cache', |
305 | | - '_kv_cache_dirty', '_resource_cache_dirty', '_volume_info_cache_dirty' |
| 305 | + '_kv_cache_dirty', '_resource_cache_dirty', '_volume_info_cache_dirty', |
| 306 | + '_resources_info_cache', |
306 | 307 | ) |
307 | 308 |
|
308 | 309 | DEV_ROOT_PATH = DRBD_BY_RES_PATH |
@@ -427,6 +428,7 @@ def __init__( |
427 | 428 | self._resource_cache_dirty = True |
428 | 429 | self._volume_info_cache = None |
429 | 430 | self._volume_info_cache_dirty = True |
| 431 | + self._resources_info_cache = None |
430 | 432 | self._build_volumes(repair=repair) |
431 | 433 |
|
432 | 434 | @property |
@@ -686,6 +688,13 @@ def destroy_volume(self, volume_uuid): |
686 | 688 | self._ensure_volume_exists(volume_uuid) |
687 | 689 | self.ensure_volume_is_not_locked(volume_uuid) |
688 | 690 |
|
| 691 | + is_volume_in_use = any(node["in-use"] for node in self.get_resource_info(volume_uuid)["nodes"].values()) |
| 692 | + if is_volume_in_use: |
| 693 | + raise LinstorVolumeManagerError( |
| 694 | + f"Could not destroy volume `{volume_uuid}` as it is currently in use", |
| 695 | + LinstorVolumeManagerError.ERR_VOLUME_DESTROY |
| 696 | + ) |
| 697 | + |
689 | 698 | # Mark volume as destroyed. |
690 | 699 | volume_properties = self._get_volume_properties(volume_uuid) |
691 | 700 | volume_properties[self.PROP_NOT_EXISTS] = self.STATE_NOT_EXISTS |
@@ -1683,6 +1692,9 @@ def get_resources_info(self): |
1683 | 1692 | Give all resources of current group name. |
1684 | 1693 | :rtype: dict(str, list) |
1685 | 1694 | """ |
| 1695 | + if self._resources_info_cache and not self._resource_cache_dirty: |
| 1696 | + return self._resources_info_cache |
| 1697 | + |
1686 | 1698 | resources = {} |
1687 | 1699 | resource_list = self._get_resource_cache() |
1688 | 1700 | volume_names = self.get_volumes_with_name() |
@@ -1739,7 +1751,23 @@ def get_resources_info(self): |
1739 | 1751 | if resource: |
1740 | 1752 | resource['uuid'] = volume_uuid |
1741 | 1753 |
|
1742 | | - return resources |
| 1754 | + self._resources_info_cache = resources |
| 1755 | + return self._resources_info_cache |
| 1756 | + |
| 1757 | + def get_resource_info(self, volume_uuid: str) -> Dict[str, Any]: |
| 1758 | + """ |
| 1759 | + Give all resources info with provided uuid on current group name. |
| 1760 | + :param volume_uuid str: volume uuid to search for |
| 1761 | + :rtype: dict |
| 1762 | + """ |
| 1763 | + for volume in self.get_resources_info().values(): |
| 1764 | + if volume["uuid"] == volume_uuid: |
| 1765 | + return volume |
| 1766 | + |
| 1767 | + raise LinstorVolumeManagerError( |
| 1768 | + f"Could not find info about volume `{volume_uuid}`", |
| 1769 | + LinstorVolumeManagerError.ERR_VOLUME_NOT_EXISTS |
| 1770 | + ) |
1743 | 1771 |
|
1744 | 1772 | def get_database_path(self): |
1745 | 1773 | """ |
|
0 commit comments