summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2020-09-30 08:56:35 +0200
committerSimon Rettberg2020-09-30 08:56:35 +0200
commit4654b9d2053321cf369e60eba6f3e79b92292589 (patch)
treee474037327595b9bfb6dcc7c07149bab4b7f7f5b
parent[slx-dmsetup] Fix minor coding style issues, fix dd call (diff)
downloadsystemd-init-4654b9d2053321cf369e60eba6f3e79b92292589.tar.gz
systemd-init-4654b9d2053321cf369e60eba6f3e79b92292589.tar.xz
systemd-init-4654b9d2053321cf369e60eba6f3e79b92292589.zip
[slx-dmsetup] Simplifications, comments
-rwxr-xr-xmodules.d/slx-dmsetup/scripts/dmsetup-slx-device54
1 files changed, 33 insertions, 21 deletions
diff --git a/modules.d/slx-dmsetup/scripts/dmsetup-slx-device b/modules.d/slx-dmsetup/scripts/dmsetup-slx-device
index 5caeafb7..4085b1cf 100755
--- a/modules.d/slx-dmsetup/scripts/dmsetup-slx-device
+++ b/modules.d/slx-dmsetup/scripts/dmsetup-slx-device
@@ -15,6 +15,7 @@
# NOTE: Encrypting thin-snapshot will actually encrypt the
# entire pool data device used for the pool.
# TODO: Support external keys
+# TODO: Put table in file in config.tgz
type -p emergency_shell || . /lib/dracut-lib.sh
@@ -85,7 +86,13 @@ parse_config() {
crypt=0
fi
# finally save it to the global array for this type
- eval "${type}"'+=("'"${name} ${crypt} ${min} ${max}"'")'
+ case "$type" in
+ linear) linear+=("${name} ${crypt} ${min} ${max}") ;;
+ snapshot) snapshot+=("${name} ${crypt} ${min} ${max}") ;;
+ thin_snapshot) thin_snapshot+=("${name} ${crypt} ${min} ${max}") ;;
+ thin_volume) thin_volume+=("${name} ${crypt} ${min} ${max}") ;;
+ *) echo "$0: SOMETHING NOT GOOT CHECK SOURCE CODE" ;;
+ esac
done <<< "$1"
}
@@ -201,10 +208,10 @@ finish_setup() {
emergency_shell "'$2' not a valid type, 0 or 1 expected."
fi
# <size> optional?
- (
- echo "# Generated by '$0'."
+ {
+ echo "# Generated by '$0'."
echo "SLX_DNBD3_DEVICE_COW=/dev/mapper/$1"
- ) >> /etc/openslx
+ } >> /etc/openslx
save_partition_info "$1" "/" "$2" "$3"
exit 0
}
@@ -224,7 +231,7 @@ save_partition_info() {
[ -b "/dev/mapper/$1" ] || return 1
[ -n "$2" ] || return 1
[[ "$3" =~ ^[0-9]$ ]] || return 1
- local opts="type=$3"
+ local opts="type=$3"
# plain size given
[[ "$4" =~ ^[0-9]+$ ]] && opts="$opts,physical_size=$4"
# <physical_backing_dev_size>-<virtual_size>
@@ -326,12 +333,12 @@ fi
writable_device_allocated="$scratch_device_size"
# first setup linear slices of the writable device
-for i in "${!linear[@]}"; do
- [ -z "${linear[$i]}" ] && continue
- read -r name crypt min max ignore <<< "${linear[$i]}"
+for line in "${linear[@]}"; do
+ [ -z "$line" ] && continue
+ read -r name crypt min max ignore <<< "$line"
free_space="$(( writable_device_size - writable_device_allocated ))"
if [ "$min" -gt "$free_space" ]; then
- echo "$0: Not enough space left for linear devices: ${linear[$i]}"
+ echo "$0: Not enough space left for linear devices: '$line'"
break
fi
# allocate its max if it fits within the free space, otherwise use the space left.
@@ -339,7 +346,7 @@ for i in "${!linear[@]}"; do
[ "$to_allocate" -gt "$free_space" ] && to_allocate="$free_space"
if ! dmsetup_create_noudevsync "$name" "0 $to_allocate linear $writable_device $writable_device_allocated"; then
- echo "$0: Failed to create linear device: ${linear[$i]}"
+ echo "$0: Failed to create linear device: $line"
continue
fi
# TODO sane?
@@ -415,18 +422,20 @@ create_pool() {
return 0
}
-# create_volume "<name> <id> <size> <backing_dev>"
+# create_volume <name> <id> <size> [backing_dev]
create_volume() {
if [ -z "$pool_dev" ] || ! [ -b "$pool_dev" ]; then
echo "$0: Global pool device not set or present."
return 1
fi
- if [ $# -ne 1 ] || [ -z "$1" ]; then
- echo "$0: create_volume requires one non-empty argument."
+ if [ $# -lt 3 ] || [ -z "$1" ]; then
+ echo "$0: create_volume: not enough arguments."
return 1
fi
- local name id size backing_dev ignore
- read -r name id size backing_dev ignore <<< "$1"
+ local name="$1"
+ local id="$2"
+ local size="$3"
+ local backing_dev="$4" # Optional, internal if empty
if ! dmsetup message "$pool_dev" 0 "create_thin $id"; then
echo "$0: Failed to create thin volume with id '$id' in pool '$pool_dev'."
@@ -441,6 +450,9 @@ create_volume() {
fi
return 0
}
+
+# Now decide what to do for the writable layer
+
if [ -n "$thin_snapshot" ] || [ -n "$thin_volume" ]; then
if ! create_pool ; then
echo "Failed to create thin pool. Will ignore:"
@@ -453,12 +465,12 @@ if [ -n "$thin_snapshot" ] || [ -n "$thin_volume" ]; then
# the thin-snapshot with id 1 which needs to call finish_setup.
volume_id=2
# go over thin-volumes
- for i in "${!thin_volume[@]}"; do
- [ -z "${thin_volume[$i]}" ] && continue
- read -r name crypt min max ignore <<< "${thin_volume[$i]}"
- # thin-volume can be safely created with max size,
+ for line in "${thin_volume[@]}"; do
+ [ -z "$line" ] && continue
+ read -r name crypt min max ignore <<< "$line"
+ # thin-volume can be created with max size,
# since they are overprovisioned anyway.
- if ! create_volume "$name $(( volume_id++ )) $max"; then
+ if ! create_volume "$name" "$(( volume_id++ ))" "$max"; then
echo "Failed to create thin volume '$name'."
fi
save_partition_info "$name" "*" "1" "${writable_device_size}-${max}"
@@ -483,7 +495,7 @@ if [ -n "$thin_snapshot" ] || [ -n "$thin_volume" ]; then
else
thin_snapshot_size="$read_only_device_size"
fi
- if ! create_volume "$name 1 $thin_snapshot_size $read_only_device"; then
+ if ! create_volume "$name" 1 "$thin_snapshot_size" "$read_only_device"; then
echo "Failed to create external snapshot for '$read_only_device'."
ramdisk_fallback
fi