btrbk: treat all related readonly subvolumes within snapdir as "snapshots"

With this, previous snapshots (far relations) are still listed when
restoring a snapshot.

Example (S = source subvolume, readwrite):

  After 3 snapshots:
  A->S, B->S, C->S

  Restore B: `btrfs subvol delete S; btrfs subvol snapshot B S'`
  A->S, B->S, C->S, S'->B

Previous implementation would show now snapshots for S', as no
snapshot has parent_uuid=S'.

New implementation shows A, B, C as snapshots for S', as orphaned
siblings (A, B, C pointing to deleted S) are also related.
pull/274/head
Axel Burri 2019-04-11 14:41:08 +02:00
parent adfdf925e2
commit 0a93f69135
1 changed files with 4 additions and 7 deletions

11
btrbk
View File

@ -2920,14 +2920,11 @@ sub get_snapshot_children($$;$)
my $snaproot = shift || die; my $snaproot = shift || die;
my $svol = shift // die; my $svol = shift // die;
my $btrbk_basename = shift; # if set, also filter by direct_leaf my $btrbk_basename = shift; # if set, also filter by direct_leaf
my @ret; my @ret = map( { vinfo_resolved($_, $snaproot, btrbk_direct_leaf => $btrbk_basename) // () }
@{get_related_readonly_nodes($svol)} );
foreach (@{vinfo_subvol_list($snaproot, readonly => 1, btrbk_direct_leaf => $btrbk_basename)}) { if($loglevel >= 4) { TRACE "get_snapshot_children: found: $_->{PRINT}" foreach(@ret); }
next unless($_->{node}{parent_uuid} eq $svol->{node}{uuid}); DEBUG "Found " . scalar(@ret) . " related snapshots of \"$svol->{PRINT}\" in: $snaproot->{PRINT}" . (defined($btrbk_basename) ? "/$btrbk_basename.*" : "");
TRACE "get_snapshot_children: found: $_->{PRINT}";
push(@ret, $_);
}
DEBUG "Found " . scalar(@ret) . " snapshot children of \"$svol->{PRINT}\" in: $snaproot->{PRINT}" . (defined($btrbk_basename) ? "/$btrbk_basename.*" : "");
return @ret; return @ret;
} }