find snapshot parent?
Is there a standard way to find the path of the subvolume parent of a snapshot?
For example:
root@xerus:/test# btrfs sub list /test ID 269 gen 9818 top level 5 path tux/test ID 1026 gen 9804 top level 1011 path tmp/xx/ss1 ID 1027 gen 9804 top level 1011 path tmp/xx/ss2
root@xerus:/test# btrfs subvolume show /test/tmp
/test/tmp
Name: tmp
UUID: 5a873eca-9b6c-fc4e-aed5-eb287839d693
Parent UUID: -
Received UUID: -
Creation time: 2019-07-04 00:17:11 +0200
Subvolume ID: 1011
Generation: 9813
Gen at creation: 9749
Parent ID: 5
Top level ID: 5
Flags: -
Snapshot(s):
xx/ss1
xx/ss2root@xerus:/test# btrfs subvolume show /test/tmp/xx/ss1
/test/tmp/xx/ss1
Name: ss1
UUID: 3641bb81-d1fd-4440-8f29-6f17ff9ec4e1
Parent UUID: 5a873eca-9b6c-fc4e-aed5-eb287839d693
Received UUID: -
Creation time: 2019-07-05 11:13:15 +0200
Subvolume ID: 1026
Generation: 9804
Gen at creation: 9793
Parent ID: 1011
Top level ID: 1011
Flags: readonly
Snapshot(s):Must I call "btrfs subvolume show" for every subvolume to find the matching Parent ID/UUID or parse the "Snapshot(s)" section?
And how can I see whether /test/tmp/xx/ss1 is a snapshot at all? Do all snapshots have a "Parent UUID" and regular subvolumes not?
Signature · 6 lines
Ullrich Horlacher Server und Virtualisierung Rechenzentrum TIK Universitaet Stuttgart E-Mail: [email protected] Allmandring 30a Tel: ++49-711-68565868 70569 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ REF:<[email protected]>
Quoted 42 lines · Ulli Horlacher
Is there a standard way to find the path of the subvolume parent of a snapshot?
For example:
root@xerus:/test# btrfs sub list /test ID 269 gen 9818 top level 5 path tux/test ID 1026 gen 9804 top level 1011 path tmp/xx/ss1 ID 1027 gen 9804 top level 1011 path tmp/xx/ss2root@xerus:/test# btrfs subvolume show /test/tmp /test/tmp Name: tmp UUID: 5a873eca-9b6c-fc4e-aed5-eb287839d693 Parent UUID: - Received UUID: - Creation time: 2019-07-04 00:17:11 +0200 Subvolume ID: 1011 Generation: 9813 Gen at creation: 9749 Parent ID: 5 Top level ID: 5 Flags: - Snapshot(s): xx/ss1 xx/ss2root@xerus:/test# btrfs subvolume show /test/tmp/xx/ss1 /test/tmp/xx/ss1 Name: ss1 UUID: 3641bb81-d1fd-4440-8f29-6f17ff9ec4e1 Parent UUID: 5a873eca-9b6c-fc4e-aed5-eb287839d693 Received UUID: - Creation time: 2019-07-05 11:13:15 +0200 Subvolume ID: 1026 Generation: 9804 Gen at creation: 9793 Parent ID: 1011 Top level ID: 1011 Flags: readonly Snapshot(s):
Quoted 2 lines
Must I call "btrfs subvolume show" for every subvolume to find the matching Parent ID/UUID or parse the "Snapshot(s)" section?
That seems to be the way, looking at code for the Snapshot(s) section it iterates every subvolume and checks if its Parent UUID matches the UUID of the subvolume - if yes it adds that particular subvol (snapshots are subvolumes with a parent) to the "SNapshot(s)" section.
Quoted 3 lines
And how can I see whether /test/tmp/xx/ss1 is a snapshot at all? Do all snapshots have a "Parent UUID" and regular subvolumes not?
Indeed, only snapshots have a Parent UUID.
Quoted 1 line
Quoted 4 lines · Nikolay Borisov
Quoted 2 lines
And how can I see whether /test/tmp/xx/ss1 is a snapshot at all? Do all snapshots have a "Parent UUID" and regular subvolumes not?
Indeed, only snapshots have a Parent UUID.
Not all:
root@xerus:/test# btrfs subvolume snapshot -r /test /test/ss1 Create a readonly snapshot of '/test' in '/test/ss1'
root@xerus:/test# btrfs subvolume show /test/ss1
/test/ss1
Name: ss1
UUID: 02bd07bc-0bab-3442-96be-40790e1ba9be
Parent UUID: -
Received UUID: -
Creation time: 2019-07-06 22:37:37 +0200
Subvolume ID: 1036
Generation: 9824
Gen at creation: 9824
Parent ID: 5
Top level ID: 5
Flags: readonly
Snapshot(s):root@xerus:/test# btrfs subvolume show /test /test is toplevel subvolume
Signature · 6 lines
Ullrich Horlacher Server und Virtualisierung Rechenzentrum TIK Universitaet Stuttgart E-Mail: [email protected] Allmandring 30a Tel: ++49-711-68565868 70569 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ REF:<[email protected]>
06.07.2019 23:43, Ulli Horlacher пишет:
Quoted 27 lines · Nikolay Borisov
Quoted 5 lines
Quoted 3 lines
And how can I see whether /test/tmp/xx/ss1 is a snapshot at all? Do all snapshots have a "Parent UUID" and regular subvolumes not?
Indeed, only snapshots have a Parent UUID.
Not all:
root@xerus:/test# btrfs subvolume snapshot -r /test /test/ss1 Create a readonly snapshot of '/test' in '/test/ss1'root@xerus:/test# btrfs subvolume show /test/ss1 /test/ss1 Name: ss1 UUID: 02bd07bc-0bab-3442-96be-40790e1ba9be Parent UUID: - Received UUID: - Creation time: 2019-07-06 22:37:37 +0200 Subvolume ID: 1036 Generation: 9824 Gen at creation: 9824 Parent ID: 5 Top level ID: 5 Flags: readonly Snapshot(s):
Quoted 3 lines
root@xerus:/test# btrfs subvolume show /test /test is toplevel subvolume
Which is one more reason to not use btrfs top level directly.
Quoted 27 lines · Ulli Horlacher
Quoted 4 lines · Nikolay Borisov
Quoted 2 lines
And how can I see whether /test/tmp/xx/ss1 is a snapshot at all? Do all snapshots have a "Parent UUID" and regular subvolumes not?
Indeed, only snapshots have a Parent UUID.
Not all:
root@xerus:/test# btrfs subvolume snapshot -r /test /test/ss1 Create a readonly snapshot of '/test' in '/test/ss1'root@xerus:/test# btrfs subvolume show /test/ss1 /test/ss1 Name: ss1 UUID: 02bd07bc-0bab-3442-96be-40790e1ba9be Parent UUID: - Received UUID: - Creation time: 2019-07-06 22:37:37 +0200 Subvolume ID: 1036 Generation: 9824 Gen at creation: 9824 Parent ID: 5 Top level ID: 5 Flags: readonly Snapshot(s):
Quoted 2 lines
root@xerus:/test# btrfs subvolume show /test /test is toplevel subvolume
This is really odd, looking at create_pending_snapshot the codes :
memcpy(new_root_item->parent_uuid, root->root_item.uuid,
BTRFS_UUID_SIZE);
And that's not conditional on whether the snapshot is read only or not.
So everytime we creata a snapshot it ought to be receiving the parent's subvolume UUID in its parent_uuid field. And indeed testing with latest misc-next kernel:
root@ubuntu-virtual:~# btrfs subvol create /media/scratch/subvol10 Create subvolume '/media/scratch/subvol10'
root@ubuntu-virtual:~# btrfs subvol snapshot /media/scratch/subvol10/ /media/scratch/snap-subvol10 Create a snapshot of '/media/scratch/subvol10/' in '/media/scratch/snap-subvol10'
root@ubuntu-virtual:~# btrfs subvol snapshot -r /media/scratch/subvol10/ /media/scratch/snap-subvol10-ro Create a readonly snapshot of '/media/scratch/subvol10/' in '/media/scratch/snap-subvol10-ro'
root@ubuntu-virtual:~# btrfs subvol show /media/scratch/snap-subvol10 snap-subvol10 Name: snap-subvol10 UUID: 8000e96e-5d6e-3c49-a4d3-5e3868ac6972 Parent UUID: 6352b676-fce5-0945-88d9-745a6ae72783 Received UUID: - Creation time: 2019-07-07 06:40:15 +0000 Subvolume ID: 262 Generation: 17 Gen at creation: 17 Parent ID: 5 Top level ID: 5 Flags: - Snapshot(s):
root@ubuntu-virtual:~# btrfs subvol show /media/scratch/snap-subvol10-ro/ snap-subvol10-ro Name: snap-subvol10-ro UUID: 8964dab3-37b0-fc4e-b891-69323d3aaea0 Parent UUID: 6352b676-fce5-0945-88d9-745a6ae72783 Received UUID: - Creation time: 2019-07-07 06:40:26 +0000 Subvolume ID: 263 Generation: 18 Gen at creation: 18 Parent ID: 5 Top level ID: 5 Flags: readonly Snapshot(s):
Note that the related code hasn't change in a long time.
07.07.2019 9:43, Nikolay Borisov пишет:
Quoted 33 lines · Ulli Horlacher
Quoted 27 lines · Nikolay Borisov
Quoted 5 lines
Quoted 3 lines
And how can I see whether /test/tmp/xx/ss1 is a snapshot at all? Do all snapshots have a "Parent UUID" and regular subvolumes not?
Indeed, only snapshots have a Parent UUID.
Not all:
root@xerus:/test# btrfs subvolume snapshot -r /test /test/ss1 Create a readonly snapshot of '/test' in '/test/ss1'root@xerus:/test# btrfs subvolume show /test/ss1 /test/ss1 Name: ss1 UUID: 02bd07bc-0bab-3442-96be-40790e1ba9be Parent UUID: - Received UUID: - Creation time: 2019-07-06 22:37:37 +0200 Subvolume ID: 1036 Generation: 9824 Gen at creation: 9824 Parent ID: 5 Top level ID: 5 Flags: readonly Snapshot(s):Quoted 2 lines
root@xerus:/test# btrfs subvolume show /test /test is toplevel subvolume
Quoted 8 lines
This is really odd, looking at
create_pending_snapshotthe codes :memcpy(new_root_item->parent_uuid,
root->root_item.uuid,BTRFS_UUID_SIZE);And that's not conditional on whether the snapshot is read only or not. So everytime we creata a snapshot it ought to be receiving the parent's subvolume UUID in its
parent_uuidfield.
Does top level subvolume of btrfs have subvolume UUID at all? How can one display it? None of "btrfs subvolume" commands show it.
Quoted 8 lines
And indeed testing with latest misc-next kernel:
root@ubuntu-virtual:~# btrfs subvol create /media/scratch/subvol10 Create subvolume '/media/scratch/subvol10'root@ubuntu-virtual:~# btrfs subvol snapshot /media/scratch/subvol10/ /media/scratch/snap-subvol10 Create a snapshot of '/media/scratch/subvol10/' in '/media/scratch/snap-subvol10'
/media/scratch/subvol10 is not top level subvolume.
Quoted 48 lines · Andrei Borzenkov
07.07.2019 9:43, Nikolay Borisov пишет:
Quoted 33 lines · Ulli Horlacher
Quoted 27 lines · Nikolay Borisov
Quoted 5 lines
Quoted 3 lines
And how can I see whether /test/tmp/xx/ss1 is a snapshot at all? Do all snapshots have a "Parent UUID" and regular subvolumes not?
Indeed, only snapshots have a Parent UUID.
Not all:
root@xerus:/test# btrfs subvolume snapshot -r /test /test/ss1 Create a readonly snapshot of '/test' in '/test/ss1'root@xerus:/test# btrfs subvolume show /test/ss1 /test/ss1 Name: ss1 UUID: 02bd07bc-0bab-3442-96be-40790e1ba9be Parent UUID: - Received UUID: - Creation time: 2019-07-06 22:37:37 +0200 Subvolume ID: 1036 Generation: 9824 Gen at creation: 9824 Parent ID: 5 Top level ID: 5 Flags: readonly Snapshot(s):Quoted 2 lines
root@xerus:/test# btrfs subvolume show /test /test is toplevel subvolumeQuoted 8 lines
This is really odd, looking at
create_pending_snapshotthe codes :memcpy(new_root_item->parent_uuid,
root->root_item.uuid,BTRFS_UUID_SIZE);And that's not conditional on whether the snapshot is read only or not. So everytime we creata a snapshot it ought to be receiving the parent's subvolume UUID in its
parent_uuidfield.Does top level subvolume of btrfs have subvolume UUID at all? How can one display it? None of "btrfs subvolume" commands show it.
Quoted 2 lines
And indeed testing with latest misc-next kernel:
Quoted 8 lines
Quoted 6 lines
root@ubuntu-virtual:~# btrfs subvol create /media/scratch/subvol10 Create subvolume '/media/scratch/subvol10'root@ubuntu-virtual:~# btrfs subvol snapshot /media/scratch/subvol10/ /media/scratch/snap-subvol10 Create a snapshot of '/media/scratch/subvol10/' in '/media/scratch/snap-subvol10'/media/scratch/subvol10 is not top level subvolume.
root@ubuntu-virtual:~# mkfs.btrfs /dev/vdc
root@ubuntu-virtual:~# mount /dev/vdc /media/scratch/
root@ubuntu-virtual:~# btrfs subvolume snapshot /media/scratch/ /media/scratch/snap1 Create a snapshot of '/media/scratch/' in '/media/scratch/snap1'
root@ubuntu-virtual:~# btrfs subvolume snapshot -r /media/scratch/ /media/scratch/snap-ro Create a readonly snapshot of '/media/scratch/' in '/media/scratch/snap-ro'
root@ubuntu-virtual:~# btrfs subvol show /media/scratch/ / Name: <FS_TREE> UUID: 80633e8d-fa8a-4922-ac0c-b46d7b2e2d81 Parent UUID: - Received UUID: - Creation time: 2019-07-07 09:09:15 +0000 Subvolume ID: 5 Generation: 8 Gen at creation: 0 Parent ID: 0 Top level ID: 0 Flags: - Snapshot(s): snap1 snap-ro
root@ubuntu-virtual:~# btrfs subvol show /media/scratch/snap1/ snap1 Name: snap1 UUID: df861e02-5f54-a74c-a560-dfa66a80b528 Parent UUID: 80633e8d-fa8a-4922-ac0c-b46d7b2e2d81 Received UUID: - Creation time: 2019-07-07 09:09:38 +0000 Subvolume ID: 257 Generation: 6 Gen at creation: 6 Parent ID: 5 Top level ID: 5 Flags: - Snapshot(s):
root@ubuntu-virtual:~# btrfs subvol show /media/scratch/snap-ro/ snap-ro Name: snap-ro UUID: f9c1a467-2d8a-2343-9011-a4ad07e701b7 Parent UUID: 80633e8d-fa8a-4922-ac0c-b46d7b2e2d81 Received UUID: - Creation time: 2019-07-07 09:11:34 +0000 Subvolume ID: 258 Generation: 8 Gen at creation: 8 Parent ID: 5 Top level ID: 5 Flags: readonly Snapshot(s):
Quoted 1 line
Quoted 18 lines · Nikolay Borisov
root@ubuntu-virtual:~# mount /dev/vdc /media/scratch/root@ubuntu-virtual:~# btrfs subvol show /media/scratch/ / Name: <FS_TREE> UUID: 80633e8d-fa8a-4922-ac0c-b46d7b2e2d81 Parent UUID: - Received UUID: - Creation time: 2019-07-07 09:09:15 +0000 Subvolume ID: 5 Generation: 8 Gen at creation: 0 Parent ID: 0 Top level ID: 0 Flags: - Snapshot(s): snap1 snap-ro
root@fex:~# lsb_release -d Description: Ubuntu 18.04.2 LTS
root@fex:~# btrfs version btrfs-progs v4.15.1
root@fex:~# mount|grep /local /dev/sdd1 on /local type btrfs (rw,relatime,space_cache,user_subvol_rm_allowed,subvolid=5,subvol=/)
root@fex:~# btrfs subvolume show /local
/
Name: <FS_TREE>
UUID: -
Parent UUID: -
Received UUID: -
Creation time: -
Subvolume ID: 5
Generation: 1633457
Gen at creation: 0
Parent ID: 0
Top level ID: 0
Flags: -No UUID!
Signature · 6 lines
Ullrich Horlacher Server und Virtualisierung Rechenzentrum TIK Universitaet Stuttgart E-Mail: [email protected] Allmandring 30a Tel: ++49-711-68565868 70569 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ REF:<[email protected]>
08.07.2019 1:18, Ulli Horlacher пишет:
Quoted 46 lines · Nikolay Borisov
Quoted 4 lines
root@ubuntu-virtual:~# mount /dev/vdc /media/scratch/Quoted 16 lines
root@ubuntu-virtual:~# btrfs subvol show /media/scratch/ / Name: <FS_TREE> UUID: 80633e8d-fa8a-4922-ac0c-b46d7b2e2d81 Parent UUID: - Received UUID: - Creation time: 2019-07-07 09:09:15 +0000 Subvolume ID: 5 Generation: 8 Gen at creation: 0 Parent ID: 0 Top level ID: 0 Flags: - Snapshot(s): snap1 snap-roroot@fex:~# lsb_release -d Description: Ubuntu 18.04.2 LTSroot@fex:~# btrfs version btrfs-progs v4.15.1root@fex:~# mount|grep /local /dev/sdd1 on /local type btrfs (rw,relatime,space_cache,user_subvol_rm_allowed,subvolid=5,subvol=/)root@fex:~# btrfs subvolume show /local / Name: <FS_TREE> UUID: - Parent UUID: - Received UUID: - Creation time: - Subvolume ID: 5 Generation: 1633457 Gen at creation: 0 Parent ID: 0 Top level ID: 0 Flags: -
Quoted 2 lines
No UUID!
Neither here on different versions of openSUSE. Note that it also mistakenly displays subvolumes as snapshots (I assume, it simply compares NULL subvolume UUID with NULL parent UUID in this case).
bor@leap423:~> sudo btrfs version
btrfs-progs v4.5.3+20160729
bor@leap423:~> uname -a
Linux leap423 4.4.180-102-default #1 SMP Mon Jun 17 13:11:23 UTC 2019 (7cfa20a) x86_64 x86_64 x86_64 GNU/Linux
bor@leap423:~> sudo btrfs su sh /mnt
/mnt is toplevel subvolume
bor@leap423:~>
bor@localhost:~> sudo btrfs version
btrfs-progs v4.19.1
bor@localhost:~> uname -a
Linux localhost 4.12.14-lp151.28.7-default #1 SMP Mon Jun 17 16:36:38 UTC 2019 (f8a1872) x86_64 x86_64 x86_64 GNU/Linux bor@localhost:~> sudo btrfs su sh /mnt
/
Name: <FS_TREE> UUID: - Parent UUID: - Received UUID: - Creation time: - Subvolume ID: 5 Generation: 338 Gen at creation: 0 Parent ID: 0 Top level ID: 0 Flags: - Snapshot(s): @ @/var @/usr/local @/tmp @/srv @/root @/opt @/home @/boot/grub2/x86_64-efi @/boot/grub2/i386-pc @/.snapshots @/.snapshots/1/snapshot
bor@localhost:~>
bor@10:~> sudo btrfs version
btrfs-progs v5.1
bor@10:~> uname -a
Linux 10.0.2.15 5.1.7-1-default #1 SMP Tue Jun 4 07:56:54 UTC 2019 (55f2451) x86_64 x86_64 x86_64 GNU/Linux
bor@10:~> sudo btrfs su sh /mnt
/
Name: <FS_TREE> UUID: - Parent UUID: - Received UUID: - Creation time: - Subvolume ID: 5 Generation: 26638 Gen at creation: 0 Parent ID: 0 Top level ID: 0 Flags: - Snapshot(s): @ @/.snapshots @/boot/grub2/i386-pc @/boot/grub2/x86_64-efi @/home @/opt @/srv @/tmp @/usr/local @/var/cache @/var/crash @/var/lib/libvirt/images @/var/lib/machines @/var/lib/mailman @/var/lib/mariadb @/var/lib/mysql @/var/lib/named @/var/lib/pgsql @/var/log @/var/opt @/var/spool @/var/tmp
bor@10:~>
I have now implemented "btrfs_subvolume_list", example:
root@xerus:~# df3 -T Filesystem Type Mbytes Used Available Use% Mounted on /dev/sda1 ext4 20,029 4,482 14,507 24% / /dev/sdd4 btrfs 53,247 101 51,052 1% /test
root@xerus:~# btrfs_subvolume_list rw /test ro /test/.snapshot/2019-07-06_2236.test <- /test ro /test/snapshot_1 <- /test ro /test/ss1 <- /test ro /test/ss3 <- - rw /test/tmp ro /test/tmp/xx/ss1 <- /test/tmp ro /test/tmp/xx/ss2 <- /test/tmp ro /test/tmp/xx/ss3 <- /test/ss3 rw /test/tmp/zz2 <- /test/tux/zz rw /test/tux/test ro /test/tux/test/.snapshot/2017-12-02_1341.test <- /test/tux/test rw /test/tux/test2 <- /test/tux/test rw /test/tux/test2/test <- /test/tux/test rw /test/tux/zz
<- means: is snapshot of ...
Note: I have deleted the subvolume parent of /test/ss3
Sourcecode is available under:
Signature · 6 lines
Ullrich Horlacher Server und Virtualisierung Rechenzentrum TIK Universitaet Stuttgart E-Mail: [email protected] Allmandring 30a Tel: ++49-711-68565868 70569 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ REF:<[email protected]>