Merge lp:~csurbhi/partman-btrfs/testing-subvol into lp:~ubuntu-core-dev/partman-btrfs/ubuntu

Proposed by Surbhi Palande
Status: Merged
Merged at revision: 55
Proposed branch: lp:~csurbhi/partman-btrfs/testing-subvol
Merge into: lp:~ubuntu-core-dev/partman-btrfs/ubuntu
Diff against target: 103 lines (+49/-1)
3 files modified
debian/changelog (+7/-0)
fstab.d/btrfs (+24/-1)
mount.d/btrfs (+18/-0)
To merge this branch: bzr merge lp:~csurbhi/partman-btrfs/testing-subvol
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+47975@code.launchpad.net

This proposal supersedes a proposal from 2011-01-28.

Description of the change

Our aim is to be able to do automatic snapshots of home and / separately. Having a separate subvolume for / and another subvolume for /home allows us to take snapshots of these subvolumes independently.

Note that we have two basic scenarios:
1) /home is a separate partition and is mounted on dir home in /
2) /home is not a separate partition and is simply a dir under /

We need to basically achieve the following through the installer:
1) create the subvolume @ for / and @home for /home (just a naming convention discussed)
2) mount @ on / and mount @home on /home
3) prepare fstab such that every time the subvolumes are mounted.

====

Code:
1) fstab.d/btrfs checks if /home is a separate partition or not. If / is btrfs formatted then it adds an entry to mount the subvol=@home on /home even if /home is not a separate partition.
2) In case /home is a separate btrfs partition then it adds an entry to mount the subvolume=@home on /home.
3) Only when both / and /home are not btrfs formatted, then no entry corresponding to @home is added.

mount.d/btrfs gets the mountpoints by reading the fstab.d/btrfs and so it always gets to mount /home in both the cases discussed above.

======

Testing:
1) have tested the code for the following cases:
a) /home:btrfs /:btrfs
b) no separate /home, /:btrfs
c) /home:ext2 /:btrfs
d) /home:btrfs, /:ext2
e) /home:ext2 /:ext2
f) no separate /home, /:ext2

====

Please do let me know what you think of it! Thanks!

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote : Posted in a previous version of this proposal
Download full text (4.0 KiB)

Could you propose this for merging into
lp:~ubuntu-core-dev/partman-btrfs/ubuntu instead, rather than the
upstream lp:partman-btrfs? That way I won't see the changes from
5ubuntu1 in the review diff.

On Fri, Jan 28, 2011 at 02:14:14PM -0000, Surbhi Palande wrote:
> Code:
> 1) fstab.d/btrfs checks if /home is a separate partition or not. If / is btrfs formatted then it adds an entry to mount the subvol=@home on /home even if /home is not a separate partition.
> 2) In case /home is a separate btrfs partition then it adds an entry to mount the subvolume=@home on /home.
> 3) Only when both / and /home are not btrfs formatted, then no entry corresponding to @home is added.

Your general approach looks fine to me.

> if [ "$mountpoint" = / ]; then
> + if [ $home_found = unknown ]; then

In shell, a good rule of thumb is to always put "" around any word
containing $ unless there's a specific reason not to. It doesn't matter
in practice here because the value of home_found is always a single
word, but it would be good style to use "$home_found" instead (and
similar for other $-expansions in your branch). I know this guideline
isn't followed universally in the installer, but I'd like to see at
least new code following it.

(Good reason not to put "" around a word containing $ are when you
explicitly want word splitting to be performed, or in the first argument
to 'case' which is never word-split so doesn't require quoting.)

More generally, I think there may be an ordering problem here. You're
iterating in disk/partition order, so this will go wrong if it happens
that the /home partition is on an earlier disk or partition than /.
This probably won't be the common case but we should still deal with it.

I suggest that you should make this file have two loops, both with
roughly the same form (don't worry about optimising away multiple calls
to 'open_dialog PARTITIONS' etc. - this code is run a few times, but it
isn't particularly time-critical). The first should just check whether
there's a partition with mountpoint=/home. The second should be more or
less what was there before your change, but with the extra changes to
options and home_options. That way, it will work whichever way round
the partitions happen to be.

> - mount -t btrfs ${options:+-o "$options"} $fs /target$mp || exit 1
> + options=${options%,subvol=*}
> + options=${options:+"-o $options"}

I'd find it clearer to put the quotes around the whole $-expansion here
(and similarly below), i.e.:

  options="${options:+-o $options}"

This means you don't have to wonder whether it's quoted that way because
the "" are supposed to end up in the value of options.

> + mkdir -p /target$mp

You can skip this - mount.d scripts are called from
partman-target/finish.d/mount_partitions, which always creates the
directory first.

> + mount -t btrfs $options $fs /target$mp || exit 1
> + case $mp in
> + /)
> + btrfs subvolume create /target$mp/@
> + umount /target$mp
> + options=${options:+"$options,subvol=@"}
> + options=${options:="-o subvol=@"}

Using := here is odd. "${options:=-o subvol=@}" assigns to options, and
then you assign the result of that to options again ...

The repe...

Read more...

Revision history for this message
Surbhi Palande (csurbhi) wrote :

Hi Colin,
Thanks for the review. I have made the following changes:
1) Added "" around the $variables where ever necessary in both the files (mount.d/btrfs and fstab.d/btrfs)
2) removed the unnecessary mkdir -p /target$mp from mount.d/btrfs
3) removed the options=${options:="something"} statements.

I have not changed the logic as it seems that the partitioning order shall be taken care of by the existing code.
===

Tested the code for /home:btrfs and /:btrfs.

Please do let me know if the patch looks better now. Thanks!

55. By Surbhi Palande

Adding support for creating and respectively mounting btrfs subvolumes
corresponding to / and /home, in case of a btrfs rootfs.

Revision history for this message
Surbhi Palande (csurbhi) wrote :

Following change added:
Need to remove the subvol=@ before creating the subvolume from the mount options. This removal could be when options="defaults,subvol=@" or options="subvol=@". Added a clause to remove the "subvol=@" when no comma is present. (Comments added in the changed code)

Revision history for this message
Colin Watson (cjwatson) wrote :

Looks fine now, so I'm merging this. Thanks!

 review approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2011-01-07 15:59:48 +0000
3+++ debian/changelog 2011-01-31 15:02:11 +0000
4@@ -1,3 +1,10 @@
5+partman-btrfs (5ubuntu2) natty; urgency=low
6+
7+ * Adding support for creating and respectively mounting btrfs subvolumes
8+ corresponding to / and /home, in case of a btrfs rootfs.
9+
10+ -- Surbhi Palande <surbhi.palande@canonical.com> Fri, 28 Jan 2011 15:35:18 +0200
11+
12 partman-btrfs (5ubuntu1) natty; urgency=low
13
14 * Allow btrfs /boot on amd64/i386, now that grub2 supports it.
15
16=== modified file 'fstab.d/btrfs'
17--- fstab.d/btrfs 2010-06-18 10:21:24 +0000
18+++ fstab.d/btrfs 2011-01-31 15:02:11 +0000
19@@ -2,6 +2,8 @@
20
21 . /lib/partman/lib/base.sh
22
23+home_found="unknown"
24+
25 for dev in $DEVICES/*; do
26 [ -d $dev ] || continue
27 cd $dev
28@@ -12,23 +14,44 @@
29 [ -f "$id/acting_filesystem" ] || continue
30 method=$(cat $id/method)
31 filesystem=$(cat $id/acting_filesystem)
32+ mountpoint=$(cat $id/mountpoint)
33 case "$filesystem" in
34 btrfs)
35 [ -f "$id/mountpoint" ] || continue
36- mountpoint=$(cat $id/mountpoint)
37 # due to #249322, #255135, #258117:
38 if [ "$mountpoint" = /tmp ]; then
39 rm -f $id/options/noexec
40 fi
41 options=$(get_mountoptions $dev $id)
42 if [ "$mountpoint" = / ]; then
43+ if [ "$home_found" = "unknown" ]; then
44+ home_found="false"
45+ fi
46 pass=1
47+ home_options="${options:+$options,}subvol=@home"
48+ options="${options:+$options,}subvol=@"
49+ home_path="$path"
50+ home_mp="$mountpoint"home
51+ elif [ "$mountpoint" = /home ]; then
52+ pass=2
53+ options="${options:+$options,}subvol=@home"
54+ home_found=true
55 else
56 pass=2
57 fi
58 echo "$path" "$mountpoint" btrfs $options 0 $pass
59 ;;
60+ *)
61+ if [ "$mountpoint" = "/home" ]; then
62+ home_found="true"
63+ fi
64+ ;;
65 esac
66 done
67 close_dialog
68 done
69+
70+if [ "$home_found" = "false" ]; then
71+ echo "$home_path" "$home_mp" btrfs "$home_options" 0 2
72+ home_found="true"
73+fi
74
75=== modified file 'mount.d/btrfs'
76--- mount.d/btrfs 2010-01-27 20:14:29 +0000
77+++ mount.d/btrfs 2011-01-31 15:02:11 +0000
78@@ -11,7 +11,25 @@
79
80 case $type in
81 btrfs)
82+ options="${options%,subvol=*}"
83+ #for removing the option subvol,when thats the only option
84+ #eg: options=="subvol=@", no comma present
85+ options="${options%subvol=*}"
86 mount -t btrfs ${options:+-o "$options"} $fs /target$mp || exit 1
87+ case $mp in
88+ /)
89+ btrfs subvolume create /target$mp/@
90+ umount /target$mp
91+ options="${options:+$options,}subvol=@"
92+ mount -t btrfs -o $options $fs /target$mp
93+ ;;
94+ /home)
95+ btrfs subvolume create /target$mp/@home
96+ umount /target$mp
97+ options="${options:+$options,}subvol=@home"
98+ mount -t btrfs -o $options $fs /target$mp
99+ ;;
100+ esac
101 echo "umount /target$mp"
102 exit 0
103 ;;

Subscribers

People subscribed via source and target branches