btrbk: new implementation of btr_subtree(), using more complete information from btr_tree(). (unfinished)

pull/30/head
Axel Burri 2015-03-13 11:44:04 +01:00
parent 618114e717
commit 7497e0b561
1 changed files with 52 additions and 0 deletions

52
btrbk
View File

@ -644,6 +644,12 @@ sub btr_tree($;$)
die unless($rel_path =~ s/^$top_level->{FIXED_PATH}\///);
}
$node->{REL_PATH} = $rel_path;
# !!! hack, remove
$node->{SUBVOL_PATH} = $rel_path;
TRACE "btr_tree: set SUBVOL_PATH: $node->{SUBVOL_PATH}";
$node->{FS_PATH} = $vol . "/" . $path;
TRACE "btr_tree: set FS_PATH: $node->{FS_PATH}";
}
# set PARENT node
@ -653,6 +659,32 @@ sub btr_tree($;$)
return \%tree;
}
sub set_correct_tree_path($)
{
my $tree = shift;
foreach my $node (values %$tree) {
if($node->{TOP_LEVEL}) {
}
}
}
sub _subtree_list
{
my $tree = shift;
my $subvols = shift;
my $prefix = shift;
return unless $subvols;
foreach(values %$subvols) {
my $path = $prefix . $_->{REL_PATH};
$tree->{$path} = $_;
_subtree_list($tree, $_->{SUBVOLUME}, $path . '/');
}
}
sub btr_subtree($;$)
{
@ -664,6 +696,26 @@ sub btr_subtree($;$)
return undef;
}
my $tree = btr_tree($vol, $config);
my $tree_root = $detail->{is_root} ? $tree : $uuid_info{$detail->{uuid}}->{SUBVOLUME};
die unless $tree_root;
my $ret = {};
_subtree_list($ret, $tree_root, "");
return $ret;
}
sub btr_subtree_old($;$)
{
my $vol = shift || die;
my $config = shift;
my $detail = btr_subvolume_detail($vol, $config);
unless($detail) {
WARN "Failed to build btrfs subtree for volume: $vol";
return undef;
}
my $volname = $detail->{name} || "";
my %tree;
my $subvol_list = btr_subvolume_list($vol, $config, subvol_only => 1);