Skip to content

Commit f1404bd

Browse files
committed
fix(linstor): typo on resize for linstor raw VDI
fix resize typo for linstor on raw VDI refactor linstor resize code Signed-off-by: Antoine Bartuccio <[email protected]>
1 parent 5e237a7 commit f1404bd

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

drivers/LinstorSR.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17-
from sm_typing import Optional, override
17+
from sm_typing import Optional, override, Tuple
1818

1919
from constants import CBTLOG_TAG
2020

@@ -1907,7 +1907,30 @@ def detach(self, sr_uuid, vdi_uuid) -> None:
19071907
vdi_uuid = parent_vdi_uuid
19081908

19091909
@override
1910-
def resize(self, sr_uuid, vdi_uuid, size) -> str:
1910+
def resize(self, sr_uuid: str, vdi_uuid: str, size: int) -> str:
1911+
def compute_vdi_sizes(vdi: LinstorVDI) -> Tuple[int, int]:
1912+
if vdi.vdi_type == vhdutil.VDI_TYPE_RAW:
1913+
return vdi.size, LinstorVolumeManager.round_up_volume_size(size)
1914+
1915+
old_volume_size = vdi.utilisation
1916+
if vdi.sr._provisioning == 'thin':
1917+
# VDI is currently deflated, so keep it deflated.
1918+
return old_volume_size, old_volume_size
1919+
1920+
return old_volume_size, LinstorVhdUtil.compute_volume_size(size, vdi.vdi_type)
1921+
1922+
def resize_vdi(vdi: LinstorVDI, old_volume_size: int, new_volume_size) -> None:
1923+
if vdi.vdi_type == vhdutil.VDI_TYPE_RAW:
1924+
vdi._linstor.resize_volume(vdi.uuid, new_volume_size)
1925+
return
1926+
1927+
if new_volume_size != old_volume_size:
1928+
vdi.sr._vhdutil.inflate(
1929+
vdi.sr._journaler, vdi.uuid, vdi.path,
1930+
new_volume_size, old_volume_size
1931+
)
1932+
vdi.sr._vhdutil.set_size_virt_fast(vdi.path, size)
1933+
19111934
util.SMlog('LinstorVDI.resize for {}'.format(self.uuid))
19121935
if not self.sr.is_master():
19131936
raise xs_errors.XenError(
@@ -1934,37 +1957,22 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
19341957
raise xs_errors.XenError('VDISize', opterr='shrinking not allowed')
19351958

19361959
if size == self.size:
1937-
return VDI.VDI.get_params(self)
1960+
return VDI.VDI.get_params(self) # No change needed
19381961

1939-
if self.vdi_type == vhdutil.VDI_TYPE_RAW:
1940-
old_volume_size = self.size
1941-
new_volume_size = LinstorVolumeManager.round_up_volume_size(size)
1942-
else:
1943-
old_volume_size = self.utilisation
1944-
if self.sr._provisioning == 'thin':
1945-
# VDI is currently deflated, so keep it deflated.
1946-
new_volume_size = old_volume_size
1947-
else:
1948-
new_volume_size = LinstorVhdUtil.compute_volume_size(size, self.vdi_type)
1962+
old_volume_size, new_volume_size = compute_vdi_sizes(self)
19491963
assert new_volume_size >= old_volume_size
19501964

19511965
space_needed = new_volume_size - old_volume_size
19521966
self.sr._ensure_space_available(space_needed)
19531967

19541968
old_size = self.size
1955-
if self.vdi_type == vhdutil.VDI_TYPE_RAW:
1956-
self._linstor.resize(self.uuid, new_volume_size)
1957-
else:
1958-
if new_volume_size != old_volume_size:
1959-
self.sr._vhdutil.inflate(
1960-
self.sr._journaler, self.uuid, self.path,
1961-
new_volume_size, old_volume_size
1962-
)
1963-
self.sr._vhdutil.set_size_virt_fast(self.path, size)
1969+
1970+
resize_vdi(self, old_volume_size, new_volume_size)
19641971

19651972
# Reload size attributes.
19661973
self._load_this()
19671974

1975+
# Update metadata
19681976
vdi_ref = self.sr.srcmd.params['vdi_ref']
19691977
self.session.xenapi.VDI.set_virtual_size(vdi_ref, str(self.size))
19701978
self.session.xenapi.VDI.set_physical_utilisation(

0 commit comments

Comments
 (0)