From ccdd4f289492e84315ea02ce83d685290d08e0ee Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 8 Apr 2021 01:36:49 +0800 Subject: [PATCH] kdump-lib.sh: introduce a helper to get underlying crypt device Resolves: bz1951415 Upstream: fedora Conflict: None commit 3423bbc17f5521de8ff80e76d91ce13657b1cea2 Author: Kairui Song Date: Thu Apr 8 01:36:49 2021 +0800 kdump-lib.sh: introduce a helper to get underlying crypt device Signed-off-by: Kairui Song Acked-by: Pingfan Liu Signed-off-by: Kairui Song --- kdump-lib.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index 92482d4..cd1e392 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -939,3 +939,20 @@ kdump_get_arch_recommend_size() echo $result return 0 } + +# Print all underlying crypt devices of a block device +# print nothing if device is not on top of a crypt device +# $1: the block device to be checked in maj:min format +get_luks_crypt_dev() +{ + [[ -b /dev/block/$1 ]] || return 1 + + local _type=$(eval "$(blkid -u filesystem,crypto -o export -- /dev/block/$1); echo \$TYPE") + [[ $_type == "crypto_LUKS" ]] && echo $1 + + for _x in /sys/dev/block/$1/slaves/*; do + [[ -f $_x/dev ]] || continue + [[ $_x/subsystem -ef /sys/class/block ]] || continue + get_luks_crypt_dev "$(< "$_x/dev")" + done +}