Skip to content

Commit 120c99c

Browse files
committed
fix(cleanup.py): resize on a primary host (#82)
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]>
1 parent a777b53 commit 120c99c

File tree

4 files changed

+110
-8
lines changed

4 files changed

+110
-8
lines changed

drivers/cleanup.py

+55
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,61 @@ def _setHidden(self, hidden=True) -> None:
17371737
else:
17381738
VDI._setHidden(self, hidden)
17391739

1740+
@override
1741+
def _increaseSizeVirt(self, size, atomic=True):
1742+
if self.raw:
1743+
offset = self.drbd_size
1744+
if self.sizeVirt < size:
1745+
oldSize = self.drbd_size
1746+
self.drbd_size = LinstorVolumeManager.round_up_volume_size(size)
1747+
Util.log(" Growing %s: %d->%d" % (self.path, oldSize, self.drbd_size))
1748+
self.sr._linstor.resize_volume(self.uuid, self.drbd_size)
1749+
offset = oldSize
1750+
unfinishedZero = False
1751+
jval = self.sr.journaler.get(LinstorJournaler.ZERO, self.uuid)
1752+
if jval:
1753+
unfinishedZero = True
1754+
offset = int(jval)
1755+
length = self.drbd_size - offset
1756+
if not length:
1757+
return
1758+
1759+
if unfinishedZero:
1760+
Util.log(" ==> Redoing unfinished zeroing out")
1761+
else:
1762+
self.sr.journaler.create(LinstorJournaler.ZERO, self.uuid, str(offset))
1763+
Util.log(" Zeroing %s: from %d, %dB" % (self.path, offset, length))
1764+
abortTest = lambda: IPCFlag(self.sr.uuid).test(FLAG_TYPE_ABORT)
1765+
func = lambda: util.zeroOut(self.path, offset, length)
1766+
Util.runAbortable(func, True, self.sr.uuid, abortTest, VDI.POLL_INTERVAL, 0)
1767+
self.sr.journaler.remove(LinstorJournaler.ZERO, self.uuid)
1768+
return
1769+
1770+
if self.sizeVirt >= size:
1771+
return
1772+
Util.log(" Expanding VHD virt size for VDI %s: %s -> %s" % \
1773+
(self, Util.num2str(self.sizeVirt), Util.num2str(size)))
1774+
1775+
msize = self.sr._vhdutil.get_max_resize_size(self.uuid) * 1024 * 1024
1776+
if (size <= msize):
1777+
self.sr._vhdutil.set_size_virt_fast(self.path, size)
1778+
else:
1779+
if atomic:
1780+
vdiList = self._getAllSubtree()
1781+
self.sr.lock()
1782+
try:
1783+
self.sr.pauseVDIs(vdiList)
1784+
try:
1785+
self._setSizeVirt(size)
1786+
finally:
1787+
self.sr.unpauseVDIs(vdiList)
1788+
finally:
1789+
self.sr.unlock()
1790+
else:
1791+
self._setSizeVirt(size)
1792+
1793+
self.sizeVirt = self.sr._vhdutil.get_size_virt(self.uuid)
1794+
17401795
@override
17411796
def _setSizeVirt(self, size) -> None:
17421797
jfile = self.uuid + '-jvhd'

drivers/linstor-manager

+35
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,15 @@ def get_allocated_size(session, args):
485485
raise
486486

487487

488+
def get_max_resize_size(session, args):
489+
try:
490+
device_path = args['devicePath']
491+
return str(vhdutil.getMaxResizeSize(device_path))
492+
except Exception as e:
493+
util.SMlog('linstor-manager:get_size_phys error: {}'.format(e))
494+
raise
495+
496+
488497
def get_depth(session, args):
489498
try:
490499
device_path = args['devicePath']
@@ -524,6 +533,29 @@ def get_drbd_size(session, args):
524533
raise
525534

526535

536+
def set_size_virt(session, args):
537+
try:
538+
device_path = args['devicePath']
539+
size = int(args['size'])
540+
jfile = args['jfile']
541+
vhdutil.setSizeVirt(device_path, size, jfile)
542+
return ''
543+
except Exception as e:
544+
util.SMlog('linstor-manager:set_size_virt error: {}'.format(e))
545+
raise
546+
547+
548+
def set_size_virt_fast(session, args):
549+
try:
550+
device_path = args['devicePath']
551+
size = int(args['size'])
552+
vhdutil.setSizeVirtFast(device_path, size)
553+
return ''
554+
except Exception as e:
555+
util.SMlog('linstor-manager:set_size_virt_fast error: {}'.format(e))
556+
raise
557+
558+
527559
def set_parent(session, args):
528560
try:
529561
device_path = args['devicePath']
@@ -1211,6 +1243,7 @@ if __name__ == '__main__':
12111243
'hasParent': has_parent,
12121244
'getParent': get_parent,
12131245
'getSizeVirt': get_size_virt,
1246+
'getMaxResizeSize': get_max_resize_size,
12141247
'getSizePhys': get_size_phys,
12151248
'getAllocatedSize': get_allocated_size,
12161249
'getDepth': get_depth,
@@ -1222,6 +1255,8 @@ if __name__ == '__main__':
12221255

12231256
# Called by cleanup.py to coalesce when a primary
12241257
# is opened on a non-local host.
1258+
'setSizeVirt': set_size_virt,
1259+
'setSizeVirtFast': set_size_virt_fast,
12251260
'setParent': set_parent,
12261261
'coalesce': coalesce,
12271262
'repair': repair,

drivers/linstorjournaler.py

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class LinstorJournaler:
4444
"""
4545
CLONE = 'clone'
4646
INFLATE = 'inflate'
47+
ZERO = 'zero'
4748

4849
@staticmethod
4950
def default_logger(*args):

drivers/linstorvhdutil.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ def _get_parent(self, vdi_uuid, response):
248248
def get_size_virt(self, vdi_uuid, response):
249249
return int(response)
250250

251+
@linstorhostcall(vhdutil.getMaxResizeSize, 'getMaxResizeSize')
252+
def get_max_resize_size(self, vdi_uuid, response):
253+
return int(response)
254+
251255
@linstorhostcall(vhdutil.getSizePhys, 'getSizePhys')
252256
def get_size_phys(self, vdi_uuid, response):
253257
return int(response)
@@ -286,14 +290,6 @@ def _get_drbd_size(self, path):
286290
def create(self, path, size, static, msize=0):
287291
return self._call_local_method_or_fail(vhdutil.create, path, size, static, msize)
288292

289-
@linstormodifier()
290-
def set_size_virt(self, path, size, jfile):
291-
return self._call_local_method_or_fail(vhdutil.setSizeVirt, path, size, jfile)
292-
293-
@linstormodifier()
294-
def set_size_virt_fast(self, path, size):
295-
return self._call_local_method_or_fail(vhdutil.setSizeVirtFast, path, size)
296-
297293
@linstormodifier()
298294
def set_size_phys(self, path, size, debug=True):
299295
return self._call_local_method_or_fail(vhdutil.setSizePhys, path, size, debug)
@@ -368,6 +364,21 @@ def deflate(self, vdi_path, new_size, old_size, zeroize=False):
368364
# Remote setters: write locally and try on another host in case of failure.
369365
# --------------------------------------------------------------------------
370366

367+
@linstormodifier()
368+
def set_size_virt(self, path, size, jfile):
369+
kwargs = {
370+
'size': size,
371+
'jfile': jfile
372+
}
373+
return self._call_method(vhdutil.setSizeVirt, 'setSizeVirt', path, use_parent=False, **kwargs)
374+
375+
@linstormodifier()
376+
def set_size_virt_fast(self, path, size):
377+
kwargs = {
378+
'size': size
379+
}
380+
return self._call_method(vhdutil.setSizeVirtFast, 'setSizeVirtFast', path, use_parent=False, **kwargs)
381+
371382
@linstormodifier()
372383
def force_parent(self, path, parentPath, parentRaw=False):
373384
kwargs = {

0 commit comments

Comments
 (0)