mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-11-02 11:21:12 +00:00
33ba6e6881
There were two API in driver.c that were silently masking flags bits prior to calling out to the drivers, and several others that were explicitly masking flags bits. This is not forward-compatible - if we ever have that many flags in the future, then talking to an old server that masks out the flags would be indistinguishable from talking to a new server that can honor the flag. In general, libvirt.c should forward _all_ flags on to drivers, and only the drivers should reject unknown flags. In the case of virDrvSecretGetValue, the solution is to separate the internal driver callback function to have two parameters instead of one, with only one parameter affected by the public API. In the case of virDomainGetXMLDesc, it turns out that no one was ever mixing VIR_DOMAIN_XML_INTERNAL_STATUS with the dumpxml path in the first place; that internal flag was only used in saving and restoring state files, which happened to be in functions internal to a single file, so there is no mixing of the internal flag with a public flags argument. Additionally, virDomainMemoryStats passed a flags argument over RPC, but not to the driver. * src/driver.h (VIR_DOMAIN_XML_FLAGS_MASK) (VIR_SECRET_GET_VALUE_FLAGS_MASK): Delete. (virDrvSecretGetValue): Separate out internal flags. (virDrvDomainMemoryStats): Provide missing flags argument. * src/driver.c (verify): Drop unused check. * src/conf/domain_conf.h (virDomainObjParseFile): Delete declaration. (virDomainXMLInternalFlags): Move... * src/conf/domain_conf.c: ...here. Delete redundant include. (virDomainObjParseFile): Make static. * src/libvirt.c (virDomainGetXMLDesc, virSecretGetValue): Update clients. (virDomainMemoryPeek, virInterfaceGetXMLDesc) (virDomainMemoryStats, virDomainBlockPeek, virNetworkGetXMLDesc) (virStoragePoolGetXMLDesc, virStorageVolGetXMLDesc) (virNodeNumOfDevices, virNodeListDevices, virNWFilterGetXMLDesc): Don't mask unknown flags. * src/interface/netcf_driver.c (interfaceGetXMLDesc): Reject unknown flags. * src/secret/secret_driver.c (secretGetValue): Update clients. * src/remote/remote_driver.c (remoteSecretGetValue) (remoteDomainMemoryStats): Likewise. * src/qemu/qemu_process.c (qemuProcessGetVolumeQcowPassphrase): Likewise. * src/qemu/qemu_driver.c (qemudDomainMemoryStats): Likewise. * daemon/remote.c (remoteDispatchDomainMemoryStats): Likewise.
99 lines
2.4 KiB
C
99 lines
2.4 KiB
C
/*
|
|
* driver.c: Helpers for loading drivers
|
|
*
|
|
* Copyright (C) 2006-2011 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
|
|
*
|
|
*/
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "driver.h"
|
|
#include "memory.h"
|
|
#include "logging.h"
|
|
#include "util.h"
|
|
#include "configmake.h"
|
|
|
|
#define DEFAULT_DRIVER_DIR LIBDIR "/libvirt/connection-driver"
|
|
|
|
#ifdef WITH_DRIVER_MODULES
|
|
|
|
/* XXX re-implment this for other OS, or use libtools helper lib ? */
|
|
|
|
# include <dlfcn.h>
|
|
|
|
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;
|
|
|
|
VIR_DEBUG("Module load %s", name);
|
|
|
|
if (virAsprintf(&modfile, "%s/libvirt_driver_%s.so", moddir, name) < 0)
|
|
return NULL;
|
|
|
|
if (access(modfile, R_OK) < 0) {
|
|
VIR_WARN("Module %s not accessible", modfile);
|
|
goto cleanup;
|
|
}
|
|
|
|
handle = dlopen(modfile, RTLD_NOW | RTLD_LOCAL);
|
|
if (!handle) {
|
|
VIR_ERROR(_("failed to load module %s %s"), modfile, dlerror());
|
|
goto cleanup;
|
|
}
|
|
|
|
if (virAsprintf(®func, "%sRegister", name) < 0) {
|
|
goto cleanup;
|
|
}
|
|
|
|
regsym = dlsym(handle, regfunc);
|
|
if (!regsym) {
|
|
VIR_ERROR(_("Missing module registration symbol %s"), regfunc);
|
|
goto cleanup;
|
|
}
|
|
|
|
if ((*regsym)() < 0) {
|
|
VIR_ERROR(_("Failed module registration %s"), regfunc);
|
|
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
|