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

Add hacky iSCSI implementation #21

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/build-fedora.sh
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ for phase in "${PHASES[@]}"; do
INITRD="initrd_$KVER.cpio.zstd"
mkosi --cache "$MKOSI_CACHE" \
--default fedora.mkosi \
--package="NetworkManager,iscsi-initiator-utils" \
--package="iscsi-initiator-utils,systemd-networkd" \
--extra-tree=mkosi.extra-iscsi \
--image-version="$KVER" \
--environment=KERNEL_VERSION="$KVER" \
--output="$INITRD" \
Expand All @@ -312,6 +313,7 @@ for phase in "${PHASES[@]}"; do
--distribution="$ID" \
--release="$VERSION_ID" \
--format=gpt_btrfs \
--package="iscsi-initiator-utils" \
--output=rootfs.img
popd

Expand All @@ -333,7 +335,7 @@ for phase in "${PHASES[@]}"; do
dnsmasq --interface=initrd0 --bind-interfaces --dhcp-range=10.10.10.10,10.10.10.100
grep -q initrd0 /etc/qemu/bridge.conf || echo "allow initrd0" >>/etc/qemu/bridge.conf

iscsi_cmdline="ip=dhcp netroot=iscsi:10.10.10.1::::$target_name"
iscsi_cmdline="ip=dhcp netroot=iscsi:10.10.10.1::::$target_name rd.systemd.wants=systemd-networkd.service rd.systemd.wants=systemd-networkd-wait-online.service"
timeout --foreground -k 10 5m \
qemu-kvm -m 1024 -smp "$(nproc)" -nographic -nic bridge,br=initrd0 \
-initrd "$INITRD" \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- INITRD_LVM
- INITRD_LUKS
- INITRD_LUKS_LVM
#- INITRD_ISCSI # iSCSI is missing a generator
- INITRD_ISCSI
- SYSEXT
container:
image: "${{ matrix.distro.name }}:${{ matrix.distro.tag }}"
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Make the unit do nothing in the initrd.
# We can't mask the unit because iscsi.services has Requires=iscsi-shutdown.service,
# so instead we let it survive switch-root.
[Unit]
IgnoreOnIsolate=true

# This is a bug in the upstream unit file. This unit has DefaultDependencies=no,
# and Conflicts=shutdown.target, but no ordering, which only guarantees that the
# stop job will be queued.
Before=shutdown.target