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

Method run_command

devices/src/pvmemcontrol.rs:346–385  ·  view source on GitHub ↗
(
        &mut self,
        guest_memory: &GuestMemoryAtomic<GuestMemoryMmap<AtomicBitmap>>,
        command: PvmemcontrolTransportCommand,
    )

Source from the content-addressed store, hash-verified

344 }
345
346 fn run_command(
347 &mut self,
348 guest_memory: &GuestMemoryAtomic<GuestMemoryMmap<AtomicBitmap>>,
349 command: PvmemcontrolTransportCommand,
350 ) {
351 let state = std::mem::replace(&mut self.state, PvmemcontrolState::Broken);
352
353 *self = match command {
354 PvmemcontrolTransportCommand::Reset => Self::reset(),
355 PvmemcontrolTransportCommand::Register => {
356 if let PvmemcontrolState::PercpuInit(state) = state {
357 // SAFETY: By device protocol. If driver is wrong the device
358 // can enter a Broken state, but the behavior is still sound.
359 Self::register_percpu_buf(guest_memory, state, unsafe {
360 self.transport.as_register()
361 })
362 } else {
363 debug!("received register without reset");
364 Self::error()
365 }
366 }
367 PvmemcontrolTransportCommand::Ready => {
368 if let PvmemcontrolState::PercpuInit(state) = state {
369 Self::ready(state)
370 } else {
371 debug!("received ready without reset");
372 Self::error()
373 }
374 }
375 PvmemcontrolTransportCommand::Disconnect => Self::error(),
376 PvmemcontrolTransportCommand::Ack => {
377 debug!("received ack as command");
378 Self::error()
379 }
380 PvmemcontrolTransportCommand::Error => {
381 debug!("received error as command");
382 Self::error()
383 }
384 }
385 }
386
387 /// read from the transport
388 fn read_transport(&self, offset: u64, data: &mut [u8]) {

Callers 1

handle_guest_writeMethod · 0.80

Calls 1

as_registerMethod · 0.80

Tested by

no test coverage detected