Skip to content

Commit

Permalink
fix(cleanup.py): resize on a primary host
Browse files Browse the repository at this point in the history
Until now the cleanup VHD resize commands were performed on the master.
But it doesn't work every time when a VHD of a chain is opened for reading on another host.

As a reminder, this portion of code is only executed rarely.
A user must have resized a VHD that must later be coalesced.

Signed-off-by: Ronan Abhamon <[email protected]>
  • Loading branch information
Wescoeur committed Feb 10, 2025
1 parent a777b53 commit ac6a9d8
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 8 deletions.
54 changes: 54 additions & 0 deletions drivers/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,60 @@ def _setHidden(self, hidden=True) -> None:
else:
VDI._setHidden(self, hidden)

@override
def _increaseSizeVirt(self, size, atomic=True):
if self.raw:
offset = self.drbd_size
if self.sizeVirt < size:
oldSize = self.drbd_size
self.drbd_size = util.roundup(LinstorVolumeManager.BLOCK_SIZE, size)
Util.log(" Growing %s: %d->%d" % (self.path, oldSize, self.drbd_size))
self.sr._linstor.resize_volume(self.uuid, self.drbd_size)
offset = oldSize
unfinishedZero = False
jval = self.sr.journaler.get(LinstorJournaler.ZERO, self.uuid)
if jval:
unfinishedZero = True
offset = int(jval)
length = self.drbd_size - offset
if not length:
return

if unfinishedZero:
Util.log(" ==> Redoing unfinished zeroing out")
else:
self.sr.journaler.create(LinstorJournaler.ZERO, self.uuid, str(offset))
Util.log(" Zeroing %s: from %d, %dB" % (self.path, offset, length))
abortTest = lambda: IPCFlag(self.sr.uuid).test(FLAG_TYPE_ABORT)
func = lambda: util.zeroOut(self.path, offset, length)
Util.runAbortable(func, True, self.sr.uuid, abortTest, VDI.POLL_INTERVAL, 0)
self.sr.journaler.remove(LinstorJournaler.ZERO, self.uuid)

if self.sizeVirt >= size:
return
Util.log(" Expanding VHD virt size for VDI %s: %s -> %s" % \
(self, Util.num2str(self.sizeVirt), Util.num2str(size)))

msize = self.sr._vhdutil.get_max_resize_size(self.uuid) * 1024 * 1024
if (size <= msize):
self.sr._vhdutil.set_size_virt_fast(self.path, size)
else:
if atomic:
vdiList = self._getAllSubtree()
self.sr.lock()
try:
self.sr.pauseVDIs(vdiList)
try:
self._setSizeVirt(size)
finally:
self.sr.unpauseVDIs(vdiList)
finally:
self.sr.unlock()
else:
self._setSizeVirt(size)

self.sizeVirt = self.sr._vhdutil.get_size_virt(self.uuid)

@override
def _setSizeVirt(self, size) -> None:
jfile = self.uuid + '-jvhd'
Expand Down
35 changes: 35 additions & 0 deletions drivers/linstor-manager
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,15 @@ def get_allocated_size(session, args):
raise


def get_max_resize_size(session, args):
try:
device_path = args['devicePath']
return str(vhdutil.getMaxResizeSize(device_path))
except Exception as e:
util.SMlog('linstor-manager:get_size_phys error: {}'.format(e))
raise


def get_depth(session, args):
try:
device_path = args['devicePath']
Expand Down Expand Up @@ -524,6 +533,29 @@ def get_drbd_size(session, args):
raise


def set_size_virt(session, args):
try:
device_path = args['devicePath']
size = int(args['size'])
jfile = args['jfile']
vhdutil.setSizeVirt(device_path, size, jfile)
return ''
except Exception as e:
util.SMlog('linstor-manager:set_size_virt error: {}'.format(e))
raise


def set_size_virt_fast(session, args):
try:
device_path = args['devicePath']
size = int(args['size'])
vhdutil.setSizeVirtFast(device_path, size)
return ''
except Exception as e:
util.SMlog('linstor-manager:set_size_virt_fast error: {}'.format(e))
raise


def set_parent(session, args):
try:
device_path = args['devicePath']
Expand Down Expand Up @@ -1211,6 +1243,7 @@ if __name__ == '__main__':
'hasParent': has_parent,
'getParent': get_parent,
'getSizeVirt': get_size_virt,
'getMaxResizeSize': get_max_resize_size,
'getSizePhys': get_size_phys,
'getAllocatedSize': get_allocated_size,
'getDepth': get_depth,
Expand All @@ -1222,6 +1255,8 @@ if __name__ == '__main__':

# Called by cleanup.py to coalesce when a primary
# is opened on a non-local host.
'setSizeVirt': set_size_virt,
'setSizeVirtFast': set_size_virt_fast,
'setParent': set_parent,
'coalesce': coalesce,
'repair': repair,
Expand Down
1 change: 1 addition & 0 deletions drivers/linstorjournaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class LinstorJournaler:
"""
CLONE = 'clone'
INFLATE = 'inflate'
ZERO = 'zero'

@staticmethod
def default_logger(*args):
Expand Down
27 changes: 19 additions & 8 deletions drivers/linstorvhdutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ def _get_parent(self, vdi_uuid, response):
def get_size_virt(self, vdi_uuid, response):
return int(response)

@linstorhostcall(vhdutil.getMaxResizeSize, 'getMaxResizeSize')
def get_max_resize_size(self, vdi_uuid, response):
return int(response)

@linstorhostcall(vhdutil.getSizePhys, 'getSizePhys')
def get_size_phys(self, vdi_uuid, response):
return int(response)
Expand Down Expand Up @@ -286,14 +290,6 @@ def _get_drbd_size(self, path):
def create(self, path, size, static, msize=0):
return self._call_local_method_or_fail(vhdutil.create, path, size, static, msize)

@linstormodifier()
def set_size_virt(self, path, size, jfile):
return self._call_local_method_or_fail(vhdutil.setSizeVirt, path, size, jfile)

@linstormodifier()
def set_size_virt_fast(self, path, size):
return self._call_local_method_or_fail(vhdutil.setSizeVirtFast, path, size)

@linstormodifier()
def set_size_phys(self, path, size, debug=True):
return self._call_local_method_or_fail(vhdutil.setSizePhys, path, size, debug)
Expand Down Expand Up @@ -368,6 +364,21 @@ def deflate(self, vdi_path, new_size, old_size, zeroize=False):
# Remote setters: write locally and try on another host in case of failure.
# --------------------------------------------------------------------------

@linstormodifier()
def set_size_virt(self, path, size, jfile):
kwargs = {
'size': size,
'jfile': jfile
}
return self._call_method(vhdutil.setSizeVirt, 'setSizeVirt', path, use_parent=False, **kwargs)

@linstormodifier()
def set_size_virt_fast(self, path, size):
kwargs = {
'size': size
}
return self._call_method(vhdutil.setSizeVirtFast, 'setSizeVirtFast', path, use_parent=False, **kwargs)

@linstormodifier()
def force_parent(self, path, parentPath, parentRaw=False):
kwargs = {
Expand Down

0 comments on commit ac6a9d8

Please sign in to comment.