Software RAID: Call udev_settle before creation

This patch fixes a race during software RAID creation:
we create the partition with parted, the kernel then
notifies udev, but we need to wait for udevd to create
the device files before calling mdadm to create the
md device.

Credits to jcosmao for finding this.

Change-Id: I642f28acc351cf50263e37dfbc8468bf59de2cc5
This commit is contained in:
Arne Wiebalck 2021-10-04 16:57:56 +02:00
parent 8d901ff0dc
commit 9d707e9f4b
2 changed files with 14 additions and 0 deletions

View File

@ -2152,6 +2152,13 @@ class GenericHardwareManager(HardwareManager):
utils.execute('parted', device, '-s', '-a',
'optimal', '--', 'mkpart', 'primary',
start_str, end_str)
# Parted/udev partition creation is asynchronous.
# Wait for udev events to be processed before going to
# next step. This avoids getting errors at mdadm
# create because a device is not ready yet.
_udev_settle()
# Necessary, if we want to avoid hitting
# an error when creating the mdadm array below
# 'mdadm: cannot open /dev/nvme1n1p1: No such file

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Fixes a race on software RAID creation: since the creation of
partitions is asynchronous, we need to wait for all udev events
to be processed before we can use the partitions to create an
md device.