summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2022-08-10 14:11:18 +0200
committerSimon Rettberg2022-08-10 14:11:18 +0200
commitfdb9970c340e04d5495651d6f19e6e61dcb14f67 (patch)
tree46cd1db4d2acac56c1d8513691c8208841efa6ef
parent[slx-dmsetup] Add linear swap space if slx.swap is in command line (diff)
downloadsystemd-init-fdb9970c340e04d5495651d6f19e6e61dcb14f67.tar.gz
systemd-init-fdb9970c340e04d5495651d6f19e6e61dcb14f67.tar.xz
systemd-init-fdb9970c340e04d5495651d6f19e6e61dcb14f67.zip
[slx-dmsetup] Handle absolute slice sizes first and remember used space
-rwxr-xr-xmodules.d/slx-dmsetup/scripts/dmsetup-slx-device21
1 files changed, 19 insertions, 2 deletions
diff --git a/modules.d/slx-dmsetup/scripts/dmsetup-slx-device b/modules.d/slx-dmsetup/scripts/dmsetup-slx-device
index 2dcd7eb3..3551a6eb 100755
--- a/modules.d/slx-dmsetup/scripts/dmsetup-slx-device
+++ b/modules.d/slx-dmsetup/scripts/dmsetup-slx-device
@@ -57,10 +57,17 @@ handle_unit() {
echo "$val"
}
+parse_config() {
+ local writable_device_sz="$writable_device_sz"
+ parse_config_int "$1" 0
+ parse_config_int "$1" 1
+}
+
# global array variables storing the configuration of the partitions
declare -ag linear snapshot thin_snapshot thin_volume
-parse_config() {
+parse_config_int() {
[ -z "$1" ] && return 1
+ local -i rel_only="$2"
while IFS= read -r line || [ -n "$line" ]; do
[ -z "$line" ] && continue
read -r type name range crypt ignore <<< "$line"
@@ -84,6 +91,12 @@ parse_config() {
local max="${BASH_REMATCH[4]:-${BASH_REMATCH[1]}}"
local min_unit="${BASH_REMATCH[2]:-${BASH_REMATCH[5]}}"
local max_unit="${BASH_REMATCH[5]:-${BASH_REMATCH[2]}}"
+ # first pass we handle absolute values unly, second pass relative ones
+ if [[ "$min_unit" = "%" || "$max_unit" = "%" ]]; then
+ [ "$rel_only" != 1 ] && continue
+ else
+ [ "$rel_only" = 1 ] && continue
+ fi
if [ -z "$min_unit" ]; then
echo "$0: WARNING: No unit given in range, assuming BYTES: $line"
fi
@@ -116,6 +129,10 @@ parse_config() {
thin_volume) thin_volume+=("${name} ${crypt} ${min} ${max}") ;;
*) echo "$0: SOMETHING NOT GOOT CHECK SOURCE CODE" ;;
esac
+ # Decrease for upcoming calculations if we used fixed values here
+ if [ "$rel_only" != 1 ]; then
+ (( writable_device_sz -= ( min + max ) / 2 ))
+ fi
done <<< "$1"
}
@@ -638,7 +655,7 @@ fi
writable_device_used_sz="$scratch_device_sz"
-# first setup linear slices of the writable device
+# setup linear slices of the writable device
for line in "${linear[@]}"; do
[ -z "$line" ] && continue
read -r name crypt min max ignore <<< "$line"