backup: use blockdev for fleecing images
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
parent
faecc35136
commit
f92c1fa0f3
3 changed files with 61 additions and 24 deletions
|
|
@ -10,6 +10,7 @@ use PVE::INotify;
|
|||
use PVE::JSONSchema;
|
||||
use PVE::QemuMigrate::Helpers;
|
||||
use PVE::QemuServer::Agent;
|
||||
use PVE::QemuServer::Blockdev;
|
||||
use PVE::QemuServer::CPUConfig;
|
||||
use PVE::QemuServer::Drive;
|
||||
use PVE::QemuServer::Helpers;
|
||||
|
|
@ -675,16 +676,7 @@ sub cleanup_fleecing_images {
|
|||
};
|
||||
$log_func->('warn', "checking/canceling old backup job failed - $@") if $@;
|
||||
|
||||
my $block_info = mon_cmd($vmid, "query-block");
|
||||
for my $info ($block_info->@*) {
|
||||
my $device_id = $info->{device};
|
||||
next if $device_id !~ m/-fleecing$/;
|
||||
|
||||
$log_func->('info', "detaching (old) fleecing image for '$device_id'");
|
||||
$device_id =~ s/^drive-//; # re-added by qemu_drivedel()
|
||||
eval { PVE::QemuServer::qemu_drivedel($vmid, $device_id) };
|
||||
$log_func->('warn', "error detaching (old) fleecing image '$device_id' - $@") if $@;
|
||||
}
|
||||
PVE::QemuServer::Blockdev::detach_fleecing_block_nodes($vmid, $log_func);
|
||||
}
|
||||
|
||||
PVE::QemuConfig->lock_config(
|
||||
|
|
|
|||
|
|
@ -14,8 +14,30 @@ use PVE::Storage;
|
|||
use PVE::QemuServer::Drive qw(drive_is_cdrom);
|
||||
use PVE::QemuServer::Monitor qw(mon_cmd);
|
||||
|
||||
my sub fleecing_node_name {
|
||||
my ($type, $drive_id) = @_;
|
||||
|
||||
if ($type eq 'fmt') {
|
||||
return "drive-$drive_id-fleecing"; # this is the top node for fleecing
|
||||
} elsif ($type eq 'file') {
|
||||
return "$drive_id-fleecing-file"; # drop the "drive-" prefix to be sure, max length is 31
|
||||
}
|
||||
|
||||
die "unknown node type '$type' for fleecing";
|
||||
}
|
||||
|
||||
my sub is_fleecing_top_node {
|
||||
my ($node_name) = @_;
|
||||
|
||||
return $node_name =~ m/-fleecing$/ ? 1 : 0;
|
||||
}
|
||||
|
||||
my sub get_node_name {
|
||||
my ($type, $drive_id, $volid, $snap) = @_;
|
||||
my ($type, $drive_id, $volid, $options) = @_;
|
||||
|
||||
return fleecing_node_name($type, $drive_id) if $options->{fleecing};
|
||||
|
||||
my $snap = $options->{'snapshot-name'};
|
||||
|
||||
my $info = "drive=$drive_id,";
|
||||
$info .= "snap=$snap," if defined($snap);
|
||||
|
|
@ -174,8 +196,7 @@ sub generate_file_blockdev {
|
|||
$blockdev->{'detect-zeroes'} = PVE::QemuServer::Drive::detect_zeroes_cmdline_option($drive);
|
||||
}
|
||||
|
||||
$blockdev->{'node-name'} =
|
||||
get_node_name('file', $drive_id, $drive->{file}, $options->{'snapshot-name'});
|
||||
$blockdev->{'node-name'} = get_node_name('file', $drive_id, $drive->{file}, $options);
|
||||
|
||||
$blockdev->{'read-only'} = read_only_json_option($drive, $options);
|
||||
|
||||
|
|
@ -208,7 +229,7 @@ sub generate_format_blockdev {
|
|||
$format = $drive->{format} // 'raw';
|
||||
}
|
||||
|
||||
my $node_name = get_node_name('fmt', $drive_id, $drive->{file}, $options->{'snapshot-name'});
|
||||
my $node_name = get_node_name('fmt', $drive_id, $drive->{file}, $options);
|
||||
|
||||
my $blockdev = {
|
||||
'node-name' => "$node_name",
|
||||
|
|
@ -237,6 +258,8 @@ sub generate_drive_blockdev {
|
|||
my $child = generate_file_blockdev($storecfg, $drive, $options);
|
||||
$child = generate_format_blockdev($storecfg, $drive, $child, $options);
|
||||
|
||||
return $child if $options->{fleecing}; # for fleecing, this is already the top node
|
||||
|
||||
# this is the top filter entry point, use $drive-drive_id as nodename
|
||||
return {
|
||||
driver => "throttle",
|
||||
|
|
@ -281,6 +304,8 @@ Parameters:
|
|||
|
||||
=over
|
||||
|
||||
=item C<< $options->{fleecing} >>: Generate and attach a block device for backup fleecing.
|
||||
|
||||
=item C<< $options->{'read-only'} >>: Attach the image as read-only irrespective of the
|
||||
configuration in C<$drive>.
|
||||
|
||||
|
|
@ -386,4 +411,18 @@ sub detach {
|
|||
return;
|
||||
}
|
||||
|
||||
sub detach_fleecing_block_nodes {
|
||||
my ($vmid, $log_func) = @_;
|
||||
|
||||
my $block_info = mon_cmd($vmid, "query-named-block-nodes");
|
||||
for my $info ($block_info->@*) {
|
||||
my $node_name = $info->{'node-name'};
|
||||
next if !is_fleecing_top_node($node_name);
|
||||
|
||||
$log_func->('info', "detaching (old) fleecing image '$node_name'");
|
||||
eval { detach($vmid, $node_name) };
|
||||
$log_func->('warn', "error detaching (old) fleecing image '$node_name' - $@") if $@;
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ use PVE::Format qw(render_duration render_bytes);
|
|||
use PVE::QemuConfig;
|
||||
use PVE::QemuServer;
|
||||
use PVE::QemuServer::Agent;
|
||||
use PVE::QemuServer::Blockdev;
|
||||
use PVE::QemuServer::Drive qw(checked_volume_format);
|
||||
use PVE::QemuServer::Helpers;
|
||||
use PVE::QemuServer::Machine;
|
||||
|
|
@ -626,9 +627,8 @@ my sub detach_fleecing_images {
|
|||
|
||||
for my $di ($disks->@*) {
|
||||
if (my $volid = $di->{'fleece-volid'}) {
|
||||
my $devid = "$di->{qmdevice}-fleecing";
|
||||
$devid =~ s/^drive-//; # re-added by qemu_drivedel()
|
||||
eval { PVE::QemuServer::qemu_drivedel($vmid, $devid) };
|
||||
my $node_name = "$di->{qmdevice}-fleecing";
|
||||
eval { PVE::QemuServer::Blockdev::detach($vmid, $node_name) };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -646,15 +646,21 @@ my sub attach_fleecing_images {
|
|||
if (my $volid = $di->{'fleece-volid'}) {
|
||||
$self->loginfo("$di->{qmdevice}: attaching fleecing image $volid to QEMU");
|
||||
|
||||
my $path = PVE::Storage::path($self->{storecfg}, $volid);
|
||||
my $devid = "$di->{qmdevice}-fleecing";
|
||||
my $drive = "file=$path,if=none,id=$devid,format=$format,discard=unmap";
|
||||
my ($interface, $index) = PVE::QemuServer::Drive::parse_drive_interface($di->{virtdev});
|
||||
my $drive = {
|
||||
file => $volid,
|
||||
interface => $interface,
|
||||
index => $index,
|
||||
format => $format,
|
||||
discard => 'on',
|
||||
};
|
||||
|
||||
my $options = { 'fleecing' => 1 };
|
||||
# Specify size explicitly, to make it work if storage backend rounded up size for
|
||||
# fleecing image when allocating.
|
||||
$drive .= ",size=$di->{'block-node-size'}" if $format eq 'raw';
|
||||
$drive =~ s/\\/\\\\/g;
|
||||
my $ret = PVE::QemuServer::Monitor::hmp_cmd($vmid, "drive_add auto \"$drive\"", 60);
|
||||
die "attaching fleecing image $volid failed - $ret\n" if $ret !~ m/OK/s;
|
||||
$options->{size} = $di->{'block-node-size'} if $format eq 'raw';
|
||||
|
||||
PVE::QemuServer::Blockdev::attach($self->{storecfg}, $vmid, $drive, $options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue