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
=== modified file '.pc/applied-patches'
--- .pc/applied-patches 2012-01-25 14:22:51 +0000
+++ .pc/applied-patches 2012-01-26 16:18:34 +0000
@@ -39,3 +39,4 @@
390026-support-new-reboot.patch390026-support-new-reboot.patch
400027-fix-lxc-netstat.patch400027-fix-lxc-netstat.patch
410028-recursively-rmdir-cgroups.patch410028-recursively-rmdir-cgroups.patch
420029-btrfs-clone-support.patch
4243
=== modified file 'debian/changelog'
--- debian/changelog 2012-01-25 14:22:51 +0000
+++ debian/changelog 2012-01-26 16:18:34 +0000
@@ -1,3 +1,10 @@
1lxc (0.7.5-3ubuntu13) precise; urgency=low
2
3 * 0029-btrfs-clone-support.patch: add support for cloning via
4 btrfs snapshots (LP: #921921).
5
6 -- Scott Moser <smoser@ubuntu.com> Thu, 26 Jan 2012 09:14:49 -0500
7
1lxc (0.7.5-3ubuntu12) precise; urgency=low8lxc (0.7.5-3ubuntu12) precise; urgency=low
29
3 * If the kernel supports container reboot disambuation, then don't drop10 * If the kernel supports container reboot disambuation, then don't drop
411
=== added file 'debian/patches/0029-btrfs-clone-support.patch'
--- debian/patches/0029-btrfs-clone-support.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0029-btrfs-clone-support.patch 2012-01-26 16:18:34 +0000
@@ -0,0 +1,132 @@
1Description: add btrfs cloning support
2 This patch adds support for btrfs filesystem clone support via the 'btrfs'
3 command. if a container has been created with '-B btrfs', then lxc-clone
4 will automatically use it. Ie, there is no need to specify '-s' or other
5 arguments to lxc-clone.
6 .
7 This patch should probably be forwarded after some testing.
8Author: Scott Moser <smoser@ubuntu.com>
9Forwarded: no
10Bug: https://bugs.launchpad.net/bugs/921921
11--- a/src/lxc/lxc-clone.in
12+++ b/src/lxc/lxc-clone.in
13@@ -40,8 +40,8 @@ help() {
14
15 shortoptions='ho:n:sL:v:'
16 longoptions='help,orig:,name:,snapshot,fssize,vgname'
17-lxc_path=@LXCPATH@
18-bindir=@BINDIR@
19+lxc_path=/var/lib/lxc
20+bindir=/usr/bin
21 snapshot=no
22 lxc_size=2G
23 lxc_vg=lxc
24@@ -197,6 +197,13 @@ if [ -b $oldroot ]; then
25 mkdir -p $lxc_path/$lxc_new/rootfs
26 mount /dev/$lxc_vg/$lxc_new $rootfs || { echo "failed to mount new rootfs"; cleanup; }
27 mounted=1
28+elif out=$(btrfs subvolume list "$lxc_path/$lxc_orig/rootfs" 2>&1); then
29+ out=$(btrfs subvolume snapshot "$lxc_path/$lxc_orig/rootfs" "$rootfs" 2>&1)
30+ if [ $? -ne 0 ]; then
31+ echo "failed btrfs subvolume snapshot of $lxc_path/$lxc_orig/rootfs"
32+ cleanup
33+ fi
34+ echo "lxc.rootfs = $rootfs" >> "$lxc_path/$lxc_new/config"
35 else
36 cp -a $lxc_path/$lxc_orig/rootfs $lxc_path/$lxc_new/rootfs || cleanup
37 echo "lxc.rootfs = $rootfs" >> $lxc_path/$lxc_new/config
38--- a/src/lxc/lxc-create.in
39+++ b/src/lxc/lxc-create.in
40@@ -25,6 +25,8 @@ usage() {
41 echo "usage: lxc-create -n <name> [-f configuration] [-t template] [-h] [fsopts] -- [template_options]"
42 echo " fsopts: -B none"
43 echo " fsopts: -B lvm [--lvname lvname] [--vgname vgname] [--fstype fstype] [--fssize fssize]"
44+ echo " fsopts: -B btrfs"
45+ echo " flag is not necessary, if possible btrfs support will be used"
46 # echo " fsopts: -B union [--uniontype overlayfs]"
47 # echo " fsopts: -B loop [--fstype fstype] [--fssize fssize]"
48 # echo " fsopts: -B qemu-nbd [--type qed|qcow2|raw] [--fstype fstype] [--fssize fssize] # Qemu qed disk format"
49@@ -67,7 +69,7 @@ longoptions='help,name:,config:,template
50 lxc_path=@LXCPATH@
51 bindir=@BINDIR@
52 templatedir=@LXCTEMPLATEDIR@
53-backingstore=none
54+backingstore=_unset
55 fstype=ext4
56 fssize=500M
57 vgname=lxc
58@@ -162,11 +164,13 @@ if [ "$(id -u)" != "0" ]; then
59 exit 1
60 fi
61
62-if [ $backingstore != "none" -a $backingstore != "lvm" ]; then
63- echo "only 'none' and 'lvm' backing stores are known"
64- usage
65- exit 1
66-fi
67+case "$backingstore" in
68+ lvm|none|btrfs|_unset) :;;
69+ *) echo "'$backingstore' is not known ('none', 'lvm', 'btrfs')"
70+ usage
71+ exit 1
72+ ;;
73+esac
74
75 if [ -d "$lxc_path/$lxc_name" ]; then
76 echo "'$lxc_name' already exists"
77@@ -174,6 +178,21 @@ if [ -d "$lxc_path/$lxc_name" ]; then
78 fi
79
80 rootfs="$lxc_path/$lxc_name/rootfs"
81+
82+if [ "$backingstore" = "_unset" -o "$backingstore" = "btrfs" ]; then
83+ # if no backing store was given, then see if btrfs would work
84+ if which btrfs >/dev/null 2>&1 &&
85+ btrfs filesystem df "$lxc_path/" >/dev/null 2>&1; then
86+ backingstore="btrfs"
87+ else
88+ if [ "$backingstore" = "btrfs" ]; then
89+ echo "missing 'btrfs' command or $lxc_path is not btrfs";
90+ exit 1;
91+ fi
92+ backingstore="none"
93+ fi
94+fi
95+
96 if [ $backingstore = "lvm" ]; then
97 which vgscan > /dev/null
98 if [ $? -ne 0 ]; then
99@@ -201,6 +220,12 @@ if [ $backingstore = "lvm" ]; then
100 echo "please delete it (using \"lvremove $rootdev\") and try again"
101 exit 1
102 fi
103+elif [ "$backingstore" = "btrfs" ]; then
104+ mkdir "$lxc_path/$lxc_name"
105+ if ! out=$(btrfs subvolume create "$rootfs" 2>&1); then
106+ echo "failed to create subvolume in $rootfs: $out";
107+ exit 1;
108+ fi
109 fi
110
111 cleanup() {
112@@ -231,7 +256,7 @@ fi
113 cp $lxc_config $lxc_path/$lxc_name/config
114
115 # Create the fs as needed
116-mkdir $rootfs
117+[ -d "$rootfs" ] || mkdir "$rootfs"
118 if [ $backingstore = "lvm" ]; then
119 lvcreate -L $fssize -n $lvname $vgname || exit 1
120 udevadm settle
121--- a/src/lxc/lxc-destroy.in
122+++ b/src/lxc/lxc-destroy.in
123@@ -105,5 +105,9 @@ if [ ! -z "$rootdev" ]; then
124 fi
125 fi
126 fi
127+if out=$(btrfs subvolume list "$lxc_path/$lxc_name/rootfs" 2>&1); then
128+ out=$(btrfs subvolume delete "$lxc_path/$lxc_name/rootfs" 2>&1) ||
129+ echo "WARN: failed btrfs subvolume delete: $out"
130+fi
131 # recursively remove the container to remove old container configuration
132 rm -rf --preserve-root $lxc_path/$lxc_name
0133
=== modified file 'debian/patches/series'
--- debian/patches/series 2012-01-25 14:22:51 +0000
+++ debian/patches/series 2012-01-26 16:18:34 +0000
@@ -39,3 +39,4 @@
390026-support-new-reboot.patch390026-support-new-reboot.patch
400027-fix-lxc-netstat.patch400027-fix-lxc-netstat.patch
410028-recursively-rmdir-cgroups.patch410028-recursively-rmdir-cgroups.patch
420029-btrfs-clone-support.patch
4243
=== modified file 'src/lxc/lxc-clone.in'
--- src/lxc/lxc-clone.in 2012-01-20 14:34:54 +0000
+++ src/lxc/lxc-clone.in 2012-01-26 16:18:34 +0000
@@ -40,8 +40,8 @@
4040
41shortoptions='ho:n:sL:v:'41shortoptions='ho:n:sL:v:'
42longoptions='help,orig:,name:,snapshot,fssize,vgname'42longoptions='help,orig:,name:,snapshot,fssize,vgname'
43lxc_path=@LXCPATH@43lxc_path=/var/lib/lxc
44bindir=@BINDIR@44bindir=/usr/bin
45snapshot=no45snapshot=no
46lxc_size=2G46lxc_size=2G
47lxc_vg=lxc47lxc_vg=lxc
@@ -197,6 +197,13 @@
197 mkdir -p $lxc_path/$lxc_new/rootfs197 mkdir -p $lxc_path/$lxc_new/rootfs
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; }
199 mounted=1199 mounted=1
200elif out=$(btrfs subvolume list "$lxc_path/$lxc_orig/rootfs" 2>&1); then
201 out=$(btrfs subvolume snapshot "$lxc_path/$lxc_orig/rootfs" "$rootfs" 2>&1)
202 if [ $? -ne 0 ]; then
203 echo "failed btrfs subvolume snapshot of $lxc_path/$lxc_orig/rootfs"
204 cleanup
205 fi
206 echo "lxc.rootfs = $rootfs" >> "$lxc_path/$lxc_new/config"
200else207else
201 cp -a $lxc_path/$lxc_orig/rootfs $lxc_path/$lxc_new/rootfs || cleanup208 cp -a $lxc_path/$lxc_orig/rootfs $lxc_path/$lxc_new/rootfs || cleanup
202 echo "lxc.rootfs = $rootfs" >> $lxc_path/$lxc_new/config209 echo "lxc.rootfs = $rootfs" >> $lxc_path/$lxc_new/config
203210
=== modified file 'src/lxc/lxc-create.in'
--- src/lxc/lxc-create.in 2012-01-23 17:24:53 +0000
+++ src/lxc/lxc-create.in 2012-01-26 16:18:34 +0000
@@ -25,6 +25,8 @@
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]"
26 echo " fsopts: -B none"26 echo " fsopts: -B none"
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]"
28 echo " fsopts: -B btrfs"
29 echo " flag is not necessary, if possible btrfs support will be used"
28# echo " fsopts: -B union [--uniontype overlayfs]"30# echo " fsopts: -B union [--uniontype overlayfs]"
29# echo " fsopts: -B loop [--fstype fstype] [--fssize fssize]"31# echo " fsopts: -B loop [--fstype fstype] [--fssize fssize]"
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"
@@ -67,7 +69,7 @@
67lxc_path=@LXCPATH@69lxc_path=@LXCPATH@
68bindir=@BINDIR@70bindir=@BINDIR@
69templatedir=@LXCTEMPLATEDIR@71templatedir=@LXCTEMPLATEDIR@
70backingstore=none72backingstore=_unset
71fstype=ext473fstype=ext4
72fssize=500M74fssize=500M
73vgname=lxc75vgname=lxc
@@ -162,11 +164,13 @@
162 exit 1164 exit 1
163fi165fi
164166
165if [ $backingstore != "none" -a $backingstore != "lvm" ]; then167case "$backingstore" in
166 echo "only 'none' and 'lvm' backing stores are known"168 lvm|none|btrfs|_unset) :;;
167 usage169 *) echo "'$backingstore' is not known ('none', 'lvm', 'btrfs')"
168 exit 1170 usage
169fi171 exit 1
172 ;;
173esac
170174
171if [ -d "$lxc_path/$lxc_name" ]; then175if [ -d "$lxc_path/$lxc_name" ]; then
172 echo "'$lxc_name' already exists"176 echo "'$lxc_name' already exists"
@@ -174,6 +178,21 @@
174fi178fi
175179
176rootfs="$lxc_path/$lxc_name/rootfs"180rootfs="$lxc_path/$lxc_name/rootfs"
181
182if [ "$backingstore" = "_unset" -o "$backingstore" = "btrfs" ]; then
183 # if no backing store was given, then see if btrfs would work
184 if which btrfs >/dev/null 2>&1 &&
185 btrfs filesystem df "$lxc_path/" >/dev/null 2>&1; then
186 backingstore="btrfs"
187 else
188 if [ "$backingstore" = "btrfs" ]; then
189 echo "missing 'btrfs' command or $lxc_path is not btrfs";
190 exit 1;
191 fi
192 backingstore="none"
193 fi
194fi
195
177if [ $backingstore = "lvm" ]; then196if [ $backingstore = "lvm" ]; then
178 which vgscan > /dev/null197 which vgscan > /dev/null
179 if [ $? -ne 0 ]; then198 if [ $? -ne 0 ]; then
@@ -201,6 +220,12 @@
201 echo "please delete it (using \"lvremove $rootdev\") and try again"220 echo "please delete it (using \"lvremove $rootdev\") and try again"
202 exit 1221 exit 1
203 fi222 fi
223elif [ "$backingstore" = "btrfs" ]; then
224 mkdir "$lxc_path/$lxc_name"
225 if ! out=$(btrfs subvolume create "$rootfs" 2>&1); then
226 echo "failed to create subvolume in $rootfs: $out";
227 exit 1;
228 fi
204fi229fi
205230
206cleanup() {231cleanup() {
@@ -231,7 +256,7 @@
231cp $lxc_config $lxc_path/$lxc_name/config256cp $lxc_config $lxc_path/$lxc_name/config
232257
233# Create the fs as needed258# Create the fs as needed
234mkdir $rootfs259[ -d "$rootfs" ] || mkdir "$rootfs"
235if [ $backingstore = "lvm" ]; then260if [ $backingstore = "lvm" ]; then
236 lvcreate -L $fssize -n $lvname $vgname || exit 1261 lvcreate -L $fssize -n $lvname $vgname || exit 1
237 udevadm settle262 udevadm settle
238263
=== modified file 'src/lxc/lxc-destroy.in'
--- src/lxc/lxc-destroy.in 2012-01-20 10:56:32 +0000
+++ src/lxc/lxc-destroy.in 2012-01-26 16:18:34 +0000
@@ -105,5 +105,9 @@
105 fi105 fi
106 fi106 fi
107fi107fi
108if out=$(btrfs subvolume list "$lxc_path/$lxc_name/rootfs" 2>&1); then
109 out=$(btrfs subvolume delete "$lxc_path/$lxc_name/rootfs" 2>&1) ||
110 echo "WARN: failed btrfs subvolume delete: $out"
111fi
108# recursively remove the container to remove old container configuration112# recursively remove the container to remove old container configuration
109rm -rf --preserve-root $lxc_path/$lxc_name113rm -rf --preserve-root $lxc_path/$lxc_name

Subscribers

People subscribed via source and target branches

to all changes: