Skip to content

Commit be3fd49

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 fb3fe3a commit be3fd49

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
@@ -2111,7 +2111,7 @@ def _get_volumes_info(self, volume_name=None):
21112111
if not self._volume_info_cache_dirty:
21122112
return self._volume_info_cache
21132113

2114-
for resource in self._get_resource_cache().resources:
2114+
def process_resource(resource):
21152115
if resource.name not in all_volume_info:
21162116
current = all_volume_info[resource.name] = self.VolumeInfo(
21172117
resource.name
@@ -2143,15 +2143,21 @@ def _get_volumes_info(self, volume_name=None):
21432143
):
21442144
current.virtual_size = usable_size
21452145

2146-
if current.virtual_size <= 0:
2147-
raise LinstorVolumeManagerError(
2148-
'Failed to get usable size of `{}` on `{}`'
2149-
.format(resource.name, volume.storage_pool_name)
2150-
)
2146+
try:
2147+
for resource in self._get_resource_cache().resources:
2148+
process_resource(resource)
2149+
for volume in all_volume_info.values():
2150+
if volume.virtual_size <= 0:
2151+
raise LinstorVolumeManagerError(
2152+
'Failed to get usable size of `{}`'
2153+
.format(volume.name)
2154+
)
21512155

2152-
for current in all_volume_info.values():
2153-
current.allocated_size *= 1024
2154-
current.virtual_size *= 1024
2156+
volume.allocated_size *= 1024
2157+
volume.virtual_size *= 1024
2158+
except LinstorVolumeManagerError:
2159+
self._mark_resource_cache_as_dirty()
2160+
raise
21552161

21562162
self._volume_info_cache_dirty = False
21572163
self._volume_info_cache = all_volume_info
@@ -2170,16 +2176,14 @@ def _get_volume_node_names_and_size(self, volume_name):
21702176
node_names.add(resource.node_name)
21712177

21722178
current_size = volume.usable_size
2173-
if current_size < 0:
2174-
raise LinstorVolumeManagerError(
2175-
'Failed to get usable size of `{}` on `{}`'
2176-
.format(resource.name, volume.storage_pool_name)
2177-
)
2178-
2179-
if size < 0:
2179+
if current_size > 0 and (current_size < size or size < 0):
21802180
size = current_size
2181-
else:
2182-
size = min(size, current_size)
2181+
2182+
if size < 0:
2183+
raise LinstorVolumeManagerError(
2184+
'Failed to get usable size of `{}` on `{}`'
2185+
.format(resource.name, volume.storage_pool_name)
2186+
)
21832187

21842188
return (node_names, size * 1024)
21852189

0 commit comments

Comments
 (0)