pub fn update_vm_config(&mut self, machine_config: &VmUpdateConfig) -> Result<VmConfigError> {
        let vcpu_count = machine_config
            .vcpu_count
            .unwrap_or(self.vm_config.vcpu_count);

        let smt = machine_config.smt.unwrap_or(self.vm_config.smt);

        if vcpu_count == 0 {
            return Err(VmConfigError::InvalidVcpuCount);
        }

        // If SMT is enabled or is to be enabled in this call
        // only allow vcpu count to be 1 or even.
        if smt && vcpu_count > 1 && vcpu_count % 2 == 1 {
            return Err(VmConfigError::InvalidVcpuCount);
        }

        self.vm_config.vcpu_count = vcpu_count;
        self.vm_config.smt = smt;

        let mem_size_mib = machine_config
            .mem_size_mib
            .unwrap_or(self.vm_config.mem_size_mib);

        if mem_size_mib == 0 {
            return Err(VmConfigError::InvalidMemorySize);
        }

        // The VM cannot have a memory size smaller than the target size
        // of the balloon device, if present.
        if self.balloon.get().is_some()
            && mem_size_mib
                < self
                    .balloon
                    .get_config()
                    .map_err(|_| VmConfigError::InvalidVmState)?
                    .amount_mib as usize
        {
            return Err(VmConfigError::IncompatibleBalloonSize);
        }

        self.vm_config.mem_size_mib = mem_size_mib;

        // Update the CPU template
        if let Some(cpu_template) = machine_config.cpu_template {
            self.vm_config.cpu_template = cpu_template;
        }

        // Update dirty page tracking
        if let Some(track_dirty_pages) = machine_config.track_dirty_pages {
            self.vm_config.track_dirty_pages = track_dirty_pages;
        }

        Ok(())
    }
/// Update the machine configuration of the microVM.
Update the machine configuration of the microVM.
Update the machine configuration of the microVM .
pub fn update_vm_config(&mut self, machine_config: &VmUpdateConfig) -> Result<VmConfigError> {
        let vcpu_count = machine_config
            .vcpu_count
            .unwrap_or(self.vm_config.vcpu_count);
        let smt = machine_config.smt.unwrap_or(self.vm_config.smt);
        if vcpu_count == 0 {
            return Err(VmConfigError::InvalidVcpuCount);
        }
        // If SMT is enabled or is to be enabled in this call
        // only allow vcpu count to be 1 or even.
        if smt && vcpu_count > 1 && vcpu_count % 2 == 1 {
            return Err(VmConfigError::InvalidVcpuCount);
        }
        self.vm_config.vcpu_count = vcpu_count;
        self.vm_config.smt = smt;
        let mem_size_mib = machine_config
            .mem_size_mib
            .unwrap_or(self.vm_config.mem_size_mib);
        if mem_size_mib == 0 {
            return Err(VmConfigError::InvalidMemorySize);
        }
        // The VM cannot have a memory size smaller than the target size
        // of the balloon device, if present.
        if self.balloon.get().is_some()
            && mem_size_mib
                < self
                    .balloon
                    .get_config()
                    .map_err(|_| VmConfigError::InvalidVmState)?
                    .amount_mib as usize
        {
            return Err(VmConfigError::IncompatibleBalloonSize);
        }
        self.vm_config.mem_size_mib = mem_size_mib;
        // Update the CPU template
        if let Some(cpu_template) = machine_config.cpu_template {
            self.vm_config.cpu_template = cpu_template;
        }
        // Update dirty page tracking
        if let Some(track_dirty_pages) = machine_config.track_dirty_pages {
            self.vm_config.track_dirty_pages = track_dirty_pages;
        }
        Ok(())
    }
pub fn update_vm_config ( & mut self , machine_config : & VmUpdateConfig ) -> Result < VmConfigError > { let vcpu_count = machine_config . vcpu_count . unwrap_or ( self . vm_config . vcpu_count ) ; let smt = machine_config . smt . unwrap_or ( self . vm_config . smt ) ; if vcpu_count == 0 { return Err ( VmConfigError :: InvalidVcpuCount ) ; } // If SMT is enabled or is to be enabled in this call // only allow vcpu count to be 1 or even. if smt && vcpu_count > 1 && vcpu_count % 2 == 1 { return Err ( VmConfigError :: InvalidVcpuCount ) ; } self . vm_config . vcpu_count = vcpu_count ; self . vm_config . smt = smt ; let mem_size_mib = machine_config . mem_size_mib . unwrap_or ( self . vm_config . mem_size_mib ) ; if mem_size_mib == 0 { return Err ( VmConfigError :: InvalidMemorySize ) ; } // The VM cannot have a memory size smaller than the target size // of the balloon device, if present. if self . balloon . get ( ) . is_some ( ) && mem_size_mib < self . balloon . get_config ( ) . map_err ( | _ | VmConfigError :: InvalidVmState ) ? . amount_mib as usize { return Err ( VmConfigError :: IncompatibleBalloonSize ) ; } self . vm_config . mem_size_mib = mem_size_mib ; // Update the CPU template if let Some ( cpu_template ) = machine_config . cpu_template { self . vm_config . cpu_template = cpu_template ; } // Update dirty page tracking if let Some ( track_dirty_pages ) = machine_config . track_dirty_pages { self . vm_config . track_dirty_pages = track_dirty_pages ; } Ok ( ( ) ) }
Update the machine configuration of the microVM.
Update the machine configuration of the microVM .
&mut self
machine_config
&VmUpdateConfig
&mut self
machine_config
&VmUpdateConfig