|
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 |
@@ -439,6 +440,7 @@ def __init__( |
439 | 440 | self._resource_cache_dirty = True |
440 | 441 | self._volume_info_cache = None |
441 | 442 | self._volume_info_cache_dirty = True |
| 443 | + self._resources_info_cache = None |
442 | 444 | self._build_volumes(repair=repair) |
443 | 445 |
|
444 | 446 | @property |
@@ -698,6 +700,13 @@ def destroy_volume(self, volume_uuid): |
698 | 700 | self._ensure_volume_exists(volume_uuid) |
699 | 701 | self.ensure_volume_is_not_locked(volume_uuid) |
700 | 702 |
|
| 703 | + is_volume_in_use = any(node["in-use"] for node in self.get_resource_info(volume_uuid)["nodes"].values()) |
| 704 | + if is_volume_in_use: |
| 705 | + raise LinstorVolumeManagerError( |
| 706 | + f"Could not destroy volume `{volume_uuid}` as it is currently in use", |
| 707 | + LinstorVolumeManagerError.ERR_VOLUME_DESTROY |
| 708 | + ) |
| 709 | + |
701 | 710 | # Mark volume as destroyed. |
702 | 711 | volume_properties = self._get_volume_properties(volume_uuid) |
703 | 712 | volume_properties[self.PROP_NOT_EXISTS] = self.STATE_NOT_EXISTS |
@@ -1701,6 +1710,9 @@ def get_resources_info(self): |
1701 | 1710 | Give all resources of current group name. |
1702 | 1711 | :rtype: dict(str, list) |
1703 | 1712 | """ |
| 1713 | + if self._resources_info_cache and not self._resource_cache_dirty: |
| 1714 | + return self._resources_info_cache |
| 1715 | + |
1704 | 1716 | resources = {} |
1705 | 1717 | resource_list = self._get_resource_cache() |
1706 | 1718 | volume_names = self.get_volumes_with_name() |
@@ -1757,7 +1769,23 @@ def get_resources_info(self): |
1757 | 1769 | if resource: |
1758 | 1770 | resource['uuid'] = volume_uuid |
1759 | 1771 |
|
1760 | | - return resources |
| 1772 | + self._resources_info_cache = resources |
| 1773 | + return self._resources_info_cache |
| 1774 | + |
| 1775 | + def get_resource_info(self, volume_uuid: str) -> Dict[str, Any]: |
| 1776 | + """ |
| 1777 | + Give all resource info related to provided UUID in the current group. |
| 1778 | + :param volume_uuid str: volume uuid to search for |
| 1779 | + :rtype: dict(str, any) |
| 1780 | + """ |
| 1781 | + for volume in self.get_resources_info().values(): |
| 1782 | + if volume["uuid"] == volume_uuid: |
| 1783 | + return volume |
| 1784 | + |
| 1785 | + raise LinstorVolumeManagerError( |
| 1786 | + f"Could not find info about volume `{volume_uuid}`", |
| 1787 | + LinstorVolumeManagerError.ERR_VOLUME_NOT_EXISTS |
| 1788 | + ) |
1761 | 1789 |
|
1762 | 1790 | def get_database_path(self): |
1763 | 1791 | """ |
|
0 commit comments