Skip to content

cleanup: refactor &Arc<T> to &T or Arc<T>#7667

Open
daschinmoy21 wants to merge 2 commits intocloud-hypervisor:mainfrom
daschinmoy21:cleanup-refactor-arc
Open

cleanup: refactor &Arc<T> to &T or Arc<T>#7667
daschinmoy21 wants to merge 2 commits intocloud-hypervisor:mainfrom
daschinmoy21:cleanup-refactor-arc

Conversation

@daschinmoy21
Copy link

Refactored various functions to take &T or Arc instead of &Arc to remove double indirection

Updated PciSegment::new and related methods to consume Arc

Updated vmm/ src/device_manager.rs to match the new signatures

Fixes #7444

Refactor various functions to take &T or Arc<T> instead of &Arc<T> to remove double indirection.

Specifically updated PciSegment::new and related methods to consume Arc<AddressManager>.

Updated vmm/src/device_manager.rs to match the new signatures.

Fixes cloud-hypervisor#7444

Signed-off-by: daschinmoy21 <daschinmoyy21@gmail.com>
@daschinmoy21 daschinmoy21 requested a review from a team as a code owner February 5, 2026 09:38
Copy link
Member

@phip1611 phip1611 left a comment

Choose a reason for hiding this comment

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

thanks! This cleans up the code IMHO a lot! I think we should also get rid of &Mutex and lock on the caller side (where the call is cheap and we do not block other code for too long)

id: u16,
numa_node: u32,
address_manager: &Arc<AddressManager>,
address_manager: Arc<AddressManager>,
Copy link
Member

Choose a reason for hiding this comment

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

ah, great catch!

vmm/src/vm.rs Outdated
payload: &PayloadConfig,
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] device_manager: &Arc<
Mutex<DeviceManager>,
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] device_manager: &Mutex<
Copy link
Member

Choose a reason for hiding this comment

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


#[cfg(feature = "fw_cfg")]
pub fn fw_cfg(&self) -> Option<&Arc<Mutex<FwCfg>>> {
pub fn fw_cfg(&self) -> Option<&Mutex<FwCfg>> {
Copy link
Member

Choose a reason for hiding this comment

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

vmm/src/acpi.rs Outdated
device_manager: &Arc<Mutex<DeviceManager>>,
cpu_manager: &Arc<Mutex<CpuManager>>,
memory_manager: &Arc<Mutex<MemoryManager>>,
device_manager: &Mutex<DeviceManager>,
Copy link
Member

Choose a reason for hiding this comment

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

vmm/src/acpi.rs Outdated
device_manager: &Arc<Mutex<DeviceManager>>,
cpu_manager: &Arc<Mutex<CpuManager>>,
memory_manager: &Arc<Mutex<MemoryManager>>,
device_manager: &Mutex<DeviceManager>,
Copy link
Member

Choose a reason for hiding this comment

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

fn allocate_bars(
&mut self,
_allocator: &Arc<Mutex<SystemAllocator>>,
_allocator: &Mutex<SystemAllocator>,
Copy link
Member

Choose a reason for hiding this comment

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

fn allocate_bars(
&mut self,
allocator: &Arc<Mutex<SystemAllocator>>,
allocator: &Mutex<SystemAllocator>,
Copy link
Member

Choose a reason for hiding this comment

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

fn allocate_bars(
&mut self,
_allocator: &Arc<Mutex<SystemAllocator>>,
_allocator: &Mutex<SystemAllocator>,
Copy link
Member

Choose a reason for hiding this comment

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

fn allocate_bars(
&mut self,
_allocator: &Arc<Mutex<SystemAllocator>>,
_allocator: &Mutex<SystemAllocator>,
Copy link
Member

Choose a reason for hiding this comment

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

Refactor ACPI table creation functions to take &DeviceManager instead
of &Mutex<DeviceManager>, moving the locking responsibility to the
caller. This ensures consistency across tables and simplifies the API.

- Update create_acpi_tables* signatures and internal logic.
- Move DeviceManager locking to Vm call sites.
- Update generate_cmdline and populate_fw_cfg to take &DeviceManager.
- Update get_interrupt_controller to take &self.
- Fix fw_cfg helper return type using as_deref().
@daschinmoy21
Copy link
Author

Updated the changes.ACPI table creation functions now take &DeviceManager instead
of &Mutex, moving the locking responsibility to the
caller

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.

cleanup: &Arc<T> -> &T or Arc<T>

2 participants