From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 08C9C1FF15C for ; Fri, 17 Oct 2025 13:34:50 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1F3A927F1E; Fri, 17 Oct 2025 13:35:08 +0200 (CEST) To: pve-devel@lists.proxmox.com Date: Fri, 17 Oct 2025 12:25:31 +0100 In-Reply-To: <20251017112539.26471-1-joao.sousa@eurotux.com> References: <20251017112539.26471-1-joao.sousa@eurotux.com> MIME-Version: 1.0 Message-ID: List-Id: Proxmox VE development discussion List-Post: From: Tiago Sousa via pve-devel Precedence: list Cc: Tiago Sousa X-Mailman-Version: 2.1.29 X-BeenThere: pve-devel@lists.proxmox.com List-Subscribe: , List-Unsubscribe: , List-Archive: Reply-To: Proxmox VE development discussion List-Help: Subject: [pve-devel] [PATCH qemu-server 6/8] blockdev: add set write threshold Content-Type: multipart/mixed; boundary="===============2097200311617324600==" Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" --===============2097200311617324600== Content-Type: message/rfc822 Content-Disposition: inline Return-Path: X-Original-To: pve-devel@lists.proxmox.com Delivered-To: pve-devel@lists.proxmox.com Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C91F8D0F19 for ; Fri, 17 Oct 2025 13:35:04 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AD4F027CCB for ; Fri, 17 Oct 2025 13:35:04 +0200 (CEST) Received: from eurotux.com (mail.eurotux.com [185.98.249.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 17 Oct 2025 13:35:03 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by eurotux.com (Postfix) with ESMTP id D7A2730D17C1; Fri, 17 Oct 2025 12:26:04 +0100 (WEST) Authentication-Results: mail.prd.eurotux.pt (amavisd-new); dkim=pass (2048-bit key) reason="pass (just generated, assumed good)" header.d=eurotux.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eurotux.com; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from; s= default; t=1760700362; x=1762514763; bh=2urS6ZfYV8YDQn9cuvsFsJCu Cf2sUdiIJtVE8kHPiGU=; b=qRZ4yTr8wfwuNBDfNL4OByL2YTm1rOSc/NoMcrc2 ZOt9H3+twZWGpxq1LIBjywE23THgUE0wwhzT/AUFDsZbquCHHfaiuM5j3zIlFU+G U1le4pE4g10nIeN1dXpt6fOQ13wBx9+hYTRjZ6nq6FbqfEvn6ofuOrQBLcFnblpc GoLrtX8dX3KqfBTOj3sVyq8qzGvC0JcrMRJOAoNCrqQmq7YC0EQoQionE+ezAXuI bJbN28cWWOYm2vkARyQofrimREnmtxdPyjPVJSccgx6ZvtPAj9zco7mbgweq+yR8 IvOg4wzMBiHUucqd/9OkXmdcfAHRUE0lRS750vfj0nU7Zw== X-Virus-Scanned: amavisd-new at mail.prd.eurotux.pt Received: from eurotux.com ([127.0.0.1]) by localhost (mail.prd.eurotux.pt [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id rOQ5XVjDWm4g; Fri, 17 Oct 2025 12:26:02 +0100 (WEST) Received: from proxmox.example (184.137.90.149.rev.vodafone.pt [149.90.137.184]) (Authenticated sender: joao.sousa@eurotux.com) by eurotux.com (Postfix) with ESMTPSA id 20D5530D17AF; Fri, 17 Oct 2025 12:26:02 +0100 (WEST) From: Tiago Sousa 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> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251017112539.26471-1-joao.sousa@eurotux.com> References: <20251017112539.26471-1-joao.sousa@eurotux.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL -0.001 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain DMARC_PASS -0.1 DMARC pass policy RCVD_IN_MSPIKE_H2 0.001 Average reputation (+2) SPF_HELO_PASS -0.001 SPF: HELO matches SPF record SPF_PASS -0.001 SPF: sender matches SPF record Signed-off-by: Tiago Sousa --- 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 $@; } =20 + # set write threshold for LVM thin provisioning disks + PVE::QemuConfig->foreach_volume( + $conf, + sub { + my ($ds, $drive) =3D @_; + return if PVE::QemuServer::drive_is_cdrom($drive, 1); + my $volid =3D $drive->{file}; + if ( $volid ne 'none') { + my $drive_id =3D PVE::QemuServer::Drive::get_drive_id($d= rive); + my $snapshots =3D PVE::Storage::volume_snapshot_info($st= orecfg, $volid); + my $parentid =3D $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 =3D $migrate_opts->{nbd}) { =20 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 { } } =20 +sub block_set_write_threshold { + my ($vmid, $nodename, $threshold) =3D @_; + + print "set threshold $nodename $threshold\n"; + + PVE::QemuServer::mon_cmd( + $vmid, + "block-set-write-threshold", + 'node-name' =3D> $nodename, + 'write-threshold' =3D> int($threshold), + ); +} + +sub compute_write_threshold { + my ($storecfg, $scfg, $volid) =3D @_; + + my $lv_size =3D PVE::Storage::volume_size_info($storecfg, $volid, 5)= ; + + my $write_threshold =3D $lv_size - $scfg->{chunksize} * $scfg->{'chu= nk-percentage'}; + + return $write_threshold; +} + +sub set_write_threshold { + my ($storecfg, $vmid, $drive_id, $volid, $options) =3D @_; + + my ($storeid) =3D PVE::Storage::parse_volume_id($volid); + my $scfg =3D PVE::Storage::storage_config($storecfg, $storeid); + my $support_qemu_snapshots =3D PVE::Storage::volume_qemu_snapshot_me= thod($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 'mixe= d'; + # return if drive is not set as thin + # return if !$drive->{thin}; + + my $nodename =3D get_node_name('file', $drive_id, $volid, $options); + my $write_threshold =3D compute_write_threshold($storecfg, $scfg, $v= olid); + + 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, $p= arent_snap) =3D @_; =20 @@ -878,6 +921,10 @@ sub blockdev_external_snapshot { node =3D> $snap_fmt_blockdev->{'node-name'}, overlay =3D> $new_fmt_blockdev->{'node-name'}, ); + + # FIX: only if thin + my $drive_id =3D PVE::QemuServer::Drive::get_drive_id($drive); + set_write_threshold($storecfg, $vmid, $drive_id, $volid); } =20 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 =3D ( optional =3D> 1, default =3D> 0, }, + thin =3D> { + type =3D> 'boolean', + description =3D> + 'Controls whether a drive should be thin provisioned', + optional =3D> 1, + default =3D> 0, + }, ); =20 my %iothread_fmt =3D ( --=20 2.47.3 --===============2097200311617324600== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel --===============2097200311617324600==--