[PATCH v2 2/2] rust: add a wrapper for the `nr_online_nodes` C function
From: Andreas Hindborg
Date: Fri Jun 05 2026 - 08:59:01 EST
This function returns the number of online NUMA nodes.
The wrapper is needed by the Rust null block driver.
Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
---
rust/kernel/lib.rs | 1 +
rust/kernel/numa.rs | 19 +++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index b72b2fbe046d..00713b2adcac 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -97,6 +97,7 @@
#[cfg(CONFIG_NET)]
pub mod net;
pub mod num;
+pub mod numa;
pub mod of;
#[cfg(CONFIG_PM_OPP)]
pub mod opp;
diff --git a/rust/kernel/numa.rs b/rust/kernel/numa.rs
new file mode 100644
index 000000000000..760db072a6c1
--- /dev/null
+++ b/rust/kernel/numa.rs
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! NUMA topology utilities.
+//!
+//! C header: [`include/linux/nodemask.h`](srctree/include/linux/nodemask.h)
+
+use crate::bindings;
+
+/// Returns the number of online NUMA nodes.
+#[inline]
+pub fn num_online_nodes() -> u32 {
+ // NOTE: In some configurations, we can read this variable without an unsafe block.
+ // SAFETY: When NUMA is enabled, this is a global mutable static. We do as C and just read it,
+ // even though it might race.
+ #[allow(unused_unsafe)]
+ unsafe {
+ bindings::nr_online_nodes
+ }
+}
--
2.51.2