btrbk: clone target subvolume tree if same url as other target (less btrfs calls, shared SUBVOL_LIST)

pull/73/head
Axel Burri 2016-03-08 16:41:02 +01:00
parent eba08f2ca3
commit c1b27c744b
1 changed files with 14 additions and 9 deletions

23
btrbk
View File

@ -2926,6 +2926,7 @@ MAIN:
# fill vinfo hash, basic checks on configuration
#
foreach my $sroot (vinfo_subsection($config, 'volume')) {
DEBUG "Initializing volume section: $sroot->{PRINT}";
unless(vinfo_root($sroot)) {
ABORTED($sroot, "Failed to fetch subvolume detail" . ($err ? ": $err" : ""));
WARN "Skipping volume \"$sroot->{PRINT}\": $abrt";
@ -2933,14 +2934,15 @@ MAIN:
}
foreach my $svol (vinfo_subsection($sroot, 'subvolume')) {
my $svol_check = vinfo_subvol($sroot, $svol->{CONFIG}->{rel_path});
if($svol_check) {
DEBUG "Initializing subvolume section: $svol->{PRINT}";
if(my $svol_check = vinfo_subvol($sroot, $svol->{CONFIG}->{rel_path})) {
DEBUG "Found \"$svol->{CONFIG}->{rel_path}\" in btrfs subtree of: $sroot->{PRINT}";
vinfo_set_detail($svol, $svol_check);
}
else {
# configured subvolume is not present in btrfs subvolume list.
# try to read subvolume detail, as configured subvolume could be a symlink.
DEBUG "Subvolume \"$svol->{CONFIG}->{rel_path}\" not present in btrfs subvolume list for \"$sroot->{PRINT}\"";
DEBUG "Missing \"$svol->{CONFIG}->{rel_path}\" in btrfs subtree of \"$sroot->{PRINT}\", checking details";
my $detail = btrfs_subvolume_detail($svol);
unless($detail) {
ABORTED($svol, "Failed to fetch subvolume detail" . ($err ? ": $err" : ""));
@ -2964,10 +2966,16 @@ MAIN:
foreach my $droot (vinfo_subsection($svol, 'target')) {
DEBUG "Initializing target section: $droot->{PRINT}";
my $target_type = $droot->{CONFIG}->{target_type} || die;
if($target_type eq "send-receive")
{
unless(vinfo_root($droot)) {
if(my $vinfo_clone = $vinfo_cache{$droot->{URL}}) {
DEBUG "Found previously initialized target with same url, cloning dataset from: $droot->{PRINT}";
vinfo_set_detail($droot, $vinfo_clone);
$droot->{SUBVOL_LIST} = $vinfo_clone->{SUBVOL_LIST};
}
elsif(! vinfo_root($droot)) {
ABORTED($droot, "Failed to fetch subvolume detail" . ($err ? ": $err" : ""));
WARN "Skipping target \"$droot->{PRINT}\": $abrt";
next;
@ -3539,14 +3547,11 @@ MAIN:
{
my $filename_info = parse_filename($child->{SUBVOL_PATH}, $snapdir . $snapshot_basename);
unless($filename_info) {
DEBUG "Resume candidate does not match btrbk filename scheme, skipping: $child->{PRINT}";
TRACE "Resume candidate does not match btrbk filename scheme, skipping: $child->{PRINT}";
next;
}
if(scalar get_receive_targets($droot, $child)) {
DEBUG "Found matching receive target, skipping: $child->{PRINT}";
}
else {
unless(scalar get_receive_targets($droot, $child)) {
DEBUG "No matching receive targets found, adding resume candidate: $child->{PRINT}";
if(my $err_vol = vinfo_subvol($droot, $child->{NAME})) {