@@ -520,13 +520,10 @@ def allocated_volume_size(self):
520520 if volume .storage_pool_name != self ._group_name :
521521 continue
522522
523- current_size = volume .allocated_size
524- if current_size < 0 :
525- raise LinstorVolumeManagerError (
526- 'Failed to get allocated size of `{}` on `{}`'
527- .format (resource .name , volume .storage_pool_name )
528- )
529- current [volume .number ] = max (current_size , current .get (volume .number ) or 0 )
523+ allocated_size = max (volume .allocated_size , 0 )
524+ current_allocated_size = current .get (volume .number ) or - 1
525+ if allocated_size > current_allocated_size :
526+ current [volume .number ] = allocated_size
530527
531528 total_size = 0
532529 for volumes in sizes .values ():
@@ -2112,32 +2109,31 @@ def _get_volumes_info(self, volume_name=None):
21122109
21132110 for volume in resource .volumes :
21142111 # We ignore diskless pools of the form "DfltDisklessStorPool".
2115- if volume .storage_pool_name == self ._group_name :
2116- if volume .allocated_size < 0 :
2117- raise LinstorVolumeManagerError (
2118- 'Failed to get allocated size of `{}` on `{}`'
2119- .format (resource .name , volume .storage_pool_name )
2120- )
2121- allocated_size = volume .allocated_size
2122-
2123- current .allocated_size = current .allocated_size and \
2124- max (current .allocated_size , allocated_size ) or \
2125- allocated_size
2112+ if volume .storage_pool_name != self ._group_name :
2113+ continue
21262114
2127- usable_size = volume .usable_size
2128- if usable_size > 0 and (
2129- usable_size < current .virtual_size or
2130- not current .virtual_size
2131- ):
2132- current .virtual_size = usable_size
2115+ allocated_size = volume .allocated_size
2116+ if allocated_size > current .allocated_size :
2117+ current .allocated_size = allocated_size
21332118
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- )
2119+ usable_size = volume .usable_size
2120+ if usable_size > 0 and (
2121+ usable_size < current .virtual_size or
2122+ not current .virtual_size
2123+ ):
2124+ current .virtual_size = usable_size
21392125
21402126 for current in all_volume_info .values ():
2127+ if current .allocated_size <= 0 :
2128+ raise LinstorVolumeManagerError (
2129+ 'Failed to get allocated size of `{}`' .format (resource .name )
2130+ )
2131+
2132+ if current .virtual_size <= 0 :
2133+ raise LinstorVolumeManagerError (
2134+ 'Failed to get usable size of `{}`' .format (resource .name )
2135+ )
2136+
21412137 current .allocated_size *= 1024
21422138 current .virtual_size *= 1024
21432139
@@ -2154,20 +2150,24 @@ def _get_volume_node_names_and_size(self, volume_name):
21542150 ).resources :
21552151 for volume in resource .volumes :
21562152 # We ignore diskless pools of the form "DfltDisklessStorPool".
2157- if volume .storage_pool_name = = self ._group_name :
2158- node_names . add ( resource . node_name )
2153+ if volume .storage_pool_name ! = self ._group_name :
2154+ continue
21592155
2160- 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- )
2156+ node_names .add (resource .node_name )
21662157
2167- if size < 0 :
2168- size = current_size
2169- else :
2170- size = min (size , current_size )
2158+ usable_size = volume .usable_size
2159+ if usable_size <= 0 :
2160+ continue
2161+
2162+ if size < 0 :
2163+ size = usable_size
2164+ else :
2165+ size = min (size , usable_size )
2166+
2167+ if size <= 0 :
2168+ raise LinstorVolumeManagerError (
2169+ 'Failed to get usable size of `{}`' .format (resource .name )
2170+ )
21712171
21722172 return (node_names , size * 1024 )
21732173
0 commit comments