Change to call blkid command once to reduce boot time 48/273648/1 accepted/tizen/6.5/unified/20220411.131407 submit/tizen_6.5/20220411.104602
authorSangYoun Kwak <sy.kwak@samsung.com>
Mon, 11 Apr 2022 06:06:01 +0000 (15:06 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Mon, 11 Apr 2022 10:21:42 +0000 (10:21 +0000)
* It is better to call blkid in function process_rootfs and process_userfs than using
get_blk_dev_path function (performance and complexity)

Change-Id: I837e28d1883782ba1c0ae5bfb4f6b98e83334f0f
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
(cherry picked from commit 46b852f937da25047649b74d9cf116bd303165ca)

scripts/init.sh

index 3944978..95cd719 100755 (executable)
@@ -16,6 +16,23 @@ IN_INITRD=0
 NEED_RESIZEFS=1
 USERFS_ENCRYPTED=0
 
+BLKID_LINES=()
+
+function get_blk_dev_path()
+{
+    PART_REGEX="(^|[ ])$1($|[ ])"
+
+    for LINE in ${BLKID_LINES[@]}; do
+        if [[ $LINE =~ $PART_REGEX ]]; then
+            IFS=':'
+            SPLITTED=($LINE)
+            echo "${SPLITTED[0]}"
+            IFS=$'\n'
+            return
+        fi
+    done
+}
+
 function find_partitions()
 {
     P_SLOT=$([[ $(</proc/cmdline) =~ partition_ab=([ab]) ]]; echo ${BASH_REMATCH[1]})
@@ -26,47 +43,53 @@ function find_partitions()
         echo "Using A/B slot: ${P_SLOT}"
     fi
 
-    ROOTFS=`/sbin/blkid -t PARTLABEL=rootfs${P_SUFFIX} -o device`
+    IFS_BACKUP=$IFS
+    IFS=$'\n'
+    BLKID_LINES=($(/sbin/blkid))
+
+    ROOTFS=`get_blk_dev_path "PARTLABEL=\"rootfs${P_SUFFIX}\""`
     if [ x$ROOTFS = "x" ]
     then
-        ROOTFS=`/sbin/blkid -L rootfs`
+        ROOTFS=`get_blk_dev_path "LABEL=\"rootfs\""`
     fi
     if [ x$ROOTFS = "x" ]
     then
-        ROOTFS=`/sbin/blkid -t LABEL=contain-rootfs -o device`
+        ROOTFS=`get_blk_dev_path "LABEL=\"contain-rootfs\""`
     fi
 
-    DATAFS=`/sbin/blkid -t PARTLABEL=system-data -o device`
+    DATAFS=`get_blk_dev_path "PARTLABEL=\"system-data\""`
     if [ x$DATAFS = "x" ]
     then
-        DATAFS=`/sbin/blkid -L system-data`
+        DATAFS=`get_blk_dev_path "LABEL=\"system-data\""`
     fi
     if [ x$DATAFS = "x" ]
     then
-        DATAFS=`/sbin/blkid -t LABEL=contain-sysdata -o device`
+        DATAFS=`get_blk_dev_path "LABEL=\"contain-sysdata\""`
     fi
 
-    USERFS=`/sbin/blkid -t PARTLABEL=user -o device`
+    USERFS=`get_blk_dev_path "PARTLABEL=\"user\""`
     if [ x$USERFS = "x" ]
     then
-        USERFS=`/sbin/blkid -L user`
+        USERFS=`get_blk_dev_path "LABEL=\"user\""`
     fi
     if [ x$USERFS = "x" ]
     then
-        USERFS=`/sbin/blkid -t LABEL=contain-user -o device`
+        USERFS=`get_blk_dev_path "LABEL=\"contain-user\""`
     fi
 
-    MODULES=`/sbin/blkid -t PARTLABEL=modules${P_SUFFIX} -o device`
+    MODULES=`get_blk_dev_path "PARTLABEL=\"modules${P_SUFFIX}\""`
     if [ x$MODULES = "x" ]
     then
-        MODULES=`/sbin/blkid -L modules`
+        MODULES=`get_blk_dev_path "LABEL=\"modules\""`
     fi
 
-    HALFS=`/sbin/blkid -t PARTLABEL=hal${P_SUFFIX} -o device`
+    HALFS=`get_blk_dev_path "PARTLABEL=\"hal${P_SUFFIX}\""`
     if [ x$HALFS = "x" ]
     then
-        HALFS=`/sbin/blkid -L hal`
+        HALFS=`get_blk_dev_path "LABEL=\"hal\""`
     fi
+
+    IFS=$IFS_BACKUP
 }
 
 function check_flags()