vmm/devices/virtio/block/
persist.rs

1// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4use std::sync::Arc;
5
6use serde::{Deserialize, Serialize};
7
8use super::vhost_user::persist::VhostUserBlockState;
9use super::virtio::persist::VirtioBlockState;
10use crate::devices::virtio::transport::VirtioInterrupt;
11use crate::vstate::memory::GuestMemoryMmap;
12
13/// Block device state.
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub enum BlockState {
16    Virtio(VirtioBlockState),
17    VhostUser(VhostUserBlockState),
18}
19
20impl BlockState {
21    pub fn is_activated(&self) -> bool {
22        match self {
23            BlockState::Virtio(virtio_block_state) => virtio_block_state.virtio_state.activated,
24            BlockState::VhostUser(vhost_user_block_state) => false,
25        }
26    }
27}
28
29/// Auxiliary structure for creating a device when resuming from a snapshot.
30#[derive(Debug)]
31pub struct BlockConstructorArgs {
32    pub mem: GuestMemoryMmap,
33}