From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org
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 [thread overview]
Message-ID: <1265843356-25765-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1265843356-25765-1-git-send-email-pbonzini@redhat.com>
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 <pbonzini@redhat.com>
---
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
next prev parent reply other threads:[~2010-02-10 23:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-10 23:09 [Qemu-devel] [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream Paolo Bonzini
2010-02-10 23:09 ` Paolo Bonzini [this message]
2010-02-10 23:09 ` [Qemu-devel] [PATCH 2/4] qemu-kvm: morph io_thread_wakeup into qemu.git's qemu_event_read Paolo Bonzini
2010-02-10 23:09 ` [Qemu-devel] [PATCH 3/4] qemu-kvm: fix placement of config-host.h inclusion Paolo Bonzini
2010-02-10 23:09 ` [Qemu-devel] [PATCH 4/4] qemu-kvm: move qemu_eventfd to osdep.c Paolo Bonzini
2010-02-13 13:26 ` [Qemu-devel] Re: [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream Marcelo Tosatti
2010-02-14 12:32 ` Avi Kivity
2010-02-17 12:53 ` Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1265843356-25765-2-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).