Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
iscsi-generator: add a PoC generator that brings up iscsi root device
Browse files Browse the repository at this point in the history
This is not indended as a real solution. The generator should be moved to the
open-iscsi project. It is added here to show how things should be done using a
systemd generator and an initrd unit. The generator does not handle all the
initricasies of iscsi.
  • Loading branch information
keszybz committed Dec 3, 2022
1 parent 1232cc8 commit e0bbe4c
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-fedora.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ for phase in "${PHASES[@]}"; do
mkosi --cache "$MKOSI_CACHE" \
--default fedora.mkosi \
--package="NetworkManager,iscsi-initiator-utils" \
--extra-tree=mkosi.extra-iscsi \
--image-version="$KVER" \
--environment=KERNEL_VERSION="$KVER" \
--output="$INITRD" \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash
set -e

# Format:
# root=iscsi:[<servername>]:[<protocol>]:[<port>]:[<LUN>]:<targetname>
# [root=*] netroot=iscsi:[<servername>]:[<protocol>]:[<port>]:[<LUN>]:<targetname>
#
# root= takes precedence over netroot= if root=iscsi[...]

# Example:
# netroot=iscsi:10.10.10.1::::iqn.2022-01.com.example:iscsi.initrd.test
# /dev/disk/by-path/ip-10.10.10.1:3260-iscsi-iqn.2022-01.com.example:iscsi.initrd.test-lun-1
# /dev/disk/by-path/ip-10.10.10.1:3260-iscsi-iqn.2022-01.com.example:iscsi.initrd.test-lun-1-part1
# /dev/disk/by-path/ip-<servername>:<port>-iscsi-<lun>-<targetname>-lun-<lun>

root=
specs=()

cmdline="${SYSTEMD_PROC_CMDLINE:-$(cat /proc/cmdline)}"

for arg in $cmdline; do
if [[ $arg == "root="* ]]; then
# The last root= assignment wins.
root="${arg#*=}"
elif [[ $arg == "netroot=iscsi:"* ]]; then
value="${arg#*=}"
# All netroot= invocations matter.
specs+=( "$value" )

if [ -z "$root" ]; then
root="$value"
fi
fi
done

if [[ $root == "iscsi:"* ]]; then
specs+=( "$root" )
fi

if [ ${#specs[@]} -eq 0 ]; then
# nothing for us to do
exit 0
fi

make_unit() {
# Handle the root= argument
if [[ $root == "iscsi:" ]]; then
: # TODO
fi

service="${dest_normal}/initrd-iscsi-auto.service"
this="$(realpath "$0")"
cat >"${service}" <<EOF
# generated by $this
[Unit]
Description=Poke iscsid to bring up iscsi devices
DefaultDependencies=no
Wants=iscsid.socket
Wants=iscsiuio.socket
Wants=network-online.target
Before=initrd-root-device.target
Conflicts=shutdown.target
Before=shutdown.target
After=network-online.target
[Service]
Type=oneshot
ExecStart=$this --go
EOF

mkdir -p "${dest_normal}/initrd-root-device.target.requires"
ln -s "../initrd-iscsi-auto.service" "${dest_normal}/initrd-root-device.target.requires/"
}

do_things() {
for spec in "${specs[@]}"; do
server=$(echo "$spec" | cut -d: -f2)
# protocol?
port=$(echo "$spec" | cut -d: -f4)
lun=$(echo "$spec" | cut -d: -f5)
target=$(echo "$spec" | cut -d: -f6-)

echo "$spec: will start server=$server port=$port lun=$lun target=$target"

iscsiadm -m discovery -t st -p "${server}${port:+:$port}"
iscsiadm -m node -T "$target" -l
done
}

if [ "${1:?}" == '--go' ]; then
do_things
else
# invoked as generator
dest_normal=${1:?}

make_unit
fi

0 comments on commit e0bbe4c

Please sign in to comment.