Skip to content

Commit 6791d55

Browse files
Ashwin Ginoriazulinx86
Ashwin Ginoria
authored andcommitted
Fix: move snapshot into module under vmm
Moved `snapshot` into module under `vmm`. Many of these crates could be modules and the number of crates in our workspace greatly reduced. This reduces the binary size and makes the workspace more ergonomic. Signed-off-by: Ashwin Ginoria <[email protected]>
1 parent 6414a07 commit 6791d55

File tree

28 files changed

+44
-88
lines changed

28 files changed

+44
-88
lines changed

Cargo.lock

+1-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/firecracker/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ thiserror = "1.0.53"
2525
timerfd = "1.5.0"
2626

2727
seccompiler = { path = "../seccompiler" }
28-
snapshot = { path = "../snapshot" }
2928
utils = { path = "../utils" }
3029
vmm = { path = "../vmm" }
3130

@@ -45,7 +44,7 @@ serde = { version = "1.0.193" }
4544
serde_json = "1.0.109"
4645

4746
[features]
48-
tracing = ["log-instrument", "seccompiler/tracing", "snapshot/tracing", "utils/tracing", "vmm/tracing"]
47+
tracing = ["log-instrument", "seccompiler/tracing", "utils/tracing", "vmm/tracing"]
4948

5049
[[example]]
5150
name = "uffd_malicious_handler"

src/firecracker/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use api_server_adapter::ApiServerError;
1717
use event_manager::SubscriberOps;
1818
use seccomp::FilterError;
1919
use seccompiler::BpfThreadMap;
20-
use snapshot::{Error as SnapshotError, Snapshot};
2120
use utils::arg_parser::{ArgParser, Argument};
2221
use utils::terminal::Terminal;
2322
use utils::validators::validate_instance_id;
@@ -28,6 +27,7 @@ use vmm::logger::{
2827
use vmm::persist::SNAPSHOT_VERSION;
2928
use vmm::resources::VmResources;
3029
use vmm::signal_handler::register_signal_handlers;
30+
use vmm::snapshot::{Error as SnapshotError, Snapshot};
3131
use vmm::vmm_config::instance_info::{InstanceInfo, VmState};
3232
use vmm::vmm_config::metrics::{init_metrics, MetricsConfig, MetricsConfigError};
3333
use vmm::{EventManager, FcExitCode, HTTP_MAX_PAYLOAD_SIZE};

src/snapshot-editor/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ displaydoc = "0.2.4"
1515
libc = "0.2.151"
1616
log-instrument = { path = "../log-instrument", optional = true }
1717
semver = "1.0.20"
18-
snapshot = { path = "../snapshot" }
1918
thiserror = "1.0.53"
2019
vmm = { path = "../vmm" }
2120

src/snapshot-editor/src/utils.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::path::PathBuf;
66

77
use fc_utils::u64_to_usize;
88
use semver::Version;
9-
use snapshot::Snapshot;
109
use vmm::persist::MicrovmState;
10+
use vmm::snapshot::Snapshot;
1111

1212
// Some errors are only used in aarch64 code
1313
#[allow(unused)]
@@ -18,11 +18,11 @@ pub enum UtilsError {
1818
/// Can not retrieve metadata for snapshot file: {0}
1919
VmStateFileMeta(std::io::Error),
2020
/// Can not load snapshot: {0}
21-
VmStateLoad(snapshot::Error),
21+
VmStateLoad(vmm::snapshot::Error),
2222
/// Can not open output file: {0}
2323
OutputFileOpen(std::io::Error),
2424
/// Can not save snapshot: {0}
25-
VmStateSave(snapshot::Error),
25+
VmStateSave(vmm::snapshot::Error),
2626
}
2727

2828
#[allow(unused)]

src/snapshot/Cargo.toml

-23
This file was deleted.

src/vmm/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ base64 = "0.21.0"
3636
bincode = "1.2.1"
3737
micro_http = { git = "https://github.com/firecracker-microvm/micro-http" }
3838
log-instrument = { path = "../log-instrument", optional = true }
39+
crc64 = "2.0.0"
3940

4041
seccompiler = { path = "../seccompiler" }
41-
snapshot = { path = "../snapshot"}
4242
utils = { path = "../utils" }
4343
smallvec = "1.11.2"
4444

src/vmm/src/arch/aarch64/regs.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,8 @@ reg_data_array!([u8; 256], 256);
478478

479479
#[cfg(test)]
480480
mod tests {
481-
use snapshot::Snapshot;
482-
483481
use super::*;
482+
use crate::snapshot::Snapshot;
484483

485484
#[test]
486485
fn test_reg_size() {

src/vmm/src/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use linux_loader::loader::elf::Elf as Loader;
1818
use linux_loader::loader::pe::PE as Loader;
1919
use linux_loader::loader::KernelLoader;
2020
use seccompiler::BpfThreadMap;
21-
use snapshot::Persist;
2221
use userfaultfd::Uffd;
2322
use utils::eventfd::EventFd;
2423
use utils::time::TimestampUs;
@@ -53,6 +52,7 @@ use crate::devices::BusDevice;
5352
use crate::logger::{debug, error};
5453
use crate::persist::{MicrovmState, MicrovmStateError};
5554
use crate::resources::VmResources;
55+
use crate::snapshot::Persist;
5656
use crate::vmm_config::boot_source::BootConfig;
5757
use crate::vmm_config::drive::BlockDeviceType;
5858
use crate::vmm_config::instance_info::InstanceInfo;

src/vmm/src/device_manager/persist.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use event_manager::{MutEventSubscriber, SubscriberOps};
1010
use kvm_ioctls::VmFd;
1111
use log::{error, warn};
1212
use serde::{Deserialize, Serialize};
13-
use snapshot::Persist;
1413
use vm_allocator::AllocPolicy;
1514

1615
use super::mmio::*;
@@ -45,6 +44,7 @@ use crate::devices::virtio::vsock::{
4544
use crate::devices::virtio::{TYPE_BALLOON, TYPE_BLOCK, TYPE_NET, TYPE_RNG};
4645
use crate::mmds::data_store::MmdsVersion;
4746
use crate::resources::VmResources;
47+
use crate::snapshot::Persist;
4848
use crate::vmm_config::mmds::MmdsConfigError;
4949
use crate::vstate::memory::GuestMemoryMmap;
5050
use crate::EventManager;
@@ -646,13 +646,13 @@ impl<'a> Persist<'a> for MMIODeviceManager {
646646

647647
#[cfg(test)]
648648
mod tests {
649-
use snapshot::Snapshot;
650649
use utils::tempfile::TempFile;
651650

652651
use super::*;
653652
use crate::builder::tests::*;
654653
use crate::devices::virtio::block_common::CacheType;
655654
use crate::resources::VmmConfig;
655+
use crate::snapshot::Snapshot;
656656
use crate::vmm_config::balloon::BalloonDeviceConfig;
657657
use crate::vmm_config::entropy::EntropyDeviceConfig;
658658
use crate::vmm_config::net::NetworkInterfaceConfig;

src/vmm/src/devices/virtio/balloon/persist.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::sync::Arc;
88
use std::time::Duration;
99

1010
use serde::{Deserialize, Serialize};
11-
use snapshot::Persist;
1211
use timerfd::{SetTimeFlags, TimerState};
1312

1413
use super::*;
@@ -17,6 +16,7 @@ use crate::devices::virtio::device::DeviceState;
1716
use crate::devices::virtio::persist::VirtioDeviceState;
1817
use crate::devices::virtio::queue::FIRECRACKER_MAX_QUEUE_SIZE;
1918
use crate::devices::virtio::TYPE_BALLOON;
19+
use crate::snapshot::Persist;
2020
use crate::vstate::memory::GuestMemoryMmap;
2121

2222
/// Information about the balloon config's that are saved
@@ -174,12 +174,11 @@ impl Persist<'_> for Balloon {
174174
mod tests {
175175
use std::sync::atomic::Ordering;
176176

177-
use snapshot::Snapshot;
178-
179177
use super::*;
180178
use crate::devices::virtio::device::VirtioDevice;
181179
use crate::devices::virtio::test_utils::default_mem;
182180
use crate::devices::virtio::TYPE_BALLOON;
181+
use crate::snapshot::Snapshot;
183182

184183
#[test]
185184
fn test_persistence() {

src/vmm/src/devices/virtio/net/persist.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::sync::atomic::AtomicU32;
88
use std::sync::{Arc, Mutex};
99

1010
use serde::{Deserialize, Serialize};
11-
use snapshot::Persist;
1211
use utils::net::mac::MacAddr;
1312

1413
use super::device::Net;
@@ -22,6 +21,7 @@ use crate::mmds::ns::MmdsNetworkStack;
2221
use crate::mmds::persist::MmdsNetworkStackState;
2322
use crate::rate_limiter::persist::RateLimiterState;
2423
use crate::rate_limiter::RateLimiter;
24+
use crate::snapshot::Persist;
2525
use crate::vstate::memory::GuestMemoryMmap;
2626

2727
/// Information about the network config's that are saved
@@ -140,12 +140,11 @@ impl Persist<'_> for Net {
140140
mod tests {
141141
use std::sync::atomic::Ordering;
142142

143-
use snapshot::Snapshot;
144-
145143
use super::*;
146144
use crate::devices::virtio::device::VirtioDevice;
147145
use crate::devices::virtio::net::test_utils::{default_net, default_net_no_mmds};
148146
use crate::devices::virtio::test_utils::default_mem;
147+
use crate::snapshot::Snapshot;
149148

150149
fn validate_save_and_restore(net: Net, mmds_ds: Option<Arc<Mutex<Mmds>>>) {
151150
let guest_mem = default_mem();

src/vmm/src/devices/virtio/persist.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use std::sync::atomic::Ordering;
88
use std::sync::{Arc, Mutex};
99

1010
use serde::{Deserialize, Serialize};
11-
use snapshot::Persist;
1211

1312
use crate::devices::virtio::device::VirtioDevice;
1413
use crate::devices::virtio::gen::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
1514
use crate::devices::virtio::mmio::MmioTransport;
1615
use crate::devices::virtio::queue::Queue;
16+
use crate::snapshot::Persist;
1717
use crate::vstate::memory::{GuestAddress, GuestMemoryMmap};
1818

1919
/// Errors thrown during restoring virtio state.
@@ -225,7 +225,6 @@ impl Persist<'_> for MmioTransport {
225225

226226
#[cfg(test)]
227227
mod tests {
228-
use snapshot::Snapshot;
229228
use utils::tempfile::TempFile;
230229

231230
use super::*;
@@ -237,6 +236,7 @@ mod tests {
237236
use crate::devices::virtio::virtio_block::test_utils::default_block_with_path;
238237
use crate::devices::virtio::virtio_block::VirtioBlock;
239238
use crate::devices::virtio::vsock::{Vsock, VsockUnixBackend};
239+
use crate::snapshot::Snapshot;
240240

241241
const DEFAULT_QUEUE_MAX_SIZE: u16 = 256;
242242
impl Default for QueueState {

src/vmm/src/devices/virtio/rng/persist.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
//! Defines the structures needed for saving/restoring entropy devices.
55
66
use serde::{Deserialize, Serialize};
7-
use snapshot::Persist;
87

98
use crate::devices::virtio::persist::{PersistError as VirtioStateError, VirtioDeviceState};
109
use crate::devices::virtio::queue::FIRECRACKER_MAX_QUEUE_SIZE;
1110
use crate::devices::virtio::rng::{Entropy, EntropyError, RNG_NUM_QUEUES};
1211
use crate::devices::virtio::TYPE_RNG;
1312
use crate::rate_limiter::persist::RateLimiterState;
1413
use crate::rate_limiter::RateLimiter;
14+
use crate::snapshot::Persist;
1515
use crate::vstate::memory::GuestMemoryMmap;
1616

1717
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -79,12 +79,11 @@ impl Persist<'_> for Entropy {
7979
mod tests {
8080
use std::sync::atomic::Ordering;
8181

82-
use snapshot::Snapshot;
83-
8482
use super::*;
8583
use crate::devices::virtio::device::VirtioDevice;
8684
use crate::devices::virtio::rng::device::ENTROPY_DEV_ID;
8785
use crate::devices::virtio::test_utils::test::create_virtio_mem;
86+
use crate::snapshot::Snapshot;
8887

8988
#[test]
9089
fn test_persistence() {

src/vmm/src/devices/virtio/vhost_user_block/persist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
//! Defines the structures needed for saving/restoring block devices.
55
66
use serde::{Deserialize, Serialize};
7-
use snapshot::Persist;
87

98
use super::device::VhostUserBlock;
109
use super::VhostUserBlockError;
1110
use crate::devices::virtio::block_common::CacheType;
1211
use crate::devices::virtio::persist::VirtioDeviceState;
12+
use crate::snapshot::Persist;
1313
use crate::vstate::memory::GuestMemoryMmap;
1414

1515
/// vhost-user block device state.

src/vmm/src/devices/virtio/virtio_block/persist.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::sync::atomic::AtomicU32;
77
use std::sync::Arc;
88

99
use serde::{Deserialize, Serialize};
10-
use snapshot::Persist;
1110
use utils::eventfd::EventFd;
1211

1312
use super::device::DiskProperties;
@@ -21,6 +20,7 @@ use crate::devices::virtio::TYPE_BLOCK;
2120
use crate::logger::warn;
2221
use crate::rate_limiter::persist::RateLimiterState;
2322
use crate::rate_limiter::RateLimiter;
23+
use crate::snapshot::Persist;
2424
use crate::vstate::memory::GuestMemoryMmap;
2525

2626
/// Holds info about block's file engine type. Gets saved in snapshot.
@@ -173,13 +173,13 @@ impl Persist<'_> for VirtioBlock {
173173
mod tests {
174174
use std::sync::atomic::Ordering;
175175

176-
use snapshot::Snapshot;
177176
use utils::tempfile::TempFile;
178177

179178
use super::*;
180179
use crate::devices::virtio::device::VirtioDevice;
181180
use crate::devices::virtio::test_utils::default_mem;
182181
use crate::devices::virtio::virtio_block::device::VirtioBlockConfig;
182+
use crate::snapshot::Snapshot;
183183

184184
#[test]
185185
fn test_cache_semantic_ser() {

0 commit comments

Comments
 (0)