qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
To: target-devel <target-devel@vger.kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>,
	Anthony Liguori <aliguori@us.ibm.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	kvm-devel <kvm@vger.kernel.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	Zhi Yong Wu <wuzhy@cn.ibm.com>,
	Anthony Liguori <aliguori@linux.vnet.ibm.com>,
	Hannes Reinecke <hare@suse.de>,
	Paolo Bonzini <pbonzini@redhat.com>,
	lf-virt <virtualization@lists.linux-foundation.org>,
	Christoph Hellwig <hch@lst.de>
Subject: [Qemu-devel] [RFC 1/9] notifier: add validity check and notify function
Date: Tue, 24 Jul 2012 22:33:58 +0000	[thread overview]
Message-ID: <1343169246-17636-2-git-send-email-nab@linux-iscsi.org> (raw)
In-Reply-To: <1343169246-17636-1-git-send-email-nab@linux-iscsi.org>

From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

Event notifiers that have not had the event_notifier_init() function
called on them are invalid.  The event_notifier_valid() function checks
whether or not an event notifier is valild.  This can be used to check
whether a notifier is in use or not.

It sometimes useful to notify the event notifier, for example when vhost
is on the receiving end of the event notifier and qemu needs to notify
it.  The event_notifier_notify() function will signal the eventfd and
increment it by one.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
 event_notifier.c |   21 +++++++++++++++++++++
 event_notifier.h |    4 ++++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/event_notifier.c b/event_notifier.c
index 2c207e1..efe00ea 100644
--- a/event_notifier.c
+++ b/event_notifier.c
@@ -25,6 +25,7 @@ void event_notifier_init_fd(EventNotifier *e, int fd)
 
 int event_notifier_init(EventNotifier *e, int active)
 {
+    assert(!event_notifier_valid(e));
 #ifdef CONFIG_EVENTFD
     int fd = eventfd(!!active, EFD_NONBLOCK | EFD_CLOEXEC);
     if (fd < 0)
@@ -39,6 +40,12 @@ int event_notifier_init(EventNotifier *e, int active)
 void event_notifier_cleanup(EventNotifier *e)
 {
     close(e->fd);
+    e->fd = -1;
+}
+
+bool event_notifier_valid(EventNotifier *e)
+{
+    return e->fd != -1;
 }
 
 int event_notifier_get_fd(EventNotifier *e)
@@ -65,3 +72,17 @@ int event_notifier_test_and_clear(EventNotifier *e)
     int r = read(e->fd, &value, sizeof(value));
     return r == sizeof(value);
 }
+
+int event_notifier_notify(EventNotifier *e)
+{
+    uint64_t value = 1;
+    int r;
+
+    assert(event_notifier_valid(e));
+    r = write(e->fd, &value, sizeof(value));
+    if (r < 0) {
+        return -errno;
+    }
+    assert(r == sizeof(value));
+    return 0;
+}
diff --git a/event_notifier.h b/event_notifier.h
index f0ec2f2..eea10a9 100644
--- a/event_notifier.h
+++ b/event_notifier.h
@@ -15,6 +15,8 @@
 
 #include "qemu-common.h"
 
+#define EVENT_NOTIFIER_INITIALIZER ((EventNotifier){ .fd = -1 })
+
 struct EventNotifier {
     int fd;
 };
@@ -24,9 +26,11 @@ typedef void EventNotifierHandler(EventNotifier *);
 void event_notifier_init_fd(EventNotifier *, int fd);
 int event_notifier_init(EventNotifier *, int active);
 void event_notifier_cleanup(EventNotifier *);
+bool event_notifier_valid(EventNotifier *e);
 int event_notifier_get_fd(EventNotifier *);
 int event_notifier_set(EventNotifier *);
 int event_notifier_test_and_clear(EventNotifier *);
 int event_notifier_set_handler(EventNotifier *, EventNotifierHandler *);
+int event_notifier_notify(EventNotifier *e);
 
 #endif
-- 
1.7.2.5

  reply	other threads:[~2012-07-24 22:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-24 22:33 [Qemu-devel] [RFC 0/9] vhost-scsi: Add support for host virtualized target Nicholas A. Bellinger
2012-07-24 22:33 ` Nicholas A. Bellinger [this message]
2012-07-25  6:53   ` [Qemu-devel] [RFC 1/9] notifier: add validity check and notify function Paolo Bonzini
2012-07-24 22:33 ` [Qemu-devel] [RFC 2/9] virtio-pci: support host notifiers in TCG mode Nicholas A. Bellinger
2012-07-25  6:50   ` Paolo Bonzini
2012-07-24 22:34 ` [Qemu-devel] [RFC 3/9] virtio-pci: check that event notification worked Nicholas A. Bellinger
2012-07-24 22:34 ` [Qemu-devel] [RFC 4/9] vhost: Pass device path to vhost_dev_init() Nicholas A. Bellinger
2012-07-24 22:34 ` [Qemu-devel] [RFC 5/9] virtio-scsi: Add wwpn and tgpt properties Nicholas A. Bellinger
2012-07-24 22:34 ` [Qemu-devel] [RFC 6/9] virtio-scsi: Open and initialize /dev/vhost-scsi Nicholas A. Bellinger
2012-07-25  7:05   ` Paolo Bonzini
2012-07-24 22:34 ` [Qemu-devel] [RFC 7/9] virtio-scsi: Start/stop vhost Nicholas A. Bellinger
2012-07-25  7:01   ` Paolo Bonzini
2012-07-25  7:03     ` Paolo Bonzini
2012-07-24 22:34 ` [Qemu-devel] [RFC 8/9] virtio-scsi: Set max_target=0 during vhost-scsi operation Nicholas A. Bellinger
2012-07-24 22:34 ` [Qemu-devel] [RFC 9/9] vhost-scsi: add -vhost-scsi host device Nicholas A. Bellinger
2012-07-25  6:58   ` Paolo Bonzini
2012-07-25  2:53 ` [Qemu-devel] [RFC 0/9] vhost-scsi: Add support for host virtualized target Zhi Yong Wu

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=1343169246-17636-2-git-send-email-nab@linux-iscsi.org \
    --to=nab@linux-iscsi.org \
    --cc=aliguori@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    --cc=target-devel@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=wuzhy@cn.ibm.com \
    /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).