btrbk: send/receive: delete possibly left-behind garbled subvolume on failure (upstream btrfs-progs does not delete unfinished "btrfs receive")

pull/30/head
Axel Burri 2015-05-09 16:00:41 +02:00
parent 2034b51058
commit 465a3eb92e
1 changed files with 16 additions and 2 deletions

18
btrbk
View File

@ -972,7 +972,8 @@ sub macro_send_receive($@)
INFO "Receiving from snapshot: $snapshot->{PRINT}"; INFO "Receiving from snapshot: $snapshot->{PRINT}";
# add info to $config->{SUBVOL_RECEIVED} # add info to $config->{SUBVOL_RECEIVED}
$info{received_name} = "$target->{PRINT}/$snapshot->{NAME}"; my $vol_received = vinfo_child($target, $snapshot->{NAME});
$info{received_subvolume} = $vol_received;
$config_target->{SUBVOL_RECEIVED} //= []; $config_target->{SUBVOL_RECEIVED} //= [];
push(@{$config_target->{SUBVOL_RECEIVED}}, \%info); push(@{$config_target->{SUBVOL_RECEIVED}}, \%info);
@ -1002,6 +1003,19 @@ sub macro_send_receive($@)
} else { } else {
$info{ERROR} = 1; $info{ERROR} = 1;
$config_target->{ABORTED} = "Failed to send/receive subvolume"; $config_target->{ABORTED} = "Failed to send/receive subvolume";
# NOTE: btrfs-progs v3.19.1 does not delete garbled received subvolume,
# we need to do this by hand.
# TODO: remove this as soon as btrfs-progs handle receive errors correctly.
DEBUG "send/received failed, deleting (possibly present and garbled) received subvolume: $vol_received->{PRINT}";
my $ret = btrfs_subvolume_delete($vol_received, commit => "after");
if(defined($ret)) {
WARN "Deleted partially received (garbled) subvolume: $vol_received->{PRINT}";
}
else {
WARN "Deletion of partially received (garbled) subvolume failed, assuming clean environment: $vol_received->{PRINT}";
}
return undef; return undef;
} }
} }
@ -2002,7 +2016,7 @@ MAIN:
$create_mode = ">>>" if($_->{parent}); $create_mode = ">>>" if($_->{parent});
# substr($create_mode, 0, 1, '%') if($_->{resume}); # substr($create_mode, 0, 1, '%') if($_->{resume});
$create_mode = "!!!" if($_->{ERROR}); $create_mode = "!!!" if($_->{ERROR});
push @out, "$create_mode $_->{received_name}"; push @out, "$create_mode $_->{received_subvolume}->{PRINT}";
} }
if($config_target->{SUBVOL_DELETED}) { if($config_target->{SUBVOL_DELETED}) {