blockdev: add set write threshold
blockdev: set write threshold
This commit is contained in:
parent
1d1e4aa3a7
commit
88d7de0720
2 changed files with 75 additions and 0 deletions
|
|
@ -5822,6 +5822,26 @@ sub vm_start_nolock {
|
|||
warn $@ if $@;
|
||||
}
|
||||
|
||||
# set write threshold for LVM thin provisioning disks
|
||||
PVE::QemuConfig->foreach_volume(
|
||||
$conf,
|
||||
sub {
|
||||
my ($ds, $drive) = @_;
|
||||
return if PVE::QemuServer::drive_is_cdrom($drive, 1);
|
||||
if ($drive->{file} ne 'none') {
|
||||
my $extra_blockdev_options = {};
|
||||
# $extra_blockdev_options->{'live-restore'} = $live_restore if $live_restore;
|
||||
# extra protection for templates, but SATA and IDE don't support it..
|
||||
$extra_blockdev_options->{'read-only'} = 1
|
||||
if drive_is_read_only($conf, $drive);
|
||||
|
||||
PVE::QemuServer::Blockdev::set_write_threshold(
|
||||
$storecfg, $vmid, $drive, $extra_blockdev_options,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
#start nbd server for storage migration
|
||||
if (my $nbd = $migrate_opts->{nbd}) {
|
||||
|
||||
|
|
|
|||
|
|
@ -820,6 +820,59 @@ sub set_io_throttle {
|
|||
}
|
||||
}
|
||||
|
||||
sub block_set_write_threshold {
|
||||
my ($vmid, $nodename, $threshold) = @_;
|
||||
|
||||
print "set threshold $nodename $threshold\n";
|
||||
|
||||
PVE::QemuServer::mon_cmd(
|
||||
$vmid,
|
||||
"block-set-write-threshold",
|
||||
'node-name' => $nodename,
|
||||
'write-threshold' => int($threshold),
|
||||
);
|
||||
}
|
||||
|
||||
sub compute_write_threshold {
|
||||
my ($storecfg, $volid) = @_;
|
||||
|
||||
my $lv_size = PVE::Storage::volume_size_info($storecfg, $volid, 5);
|
||||
|
||||
# FIX: change these vars to config inputs
|
||||
my $chunksize = 1024 * 1024 * 1024; # 1 GiB
|
||||
my $alert_chunk_percentage = 0.5; # alert when percetage of chunk used
|
||||
|
||||
my $write_threshold = $lv_size - $chunksize * (1 - $alert_chunk_percentage);
|
||||
|
||||
return $write_threshold;
|
||||
}
|
||||
|
||||
sub set_write_threshold {
|
||||
my ($storecfg, $vmid, $drive, $options) = @_;
|
||||
|
||||
my $volid = $drive->{'file'};
|
||||
my ($storeid) = PVE::Storage::parse_volume_id($volid);
|
||||
my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
|
||||
my $support_qemu_snapshots = PVE::Storage::volume_qemu_snapshot_method($storecfg, $volid);
|
||||
|
||||
# set write threshold is only supported for lvm storage using
|
||||
# qcow2+external snapshots
|
||||
return if $scfg->{type} ne 'lvm' || $support_qemu_snapshots ne 'mixed';
|
||||
|
||||
print "setting threshold for $volid from $storeid\n";
|
||||
|
||||
my $snapshots = PVE::Storage::volume_snapshot_info($storecfg, $volid);
|
||||
my $parentid = $snapshots->{'current'}->{parent};
|
||||
# for now only set write_threshold for volumes that have snapshots
|
||||
if ($parentid) {
|
||||
my $drive_id = PVE::QemuServer::Drive::get_drive_id($drive);
|
||||
my $nodename = get_node_name('file', $drive_id, $volid, $options);
|
||||
my $write_threshold = compute_write_threshold($storecfg, $volid);
|
||||
|
||||
block_set_write_threshold($vmid, $nodename, $write_threshold);
|
||||
}
|
||||
}
|
||||
|
||||
sub blockdev_external_snapshot {
|
||||
my ($storecfg, $vmid, $machine_version, $deviceid, $drive, $snap, $parent_snap) = @_;
|
||||
|
||||
|
|
@ -868,6 +921,8 @@ sub blockdev_external_snapshot {
|
|||
node => $snap_fmt_blockdev->{'node-name'},
|
||||
overlay => $new_fmt_blockdev->{'node-name'},
|
||||
);
|
||||
|
||||
set_write_threshold($storecfg, $vmid, $drive);
|
||||
}
|
||||
|
||||
sub blockdev_delete {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue