[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 08/16] notifier: add validity check and notify funct
From: |
zwu . kernel |
Subject: |
[Qemu-devel] [PATCH 08/16] notifier: add validity check and notify function |
Date: |
Thu, 19 Apr 2012 10:39:01 +0800 |
From: Stefan Hajnoczi <address@hidden>
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 <address@hidden>
---
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 0b82981..a3d42db 100644
--- a/event_notifier.c
+++ b/event_notifier.c
@@ -17,6 +17,7 @@
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)
@@ -31,6 +32,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)
@@ -59,3 +66,17 @@ int event_notifier_test(EventNotifier *e)
}
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 886222c..a81295e 100644
--- a/event_notifier.h
+++ b/event_notifier.h
@@ -15,14 +15,18 @@
#include "qemu-common.h"
+#define EVENT_NOTIFIER_INITIALIZER ((EventNotifier){ .fd = -1 })
+
struct 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_test_and_clear(EventNotifier *);
int event_notifier_test(EventNotifier *);
+int event_notifier_notify(EventNotifier *e);
#endif
--
1.7.6
- [Qemu-devel] [PATCH 03/16] virtio-scsi: Add vhost_vring_target ioctl struct, (continued)
- [Qemu-devel] [PATCH 03/16] virtio-scsi: Add vhost_vring_target ioctl struct, zwu . kernel, 2012/04/18
- [Qemu-devel] [PATCH 06/16] virtio-scsi: Open and initialize /dev/vhost-scsi, zwu . kernel, 2012/04/18
- [Qemu-devel] [PATCH 01/16] virtio-scsi: Add wwpn and tgpt properties, zwu . kernel, 2012/04/18
- [Qemu-devel] [PATCH 13/16] virtio-scsi: WIP VHOST_SCSI_SET_ENDPOINT call, zwu . kernel, 2012/04/18
- [Qemu-devel] [PATCH 12/16] virtio-scsi: use the vhost-scsi host device, zwu . kernel, 2012/04/18
- [Qemu-devel] [PATCH 14/16] vhost-scsi: enable vhost notifiers for multiple queues, zwu . kernel, 2012/04/18
- [Qemu-devel] [PATCH 09/16] virtio-pci: support host notifiers in TCG mode, zwu . kernel, 2012/04/18
- [Qemu-devel] [PATCH 11/16] vhost-scsi: add -vhost-scsi host device, zwu . kernel, 2012/04/18
- [Qemu-devel] [PATCH 08/16] notifier: add validity check and notify function,
zwu . kernel <=
- [Qemu-devel] [PATCH 15/16] vhost-scsi: move some definitions to its header file, zwu . kernel, 2012/04/18
- [Qemu-devel] [PATCH 10/16] virtio-pci: check that event notification worked, zwu . kernel, 2012/04/18
- [Qemu-devel] [PATCH 16/16] vhost-scsi: clear endpoint on stopped, zwu . kernel, 2012/04/18
- Re: [Qemu-devel] [PATCH 00/16] QEMU vhost-scsi support, Paolo Bonzini, 2012/04/19
- Re: [Qemu-devel] [PATCH 00/16] QEMU vhost-scsi support, Anthony Liguori, 2012/04/19