From 4534b331e48ddb436939a6a46ed829673bedd846 Mon Sep 17 00:00:00 2001 From: Thanos Makatos Date: Fri, 7 Aug 2026 09:48:47 +0000 Subject: [PATCH] add dedicated D-Bus version method Signed-off-by: Thanos Makatos --- src/controller.rs | 31 ++++++++++++++++++++----------- src/daemon.rs | 10 ++++++++++ src/dbus.rs | 20 ++++++++++++++++++++ src/main.rs | 7 ++++++- 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/controller.rs b/src/controller.rs index e6b83a2..59e2557 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -278,6 +278,9 @@ impl Controller { DbusRequest::GetSnapshot { reply } => { let _ = reply.send(self.handle_get_snapshot().await); } + DbusRequest::GetVersion { reply } => { + let _ = reply.send(env!("CARGO_PKG_VERSION").to_string()); + } DbusRequest::GetIoThreadVqMapping { vm, device, reply } => { let result = match self.instances.get(&vm) { Some(instance) => instance @@ -559,8 +562,10 @@ impl Controller { .await; tracing::info!( target: "controller", - id = %instance.id, - "" + event = "scale_blocked", + reason = "manual_override", + vm = %instance.id, + action = %action ); return Ok(()); } @@ -570,8 +575,10 @@ impl Controller { .await; tracing::info!( target: "controller", - id = %instance.id, - "" + event = "scale_blocked", + reason = "unmanaged_vm", + vm = %instance.id, + action = %action ); return Ok(()); } @@ -664,10 +671,12 @@ impl Controller { .await; tracing::info!( target: "controller", - id = %instance.id, - %action, + event = "scale_applied", + vm = %instance.id, + action = %action, target, - "" + prev_thread_count = previous_count, + prev_io_count_total = previous_io_count ); } Err(error) => { @@ -677,11 +686,11 @@ impl Controller { .await; tracing::warn!( target: "controller", - id = %instance.id, - %action, + event = "scale_failed", + vm = %instance.id, + action = %action, target, - error = %error_text, - "" + error = %error_text ); } } diff --git a/src/daemon.rs b/src/daemon.rs index d9e1cb0..d72d8d5 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -12,6 +12,11 @@ use inotify::{Inotify, WatchMask}; use thiserror::Error; use tokio::time::{MissedTickBehavior, interval}; +pub const VERSION: &str = match option_env!("IO_THREAD_CONTROLLER_VERSION") { + Some(v) => v, + None => "unknown", +}; + use crate::{ backends::Backend, config::Config, @@ -48,6 +53,11 @@ const INOTIFY_EVENT_BUF_SIZE: usize = 32 * 1024; /// Run until SIGTERM or SIGINT. pub async fn run(cfg: Config, backends: Vec>) -> Result<(), DaemonError> { + tracing::info!( + target: "controller", + version = VERSION, + "io-thread-controller starting" + ); if cfg.print_status_header { tracing::info!( target: "status", diff --git a/src/dbus.rs b/src/dbus.rs index 34eee3f..fa9cbf2 100644 --- a/src/dbus.rs +++ b/src/dbus.rs @@ -12,6 +12,7 @@ //! Verbs currently exposed: //! * debug-only `SetThreadCount(vm, threads, sticky)`; //! * read-only `GetStats()`; +//! * read-only `GetVersion()`; //! * named-IOThread and virtqueue-mapping operations for clients that support //! them. @@ -62,6 +63,11 @@ pub enum DbusRequest { /// [`crate::controller::SnapshotPayload`] on success. reply: oneshot::Sender, }, + /// Return the controller binary version string. + GetVersion { + /// Reply channel carrying the version string. + reply: oneshot::Sender, + }, /// Read the current virtqueue-to-IOThread mapping. GetIoThreadVqMapping { /// Instance / vm id to address. @@ -190,6 +196,20 @@ impl Service { await_with_timeout(rx).await } + /// D-Bus wire signature: `GetVersion() -> s`. + /// + /// Returns the controller binary version string (same source as startup + /// logs), exposed separately so high-frequency snapshot payloads stay + /// focused on dynamic metrics. + async fn get_version(&self) -> zbus::fdo::Result { + let (tx, rx) = oneshot::channel(); + self.tx + .send(DbusRequest::GetVersion { reply: tx }) + .await + .map_err(|_| zbus::fdo::Error::Failed("controller channel closed".into()))?; + await_with_timeout(rx).await + } + async fn get_io_thread_vq_mapping( &self, vm: String, diff --git a/src/main.rs b/src/main.rs index f011b6a..dd0a159 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use io_thread_controller::{ backends::BackendClientError, backends::registered_backends, config::{Config, ConfigError, dump_default_config, load_config, validate_config}, - daemon::{DaemonError, run}, + daemon::{DaemonError, VERSION, run}, util::Path, }; use thiserror::Error; @@ -37,6 +37,11 @@ enum IoThreadControllerError { #[derive(Debug, Parser)] #[command( + // Populated at build time by `build.rs` from the git tree + // (short hash, with `-dirty` when the tree had uncommitted + // changes). Falls back to `CARGO_PKG_VERSION` for tarball + // builds where `.git` is absent. + version = VERSION, name = "io-thread-controller", about = "Measure VM I/O workers and resize their pools through a selectable scaling engine." )]