Skip to content

Commit d52dd07

Browse files
authored
fix(cleanup.py): resize on a primary host (#81)
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 5aeaf47 commit d52dd07

File tree

4 files changed

+109
-8
lines changed

4 files changed

+109
-8
lines changed

drivers/cleanup.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,60 @@ def _setHidden(self, hidden=True):
15671567
else:
15681568
VDI._setHidden(self, hidden)
15691569

1570+
def _increaseSizeVirt(self, size, atomic=True):
1571+
if self.raw:
1572+
offset = self.drbd_size
1573+
if self.sizeVirt < size:
1574+
oldSize = self.drbd_size
1575+
self.drbd_size = LinstorVolumeManager.round_up_volume_size(size)
1576+
Util.log(" Growing %s: %d->%d" % (self.path, oldSize, self.drbd_size))
1577+
self.sr._linstor.resize_volume(self.uuid, self.drbd_size)
1578+
offset = oldSize
1579+
unfinishedZero = False
1580+
jval = self.sr.journaler.get(LinstorJournaler.ZERO, self.uuid)
1581+
if jval:
1582+
unfinishedZero = True
1583+
offset = int(jval)
1584+
length = self.drbd_size - offset
1585+
if not length:
1586+
return
1587+
1588+
if unfinishedZero:
1589+
Util.log(" ==> Redoing unfinished zeroing out")
1590+
else:
1591+
self.sr.journaler.create(LinstorJournaler.ZERO, self.uuid, str(offset))
1592+
Util.log(" Zeroing %s: from %d, %dB" % (self.path, offset, length))
1593+
abortTest = lambda: IPCFlag(self.sr.uuid).test(FLAG_TYPE_ABORT)
1594+
func = lambda: util.zeroOut(self.path, offset, length)
1595+
Util.runAbortable(func, True, self.sr.uuid, abortTest, VDI.POLL_INTERVAL, 0)
1596+
self.sr.journaler.remove(LinstorJournaler.ZERO, self.uuid)
1597+
return
1598+
1599+
if self.sizeVirt >= size:
1600+
return
1601+
Util.log(" Expanding VHD virt size for VDI %s: %s -> %s" % \
1602+
(self, Util.num2str(self.sizeVirt), Util.num2str(size)))
1603+
1604+
msize = self.sr._vhdutil.get_max_resize_size(self.uuid) * 1024 * 1024
1605+
if (size <= msize):
1606+
self.sr._vhdutil.set_size_virt_fast(self.path, size)
1607+
else:
1608+
if atomic:
1609+
vdiList = self._getAllSubtree()
1610+
self.sr.lock()
1611+
try:
1612+
self.sr.pauseVDIs(vdiList)
1613+
try:
1614+
self._setSizeVirt(size)
1615+
finally:
1616+
self.sr.unpauseVDIs(vdiList)
1617+
finally:
1618+
self.sr.unlock()
1619+
else:
1620+
self._setSizeVirt(size)
1621+
1622+
self.sizeVirt = self.sr._vhdutil.get_size_virt(self.uuid)
1623+
15701624
def _setSizeVirt(self, size):
15711625
jfile = self.uuid + '-jvhd'
15721626
self.sr._linstor.create_volume(

drivers/linstor-manager

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,15 @@ def get_size_phys(session, args):
477477
raise
478478

479479

480+
def get_max_resize_size(session, args):
481+
try:
482+
device_path = args['devicePath']
483+
return str(vhdutil.getMaxResizeSize(device_path))
484+
except Exception as e:
485+
util.SMlog('linstor-manager:get_size_phys error: {}'.format(e))
486+
raise
487+
488+
480489
def get_depth(session, args):
481490
try:
482491
device_path = args['devicePath']
@@ -516,6 +525,29 @@ def get_drbd_size(session, args):
516525
raise
517526

518527

528+
def set_size_virt(session, args):
529+
try:
530+
device_path = args['devicePath']
531+
size = int(args['size'])
532+
jfile = args['jfile']
533+
vhdutil.setSizeVirt(device_path, size, jfile)
534+
return ''
535+
except Exception as e:
536+
util.SMlog('linstor-manager:set_size_virt error: {}'.format(e))
537+
raise
538+
539+
540+
def set_size_virt_fast(session, args):
541+
try:
542+
device_path = args['devicePath']
543+
size = int(args['size'])
544+
vhdutil.setSizeVirtFast(device_path, size)
545+
return ''
546+
except Exception as e:
547+
util.SMlog('linstor-manager:set_size_virt_fast error: {}'.format(e))
548+
raise
549+
550+
519551
def set_parent(session, args):
520552
try:
521553
device_path = args['devicePath']
@@ -1204,6 +1236,7 @@ if __name__ == '__main__':
12041236
'hasParent': has_parent,
12051237
'getParent': get_parent,
12061238
'getSizeVirt': get_size_virt,
1239+
'getMaxResizeSize': get_max_resize_size,
12071240
'getSizePhys': get_size_phys,
12081241
'getDepth': get_depth,
12091242
'getKeyHash': get_key_hash,
@@ -1214,6 +1247,8 @@ if __name__ == '__main__':
12141247

12151248
# Called by cleanup.py to coalesce when a primary
12161249
# is opened on a non-local host.
1250+
'setSizeVirt': set_size_virt,
1251+
'setSizeVirtFast': set_size_virt_fast,
12171252
'setParent': set_parent,
12181253
'coalesce': coalesce,
12191254
'repair': repair,

drivers/linstorjournaler.py

Lines changed: 1 addition & 0 deletions
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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ def _get_parent(self, vdi_uuid, response):
267267
def get_size_virt(self, vdi_uuid, response):
268268
return int(response)
269269

270+
@linstorhostcall(vhdutil.getMaxResizeSize, 'getMaxResizeSize')
271+
def get_max_resize_size(self, vdi_uuid, response):
272+
return int(response)
273+
270274
@linstorhostcall(vhdutil.getSizePhys, 'getSizePhys')
271275
def get_size_phys(self, vdi_uuid, response):
272276
return int(response)
@@ -301,14 +305,6 @@ def _get_drbd_size(self, path):
301305
def create(self, path, size, static, msize=0):
302306
return self._call_local_method_or_fail(vhdutil.create, path, size, static, msize)
303307

304-
@linstormodifier()
305-
def set_size_virt(self, path, size, jfile):
306-
return self._call_local_method_or_fail(vhdutil.setSizeVirt, path, size, jfile)
307-
308-
@linstormodifier()
309-
def set_size_virt_fast(self, path, size):
310-
return self._call_local_method_or_fail(vhdutil.setSizeVirtFast, path, size)
311-
312308
@linstormodifier()
313309
def set_size_phys(self, path, size, debug=True):
314310
return self._call_local_method_or_fail(vhdutil.setSizePhys, path, size, debug)
@@ -383,6 +379,21 @@ def deflate(self, vdi_path, new_size, old_size, zeroize=False):
383379
# Remote setters: write locally and try on another host in case of failure.
384380
# --------------------------------------------------------------------------
385381

382+
@linstormodifier()
383+
def set_size_virt(self, path, size, jfile):
384+
kwargs = {
385+
'size': size,
386+
'jfile': jfile
387+
}
388+
return self._call_method(vhdutil.setSizeVirt, 'setSizeVirt', path, use_parent=False, **kwargs)
389+
390+
@linstormodifier()
391+
def set_size_virt_fast(self, path, size):
392+
kwargs = {
393+
'size': size
394+
}
395+
return self._call_method(vhdutil.setSizeVirtFast, 'setSizeVirtFast', path, use_parent=False, **kwargs)
396+
386397
@linstormodifier()
387398
def force_parent(self, path, parentPath, parentRaw=False):
388399
kwargs = {

0 commit comments

Comments
 (0)