From 9aeaf2b15cbbc698c2535049ec4f0ca4d3d1e34c Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Mon, 9 Jul 2018 18:34:57 +0200 Subject: [PATCH] btrbk: fix regression introduced with btrfs_subvolume_list_complete If btrfs_subvolume_show($vol, rootid => 5) fails, there are no "received_uuid" and no "gen" keys in the root node. Fixes: 0acbf74c57 (btrbk: add btrfs_subvolume_list_complete: fetch all subvolumes with all flags) --- btrbk | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/btrbk b/btrbk index 13f328a..10dcb40 100755 --- a/btrbk +++ b/btrbk @@ -2157,19 +2157,21 @@ sub btr_tree($$$$) my $gen_max = 0; foreach my $node (@$node_list) { my $node_id = $node->{id}; + my $node_uuid = $node->{uuid}; die unless($node_id >= 5); die "duplicate node id" if(exists($id{$node_id})); $id{$node_id} = $node; - if($node->{uuid}) { - $uuid_hash{$node->{uuid}} = $node; - $uuid_cache{$node->{uuid}} = $node; + if($node_uuid) { + # NOTE: uuid on btrfs root (id=5) is not always present + $uuid_hash{$node_uuid} = $node; + $uuid_cache{$node_uuid} = $node; + # hacky: if root node has no "uuid", it also has no "received_uuid" and no "gen" + push(@{$received_uuid_hash{$node->{received_uuid}}}, $node) if($node->{received_uuid} ne '-'); + $gen_max = $node->{gen} if($node->{gen} > $gen_max); } elsif(not $node->{is_root}) { - # uuid on btrfs root (id=5) is not always present die "missing uuid on subvolume"; } - push(@{$received_uuid_hash{$node->{received_uuid}}}, $node) if($node->{received_uuid} ne '-'); - $gen_max = $node->{gen} if($node->{gen} > $gen_max); $node->{SUBTREE} = []; } my $tree_root = $id{5} // die "missing btrfs root";