Skip to content

Commit d205152

Browse files
committed
Handle overlapping iscsi names: foo and foo2, for example
1 parent 9e852e6 commit d205152

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/vm-info

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,19 +485,22 @@ info::__find_iscsi() {
485485
[ "${_lun}" = "${_target}" ] && _lun=0
486486
_target=${_target%/*}
487487

488-
_found=$(iscsictl -L -w 10 | grep ${_target} | wc -l)
489-
if [ "${_found}" -ne 1 ]; then
488+
# Set _col to be the column of iscsictl -L we want
489+
_col=$((_lun + 4))
490+
491+
# Check first with trailing space for a unique case; if this returns no results,
492+
# recheck (backward compat) without trailing space.
493+
_found=$(iscsictl -L -w 10 | awk "/${_target} /{print \$${_col}}")
494+
[ -z "_found" ] && _found=$(iscsictl -L | awk "/${_target}/{print \$${_col}}")
495+
496+
if [ $(echo "${_found}" | wc -w) -ne 1 ]; then
490497
setvar "${_var}" ""
491-
util::err "Unable to locate unique iSCSI device ${_target}"
498+
util::err "Unable to locate unique iSCSI device [${_target}]"
492499
fi
493500

494-
# _col to be the column of iscsictl -L we want
495-
_col=$((_lun + 4))
496-
_found=$(iscsictl -L | awk "/${_target}/{print \$${_col}}")
497501
if echo "${_found}" | egrep -q '^da[0-9]+$'; then
498502
setvar "${_var}" /dev/"${_found}"
499503
return 0
500504
fi
501-
502505
util::err "Unable to locate iSCSI device ${_target}/${_lun}"
503506
}

0 commit comments

Comments
 (0)