Skip to content

Commit 99cbd4d

Browse files
committed
ephemeral: Add virtiofsd logging for debugging
Add support for logging virtiofsd output to help diagnose filesystem sharing issues between the container and VM. Assisted-By: Claude Code (Sonnet 4.5) Signed-off-by: Colin Walters <[email protected]>
1 parent 1d30aa7 commit 99cbd4d

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

crates/kit/src/qemu.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,8 @@ pub struct VirtiofsConfig {
907907
pub debug: bool,
908908
/// Mount as read-only
909909
pub readonly: bool,
910+
/// Optional log file path for virtiofsd output
911+
pub log_file: Option<Utf8PathBuf>,
910912
}
911913

912914
impl Default for VirtiofsConfig {
@@ -917,6 +919,7 @@ impl Default for VirtiofsConfig {
917919
debug: false,
918920
// We don't need to write to this, there's a transient overlay
919921
readonly: true,
922+
log_file: None,
920923
}
921924
}
922925
}
@@ -998,8 +1001,31 @@ pub async fn spawn_virtiofsd_async(config: &VirtiofsConfig) -> Result<tokio::pro
9981001
// but we want to be compatible with older virtiofsd too.
9991002
cmd.arg("--inode-file-handles=fallback");
10001003

1001-
cmd.stdout(std::process::Stdio::piped());
1002-
cmd.stderr(std::process::Stdio::piped());
1004+
// Configure output redirection
1005+
if let Some(log_file) = &config.log_file {
1006+
// Create/open log file for both stdout and stderr
1007+
let tokio_file = tokio::fs::OpenOptions::new()
1008+
.create(true)
1009+
.append(true)
1010+
.open(log_file)
1011+
.await
1012+
.with_context(|| format!("Failed to open virtiofsd log file: {}", log_file))?;
1013+
1014+
let log_file_handle = tokio_file.into_std().await;
1015+
1016+
// Clone for stderr
1017+
let stderr_handle = log_file_handle
1018+
.try_clone()
1019+
.with_context(|| "Failed to clone log file handle for stderr")?;
1020+
1021+
cmd.stdout(std::process::Stdio::from(log_file_handle));
1022+
cmd.stderr(std::process::Stdio::from(stderr_handle));
1023+
1024+
debug!("virtiofsd output will be logged to: {}", log_file);
1025+
} else {
1026+
cmd.stdout(std::process::Stdio::piped());
1027+
cmd.stderr(std::process::Stdio::piped());
1028+
}
10031029

10041030
let child = cmd.spawn().with_context(|| {
10051031
format!(
@@ -1009,8 +1035,8 @@ pub async fn spawn_virtiofsd_async(config: &VirtiofsConfig) -> Result<tokio::pro
10091035
})?;
10101036

10111037
debug!(
1012-
"Spawned virtiofsd: binary={}, socket={}, shared_dir={}, debug={}",
1013-
virtiofsd_binary, config.socket_path, config.shared_dir, config.debug
1038+
"Spawned virtiofsd: binary={}, socket={}, shared_dir={}, debug={}, log_file={:?}",
1039+
virtiofsd_binary, config.socket_path, config.shared_dir, config.debug, config.log_file
10141040
);
10151041

10161042
Ok(child)

crates/kit/src/run_ephemeral.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ pub(crate) async fn run_impl(opts: RunEphemeralOpts) -> Result<()> {
823823
shared_dir: source_path,
824824
debug: false,
825825
readonly: is_readonly,
826+
log_file: Some(format!("/run/virtiofsd-{}.log", mount_name_str).into()),
826827
};
827828
additional_mounts.push((virtiofsd_config, tag.clone()));
828829

@@ -945,6 +946,8 @@ StandardOutput=file:/dev/virtio-ports/executestatus
945946
// Prepare main virtiofsd config for the source image (will be spawned by QEMU)
946947
let mut main_virtiofsd_config = qemu::VirtiofsConfig::default();
947948
main_virtiofsd_config.debug = std::env::var("DEBUG_MODE").is_ok();
949+
// Always log virtiofsd output for debugging
950+
main_virtiofsd_config.log_file = Some("/run/virtiofsd.log".into());
948951

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

docs/src/man/bcvk-ephemeral-run.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,27 @@ Development workflow example:
173173

174174
# VM automatically cleans up when stopped due to --rm flag
175175

176+
# DEBUGGING
177+
178+
When troubleshooting ephemeral VM issues, bcvk provides debugging logs that can be accessed from within the container.
179+
180+
## Virtiofsd Logs
181+
182+
The virtiofsd daemon logs are written to `/run/virtiofsd.log` and `/run/virtiofsd-<mount-name>.log` for each filesystem mount. These logs show filesystem sharing operations between the container and VM.
183+
184+
To view virtiofsd logs:
185+
186+
# Main virtiofsd log
187+
podman exec <container-id> cat /run/virtiofsd.log
188+
189+
# Logs for additional bind mounts
190+
podman exec <container-id> cat /run/virtiofsd-workspace.log
191+
192+
Virtiofsd logs are helpful for:
193+
- Debugging filesystem access issues
194+
- Understanding file handle support warnings
195+
- Investigating mount-related errors
196+
176197
# SEE ALSO
177198

178199
**bcvk**(8)

0 commit comments

Comments
 (0)