summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--devices/src/virtio/block.rs32
-rw-r--r--seccomp/aarch64/block_device.policy3
-rw-r--r--seccomp/x86_64/block_device.policy3
3 files changed, 28 insertions, 10 deletions
diff --git a/devices/src/virtio/block.rs b/devices/src/virtio/block.rs
index ca0b222..2faa45d 100644
--- a/devices/src/virtio/block.rs
+++ b/devices/src/virtio/block.rs
@@ -11,7 +11,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
 use std::thread;
 
 use sys_util::Result as SysResult;
-use sys_util::{EventFd, GuestAddress, GuestMemory, GuestMemoryError, Poller};
+use sys_util::{EventFd, GuestAddress, GuestMemory, GuestMemoryError, PollContext, PollToken};
 
 use super::{VirtioDevice, Queue, DescriptorChain, INTERRUPT_STATUS_USED_RING, TYPE_BLOCK};
 
@@ -232,12 +232,25 @@ impl<T: DiskFile> Worker<T> {
     }
 
     fn run(&mut self, queue_evt: EventFd, kill_evt: EventFd) {
-        const Q_AVAIL: u32 = 0;
-        const KILL: u32 = 1;
+        #[derive(PollToken)]
+        enum Token {
+            QueueAvailable,
+            Kill,
+        }
+
+        let poll_ctx: PollContext<Token> =
+            match PollContext::new()
+                      .and_then(|pc| pc.add(&queue_evt, Token::QueueAvailable).and(Ok(pc)))
+                      .and_then(|pc| pc.add(&kill_evt, Token::Kill).and(Ok(pc))) {
+                Ok(pc) => pc,
+                Err(e) => {
+                    error!("failed creating PollContext: {:?}", e);
+                    return;
+                }
+            };
 
-        let mut poller = Poller::new(2);
         'poll: loop {
-            let tokens = match poller.poll(&[(Q_AVAIL, &queue_evt), (KILL, &kill_evt)]) {
+            let events = match poll_ctx.wait() {
                 Ok(v) => v,
                 Err(e) => {
                     error!("failed polling for events: {:?}", e);
@@ -246,17 +259,16 @@ impl<T: DiskFile> Worker<T> {
             };
 
             let mut needs_interrupt = false;
-            for &token in tokens {
-                match token {
-                    Q_AVAIL => {
+            for event in events.iter_readable() {
+                match event.token() {
+                    Token::QueueAvailable => {
                         if let Err(e) = queue_evt.read() {
                             error!("failed reading queue EventFd: {:?}", e);
                             break 'poll;
                         }
                         needs_interrupt |= self.process_queue(0);
                     }
-                    KILL => break 'poll,
-                    _ => unreachable!(),
+                    Token::Kill => break 'poll,
                 }
             }
             if needs_interrupt {
diff --git a/seccomp/aarch64/block_device.policy b/seccomp/aarch64/block_device.policy
index 2d6fca6..2818412 100644
--- a/seccomp/aarch64/block_device.policy
+++ b/seccomp/aarch64/block_device.policy
@@ -30,3 +30,6 @@ getpid: 1
 # Allow PR_SET_NAME only.
 prctl: arg0 == 15
 restart_syscall: 1
+epoll_create1: 1
+epoll_ctl: 1
+epoll_wait: 1
diff --git a/seccomp/x86_64/block_device.policy b/seccomp/x86_64/block_device.policy
index 5099171..22a6846 100644
--- a/seccomp/x86_64/block_device.policy
+++ b/seccomp/x86_64/block_device.policy
@@ -32,3 +32,6 @@ getpid: 1
 # Allow PR_SET_NAME only.
 prctl: arg0 == 15
 restart_syscall: 1
+epoll_create1: 1
+epoll_ctl: 1
+epoll_wait: 1
\ No newline at end of file