-
Notifications
You must be signed in to change notification settings - Fork 11
libvirt: Only inject STORAGE_OPTS when bind-storage-ro is enabled #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -961,12 +961,6 @@ fn create_libvirt_domain_from_disk( | |||||||||||||||||||||||
| // Generate SMBIOS credential for SSH key injection and systemd environment configuration | ||||||||||||||||||||||||
| // Combine SSH key setup and storage opts for systemd contexts | ||||||||||||||||||||||||
| let mut tmpfiles_content = crate::credentials::key_to_root_tmpfiles_d(&public_key_content); | ||||||||||||||||||||||||
| tmpfiles_content.push_str(&crate::credentials::storage_opts_tmpfiles_d_lines()); | ||||||||||||||||||||||||
| let encoded = data_encoding::BASE64.encode(tmpfiles_content.as_bytes()); | ||||||||||||||||||||||||
| let smbios_cred = format!("io.systemd.credential.binary:tmpfiles.extra={encoded}"); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Generate SMBIOS credentials for storage opts unit (handles /etc/environment for PAM/SSH) | ||||||||||||||||||||||||
| let storage_opts_creds = crate::credentials::smbios_creds_for_storage_opts()?; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let memory = opts.resolved_memory_mb()?; | ||||||||||||||||||||||||
| let cpus = opts.resolved_cpus()?; | ||||||||||||||||||||||||
|
|
@@ -1063,8 +1057,8 @@ fn create_libvirt_domain_from_disk( | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Collect mount unit SMBIOS credentials and unit names | ||||||||||||||||||||||||
| let mut mount_unit_smbios_creds = Vec::new(); | ||||||||||||||||||||||||
| // Collect SMBIOS credentials and mount unit names | ||||||||||||||||||||||||
| let mut smbios_creds = Vec::new(); | ||||||||||||||||||||||||
| let mut mount_unit_names = Vec::new(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Process bind mounts (read-write and read-only) | ||||||||||||||||||||||||
|
|
@@ -1073,7 +1067,7 @@ fn create_libvirt_domain_from_disk( | |||||||||||||||||||||||
| "bcvk-bind-", | ||||||||||||||||||||||||
| false, | ||||||||||||||||||||||||
| domain_builder, | ||||||||||||||||||||||||
| &mut mount_unit_smbios_creds, | ||||||||||||||||||||||||
| &mut smbios_creds, | ||||||||||||||||||||||||
| &mut mount_unit_names, | ||||||||||||||||||||||||
| )?; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -1082,7 +1076,7 @@ fn create_libvirt_domain_from_disk( | |||||||||||||||||||||||
| "bcvk-bind-ro-", | ||||||||||||||||||||||||
| true, | ||||||||||||||||||||||||
| domain_builder, | ||||||||||||||||||||||||
| &mut mount_unit_smbios_creds, | ||||||||||||||||||||||||
| &mut smbios_creds, | ||||||||||||||||||||||||
| &mut mount_unit_names, | ||||||||||||||||||||||||
| )?; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -1120,8 +1114,15 @@ fn create_libvirt_domain_from_disk( | |||||||||||||||||||||||
| let encoded_mount = data_encoding::BASE64.encode(mount_unit_content.as_bytes()); | ||||||||||||||||||||||||
| let mount_cred = | ||||||||||||||||||||||||
| format!("io.systemd.credential.binary:systemd.extra-unit.{unit_name}={encoded_mount}"); | ||||||||||||||||||||||||
| mount_unit_smbios_creds.push(mount_cred); | ||||||||||||||||||||||||
| smbios_creds.push(mount_cred); | ||||||||||||||||||||||||
| mount_unit_names.push(unit_name); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Add tmpfiles.d lines and systemd service credentials for STORAGE_OPTS | ||||||||||||||||||||||||
| tmpfiles_content.push_str(&crate::credentials::storage_opts_tmpfiles_d_lines()); | ||||||||||||||||||||||||
| smbios_creds.extend( | ||||||||||||||||||||||||
| crate::credentials::smbios_creds_for_storage_opts() | ||||||||||||||||||||||||
| .context("Failed to generate storage opts credentials")?, | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Create a single dropin for local-fs.target that wants all mount units | ||||||||||||||||||||||||
|
|
@@ -1133,25 +1134,25 @@ fn create_libvirt_domain_from_disk( | |||||||||||||||||||||||
| let dropin_cred = format!( | ||||||||||||||||||||||||
| "io.systemd.credential.binary:systemd.unit-dropin.local-fs.target~bcvk-mounts={encoded_dropin}" | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| mount_unit_smbios_creds.push(dropin_cred); | ||||||||||||||||||||||||
| smbios_creds.push(dropin_cred); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Build QEMU args with all SMBIOS credentials | ||||||||||||||||||||||||
| let mut qemu_args = vec![ | ||||||||||||||||||||||||
| "-smbios".to_string(), | ||||||||||||||||||||||||
| format!("type=11,value={}", smbios_cred), | ||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||
| let mut qemu_args = Vec::new(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Add storage opts credentials (unit + dropin) | ||||||||||||||||||||||||
| for storage_cred in storage_opts_creds { | ||||||||||||||||||||||||
| qemu_args.push("-smbios".to_string()); | ||||||||||||||||||||||||
| qemu_args.push(format!("type=11,value={}", storage_cred)); | ||||||||||||||||||||||||
| // Build QEMU args with all SMBIOS credentials | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| let encoded = data_encoding::BASE64.encode(tmpfiles_content.as_bytes()); | ||||||||||||||||||||||||
| let smbios_cred = format!("io.systemd.credential.binary:tmpfiles.extra={encoded}"); | ||||||||||||||||||||||||
| qemu_args.extend([ | ||||||||||||||||||||||||
| "-smbios".to_string(), | ||||||||||||||||||||||||
| format!("type=11,value={}", smbios_cred), | ||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Add SMBIOS credentials for mount units | ||||||||||||||||||||||||
| for mount_cred in mount_unit_smbios_creds { | ||||||||||||||||||||||||
| // Add all SMBIOS credentials (mount units, storage opts, etc.) | ||||||||||||||||||||||||
| for cred in smbios_creds { | ||||||||||||||||||||||||
| qemu_args.push("-smbios".to_string()); | ||||||||||||||||||||||||
| qemu_args.push(format!("type=11,value={}", mount_cred)); | ||||||||||||||||||||||||
| qemu_args.push(format!("type=11,value={}", cred)); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+1153
to
1156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better performance and more idiomatic Rust, you can replace this loop with a combination of
Suggested change
Comment on lines
+1142
to
1156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic for adding SMBIOS credentials to For example: // Collect all credentials into one vector
let mut all_creds = smbios_creds;
let encoded = data_encoding::BASE64.encode(tmpfiles_content.as_bytes());
all_creds.push(format!(
"io.systemd.credential.binary:tmpfiles.extra={}",
encoded
));
// Build QEMU args from the consolidated list
for cred in all_creds {
qemu_args.push("-smbios".to_string());
qemu_args.push(format!("type=11,value={}", cred));
} |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Add extra SMBIOS credentials from opts | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the current time in seconds for unique names can lead to collisions if tests run in the same second. Using nanoseconds provides higher resolution and significantly reduces the chance of creating duplicate domain names, making the tests more robust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'll try to get back to #78