Skip to content

petri: consolidate hyper-v vm creation with wmi#3113

Open
tjones60 wants to merge 2 commits intomicrosoft:mainfrom
tjones60:hyperv_newvm_wmi
Open

petri: consolidate hyper-v vm creation with wmi#3113
tjones60 wants to merge 2 commits intomicrosoft:mainfrom
tjones60:hyperv_newvm_wmi

Conversation

@tjones60
Copy link
Copy Markdown
Contributor

Consolidate several PowerShell commands called during the creation of a Hyper-V VM into one using the DefineSystem WMI method. This should help speed up tests, especially since the WMI provider is single threaded.

@tjones60 tjones60 requested a review from a team as a code owner March 24, 2026 00:26
Copilot AI review requested due to automatic review settings March 24, 2026 00:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the Hyper-V Petri backend VM creation path to reduce the number of PowerShell/WMI calls by consolidating creation-time configuration into a single WMI DefineSystem call (via a new New-CustomVM helper), aiming to speed up tests given the single-threaded WMI provider.

Changes:

  • Introduces New-CustomVM (WMI/DefineSystem-based) and routes VM creation through a consolidated argument struct (HyperVNewCustomVMArgs).
  • Refactors VMGS resource accessors and updates OpenHCL VMGS encryption-policy checks to use the new helpers.
  • Adds compatibility plumbing to detect missing VSSD properties and fall back to OpenHCL command-line parameters when needed.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
petri/src/vm/openvmm/construct.rs Updates VMGS encryption-policy check to use the new encryption_policy() helper.
petri/src/vm/mod.rs Refactors PetriVmgsResource accessors (vmgs(), disk(), encryption_policy()) and adds Firmware::openhcl_firmware().
petri/src/vm/hyperv/vm.rs Changes Hyper-V VM creation to take a single HyperVNewCustomVMArgs struct and call the consolidated creation path.
petri/src/vm/hyperv/powershell.rs Adds new enums/flags and HyperVNewCustomVMArgs + run_new_customvm, including compatibility handling for missing VSSD properties.
petri/src/vm/hyperv/mod.rs Switches backend VM creation flow to build HyperVNewCustomVMArgs from config and rely on consolidated creation.
petri/src/vm/hyperv/hyperv.psm1 Adds New-CustomVM that uses WMI DefineSystem and performs initial VM settings in one call.
petri/Cargo.toml Adds bitfield-struct dependency for the new flags type.
Cargo.lock Records the new dependency in the lockfile.

Copilot AI review requested due to automatic review settings March 24, 2026 00:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.

@github-actions
Copy link
Copy Markdown

Copilot AI review requested due to automatic review settings March 27, 2026 22:04
@tjones60 tjones60 requested a review from a team as a code owner March 27, 2026 22:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.

Comment on lines +282 to +288
$psd = Get-CimClass -Namespace $ROOT_HYPER_V_NAMESPACE -ClassName "Msvm_ProcessorSettingData" | New-CimInstance -ClientOnly -Property @{
VirtualQuantity = $VpCount
ApicMode = $ApicMode
HwThreadsPerCore = $HwThreadsPerCore
MaxProcessorsPerNumaNode = $MaxProcessorsPerNumaNode
}

Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

MaxProcessorsPerNumaNode is always written into Msvm_ProcessorSettingData, even when the caller did not intend to override it. With the current default of 1, this can produce an invalid or overly constrained topology relative to VirtualQuantity/VpCount. Gate this assignment behind a $null check (and make the parameter nullable) so the default Hyper-V behavior is preserved unless overridden.

Suggested change
$psd = Get-CimClass -Namespace $ROOT_HYPER_V_NAMESPACE -ClassName "Msvm_ProcessorSettingData" | New-CimInstance -ClientOnly -Property @{
VirtualQuantity = $VpCount
ApicMode = $ApicMode
HwThreadsPerCore = $HwThreadsPerCore
MaxProcessorsPerNumaNode = $MaxProcessorsPerNumaNode
}
$psdProperties = @{
VirtualQuantity = $VpCount
ApicMode = $ApicMode
HwThreadsPerCore = $HwThreadsPerCore
}
if ($null -ne $MaxProcessorsPerNumaNode) {
$psdProperties["MaxProcessorsPerNumaNode"] = $MaxProcessorsPerNumaNode
}
$psd = Get-CimClass -Namespace $ROOT_HYPER_V_NAMESPACE -ClassName "Msvm_ProcessorSettingData" | New-CimInstance -ClientOnly -Property $psdProperties

Copilot uses AI. Check for mistakes.

let hyperv_args = {
let mut args = HyperVNewCustomVMArgs::from_config(&config, &properties)?;
args.firmware_file = igvm_file.clone();
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

args.firmware_file points at temp_dir/.../igvm.bin and is passed into New-CustomVM before the IGVM is copied into that location and before ACLs are applied (the copy happens later in the OpenHCL block). VM creation can fail if DefineSystem validates/probes FirmwareFile during creation. Consider copying the IGVM into temp_dir (and applying an ACL readable by Hyper-V, e.g. the Virtual Machines group) before calling HyperVVM::new(), or avoid setting FirmwareFile until after the copy as the old flow did.

Suggested change
args.firmware_file = igvm_file.clone();

Copilot uses AI. Check for mistakes.
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.

2 participants