Merge lp:~smoser/ubuntu/precise/lxc/btrfs-clone-support into lp:ubuntu/precise/lxc

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
Reviewer Review Type Date Requested Status
Ubuntu branches Pending
Review via email: mp+90236@code.launchpad.net

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

Subscribers

People subscribed via source and target branches

to all changes: