Skip to content

Commit 768440e

Browse files
committed
refactor: #[from]-ify CreateSnapshotError
Avoid some .map_err() calls using #[from] and the auto-From::from calling of the question mark operator. Signed-off-by: Patrick Roy <[email protected]>
1 parent 12fa176 commit 768440e

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/vmm/src/persist.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ pub enum MicrovmStateError {
134134
#[derive(Debug, thiserror::Error, displaydoc::Display)]
135135
pub enum CreateSnapshotError {
136136
/// Cannot get dirty bitmap: {0}
137-
DirtyBitmap(vmm_sys_util::errno::Error),
137+
DirtyBitmap(#[from] vmm_sys_util::errno::Error),
138138
/// Cannot write memory file: {0}
139-
Memory(MemoryError),
139+
Memory(#[from] MemoryError),
140140
/// Cannot perform {0} on the memory backing file: {1}
141141
MemoryBackingFile(&'static str, io::Error),
142142
/// Cannot save the microVM state: {0}
143143
MicrovmState(MicrovmStateError),
144144
/// Cannot serialize the microVM state: {0}
145-
SerializeMicrovmState(crate::snapshot::SnapshotError),
145+
SerializeMicrovmState(#[from] crate::snapshot::SnapshotError),
146146
/// Cannot perform {0} on the snapshot backing file: {1}
147147
SnapshotBackingFile(&'static str, io::Error),
148148
}
@@ -198,9 +198,7 @@ fn snapshot_state_to_file(
198198
.map_err(|err| SnapshotBackingFile("open", err))?;
199199

200200
let snapshot = Snapshot::new(SNAPSHOT_VERSION);
201-
snapshot
202-
.save(&mut snapshot_file, microvm_state)
203-
.map_err(SerializeMicrovmState)?;
201+
snapshot.save(&mut snapshot_file, microvm_state)?;
204202
snapshot_file
205203
.flush()
206204
.map_err(|err| SnapshotBackingFile("flush", err))?;

src/vmm/src/vstate/vm.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,11 @@ impl Vm {
261261

262262
match snapshot_type {
263263
SnapshotType::Diff => {
264-
let dirty_bitmap = self.get_dirty_bitmap().map_err(DirtyBitmap)?;
265-
self.guest_memory()
266-
.dump_dirty(&mut file, &dirty_bitmap)
267-
.map_err(Memory)
264+
let dirty_bitmap = self.get_dirty_bitmap()?;
265+
self.guest_memory().dump_dirty(&mut file, &dirty_bitmap)
268266
}
269267
SnapshotType::Full => {
270-
let dump_res = self.guest_memory().dump(&mut file).map_err(Memory);
268+
let dump_res = self.guest_memory().dump(&mut file);
271269
if dump_res.is_ok() {
272270
self.reset_dirty_bitmap();
273271
self.guest_memory().reset_dirty();

0 commit comments

Comments
 (0)