Add partition detection to fix osd initialization failure

The changes in the following commit did not completely solve the
problem of osd initialization failure:
https://review.opendev.org/652612

In order to solve this problem, the partprobe command consistent with
ceph-disk is added, and then a loop is added to detect the partition,
which is acquired every 1s. When the partition appears, the osd
initialization is continued.

Change-Id: I0ca255c6358132d9e3acfa6b610b70a78756512c
Closes-bug: #1824787
This commit is contained in:
wangwei 2019-07-10 16:29:48 +09:00
parent 008aa957f2
commit 342c9f0cd0
1 changed files with 29 additions and 1 deletions

View File

@ -7,6 +7,32 @@ if [[ $(stat -c %a /var/log/kolla/ceph) != "755" ]]; then
chmod 755 /var/log/kolla/ceph
fi
# Inform the os about partition table changes
function partprobe_device {
local device=$1
udevadm settle --timeout=600
flock -s ${device} partprobe ${device}
udevadm settle --timeout=600
}
# In some cases, the disk partition will not appear immediately, so check every
# 1s, try up to 10 times. In general, this interval is enough.
function wait_partition_appear {
local dev_part=$1
local part_name=$(echo ${dev_part} | awk -F '/' '{print $NF}')
for(( i=1; i<11; i++ )); do
flag=$(ls /dev | awk '/'"${part_name}"'/{print $0}' | wc -l)
if [[ "${flag}" -eq 0 ]]; then
echo "sleep 1 waits for the partition ${dev_part} to appear: ${i}"
sleep 1
else
return 0
fi
done
echo "The device /dev/${dev_part} does not appear within the limited time 10s."
exit 1
}
# Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases
# of the KOLLA_BOOTSTRAP variable being set, including empty.
if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
@ -38,11 +64,13 @@ if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
sgdisk --zap-all -- "${OSD_BS_DEV}"
sgdisk --new=1:0:+100M --mbrtogpt -- "${OSD_BS_DEV}"
sgdisk --largest-new=2 --mbrtogpt -- "${OSD_BS_DEV}"
partprobe || true
partprobe_device "${OSD_BS_DEV}"
if [[ "${OSD_BS_DEV}" =~ "/dev/loop" ]]; then
wait_partition_appear "${OSD_BS_DEV}"p2
sgdisk --zap-all -- "${OSD_BS_DEV}"p2
else
wait_partition_appear "${OSD_BS_DEV}"2
sgdisk --zap-all -- "${OSD_BS_DEV}"2
fi
fi