From 84820933ed2ba1b99ccaf1da90ffdbee7853ddb3 Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Thu, 10 Mar 2016 19:10:57 +0100 Subject: [PATCH] btrbk: remove %uuid_url_map (replace by get_cached_url_by_uuid() operating on %btrfs_tree_cache) --- btrbk | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/btrbk b/btrbk index 614a1e7..7450565 100755 --- a/btrbk +++ b/btrbk @@ -169,7 +169,6 @@ my %table_formats = ( my %btrfs_tree_cache; # map URL to btr_tree node my %uuid_info; # map UUID to btr_tree node -my %uuid_url_map; # map UUID to hash ( URL => btr_tree, ... ) # enabling this may speed up a bit, but makes it impossible to inject nodes. # keep disabled for now! @@ -1634,7 +1633,6 @@ sub _btr_tree_fill_cache #TRACE "_btr_tree_fill_cache: $abs_path"; $btrfs_tree_cache{$abs_path} = $node; - $uuid_url_map{$node->{uuid}}->{$abs_path} = $node if($node->{uuid}); #!!! fix this also foreach(values %{$node->{SUBTREE}}) { _btr_tree_fill_cache($_, $abs_path . '/' . $_->{REL_PATH}); } @@ -1772,6 +1770,20 @@ sub vinfo_subvol_list($;@) } +# reverse path lookup +sub get_cached_url_by_uuid($) +{ + my $uuid = shift; + my @result; + while(my ($key, $n) = each(%btrfs_tree_cache)) { + next if($n->{is_root}); + next unless($n->{uuid} eq $uuid); + push @result, $key; + } + return @result; +} + + sub __get_by_id($$) { my $subvol_list = shift; @@ -2123,8 +2135,10 @@ sub _origin_tree push(@$lines, ["$prefix", $uuid]); return 0; } - if($uuid_url_map{$uuid}) { - push(@$lines, ["$prefix" . join(" === ", sort map { vinfo($_)->{PRINT} } keys %{$uuid_url_map{$uuid}}), $uuid]); + + my @url = get_cached_url_by_uuid($uuid); + if(scalar @url) { + push(@$lines, ["$prefix" . join(" === ", sort map { vinfo($_)->{PRINT} } @url), $uuid]); } else { push(@$lines, ["$prefix/$node->{path}", $uuid]); } @@ -3128,7 +3142,6 @@ MAIN: }; vinfo_set_detail($subvol, $detail); $uuid_info{$subvol->{uuid}} = $subvol; - $uuid_url_map{$subvol->{uuid}}->{$subvol->{URL}} = $subvol; $subvol_list{$file} = $subvol; if($filename_info->{REMOTE_PARENT_UUID} ne '-') {