dracut/0030-Add-all-btrfs-devices.patch
Harald Hoyer 0840a3b62c dracut-043-40.git20150710
- git snapshot
2015-07-10 11:31:14 +02:00

104 lines
3.7 KiB
Diff

From 1cadc26fd44a602ffbcfb59786b400990541dc86 Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Thu, 9 Jul 2015 13:18:13 +0200
Subject: [PATCH] Add all btrfs devices
We have to find them with "btrfs usage", which is cumbersome.
---
dracut-functions.sh | 13 +++++++++++++
dracut.sh | 22 ++++++++++++++++++++--
modules.d/99base/module-setup.sh | 4 +++-
3 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/dracut-functions.sh b/dracut-functions.sh
index f415f0d..639c5ae 100755
--- a/dracut-functions.sh
+++ b/dracut-functions.sh
@@ -31,6 +31,10 @@ strstr() { [[ $1 = *"$2"* ]]; }
strglobin() { [[ $1 = *$2* ]]; }
# Generic glob matching function. If glob pattern $2 matches all of $1, OK
strglob() { [[ $1 = $2 ]]; }
+# returns OK if $1 contains literal string $2 at the beginning, and isn't empty
+str_starts() { [ "${1#"$2"*}" != "$1" ]; }
+# returns OK if $1 contains literal string $2 at the end, and isn't empty
+str_ends() { [ "${1%*"$2"}" != "$1" ]; }
# helper function for check() in module-setup.sh
# to check for required installed binaries
@@ -1815,3 +1819,12 @@ lvm_internal_dev() {
[[ ${DM_LV_LAYER} ]] || [[ ! -L /dev/${DM_VG_NAME}/${DM_LV_NAME} ]]
}
+btrfs_devs() {
+ local _mp="$1"
+ btrfs device usage "$_mp" \
+ | while read _dev _rest; do
+ str_starts "$_dev" "/" || continue
+ _dev=${_dev%,}
+ printf -- "%s\n" "$_dev"
+ done
+}
diff --git a/dracut.sh b/dracut.sh
index 8394cee..bf1886f 100755
--- a/dracut.sh
+++ b/dracut.sh
@@ -1146,6 +1146,11 @@ for line in "${fstab_lines[@]}"; do
;;
esac
[ -z "$dev" ] && dwarn "Bad fstab entry $@" && continue
+ if [[ "$3" == btrfs ]]; then
+ for i in $(btrfs_devs "$2"); do
+ push_host_devs "$i"
+ done
+ fi
push_host_devs "$dev"
host_fs_types["$dev"]="$3"
done
@@ -1194,8 +1199,14 @@ if [[ $hostonly ]]; then
_bdev=$(readlink -f "/dev/block/$_dev")
[[ -b $_bdev ]] && _dev=$_bdev
push_host_devs $_dev
- [[ "$mp" == "/" ]] && root_dev="$_dev"
+ [[ "$mp" == "/" ]] && push root_devs "$_dev"
push_host_devs "$_dev"
+ if [[ $(find_mp_fstype "$mp") == btrfs ]]; then
+ for i in $(btrfs_devs "$mp"); do
+ [[ "$mp" == "/" ]] && push root_devs "$i"
+ push_host_devs "$i"
+ done
+ fi
done
if [[ -f /proc/swaps ]] && [[ -f /etc/fstab ]]; then
@@ -1240,7 +1251,14 @@ if [[ $hostonly ]]; then
[[ "$_o" != *x-initrd.mount* ]] && continue
_dev=$(expand_persistent_dev "$_d")
_dev="$(readlink -f "$_dev")"
- [[ -b $_dev ]] && push_host_devs "$_dev"
+ [[ -b $_dev ]] || continue
+
+ push_host_devs "$_dev"
+ if [[ "$_t" == btrfs ]]; then
+ for i in $(find_btrfs_devs "$_m"); do
+ push_host_devs "$i"
+ done
+ fi
done < /etc/fstab
fi
diff --git a/modules.d/99base/module-setup.sh b/modules.d/99base/module-setup.sh
index bbc68ba..3fbdc41 100755
--- a/modules.d/99base/module-setup.sh
+++ b/modules.d/99base/module-setup.sh
@@ -102,7 +102,9 @@ install() {
. "$moddir/dracut-lib.sh"
for _dev in ${host_devs[@]}; do
- [[ "$_dev" == "$root_dev" ]] && continue
+ for _dev2 in ${root_devs[@]}; do
+ [[ "$_dev" == "$_dev2" ]] && continue 2
+ done
# We only actually wait for real devs - swap is only needed
# for resume and udev rules generated when parsing resume=