From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox v4 2/2] resource-scheduling: allow owned nodes slice for score_nodes_to_start_service
Date: Fri, 14 Nov 2025 11:06:14 +0100 [thread overview]
Message-ID: <20251114100641.92919-3-d.kral@proxmox.com> (raw)
In-Reply-To: <20251114100641.92919-1-d.kral@proxmox.com>
This is needed to allow StaticNodeUsage to be passed as a owned value in
PVE::RS::ResourceScheduling::Static::score_nodes_to_start_service.
Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
changes since v3:
- remove R-b from Fiona because...
- do not change the signature of score_nodes_to_start_service but
generic to accept nodes as &[T] where T: AsRef<StaticNodeUsage>
- doesn't need a versioned break anymore
proxmox-resource-scheduling/src/pve_static.rs | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/proxmox-resource-scheduling/src/pve_static.rs b/proxmox-resource-scheduling/src/pve_static.rs
index d39614cd..b81086dd 100644
--- a/proxmox-resource-scheduling/src/pve_static.rs
+++ b/proxmox-resource-scheduling/src/pve_static.rs
@@ -27,6 +27,12 @@ impl StaticNodeUsage {
}
}
+impl AsRef<StaticNodeUsage> for StaticNodeUsage {
+ fn as_ref(&self) -> &Self {
+ self
+ }
+}
+
/// Calculate new CPU usage in percent.
/// `add` being `0.0` means "unlimited" and results in `max` being added.
fn add_cpu_usage(old: f64, max: f64, add: f64) -> f64 {
@@ -69,8 +75,8 @@ criteria_struct! {
///
/// Returns a vector of (nodename, score) pairs. Scores are between 0.0 and 1.0 and a higher score
/// is better.
-pub fn score_nodes_to_start_service(
- nodes: &[&StaticNodeUsage],
+pub fn score_nodes_to_start_service<T: AsRef<StaticNodeUsage>>(
+ nodes: &[T],
service: &StaticServiceUsage,
) -> Result<Vec<(String, f64)>, Error> {
let len = nodes.len();
@@ -86,6 +92,7 @@ pub fn score_nodes_to_start_service(
let mut squares_mem = 0.0;
for (index, node) in nodes.iter().enumerate() {
+ let node = node.as_ref();
let new_cpu = if index == target_index {
add_cpu_usage(node.cpu, node.maxcpu as f64, service.maxcpu)
} else {
@@ -122,6 +129,6 @@ pub fn score_nodes_to_start_service(
Ok(scores
.into_iter()
.enumerate()
- .map(|(n, score)| (nodes[n].name.clone(), score))
+ .map(|(n, score)| (nodes[n].as_ref().name.clone(), score))
.collect())
}
--
2.47.3
_______________________________________________
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-11-14 10:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 10:06 [pve-devel] [PATCH-SERIES ha-manager/perl-rs/proxmox v4 00/12] Granular online_node_usage accounting Daniel Kral
2025-11-14 10:06 ` [pve-devel] [PATCH proxmox v4 1/2] resource-scheduling: use workspace's .cargo/config.toml Daniel Kral
2025-11-14 10:06 ` Daniel Kral [this message]
2025-11-14 10:06 ` [pve-devel] [PATCH perl-rs v4 1/2] pve-rs: resource scheduling: allow granular usage changes Daniel Kral
2025-11-14 10:06 ` [pve-devel] [PATCH perl-rs v4 2/2] test: resource_scheduling: use score_nodes helper to imitate HA Manager Daniel Kral
2025-11-14 10:06 ` [pve-devel] [PATCH ha-manager v4 1/8] manager: remove redundant recompute_online_node_usage from next_state_recovery Daniel Kral
2025-11-14 10:06 ` [pve-devel] [PATCH ha-manager v4 2/8] manager: remove redundant add_service_usage_to_node " Daniel Kral
2025-11-14 10:06 ` [pve-devel] [PATCH ha-manager v4 3/8] manager: remove redundant add_service_usage_to_node from next_state_started Daniel Kral
2025-11-14 10:06 ` [pve-devel] [PATCH ha-manager v4 4/8] rules: resource affinity: decouple get_resource_affinity helper from Usage class Daniel Kral
2025-11-14 10:06 ` [pve-devel] [PATCH ha-manager v4 5/8] manager: make recompute_online_node_usage use add_service_usage helper Daniel Kral
2025-11-14 10:06 ` [pve-devel] [PATCH ha-manager v4 6/8] usage: allow granular changes to Usage implementations Daniel Kral
2025-11-14 10:06 ` [pve-devel] [PATCH ha-manager v4 7/8] manager: make online node usage computation granular Daniel Kral
2025-11-14 10:06 ` [pve-devel] [PATCH ha-manager v4 8/8] implement static service stats cache Daniel Kral
2025-11-14 12:57 ` [pve-devel] applied-series: [PATCH-SERIES ha-manager/perl-rs/proxmox v4 00/12] Granular online_node_usage accounting Thomas Lamprecht
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=20251114100641.92919-3-d.kral@proxmox.com \
--to=d.kral@proxmox.com \
--cc=pve-devel@lists.proxmox.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