main: cli: add D-Bus API related CLI options

Introduces three new CLI options, `dbus-service-name`,
`dbus-object-path` and `dbus-system-bus` to configure the DBus API.

Signed-off-by: Omer Faruk Bayram <omer.faruk@sartura.hr>
This commit is contained in:
Omer Faruk Bayram
2023-04-05 15:22:05 +03:00
committed by Bo Chen
parent a92d852848
commit 7a458d85d1
3 changed files with 72 additions and 15 deletions

View File

@@ -20,6 +20,12 @@ use zbus::{dbus_interface, ConnectionBuilder};
pub type DBusApiShutdownChannels = (oneshot::Sender<()>, oneshot::Receiver<()>);
pub struct DBusApiOptions {
pub service_name: String,
pub object_path: String,
pub system_bus: bool,
}
pub struct DBusApi {
api_notifier: EventFd,
api_sender: futures::lock::Mutex<Sender<ApiRequest>>,
@@ -278,8 +284,8 @@ impl DBusApi {
}
}
// TODO: add command line arguments to make this configurable
pub fn start_dbus_thread(
dbus_options: DBusApiOptions,
api_notifier: EventFd,
api_sender: Sender<ApiRequest>,
seccomp_action: &SeccompAction,
@@ -288,10 +294,16 @@ pub fn start_dbus_thread(
) -> VmmResult<(thread::JoinHandle<VmmResult<()>>, DBusApiShutdownChannels)> {
let dbus_iface = DBusApi::new(api_notifier, api_sender);
let connection = executor::block_on(async move {
ConnectionBuilder::session()?
let conn_builder = if dbus_options.system_bus {
ConnectionBuilder::system()?
} else {
ConnectionBuilder::session()?
};
conn_builder
.internal_executor(false)
.name("org.cloudhypervisor.DBusApi")?
.serve_at("/org/cloudhypervisor/DBusApi", dbus_iface)?
.name(dbus_options.service_name)?
.serve_at(dbus_options.object_path, dbus_iface)?
.build()
.await
})

View File

@@ -26,7 +26,7 @@ use crate::seccomp_filters::{get_seccomp_filter, Thread};
use crate::vm::{Error as VmError, Vm, VmState};
use anyhow::anyhow;
#[cfg(feature = "dbus_api")]
use api::dbus::DBusApiShutdownChannels;
use api::dbus::{DBusApiOptions, DBusApiShutdownChannels};
use libc::{tcsetattr, termios, EFD_NONBLOCK, SIGINT, SIGTERM, TCSANOW};
use memory_manager::MemoryManagerSnapshotData;
use pci::PciBdf;
@@ -294,6 +294,7 @@ pub fn start_vmm_thread(
vmm_version: VmmVersionInfo,
http_path: &Option<String>,
http_fd: Option<RawFd>,
#[cfg(feature = "dbus_api")] dbus_options: Option<DBusApiOptions>,
api_event: EventFd,
api_sender: Sender<ApiRequest>,
api_receiver: Receiver<ApiRequest>,
@@ -357,13 +358,20 @@ pub fn start_vmm_thread(
// The VMM thread is started, we can start the dbus thread
// and start serving HTTP requests
#[cfg(feature = "dbus_api")]
let (_, dbus_shutdown_chs) = api::start_dbus_thread(
api_event_clone.try_clone().map_err(Error::EventFdClone)?,
api_sender.clone(),
seccomp_action,
exit_event.try_clone().map_err(Error::EventFdClone)?,
hypervisor_type,
)?;
let dbus_shutdown_chs = match dbus_options {
Some(opts) => {
let (_, chs) = api::start_dbus_thread(
opts,
api_event_clone.try_clone().map_err(Error::EventFdClone)?,
api_sender.clone(),
seccomp_action,
exit_event.try_clone().map_err(Error::EventFdClone)?,
hypervisor_type,
)?;
Some(chs)
}
None => None,
};
if let Some(http_path) = http_path {
api::start_http_path_thread(
@@ -432,7 +440,7 @@ impl VmmVersionInfo {
pub struct VmmThreadHandle {
pub thread_handle: thread::JoinHandle<Result<()>>,
#[cfg(feature = "dbus_api")]
pub dbus_shutdown_chs: DBusApiShutdownChannels,
pub dbus_shutdown_chs: Option<DBusApiShutdownChannels>,
}
pub struct Vmm {