Merge lp:~smoser/cloud-utils/trunk.lp1630274 into lp:cloud-utils

Proposed by Scott Moser
Status: Merged
Merged at revision: 304
Proposed branch: lp:~smoser/cloud-utils/trunk.lp1630274
Merge into: lp:cloud-utils
Diff against target: 107 lines (+37/-34)
1 file modified
bin/mount-image-callback (+37/-34)
To merge this branch: bzr merge lp:~smoser/cloud-utils/trunk.lp1630274
Reviewer Review Type Date Requested Status
Registry Administrators Pending
Review via email: mp+307586@code.launchpad.net

Commit message

mount-image-callback: try mounting overlay rather than checking 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.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/mount-image-callback'
2--- bin/mount-image-callback 2016-09-27 21:05:03 +0000
3+++ bin/mount-image-callback 2016-10-04 15:12:25 +0000
4@@ -4,6 +4,8 @@
5 TEMP_D=""
6 UMOUNTS=( )
7 QEMU_DISCONNECT=""
8+CR=$'\n'
9+TAB=$'\t'
10
11 error() { echo "$@" 1>&2; }
12
13@@ -138,23 +140,37 @@
14 fi
15 }
16
17-has_fs_support() {
18- local fstype="$1" tab=' '
19- grep -q "${tab}${fstype}$" /proc/filesystems
20-}
21+mount_overlay() {
22+ local lower="$1" upper="$2" workdir="$3"
23+ local olayopts="lowerdir=$lower,upperdir=$upper"
24+ # 3.18+ require 'workdir=' option.
25+ case "$(uname -r)" in
26+ 2*|3.1[01234567]*|3.[0-9].*) :;;
27+ *) olayopts="${olayopts},workdir=$workdir"
28+ mkdir -p "$workdir" ||
29+ { _ERR="Failed to create workdir '$workdir'"; return 1; }
30+ ;;
31+ esac
32
33-find_overlay_fstype() {
34- local fstype
35- set -- overlay overlayfs
36- for fstype in "$@"; do
37- has_fs_support "$m" && _RET="$fstype" && return 0
38- done
39- for modname in "$@"; do
40- if modprobe --quiet --use-blacklist "$modname"; then
41- has_fs_support "$modname" && _RET="$modname" && return 0
42- fi
43- done
44- return 1
45+ local cmd="" fstype="" ret="" out="" fsfile="/proc/filesystems"
46+ _ERR=""
47+ for fstype in overlay overlayfs; do
48+ cmd=( mount -t "$fstype" -o "$olayopts" "$lower" "$upper" )
49+ debug 2 "attempting '$fstype' mount with: ${cmd[*]}"
50+ out=$("${cmd[@]}" 2>&1)
51+ ret=$?
52+ if [ $ret -eq 0 ]; then
53+ debug 1 "mounted '$fstype' via $fstype: ${cmd[*]}"
54+ return 0
55+ fi
56+ _ERR="${_ERR}Failed [$ret]: ${cmd[*]}:${CR}"
57+ _ERR="${_ERR}$out${CR}"
58+ if [ -r "$fsfile" ] && grep -q "${TAB}${fstype}$" "$fsfile"; then
59+ # this failed and we have support in kernel. do not try further.
60+ return $ret
61+ fi
62+ done
63+ return $ret
64 }
65
66 mount_callback_umount() {
67@@ -321,7 +337,7 @@
68 fi
69
70 local nptnum=""
71- debug 1 "connected $img_in ($fmt) to $nbd. waiting for device."
72+ debug 1 "connected ${readonly:+${readonly} }$img_in ($fmt) to $nbd. waiting for device."
73 i=0
74 while i=$(($i+1)):; do
75 get_partition "$nbd" && nptnum="$_RET" && break
76@@ -377,27 +393,14 @@
77 fi
78
79 if $overlay; then
80- find_overlay_fstype || {
81- error "Unable to find a filesystem type for overlay."
82- error "You need support for overlayfs or overlay in your kernel."
83+ mount_overlay "$img_mp" "$mp" "${TEMP_D}/workdir" || {
84+ [ -n "${_ERR}" ] && error "${_ERR}"
85+ error "Unable to mount overlay filesystem. Maybe no kernel support?"
86 return 1
87 }
88- overlay_fstype="$_RET"
89-
90- local olayopts="lowerdir=$img_mp,upperdir=$mp"
91- workdir="${TEMP_D}/workdir"
92- mkdir "$workdir"
93- # 3.18+ require 'workdir=' option.
94- case "$(uname -r)" in
95- 2*|3.1[01234567]*|3.[0-9].*) :;;
96- *) olayopts="${olayopts},workdir=$workdir";;
97- esac
98- mount -t "${overlay_fstype}" -o "$olayopts" "$img_mp" "$mp" || {
99- error "failed mount -t ${overlay_fstype} -o '$olayopts' '$img_mp' '$mp'"
100- return 1;
101- }
102 UMOUNTS[${#UMOUNTS[@]}]="$mp"
103 fi
104+
105 local bindmp=""
106 for bindmp in $bmounts; do
107 [ -d "$mp${bindmp}" ] || mkdir "$mp${bindmp}" ||

Subscribers

People subscribed via source and target branches