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 346211FF161 for ; Sat, 2 Aug 2025 18:41:41 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 975B7944E; Sat, 2 Aug 2025 18:42:59 +0200 (CEST) To: pve-devel@lists.proxmox.com Date: Sat, 2 Aug 2025 17:42:39 +0100 In-Reply-To: <20250802164240.21751-1-joao.sousa@eurotux.com> References: <20250802164240.21751-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 1/2] blockdev: add set write threshold Content-Type: multipart/mixed; boundary="===============5977362408358943127==" Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" --===============5977362408358943127== 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 43E7AD09E7 for ; Sat, 2 Aug 2025 18:42:57 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2E40391FF for ; Sat, 2 Aug 2025 18:42:57 +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 ; Sat, 2 Aug 2025 18:42:56 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by eurotux.com (Postfix) with ESMTP id 322BC30C99C7; Sat, 2 Aug 2025 17:42:56 +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=1754152975; x=1755967376; bh=vCyMripDJk8VEITpqktCeQq9 Bs2CDdQRmLsyLRFpx7E=; b=ewsS0Y3GT0BOTzcsq9J/ocuFnPbQj3Eo9k6Aounl CDzkX1vBe4v3LZ2EI//IoW1Z8v3dTFh5iFw261vQieJFcDJjY/KPUXo9l9teAF3a 34w0Y04a60Yg03BckXTMR50TPYjhfVmwyqBN21GHKJ2/nj9cEOWq/K8ue26XkNP5 9cS9O1jglzwSYQvpz3PRhUtEx+ReLOl7ktyJAbCZtmfoSXrLmkW/Aapo8JFRkeI7 6ujeq7GAFe8ckqJmn78BwzFMMQEErtUwaoR7imB8nzNrSAuhCaC5EyJuGqsZ6W/F iXxeRu/Qz1iaxLOXSMbMHvME9w6vLzkygHp/9686gC0Rpw== 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 apOWmV3ID59k; Sat, 2 Aug 2025 17:42:55 +0100 (WEST) Received: from proxmox.example (unknown [161.230.225.89]) (Authenticated sender: joao.sousa@eurotux.com) by eurotux.com (Postfix) with ESMTPSA id 8FFA930CA7E0; Sat, 2 Aug 2025 17:42:55 +0100 (WEST) From: Tiago Sousa 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> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250802164240.21751-1-joao.sousa@eurotux.com> References: <20250802164240.21751-1-joao.sousa@eurotux.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.042 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) RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_PASS -0.001 SPF: HELO matches SPF record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [blockdev.pm,eurotux.com] Signed-off-by: Tiago Sousa --- 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; } =20 + set_write_threshold($storecfg, $vmid, $drive, $options); + return $blockdev->{'node-name'}; } =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 ($scfg, $volid) =3D @_; + my $lv_size =3D PVE::Storage::volume_size_info($scfg, $volid, 5); + + # FIX: change these vars to config inputs + my $chunksize =3D 1024 * 1024 * 1024; # 1 GB + my $alert_chunk_percentage =3D 0.5; # alert when percetage of chunk = used + + my $write_threshold =3D $lv_size - $chunksize * (1 - $alert_chunk_pe= rcentage); + + return $write_threshold; +} + +sub set_write_threshold { + my ($storecfg, $vmid, $drive, $options) =3D @_; + + my $volid =3D $drive->{'file'}; + my ($storeid) =3D PVE::Storage::parse_volume_id($volid); + my $support_qemu_snapshots =3D PVE::Storage::volume_qemu_snapshot_me= thod($storecfg, $volid); + my $scfg =3D 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 'mixe= d'; + + my $snapshots =3D PVE::Storage::volume_snapshot_info($storecfg, $vol= id); + my $parentid =3D $snapshots->{'current'}->{parent}; + # for now only set write_threshold for volumes that have snapshots + if ($parentid) { + my $drive_id =3D PVE::QemuServer::Drive::get_drive_id($drive); + my $nodename =3D get_node_name('file', $drive_id, $drive->{file}= , $options); + my $write_threshold =3D compute_write_threshold($scfg, $volid); + + block_set_write_threshold($vmid, $nodename, $write_threshold); + } +} + =3Dpod =20 =3Dhead3 detach --=20 2.39.5 --===============5977362408358943127== 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 --===============5977362408358943127==--