MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / new

Method new

devices/src/ivshmem.rs:112–182  ·  view source on GitHub ↗
(
        id: String,
        region_size: u64,
        backend_file: Option<PathBuf>,
        ivshmem_ops: Arc<Mutex<dyn IvshmemOps>>,
        snapshot: Option<&Snapshot>,
    )

Source from the content-addressed store, hash-verified

110
111impl IvshmemDevice {
112 pub fn new(
113 id: String,
114 region_size: u64,
115 backend_file: Option<PathBuf>,
116 ivshmem_ops: Arc<Mutex<dyn IvshmemOps>>,
117 snapshot: Option<&Snapshot>,
118 ) -> Result<Self, IvshmemError> {
119 let pci_configuration_state = vm_migration::state_from_id(snapshot, PCI_CONFIGURATION_ID)
120 .map_err(|e| {
121 IvshmemError::RetrievePciConfigurationState(anyhow!(
122 "Failed to get PciConfigurationState from Snapshot: {e}",
123 ))
124 })?;
125
126 let state: Option<IvshmemDeviceState> = snapshot
127 .as_ref()
128 .map(|s| s.to_state())
129 .transpose()
130 .map_err(|e| {
131 IvshmemError::RetrieveIvshmemDeviceStateState(anyhow!(
132 "Failed to get IvshmemDeviceState from Snapshot: {e}",
133 ))
134 })?;
135
136 let configuration = PciConfiguration::new(
137 IVSHMEM_VENDOR_ID,
138 IVSHMEM_DEVICE_ID,
139 0x1,
140 PciClassCode::MemoryController,
141 &IvshmemSubclass::Other,
142 None,
143 PciHeaderType::Device,
144 0,
145 0,
146 None,
147 pci_configuration_state,
148 );
149
150 let device = if let Some(s) = state {
151 IvshmemDevice {
152 id,
153 configuration,
154 bar_regions: vec![],
155 _interrupt_mask: s.interrupt_mask,
156 _interrupt_status: Arc::new(AtomicU32::new(s.interrupt_status)),
157 _iv_position: s.iv_position,
158 _doorbell: s.doorbell,
159 region_size,
160 ivshmem_ops,
161 region: None,
162 userspace_mapping: None,
163 backend_file,
164 }
165 } else {
166 IvshmemDevice {
167 id,
168 configuration,
169 bar_regions: vec![],

Callers

nothing calls this directly

Calls 4

state_from_idFunction · 0.85
newFunction · 0.85
to_stateMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected