libvirt/src/driver.c

102 lines
2.5 KiB
C
Raw Normal View History

2008-11-21 12:16:08 +00:00
/*
* driver.c: Helpers for loading drivers
*
* Copyright (C) 2006-2009 Red Hat, Inc.
2008-11-21 12:16:08 +00:00
*
* 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
*
*/
#include <config.h>
#include <unistd.h>
#include "driver.h"
#include "memory.h"
#include "logging.h"
#include "util.h"
2008-11-21 12:16:08 +00:00
#define DEFAULT_DRIVER_DIR LIBDIR "/libvirt/drivers"
Remote driver & daemon impl of new event API This wires up the remote driver to handle the new events APIs. The public API allows an application to request a callback filters events to a specific domain object, and register multiple callbacks for the same event type. On the wire there are two strategies for this - Register multiple callbacks with the remote daemon, each with filtering as needed - Register only one callback per event type, with no filtering Both approaches have potential inefficiency. In the first scheme, the same event gets sent over the wire many times if multiple callbacks are registered. With the second scheme, unneccessary events get sent over the wire if a per-domain filter is set on the client. The second scheme is far easier to implement though, so this patch takes that approach. * daemon/dispatch.h: Don't export remoteRelayDomainEvent since it is no longer needed for unregistering callbacks, instead the unique callback ID is used * daemon/libvirtd.c, daemon/libvirtd.h: Track and unregister callbacks based on callback ID, instead of function pointer * daemon/remote.c: Switch over to using virConnectDomainEventRegisterAny instead of legacy virConnectDomainEventRegister function. Refactor remoteDispatchDomainEventSend() to cope with arbitrary event types * src/driver.h, src/driver.c: Move verify() call into source file instead of header, to avoid polluting the global namespace with the verify function name * src/remote/remote_driver.c: Implement new APIs for event registration. Refactor processCallDispatchMessage() to cope with arbitrary incoming event types. Merge remoteDomainQueueEvent() into processCallDispatchMessage() to avoid duplication of code. Rename remoteDomainReadEvent() to remoteDomainReadEventLifecycle() * src/remote/remote_protocol.x: Define wire format for the new virConnectDomainEventRegisterAny and virConnectDomainEventDeregisterAny functions
2010-03-18 14:56:56 +00:00
/* Make sure ... INTERNAL_CALL can not be set by the caller */
verify((VIR_SECRET_GET_VALUE_INTERNAL_CALL &
VIR_SECRET_GET_VALUE_FLAGS_MASK) == 0);
2008-11-21 12:16:08 +00:00
#ifdef WITH_DRIVER_MODULES
/* XXX re-implment this for other OS, or use libtools helper lib ? */
# include <dlfcn.h>
2008-11-21 12:16:08 +00:00
void *
virDriverLoadModule(const char *name)
{
const char *moddir = getenv("LIBVIRT_DRIVER_DIR");
char *modfile = NULL, *regfunc = NULL;
void *handle = NULL;
int (*regsym)(void);
if (moddir == NULL)
moddir = DEFAULT_DRIVER_DIR;
DEBUG("Module load %s", name);
2008-12-23 13:03:29 +00:00
if (virAsprintf(&modfile, "%s/libvirt_driver_%s.so", moddir, name) < 0)
2008-11-21 12:16:08 +00:00
return NULL;
if (access(modfile, R_OK) < 0) {
2009-05-08 10:05:56 +00:00
VIR_WARN("Module %s not accessible", modfile);
2008-11-21 12:16:08 +00:00
goto cleanup;
}
handle = dlopen(modfile, RTLD_NOW | RTLD_LOCAL);
if (!handle) {
VIR_ERROR(_("failed to load module %s %s"), modfile, dlerror());
2008-11-21 12:16:08 +00:00
goto cleanup;
}
2008-12-23 13:03:29 +00:00
if (virAsprintf(&regfunc, "%sRegister", name) < 0) {
2008-11-21 12:16:08 +00:00
goto cleanup;
}
regsym = dlsym(handle, regfunc);
if (!regsym) {
VIR_ERROR(_("Missing module registration symbol %s"), regfunc);
2008-11-21 12:16:08 +00:00
goto cleanup;
}
if ((*regsym)() < 0) {
VIR_ERROR(_("Failed module registration %s"), regfunc);
2008-11-21 12:16:08 +00:00
goto cleanup;
}
VIR_FREE(modfile);
VIR_FREE(regfunc);
return handle;
cleanup:
VIR_FREE(modfile);
VIR_FREE(regfunc);
if (handle)
dlclose(handle);
return NULL;
}
/* XXX unload modules, but we can't until we can unregister libvirt drivers */
#endif