| #!/bin/sh |
| # Creates a ZFS dataset per PV. The helper pod runs with hostPID, and all |
| # ZFS and filesystem operations are performed in the host's mount namespace |
| # (nsenter -t 1 -m). Running zfs directly inside the helper container would |
| # mount the dataset only inside the container's own mount namespace; the |
| # workload would then write into the parent dataset, and the child dataset |
| # would shadow that data after the next host reboot. |
| # |
| # The provisioner passes the volume path as $VOL_DIR (v0.0.2x and later); |
| # older versions passed it as -p. |
| set -eu |
| |
| absolutePath=${VOL_DIR:-} |
| while getopts "m:s:p:" opt |
| do |
| case $opt in |
| p) |
| absolutePath=$OPTARG |
| ;; |
| s) |
| sizeInBytes=$OPTARG |
| ;; |
| m) |
| volMode=$OPTARG |
| ;; |
| esac |
| done |
| [ -n "$absolutePath" ] || { echo "setup: no volume path given" >&2; exit 1; } |
| |
| host() { nsenter -t 1 -m -- "$@"; } |
| |
| host zfs create "rpool${absolutePath}" |
| host zfs mount "rpool${absolutePath}" 2>/dev/null || : |
| host findmnt -n -o SOURCE "${absolutePath}" | grep -qx "rpool${absolutePath}" |
| host chmod 0777 "${absolutePath}" |