Skip to content

Commit

Permalink
xen: remove unwraps in listen
Browse files Browse the repository at this point in the history
  • Loading branch information
Wenzel committed Dec 20, 2020
1 parent 4c13f32 commit ea13cdf
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/driver/xen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl Introspectable for Xen {

fn listen(&mut self, timeout: u32) -> Result<Option<Event>, Box<dyn Error>> {
let mut fds: [PollFd; 1] = [self.evtchn_pollfd];
let event: Option<Event> = match poll(&mut fds, timeout.try_into().unwrap()).unwrap() {
let event: Option<Event> = match poll(&mut fds, timeout.try_into()?)? {
0 => {
// timeout. no file descriptors were ready
None
Expand All @@ -356,7 +356,7 @@ impl Introspectable for Xen {
}
// unmask
self.xev
.xenevtchn_unmask(pending_event_port.try_into().unwrap())?;
.xenevtchn_unmask(pending_event_port.try_into()?)?;
}
};
let back_ring_ptr = &mut self.back_ring;
Expand All @@ -367,8 +367,8 @@ impl Introspectable for Xen {
if req.version != VM_EVENT_INTERFACE_VERSION {
panic!("version mismatch");
}
let xen_event_type = (self.xc.get_event_type(req)).unwrap();
let vcpu: u32 = req.vcpu_id.try_into().unwrap();
let xen_event_type = (self.xc.get_event_type(req))?;
let vcpu: u32 = req.vcpu_id.try_into()?;
let event_type: EventType = match xen_event_type {
XenEventType::Cr { cr_type, new, old } => EventType::Cr {
cr_type: match cr_type {
Expand All @@ -390,10 +390,10 @@ impl Introspectable for Xen {
};
// associate VCPU => vm_event_request_t
// to find it in reply_event()
let vcpu_index: usize = vcpu.try_into().unwrap();
let vcpu_index: usize = vcpu.try_into()?;
self.vec_events[vcpu_index] = Some(req);
Some(Event {
vcpu: vcpu.try_into().unwrap(),
vcpu: vcpu.try_into()?,
kind: event_type,
})
}
Expand All @@ -414,7 +414,7 @@ impl Introspectable for Xen {
EventReplyType::Continue => VM_EVENT_FLAG_VCPU_PAUSED,
};
// get the request back
let vcpu_index: usize = event.vcpu.try_into().unwrap();
let vcpu_index: usize = event.vcpu.try_into()?;
let req: vm_event_request_t = mem::replace(&mut self.vec_events[vcpu_index], None).unwrap();
let mut rsp: vm_event_response_t =
unsafe { mem::MaybeUninit::<vm_event_response_t>::zeroed().assume_init() };
Expand Down

0 comments on commit ea13cdf

Please sign in to comment.