iscsi initiator utilities Signed-off-by: Lucian Cristian <lucian.cristian@gmail.com>lilik-openwrt-22.03
@ -0,0 +1,96 @@ | |||
# This is free software, licensed under the GNU General Public License v2. | |||
# See /LICENSE for more information. | |||
include $(TOPDIR)/rules.mk | |||
PKG_NAME:=open-iscsi | |||
PKG_VERSION:=2.1.1 | |||
PKG_RELEASE:=1 | |||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz | |||
PKG_SOURCE_URL:=https://codeload.github.com/open-iscsi/open-iscsi/tar.gz/$(PKG_VERSION)? | |||
PKG_HASH:=dfc1ea37f230f9d116f5b39c795b35be43002d65c81330ccd3878786532b811b | |||
PKG_MAINTAINER:=Lucian CRISTIAN <lucian.cristian@gmail.com> | |||
PKG_LICENSE:=GPL-2.0-or-later | |||
PKG_LICENSE_FILES:=COPYING | |||
PKG_FIXUP:=autoreconf | |||
PKG_INSTALL:=1 | |||
include $(INCLUDE_DIR)/package.mk | |||
define Package/open-iscsi | |||
SECTION:=net | |||
CATEGORY:=Network | |||
URL:=http://www.open-iscsi.com/ | |||
TITLE:=iSCSI userland tools | |||
DEPENDS:=+libopenssl +open-isns +libmount +libkmod +kmod-iscsi-initiator | |||
endef | |||
define Package/open-iscsi/description | |||
The Open-iSCSI project provides a high-performance, transport independent, | |||
implementation of RFC 3720 iSCSI for Linux. | |||
User space contains the entire control plane: configuration manager, | |||
iSCSI Discovery, Login and Logout processing, connection-level error processing, | |||
Nop-In and Nop-Out handling, etc. | |||
endef | |||
define Build/Prepare | |||
$(call Build/Prepare/Default) | |||
$(SED)'s,/run,/var/run,g' $(PKG_BUILD_DIR)/libopeniscsiusr/idbm.c | |||
$(SED)'s,/run,/var/run,g' $(PKG_BUILD_DIR)/usr/initiator.h | |||
endef | |||
define Build/Configure | |||
$(call Build/Configure/Default) | |||
(cd $(PKG_BUILD_DIR)/iscsiuio/; \ | |||
autoreconf --install; \ | |||
./configure \ | |||
--target=$(GNU_TARGET_NAME) \ | |||
--host=$(GNU_TARGET_NAME) \ | |||
--build=$(GNU_HOST_NAME) \ | |||
--prefix=/usr \ | |||
LIB_DIR=/usr/lib \ | |||
CFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS)" \ | |||
) | |||
endef | |||
TARGET_CFLAGS += \ | |||
$(FPIC) -flto \ | |||
-D_GNU_SOURCE -DNO_SYSTEMD | |||
TARGET_LDFLAGS += -lkmod | |||
MAKE_FLAGS += \ | |||
CC="$(TARGET_CC)" \ | |||
CFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS) \ | |||
-I$(PKG_BUILD_DIR)/include \ | |||
-I$(PKG_BUILD_DIR)/usr \ | |||
-I$(PKG_BUILD_DIR)/libopeniscsiusr" \ | |||
LDFLAGS="$(TARGET_LDFLAGS) $(EXTRA_LDFLAGS) \ | |||
-L$(PKG_BUILD_DIR)/libopeniscsiusr" \ | |||
PREFIX=/usr \ | |||
LIB_DIR=/usr/lib | |||
define Package/open-iscsi/conffiles | |||
/etc/iscsi/ | |||
endef | |||
define Package/open-iscsi/postinst | |||
#!/bin/sh | |||
[ -x /usr/sbin/iscsi-gen-initiatorname ] && /usr/sbin/iscsi-gen-initiatorname || exit 0 | |||
endef | |||
define Package/open-iscsi/install | |||
$(INSTALL_DIR) \ | |||
$(1)/etc/init.d $(1)/etc/iscsi \ | |||
$(1)/usr/lib $(1)/sbin $(1)/usr/sbin | |||
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/etc/iscsi/iscsid.conf $(1)/etc/iscsi/ | |||
$(INSTALL_BIN) ./files/iscsi* $(1)/usr/sbin/ | |||
$(INSTALL_BIN) ./files/open-iscsi $(1)/etc/init.d/ | |||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/sbin/iscsi{adm,d,-iname,uio} $(1)/sbin/ | |||
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libopeniscsiusr.so* $(1)/usr/lib/ | |||
endef | |||
$(eval $(call BuildPackage,open-iscsi)) |
@ -0,0 +1,75 @@ | |||
#!/bin/sh | |||
# | |||
# /sbin/iscsi-gen-initiatorname | |||
# | |||
# Generate a default iSCSI Initiatorname for SUSE installations. | |||
# | |||
# Copyright (c) 2011 Hannes Reinecke, SUSE Labs | |||
# This script is licensed under the GPL. | |||
# | |||
if [ "$1" ] ; then | |||
if [ "$1" = "-f" ] ; then | |||
FORCE=1 | |||
else | |||
echo "Invalid option $1" | |||
echo "Usage: $0 [-f]" | |||
exit 1 | |||
fi | |||
fi | |||
if [ -d /sys/firmware/ibft/initiator ] ; then | |||
read iSCSI_INITIATOR_NAME < /sys/firmware/ibft/initiator/initiator-name | |||
fi | |||
if [ -f /etc/iscsi/initiatorname.iscsi -a -z "$FORCE" ] ; then | |||
if [ "$iSCSI_INITIATOR_NAME" ] ; then | |||
eval $(cat /etc/iscsi/initiatorname.iscsi | sed -e '/^#/d') | |||
if [ "$iSCSI_INITIATOR_NAME" != "$InitiatorName" ] ; then | |||
echo "iSCSI Initiatorname from iBFT is different from the current setting." | |||
echo "Please call '/sbin/iscsi-gen-initiatorname -f' to update the iSCSI Initiatorname." | |||
exit 1 | |||
fi | |||
fi | |||
fi | |||
if [ "$iSCSI_INITIATOR_NAME" ] ; then | |||
cat << EOF >> /etc/iscsi/initiatorname.iscsi | |||
## | |||
## /etc/iscsi/iscsi.initiatorname | |||
## | |||
## iSCSI Initiatorname taken from iBFT BIOS tables. | |||
## | |||
## DO NOT EDIT OR REMOVE THIS FILE! | |||
## If you remove this file, the iSCSI daemon will not start. | |||
## Any change here will not be reflected to the iBFT BIOS tables. | |||
## If a different initiatorname is required please change the | |||
## initiatorname in the BIOS setup and call | |||
## /sbin/iscsi-gen-initiatorname -f | |||
## to recreate an updated version of this file. | |||
## | |||
InitiatorName=$iSCSI_INITIATOR_NAME | |||
EOF | |||
fi | |||
if [ ! -f /etc/iscsi/initiatorname.iscsi ] ; then | |||
cat << EOF >> /etc/iscsi/initiatorname.iscsi | |||
## | |||
## /etc/iscsi/iscsi.initiatorname | |||
## | |||
## Default iSCSI Initiatorname. | |||
## | |||
## DO NOT EDIT OR REMOVE THIS FILE! | |||
## If you remove this file, the iSCSI daemon will not start. | |||
## If you change the InitiatorName, existing access control lists | |||
## may reject this initiator. The InitiatorName must be unique | |||
## for each iSCSI initiator. Do NOT duplicate iSCSI InitiatorNames. | |||
EOF | |||
YEAR=$(date +"%Y") | |||
MONTH=$(date +"%m") | |||
ISSUEDATE="$YEAR$MONTH" | |||
INAME=$(iscsi-iname -p iqn.$ISSUEDATE.local.openwrt:01) | |||
printf "InitiatorName=$INAME\n" >>/etc/iscsi/initiatorname.iscsi | |||
chmod 0600 /etc/iscsi/initiatorname.iscsi | |||
fi | |||
@ -0,0 +1,195 @@ | |||
#!/bin/sh | |||
# | |||
# Copyright (C) Voltaire Ltd. 2006. ALL RIGHTS RESERVED. | |||
# | |||
# This program is free software; you can redistribute it and/or | |||
# modify it under the terms of the GNU General Public License | |||
# as published by the Free Software Foundation; either version 2 | |||
# of the License, or (at your option) any later version. | |||
# | |||
# This program is distributed in the hope that it will be useful, | |||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
# GNU General Public License for more details. | |||
# | |||
# You should have received a copy of the GNU General Public License | |||
# along with this program; if not, write to the Free Software | |||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
# | |||
# Author: Dan Bar Dov <danb@voltaire.com> | |||
# iscsi_discovery: | |||
# * does a send-targets discovery to the given IP | |||
# * set the transport type to the preferred transport (or tcp is -t flag is not used) | |||
# * tries to login | |||
# * if succeeds, | |||
# o logout, | |||
# o mark record autmatic (unless -m flag is used) | |||
# * else | |||
# o reset transport type to TCP | |||
# o try to login | |||
# o if succeeded | |||
# + logout | |||
# + mark record automatic (unless -m flag is used) | |||
# | |||
usage() | |||
{ | |||
echo "Usage: $0 <IP> [-p <port>] [-d] [-t <tcp|iser> [-f]] [-m] [-l]" | |||
echo "Options:" | |||
echo "-p set the port number (default is 3260)." | |||
echo "-d print debugging information" | |||
echo "-t set transport (default is tcp)." | |||
echo "-f force specific transport -disable the fallback to tcp (default is fallback enabled)." | |||
echo " force the transport specified by the argument of the -t flag." | |||
echo "-m manual startup - will set manual startup (default is automatic startup)." | |||
echo "-l login to the new discovered nodes (default is false)." | |||
} | |||
dbg() | |||
{ | |||
$debug && echo $@ | |||
} | |||
initialize() | |||
{ | |||
trap "exit" 2 | |||
debug=false | |||
force="0" | |||
log_out="1" | |||
startup_manual="0" | |||
#set default transport to tcp | |||
transport=tcp | |||
#set default port to 3260 | |||
port=3260; | |||
} | |||
parse_cmdline() | |||
{ | |||
if [ $# -lt 1 ]; then | |||
usage | |||
exit 1 | |||
fi | |||
# check if the IP address is valid | |||
ip=`echo $1 | awk -F'.' '$1 != "" && $1 <=255 && $2 != "" && $2 <= 255 && $3 != "" && $3 <= 255 && $4 != "" && $4 <= 255 {print $0}'` | |||
if [ -z "$ip" ]; then | |||
echo "$1 is not a vaild IP address!" | |||
exit 1 | |||
fi | |||
shift | |||
while getopts "dfmlt:p:" options; do | |||
case $options in | |||
d ) debug=true;; | |||
f ) force="1";; | |||
t ) transport=$OPTARG;; | |||
p ) port=$OPTARG;; | |||
m ) startup_manual="1";; | |||
l ) log_out=0;; | |||
\? ) usage | |||
exit 1;; | |||
* ) usage | |||
exit 1;; | |||
esac | |||
done | |||
} | |||
discover() | |||
{ | |||
# If open-iscsi is already logged in to the portal, exit | |||
if [ $(iscsiadm -m session | grep -c ${ip}:${port}) -ne 0 ]; then | |||
echo "Please logout from all targets on ${ip}:${port} before trying to run discovery on that portal" | |||
exit 2 | |||
fi | |||
connected=0 | |||
discovered=0 | |||
dbg "starting discovery to $ip" | |||
disc="$(iscsiadm -m discovery --type sendtargets --portal ${ip}:${port})" | |||
echo "${disc}" | while read portal target | |||
do | |||
portal=${portal%,*} | |||
select_transport | |||
done | |||
discovered=$(echo "${disc}" | wc -l) | |||
if [ ${discovered} = 0 ]; then | |||
echo "failed to discover targets at ${ip}" | |||
exit 2 | |||
else | |||
echo "discovered ${discovered} targets at ${ip}" | |||
fi | |||
} | |||
try_login() | |||
{ | |||
if [ "$startup_manual" != "1" ]; then | |||
iscsiadm -m node --targetname ${target} --portal ${portal} --op update -n node.conn[0].startup -v automatic | |||
fi | |||
iscsiadm -m node --targetname ${target} --portal ${portal} --login >/dev/null 2>&1 | |||
ret=$? | |||
if [ ${ret} = 0 ]; then | |||
echo "Set target ${target} to automatic login over ${transport} to portal ${portal}" | |||
((connected++)) | |||
if [ "$log_out" = "1" ]; then | |||
iscsiadm -m node --targetname ${target} --portal ${portal} --logout | |||
fi | |||
else | |||
echo "Cannot login over ${transport} to portal ${portal}" | |||
iscsiadm -m node --targetname ${target} --portal ${portal} --op update -n node.conn[0].startup -v manual | |||
fi | |||
return ${ret} | |||
} | |||
set_transport() | |||
{ | |||
transport=$1 | |||
case "$transport" in | |||
iser) | |||
# iSER does not use digest | |||
iscsiadm -m node --targetname ${target} --portal ${portal} \ | |||
--op update -n node.conn[0].iscsi.HeaderDigest -v None | |||
iscsiadm -m node --targetname ${target} --portal ${portal} \ | |||
--op update -n node.conn[0].iscsi.DataDigest -v None | |||
;; | |||
cxgb3i) | |||
# cxgb3i supports <= 16K packet (BHS + AHS + pdu payload + digests) | |||
iscsiadm -m node --targetname ${target} --portal ${portal} \ | |||
--op update -n node.conn[0].iscsi.MaxRecvDataSegmentLength \ | |||
-v 8192 | |||
;; | |||
esac | |||
transport_name=`iscsiadm -m node -p ${portal} -T ${target} |awk '/transport_name/ {print $1}'` | |||
iscsiadm -m node --targetname ${target} --portal ${portal} \ | |||
--op update -n ${transport_name} -v ${transport} | |||
} | |||
select_transport() | |||
{ | |||
set_transport $transport | |||
dbg "Testing $transport-login to target ${target} portal ${portal}" | |||
try_login; | |||
if [ $? != 0 -a "$force" = "0" ]; then | |||
set_transport tcp | |||
dbg "starting to test tcp-login to target ${target} portal ${portal}" | |||
try_login; | |||
fi | |||
} | |||
check_iscsid() | |||
{ | |||
#check if iscsid is running | |||
pidof iscsid &>/dev/null | |||
ret=$? | |||
if [ $ret -ne 0 ]; then | |||
echo "iscsid is not running" | |||
echo "Exiting..." | |||
exit 1 | |||
fi | |||
} | |||
check_iscsid | |||
initialize | |||
parse_cmdline "$@" | |||
discover |
@ -0,0 +1,12 @@ | |||
#!/bin/sh | |||
# | |||
# iscsi_fw_login -- login to iscsi firmware targets, if any | |||
# | |||
# This script is called when udev discovers a new iscsi | |||
# firmware target | |||
# | |||
ARGS="-m fw -l" | |||
ISCSIADM="iscsiadm" | |||
$ISCSIADM $ARGS |
@ -0,0 +1,378 @@ | |||
#!/bin/sh | |||
# | |||
# iscsi_offload | |||
# | |||
# Configure iSCSI offload engines for use with open-iscsi | |||
# Usage: | |||
# iscsi_offload [-d | -f | -i <ipaddr> | -t ] <nic> | |||
# | |||
# Copyright (c) 2011 Hannes Reinecke, SUSE Labs | |||
# This script is licensed under the GPL. | |||
# | |||
# The script creates an open-iscsi interface definition | |||
# in the style <nic>-<module>, where <nic> matches the | |||
# network interface passed on the commandline. | |||
# If '-t' (test mode) is passed as an option, the script | |||
# will not create nor modify any setting but just print | |||
# the currently active ones. | |||
# | |||
# Currently the script works with Broadcom (bnx2i) and | |||
# Chelsio T3 (cxgbi) iSCSI offload engines. | |||
# Should work with Chelsio T4, but has not been tested. | |||
# ServerEngines (be2iscsi) and QLogic (qla4xxx) can only | |||
# be configured via BIOS, open-iscsi support is still in | |||
# development. | |||
# | |||
# | |||
# Return codes: | |||
# 0: Success | |||
# 1: Invalid command line parameter | |||
# 2: iSCSI offloading not supported | |||
# 3: Error during module loading | |||
# 4: Cannot configure interface via iscsiadm, use BIOS setup | |||
# 5: internal error running iscsiadm | |||
# | |||
# Output: | |||
# <mac> [none|dhcp|ip <ipaddr>|ibft] | |||
# where | |||
# <mac>: MAC Address of the iSCSI offload engine | |||
# none: No IP configuration set for the iSCSI offload engine | |||
# dhcp: iSCSI offload engine configured for DHCP | |||
# ip: iSCSI offload engine configured with static IP address <ipaddr> | |||
# ibft: iSCSI offload engine configured from iBFT values | |||
# | |||
# | |||
# Figure out the MAC address of the iSCSI offload engine | |||
# corresponding to a NIC from a given PCI device. | |||
# bnx2 is using one PCI device per port for both network and iSCSI offloading | |||
# cxgb3 is using one PCI device for everything. | |||
# | |||
iscsi_macaddress_from_pcidevice() | |||
{ | |||
local path=$1 | |||
local if=$2 | |||
local h | |||
local host | |||
for h in $path/host* ; do | |||
if [ -d "$h" ] ; then | |||
host=${h##*/} | |||
read netdev < /sys/class/iscsi_host/$host/netdev | |||
if [ "$netdev" = "$IFNAME" ] ; then | |||
read mac < /sys/class/iscsi_host/$host/hwaddress | |||
if [ "$mac" != "00:00:00:00:00:00" ] ; then | |||
echo "$mac" | |||
fi | |||
break; | |||
fi | |||
fi | |||
done | |||
} | |||
# | |||
# Figure out the MAC address of the iSCSI offload engine | |||
# corresponding to a NIC from a given PCI function. | |||
# It is assumed that the MAC address of the iSCSI offload | |||
# engine is equal of the MAC address of the NIC plus one. | |||
# Suitable for be2iscsi and qla4xxx | |||
# | |||
iscsi_macaddress_from_pcifn() | |||
{ | |||
local path=$1 | |||
local if=$2 | |||
local h | |||
local host | |||
local ifmac | |||
ifmac=$(ip addr show dev $if | sed -n 's/ *link\/ether \(.*\) brd.*/\1/p') | |||
m5=$(( 0x${ifmac##*:} )) | |||
m5=$(( $m5 + 1 )) | |||
ifmac=$(printf "%s:%02x" ${ifmac%:*} $m5) | |||
for host in /sys/class/iscsi_host/host* ; do | |||
if [ -L "$host" ] ; then | |||
read mac < $host/hwaddress | |||
if [ "$mac" = "$ifmac" ] ; then | |||
echo "$mac" | |||
break; | |||
fi | |||
fi | |||
done | |||
} | |||
update_iface_setting() { | |||
local iface="$1" | |||
local name="$2" | |||
local value="$3" | |||
iface_value=$(iscsiadm -m iface -I $iface | sed -n "s/$name = \(.*\)/\1/p") | |||
if [ "$iface_value" = "<empty>" ] ; then | |||
iface_value= | |||
fi | |||
if [ "$iface_value" != "$value" ] ; then | |||
if ! iscsiadm -m iface -I $iface -o update -n "$name" -v "$value" ; then | |||
return 1 | |||
fi | |||
fi | |||
return 0 | |||
} | |||
while getopts di:t options ; do | |||
case $options in | |||
d ) mode=dhcp;; | |||
i ) mode=static | |||
optaddr=$OPTARG | |||
;; | |||
f ) mode=firmware;; | |||
t ) dry_run=1;; | |||
?) printf "Usage: %s [-d|-t|-i ipaddr|-f] ifname\n" $0 | |||
exit 1;; | |||
esac | |||
done | |||
shift $(($OPTIND - 1)) | |||
IFNAME=$1 | |||
ibft_mode="none" | |||
if [ -z "$IFNAME" ] ; then | |||
echo "No interface specified" | |||
exit 1 | |||
fi | |||
if [ "$dry_run" ] ; then | |||
if [ "$mode" = "dhcp" ] ; then | |||
echo "'-t' specified, ignoring '-d'" | |||
mode= | |||
elif [ "$mode" = "static" ] ; then | |||
echo "'-t' specified, ignoring '-s'" | |||
mode= | |||
fi | |||
fi | |||
if [ ! -L /sys/class/net/$IFNAME ] ; then | |||
echo "Interface $IFNAME not found" | |||
exit 1 | |||
fi | |||
if [ "$optaddr" ] && ! ip route get $optaddr ; then | |||
echo "Invalid IP address $optaddr" | |||
exit 1 | |||
fi | |||
if [ "$dry_run" ] ; then | |||
mode= | |||
fi | |||
ifpath=$(cd -P /sys/class/net/$IFNAME; echo $PWD) | |||
pcipath=$(cd -P $ifpath/device; echo $PWD) | |||
if [ -d $pcipath ] ; then | |||
drvlink=$(readlink $pcipath/driver) | |||
driver=${drvlink##*/} | |||
fi | |||
if [ -z "$driver" ] ; then | |||
echo "No driver found for interface $IFNAME" | |||
exit 1 | |||
fi | |||
case "$driver" in | |||
bnx2*) | |||
mod=bnx2i | |||
;; | |||
cxgb*) | |||
mod=cxgb3i | |||
;; | |||
be2*) | |||
mod=be2iscsi | |||
;; | |||
qla*) | |||
mod=qla4xxx | |||
;; | |||
esac | |||
if [ -z "$mod" ] ; then | |||
echo "iSCSI offloading not supported on interface $IFNAME" | |||
exit 2 | |||
fi | |||
# Check if the required modules are already loaded | |||
loaded=$(sed -n "/^$mod/p" /proc/modules) | |||
if [ -z "$loaded" ] ; then | |||
modprobe $mod | |||
fi | |||
loaded=$(sed -n "/^$mod/p" /proc/modules) | |||
if [ -z "$loaded" ] ; then | |||
echo "Loading of $mod.ko failed, please check dmesg" | |||
exit 3 | |||
fi | |||
# Get the correct MAC address for the various devices | |||
if [ "$mod" = "bnx2i" ] ; then | |||
mac=$(iscsi_macaddress_from_pcidevice $pcipath $IFNAME) | |||
elif [ "$mod" = "cxgb3i" ] ; then | |||
mac=$(iscsi_macaddress_from_pcidevice $pcipath $IFNAME) | |||
elif [ "$mod" = "be2iscsi" ] ; then | |||
mac=$(iscsi_macaddress_from_pcifn $pcipath $IFNAME) | |||
elif [ "$mod" = "qla4xxx" ] ; then | |||
mac=$(iscsi_macaddress_from_pcifn $pcipath $IFNAME) | |||
fi | |||
if [ -z "$mac" ] ; then | |||
echo "iSCSI offloading not supported on interface $IFNAME" | |||
exit 2 | |||
fi | |||
gen_iface="$mod.$mac" | |||
ioe_iface="${IFNAME}-${mod}" | |||
# Get existing settings | |||
if iscsiadm -m iface -I $ioe_iface > /dev/null 2>&1 ; then | |||
ioe_mac=$(iscsiadm -m iface -I $ioe_iface 2> /dev/null| sed -n "s/iface\.hwaddress = \(.*\)/\1/p") | |||
ioe_mod=$(iscsiadm -m iface -I $ioe_iface 2> /dev/null| sed -n "s/iface\.transport_name = \(.*\)/\1/p") | |||
ipaddr=$(iscsiadm -m iface -I $ioe_iface 2> /dev/null| sed -n "s/iface\.ipaddress = \(.*\)/\1/p") | |||
if [ "$ipaddr" == "<empty>" ] ; then | |||
ipaddr= | |||
fi | |||
elif [ "$mod" = "be2iscsi" ] ; then | |||
ioe_mac=$mac | |||
ioe_mod=$mod | |||
else | |||
# Create new interface | |||
iscsiadm -m iface -I $ioe_iface --op=new 2> /dev/null | |||
ioe_mac= | |||
ioe_mod= | |||
ipaddr= | |||
fi | |||
if [ -z "$dry_run" ] ; then | |||
if [ "$ioe_mac" != "$mac" ] ; then | |||
if [ -n "$ioe_mac" ] ; then | |||
echo "Warning: Updating MAC address on iface $ioe_iface" | |||
fi | |||
update_iface_setting $ioe_iface iface.hwaddress "$mac" | |||
fi | |||
if [ "$ioe_mod" != "$mod" ] ; then | |||
if [ -n "$ioe_mod" ] ; then | |||
echo "Warning: Update transport on iface $ioe_iface" | |||
fi | |||
update_iface_setting $ioe_iface iface.transport_name "$mod" | |||
fi | |||
elif [ -z "$ipaddr" ] ; then | |||
ipaddr=$(iscsiadm -m iface -I $gen_iface 2> /dev/null| sed -n "s/iface\.ipaddress = \(.*\)/\1/p") | |||
if [ "$ipaddr" = "<empty>" ] ; then | |||
ipaddr= | |||
fi | |||
elif [ "$ioe_mod" != "$mod" ] ; then | |||
echo "Warning: Transport mismatch on iface $ioe_iface: $ioe_mod should be $mod" | |||
fi | |||
# Check iBFT setting | |||
for d in /sys/firmware/* ; do | |||
[ -d $d ] || continue | |||
[ -d $d/ethernet0 ] || continue | |||
iboot_dir=$d | |||
done | |||
if [ -n "$iboot_dir" ] && [ -d "$iboot_dir" ] ; then | |||
for if in ${iboot_dir}/ethernet* ; do | |||
read ibft_mac < $if/mac | |||
[ "$ibft_mac" = "$mac" ] || continue | |||
ibft_origin=0 | |||
[ -f ${if}/origin ] && read ibft_origin < $if/origin | |||
if [ "$ibft_origin" -eq 1 ] ; then | |||
ibft_mode="static" | |||
elif [ "$ibft_origin" -eq 3 ] ; then | |||
ibft_mode="dhcp" | |||
fi | |||
[ -f $if/dhcp ] && read ibft_dhcp < $if/dhcp | |||
if [ -n "$ibft_dhcp" -a "$ibft_mode" != "dhcp" ] ; then | |||
ibft_mode=dhcp | |||
fi | |||
if [ "$ibft_mode" = "dhcp" ] ; then | |||
ibft_ipaddr="0.0.0.0" | |||
ibft_gateway= | |||
ibft_mask= | |||
break | |||
fi | |||
[ -f $if/ip-addr ] && read ibft_ipaddr < $if/ip-addr | |||
[ -f $if/gateway ] && read ibft_gateway < $if/gateway | |||
[ -f $if/subnet-mask ] && read ibft_mask < $if/subnet-mask | |||
break | |||
done | |||
fi | |||
if [ -z "$optaddr" ] && [ "$ibft_ipaddr" ] ; then | |||
optaddr=$ibft_ipaddr | |||
fi | |||
# Check if the interface needs to be configured | |||
if [ -z "$mode" ] ; then | |||
if [ "$ibft_mode" != "none" ] ; then | |||
echo "$mac ibft" | |||
mode="ibft" | |||
elif [ -z "$ipaddr" ] ; then | |||
echo "$mac none" | |||
mode="none" | |||
elif [ "$ipaddr" = "0.0.0.0" ] ; then | |||
echo "$mac dhcp" | |||
ipaddr= | |||
mode="dhcp" | |||
else | |||
echo "$mac ip $ipaddr" | |||
mode="static" | |||
fi | |||
[ "$dry_run" ] && exit 0 | |||
elif [ "$mode" = "dhcp" ] ; then | |||
if [ "$ipaddr" = "0.0.0.0" ] ; then | |||
echo "$mac dhcp" | |||
exit 0 | |||
fi | |||
optaddr="0.0.0.0" | |||
elif [ "$mode" = "static" ] && [ "$ipaddr" = "$optaddr" ] ; then | |||
echo "$mac ip $ipaddr" | |||
exit 0 | |||
fi | |||
if [ "$mod" = "be2iscsi" ] ; then | |||
exit 4 | |||
fi | |||
if ! update_iface_setting $ioe_iface iface.ipaddress "$optaddr" ; then | |||
echo "Failed to set IP address: $?" | |||
exit 1 | |||
fi | |||
if ! update_iface_setting $gen_iface iface.ipaddress "$optaddr" ; then | |||
echo "Failed to set IP address for generic interface: $?" | |||
exit 1 | |||
fi | |||
if ! update_iface_setting $ioe_iface iface.gateway "$ibft_gateway" ; then | |||
echo "Failed to set gateway address: $?" | |||
exit 1 | |||
fi | |||
if ! update_iface_setting $gen_iface iface.gateway "$ibft_gateway" ; then | |||
echo "Failed to set gateway address for generic interface: $?" | |||
exit 1 | |||
fi | |||
if ! update_iface_setting $ioe_iface iface.subnet_mask "$ibft_mask" ; then | |||
echo "Failed to set subnet mask: $?" | |||
exit 1 | |||
fi | |||
if ! update_iface_setting $gen_iface iface.subnet_mask "$ibft_mask" ; then | |||
echo "Failed to set subnet mask for generic interface: $?" | |||
exit 1 | |||
fi | |||
if [ "$mod" = "qla4xxx" ] ; then | |||
iscsiadm -m iface -H $mac -o applyall | |||
fi | |||
ip link set dev $IFNAME up | |||
exit 0 | |||
@ -0,0 +1,93 @@ | |||
#!/bin/sh /etc/rc.common | |||
START=50 | |||
STOP=50 | |||
#USE_PROCD=1 | |||
DAEMON=/sbin/iscsid | |||
ADM=/sbin/iscsiadm | |||
PIDFILE=/var/run/iscsid.pid | |||
log() | |||
{ | |||
logger -t iscsid -s -p daemon.info "$@" | |||
} | |||
#start_service() { | |||
# procd_open_instance | |||
# procd_set_param command $DAEMON -f -d 8 -p $PIDFILE | |||
# procd_set_param respawn | |||
# procd_close_instance | |||
#} | |||
prepare() { | |||
[ ! -f /etc/iscsi/initiatorname.iscsi ] && logger "Generate initator name ..." \ | |||
&& /usr/sbin/iscsi-gen-initiatorname | |||
mkdir -p /var/run/lock/iscsi | |||
} | |||
unmount() { | |||
TARGETS="$(iscsiadm -m session -P 3 | grep disk | awk '{print $4}')" | |||
for VAL in $TARGETS; do | |||
MOUNTED="$(mount | grep $VAL | awk '{print $1}')" | |||
for PART in $MOUNTED; do | |||
log "Umount $PART" | |||
$(umount $PART) | |||
done | |||
done | |||
RETVAL=$? | |||
} | |||
start() { | |||
pgrep -o iscsid && return 1 | |||
prepare | |||
$DAEMON -p $PIDFILE | |||
starttargets | |||
} | |||
starttargets() { | |||
log "Setting up iSCSI targets" | |||
$ADM -m node -l | |||
} | |||
stoptargets() { | |||
unmount | |||
if [ $RETVAL -ne 0 ]; then | |||
log "Could not umount all partitions, verify file lock!" | |||
return $RETVAL | |||
fi | |||
log "Disconnecting iSCSI targets" | |||
sync | |||
$ADM -m node -u | |||
} | |||
stop() { | |||
pgrep -o iscsid || return 1 | |||
stoptargets | |||
#needs more checks | |||
if [ $RETVAL -ne 0 ]; then | |||
log "Could not stop all targets, try again later" | |||
return $RETVAL | |||
fi | |||
log "Stopping iSCSI initiator service" | |||
$ADM -k 0 2 | |||
rm -f $PIDFILE | |||
} | |||
restart() { | |||
stop | |||
if [ $RETVAL -ne 0 ]; then | |||
log "Stopping iSCSI initiator service failed, not starting" | |||
return $RETVAL | |||
fi | |||
start | |||
} | |||
restarttargets() { | |||
stoptargets | |||
if [ $RETVAL -ne 0 ]; then | |||
log "Could not stop all targets, try again later" | |||
return $RETVAL | |||
fi | |||
starttargets | |||
} |
@ -0,0 +1,54 @@ | |||
From 97071360caa6868c21a161047ed471790c405efb Mon Sep 17 00:00:00 2001 | |||
From: Chris Leech <cleech@redhat.com> | |||
Date: Tue, 13 Aug 2013 10:59:44 -0700 | |||
Subject: [PATCH] idmb_rec_write, check for tpgt first | |||
Factor out the check for a tpgt to a single place, before going crazy on | |||
the rec files. Makes flow of this function easier to follow, and preps | |||
for splitting it up. | |||
--- | |||
usr/idbm.c | 18 +++++------------- | |||
1 file changed, 5 insertions(+), 13 deletions(-) | |||
diff --git a/usr/idbm.c b/usr/idbm.c | |||
index be4d4e3..a7da540 100644 | |||
--- a/usr/idbm.c | |||
+++ b/usr/idbm.c | |||
@@ -2078,6 +2078,10 @@ static int idbm_rec_write(node_rec_t *rec, bool disable_lock) | |||
goto free_portal; | |||
} | |||
+ if (rec->tpgt == PORTAL_GROUP_TAG_UNKNOWN) | |||
+ /* drop down to old style portal as config */ | |||
+ goto open_conf; | |||
+ | |||
rc = stat(portal, &statb); | |||
if (rc) { | |||
rc = 0; | |||
@@ -2086,22 +2090,10 @@ static int idbm_rec_write(node_rec_t *rec, bool disable_lock) | |||
* set the tgpt. In new versions you must pass all the info in | |||
* from the start | |||
*/ | |||
- if (rec->tpgt == PORTAL_GROUP_TAG_UNKNOWN) | |||
- /* drop down to old style portal as config */ | |||
- goto open_conf; | |||
- else | |||
- goto mkdir_portal; | |||
+ goto mkdir_portal; | |||
} | |||
if (!S_ISDIR(statb.st_mode)) { | |||
- /* | |||
- * older iscsiadm versions had you create the config then set | |||
- * set the tgpt. In new versions you must pass all the info in | |||
- * from the start | |||
- */ | |||
- if (rec->tpgt == PORTAL_GROUP_TAG_UNKNOWN) | |||
- /* drop down to old style portal as config */ | |||
- goto open_conf; | |||
/* | |||
* Old style portal as a file, but with tpgt. Let's update it. | |||
*/ | |||
-- | |||
2.21.0 | |||
@ -0,0 +1,193 @@ | |||
From 4c6e7c0fcc6da66cf81c0714bf907762194eedf2 Mon Sep 17 00:00:00 2001 | |||
From: Chris Leech <cleech@redhat.com> | |||
Date: Tue, 13 Aug 2013 11:34:31 -0700 | |||
Subject: [PATCH] idbm_rec_write, seperate old and new style writes | |||
Duplicates a small bit of code, but easier to understand and extened. | |||
--- | |||
usr/idbm.c | 129 +++++++++++++++++++++++++++++++++++------------------ | |||
1 file changed, 86 insertions(+), 43 deletions(-) | |||
diff --git a/usr/idbm.c b/usr/idbm.c | |||
index a7da540..2f5e309 100644 | |||
--- a/usr/idbm.c | |||
+++ b/usr/idbm.c | |||
@@ -2030,12 +2030,7 @@ mkdir_portal: | |||
return f; | |||
} | |||
-/* | |||
- * When the disable_lock param is true, the idbm_lock/idbm_unlock needs | |||
- * to be holt by the caller, this will avoid overwriting each other in | |||
- * case of updating(read-modify-write) the recs in parallel. | |||
- */ | |||
-static int idbm_rec_write(node_rec_t *rec, bool disable_lock) | |||
+static int idbm_rec_write_new(node_rec_t *rec) | |||
{ | |||
struct stat statb; | |||
FILE *f; | |||
@@ -2048,39 +2043,8 @@ static int idbm_rec_write(node_rec_t *rec, bool disable_lock) | |||
return ISCSI_ERR_NOMEM; | |||
} | |||
- snprintf(portal, PATH_MAX, "%s", NODE_CONFIG_DIR); | |||
- if (access(portal, F_OK) != 0) { | |||
- if (mkdir(portal, 0660) != 0) { | |||
- log_error("Could not make %s: %s", portal, | |||
- strerror(errno)); | |||
- rc = ISCSI_ERR_IDBM; | |||
- goto free_portal; | |||
- } | |||
- } | |||
- | |||
- snprintf(portal, PATH_MAX, "%s/%s", NODE_CONFIG_DIR, rec->name); | |||
- if (access(portal, F_OK) != 0) { | |||
- if (mkdir(portal, 0660) != 0) { | |||
- log_error("Could not make %s: %s", portal, | |||
- strerror(errno)); | |||
- rc = ISCSI_ERR_IDBM; | |||
- goto free_portal; | |||
- } | |||
- } | |||
- | |||
snprintf(portal, PATH_MAX, "%s/%s/%s,%d", NODE_CONFIG_DIR, | |||
rec->name, rec->conn[0].address, rec->conn[0].port); | |||
- log_debug(5, "Looking for config file %s", portal); | |||
- | |||
- if (!disable_lock) { | |||
- rc = idbm_lock(); | |||
- if (rc) | |||
- goto free_portal; | |||
- } | |||
- | |||
- if (rec->tpgt == PORTAL_GROUP_TAG_UNKNOWN) | |||
- /* drop down to old style portal as config */ | |||
- goto open_conf; | |||
rc = stat(portal, &statb); | |||
if (rc) { | |||
@@ -2101,11 +2065,11 @@ static int idbm_rec_write(node_rec_t *rec, bool disable_lock) | |||
log_error("Could not convert %s: %s", portal, | |||
strerror(errno)); | |||
rc = ISCSI_ERR_IDBM; | |||
- goto unlock; | |||
+ goto free_portal; | |||
} | |||
} else { | |||
rc = ISCSI_ERR_INVAL; | |||
- goto unlock; | |||
+ goto free_portal; | |||
} | |||
mkdir_portal: | |||
@@ -2116,24 +2080,103 @@ mkdir_portal: | |||
log_error("Could not make dir %s: %s", | |||
portal, strerror(errno)); | |||
rc = ISCSI_ERR_IDBM; | |||
- goto unlock; | |||
+ goto free_portal; | |||
} | |||
} | |||
snprintf(portal, PATH_MAX, "%s/%s/%s,%d,%d/%s", NODE_CONFIG_DIR, | |||
rec->name, rec->conn[0].address, rec->conn[0].port, rec->tpgt, | |||
rec->iface.name); | |||
-open_conf: | |||
+ | |||
f = fopen(portal, "w"); | |||
if (!f) { | |||
log_error("Could not open %s: %s", portal, strerror(errno)); | |||
rc = ISCSI_ERR_IDBM; | |||
- goto unlock; | |||
+ goto free_portal; | |||
} | |||
idbm_print(IDBM_PRINT_TYPE_NODE, rec, 1, f); | |||
fclose(f); | |||
-unlock: | |||
+free_portal: | |||
+ free(portal); | |||
+ return rc; | |||
+} | |||
+ | |||
+static int idbm_rec_write_old(node_rec_t *rec) | |||
+{ | |||
+ FILE *f; | |||
+ char *portal; | |||
+ int rc = 0; | |||
+ | |||
+ portal = malloc(PATH_MAX); | |||
+ if (!portal) { | |||
+ log_error("Could not alloc portal"); | |||
+ return ISCSI_ERR_NOMEM; | |||
+ } | |||
+ snprintf(portal, PATH_MAX, "%s/%s/%s,%d", NODE_CONFIG_DIR, | |||
+ rec->name, rec->conn[0].address, rec->conn[0].port); | |||
+ | |||
+ f = fopen(portal, "w"); | |||
+ if (!f) { | |||
+ log_error("Could not open %s: %sd", portal, strerror(errno)); | |||
+ rc = ISCSI_ERR_IDBM; | |||
+ goto free_portal; | |||
+ } | |||
+ idbm_print(IDBM_PRINT_TYPE_NODE, rec, 1, f); | |||
+ fclose(f); | |||
+free_portal: | |||
+ free(portal); | |||
+ return rc; | |||
+} | |||
+ | |||
+/* | |||
+ * When the disable_lock param is true, the idbm_lock/idbm_unlock needs | |||
+ * to be holt by the caller, this will avoid overwriting each other in | |||
+ * case of updating(read-modify-write) the recs in parallel. | |||
+ */ | |||
+static int idbm_rec_write(node_rec_t *rec, bool disable_lock) | |||
+{ | |||
+ char *portal; | |||
+ int rc = 0; | |||
+ | |||
+ portal = malloc(PATH_MAX); | |||
+ if (!portal) { | |||
+ log_error("Could not alloc portal"); | |||
+ return ISCSI_ERR_NOMEM; | |||
+ } | |||
+ | |||
+ snprintf(portal, PATH_MAX, "%s", NODE_CONFIG_DIR); | |||
+ if (access(portal, F_OK) != 0) { | |||
+ if (mkdir(portal, 0660) != 0) { | |||
+ log_error("Could not make %s: %s", portal, | |||
+ strerror(errno)); | |||
+ rc = ISCSI_ERR_IDBM; | |||
+ goto free_portal; | |||
+ } | |||
+ } | |||
+ | |||
+ snprintf(portal, PATH_MAX, "%s/%s", NODE_CONFIG_DIR, rec->name); | |||
+ if (access(portal, F_OK) != 0) { | |||
+ if (mkdir(portal, 0660) != 0) { | |||
+ log_error("Could not make %s: %s", portal, | |||
+ strerror(errno)); | |||
+ rc = ISCSI_ERR_IDBM; | |||
+ goto free_portal; | |||
+ } | |||
+ } | |||
+ | |||
+ if (!disable_lock) { | |||
+ rc = idbm_lock(); | |||
+ if (rc) | |||
+ goto free_portal; | |||
+ } | |||
+ | |||
+ if (rec->tpgt == PORTAL_GROUP_TAG_UNKNOWN) | |||
+ /* old style portal as config */ | |||
+ rc = idbm_rec_write_old(rec); | |||
+ else | |||
+ rc = idbm_rec_write_new(rec); | |||
+ | |||
if (!disable_lock) | |||
idbm_unlock(); | |||
free_portal: | |||
-- | |||
2.21.0 | |||
@ -0,0 +1,87 @@ | |||
From 351ee477f713730d1c53cf26b6fb87706d268a5f Mon Sep 17 00:00:00 2001 | |||
From: Chris Leech <cleech@redhat.com> | |||
Date: Tue, 13 Aug 2013 12:39:07 -0700 | |||
Subject: [PATCH 1/1] idbw_rec_write, pick tpgt from existing record | |||
On a static add (-m node -o new) without a user specified tpgt, looks | |||
for existing new style records with tpgt before creating an old style | |||
record without. If one exists, take the tpgt from it an write an | |||
updated new style record instead. | |||
--- | |||
usr/idbm.c | 40 ++++++++++++++++++++++++++++++++++++++++ | |||
1 file changed, 40 insertions(+) | |||
diff --git a/usr/idbm.c b/usr/idbm.c | |||
index b6193e7..2208c4a 100644 | |||
--- a/usr/idbm.c | |||
+++ b/usr/idbm.c | |||
@@ -28,6 +28,7 @@ | |||
#include <dirent.h> | |||
#include <limits.h> | |||
#include <fcntl.h> | |||
+#include <glob.h> | |||
#include <sys/stat.h> | |||
#include <sys/file.h> | |||
#include <inttypes.h> | |||
@@ -202,6 +203,8 @@ static struct int_list_tbl { | |||
{ "SHA3-256", AUTH_CHAP_ALG_SHA3_256 }, | |||
}; | |||
+static int idbm_remove_disc_to_node_link(node_rec_t *rec, char *portal); | |||
+ | |||
static void | |||
idbm_recinfo_discovery(discovery_rec_t *r, recinfo_t *ri) | |||
{ | |||
@@ -2206,12 +2209,49 @@ static int idbm_rec_write_old(node_rec_t *rec) | |||
FILE *f; | |||
char *portal; | |||
int rc = 0; | |||
+ glob_t globbuf; | |||
+ size_t i; | |||
+ int tpgt = PORTAL_GROUP_TAG_UNKNOWN; | |||
portal = malloc(PATH_MAX); | |||
if (!portal) { | |||
log_error("Could not alloc portal"); | |||
return ISCSI_ERR_NOMEM; | |||
} | |||
+ | |||
+ /* check for newer portal dir with tpgt */ | |||
+ snprintf(portal, PATH_MAX, "%s/%s/%s,%d,*", NODE_CONFIG_DIR, | |||
+ rec->name, rec->conn[0].address, rec->conn[0].port); | |||
+ rc = glob(portal, GLOB_ONLYDIR, NULL, &globbuf); | |||
+ if (!rc) { | |||
+ if (globbuf.gl_pathc > 1) | |||
+ log_warning("multiple tpg records for portal " | |||
+ "%s/%s:%d found", rec->name, | |||
+ rec->conn[0].address, rec->conn[0].port); | |||
+ /* set pattern for sscanf matching of tpgt */ | |||
+ snprintf(portal, PATH_MAX, "%s/%s/%s,%d,%%u", NODE_CONFIG_DIR, | |||
+ rec->name, rec->conn[0].address, rec->conn[0].port); | |||
+ for (i = 0; i < globbuf.gl_pathc; i++) { | |||
+ rc = sscanf(globbuf.gl_pathv[i], portal, &tpgt); | |||
+ if (rc == 1) | |||
+ break; | |||
+ } | |||
+ if (tpgt == PORTAL_GROUP_TAG_UNKNOWN) | |||
+ log_warning("glob match on existing records, " | |||
+ "but no valid tpgt found"); | |||
+ } | |||
+ globfree(&globbuf); | |||
+ rc = 0; | |||
+ | |||
+ /* if a tpgt was selected from an old record, write entry in new format */ | |||
+ if (tpgt != PORTAL_GROUP_TAG_UNKNOWN) { | |||
+ log_warning("using tpgt %u from existing record", tpgt); | |||
+ rec->tpgt = tpgt; | |||
+ rc = idbm_remove_disc_to_node_link(rec, portal); | |||
+ free(portal); | |||
+ return idbm_rec_write_new(rec); | |||
+ } | |||
+ | |||
snprintf(portal, PATH_MAX, "%s/%s/%s,%d", NODE_CONFIG_DIR, | |||
rec->name, rec->conn[0].address, rec->conn[0].port); | |||
-- | |||
2.21.1 | |||
@ -0,0 +1,45 @@ | |||
From d0689253c9e2eb78fc5296adb109aba4d35a13fd Mon Sep 17 00:00:00 2001 | |||
From: Chris Leech <cleech@redhat.com> | |||
Date: Mon, 19 Nov 2012 17:09:24 -0800 | |||
Subject: [PATCH] remove the offload boot supported ifdef | |||
--- | |||
usr/iface.c | 7 +------ | |||
1 file changed, 1 insertion(+), 6 deletions(-) | |||
diff --git a/usr/iface.c b/usr/iface.c | |||
index 645b0b8..9cd07fd 100644 | |||
--- a/usr/iface.c | |||
+++ b/usr/iface.c | |||
@@ -993,6 +993,7 @@ int iface_setup_from_boot_context(struct iface_rec *iface, | |||
{ | |||
struct iscsi_transport *t = NULL; | |||
uint32_t hostno; | |||
+ int rc; | |||
if (strlen(context->initiatorname)) | |||
strlcpy(iface->iname, context->initiatorname, | |||
@@ -1006,10 +1007,7 @@ int iface_setup_from_boot_context(struct iface_rec *iface, | |||
return 0; | |||
} | |||
} else if (strlen(context->iface)) { | |||
-/* this ifdef is only temp until distros and firmwares are updated */ | |||
-#ifdef OFFLOAD_BOOT_SUPPORTED | |||
char transport_name[ISCSI_TRANSPORT_NAME_MAXLEN]; | |||
- int rc; | |||
memset(transport_name, 0, ISCSI_TRANSPORT_NAME_MAXLEN); | |||
/* make sure offload driver is loaded */ | |||
@@ -1035,9 +1033,6 @@ int iface_setup_from_boot_context(struct iface_rec *iface, | |||
} | |||
strlcpy(iface->netdev, context->iface, sizeof(iface->netdev)); | |||
-#else | |||
- return 0; | |||
-#endif | |||
} else | |||
return 0; | |||
-- | |||
2.21.0 | |||
@ -0,0 +1,114 @@ | |||
From ad8c3353b8e482575ff2208182290cf35b624dde Mon Sep 17 00:00:00 2001 | |||
From: Chris Leech <cleech@redhat.com> | |||
Date: Wed, 5 Jun 2019 09:08:39 -0700 | |||
Subject: [PATCH 1/1] Coverity scan fixes | |||
--- | |||
iscsiuio/src/unix/libs/qedi.c | 2 +- | |||
iscsiuio/src/unix/main.c | 3 +++ | |||
libopeniscsiusr/idbm.c | 11 +++++------ | |||
usr/idbm.c | 10 ++++------ | |||
usr/initiator.c | 2 +- | |||
usr/iscsid.c | 2 +- | |||
6 files changed, 15 insertions(+), 15 deletions(-) | |||
diff --git a/iscsiuio/src/unix/libs/qedi.c b/iscsiuio/src/unix/libs/qedi.c | |||
index 3414cb5..a359700 100644 | |||
--- a/iscsiuio/src/unix/libs/qedi.c | |||
+++ b/iscsiuio/src/unix/libs/qedi.c | |||
@@ -1023,7 +1023,7 @@ static int qedi_read(nic_t *nic, packet_t *pkt) | |||
LOG_DEBUG(PFX "%s:hw_prod %d bd_prod %d, rx_pkt_idx %d, rxlen %d", | |||
nic->log_name, hw_prod, bd_prod, rx_bd->rx_pkt_index, len); | |||
- LOG_DEBUG(PFX "%s: sw_con %d bd_cons %d num BD %d", | |||
+ LOG_DEBUG(PFX "%s: sw_con %d bd_cons %d num BD %lu", | |||
nic->log_name, sw_cons, bd_cons, QEDI_NUM_RX_BD); | |||
if (bd_cons != bd_prod) { | |||
diff --git a/iscsiuio/src/unix/main.c b/iscsiuio/src/unix/main.c | |||
index 0c9ad49..f83f305 100644 | |||
--- a/iscsiuio/src/unix/main.c | |||
+++ b/iscsiuio/src/unix/main.c | |||
@@ -391,6 +391,9 @@ int main(int argc, char *argv[]) | |||
sigaddset(&set, SIGTERM); | |||
sigaddset(&set, SIGUSR1); | |||
rc = pthread_sigmask(SIG_SETMASK, &set, NULL); | |||
+ if (rc != 0) { | |||
+ LOG_ERR("Failed to set thread signal mask"); | |||
+ } | |||
/* Spin off the signal handling thread */ | |||
pthread_attr_init(&attr); | |||
diff --git a/libopeniscsiusr/idbm.c b/libopeniscsiusr/idbm.c | |||
index 7bc2381..7d4c338 100644 | |||
--- a/libopeniscsiusr/idbm.c | |||
+++ b/libopeniscsiusr/idbm.c | |||
@@ -321,12 +321,11 @@ int _idbm_lock(struct iscsi_context *ctx) | |||
return 0; | |||
} | |||
- if (access(LOCK_DIR, F_OK) != 0) { | |||
- if (mkdir(LOCK_DIR, 0660) != 0) { | |||
- _error(ctx, "Could not open %s: %d %s", LOCK_DIR, errno, | |||
- _strerror(errno, strerr_buff)); | |||
- return LIBISCSI_ERR_IDBM; | |||
- } | |||
+ if (((mkdir(LOCK_DIR, 0660) != 0) && (errno != EEXIST)) || | |||
+ (access(LOCK_DIR, F_OK) != 0)) { | |||
+ _error(ctx, "Could not open %s: %d %s", LOCK_DIR, errno, | |||
+ _strerror(errno, strerr_buff)); | |||
+ return LIBISCSI_ERR_IDBM; | |||
} | |||
fd = open(LOCK_FILE, O_RDWR | O_CREAT, 0666); | |||
diff --git a/usr/idbm.c b/usr/idbm.c | |||
index d5e16cb..a210c88 100644 | |||
--- a/usr/idbm.c | |||
+++ b/usr/idbm.c | |||
@@ -1438,12 +1438,10 @@ int idbm_lock(void) | |||
return 0; | |||
} | |||
- if (access(LOCK_DIR, F_OK) != 0) { | |||
- if (mkdir(LOCK_DIR, 0660) != 0) { | |||
- log_error("Could not open %s: %s", LOCK_DIR, | |||
- strerror(errno)); | |||
- return ISCSI_ERR_IDBM; | |||
- } | |||
+ if (((mkdir(LOCK_DIR, 0660) != 0) && (errno != EEXIST)) || | |||
+ (access(LOCK_DIR, F_OK) != 0)) { | |||
+ log_error("Could not open %s: %s", LOCK_DIR, strerror(errno)); | |||
+ return ISCSI_ERR_IDBM; | |||
} | |||
fd = open(LOCK_FILE, O_RDWR | O_CREAT, 0666); | |||
diff --git a/usr/iscsid.c b/usr/iscsid.c | |||
index 99d27ab..dbb0900 100644 | |||
--- a/usr/iscsid.c | |||
+++ b/usr/iscsid.c | |||
@@ -490,8 +490,8 @@ int main(int argc, char *argv[]) | |||
log_close(log_pid); | |||
exit(ISCSI_ERR); | |||
} | |||
+ close(fd); | |||
} | |||
- close(fd); | |||
if ((control_fd = ipc->ctldev_open()) < 0) { | |||
log_close(log_pid); | |||
diff --git a/usr/initiator.c b/usr/initiator.c | |||
index a07f9aa..a06760c 100644 | |||
--- a/usr/initiator.c | |||
+++ b/usr/initiator.c | |||
@@ -580,7 +580,7 @@ __session_conn_reopen(iscsi_conn_t *conn, queue_task_t *qtask, int do_stop, | |||
int redirected) | |||
{ | |||
iscsi_session_t *session = conn->session; | |||
- uint32_t delay; | |||
+ uint32_t delay = 0; | |||
log_debug(1, "re-opening session %d (reopen_cnt %d)", session->id, | |||
session->reopen_cnt); | |||
-- | |||
2.21.1 | |||
@ -0,0 +1,62 @@ | |||
From d4ed4972df1ffe9381e33f2800f8e574f632948c Mon Sep 17 00:00:00 2001 | |||
From: rpm-build <rpm-build> | |||
Date: Mon, 2 Mar 2020 15:21:30 -0800 | |||
Subject: [PATCH 1/1] iscsi_if.h replace zero-length array with flexible-array | |||
member | |||
--- | |||
include/iscsi_if.h | 10 +++++----- | |||
1 file changed, 5 insertions(+), 5 deletions(-) | |||
diff --git a/include/iscsi_if.h b/include/iscsi_if.h | |||
index 2d46214..e8cee0d 100644 | |||
--- a/include/iscsi_if.h | |||
+++ b/include/iscsi_if.h | |||
@@ -337,7 +337,7 @@ enum iscsi_param_type { | |||
struct iscsi_param_info { | |||
uint32_t len; /* Actual length of the param value */ | |||
uint16_t param; /* iscsi param */ | |||
- uint8_t value[0]; /* length sized value follows */ | |||
+ uint8_t value[]; /* length sized value follows */ | |||
} __attribute__((__packed__)); | |||
struct iscsi_iface_param_info { | |||
@@ -346,7 +346,7 @@ struct iscsi_iface_param_info { | |||
uint16_t param; /* iscsi param value */ | |||
uint8_t iface_type; /* IPv4 or IPv6 */ | |||
uint8_t param_type; /* iscsi_param_type */ | |||
- uint8_t value[0]; /* length sized value follows */ | |||
+ uint8_t value[]; /* length sized value follows */ | |||
} __attribute__((__packed__)); | |||
/* | |||
@@ -723,7 +723,7 @@ enum iscsi_flashnode_param { | |||
struct iscsi_flashnode_param_info { | |||
uint32_t len; /* Actual length of the param */ | |||
uint16_t param; /* iscsi param value */ | |||
- uint8_t value[0]; /* length sized value follows */ | |||
+ uint8_t value[]; /* length sized value follows */ | |||
} __attribute__((__packed__)); | |||
enum iscsi_discovery_parent_type { | |||
@@ -841,7 +841,7 @@ struct iscsi_stats { | |||
* up to ISCSI_STATS_CUSTOM_MAX | |||
*/ | |||
uint32_t custom_length; | |||
- struct iscsi_stats_custom custom[0] | |||
+ struct iscsi_stats_custom custom[] | |||
__attribute__ ((aligned (sizeof(uint64_t)))); | |||
}; | |||
@@ -972,7 +972,7 @@ struct iscsi_offload_host_stats { | |||
* up to ISCSI_HOST_STATS_CUSTOM_MAX | |||
*/ | |||
uint32_t custom_length; | |||
- struct iscsi_host_stats_custom custom[0] | |||
+ struct iscsi_host_stats_custom custom[] | |||
__attribute__ ((aligned (sizeof(uint64_t)))); | |||
}; | |||
-- | |||
2.21.1 | |||
@ -0,0 +1,65 @@ | |||
From b32f59619c32ed6cd136194d92c649b74926c6f2 Mon Sep 17 00:00:00 2001 | |||
From: Lee Duncan <lduncan@suse.com> | |||
Date: Wed, 25 Mar 2020 18:00:50 -0700 | |||
Subject: [PATCH] Fix issue where "iscsi-iname -p" core dumps. | |||
While I was at it, I made the usage message a function | |||
and made it print to stderr insted of stdout. | |||
--- | |||
utils/Makefile | 2 +- | |||
utils/iscsi-iname.c | 17 +++++++++++++---- | |||
2 files changed, 14 insertions(+), 5 deletions(-) | |||
diff --git a/utils/Makefile b/utils/Makefile | |||
index f65f1e79..aed3bb0a 100644 | |||
--- a/utils/Makefile | |||
+++ b/utils/Makefile | |||
@@ -1,7 +1,7 @@ | |||
# This Makefile will work only with GNU make. | |||
CFLAGS ?= -O2 -fno-inline -g | |||
-CFLAGS += -Wall -Wstrict-prototypes | |||
+CFLAGS += -Wall -Wextra -Wstrict-prototypes | |||
PROGRAMS = iscsi-iname | |||
all: $(PROGRAMS) | |||
diff --git a/utils/iscsi-iname.c b/utils/iscsi-iname.c | |||
index da850dca..0f587e1e 100644 | |||
--- a/utils/iscsi-iname.c | |||
+++ b/utils/iscsi-iname.c | |||
@@ -40,6 +40,13 @@ | |||
* a seperator and 12 characters (6 random bytes in hex representation) */ | |||
#define PREFIX_MAX_LEN 210 | |||
+static void usage(void) | |||
+{ | |||
+ fprintf(stderr, "Usage: iscsi-iname [-h | --help | -p <prefix>]\n"); | |||
+ fprintf(stderr, "where <prefix> has max length of %d\n", | |||
+ PREFIX_MAX_LEN); | |||
+} | |||
+ | |||
int | |||
main(int argc, char *argv[]) | |||
{ | |||
@@ -68,15 +75,17 @@ main(int argc, char *argv[]) | |||
"on every invocation.\n"); | |||
exit(0); | |||
} else if ( strcmp(prefix, "-p") == 0 ) { | |||
+ if (argc != 3) { | |||
+ usage(); | |||
+ exit(1); | |||
+ } | |||
prefix = argv[2]; | |||
if (strnlen(prefix, PREFIX_MAX_LEN + 1) > PREFIX_MAX_LEN) { | |||
- printf("Error: Prefix cannot exceed %d " | |||
- "characters.\n", PREFIX_MAX_LEN); | |||
+ usage(); | |||
exit(1); | |||
} | |||
} else { | |||
- printf("\nUsage: iscsi-iname [-h | --help | " | |||
- "-p <prefix>]\n"); | |||
+ usage(); | |||
exit(0); | |||
} | |||
} else { |
@ -0,0 +1,173 @@ | |||
From 6ed14d48f6e9a8dfb37cc68472b04cfb3673b7bd Mon Sep 17 00:00:00 2001 | |||
From: Lee Duncan <lduncan@suse.com> | |||
Date: Fri, 27 Mar 2020 17:50:41 -0700 | |||
Subject: [PATCH 1/3] Change include of <sys/poll.h> to <poll.h> | |||
The proper local is <poll.h>. | |||
--- | |||
iscsiuio/src/unix/nic_nl.c | 2 +- | |||
usr/discovery.c | 2 +- | |||
usr/event_poll.c | 2 +- | |||
usr/io.c | 2 +- | |||
usr/netlink.c | 2 +- | |||
5 files changed, 5 insertions(+), 5 deletions(-) | |||
diff --git a/iscsiuio/src/unix/nic_nl.c b/iscsiuio/src/unix/nic_nl.c | |||
index f8306563..dee462e7 100644 | |||
--- a/iscsiuio/src/unix/nic_nl.c | |||
+++ b/iscsiuio/src/unix/nic_nl.c | |||
@@ -50,7 +50,7 @@ | |||
#include <linux/netlink.h> | |||
#include <iscsi_if.h> | |||
#include <sys/ioctl.h> | |||
-#include <sys/poll.h> | |||
+#include <poll.h> | |||
#include <sys/types.h> | |||
#include <sys/user.h> | |||
#include <sys/socket.h> | |||
diff --git a/usr/discovery.c b/usr/discovery.c | |||
index 9ce122e1..7dec696f 100644 | |||
--- a/usr/discovery.c | |||
+++ b/usr/discovery.c | |||
@@ -25,7 +25,7 @@ | |||
#include <stdint.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
-#include <sys/poll.h> | |||
+#include <poll.h> | |||
#include <sys/time.h> | |||
#include <sys/param.h> | |||
#include <sys/socket.h> | |||
diff --git a/usr/event_poll.c b/usr/event_poll.c | |||
index 4cf4ce2b..ffd12a37 100644 | |||
--- a/usr/event_poll.c | |||
+++ b/usr/event_poll.c | |||
@@ -23,7 +23,7 @@ | |||
*/ | |||
#include <stdlib.h> | |||
#include <errno.h> | |||
-#include <sys/poll.h> | |||
+#include <poll.h> | |||
#include <sys/types.h> | |||
#include <sys/wait.h> | |||
#include <sys/signalfd.h> | |||
diff --git a/usr/io.c b/usr/io.c | |||
index 210a10ad..a46c9f8c 100644 | |||
--- a/usr/io.c | |||
+++ b/usr/io.c | |||
@@ -24,7 +24,7 @@ | |||
#include <signal.h> | |||
#include <unistd.h> | |||
#include <fcntl.h> | |||
-#include <sys/poll.h> | |||
+#include <poll.h> | |||
#include <sys/ioctl.h> | |||
#include <netinet/tcp.h> | |||
#include <arpa/inet.h> | |||
diff --git a/usr/netlink.c b/usr/netlink.c | |||
index d42ca4fb..22cad834 100644 | |||
--- a/usr/netlink.c | |||
+++ b/usr/netlink.c | |||
@@ -30,7 +30,7 @@ | |||
#include <asm/types.h> | |||
#include <sys/socket.h> | |||
#include <sys/types.h> | |||
-#include <sys/poll.h> | |||
+#include <poll.h> | |||
#include <linux/netlink.h> | |||
#include "types.h" | |||
From fbe6c1c766a88edccb0d7f4168d2d87a3cdb4660 Mon Sep 17 00:00:00 2001 | |||
From: Lee Duncan <lduncan@suse.com> | |||
Date: Fri, 27 Mar 2020 17:57:52 -0700 | |||
Subject: [PATCH 2/3] Fix type mismatch under musl. | |||
It complains about rl.rlim_cur and rl.rlim_max being | |||
long long unsigned, so cast them, since it's debug | |||
messages anyway. | |||
--- | |||
usr/iscsi_util.c | 7 +++++-- | |||
1 file changed, 5 insertions(+), 2 deletions(-) | |||
diff --git a/usr/iscsi_util.c b/usr/iscsi_util.c | |||
index fd8fc0cf..db1dc377 100644 | |||
--- a/usr/iscsi_util.c | |||
+++ b/usr/iscsi_util.c | |||
@@ -152,7 +152,9 @@ int increase_max_files(void) | |||
log_debug(1, "Could not get file limit (err %d)", errno); | |||
return errno; | |||
} | |||
- log_debug(1, "Max file limits %lu %lu", rl.rlim_cur, rl.rlim_max); | |||
+ log_debug(1, "Max file limits %lu %lu", | |||
+ (long unsigned)rl.rlim_cur, | |||
+ (long unsigned)rl.rlim_max); | |||
if (rl.rlim_cur < ISCSI_MAX_FILES) | |||
rl.rlim_cur = ISCSI_MAX_FILES; | |||
@@ -162,7 +164,8 @@ int increase_max_files(void) | |||
err = setrlimit(RLIMIT_NOFILE, &rl); | |||
if (err) { | |||
log_debug(1, "Could not set file limit to %lu/%lu (err %d)", | |||
- rl.rlim_cur, rl.rlim_max, errno); | |||
+ (long unsigned)rl.rlim_cur, | |||
+ (long unsigned)rl.rlim_max, errno); | |||
return errno; | |||
} | |||
From a93c2f1cf5a55887074bdda65aa6ad6c533191f0 Mon Sep 17 00:00:00 2001 | |||
From: Lee Duncan <lduncan@suse.com> | |||
Date: Sun, 29 Mar 2020 11:01:07 -0700 | |||
Subject: [PATCH 3/3] More changes for musl. | |||
Clean up some code that musl complains about. The | |||
changes all seem like a good idea in general, and | |||
should not effect functionality. | |||
--- | |||
usr/iscsistart.c | 1 - | |||
usr/mgmt_ipc.c | 1 + | |||
usr/statics.c | 3 +-- | |||
3 files changed, 2 insertions(+), 3 deletions(-) | |||
diff --git a/usr/iscsistart.c b/usr/iscsistart.c | |||
index 00a9c78a..ee810f7a 100644 | |||
--- a/usr/iscsistart.c | |||
+++ b/usr/iscsistart.c | |||
@@ -30,7 +30,6 @@ | |||
#include <time.h> | |||
#include <sys/mman.h> | |||
#include <sys/utsname.h> | |||
-#include <sys/signal.h> | |||
#include <sys/types.h> | |||
#include <sys/wait.h> | |||
diff --git a/usr/mgmt_ipc.c b/usr/mgmt_ipc.c | |||
index 51267c13..c292161f 100644 | |||
--- a/usr/mgmt_ipc.c | |||
+++ b/usr/mgmt_ipc.c | |||
@@ -26,6 +26,7 @@ | |||
#include <unistd.h> | |||
#include <pwd.h> | |||
#include <sys/un.h> | |||
+#include <string.h> | |||
#include "iscsid.h" | |||
#include "idbm.h" | |||
diff --git a/usr/statics.c b/usr/statics.c | |||
index 59fb044d..f59729ba 100644 | |||
--- a/usr/statics.c | |||
+++ b/usr/statics.c | |||
@@ -1,6 +1,6 @@ | |||
#include <unistd.h> | |||
#include <pwd.h> | |||
-#include <sys/errno.h> | |||
+#include <errno.h> | |||
#include <sys/types.h> | |||
static struct passwd root_pw = { | |||
@@ -17,4 +17,3 @@ getpwuid(uid_t uid) | |||
return 0; | |||
} | |||
} | |||
- |
@ -0,0 +1,25 @@ | |||
From 16d4899d52b3b88774ac6d9b3cc0f5626f4705da Mon Sep 17 00:00:00 2001 | |||
From: Lee Duncan <lduncan@suse.com> | |||
Date: Tue, 19 Nov 2019 07:54:41 -0800 | |||
Subject: [PATCH] Ignore iface.example in iface match checks | |||
Just a cleanup, as looking at the example file | |||
didn't hurt anything, but did waste our time. | |||
--- | |||
usr/iface.c | 3 +++ | |||
1 file changed, 3 insertions(+) | |||
diff --git a/usr/iface.c b/usr/iface.c | |||
index 323f1675..11f3d2ac 100644 | |||
--- a/usr/iface.c | |||
+++ b/usr/iface.c | |||
@@ -905,6 +905,9 @@ int iface_for_each_iface(void *data, int skip_def, int *nr_found, | |||
!strcmp(iface_dent->d_name, "..")) | |||
continue; | |||
+ if (!strcmp(iface_dent->d_name, "iface.example")) | |||
+ continue; | |||
+ | |||
log_debug(5, "iface_for_each_iface found %s", | |||
iface_dent->d_name); | |||
iface = iface_alloc(iface_dent->d_name, &err); |