growvols: reserve space for spare metadata volume

Currently space is reserved for the metadata volume, but there is also a
spare metadata volume which is used for metadata check and restore.

This change reserves space for the spare. It also changes the volume
reference in the lvextend call to vg/lv_thinpool, the path based
reference results in the spare not growing.

Resolves: rhbz#2232632
Change-Id: If78743bb37f24756c049939645db202261df6775
This commit is contained in:
Steve Baker 2023-08-22 09:44:03 +12:00
parent deb1869c6e
commit 420fb14e8f
2 changed files with 17 additions and 15 deletions

View File

@ -475,7 +475,7 @@ def find_thin_pool(devices, group):
break
if not thin_pool_device:
return
return None, None
# ensure every volume uses the pool
for d in lvs_devices:
@ -490,7 +490,7 @@ def find_thin_pool(devices, group):
raise Exception('All volumes need to be in pool %s. '
'%s is in pool %s' %
(thin_pool_name, lv_name, pool_lv))
return thin_pool_device
return thin_pool_device, thin_pool_name
def main(argv):
@ -522,13 +522,16 @@ def main(argv):
group = find_group(opts)
partnum = find_next_partnum(devices, disk_name)
devname = find_next_device_name(devices, disk_name, partnum)
thin_pool = find_thin_pool(devices, group)
thin_pool, thin_pool_name = find_thin_pool(devices, group)
if thin_pool:
# total size available, reduced by POOL_METADATA_SIZE
# rounded down to whole extent and reduced by 1 extent
# for metadata overhead
# reserve for the size of the metadata volume
size_bytes -= POOL_METADATA_SIZE
# reserve for the size of the spare metadata volume,
# used for metadata check and repair
size_bytes -= POOL_METADATA_SIZE
# round down to a whole extent
size_bytes -= size_bytes % PHYSICAL_EXTENT_BYTES
# reduce for metadata overhead
size_bytes -= PHYSICAL_EXTENT_BYTES
dev_path = '/dev/%s' % devname
grow_vols = find_grow_vols(opts, devices, group, size_bytes)
@ -562,8 +565,7 @@ def main(argv):
'lvextend',
'--poolmetadatasize',
'+%sB' % POOL_METADATA_SIZE,
thin_pool,
dev_path
'%s/%s' % (group, thin_pool_name)
], 'Add %s to thin pool metadata %s' % (
convert_bytes(POOL_METADATA_SIZE), thin_pool)))
commands.append(Command([

View File

@ -433,14 +433,14 @@ class TestGrowvols(base.BaseTestCase):
def test_find_thin_pool(self, mock_execute):
# No thin pool
mock_execute.return_value = LVS
self.assertIsNone(growvols.find_thin_pool(DEVICES, 'vg'))
self.assertEqual((None, None), growvols.find_thin_pool(DEVICES, 'vg'))
mock_execute.assert_called_once_with([
'lvs', '--noheadings', '--options',
'lv_name,lv_dm_path,lv_attr,pool_lv'])
# One thin pool, all volumes use it
mock_execute.return_value = LVS_THIN
self.assertEqual('/dev/mapper/vg-lv_thinpool',
self.assertEqual(('/dev/mapper/vg-lv_thinpool', 'lv_thinpool'),
growvols.find_thin_pool(DEVICES, 'vg'))
# One pool, not used by all volumes
@ -621,14 +621,14 @@ class TestGrowvols(base.BaseTestCase):
mock.call(['pvcreate', '/dev/sda5']),
mock.call(['vgextend', 'vg', '/dev/sda5']),
mock.call(['lvextend', '--poolmetadatasize', '+1073741824B',
'vg/lv_thinpool']),
mock.call(['lvextend', '-L+207253143552B',
'/dev/mapper/vg-lv_thinpool', '/dev/sda5']),
mock.call(['lvextend', '-L+208326885376B',
'/dev/mapper/vg-lv_thinpool', '/dev/sda5']),
mock.call(['lvextend', '--size', '+41662021632B',
mock.call(['lvextend', '--size', '+41448112128B',
'/dev/mapper/vg-lv_home']),
mock.call(['lvextend', '--size', '+83328237568B',
mock.call(['lvextend', '--size', '+82900418560B',
'/dev/mapper/vg-lv_var']),
mock.call(['lvextend', '--size', '+83336626176B',
mock.call(['lvextend', '--size', '+82904612864B',
'/dev/mapper/vg-lv_root']),
mock.call(['xfs_growfs', '/dev/mapper/vg-lv_home']),
mock.call(['xfs_growfs', '/dev/mapper/vg-lv_var']),