Skip to content

Conversation

@cgwalters
Copy link
Collaborator

Closes: #61

@gemini-code-assist
Copy link

Summary of Changes

Hello @cgwalters, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances bcvk's compatibility with libvirt by introducing robust support for the qemu:///system connection URI. This is achieved through an adaptive base disk creation mechanism that handles scenarios where direct file system access to libvirt storage pools is restricted, and by standardizing virsh command execution for improved reliability. The changes also include new integration tests to validate qemu:///system functionality.

Highlights

  • Support for qemu:///system Libvirt URI: The core change enables bcvk to interact with the system-wide libvirt daemon, which often runs with different permissions than user-level qemu:///session. This is achieved by passing the LIBVIRT_DEFAULT_URI environment variable to virsh commands.
  • Adaptive Base Disk Creation: Implemented a new strategy for creating base disks. If bcvk lacks direct write access to the libvirt storage pool directory (common with qemu:///system), it now creates the disk in a temporary user-writable location and then uploads it to libvirt using virsh vol-upload.
  • Standardized virsh XML Command Execution: Introduced a run_virsh_xml helper function to centralize the execution and XML parsing of virsh commands, improving code consistency and error handling across various libvirt-related operations.
  • Integration Test Coverage: Added a new just target (test-integration-system) to specifically run integration tests against qemu:///system, ensuring the new functionality is thoroughly tested in this environment.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds significant functionality by supporting qemu:///system libvirt connections, which is crucial for environments where the user lacks direct write access to the libvirt storage pool. The approach of using virsh commands for all volume management and introducing a fallback path for disk creation via virsh vol-upload is robust and well-implemented. The refactoring to centralize virsh XML command execution is also a good improvement. I have identified some issues in the new integration tests regarding incorrect command argument ordering and a potential improvement for temporary file handling to enhance robustness. Overall, this is a solid and valuable contribution.

Comment on lines 37 to 42
let mut vm1_cmd = Command::new("timeout");
vm1_cmd.args(["300s", &bck, "libvirt", "run"]);
for arg in &connect_args {
vm1_cmd.arg(arg);
}
vm1_cmd.args(["--name", &vm1_name, "--filesystem", "ext4", &test_image]);
let vm1_output = vm1_cmd.output().expect("Failed to create first VM");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The --connect argument is a global option for the bcvk libvirt subcommand and should be placed before the run subcommand. The current argument order is incorrect and will cause the test to fail when LIBVIRT_DEFAULT_URI is set.

Suggested change
let mut vm1_cmd = Command::new("timeout");
vm1_cmd.args(["300s", &bck, "libvirt", "run"]);
for arg in &connect_args {
vm1_cmd.arg(arg);
}
vm1_cmd.args(["--name", &vm1_name, "--filesystem", "ext4", &test_image]);
let vm1_output = vm1_cmd.output().expect("Failed to create first VM");
let mut vm1_cmd = Command::new("timeout");
vm1_cmd.args(["300s", &bck, "libvirt"]);
vm1_cmd.args(&connect_args);
vm1_cmd.arg("run");
vm1_cmd.args(["--name", &vm1_name, "--filesystem", "ext4", &test_image]);
let vm1_output = vm1_cmd.output().expect("Failed to create first VM");

Comment on lines 66 to 70
let mut vm2_cmd = Command::new("timeout");
vm2_cmd.args(["300s", &bck, "libvirt", "run"]);
for arg in &connect_args {
vm2_cmd.arg(arg);
}
vm2_cmd.args(["--name", &vm2_name, "--filesystem", "ext4", &test_image]);
let vm2_output = vm2_cmd.output().expect("Failed to create second VM");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to the previous command construction, the --connect argument for bcvk libvirt is misplaced. It should appear before the run subcommand to be parsed correctly as a global option for libvirt.

Suggested change
let mut vm2_cmd = Command::new("timeout");
vm2_cmd.args(["300s", &bck, "libvirt", "run"]);
for arg in &connect_args {
vm2_cmd.arg(arg);
}
vm2_cmd.args(["--name", &vm2_name, "--filesystem", "ext4", &test_image]);
let vm2_output = vm2_cmd.output().expect("Failed to create second VM");
let mut vm2_cmd = Command::new("timeout");
vm2_cmd.args(["300s", &bck, "libvirt"]);
vm2_cmd.args(&connect_args);
vm2_cmd.arg("run");
vm2_cmd.args(["--name", &vm2_name, "--filesystem", "ext4", &test_image]);
let vm2_output = vm2_cmd.output().expect("Failed to create second VM");

Comment on lines 104 to 106
let mut cmd = Command::new(&bck);
cmd.args(["libvirt", "base-disks", "list"]);
for arg in &connect_args {
cmd.arg(arg);
}
let output = cmd.output().expect("Failed to run base-disks list");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The --connect argument should be provided before the base-disks subcommand for bcvk libvirt. The current ordering is incorrect.

Suggested change
let mut cmd = Command::new(&bck);
cmd.args(["libvirt", "base-disks", "list"]);
for arg in &connect_args {
cmd.arg(arg);
}
let output = cmd.output().expect("Failed to run base-disks list");
let mut cmd = Command::new(&bck);
cmd.arg("libvirt");
cmd.args(&connect_args);
cmd.args(["base-disks", "list"]);
let output = cmd.output().expect("Failed to run base-disks list");

Comment on lines 146 to 149
let mut cmd = Command::new(&bck);
cmd.args(["libvirt", "base-disks", "prune", "--dry-run"]);
for arg in &connect_args {
cmd.arg(arg);
}
let output = cmd
.output()
.expect("Failed to run base-disks prune --dry-run");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The --connect argument is misplaced. It should be a global option for the libvirt subcommand, placed before the base-disks subcommand.

Suggested change
let mut cmd = Command::new(&bck);
cmd.args(["libvirt", "base-disks", "prune", "--dry-run"]);
for arg in &connect_args {
cmd.arg(arg);
}
let output = cmd
.output()
.expect("Failed to run base-disks prune --dry-run");
let mut cmd = Command::new(&bck);
cmd.arg("libvirt");
cmd.args(&connect_args);
cmd.args(["base-disks", "prune", "--dry-run"]);
let output = cmd
.output()
.expect("Failed to run base-disks prune --dry-run");

Comment on lines 196 to 197
let mut vm_cmd = Command::new("timeout");
vm_cmd.args(["300s", &bck, "libvirt", "run"]);
for arg in &connect_args {
vm_cmd.arg(arg);
}
vm_cmd.args(["--name", &vm_name, "--filesystem", "ext4", &test_image]);
let output = vm_cmd.output().expect("Failed to create VM");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The --connect argument for bcvk libvirt is a global option and should be placed before the run subcommand.

Suggested change
let mut vm_cmd = Command::new("timeout");
vm_cmd.args(["300s", &bck, "libvirt", "run"]);
for arg in &connect_args {
vm_cmd.arg(arg);
}
vm_cmd.args(["--name", &vm_name, "--filesystem", "ext4", &test_image]);
let output = vm_cmd.output().expect("Failed to create VM");
let mut vm_cmd = Command::new("timeout");
vm_cmd.args(["300s", &bck, "libvirt"]);
vm_cmd.args(&connect_args);
vm_cmd.arg("run");
vm_cmd.args(["--name", &vm_name, "--filesystem", "ext4", &test_image]);
let output = vm_cmd.output().expect("Failed to create VM");

Comment on lines 268 to 267
let mut cleanup_cmd = Command::new(&bck);
cleanup_cmd.args(&["libvirt", "rm", domain_name]);
for arg in &connect_args {
cleanup_cmd.arg(arg);
}
cleanup_cmd.args(&["--force", "--stop"]);
let cleanup_output = cleanup_cmd.output();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The --connect argument for bcvk libvirt is misplaced. It should be provided before the rm subcommand.

Suggested change
let mut cleanup_cmd = Command::new(&bck);
cleanup_cmd.args(&["libvirt", "rm", domain_name]);
for arg in &connect_args {
cleanup_cmd.arg(arg);
}
cleanup_cmd.args(&["--force", "--stop"]);
let cleanup_output = cleanup_cmd.output();
let mut cleanup_cmd = Command::new(&bck);
cleanup_cmd.arg("libvirt");
cleanup_cmd.args(&connect_args);
cleanup_cmd.args(&["rm", domain_name, "--force", "--stop"]);
let cleanup_output = cleanup_cmd.output();

Comment on lines 264 to 272
let timestamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_nanos())
.unwrap_or(0);
let temp_disk_path = temp_dir.join(format!(
"bcvk-base-disk-{}-{}.qcow2",
std::process::id(),
timestamp
));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The manual construction of a temporary file path using PID and timestamp is not fully robust against race conditions and is inconsistent with the create_base_disk function, which uses the tempfile crate. Using tempfile::Builder would be safer and also simplifies cleanup logic, as the temporary file would be automatically removed when it goes out of scope. This would allow removing the manual fs::remove_file calls elsewhere in this function.

Suggested change
let timestamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_nanos())
.unwrap_or(0);
let temp_disk_path = temp_dir.join(format!(
"bcvk-base-disk-{}-{}.qcow2",
std::process::id(),
timestamp
));
let temp_file = tempfile::Builder::new()
.prefix("bcvk-base-disk-")
.suffix(".qcow2")
.tempfile_in(&temp_dir)
.with_context(|| format!("Failed to create temp file in {:?}", temp_dir))?;
let temp_disk_path = Utf8PathBuf::from_path_buf(temp_file.path().to_path_buf())
.map_err(|p| eyre!("temp path is not UTF-8: {:?}", p))?;

Closes: bootc-dev#61
Signed-off-by: Colin Walters <[email protected]>
With a helper fn.

Signed-off-by: Colin Walters <[email protected]>
@cgwalters cgwalters marked this pull request as draft October 27, 2025 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle qemu:///system with podman rootless

1 participant