Description: mount-image-callback: try mounting overlay first
 The logic to determine if mount would work was flawed in it assumed
 that both or neither of the following would succeed:
   modprobe --quiet --use-blacklist fstype
   mount -t fstype would succeed
 .
 That logic failed when modprobe could not load the module due to
 being in a chroot or some other reason.  The change here is to just
 do try the mount.  In order to avoid confusing output about trying
 to mount overlayfs we first try mounting overlay.  If that fails
 and 'overlay' seems present in /proc/filesystems, then do not bother
 trying to mount overlayfs.
Bug: https://launchpad.net/bugs/1630274
Origin: upstream, bzr-revno-304

=== modified file 'bin/mount-image-callback'
Index: cloud-utils/bin/mount-image-callback
===================================================================
--- cloud-utils.orig/bin/mount-image-callback
+++ cloud-utils/bin/mount-image-callback
@@ -4,6 +4,8 @@ VERBOSITY=0
 TEMP_D=""
 UMOUNTS=( )
 QEMU_DISCONNECT=""
+CR=$'\n'
+TAB=$'\t'
 
 error() { echo "$@" 1>&2; }
 
@@ -138,23 +140,37 @@ get_partition() {
 	fi
 }
 
-has_fs_support() {
-        local fstype="$1" tab=' '
-        grep -q "${tab}${fstype}$" /proc/filesystems
-}
-
-find_overlay_fstype() {
-        local fstype
-        set -- overlay overlayfs
-        for fstype in "$@"; do
-                has_fs_support "$m" && _RET="$fstype" && return 0
-        done
-        for modname in "$@"; do
-                if modprobe --quiet --use-blacklist "$modname"; then
-                        has_fs_support "$modname" && _RET="$modname" && return 0
+mount_overlay() {
+        local lower="$1" upper="$2" workdir="$3"
+        local olayopts="lowerdir=$lower,upperdir=$upper"
+        # 3.18+ require 'workdir=' option.
+        case "$(uname -r)" in
+                2*|3.1[01234567]*|3.[0-9].*) :;;
+                *) olayopts="${olayopts},workdir=$workdir"
+                        mkdir -p "$workdir" ||
+                                { _ERR="Failed to create workdir '$workdir'"; return 1; }
+                        ;;
+        esac
+
+        local cmd="" fstype="" ret="" out="" fsfile="/proc/filesystems"
+        _ERR=""
+        for fstype in overlay overlayfs; do
+                cmd=( mount -t "$fstype" -o "$olayopts" "$lower" "$upper" )
+                debug 2 "attempting '$fstype' mount with: ${cmd[*]}"
+                out=$("${cmd[@]}" 2>&1)
+                ret=$?
+                if [ $ret -eq 0 ]; then
+                        debug 1 "mounted '$fstype' via $fstype: ${cmd[*]}"
+                        return 0
+                fi
+                _ERR="${_ERR}Failed [$ret]: ${cmd[*]}:${CR}"
+                _ERR="${_ERR}$out${CR}"
+                if [ -r "$fsfile" ] && grep -q "${TAB}${fstype}$" "$fsfile"; then
+                        # this failed and we have support in kernel. do not try further.
+                        return $ret
                 fi
         done
-        return 1
+        return $ret
 }
 
 mount_callback_umount() {
@@ -321,7 +337,7 @@ mount_callback_umount() {
 		fi
 
 		local nptnum=""
-		debug 1 "connected $img_in ($fmt) to $nbd. waiting for device."
+                debug 1 "connected ${readonly:+${readonly} }$img_in ($fmt) to $nbd. waiting for device."
 		i=0
 
 		local out=""
@@ -385,27 +401,14 @@ mount_callback_umount() {
 	fi
 
 	if $overlay; then
-                find_overlay_fstype || {
-                        error "Unable to find a filesystem type for overlay."
-                        error "You need support for overlayfs or overlay in your kernel."
+                mount_overlay "$img_mp" "$mp" "${TEMP_D}/workdir" || {
+                        [ -n "${_ERR}" ] && error "${_ERR}"
+                        error "Unable to mount overlay filesystem.  Maybe no kernel support?"
                         return 1
                 }
-                overlay_fstype="$_RET"
-
-		local olayopts="lowerdir=$img_mp,upperdir=$mp"
-		workdir="${TEMP_D}/workdir"
-		mkdir "$workdir"
-		# 3.18+ require 'workdir=' option.
-		case "$(uname -r)" in
-			2*|3.1[01234567]*|3.[0-9].*) :;;
-			*) olayopts="${olayopts},workdir=$workdir";;
-		esac
-                mount -t "${overlay_fstype}" -o "$olayopts" "$img_mp" "$mp" || {
-                        error "failed mount -t ${overlay_fstype} -o '$olayopts' '$img_mp' '$mp'"
-			return 1;
-		}
 		UMOUNTS[${#UMOUNTS[@]}]="$mp"
 	fi
+
 	local bindmp=""
 	for bindmp in $bmounts; do
 		[ -d "$mp${bindmp}" ] || mkdir "$mp${bindmp}" ||
