improve disk I/O error handling during cleanup

This is a test PR I use it to share code with folks who have
access to a lab environment where they are experiencing Disk problems
that I am investigating right now.

I am not proposing any feature or bugfix yet, please ignore the code while
my own -1 is on the change.

Change-Id: I032dda8530e915c431c5e71e653197df27b7477f
Signed-off-by: Adam Rozman <adam.rozman@est.tech>
This commit is contained in:
Adam Rozman 2024-02-13 11:09:50 +02:00 committed by Adam Rozman
parent 118da00f2f
commit 4c437e9981
1 changed files with 23 additions and 7 deletions

View File

@ -551,21 +551,37 @@ def destroy_disk_metadata(dev, node_uuid):
dev_size = get_dev_block_size(dev)
if dev_size < GPT_SIZE_SECTORS:
dd_count = 'count=%s' % dev_size
utils.execute('dd', 'bs=512', 'if=/dev/zero', dd_device, dd_count,
'oflag=direct', run_as_root=True, use_standard_locale=True)
try:
utils.execute('dd', 'bs=512', 'if=/dev/zero', dd_device, dd_count,
'oflag=direct', run_as_root=True,
use_standard_locale=True)
except Exception as e :
LOG.info("Destroying metadata on device %(device) Error %(error)"
"Destruction with dd dev_size < GPT_SIZE_SECTORS."
% {'device': dev, 'error': e} )
# Overwrite the Secondary GPT, do this only if there could be one
if dev_size > GPT_SIZE_SECTORS:
gpt_backup = dev_size - GPT_SIZE_SECTORS
dd_seek = 'seek=%i' % gpt_backup
dd_count = 'count=%s' % GPT_SIZE_SECTORS
utils.execute('dd', 'bs=512', 'if=/dev/zero', dd_device, dd_count,
'oflag=direct', dd_seek, run_as_root=True,
use_standard_locale=True)
try:
utils.execute('dd', 'bs=512', 'if=/dev/zero', dd_device, dd_count,
'oflag=direct', dd_seek, run_as_root=True,
use_standard_locale=True)
except Exception as e :
LOG.info("Destroying metadata on device %(device) Error %(error)"
"Destruction with dd dev_size > GPT_SIZE_SECTORS."
% {'device': dev, 'error': e} )
# Go ahead and let sgdisk run as well.
utils.execute('sgdisk', '-Z', dev, run_as_root=True,
use_standard_locale=True)
try:
utils.execute('sgdisk', '-Z', dev, run_as_root=True,
use_standard_locale=True)
except:
LOG.info("Destroying metadata on device %(device) Error %(error)"
"Destruction with sgdisk."
% {'device': dev, 'error': e} )
try:
utils.wait_for_disk_to_become_available(dev)