Package: partman-iscsi Version: 60 Severity: wishlist Tags: patch Hi,
These 2 patches help with the iSCSI iBFT support in installer (basic support for iBFT in disk-detect posted in bug #924675). iBFT provides iSCSI configuration in the system firmware tables, often used for automatic installs, mainly in larger deployments. It can be made available to userspace with a kernel module, and used accordingly by the iscsistart tool to configure networking, iSCSI sessions, that brings up the intended target's iSCSI LUNs. The network configuration stage can actually set up any network interface, other than the installer's default/primary interface. Patch 1 addresses a couple of problems with another interface: ----- Currently, partman-iscsi/finish.d/iscsi_settings assumes that the default network interface in the installer is used by the the iSCSI devices. That is a reasonable assumption, as currently the installer only configures one, primary network interface (afaik), and thus it is used for all network traffic, iSCSI included. However, if another network interface is configured somehow (e.g., automation scripts, or iSCSI iBFT -- see bug #924675) and that non-primary/different network interface is used to provide access to iSCSI LUNs there are currently 2 problems: 1) The HWADDR field in iscsi.initramfs refers to the default network interface. 2) The /etc/network/interfaces file is changed to disable DHCP on the default network interface so not to disrupt an iSCSI connection from the initramfs. *But* if another interface is used for iSCSI, that is not protecting the right interface. *And worse* the default interface doesn't get DHCP address even if it is supposed to (ie, it effectively lost network). Patch 1 uses 'ip route' to detect which network interface is used to the iSCSI portal address, or fallback to the default interface if it can't detect it. That resolves both problems. Patch 2 adds an option to set ISCSI_AUTO=true in iscsi.initramfs ------- In an iSCSI iBFT scenario, the system is expected to boot with ISCSI_AUTO=true, but currently the installer doesn't set it up. Patch 2 adds the 'partman-iscsi/iscsi_auto' preseed option for doing that, which writes just that line into iscsi.initramfs. That way, an automated installation (where iBFT is often used) can just add that option to its preseed file/cmdline for iBFT. P.S.: I understand the timing may not be good for new features, but I would really appreciate any feedback about this patch if at all possible. Coming in shortly: test procedure. Thank you, Mauricio -- Mauricio Faria de Oliveira
From 02ada1e3b0d447de59c3673dc7962581ab07c492 Mon Sep 17 00:00:00 2001 From: Mauricio Faria de Oliveira <m...@canonical.com> Date: Thu, 7 Mar 2019 17:46:12 -0300 Subject: [PATCH 1/3] Handle non-default interface for iSCSI Signed-off-by: Mauricio Faria de Oliveira <m...@canonical.com> --- finish.d/iscsi_settings | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/finish.d/iscsi_settings b/finish.d/iscsi_settings index 9e44fdb2b5c1..110a4f2e47b1 100755 --- a/finish.d/iscsi_settings +++ b/finish.d/iscsi_settings @@ -15,6 +15,17 @@ get_default_interface () { fi } +get_address_interface () { + local address="$1" + [ -n "$address" ] || return 1 + + local dev="$(ip route get "$address" 2>/dev/null | \ + grep -w dev | tr -s ' ' | cut -d' ' -f3)" + [ -d "/sys/class/net/$dev" ] || return 1 + + address_interface="$dev" +} + have_iscsi= portal= target= @@ -64,10 +75,21 @@ if [ "$portal" ]; then ip="${portal%%:*}" port="${portal#*:}" mkdir -p /target/etc/iscsi - get_default_interface - if [ -f "/sys/class/net/$default_interface/address" ]; then + + # The network interface for iSCSI may not be the default interface. + # Try to detect it based on iSCSI portal IP address, and prefer it. + if get_address_interface "$ip"; then + iscsi_interface="$address_interface" + elif get_default_interface; then + iscsi_interface="$default_interface" + else + iscsi_interface="" + fi + + if [ -n "$iscsi_interface" ] && + [ -f "/sys/class/net/$iscsi_interface/address" ]; then cat >>/target/etc/iscsi/iscsi.initramfs <<EOF -HWADDR="$(cat "/sys/class/net/$default_interface/address")" +HWADDR="$(cat "/sys/class/net/$iscsi_interface/address")" EOF fi cat >>/target/etc/iscsi/iscsi.initramfs <<EOF @@ -93,11 +115,8 @@ EOF # This isn't ideal, but ifupdown doesn't expose any interface that # might allow the initramfs to dynamically tell it to avoid a # particular interface on this boot. - if db_get netcfg/choose_interface; then - # Work around netcfg/choose_interface not always being set: - # https://bugs.launchpad.net/ubuntu/+source/netcfg/+bug/430820 - [ "$RET" ] || RET=eth0 - sed -i "s/\(iface ${RET%%:*} inet\) dhcp/\1 manual/" \ + if [ -n "$iscsi_interface" ]; then + sed -i "s/\(iface $iscsi_interface inet\) dhcp/\1 manual/" \ /etc/network/interfaces || true fi else -- 2.17.1
From 7d3be6e3740934bc1afd7c8a3f9630cdb823c261 Mon Sep 17 00:00:00 2001 From: Mauricio Faria de Oliveira <m...@canonical.com> Date: Thu, 7 Mar 2019 17:59:50 -0300 Subject: [PATCH 2/3] Add partman-iscsi/iscsi_auto option for ISCSI_AUTO=true in initramfs Signed-off-by: Mauricio Faria de Oliveira <m...@canonical.com> --- debian/partman-iscsi.templates | 7 +++++++ finish.d/iscsi_settings | 25 +++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/debian/partman-iscsi.templates b/debian/partman-iscsi.templates index b3f4e0840095..630ca1347aad 100644 --- a/debian/partman-iscsi.templates +++ b/debian/partman-iscsi.templates @@ -92,3 +92,10 @@ _Description: iSCSI login failed Logging into the iSCSI target ${TARGET} on ${PORTAL} failed. . Check /var/log/syslog or see virtual console 4 for the details. + +Template: partman-iscsi/iscsi_auto +Type: boolean +Default: false +Description: for internal use; can be preseeded + Use ISCSI_AUTO=true instead of the ISCSI_* variables + in the /etc/iscsi/iscsi.initramfs configuration file. diff --git a/finish.d/iscsi_settings b/finish.d/iscsi_settings index 110a4f2e47b1..26f8b7d37f51 100755 --- a/finish.d/iscsi_settings +++ b/finish.d/iscsi_settings @@ -86,28 +86,37 @@ if [ "$portal" ]; then iscsi_interface="" fi - if [ -n "$iscsi_interface" ] && - [ -f "/sys/class/net/$iscsi_interface/address" ]; then + db_get partman-iscsi/iscsi_auto || RET="false" + if [ "$RET" = true ]; then cat >>/target/etc/iscsi/iscsi.initramfs <<EOF +ISCSI_AUTO=true +EOF + else + if [ -n "$iscsi_interface" ] && + [ -f "/sys/class/net/$iscsi_interface/address" ]; then + cat >>/target/etc/iscsi/iscsi.initramfs <<EOF HWADDR="$(cat "/sys/class/net/$iscsi_interface/address")" EOF - fi - cat >>/target/etc/iscsi/iscsi.initramfs <<EOF + fi + cat >>/target/etc/iscsi/iscsi.initramfs <<EOF ISCSI_TARGET_NAME="$target" ISCSI_TARGET_IP="$ip" ISCSI_TARGET_PORT="$port" ISCSI_TARGET_GROUP="$group" EOF - if [ "$username" ] && [ "$username" != "(null)" ]; then - cat >>/target/etc/iscsi/iscsi.initramfs <<EOF + if [ "$username" ] && + [ "$username" != "(null)" ]; then + cat >>/target/etc/iscsi/iscsi.initramfs <<EOF ISCSI_USERNAME="$username" ISCSI_PASSWORD="$password" EOF - if [ "$username_in" ] && [ "$username_in" != "(null)" ]; then - cat >>/target/etc/iscsi/iscsi.initramfs <<EOF + if [ "$username_in" ] && + [ "$username_in" != "(null)" ]; then + cat >>/target/etc/iscsi/iscsi.initramfs <<EOF ISCSI_IN_USERNAME="$username_in" ISCSI_IN_PASSWORD="$password_in" EOF + fi fi fi chmod 600 /target/etc/iscsi/iscsi.initramfs -- 2.17.1
From fd9a0735f82c8eda63cae1664ad706ff3aeb7f6d Mon Sep 17 00:00:00 2001 From: Mauricio Faria de Oliveira <m...@canonical.com> Date: Thu, 7 Mar 2019 18:17:44 -0300 Subject: [PATCH 3/3] Add changelog entry Signed-off-by: Mauricio Faria de Oliveira <m...@canonical.com> --- debian/changelog | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/debian/changelog b/debian/changelog index e60b32b6a561..d71e76440e11 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,13 @@ +partman-iscsi (60+ibft1) unstable; urgency=medium + + * Add support for different network interfaces and iscsi_auto for iBFT. + - debian/partman-iscsi.template: add partman-iscsi/iscsi_auto option. + - finish.d/iscsi_settings: handle non-default interface for iSCSI. + - finish.d/iscsi_settings: check option to include ISCSI_AUTO=true + instead of ISCSI_* variables in /etc/iscsi/iscsi.initramfs. + + -- Mauricio Faria de Oliveira <m...@canonical.com> Thu, 07 Mar 2019 15:53:09 -0300 + partman-iscsi (60) unstable; urgency=medium * Team upload -- 2.17.1