[libvirt] [PATCH] build: Create needed folders without dependency tracking
by Martin Kletzander
The parameter --disable-dependency-tracking is supposed to speed up
one-time build due to the fact that it disables some dependency
extractors that, apparently, take longer time to execute. That is a
problem for code that is generated into builddir (especially some
specific subdirectory) because the directory it should be installed to
does not exists in VPATH and without the dependency tracking is not
created. Generating such file hence fails with -ENOENT. In order to
keep generating files into builddir instead of srcdir, we must create
the directory ourselves. This should finally fix the problem that is
being fixed multiple times since its introduction in commit a9fe62037214
and let us continue with cleaning those parts of Makefiles that depend
on generating files into the srcdir rather than builddir as it should
be.
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
src/Makefile.am | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/Makefile.am b/src/Makefile.am
index bcbee9de11d6..93b9c66662a1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -181,6 +181,7 @@ MAINTAINERCLEANFILES += util/virkeymaps.h
util/virkeymaps.h: $(srcdir)/util/keymaps.csv \
$(srcdir)/util/virkeycode-mapgen.py
+ $(MKDIR_P) util/
$(AM_V_GEN)$(PYTHON) $(srcdir)/util/virkeycode-mapgen.py \
<$(srcdir)/util/keymaps.csv >util/virkeymaps.h
--
2.6.3
9 years
[libvirt] [PATCH] util: Avoid variable named 'truncate' shadowing global declaration
by Martin Kletzander
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
Pushed under the build-breaker rule as trivial.
src/util/virrotatingfile.c | 6 +++---
src/util/virrotatingfile.h | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/util/virrotatingfile.c b/src/util/virrotatingfile.c
index 827b44b6f948..a32759abe66d 100644
--- a/src/util/virrotatingfile.c
+++ b/src/util/virrotatingfile.c
@@ -219,7 +219,7 @@ virRotatingFileWriterDelete(virRotatingFileWriterPtr file)
* @path: the base path for files
* @maxlen: the maximum number of bytes to write before rollover
* @maxbackup: number of backup files to keep when rolling over
- * @truncate: whether to truncate the current files when opening
+ * @trunc: whether to truncate the current files when opening
* @mode: the file mode to use for creating new files
*
* Create a new object for writing data to a file with
@@ -235,7 +235,7 @@ virRotatingFileWriterPtr
virRotatingFileWriterNew(const char *path,
off_t maxlen,
size_t maxbackup,
- bool truncate,
+ bool trunc,
mode_t mode)
{
virRotatingFileWriterPtr file;
@@ -257,7 +257,7 @@ virRotatingFileWriterNew(const char *path,
file->maxbackup = maxbackup;
file->maxlen = maxlen;
- if (truncate &&
+ if (trunc &&
virRotatingFileWriterDelete(file) < 0)
goto error;
diff --git a/src/util/virrotatingfile.h b/src/util/virrotatingfile.h
index 30cc8a540896..7848443101a6 100644
--- a/src/util/virrotatingfile.h
+++ b/src/util/virrotatingfile.h
@@ -33,7 +33,7 @@ typedef virRotatingFileReader *virRotatingFileReaderPtr;
virRotatingFileWriterPtr virRotatingFileWriterNew(const char *path,
off_t maxlen,
size_t maxbackup,
- bool truncate,
+ bool trunc,
mode_t mode);
virRotatingFileReaderPtr virRotatingFileReaderNew(const char *path,
--
2.6.3
9 years
[libvirt] [PATCH] include: Install libvirt-common.h
by Martin Kletzander
Otherwise nobody will be able to include libvirt.h.
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
include/libvirt/Makefile.am | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/libvirt/Makefile.am b/include/libvirt/Makefile.am
index 8e5b1b873dd7..5a4ada0b77d2 100644
--- a/include/libvirt/Makefile.am
+++ b/include/libvirt/Makefile.am
@@ -19,6 +19,7 @@
virincdir = $(includedir)/libvirt
virinc_HEADERS = libvirt.h \
+ libvirt-common.h \
libvirt-domain.h \
libvirt-domain-snapshot.h \
libvirt-event.h \
--
2.6.3
9 years
[libvirt] [PATCH] guest-agent-socket: don't generate default path to config XML
by Pavel Hrdina
While we started using for all unix sockets as default one common
directory based on a guest name it introduced several issues, for example
with renaming the guest or cloning it. In general it's not entirely
bad, but in this case it would be best to hide the auto-generated socket
path from user and don't export it in the config XML.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/conf/domain_conf.c | 2 +-
src/qemu/qemu_command.c | 28 ++++++++++++++++++++++++++++
src/qemu/qemu_command.h | 1 +
src/qemu/qemu_domain.c | 16 ----------------
src/qemu/qemu_driver.c | 10 ++++++++++
src/qemu/qemu_process.c | 3 +++
tests/qemuhotplugtest.c | 5 +++++
tests/qemuxml2argvtest.c | 5 +++++
8 files changed, 53 insertions(+), 17 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index cbfc41e..ebae828 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9810,7 +9810,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
goto error;
}
- def->data.nix.listen = mode != NULL && STRNEQ(mode, "connect");
+ def->data.nix.listen = mode == NULL || STRNEQ(mode, "connect");
def->data.nix.path = path;
path = NULL;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2a9fab5..f1bb621 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1262,6 +1262,34 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
}
+int
+qemuUnixSocketGenerate(virDomainDefPtr def,
+ virQEMUDriverConfigPtr cfg)
+{
+ size_t i;
+
+ for (i = 0; i < def->nchannels; i++) {
+ virDomainChrDefPtr channel = def->channels[i];
+
+ if (channel->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
+ channel->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO &&
+ channel->source.type == VIR_DOMAIN_CHR_TYPE_UNIX &&
+ !channel->source.data.nix.path) {
+ if (virAsprintf(&channel->source.data.nix.path,
+ "%s/domain-%s/%s",
+ cfg->channelTargetDir, def->name,
+ channel->target.name ? channel->target.name
+ : "unknown.sock") < 0)
+ return -1;
+
+ channel->source.data.nix.listen = true;
+ }
+ }
+
+ return 0;
+}
+
+
static void
qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr def,
virDomainDeviceAddressType type)
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index bebdd27..0512a23 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -283,6 +283,7 @@ int qemuAssignDevicePCISlots(virDomainDefPtr def,
virDomainPCIAddressSetPtr addrs);
int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps);
+int qemuUnixSocketGenerate(virDomainDefPtr def, virQEMUDriverConfigPtr cfg);
int qemuDomainNetVLAN(virDomainNetDefPtr def);
int qemuAssignDeviceNetAlias(virDomainDefPtr def, virDomainNetDefPtr net, int idx);
int qemuAssignDeviceDiskAlias(virDomainDefPtr vmdef,
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index ed21245..7e05289 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1329,22 +1329,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
ARCH_IS_S390(def->os.arch))
dev->data.controller->model = VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_SCSI;
- /* auto generate unix socket path */
- if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
- dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
- dev->data.chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO &&
- dev->data.chr->source.type == VIR_DOMAIN_CHR_TYPE_UNIX &&
- !dev->data.chr->source.data.nix.path) {
- if (virAsprintf(&dev->data.chr->source.data.nix.path,
- "%s/domain-%s/%s",
- cfg->channelTargetDir, def->name,
- dev->data.chr->target.name ? dev->data.chr->target.name
- : "unknown.sock") < 0)
- goto cleanup;
-
- dev->data.chr->source.data.nix.listen = true;
- }
-
/* forbid capabilities mode hostdev in this kind of hypervisor */
if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ae1d8e7..b4fac55 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7254,6 +7254,9 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
if (qemuAssignDeviceAliases(def, qemuCaps) < 0)
goto cleanup;
+ if (qemuUnixSocketGenerate(def, cfg) < 0)
+ goto cleanup;
+
if (qemuDomainAssignAddresses(def, qemuCaps, NULL) < 0)
goto cleanup;
@@ -15846,6 +15849,7 @@ static virDomainPtr qemuDomainQemuAttach(virConnectPtr conn,
unsigned int flags)
{
virQEMUDriverPtr driver = conn->privateData;
+ virQEMUDriverConfigPtr cfg = NULL;
virDomainObjPtr vm = NULL;
virDomainDefPtr def = NULL;
virDomainPtr dom = NULL;
@@ -15858,6 +15862,8 @@ static virDomainPtr qemuDomainQemuAttach(virConnectPtr conn,
virCheckFlags(0, NULL);
+ cfg = virQEMUDriverGetConfig(driver);
+
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup;
@@ -15895,6 +15901,9 @@ static virDomainPtr qemuDomainQemuAttach(virConnectPtr conn,
if (qemuAssignDeviceAliases(def, qemuCaps) < 0)
goto cleanup;
+ if (qemuUnixSocketGenerate(def, cfg) < 0)
+ goto cleanup;
+
if (qemuDomainAssignAddresses(def, qemuCaps, NULL) < 0)
goto cleanup;
@@ -15936,6 +15945,7 @@ static virDomainPtr qemuDomainQemuAttach(virConnectPtr conn,
VIR_FREE(pidfile);
virObjectUnref(caps);
virObjectUnref(qemuCaps);
+ virObjectUnref(cfg);
return dom;
}
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 192730c..29cf965 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4663,6 +4663,9 @@ qemuProcessLaunch(virConnectPtr conn,
if (qemuAssignDeviceAliases(vm->def, priv->qemuCaps) < 0)
goto cleanup;
+ if (qemuUnixSocketGenerate(vm->def, cfg) < 0)
+ goto cleanup;
+
/* Get the advisory nodeset from numad if 'placement' of
* either <vcpu> or <numatune> is 'auto'.
*/
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 102e052..b17cca2 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -61,6 +61,7 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt,
{
int ret = -1;
qemuDomainObjPrivatePtr priv = NULL;
+ virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(&driver);
if (!(*vm = virDomainObjNew(xmlopt)))
goto cleanup;
@@ -94,10 +95,14 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt,
if (qemuAssignDeviceAliases((*vm)->def, priv->qemuCaps) < 0)
goto cleanup;
+ if (qemuUnixSocketGenerate((*vm)->def, cfg) < 0)
+ goto cleanup;
+
(*vm)->def->id = QEMU_HOTPLUG_TEST_DOMAIN_ID;
ret = 0;
cleanup:
+ virObjectUnref(cfg);
return ret;
}
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index f7596a0..f6083db 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -262,6 +262,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
virCommandPtr cmd = NULL;
size_t i;
virBitmapPtr nodeset = NULL;
+ virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(&driver);
if (!(conn = virGetConnect()))
goto out;
@@ -324,6 +325,9 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (qemuAssignDeviceAliases(vmdef, extraFlags) < 0)
goto out;
+ if (qemuUnixSocketGenerate(vmdef, cfg) < 0)
+ goto out;
+
for (i = 0; i < vmdef->nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = vmdef->hostdevs[i];
@@ -387,6 +391,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
virCommandFree(cmd);
virDomainDefFree(vmdef);
virObjectUnref(conn);
+ virObjectUnref(cfg);
virBitmapFree(nodeset);
return ret;
}
--
2.6.3
9 years
[libvirt] [PATCH] sheepdog: allow snapshot
by Vasiliy Tolstov
In commit f7c1410b0ee5b878e81f2eddf86c609947a9b27c libvirt devs
disable creating snapshot with sheepdog storage and raw image format.
This patch allows creating snapshot (without --live flag for now)
Vasiliy Tolstov (1):
sheepdog: allow snapshot
src/qemu/qemu_driver.c | 6 ++++++
1 file changed, 6 insertions(+)
--
2.5.0
9 years
[libvirt] [PATCH v2] conf: Split virDomainObjList into a separate file
by Michal Privoznik
Our domain_conf.* files are big enough. Not only they contain XML
parsing code, but they served as a storage of all functions whose
name is virDomain prefixed. This is just wrong as it gathers not
related functions (and modules) into one big file which is then
harder to maintain. Split virDomainObjList module into a separate
file called virdomainobjlist.[ch].
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
diff to v1:
-rebase to current HEAD
po/POTFILES.in | 1 +
src/Makefile.am | 3 +-
src/conf/domain_conf.c | 936 ----------------------------------------
src/conf/domain_conf.h | 120 ------
src/conf/nwfilter_conf.h | 2 +-
src/conf/virdomainobjlist.c | 999 +++++++++++++++++++++++++++++++++++++++++++
src/conf/virdomainobjlist.h | 151 +++++++
src/esx/esx_driver.c | 2 +-
src/hyperv/hyperv_driver.c | 2 +-
src/libvirt_private.syms | 39 +-
src/libxl/libxl_conf.h | 2 +-
src/openvz/openvz_conf.h | 2 +-
src/test/test_driver.c | 1 +
src/uml/uml_conf.h | 2 +-
src/util/virclosecallbacks.h | 2 +-
src/vbox/vbox_common.c | 2 +-
src/vmware/vmware_conf.h | 2 +-
src/vz/vz_utils.h | 1 +
tools/virsh-domain-monitor.c | 2 +-
19 files changed, 1186 insertions(+), 1085 deletions(-)
create mode 100644 src/conf/virdomainobjlist.c
create mode 100644 src/conf/virdomainobjlist.h
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0cc5b99..f007d3e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -36,6 +36,7 @@ src/conf/secret_conf.c
src/conf/snapshot_conf.c
src/conf/storage_conf.c
src/conf/virchrdev.c
+src/conf/virdomainobjlist.c
src/cpu/cpu.c
src/cpu/cpu_generic.c
src/cpu/cpu_map.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 99b4993..26d29a9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -277,7 +277,8 @@ DOMAIN_CONF_SOURCES = \
conf/domain_audit.c conf/domain_audit.h \
conf/domain_nwfilter.c conf/domain_nwfilter.h \
conf/snapshot_conf.c conf/snapshot_conf.h \
- conf/numa_conf.c conf/numa_conf.h
+ conf/numa_conf.c conf/numa_conf.h \
+ conf/virdomainobjlist.c conf/virdomainobjlist.h
OBJECT_EVENT_SOURCES = \
conf/object_event.c conf/object_event.h \
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0ac7dbf..1093a5e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -24,7 +24,6 @@
#include <config.h>
-#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -59,19 +58,6 @@
VIR_LOG_INIT("conf.domain_conf");
-struct _virDomainObjList {
- virObjectLockable parent;
-
- /* uuid string -> virDomainObj mapping
- * for O(1), lockless lookup-by-uuid */
- virHashTable *objs;
-
- /* name -> virDomainObj mapping for O(1),
- * lockless lookup-by-name */
- virHashTable *objsName;
-};
-
-
/* This structure holds various callbacks and data needed
* while parsing and creating domain XMLs */
struct _virDomainXMLOption {
@@ -818,10 +804,8 @@ VIR_ENUM_IMPL(virDomainMemoryModel, VIR_DOMAIN_MEMORY_MODEL_LAST,
"", "dimm")
static virClassPtr virDomainObjClass;
-static virClassPtr virDomainObjListClass;
static virClassPtr virDomainXMLOptionClass;
static void virDomainObjDispose(void *obj);
-static void virDomainObjListDispose(void *obj);
static void virDomainXMLOptionClassDispose(void *obj);
static int virDomainObjOnceInit(void)
@@ -832,12 +816,6 @@ static int virDomainObjOnceInit(void)
virDomainObjDispose)))
return -1;
- if (!(virDomainObjListClass = virClassNew(virClassForObjectLockable(),
- "virDomainObjList",
- sizeof(virDomainObjList),
- virDomainObjListDispose)))
- return -1;
-
if (!(virDomainXMLOptionClass = virClassNew(virClassForObject(),
"virDomainXMLOption",
sizeof(virDomainXMLOption),
@@ -1187,134 +1165,6 @@ virDomainDeviceDefCheckUnsupportedMemoryDevice(virDomainDeviceDefPtr dev)
}
-virDomainObjListPtr virDomainObjListNew(void)
-{
- virDomainObjListPtr doms;
-
- if (virDomainObjInitialize() < 0)
- return NULL;
-
- if (!(doms = virObjectLockableNew(virDomainObjListClass)))
- return NULL;
-
- if (!(doms->objs = virHashCreate(50, virObjectFreeHashData)) ||
- !(doms->objsName = virHashCreate(50, virObjectFreeHashData))) {
- virObjectUnref(doms);
- return NULL;
- }
-
- return doms;
-}
-
-
-static void virDomainObjListDispose(void *obj)
-{
- virDomainObjListPtr doms = obj;
-
- virHashFree(doms->objs);
- virHashFree(doms->objsName);
-}
-
-
-static int virDomainObjListSearchID(const void *payload,
- const void *name ATTRIBUTE_UNUSED,
- const void *data)
-{
- virDomainObjPtr obj = (virDomainObjPtr)payload;
- const int *id = data;
- int want = 0;
-
- virObjectLock(obj);
- if (virDomainObjIsActive(obj) &&
- obj->def->id == *id)
- want = 1;
- virObjectUnlock(obj);
- return want;
-}
-
-virDomainObjPtr virDomainObjListFindByID(virDomainObjListPtr doms,
- int id)
-{
- virDomainObjPtr obj;
- virObjectLock(doms);
- obj = virHashSearch(doms->objs, virDomainObjListSearchID, &id);
- if (obj) {
- virObjectLock(obj);
- if (obj->removing) {
- virObjectUnlock(obj);
- obj = NULL;
- }
- }
- virObjectUnlock(doms);
- return obj;
-}
-
-
-static virDomainObjPtr
-virDomainObjListFindByUUIDInternal(virDomainObjListPtr doms,
- const unsigned char *uuid,
- bool ref)
-{
- char uuidstr[VIR_UUID_STRING_BUFLEN];
- virDomainObjPtr obj;
-
- virObjectLock(doms);
- virUUIDFormat(uuid, uuidstr);
-
- obj = virHashLookup(doms->objs, uuidstr);
- if (ref) {
- virObjectRef(obj);
- virObjectUnlock(doms);
- }
- if (obj) {
- virObjectLock(obj);
- if (obj->removing) {
- virObjectUnlock(obj);
- if (ref)
- virObjectUnref(obj);
- obj = NULL;
- }
- }
- if (!ref)
- virObjectUnlock(doms);
- return obj;
-}
-
-virDomainObjPtr
-virDomainObjListFindByUUID(virDomainObjListPtr doms,
- const unsigned char *uuid)
-{
- return virDomainObjListFindByUUIDInternal(doms, uuid, false);
-}
-
-virDomainObjPtr
-virDomainObjListFindByUUIDRef(virDomainObjListPtr doms,
- const unsigned char *uuid)
-{
- return virDomainObjListFindByUUIDInternal(doms, uuid, true);
-}
-
-virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
- const char *name)
-{
- virDomainObjPtr obj;
-
- virObjectLock(doms);
- obj = virHashLookup(doms->objsName, name);
- virObjectRef(obj);
- virObjectUnlock(doms);
- if (obj) {
- virObjectLock(obj);
- if (obj->removing) {
- virObjectUnlock(obj);
- virObjectUnref(obj);
- obj = NULL;
- }
- }
- return obj;
-}
-
-
bool virDomainObjTaint(virDomainObjPtr obj,
virDomainTaintFlags taint)
{
@@ -2810,153 +2660,6 @@ virDomainObjWaitUntil(virDomainObjPtr vm,
/*
- *
- * If flags & VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE then
- * this will refuse updating an existing def if the
- * current def is Live
- *
- * If flags & VIR_DOMAIN_OBJ_LIST_ADD_LIVE then
- * the @def being added is assumed to represent a
- * live config, not a future inactive config
- *
- */
-static virDomainObjPtr
-virDomainObjListAddLocked(virDomainObjListPtr doms,
- virDomainDefPtr def,
- virDomainXMLOptionPtr xmlopt,
- unsigned int flags,
- virDomainDefPtr *oldDef)
-{
- virDomainObjPtr vm;
- char uuidstr[VIR_UUID_STRING_BUFLEN];
-
- if (oldDef)
- *oldDef = NULL;
-
- virUUIDFormat(def->uuid, uuidstr);
-
- /* See if a VM with matching UUID already exists */
- if ((vm = virHashLookup(doms->objs, uuidstr))) {
- virObjectLock(vm);
- /* UUID matches, but if names don't match, refuse it */
- if (STRNEQ(vm->def->name, def->name)) {
- virUUIDFormat(vm->def->uuid, uuidstr);
- virReportError(VIR_ERR_OPERATION_FAILED,
- _("domain '%s' is already defined with uuid %s"),
- vm->def->name, uuidstr);
- goto error;
- }
-
- if (flags & VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE) {
- /* UUID & name match, but if VM is already active, refuse it */
- if (virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- _("domain '%s' is already active"),
- vm->def->name);
- goto error;
- }
- if (!vm->persistent) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- _("domain '%s' is already being started"),
- vm->def->name);
- goto error;
- }
- }
-
- virDomainObjAssignDef(vm,
- def,
- !!(flags & VIR_DOMAIN_OBJ_LIST_ADD_LIVE),
- oldDef);
- } else {
- /* UUID does not match, but if a name matches, refuse it */
- if ((vm = virHashLookup(doms->objsName, def->name))) {
- virObjectLock(vm);
- virUUIDFormat(vm->def->uuid, uuidstr);
- virReportError(VIR_ERR_OPERATION_FAILED,
- _("domain '%s' already exists with uuid %s"),
- def->name, uuidstr);
- goto error;
- }
-
- if (!(vm = virDomainObjNew(xmlopt)))
- goto cleanup;
- vm->def = def;
-
- virUUIDFormat(def->uuid, uuidstr);
- if (virHashAddEntry(doms->objs, uuidstr, vm) < 0) {
- virObjectUnref(vm);
- return NULL;
- }
-
- if (virHashAddEntry(doms->objsName, def->name, vm) < 0) {
- virHashRemoveEntry(doms->objs, uuidstr);
- return NULL;
- }
-
- /* Since domain is in two hash tables, increment the
- * reference counter */
- virObjectRef(vm);
- }
- cleanup:
- return vm;
-
- error:
- virObjectUnlock(vm);
- vm = NULL;
- goto cleanup;
-}
-
-
-virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms,
- virDomainDefPtr def,
- virDomainXMLOptionPtr xmlopt,
- unsigned int flags,
- virDomainDefPtr *oldDef)
-{
- virDomainObjPtr ret;
-
- virObjectLock(doms);
- ret = virDomainObjListAddLocked(doms, def, xmlopt, flags, oldDef);
- virObjectUnlock(doms);
- return ret;
-}
-
-
-int
-virDomainObjListRenameAddNew(virDomainObjListPtr doms,
- virDomainObjPtr vm,
- const char *name)
-{
- int ret = -1;
- virObjectLock(doms);
-
- /* Add new name into the hash table of domain names. */
- if (virHashAddEntry(doms->objsName, name, vm) < 0)
- goto cleanup;
-
- /* Okay, this is crazy. virHashAddEntry() does not increment
- * the refcounter of @vm, but virHashRemoveEntry() does
- * decrement it. We need to work around it. */
- virObjectRef(vm);
-
- ret = 0;
- cleanup:
- virObjectUnlock(doms);
- return ret;
-}
-
-
-int
-virDomainObjListRenameRemove(virDomainObjListPtr doms, const char *name)
-{
- virObjectLock(doms);
- virHashRemoveEntry(doms->objsName, name);
- virObjectUnlock(doms);
- return 0;
-}
-
-
-/*
* Mark the running VM config as transient. Ensures transient hotplug
* operations do not persist past shutdown.
*
@@ -3177,48 +2880,6 @@ virDomainObjGetOneDef(virDomainObjPtr vm,
}
-/*
- * The caller must hold a lock on the driver owning 'doms',
- * and must also have locked 'dom', to ensure no one else
- * is either waiting for 'dom' or still using it
- */
-void virDomainObjListRemove(virDomainObjListPtr doms,
- virDomainObjPtr dom)
-{
- char uuidstr[VIR_UUID_STRING_BUFLEN];
-
- dom->removing = true;
- virUUIDFormat(dom->def->uuid, uuidstr);
- virObjectRef(dom);
- virObjectUnlock(dom);
-
- virObjectLock(doms);
- virObjectLock(dom);
- virHashRemoveEntry(doms->objs, uuidstr);
- virHashRemoveEntry(doms->objsName, dom->def->name);
- virObjectUnlock(dom);
- virObjectUnref(dom);
- virObjectUnlock(doms);
-}
-
-/* The caller must hold lock on 'doms' in addition to 'virDomainObjListRemove'
- * requirements
- *
- * Can be used to remove current element while iterating with
- * virDomainObjListForEach
- */
-void virDomainObjListRemoveLocked(virDomainObjListPtr doms,
- virDomainObjPtr dom)
-{
- char uuidstr[VIR_UUID_STRING_BUFLEN];
-
- virUUIDFormat(dom->def->uuid, uuidstr);
-
- virHashRemoveEntry(doms->objs, uuidstr);
- virHashRemoveEntry(doms->objsName, dom->def->name);
- virObjectUnlock(dom);
-}
-
static int
virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr)
{
@@ -22768,179 +22429,6 @@ virDomainSaveStatus(virDomainXMLOptionPtr xmlopt,
}
-static virDomainObjPtr
-virDomainObjListLoadConfig(virDomainObjListPtr doms,
- virCapsPtr caps,
- virDomainXMLOptionPtr xmlopt,
- const char *configDir,
- const char *autostartDir,
- const char *name,
- virDomainLoadConfigNotify notify,
- void *opaque)
-{
- char *configFile = NULL, *autostartLink = NULL;
- virDomainDefPtr def = NULL;
- virDomainObjPtr dom;
- int autostart;
- virDomainDefPtr oldDef = NULL;
-
- if ((configFile = virDomainConfigFile(configDir, name)) == NULL)
- goto error;
- if (!(def = virDomainDefParseFile(configFile, caps, xmlopt,
- VIR_DOMAIN_DEF_PARSE_INACTIVE |
- VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)))
- goto error;
-
- if ((autostartLink = virDomainConfigFile(autostartDir, name)) == NULL)
- goto error;
-
- if ((autostart = virFileLinkPointsTo(autostartLink, configFile)) < 0)
- goto error;
-
- if (!(dom = virDomainObjListAddLocked(doms, def, xmlopt, 0, &oldDef)))
- goto error;
-
- dom->autostart = autostart;
-
- if (notify)
- (*notify)(dom, oldDef == NULL, opaque);
-
- virDomainDefFree(oldDef);
- VIR_FREE(configFile);
- VIR_FREE(autostartLink);
- return dom;
-
- error:
- VIR_FREE(configFile);
- VIR_FREE(autostartLink);
- virDomainDefFree(def);
- return NULL;
-}
-
-static virDomainObjPtr
-virDomainObjListLoadStatus(virDomainObjListPtr doms,
- const char *statusDir,
- const char *name,
- virCapsPtr caps,
- virDomainXMLOptionPtr xmlopt,
- virDomainLoadConfigNotify notify,
- void *opaque)
-{
- char *statusFile = NULL;
- virDomainObjPtr obj = NULL;
- char uuidstr[VIR_UUID_STRING_BUFLEN];
-
- if ((statusFile = virDomainConfigFile(statusDir, name)) == NULL)
- goto error;
-
- if (!(obj = virDomainObjParseFile(statusFile, caps, xmlopt,
- VIR_DOMAIN_DEF_PARSE_STATUS |
- VIR_DOMAIN_DEF_PARSE_ACTUAL_NET |
- VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES |
- VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)))
- goto error;
-
- virUUIDFormat(obj->def->uuid, uuidstr);
-
- if (virHashLookup(doms->objs, uuidstr) != NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unexpected domain %s already exists"),
- obj->def->name);
- goto error;
- }
-
- if (virHashAddEntry(doms->objs, uuidstr, obj) < 0)
- goto error;
-
- if (virHashAddEntry(doms->objsName, obj->def->name, obj) < 0) {
- virHashRemoveEntry(doms->objs, uuidstr);
- goto error;
- }
-
- /* Since domain is in two hash tables, increment the
- * reference counter */
- virObjectRef(obj);
-
- if (notify)
- (*notify)(obj, 1, opaque);
-
- VIR_FREE(statusFile);
- return obj;
-
- error:
- virObjectUnref(obj);
- VIR_FREE(statusFile);
- return NULL;
-}
-
-int
-virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,
- const char *configDir,
- const char *autostartDir,
- int liveStatus,
- virCapsPtr caps,
- virDomainXMLOptionPtr xmlopt,
- virDomainLoadConfigNotify notify,
- void *opaque)
-{
- DIR *dir;
- struct dirent *entry;
- int ret = -1;
-
- VIR_INFO("Scanning for configs in %s", configDir);
-
- if (!(dir = opendir(configDir))) {
- if (errno == ENOENT)
- return 0;
- virReportSystemError(errno,
- _("Failed to open dir '%s'"),
- configDir);
- return -1;
- }
-
- virObjectLock(doms);
-
- while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
- virDomainObjPtr dom;
-
- if (entry->d_name[0] == '.')
- continue;
-
- if (!virFileStripSuffix(entry->d_name, ".xml"))
- continue;
-
- /* NB: ignoring errors, so one malformed config doesn't
- kill the whole process */
- VIR_INFO("Loading config file '%s.xml'", entry->d_name);
- if (liveStatus)
- dom = virDomainObjListLoadStatus(doms,
- configDir,
- entry->d_name,
- caps,
- xmlopt,
- notify,
- opaque);
- else
- dom = virDomainObjListLoadConfig(doms,
- caps,
- xmlopt,
- configDir,
- autostartDir,
- entry->d_name,
- notify,
- opaque);
- if (dom) {
- if (!liveStatus)
- dom->persistent = 1;
- virObjectUnlock(dom);
- }
- }
-
- closedir(dir);
- virObjectUnlock(doms);
- return ret;
-}
-
int
virDomainDeleteConfig(const char *configDir,
const char *autostartDir,
@@ -23057,178 +22545,6 @@ virDomainGetFilesystemForTarget(virDomainDefPtr def,
}
-struct virDomainObjListData {
- virDomainObjListACLFilter filter;
- virConnectPtr conn;
- bool active;
- int count;
-};
-
-static void
-virDomainObjListCount(void *payload,
- const void *name ATTRIBUTE_UNUSED,
- void *opaque)
-{
- virDomainObjPtr obj = payload;
- struct virDomainObjListData *data = opaque;
- virObjectLock(obj);
- if (data->filter &&
- !data->filter(data->conn, obj->def))
- goto cleanup;
- if (virDomainObjIsActive(obj)) {
- if (data->active)
- data->count++;
- } else {
- if (!data->active)
- data->count++;
- }
- cleanup:
- virObjectUnlock(obj);
-}
-
-int
-virDomainObjListNumOfDomains(virDomainObjListPtr doms,
- bool active,
- virDomainObjListACLFilter filter,
- virConnectPtr conn)
-{
- struct virDomainObjListData data = { filter, conn, active, 0 };
- virObjectLock(doms);
- virHashForEach(doms->objs, virDomainObjListCount, &data);
- virObjectUnlock(doms);
- return data.count;
-}
-
-struct virDomainIDData {
- virDomainObjListACLFilter filter;
- virConnectPtr conn;
- int numids;
- int maxids;
- int *ids;
-};
-
-static void
-virDomainObjListCopyActiveIDs(void *payload,
- const void *name ATTRIBUTE_UNUSED,
- void *opaque)
-{
- virDomainObjPtr obj = payload;
- struct virDomainIDData *data = opaque;
- virObjectLock(obj);
- if (data->filter &&
- !data->filter(data->conn, obj->def))
- goto cleanup;
- if (virDomainObjIsActive(obj) && data->numids < data->maxids)
- data->ids[data->numids++] = obj->def->id;
- cleanup:
- virObjectUnlock(obj);
-}
-
-int
-virDomainObjListGetActiveIDs(virDomainObjListPtr doms,
- int *ids,
- int maxids,
- virDomainObjListACLFilter filter,
- virConnectPtr conn)
-{
- struct virDomainIDData data = { filter, conn,
- 0, maxids, ids };
- virObjectLock(doms);
- virHashForEach(doms->objs, virDomainObjListCopyActiveIDs, &data);
- virObjectUnlock(doms);
- return data.numids;
-}
-
-struct virDomainNameData {
- virDomainObjListACLFilter filter;
- virConnectPtr conn;
- int oom;
- int numnames;
- int maxnames;
- char **const names;
-};
-
-static void
-virDomainObjListCopyInactiveNames(void *payload,
- const void *name ATTRIBUTE_UNUSED,
- void *opaque)
-{
- virDomainObjPtr obj = payload;
- struct virDomainNameData *data = opaque;
-
- if (data->oom)
- return;
-
- virObjectLock(obj);
- if (data->filter &&
- !data->filter(data->conn, obj->def))
- goto cleanup;
- if (!virDomainObjIsActive(obj) && data->numnames < data->maxnames) {
- if (VIR_STRDUP(data->names[data->numnames], obj->def->name) < 0)
- data->oom = 1;
- else
- data->numnames++;
- }
- cleanup:
- virObjectUnlock(obj);
-}
-
-
-int
-virDomainObjListGetInactiveNames(virDomainObjListPtr doms,
- char **const names,
- int maxnames,
- virDomainObjListACLFilter filter,
- virConnectPtr conn)
-{
- struct virDomainNameData data = { filter, conn,
- 0, 0, maxnames, names };
- size_t i;
- virObjectLock(doms);
- virHashForEach(doms->objs, virDomainObjListCopyInactiveNames, &data);
- virObjectUnlock(doms);
- if (data.oom) {
- for (i = 0; i < data.numnames; i++)
- VIR_FREE(data.names[i]);
- return -1;
- }
-
- return data.numnames;
-}
-
-
-struct virDomainListIterData {
- virDomainObjListIterator callback;
- void *opaque;
- int ret;
-};
-
-static void
-virDomainObjListHelper(void *payload,
- const void *name ATTRIBUTE_UNUSED,
- void *opaque)
-{
- struct virDomainListIterData *data = opaque;
-
- if (data->callback(payload, data->opaque) < 0)
- data->ret = -1;
-}
-
-int
-virDomainObjListForEach(virDomainObjListPtr doms,
- virDomainObjListIterator callback,
- void *opaque)
-{
- struct virDomainListIterData data = {
- callback, opaque, 0,
- };
- virObjectLock(doms);
- virHashForEach(doms->objs, virDomainObjListHelper, &data);
- virObjectUnlock(doms);
- return data.ret;
-}
-
-
int
virDomainChrDefForeach(virDomainDefPtr def,
bool abortOnError,
@@ -23943,258 +23259,6 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
}
-#define MATCH(FLAG) (filter & (FLAG))
-static bool
-virDomainObjMatchFilter(virDomainObjPtr vm,
- unsigned int filter)
-{
- /* filter by active state */
- if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) &&
- !((MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE) &&
- virDomainObjIsActive(vm)) ||
- (MATCH(VIR_CONNECT_LIST_DOMAINS_INACTIVE) &&
- !virDomainObjIsActive(vm))))
- return false;
-
- /* filter by persistence */
- if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT) &&
- !((MATCH(VIR_CONNECT_LIST_DOMAINS_PERSISTENT) &&
- vm->persistent) ||
- (MATCH(VIR_CONNECT_LIST_DOMAINS_TRANSIENT) &&
- !vm->persistent)))
- return false;
-
- /* filter by domain state */
- if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE)) {
- int st = virDomainObjGetState(vm, NULL);
- if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_RUNNING) &&
- st == VIR_DOMAIN_RUNNING) ||
- (MATCH(VIR_CONNECT_LIST_DOMAINS_PAUSED) &&
- st == VIR_DOMAIN_PAUSED) ||
- (MATCH(VIR_CONNECT_LIST_DOMAINS_SHUTOFF) &&
- st == VIR_DOMAIN_SHUTOFF) ||
- (MATCH(VIR_CONNECT_LIST_DOMAINS_OTHER) &&
- (st != VIR_DOMAIN_RUNNING &&
- st != VIR_DOMAIN_PAUSED &&
- st != VIR_DOMAIN_SHUTOFF))))
- return false;
- }
-
- /* filter by existence of managed save state */
- if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_MANAGEDSAVE) &&
- !((MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE) &&
- vm->hasManagedSave) ||
- (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE) &&
- !vm->hasManagedSave)))
- return false;
-
- /* filter by autostart option */
- if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_AUTOSTART) &&
- !((MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART) && vm->autostart) ||
- (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART) && !vm->autostart)))
- return false;
-
- /* filter by snapshot existence */
- if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT)) {
- int nsnap = virDomainSnapshotObjListNum(vm->snapshots, NULL, 0);
- if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) && nsnap > 0) ||
- (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT) && nsnap <= 0)))
- return false;
- }
-
- return true;
-}
-#undef MATCH
-
-
-struct virDomainListData {
- virDomainObjPtr *vms;
- size_t nvms;
-};
-
-
-static void
-virDomainObjListCollectIterator(void *payload,
- const void *name ATTRIBUTE_UNUSED,
- void *opaque)
-{
- struct virDomainListData *data = opaque;
-
- data->vms[data->nvms++] = virObjectRef(payload);
-}
-
-
-static void
-virDomainObjListFilter(virDomainObjPtr **list,
- size_t *nvms,
- virConnectPtr conn,
- virDomainObjListACLFilter filter,
- unsigned int flags)
-{
- size_t i = 0;
-
- while (i < *nvms) {
- virDomainObjPtr vm = (*list)[i];
-
- virObjectLock(vm);
-
- /* do not list the object if:
- * 1) it's being removed.
- * 2) connection does not have ACL to see it
- * 3) it doesn't match the filter
- */
- if (vm->removing ||
- (filter && !filter(conn, vm->def)) ||
- !virDomainObjMatchFilter(vm, flags)) {
- virObjectUnlock(vm);
- virObjectUnref(vm);
- VIR_DELETE_ELEMENT(*list, i, *nvms);
- continue;
- }
-
- virObjectUnlock(vm);
- i++;
- }
-}
-
-
-int
-virDomainObjListCollect(virDomainObjListPtr domlist,
- virConnectPtr conn,
- virDomainObjPtr **vms,
- size_t *nvms,
- virDomainObjListACLFilter filter,
- unsigned int flags)
-{
- struct virDomainListData data = { NULL, 0 };
- ssize_t hash_size;
-
- virObjectLock(domlist);
- if ((hash_size = virHashSize(domlist->objs)) < 0 ||
- (VIR_ALLOC_N(data.vms, hash_size) < 0)) {
- virObjectUnlock(domlist);
- return -1;
- }
-
- virHashForEach(domlist->objs, virDomainObjListCollectIterator, &data);
- virObjectUnlock(domlist);
-
- virDomainObjListFilter(&data.vms, &data.nvms, conn, filter, flags);
-
- *nvms = data.nvms;
- *vms = data.vms;
-
- return 0;
-}
-
-
-int
-virDomainObjListConvert(virDomainObjListPtr domlist,
- virConnectPtr conn,
- virDomainPtr *doms,
- size_t ndoms,
- virDomainObjPtr **vms,
- size_t *nvms,
- virDomainObjListACLFilter filter,
- unsigned int flags,
- bool skip_missing)
-{
- char uuidstr[VIR_UUID_STRING_BUFLEN];
- virDomainObjPtr vm;
- size_t i;
-
- *nvms = 0;
- *vms = NULL;
-
- virObjectLock(domlist);
- for (i = 0; i < ndoms; i++) {
- virDomainPtr dom = doms[i];
-
- virUUIDFormat(dom->uuid, uuidstr);
-
- if (!(vm = virHashLookup(domlist->objs, uuidstr))) {
- if (skip_missing)
- continue;
-
- virObjectUnlock(domlist);
- virReportError(VIR_ERR_NO_DOMAIN,
- _("no domain with matching uuid '%s' (%s)"),
- uuidstr, dom->name);
- goto error;
- }
-
- virObjectRef(vm);
-
- if (VIR_APPEND_ELEMENT(*vms, *nvms, vm) < 0) {
- virObjectUnlock(domlist);
- virObjectUnref(vm);
- goto error;
- }
- }
- virObjectUnlock(domlist);
-
- if (*vms)
- virDomainObjListFilter(vms, nvms, conn, filter, flags);
-
- return 0;
-
- error:
- virObjectListFreeCount(*vms, *nvms);
- *vms = NULL;
- *nvms = 0;
-
- return -1;
-}
-
-
-int
-virDomainObjListExport(virDomainObjListPtr domlist,
- virConnectPtr conn,
- virDomainPtr **domains,
- virDomainObjListACLFilter filter,
- unsigned int flags)
-{
- virDomainObjPtr *vms = NULL;
- virDomainPtr *doms = NULL;
- size_t nvms = 0;
- size_t i;
- int ret = -1;
-
- if (virDomainObjListCollect(domlist, conn, &vms, &nvms, filter, flags) < 0)
- return -1;
-
- if (domains) {
- if (VIR_ALLOC_N(doms, nvms + 1) < 0)
- goto cleanup;
-
- for (i = 0; i < nvms; i++) {
- virDomainObjPtr vm = vms[i];
-
- virObjectLock(vm);
-
- if (!(doms[i] = virGetDomain(conn, vm->def->name, vm->def->uuid))) {
- virObjectUnlock(vm);
- goto cleanup;
- }
-
- doms[i]->id = vm->def->id;
-
- virObjectUnlock(vm);
- }
-
- *domains = doms;
- doms = NULL;
- }
-
- ret = nvms;
-
- cleanup:
- virObjectListFree(doms);
- virObjectListFreeCount(vms, nvms);
- return ret;
-}
-
-
virSecurityLabelDefPtr
virDomainDefGetSecurityLabelDef(virDomainDefPtr def, const char *model)
{
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 8d43ee6..3d1d142 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2388,9 +2388,6 @@ struct _virDomainObj {
int taint;
};
-typedef struct _virDomainObjList virDomainObjList;
-typedef virDomainObjList *virDomainObjListPtr;
-
typedef bool (*virDomainObjListACLFilter)(virConnectPtr conn,
virDomainDefPtr def);
@@ -2472,17 +2469,6 @@ virDomainObjIsActive(virDomainObjPtr dom)
virDomainObjPtr virDomainObjNew(virDomainXMLOptionPtr caps)
ATTRIBUTE_NONNULL(1);
-virDomainObjListPtr virDomainObjListNew(void);
-
-virDomainObjPtr virDomainObjListFindByID(virDomainObjListPtr doms,
- int id);
-virDomainObjPtr virDomainObjListFindByUUID(virDomainObjListPtr doms,
- const unsigned char *uuid);
-virDomainObjPtr virDomainObjListFindByUUIDRef(virDomainObjListPtr doms,
- const unsigned char *uuid);
-virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
- const char *name);
-
void virDomainObjEndAPI(virDomainObjPtr *vm);
bool virDomainObjTaint(virDomainObjPtr obj,
@@ -2579,20 +2565,6 @@ virDomainDefPtr virDomainDefNewFull(const char *name,
const unsigned char *uuid,
int id);
-enum {
- VIR_DOMAIN_OBJ_LIST_ADD_LIVE = (1 << 0),
- VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE = (1 << 1),
-};
-virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms,
- virDomainDefPtr def,
- virDomainXMLOptionPtr xmlopt,
- unsigned int flags,
- virDomainDefPtr *oldDef);
-int virDomainObjListRenameAddNew(virDomainObjListPtr doms,
- virDomainObjPtr vm,
- const char *name);
-int virDomainObjListRenameRemove(virDomainObjListPtr doms,
- const char *name);
void virDomainObjAssignDef(virDomainObjPtr domain,
virDomainDefPtr def,
bool live,
@@ -2630,11 +2602,6 @@ virDomainDefPtr virDomainObjCopyPersistentDef(virDomainObjPtr dom,
virCapsPtr caps,
virDomainXMLOptionPtr xmlopt);
-void virDomainObjListRemove(virDomainObjListPtr doms,
- virDomainObjPtr dom);
-void virDomainObjListRemoveLocked(virDomainObjListPtr doms,
- virDomainObjPtr dom);
-
typedef enum {
/* parse internal domain status information */
VIR_DOMAIN_DEF_PARSE_STATUS = 1 << 0,
@@ -2905,15 +2872,6 @@ typedef void (*virDomainLoadConfigNotify)(virDomainObjPtr dom,
int newDomain,
void *opaque);
-int virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,
- const char *configDir,
- const char *autostartDir,
- int liveStatus,
- virCapsPtr caps,
- virDomainXMLOptionPtr xmlopt,
- virDomainLoadConfigNotify notify,
- void *opaque);
-
int virDomainDeleteConfig(const char *configDir,
const char *autostartDir,
virDomainObjPtr dom);
@@ -2935,29 +2893,6 @@ int virDomainVideoDefaultType(const virDomainDef *def);
unsigned int virDomainVideoDefaultRAM(const virDomainDef *def,
const virDomainVideoType type);
-int virDomainObjListNumOfDomains(virDomainObjListPtr doms,
- bool active,
- virDomainObjListACLFilter filter,
- virConnectPtr conn);
-
-int virDomainObjListGetActiveIDs(virDomainObjListPtr doms,
- int *ids,
- int maxids,
- virDomainObjListACLFilter filter,
- virConnectPtr conn);
-int virDomainObjListGetInactiveNames(virDomainObjListPtr doms,
- char **const names,
- int maxnames,
- virDomainObjListACLFilter filter,
- virConnectPtr conn);
-
-typedef int (*virDomainObjListIterator)(virDomainObjPtr dom,
- void *opaque);
-
-int virDomainObjListForEach(virDomainObjListPtr doms,
- virDomainObjListIterator callback,
- void *opaque);
-
typedef int (*virDomainSmartcardDefIterator)(virDomainDefPtr def,
virDomainSmartcardDefPtr dev,
void *opaque);
@@ -3113,61 +3048,6 @@ VIR_ENUM_DECL(virDomainCpuPlacementMode)
VIR_ENUM_DECL(virDomainStartupPolicy)
-# define VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE \
- (VIR_CONNECT_LIST_DOMAINS_ACTIVE | \
- VIR_CONNECT_LIST_DOMAINS_INACTIVE)
-
-# define VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT \
- (VIR_CONNECT_LIST_DOMAINS_PERSISTENT | \
- VIR_CONNECT_LIST_DOMAINS_TRANSIENT)
-
-# define VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE \
- (VIR_CONNECT_LIST_DOMAINS_RUNNING | \
- VIR_CONNECT_LIST_DOMAINS_PAUSED | \
- VIR_CONNECT_LIST_DOMAINS_SHUTOFF | \
- VIR_CONNECT_LIST_DOMAINS_OTHER)
-
-# define VIR_CONNECT_LIST_DOMAINS_FILTERS_MANAGEDSAVE \
- (VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE | \
- VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE)
-
-# define VIR_CONNECT_LIST_DOMAINS_FILTERS_AUTOSTART \
- (VIR_CONNECT_LIST_DOMAINS_AUTOSTART | \
- VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)
-
-# define VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT \
- (VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT | \
- VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT)
-
-# define VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL \
- (VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE | \
- VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT | \
- VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE | \
- VIR_CONNECT_LIST_DOMAINS_FILTERS_MANAGEDSAVE | \
- VIR_CONNECT_LIST_DOMAINS_FILTERS_AUTOSTART | \
- VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT)
-
-int virDomainObjListCollect(virDomainObjListPtr doms,
- virConnectPtr conn,
- virDomainObjPtr **vms,
- size_t *nvms,
- virDomainObjListACLFilter filter,
- unsigned int flags);
-int virDomainObjListExport(virDomainObjListPtr doms,
- virConnectPtr conn,
- virDomainPtr **domains,
- virDomainObjListACLFilter filter,
- unsigned int flags);
-int virDomainObjListConvert(virDomainObjListPtr domlist,
- virConnectPtr conn,
- virDomainPtr *doms,
- size_t ndoms,
- virDomainObjPtr **vms,
- size_t *nvms,
- virDomainObjListACLFilter filter,
- unsigned int flags,
- bool skip_missing);
-
int
virDomainDefMaybeAddController(virDomainDefPtr def,
int type,
diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h
index 6e68ecc..0211861 100644
--- a/src/conf/nwfilter_conf.h
+++ b/src/conf/nwfilter_conf.h
@@ -33,7 +33,7 @@
# include "virbuffer.h"
# include "virsocketaddr.h"
# include "virmacaddr.h"
-# include "domain_conf.h"
+# include "virdomainobjlist.h"
/* XXX
* The config parser/structs should not be using platform specific
diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
new file mode 100644
index 0000000..7568f93
--- /dev/null
+++ b/src/conf/virdomainobjlist.c
@@ -0,0 +1,999 @@
+/*
+ * virdomainobjlist.c: domain objects list utilities
+ *
+ * Copyright (C) 2006-2015 Red Hat, Inc.
+ * Copyright (C) 2006-2008 Daniel P. Berrange
+ * Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Daniel P. Berrange <berrange(a)redhat.com>
+ */
+
+#include <config.h>
+
+#include "internal.h"
+#include "datatypes.h"
+#include "virdomainobjlist.h"
+#include "snapshot_conf.h"
+#include "viralloc.h"
+#include "virfile.h"
+#include "virlog.h"
+#include "virstring.h"
+
+#define VIR_FROM_THIS VIR_FROM_DOMAIN
+
+VIR_LOG_INIT("conf.virdomainobjlist");
+
+static virClassPtr virDomainObjListClass;
+static void virDomainObjListDispose(void *obj);
+
+
+struct _virDomainObjList {
+ virObjectLockable parent;
+
+ /* uuid string -> virDomainObj mapping
+ * for O(1), lockless lookup-by-uuid */
+ virHashTable *objs;
+
+ /* name -> virDomainObj mapping for O(1),
+ * lockless lookup-by-name */
+ virHashTable *objsName;
+};
+
+
+static int virDomainObjListOnceInit(void)
+{
+ if (!(virDomainObjListClass = virClassNew(virClassForObjectLockable(),
+ "virDomainObjList",
+ sizeof(virDomainObjList),
+ virDomainObjListDispose)))
+ return -1;
+
+ return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virDomainObjList)
+
+virDomainObjListPtr virDomainObjListNew(void)
+{
+ virDomainObjListPtr doms;
+
+ if (virDomainObjListInitialize() < 0)
+ return NULL;
+
+ if (!(doms = virObjectLockableNew(virDomainObjListClass)))
+ return NULL;
+
+ if (!(doms->objs = virHashCreate(50, virObjectFreeHashData)) ||
+ !(doms->objsName = virHashCreate(50, virObjectFreeHashData))) {
+ virObjectUnref(doms);
+ return NULL;
+ }
+
+ return doms;
+}
+
+
+static void virDomainObjListDispose(void *obj)
+{
+ virDomainObjListPtr doms = obj;
+
+ virHashFree(doms->objs);
+ virHashFree(doms->objsName);
+}
+
+
+static int virDomainObjListSearchID(const void *payload,
+ const void *name ATTRIBUTE_UNUSED,
+ const void *data)
+{
+ virDomainObjPtr obj = (virDomainObjPtr)payload;
+ const int *id = data;
+ int want = 0;
+
+ virObjectLock(obj);
+ if (virDomainObjIsActive(obj) &&
+ obj->def->id == *id)
+ want = 1;
+ virObjectUnlock(obj);
+ return want;
+}
+
+
+virDomainObjPtr virDomainObjListFindByID(virDomainObjListPtr doms,
+ int id)
+{
+ virDomainObjPtr obj;
+ virObjectLock(doms);
+ obj = virHashSearch(doms->objs, virDomainObjListSearchID, &id);
+ if (obj) {
+ virObjectLock(obj);
+ if (obj->removing) {
+ virObjectUnlock(obj);
+ obj = NULL;
+ }
+ }
+ virObjectUnlock(doms);
+ return obj;
+}
+
+
+static virDomainObjPtr
+virDomainObjListFindByUUIDInternal(virDomainObjListPtr doms,
+ const unsigned char *uuid,
+ bool ref)
+{
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+ virDomainObjPtr obj;
+
+ virObjectLock(doms);
+ virUUIDFormat(uuid, uuidstr);
+
+ obj = virHashLookup(doms->objs, uuidstr);
+ if (ref) {
+ virObjectRef(obj);
+ virObjectUnlock(doms);
+ }
+ if (obj) {
+ virObjectLock(obj);
+ if (obj->removing) {
+ virObjectUnlock(obj);
+ if (ref)
+ virObjectUnref(obj);
+ obj = NULL;
+ }
+ }
+ if (!ref)
+ virObjectUnlock(doms);
+ return obj;
+}
+
+
+virDomainObjPtr
+virDomainObjListFindByUUID(virDomainObjListPtr doms,
+ const unsigned char *uuid)
+{
+ return virDomainObjListFindByUUIDInternal(doms, uuid, false);
+}
+
+
+virDomainObjPtr
+virDomainObjListFindByUUIDRef(virDomainObjListPtr doms,
+ const unsigned char *uuid)
+{
+ return virDomainObjListFindByUUIDInternal(doms, uuid, true);
+}
+
+
+virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
+ const char *name)
+{
+ virDomainObjPtr obj;
+
+ virObjectLock(doms);
+ obj = virHashLookup(doms->objsName, name);
+ virObjectRef(obj);
+ virObjectUnlock(doms);
+ if (obj) {
+ virObjectLock(obj);
+ if (obj->removing) {
+ virObjectUnlock(obj);
+ virObjectUnref(obj);
+ obj = NULL;
+ }
+ }
+ return obj;
+}
+
+
+/*
+ * virDomainObjListAddLocked:
+ *
+ * If flags & VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE then
+ * this will refuse updating an existing def if the
+ * current def is Live
+ *
+ * If flags & VIR_DOMAIN_OBJ_LIST_ADD_LIVE then
+ * the @def being added is assumed to represent a
+ * live config, not a future inactive config
+ *
+ */
+static virDomainObjPtr
+virDomainObjListAddLocked(virDomainObjListPtr doms,
+ virDomainDefPtr def,
+ virDomainXMLOptionPtr xmlopt,
+ unsigned int flags,
+ virDomainDefPtr *oldDef)
+{
+ virDomainObjPtr vm;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+ if (oldDef)
+ *oldDef = NULL;
+
+ virUUIDFormat(def->uuid, uuidstr);
+
+ /* See if a VM with matching UUID already exists */
+ if ((vm = virHashLookup(doms->objs, uuidstr))) {
+ virObjectLock(vm);
+ /* UUID matches, but if names don't match, refuse it */
+ if (STRNEQ(vm->def->name, def->name)) {
+ virUUIDFormat(vm->def->uuid, uuidstr);
+ virReportError(VIR_ERR_OPERATION_FAILED,
+ _("domain '%s' is already defined with uuid %s"),
+ vm->def->name, uuidstr);
+ goto error;
+ }
+
+ if (flags & VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE) {
+ /* UUID & name match, but if VM is already active, refuse it */
+ if (virDomainObjIsActive(vm)) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ _("domain '%s' is already active"),
+ vm->def->name);
+ goto error;
+ }
+ if (!vm->persistent) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ _("domain '%s' is already being started"),
+ vm->def->name);
+ goto error;
+ }
+ }
+
+ virDomainObjAssignDef(vm,
+ def,
+ !!(flags & VIR_DOMAIN_OBJ_LIST_ADD_LIVE),
+ oldDef);
+ } else {
+ /* UUID does not match, but if a name matches, refuse it */
+ if ((vm = virHashLookup(doms->objsName, def->name))) {
+ virObjectLock(vm);
+ virUUIDFormat(vm->def->uuid, uuidstr);
+ virReportError(VIR_ERR_OPERATION_FAILED,
+ _("domain '%s' already exists with uuid %s"),
+ def->name, uuidstr);
+ goto error;
+ }
+
+ if (!(vm = virDomainObjNew(xmlopt)))
+ goto cleanup;
+ vm->def = def;
+
+ virUUIDFormat(def->uuid, uuidstr);
+ if (virHashAddEntry(doms->objs, uuidstr, vm) < 0) {
+ virObjectUnref(vm);
+ return NULL;
+ }
+
+ if (virHashAddEntry(doms->objsName, def->name, vm) < 0) {
+ virHashRemoveEntry(doms->objs, uuidstr);
+ return NULL;
+ }
+
+ /* Since domain is in two hash tables, increment the
+ * reference counter */
+ virObjectRef(vm);
+ }
+ cleanup:
+ return vm;
+
+ error:
+ virObjectUnlock(vm);
+ vm = NULL;
+ goto cleanup;
+}
+
+
+virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms,
+ virDomainDefPtr def,
+ virDomainXMLOptionPtr xmlopt,
+ unsigned int flags,
+ virDomainDefPtr *oldDef)
+{
+ virDomainObjPtr ret;
+
+ virObjectLock(doms);
+ ret = virDomainObjListAddLocked(doms, def, xmlopt, flags, oldDef);
+ virObjectUnlock(doms);
+ return ret;
+}
+
+
+int
+virDomainObjListRenameAddNew(virDomainObjListPtr doms,
+ virDomainObjPtr vm,
+ const char *name)
+{
+ int ret = -1;
+ virObjectLock(doms);
+
+ /* Add new name into the hash table of domain names. */
+ if (virHashAddEntry(doms->objsName, name, vm) < 0)
+ goto cleanup;
+
+ /* Okay, this is crazy. virHashAddEntry() does not increment
+ * the refcounter of @vm, but virHashRemoveEntry() does
+ * decrement it. We need to work around it. */
+ virObjectRef(vm);
+
+ ret = 0;
+ cleanup:
+ virObjectUnlock(doms);
+ return ret;
+}
+
+
+int
+virDomainObjListRenameRemove(virDomainObjListPtr doms, const char *name)
+{
+ virObjectLock(doms);
+ virHashRemoveEntry(doms->objsName, name);
+ virObjectUnlock(doms);
+ return 0;
+}
+
+
+/*
+ * The caller must hold a lock on the driver owning 'doms',
+ * and must also have locked 'dom', to ensure no one else
+ * is either waiting for 'dom' or still using it
+ */
+void virDomainObjListRemove(virDomainObjListPtr doms,
+ virDomainObjPtr dom)
+{
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+ dom->removing = true;
+ virUUIDFormat(dom->def->uuid, uuidstr);
+ virObjectRef(dom);
+ virObjectUnlock(dom);
+
+ virObjectLock(doms);
+ virObjectLock(dom);
+ virHashRemoveEntry(doms->objs, uuidstr);
+ virHashRemoveEntry(doms->objsName, dom->def->name);
+ virObjectUnlock(dom);
+ virObjectUnref(dom);
+ virObjectUnlock(doms);
+}
+
+
+/* The caller must hold lock on 'doms' in addition to 'virDomainObjListRemove'
+ * requirements
+ *
+ * Can be used to remove current element while iterating with
+ * virDomainObjListForEach
+ */
+void virDomainObjListRemoveLocked(virDomainObjListPtr doms,
+ virDomainObjPtr dom)
+{
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+ virUUIDFormat(dom->def->uuid, uuidstr);
+
+ virHashRemoveEntry(doms->objs, uuidstr);
+ virHashRemoveEntry(doms->objsName, dom->def->name);
+ virObjectUnlock(dom);
+}
+
+
+static virDomainObjPtr
+virDomainObjListLoadConfig(virDomainObjListPtr doms,
+ virCapsPtr caps,
+ virDomainXMLOptionPtr xmlopt,
+ const char *configDir,
+ const char *autostartDir,
+ const char *name,
+ virDomainLoadConfigNotify notify,
+ void *opaque)
+{
+ char *configFile = NULL, *autostartLink = NULL;
+ virDomainDefPtr def = NULL;
+ virDomainObjPtr dom;
+ int autostart;
+ virDomainDefPtr oldDef = NULL;
+
+ if ((configFile = virDomainConfigFile(configDir, name)) == NULL)
+ goto error;
+ if (!(def = virDomainDefParseFile(configFile, caps, xmlopt,
+ VIR_DOMAIN_DEF_PARSE_INACTIVE |
+ VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)))
+ goto error;
+
+ if ((autostartLink = virDomainConfigFile(autostartDir, name)) == NULL)
+ goto error;
+
+ if ((autostart = virFileLinkPointsTo(autostartLink, configFile)) < 0)
+ goto error;
+
+ if (!(dom = virDomainObjListAddLocked(doms, def, xmlopt, 0, &oldDef)))
+ goto error;
+
+ dom->autostart = autostart;
+
+ if (notify)
+ (*notify)(dom, oldDef == NULL, opaque);
+
+ virDomainDefFree(oldDef);
+ VIR_FREE(configFile);
+ VIR_FREE(autostartLink);
+ return dom;
+
+ error:
+ VIR_FREE(configFile);
+ VIR_FREE(autostartLink);
+ virDomainDefFree(def);
+ return NULL;
+}
+
+
+static virDomainObjPtr
+virDomainObjListLoadStatus(virDomainObjListPtr doms,
+ const char *statusDir,
+ const char *name,
+ virCapsPtr caps,
+ virDomainXMLOptionPtr xmlopt,
+ virDomainLoadConfigNotify notify,
+ void *opaque)
+{
+ char *statusFile = NULL;
+ virDomainObjPtr obj = NULL;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+ if ((statusFile = virDomainConfigFile(statusDir, name)) == NULL)
+ goto error;
+
+ if (!(obj = virDomainObjParseFile(statusFile, caps, xmlopt,
+ VIR_DOMAIN_DEF_PARSE_STATUS |
+ VIR_DOMAIN_DEF_PARSE_ACTUAL_NET |
+ VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES |
+ VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)))
+ goto error;
+
+ virUUIDFormat(obj->def->uuid, uuidstr);
+
+ if (virHashLookup(doms->objs, uuidstr) != NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unexpected domain %s already exists"),
+ obj->def->name);
+ goto error;
+ }
+
+ if (virHashAddEntry(doms->objs, uuidstr, obj) < 0)
+ goto error;
+
+ if (virHashAddEntry(doms->objsName, obj->def->name, obj) < 0) {
+ virHashRemoveEntry(doms->objs, uuidstr);
+ goto error;
+ }
+
+ /* Since domain is in two hash tables, increment the
+ * reference counter */
+ virObjectRef(obj);
+
+ if (notify)
+ (*notify)(obj, 1, opaque);
+
+ VIR_FREE(statusFile);
+ return obj;
+
+ error:
+ virObjectUnref(obj);
+ VIR_FREE(statusFile);
+ return NULL;
+}
+
+
+int
+virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,
+ const char *configDir,
+ const char *autostartDir,
+ int liveStatus,
+ virCapsPtr caps,
+ virDomainXMLOptionPtr xmlopt,
+ virDomainLoadConfigNotify notify,
+ void *opaque)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int ret = -1;
+
+ VIR_INFO("Scanning for configs in %s", configDir);
+
+ if (!(dir = opendir(configDir))) {
+ if (errno == ENOENT)
+ return 0;
+ virReportSystemError(errno,
+ _("Failed to open dir '%s'"),
+ configDir);
+ return -1;
+ }
+
+ virObjectLock(doms);
+
+ while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
+ virDomainObjPtr dom;
+
+ if (entry->d_name[0] == '.')
+ continue;
+
+ if (!virFileStripSuffix(entry->d_name, ".xml"))
+ continue;
+
+ /* NB: ignoring errors, so one malformed config doesn't
+ kill the whole process */
+ VIR_INFO("Loading config file '%s.xml'", entry->d_name);
+ if (liveStatus)
+ dom = virDomainObjListLoadStatus(doms,
+ configDir,
+ entry->d_name,
+ caps,
+ xmlopt,
+ notify,
+ opaque);
+ else
+ dom = virDomainObjListLoadConfig(doms,
+ caps,
+ xmlopt,
+ configDir,
+ autostartDir,
+ entry->d_name,
+ notify,
+ opaque);
+ if (dom) {
+ if (!liveStatus)
+ dom->persistent = 1;
+ virObjectUnlock(dom);
+ }
+ }
+
+ closedir(dir);
+ virObjectUnlock(doms);
+ return ret;
+}
+
+
+struct virDomainObjListData {
+ virDomainObjListACLFilter filter;
+ virConnectPtr conn;
+ bool active;
+ int count;
+};
+
+
+static void
+virDomainObjListCount(void *payload,
+ const void *name ATTRIBUTE_UNUSED,
+ void *opaque)
+{
+ virDomainObjPtr obj = payload;
+ struct virDomainObjListData *data = opaque;
+ virObjectLock(obj);
+ if (data->filter &&
+ !data->filter(data->conn, obj->def))
+ goto cleanup;
+ if (virDomainObjIsActive(obj)) {
+ if (data->active)
+ data->count++;
+ } else {
+ if (!data->active)
+ data->count++;
+ }
+ cleanup:
+ virObjectUnlock(obj);
+}
+
+
+int
+virDomainObjListNumOfDomains(virDomainObjListPtr doms,
+ bool active,
+ virDomainObjListACLFilter filter,
+ virConnectPtr conn)
+{
+ struct virDomainObjListData data = { filter, conn, active, 0 };
+ virObjectLock(doms);
+ virHashForEach(doms->objs, virDomainObjListCount, &data);
+ virObjectUnlock(doms);
+ return data.count;
+}
+
+
+struct virDomainIDData {
+ virDomainObjListACLFilter filter;
+ virConnectPtr conn;
+ int numids;
+ int maxids;
+ int *ids;
+};
+
+
+static void
+virDomainObjListCopyActiveIDs(void *payload,
+ const void *name ATTRIBUTE_UNUSED,
+ void *opaque)
+{
+ virDomainObjPtr obj = payload;
+ struct virDomainIDData *data = opaque;
+ virObjectLock(obj);
+ if (data->filter &&
+ !data->filter(data->conn, obj->def))
+ goto cleanup;
+ if (virDomainObjIsActive(obj) && data->numids < data->maxids)
+ data->ids[data->numids++] = obj->def->id;
+ cleanup:
+ virObjectUnlock(obj);
+}
+
+
+int
+virDomainObjListGetActiveIDs(virDomainObjListPtr doms,
+ int *ids,
+ int maxids,
+ virDomainObjListACLFilter filter,
+ virConnectPtr conn)
+{
+ struct virDomainIDData data = { filter, conn,
+ 0, maxids, ids };
+ virObjectLock(doms);
+ virHashForEach(doms->objs, virDomainObjListCopyActiveIDs, &data);
+ virObjectUnlock(doms);
+ return data.numids;
+}
+
+
+struct virDomainNameData {
+ virDomainObjListACLFilter filter;
+ virConnectPtr conn;
+ int oom;
+ int numnames;
+ int maxnames;
+ char **const names;
+};
+
+
+static void
+virDomainObjListCopyInactiveNames(void *payload,
+ const void *name ATTRIBUTE_UNUSED,
+ void *opaque)
+{
+ virDomainObjPtr obj = payload;
+ struct virDomainNameData *data = opaque;
+
+ if (data->oom)
+ return;
+
+ virObjectLock(obj);
+ if (data->filter &&
+ !data->filter(data->conn, obj->def))
+ goto cleanup;
+ if (!virDomainObjIsActive(obj) && data->numnames < data->maxnames) {
+ if (VIR_STRDUP(data->names[data->numnames], obj->def->name) < 0)
+ data->oom = 1;
+ else
+ data->numnames++;
+ }
+ cleanup:
+ virObjectUnlock(obj);
+}
+
+
+int
+virDomainObjListGetInactiveNames(virDomainObjListPtr doms,
+ char **const names,
+ int maxnames,
+ virDomainObjListACLFilter filter,
+ virConnectPtr conn)
+{
+ struct virDomainNameData data = { filter, conn,
+ 0, 0, maxnames, names };
+ size_t i;
+ virObjectLock(doms);
+ virHashForEach(doms->objs, virDomainObjListCopyInactiveNames, &data);
+ virObjectUnlock(doms);
+ if (data.oom) {
+ for (i = 0; i < data.numnames; i++)
+ VIR_FREE(data.names[i]);
+ return -1;
+ }
+
+ return data.numnames;
+}
+
+
+struct virDomainListIterData {
+ virDomainObjListIterator callback;
+ void *opaque;
+ int ret;
+};
+
+
+static void
+virDomainObjListHelper(void *payload,
+ const void *name ATTRIBUTE_UNUSED,
+ void *opaque)
+{
+ struct virDomainListIterData *data = opaque;
+
+ if (data->callback(payload, data->opaque) < 0)
+ data->ret = -1;
+}
+
+
+int
+virDomainObjListForEach(virDomainObjListPtr doms,
+ virDomainObjListIterator callback,
+ void *opaque)
+{
+ struct virDomainListIterData data = {
+ callback, opaque, 0,
+ };
+ virObjectLock(doms);
+ virHashForEach(doms->objs, virDomainObjListHelper, &data);
+ virObjectUnlock(doms);
+ return data.ret;
+}
+
+
+#define MATCH(FLAG) (filter & (FLAG))
+static bool
+virDomainObjMatchFilter(virDomainObjPtr vm,
+ unsigned int filter)
+{
+ /* filter by active state */
+ if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) &&
+ !((MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE) &&
+ virDomainObjIsActive(vm)) ||
+ (MATCH(VIR_CONNECT_LIST_DOMAINS_INACTIVE) &&
+ !virDomainObjIsActive(vm))))
+ return false;
+
+ /* filter by persistence */
+ if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT) &&
+ !((MATCH(VIR_CONNECT_LIST_DOMAINS_PERSISTENT) &&
+ vm->persistent) ||
+ (MATCH(VIR_CONNECT_LIST_DOMAINS_TRANSIENT) &&
+ !vm->persistent)))
+ return false;
+
+ /* filter by domain state */
+ if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE)) {
+ int st = virDomainObjGetState(vm, NULL);
+ if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_RUNNING) &&
+ st == VIR_DOMAIN_RUNNING) ||
+ (MATCH(VIR_CONNECT_LIST_DOMAINS_PAUSED) &&
+ st == VIR_DOMAIN_PAUSED) ||
+ (MATCH(VIR_CONNECT_LIST_DOMAINS_SHUTOFF) &&
+ st == VIR_DOMAIN_SHUTOFF) ||
+ (MATCH(VIR_CONNECT_LIST_DOMAINS_OTHER) &&
+ (st != VIR_DOMAIN_RUNNING &&
+ st != VIR_DOMAIN_PAUSED &&
+ st != VIR_DOMAIN_SHUTOFF))))
+ return false;
+ }
+
+ /* filter by existence of managed save state */
+ if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_MANAGEDSAVE) &&
+ !((MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE) &&
+ vm->hasManagedSave) ||
+ (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE) &&
+ !vm->hasManagedSave)))
+ return false;
+
+ /* filter by autostart option */
+ if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_AUTOSTART) &&
+ !((MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART) && vm->autostart) ||
+ (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART) && !vm->autostart)))
+ return false;
+
+ /* filter by snapshot existence */
+ if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT)) {
+ int nsnap = virDomainSnapshotObjListNum(vm->snapshots, NULL, 0);
+ if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) && nsnap > 0) ||
+ (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT) && nsnap <= 0)))
+ return false;
+ }
+
+ return true;
+}
+#undef MATCH
+
+
+struct virDomainListData {
+ virDomainObjPtr *vms;
+ size_t nvms;
+};
+
+
+static void
+virDomainObjListCollectIterator(void *payload,
+ const void *name ATTRIBUTE_UNUSED,
+ void *opaque)
+{
+ struct virDomainListData *data = opaque;
+
+ data->vms[data->nvms++] = virObjectRef(payload);
+}
+
+
+static void
+virDomainObjListFilter(virDomainObjPtr **list,
+ size_t *nvms,
+ virConnectPtr conn,
+ virDomainObjListACLFilter filter,
+ unsigned int flags)
+{
+ size_t i = 0;
+
+ while (i < *nvms) {
+ virDomainObjPtr vm = (*list)[i];
+
+ virObjectLock(vm);
+
+ /* do not list the object if:
+ * 1) it's being removed.
+ * 2) connection does not have ACL to see it
+ * 3) it doesn't match the filter
+ */
+ if (vm->removing ||
+ (filter && !filter(conn, vm->def)) ||
+ !virDomainObjMatchFilter(vm, flags)) {
+ virObjectUnlock(vm);
+ virObjectUnref(vm);
+ VIR_DELETE_ELEMENT(*list, i, *nvms);
+ continue;
+ }
+
+ virObjectUnlock(vm);
+ i++;
+ }
+}
+
+
+int
+virDomainObjListCollect(virDomainObjListPtr domlist,
+ virConnectPtr conn,
+ virDomainObjPtr **vms,
+ size_t *nvms,
+ virDomainObjListACLFilter filter,
+ unsigned int flags)
+{
+ struct virDomainListData data = { NULL, 0 };
+
+ virObjectLock(domlist);
+ sa_assert(domlist->objs);
+ if (VIR_ALLOC_N(data.vms, virHashSize(domlist->objs)) < 0) {
+ virObjectUnlock(domlist);
+ return -1;
+ }
+
+ virHashForEach(domlist->objs, virDomainObjListCollectIterator, &data);
+ virObjectUnlock(domlist);
+
+ virDomainObjListFilter(&data.vms, &data.nvms, conn, filter, flags);
+
+ *nvms = data.nvms;
+ *vms = data.vms;
+
+ return 0;
+}
+
+
+int
+virDomainObjListConvert(virDomainObjListPtr domlist,
+ virConnectPtr conn,
+ virDomainPtr *doms,
+ size_t ndoms,
+ virDomainObjPtr **vms,
+ size_t *nvms,
+ virDomainObjListACLFilter filter,
+ unsigned int flags,
+ bool skip_missing)
+{
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+ virDomainObjPtr vm;
+ size_t i;
+
+ *nvms = 0;
+ *vms = NULL;
+
+ virObjectLock(domlist);
+ for (i = 0; i < ndoms; i++) {
+ virDomainPtr dom = doms[i];
+
+ virUUIDFormat(dom->uuid, uuidstr);
+
+ if (!(vm = virHashLookup(domlist->objs, uuidstr))) {
+ if (skip_missing)
+ continue;
+
+ virObjectUnlock(domlist);
+ virReportError(VIR_ERR_NO_DOMAIN,
+ _("no domain with matching uuid '%s' (%s)"),
+ uuidstr, dom->name);
+ goto error;
+ }
+
+ virObjectRef(vm);
+
+ if (VIR_APPEND_ELEMENT(*vms, *nvms, vm) < 0) {
+ virObjectUnlock(domlist);
+ virObjectUnref(vm);
+ goto error;
+ }
+ }
+ virObjectUnlock(domlist);
+
+ sa_assert(*vms);
+ virDomainObjListFilter(vms, nvms, conn, filter, flags);
+
+ return 0;
+
+ error:
+ virObjectListFreeCount(*vms, *nvms);
+ *vms = NULL;
+ *nvms = 0;
+
+ return -1;
+}
+
+
+int
+virDomainObjListExport(virDomainObjListPtr domlist,
+ virConnectPtr conn,
+ virDomainPtr **domains,
+ virDomainObjListACLFilter filter,
+ unsigned int flags)
+{
+ virDomainObjPtr *vms = NULL;
+ virDomainPtr *doms = NULL;
+ size_t nvms = 0;
+ size_t i;
+ int ret = -1;
+
+ if (virDomainObjListCollect(domlist, conn, &vms, &nvms, filter, flags) < 0)
+ return -1;
+
+ if (domains) {
+ if (VIR_ALLOC_N(doms, nvms + 1) < 0)
+ goto cleanup;
+
+ for (i = 0; i < nvms; i++) {
+ virDomainObjPtr vm = vms[i];
+
+ virObjectLock(vm);
+
+ if (!(doms[i] = virGetDomain(conn, vm->def->name, vm->def->uuid))) {
+ virObjectUnlock(vm);
+ goto cleanup;
+ }
+
+ doms[i]->id = vm->def->id;
+
+ virObjectUnlock(vm);
+ }
+
+ *domains = doms;
+ doms = NULL;
+ }
+
+ ret = nvms;
+
+ cleanup:
+ virObjectListFree(doms);
+ virObjectListFreeCount(vms, nvms);
+ return ret;
+}
diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h
new file mode 100644
index 0000000..f479598
--- /dev/null
+++ b/src/conf/virdomainobjlist.h
@@ -0,0 +1,151 @@
+/*
+ * virdomainobjlist.h: domain objects list utilities
+ *
+ * Copyright (C) 2006-2015 Red Hat, Inc.
+ * Copyright (C) 2006-2008 Daniel P. Berrange
+ * Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Daniel P. Berrange <berrange(a)redhat.com>
+ */
+
+#ifndef __VIRDOMAINOBJLIST_H__
+# define __VIRDOMAINOBJLIST_H__
+
+# include "domain_conf.h"
+
+typedef struct _virDomainObjList virDomainObjList;
+typedef virDomainObjList *virDomainObjListPtr;
+
+virDomainObjListPtr virDomainObjListNew(void);
+
+virDomainObjPtr virDomainObjListFindByID(virDomainObjListPtr doms,
+ int id);
+virDomainObjPtr virDomainObjListFindByUUID(virDomainObjListPtr doms,
+ const unsigned char *uuid);
+virDomainObjPtr virDomainObjListFindByUUIDRef(virDomainObjListPtr doms,
+ const unsigned char *uuid);
+virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
+ const char *name);
+
+enum {
+ VIR_DOMAIN_OBJ_LIST_ADD_LIVE = (1 << 0),
+ VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE = (1 << 1),
+};
+virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms,
+ virDomainDefPtr def,
+ virDomainXMLOptionPtr xmlopt,
+ unsigned int flags,
+ virDomainDefPtr *oldDef);
+
+int virDomainObjListRenameAddNew(virDomainObjListPtr doms,
+ virDomainObjPtr vm,
+ const char *name);
+int virDomainObjListRenameRemove(virDomainObjListPtr doms,
+ const char *name);
+void virDomainObjListRemove(virDomainObjListPtr doms,
+ virDomainObjPtr dom);
+void virDomainObjListRemoveLocked(virDomainObjListPtr doms,
+ virDomainObjPtr dom);
+
+int virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,
+ const char *configDir,
+ const char *autostartDir,
+ int liveStatus,
+ virCapsPtr caps,
+ virDomainXMLOptionPtr xmlopt,
+ virDomainLoadConfigNotify notify,
+ void *opaque);
+
+int virDomainObjListNumOfDomains(virDomainObjListPtr doms,
+ bool active,
+ virDomainObjListACLFilter filter,
+ virConnectPtr conn);
+
+int virDomainObjListGetActiveIDs(virDomainObjListPtr doms,
+ int *ids,
+ int maxids,
+ virDomainObjListACLFilter filter,
+ virConnectPtr conn);
+int virDomainObjListGetInactiveNames(virDomainObjListPtr doms,
+ char **const names,
+ int maxnames,
+ virDomainObjListACLFilter filter,
+ virConnectPtr conn);
+
+typedef int (*virDomainObjListIterator)(virDomainObjPtr dom,
+ void *opaque);
+
+int virDomainObjListForEach(virDomainObjListPtr doms,
+ virDomainObjListIterator callback,
+ void *opaque);
+
+# define VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE \
+ (VIR_CONNECT_LIST_DOMAINS_ACTIVE | \
+ VIR_CONNECT_LIST_DOMAINS_INACTIVE)
+
+# define VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT \
+ (VIR_CONNECT_LIST_DOMAINS_PERSISTENT | \
+ VIR_CONNECT_LIST_DOMAINS_TRANSIENT)
+
+# define VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE \
+ (VIR_CONNECT_LIST_DOMAINS_RUNNING | \
+ VIR_CONNECT_LIST_DOMAINS_PAUSED | \
+ VIR_CONNECT_LIST_DOMAINS_SHUTOFF | \
+ VIR_CONNECT_LIST_DOMAINS_OTHER)
+
+# define VIR_CONNECT_LIST_DOMAINS_FILTERS_MANAGEDSAVE \
+ (VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE | \
+ VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE)
+
+# define VIR_CONNECT_LIST_DOMAINS_FILTERS_AUTOSTART \
+ (VIR_CONNECT_LIST_DOMAINS_AUTOSTART | \
+ VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)
+
+# define VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT \
+ (VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT | \
+ VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT)
+
+# define VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL \
+ (VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE | \
+ VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT | \
+ VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE | \
+ VIR_CONNECT_LIST_DOMAINS_FILTERS_MANAGEDSAVE | \
+ VIR_CONNECT_LIST_DOMAINS_FILTERS_AUTOSTART | \
+ VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT)
+
+int virDomainObjListCollect(virDomainObjListPtr doms,
+ virConnectPtr conn,
+ virDomainObjPtr **vms,
+ size_t *nvms,
+ virDomainObjListACLFilter filter,
+ unsigned int flags);
+int virDomainObjListExport(virDomainObjListPtr doms,
+ virConnectPtr conn,
+ virDomainPtr **domains,
+ virDomainObjListACLFilter filter,
+ unsigned int flags);
+int virDomainObjListConvert(virDomainObjListPtr domlist,
+ virConnectPtr conn,
+ virDomainPtr *doms,
+ size_t ndoms,
+ virDomainObjPtr **vms,
+ size_t *nvms,
+ virDomainObjListACLFilter filter,
+ unsigned int flags,
+ bool skip_missing);
+
+#endif /* __VIRDOMAINOBJLIST_H__ */
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 5944947..ebf23be 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -24,7 +24,7 @@
#include <config.h>
#include "internal.h"
-#include "domain_conf.h"
+#include "virdomainobjlist.h"
#include "snapshot_conf.h"
#include "virauth.h"
#include "viralloc.h"
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 1958bbe..083e62a 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -24,7 +24,7 @@
#include "internal.h"
#include "datatypes.h"
-#include "domain_conf.h"
+#include "virdomainobjlist.h"
#include "virauth.h"
#include "viralloc.h"
#include "virlog.h"
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7e60d87..5f2006b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -396,24 +396,6 @@ virDomainObjGetMetadata;
virDomainObjGetOneDef;
virDomainObjGetPersistentDef;
virDomainObjGetState;
-virDomainObjListAdd;
-virDomainObjListCollect;
-virDomainObjListConvert;
-virDomainObjListExport;
-virDomainObjListFindByID;
-virDomainObjListFindByName;
-virDomainObjListFindByUUID;
-virDomainObjListFindByUUIDRef;
-virDomainObjListForEach;
-virDomainObjListGetActiveIDs;
-virDomainObjListGetInactiveNames;
-virDomainObjListLoadAllConfigs;
-virDomainObjListNew;
-virDomainObjListNumOfDomains;
-virDomainObjListRemove;
-virDomainObjListRemoveLocked;
-virDomainObjListRenameAddNew;
-virDomainObjListRenameRemove;
virDomainObjNew;
virDomainObjParseNode;
virDomainObjSetDefTransient;
@@ -885,6 +867,27 @@ virChrdevFree;
virChrdevOpen;
+# conf/virdomainobjlist.h
+virDomainObjListAdd;
+virDomainObjListCollect;
+virDomainObjListConvert;
+virDomainObjListExport;
+virDomainObjListFindByID;
+virDomainObjListFindByName;
+virDomainObjListFindByUUID;
+virDomainObjListFindByUUIDRef;
+virDomainObjListForEach;
+virDomainObjListGetActiveIDs;
+virDomainObjListGetInactiveNames;
+virDomainObjListLoadAllConfigs;
+virDomainObjListNew;
+virDomainObjListNumOfDomains;
+virDomainObjListRemove;
+virDomainObjListRemoveLocked;
+virDomainObjListRenameAddNew;
+virDomainObjListRenameRemove;
+
+
# cpu/cpu.h
cpuBaseline;
cpuBaselineXML;
diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h
index 9c29b1e..7c68b2b 100644
--- a/src/libxl/libxl_conf.h
+++ b/src/libxl/libxl_conf.h
@@ -30,7 +30,7 @@
# include "internal.h"
# include "libvirt_internal.h"
-# include "domain_conf.h"
+# include "virdomainobjlist.h"
# include "domain_event.h"
# include "capabilities.h"
# include "configmake.h"
diff --git a/src/openvz/openvz_conf.h b/src/openvz/openvz_conf.h
index a5c5806..fc36740 100644
--- a/src/openvz/openvz_conf.h
+++ b/src/openvz/openvz_conf.h
@@ -30,7 +30,7 @@
# define OPENVZ_CONF_H
# include "internal.h"
-# include "domain_conf.h"
+# include "virdomainobjlist.h"
# include "virthread.h"
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 9ccd567..3b27396 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -60,6 +60,7 @@
#include "cpu/cpu.h"
#include "virauth.h"
#include "viratomic.h"
+#include "virdomainobjlist.h"
#define VIR_FROM_THIS VIR_FROM_TEST
diff --git a/src/uml/uml_conf.h b/src/uml/uml_conf.h
index 05e19ff..9a45d10 100644
--- a/src/uml/uml_conf.h
+++ b/src/uml/uml_conf.h
@@ -28,7 +28,7 @@
# include "libvirt_internal.h"
# include "capabilities.h"
# include "network_conf.h"
-# include "domain_conf.h"
+# include "virdomainobjlist.h"
# include "domain_event.h"
# include "virerror.h"
# include "virthread.h"
diff --git a/src/util/virclosecallbacks.h b/src/util/virclosecallbacks.h
index e6b8a9e..4df0a00 100644
--- a/src/util/virclosecallbacks.h
+++ b/src/util/virclosecallbacks.h
@@ -25,7 +25,7 @@
#ifndef __VIR_CLOSE_CALLBACKS__
# define __VIR_CLOSE_CALLBACKS__
-# include "domain_conf.h"
+# include "virdomainobjlist.h"
typedef struct _virCloseCallbacks virCloseCallbacks;
typedef virCloseCallbacks *virCloseCallbacksPtr;
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 3e6ed7a..5ed6d93 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -25,7 +25,7 @@
#include "internal.h"
#include "datatypes.h"
-#include "domain_conf.h"
+#include "virdomainobjlist.h"
#include "domain_event.h"
#include "virlog.h"
#include "viralloc.h"
diff --git a/src/vmware/vmware_conf.h b/src/vmware/vmware_conf.h
index 1f3c41a..b3f8cdf 100644
--- a/src/vmware/vmware_conf.h
+++ b/src/vmware/vmware_conf.h
@@ -26,7 +26,7 @@
# define NOGUI "nogui"
# include "internal.h"
-# include "domain_conf.h"
+# include "virdomainobjlist.h"
# include "virthread.h"
# define VIR_FROM_THIS VIR_FROM_VMWARE
diff --git a/src/vz/vz_utils.h b/src/vz/vz_utils.h
index 84cf08f..b7a4c81 100644
--- a/src/vz/vz_utils.h
+++ b/src/vz/vz_utils.h
@@ -27,6 +27,7 @@
# include "driver.h"
# include "conf/domain_conf.h"
+# include "conf/virdomainobjlist.h"
# include "conf/domain_event.h"
# include "virthread.h"
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index d4e500b..abc18e5 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -32,7 +32,7 @@
#include <libxml/xmlsave.h>
#include "internal.h"
-#include "conf/domain_conf.h"
+#include "conf/virdomainobjlist.h"
#include "intprops.h"
#include "viralloc.h"
#include "virmacaddr.h"
--
2.4.10
9 years
[libvirt] [PATCH v3 00/11] Introduce virt-admin client
by Erik Skultety
v1:
1/9 - ACKed if adjusted
6/9 - ACKed
8/9 - ACKed if squashed into 4/9 --> resolves 7/9
v2:
- double empty line in private.syms is preserved (1/9)
- adjusted authors of virt-admin modules (2/9)
- removed unnecessary includes from virt-admin module (2/9)
- replaced "int" disconnected type for type "bool" (2/9)
- dropped unused command groups (2/9)
- removed unnecessary flags and adminControl struct element (2/9)
- introduction of virAdmConnectIsAlive split separately (3/9)
- remote version of admin API moved into a separate module (4/9)
- updated admin_protocol-structs (8/9)
- removed debugging leftovers from gendispatch.pl (8/9)
- properly indented if-else conditions in gendispatch.pl (8/9)
- removed unrelated paragraph, domain references, unsupported
options from virt-admin.pod and command 'connect' is now
(hopefully correctly) documented (9/9)
- introduction of vshAdmCatchDisconnect and introduction of close
callbacks had to be squashed together due to dependencies both
ways <-- review 4/9 pointed out dummy NULL close callback which
should be replaced by something relevant
since v2:
1/9 - ACKed if virGetLibvirtConfigFile is renamed
3/9 - ACKed, 'disconnected' removed, replaced by virAdmConnectIsAlive
4/9 - ACKed, admin_remote.c include moved up
5/9 - ACKed
v3:
- adjusted formatting issues (missing/extra whitespaces, missaligned
tabs)
- fixed dual assignment in virAdmConnectOpen
- cleaned some of the 'bogus' in vshAdmShowVersion
- fixed the logic in getSocketPath
- fixed coverity issues
- virt-admin -h behaves the same as --help
- virGetEnvBlockSUID replaced by virGetEnvAllowSUID
- changed the prefix for default admin URI
- close callback disposal now takes NULL for all relevant arguments
- Makefile: simplified man page pattern rule
- Makefile: fixed virt-admin recipes
- Man: reworded or deleted suggested parts
- proposed URI aliases support
Erik Skultety (11):
libvirt: Export libvirt config getters by moving them to util
virt-admin: Introduce first working skeleton
admin: Introduce virAdmConnectIsAlive
admin: Move remote admin API version to a separate module
admin: Do not generate remoteAdminConnect{Open,Close}
admin: Add URI support and introduce virAdmGetDefaultURI
livirt: Move URI alias matching to util
admin: Add support for URI aliases
admin: Add support for connection close callbacks
admin: Introduce virAdmConnectGetLibVersion
virt-admin: Provide a man page for virt-admin
.gitignore | 1 +
cfg.mk | 2 +-
daemon/admin_server.c | 9 +
include/libvirt/libvirt-admin.h | 27 ++
po/POTFILES.in | 2 +
src/admin/admin_protocol.x | 15 +-
src/admin/admin_remote.c | 216 ++++++++++++
src/admin_protocol-structs | 4 +
src/datatypes.c | 26 ++
src/datatypes.h | 17 +-
src/libvirt-admin.c | 423 ++++++++++++++++--------
src/libvirt.c | 133 +-------
src/libvirt.conf | 7 +-
src/libvirt_admin_private.syms | 1 +
src/libvirt_admin_public.syms | 5 +
src/libvirt_private.syms | 2 +
src/rpc/gendispatch.pl | 11 +-
src/util/virconf.c | 52 +++
src/util/virconf.h | 1 +
src/util/viruri.c | 92 ++++++
src/util/viruri.h | 2 +
tools/Makefile.am | 38 ++-
tools/virt-admin.c | 712 ++++++++++++++++++++++++++++++++++++++++
tools/virt-admin.h | 46 +++
tools/virt-admin.pod | 255 ++++++++++++++
25 files changed, 1801 insertions(+), 298 deletions(-)
create mode 100644 src/admin/admin_remote.c
create mode 100644 tools/virt-admin.c
create mode 100644 tools/virt-admin.h
create mode 100644 tools/virt-admin.pod
--
2.4.3
9 years
[libvirt] libvirt-php 0.5.1 broken build on RHEL-7
by Remi Collet
RHEL 7 have libvirt 1.2.8 which is the minimum version according to
configure check
LIBVIRT_REQUIRED=1.2.8
libvirt-php.c: In function 'zm_startup_libvirt':
libvirt-php.c:1351:136: error:
'VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES' undeclared (first use in
this function)
REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES",
VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES, CONST_CS | CONST_PERSISTENT);
Remi
9 years
[libvirt] libvirt external snapshot error
by Vasiliy Tolstov
Hi, i'm using
virsh -c qemu+ssh://test.node/system snapshot-create-as 40083
--no-metadata --disk-only --live –atomic --diskspec sda,file=/test
outputs:
error: Operation not supported: live snapshot creation is supported
only with external checkpoints
info:
Compiled against library: libvirt 1.2.16
Using library: libvirt 1.2.16
Using API: QEMU 1.2.16
Running hypervisor: QEMU 2.4.1
Does it supported on never libvirt? How can i solve the issue? I'm use
raw format for disk.
--
Vasiliy Tolstov,
e-mail: v.tolstov(a)selfip.ru
9 years
[libvirt] [PATCH] virlogd: fix crash if log file exists and it's larger the maxlen
by Pavel Hrdina
If for some reason there is an existing log file, that is larger then
max length of log file, we need to rollover that file immediately.
Trying to figure out how much data we could write will resolve in
overflow of unsigned variable 'towrite' and this leads to segfault.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/util/virrotatingfile.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/util/virrotatingfile.c b/src/util/virrotatingfile.c
index 1260710..827b44b 100644
--- a/src/util/virrotatingfile.c
+++ b/src/util/virrotatingfile.c
@@ -443,7 +443,12 @@ virRotatingFileWriterAppend(virRotatingFileWriterPtr file,
size_t towrite = len;
bool forceRollover = false;
- if ((file->entry->pos + towrite) > file->maxlen) {
+ if (file->entry->pos > file->maxlen) {
+ /* If existing file is for some reason larger then max length we
+ * won't write to this file anymore, but we rollover this file.*/
+ forceRollover = true;
+ towrite = 0;
+ } else if ((file->entry->pos + towrite) > file->maxlen) {
towrite = file->maxlen - file->entry->pos;
/*
--
2.6.3
9 years