From 6bc6469bc6750ccc388971d5b2f7e3fe98aba8f9 Mon Sep 17 00:00:00 2001 From: Eddie Yen Date: Mon, 14 Oct 2019 05:24:46 +0000 Subject: [PATCH] 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 1d5f753fb13bcc3659b4abd1bb768de8550a6dc4) --- docker/ceph/ceph-osd/extend_start.sh | 59 ++++++++++------------------ 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/docker/ceph/ceph-osd/extend_start.sh b/docker/ceph/ceph-osd/extend_start.sh index 5590afabde..f1a7f776f6 100644 --- a/docker/ceph/ceph-osd/extend_start.sh +++ b/docker/ceph/ceph-osd/extend_start.sh @@ -33,6 +33,16 @@ function wait_partition_appear { 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 # of the KOLLA_BOOTSTRAP variable being set, including empty. if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then @@ -48,47 +58,26 @@ if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then if [[ "${USE_EXTERNAL_JOURNAL}" == "False" ]]; then # Formatting disk for ceph if [[ "${OSD_STORETYPE}" == "bluestore" ]]; then - if [[ "${OSD_BS_DEV}" =~ "/dev/loop" ]]; then - sgdisk --zap-all -- "${OSD_BS_DEV}""p${OSD_BS_PARTNUM}" - else - sgdisk --zap-all -- "${OSD_BS_DEV}""${OSD_BS_PARTNUM}" - fi + sgdisk --zap-all -- "$(part_name_checker $OSD_BS_DEV $OSD_BS_PARTNUM)" 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 -- "${OSD_BS_BLK_DEV}""p${OSD_BS_BLK_PARTNUM}" - else - sgdisk --zap-all -- "${OSD_BS_BLK_DEV}""${OSD_BS_BLK_PARTNUM}" - fi + sgdisk --zap-all -- "$(part_name_checker ${OSD_BS_BLK_DEV} ${OSD_BS_BLK_PARTNUM})" else sgdisk --zap-all -- "${OSD_BS_DEV}" sgdisk --new=1:0:+100M --mbrtogpt -- "${OSD_BS_DEV}" sgdisk --largest-new=2 --mbrtogpt -- "${OSD_BS_DEV}" 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 + wait_partition_appear "$(part_name_checker $OSD_BS_DEV 2)" + sgdisk --zap-all -- "$(part_name_checker $OSD_BS_DEV 2)" fi 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 -- "${OSD_BS_WAL_DEV}""p${OSD_BS_WAL_PARTNUM}" - else - sgdisk --zap-all -- "${OSD_BS_WAL_DEV}""${OSD_BS_WAL_PARTNUM}" - fi + sgdisk --zap-all -- "$(part_name_checker $OSD_BS_WAL_DEV $OSD_BS_WAL_PARTNUM)" fi 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 -- "${OSD_BS_DB_DEV}""p${OSD_BS_DB_PARTNUM}" - else - sgdisk --zap-all -- "${OSD_BS_DB_DEV}""${OSD_BS_DB_PARTNUM}" - fi + sgdisk --zap-all -- "$(part_name_checker $OSD_BS_DB_DEV $OSD_BS_DB_PARTNUM)" fi else sgdisk --zap-all -- "${OSD_DEV}" @@ -106,13 +95,8 @@ if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then OSD_DIR="/var/lib/ceph/osd/ceph-${OSD_ID}" mkdir -p "${OSD_DIR}" - if [[ "${OSD_BS_DEV}" =~ "/dev/loop" ]]; then - mkfs.xfs -f "${OSD_BS_DEV}""p${OSD_BS_PARTNUM}" - 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 + mkfs.xfs -f "$(part_name_checker $OSD_BS_DEV $OSD_BS_PARTNUM)" + mount "$(part_name_checker $OSD_BS_DEV $OSD_BS_PARTNUM)" "${OSD_DIR}" # This will through an error about no key existing. That is normal. It then # 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" - if [[ "${OSD_BS_DEV}" =~ "/dev/loop" ]]; then - umount "${OSD_BS_DEV}""p${OSD_BS_PARTNUM}" - else - umount "${OSD_BS_DEV}""${OSD_BS_PARTNUM}" - fi + umount "$(part_name_checker $OSD_BS_DEV $OSD_BS_PARTNUM)" + else OSD_ID=$(ceph osd create) OSD_DIR="/var/lib/ceph/osd/ceph-${OSD_ID}"