first functional version of extend lv

This commit is contained in:
Tiago Sousa 2025-09-20 18:49:23 +01:00
parent 7fe84f2902
commit be6264ebbf
3 changed files with 50 additions and 31 deletions

View file

@ -5828,16 +5828,18 @@ sub vm_start_nolock {
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,
);
my $volid = $drive->{file};
if ( $volid ne 'none') {
my $drive_id = PVE::QemuServer::Drive::get_drive_id($drive);
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
# FIX: Change to only thin drives
if ($parentid) {
PVE::QemuServer::Blockdev::set_write_threshold(
$storecfg, $vmid, $drive_id, $volid
);
}
}
},
);

View file

@ -715,6 +715,24 @@ sub resize {
);
}
sub underlay_resize {
my ($storecfg, $vmid, $drive_id, $volid) = @_;
my $running = PVE::QemuServer::Helpers::vm_running_locally($vmid);
# get backing_snap
my $snapshots = PVE::Storage::volume_snapshot_info($storecfg, $volid);
my $backing_snap = $snapshots->{current}->{parent};
my $size = PVE::Storage::volume_underlay_resize($storecfg, $volid, $backing_snap);
return if !$running;
my $block_info = get_block_info($vmid);
my $inserted = $block_info->{$drive_id}->{inserted}
or die "no block node inserted for drive '$drive_id'\n";
set_write_threshold($storecfg, $vmid, $drive_id, $volid);
}
my sub blockdev_change_medium {
my ($storecfg, $vmid, $qdev_id, $drive) = @_;
@ -849,23 +867,18 @@ sub block_set_write_threshold {
}
sub compute_write_threshold {
my ($storecfg, $volid) = @_;
my ($storecfg, $scfg, $volid) = @_;
my $lv_size = PVE::Storage::volume_size_info($storecfg, $volid, 5);
my $lv_size = PVE::Storage::volume_underlay_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);
my $write_threshold = $lv_size - $scfg->{chunksize} * (1 - $scfg->{'chunk-percentage'});
return $write_threshold;
}
sub set_write_threshold {
my ($storecfg, $vmid, $drive, $options) = @_;
my ($storecfg, $vmid, $drive_id, $volid, $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);
@ -873,19 +886,14 @@ sub set_write_threshold {
# set write threshold is only supported for lvm storage using
# qcow2+external snapshots
return if $scfg->{type} ne 'lvm' || $support_qemu_snapshots ne 'mixed';
# return if drive is not set as thin
# return if !$drive->{thin};
my $nodename = get_node_name('file', $drive_id, $volid, $options);
my $write_threshold = compute_write_threshold($storecfg, $scfg, $volid);
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);
}
block_set_write_threshold($vmid, $nodename, $write_threshold);
}
sub blockdev_external_snapshot {
@ -937,7 +945,9 @@ sub blockdev_external_snapshot {
overlay => $new_fmt_blockdev->{'node-name'},
);
set_write_threshold($storecfg, $vmid, $drive);
# FIX: only if thin
my $drive_id = PVE::QemuServer::Drive::get_drive_id($drive);
set_write_threshold($storecfg, $vmid, $drive_id, $volid);
}
sub blockdev_delete {

View file

@ -254,6 +254,13 @@ my %drivedesc_base = (
optional => 1,
default => 0,
},
thin => {
type => 'boolean',
description =>
'Controls whether a drive should be thin provisioned',
optional => 1,
default => 0,
},
);
my %iothread_fmt = (