Skip to content

Commit 477200c

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 0131cdc commit 477200c

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/vmm/src/persist.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ pub enum CreateSnapshotError {
135135
/// Cannot get dirty bitmap: {0}
136136
DirtyBitmap(kvm_ioctls::Error),
137137
/// Cannot write memory file: {0}
138-
Memory(MemoryError),
138+
Memory(#[from] MemoryError),
139139
/// Cannot perform {0} on the memory backing file: {1}
140140
MemoryBackingFile(&'static str, io::Error),
141141
/// Cannot save the microVM state: {0}
142142
MicrovmState(MicrovmStateError),
143143
/// Cannot serialize the microVM state: {0}
144-
SerializeMicrovmState(crate::snapshot::SnapshotError),
144+
SerializeMicrovmState(#[from] crate::snapshot::SnapshotError),
145145
/// Cannot perform {0} on the snapshot backing file: {1}
146146
SnapshotBackingFile(&'static str, io::Error),
147147
}
@@ -197,9 +197,7 @@ fn snapshot_state_to_file(
197197
.map_err(|err| SnapshotBackingFile("open", err))?;
198198

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

src/vmm/src/vstate/vm.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,10 @@ impl Vm {
262262
match snapshot_type {
263263
SnapshotType::Diff => {
264264
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)
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)