blob: 4653e9f37476885c5045c1616f741dfcdc45903a [file] [log] [blame]
Matthias Andreas Benkard05e482e2026-11-04 11:05:51 +01001#!/bin/sh
2# Creates a ZFS dataset per PV. The helper pod runs with hostPID, and all
3# ZFS and filesystem operations are performed in the host's mount namespace
4# (nsenter -t 1 -m). Running zfs directly inside the helper container would
5# mount the dataset only inside the container's own mount namespace; the
6# workload would then write into the parent dataset, and the child dataset
7# would shadow that data after the next host reboot.
Matthias Andreas Benkardea839162026-11-04 20:47:43 +01008#
9# The provisioner passes the volume path as $VOL_DIR (v0.0.2x and later);
10# older versions passed it as -p.
Matthias Andreas Benkard05e482e2026-11-04 11:05:51 +010011set -eu
12
Matthias Andreas Benkardea839162026-11-04 20:47:43 +010013absolutePath=${VOL_DIR:-}
Matthias Andreas Benkard05e482e2026-11-04 11:05:51 +010014while getopts "m:s:p:" opt
15do
16 case $opt in
17 p)
18 absolutePath=$OPTARG
19 ;;
20 s)
21 sizeInBytes=$OPTARG
22 ;;
23 m)
24 volMode=$OPTARG
25 ;;
26 esac
27done
Matthias Andreas Benkardea839162026-11-04 20:47:43 +010028[ -n "$absolutePath" ] || { echo "setup: no volume path given" >&2; exit 1; }
Matthias Andreas Benkard05e482e2026-11-04 11:05:51 +010029
30host() { nsenter -t 1 -m -- "$@"; }
31
32host zfs create "rpool${absolutePath}"
33host zfs mount "rpool${absolutePath}" 2>/dev/null || :
34host findmnt -n -o SOURCE "${absolutePath}" | grep -qx "rpool${absolutePath}"
35host chmod 0777 "${absolutePath}"