I need to find (all) subvolume directories.
I know, btrfs subvolumes root directories have inode #256, but a
"find / -inum 256" is horrible slow!

Next idea: "btrfs subvolume list /" is really fast, but its output is not
always direct usable to find the subvolume directory.

Example output on a SUSE system:

root@trulla:~# btrfs subvolume list /
ID 257 gen 2280099 top level 5 path @
ID 258 gen 2280769 top level 257 path @/home
ID 259 gen 2280947 top level 257 path @/opt
ID 260 gen 2280098 top level 257 path @/srv
ID 261 gen 2280954 top level 257 path @/tmp
ID 262 gen 2280187 top level 257 path @/usr/local
ID 263 gen 2280099 top level 257 path @/var/crash
ID 264 gen 2280949 top level 257 path @/var/log
ID 265 gen 2280099 top level 257 path @/var/opt
ID 266 gen 2280954 top level 257 path @/var/spool
ID 267 gen 2280947 top level 257 path @/var/tmp
ID 270 gen 2280222 top level 257 path @/.snapshots
ID 453 gen 2280954 top level 270 path @/.snapshots/128/snapshot
ID 1235 gen 2280099 top level 257 path @/var/lib/machines
ID 12392 gen 2123118 top level 270 path @/.snapshots/1065/snapshot
ID 12393 gen 2123120 top level 270 path @/.snapshots/1066/snapshot
ID 13273 gen 2176640 top level 270 path @/.snapshots/1089/snapshot
ID 13274 gen 2176651 top level 270 path @/.snapshots/1090/snapshot
ID 13553 gen 2203681 top level 270 path @/.snapshots/1103/snapshot

There is no /@/ directory in the default filesystem because of:

root@trulla:/# stat /@/.snapshots/128/snapshot
stat: cannot stat '/@/.snapshots/128/snapshot': No such file or directory

root@trulla:~# btrfs subvolume get-default /
ID 453 gen 2280954 top level 270 path @/.snapshots/128/snapshot

root@trulla:/# mount | grep " / "
/dev/sda2 on / type btrfs 
(rw,relatime,space_cache,subvolid=453,subvol=/@/.snapshots/128/snapshot)

On this particular system I could remove "@" from the subvolume path to
get the subvolume directory:

root@trulla:/# stat /.snapshots/128/snapshot
  File: '/.snapshots/128/snapshot'
  Size: 198             Blocks: 0          IO Block: 4096   directory
Device: 27h/39d Inode: 256         Links: 1
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-07-13 01:03:08.543830085 +0200
Modify: 2019-07-13 01:03:37.336445461 +0200
Change: 2019-07-13 01:03:37.336445461 +0200
 Birth: -

But what if a btrfs filesystem does not have a toplevel /@/ directory, but
anything else, like /this/is/my/top/directory ?

Will be the first output line of "btrfs subvolume list /"
always look like

ID 257 gen 2280099 top level 5 path this/is/my/top/directory 

?



-- 
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum TIK         
Universitaet Stuttgart         E-Mail: horlac...@tik.uni-stuttgart.de
Allmandring 30a                Tel:    ++49-711-68565868
70569 Stuttgart (Germany)      WWW:    http://www.tik.uni-stuttgart.de/
REF:<20190712231705.ga16...@tik.uni-stuttgart.de>

Reply via email to