Use direct writes when erasing the GPT

Use direct I/O when overwriting the partition table to expose device
failures (which would not be directly noticed otherwise).

Change-Id: Ib0790099d895410681e4a1679bedea62209ff277
This commit is contained in:
Arne Wiebalck 2023-03-01 14:02:47 +01:00
parent 71a7655723
commit ec6ba65392
3 changed files with 19 additions and 12 deletions

View File

@ -627,7 +627,7 @@ def destroy_disk_metadata(dev, node_uuid):
if dev_size < GPT_SIZE_SECTORS:
dd_count = 'count=%s' % dev_size
utils.execute('dd', 'bs=512', 'if=/dev/zero', dd_device, dd_count,
run_as_root=True, use_standard_locale=True)
'oflag=direct', run_as_root=True, use_standard_locale=True)
# Overwrite the Secondary GPT, do this only if there could be one
if dev_size > GPT_SIZE_SECTORS:
@ -635,7 +635,8 @@ def destroy_disk_metadata(dev, node_uuid):
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,
dd_seek, run_as_root=True, use_standard_locale=True)
'oflag=direct', dd_seek, run_as_root=True,
use_standard_locale=True)
# Go ahead and let sgdisk run as well.
utils.execute('sgdisk', '-Z', dev, run_as_root=True,

View File

@ -401,12 +401,12 @@ class DestroyMetaDataTestCase(base.IronicLibTestCase):
mock.call('blockdev', '--getsz', 'fake-dev',
run_as_root=True),
mock.call('dd', 'bs=512', 'if=/dev/zero',
'of=fake-dev', 'count=33',
'of=fake-dev', 'count=33', 'oflag=direct',
run_as_root=True,
use_standard_locale=True),
mock.call('dd', 'bs=512', 'if=/dev/zero',
'of=fake-dev', 'count=33', 'seek=991',
run_as_root=True,
'of=fake-dev', 'count=33', 'oflag=direct',
'seek=991', run_as_root=True,
use_standard_locale=True),
mock.call('sgdisk', '-Z', 'fake-dev',
run_as_root=True,
@ -436,12 +436,12 @@ class DestroyMetaDataTestCase(base.IronicLibTestCase):
mock.call('blockdev', '--getsz', 'fake-dev',
run_as_root=True),
mock.call('dd', 'bs=512', 'if=/dev/zero',
'of=fake-dev', 'count=33',
'of=fake-dev', 'count=33', 'oflag=direct',
run_as_root=True,
use_standard_locale=True),
mock.call('dd', 'bs=512', 'if=/dev/zero',
'of=fake-dev', 'count=33', 'seek=991',
run_as_root=True,
'of=fake-dev', 'count=33', 'oflag=direct',
'seek=991', run_as_root=True,
use_standard_locale=True),
mock.call('sgdisk', '-Z', 'fake-dev',
run_as_root=True,
@ -484,7 +484,7 @@ class DestroyMetaDataTestCase(base.IronicLibTestCase):
mock.call('blockdev', '--getsz', 'fake-dev',
run_as_root=True),
mock.call('dd', 'bs=512', 'if=/dev/zero',
'of=fake-dev', 'count=2',
'of=fake-dev', 'count=2', 'oflag=direct',
run_as_root=True,
use_standard_locale=True),
mock.call('sgdisk', '-Z', 'fake-dev',
@ -507,12 +507,12 @@ class DestroyMetaDataTestCase(base.IronicLibTestCase):
mock.call('blockdev', '--getsz', 'fake-dev',
run_as_root=True),
mock.call('dd', 'bs=512', 'if=/dev/zero',
'of=fake-dev', 'count=33',
'of=fake-dev', 'count=33', 'oflag=direct',
run_as_root=True,
use_standard_locale=True),
mock.call('dd', 'bs=512', 'if=/dev/zero',
'of=fake-dev', 'count=33', 'seek=9',
run_as_root=True,
'of=fake-dev', 'count=33', 'oflag=direct',
'seek=9', run_as_root=True,
use_standard_locale=True),
mock.call('sgdisk', '-Z', 'fake-dev',
run_as_root=True,

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixes a bug when erasing a partition table: the corresponding I/O needs
to be synchronous in order to avoid masking failed write requests to
broken devices.