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 1/2] blockdev: add set write threshold
Date: Sat, 2 Aug 2025 17:42:39 +0100 [thread overview]
Message-ID: <mailman.533.1754152977.367.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <20250802164240.21751-1-joao.sousa@eurotux.com>
[-- Attachment #1: Type: message/rfc822, Size: 6815 bytes --]
From: Tiago Sousa <joao.sousa@eurotux.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server 1/2] blockdev: add set write threshold
Date: Sat, 2 Aug 2025 17:42:39 +0100
Message-ID: <20250802164240.21751-2-joao.sousa@eurotux.com>
Signed-off-by: Tiago Sousa <joao.sousa@eurotux.com>
---
src/PVE/QemuServer/Blockdev.pm | 52 ++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/src/PVE/QemuServer/Blockdev.pm b/src/PVE/QemuServer/Blockdev.pm
index 0cc4a0f6..a5d7a3b9 100644
--- a/src/PVE/QemuServer/Blockdev.pm
+++ b/src/PVE/QemuServer/Blockdev.pm
@@ -567,9 +567,61 @@ sub attach {
die $err;
}
+ set_write_threshold($storecfg, $vmid, $drive, $options);
+
return $blockdev->{'node-name'};
}
+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 ($scfg, $volid) = @_;
+ my $lv_size = PVE::Storage::volume_size_info($scfg, $volid, 5);
+
+ # FIX: change these vars to config inputs
+ my $chunksize = 1024 * 1024 * 1024; # 1 GB
+ 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 $support_qemu_snapshots = PVE::Storage::volume_qemu_snapshot_method($storecfg, $volid);
+ my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+
+ # set write threshold is only supported for lvm storage using
+ # qcow2+external snapshots
+ return if $scfg->{type} ne 'lvm' || $support_qemu_snapshots ne 'mixed';
+
+ 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, $drive->{file}, $options);
+ my $write_threshold = compute_write_threshold($scfg, $volid);
+
+ block_set_write_threshold($vmid, $nodename, $write_threshold);
+ }
+}
+
=pod
=head3 detach
--
2.39.5
[-- 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-08-02 16:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-25 10:00 [pve-devel] [RFC storage/qemu-server] Thin provisioning on LVM Joao Sousa via pve-devel
2025-07-25 14:46 ` Tiago Sousa via pve-devel
2025-08-02 16:42 ` [pve-devel] [PATCH qemu-server 0/2] set write threshold logic Tiago Sousa via pve-devel
2025-08-04 9:14 ` Fiona Ebner
2025-08-11 20:34 ` Joao Sousa via pve-devel
[not found] ` <20250802164240.21751-1-joao.sousa@eurotux.com>
2025-08-02 16:42 ` Tiago Sousa via pve-devel [this message]
2025-08-02 16:42 ` [pve-devel] [PATCH qemu-server 2/2] qmeventd: add block write threshold event handling 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.533.1754152977.367.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