Skip to content

Commit 237bce4

Browse files
committed
fix(linstorvolumemanager): robustify "usable size" getters
Impacted functions: `_get_volumes_info` and `_get_volume_node_names_and_size`. Before this change "usable_size" validity was checked too early and which could lead to an exception for no good reason while the size could be known on at least one host despite an issue on other machines. Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.tech>
1 parent a96aed5 commit 237bce4

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

drivers/linstorvolumemanager.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,7 @@ def _get_volumes_info(self, volume_name=None):
20992099
if not self._volume_info_cache_dirty:
21002100
return self._volume_info_cache
21012101

2102-
for resource in self._get_resource_cache().resources:
2102+
def process_resource(resource):
21032103
if resource.name not in all_volume_info:
21042104
current = all_volume_info[resource.name] = self.VolumeInfo(
21052105
resource.name
@@ -2131,15 +2131,21 @@ def _get_volumes_info(self, volume_name=None):
21312131
):
21322132
current.virtual_size = usable_size
21332133

2134-
if current.virtual_size <= 0:
2135-
raise LinstorVolumeManagerError(
2136-
'Failed to get usable size of `{}` on `{}`'
2137-
.format(resource.name, volume.storage_pool_name)
2138-
)
2134+
try:
2135+
for resource in self._get_resource_cache().resources:
2136+
process_resource(resource)
2137+
for volume in all_volume_info.values():
2138+
if volume.virtual_size <= 0:
2139+
raise LinstorVolumeManagerError(
2140+
'Failed to get usable size of `{}`'
2141+
.format(volume.name)
2142+
)
21392143

2140-
for current in all_volume_info.values():
2141-
current.allocated_size *= 1024
2142-
current.virtual_size *= 1024
2144+
volume.allocated_size *= 1024
2145+
volume.virtual_size *= 1024
2146+
except LinstorVolumeManagerError:
2147+
self._mark_resource_cache_as_dirty()
2148+
raise
21432149

21442150
self._volume_info_cache_dirty = False
21452151
self._volume_info_cache = all_volume_info
@@ -2158,16 +2164,14 @@ def _get_volume_node_names_and_size(self, volume_name):
21582164
node_names.add(resource.node_name)
21592165

21602166
current_size = volume.usable_size
2161-
if current_size < 0:
2162-
raise LinstorVolumeManagerError(
2163-
'Failed to get usable size of `{}` on `{}`'
2164-
.format(resource.name, volume.storage_pool_name)
2165-
)
2166-
2167-
if size < 0:
2167+
if current_size > 0 and (current_size < size or size < 0):
21682168
size = current_size
2169-
else:
2170-
size = min(size, current_size)
2169+
2170+
if size < 0:
2171+
raise LinstorVolumeManagerError(
2172+
'Failed to get usable size of `{}` on `{}`'
2173+
.format(resource.name, volume.storage_pool_name)
2174+
)
21712175

21722176
return (node_names, size * 1024)
21732177

0 commit comments

Comments
 (0)