Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target/
target/
.flox
55 changes: 34 additions & 21 deletions crates/bcvk-qemu/src/virtiofsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub struct VirtiofsConfig {
pub readonly: bool,
/// Optional log file path for virtiofsd output.
pub log_file: Option<Utf8PathBuf>,
/// Optional explicit path to virtiofsd binary (overrides auto-detection).
pub virtiofsd_binary: Option<Utf8PathBuf>,
}

impl Default for VirtiofsConfig {
Expand All @@ -32,6 +34,7 @@ impl Default for VirtiofsConfig {
// We don't need to write to this, there's a transient overlay
readonly: true,
log_file: None,
virtiofsd_binary: None,
}
}
}
Expand Down Expand Up @@ -61,32 +64,42 @@ pub async fn spawn_virtiofsd_async(config: &VirtiofsConfig) -> Result<tokio::pro
// Validate configuration
validate_virtiofsd_config(config)?;

// Try common virtiofsd binary locations
let virtiofsd_paths = [
"/usr/libexec/virtiofsd",
"/usr/bin/virtiofsd",
"/usr/local/bin/virtiofsd",
"/usr/lib/virtiofsd",
];

let virtiofsd_binary = virtiofsd_paths
.iter()
.find(|path| std::path::Path::new(path).exists())
.ok_or_else(|| {
eyre!(
"virtiofsd binary not found. Searched paths: {}. Please install virtiofsd.",
virtiofsd_paths.join(", ")
)
})?;
// Resolve virtiofsd binary: explicit override or path search
let virtiofsd_binary: String = if let Some(ref path) = config.virtiofsd_binary {
if !path.exists() {
return Err(eyre!("Explicit virtiofsd binary not found at: {}", path));
}
camino::absolute_utf8(path)?.to_string()
} else {
// Try common virtiofsd binary locations
let virtiofsd_paths = [
"/usr/libexec/virtiofsd",
"/usr/bin/virtiofsd",
"/usr/local/bin/virtiofsd",
"/usr/lib/virtiofsd",
];

virtiofsd_paths
.iter()
.find(|path| std::path::Path::new(path).exists())
.ok_or_else(|| {
eyre!(
"virtiofsd binary not found. Searched paths: {}. \
Set --virtiofsd or VIRTIOFSD_BIN to specify the path explicitly.",
virtiofsd_paths.join(", ")
)
})?
.to_string()
};

// Check if virtiofsd supports --readonly flag
let supports_readonly = virtiofsd_supports_readonly(virtiofsd_binary).await;
let supports_readonly = virtiofsd_supports_readonly(&virtiofsd_binary).await;
debug!(
"virtiofsd at {} supports --readonly: {}",
virtiofsd_binary, supports_readonly
);

let mut cmd = tokio::process::Command::new(virtiofsd_binary);
let mut cmd = tokio::process::Command::new(&virtiofsd_binary);
// SAFETY: This API is safe to call in a forked child.
#[allow(unsafe_code)]
unsafe {
Expand Down Expand Up @@ -148,13 +161,13 @@ pub async fn spawn_virtiofsd_async(config: &VirtiofsConfig) -> Result<tokio::pro
let child = cmd.spawn().with_context(|| {
format!(
"Failed to spawn virtiofsd. Binary: {}, Socket: {}, Shared dir: {}",
virtiofsd_binary, config.socket_path, config.shared_dir
&virtiofsd_binary, config.socket_path, config.shared_dir
)
})?;

debug!(
"Spawned virtiofsd: binary={}, socket={}, shared_dir={}, debug={}, log_file={:?}",
virtiofsd_binary, config.socket_path, config.shared_dir, config.debug, config.log_file
&virtiofsd_binary, config.socket_path, config.shared_dir, config.debug, config.log_file
);

Ok(child)
Expand Down
2 changes: 1 addition & 1 deletion crates/kit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ base64 = "0.22"
chrono = { version = "0.4", features = ["serde"] }
const_format = { workspace = true }
color-eyre = { workspace = true }
clap = { version = "4.4", features = ["derive"] }
clap = { version = "4.4", features = ["derive", "env"] }
clap_mangen = { version = "0.2.20", optional = true }
data-encoding = { version = "2.9" }
dirs = "5.0"
Expand Down
4 changes: 4 additions & 0 deletions crates/kit/src/libvirt/base_disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub fn find_or_create_base_disk(
image_digest: &str,
install_options: &InstallOptions,
connect_uri: Option<&str>,
virtiofsd_binary: Option<String>,
) -> Result<Utf8PathBuf> {
let metadata = DiskImageMetadata::from(install_options, image_digest, source_image);
let cache_hash = metadata.compute_cache_hash();
Expand Down Expand Up @@ -67,6 +68,7 @@ pub fn find_or_create_base_disk(
image_digest,
install_options,
connect_uri,
virtiofsd_binary,
)?;

Ok(base_disk_path)
Expand All @@ -79,6 +81,7 @@ fn create_base_disk(
image_digest: &str,
install_options: &InstallOptions,
connect_uri: Option<&str>,
virtiofsd_binary: Option<String>,
) -> Result<()> {
use crate::run_ephemeral::CommonVmOpts;
use crate::to_disk::{Format, ToDiskAdditionalOpts, ToDiskOpts};
Expand Down Expand Up @@ -116,6 +119,7 @@ fn create_base_disk(
memory: crate::common_opts::MemoryOpts {
memory: super::LIBVIRT_DEFAULT_MEMORY.to_string(),
},
virtiofsd_binary,
..Default::default()
},
..Default::default()
Expand Down
1 change: 1 addition & 0 deletions crates/kit/src/libvirt/base_disks_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub fn run_create(
&image_digest,
&opts.install_options,
connect_uri,
None,
)?;
println!("Created base disk: {path}");

Expand Down
5 changes: 5 additions & 0 deletions crates/kit/src/libvirt/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ pub struct LibvirtRunOpts {
#[clap(long = "ignition")]
pub ignition_config: Option<Utf8PathBuf>,

/// Path to virtiofsd binary (overrides auto-detection for disk creation)
#[clap(long = "virtiofsd", env = "VIRTIOFSD_BIN")]
pub virtiofsd_binary: Option<String>,

/// Additional metadata key-value pairs (used internally, not exposed via CLI)
#[clap(skip)]
pub metadata: std::collections::HashMap<String, String>,
Expand Down Expand Up @@ -488,6 +492,7 @@ pub fn run(global_opts: &crate::libvirt::LibvirtOptions, mut opts: LibvirtRunOpt
&image_digest,
&opts.install,
connect_uri,
opts.virtiofsd_binary.take(),
)
.with_context(|| "Failed to find or create base disk")?;

Expand Down
9 changes: 9 additions & 0 deletions crates/kit/src/run_ephemeral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ pub struct CommonVmOpts {
help = "Generate SSH keypair and inject via systemd credentials"
)]
pub ssh_keygen: bool,

#[clap(
long = "virtiofsd",
env = "VIRTIOFSD_BIN",
help = "Path to virtiofsd binary (overrides auto-detection)"
)]
pub virtiofsd_binary: Option<String>,
Comment thread
nickryand marked this conversation as resolved.
}

impl CommonVmOpts {
Expand Down Expand Up @@ -1171,6 +1178,7 @@ pub(crate) async fn run_impl(opts: RunEphemeralOpts) -> Result<()> {
debug: false,
readonly: is_readonly,
log_file: Some(format!("/run/virtiofsd-{}.log", mount_name_str).into()),
virtiofsd_binary: opts.common.virtiofsd_binary.as_deref().map(Into::into),
};
additional_mounts.push((virtiofsd_config, tag.clone()));

Expand Down Expand Up @@ -1329,6 +1337,7 @@ StandardOutput=file:/dev/virtio-ports/executestatus
main_virtiofsd_config.debug = std::env::var("DEBUG_MODE").is_ok();
// Always log virtiofsd output for debugging
main_virtiofsd_config.log_file = Some("/run/virtiofsd.log".into());
main_virtiofsd_config.virtiofsd_binary = opts.common.virtiofsd_binary.as_deref().map(Into::into);

std::fs::create_dir_all(CONTAINER_STATEDIR)?;

Expand Down