Merge lp:~smoser/cloud-utils/trunk.1715994-drop-lxd into lp:cloud-utils

Proposed by Scott Moser
Status: Merged
Merged at revision: 321
Proposed branch: lp:~smoser/cloud-utils/trunk.1715994-drop-lxd
Merge into: lp:cloud-utils
Diff against target: 130 lines (+11/-72)
1 file modified
bin/mount-image-callback (+11/-72)
To merge this branch: bzr merge lp:~smoser/cloud-utils/trunk.1715994-drop-lxd
Reviewer Review Type Date Requested Status
Registry Administrators Pending
Review via email: mp+332809@code.launchpad.net

Commit message

mount-image-callback: Drop support for mounting lxd containers.

The 'lxd:' support in mount-image-callback only worked in some cases,
and then stopped working in all cases with lxc 2.17.

This drops the lxd support, but leaves in the 'mchroot' support which
came with it.

To post a comment you must log in.
318. By Scott Moser

better unsupported message

319. By Scott Moser

merge with trunk

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 2017-02-10 20:30:56 +0000
3+++ bin/mount-image-callback 2018-01-03 14:53:10 +0000
4@@ -17,7 +17,6 @@
5 invoke the provided cmd with args
6
7 supported 'file' are:
8- lxd:name : the rootfs for lxd container 'name'
9 file : any disk format supported by qemu-nbd
10
11 the temporary mountpoint will be put in an a environment variable
12@@ -159,37 +158,13 @@
13 local d="$1"
14 local umap="$1" gmap="$2"
15 [ -d "$1" ] || mkdir -p "$1"
16- add_bin "$d/uns-switch" <<"EOF" || return 1
17-#!/bin/sh
18-[ $# -eq 0 ] && set -- ${SHELL:-/bin/bash}
19-if [ -z "$MIC_SUBUID" -a -z "$MIC_SUBGID" ]; then
20- exec "$@"
21-fi
22-exec lxc-usernsexec ${MIC_SUBUID:+-m u:0:${MIC_SUBUID}} \
23- ${MIC_SUBGID:+-m g:0:${MIC_SUBGID}} -- "$@"
24-EOF
25 add_bin "$d/mchroot" <<"EOF" || return 1
26 #!/bin/sh
27-exec uns-switch chroot "$MOUNTPOINT" "$@"
28+exec chroot "$MOUNTPOINT" "$@"
29 EOF
30 return
31 }
32
33-get_subid() {
34- local id="$1" file="$2"
35- awk -F: '$1 == id { printf("%s:%s\n", $2, $3); exit(0); }' \
36- id="$id" "$file"
37-}
38-
39-set_subids() {
40- local id="$1" out="" muid="" mgid=""
41- [ -z "$id" ] && return 0
42- muid=$(get_subid "$id" /etc/subuid) &&
43- mgid=$(get_subid "$id" /etc/subgid) &&
44- [ -n "$muid" -a -n "$mgid" ] &&
45- export MIC_SUBGID="$muid" MIC_SUBUID="$mgid" && return
46-}
47-
48 mount_overlay() {
49 local lower="$1" upper="$2" workdir="$3"
50 local olayopts="lowerdir=$lower,upperdir=$upper"
51@@ -396,38 +371,18 @@
52 return 1;
53 }
54
55- local uns_switch=false
56 img_in="$1"
57 shift 1
58
59- case "$img_in" in
60- lxd:*)
61- if [ "$ptnum" != "auto" ]; then
62- error "--ptnum incompatible with directory"
63- return 1;
64- fi
65- command -v lxc-usernsexec >/dev/null 2>&1 || {
66- error "lxd support needs lxc-usernsexec";
67- return 1;
68- }
69- img="/var/lib/lxd/containers/${img_in#lxd:}/rootfs"
70- [ -d "$img" ] || {
71- error "${img_in}: no rootfs in $img. Not a container?"
72- return 1;
73- }
74- set_subids lxd || {
75- error "failed reading subids for lxd";
76- return 1;
77- }
78- uns_switch=true
79- ;;
80- *)
81- img=$(readlink -f "$img_in") ||
82- { error "failed to get full path to $img_in"; return 1; }
83- [ -f "$img" ] ||
84- { error "$img: not a file"; return 1; }
85- ;;
86- esac
87+ if [ "${img_in#lxd:}" != "${img_in}" -a ! -f "${img_in}" ]; then
88+ error "${img_in}: lxd is no longer supported."
89+ return 1;
90+ fi
91+
92+ img=$(readlink -f "$img_in") ||
93+ { error "failed to get full path to $img_in"; return 1; }
94+ [ -f "$img" ] ||
95+ { error "$img: not a file"; return 1; }
96
97 [ "$(id -u)" = "0" ] ||
98 { error "sorry, must be root"; return 1; }
99@@ -454,16 +409,7 @@
100 fi
101
102 out=""
103- if [ -d "$img" ]; then
104- debug 1 "using directory at $img for $img_in"
105- mp=$img
106- if $overlay; then
107- debug 1 "mounting $img to $mp"
108- mount --bind "$img" "$img_mp" ||
109- { error "failed to mount --bind '$img' '$mp'"; return 1; }
110- UMOUNTS[${#UMOUNTS[@]}]="$mp"
111- fi
112- elif [ "$ptnum" = "auto" -o "$ptnum" = "0" ] &&
113+ if [ "$ptnum" = "auto" -o "$ptnum" = "0" ] &&
114 out=$(set -f; mount -o "loop,$rwmode" $opts "$img" "$img_mp" 2>&1); then
115 debug 1 "mounted simple filesystem image $rwmode in '$img_in'"
116 UMOUNTS[${UMOUNT[@]}]="$img_mp"
117@@ -530,13 +476,6 @@
118 error "MOUNTPOINT=$mp"
119 fi
120
121- if $uns_switch && [ "$1" = "chroot" ]; then
122- debug 1 "added helper uns-switch for chroot"
123- cmd=( uns-switch "${cmd[@]}" )
124- elif $uns_switch; then
125- debug 1 "uns-switch helper can be used for changing user map"
126- fi
127-
128 add_helpers "$TEMP_D/bin" "$SUBUID" "$SUBGID" || {
129 error "failed to add helpers to $TEMP_D";
130 return 1;

Subscribers

People subscribed via source and target branches