2008-11-04 23:22:06 +00:00
|
|
|
/*
|
|
|
|
* datatypes.h: management of structs for public data types
|
|
|
|
*
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
* Copyright (C) 2006-2012 Red Hat, Inc.
|
2008-11-04 23:22:06 +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
|
2012-07-21 10:06:23 +00:00
|
|
|
* License along with this library; If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-11-04 23:22:06 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2009-10-07 10:18:31 +00:00
|
|
|
#include <unistd.h>
|
2008-11-04 23:22:06 +00:00
|
|
|
|
|
|
|
#include "datatypes.h"
|
|
|
|
#include "virterror_internal.h"
|
2008-11-06 16:36:07 +00:00
|
|
|
#include "logging.h"
|
2008-11-04 23:22:06 +00:00
|
|
|
#include "memory.h"
|
Fix UUID handling in secrets/storage encryption APIs
Convert all the secret/storage encryption APIs / wire format to
handle UUIDs in raw format instead of non-canonical printable
format. Guarentees data format correctness.
* docs/schemas/storageencryption.rng: Make UUID mandatory for a secret
and validate fully
* docs/schemas/secret.rng: Fully validate UUID
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in, Add
virSecretLookupByUUID and virSecretGetUUID. Make
virSecretGetUUIDString follow normal API design pattern
* python/generator.py: Skip generation of virSecretGetUUID,
virSecretGetUUIDString and virSecretLookupByUUID
* python/libvir.c, python/libvirt-python-api.xml: Manual impl
of virSecretGetUUID,virSecretGetUUIDString and virSecretLookupByUUID
* qemud/remote.c: s/virSecretLookupByUUIDString/virSecretLookupByUUID/
Fix get_nonnull_secret/make_nonnull_secret to use unsigned char
* qemud/remote_protocol.x: Fix remote_nonnull_secret to use a
remote_uuid instead of remote_nonnull_string for UUID field.
Rename REMOTE_PROC_SECRET_LOOKUP_BY_UUID_STRING to
REMOTE_PROC_SECRET_LOOKUP_BY_UUID_STRING and make it take an
remote_uuid value
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.h, src/datatypes.c: Store UUID in raw format instead
of printable. Change virGetSecret to use raw format UUID
* src/driver.h: Rename virDrvSecretLookupByUUIDString to
virDrvSecretLookupByUUID and use raw format UUID
* src/libvirt.c: Add virSecretLookupByUUID and virSecretGetUUID
and re-implement virSecretLookupByUUIDString and
virSecretGetUUIDString in terms of those
* src/libvirt_public.syms: Add virSecretLookupByUUID and
virSecretGetUUID
* src/remote_internal.c: Rename remoteSecretLookupByUUIDString
to remoteSecretLookupByUUID. Fix typo in args for
remoteSecretDefineXML impl. Use raw UUID format for
get_nonnull_secret and make_nonnull_secret
* src/storage_encryption_conf.c, src/storage_encryption_conf.h:
Storage UUID in raw format, and require it to be present in
XML. Use UUID parser to validate.
* secret_conf.h, secret_conf.c: Generate a UUID if none is provided.
Storage UUID in raw format.
* src/secret_driver.c: Adjust to deal with raw UUIDs. Save secrets
in a filed with printable UUID, instead of base64 UUID.
* src/virsh.c: Adjust for changed public API contract of
virSecretGetUUIDString.
* src/storage_Backend.c: DOn't undefine secret we just generated
upon successful volume creation. Fix to handle raw UUIDs. Generate
a non-clashing UUID
* src/qemu_driver.c: Change to use lookupByUUID instead of
lookupByUUIDString
2009-09-10 16:44:12 +00:00
|
|
|
#include "uuid.h"
|
2009-08-03 12:37:44 +00:00
|
|
|
#include "util.h"
|
2008-11-04 23:22:06 +00:00
|
|
|
|
2009-01-29 12:10:32 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
2010-04-03 13:01:26 +00:00
|
|
|
#define virLibConnError(code, ...) \
|
2011-04-16 08:30:22 +00:00
|
|
|
virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \
|
2010-03-01 23:38:28 +00:00
|
|
|
__FUNCTION__, __LINE__, __VA_ARGS__)
|
2009-04-01 10:31:01 +00:00
|
|
|
|
2008-11-04 23:22:06 +00:00
|
|
|
/************************************************************************
|
|
|
|
* *
|
|
|
|
* Domain and Connections allocations *
|
|
|
|
* *
|
|
|
|
************************************************************************/
|
|
|
|
|
2010-03-31 20:33:13 +00:00
|
|
|
|
2008-11-04 23:22:06 +00:00
|
|
|
/**
|
|
|
|
* virGetConnect:
|
|
|
|
*
|
|
|
|
* Allocates a new hypervisor connection structure
|
|
|
|
*
|
|
|
|
* Returns a new pointer or NULL in case of error.
|
|
|
|
*/
|
|
|
|
virConnectPtr
|
|
|
|
virGetConnect(void) {
|
|
|
|
virConnectPtr ret;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(ret) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-11-04 23:22:06 +00:00
|
|
|
goto failed;
|
|
|
|
}
|
2009-01-15 19:56:05 +00:00
|
|
|
if (virMutexInit(&ret->lock) < 0) {
|
|
|
|
VIR_FREE(ret);
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2008-11-04 23:22:06 +00:00
|
|
|
ret->magic = VIR_CONNECT_MAGIC;
|
|
|
|
ret->driver = NULL;
|
|
|
|
ret->networkDriver = NULL;
|
|
|
|
ret->privateData = NULL;
|
|
|
|
ret->networkPrivateData = NULL;
|
2009-05-20 14:26:49 +00:00
|
|
|
ret->interfacePrivateData = NULL;
|
2008-11-04 23:22:06 +00:00
|
|
|
|
|
|
|
ret->refs = 1;
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2008-11-04 23:22:06 +00:00
|
|
|
|
|
|
|
failed:
|
|
|
|
if (ret != NULL) {
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexDestroy(&ret->lock);
|
2008-11-04 23:22:06 +00:00
|
|
|
VIR_FREE(ret);
|
|
|
|
}
|
2012-03-22 11:33:35 +00:00
|
|
|
return NULL;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virReleaseConnect:
|
|
|
|
* @conn: the hypervisor connection to release
|
|
|
|
*
|
|
|
|
* Unconditionally release all memory associated with a connection.
|
|
|
|
* The conn.lock mutex must be held prior to calling this, and will
|
|
|
|
* be released prior to this returning. The connection obj must not
|
|
|
|
* be used once this method returns.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
virReleaseConnect(virConnectPtr conn) {
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("release connection %p", conn);
|
2010-11-24 17:10:14 +00:00
|
|
|
|
|
|
|
/* make sure to release the connection lock before we call the
|
maint: reject raw close, popen in 'make syntax-check'
commit f1fe9671e was supposed to make sure we use files.h
macros to avoid double close, but it didn't work.
Meanwhile, virCommand is vastly superior to system(), fork(),
and popen() (also to virExec, but we haven't completed that
conversion), so enforce that, too.
* cfg.mk (sc_prohibit_close): Fix typo that excluded close, and
add pclose.
(sc_prohibit_fork_wrappers): New rule, for fork, system, and popen.
* .x-sc_prohibit_close: More exemptions.
* .x-sc_prohibit_fork_wrappers: New file.
* Makefile.am (syntax_check_exceptions): Ship new file.
* src/datatypes.c (virReleaseConnect): Tweak comment to avoid
false positive.
* src/util/files.h (VIR_CLOSE): Likewise.
2011-01-27 22:16:14 +00:00
|
|
|
* close callbacks, otherwise we will deadlock if an error
|
2010-11-24 17:10:14 +00:00
|
|
|
* is raised by any of the callbacks */
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
|
|
|
|
if (conn->networkDriver)
|
2011-02-17 21:18:21 +00:00
|
|
|
conn->networkDriver->close(conn);
|
2010-11-24 17:10:14 +00:00
|
|
|
if (conn->interfaceDriver)
|
2011-02-17 21:18:21 +00:00
|
|
|
conn->interfaceDriver->close(conn);
|
2010-11-24 17:10:14 +00:00
|
|
|
if (conn->storageDriver)
|
2011-02-17 21:18:21 +00:00
|
|
|
conn->storageDriver->close(conn);
|
2010-11-24 17:10:14 +00:00
|
|
|
if (conn->deviceMonitor)
|
2011-02-17 21:18:21 +00:00
|
|
|
conn->deviceMonitor->close(conn);
|
2010-11-24 17:10:14 +00:00
|
|
|
if (conn->secretDriver)
|
2011-02-17 21:18:21 +00:00
|
|
|
conn->secretDriver->close(conn);
|
2010-11-24 17:10:14 +00:00
|
|
|
if (conn->nwfilterDriver)
|
2011-02-17 21:18:21 +00:00
|
|
|
conn->nwfilterDriver->close(conn);
|
2010-11-24 17:10:14 +00:00
|
|
|
if (conn->driver)
|
2011-02-17 21:18:21 +00:00
|
|
|
conn->driver->close(conn);
|
2010-11-24 17:10:14 +00:00
|
|
|
|
|
|
|
virMutexLock(&conn->lock);
|
|
|
|
|
2012-07-19 10:01:07 +00:00
|
|
|
if (conn->closeFreeCallback)
|
|
|
|
conn->closeFreeCallback(conn->closeOpaque);
|
|
|
|
|
2008-11-04 23:22:06 +00:00
|
|
|
virResetError(&conn->err);
|
|
|
|
|
2012-03-20 11:59:42 +00:00
|
|
|
virURIFree(conn->uri);
|
2008-11-04 23:22:06 +00:00
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virMutexDestroy(&conn->lock);
|
2008-11-04 23:22:06 +00:00
|
|
|
VIR_FREE(conn);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virUnrefConnect:
|
|
|
|
* @conn: the hypervisor connection to unreference
|
|
|
|
*
|
|
|
|
* Unreference the connection. If the use count drops to zero, the structure is
|
|
|
|
* actually freed.
|
|
|
|
*
|
|
|
|
* Returns the reference count or -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virUnrefConnect(virConnectPtr conn) {
|
|
|
|
int refs;
|
|
|
|
|
|
|
|
if ((!VIR_IS_CONNECT(conn))) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
|
2010-05-12 02:57:56 +00:00
|
|
|
return -1;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&conn->lock);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref connection %p %d", conn, conn->refs);
|
2008-11-04 23:22:06 +00:00
|
|
|
conn->refs--;
|
|
|
|
refs = conn->refs;
|
|
|
|
if (refs == 0) {
|
|
|
|
virReleaseConnect(conn);
|
|
|
|
/* Already unlocked mutex */
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return refs;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virGetDomain:
|
|
|
|
* @conn: the hypervisor connection
|
|
|
|
* @name: pointer to the domain name
|
|
|
|
* @uuid: pointer to the uuid
|
|
|
|
*
|
|
|
|
* Lookup if the domain is already registered for that connection,
|
|
|
|
* if yes return a new pointer to it, if no allocate a new structure,
|
|
|
|
* and register it in the table. In any case a corresponding call to
|
|
|
|
* virUnrefDomain() is needed to not leak data.
|
|
|
|
*
|
|
|
|
* Returns a pointer to the domain, or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virDomainPtr
|
2008-11-17 11:03:25 +00:00
|
|
|
virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
|
2008-11-04 23:22:06 +00:00
|
|
|
virDomainPtr ret = NULL;
|
2010-06-17 14:45:26 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2008-11-04 23:22:06 +00:00
|
|
|
|
2010-05-12 02:57:56 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
|
2010-05-12 02:57:56 +00:00
|
|
|
return NULL;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
virCheckNonNullArgReturn(name, NULL);
|
|
|
|
virCheckNonNullArgReturn(uuid, NULL);
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&conn->lock);
|
2008-11-04 23:22:06 +00:00
|
|
|
|
2010-06-17 14:45:26 +00:00
|
|
|
virUUIDFormat(uuid, uuidstr);
|
2008-11-04 23:22:06 +00:00
|
|
|
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
if (VIR_ALLOC(ret) < 0) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ret->name = strdup(name);
|
|
|
|
if (ret->name == NULL) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
ret->magic = VIR_DOMAIN_MAGIC;
|
|
|
|
ret->conn = conn;
|
|
|
|
ret->id = -1;
|
|
|
|
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
|
|
|
|
|
|
|
|
conn->refs++;
|
2008-11-04 23:22:06 +00:00
|
|
|
ret->refs++;
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2008-11-04 23:22:06 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (ret != NULL) {
|
|
|
|
VIR_FREE(ret->name);
|
|
|
|
VIR_FREE(ret);
|
|
|
|
}
|
2012-03-22 11:33:35 +00:00
|
|
|
return NULL;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virReleaseDomain:
|
|
|
|
* @domain: the domain to release
|
|
|
|
*
|
|
|
|
* Unconditionally release all memory associated with a domain.
|
|
|
|
* The conn.lock mutex must be held prior to calling this, and will
|
|
|
|
* be released prior to this returning. The domain obj must not
|
|
|
|
* be used once this method returns.
|
|
|
|
*
|
|
|
|
* It will also unreference the associated connection object,
|
|
|
|
* which may also be released if its ref count hits zero.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
virReleaseDomain(virDomainPtr domain) {
|
|
|
|
virConnectPtr conn = domain->conn;
|
2010-06-17 14:45:26 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2008-11-04 23:22:06 +00:00
|
|
|
|
2010-06-17 14:45:26 +00:00
|
|
|
virUUIDFormat(domain->uuid, uuidstr);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("release domain %p %s %s", domain, domain->name, uuidstr);
|
2010-06-17 14:45:26 +00:00
|
|
|
|
2008-11-04 23:22:06 +00:00
|
|
|
domain->magic = -1;
|
|
|
|
domain->id = -1;
|
|
|
|
VIR_FREE(domain->name);
|
|
|
|
VIR_FREE(domain);
|
|
|
|
|
2009-07-22 17:22:41 +00:00
|
|
|
if (conn) {
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref connection %p %d", conn, conn->refs);
|
2009-07-22 17:22:41 +00:00
|
|
|
conn->refs--;
|
|
|
|
if (conn->refs == 0) {
|
|
|
|
virReleaseConnect(conn);
|
|
|
|
/* Already unlocked mutex */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
virMutexUnlock(&conn->lock);
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virUnrefDomain:
|
|
|
|
* @domain: the domain to unreference
|
|
|
|
*
|
|
|
|
* Unreference the domain. If the use count drops to zero, the structure is
|
|
|
|
* actually freed.
|
|
|
|
*
|
|
|
|
* Returns the reference count or -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virUnrefDomain(virDomainPtr domain) {
|
|
|
|
int refs;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_DOMAIN, "%s",
|
|
|
|
_("bad domain or no connection"));
|
2010-05-12 02:57:56 +00:00
|
|
|
return -1;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&domain->conn->lock);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref domain %p %s %d", domain, domain->name, domain->refs);
|
2008-11-04 23:22:06 +00:00
|
|
|
domain->refs--;
|
|
|
|
refs = domain->refs;
|
|
|
|
if (refs == 0) {
|
|
|
|
virReleaseDomain(domain);
|
|
|
|
/* Already unlocked mutex */
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&domain->conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return refs;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virGetNetwork:
|
|
|
|
* @conn: the hypervisor connection
|
|
|
|
* @name: pointer to the network name
|
|
|
|
* @uuid: pointer to the uuid
|
|
|
|
*
|
|
|
|
* Lookup if the network is already registered for that connection,
|
|
|
|
* if yes return a new pointer to it, if no allocate a new structure,
|
|
|
|
* and register it in the table. In any case a corresponding call to
|
|
|
|
* virUnrefNetwork() is needed to not leak data.
|
|
|
|
*
|
|
|
|
* Returns a pointer to the network, or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virNetworkPtr
|
2008-11-17 11:03:25 +00:00
|
|
|
virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
|
2008-11-04 23:22:06 +00:00
|
|
|
virNetworkPtr ret = NULL;
|
2010-06-17 14:45:26 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2008-11-04 23:22:06 +00:00
|
|
|
|
2010-05-12 02:57:56 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
|
2010-05-12 02:57:56 +00:00
|
|
|
return NULL;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
virCheckNonNullArgReturn(name, NULL);
|
|
|
|
virCheckNonNullArgReturn(uuid, NULL);
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&conn->lock);
|
2008-11-04 23:22:06 +00:00
|
|
|
|
2010-06-17 14:45:26 +00:00
|
|
|
virUUIDFormat(uuid, uuidstr);
|
2008-11-04 23:22:06 +00:00
|
|
|
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
if (VIR_ALLOC(ret) < 0) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ret->name = strdup(name);
|
|
|
|
if (ret->name == NULL) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
ret->magic = VIR_NETWORK_MAGIC;
|
|
|
|
ret->conn = conn;
|
|
|
|
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
|
|
|
|
|
|
|
|
conn->refs++;
|
2008-11-04 23:22:06 +00:00
|
|
|
ret->refs++;
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2008-11-04 23:22:06 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (ret != NULL) {
|
|
|
|
VIR_FREE(ret->name);
|
|
|
|
VIR_FREE(ret);
|
|
|
|
}
|
2012-03-22 11:33:35 +00:00
|
|
|
return NULL;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virReleaseNetwork:
|
|
|
|
* @network: the network to release
|
|
|
|
*
|
|
|
|
* Unconditionally release all memory associated with a network.
|
|
|
|
* The conn.lock mutex must be held prior to calling this, and will
|
|
|
|
* be released prior to this returning. The network obj must not
|
|
|
|
* be used once this method returns.
|
|
|
|
*
|
|
|
|
* It will also unreference the associated connection object,
|
|
|
|
* which may also be released if its ref count hits zero.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
virReleaseNetwork(virNetworkPtr network) {
|
|
|
|
virConnectPtr conn = network->conn;
|
2010-06-17 14:45:26 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2008-11-04 23:22:06 +00:00
|
|
|
|
2010-06-17 14:45:26 +00:00
|
|
|
virUUIDFormat(network->uuid, uuidstr);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("release network %p %s %s", network, network->name, uuidstr);
|
2010-06-17 14:45:26 +00:00
|
|
|
|
2008-11-04 23:22:06 +00:00
|
|
|
network->magic = -1;
|
|
|
|
VIR_FREE(network->name);
|
|
|
|
VIR_FREE(network);
|
|
|
|
|
2009-07-22 17:22:41 +00:00
|
|
|
if (conn) {
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref connection %p %d", conn, conn->refs);
|
2009-07-22 17:22:41 +00:00
|
|
|
conn->refs--;
|
|
|
|
if (conn->refs == 0) {
|
|
|
|
virReleaseConnect(conn);
|
|
|
|
/* Already unlocked mutex */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
virMutexUnlock(&conn->lock);
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virUnrefNetwork:
|
|
|
|
* @network: the network to unreference
|
|
|
|
*
|
|
|
|
* Unreference the network. If the use count drops to zero, the structure is
|
|
|
|
* actually freed.
|
|
|
|
*
|
|
|
|
* Returns the reference count or -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virUnrefNetwork(virNetworkPtr network) {
|
|
|
|
int refs;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_NETWORK(network)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_NETWORK, "%s",
|
2010-05-12 02:57:56 +00:00
|
|
|
_("bad network or no connection"));
|
|
|
|
return -1;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&network->conn->lock);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref network %p %s %d", network, network->name, network->refs);
|
2008-11-04 23:22:06 +00:00
|
|
|
network->refs--;
|
|
|
|
refs = network->refs;
|
|
|
|
if (refs == 0) {
|
|
|
|
virReleaseNetwork(network);
|
|
|
|
/* Already unlocked mutex */
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&network->conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return refs;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-20 14:26:49 +00:00
|
|
|
/**
|
|
|
|
* virGetInterface:
|
|
|
|
* @conn: the hypervisor connection
|
|
|
|
* @name: pointer to the interface name
|
|
|
|
* @mac: pointer to the mac
|
|
|
|
*
|
|
|
|
* Lookup if the interface is already registered for that connection,
|
2009-07-21 13:37:20 +00:00
|
|
|
* if yes return a new pointer to it (possibly updating the MAC
|
|
|
|
* address), if no allocate a new structure, and register it in the
|
|
|
|
* table. In any case a corresponding call to virUnrefInterface() is
|
|
|
|
* needed to not leak data.
|
2009-05-20 14:26:49 +00:00
|
|
|
*
|
|
|
|
* Returns a pointer to the interface, or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virInterfacePtr
|
|
|
|
virGetInterface(virConnectPtr conn, const char *name, const char *mac) {
|
|
|
|
virInterfacePtr ret = NULL;
|
|
|
|
|
2010-05-12 02:57:56 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
|
2010-05-12 02:57:56 +00:00
|
|
|
return NULL;
|
2009-05-20 14:26:49 +00:00
|
|
|
}
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
virCheckNonNullArgReturn(name, NULL);
|
2009-11-03 15:42:53 +00:00
|
|
|
|
|
|
|
/* a NULL mac from caller is okay. Treat it as blank */
|
|
|
|
if (mac == NULL)
|
|
|
|
mac = "";
|
|
|
|
|
2009-05-20 14:26:49 +00:00
|
|
|
virMutexLock(&conn->lock);
|
|
|
|
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
if (VIR_ALLOC(ret) < 0) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ret->name = strdup(name);
|
|
|
|
if (ret->name == NULL) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ret->mac = strdup(mac);
|
|
|
|
if (ret->mac == NULL) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
2009-05-20 14:26:49 +00:00
|
|
|
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
ret->magic = VIR_INTERFACE_MAGIC;
|
|
|
|
ret->conn = conn;
|
2009-05-20 14:26:49 +00:00
|
|
|
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
conn->refs++;
|
2009-05-20 14:26:49 +00:00
|
|
|
ret->refs++;
|
|
|
|
virMutexUnlock(&conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-05-20 14:26:49 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (ret != NULL) {
|
|
|
|
VIR_FREE(ret->name);
|
|
|
|
VIR_FREE(ret->mac);
|
|
|
|
VIR_FREE(ret);
|
|
|
|
}
|
2012-03-22 11:33:35 +00:00
|
|
|
return NULL;
|
2009-05-20 14:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virReleaseInterface:
|
|
|
|
* @interface: the interface to release
|
|
|
|
*
|
2009-10-26 23:02:46 +00:00
|
|
|
* Unconditionally release all memory associated with an interface.
|
2009-05-20 14:26:49 +00:00
|
|
|
* The conn.lock mutex must be held prior to calling this, and will
|
|
|
|
* be released prior to this returning. The interface obj must not
|
|
|
|
* be used once this method returns.
|
|
|
|
*
|
|
|
|
* It will also unreference the associated connection object,
|
|
|
|
* which may also be released if its ref count hits zero.
|
|
|
|
*/
|
|
|
|
static void
|
2009-05-29 14:29:22 +00:00
|
|
|
virReleaseInterface(virInterfacePtr iface) {
|
|
|
|
virConnectPtr conn = iface->conn;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("release interface %p %s", iface, iface->name);
|
2009-05-20 14:26:49 +00:00
|
|
|
|
2009-05-29 14:29:22 +00:00
|
|
|
iface->magic = -1;
|
|
|
|
VIR_FREE(iface->name);
|
|
|
|
VIR_FREE(iface->mac);
|
|
|
|
VIR_FREE(iface);
|
2009-05-20 14:26:49 +00:00
|
|
|
|
2009-07-22 14:15:52 +00:00
|
|
|
if (conn) {
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref connection %p %d", conn, conn->refs);
|
2009-07-22 14:15:52 +00:00
|
|
|
conn->refs--;
|
|
|
|
if (conn->refs == 0) {
|
|
|
|
virReleaseConnect(conn);
|
|
|
|
/* Already unlocked mutex */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
virMutexUnlock(&conn->lock);
|
2009-05-20 14:26:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virUnrefInterface:
|
|
|
|
* @interface: the interface to unreference
|
|
|
|
*
|
|
|
|
* Unreference the interface. If the use count drops to zero, the structure is
|
|
|
|
* actually freed.
|
|
|
|
*
|
|
|
|
* Returns the reference count or -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2009-05-29 14:29:22 +00:00
|
|
|
virUnrefInterface(virInterfacePtr iface) {
|
2009-05-20 14:26:49 +00:00
|
|
|
int refs;
|
|
|
|
|
2009-05-29 14:29:22 +00:00
|
|
|
if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_INTERFACE, "%s",
|
2010-05-12 02:57:56 +00:00
|
|
|
_("bad interface or no connection"));
|
|
|
|
return -1;
|
2009-05-20 14:26:49 +00:00
|
|
|
}
|
2009-05-29 14:29:22 +00:00
|
|
|
virMutexLock(&iface->conn->lock);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref interface %p %s %d", iface, iface->name, iface->refs);
|
2009-05-29 14:29:22 +00:00
|
|
|
iface->refs--;
|
|
|
|
refs = iface->refs;
|
2009-05-20 14:26:49 +00:00
|
|
|
if (refs == 0) {
|
2009-05-29 14:29:22 +00:00
|
|
|
virReleaseInterface(iface);
|
2009-05-20 14:26:49 +00:00
|
|
|
/* Already unlocked mutex */
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2009-05-20 14:26:49 +00:00
|
|
|
}
|
|
|
|
|
2009-05-29 14:29:22 +00:00
|
|
|
virMutexUnlock(&iface->conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return refs;
|
2009-05-20 14:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-04 23:22:06 +00:00
|
|
|
/**
|
|
|
|
* virGetStoragePool:
|
|
|
|
* @conn: the hypervisor connection
|
|
|
|
* @name: pointer to the storage pool name
|
|
|
|
* @uuid: pointer to the uuid
|
|
|
|
*
|
|
|
|
* Lookup if the storage pool is already registered for that connection,
|
|
|
|
* if yes return a new pointer to it, if no allocate a new structure,
|
|
|
|
* and register it in the table. In any case a corresponding call to
|
2011-01-15 14:42:22 +00:00
|
|
|
* virUnrefStoragePool() is needed to not leak data.
|
2008-11-04 23:22:06 +00:00
|
|
|
*
|
|
|
|
* Returns a pointer to the network, or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virStoragePoolPtr
|
2010-05-12 02:57:56 +00:00
|
|
|
virGetStoragePool(virConnectPtr conn, const char *name,
|
|
|
|
const unsigned char *uuid) {
|
2008-11-04 23:22:06 +00:00
|
|
|
virStoragePoolPtr ret = NULL;
|
2010-06-17 14:45:26 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2008-11-04 23:22:06 +00:00
|
|
|
|
2010-05-12 02:57:56 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
|
2010-05-12 02:57:56 +00:00
|
|
|
return NULL;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
virCheckNonNullArgReturn(name, NULL);
|
|
|
|
virCheckNonNullArgReturn(uuid, NULL);
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&conn->lock);
|
2008-11-04 23:22:06 +00:00
|
|
|
|
2010-06-17 14:45:26 +00:00
|
|
|
virUUIDFormat(uuid, uuidstr);
|
2008-11-04 23:22:06 +00:00
|
|
|
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
if (VIR_ALLOC(ret) < 0) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ret->name = strdup(name);
|
|
|
|
if (ret->name == NULL) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
ret->magic = VIR_STORAGE_POOL_MAGIC;
|
|
|
|
ret->conn = conn;
|
|
|
|
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
|
|
|
|
|
|
|
|
conn->refs++;
|
2008-11-04 23:22:06 +00:00
|
|
|
ret->refs++;
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2008-11-04 23:22:06 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (ret != NULL) {
|
|
|
|
VIR_FREE(ret->name);
|
|
|
|
VIR_FREE(ret);
|
|
|
|
}
|
2012-03-22 11:33:35 +00:00
|
|
|
return NULL;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virReleaseStoragePool:
|
|
|
|
* @pool: the pool to release
|
|
|
|
*
|
|
|
|
* Unconditionally release all memory associated with a pool.
|
|
|
|
* The conn.lock mutex must be held prior to calling this, and will
|
|
|
|
* be released prior to this returning. The pool obj must not
|
|
|
|
* be used once this method returns.
|
|
|
|
*
|
|
|
|
* It will also unreference the associated connection object,
|
|
|
|
* which may also be released if its ref count hits zero.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
virReleaseStoragePool(virStoragePoolPtr pool) {
|
|
|
|
virConnectPtr conn = pool->conn;
|
2010-06-17 14:45:26 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2008-11-04 23:22:06 +00:00
|
|
|
|
2010-06-17 14:45:26 +00:00
|
|
|
virUUIDFormat(pool->uuid, uuidstr);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("release pool %p %s %s", pool, pool->name, uuidstr);
|
2010-06-17 14:45:26 +00:00
|
|
|
|
2008-11-04 23:22:06 +00:00
|
|
|
pool->magic = -1;
|
|
|
|
VIR_FREE(pool->name);
|
|
|
|
VIR_FREE(pool);
|
|
|
|
|
2009-07-22 17:22:41 +00:00
|
|
|
if (conn) {
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref connection %p %d", conn, conn->refs);
|
2009-07-22 17:22:41 +00:00
|
|
|
conn->refs--;
|
|
|
|
if (conn->refs == 0) {
|
|
|
|
virReleaseConnect(conn);
|
|
|
|
/* Already unlocked mutex */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
virMutexUnlock(&conn->lock);
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virUnrefStoragePool:
|
|
|
|
* @pool: the pool to unreference
|
|
|
|
*
|
|
|
|
* Unreference the pool. If the use count drops to zero, the structure is
|
|
|
|
* actually freed.
|
|
|
|
*
|
|
|
|
* Returns the reference count or -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virUnrefStoragePool(virStoragePoolPtr pool) {
|
|
|
|
int refs;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_STORAGE_POOL, "%s",
|
2010-05-12 02:57:56 +00:00
|
|
|
_("bad storage pool or no connection"));
|
|
|
|
return -1;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&pool->conn->lock);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref pool %p %s %d", pool, pool->name, pool->refs);
|
2008-11-04 23:22:06 +00:00
|
|
|
pool->refs--;
|
|
|
|
refs = pool->refs;
|
|
|
|
if (refs == 0) {
|
|
|
|
virReleaseStoragePool(pool);
|
|
|
|
/* Already unlocked mutex */
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&pool->conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return refs;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virGetStorageVol:
|
|
|
|
* @conn: the hypervisor connection
|
|
|
|
* @pool: pool owning the volume
|
|
|
|
* @name: pointer to the storage vol name
|
2010-06-17 14:45:29 +00:00
|
|
|
* @key: pointer to unique key of the volume
|
2008-11-04 23:22:06 +00:00
|
|
|
*
|
|
|
|
* Lookup if the storage vol is already registered for that connection,
|
|
|
|
* if yes return a new pointer to it, if no allocate a new structure,
|
|
|
|
* and register it in the table. In any case a corresponding call to
|
2011-01-15 14:42:22 +00:00
|
|
|
* virUnrefStorageVol() is needed to not leak data.
|
2008-11-04 23:22:06 +00:00
|
|
|
*
|
|
|
|
* Returns a pointer to the storage vol, or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virStorageVolPtr
|
2010-05-12 02:57:56 +00:00
|
|
|
virGetStorageVol(virConnectPtr conn, const char *pool, const char *name,
|
|
|
|
const char *key) {
|
2008-11-04 23:22:06 +00:00
|
|
|
virStorageVolPtr ret = NULL;
|
|
|
|
|
2010-05-12 02:57:56 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
|
2010-05-12 02:57:56 +00:00
|
|
|
return NULL;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
virCheckNonNullArgReturn(name, NULL);
|
|
|
|
virCheckNonNullArgReturn(key, NULL);
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&conn->lock);
|
2008-11-04 23:22:06 +00:00
|
|
|
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
if (VIR_ALLOC(ret) < 0) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ret->pool = strdup(pool);
|
|
|
|
if (ret->pool == NULL) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ret->name = strdup(name);
|
|
|
|
if (ret->name == NULL) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
2011-06-22 19:51:32 +00:00
|
|
|
ret->key = strdup(key);
|
|
|
|
if (ret->key == NULL) {
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
virMutexUnlock(&conn->lock);
|
2011-06-22 19:51:32 +00:00
|
|
|
virReportOOMError();
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
goto error;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
ret->magic = VIR_STORAGE_VOL_MAGIC;
|
|
|
|
ret->conn = conn;
|
|
|
|
|
|
|
|
conn->refs++;
|
2008-11-04 23:22:06 +00:00
|
|
|
ret->refs++;
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2008-11-04 23:22:06 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (ret != NULL) {
|
2011-06-22 19:51:32 +00:00
|
|
|
VIR_FREE(ret->key);
|
2008-11-04 23:22:06 +00:00
|
|
|
VIR_FREE(ret->name);
|
|
|
|
VIR_FREE(ret->pool);
|
|
|
|
VIR_FREE(ret);
|
|
|
|
}
|
2012-03-22 11:33:35 +00:00
|
|
|
return NULL;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virReleaseStorageVol:
|
|
|
|
* @vol: the vol to release
|
|
|
|
*
|
|
|
|
* Unconditionally release all memory associated with a vol.
|
|
|
|
* The conn.lock mutex must be held prior to calling this, and will
|
|
|
|
* be released prior to this returning. The vol obj must not
|
|
|
|
* be used once this method returns.
|
|
|
|
*
|
|
|
|
* It will also unreference the associated connection object,
|
|
|
|
* which may also be released if its ref count hits zero.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
virReleaseStorageVol(virStorageVolPtr vol) {
|
|
|
|
virConnectPtr conn = vol->conn;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("release vol %p %s", vol, vol->name);
|
2008-11-04 23:22:06 +00:00
|
|
|
|
|
|
|
vol->magic = -1;
|
2011-06-22 19:51:32 +00:00
|
|
|
VIR_FREE(vol->key);
|
2008-11-04 23:22:06 +00:00
|
|
|
VIR_FREE(vol->name);
|
|
|
|
VIR_FREE(vol->pool);
|
|
|
|
VIR_FREE(vol);
|
|
|
|
|
2009-07-22 17:22:41 +00:00
|
|
|
if (conn) {
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref connection %p %d", conn, conn->refs);
|
2009-07-22 17:22:41 +00:00
|
|
|
conn->refs--;
|
|
|
|
if (conn->refs == 0) {
|
|
|
|
virReleaseConnect(conn);
|
|
|
|
/* Already unlocked mutex */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
virMutexUnlock(&conn->lock);
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virUnrefStorageVol:
|
|
|
|
* @vol: the vol to unreference
|
|
|
|
*
|
|
|
|
* Unreference the vol. If the use count drops to zero, the structure is
|
|
|
|
* actually freed.
|
|
|
|
*
|
|
|
|
* Returns the reference count or -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virUnrefStorageVol(virStorageVolPtr vol) {
|
|
|
|
int refs;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_VOL(vol)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_STORAGE_VOL, "%s",
|
2010-05-12 02:57:56 +00:00
|
|
|
_("bad storage volume or no connection"));
|
|
|
|
return -1;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&vol->conn->lock);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref vol %p %s %d", vol, vol->name, vol->refs);
|
2008-11-04 23:22:06 +00:00
|
|
|
vol->refs--;
|
|
|
|
refs = vol->refs;
|
|
|
|
if (refs == 0) {
|
|
|
|
virReleaseStorageVol(vol);
|
|
|
|
/* Already unlocked mutex */
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&vol->conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return refs;
|
2008-11-04 23:22:06 +00:00
|
|
|
}
|
2008-11-21 12:19:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virGetNodeDevice:
|
|
|
|
* @conn: the hypervisor connection
|
|
|
|
* @name: device name (unique on node)
|
|
|
|
*
|
|
|
|
* Lookup if the device is already registered for that connection,
|
|
|
|
* if yes return a new pointer to it, if no allocate a new structure,
|
|
|
|
* and register it in the table. In any case a corresponding call to
|
2011-01-15 14:42:22 +00:00
|
|
|
* virUnrefNodeDevice() is needed to not leak data.
|
2008-11-21 12:19:22 +00:00
|
|
|
*
|
|
|
|
* Returns a pointer to the node device, or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virNodeDevicePtr
|
|
|
|
virGetNodeDevice(virConnectPtr conn, const char *name)
|
|
|
|
{
|
|
|
|
virNodeDevicePtr ret = NULL;
|
|
|
|
|
2010-05-12 02:57:56 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
|
2010-05-12 02:57:56 +00:00
|
|
|
return NULL;
|
2008-11-21 12:19:22 +00:00
|
|
|
}
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
virCheckNonNullArgReturn(name, NULL);
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&conn->lock);
|
2008-11-21 12:19:22 +00:00
|
|
|
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
if (VIR_ALLOC(ret) < 0) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
2008-11-21 12:19:22 +00:00
|
|
|
}
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
ret->magic = VIR_NODE_DEVICE_MAGIC;
|
|
|
|
ret->conn = conn;
|
|
|
|
ret->name = strdup(name);
|
|
|
|
if (ret->name == NULL) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
conn->refs++;
|
2008-11-21 12:19:22 +00:00
|
|
|
ret->refs++;
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2008-11-21 12:19:22 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (ret != NULL) {
|
|
|
|
VIR_FREE(ret->name);
|
|
|
|
VIR_FREE(ret);
|
|
|
|
}
|
2012-03-22 11:33:35 +00:00
|
|
|
return NULL;
|
2008-11-21 12:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virReleaseNodeDevice:
|
|
|
|
* @dev: the dev to release
|
|
|
|
*
|
|
|
|
* Unconditionally release all memory associated with a dev.
|
|
|
|
* The conn.lock mutex must be held prior to calling this, and will
|
|
|
|
* be released prior to this returning. The dev obj must not
|
|
|
|
* be used once this method returns.
|
|
|
|
*
|
|
|
|
* It will also unreference the associated connection object,
|
|
|
|
* which may also be released if its ref count hits zero.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
virReleaseNodeDevice(virNodeDevicePtr dev) {
|
|
|
|
virConnectPtr conn = dev->conn;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("release dev %p %s", dev, dev->name);
|
2008-11-21 12:19:22 +00:00
|
|
|
|
|
|
|
dev->magic = -1;
|
|
|
|
VIR_FREE(dev->name);
|
2008-12-04 21:46:34 +00:00
|
|
|
VIR_FREE(dev->parent);
|
2008-11-21 12:19:22 +00:00
|
|
|
VIR_FREE(dev);
|
|
|
|
|
2009-07-22 17:22:41 +00:00
|
|
|
if (conn) {
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref connection %p %d", conn, conn->refs);
|
2009-07-22 17:22:41 +00:00
|
|
|
conn->refs--;
|
|
|
|
if (conn->refs == 0) {
|
|
|
|
virReleaseConnect(conn);
|
|
|
|
/* Already unlocked mutex */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
virMutexUnlock(&conn->lock);
|
2008-11-21 12:19:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virUnrefNodeDevice:
|
|
|
|
* @dev: the dev to unreference
|
|
|
|
*
|
|
|
|
* Unreference the dev. If the use count drops to zero, the structure is
|
|
|
|
* actually freed.
|
|
|
|
*
|
|
|
|
* Returns the reference count or -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virUnrefNodeDevice(virNodeDevicePtr dev) {
|
|
|
|
int refs;
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&dev->conn->lock);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref dev %p %s %d", dev, dev->name, dev->refs);
|
2008-11-21 12:19:22 +00:00
|
|
|
dev->refs--;
|
|
|
|
refs = dev->refs;
|
|
|
|
if (refs == 0) {
|
|
|
|
virReleaseNodeDevice(dev);
|
|
|
|
/* Already unlocked mutex */
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2008-11-21 12:19:22 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&dev->conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return refs;
|
2008-11-21 12:19:22 +00:00
|
|
|
}
|
2009-08-14 19:42:19 +00:00
|
|
|
|
2009-07-10 11:18:12 +00:00
|
|
|
|
2009-08-14 19:42:19 +00:00
|
|
|
/**
|
|
|
|
* virGetSecret:
|
|
|
|
* @conn: the hypervisor connection
|
|
|
|
* @uuid: secret UUID
|
|
|
|
*
|
|
|
|
* Lookup if the secret is already registered for that connection, if so return
|
|
|
|
* a pointer to it, otherwise allocate a new structure, and register it in the
|
2011-01-15 14:42:22 +00:00
|
|
|
* table. In any case a corresponding call to virUnrefSecret() is needed to not
|
2009-08-14 19:42:19 +00:00
|
|
|
* leak data.
|
|
|
|
*
|
|
|
|
* Returns a pointer to the secret, or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virSecretPtr
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
virGetSecret(virConnectPtr conn, const unsigned char *uuid,
|
|
|
|
int usageType, const char *usageID)
|
2009-08-14 19:42:19 +00:00
|
|
|
{
|
|
|
|
virSecretPtr ret = NULL;
|
Fix UUID handling in secrets/storage encryption APIs
Convert all the secret/storage encryption APIs / wire format to
handle UUIDs in raw format instead of non-canonical printable
format. Guarentees data format correctness.
* docs/schemas/storageencryption.rng: Make UUID mandatory for a secret
and validate fully
* docs/schemas/secret.rng: Fully validate UUID
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in, Add
virSecretLookupByUUID and virSecretGetUUID. Make
virSecretGetUUIDString follow normal API design pattern
* python/generator.py: Skip generation of virSecretGetUUID,
virSecretGetUUIDString and virSecretLookupByUUID
* python/libvir.c, python/libvirt-python-api.xml: Manual impl
of virSecretGetUUID,virSecretGetUUIDString and virSecretLookupByUUID
* qemud/remote.c: s/virSecretLookupByUUIDString/virSecretLookupByUUID/
Fix get_nonnull_secret/make_nonnull_secret to use unsigned char
* qemud/remote_protocol.x: Fix remote_nonnull_secret to use a
remote_uuid instead of remote_nonnull_string for UUID field.
Rename REMOTE_PROC_SECRET_LOOKUP_BY_UUID_STRING to
REMOTE_PROC_SECRET_LOOKUP_BY_UUID_STRING and make it take an
remote_uuid value
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.h, src/datatypes.c: Store UUID in raw format instead
of printable. Change virGetSecret to use raw format UUID
* src/driver.h: Rename virDrvSecretLookupByUUIDString to
virDrvSecretLookupByUUID and use raw format UUID
* src/libvirt.c: Add virSecretLookupByUUID and virSecretGetUUID
and re-implement virSecretLookupByUUIDString and
virSecretGetUUIDString in terms of those
* src/libvirt_public.syms: Add virSecretLookupByUUID and
virSecretGetUUID
* src/remote_internal.c: Rename remoteSecretLookupByUUIDString
to remoteSecretLookupByUUID. Fix typo in args for
remoteSecretDefineXML impl. Use raw UUID format for
get_nonnull_secret and make_nonnull_secret
* src/storage_encryption_conf.c, src/storage_encryption_conf.h:
Storage UUID in raw format, and require it to be present in
XML. Use UUID parser to validate.
* secret_conf.h, secret_conf.c: Generate a UUID if none is provided.
Storage UUID in raw format.
* src/secret_driver.c: Adjust to deal with raw UUIDs. Save secrets
in a filed with printable UUID, instead of base64 UUID.
* src/virsh.c: Adjust for changed public API contract of
virSecretGetUUIDString.
* src/storage_Backend.c: DOn't undefine secret we just generated
upon successful volume creation. Fix to handle raw UUIDs. Generate
a non-clashing UUID
* src/qemu_driver.c: Change to use lookupByUUID instead of
lookupByUUIDString
2009-09-10 16:44:12 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2009-08-14 19:42:19 +00:00
|
|
|
|
2010-05-12 02:57:56 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
|
2009-08-14 19:42:19 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
virCheckNonNullArgReturn(uuid, NULL);
|
|
|
|
virCheckNonNullArgReturn(usageID, NULL);
|
|
|
|
|
2009-08-14 19:42:19 +00:00
|
|
|
virMutexLock(&conn->lock);
|
|
|
|
|
Fix UUID handling in secrets/storage encryption APIs
Convert all the secret/storage encryption APIs / wire format to
handle UUIDs in raw format instead of non-canonical printable
format. Guarentees data format correctness.
* docs/schemas/storageencryption.rng: Make UUID mandatory for a secret
and validate fully
* docs/schemas/secret.rng: Fully validate UUID
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in, Add
virSecretLookupByUUID and virSecretGetUUID. Make
virSecretGetUUIDString follow normal API design pattern
* python/generator.py: Skip generation of virSecretGetUUID,
virSecretGetUUIDString and virSecretLookupByUUID
* python/libvir.c, python/libvirt-python-api.xml: Manual impl
of virSecretGetUUID,virSecretGetUUIDString and virSecretLookupByUUID
* qemud/remote.c: s/virSecretLookupByUUIDString/virSecretLookupByUUID/
Fix get_nonnull_secret/make_nonnull_secret to use unsigned char
* qemud/remote_protocol.x: Fix remote_nonnull_secret to use a
remote_uuid instead of remote_nonnull_string for UUID field.
Rename REMOTE_PROC_SECRET_LOOKUP_BY_UUID_STRING to
REMOTE_PROC_SECRET_LOOKUP_BY_UUID_STRING and make it take an
remote_uuid value
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.h, src/datatypes.c: Store UUID in raw format instead
of printable. Change virGetSecret to use raw format UUID
* src/driver.h: Rename virDrvSecretLookupByUUIDString to
virDrvSecretLookupByUUID and use raw format UUID
* src/libvirt.c: Add virSecretLookupByUUID and virSecretGetUUID
and re-implement virSecretLookupByUUIDString and
virSecretGetUUIDString in terms of those
* src/libvirt_public.syms: Add virSecretLookupByUUID and
virSecretGetUUID
* src/remote_internal.c: Rename remoteSecretLookupByUUIDString
to remoteSecretLookupByUUID. Fix typo in args for
remoteSecretDefineXML impl. Use raw UUID format for
get_nonnull_secret and make_nonnull_secret
* src/storage_encryption_conf.c, src/storage_encryption_conf.h:
Storage UUID in raw format, and require it to be present in
XML. Use UUID parser to validate.
* secret_conf.h, secret_conf.c: Generate a UUID if none is provided.
Storage UUID in raw format.
* src/secret_driver.c: Adjust to deal with raw UUIDs. Save secrets
in a filed with printable UUID, instead of base64 UUID.
* src/virsh.c: Adjust for changed public API contract of
virSecretGetUUIDString.
* src/storage_Backend.c: DOn't undefine secret we just generated
upon successful volume creation. Fix to handle raw UUIDs. Generate
a non-clashing UUID
* src/qemu_driver.c: Change to use lookupByUUID instead of
lookupByUUIDString
2009-09-10 16:44:12 +00:00
|
|
|
virUUIDFormat(uuid, uuidstr);
|
|
|
|
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
if (VIR_ALLOC(ret) < 0) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ret->magic = VIR_SECRET_MAGIC;
|
|
|
|
ret->conn = conn;
|
|
|
|
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
|
|
|
|
ret->usageType = usageType;
|
|
|
|
if (!(ret->usageID = strdup(usageID))) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
2009-08-14 19:42:19 +00:00
|
|
|
}
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
conn->refs++;
|
2009-08-14 19:42:19 +00:00
|
|
|
ret->refs++;
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (ret != NULL) {
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
VIR_FREE(ret->usageID);
|
2009-08-14 19:42:19 +00:00
|
|
|
VIR_FREE(ret);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virReleaseSecret:
|
|
|
|
* @secret: the secret to release
|
|
|
|
*
|
|
|
|
* Unconditionally release all memory associated with a secret. The conn.lock
|
|
|
|
* mutex must be held prior to calling this, and will be released prior to this
|
|
|
|
* returning. The secret obj must not be used once this method returns.
|
|
|
|
*
|
|
|
|
* It will also unreference the associated connection object, which may also be
|
|
|
|
* released if its ref count hits zero.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
virReleaseSecret(virSecretPtr secret) {
|
|
|
|
virConnectPtr conn = secret->conn;
|
Fix UUID handling in secrets/storage encryption APIs
Convert all the secret/storage encryption APIs / wire format to
handle UUIDs in raw format instead of non-canonical printable
format. Guarentees data format correctness.
* docs/schemas/storageencryption.rng: Make UUID mandatory for a secret
and validate fully
* docs/schemas/secret.rng: Fully validate UUID
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in, Add
virSecretLookupByUUID and virSecretGetUUID. Make
virSecretGetUUIDString follow normal API design pattern
* python/generator.py: Skip generation of virSecretGetUUID,
virSecretGetUUIDString and virSecretLookupByUUID
* python/libvir.c, python/libvirt-python-api.xml: Manual impl
of virSecretGetUUID,virSecretGetUUIDString and virSecretLookupByUUID
* qemud/remote.c: s/virSecretLookupByUUIDString/virSecretLookupByUUID/
Fix get_nonnull_secret/make_nonnull_secret to use unsigned char
* qemud/remote_protocol.x: Fix remote_nonnull_secret to use a
remote_uuid instead of remote_nonnull_string for UUID field.
Rename REMOTE_PROC_SECRET_LOOKUP_BY_UUID_STRING to
REMOTE_PROC_SECRET_LOOKUP_BY_UUID_STRING and make it take an
remote_uuid value
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.h, src/datatypes.c: Store UUID in raw format instead
of printable. Change virGetSecret to use raw format UUID
* src/driver.h: Rename virDrvSecretLookupByUUIDString to
virDrvSecretLookupByUUID and use raw format UUID
* src/libvirt.c: Add virSecretLookupByUUID and virSecretGetUUID
and re-implement virSecretLookupByUUIDString and
virSecretGetUUIDString in terms of those
* src/libvirt_public.syms: Add virSecretLookupByUUID and
virSecretGetUUID
* src/remote_internal.c: Rename remoteSecretLookupByUUIDString
to remoteSecretLookupByUUID. Fix typo in args for
remoteSecretDefineXML impl. Use raw UUID format for
get_nonnull_secret and make_nonnull_secret
* src/storage_encryption_conf.c, src/storage_encryption_conf.h:
Storage UUID in raw format, and require it to be present in
XML. Use UUID parser to validate.
* secret_conf.h, secret_conf.c: Generate a UUID if none is provided.
Storage UUID in raw format.
* src/secret_driver.c: Adjust to deal with raw UUIDs. Save secrets
in a filed with printable UUID, instead of base64 UUID.
* src/virsh.c: Adjust for changed public API contract of
virSecretGetUUIDString.
* src/storage_Backend.c: DOn't undefine secret we just generated
upon successful volume creation. Fix to handle raw UUIDs. Generate
a non-clashing UUID
* src/qemu_driver.c: Change to use lookupByUUID instead of
lookupByUUIDString
2009-09-10 16:44:12 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2009-08-14 19:42:19 +00:00
|
|
|
|
Fix UUID handling in secrets/storage encryption APIs
Convert all the secret/storage encryption APIs / wire format to
handle UUIDs in raw format instead of non-canonical printable
format. Guarentees data format correctness.
* docs/schemas/storageencryption.rng: Make UUID mandatory for a secret
and validate fully
* docs/schemas/secret.rng: Fully validate UUID
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in, Add
virSecretLookupByUUID and virSecretGetUUID. Make
virSecretGetUUIDString follow normal API design pattern
* python/generator.py: Skip generation of virSecretGetUUID,
virSecretGetUUIDString and virSecretLookupByUUID
* python/libvir.c, python/libvirt-python-api.xml: Manual impl
of virSecretGetUUID,virSecretGetUUIDString and virSecretLookupByUUID
* qemud/remote.c: s/virSecretLookupByUUIDString/virSecretLookupByUUID/
Fix get_nonnull_secret/make_nonnull_secret to use unsigned char
* qemud/remote_protocol.x: Fix remote_nonnull_secret to use a
remote_uuid instead of remote_nonnull_string for UUID field.
Rename REMOTE_PROC_SECRET_LOOKUP_BY_UUID_STRING to
REMOTE_PROC_SECRET_LOOKUP_BY_UUID_STRING and make it take an
remote_uuid value
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.h, src/datatypes.c: Store UUID in raw format instead
of printable. Change virGetSecret to use raw format UUID
* src/driver.h: Rename virDrvSecretLookupByUUIDString to
virDrvSecretLookupByUUID and use raw format UUID
* src/libvirt.c: Add virSecretLookupByUUID and virSecretGetUUID
and re-implement virSecretLookupByUUIDString and
virSecretGetUUIDString in terms of those
* src/libvirt_public.syms: Add virSecretLookupByUUID and
virSecretGetUUID
* src/remote_internal.c: Rename remoteSecretLookupByUUIDString
to remoteSecretLookupByUUID. Fix typo in args for
remoteSecretDefineXML impl. Use raw UUID format for
get_nonnull_secret and make_nonnull_secret
* src/storage_encryption_conf.c, src/storage_encryption_conf.h:
Storage UUID in raw format, and require it to be present in
XML. Use UUID parser to validate.
* secret_conf.h, secret_conf.c: Generate a UUID if none is provided.
Storage UUID in raw format.
* src/secret_driver.c: Adjust to deal with raw UUIDs. Save secrets
in a filed with printable UUID, instead of base64 UUID.
* src/virsh.c: Adjust for changed public API contract of
virSecretGetUUIDString.
* src/storage_Backend.c: DOn't undefine secret we just generated
upon successful volume creation. Fix to handle raw UUIDs. Generate
a non-clashing UUID
* src/qemu_driver.c: Change to use lookupByUUID instead of
lookupByUUIDString
2009-09-10 16:44:12 +00:00
|
|
|
virUUIDFormat(secret->uuid, uuidstr);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("release secret %p %s", secret, uuidstr);
|
2010-06-17 14:45:29 +00:00
|
|
|
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
VIR_FREE(secret->usageID);
|
2009-08-14 19:42:19 +00:00
|
|
|
secret->magic = -1;
|
|
|
|
VIR_FREE(secret);
|
|
|
|
|
|
|
|
if (conn) {
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref connection %p %d", conn, conn->refs);
|
2009-08-14 19:42:19 +00:00
|
|
|
conn->refs--;
|
|
|
|
if (conn->refs == 0) {
|
|
|
|
virReleaseConnect(conn);
|
|
|
|
/* Already unlocked mutex */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virUnrefSecret:
|
|
|
|
* @secret: the secret to unreference
|
|
|
|
*
|
|
|
|
* Unreference the secret. If the use count drops to zero, the structure is
|
|
|
|
* actually freed.
|
|
|
|
*
|
|
|
|
* Returns the reference count or -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virUnrefSecret(virSecretPtr secret) {
|
|
|
|
int refs;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_SECRET(secret)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_SECRET, "%s",
|
|
|
|
_("bad secret or no connection"));
|
2009-08-14 19:42:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
virMutexLock(&secret->conn->lock);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref secret %p %p %d", secret, secret->uuid, secret->refs);
|
2009-08-14 19:42:19 +00:00
|
|
|
secret->refs--;
|
|
|
|
refs = secret->refs;
|
|
|
|
if (refs == 0) {
|
|
|
|
virReleaseSecret(secret);
|
|
|
|
/* Already unlocked mutex */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virMutexUnlock(&secret->conn->lock);
|
|
|
|
return refs;
|
|
|
|
}
|
2009-07-10 11:18:12 +00:00
|
|
|
|
|
|
|
virStreamPtr virGetStream(virConnectPtr conn) {
|
|
|
|
virStreamPtr ret = NULL;
|
|
|
|
|
|
|
|
virMutexLock(&conn->lock);
|
|
|
|
|
|
|
|
if (VIR_ALLOC(ret) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-10 11:18:12 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ret->magic = VIR_STREAM_MAGIC;
|
|
|
|
ret->conn = conn;
|
|
|
|
conn->refs++;
|
|
|
|
ret->refs++;
|
|
|
|
virMutexUnlock(&conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-07-10 11:18:12 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
VIR_FREE(ret);
|
2012-03-22 11:33:35 +00:00
|
|
|
return NULL;
|
2009-07-10 11:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
virReleaseStream(virStreamPtr st) {
|
|
|
|
virConnectPtr conn = st->conn;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("release dev %p", st);
|
2009-07-10 11:18:12 +00:00
|
|
|
|
|
|
|
st->magic = -1;
|
|
|
|
VIR_FREE(st);
|
|
|
|
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref connection %p %d", conn, conn->refs);
|
2009-07-10 11:18:12 +00:00
|
|
|
conn->refs--;
|
|
|
|
if (conn->refs == 0) {
|
|
|
|
virReleaseConnect(conn);
|
|
|
|
/* Already unlocked mutex */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
int virUnrefStream(virStreamPtr st) {
|
|
|
|
int refs;
|
|
|
|
|
|
|
|
virMutexLock(&st->conn->lock);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref stream %p %d", st, st->refs);
|
2009-07-10 11:18:12 +00:00
|
|
|
st->refs--;
|
|
|
|
refs = st->refs;
|
|
|
|
if (refs == 0) {
|
|
|
|
virReleaseStream(st);
|
|
|
|
/* Already unlocked mutex */
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2009-07-10 11:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virMutexUnlock(&st->conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return refs;
|
2009-07-10 11:18:12 +00:00
|
|
|
}
|
2010-03-25 17:46:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virGetNWFilter:
|
|
|
|
* @conn: the hypervisor connection
|
|
|
|
* @name: pointer to the network filter pool name
|
|
|
|
* @uuid: pointer to the uuid
|
|
|
|
*
|
|
|
|
* Lookup if the network filter is already registered for that connection,
|
|
|
|
* if yes return a new pointer to it, if no allocate a new structure,
|
|
|
|
* and register it in the table. In any case a corresponding call to
|
2011-01-15 15:06:52 +00:00
|
|
|
* virUnrefNWFilter() is needed to not leak data.
|
2010-03-25 17:46:02 +00:00
|
|
|
*
|
|
|
|
* Returns a pointer to the network, or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virNWFilterPtr
|
|
|
|
virGetNWFilter(virConnectPtr conn, const char *name, const unsigned char *uuid) {
|
|
|
|
virNWFilterPtr ret = NULL;
|
2010-06-17 14:45:26 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2010-03-25 17:46:02 +00:00
|
|
|
|
2010-05-12 02:57:56 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
|
2010-05-12 02:57:56 +00:00
|
|
|
return NULL;
|
2010-03-25 17:46:02 +00:00
|
|
|
}
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
virCheckNonNullArgReturn(name, NULL);
|
|
|
|
virCheckNonNullArgReturn(uuid, NULL);
|
|
|
|
|
2010-03-25 17:46:02 +00:00
|
|
|
virMutexLock(&conn->lock);
|
|
|
|
|
2010-06-17 14:45:26 +00:00
|
|
|
virUUIDFormat(uuid, uuidstr);
|
2010-03-25 17:46:02 +00:00
|
|
|
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
if (VIR_ALLOC(ret) < 0) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ret->name = strdup(name);
|
|
|
|
if (ret->name == NULL) {
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
2010-03-25 17:46:02 +00:00
|
|
|
}
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
ret->magic = VIR_NWFILTER_MAGIC;
|
|
|
|
ret->conn = conn;
|
|
|
|
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
|
|
|
|
|
|
|
|
conn->refs++;
|
2010-03-25 17:46:02 +00:00
|
|
|
ret->refs++;
|
|
|
|
virMutexUnlock(&conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2010-03-25 17:46:02 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (ret != NULL) {
|
|
|
|
VIR_FREE(ret->name);
|
|
|
|
VIR_FREE(ret);
|
|
|
|
}
|
2012-03-22 11:33:35 +00:00
|
|
|
return NULL;
|
2010-03-25 17:46:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-01-15 15:06:52 +00:00
|
|
|
* virReleaseNWFilter:
|
|
|
|
* @nwfilter: the nwfilter to release
|
2010-03-25 17:46:02 +00:00
|
|
|
*
|
2011-01-15 15:06:52 +00:00
|
|
|
* Unconditionally release all memory associated with a nwfilter.
|
2010-03-25 17:46:02 +00:00
|
|
|
* The conn.lock mutex must be held prior to calling this, and will
|
2011-01-15 15:06:52 +00:00
|
|
|
* be released prior to this returning. The nwfilter obj must not
|
2010-03-25 17:46:02 +00:00
|
|
|
* be used once this method returns.
|
|
|
|
*
|
|
|
|
* It will also unreference the associated connection object,
|
|
|
|
* which may also be released if its ref count hits zero.
|
|
|
|
*/
|
|
|
|
static void
|
2011-01-15 15:06:52 +00:00
|
|
|
virReleaseNWFilter(virNWFilterPtr nwfilter)
|
|
|
|
{
|
|
|
|
virConnectPtr conn = nwfilter->conn;
|
2010-06-17 14:45:26 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2010-03-25 17:46:02 +00:00
|
|
|
|
2011-01-15 15:06:52 +00:00
|
|
|
virUUIDFormat(nwfilter->uuid, uuidstr);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("release nwfilter %p %s %s", nwfilter, nwfilter->name, uuidstr);
|
2010-06-17 14:45:26 +00:00
|
|
|
|
2011-01-15 15:06:52 +00:00
|
|
|
nwfilter->magic = -1;
|
|
|
|
VIR_FREE(nwfilter->name);
|
|
|
|
VIR_FREE(nwfilter);
|
2010-03-25 17:46:02 +00:00
|
|
|
|
|
|
|
if (conn) {
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref connection %p %d", conn, conn->refs);
|
2010-03-25 17:46:02 +00:00
|
|
|
conn->refs--;
|
|
|
|
if (conn->refs == 0) {
|
|
|
|
virReleaseConnect(conn);
|
|
|
|
/* Already unlocked mutex */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virUnrefNWFilter:
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
* @nwfilter: the nwfilter to unreference
|
2010-03-25 17:46:02 +00:00
|
|
|
*
|
|
|
|
* Unreference the networkf itler. If the use count drops to zero, the
|
|
|
|
* structure is actually freed.
|
|
|
|
*
|
|
|
|
* Returns the reference count or -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2011-01-15 15:06:52 +00:00
|
|
|
virUnrefNWFilter(virNWFilterPtr nwfilter)
|
|
|
|
{
|
2010-03-25 17:46:02 +00:00
|
|
|
int refs;
|
|
|
|
|
2011-01-15 15:06:52 +00:00
|
|
|
if (!VIR_IS_CONNECTED_NWFILTER(nwfilter)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_NWFILTER, "%s",
|
2010-05-12 02:57:56 +00:00
|
|
|
_("bad nwfilter or no connection"));
|
2010-03-25 17:46:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2011-01-15 15:06:52 +00:00
|
|
|
virMutexLock(&nwfilter->conn->lock);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref nwfilter %p %s %d", nwfilter, nwfilter->name,
|
|
|
|
nwfilter->refs);
|
2011-01-15 15:06:52 +00:00
|
|
|
nwfilter->refs--;
|
|
|
|
refs = nwfilter->refs;
|
2010-03-25 17:46:02 +00:00
|
|
|
if (refs == 0) {
|
2011-01-15 15:06:52 +00:00
|
|
|
virReleaseNWFilter(nwfilter);
|
2010-03-25 17:46:02 +00:00
|
|
|
/* Already unlocked mutex */
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2010-03-25 17:46:02 +00:00
|
|
|
}
|
|
|
|
|
2011-01-15 15:06:52 +00:00
|
|
|
virMutexUnlock(&nwfilter->conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return refs;
|
2010-03-25 17:46:02 +00:00
|
|
|
}
|
2010-03-31 20:33:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
virDomainSnapshotPtr
|
|
|
|
virGetDomainSnapshot(virDomainPtr domain, const char *name)
|
|
|
|
{
|
|
|
|
virDomainSnapshotPtr ret = NULL;
|
|
|
|
|
2010-05-12 02:57:56 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_DOMAIN, "%s", _("bad domain"));
|
2010-05-12 02:57:56 +00:00
|
|
|
return NULL;
|
2010-03-31 20:33:13 +00:00
|
|
|
}
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
virCheckNonNullArgReturn(name, NULL);
|
|
|
|
|
2010-03-31 20:33:13 +00:00
|
|
|
virMutexLock(&domain->conn->lock);
|
|
|
|
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
if (VIR_ALLOC(ret) < 0) {
|
|
|
|
virMutexUnlock(&domain->conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ret->name = strdup(name);
|
|
|
|
if (ret->name == NULL) {
|
|
|
|
virMutexUnlock(&domain->conn->lock);
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
2010-03-31 20:33:13 +00:00
|
|
|
}
|
Remove all object hashtable caches from virConnectPtr
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
2010-10-29 11:43:34 +00:00
|
|
|
ret->magic = VIR_SNAPSHOT_MAGIC;
|
|
|
|
ret->domain = domain;
|
|
|
|
|
|
|
|
domain->refs++;
|
2010-03-31 20:33:13 +00:00
|
|
|
ret->refs++;
|
|
|
|
virMutexUnlock(&domain->conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2010-03-31 20:33:13 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (ret != NULL) {
|
|
|
|
VIR_FREE(ret->name);
|
|
|
|
VIR_FREE(ret);
|
|
|
|
}
|
2012-03-22 11:33:35 +00:00
|
|
|
return NULL;
|
2010-03-31 20:33:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
virReleaseDomainSnapshot(virDomainSnapshotPtr snapshot)
|
|
|
|
{
|
|
|
|
virDomainPtr domain = snapshot->domain;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("release snapshot %p %s", snapshot, snapshot->name);
|
2010-03-31 20:33:13 +00:00
|
|
|
|
|
|
|
snapshot->magic = -1;
|
|
|
|
VIR_FREE(snapshot->name);
|
|
|
|
VIR_FREE(snapshot);
|
|
|
|
|
|
|
|
if (domain) {
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref domain %p %d", domain, domain->refs);
|
2010-03-31 20:33:13 +00:00
|
|
|
domain->refs--;
|
|
|
|
if (domain->refs == 0) {
|
|
|
|
virReleaseDomain(domain);
|
|
|
|
/* Already unlocked mutex */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
virMutexUnlock(&domain->conn->lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
virUnrefDomainSnapshot(virDomainSnapshotPtr snapshot)
|
|
|
|
{
|
|
|
|
int refs;
|
|
|
|
|
|
|
|
if (!VIR_IS_DOMAIN_SNAPSHOT(snapshot)) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virLibConnError(VIR_ERR_INVALID_DOMAIN_SNAPSHOT, "%s",
|
|
|
|
_("not a snapshot"));
|
2010-05-12 02:57:56 +00:00
|
|
|
return -1;
|
2010-03-31 20:33:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virMutexLock(&snapshot->domain->conn->lock);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("unref snapshot %p %s %d", snapshot, snapshot->name, snapshot->refs);
|
2010-03-31 20:33:13 +00:00
|
|
|
snapshot->refs--;
|
|
|
|
refs = snapshot->refs;
|
|
|
|
if (refs == 0) {
|
|
|
|
virReleaseDomainSnapshot(snapshot);
|
|
|
|
/* Already unlocked mutex */
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2010-03-31 20:33:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virMutexUnlock(&snapshot->domain->conn->lock);
|
2012-03-22 11:33:35 +00:00
|
|
|
return refs;
|
2010-03-31 20:33:13 +00:00
|
|
|
}
|