Add disk dev name check function

This patch will add new function in extend_start.sh for OSD
creation. Not only support loop device but also others that
disk dev layout is end with numbers.

Change-Id: Iee5f8b8581d70166de6eba1bdc9e42766fe8cb48
Closes-Bug: #1847014
(cherry picked from commit 1d5f753fb1)
This commit is contained in:
Eddie Yen 2019-10-14 05:24:46 +00:00
parent 7e31dac6a3
commit 6bc6469bc6
1 changed files with 20 additions and 39 deletions

View File

@ -33,6 +33,16 @@ function wait_partition_appear {
exit 1 exit 1
} }
# Few storage device like loop or NVMe, wiil add "p" between disk & partition
# name if disk layout is end with number. This function will fix to correct format.
function part_name_checker {
if [[ $1 =~ .*[0-9] ]]; then
echo ${1}p${2}
else
echo ${1}${2}
fi
}
# Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases # Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases
# of the KOLLA_BOOTSTRAP variable being set, including empty. # of the KOLLA_BOOTSTRAP variable being set, including empty.
if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
@ -48,47 +58,26 @@ if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
if [[ "${USE_EXTERNAL_JOURNAL}" == "False" ]]; then if [[ "${USE_EXTERNAL_JOURNAL}" == "False" ]]; then
# Formatting disk for ceph # Formatting disk for ceph
if [[ "${OSD_STORETYPE}" == "bluestore" ]]; then if [[ "${OSD_STORETYPE}" == "bluestore" ]]; then
if [[ "${OSD_BS_DEV}" =~ "/dev/loop" ]]; then sgdisk --zap-all -- "$(part_name_checker $OSD_BS_DEV $OSD_BS_PARTNUM)"
sgdisk --zap-all -- "${OSD_BS_DEV}""p${OSD_BS_PARTNUM}"
else
sgdisk --zap-all -- "${OSD_BS_DEV}""${OSD_BS_PARTNUM}"
fi
if [ -n "${OSD_BS_BLK_DEV}" ] && [ "${OSD_BS_DEV}" != "${OSD_BS_BLK_DEV}" ] && [ -n "${OSD_BS_BLK_PARTNUM}" ]; then if [ -n "${OSD_BS_BLK_DEV}" ] && [ "${OSD_BS_DEV}" != "${OSD_BS_BLK_DEV}" ] && [ -n "${OSD_BS_BLK_PARTNUM}" ]; then
if [[ "${OSD_BS_BLK_DEV}" =~ "/dev/loop" ]]; then sgdisk --zap-all -- "$(part_name_checker ${OSD_BS_BLK_DEV} ${OSD_BS_BLK_PARTNUM})"
sgdisk --zap-all -- "${OSD_BS_BLK_DEV}""p${OSD_BS_BLK_PARTNUM}"
else
sgdisk --zap-all -- "${OSD_BS_BLK_DEV}""${OSD_BS_BLK_PARTNUM}"
fi
else else
sgdisk --zap-all -- "${OSD_BS_DEV}" sgdisk --zap-all -- "${OSD_BS_DEV}"
sgdisk --new=1:0:+100M --mbrtogpt -- "${OSD_BS_DEV}" sgdisk --new=1:0:+100M --mbrtogpt -- "${OSD_BS_DEV}"
sgdisk --largest-new=2 --mbrtogpt -- "${OSD_BS_DEV}" sgdisk --largest-new=2 --mbrtogpt -- "${OSD_BS_DEV}"
partprobe_device "${OSD_BS_DEV}" partprobe_device "${OSD_BS_DEV}"
if [[ "${OSD_BS_DEV}" =~ "/dev/loop" ]]; then wait_partition_appear "$(part_name_checker $OSD_BS_DEV 2)"
wait_partition_appear "${OSD_BS_DEV}"p2 sgdisk --zap-all -- "$(part_name_checker $OSD_BS_DEV 2)"
sgdisk --zap-all -- "${OSD_BS_DEV}"p2
else
wait_partition_appear "${OSD_BS_DEV}"2
sgdisk --zap-all -- "${OSD_BS_DEV}"2
fi
fi fi
if [ -n "${OSD_BS_WAL_DEV}" ] && [ "${OSD_BS_BLK_DEV}" != "${OSD_BS_WAL_DEV}" ] && [ -n "${OSD_BS_WAL_PARTNUM}" ]; then if [ -n "${OSD_BS_WAL_DEV}" ] && [ "${OSD_BS_BLK_DEV}" != "${OSD_BS_WAL_DEV}" ] && [ -n "${OSD_BS_WAL_PARTNUM}" ]; then
if [[ "${OSD_BS_WAL_DEV}" =~ "/dev/loop" ]]; then sgdisk --zap-all -- "$(part_name_checker $OSD_BS_WAL_DEV $OSD_BS_WAL_PARTNUM)"
sgdisk --zap-all -- "${OSD_BS_WAL_DEV}""p${OSD_BS_WAL_PARTNUM}"
else
sgdisk --zap-all -- "${OSD_BS_WAL_DEV}""${OSD_BS_WAL_PARTNUM}"
fi
fi fi
if [ -n "${OSD_BS_DB_DEV}" ] && [ "${OSD_BS_BLK_DEV}" != "${OSD_BS_DB_DEV}" ] && [ -n "${OSD_BS_DB_PARTNUM}" ]; then if [ -n "${OSD_BS_DB_DEV}" ] && [ "${OSD_BS_BLK_DEV}" != "${OSD_BS_DB_DEV}" ] && [ -n "${OSD_BS_DB_PARTNUM}" ]; then
if [[ "${OSD_BS_DB_DEV}" =~ "/dev/loop" ]]; then sgdisk --zap-all -- "$(part_name_checker $OSD_BS_DB_DEV $OSD_BS_DB_PARTNUM)"
sgdisk --zap-all -- "${OSD_BS_DB_DEV}""p${OSD_BS_DB_PARTNUM}"
else
sgdisk --zap-all -- "${OSD_BS_DB_DEV}""${OSD_BS_DB_PARTNUM}"
fi
fi fi
else else
sgdisk --zap-all -- "${OSD_DEV}" sgdisk --zap-all -- "${OSD_DEV}"
@ -106,13 +95,8 @@ if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
OSD_DIR="/var/lib/ceph/osd/ceph-${OSD_ID}" OSD_DIR="/var/lib/ceph/osd/ceph-${OSD_ID}"
mkdir -p "${OSD_DIR}" mkdir -p "${OSD_DIR}"
if [[ "${OSD_BS_DEV}" =~ "/dev/loop" ]]; then mkfs.xfs -f "$(part_name_checker $OSD_BS_DEV $OSD_BS_PARTNUM)"
mkfs.xfs -f "${OSD_BS_DEV}""p${OSD_BS_PARTNUM}" mount "$(part_name_checker $OSD_BS_DEV $OSD_BS_PARTNUM)" "${OSD_DIR}"
mount "${OSD_BS_DEV}""p${OSD_BS_PARTNUM}" "${OSD_DIR}"
else
mkfs.xfs -f "${OSD_BS_DEV}""${OSD_BS_PARTNUM}"
mount "${OSD_BS_DEV}""${OSD_BS_PARTNUM}" "${OSD_DIR}"
fi
# This will through an error about no key existing. That is normal. It then # This will through an error about no key existing. That is normal. It then
# creates the key in the next step. # creates the key in the next step.
@ -158,11 +142,8 @@ if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
ceph auth add "osd.${OSD_ID}" osd 'allow *' mon 'allow profile osd' -i "${OSD_DIR}/keyring" ceph auth add "osd.${OSD_ID}" osd 'allow *' mon 'allow profile osd' -i "${OSD_DIR}/keyring"
if [[ "${OSD_BS_DEV}" =~ "/dev/loop" ]]; then umount "$(part_name_checker $OSD_BS_DEV $OSD_BS_PARTNUM)"
umount "${OSD_BS_DEV}""p${OSD_BS_PARTNUM}"
else
umount "${OSD_BS_DEV}""${OSD_BS_PARTNUM}"
fi
else else
OSD_ID=$(ceph osd create) OSD_ID=$(ceph osd create)
OSD_DIR="/var/lib/ceph/osd/ceph-${OSD_ID}" OSD_DIR="/var/lib/ceph/osd/ceph-${OSD_ID}"