From: Axel Burri <axel@tty0.ch>
To: Linux fs Btrfs <linux-btrfs@vger.kernel.org>
Subject: Re: finding root filesystem of a subvolume?
Date: Wed, 23 Aug 2017 15:14:04 +0200 [thread overview]
Message-ID: <391cbefd-80e1-fc3c-d743-c15e6a5e20e4@tty0.ch> (raw)
In-Reply-To: <3026f8a6-0ea6-0ed2-41c7-7d25c51a32fe@gmail.com>
On 2017-08-23 14:07, Austin S. Hemmelgarn wrote:
> On 2017-08-22 13:41, Peter Grandi wrote:
> [ ... ]
>> This stupid point relies on ignoring that it is not mandatory to
>> mount the main volume, and that therefore "There is no fixed
>> relationship between the root directory inode of a subvolume and
>> the root directory inode of any other subvolume or the main
>> volume", because the "root directory inode" of the "main volume"
>> may not be mounted at all.
>>
>> This stupid point also relies on ignoring that subvolumes can be
>> mounted *also* under another directory, even if the main volume
>> is mounted somewhere else. Suppose that the following applies:
>>
>> subvol=5 /local
>> subvol=383 /local/.backup/home
>> subvol=383 /mnt/home-backup
>>
>> and you are given the mountpoint '/mnt/home-backup', how can you
>> find the main volume mountpoint '/local' from that?Assuming
>> /mnt/home-backup is mounted and visible in /proc/mounts (your
> explanation requires it was either mounted directly via a subvol option
> or indirectly via a bind mount), then the following generic method works
> (and should always work on a modern kernel):
> 1. Find it in /proc/mounts or the output of `mount` run without any
> arguments.
> 2. If the mount type is 'bind', the device field will point to the
> source directory. Using any method you like, figure out what the actual
> mount point that is under is, and repeat from step one with that mount
> point.
> 3. If the mount type is 'btrfs', and 'subvolid=5' is present in the
> mount options (this gets added automatically on any recent kernel), you
> just found the top level subvolume.
> 4. If the mount type is 'btrfs', and 'subvolid=5' is not present in the
> mount options, scan /proc/mounts for other entries with the same device
> value (this is going to be consistent).
> 5. If another entry does exist, and has 'subvolid=5' in the mount
> options, that's the top level subvolume.
> 6. If other entries exist, but 'subvolid=5' not in the mount options for
> any of them, or no other entries exist, the top level volume isn't
> mounted, and you can view it by mounting the device with 'subvolid=5'.
>
> In the event that you need to know where the next higher level subvolume
> is mounted instead of the root subvolume for the volume, you can use the
> same method, but add the following after step two to figure out what
> subvolid to look for:
> 2b. Run `btrfs subvol show` on the mount point (it by definition has to
> be a subvolume because it's mounted and it's not a bind mount in
> userspace). Find the 'Top level ID' (note that this just points to the
> next higher subvolume, not the root subvolume) value in the output, and
> use that instead of 5 when looking for 'subvolid=' options.
In order to have a complete view of all mounts, this is what btrbk does
here (which basically matches Austins explanation):
1. Buld a complete tree from:
# btrfs subvolume list -a -u /mnt/home-backup
2. Correlate all subvolume ID's with mount points (second column) and
"subvolid=" from mount options:
# cat /proc/self/mounts
Now you have a complete view of all mounts. In order to query a given
subvolume, fetch "Subvolume ID" (or "UUID") from:
# btrfs subvolume show /local/.backup/home
see: https://github.com/digint/btrbk/blob/v0.25.1/btrbk
(I apologize that Github has broken display of perl source files at the
time being...)
prev parent reply other threads:[~2017-08-23 13:19 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-22 12:23 finding root filesystem of a subvolume? Ulli Horlacher
2017-08-22 12:40 ` Hugo Mills
2017-08-22 12:50 ` Ulli Horlacher
2017-08-22 12:58 ` Marat Khalili
2017-08-22 13:12 ` Ulli Horlacher
2017-08-22 13:41 ` Marat Khalili
2017-08-22 13:27 ` Austin S. Hemmelgarn
2017-08-22 13:30 ` Ulli Horlacher
2017-08-22 13:37 ` Austin S. Hemmelgarn
2017-08-22 13:45 ` Marat Khalili
2017-08-22 13:53 ` Ulli Horlacher
2017-08-22 14:12 ` Austin S. Hemmelgarn
2017-08-22 14:23 ` Hugo Mills
2017-08-22 14:37 ` Austin S. Hemmelgarn
2017-08-22 14:43 ` Peter Grandi
2017-08-22 15:03 ` Austin S. Hemmelgarn
2017-08-22 15:45 ` Ulli Horlacher
2017-08-22 16:48 ` Roman Mamedov
2017-08-22 17:41 ` Peter Grandi
2017-08-23 12:07 ` Austin S. Hemmelgarn
2017-08-23 13:14 ` Axel Burri [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=391cbefd-80e1-fc3c-d743-c15e6a5e20e4@tty0.ch \
--to=axel@tty0.ch \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).