Skip to contentSkip to conversation

btrfs-probe branch

PATCH Colin Watson 1 participant 3 messages May 18, 2010

lore
Share & tools
lore
#0 lore raw

I've pushed sftp://bzr.sv.gnu.org/srv/bzr/grub/branches/btrfs-probe/ (world-readable: 'bzr get
http://bzr.savannah.gnu.org/r/grub/branches/btrfs-probe/') to handle probing single-device btrfs filesystems. I'm not going to pretend that this is anything other than a hack, but it is reasonably well isolated and it should be enough to handle the simple case where somebody has a btrfs root filesystem and an ext[234] /boot.

Background and justification: since btrfs supports multiple-device mounts, it always returns a virtual device (major number 0) in st_dev. This means that grub-probe can't find the appropriate device node for a given filesystem path just by statting the directory path and walking /dev. Instead, for the moment, I've taken the approach of looking through /proc/self/mountinfo. Note that this is pretty much exactly what the now-widely-used udisks package does (src/mount-monitor.c), and that's where I got the idea, although I implemented it independently to avoid copyright assignment questions.

(Vladimir cited a rumour to the effect that libblkid may be able to handle this, but I haven't been able to find any evidence of it knowing how to deal with mount points at all. We can always revisit this later.)

This only deals with the single-device case for now. Dealing with the multiple-device case would (I think) require interface changes to grub-probe, and I haven't thought about that much yet.

I've done basic testing, but would appreciate testing from others as well. For those who don't want to bother checking it out from revision control, the patch follows. It's against trunk, but should apply with only a little bit of fuzz to 1.98; just note that in that case you'll need to apply the patch for kern/emu/hostdisk.c to util/hostdisk.c instead.

=== added file 'ChangeLog.btrfs-probe'

ChangeLog.btrfs-probe +8 -0
@@ -0,0 +1,8 @@
+2010-05-18  Colin Watson  <[email protected]>
+
+	Add btrfs probing support, currently only in the single-device case.
+
+	* kern/emu/getroot.c (find_root_device_from_mountinfo): New
+	function.
+	(grub_guess_root_device): Call find_root_device_from_mountinfo
+	before looking in /dev.

=== modified file 'kern/emu/getroot.c'

emu/getroot.c +84 -0

96 lines not on this page · raw message

Signature · 1 line
Colin Watson                                       [[email protected]]
#1 lore raw
Quoted 6 lines · Colin Watson

I've done basic testing, but would appreciate testing from others as well. For those who don't want to bother checking it out from revision control, the patch follows. It's against trunk, but should apply with only a little bit of fuzz to 1.98; just note that in that case you'll need to apply the patch for kern/emu/hostdisk.c to util/hostdisk.c instead.

Err, just checking whether you were paying attention ... obviously I meant "you'll need to apply the patch for kern/emu/getroot.c to util/getroot.c instead".

Signature · 1 line
Colin Watson                                       [[email protected]]
#2 lore raw
In reply to Colin Watson
Quoted 4 lines · Colin Watson

(Vladimir cited a rumour to the effect that libblkid may be able to handle this, but I haven't been able to find any evidence of it knowing how to deal with mount points at all. We can always revisit this later.)

Scott James Remnant chased this up. 'blkid -o list' shows mount points, but this is implemented in the blkid command-line tool rather than in the libblkid library. I don't think it would be significantly easier for grub-probe to parse the output of a command-line tool than for it to just parse /proc/self/mountinfo, and it certainly wouldn't be any quicker, so I suggest staying with the approach in my branch until some appropriate feature is available in libblkid or another common library.

Signature · 1 line
Colin Watson                                       [[email protected]]