From b7497e807fa12a26d4a12aaf1ee9302a4fd24728 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 21 Feb 2018 16:09:14 -0500 Subject: ds-identify: Fix searching for iso9660 OVF cdroms. This fixes a bug in parsing of 'blkid -o export' output. The result of the bug meant that DI_ISO9660_DEVS did not get set correctly and is_cdrom_ovf would not identify devices in most cases. The tests are improved to demonstrate both multiple iso devices and also a cdrom that doesn't sort "last" in blkid output. The code change is to use DEVNAME as the record separator when parsing blkid -o export rather than relying on being able to read the empty line. LP: #1749980 --- tools/ds-identify | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'tools') diff --git a/tools/ds-identify b/tools/ds-identify index 5f762438..5da51bcc 100755 --- a/tools/ds-identify +++ b/tools/ds-identify @@ -186,7 +186,8 @@ block_dev_with_label() { read_fs_info() { cached "${DI_BLKID_OUTPUT}" && return 0 # do not rely on links in /dev/disk which might not be present yet. - # note that older blkid versions do not report DEVNAME in 'export' output. + # Note that blkid < 2.22 (centos6, trusty) do not output DEVNAME. + # that means that DI_ISO9660_DEVS will not be set. if is_container; then # blkid will in a container, or at least currently in lxd # not provide useful information. @@ -203,21 +204,26 @@ read_fs_info() { DI_ISO9660_DEVS="$UNAVAILABLE:error" return $ret } - IFS="$CR" - set -- $out - IFS="$oifs" - for line in "$@" ""; do + # 'set --' will collapse multiple consecutive entries in IFS for + # whitespace characters (\n, tab, " ") so we cannot rely on getting + # empty lines in "$@" below. + IFS="$CR"; set -- $out; IFS="$oifs" + + for line in "$@"; do case "${line}" in - DEVNAME=*) dev=${line#DEVNAME=};; + DEVNAME=*) + [ -n "$dev" -a "$ftype" = "iso9660" ] && + isodevs="${isodevs} ${dev}=$label" + ftype=""; dev=""; label=""; + dev=${line#DEVNAME=};; LABEL=*) label="${line#LABEL=}"; labels="${labels}${line#LABEL=}${delim}";; TYPE=*) ftype=${line#TYPE=};; - "") if [ "$ftype" = "iso9660" ]; then - isodevs="${isodevs} ${dev}=$label" - fi - ftype=""; devname=""; label=""; esac done + [ -n "$dev" -a "$ftype" = "iso9660" ] && + isodevs="${isodevs} ${dev}=$label" + DI_FS_LABELS="${labels%${delim}}" DI_ISO9660_DEVS="${isodevs# }" } @@ -696,15 +702,12 @@ dscheck_OVF() { # Azure provides ovf. Skip false positive by dis-allowing. is_azure_chassis && return $DS_NOT_FOUND - local isodevs="${DI_ISO9660_DEVS}" - case "$isodevs" in - ""|$UNAVAILABLE:*) return ${DS_NOT_FOUND};; - esac - # DI_ISO9660_DEVS is =label, like /dev/sr0=OVF-TRANSPORT - for tok in $isodevs; do - is_cdrom_ovf "${tok%%=*}" "${tok#*=}" && return $DS_FOUND - done + if [ "${DI_ISO9660_DEVS#${UNAVAILABLE}:}" = "${DI_ISO9660_DEVS}" ]; then + for tok in ${DI_ISO9660_DEVS}; do + is_cdrom_ovf "${tok%%=*}" "${tok#*=}" && return $DS_FOUND + done + fi if ovf_vmware_guest_customization; then return ${DS_FOUND} -- cgit v1.2.3