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

Commit

Permalink
iscsi-generator: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
keszybz committed Dec 3, 2022
1 parent 1232cc8 commit c8513aa
Show file tree
Hide file tree
Showing 2 changed files with 97 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,96 @@
#!/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
Before=initrd-root-device.target
Conflicts=shutdown.target
Before=shutdown.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: -f1)
# protocol?
port=$(echo "$spec" | cut -d: -f3)
lun=$(echo "$spec" | cut -d: -f4)
target=$(echo "$spec" | cut -d: -f5-)

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 c8513aa

Please sign in to comment.