Merge lp:~smoser/ubuntu/precise/lxc/btrfs-clone-support into lp:ubuntu/precise/lxc
- Precise (12.04)
- btrfs-clone-support
- Merge into precise
Proposed by
Scott Moser
Status: | Merged |
---|---|
Merged at revision: | 54 |
Proposed branch: | lp:~smoser/ubuntu/precise/lxc/btrfs-clone-support |
Merge into: | lp:ubuntu/precise/lxc |
Diff against target: |
297 lines (+186/-9) 7 files modified
.pc/applied-patches (+1/-0) debian/changelog (+7/-0) debian/patches/0029-btrfs-clone-support.patch (+132/-0) debian/patches/series (+1/-0) src/lxc/lxc-clone.in (+9/-2) src/lxc/lxc-create.in (+32/-7) src/lxc/lxc-destroy.in (+4/-0) |
To merge this branch: | bzr merge lp:~smoser/ubuntu/precise/lxc/btrfs-clone-support |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu branches | Pending | ||
Review via email: mp+90236@code.launchpad.net |
Commit message
Description of the change
This adds minimally tested btrfs clone support.
To post a comment you must log in.
- 52. By Scott Moser
-
0029-btrfs-
clone-support. patch: add support for cloning via
btrfs snapshots (LP: #921921). - 53. By Scott Moser
-
fix issue in clone, where rootfs was not written
- 54. By Scott Moser
-
lxc-create: if no '-B' flag is given and btrfs is available, use it
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.pc/applied-patches' | |||
2 | --- .pc/applied-patches 2012-01-25 14:22:51 +0000 | |||
3 | +++ .pc/applied-patches 2012-01-26 16:18:34 +0000 | |||
4 | @@ -39,3 +39,4 @@ | |||
5 | 39 | 0026-support-new-reboot.patch | 39 | 0026-support-new-reboot.patch |
6 | 40 | 0027-fix-lxc-netstat.patch | 40 | 0027-fix-lxc-netstat.patch |
7 | 41 | 0028-recursively-rmdir-cgroups.patch | 41 | 0028-recursively-rmdir-cgroups.patch |
8 | 42 | 0029-btrfs-clone-support.patch | ||
9 | 42 | 43 | ||
10 | === modified file 'debian/changelog' | |||
11 | --- debian/changelog 2012-01-25 14:22:51 +0000 | |||
12 | +++ debian/changelog 2012-01-26 16:18:34 +0000 | |||
13 | @@ -1,3 +1,10 @@ | |||
14 | 1 | lxc (0.7.5-3ubuntu13) precise; urgency=low | ||
15 | 2 | |||
16 | 3 | * 0029-btrfs-clone-support.patch: add support for cloning via | ||
17 | 4 | btrfs snapshots (LP: #921921). | ||
18 | 5 | |||
19 | 6 | -- Scott Moser <smoser@ubuntu.com> Thu, 26 Jan 2012 09:14:49 -0500 | ||
20 | 7 | |||
21 | 1 | lxc (0.7.5-3ubuntu12) precise; urgency=low | 8 | lxc (0.7.5-3ubuntu12) precise; urgency=low |
22 | 2 | 9 | ||
23 | 3 | * If the kernel supports container reboot disambuation, then don't drop | 10 | * If the kernel supports container reboot disambuation, then don't drop |
24 | 4 | 11 | ||
25 | === added file 'debian/patches/0029-btrfs-clone-support.patch' | |||
26 | --- debian/patches/0029-btrfs-clone-support.patch 1970-01-01 00:00:00 +0000 | |||
27 | +++ debian/patches/0029-btrfs-clone-support.patch 2012-01-26 16:18:34 +0000 | |||
28 | @@ -0,0 +1,132 @@ | |||
29 | 1 | Description: add btrfs cloning support | ||
30 | 2 | This patch adds support for btrfs filesystem clone support via the 'btrfs' | ||
31 | 3 | command. if a container has been created with '-B btrfs', then lxc-clone | ||
32 | 4 | will automatically use it. Ie, there is no need to specify '-s' or other | ||
33 | 5 | arguments to lxc-clone. | ||
34 | 6 | . | ||
35 | 7 | This patch should probably be forwarded after some testing. | ||
36 | 8 | Author: Scott Moser <smoser@ubuntu.com> | ||
37 | 9 | Forwarded: no | ||
38 | 10 | Bug: https://bugs.launchpad.net/bugs/921921 | ||
39 | 11 | --- a/src/lxc/lxc-clone.in | ||
40 | 12 | +++ b/src/lxc/lxc-clone.in | ||
41 | 13 | @@ -40,8 +40,8 @@ help() { | ||
42 | 14 | |||
43 | 15 | shortoptions='ho:n:sL:v:' | ||
44 | 16 | longoptions='help,orig:,name:,snapshot,fssize,vgname' | ||
45 | 17 | -lxc_path=@LXCPATH@ | ||
46 | 18 | -bindir=@BINDIR@ | ||
47 | 19 | +lxc_path=/var/lib/lxc | ||
48 | 20 | +bindir=/usr/bin | ||
49 | 21 | snapshot=no | ||
50 | 22 | lxc_size=2G | ||
51 | 23 | lxc_vg=lxc | ||
52 | 24 | @@ -197,6 +197,13 @@ if [ -b $oldroot ]; then | ||
53 | 25 | mkdir -p $lxc_path/$lxc_new/rootfs | ||
54 | 26 | mount /dev/$lxc_vg/$lxc_new $rootfs || { echo "failed to mount new rootfs"; cleanup; } | ||
55 | 27 | mounted=1 | ||
56 | 28 | +elif out=$(btrfs subvolume list "$lxc_path/$lxc_orig/rootfs" 2>&1); then | ||
57 | 29 | + out=$(btrfs subvolume snapshot "$lxc_path/$lxc_orig/rootfs" "$rootfs" 2>&1) | ||
58 | 30 | + if [ $? -ne 0 ]; then | ||
59 | 31 | + echo "failed btrfs subvolume snapshot of $lxc_path/$lxc_orig/rootfs" | ||
60 | 32 | + cleanup | ||
61 | 33 | + fi | ||
62 | 34 | + echo "lxc.rootfs = $rootfs" >> "$lxc_path/$lxc_new/config" | ||
63 | 35 | else | ||
64 | 36 | cp -a $lxc_path/$lxc_orig/rootfs $lxc_path/$lxc_new/rootfs || cleanup | ||
65 | 37 | echo "lxc.rootfs = $rootfs" >> $lxc_path/$lxc_new/config | ||
66 | 38 | --- a/src/lxc/lxc-create.in | ||
67 | 39 | +++ b/src/lxc/lxc-create.in | ||
68 | 40 | @@ -25,6 +25,8 @@ usage() { | ||
69 | 41 | echo "usage: lxc-create -n <name> [-f configuration] [-t template] [-h] [fsopts] -- [template_options]" | ||
70 | 42 | echo " fsopts: -B none" | ||
71 | 43 | echo " fsopts: -B lvm [--lvname lvname] [--vgname vgname] [--fstype fstype] [--fssize fssize]" | ||
72 | 44 | + echo " fsopts: -B btrfs" | ||
73 | 45 | + echo " flag is not necessary, if possible btrfs support will be used" | ||
74 | 46 | # echo " fsopts: -B union [--uniontype overlayfs]" | ||
75 | 47 | # echo " fsopts: -B loop [--fstype fstype] [--fssize fssize]" | ||
76 | 48 | # echo " fsopts: -B qemu-nbd [--type qed|qcow2|raw] [--fstype fstype] [--fssize fssize] # Qemu qed disk format" | ||
77 | 49 | @@ -67,7 +69,7 @@ longoptions='help,name:,config:,template | ||
78 | 50 | lxc_path=@LXCPATH@ | ||
79 | 51 | bindir=@BINDIR@ | ||
80 | 52 | templatedir=@LXCTEMPLATEDIR@ | ||
81 | 53 | -backingstore=none | ||
82 | 54 | +backingstore=_unset | ||
83 | 55 | fstype=ext4 | ||
84 | 56 | fssize=500M | ||
85 | 57 | vgname=lxc | ||
86 | 58 | @@ -162,11 +164,13 @@ if [ "$(id -u)" != "0" ]; then | ||
87 | 59 | exit 1 | ||
88 | 60 | fi | ||
89 | 61 | |||
90 | 62 | -if [ $backingstore != "none" -a $backingstore != "lvm" ]; then | ||
91 | 63 | - echo "only 'none' and 'lvm' backing stores are known" | ||
92 | 64 | - usage | ||
93 | 65 | - exit 1 | ||
94 | 66 | -fi | ||
95 | 67 | +case "$backingstore" in | ||
96 | 68 | + lvm|none|btrfs|_unset) :;; | ||
97 | 69 | + *) echo "'$backingstore' is not known ('none', 'lvm', 'btrfs')" | ||
98 | 70 | + usage | ||
99 | 71 | + exit 1 | ||
100 | 72 | + ;; | ||
101 | 73 | +esac | ||
102 | 74 | |||
103 | 75 | if [ -d "$lxc_path/$lxc_name" ]; then | ||
104 | 76 | echo "'$lxc_name' already exists" | ||
105 | 77 | @@ -174,6 +178,21 @@ if [ -d "$lxc_path/$lxc_name" ]; then | ||
106 | 78 | fi | ||
107 | 79 | |||
108 | 80 | rootfs="$lxc_path/$lxc_name/rootfs" | ||
109 | 81 | + | ||
110 | 82 | +if [ "$backingstore" = "_unset" -o "$backingstore" = "btrfs" ]; then | ||
111 | 83 | + # if no backing store was given, then see if btrfs would work | ||
112 | 84 | + if which btrfs >/dev/null 2>&1 && | ||
113 | 85 | + btrfs filesystem df "$lxc_path/" >/dev/null 2>&1; then | ||
114 | 86 | + backingstore="btrfs" | ||
115 | 87 | + else | ||
116 | 88 | + if [ "$backingstore" = "btrfs" ]; then | ||
117 | 89 | + echo "missing 'btrfs' command or $lxc_path is not btrfs"; | ||
118 | 90 | + exit 1; | ||
119 | 91 | + fi | ||
120 | 92 | + backingstore="none" | ||
121 | 93 | + fi | ||
122 | 94 | +fi | ||
123 | 95 | + | ||
124 | 96 | if [ $backingstore = "lvm" ]; then | ||
125 | 97 | which vgscan > /dev/null | ||
126 | 98 | if [ $? -ne 0 ]; then | ||
127 | 99 | @@ -201,6 +220,12 @@ if [ $backingstore = "lvm" ]; then | ||
128 | 100 | echo "please delete it (using \"lvremove $rootdev\") and try again" | ||
129 | 101 | exit 1 | ||
130 | 102 | fi | ||
131 | 103 | +elif [ "$backingstore" = "btrfs" ]; then | ||
132 | 104 | + mkdir "$lxc_path/$lxc_name" | ||
133 | 105 | + if ! out=$(btrfs subvolume create "$rootfs" 2>&1); then | ||
134 | 106 | + echo "failed to create subvolume in $rootfs: $out"; | ||
135 | 107 | + exit 1; | ||
136 | 108 | + fi | ||
137 | 109 | fi | ||
138 | 110 | |||
139 | 111 | cleanup() { | ||
140 | 112 | @@ -231,7 +256,7 @@ fi | ||
141 | 113 | cp $lxc_config $lxc_path/$lxc_name/config | ||
142 | 114 | |||
143 | 115 | # Create the fs as needed | ||
144 | 116 | -mkdir $rootfs | ||
145 | 117 | +[ -d "$rootfs" ] || mkdir "$rootfs" | ||
146 | 118 | if [ $backingstore = "lvm" ]; then | ||
147 | 119 | lvcreate -L $fssize -n $lvname $vgname || exit 1 | ||
148 | 120 | udevadm settle | ||
149 | 121 | --- a/src/lxc/lxc-destroy.in | ||
150 | 122 | +++ b/src/lxc/lxc-destroy.in | ||
151 | 123 | @@ -105,5 +105,9 @@ if [ ! -z "$rootdev" ]; then | ||
152 | 124 | fi | ||
153 | 125 | fi | ||
154 | 126 | fi | ||
155 | 127 | +if out=$(btrfs subvolume list "$lxc_path/$lxc_name/rootfs" 2>&1); then | ||
156 | 128 | + out=$(btrfs subvolume delete "$lxc_path/$lxc_name/rootfs" 2>&1) || | ||
157 | 129 | + echo "WARN: failed btrfs subvolume delete: $out" | ||
158 | 130 | +fi | ||
159 | 131 | # recursively remove the container to remove old container configuration | ||
160 | 132 | rm -rf --preserve-root $lxc_path/$lxc_name | ||
161 | 0 | 133 | ||
162 | === modified file 'debian/patches/series' | |||
163 | --- debian/patches/series 2012-01-25 14:22:51 +0000 | |||
164 | +++ debian/patches/series 2012-01-26 16:18:34 +0000 | |||
165 | @@ -39,3 +39,4 @@ | |||
166 | 39 | 0026-support-new-reboot.patch | 39 | 0026-support-new-reboot.patch |
167 | 40 | 0027-fix-lxc-netstat.patch | 40 | 0027-fix-lxc-netstat.patch |
168 | 41 | 0028-recursively-rmdir-cgroups.patch | 41 | 0028-recursively-rmdir-cgroups.patch |
169 | 42 | 0029-btrfs-clone-support.patch | ||
170 | 42 | 43 | ||
171 | === modified file 'src/lxc/lxc-clone.in' | |||
172 | --- src/lxc/lxc-clone.in 2012-01-20 14:34:54 +0000 | |||
173 | +++ src/lxc/lxc-clone.in 2012-01-26 16:18:34 +0000 | |||
174 | @@ -40,8 +40,8 @@ | |||
175 | 40 | 40 | ||
176 | 41 | shortoptions='ho:n:sL:v:' | 41 | shortoptions='ho:n:sL:v:' |
177 | 42 | longoptions='help,orig:,name:,snapshot,fssize,vgname' | 42 | longoptions='help,orig:,name:,snapshot,fssize,vgname' |
180 | 43 | lxc_path=@LXCPATH@ | 43 | lxc_path=/var/lib/lxc |
181 | 44 | bindir=@BINDIR@ | 44 | bindir=/usr/bin |
182 | 45 | snapshot=no | 45 | snapshot=no |
183 | 46 | lxc_size=2G | 46 | lxc_size=2G |
184 | 47 | lxc_vg=lxc | 47 | lxc_vg=lxc |
185 | @@ -197,6 +197,13 @@ | |||
186 | 197 | mkdir -p $lxc_path/$lxc_new/rootfs | 197 | mkdir -p $lxc_path/$lxc_new/rootfs |
187 | 198 | mount /dev/$lxc_vg/$lxc_new $rootfs || { echo "failed to mount new rootfs"; cleanup; } | 198 | mount /dev/$lxc_vg/$lxc_new $rootfs || { echo "failed to mount new rootfs"; cleanup; } |
188 | 199 | mounted=1 | 199 | mounted=1 |
189 | 200 | elif out=$(btrfs subvolume list "$lxc_path/$lxc_orig/rootfs" 2>&1); then | ||
190 | 201 | out=$(btrfs subvolume snapshot "$lxc_path/$lxc_orig/rootfs" "$rootfs" 2>&1) | ||
191 | 202 | if [ $? -ne 0 ]; then | ||
192 | 203 | echo "failed btrfs subvolume snapshot of $lxc_path/$lxc_orig/rootfs" | ||
193 | 204 | cleanup | ||
194 | 205 | fi | ||
195 | 206 | echo "lxc.rootfs = $rootfs" >> "$lxc_path/$lxc_new/config" | ||
196 | 200 | else | 207 | else |
197 | 201 | cp -a $lxc_path/$lxc_orig/rootfs $lxc_path/$lxc_new/rootfs || cleanup | 208 | cp -a $lxc_path/$lxc_orig/rootfs $lxc_path/$lxc_new/rootfs || cleanup |
198 | 202 | echo "lxc.rootfs = $rootfs" >> $lxc_path/$lxc_new/config | 209 | echo "lxc.rootfs = $rootfs" >> $lxc_path/$lxc_new/config |
199 | 203 | 210 | ||
200 | === modified file 'src/lxc/lxc-create.in' | |||
201 | --- src/lxc/lxc-create.in 2012-01-23 17:24:53 +0000 | |||
202 | +++ src/lxc/lxc-create.in 2012-01-26 16:18:34 +0000 | |||
203 | @@ -25,6 +25,8 @@ | |||
204 | 25 | echo "usage: lxc-create -n <name> [-f configuration] [-t template] [-h] [fsopts] -- [template_options]" | 25 | echo "usage: lxc-create -n <name> [-f configuration] [-t template] [-h] [fsopts] -- [template_options]" |
205 | 26 | echo " fsopts: -B none" | 26 | echo " fsopts: -B none" |
206 | 27 | echo " fsopts: -B lvm [--lvname lvname] [--vgname vgname] [--fstype fstype] [--fssize fssize]" | 27 | echo " fsopts: -B lvm [--lvname lvname] [--vgname vgname] [--fstype fstype] [--fssize fssize]" |
207 | 28 | echo " fsopts: -B btrfs" | ||
208 | 29 | echo " flag is not necessary, if possible btrfs support will be used" | ||
209 | 28 | # echo " fsopts: -B union [--uniontype overlayfs]" | 30 | # echo " fsopts: -B union [--uniontype overlayfs]" |
210 | 29 | # echo " fsopts: -B loop [--fstype fstype] [--fssize fssize]" | 31 | # echo " fsopts: -B loop [--fstype fstype] [--fssize fssize]" |
211 | 30 | # echo " fsopts: -B qemu-nbd [--type qed|qcow2|raw] [--fstype fstype] [--fssize fssize] # Qemu qed disk format" | 32 | # echo " fsopts: -B qemu-nbd [--type qed|qcow2|raw] [--fstype fstype] [--fssize fssize] # Qemu qed disk format" |
212 | @@ -67,7 +69,7 @@ | |||
213 | 67 | lxc_path=@LXCPATH@ | 69 | lxc_path=@LXCPATH@ |
214 | 68 | bindir=@BINDIR@ | 70 | bindir=@BINDIR@ |
215 | 69 | templatedir=@LXCTEMPLATEDIR@ | 71 | templatedir=@LXCTEMPLATEDIR@ |
217 | 70 | backingstore=none | 72 | backingstore=_unset |
218 | 71 | fstype=ext4 | 73 | fstype=ext4 |
219 | 72 | fssize=500M | 74 | fssize=500M |
220 | 73 | vgname=lxc | 75 | vgname=lxc |
221 | @@ -162,11 +164,13 @@ | |||
222 | 162 | exit 1 | 164 | exit 1 |
223 | 163 | fi | 165 | fi |
224 | 164 | 166 | ||
230 | 165 | if [ $backingstore != "none" -a $backingstore != "lvm" ]; then | 167 | case "$backingstore" in |
231 | 166 | echo "only 'none' and 'lvm' backing stores are known" | 168 | lvm|none|btrfs|_unset) :;; |
232 | 167 | usage | 169 | *) echo "'$backingstore' is not known ('none', 'lvm', 'btrfs')" |
233 | 168 | exit 1 | 170 | usage |
234 | 169 | fi | 171 | exit 1 |
235 | 172 | ;; | ||
236 | 173 | esac | ||
237 | 170 | 174 | ||
238 | 171 | if [ -d "$lxc_path/$lxc_name" ]; then | 175 | if [ -d "$lxc_path/$lxc_name" ]; then |
239 | 172 | echo "'$lxc_name' already exists" | 176 | echo "'$lxc_name' already exists" |
240 | @@ -174,6 +178,21 @@ | |||
241 | 174 | fi | 178 | fi |
242 | 175 | 179 | ||
243 | 176 | rootfs="$lxc_path/$lxc_name/rootfs" | 180 | rootfs="$lxc_path/$lxc_name/rootfs" |
244 | 181 | |||
245 | 182 | if [ "$backingstore" = "_unset" -o "$backingstore" = "btrfs" ]; then | ||
246 | 183 | # if no backing store was given, then see if btrfs would work | ||
247 | 184 | if which btrfs >/dev/null 2>&1 && | ||
248 | 185 | btrfs filesystem df "$lxc_path/" >/dev/null 2>&1; then | ||
249 | 186 | backingstore="btrfs" | ||
250 | 187 | else | ||
251 | 188 | if [ "$backingstore" = "btrfs" ]; then | ||
252 | 189 | echo "missing 'btrfs' command or $lxc_path is not btrfs"; | ||
253 | 190 | exit 1; | ||
254 | 191 | fi | ||
255 | 192 | backingstore="none" | ||
256 | 193 | fi | ||
257 | 194 | fi | ||
258 | 195 | |||
259 | 177 | if [ $backingstore = "lvm" ]; then | 196 | if [ $backingstore = "lvm" ]; then |
260 | 178 | which vgscan > /dev/null | 197 | which vgscan > /dev/null |
261 | 179 | if [ $? -ne 0 ]; then | 198 | if [ $? -ne 0 ]; then |
262 | @@ -201,6 +220,12 @@ | |||
263 | 201 | echo "please delete it (using \"lvremove $rootdev\") and try again" | 220 | echo "please delete it (using \"lvremove $rootdev\") and try again" |
264 | 202 | exit 1 | 221 | exit 1 |
265 | 203 | fi | 222 | fi |
266 | 223 | elif [ "$backingstore" = "btrfs" ]; then | ||
267 | 224 | mkdir "$lxc_path/$lxc_name" | ||
268 | 225 | if ! out=$(btrfs subvolume create "$rootfs" 2>&1); then | ||
269 | 226 | echo "failed to create subvolume in $rootfs: $out"; | ||
270 | 227 | exit 1; | ||
271 | 228 | fi | ||
272 | 204 | fi | 229 | fi |
273 | 205 | 230 | ||
274 | 206 | cleanup() { | 231 | cleanup() { |
275 | @@ -231,7 +256,7 @@ | |||
276 | 231 | cp $lxc_config $lxc_path/$lxc_name/config | 256 | cp $lxc_config $lxc_path/$lxc_name/config |
277 | 232 | 257 | ||
278 | 233 | # Create the fs as needed | 258 | # Create the fs as needed |
280 | 234 | mkdir $rootfs | 259 | [ -d "$rootfs" ] || mkdir "$rootfs" |
281 | 235 | if [ $backingstore = "lvm" ]; then | 260 | if [ $backingstore = "lvm" ]; then |
282 | 236 | lvcreate -L $fssize -n $lvname $vgname || exit 1 | 261 | lvcreate -L $fssize -n $lvname $vgname || exit 1 |
283 | 237 | udevadm settle | 262 | udevadm settle |
284 | 238 | 263 | ||
285 | === modified file 'src/lxc/lxc-destroy.in' | |||
286 | --- src/lxc/lxc-destroy.in 2012-01-20 10:56:32 +0000 | |||
287 | +++ src/lxc/lxc-destroy.in 2012-01-26 16:18:34 +0000 | |||
288 | @@ -105,5 +105,9 @@ | |||
289 | 105 | fi | 105 | fi |
290 | 106 | fi | 106 | fi |
291 | 107 | fi | 107 | fi |
292 | 108 | if out=$(btrfs subvolume list "$lxc_path/$lxc_name/rootfs" 2>&1); then | ||
293 | 109 | out=$(btrfs subvolume delete "$lxc_path/$lxc_name/rootfs" 2>&1) || | ||
294 | 110 | echo "WARN: failed btrfs subvolume delete: $out" | ||
295 | 111 | fi | ||
296 | 108 | # recursively remove the container to remove old container configuration | 112 | # recursively remove the container to remove old container configuration |
297 | 109 | rm -rf --preserve-root $lxc_path/$lxc_name | 113 | rm -rf --preserve-root $lxc_path/$lxc_name |