Browse Source

Merge "Add partition detection to fix osd initialization failure" into stable/rocky

tags/7.0.4
Zuul 4 weeks ago
parent
commit
65d5c29753
1 changed files with 29 additions and 1 deletions
  1. 29
    1
      docker/ceph/ceph-osd/extend_start.sh

+ 29
- 1
docker/ceph/ceph-osd/extend_start.sh View File

@@ -7,6 +7,32 @@ if [[ $(stat -c %a /var/log/kolla/ceph) != "755" ]]; then
7 7
     chmod 755 /var/log/kolla/ceph
8 8
 fi
9 9
 
10
+# Inform the os about partition table changes
11
+function partprobe_device {
12
+    local device=$1
13
+    udevadm settle --timeout=600
14
+    flock -s ${device} partprobe ${device}
15
+    udevadm settle --timeout=600
16
+}
17
+
18
+# In some cases, the disk partition will not appear immediately, so check every
19
+# 1s, try up to 10 times. In general, this interval is enough.
20
+function wait_partition_appear {
21
+    local dev_part=$1
22
+    local part_name=$(echo ${dev_part} | awk -F '/' '{print $NF}')
23
+    for(( i=1; i<11; i++ )); do
24
+        flag=$(ls /dev | awk '/'"${part_name}"'/{print $0}' | wc -l)
25
+        if [[ "${flag}" -eq 0 ]]; then
26
+            echo "sleep 1 waits for the partition ${dev_part} to appear: ${i}"
27
+            sleep 1
28
+        else
29
+            return 0
30
+        fi
31
+    done
32
+    echo "The device /dev/${dev_part} does not appear within the limited time 10s."
33
+    exit 1
34
+}
35
+
10 36
 # Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases
11 37
 # of the KOLLA_BOOTSTRAP variable being set, including empty.
12 38
 if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
@@ -38,11 +64,13 @@ if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
38 64
                 sgdisk --zap-all -- "${OSD_BS_DEV}"
39 65
                 sgdisk --new=1:0:+100M --mbrtogpt -- "${OSD_BS_DEV}"
40 66
                 sgdisk --largest-new=2 --mbrtogpt -- "${OSD_BS_DEV}"
41
-                partprobe || true
67
+                partprobe_device "${OSD_BS_DEV}"
42 68
 
43 69
                 if [[ "${OSD_BS_DEV}" =~ "/dev/loop" ]]; then
70
+                    wait_partition_appear "${OSD_BS_DEV}"p2
44 71
                     sgdisk --zap-all -- "${OSD_BS_DEV}"p2
45 72
                 else
73
+                    wait_partition_appear "${OSD_BS_DEV}"2
46 74
                     sgdisk --zap-all -- "${OSD_BS_DEV}"2
47 75
                 fi
48 76
             fi

Loading…
Cancel
Save