提交 25905a78 编写于 作者: D Daniel P. Berrange

Switch to using internal event API for QEMU driver

上级 133fdfe9
Tue Jun 26 18:47:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* src/event.h, src/event.c, src/Makefile.am, src/libvirt_sym.version:
Provide an internal API for drivers to register callbacks for
monitoring file handles & generating timer notifications.
* qemud/driver.c, qemud/event.c, qemud/event.h, qemud/qemud.c:
Adapt to make use of internal driver API for events.
Tue Jun 26 18:41:00 EST 2007 Daniel P. Berrange <berrange@redhat.com> Tue Jun 26 18:41:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* qemud/conf.c, qemud/conf.h, qemud/dispatch.c, qemud/driver.c, * qemud/conf.c, qemud/conf.h, qemud/dispatch.c, qemud/driver.c,
......
...@@ -49,6 +49,8 @@ ignored_files = { ...@@ -49,6 +49,8 @@ ignored_files = {
"conf.c": "internal code", "conf.c": "internal code",
"console.h": "internal code", "console.h": "internal code",
"console.c": "internal code", "console.c": "internal code",
"event.h": "internal code",
"event.c": "internal code",
} }
ignored_words = { ignored_words = {
......
...@@ -81,6 +81,9 @@ static int qemudSetNonBlock(int fd) { ...@@ -81,6 +81,9 @@ static int qemudSetNonBlock(int fd) {
} }
#define virEventAddHandle(fd, events, cb, opaque) virEventAddHandleImpl(fd, events, cb, opaque)
#define virEventRemoveHandle(fd) virEventRemoveHandleImpl(fd)
static void qemudDispatchVMEvent(int fd, int events, void *opaque); static void qemudDispatchVMEvent(int fd, int events, void *opaque);
int qemudStartVMDaemon(struct qemud_driver *driver, int qemudStartVMDaemon(struct qemud_driver *driver,
......
...@@ -76,7 +76,7 @@ static int nextTimer = 0; ...@@ -76,7 +76,7 @@ static int nextTimer = 0;
* NB, it *must* be safe to call this from within a callback * NB, it *must* be safe to call this from within a callback
* For this reason we only ever append to existing list. * For this reason we only ever append to existing list.
*/ */
int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void *opaque) { int virEventAddHandleImpl(int fd, int events, virEventHandleCallback cb, void *opaque) {
qemudDebug("Add handle %d %d %p %p\n", fd, events, cb, opaque); qemudDebug("Add handle %d %d %p %p\n", fd, events, cb, opaque);
if (eventLoop.handlesCount == eventLoop.handlesAlloc) { if (eventLoop.handlesCount == eventLoop.handlesAlloc) {
struct virEventHandle *tmp; struct virEventHandle *tmp;
...@@ -109,7 +109,7 @@ int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void *opaqu ...@@ -109,7 +109,7 @@ int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void *opaqu
* For this reason we only ever set a flag in the existing list. * For this reason we only ever set a flag in the existing list.
* Actual deletion will be done out-of-band * Actual deletion will be done out-of-band
*/ */
int virEventRemoveHandle(int fd) { int virEventRemoveHandleImpl(int fd) {
int i; int i;
qemudDebug("Remove handle %d\n", fd); qemudDebug("Remove handle %d\n", fd);
for (i = 0 ; i < eventLoop.handlesCount ; i++) { for (i = 0 ; i < eventLoop.handlesCount ; i++) {
...@@ -131,7 +131,7 @@ int virEventRemoveHandle(int fd) { ...@@ -131,7 +131,7 @@ int virEventRemoveHandle(int fd) {
* NB, it *must* be safe to call this from within a callback * NB, it *must* be safe to call this from within a callback
* For this reason we only ever append to existing list. * For this reason we only ever append to existing list.
*/ */
int virEventAddTimeout(int timeout, virEventTimeoutCallback cb, void *opaque) { int virEventAddTimeoutImpl(int timeout, virEventTimeoutCallback cb, void *opaque) {
struct timeval tv; struct timeval tv;
qemudDebug("Adding timeout with %d ms period", timeout); qemudDebug("Adding timeout with %d ms period", timeout);
if (gettimeofday(&tv, NULL) < 0) { if (gettimeofday(&tv, NULL) < 0) {
...@@ -173,7 +173,7 @@ int virEventAddTimeout(int timeout, virEventTimeoutCallback cb, void *opaque) { ...@@ -173,7 +173,7 @@ int virEventAddTimeout(int timeout, virEventTimeoutCallback cb, void *opaque) {
* For this reason we only ever set a flag in the existing list. * For this reason we only ever set a flag in the existing list.
* Actual deletion will be done out-of-band * Actual deletion will be done out-of-band
*/ */
int virEventRemoveTimeout(int timer) { int virEventRemoveTimeoutImpl(int timer) {
int i; int i;
for (i = 0 ; i < eventLoop.timeoutsCount ; i++) { for (i = 0 ; i < eventLoop.timeoutsCount ; i++) {
if (eventLoop.timeouts[i].deleted) if (eventLoop.timeouts[i].deleted)
......
...@@ -24,18 +24,10 @@ ...@@ -24,18 +24,10 @@
#ifndef __VIRTD_EVENT_H__ #ifndef __VIRTD_EVENT_H__
#define __VIRTD_EVENT_H__ #define __VIRTD_EVENT_H__
#include "../src/event.h"
/** /**
* virEventHandleCallback: callback for receiving file handle events * virEventAddHandleImpl: register a callback for monitoring file handle events
*
* @fd: file handle on which the event occured
* @events: bitset of events from POLLnnn constants
* @opaque: user data registered with handle
*/
typedef void (*virEventHandleCallback)(int fd, int events, void *opaque);
/**
* virEventAddHandle: register a callback for monitoring file handle events
* *
* @fd: file handle to monitor for events * @fd: file handle to monitor for events
* @events: bitset of events to wach from POLLnnn constants * @events: bitset of events to wach from POLLnnn constants
...@@ -44,27 +36,19 @@ typedef void (*virEventHandleCallback)(int fd, int events, void *opaque); ...@@ -44,27 +36,19 @@ typedef void (*virEventHandleCallback)(int fd, int events, void *opaque);
* *
* returns -1 if the file handle cannot be registered, 0 upon success * returns -1 if the file handle cannot be registered, 0 upon success
*/ */
int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void *opaque); int virEventAddHandleImpl(int fd, int events, virEventHandleCallback cb, void *opaque);
/** /**
* virEventRemoveHandle: unregister a callback from a file handle * virEventRemoveHandleImpl: unregister a callback from a file handle
* *
* @fd: file handle to stop monitoring for events * @fd: file handle to stop monitoring for events
* *
* returns -1 if the file handle was not registered, 0 upon success * returns -1 if the file handle was not registered, 0 upon success
*/ */
int virEventRemoveHandle(int fd); int virEventRemoveHandleImpl(int fd);
/** /**
* virEventTimeoutCallback: callback for receiving timer events * virEventAddTimeoutImpl: register a callback for a timer event
*
* @timer: timer id emitting the event
* @opaque: user data registered with handle
*/
typedef void (*virEventTimeoutCallback)(int timer, void *opaque);
/**
* virEventAddTimeout: register a callback for a timer event
* *
* @timeout: timeout between events in milliseconds * @timeout: timeout between events in milliseconds
* @cb: callback to invoke when an event occurrs * @cb: callback to invoke when an event occurrs
...@@ -73,17 +57,16 @@ typedef void (*virEventTimeoutCallback)(int timer, void *opaque); ...@@ -73,17 +57,16 @@ typedef void (*virEventTimeoutCallback)(int timer, void *opaque);
* returns -1 if the file handle cannot be registered, a positive * returns -1 if the file handle cannot be registered, a positive
* integer timer id upon success * integer timer id upon success
*/ */
int virEventAddTimeout(int timeout, virEventTimeoutCallback cb, void *opaque); int virEventAddTimeoutImpl(int timeout, virEventTimeoutCallback cb, void *opaque);
/** /**
* virEventRemoveTimeout: unregister a callback for a timer * virEventRemoveTimeoutImpl: unregister a callback for a timer
* *
* @timer: the timer id to remove * @timer: the timer id to remove
* *
* returns -1 if the timer was not registered, 0 upon success * returns -1 if the timer was not registered, 0 upon success
*/ */
int virEventRemoveTimeout(int timer); int virEventRemoveTimeoutImpl(int timer);
/** /**
* virEventRunOnce: run a single iteration of the event loop. * virEventRunOnce: run a single iteration of the event loop.
......
...@@ -471,10 +471,10 @@ static int qemudListenUnix(struct qemud_server *server, ...@@ -471,10 +471,10 @@ static int qemudListenUnix(struct qemud_server *server,
goto cleanup; goto cleanup;
} }
if (virEventAddHandle(sock->fd, if (virEventAddHandleImpl(sock->fd,
POLLIN| POLLERR | POLLHUP, POLLIN| POLLERR | POLLHUP,
qemudDispatchServerEvent, qemudDispatchServerEvent,
server) < 0) { server) < 0) {
qemudLog(QEMUD_ERR, "Failed to add server event callback"); qemudLog(QEMUD_ERR, "Failed to add server event callback");
goto cleanup; goto cleanup;
} }
...@@ -584,10 +584,10 @@ remoteListenTCP (struct qemud_server *server, ...@@ -584,10 +584,10 @@ remoteListenTCP (struct qemud_server *server,
return -1; return -1;
} }
if (virEventAddHandle(sock->fd, if (virEventAddHandleImpl(sock->fd,
POLLIN| POLLERR | POLLHUP, POLLIN| POLLERR | POLLHUP,
qemudDispatchServerEvent, qemudDispatchServerEvent,
server) < 0) { server) < 0) {
qemudLog(QEMUD_ERR, "Failed to add server event callback"); qemudLog(QEMUD_ERR, "Failed to add server event callback");
return -1; return -1;
} }
...@@ -1056,7 +1056,7 @@ static void qemudDispatchClientFailure(struct qemud_server *server, struct qemud ...@@ -1056,7 +1056,7 @@ static void qemudDispatchClientFailure(struct qemud_server *server, struct qemud
tmp = tmp->next; tmp = tmp->next;
} }
virEventRemoveHandle(client->fd); virEventRemoveHandleImpl(client->fd);
if (client->tls && client->session) gnutls_deinit (client->session); if (client->tls && client->session) gnutls_deinit (client->session);
close(client->fd); close(client->fd);
...@@ -1418,22 +1418,22 @@ static int qemudRegisterClientEvent(struct qemud_server *server, ...@@ -1418,22 +1418,22 @@ static int qemudRegisterClientEvent(struct qemud_server *server,
struct qemud_client *client, struct qemud_client *client,
int removeFirst) { int removeFirst) {
if (removeFirst) if (removeFirst)
if (virEventRemoveHandle(client->fd) < 0) if (virEventRemoveHandleImpl(client->fd) < 0)
return -1; return -1;
if (client->tls) { if (client->tls) {
if (virEventAddHandle(client->fd, if (virEventAddHandleImpl(client->fd,
(client->direction ? (client->direction ?
POLLOUT : POLLIN) | POLLERR | POLLHUP, POLLOUT : POLLIN) | POLLERR | POLLHUP,
qemudDispatchClientEvent, qemudDispatchClientEvent,
server) < 0) server) < 0)
return -1; return -1;
} else { } else {
if (virEventAddHandle(client->fd, if (virEventAddHandleImpl(client->fd,
(client->mode == QEMUD_MODE_TX_PACKET ? (client->mode == QEMUD_MODE_TX_PACKET ?
POLLOUT : POLLIN) | POLLERR | POLLHUP, POLLOUT : POLLIN) | POLLERR | POLLHUP,
qemudDispatchClientEvent, qemudDispatchClientEvent,
server) < 0) server) < 0)
return -1; return -1;
} }
...@@ -1864,10 +1864,10 @@ int main(int argc, char **argv) { ...@@ -1864,10 +1864,10 @@ int main(int argc, char **argv) {
goto error2; goto error2;
} }
if (virEventAddHandle(sigpipe[0], if (virEventAddHandleImpl(sigpipe[0],
POLLIN, POLLIN,
qemudDispatchSignalEvent, qemudDispatchSignalEvent,
server) < 0) { server) < 0) {
qemudLog(QEMUD_ERR, "Failed to register callback for signal pipe"); qemudLog(QEMUD_ERR, "Failed to register callback for signal pipe");
ret = 3; ret = 3;
goto error2; goto error2;
......
...@@ -31,6 +31,7 @@ CLIENT_SOURCES = \ ...@@ -31,6 +31,7 @@ CLIENT_SOURCES = \
test.c test.h \ test.c test.h \
buf.c buf.h \ buf.c buf.h \
xml.c xml.h \ xml.c xml.h \
event.c event.h \
xen_unified.c xen_unified.h \ xen_unified.c xen_unified.h \
xen_internal.c xen_internal.h \ xen_internal.c xen_internal.h \
xs_internal.c xs_internal.h \ xs_internal.c xs_internal.h \
......
/*
* event.h: event loop for monitoring file handles
*
* Copyright (C) 2007 Daniel P. Berrange
* Copyright (C) 2007 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Daniel P. Berrange <berrange@redhat.com>
*/
#include "event.h"
#include <stdlib.h>
static virEventAddHandleFunc addHandleImpl = NULL;
static virEventRemoveHandleFunc removeHandleImpl = NULL;
static virEventAddTimeoutFunc addTimeoutImpl = NULL;
static virEventRemoveTimeoutFunc removeTimeoutImpl = NULL;
int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void *opaque) {
if (!addHandleImpl)
return -1;
return addHandleImpl(fd, events, cb, opaque);
}
int virEventRemoveHandle(int fd) {
if (!removeHandleImpl)
return -1;
return removeHandleImpl(fd);
}
int virEventAddTimeout(int timeout, virEventTimeoutCallback cb, void *opaque) {
if (!addTimeoutImpl)
return -1;
return addTimeoutImpl(timeout, cb, opaque);
}
int virEventRemoveTimeout(int timer) {
if (!removeTimeoutImpl)
return -1;
return removeTimeoutImpl(timer);
}
void __virEventRegisterImpl(virEventAddHandleFunc addHandle,
virEventRemoveHandleFunc removeHandle,
virEventAddTimeoutFunc addTimeout,
virEventRemoveTimeoutFunc removeTimeout) {
addHandleImpl = addHandle;
removeHandleImpl = removeHandle;
addTimeoutImpl = addTimeout;
removeTimeoutImpl = removeTimeout;
}
/*
* Local variables:
* indent-tabs-mode: nil
* c-indent-level: 4
* c-basic-offset: 4
* tab-width: 4
* End:
*/
/*
* event.h: event loop for monitoring file handles
*
* Copyright (C) 2007 Daniel P. Berrange
* Copyright (C) 2007 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Daniel P. Berrange <berrange@redhat.com>
*/
#ifndef __VIR_EVENT_H__
#define __VIR_EVENT_H__
/**
* virEventHandleCallback: callback for receiving file handle events
*
* @fd: file handle on which the event occured
* @events: bitset of events from POLLnnn constants
* @opaque: user data registered with handle
*/
typedef void (*virEventHandleCallback)(int fd, int events, void *opaque);
/**
* virEventAddHandle: register a callback for monitoring file handle events
*
* @fd: file handle to monitor for events
* @events: bitset of events to wach from POLLnnn constants
* @cb: callback to invoke when an event occurrs
* @opaque: user data to pass to callback
*
* returns -1 if the file handle cannot be registered, 0 upon success
*/
int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void *opaque);
/**
* virEventRemoveHandle: unregister a callback from a file handle
*
* @fd: file handle to stop monitoring for events
*
* returns -1 if the file handle was not registered, 0 upon success
*/
int virEventRemoveHandle(int fd);
/**
* virEventTimeoutCallback: callback for receiving timer events
*
* @timer: timer id emitting the event
* @opaque: user data registered with handle
*/
typedef void (*virEventTimeoutCallback)(int timer, void *opaque);
/**
* virEventAddTimeout: register a callback for a timer event
*
* @timeout: timeout between events in milliseconds
* @cb: callback to invoke when an event occurrs
* @opaque: user data to pass to callback
*
* returns -1 if the file handle cannot be registered, a positive
* integer timer id upon success
*/
int virEventAddTimeout(int timeout, virEventTimeoutCallback cb, void *opaque);
/**
* virEventRemoveTimeout: unregister a callback for a timer
*
* @timer: the timer id to remove
*
* returns -1 if the timer was not registered, 0 upon success
*/
int virEventRemoveTimeout(int timer);
typedef int (*virEventAddHandleFunc)(int, int, virEventHandleCallback, void *);
typedef int (*virEventRemoveHandleFunc)(int);
typedef int (*virEventAddTimeoutFunc)(int, virEventTimeoutCallback, void *);
typedef int (*virEventRemoveTimeoutFunc)(int);
void __virEventRegisterImpl(virEventAddHandleFunc addHandle,
virEventRemoveHandleFunc removeHandle,
virEventAddTimeoutFunc addTimeout,
virEventRemoveTimeoutFunc removeTimeout);
#define virEventRegisterImpl(ah,rh,at,rt) __virEventRegisterImpl(ah,rh,at,rt)
#endif /* __VIR_EVENT_H__ */
...@@ -91,6 +91,12 @@ ...@@ -91,6 +91,12 @@
virNetworkGetAutostart; virNetworkGetAutostart;
virNetworkSetAutostart; virNetworkSetAutostart;
/* Symbols with __ are private only
for use by the libvirtd daemon.
They are not part of stable ABI
guarentee provided for the public
symbols above */
__virConfNew; __virConfNew;
__virConfReadFile; __virConfReadFile;
__virConfReadMem; __virConfReadMem;
...@@ -103,5 +109,7 @@ ...@@ -103,5 +109,7 @@
__virGetDomain; __virGetDomain;
__virGetNetwork; __virGetNetwork;
__virEventRegisterImpl;
local: *; local: *;
}; };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册