[pve-devel] [pve-manager] snapshot rollback: cleanup replication snapshots
Fabian Grünbichler
f.gruenbichler at proxmox.com
Mon Jun 12 09:10:39 CEST 2017
On Mon, Jun 12, 2017 at 08:18:12AM +0200, Dietmar Maurer wrote:
> We want to remove all replication snapshots before rollback (some storage
> backends (i.e. zfs) rejects rollback if there are newer snapshots).
>
> Next replication can simply use the rolled-backed snapshot as base.
>
> Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
> ---
> PVE/API2/Qemu.pm | 21 ++++++++++++++++++++-
misleading subject, as this is not in pve-manager :P
but, shouldn't it actually be in PVE::AbstractConfig->snapshot_rollback?
> 1 file changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
> index 54db5ab..e495d90 100644
> --- a/PVE/API2/Qemu.pm
> +++ b/PVE/API2/Qemu.pm
> @@ -16,6 +16,7 @@ use PVE::Storage;
> use PVE::JSONSchema qw(get_standard_option);
> use PVE::RESTHandler;
> use PVE::ReplicationConfig;
> +use PVE::Replication;
> use PVE::GuestHelpers;
> use PVE::QemuConfig;
> use PVE::QemuServer;
> @@ -3390,11 +3391,29 @@ __PACKAGE__->register_method({
> my $snapname = extract_param($param, 'snapname');
>
> my $realcmd = sub {
> + my $storecfg = PVE::Storage::config();
> + my $repl_conf = PVE::ReplicationConfig->new();
> + if ($repl_conf->check_for_existing_jobs($vmid, 1)) {
> + # remove all replication snapshots
> + my $conf = PVE::QemuConfig->load_config($vmid);
> + my $volumes = PVE::QemuConfig->get_replicatable_volumes($storecfg, $conf);
> + my $sorted_volids = [ sort keys %$volumes ];
> +
> + # remove all local replication snapshots (lastsync => 0)
> + my $logfunc = sub { my $line = shift; chomp $line; print "$line\n"; };
> + PVE::Replication::prepare($storecfg, $sorted_volids, undef, 0, undef, $logfunc);
> + }
> +
> PVE::Cluster::log_msg('info', $authuser, "rollback snapshot VM $vmid: $snapname");
> PVE::QemuConfig->snapshot_rollback($vmid, $snapname);
> };
>
> - return $rpcenv->fork_worker('qmrollback', $vmid, $authuser, $realcmd);
> + my $worker = sub {
> + # hold migration lock, this makes sure that nobody create replication snapshots
> + return PVE::GuestHelpers::guest_migration_lock($vmid, 10, $realcmd);
> + };
> +
> + return $rpcenv->fork_worker('qmrollback', $vmid, $authuser, $worker);
> }});
>
> __PACKAGE__->register_method({
> --
> 2.11.0
>
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
More information about the pve-devel
mailing list