Merge lp:~csurbhi/ubuntu/natty/os-prober/os-prober.fix764893 into lp:ubuntu/natty/os-prober

Proposed by Surbhi Palande
Status: Needs review
Proposed branch: lp:~csurbhi/ubuntu/natty/os-prober/os-prober.fix764893
Merge into: lp:ubuntu/natty/os-prober
Diff against target: 123 lines (+80/-0)
3 files modified
debian/changelog (+7/-0)
linux-boot-probes/common/50mounted-tests (+37/-0)
os-probes/common/50mounted-tests (+36/-0)
To merge this branch: bzr merge lp:~csurbhi/ubuntu/natty/os-prober/os-prober.fix764893
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+58654@code.launchpad.net

Description of the change

Hi,

This patch adds support to mount the "@" subvolume to access a btrfs formatted rootfs. It checks if "@" is present and if so, then unmounts the partition before trying to mount the subvolume. Releases previous to Natty and other OS distros may not have the "/" on the "@" subvolume.

Tested lightly on kvm with Natty-btrfs rootfs.

Please do consider this as a *SRU* for Natty.

Thanks,
Surbhi.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

> mounted=1
> + debug "mounted as $type filesystem"

The indentation is in general wrong here - make sure to check whether
the code you're patching is using tabs or spaces for indentation, and
match it.

> + if [ $type="btrfs" ] && [ -x "$tmpmnt/@" ]; then

The first test is wrong shell syntax. This must be [ "$type" = btrfs ]
instead.

Furthermore, this won't work when we're using grub-mount, which we
generally will be nowadays; and remounting with 'mount -o ro,subvol=@ -t
btrfs' will bring us back to the bad old days before grub-mount, when we
had to choose between either corrupting hibernated filesystems or
failing to mount journalled filesystems that weren't cleanly unmounted.

I suggest instead that we check whether $type is either btrfs or fuse
(using 'case') and whether $tmpmnt/@/lib exists (this should be
reasonably safe since btrfs is only used on Linux); in that case,
bind-mount $tmpmnt/@ on $tmpmnt and remember to umount it twice at the
end. (Alternatively, we could arrange for everything to read from
$tmpmnt/@ without a bind-mount, but I think that would be rather more
code churn.)

> + warn "failed to mount" \
> + "@ ($partition)"

Try to make the warnings a bit more descriptive; most people will have
no idea what our subvolume scheme involves. They should still be
one-line warnings or thereabouts, not essays, but for example
consistently referring to "btrfs subvolume @ on $partition" would be an
improvement.

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

Hi Colin,

Thanks a lot for the insightful review. Did not know about the fs-corruption issue before. The reading of the $tmpmnt/@ indeed is a lot more code than mount-bind (or remount) and I decided against it just for the same reason before.

I have uploaded the changes after testing them on kvm. Please do let me know if they look good now.

Regards,
Surbhi.

18. By Surbhi Palande

mount btrfs subvolume @ when present to access a btrfs formatted rootfs.
(LP: #764893)

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

This looks fine now - thanks, and sorry for the delay! I'm merging this (although rebased against lp:os-prober), and adjusting for some minor style nits.

review: Approve

Unmerged revisions

18. By Surbhi Palande

mount btrfs subvolume @ when present to access a btrfs formatted rootfs.
(LP: #764893)

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-04-10 00:36:21 +0000
3+++ debian/changelog 2011-04-21 15:53:23 +0000
4@@ -1,3 +1,10 @@
5+os-prober (1.44ubuntu2) natty; urgency=low
6+
7+ * mount btrfs subvolume @ when present to access a btrfs formatted rootfs.
8+ (LP: #764893)
9+
10+ -- Surbhi Palande <surbhi.palande@canonical.com> Thu, 21 Apr 2011 17:44:10 +0300
11+
12 os-prober (1.44ubuntu1) natty; urgency=low
13
14 * Cherry-pick from trunk:
15
16=== modified file 'linux-boot-probes/common/50mounted-tests'
17--- linux-boot-probes/common/50mounted-tests 2011-04-10 00:36:21 +0000
18+++ linux-boot-probes/common/50mounted-tests 2011-04-21 15:53:23 +0000
19@@ -43,6 +43,26 @@
20 for type in $types; do
21 if mount -o ro -t "$type" "$partition" "$tmpmnt" 2>/dev/null; then
22 mounted=1
23+ case "$type" in
24+ btrfs|fuse)
25+ if [ -x "$tmpmnt/@/lib" ]; then
26+ if ! mount --bind "$tmpmnt/@" \
27+ "$tmpmnt";
28+ then
29+ warn "failed to bind mount" \
30+ "the subvolume:@ on $partition"
31+ if ! umount $tmpmnt
32+ then
33+ warn "failed to" \
34+ "unmount $tmpmnt"
35+ fi
36+ mounted=
37+ fi
38+ fi
39+ ;;
40+ *)
41+ ;;
42+ esac
43 break
44 fi
45 done
46@@ -62,6 +82,23 @@
47 if ! umount "$tmpmnt"; then
48 warn "failed to umount $tmpmnt"
49 fi
50+ case $type in
51+ btrfs|fuse)
52+ if [ -x "$tmpmnt/@/lib" ]
53+ then
54+ # umount to account
55+ # for the mount-bind
56+ if ! umount $tmpmnt
57+ then
58+ warn "failed to "\
59+ "umount $tmpmnt"
60+ fi
61+ fi
62+ ;;
63+ *)
64+ ;;
65+ esac
66+
67 rmdir "$tmpmnt" || true
68 exit 0
69 fi
70
71=== modified file 'os-probes/common/50mounted-tests'
72--- os-probes/common/50mounted-tests 2011-04-10 00:36:21 +0000
73+++ os-probes/common/50mounted-tests 2011-04-21 15:53:23 +0000
74@@ -57,6 +57,26 @@
75 if mount -o ro -t "$type" "$partition" "$tmpmnt" 2>/dev/null; then
76 debug "mounted as $type filesystem"
77 mounted=1
78+ case "$type" in
79+ btrfs|fuse)
80+ if [ -x "$tmpmnt/@/lib" ]; then
81+ if ! mount --bind "$tmpmnt/@" \
82+ "$tmpmnt"
83+ then
84+ warn "failed to bind mount" \
85+ "the subvolume:@ on $partition"
86+ if ! umount $tmpmnt
87+ then
88+ warn "failed to" \
89+ "unmount $tmpmnt"
90+ fi
91+ mounted=
92+ fi
93+ fi
94+ ;;
95+ *)
96+ ;;
97+ esac
98 break
99 fi
100 done
101@@ -71,6 +91,22 @@
102 if ! umount "$tmpmnt"; then
103 warn "failed to umount $tmpmnt"
104 fi
105+ case "$type" in
106+ btrfs|fuse)
107+ if [ -x "$tmpmnt/@/lib" ]
108+ then
109+ # umount to account
110+ # for the mount-bind
111+ if ! umount $tmpmnt
112+ then
113+ warn "failed to "\
114+ "umount $tmpmnt"
115+ fi
116+ fi
117+ ;;
118+ *)
119+ ;;
120+ esac
121 rmdir "$tmpmnt" || true
122 exit 0
123 fi

Subscribers

People subscribed via source and target branches