mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
Convert daemon/virsh over to use primary event APIs, rather than impl
The daemon code calls virEventAddHandleImpl directly instead of calling the wrapper virEventAddHandle. * tools/console.c, daemon/libvirtd.c, daemon/mdns.c: Convert to use primary event APIs
This commit is contained in:
parent
bcb40b852c
commit
5d2c045cd8
@ -63,6 +63,7 @@
|
|||||||
#include "remote_driver.h"
|
#include "remote_driver.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
#include "src/util/event.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
#include "hooks.h"
|
#include "hooks.h"
|
||||||
@ -1104,12 +1105,12 @@ static int qemudNetworkEnable(struct qemud_server *server) {
|
|||||||
|
|
||||||
sock = server->sockets;
|
sock = server->sockets;
|
||||||
while (sock) {
|
while (sock) {
|
||||||
if ((sock->watch = virEventAddHandleImpl(sock->fd,
|
if ((sock->watch = virEventAddHandle(sock->fd,
|
||||||
VIR_EVENT_HANDLE_READABLE |
|
VIR_EVENT_HANDLE_READABLE |
|
||||||
VIR_EVENT_HANDLE_ERROR |
|
VIR_EVENT_HANDLE_ERROR |
|
||||||
VIR_EVENT_HANDLE_HANGUP,
|
VIR_EVENT_HANDLE_HANGUP,
|
||||||
qemudDispatchServerEvent,
|
qemudDispatchServerEvent,
|
||||||
server, NULL)) < 0) {
|
server, NULL)) < 0) {
|
||||||
VIR_ERROR0(_("Failed to add server event callback"));
|
VIR_ERROR0(_("Failed to add server event callback"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1541,7 +1542,7 @@ error:
|
|||||||
*/
|
*/
|
||||||
void qemudDispatchClientFailure(struct qemud_client *client) {
|
void qemudDispatchClientFailure(struct qemud_client *client) {
|
||||||
if (client->watch != -1) {
|
if (client->watch != -1) {
|
||||||
virEventRemoveHandleImpl(client->watch);
|
virEventRemoveHandle(client->watch);
|
||||||
client->watch = -1;
|
client->watch = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2235,10 +2236,10 @@ int qemudRegisterClientEvent(struct qemud_server *server,
|
|||||||
|
|
||||||
mode = qemudCalculateHandleMode(client);
|
mode = qemudCalculateHandleMode(client);
|
||||||
|
|
||||||
if ((client->watch = virEventAddHandleImpl(client->fd,
|
if ((client->watch = virEventAddHandle(client->fd,
|
||||||
mode,
|
mode,
|
||||||
qemudDispatchClientEvent,
|
qemudDispatchClientEvent,
|
||||||
server, NULL)) < 0)
|
server, NULL)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -2252,7 +2253,7 @@ void qemudUpdateClientEvent(struct qemud_client *client) {
|
|||||||
|
|
||||||
mode = qemudCalculateHandleMode(client);
|
mode = qemudCalculateHandleMode(client);
|
||||||
|
|
||||||
virEventUpdateHandleImpl(client->watch, mode);
|
virEventUpdateHandle(client->watch, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2304,7 +2305,7 @@ static void qemudInactiveTimer(int timerid, void *data) {
|
|||||||
if (virStateActive() ||
|
if (virStateActive() ||
|
||||||
server->clients) {
|
server->clients) {
|
||||||
VIR_DEBUG0("Timer expired but still active, not shutting down");
|
VIR_DEBUG0("Timer expired but still active, not shutting down");
|
||||||
virEventUpdateTimeoutImpl(timerid, -1);
|
virEventUpdateTimeout(timerid, -1);
|
||||||
} else {
|
} else {
|
||||||
VIR_DEBUG0("Timer expired and inactive, shutting down");
|
VIR_DEBUG0("Timer expired and inactive, shutting down");
|
||||||
server->quitEventThread = 1;
|
server->quitEventThread = 1;
|
||||||
@ -2347,9 +2348,9 @@ static void *qemudRunLoop(void *opaque) {
|
|||||||
virMutexLock(&server->lock);
|
virMutexLock(&server->lock);
|
||||||
|
|
||||||
if (timeout > 0 &&
|
if (timeout > 0 &&
|
||||||
(timerid = virEventAddTimeoutImpl(-1,
|
(timerid = virEventAddTimeout(-1,
|
||||||
qemudInactiveTimer,
|
qemudInactiveTimer,
|
||||||
server, NULL)) < 0) {
|
server, NULL)) < 0) {
|
||||||
VIR_ERROR0(_("Failed to register shutdown timeout"));
|
VIR_ERROR0(_("Failed to register shutdown timeout"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -2378,14 +2379,14 @@ static void *qemudRunLoop(void *opaque) {
|
|||||||
if (timerActive) {
|
if (timerActive) {
|
||||||
if (server->clients) {
|
if (server->clients) {
|
||||||
VIR_DEBUG("Deactivating shutdown timer %d", timerid);
|
VIR_DEBUG("Deactivating shutdown timer %d", timerid);
|
||||||
virEventUpdateTimeoutImpl(timerid, -1);
|
virEventUpdateTimeout(timerid, -1);
|
||||||
timerActive = 0;
|
timerActive = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!virStateActive() &&
|
if (!virStateActive() &&
|
||||||
!server->clients) {
|
!server->clients) {
|
||||||
VIR_DEBUG("Activating shutdown timer %d", timerid);
|
VIR_DEBUG("Activating shutdown timer %d", timerid);
|
||||||
virEventUpdateTimeoutImpl(timerid, timeout * 1000);
|
virEventUpdateTimeout(timerid, timeout * 1000);
|
||||||
timerActive = 1;
|
timerActive = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2501,7 +2502,7 @@ static void qemudCleanup(struct qemud_server *server) {
|
|||||||
while (sock) {
|
while (sock) {
|
||||||
struct qemud_socket *next = sock->next;
|
struct qemud_socket *next = sock->next;
|
||||||
if (sock->watch)
|
if (sock->watch)
|
||||||
virEventRemoveHandleImpl(sock->watch);
|
virEventRemoveHandle(sock->watch);
|
||||||
VIR_FORCE_CLOSE(sock->fd);
|
VIR_FORCE_CLOSE(sock->fd);
|
||||||
|
|
||||||
/* Unlink unix domain sockets which are not in
|
/* Unlink unix domain sockets which are not in
|
||||||
@ -3081,10 +3082,10 @@ daemonSetupSignals(struct qemud_server *server)
|
|||||||
sig_action.sa_handler = SIG_IGN;
|
sig_action.sa_handler = SIG_IGN;
|
||||||
sigaction(SIGPIPE, &sig_action, NULL);
|
sigaction(SIGPIPE, &sig_action, NULL);
|
||||||
|
|
||||||
if (virEventAddHandleImpl(sigpipe[0],
|
if (virEventAddHandle(sigpipe[0],
|
||||||
VIR_EVENT_HANDLE_READABLE,
|
VIR_EVENT_HANDLE_READABLE,
|
||||||
qemudDispatchSignalEvent,
|
qemudDispatchSignalEvent,
|
||||||
server, NULL) < 0) {
|
server, NULL) < 0) {
|
||||||
VIR_ERROR0(_("Failed to register callback for signal pipe"));
|
VIR_ERROR0(_("Failed to register callback for signal pipe"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include "libvirtd.h"
|
#include "libvirtd.h"
|
||||||
#include "mdns.h"
|
#include "mdns.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
#include "src/util/event.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
#define AVAHI_DEBUG(fmt, ...) VIR_DEBUG(fmt, __VA_ARGS__)
|
#define AVAHI_DEBUG(fmt, ...) VIR_DEBUG(fmt, __VA_ARGS__)
|
||||||
@ -257,10 +258,10 @@ static AvahiWatch *libvirtd_mdns_watch_new(const AvahiPoll *api ATTRIBUTE_UNUSED
|
|||||||
|
|
||||||
AVAHI_DEBUG("New handle %p FD %d Event %d", w, w->fd, event);
|
AVAHI_DEBUG("New handle %p FD %d Event %d", w, w->fd, event);
|
||||||
hEvents = virPollEventToEventHandleType(event);
|
hEvents = virPollEventToEventHandleType(event);
|
||||||
if ((w->watch = virEventAddHandleImpl(fd, hEvents,
|
if ((w->watch = virEventAddHandle(fd, hEvents,
|
||||||
libvirtd_mdns_watch_dispatch,
|
libvirtd_mdns_watch_dispatch,
|
||||||
w,
|
w,
|
||||||
libvirtd_mdns_watch_dofree)) < 0) {
|
libvirtd_mdns_watch_dofree)) < 0) {
|
||||||
VIR_FREE(w);
|
VIR_FREE(w);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -271,7 +272,7 @@ static AvahiWatch *libvirtd_mdns_watch_new(const AvahiPoll *api ATTRIBUTE_UNUSED
|
|||||||
static void libvirtd_mdns_watch_update(AvahiWatch *w, AvahiWatchEvent event)
|
static void libvirtd_mdns_watch_update(AvahiWatch *w, AvahiWatchEvent event)
|
||||||
{
|
{
|
||||||
AVAHI_DEBUG("Update handle %p FD %d Event %d", w, w->fd, event);
|
AVAHI_DEBUG("Update handle %p FD %d Event %d", w, w->fd, event);
|
||||||
virEventUpdateHandleImpl(w->watch, event);
|
virEventUpdateHandle(w->watch, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
static AvahiWatchEvent libvirtd_mdns_watch_get_events(AvahiWatch *w)
|
static AvahiWatchEvent libvirtd_mdns_watch_get_events(AvahiWatch *w)
|
||||||
@ -283,14 +284,14 @@ static AvahiWatchEvent libvirtd_mdns_watch_get_events(AvahiWatch *w)
|
|||||||
static void libvirtd_mdns_watch_free(AvahiWatch *w)
|
static void libvirtd_mdns_watch_free(AvahiWatch *w)
|
||||||
{
|
{
|
||||||
AVAHI_DEBUG("Free handle %p %d", w, w->fd);
|
AVAHI_DEBUG("Free handle %p %d", w, w->fd);
|
||||||
virEventRemoveHandleImpl(w->watch);
|
virEventRemoveHandle(w->watch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void libvirtd_mdns_timeout_dispatch(int timer ATTRIBUTE_UNUSED, void *opaque)
|
static void libvirtd_mdns_timeout_dispatch(int timer ATTRIBUTE_UNUSED, void *opaque)
|
||||||
{
|
{
|
||||||
AvahiTimeout *t = (AvahiTimeout*)opaque;
|
AvahiTimeout *t = (AvahiTimeout*)opaque;
|
||||||
AVAHI_DEBUG("Dispatch timeout %p %d", t, timer);
|
AVAHI_DEBUG("Dispatch timeout %p %d", t, timer);
|
||||||
virEventUpdateTimeoutImpl(t->timer, -1);
|
virEventUpdateTimeout(t->timer, -1);
|
||||||
t->callback(t, t->userdata);
|
t->callback(t, t->userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,10 +330,10 @@ static AvahiTimeout *libvirtd_mdns_timeout_new(const AvahiPoll *api ATTRIBUTE_UN
|
|||||||
timeout = -1;
|
timeout = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
t->timer = virEventAddTimeoutImpl(timeout,
|
t->timer = virEventAddTimeout(timeout,
|
||||||
libvirtd_mdns_timeout_dispatch,
|
libvirtd_mdns_timeout_dispatch,
|
||||||
t,
|
t,
|
||||||
libvirtd_mdns_timeout_dofree);
|
libvirtd_mdns_timeout_dofree);
|
||||||
t->callback = cb;
|
t->callback = cb;
|
||||||
t->userdata = userdata;
|
t->userdata = userdata;
|
||||||
|
|
||||||
@ -364,13 +365,13 @@ static void libvirtd_mdns_timeout_update(AvahiTimeout *t, const struct timeval *
|
|||||||
timeout = -1;
|
timeout = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virEventUpdateTimeoutImpl(t->timer, timeout);
|
virEventUpdateTimeout(t->timer, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void libvirtd_mdns_timeout_free(AvahiTimeout *t)
|
static void libvirtd_mdns_timeout_free(AvahiTimeout *t)
|
||||||
{
|
{
|
||||||
AVAHI_DEBUG("Free timeout %p", t);
|
AVAHI_DEBUG("Free timeout %p", t);
|
||||||
virEventRemoveTimeoutImpl(t->timer);
|
virEventRemoveTimeout(t->timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
# include "virterror_internal.h"
|
# include "virterror_internal.h"
|
||||||
|
|
||||||
# include "daemon/event.h"
|
# include "daemon/event.h"
|
||||||
|
# include "src/util/event.h"
|
||||||
|
|
||||||
/* ie Ctrl-] as per telnet */
|
/* ie Ctrl-] as per telnet */
|
||||||
# define CTRL_CLOSE_BRACKET '\35'
|
# define CTRL_CLOSE_BRACKET '\35'
|
||||||
@ -93,9 +94,9 @@ virConsoleShutdown(virConsolePtr con)
|
|||||||
con->quit = true;
|
con->quit = true;
|
||||||
virStreamEventRemoveCallback(con->st);
|
virStreamEventRemoveCallback(con->st);
|
||||||
if (con->stdinWatch != -1)
|
if (con->stdinWatch != -1)
|
||||||
virEventRemoveHandleImpl(con->stdinWatch);
|
virEventRemoveHandle(con->stdinWatch);
|
||||||
if (con->stdinWatch != -1)
|
if (con->stdinWatch != -1)
|
||||||
virEventRemoveHandleImpl(con->stdoutWatch);
|
virEventRemoveHandle(con->stdoutWatch);
|
||||||
con->stdinWatch = -1;
|
con->stdinWatch = -1;
|
||||||
con->stdoutWatch = -1;
|
con->stdoutWatch = -1;
|
||||||
}
|
}
|
||||||
@ -134,8 +135,8 @@ virConsoleEventOnStream(virStreamPtr st,
|
|||||||
}
|
}
|
||||||
con->streamToTerminal.offset += got;
|
con->streamToTerminal.offset += got;
|
||||||
if (con->streamToTerminal.offset)
|
if (con->streamToTerminal.offset)
|
||||||
virEventUpdateHandleImpl(con->stdoutWatch,
|
virEventUpdateHandle(con->stdoutWatch,
|
||||||
VIR_EVENT_HANDLE_WRITABLE);
|
VIR_EVENT_HANDLE_WRITABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (events & VIR_STREAM_EVENT_WRITABLE &&
|
if (events & VIR_STREAM_EVENT_WRITABLE &&
|
||||||
@ -266,7 +267,7 @@ virConsoleEventOnStdout(int watch ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!con->streamToTerminal.offset)
|
if (!con->streamToTerminal.offset)
|
||||||
virEventUpdateHandleImpl(con->stdoutWatch, 0);
|
virEventUpdateHandle(con->stdoutWatch, 0);
|
||||||
|
|
||||||
if (events & VIR_EVENT_HANDLE_ERROR ||
|
if (events & VIR_EVENT_HANDLE_ERROR ||
|
||||||
events & VIR_EVENT_HANDLE_HANGUP) {
|
events & VIR_EVENT_HANDLE_HANGUP) {
|
||||||
@ -331,16 +332,16 @@ int vshRunConsole(virDomainPtr dom, const char *devname)
|
|||||||
if (virDomainOpenConsole(dom, devname, con->st, 0) < 0)
|
if (virDomainOpenConsole(dom, devname, con->st, 0) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
con->stdinWatch = virEventAddHandleImpl(STDIN_FILENO,
|
con->stdinWatch = virEventAddHandle(STDIN_FILENO,
|
||||||
VIR_EVENT_HANDLE_READABLE,
|
VIR_EVENT_HANDLE_READABLE,
|
||||||
virConsoleEventOnStdin,
|
virConsoleEventOnStdin,
|
||||||
con,
|
con,
|
||||||
NULL);
|
NULL);
|
||||||
con->stdoutWatch = virEventAddHandleImpl(STDOUT_FILENO,
|
con->stdoutWatch = virEventAddHandle(STDOUT_FILENO,
|
||||||
0,
|
0,
|
||||||
virConsoleEventOnStdout,
|
virConsoleEventOnStdout,
|
||||||
con,
|
con,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
virStreamEventAddCallback(con->st,
|
virStreamEventAddCallback(con->st,
|
||||||
VIR_STREAM_EVENT_READABLE,
|
VIR_STREAM_EVENT_READABLE,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user