qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/4] qemu-kvm: morph qemu_kvm_notify_work into qemu.


From: Paolo Bonzini
Subject: [Qemu-devel] [PATCH 1/4] qemu-kvm: morph qemu_kvm_notify_work into qemu.git's qemu_event_increment
Date: Thu, 11 Feb 2010 00:09:13 +0100

No need to loop if < 8 bytes are written, since that will happen only
for pipes and is harmless.  eventfd writes of 8 bytes will always succeed
or fail with EAGAIN.

Signed-off-by: Paolo Bonzini <address@hidden>
---
 qemu-kvm.c |   34 ++++++++++++----------------------
 1 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/qemu-kvm.c b/qemu-kvm.c
index a305907..669a784 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -1991,32 +1991,22 @@ int kvm_init_ap(void)
 
 void qemu_kvm_notify_work(void)
 {
-    uint64_t value = 1;
-    char buffer[8];
-    size_t offset = 0;
+    /* Write 8 bytes to be compatible with eventfd.  */
+    static uint64_t val = 1;
+    ssize_t ret;
 
     if (io_thread_fd == -1)
         return;
 
-    memcpy(buffer, &value, sizeof(value));
-
-    while (offset < 8) {
-        ssize_t len;
-
-        len = write(io_thread_fd, buffer + offset, 8 - offset);
-        if (len == -1 && errno == EINTR)
-            continue;
-
-        /* In case we have a pipe, there is not reason to insist writing
-         * 8 bytes
-         */
-        if (len == -1 && errno == EAGAIN)
-            break;
-
-        if (len <= 0)
-            break;
-
-        offset += len;
+    do {
+        ret = write(io_thread_fd, &val, sizeof(val));
+    } while (ret < 0 && errno == EINTR);
+
+    /* EAGAIN is fine in case we have a pipe.  */
+    if (ret < 0 && errno != EAGAIN) {
+         fprintf(stderr, "qemu_kvm_notify_work: write() filed: %s\n",
+                 strerror(errno));
+         exit (1);
     }
 }
 
-- 
1.6.6






reply via email to

[Prev in Thread] Current Thread [Next in Thread]