Devel
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- 25 participants
- 40350 discussions
Signed-off-by: Cao jin <caoj.fnst(a)cn.fujitsu.com>
---
src/qemu/qemu_monitor.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 4f30b15..15ba39b 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -838,7 +838,6 @@ qemuMonitorOpenInternal(virDomainObjPtr vm,
if (!(mon = virObjectLockableNew(qemuMonitorClass)))
return NULL;
- mon->fd = -1;
mon->logfd = -1;
if (virCondInit(&mon->notify) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
--
2.1.0
1
1
Hi All
I am trying to get up to speed with developing with libvirt. Can anyone provide some good examples in C of how to gather statistics from domains, network and storage?
The dev guide just has TBD for these items....
Kind regards
Kevin Walker
2
1
Our atomic increment (virAtomicIntInc) uses (if available) gcc
__sync_add_and_fetch builtin. In qemu driver though, we'd profit more
from __sync_fetch_and_add builtin. To keep it simplistic, this patch
adjusts qemu driver initialization rather than adding a new atomic
increment macro.
---
src/qemu/qemu_conf.c | 2 +-
src/qemu/qemu_conf.h | 2 +-
src/qemu/qemu_driver.c | 7 ++-----
3 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 38d4a86..29049dc 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1492,7 +1492,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
int qemuDriverAllocateID(virQEMUDriverPtr driver)
{
- return virAtomicIntInc(&driver->nextvmid);
+ return virAtomicIntInc(&driver->lastvmid);
}
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 3f73929..ed9cd46 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -192,7 +192,7 @@ struct _virQEMUDriver {
virThreadPoolPtr workerPool;
/* Atomic increment only */
- int nextvmid;
+ int lastvmid;
/* Atomic inc/dec only */
unsigned int nactive;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a761448..055f0ca 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -612,7 +612,7 @@ qemuDomainFindMaxID(virDomainObjPtr vm,
int *driver_maxid = data;
if (vm->def->id >= *driver_maxid)
- *driver_maxid = vm->def->id + 1;
+ *driver_maxid = vm->def->id;
return 0;
}
@@ -649,9 +649,6 @@ qemuStateInitialize(bool privileged,
qemu_driver->inhibitCallback = callback;
qemu_driver->inhibitOpaque = opaque;
- /* Don't have a dom0 so start from 1 */
- qemu_driver->nextvmid = 1;
-
qemu_driver->privileged = privileged;
if (!(qemu_driver->domains = virDomainObjListNew()))
@@ -909,7 +906,7 @@ qemuStateInitialize(bool privileged,
* threads */
virDomainObjListForEach(qemu_driver->domains,
qemuDomainFindMaxID,
- &qemu_driver->nextvmid);
+ &qemu_driver->lastvmid);
virDomainObjListForEach(qemu_driver->domains,
qemuDomainNetsRestart,
--
2.4.3
2
2
[libvirt] [PATCH] lxc: Don't accidentaly reset autostart flag in virLXCProcessCleanup
by Peter Krempa 28 Jul '15
by Peter Krempa 28 Jul '15
28 Jul '15
virDomainDeleteConfig is meant to delete the persistent config and thus
it resets vm->autostart. Copy parts of qemuProcessRemoveDomainStatus to
a new helper to avoid using the incorrect function.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1230071
---
src/lxc/lxc_process.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 87ee484..e99b039 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -137,6 +137,23 @@ virLXCProcessReboot(virLXCDriverPtr driver,
}
+static void
+lxcProcessRemoveDomainStatus(virLXCDriverConfigPtr cfg,
+ virDomainObjPtr vm)
+{
+ char ebuf[1024];
+ char *file = NULL;
+
+ if (virAsprintf(&file, "%s/%s.xml", cfg->stateDir, vm->def->name) < 0)
+ return;
+
+ if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
+ VIR_WARN("Failed to remove domain XML for %s: %s",
+ vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
+ VIR_FREE(file);
+}
+
+
/**
* virLXCProcessCleanup:
* @driver: pointer to driver structure
@@ -180,7 +197,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
}
virPidFileDelete(cfg->stateDir, vm->def->name);
- virDomainDeleteConfig(cfg->stateDir, NULL, vm);
+ lxcProcessRemoveDomainStatus(cfg, vm);
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, reason);
vm->pid = -1;
--
2.4.5
2
2
28 Jul '15
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>
---
BTW: this is the first patch of my attempt to merge
virDomainObjList and virNetworkObjList together into one
virObjectList as the code is pretty much duplicated between the
two.
I know the patch is rather big, but this all needs to be done in
a single commit if we want to remain compile-able after each
commit.
po/POTFILES.in | 1 +
src/Makefile.am | 3 +-
src/conf/domain_conf.c | 901 ----------------------------------------
src/conf/domain_conf.h | 115 ------
src/conf/nwfilter_conf.h | 2 +-
src/conf/virdomainobjlist.c | 966 +++++++++++++++++++++++++++++++++++++++++++
src/conf/virdomainobjlist.h | 146 +++++++
src/esx/esx_driver.c | 2 +-
src/hyperv/hyperv_driver.c | 2 +-
src/libvirt_private.syms | 35 +-
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 | 2 +-
tools/virsh-domain-monitor.c | 2 +-
19 files changed, 1146 insertions(+), 1044 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 a75f5ae..ea89347 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 be63e26..4d888ff 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 5a9a88d..bd599f7 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 {
@@ -804,10 +790,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)
@@ -818,12 +802,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),
@@ -1173,134 +1151,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)
{
@@ -2705,118 +2555,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;
-}
-
-/*
* Mark the running VM config as transient. Ensures transient hotplug
* operations do not persist past shutdown.
*
@@ -3037,48 +2775,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)
{
@@ -22296,180 +21992,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_CLOCK_ADJUST |
- 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,
@@ -22586,178 +22108,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,
@@ -23472,257 +22822,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 };
-
- 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;
-}
-
-
virSecurityLabelDefPtr
virDomainDefGetSecurityLabelDef(virDomainDefPtr def, const char *model)
{
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 50750c1..df63a4e 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2345,9 +2345,6 @@ struct _virDomainObj {
int taint;
};
-typedef struct _virDomainObjList virDomainObjList;
-typedef virDomainObjList *virDomainObjListPtr;
-
typedef bool (*virDomainObjListACLFilter)(virConnectPtr conn,
virDomainDefPtr def);
@@ -2427,17 +2424,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,
@@ -2534,15 +2520,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);
void virDomainObjAssignDef(virDomainObjPtr domain,
virDomainDefPtr def,
bool live,
@@ -2580,11 +2557,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,
@@ -2847,15 +2819,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);
@@ -2877,29 +2840,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);
@@ -3054,61 +2994,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..f1b548d
--- /dev/null
+++ b/src/conf/virdomainobjlist.c
@@ -0,0 +1,966 @@
+/*
+ * 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;
+}
+
+
+/*
+ * 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_CLOCK_ADJUST |
+ 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..bcff88a
--- /dev/null
+++ b/src/conf/virdomainobjlist.h
@@ -0,0 +1,146 @@
+/*
+ * 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);
+
+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 c304ff3..3105563 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 b539541..e3bd49f 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 eb7ec76..7f85721 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -391,22 +391,6 @@ virDomainObjGetMetadata;
virDomainObjGetOneDef;
virDomainObjGetPersistentDef;
virDomainObjGetState;
-virDomainObjListAdd;
-virDomainObjListCollect;
-virDomainObjListConvert;
-virDomainObjListExport;
-virDomainObjListFindByID;
-virDomainObjListFindByName;
-virDomainObjListFindByUUID;
-virDomainObjListFindByUUIDRef;
-virDomainObjListForEach;
-virDomainObjListGetActiveIDs;
-virDomainObjListGetInactiveNames;
-virDomainObjListLoadAllConfigs;
-virDomainObjListNew;
-virDomainObjListNumOfDomains;
-virDomainObjListRemove;
-virDomainObjListRemoveLocked;
virDomainObjNew;
virDomainObjParseNode;
virDomainObjSetDefTransient;
@@ -876,6 +860,25 @@ virChrdevFree;
virChrdevOpen;
+# conf/virdomainobjlist.h
+virDomainObjListAdd;
+virDomainObjListCollect;
+virDomainObjListConvert;
+virDomainObjListExport;
+virDomainObjListFindByID;
+virDomainObjListFindByName;
+virDomainObjListFindByUUID;
+virDomainObjListFindByUUIDRef;
+virDomainObjListForEach;
+virDomainObjListGetActiveIDs;
+virDomainObjListGetInactiveNames;
+virDomainObjListLoadAllConfigs;
+virDomainObjListNew;
+virDomainObjListNumOfDomains;
+virDomainObjListRemove;
+virDomainObjListRemoveLocked;
+
+
# 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 d38006f..ac3ff5b 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 91a61f8..7383f41 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 db09647..d35616a 100644
--- a/src/vz/vz_utils.h
+++ b/src/vz/vz_utils.h
@@ -26,7 +26,7 @@
# include <Parallels.h>
# include "driver.h"
-# include "conf/domain_conf.h"
+# include "conf/virdomainobjlist.h"
# include "conf/storage_conf.h"
# include "conf/domain_event.h"
# include "conf/network_conf.h"
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 1d4dc25..86092e5 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.5
2
1
[libvirt] [PATCH v7] autocreate tap device for VIR_DOMAIN_NET_TYPE_ETHERNET
by Vasiliy Tolstov 28 Jul '15
by Vasiliy Tolstov 28 Jul '15
28 Jul '15
If a user specify ehernet device create it via libvirt and run
script if it provided. After this commit user does not need to
run external script to create tap device or add root to qemu
process.
Signed-off-by: Vasiliy Tolstov <v.tolstov(a)selfip.ru>
---
src/qemu/qemu_command.c | 143 +++++++++++++++++++++++++++++++-----------------
src/qemu/qemu_hotplug.c | 13 ++---
src/qemu/qemu_process.c | 6 ++
3 files changed, 102 insertions(+), 60 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3886b4f..c4d1fde 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -332,10 +332,39 @@ static int qemuCreateInBridgePortWithHelper(virQEMUDriverConfigPtr cfg,
return *tapfd < 0 ? -1 : 0;
}
+/**
+ * qemuExecuteEthernetScript:
+ * @ifname: the interface name
+ * @script: the script name
+ *
+ * This function executes script for new tap device created by libvirt.
+ * Returns 0 in case of success or -1 on failure
+ */
+static int
+qemuExecuteEthernetScript(const char *ifname, const char *script)
+{
+ virCommandPtr cmd;
+ int ret;
+
+ cmd = virCommandNew(script);
+ virCommandAddArgFormat(cmd, "%s", ifname);
+ virCommandClearCaps(cmd);
+#ifdef CAP_NET_ADMIN
+ virCommandAllowCap(cmd, CAP_NET_ADMIN);
+#endif
+ virCommandAddEnvPassCommon(cmd);
+
+ ret = virCommandRun(cmd, NULL);
+
+ virCommandFree(cmd);
+ return ret;
+}
+
/* qemuNetworkIfaceConnect - *only* called if actualType is
- * VIR_DOMAIN_NET_TYPE_NETWORK or VIR_DOMAIN_NET_TYPE_BRIDGE (i.e. if
- * the connection is made with a tap device connecting to a bridge
- * device)
+ * VIR_DOMAIN_NET_TYPE_NETWORK, VIR_DOMAIN_NET_TYPE_BRIDGE
+ * VIR_DOMAIN_NET_TYPE_ETHERNET (i.e. if the connection is
+ * made with a tap device connecting to a bridge device or
+ * use plain tap device)
*/
int
qemuNetworkIfaceConnect(virDomainDefPtr def,
@@ -351,6 +380,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
bool template_ifname = false;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
const char *tunpath = "/dev/net/tun";
+ virMacAddr tapmac;
if (net->backend.tap) {
tunpath = net->backend.tap;
@@ -361,11 +391,6 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
}
}
- if (!(brname = virDomainNetGetActualBridgeName(net))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing bridge name"));
- goto cleanup;
- }
-
if (!net->ifname ||
STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) ||
strchr(net->ifname, '%')) {
@@ -381,40 +406,66 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
}
- if (cfg->privileged) {
- if (virNetDevTapCreateInBridgePort(brname, &net->ifname, &net->mac,
- def->uuid, tunpath, tapfd, *tapfdSize,
- virDomainNetGetActualVirtPortProfile(net),
- virDomainNetGetActualVlan(net),
- tap_create_flags) < 0) {
+ if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_ETHERNET) {
+ if (virNetDevTapCreate(&net->ifname, tunpath, tapfd, *tapfdSize,
+ tap_create_flags) < 0) {
virDomainAuditNetDevice(def, net, tunpath, false);
goto cleanup;
}
- if (virDomainNetGetActualBridgeMACTableManager(net)
- == VIR_NETWORK_BRIDGE_MAC_TABLE_MANAGER_LIBVIRT) {
- /* libvirt is managing the FDB of the bridge this device
- * is attaching to, so we need to turn off learning and
- * unicast_flood on the device to prevent the kernel from
- * adding any FDB entries for it. We will add add an fdb
- * entry ourselves (during qemuInterfaceStartDevices(),
- * using the MAC address from the interface config.
- */
- if (virNetDevBridgePortSetLearning(brname, net->ifname, false) < 0)
- goto cleanup;
- if (virNetDevBridgePortSetUnicastFlood(brname, net->ifname, false) < 0)
+ virMacAddrSet(&tapmac, &net->mac);
+ tapmac.addr[0] = 0xFE;
+
+ if (virNetDevSetMAC(net->ifname, &tapmac) < 0)
+ goto cleanup;
+
+ if (virNetDevSetOnline(net->ifname, true) < 0)
+ goto cleanup;
+
+ if (net->script) {
+ if (qemuExecuteEthernetScript(net->ifname, net->script) < 0)
goto cleanup;
}
} else {
- if (qemuCreateInBridgePortWithHelper(cfg, brname,
- &net->ifname,
- tapfd, tap_create_flags) < 0) {
- virDomainAuditNetDevice(def, net, tunpath, false);
+ if (!(brname = virDomainNetGetActualBridgeName(net))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing bridge name"));
goto cleanup;
}
- /* qemuCreateInBridgePortWithHelper can only create a single FD */
- if (*tapfdSize > 1) {
- VIR_WARN("Ignoring multiqueue network request");
- *tapfdSize = 1;
+
+ if (cfg->privileged) {
+ if (virNetDevTapCreateInBridgePort(brname, &net->ifname, &net->mac,
+ def->uuid, tunpath, tapfd, *tapfdSize,
+ virDomainNetGetActualVirtPortProfile(net),
+ virDomainNetGetActualVlan(net),
+ tap_create_flags) < 0) {
+ virDomainAuditNetDevice(def, net, tunpath, false);
+ goto cleanup;
+ }
+ if (virDomainNetGetActualBridgeMACTableManager(net)
+ == VIR_NETWORK_BRIDGE_MAC_TABLE_MANAGER_LIBVIRT) {
+ /* libvirt is managing the FDB of the bridge this device
+ * is attaching to, so we need to turn off learning and
+ * unicast_flood on the device to prevent the kernel from
+ * adding any FDB entries for it. We will add add an fdb
+ * entry ourselves (during qemuInterfaceStartDevices(),
+ * using the MAC address from the interface config.
+ */
+ if (virNetDevBridgePortSetLearning(brname, net->ifname, false) < 0)
+ goto cleanup;
+ if (virNetDevBridgePortSetUnicastFlood(brname, net->ifname, false) < 0)
+ goto cleanup;
+ }
+ } else {
+ if (qemuCreateInBridgePortWithHelper(cfg, brname,
+ &net->ifname,
+ tapfd, tap_create_flags) < 0) {
+ virDomainAuditNetDevice(def, net, tunpath, false);
+ goto cleanup;
+ }
+ /* qemuCreateInBridgePortWithHelper can only create a single FD */
+ if (*tapfdSize > 1) {
+ VIR_WARN("Ignoring multiqueue network request");
+ *tapfdSize = 1;
+ }
}
}
@@ -5221,6 +5272,7 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
case VIR_DOMAIN_NET_TYPE_BRIDGE:
case VIR_DOMAIN_NET_TYPE_NETWORK:
case VIR_DOMAIN_NET_TYPE_DIRECT:
+ case VIR_DOMAIN_NET_TYPE_ETHERNET:
virBufferAsprintf(&buf, "tap%c", type_sep);
/* for one tapfd 'fd=' shall be used,
* for more than one 'fds=' is the right choice */
@@ -5238,20 +5290,6 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
is_tap = true;
break;
- case VIR_DOMAIN_NET_TYPE_ETHERNET:
- virBufferAddLit(&buf, "tap");
- if (net->ifname) {
- virBufferAsprintf(&buf, "%cifname=%s", type_sep, net->ifname);
- type_sep = ',';
- }
- if (net->script) {
- virBufferAsprintf(&buf, "%cscript=%s", type_sep,
- net->script);
- type_sep = ',';
- }
- is_tap = true;
- break;
-
case VIR_DOMAIN_NET_TYPE_CLIENT:
virBufferAsprintf(&buf, "socket%cconnect=%s:%d",
type_sep,
@@ -8226,7 +8264,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
/* Currently nothing besides TAP devices supports multiqueue. */
if (net->driver.virtio.queues > 0 &&
!(actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
- actualType == VIR_DOMAIN_NET_TYPE_BRIDGE)) {
+ actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
+ actualType == VIR_DOMAIN_NET_TYPE_ETHERNET)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Multiqueue network is not supported for: %s"),
virDomainNetTypeToString(actualType));
@@ -8235,7 +8274,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
if (net->backend.tap &&
!(actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
- actualType == VIR_DOMAIN_NET_TYPE_BRIDGE)) {
+ actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
+ actualType == VIR_DOMAIN_NET_TYPE_ETHERNET)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Custom tap device path is not supported for: %s"),
virDomainNetTypeToString(actualType));
@@ -8245,7 +8285,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
cfg = virQEMUDriverGetConfig(driver);
if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
- actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
+ actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
+ actualType == VIR_DOMAIN_NET_TYPE_ETHERNET) {
tapfdSize = net->driver.virtio.queues;
if (!tapfdSize)
tapfdSize = 1;
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index cc86a3b..21ea3fd 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -908,7 +908,8 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
/* Currently nothing besides TAP devices supports multiqueue. */
if (net->driver.virtio.queues > 0 &&
!(actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
- actualType == VIR_DOMAIN_NET_TYPE_BRIDGE)) {
+ actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
+ actualType == VIR_DOMAIN_NET_TYPE_ETHERNET)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Multiqueue network is not supported for: %s"),
virDomainNetTypeToString(actualType));
@@ -916,7 +917,8 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
}
if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
- actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
+ actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
+ actualType == VIR_DOMAIN_NET_TYPE_ETHERNET) {
tapfdSize = vhostfdSize = net->driver.virtio.queues;
if (!tapfdSize)
tapfdSize = vhostfdSize = 1;
@@ -947,13 +949,6 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
iface_connected = true;
if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, vhostfd, &vhostfdSize) < 0)
goto cleanup;
- } else if (actualType == VIR_DOMAIN_NET_TYPE_ETHERNET) {
- vhostfdSize = 1;
- if (VIR_ALLOC(vhostfd) < 0)
- goto cleanup;
- *vhostfd = -1;
- if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, vhostfd, &vhostfdSize) < 0)
- goto cleanup;
}
/* Set device online immediately */
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 64ee049..d866e44 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5205,6 +5205,12 @@ void qemuProcessStop(virQEMUDriverPtr driver,
cfg->stateDir));
VIR_FREE(net->ifname);
break;
+ case VIR_DOMAIN_NET_TYPE_ETHERNET:
+ if (net->ifname) {
+ ignore_value(virNetDevTapDelete(net->ifname, net->backend.tap));
+ VIR_FREE(net->ifname);
+ }
+ break;
case VIR_DOMAIN_NET_TYPE_BRIDGE:
case VIR_DOMAIN_NET_TYPE_NETWORK:
#ifdef VIR_NETDEV_TAP_REQUIRE_MANUAL_CLEANUP
--
2.3.3
2
3
[libvirt] [libvirt-test-API][PATCH 0/2] Add a new case for storagePoolLookupByVolume API
by jiahu 28 Jul '15
by jiahu 28 Jul '15
28 Jul '15
This API will be tested in dir/logicl/netfs pool type.
jiahu (2):
Add pool_lookup_by_volume.py to conf
Add new case to test storagePoolLookupByVolume
cases/storage_dir.conf | 6 +++++
cases/storage_logical.conf | 6 +++++
cases/storage_netfs.conf | 6 +++++
repos/storage/pool_lookup_by_volume.py | 46 ++++++++++++++++++++++++++++++++++
4 files changed, 64 insertions(+)
create mode 100644 repos/storage/pool_lookup_by_volume.py
--
1.8.1.4
2
3
Dear All,
I continue my work on the tunnelled selective block disks migration and the
next step is to implement Tunnelled NBD block disk migration.
As far as I see libvirt uses the following algorithm for tunnelling the
QEMU migration stream that is unidirectional:
1. The qemuMigrationStartTunnel (src/qemu/qemu_migration.c) starts a thread
that reads the data from the local QEMU pipe and writes it to the virStream
using virStreamSend.
2. The stream used by virStreamSend is embedded in the remote protocol
messaging by the remoteDomainMigratePrepareTunnel3{,Params}
(src/remote/remote_driver.c).
3. Remote links the daemonStream with the virFDStream connected to the
write end of a pipe linked with the QEMU.
4. Overall stream path is then: QEMU -(pipe)> virStreamSend -> (message
passing to the remote) -> TCP -> (message received by deamon/*.c code) ->
virStreamSend -> virFDStreamWrite -(pipe)> QEMU.
Given that I wonder what should be the changes required to implement a
bidirectional QEMU tunnelled connection for the NBD device disk migration.
The way I see implementation details at the moment:
0. The `virStream` and corresponding `daemon/*.c` must be modified in a way
that multiple streams can be multiplexed through the only one remote
connection.
1. `Pipe`s used to interconnect to the QEMU on the both sides are obviously
to be replaced by the UNIX sockets since the pipes cannot support
bidirectional output due to the design. This is to be made *one for each*
block device, requiring the above change.
2. The `qemuMigrationIOFunc` must be rewritten in such a way it polls for
both read and write on the UNIX sockets *and* VM migration pipe and
tunnells these to the appropriate `virStream`.
3. The receiving code must be modified in such a way to tunnel each of the
opened UNIX socket to the according virFDStream.
Of the mentioned above the most intriguing for me is the zero-th item which
will require some changes to the binary remote messaging protocol.
Is my vision on the problem is correct? Are there any other difficulties
I'm going to face but not aware of due to the lack of the familiarity with
the code?
Pavel
2
3
[libvirt] [PATCH] docs: set more permissive patterns for paths in rng schemas
by Dmitry Guryanov 27 Jul '15
by Dmitry Guryanov 27 Jul '15
27 Jul '15
There is no obvious reason to limit paths, used in
libvirt to a subset of what is allowed in linux. So
let's allow any symbols in paths.
---
docs/schemas/basictypes.rng | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng
index a83063a..12cab6a 100644
--- a/docs/schemas/basictypes.rng
+++ b/docs/schemas/basictypes.rng
@@ -230,25 +230,25 @@
<define name="filePath">
<data type="string">
- <param name="pattern">[a-zA-Z0-9_\.\+\-\\&"'<>/%]+</param>
+ <param name="pattern">.+</param>
</data>
</define>
<define name="dirPath">
<data type="string">
- <param name="pattern">[a-zA-Z0-9_\.\+\-\\&"'<>/%]+</param>
+ <param name="pattern">.+</param>
</data>
</define>
<define name="absFilePath">
<data type="string">
- <param name="pattern">/[a-zA-Z0-9_\.\+\-\\&"'<>/%,:]+</param>
+ <param name="pattern">/.+</param>
</data>
</define>
<define name="absDirPath">
<data type="string">
- <param name="pattern">/[a-zA-Z0-9_\.\+\-\\&"'<>/%]*</param>
+ <param name="pattern">/.*</param>
</data>
</define>
--
2.4.3
2
1
[libvirt] PING: [PATCH v5 0/4] qemu: Allow PCI virtio on ARM "virt" machine
by Pavel Fedin 27 Jul '15
by Pavel Fedin 27 Jul '15
27 Jul '15
PING
Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia
> -----Original Message-----
> From: libvir-list-bounces(a)redhat.com [mailto:libvir-list-bounces@redhat.com] On Behalf Of Pavel
Fedin
> Sent: Friday, July 17, 2015 2:28 PM
> To: libvir-list(a)redhat.com
> Cc: Peter Krempa
> Subject: [libvirt] [PATCH v5 0/4] qemu: Allow PCI virtio on ARM "virt" machine
>
> Virt machine in qemu since v2.3.0 has PCI generic host controller, and
> can use PCI devices. This provides performance improvement as well as
> vhost-net with irqfd support for virtio-net. However libvirt currently
> does not allow ARM virt machine to have PCI devices. This patchset adds
> the necessary support.
>
> Changes since v4:
> - Rebased onto current master
> - Added possibility to plug virtio-net-pci adapter directly into PCIe bus.
> This is necessary for irqfds to work in qemu.
> Changes since v3:
> - Capability is based not on qemu version but on support of "gpex-pcihost"
> device by qemu
> - Added a workaround, allowing to pass "make check". The problem is that
> test suite does not build capabilities cache. Unfortunately this means
> that correct unit-test for the new functionality currently cannot be
> written. Test suite framework needs to be improved.
> Changes since v2:
> Complete rework, use different approach
> - Correctly model PCI Express bus on the machine. It is now possible to
> explicitly specify <address-type='pci'> with attributes. This allows to
> attach not only virtio, but any other PCI device to the model.
> - Default is not changed and still mmio, for backwards compatibility with
> existing installations. PCI bus has to be explicitly specified.
> - Check for the capability in correct place, in v2 it actually did not
> work
> Changes since v1:
> - Added capability based on qemu version number
> - Recognize also "virt-" prefix
>
> Pavel Fedin (4):
> qemu: Introduce QEMU_CAPS_OBJECT_GPEX
> Add PCI-Express root to ARM virt machine
> Build correct command line for PCI NICs on ARM
> Allow to plug virtio-net-pci into PCIe slot
>
> src/qemu/qemu_capabilities.c | 10 ++++++++++
> src/qemu/qemu_capabilities.h | 1 +
> src/qemu/qemu_command.c | 11 ++++++++++-
> src/qemu/qemu_domain.c | 17 +++++++++++++----
> 4 files changed, 34 insertions(+), 5 deletions(-)
>
> --
> 1.9.5.msysgit.0
>
> --
> libvir-list mailing list
> libvir-list(a)redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
1
0