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

Method new

virtio-devices/src/vdpa.rs:120–201  ·  view source on GitHub ↗
(
        id: String,
        device_path: &str,
        mem: GuestMemoryAtomic<GuestMemoryMmap>,
        num_queues: u16,
        state: Option<VdpaState>,
    )

Source from the content-addressed store, hash-verified

118
119impl Vdpa {
120 pub fn new(
121 id: String,
122 device_path: &str,
123 mem: GuestMemoryAtomic<GuestMemoryMmap>,
124 num_queues: u16,
125 state: Option<VdpaState>,
126 ) -> Result<Self> {
127 let mut vhost = VhostKernVdpa::new(device_path, mem).map_err(Error::CreateVhostVdpa)?;
128 vhost.set_owner().map_err(Error::SetOwner)?;
129
130 let (
131 device_type,
132 avail_features,
133 acked_features,
134 queue_sizes,
135 iova_range,
136 backend_features,
137 paused,
138 ) = if let Some(state) = state {
139 info!("Restoring vDPA {id}");
140
141 vhost.set_backend_features_acked(state.backend_features);
142 vhost
143 .set_config(0, state.config.as_slice())
144 .map_err(Error::SetConfig)?;
145
146 (
147 state.device_type,
148 state.avail_features,
149 state.acked_features,
150 state.queue_sizes,
151 VhostVdpaIovaRange {
152 first: state.iova_range_first,
153 last: state.iova_range_last,
154 },
155 state.backend_features,
156 false,
157 )
158 } else {
159 let device_type = vhost.get_device_id().map_err(Error::GetDeviceId)?;
160 let queue_size = vhost.get_vring_num().map_err(Error::GetVringNum)?;
161 let avail_features = vhost.get_features().map_err(Error::GetFeatures)?;
162 let backend_features = vhost
163 .get_backend_features()
164 .map_err(Error::GetBackendFeatures)?;
165 vhost.set_backend_features_acked(backend_features);
166
167 let iova_range = vhost.get_iova_range().map_err(Error::GetIovaRange)?;
168
169 if avail_features & (1u64 << VIRTIO_F_ACCESS_PLATFORM) == 0 {
170 return Err(Error::MissingAccessPlatformVirtioFeature);
171 }
172
173 (
174 device_type,
175 avail_features,
176 0,
177 vec![queue_size; num_queues as usize],

Callers

nothing calls this directly

Calls 3

newFunction · 0.85
set_configMethod · 0.80
as_sliceMethod · 0.80

Tested by

no test coverage detected