Patchwork [03/15] rng random backend: check for -EAGAIN errors on read

login
register
mail settings
Submitter Michael Roth
Date May 14, 2013, 9:53 p.m.
Message ID <1368568392-2127-4-git-send-email-mdroth@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/243838/
State New
Headers show

Comments

Michael Roth - May 14, 2013, 9:53 p.m.
From: Amit Shah <amit.shah@redhat.com>

Not handling EAGAIN triggers the assert

qemu/backends/rng-random.c:44:entropy_available: assertion failed: (len != -1)
Aborted (core dumped)

This happens when starting a guest with '-device virtio-rng-pci',
issuing a 'cat /dev/hwrng' in the guest, while also doing 'cat
/dev/random' on the host.

Reported-by: yunpingzheng <yunzheng@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Message-id: eacda84dfaf2d99cf6d250b678be4e4d6c2088fb.1366108096.git.amit.shah@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
(cherry picked from commit acbbc036619092fcd2c882222e1be168bd972b3e)

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 backends/rng-random.c |    3 +++
 1 file changed, 3 insertions(+)

Patch

diff --git a/backends/rng-random.c b/backends/rng-random.c
index 0d11088..813388b 100644
--- a/backends/rng-random.c
+++ b/backends/rng-random.c
@@ -41,6 +41,9 @@  static void entropy_available(void *opaque)
     ssize_t len;
 
     len = read(s->fd, buffer, s->size);
+    if (len < 0 && errno == EAGAIN) {
+        return;
+    }
     g_assert(len != -1);
 
     s->receive_func(s->opaque, buffer, len);