From: Tiago Sousa via pve-devel <pve-devel@lists.proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Tiago Sousa <joao.sousa@eurotux.com>
Subject: [pve-devel] [PATCH qemu-server 6/8] blockdev: add set write threshold
Date: Fri, 17 Oct 2025 12:25:31 +0100 [thread overview]
Message-ID: <mailman.50.1760700905.362.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <20251017112539.26471-1-joao.sousa@eurotux.com>
[-- Attachment #1: Type: message/rfc822, Size: 7867 bytes --]
From: Tiago Sousa <joao.sousa@eurotux.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server 6/8] blockdev: add set write threshold
Date: Fri, 17 Oct 2025 12:25:31 +0100
Message-ID: <20251017112539.26471-7-joao.sousa@eurotux.com>
Signed-off-by: Tiago Sousa <joao.sousa@eurotux.com>
---
src/PVE/QemuServer.pm | 22 ++++++++++++++++
src/PVE/QemuServer/Blockdev.pm | 47 ++++++++++++++++++++++++++++++++++
src/PVE/QemuServer/Drive.pm | 7 +++++
3 files changed, 76 insertions(+)
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 45daa06c..de1c39a5 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -5729,6 +5729,28 @@ 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);
+ 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
+ );
+ }
+ }
+ },
+ );
+
#start nbd server for storage migration
if (my $nbd = $migrate_opts->{nbd}) {
diff --git a/src/PVE/QemuServer/Blockdev.pm b/src/PVE/QemuServer/Blockdev.pm
index 8fa5eb51..38a1408a 100644
--- a/src/PVE/QemuServer/Blockdev.pm
+++ b/src/PVE/QemuServer/Blockdev.pm
@@ -830,6 +830,49 @@ 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, $scfg, $volid) = @_;
+
+ my $lv_size = PVE::Storage::volume_size_info($storecfg, $volid, 5);
+
+ my $write_threshold = $lv_size - $scfg->{chunksize} * $scfg->{'chunk-percentage'};
+
+ return $write_threshold;
+}
+
+sub set_write_threshold {
+ my ($storecfg, $vmid, $drive_id, $volid, $options) = @_;
+
+ 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';
+ # 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";
+ block_set_write_threshold($vmid, $nodename, $write_threshold);
+}
+
sub blockdev_external_snapshot {
my ($storecfg, $vmid, $machine_version, $deviceid, $drive, $snap, $parent_snap) = @_;
@@ -878,6 +921,10 @@ sub blockdev_external_snapshot {
node => $snap_fmt_blockdev->{'node-name'},
overlay => $new_fmt_blockdev->{'node-name'},
);
+
+ # 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 {
diff --git a/src/PVE/QemuServer/Drive.pm b/src/PVE/QemuServer/Drive.pm
index 79dd22e6..44f477a9 100644
--- a/src/PVE/QemuServer/Drive.pm
+++ b/src/PVE/QemuServer/Drive.pm
@@ -253,6 +253,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 = (
--
2.47.3
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-10-17 11:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20251017112539.26471-1-joao.sousa@eurotux.com>
2025-10-17 11:25 ` [pve-devel] [PATCH pve-storage 1/4] pvestord: setup new pvestord daemon Tiago Sousa via pve-devel
2025-10-17 11:25 ` [pve-devel] [PATCH pve-storage 2/4] storage: add extend queue handling Tiago Sousa via pve-devel
2025-10-17 11:25 ` [pve-devel] [PATCH pve-storage 3/4] lvmplugin: add thin volume support for LVM external snapshots Tiago Sousa via pve-devel
2025-10-17 11:25 ` [pve-devel] [PATCH pve-storage 4/4] plugin: lvmplugin: add underlay functions Tiago Sousa via pve-devel
2025-10-17 11:25 ` [pve-devel] [PATCH qemu-server 5/8] qmeventd: add block write threshold event handling Tiago Sousa via pve-devel
2025-10-17 11:25 ` Tiago Sousa via pve-devel [this message]
2025-10-17 11:25 ` [pve-devel] [PATCH qemu-server 7/8] blockdev: add query-blockstats qmp command Tiago Sousa via pve-devel
2025-10-17 11:25 ` [pve-devel] [PATCH qemu-server 8/8] blockdev: add underlay resize Tiago Sousa via pve-devel
2025-10-17 11:25 ` [pve-devel] [PATCH pve-cluster 9/9] observe extend queue Tiago Sousa via pve-devel
2025-10-17 11:25 ` [pve-devel] [PATCH pve-manager 10/10] services: add pvestord service Tiago Sousa via pve-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=mailman.50.1760700905.362.pve-devel@lists.proxmox.com \
--to=pve-devel@lists.proxmox.com \
--cc=joao.sousa@eurotux.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox