2006-06-06 03:32:51 +00:00
|
|
|
/*
|
2014-03-07 13:38:51 +00:00
|
|
|
* test_driver.c: A "mock" hypervisor for use by application unit tests
|
2006-06-06 03:32:51 +00:00
|
|
|
*
|
test: Avoid use-after-free on virDomainSnapshotDelete
The following virsh command was triggering a use-after-free:
$ virsh -c test:///default '
snapshot-create-as test s1
snapshot-create-as test s2
snapshot-delete --children-only test s1
snapshot-current --name test'
Domain snapshot s1 created
Domain snapshot s2 created
Domain snapshot s1 children deleted
error: name in virGetDomainSnapshot must not be NULL
I got lucky on that run - although the error message is quite
unexpected. On other runs, I was able to get a core dump, and
valgrind confirms there is a definitive problem.
The culprit? We were inconsistent about whether we set
vm->current_snapshot, snap->def->current, or both when updating how
the current snapshot was being tracked. As a result, deletion did not
see that snapshot s2 was previously current, and failed to update
vm->current_snapshot, so that the next API using the current snapshot
failed because it referenced stale memory for the now-gone s2 (instead
of the intended s1).
The test driver code was copied from the qemu code (which DOES track
both pieces of state everywhere), but was purposefully simplified
because the test driver does not have to write persistent snapshot
state to the file system. But when you realize that the only reason
snap->def->current needs to exist is when writing out one file per
snapshot for qemu, it's just as easy to state that the test driver
never has to mess with the field (rather than chasing down which
places forgot to set the field), and have vm->current_snapshot be the
sole source of truth in the test driver.
Ideally, I'd get rid of the 'current' member in virDomainSnapshotDef,
as well as the 'current_snapshot' member in virDomainDef, and instead
track the current member in virDomainSnapshotObjList, coupled with
writing ALL snapshot state for qemu in a single file (where I can use
<snapshots current='...'> as a wrapper, rather than
VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL to output <current>1</current> XML
on a per-snapshot file basis). But that's a bigger change, so for now
I'm just patching things to avoid the test driver segfault.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-03-17 03:57:45 +00:00
|
|
|
* Copyright (C) 2006-2019 Red Hat, Inc.
|
2007-01-18 21:08:21 +00:00
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
2006-06-06 03:32:51 +00:00
|
|
|
*
|
2007-01-18 21:08:21 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2006-06-06 03:32:51 +00:00
|
|
|
*/
|
|
|
|
|
2008-01-29 18:15:54 +00:00
|
|
|
#include <config.h>
|
2007-11-26 11:50:16 +00:00
|
|
|
|
2006-06-06 03:32:51 +00:00
|
|
|
#include <sys/time.h>
|
2006-08-16 16:36:39 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2007-12-07 14:45:39 +00:00
|
|
|
#include <sys/stat.h>
|
2008-10-30 17:40:57 +00:00
|
|
|
#include <libxml/xmlsave.h>
|
2013-08-06 21:42:16 +00:00
|
|
|
#include <libxml/xpathInternals.h>
|
2007-12-07 14:45:39 +00:00
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2008-11-04 23:22:06 +00:00
|
|
|
#include "datatypes.h"
|
2009-09-15 17:38:50 +00:00
|
|
|
#include "test_driver.h"
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2008-02-27 04:35:08 +00:00
|
|
|
#include "capabilities.h"
|
2013-03-29 21:25:13 +00:00
|
|
|
#include "configmake.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2017-03-08 15:25:24 +00:00
|
|
|
#include "virnetworkobj.h"
|
2009-07-21 13:45:55 +00:00
|
|
|
#include "interface_conf.h"
|
2008-07-11 16:41:27 +00:00
|
|
|
#include "domain_conf.h"
|
2009-01-20 20:23:53 +00:00
|
|
|
#include "domain_event.h"
|
2013-12-11 10:37:59 +00:00
|
|
|
#include "network_event.h"
|
2013-08-06 15:20:37 +00:00
|
|
|
#include "snapshot_conf.h"
|
2017-03-07 09:34:47 +00:00
|
|
|
#include "virfdstream.h"
|
2008-10-30 17:40:57 +00:00
|
|
|
#include "storage_conf.h"
|
2017-03-07 20:18:01 +00:00
|
|
|
#include "virstorageobj.h"
|
2016-06-15 18:15:39 +00:00
|
|
|
#include "storage_event.h"
|
2009-10-01 18:54:36 +00:00
|
|
|
#include "node_device_conf.h"
|
2017-02-28 18:24:26 +00:00
|
|
|
#include "virnodedeviceobj.h"
|
2016-07-28 12:02:52 +00:00
|
|
|
#include "node_device_event.h"
|
2012-12-13 18:13:21 +00:00
|
|
|
#include "virxml.h"
|
2012-12-13 15:49:48 +00:00
|
|
|
#include "virthread.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2012-01-07 12:47:43 +00:00
|
|
|
#include "virtypedparam.h"
|
2012-01-25 15:17:46 +00:00
|
|
|
#include "virrandom.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2013-09-23 09:46:02 +00:00
|
|
|
#include "cpu/cpu.h"
|
2014-01-08 18:32:48 +00:00
|
|
|
#include "virauth.h"
|
2015-06-24 13:08:47 +00:00
|
|
|
#include "viratomic.h"
|
2015-07-17 09:11:23 +00:00
|
|
|
#include "virdomainobjlist.h"
|
2017-02-28 21:20:44 +00:00
|
|
|
#include "virinterfaceobj.h"
|
2016-09-15 08:27:06 +00:00
|
|
|
#include "virhostcpu.h"
|
2019-03-15 02:19:18 +00:00
|
|
|
#include "virdomainsnapshotobjlist.h"
|
2019-06-01 12:46:56 +00:00
|
|
|
#include "virkeycode.h"
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_TEST
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("test.test_driver");
|
|
|
|
|
2009-10-27 18:06:30 +00:00
|
|
|
|
2008-04-04 07:31:24 +00:00
|
|
|
#define MAX_CPUS 128
|
|
|
|
|
|
|
|
struct _testCell {
|
|
|
|
unsigned long mem;
|
2016-09-15 08:27:07 +00:00
|
|
|
unsigned long freeMem;
|
2008-04-04 07:31:24 +00:00
|
|
|
int numCpus;
|
2013-01-22 17:42:08 +00:00
|
|
|
virCapsHostNUMACellCPU cpus[MAX_CPUS];
|
2008-04-04 07:31:24 +00:00
|
|
|
};
|
|
|
|
typedef struct _testCell testCell;
|
|
|
|
typedef struct _testCell *testCellPtr;
|
|
|
|
|
|
|
|
#define MAX_CELLS 128
|
2006-06-06 03:32:51 +00:00
|
|
|
|
2014-01-08 18:32:48 +00:00
|
|
|
struct _testAuth {
|
|
|
|
char *username;
|
|
|
|
char *password;
|
|
|
|
};
|
|
|
|
typedef struct _testAuth testAuth;
|
|
|
|
typedef struct _testAuth *testAuthPtr;
|
|
|
|
|
2015-06-22 14:25:16 +00:00
|
|
|
struct _testDriver {
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLockable parent;
|
2008-12-04 20:59:06 +00:00
|
|
|
|
2007-01-18 21:08:21 +00:00
|
|
|
virNodeInfo nodeInfo;
|
2017-04-14 19:45:27 +00:00
|
|
|
virInterfaceObjListPtr ifaces;
|
2011-05-09 19:17:26 +00:00
|
|
|
bool transaction_running;
|
2017-04-14 19:45:27 +00:00
|
|
|
virInterfaceObjListPtr backupIfaces;
|
2017-10-07 11:24:24 +00:00
|
|
|
virStoragePoolObjListPtr pools;
|
2017-05-12 17:51:25 +00:00
|
|
|
virNodeDeviceObjListPtr devs;
|
2008-04-04 07:31:24 +00:00
|
|
|
int numCells;
|
|
|
|
testCell cells[MAX_CELLS];
|
2014-01-08 18:32:48 +00:00
|
|
|
size_t numAuths;
|
|
|
|
testAuthPtr auths;
|
2009-01-20 20:23:53 +00:00
|
|
|
|
2015-06-24 13:08:47 +00:00
|
|
|
/* virAtomic access only */
|
|
|
|
volatile int nextDomID;
|
|
|
|
|
2015-06-24 10:46:19 +00:00
|
|
|
/* immutable pointer, immutable object after being initialized with
|
|
|
|
* testBuildCapabilities */
|
|
|
|
virCapsPtr caps;
|
|
|
|
|
|
|
|
/* immutable pointer, immutable object */
|
|
|
|
virDomainXMLOptionPtr xmlopt;
|
|
|
|
|
|
|
|
/* immutable pointer, self-locking APIs */
|
|
|
|
virDomainObjListPtr domains;
|
|
|
|
virNetworkObjListPtr networks;
|
2014-01-04 13:14:33 +00:00
|
|
|
virObjectEventStatePtr eventState;
|
2007-07-27 23:23:00 +00:00
|
|
|
};
|
2015-06-22 14:25:16 +00:00
|
|
|
typedef struct _testDriver testDriver;
|
|
|
|
typedef testDriver *testDriverPtr;
|
2006-06-06 03:32:51 +00:00
|
|
|
|
2018-03-08 12:20:33 +00:00
|
|
|
static testDriverPtr defaultPrivconn;
|
2014-03-25 14:54:44 +00:00
|
|
|
static virMutex defaultLock = VIR_MUTEX_INITIALIZER;
|
2014-01-01 16:30:12 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
static virClassPtr testDriverClass;
|
|
|
|
static void testDriverDispose(void *obj);
|
|
|
|
static int testDriverOnceInit(void)
|
|
|
|
{
|
|
|
|
if (!(VIR_CLASS_NEW(testDriver, virClassForObjectLockable())))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-01-20 17:23:29 +00:00
|
|
|
VIR_ONCE_GLOBAL_INIT(testDriver);
|
2018-11-20 13:54:16 +00:00
|
|
|
|
2007-03-15 17:24:56 +00:00
|
|
|
#define TEST_MODEL "i686"
|
2008-07-11 16:41:27 +00:00
|
|
|
#define TEST_EMULATOR "/usr/bin/test-hv"
|
2007-03-15 17:24:56 +00:00
|
|
|
|
2006-08-16 16:36:39 +00:00
|
|
|
static const virNodeInfo defaultNodeInfo = {
|
2007-03-15 17:24:56 +00:00
|
|
|
TEST_MODEL,
|
2007-01-18 21:08:21 +00:00
|
|
|
1024*1024*3, /* 3 GB */
|
|
|
|
16,
|
|
|
|
1400,
|
|
|
|
2,
|
|
|
|
2,
|
|
|
|
2,
|
|
|
|
2,
|
2006-06-06 03:32:51 +00:00
|
|
|
};
|
|
|
|
|
2015-06-22 18:13:12 +00:00
|
|
|
static void
|
2018-11-20 13:54:16 +00:00
|
|
|
testDriverDispose(void *obj)
|
2015-06-22 18:13:12 +00:00
|
|
|
{
|
2018-11-20 13:54:16 +00:00
|
|
|
testDriverPtr driver = obj;
|
2015-06-22 18:13:12 +00:00
|
|
|
|
|
|
|
virObjectUnref(driver->caps);
|
|
|
|
virObjectUnref(driver->xmlopt);
|
|
|
|
virObjectUnref(driver->domains);
|
2017-05-12 17:51:25 +00:00
|
|
|
virNodeDeviceObjListFree(driver->devs);
|
2015-06-22 18:13:12 +00:00
|
|
|
virObjectUnref(driver->networks);
|
2017-10-19 15:51:22 +00:00
|
|
|
virObjectUnref(driver->ifaces);
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectUnref(driver->pools);
|
2016-10-11 07:48:36 +00:00
|
|
|
virObjectUnref(driver->eventState);
|
2008-12-04 20:59:06 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 21:42:16 +00:00
|
|
|
#define TEST_NAMESPACE_HREF "http://libvirt.org/schemas/domain/test/1.0"
|
|
|
|
|
|
|
|
typedef struct _testDomainNamespaceDef testDomainNamespaceDef;
|
|
|
|
typedef testDomainNamespaceDef *testDomainNamespaceDefPtr;
|
|
|
|
struct _testDomainNamespaceDef {
|
|
|
|
int runstate;
|
2013-08-06 22:36:30 +00:00
|
|
|
bool transient;
|
2013-08-06 23:33:25 +00:00
|
|
|
bool hasManagedSave;
|
2013-08-07 14:57:55 +00:00
|
|
|
|
|
|
|
unsigned int num_snap_nodes;
|
|
|
|
xmlNodePtr *snap_nodes;
|
2013-08-06 21:42:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
testDomainDefNamespaceFree(void *data)
|
|
|
|
{
|
|
|
|
testDomainNamespaceDefPtr nsdata = data;
|
2013-08-07 14:57:55 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!nsdata)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < nsdata->num_snap_nodes; i++)
|
|
|
|
xmlFreeNode(nsdata->snap_nodes[i]);
|
|
|
|
|
|
|
|
VIR_FREE(nsdata->snap_nodes);
|
2013-08-06 21:42:16 +00:00
|
|
|
VIR_FREE(nsdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_UNUSED,
|
|
|
|
xmlNodePtr root ATTRIBUTE_UNUSED,
|
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
void **data)
|
|
|
|
{
|
|
|
|
testDomainNamespaceDefPtr nsdata = NULL;
|
2013-08-07 14:57:55 +00:00
|
|
|
int tmp, n;
|
|
|
|
size_t i;
|
2013-08-06 21:42:16 +00:00
|
|
|
unsigned int tmpuint;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(xmlNodePtr *) nodes = NULL;
|
2013-08-06 21:42:16 +00:00
|
|
|
|
|
|
|
if (xmlXPathRegisterNs(ctxt, BAD_CAST "test",
|
|
|
|
BAD_CAST TEST_NAMESPACE_HREF) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Failed to register xml namespace '%s'"),
|
|
|
|
TEST_NAMESPACE_HREF);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC(nsdata) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2013-08-07 14:57:55 +00:00
|
|
|
n = virXPathNodeSet("./test:domainsnapshot", ctxt, &nodes);
|
|
|
|
if (n < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (n && VIR_ALLOC_N(nsdata->snap_nodes, n) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
xmlNodePtr newnode = xmlCopyNode(nodes[i], 1);
|
|
|
|
if (!newnode) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsdata->snap_nodes[nsdata->num_snap_nodes] = newnode;
|
|
|
|
nsdata->num_snap_nodes++;
|
|
|
|
}
|
|
|
|
|
2013-08-06 22:36:30 +00:00
|
|
|
tmp = virXPathBoolean("boolean(./test:transient)", ctxt);
|
|
|
|
if (tmp == -1) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid transient"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
nsdata->transient = tmp;
|
|
|
|
|
2013-08-06 23:33:25 +00:00
|
|
|
tmp = virXPathBoolean("boolean(./test:hasmanagedsave)", ctxt);
|
|
|
|
if (tmp == -1) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid hasmanagedsave"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
nsdata->hasManagedSave = tmp;
|
|
|
|
|
2013-08-06 21:42:16 +00:00
|
|
|
tmp = virXPathUInt("string(./test:runstate)", ctxt, &tmpuint);
|
|
|
|
if (tmp == 0) {
|
|
|
|
if (tmpuint >= VIR_DOMAIN_LAST) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("runstate '%d' out of range'"), tmpuint);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
nsdata->runstate = tmpuint;
|
|
|
|
} else if (tmp == -1) {
|
|
|
|
nsdata->runstate = VIR_DOMAIN_RUNNING;
|
|
|
|
} else if (tmp == -2) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("invalid runstate"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-08-06 22:36:30 +00:00
|
|
|
if (nsdata->transient && nsdata->runstate == VIR_DOMAIN_SHUTOFF) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("transient domain cannot have runstate 'shutoff'"));
|
|
|
|
goto error;
|
|
|
|
}
|
2013-08-06 23:33:25 +00:00
|
|
|
if (nsdata->hasManagedSave && nsdata->runstate != VIR_DOMAIN_SHUTOFF) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("domain with managedsave data can only have runstate 'shutoff'"));
|
|
|
|
goto error;
|
|
|
|
}
|
2013-08-06 22:36:30 +00:00
|
|
|
|
2013-08-06 21:42:16 +00:00
|
|
|
*data = nsdata;
|
|
|
|
return 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-08-06 21:42:16 +00:00
|
|
|
testDomainDefNamespaceFree(nsdata);
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-27 18:06:30 +00:00
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
static virCapsPtr
|
2014-03-18 08:17:30 +00:00
|
|
|
testBuildCapabilities(virConnectPtr conn)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2008-07-11 16:41:27 +00:00
|
|
|
virCapsPtr caps;
|
|
|
|
virCapsGuestPtr guest;
|
2015-04-17 22:09:16 +00:00
|
|
|
int guest_types[] = { VIR_DOMAIN_OSTYPE_HVM,
|
|
|
|
VIR_DOMAIN_OSTYPE_XEN };
|
2016-09-15 08:27:08 +00:00
|
|
|
size_t i, j;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2014-07-14 12:56:13 +00:00
|
|
|
if ((caps = virCapabilitiesNew(VIR_ARCH_I686, false, false)) == NULL)
|
2013-07-04 10:16:47 +00:00
|
|
|
goto error;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
if (virCapabilitiesAddHostFeature(caps, "pae") < 0)
|
2013-07-04 10:16:47 +00:00
|
|
|
goto error;
|
2013-11-19 23:04:25 +00:00
|
|
|
if (virCapabilitiesAddHostFeature(caps, "nonpae") < 0)
|
2013-07-04 10:16:47 +00:00
|
|
|
goto error;
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2018-06-01 08:15:59 +00:00
|
|
|
virCapabilitiesHostInitIOMMU(caps);
|
|
|
|
|
2018-05-23 12:40:40 +00:00
|
|
|
if (VIR_ALLOC_N(caps->host.pagesSize, 4) < 0)
|
2016-09-15 08:27:08 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
caps->host.pagesSize[caps->host.nPagesSize++] = 4;
|
2018-05-23 12:40:40 +00:00
|
|
|
caps->host.pagesSize[caps->host.nPagesSize++] = 8;
|
2016-09-15 08:27:08 +00:00
|
|
|
caps->host.pagesSize[caps->host.nPagesSize++] = 2048;
|
2018-05-23 12:40:40 +00:00
|
|
|
caps->host.pagesSize[caps->host.nPagesSize++] = 1024 * 1024;
|
2016-09-15 08:27:08 +00:00
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
for (i = 0; i < privconn->numCells; i++) {
|
2013-01-22 17:42:08 +00:00
|
|
|
virCapsHostNUMACellCPUPtr cpu_cells;
|
2016-09-15 08:27:08 +00:00
|
|
|
virCapsHostNUMACellPageInfoPtr pages;
|
2018-05-23 12:40:40 +00:00
|
|
|
size_t nPages = caps->host.nPagesSize - 1;
|
2013-01-22 17:42:08 +00:00
|
|
|
|
2016-09-15 08:27:08 +00:00
|
|
|
if (VIR_ALLOC_N(cpu_cells, privconn->cells[i].numCpus) < 0 ||
|
2018-05-23 12:40:40 +00:00
|
|
|
VIR_ALLOC_N(pages, nPages) < 0) {
|
2016-09-15 08:27:08 +00:00
|
|
|
VIR_FREE(cpu_cells);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-01-22 17:42:08 +00:00
|
|
|
memcpy(cpu_cells, privconn->cells[i].cpus,
|
|
|
|
sizeof(*cpu_cells) * privconn->cells[i].numCpus);
|
|
|
|
|
2018-05-23 12:40:40 +00:00
|
|
|
if (i == 1)
|
|
|
|
pages[0].size = caps->host.pagesSize[1];
|
|
|
|
else
|
|
|
|
pages[0].size = caps->host.pagesSize[0];
|
|
|
|
|
|
|
|
for (j = 1; j < nPages; j++)
|
|
|
|
pages[j].size = caps->host.pagesSize[j + 1];
|
2016-09-15 08:27:08 +00:00
|
|
|
|
|
|
|
pages[0].avail = privconn->cells[i].mem / pages[0].size;
|
2013-01-22 17:42:08 +00:00
|
|
|
|
2016-09-15 08:27:08 +00:00
|
|
|
if (virCapabilitiesAddHostNUMACell(caps, i, privconn->cells[i].mem,
|
2014-06-03 13:18:27 +00:00
|
|
|
privconn->cells[i].numCpus,
|
2016-09-15 08:27:08 +00:00
|
|
|
cpu_cells, 0, NULL, nPages, pages) < 0)
|
2013-07-04 10:16:47 +00:00
|
|
|
goto error;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(guest_types); i++) {
|
2008-07-11 16:41:27 +00:00
|
|
|
if ((guest = virCapabilitiesAddGuest(caps,
|
|
|
|
guest_types[i],
|
2012-12-10 22:28:09 +00:00
|
|
|
VIR_ARCH_I686,
|
2008-07-11 16:41:27 +00:00
|
|
|
TEST_EMULATOR,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL)) == NULL)
|
2013-07-04 10:16:47 +00:00
|
|
|
goto error;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
if (virCapabilitiesAddGuestDomain(guest,
|
2015-04-17 22:38:10 +00:00
|
|
|
VIR_DOMAIN_VIRT_TEST,
|
2008-07-11 16:41:27 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL) == NULL)
|
2013-07-04 10:16:47 +00:00
|
|
|
goto error;
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2014-07-14 12:56:13 +00:00
|
|
|
if (virCapabilitiesAddGuestFeature(guest, "pae", true, true) == NULL)
|
2013-07-04 10:16:47 +00:00
|
|
|
goto error;
|
2014-07-14 12:56:13 +00:00
|
|
|
if (virCapabilitiesAddGuestFeature(guest, "nonpae", true, true) == NULL)
|
2013-07-04 10:16:47 +00:00
|
|
|
goto error;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
|
|
|
|
2012-08-15 22:10:35 +00:00
|
|
|
caps->host.nsecModels = 1;
|
|
|
|
if (VIR_ALLOC_N(caps->host.secModels, caps->host.nsecModels) < 0)
|
2013-07-04 10:16:47 +00:00
|
|
|
goto error;
|
2013-05-03 12:49:30 +00:00
|
|
|
if (VIR_STRDUP(caps->host.secModels[0].model, "testSecurity") < 0)
|
|
|
|
goto error;
|
2010-02-09 17:16:00 +00:00
|
|
|
|
2013-05-03 12:49:30 +00:00
|
|
|
if (VIR_STRDUP(caps->host.secModels[0].doi, "") < 0)
|
|
|
|
goto error;
|
2010-02-09 17:16:00 +00:00
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
return caps;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-02-01 12:26:18 +00:00
|
|
|
virObjectUnref(caps);
|
2008-07-11 16:41:27 +00:00
|
|
|
return NULL;
|
2006-08-16 16:36:39 +00:00
|
|
|
}
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2015-06-24 09:06:24 +00:00
|
|
|
static testDriverPtr
|
|
|
|
testDriverNew(void)
|
|
|
|
{
|
|
|
|
virDomainXMLNamespace ns = {
|
|
|
|
.parse = testDomainDefNamespaceParse,
|
|
|
|
.free = testDomainDefNamespaceFree,
|
|
|
|
};
|
2019-04-17 14:38:57 +00:00
|
|
|
virDomainDefParserConfig config = {
|
|
|
|
.features = VIR_DOMAIN_DEF_FEATURE_MEMORY_HOTPLUG |
|
|
|
|
VIR_DOMAIN_DEF_FEATURE_OFFLINE_VCPUPIN |
|
|
|
|
VIR_DOMAIN_DEF_FEATURE_INDIVIDUAL_VCPUS |
|
|
|
|
VIR_DOMAIN_DEF_FEATURE_USER_ALIAS |
|
|
|
|
VIR_DOMAIN_DEF_FEATURE_FW_AUTOSELECT |
|
|
|
|
VIR_DOMAIN_DEF_FEATURE_NET_MODEL_STRING,
|
|
|
|
};
|
2015-06-24 09:06:24 +00:00
|
|
|
testDriverPtr ret;
|
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
if (testDriverInitialize() < 0)
|
2015-06-24 09:06:24 +00:00
|
|
|
return NULL;
|
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
if (!(ret = virObjectLockableNew(testDriverClass)))
|
|
|
|
return NULL;
|
2015-06-24 09:06:24 +00:00
|
|
|
|
2019-04-17 14:38:57 +00:00
|
|
|
if (!(ret->xmlopt = virDomainXMLOptionNew(&config, NULL, &ns, NULL, NULL)) ||
|
2015-06-24 09:06:24 +00:00
|
|
|
!(ret->eventState = virObjectEventStateNew()) ||
|
2017-04-14 19:45:27 +00:00
|
|
|
!(ret->ifaces = virInterfaceObjListNew()) ||
|
2015-06-24 09:06:24 +00:00
|
|
|
!(ret->domains = virDomainObjListNew()) ||
|
2017-05-12 17:51:25 +00:00
|
|
|
!(ret->networks = virNetworkObjListNew()) ||
|
2017-10-07 11:24:24 +00:00
|
|
|
!(ret->devs = virNodeDeviceObjListNew()) ||
|
|
|
|
!(ret->pools = virStoragePoolObjListNew()))
|
2015-06-24 09:06:24 +00:00
|
|
|
goto error;
|
|
|
|
|
2015-06-24 13:08:47 +00:00
|
|
|
virAtomicIntSet(&ret->nextDomID, 1);
|
2015-06-24 09:06:24 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
error:
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnref(ret);
|
2015-06-24 09:06:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-27 22:09:14 +00:00
|
|
|
static const char *defaultConnXML =
|
|
|
|
"<node>"
|
2008-07-11 16:41:27 +00:00
|
|
|
"<domain type='test'>"
|
|
|
|
" <name>test</name>"
|
2012-04-17 14:53:51 +00:00
|
|
|
" <uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid>"
|
2008-07-11 16:41:27 +00:00
|
|
|
" <memory>8388608</memory>"
|
|
|
|
" <currentMemory>2097152</currentMemory>"
|
|
|
|
" <vcpu>2</vcpu>"
|
|
|
|
" <os>"
|
|
|
|
" <type>hvm</type>"
|
|
|
|
" </os>"
|
2019-05-23 12:50:01 +00:00
|
|
|
" <devices>"
|
2019-06-25 21:58:06 +00:00
|
|
|
" <disk type='file' device='disk'>"
|
|
|
|
" <source file='/guest/diskimage1'/>"
|
|
|
|
" <target dev='vda' bus='virtio'/>"
|
|
|
|
" <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>"
|
|
|
|
" </disk>"
|
2019-05-23 12:50:01 +00:00
|
|
|
" <interface type='network'>"
|
|
|
|
" <mac address='aa:bb:cc:dd:ee:ff'/>"
|
|
|
|
" <source network='default' bridge='virbr0'/>"
|
|
|
|
" <address type='pci' domain='0x0000' bus='0x00' slot='0x1' function='0x0'/>"
|
|
|
|
" </interface>"
|
|
|
|
" </devices>"
|
2016-06-27 22:09:14 +00:00
|
|
|
"</domain>"
|
|
|
|
""
|
2008-07-11 16:39:08 +00:00
|
|
|
"<network>"
|
|
|
|
" <name>default</name>"
|
2012-04-17 14:53:51 +00:00
|
|
|
" <uuid>dd8fe884-6c02-601e-7551-cca97df1c5df</uuid>"
|
2013-07-30 12:36:08 +00:00
|
|
|
" <bridge name='virbr0'/>"
|
2008-07-11 16:39:08 +00:00
|
|
|
" <forward/>"
|
|
|
|
" <ip address='192.168.122.1' netmask='255.255.255.0'>"
|
|
|
|
" <dhcp>"
|
2013-07-30 12:36:08 +00:00
|
|
|
" <range start='192.168.122.2' end='192.168.122.254'/>"
|
2008-07-11 16:39:08 +00:00
|
|
|
" </dhcp>"
|
|
|
|
" </ip>"
|
2016-06-27 22:09:14 +00:00
|
|
|
"</network>"
|
|
|
|
""
|
2009-07-21 13:45:55 +00:00
|
|
|
"<interface type=\"ethernet\" name=\"eth1\">"
|
|
|
|
" <start mode=\"onboot\"/>"
|
|
|
|
" <mac address=\"aa:bb:cc:dd:ee:ff\"/>"
|
|
|
|
" <mtu size=\"1492\"/>"
|
|
|
|
" <protocol family=\"ipv4\">"
|
|
|
|
" <ip address=\"192.168.0.5\" prefix=\"24\"/>"
|
|
|
|
" <route gateway=\"192.168.0.1\"/>"
|
|
|
|
" </protocol>"
|
2016-06-27 22:09:14 +00:00
|
|
|
"</interface>"
|
|
|
|
""
|
2008-10-30 17:40:57 +00:00
|
|
|
"<pool type='dir'>"
|
|
|
|
" <name>default-pool</name>"
|
2012-04-17 14:53:51 +00:00
|
|
|
" <uuid>dfe224cb-28fb-8dd0-c4b2-64eb3f0f4566</uuid>"
|
2008-10-30 17:40:57 +00:00
|
|
|
" <target>"
|
|
|
|
" <path>/default-pool</path>"
|
|
|
|
" </target>"
|
2016-06-27 22:09:14 +00:00
|
|
|
"</pool>"
|
|
|
|
""
|
|
|
|
"<device>"
|
|
|
|
" <name>computer</name>"
|
|
|
|
" <capability type='system'>"
|
|
|
|
" <hardware>"
|
|
|
|
" <vendor>Libvirt</vendor>"
|
|
|
|
" <version>Test driver</version>"
|
|
|
|
" <serial>123456</serial>"
|
|
|
|
" <uuid>11111111-2222-3333-4444-555555555555</uuid>"
|
|
|
|
" </hardware>"
|
|
|
|
" <firmware>"
|
|
|
|
" <vendor>Libvirt</vendor>"
|
|
|
|
" <version>Test Driver</version>"
|
|
|
|
" <release_date>01/22/2007</release_date>"
|
|
|
|
" </firmware>"
|
|
|
|
" </capability>"
|
|
|
|
"</device>"
|
2016-07-01 11:33:10 +00:00
|
|
|
"<device>"
|
2017-01-23 20:24:59 +00:00
|
|
|
" <name>scsi_host1</name>"
|
2016-07-01 11:33:10 +00:00
|
|
|
" <parent>computer</parent>"
|
|
|
|
" <capability type='scsi_host'>"
|
|
|
|
" <host>1</host>"
|
2017-01-23 20:24:59 +00:00
|
|
|
" <unique_id>0</unique_id>"
|
2016-07-01 11:33:10 +00:00
|
|
|
" <capability type='fc_host'>"
|
|
|
|
" <wwnn>2000000012341234</wwnn>"
|
|
|
|
" <wwpn>1000000012341234</wwpn>"
|
2017-01-23 20:24:59 +00:00
|
|
|
" <fabric_wwn>2000000043214321</fabric_wwn>"
|
|
|
|
" </capability>"
|
|
|
|
" <capability type='vport_ops'>"
|
|
|
|
" <max_vports>127</max_vports>"
|
2017-01-24 11:32:03 +00:00
|
|
|
" <vports>1</vports>"
|
|
|
|
" </capability>"
|
|
|
|
" </capability>"
|
|
|
|
"</device>"
|
|
|
|
"<device>"
|
|
|
|
" <name>scsi_host2</name>"
|
|
|
|
" <parent>computer</parent>"
|
|
|
|
" <capability type='scsi_host'>"
|
|
|
|
" <host>2</host>"
|
|
|
|
" <unique_id>1</unique_id>"
|
|
|
|
" <capability type='fc_host'>"
|
|
|
|
" <wwnn>2000000056785678</wwnn>"
|
|
|
|
" <wwpn>1000000056785678</wwpn>"
|
|
|
|
" <fabric_wwn>2000000087658765</fabric_wwn>"
|
|
|
|
" </capability>"
|
|
|
|
" <capability type='vport_ops'>"
|
|
|
|
" <max_vports>127</max_vports>"
|
2017-01-23 20:24:59 +00:00
|
|
|
" <vports>0</vports>"
|
2016-07-01 11:33:10 +00:00
|
|
|
" </capability>"
|
|
|
|
" </capability>"
|
|
|
|
"</device>"
|
2017-01-24 11:32:03 +00:00
|
|
|
"<device>"
|
|
|
|
" <name>scsi_host11</name>"
|
|
|
|
" <parent>scsi_host1</parent>"
|
|
|
|
" <capability type='scsi_host'>"
|
|
|
|
" <host>11</host>"
|
|
|
|
" <unique_id>10</unique_id>"
|
|
|
|
" <capability type='fc_host'>"
|
|
|
|
" <wwnn>2000000034563456</wwnn>"
|
|
|
|
" <wwpn>1000000034563456</wwpn>"
|
|
|
|
" <fabric_wwn>2000000043214321</fabric_wwn>"
|
|
|
|
" </capability>"
|
|
|
|
" </capability>"
|
|
|
|
"</device>"
|
2016-06-27 22:09:14 +00:00
|
|
|
"</node>";
|
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2009-10-16 08:35:05 +00:00
|
|
|
static const char *defaultPoolSourcesLogicalXML =
|
|
|
|
"<sources>\n"
|
|
|
|
" <source>\n"
|
|
|
|
" <device path='/dev/sda20'/>\n"
|
|
|
|
" <name>testvg1</name>\n"
|
|
|
|
" <format type='lvm2'/>\n"
|
|
|
|
" </source>\n"
|
|
|
|
" <source>\n"
|
|
|
|
" <device path='/dev/sda21'/>\n"
|
|
|
|
" <name>testvg2</name>\n"
|
|
|
|
" <format type='lvm2'/>\n"
|
|
|
|
" </source>\n"
|
|
|
|
"</sources>\n";
|
|
|
|
|
|
|
|
static const char *defaultPoolSourcesNetFSXML =
|
|
|
|
"<sources>\n"
|
|
|
|
" <source>\n"
|
|
|
|
" <host name='%s'/>\n"
|
|
|
|
" <dir path='/testshare'/>\n"
|
|
|
|
" <format type='nfs'/>\n"
|
|
|
|
" </source>\n"
|
|
|
|
"</sources>\n";
|
|
|
|
|
2008-12-07 20:45:28 +00:00
|
|
|
static const unsigned long long defaultPoolCap = (100 * 1024 * 1024 * 1024ull);
|
2014-10-28 18:38:04 +00:00
|
|
|
static const unsigned long long defaultPoolAlloc;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr obj);
|
2009-10-27 18:06:30 +00:00
|
|
|
static int testNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);
|
2019-06-19 16:45:30 +00:00
|
|
|
static virNetworkObjPtr testNetworkObjFindByName(testDriverPtr privconn, const char *name);
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2013-08-06 15:20:37 +00:00
|
|
|
static virDomainObjPtr
|
|
|
|
testDomObjFromDomain(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = domain->conn->privateData;
|
2013-08-06 15:20:37 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
2018-03-09 15:47:46 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, domain->uuid);
|
2013-08-06 15:20:37 +00:00
|
|
|
if (!vm) {
|
|
|
|
virUUIDFormat(domain->uuid, uuidstr);
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("no domain with matching uuid '%s' (%s)"),
|
|
|
|
uuidstr, domain->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return vm;
|
|
|
|
}
|
|
|
|
|
2009-07-24 15:05:29 +00:00
|
|
|
static char *
|
2014-03-18 08:17:30 +00:00
|
|
|
testDomainGenerateIfname(virDomainDefPtr domdef)
|
|
|
|
{
|
2009-07-24 15:05:29 +00:00
|
|
|
int maxif = 1024;
|
Convert 'int i' to 'size_t i' in src/test/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int ifctr;
|
2009-07-24 15:05:29 +00:00
|
|
|
|
|
|
|
for (ifctr = 0; ifctr < maxif; ++ifctr) {
|
2017-10-02 13:24:39 +00:00
|
|
|
virDomainNetDefPtr net = NULL;
|
2009-07-24 15:05:29 +00:00
|
|
|
char *ifname;
|
|
|
|
|
2013-07-04 10:16:47 +00:00
|
|
|
if (virAsprintf(&ifname, "testnet%d", ifctr) < 0)
|
2009-07-24 15:05:29 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Generate network interface names */
|
2017-10-02 13:24:39 +00:00
|
|
|
if (!(net = virDomainNetFindByName(domdef, ifname)))
|
2009-07-24 15:05:29 +00:00
|
|
|
return ifname;
|
2014-09-02 09:54:05 +00:00
|
|
|
VIR_FREE(ifname);
|
2009-07-24 15:05:29 +00:00
|
|
|
}
|
|
|
|
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Exceeded max iface limit %d"), maxif);
|
2009-07-24 15:05:29 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-02 13:02:06 +00:00
|
|
|
static int
|
2010-04-02 21:56:10 +00:00
|
|
|
testDomainGenerateIfnames(virDomainDefPtr domdef)
|
2009-07-24 15:05:29 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/test/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i = 0;
|
2009-07-24 15:05:29 +00:00
|
|
|
|
|
|
|
for (i = 0; i < domdef->nnets; i++) {
|
|
|
|
char *ifname;
|
|
|
|
if (domdef->nets[i]->ifname)
|
|
|
|
continue;
|
|
|
|
|
2010-04-02 21:56:10 +00:00
|
|
|
ifname = testDomainGenerateIfname(domdef);
|
2009-07-24 15:05:29 +00:00
|
|
|
if (!ifname)
|
2009-09-02 13:02:06 +00:00
|
|
|
return -1;
|
2009-07-24 15:05:29 +00:00
|
|
|
|
|
|
|
domdef->nets[i]->ifname = ifname;
|
|
|
|
}
|
|
|
|
|
2009-09-02 13:02:06 +00:00
|
|
|
return 0;
|
2009-07-24 15:05:29 +00:00
|
|
|
}
|
|
|
|
|
2009-10-27 18:06:30 +00:00
|
|
|
|
2010-11-19 18:36:29 +00:00
|
|
|
static void
|
|
|
|
testDomainShutdownState(virDomainPtr domain,
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjPtr privdom,
|
|
|
|
virDomainShutoffReason reason)
|
2010-11-19 18:36:29 +00:00
|
|
|
{
|
2016-09-08 13:16:58 +00:00
|
|
|
virDomainObjRemoveTransientDef(privdom);
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(privdom, VIR_DOMAIN_SHUTOFF, reason);
|
2016-09-08 13:16:58 +00:00
|
|
|
|
2010-11-19 18:36:29 +00:00
|
|
|
if (domain)
|
|
|
|
domain->id = -1;
|
|
|
|
}
|
|
|
|
|
2009-10-27 18:06:30 +00:00
|
|
|
/* Set up domain runtime state */
|
2009-10-27 17:15:44 +00:00
|
|
|
static int
|
2015-06-22 14:25:16 +00:00
|
|
|
testDomainStartState(testDriverPtr privconn,
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjPtr dom,
|
|
|
|
virDomainRunningReason reason)
|
2009-10-27 17:15:44 +00:00
|
|
|
{
|
2009-10-27 18:06:30 +00:00
|
|
|
int ret = -1;
|
2009-10-27 17:15:44 +00:00
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(dom, VIR_DOMAIN_RUNNING, reason);
|
2015-06-24 13:08:47 +00:00
|
|
|
dom->def->id = virAtomicIntAdd(&privconn->nextDomID, 1);
|
2009-10-27 17:15:44 +00:00
|
|
|
|
2013-03-05 15:17:24 +00:00
|
|
|
if (virDomainObjSetDefTransient(privconn->caps,
|
2013-03-31 18:03:42 +00:00
|
|
|
privconn->xmlopt,
|
2016-05-27 12:00:34 +00:00
|
|
|
dom) < 0) {
|
2010-11-19 18:36:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-08-06 23:33:25 +00:00
|
|
|
dom->hasManagedSave = false;
|
2009-10-27 18:06:30 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2010-11-19 18:36:29 +00:00
|
|
|
if (ret < 0)
|
2011-05-04 09:07:01 +00:00
|
|
|
testDomainShutdownState(NULL, dom, VIR_DOMAIN_SHUTOFF_FAILED);
|
2009-10-27 18:06:30 +00:00
|
|
|
return ret;
|
2009-10-27 17:15:44 +00:00
|
|
|
}
|
2009-09-02 13:02:06 +00:00
|
|
|
|
2014-01-01 16:30:12 +00:00
|
|
|
|
2006-08-16 16:36:39 +00:00
|
|
|
static char *testBuildFilename(const char *relativeTo,
|
2014-03-18 08:17:30 +00:00
|
|
|
const char *filename)
|
|
|
|
{
|
2007-01-18 21:08:21 +00:00
|
|
|
char *offset;
|
|
|
|
int baseLen;
|
2013-05-03 12:49:30 +00:00
|
|
|
char *ret;
|
|
|
|
|
2007-01-18 21:08:21 +00:00
|
|
|
if (!filename || filename[0] == '\0')
|
2012-03-22 11:33:35 +00:00
|
|
|
return NULL;
|
2013-05-03 12:49:30 +00:00
|
|
|
if (filename[0] == '/') {
|
|
|
|
ignore_value(VIR_STRDUP(ret, filename));
|
|
|
|
return ret;
|
|
|
|
}
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2007-06-15 13:44:19 +00:00
|
|
|
offset = strrchr(relativeTo, '/');
|
2007-01-18 21:08:21 +00:00
|
|
|
if ((baseLen = (offset-relativeTo+1))) {
|
2008-05-29 19:20:22 +00:00
|
|
|
char *absFile;
|
2009-08-03 12:37:44 +00:00
|
|
|
int totalLen = baseLen + strlen(filename) + 1;
|
|
|
|
if (VIR_ALLOC_N(absFile, totalLen) < 0)
|
2008-05-29 19:20:22 +00:00
|
|
|
return NULL;
|
2018-07-20 07:50:37 +00:00
|
|
|
if (virStrncpy(absFile, relativeTo, baseLen, totalLen) < 0) {
|
2009-08-03 12:37:44 +00:00
|
|
|
VIR_FREE(absFile);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-01-18 21:08:21 +00:00
|
|
|
strcat(absFile, filename);
|
|
|
|
return absFile;
|
|
|
|
} else {
|
2013-05-03 12:49:30 +00:00
|
|
|
ignore_value(VIR_STRDUP(ret, filename));
|
|
|
|
return ret;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2006-08-16 16:36:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 20:56:50 +00:00
|
|
|
static xmlNodePtr
|
|
|
|
testParseXMLDocFromFile(xmlNodePtr node, const char *file, const char *type)
|
|
|
|
{
|
|
|
|
xmlNodePtr ret = NULL;
|
|
|
|
xmlDocPtr doc = NULL;
|
|
|
|
char *absFile = NULL;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(char *) relFile = NULL;
|
2013-08-06 20:56:50 +00:00
|
|
|
|
2019-02-01 13:54:56 +00:00
|
|
|
if ((relFile = virXMLPropString(node, "file"))) {
|
2013-08-06 20:56:50 +00:00
|
|
|
absFile = testBuildFilename(file, relFile);
|
|
|
|
if (!absFile) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("resolving %s filename"), type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(doc = virXMLParse(absFile, NULL, type)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
ret = xmlCopyNode(xmlDocGetRootElement(doc), 1);
|
|
|
|
if (!ret) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
xmlReplaceNode(node, ret);
|
|
|
|
xmlFreeNode(node);
|
|
|
|
} else {
|
|
|
|
ret = node;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-08-06 20:56:50 +00:00
|
|
|
xmlFreeDoc(doc);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
static int
|
|
|
|
testParseNodeInfo(virNodeInfoPtr nodeInfo, xmlXPathContextPtr ctxt)
|
|
|
|
{
|
|
|
|
long l;
|
|
|
|
int ret;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(char *) str = NULL;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathLong("string(/node/cpu/nodes[1])", ctxt, &l);
|
2007-04-06 15:34:09 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
nodeInfo->nodes = l;
|
|
|
|
} else if (ret == -2) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("invalid node cpu nodes value"));
|
2007-07-27 23:23:00 +00:00
|
|
|
goto error;
|
2006-08-16 16:36:39 +00:00
|
|
|
}
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathLong("string(/node/cpu/sockets[1])", ctxt, &l);
|
2007-04-06 15:34:09 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
nodeInfo->sockets = l;
|
|
|
|
} else if (ret == -2) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("invalid node cpu sockets value"));
|
2007-07-27 23:23:00 +00:00
|
|
|
goto error;
|
2006-08-16 16:36:39 +00:00
|
|
|
}
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathLong("string(/node/cpu/cores[1])", ctxt, &l);
|
2007-04-06 15:34:09 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
nodeInfo->cores = l;
|
|
|
|
} else if (ret == -2) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("invalid node cpu cores value"));
|
2007-07-27 23:23:00 +00:00
|
|
|
goto error;
|
2006-08-16 16:36:39 +00:00
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathLong("string(/node/cpu/threads[1])", ctxt, &l);
|
2007-04-06 15:34:09 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
nodeInfo->threads = l;
|
|
|
|
} else if (ret == -2) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("invalid node cpu threads value"));
|
2007-07-27 23:23:00 +00:00
|
|
|
goto error;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2007-04-06 15:34:09 +00:00
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
nodeInfo->cpus = (nodeInfo->cores * nodeInfo->threads *
|
|
|
|
nodeInfo->sockets * nodeInfo->nodes);
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathLong("string(/node/cpu/active[1])", ctxt, &l);
|
2007-04-06 15:34:09 +00:00
|
|
|
if (ret == 0) {
|
2014-11-13 14:24:39 +00:00
|
|
|
if (l < nodeInfo->cpus)
|
2007-07-27 23:23:00 +00:00
|
|
|
nodeInfo->cpus = l;
|
2007-04-06 15:34:09 +00:00
|
|
|
} else if (ret == -2) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("invalid node cpu active value"));
|
2007-07-27 23:23:00 +00:00
|
|
|
goto error;
|
2007-04-06 15:34:09 +00:00
|
|
|
}
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathLong("string(/node/cpu/mhz[1])", ctxt, &l);
|
2007-04-06 15:34:09 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
nodeInfo->mhz = l;
|
|
|
|
} else if (ret == -2) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("invalid node cpu mhz value"));
|
2007-07-27 23:23:00 +00:00
|
|
|
goto error;
|
2007-04-06 15:34:09 +00:00
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
str = virXPathString("string(/node/cpu/model[1])", ctxt);
|
2007-04-06 15:34:09 +00:00
|
|
|
if (str != NULL) {
|
2018-07-20 07:50:37 +00:00
|
|
|
if (virStrcpyStatic(nodeInfo->model, str) < 0) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Model %s too big for destination"), str);
|
2009-08-03 12:37:44 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2006-08-16 16:36:39 +00:00
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathLong("string(/node/memory[1])", ctxt, &l);
|
2007-04-06 15:34:09 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
nodeInfo->memory = l;
|
|
|
|
} else if (ret == -2) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("invalid node memory value"));
|
2007-07-27 23:23:00 +00:00
|
|
|
goto error;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
return 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-08-06 18:45:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-08-07 14:57:55 +00:00
|
|
|
static int
|
2015-06-22 14:25:16 +00:00
|
|
|
testParseDomainSnapshots(testDriverPtr privconn,
|
2013-08-07 14:57:55 +00:00
|
|
|
virDomainObjPtr domobj,
|
|
|
|
const char *file,
|
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
int ret = -1;
|
|
|
|
testDomainNamespaceDefPtr nsdata = domobj->def->namespaceData;
|
|
|
|
xmlNodePtr *nodes = nsdata->snap_nodes;
|
snapshot: Drop virDomainSnapshotDef.current
The only use for the 'current' member of virDomainSnapshotDef was with
the PARSE/FORMAT_INTERNAL flag for controlling an internal-use
<active> element marking whether a particular snapshot definition was
current, and even then, only by the qemu driver on output, and by qemu
and test driver on input. But this duplicates vm->snapshot_current,
and gets in the way of potential simplifications to have qemu store a
single file for all snapshots rather than one file per snapshot. Get
rid of the member by adding a bool* parameter during parse (ignored if
the PARSE_INTERNAL flag is not set), and by adding a new flag during
format (if FORMAT_INTERNAL is set, the value printed in <active>
depends on the new FORMAT_CURRENT).
Then update the qemu driver accordingly, which involves hoisting
assignments to vm->current_snapshot to occur prior to any point where
a snapshot XML file is written (although qemu kept
vm->current_snapshot and snapshot->def_current in sync by the end of
the function, they were not always identical in the middle of
functions, so the shuffling gets a bit interesting). Later patches
will clean up some of that confusing churn to vm->current_snapshot.
Note: even if later patches refactor qemu to no longer use
FORMAT_INTERNAL for output (by storing bulk snapshot XML instead), we
will always need PARSE_INTERNAL for input (because on upgrade, a new
libvirt still has to parse XML left from a previous libvirt).
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-03-19 03:56:19 +00:00
|
|
|
bool cur;
|
2013-08-07 14:57:55 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nsdata->num_snap_nodes; i++) {
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr snap;
|
2013-08-07 14:57:55 +00:00
|
|
|
virDomainSnapshotDefPtr def;
|
|
|
|
xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file,
|
|
|
|
"domainsnapshot");
|
|
|
|
if (!node)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
def = virDomainSnapshotDefParseNode(ctxt->doc, node,
|
|
|
|
privconn->caps,
|
|
|
|
privconn->xmlopt,
|
snapshot: Drop virDomainSnapshotDef.current
The only use for the 'current' member of virDomainSnapshotDef was with
the PARSE/FORMAT_INTERNAL flag for controlling an internal-use
<active> element marking whether a particular snapshot definition was
current, and even then, only by the qemu driver on output, and by qemu
and test driver on input. But this duplicates vm->snapshot_current,
and gets in the way of potential simplifications to have qemu store a
single file for all snapshots rather than one file per snapshot. Get
rid of the member by adding a bool* parameter during parse (ignored if
the PARSE_INTERNAL flag is not set), and by adding a new flag during
format (if FORMAT_INTERNAL is set, the value printed in <active>
depends on the new FORMAT_CURRENT).
Then update the qemu driver accordingly, which involves hoisting
assignments to vm->current_snapshot to occur prior to any point where
a snapshot XML file is written (although qemu kept
vm->current_snapshot and snapshot->def_current in sync by the end of
the function, they were not always identical in the middle of
functions, so the shuffling gets a bit interesting). Later patches
will clean up some of that confusing churn to vm->current_snapshot.
Note: even if later patches refactor qemu to no longer use
FORMAT_INTERNAL for output (by storing bulk snapshot XML instead), we
will always need PARSE_INTERNAL for input (because on upgrade, a new
libvirt still has to parse XML left from a previous libvirt).
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-03-19 03:56:19 +00:00
|
|
|
&cur,
|
2013-08-07 14:57:55 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_PARSE_DISKS |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE);
|
|
|
|
if (!def)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(snap = virDomainSnapshotAssignDef(domobj->snapshots, def))) {
|
2019-05-09 14:59:06 +00:00
|
|
|
virObjectUnref(def);
|
2013-08-07 14:57:55 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
snapshot: Drop virDomainSnapshotDef.current
The only use for the 'current' member of virDomainSnapshotDef was with
the PARSE/FORMAT_INTERNAL flag for controlling an internal-use
<active> element marking whether a particular snapshot definition was
current, and even then, only by the qemu driver on output, and by qemu
and test driver on input. But this duplicates vm->snapshot_current,
and gets in the way of potential simplifications to have qemu store a
single file for all snapshots rather than one file per snapshot. Get
rid of the member by adding a bool* parameter during parse (ignored if
the PARSE_INTERNAL flag is not set), and by adding a new flag during
format (if FORMAT_INTERNAL is set, the value printed in <active>
depends on the new FORMAT_CURRENT).
Then update the qemu driver accordingly, which involves hoisting
assignments to vm->current_snapshot to occur prior to any point where
a snapshot XML file is written (although qemu kept
vm->current_snapshot and snapshot->def_current in sync by the end of
the function, they were not always identical in the middle of
functions, so the shuffling gets a bit interesting). Later patches
will clean up some of that confusing churn to vm->current_snapshot.
Note: even if later patches refactor qemu to no longer use
FORMAT_INTERNAL for output (by storing bulk snapshot XML instead), we
will always need PARSE_INTERNAL for input (because on upgrade, a new
libvirt still has to parse XML left from a previous libvirt).
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-03-19 03:56:19 +00:00
|
|
|
if (cur) {
|
2019-03-21 20:00:08 +00:00
|
|
|
if (virDomainSnapshotGetCurrent(domobj->snapshots)) {
|
2013-08-07 14:57:55 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("more than one snapshot claims to be active"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2019-03-21 20:00:08 +00:00
|
|
|
virDomainSnapshotSetCurrent(domobj->snapshots, snap);
|
2013-08-07 14:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainSnapshotUpdateRelations(domobj->snapshots) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Snapshots have inconsistent relations for "
|
|
|
|
"domain %s"), domobj->def->name);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-08-07 14:57:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
static int
|
2015-06-22 14:25:16 +00:00
|
|
|
testParseDomains(testDriverPtr privconn,
|
2013-08-06 20:56:50 +00:00
|
|
|
const char *file,
|
|
|
|
xmlXPathContextPtr ctxt)
|
2013-08-06 18:45:02 +00:00
|
|
|
{
|
|
|
|
int num, ret = -1;
|
|
|
|
size_t i;
|
2018-04-23 14:40:48 +00:00
|
|
|
virDomainObjPtr obj = NULL;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(xmlNodePtr *) nodes = NULL;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
num = virXPathNodeSet("/node/domain", ctxt, &nodes);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (num < 0)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2008-07-11 16:41:27 +00:00
|
|
|
virDomainDefPtr def;
|
2013-08-06 21:42:16 +00:00
|
|
|
testDomainNamespaceDefPtr nsdata;
|
2013-08-06 20:56:50 +00:00
|
|
|
xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file, "domain");
|
|
|
|
if (!node)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
def = virDomainDefParseNode(ctxt->doc, node,
|
2016-09-22 14:56:26 +00:00
|
|
|
privconn->caps, privconn->xmlopt, NULL,
|
2014-11-18 16:44:00 +00:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE);
|
2013-08-06 20:56:50 +00:00
|
|
|
if (!def)
|
|
|
|
goto error;
|
2008-07-11 16:41:27 +00:00
|
|
|
|
2010-04-02 21:56:10 +00:00
|
|
|
if (testDomainGenerateIfnames(def) < 0 ||
|
2013-08-06 18:45:02 +00:00
|
|
|
!(obj = virDomainObjListAdd(privconn->domains,
|
2013-03-28 13:55:55 +00:00
|
|
|
def,
|
2013-03-31 18:03:42 +00:00
|
|
|
privconn->xmlopt,
|
2013-03-28 13:55:55 +00:00
|
|
|
0, NULL))) {
|
2008-07-11 16:41:27 +00:00
|
|
|
virDomainDefFree(def);
|
2007-01-18 21:08:21 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2008-07-11 16:41:27 +00:00
|
|
|
|
2018-04-23 14:40:48 +00:00
|
|
|
if (testParseDomainSnapshots(privconn, obj, file, ctxt) < 0)
|
2013-08-07 14:57:55 +00:00
|
|
|
goto error;
|
|
|
|
|
2013-08-06 21:42:16 +00:00
|
|
|
nsdata = def->namespaceData;
|
2013-08-06 22:36:30 +00:00
|
|
|
obj->persistent = !nsdata->transient;
|
2013-08-06 23:33:25 +00:00
|
|
|
obj->hasManagedSave = nsdata->hasManagedSave;
|
2013-08-06 21:42:16 +00:00
|
|
|
|
|
|
|
if (nsdata->runstate != VIR_DOMAIN_SHUTOFF) {
|
|
|
|
if (testDomainStartState(privconn, obj,
|
2018-04-23 14:40:48 +00:00
|
|
|
VIR_DOMAIN_RUNNING_BOOTED) < 0)
|
2013-08-06 21:42:16 +00:00
|
|
|
goto error;
|
|
|
|
} else {
|
|
|
|
testDomainShutdownState(NULL, obj, 0);
|
2009-10-27 17:15:44 +00:00
|
|
|
}
|
2013-08-06 21:42:16 +00:00
|
|
|
virDomainObjSetState(obj, nsdata->runstate, 0);
|
2009-10-27 17:15:44 +00:00
|
|
|
|
2018-04-23 14:40:48 +00:00
|
|
|
virDomainObjEndAPI(&obj);
|
2006-08-16 16:36:39 +00:00
|
|
|
}
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2018-04-23 14:40:48 +00:00
|
|
|
virDomainObjEndAPI(&obj);
|
2013-08-06 18:45:02 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
static int
|
2015-06-22 14:25:16 +00:00
|
|
|
testParseNetworks(testDriverPtr privconn,
|
2013-08-06 20:56:50 +00:00
|
|
|
const char *file,
|
|
|
|
xmlXPathContextPtr ctxt)
|
2013-08-06 18:45:02 +00:00
|
|
|
{
|
2019-02-01 13:54:56 +00:00
|
|
|
int num;
|
2013-08-06 18:45:02 +00:00
|
|
|
size_t i;
|
|
|
|
virNetworkObjPtr obj;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(xmlNodePtr *) nodes = NULL;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
num = virXPathNodeSet("/node/network", ctxt, &nodes);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (num < 0)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
2008-07-11 16:39:08 +00:00
|
|
|
virNetworkDefPtr def;
|
2013-08-06 20:56:50 +00:00
|
|
|
xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file, "network");
|
|
|
|
if (!node)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2008-07-11 16:39:08 +00:00
|
|
|
|
2013-08-06 20:56:50 +00:00
|
|
|
def = virNetworkDefParseNode(ctxt->doc, node);
|
|
|
|
if (!def)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
2017-03-08 16:41:18 +00:00
|
|
|
if (!(obj = virNetworkObjAssignDef(privconn->networks, def, 0))) {
|
2008-07-11 16:39:08 +00:00
|
|
|
virNetworkDefFree(def);
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2013-08-06 18:45:02 +00:00
|
|
|
|
2017-05-10 11:22:15 +00:00
|
|
|
virNetworkObjSetActive(obj, true);
|
2015-02-26 12:45:05 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
2008-07-11 16:39:08 +00:00
|
|
|
}
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2019-02-01 13:54:56 +00:00
|
|
|
return 0;
|
2013-08-06 18:45:02 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
static int
|
2015-06-22 14:25:16 +00:00
|
|
|
testParseInterfaces(testDriverPtr privconn,
|
2013-08-06 20:56:50 +00:00
|
|
|
const char *file,
|
|
|
|
xmlXPathContextPtr ctxt)
|
2013-08-06 18:45:02 +00:00
|
|
|
{
|
2019-02-01 13:54:56 +00:00
|
|
|
int num;
|
2013-08-06 18:45:02 +00:00
|
|
|
size_t i;
|
|
|
|
virInterfaceObjPtr obj;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(xmlNodePtr *) nodes = NULL;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
num = virXPathNodeSet("/node/interface", ctxt, &nodes);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (num < 0)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceDefPtr def;
|
2013-08-06 20:56:50 +00:00
|
|
|
xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file,
|
|
|
|
"interface");
|
|
|
|
if (!node)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2013-08-06 20:56:50 +00:00
|
|
|
def = virInterfaceDefParseNode(ctxt->doc, node);
|
|
|
|
if (!def)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2009-10-07 14:44:05 +00:00
|
|
|
|
2017-04-14 20:49:48 +00:00
|
|
|
if (!(obj = virInterfaceObjListAssignDef(privconn->ifaces, def))) {
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceDefFree(def);
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2009-07-21 13:45:55 +00:00
|
|
|
}
|
2009-10-07 14:44:05 +00:00
|
|
|
|
2017-04-25 21:45:02 +00:00
|
|
|
virInterfaceObjSetActive(obj, true);
|
2017-05-15 18:31:44 +00:00
|
|
|
virInterfaceObjEndAPI(&obj);
|
2013-08-06 18:45:02 +00:00
|
|
|
}
|
|
|
|
|
2019-02-01 13:54:56 +00:00
|
|
|
return 0;
|
2013-08-06 18:45:02 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
static int
|
2013-08-06 20:56:50 +00:00
|
|
|
testOpenVolumesForPool(const char *file,
|
2013-08-06 18:45:02 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj,
|
|
|
|
int objidx)
|
2013-08-06 18:45:02 +00:00
|
|
|
{
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj);
|
2013-08-06 18:45:02 +00:00
|
|
|
size_t i;
|
2019-02-01 13:54:56 +00:00
|
|
|
int num;
|
|
|
|
VIR_AUTOFREE(char *) vol_xpath = NULL;
|
|
|
|
VIR_AUTOFREE(xmlNodePtr *) nodes = NULL;
|
2019-01-31 14:44:54 +00:00
|
|
|
VIR_AUTOPTR(virStorageVolDef) volDef = NULL;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
/* Find storage volumes */
|
2017-05-05 19:31:40 +00:00
|
|
|
if (virAsprintf(&vol_xpath, "/node/pool[%d]/volume", objidx) < 0)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
num = virXPathNodeSet(vol_xpath, ctxt, &nodes);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (num < 0)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
2013-08-06 20:56:50 +00:00
|
|
|
xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file,
|
|
|
|
"volume");
|
|
|
|
if (!node)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
if (!(volDef = virStorageVolDefParseNode(def, ctxt->doc, node, 0)))
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
2017-07-26 17:33:30 +00:00
|
|
|
if (!volDef->target.path) {
|
|
|
|
if (virAsprintf(&volDef->target.path, "%s/%s",
|
2017-05-08 12:21:52 +00:00
|
|
|
def->target.path, volDef->name) < 0)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2013-08-06 18:45:02 +00:00
|
|
|
}
|
|
|
|
|
2017-07-26 17:33:30 +00:00
|
|
|
if (!volDef->key && VIR_STRDUP(volDef->key, volDef->target.path) < 0)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2017-05-09 12:05:16 +00:00
|
|
|
|
2017-07-26 17:33:30 +00:00
|
|
|
if (virStoragePoolObjAddVol(obj, volDef) < 0)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
def->allocation += volDef->target.allocation;
|
|
|
|
def->available = (def->capacity - def->allocation);
|
2017-07-26 17:33:30 +00:00
|
|
|
volDef = NULL;
|
2009-07-21 13:45:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-01 13:54:56 +00:00
|
|
|
return 0;
|
2013-08-06 18:45:02 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
static int
|
2015-06-22 14:25:16 +00:00
|
|
|
testParseStorage(testDriverPtr privconn,
|
2013-08-06 20:56:50 +00:00
|
|
|
const char *file,
|
|
|
|
xmlXPathContextPtr ctxt)
|
2013-08-06 18:45:02 +00:00
|
|
|
{
|
2019-02-01 13:54:56 +00:00
|
|
|
int num;
|
2013-08-06 18:45:02 +00:00
|
|
|
size_t i;
|
|
|
|
virStoragePoolObjPtr obj;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(xmlNodePtr *) nodes = NULL;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
num = virXPathNodeSet("/node/pool", ctxt, &nodes);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (num < 0)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
2008-10-30 17:40:57 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2013-08-06 20:56:50 +00:00
|
|
|
xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file,
|
|
|
|
"pool");
|
|
|
|
if (!node)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2013-08-06 20:56:50 +00:00
|
|
|
def = virStoragePoolDefParseNode(ctxt->doc, node);
|
|
|
|
if (!def)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2018-08-17 10:30:08 +00:00
|
|
|
if (!(obj = virStoragePoolObjAssignDef(privconn->pools, def, false))) {
|
2008-10-30 17:40:57 +00:00
|
|
|
virStoragePoolDefFree(def);
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
if (testStoragePoolObjSetDefaults(obj) == -1) {
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2008-12-04 20:59:06 +00:00
|
|
|
}
|
2017-07-26 16:15:42 +00:00
|
|
|
virStoragePoolObjSetActive(obj, true);
|
2009-06-22 17:19:30 +00:00
|
|
|
|
|
|
|
/* Find storage volumes */
|
2013-08-06 20:56:50 +00:00
|
|
|
if (testOpenVolumesForPool(file, ctxt, obj, i+1) < 0) {
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2009-06-22 17:19:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2019-02-01 13:54:56 +00:00
|
|
|
return 0;
|
2013-08-06 18:45:02 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
static int
|
2015-06-22 14:25:16 +00:00
|
|
|
testParseNodedevs(testDriverPtr privconn,
|
2013-08-06 20:56:50 +00:00
|
|
|
const char *file,
|
|
|
|
xmlXPathContextPtr ctxt)
|
2013-08-06 18:45:02 +00:00
|
|
|
{
|
2019-02-01 13:54:56 +00:00
|
|
|
int num;
|
2013-08-06 18:45:02 +00:00
|
|
|
size_t i;
|
|
|
|
virNodeDeviceObjPtr obj;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(xmlNodePtr *) nodes = NULL;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
num = virXPathNodeSet("/node/device", ctxt, &nodes);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (num < 0)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
2009-10-02 14:05:17 +00:00
|
|
|
virNodeDeviceDefPtr def;
|
2013-08-06 20:56:50 +00:00
|
|
|
xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file,
|
|
|
|
"nodedev");
|
|
|
|
if (!node)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2009-10-02 14:05:17 +00:00
|
|
|
|
2013-08-06 20:56:50 +00:00
|
|
|
def = virNodeDeviceDefParseNode(ctxt->doc, node, 0, NULL);
|
|
|
|
if (!def)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
2017-05-12 18:47:17 +00:00
|
|
|
if (!(obj = virNodeDeviceObjListAssignDef(privconn->devs, def))) {
|
2009-10-02 14:05:17 +00:00
|
|
|
virNodeDeviceDefFree(def);
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2009-10-02 14:05:17 +00:00
|
|
|
}
|
2013-08-06 18:45:02 +00:00
|
|
|
|
2018-02-23 23:09:20 +00:00
|
|
|
virNodeDeviceObjSetSkipUpdateCaps(obj, true);
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
2013-08-06 18:45:02 +00:00
|
|
|
}
|
|
|
|
|
2019-02-01 13:54:56 +00:00
|
|
|
return 0;
|
2013-08-06 18:45:02 +00:00
|
|
|
}
|
|
|
|
|
2014-01-08 18:32:48 +00:00
|
|
|
static int
|
2015-06-22 14:25:16 +00:00
|
|
|
testParseAuthUsers(testDriverPtr privconn,
|
2014-01-08 18:32:48 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2019-02-01 13:54:56 +00:00
|
|
|
int num;
|
2014-01-08 18:32:48 +00:00
|
|
|
size_t i;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(xmlNodePtr *) nodes = NULL;
|
2014-01-08 18:32:48 +00:00
|
|
|
|
|
|
|
num = virXPathNodeSet("/node/auth/user", ctxt, &nodes);
|
|
|
|
if (num < 0)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2014-01-08 18:32:48 +00:00
|
|
|
|
|
|
|
privconn->numAuths = num;
|
|
|
|
if (num && VIR_ALLOC_N(privconn->auths, num) < 0)
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2014-01-08 18:32:48 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(char *) username = NULL;
|
2014-01-08 18:32:48 +00:00
|
|
|
|
|
|
|
ctxt->node = nodes[i];
|
|
|
|
username = virXPathString("string(.)", ctxt);
|
|
|
|
if (!username || STREQ(username, "")) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("missing username in /node/auth/user field"));
|
2019-02-01 13:54:56 +00:00
|
|
|
return -1;
|
2014-01-08 18:32:48 +00:00
|
|
|
}
|
|
|
|
/* This field is optional. */
|
2019-02-01 13:54:56 +00:00
|
|
|
privconn->auths[i].password = virXMLPropString(nodes[i], "password");
|
|
|
|
VIR_STEAL_PTR(privconn->auths[i].username, username);
|
2014-01-08 18:32:48 +00:00
|
|
|
}
|
|
|
|
|
2019-02-01 13:54:56 +00:00
|
|
|
return 0;
|
2014-01-08 18:32:48 +00:00
|
|
|
}
|
2014-01-01 16:30:12 +00:00
|
|
|
|
2016-06-27 21:03:07 +00:00
|
|
|
static int
|
|
|
|
testOpenParse(testDriverPtr privconn,
|
|
|
|
const char *file,
|
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2017-08-14 12:31:52 +00:00
|
|
|
if (!virXMLNodeNameEqual(ctxt->node, "node")) {
|
2016-06-27 21:03:07 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Root element is not 'node'"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (testParseNodeInfo(&privconn->nodeInfo, ctxt) < 0)
|
|
|
|
goto error;
|
|
|
|
if (testParseDomains(privconn, file, ctxt) < 0)
|
|
|
|
goto error;
|
|
|
|
if (testParseNetworks(privconn, file, ctxt) < 0)
|
|
|
|
goto error;
|
|
|
|
if (testParseInterfaces(privconn, file, ctxt) < 0)
|
|
|
|
goto error;
|
|
|
|
if (testParseStorage(privconn, file, ctxt) < 0)
|
|
|
|
goto error;
|
|
|
|
if (testParseNodedevs(privconn, file, ctxt) < 0)
|
|
|
|
goto error;
|
|
|
|
if (testParseAuthUsers(privconn, ctxt) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
error:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-01-01 16:30:12 +00:00
|
|
|
/* No shared state between simultaneous test connections initialized
|
|
|
|
* from a file. */
|
2013-08-06 18:45:02 +00:00
|
|
|
static int
|
|
|
|
testOpenFromFile(virConnectPtr conn, const char *file)
|
|
|
|
{
|
|
|
|
xmlDocPtr doc = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
2015-06-24 09:06:24 +00:00
|
|
|
if (!(privconn = testDriverNew()))
|
2013-08-06 18:45:02 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
2009-10-02 14:05:17 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2013-08-06 18:45:02 +00:00
|
|
|
conn->privateData = privconn;
|
|
|
|
|
|
|
|
if (!(privconn->caps = testBuildCapabilities(conn)))
|
|
|
|
goto error;
|
|
|
|
|
2014-11-13 14:24:39 +00:00
|
|
|
if (!(doc = virXMLParseFileCtxt(file, &ctxt)))
|
2013-08-06 18:45:02 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
privconn->numCells = 0;
|
|
|
|
memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
|
|
|
|
|
2016-06-27 21:03:07 +00:00
|
|
|
if (testOpenParse(privconn, file, ctxt) < 0)
|
2014-01-08 18:32:48 +00:00
|
|
|
goto error;
|
2009-10-02 14:05:17 +00:00
|
|
|
|
2008-01-30 19:50:14 +00:00
|
|
|
xmlXPathFreeContext(ctxt);
|
2013-08-06 18:45:02 +00:00
|
|
|
xmlFreeDoc(doc);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2018-03-08 12:20:30 +00:00
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
2006-08-16 16:36:39 +00:00
|
|
|
|
|
|
|
error:
|
2008-01-30 19:50:14 +00:00
|
|
|
xmlXPathFreeContext(ctxt);
|
2013-08-06 18:45:02 +00:00
|
|
|
xmlFreeDoc(doc);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnref(privconn);
|
2007-07-27 23:23:00 +00:00
|
|
|
conn->privateData = NULL;
|
2007-04-04 14:19:49 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
2006-08-16 16:36:39 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 21:06:43 +00:00
|
|
|
/* Simultaneous test:///default connections should share the same
|
|
|
|
* common state (among other things, this allows testing event
|
|
|
|
* detection in one connection for an action caused in another). */
|
|
|
|
static int
|
|
|
|
testOpenDefault(virConnectPtr conn)
|
|
|
|
{
|
2018-03-08 12:20:29 +00:00
|
|
|
int ret = VIR_DRV_OPEN_ERROR;
|
2016-06-27 21:06:43 +00:00
|
|
|
testDriverPtr privconn = NULL;
|
2016-06-27 22:09:14 +00:00
|
|
|
xmlDocPtr doc = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
2016-09-15 15:10:15 +00:00
|
|
|
size_t i;
|
2016-06-27 21:06:43 +00:00
|
|
|
|
|
|
|
virMutexLock(&defaultLock);
|
2018-11-20 13:54:16 +00:00
|
|
|
if (defaultPrivconn) {
|
|
|
|
conn->privateData = virObjectRef(defaultPrivconn);
|
2016-06-27 21:06:43 +00:00
|
|
|
virMutexUnlock(&defaultLock);
|
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(privconn = testDriverNew()))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
conn->privateData = privconn;
|
|
|
|
|
|
|
|
memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
|
|
|
|
|
|
|
|
/* Numa setup */
|
|
|
|
privconn->numCells = 2;
|
2016-09-15 15:10:15 +00:00
|
|
|
for (i = 0; i < privconn->numCells; i++) {
|
|
|
|
privconn->cells[i].numCpus = 8;
|
|
|
|
privconn->cells[i].mem = (i + 1) * 2048 * 1024;
|
|
|
|
privconn->cells[i].freeMem = (i + 1) * 1024 * 1024;
|
2016-06-27 21:06:43 +00:00
|
|
|
}
|
2016-09-15 15:10:15 +00:00
|
|
|
for (i = 0; i < 16; i++) {
|
2016-06-27 21:06:43 +00:00
|
|
|
virBitmapPtr siblings = virBitmapNew(16);
|
|
|
|
if (!siblings)
|
|
|
|
goto error;
|
2016-09-15 15:10:15 +00:00
|
|
|
ignore_value(virBitmapSetBit(siblings, i));
|
|
|
|
privconn->cells[i / 8].cpus[(i % 8)].id = i;
|
|
|
|
privconn->cells[i / 8].cpus[(i % 8)].socket_id = i / 8;
|
|
|
|
privconn->cells[i / 8].cpus[(i % 8)].core_id = i % 8;
|
|
|
|
privconn->cells[i / 8].cpus[(i % 8)].siblings = siblings;
|
2016-06-27 21:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(privconn->caps = testBuildCapabilities(conn)))
|
|
|
|
goto error;
|
|
|
|
|
2016-06-27 22:09:14 +00:00
|
|
|
if (!(doc = virXMLParseStringCtxt(defaultConnXML,
|
|
|
|
_("(test driver)"), &ctxt)))
|
2016-06-27 21:06:43 +00:00
|
|
|
goto error;
|
|
|
|
|
2016-06-27 22:09:14 +00:00
|
|
|
if (testOpenParse(privconn, NULL, ctxt) < 0)
|
2016-06-27 21:06:43 +00:00
|
|
|
goto error;
|
|
|
|
|
2018-03-08 12:20:33 +00:00
|
|
|
defaultPrivconn = privconn;
|
2018-03-08 12:20:29 +00:00
|
|
|
ret = VIR_DRV_OPEN_SUCCESS;
|
|
|
|
cleanup:
|
|
|
|
virMutexUnlock(&defaultLock);
|
2016-06-27 22:09:14 +00:00
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(doc);
|
2018-03-08 12:20:29 +00:00
|
|
|
return ret;
|
2016-06-27 21:06:43 +00:00
|
|
|
|
|
|
|
error:
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnref(privconn);
|
2016-06-27 21:06:43 +00:00
|
|
|
conn->privateData = NULL;
|
2018-03-08 12:20:29 +00:00
|
|
|
goto cleanup;
|
2016-06-27 21:06:43 +00:00
|
|
|
}
|
|
|
|
|
2014-01-08 18:32:48 +00:00
|
|
|
static int
|
|
|
|
testConnectAuthenticate(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2014-01-08 18:32:48 +00:00
|
|
|
int ret = -1;
|
|
|
|
ssize_t i;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(char *) username = NULL;
|
|
|
|
VIR_AUTOFREE(char *) password = NULL;
|
2014-01-08 18:32:48 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2018-03-08 12:20:31 +00:00
|
|
|
if (privconn->numAuths == 0) {
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2014-01-08 18:32:48 +00:00
|
|
|
return 0;
|
2018-03-08 12:20:31 +00:00
|
|
|
}
|
2014-01-08 18:32:48 +00:00
|
|
|
|
|
|
|
/* Authentication is required because the test XML contains a
|
|
|
|
* non-empty <auth/> section. First we must ask for a username.
|
|
|
|
*/
|
2018-08-14 14:30:48 +00:00
|
|
|
if (!(username = virAuthGetUsername(conn, auth, "test", NULL,
|
|
|
|
"localhost"/*?*/)))
|
2014-01-08 18:32:48 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Does the username exist? */
|
|
|
|
for (i = 0; i < privconn->numAuths; ++i) {
|
|
|
|
if (STREQ(privconn->auths[i].username, username))
|
|
|
|
goto found_user;
|
|
|
|
}
|
|
|
|
i = -1;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
found_user:
|
2014-01-08 18:32:48 +00:00
|
|
|
/* Even if we didn't find the user, we still ask for a password. */
|
|
|
|
if (i == -1 || privconn->auths[i].password != NULL) {
|
2018-08-14 14:30:48 +00:00
|
|
|
if (!(password = virAuthGetPassword(conn, auth, "test", username,
|
|
|
|
"localhost")))
|
2014-01-08 18:32:48 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == -1 ||
|
|
|
|
(password && STRNEQ(privconn->auths[i].password, password))) {
|
|
|
|
virReportError(VIR_ERR_AUTH_FAILED, "%s",
|
|
|
|
_("authentication failed, see test XML for the correct username/password"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2014-01-08 18:32:48 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2006-06-06 03:32:51 +00:00
|
|
|
|
2018-03-08 12:20:34 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
testDriverCloseInternal(testDriverPtr driver)
|
|
|
|
{
|
2018-11-20 13:54:16 +00:00
|
|
|
virMutexLock(&defaultLock);
|
|
|
|
bool disposed = !virObjectUnref(driver);
|
|
|
|
if (disposed && driver == defaultPrivconn)
|
2018-03-08 12:20:34 +00:00
|
|
|
defaultPrivconn = NULL;
|
2018-11-20 13:54:16 +00:00
|
|
|
virMutexUnlock(&defaultLock);
|
2018-03-08 12:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virDrvOpenStatus
|
|
|
|
testConnectOpen(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth,
|
|
|
|
virConfPtr conf ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2007-07-27 23:23:00 +00:00
|
|
|
int ret;
|
2006-06-06 03:32:51 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
2018-03-28 13:25:23 +00:00
|
|
|
if (conn->uri->path[0] == '\0' ||
|
|
|
|
(conn->uri->path[0] == '/' && conn->uri->path[1] == '\0')) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
"%s", _("testOpen: supply a path or use test:///default"));
|
2007-04-18 10:14:07 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
2006-06-06 03:32:51 +00:00
|
|
|
|
2008-11-17 11:44:51 +00:00
|
|
|
if (STREQ(conn->uri->path, "/default"))
|
2007-07-27 23:23:00 +00:00
|
|
|
ret = testOpenDefault(conn);
|
|
|
|
else
|
2007-01-18 21:08:21 +00:00
|
|
|
ret = testOpenFromFile(conn,
|
2008-11-17 11:44:51 +00:00
|
|
|
conn->uri->path);
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2011-05-12 12:58:44 +00:00
|
|
|
if (ret != VIR_DRV_OPEN_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
|
2014-01-08 18:32:48 +00:00
|
|
|
/* Fake authentication. */
|
2018-03-08 12:20:35 +00:00
|
|
|
if (testConnectAuthenticate(conn, auth) < 0) {
|
|
|
|
testDriverCloseInternal(conn->privateData);
|
|
|
|
conn->privateData = NULL;
|
2014-01-08 18:32:48 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
2018-03-08 12:20:35 +00:00
|
|
|
}
|
2014-01-08 18:32:48 +00:00
|
|
|
|
2011-05-12 12:58:44 +00:00
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
2015-06-22 14:49:28 +00:00
|
|
|
|
2018-03-08 12:20:34 +00:00
|
|
|
static int
|
|
|
|
testConnectClose(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
testDriverCloseInternal(conn->privateData);
|
2008-12-04 20:56:10 +00:00
|
|
|
conn->privateData = NULL;
|
2007-04-04 14:19:49 +00:00
|
|
|
return 0;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 12:20:34 +00:00
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectGetVersion(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
unsigned long *hvVer)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2007-01-18 21:08:21 +00:00
|
|
|
*hvVer = 2;
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
2013-04-26 16:39:11 +00:00
|
|
|
static char *testConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return virGetHostname();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
|
2011-09-23 06:56:13 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectGetMaxVcpus(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
const char *type ATTRIBUTE_UNUSED)
|
2007-07-27 23:23:00 +00:00
|
|
|
{
|
|
|
|
return 32;
|
|
|
|
}
|
|
|
|
|
2013-11-06 18:27:30 +00:00
|
|
|
static char *
|
|
|
|
testConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
const char **xmlCPUs,
|
|
|
|
unsigned int ncpus,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2017-09-13 14:27:15 +00:00
|
|
|
virCPUDefPtr *cpus = NULL;
|
|
|
|
virCPUDefPtr cpu = NULL;
|
|
|
|
char *cpustr = NULL;
|
2013-11-06 18:27:30 +00:00
|
|
|
|
|
|
|
virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, NULL);
|
|
|
|
|
2017-09-13 14:27:15 +00:00
|
|
|
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2018-05-15 09:57:35 +00:00
|
|
|
if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL, false)))
|
2017-09-13 14:27:15 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
|
|
|
|
virCPUExpandFeatures(cpus[0]->arch, cpu) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-06-30 13:47:23 +00:00
|
|
|
cpustr = virCPUDefFormat(cpu, NULL);
|
2017-09-13 14:27:15 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virCPUDefListFree(cpus);
|
|
|
|
virCPUDefFree(cpu);
|
2013-11-06 18:27:30 +00:00
|
|
|
|
2017-09-13 14:27:15 +00:00
|
|
|
return cpustr;
|
2013-11-06 18:27:30 +00:00
|
|
|
}
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
static int testNodeGetInfo(virConnectPtr conn,
|
|
|
|
virNodeInfoPtr info)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2007-07-27 23:23:00 +00:00
|
|
|
memcpy(info, &privconn->nodeInfo, sizeof(virNodeInfo));
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static char *testConnectGetCapabilities(virConnectPtr conn)
|
2007-03-15 17:24:56 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2008-02-27 04:35:08 +00:00
|
|
|
char *xml;
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2014-06-27 07:55:44 +00:00
|
|
|
xml = virCapabilitiesFormatXML(privconn->caps);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2008-02-27 04:35:08 +00:00
|
|
|
return xml;
|
2007-03-15 17:24:56 +00:00
|
|
|
}
|
|
|
|
|
2016-09-15 08:27:04 +00:00
|
|
|
static char *
|
|
|
|
testConnectGetSysinfo(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
const char *sysinfo = "<sysinfo type='smbios'>\n"
|
|
|
|
" <bios>\n"
|
|
|
|
" <entry name='vendor'>LENOVO</entry>\n"
|
|
|
|
" <entry name='version'>G4ETA1WW (2.61 )</entry>\n"
|
|
|
|
" <entry name='date'>05/07/2014</entry>\n"
|
|
|
|
" <entry name='release'>2.61</entry>\n"
|
|
|
|
" </bios>\n"
|
|
|
|
"</sysinfo>\n";
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
ignore_value(VIR_STRDUP(ret, sysinfo));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-09-15 08:27:05 +00:00
|
|
|
static const char *
|
|
|
|
testConnectGetType(virConnectPtr conn ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return "TEST";
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectNumOfDomains(virConnectPtr conn)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
Convert virDomainObjListPtr to use a hash of domain objects
The current virDomainObjListPtr object stores domain objects in
an array. This means that to find a particular objects requires
O(n) time, and more critically acquiring O(n) mutex locks.
The new impl replaces the array with a virHashTable, keyed off
UUID. Finding a object based on UUID is now O(1) time, and only
requires a single mutex lock. Finding by name/id is unchanged
in complexity.
In changing this, all code which iterates over the array had
to be updated to use a hash table iterator function callback.
Several of the functions which were identically duplicating
across all drivers were pulled into domain_conf.c
* src/conf/domain_conf.h, src/conf/domain_conf.c: Change
virDomainObjListPtr to use virHashTable. Add a initializer
method virDomainObjListInit, and rename virDomainObjListFree
to virDomainObjListDeinit, since its not actually freeing
the container, only its contents. Also add some convenient
methods virDomainObjListGetInactiveNames,
virDomainObjListGetActiveIDs and virDomainObjListNumOfDomains
which can be used to implement the correspondingly named
public API entry points in drivers
* src/libvirt_private.syms: Export new methods from domain_conf.h
* src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_conf.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/test/test_driver.c,
src/uml/uml_driver.c, src/vbox/vbox_tmpl.c: Update all code
to deal with hash tables instead of arrays for domains
2009-10-09 11:33:51 +00:00
|
|
|
int count;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2013-06-24 16:49:47 +00:00
|
|
|
count = virDomainObjListNumOfDomains(privconn->domains, true, NULL, NULL);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2008-10-10 14:20:37 +00:00
|
|
|
|
Convert virDomainObjListPtr to use a hash of domain objects
The current virDomainObjListPtr object stores domain objects in
an array. This means that to find a particular objects requires
O(n) time, and more critically acquiring O(n) mutex locks.
The new impl replaces the array with a virHashTable, keyed off
UUID. Finding a object based on UUID is now O(1) time, and only
requires a single mutex lock. Finding by name/id is unchanged
in complexity.
In changing this, all code which iterates over the array had
to be updated to use a hash table iterator function callback.
Several of the functions which were identically duplicating
across all drivers were pulled into domain_conf.c
* src/conf/domain_conf.h, src/conf/domain_conf.c: Change
virDomainObjListPtr to use virHashTable. Add a initializer
method virDomainObjListInit, and rename virDomainObjListFree
to virDomainObjListDeinit, since its not actually freeing
the container, only its contents. Also add some convenient
methods virDomainObjListGetInactiveNames,
virDomainObjListGetActiveIDs and virDomainObjListNumOfDomains
which can be used to implement the correspondingly named
public API entry points in drivers
* src/libvirt_private.syms: Export new methods from domain_conf.h
* src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_conf.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/test/test_driver.c,
src/uml/uml_driver.c, src/vbox/vbox_tmpl.c: Update all code
to deal with hash tables instead of arrays for domains
2009-10-09 11:33:51 +00:00
|
|
|
return count;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
static int testDomainIsActive(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
virDomainObjPtr obj;
|
2015-06-16 16:18:03 +00:00
|
|
|
int ret;
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(obj = testDomObjFromDomain(dom)))
|
|
|
|
return -1;
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
ret = virDomainObjIsActive(obj);
|
|
|
|
virDomainObjEndAPI(&obj);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testDomainIsPersistent(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
virDomainObjPtr obj;
|
2015-06-16 16:18:03 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(obj = testDomObjFromDomain(dom)))
|
|
|
|
return -1;
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
|
|
|
|
ret = obj->persistent;
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
virDomainObjEndAPI(&obj);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-24 07:43:15 +00:00
|
|
|
static int testDomainIsUpdated(virDomainPtr dom ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
static virDomainPtr
|
2008-10-10 09:32:27 +00:00
|
|
|
testDomainCreateXML(virConnectPtr conn, const char *xml,
|
2010-05-25 17:13:13 +00:00
|
|
|
unsigned int flags)
|
2006-08-16 16:36:39 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2008-12-04 20:57:47 +00:00
|
|
|
virDomainPtr ret = NULL;
|
2008-07-11 16:41:27 +00:00
|
|
|
virDomainDefPtr def;
|
2008-12-04 20:59:06 +00:00
|
|
|
virDomainObjPtr dom = NULL;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2014-11-18 17:34:42 +00:00
|
|
|
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2014-11-18 17:34:42 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_START_VALIDATE, NULL);
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_START_VALIDATE)
|
2016-05-24 15:20:20 +00:00
|
|
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA;
|
2010-05-25 17:13:13 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2013-11-19 23:04:25 +00:00
|
|
|
if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt,
|
2016-09-22 15:14:17 +00:00
|
|
|
NULL, parse_flags)) == NULL)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2010-04-02 21:56:10 +00:00
|
|
|
if (testDomainGenerateIfnames(def) < 0)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2013-01-11 16:04:47 +00:00
|
|
|
if (!(dom = virDomainObjListAdd(privconn->domains,
|
Merge virDomainObjListIsDuplicate into virDomainObjListAdd
The duplicate VM checking should be done atomically with
virDomainObjListAdd, so shoud not be a separate function.
Instead just use flags to indicate what kind of checks are
required.
This pair, used in virDomainCreateXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainRestoreFlags:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, true)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainDefineXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 0) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
0, NULL)))
goto cleanup;
2013-01-14 14:46:58 +00:00
|
|
|
def,
|
2013-03-28 13:55:55 +00:00
|
|
|
privconn->xmlopt,
|
2015-09-22 14:57:52 +00:00
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
|
Merge virDomainObjListIsDuplicate into virDomainObjListAdd
The duplicate VM checking should be done atomically with
virDomainObjListAdd, so shoud not be a separate function.
Instead just use flags to indicate what kind of checks are
required.
This pair, used in virDomainCreateXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainRestoreFlags:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, true)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainDefineXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 0) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
0, NULL)))
goto cleanup;
2013-01-14 14:46:58 +00:00
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
|
|
|
|
NULL)))
|
2009-09-02 13:02:06 +00:00
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
2009-10-27 17:15:44 +00:00
|
|
|
|
2015-09-22 14:52:03 +00:00
|
|
|
if (testDomainStartState(privconn, dom, VIR_DOMAIN_RUNNING_BOOTED) < 0) {
|
2018-04-23 14:40:48 +00:00
|
|
|
if (!dom->persistent)
|
2015-09-22 14:52:03 +00:00
|
|
|
virDomainObjListRemove(privconn->domains, dom);
|
2009-10-27 17:15:44 +00:00
|
|
|
goto cleanup;
|
2015-09-22 14:52:03 +00:00
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(dom,
|
2009-01-20 20:23:53 +00:00
|
|
|
VIR_DOMAIN_EVENT_STARTED,
|
|
|
|
VIR_DOMAIN_EVENT_STARTED_BOOTED);
|
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
ret = virGetDomain(conn, dom->def->name, dom->def->uuid, dom->def->id);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2018-04-23 14:40:48 +00:00
|
|
|
virDomainObjEndAPI(&dom);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2010-03-25 20:53:29 +00:00
|
|
|
virDomainDefFree(def);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2008-07-11 16:41:27 +00:00
|
|
|
return ret;
|
2006-08-16 16:36:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static virDomainPtr testDomainLookupByID(virConnectPtr conn,
|
2007-07-27 23:23:00 +00:00
|
|
|
int id)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2008-12-04 20:57:47 +00:00
|
|
|
virDomainPtr ret = NULL;
|
|
|
|
virDomainObjPtr dom;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2018-03-09 15:59:28 +00:00
|
|
|
if (!(dom = virDomainObjListFindByID(privconn->domains, id))) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
2018-03-27 17:16:38 +00:00
|
|
|
return NULL;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
ret = virGetDomain(conn, dom->def->name, dom->def->uuid, dom->def->id);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2018-03-27 17:16:38 +00:00
|
|
|
virDomainObjEndAPI(&dom);
|
2008-07-11 16:41:27 +00:00
|
|
|
return ret;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static virDomainPtr testDomainLookupByUUID(virConnectPtr conn,
|
2007-07-27 23:23:00 +00:00
|
|
|
const unsigned char *uuid)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2008-12-04 20:57:47 +00:00
|
|
|
virDomainPtr ret = NULL;
|
2013-05-21 07:21:18 +00:00
|
|
|
virDomainObjPtr dom;
|
2007-07-06 14:56:15 +00:00
|
|
|
|
2018-03-09 15:47:46 +00:00
|
|
|
if (!(dom = virDomainObjListFindByUUID(privconn->domains, uuid))) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
2018-03-09 15:37:52 +00:00
|
|
|
return NULL;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2007-07-06 14:56:15 +00:00
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
ret = virGetDomain(conn, dom->def->name, dom->def->uuid, dom->def->id);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2018-03-09 15:37:52 +00:00
|
|
|
virDomainObjEndAPI(&dom);
|
2008-07-11 16:41:27 +00:00
|
|
|
return ret;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static virDomainPtr testDomainLookupByName(virConnectPtr conn,
|
2007-07-27 23:23:00 +00:00
|
|
|
const char *name)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2008-12-04 20:57:47 +00:00
|
|
|
virDomainPtr ret = NULL;
|
|
|
|
virDomainObjPtr dom;
|
2007-07-06 14:56:15 +00:00
|
|
|
|
2015-06-22 12:33:23 +00:00
|
|
|
if (!(dom = virDomainObjListFindByName(privconn->domains, name))) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2007-07-06 14:56:15 +00:00
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
ret = virGetDomain(conn, dom->def->name, dom->def->uuid, dom->def->id);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&dom);
|
2008-07-11 16:41:27 +00:00
|
|
|
return ret;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectListDomains(virConnectPtr conn,
|
|
|
|
int *ids,
|
|
|
|
int maxids)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2008-10-10 14:20:37 +00:00
|
|
|
|
2015-06-22 12:33:23 +00:00
|
|
|
return virDomainObjListGetActiveIDs(privconn->domains, ids, maxids,
|
|
|
|
NULL, NULL);
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
2018-03-22 18:42:27 +00:00
|
|
|
static int testDomainDestroyFlags(virDomainPtr domain,
|
|
|
|
unsigned int flags)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = domain->conn->privateData;
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2018-03-22 18:42:27 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_DESTROY_GRACEFUL, -1);
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2018-04-17 22:13:28 +00:00
|
|
|
if (virDomainObjCheckActive(privdom) < 0)
|
2016-11-07 20:09:26 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
testDomainShutdownState(domain, privdom, VIR_DOMAIN_SHUTOFF_DESTROYED);
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(privdom,
|
2009-01-20 20:23:53 +00:00
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
|
2009-11-03 17:06:00 +00:00
|
|
|
|
2018-04-23 14:40:48 +00:00
|
|
|
if (!privdom->persistent)
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjListRemove(privconn->domains, privdom);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
2018-03-22 18:42:27 +00:00
|
|
|
static int testDomainDestroy(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
return testDomainDestroyFlags(domain, 0);
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testDomainResume(virDomainPtr domain)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = domain->conn->privateData;
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
if (virDomainObjGetState(privdom, NULL) != VIR_DOMAIN_PAUSED) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, _("domain '%s' not paused"),
|
|
|
|
domain->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(privdom, VIR_DOMAIN_RUNNING,
|
|
|
|
VIR_DOMAIN_RUNNING_UNPAUSED);
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(privdom,
|
2009-01-20 20:23:53 +00:00
|
|
|
VIR_DOMAIN_EVENT_RESUMED,
|
|
|
|
VIR_DOMAIN_EVENT_RESUMED_UNPAUSED);
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testDomainSuspend(virDomainPtr domain)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = domain->conn->privateData;
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2011-05-04 09:07:01 +00:00
|
|
|
int state;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
state = virDomainObjGetState(privdom, NULL);
|
|
|
|
if (state == VIR_DOMAIN_SHUTOFF || state == VIR_DOMAIN_PAUSED) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, _("domain '%s' not running"),
|
|
|
|
domain->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(privdom, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER);
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(privdom,
|
2009-01-20 20:23:53 +00:00
|
|
|
VIR_DOMAIN_EVENT_SUSPENDED,
|
|
|
|
VIR_DOMAIN_EVENT_SUSPENDED_PAUSED);
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testDomainShutdownFlags(virDomainPtr domain,
|
2011-10-05 17:31:55 +00:00
|
|
|
unsigned int flags)
|
2006-06-14 23:58:34 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = domain->conn->privateData;
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2011-10-05 17:31:55 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
if (virDomainObjGetState(privdom, NULL) == VIR_DOMAIN_SHUTOFF) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("domain '%s' not running"), domain->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2006-06-14 23:58:34 +00:00
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
testDomainShutdownState(domain, privdom, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(privdom,
|
2009-01-20 20:23:53 +00:00
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
|
2009-11-03 17:06:00 +00:00
|
|
|
|
2018-04-23 14:40:48 +00:00
|
|
|
if (!privdom->persistent)
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjListRemove(privconn->domains, privdom);
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2009-11-03 17:06:00 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2006-06-14 23:58:34 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testDomainShutdown(virDomainPtr domain)
|
2011-10-05 17:31:55 +00:00
|
|
|
{
|
2013-04-23 12:50:18 +00:00
|
|
|
return testDomainShutdownFlags(domain, 0);
|
2011-10-05 17:31:55 +00:00
|
|
|
}
|
|
|
|
|
2006-06-14 23:58:34 +00:00
|
|
|
/* Similar behaviour as shutdown */
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testDomainReboot(virDomainPtr domain,
|
2019-06-20 09:48:57 +00:00
|
|
|
unsigned int flags)
|
2006-06-14 23:58:34 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = domain->conn->privateData;
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2019-06-20 09:48:57 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_REBOOT_DEFAULT |
|
|
|
|
VIR_DOMAIN_REBOOT_ACPI_POWER_BTN |
|
|
|
|
VIR_DOMAIN_REBOOT_GUEST_AGENT |
|
|
|
|
VIR_DOMAIN_REBOOT_INITCTL |
|
|
|
|
VIR_DOMAIN_REBOOT_SIGNAL |
|
|
|
|
VIR_DOMAIN_REBOOT_PARAVIRT, -1);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2018-04-17 22:13:28 +00:00
|
|
|
if (virDomainObjCheckActive(privdom) < 0)
|
2016-11-08 08:49:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(privdom, VIR_DOMAIN_SHUTDOWN,
|
|
|
|
VIR_DOMAIN_SHUTDOWN_USER);
|
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
switch (privdom->def->onReboot) {
|
2017-10-10 12:32:11 +00:00
|
|
|
case VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY:
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(privdom, VIR_DOMAIN_SHUTOFF,
|
|
|
|
VIR_DOMAIN_SHUTOFF_SHUTDOWN);
|
2007-01-18 21:08:21 +00:00
|
|
|
break;
|
|
|
|
|
2017-10-10 12:32:11 +00:00
|
|
|
case VIR_DOMAIN_LIFECYCLE_ACTION_RESTART:
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(privdom, VIR_DOMAIN_RUNNING,
|
|
|
|
VIR_DOMAIN_RUNNING_BOOTED);
|
2007-01-18 21:08:21 +00:00
|
|
|
break;
|
|
|
|
|
2017-10-10 12:32:11 +00:00
|
|
|
case VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE:
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(privdom, VIR_DOMAIN_SHUTOFF,
|
|
|
|
VIR_DOMAIN_SHUTOFF_SHUTDOWN);
|
2007-01-18 21:08:21 +00:00
|
|
|
break;
|
|
|
|
|
2017-10-10 12:32:11 +00:00
|
|
|
case VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME:
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(privdom, VIR_DOMAIN_RUNNING,
|
|
|
|
VIR_DOMAIN_RUNNING_BOOTED);
|
2007-01-18 21:08:21 +00:00
|
|
|
break;
|
2006-06-14 23:58:34 +00:00
|
|
|
|
2007-01-18 21:08:21 +00:00
|
|
|
default:
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(privdom, VIR_DOMAIN_SHUTOFF,
|
|
|
|
VIR_DOMAIN_SHUTOFF_SHUTDOWN);
|
2007-01-18 21:08:21 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-06-14 23:58:34 +00:00
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
if (virDomainObjGetState(privdom, NULL) == VIR_DOMAIN_SHUTOFF) {
|
|
|
|
testDomainShutdownState(domain, privdom, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(privdom,
|
2009-01-20 20:23:53 +00:00
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
|
2009-11-03 17:06:00 +00:00
|
|
|
|
2018-04-23 14:40:48 +00:00
|
|
|
if (!privdom->persistent)
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjListRemove(privconn->domains, privdom);
|
2008-12-04 20:59:06 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2006-06-14 23:58:34 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 14:31:35 +00:00
|
|
|
|
|
|
|
static char *
|
|
|
|
testDomainGetHostname(virDomainPtr domain,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
char *ret = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainObjCheckActive(vm) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ignore_value(virAsprintf(&ret, "%shost", domain->name));
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainObjEndAPI(&vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testDomainGetInfo(virDomainPtr domain,
|
2012-10-17 09:23:12 +00:00
|
|
|
virDomainInfoPtr info)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2007-01-18 21:08:21 +00:00
|
|
|
struct timeval tv;
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
|
|
|
if (gettimeofday(&tv, NULL) < 0) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("getting time of day"));
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
info->state = virDomainObjGetState(privdom, NULL);
|
2010-10-12 14:43:39 +00:00
|
|
|
info->memory = privdom->def->mem.cur_balloon;
|
2016-06-15 13:34:04 +00:00
|
|
|
info->maxMem = virDomainDefGetMemoryTotal(privdom->def);
|
2015-10-22 12:59:03 +00:00
|
|
|
info->nrVirtCpu = virDomainDefGetVcpus(privdom->def);
|
2008-07-11 16:41:27 +00:00
|
|
|
info->cpuTime = ((tv.tv_sec * 1000ll * 1000ll * 1000ll) + (tv.tv_usec * 1000ll));
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2006-08-16 16:36:39 +00:00
|
|
|
}
|
|
|
|
|
2011-05-02 09:35:29 +00:00
|
|
|
static int
|
|
|
|
testDomainGetState(virDomainPtr domain,
|
|
|
|
int *state,
|
|
|
|
int *reason,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr privdom;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2011-05-02 09:35:29 +00:00
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
*state = virDomainObjGetState(privdom, reason);
|
2011-05-02 09:35:29 +00:00
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2015-06-16 16:18:03 +00:00
|
|
|
|
|
|
|
return 0;
|
2011-05-02 09:35:29 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 16:57:57 +00:00
|
|
|
static int
|
2019-06-20 11:41:01 +00:00
|
|
|
testDomainGetTime(virDomainPtr dom,
|
2019-04-24 16:57:57 +00:00
|
|
|
long long *seconds,
|
|
|
|
unsigned int *nseconds,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2019-06-20 11:41:01 +00:00
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
2019-04-24 16:57:57 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2019-06-20 11:41:01 +00:00
|
|
|
if (!(vm = testDomObjFromDomain(dom)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("domain is not running"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2019-04-24 16:57:57 +00:00
|
|
|
*seconds = 627319920;
|
|
|
|
*nseconds = 0;
|
|
|
|
|
2019-06-20 11:41:01 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
virDomainObjEndAPI(&vm);
|
|
|
|
return ret;
|
2019-04-24 16:57:57 +00:00
|
|
|
}
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
#define TEST_SAVE_MAGIC "TestGuestMagic"
|
|
|
|
|
2019-06-10 09:04:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testDomainSaveImageWrite:
|
|
|
|
* @driver: test driver data
|
|
|
|
* @def: domain definition whose XML will be stored in the image
|
|
|
|
* @path: path to the saved image
|
|
|
|
*
|
|
|
|
* Returns true on success, else false.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
testDomainSaveImageWrite(testDriverPtr driver,
|
|
|
|
const char *path,
|
|
|
|
virDomainDefPtr def)
|
2007-07-27 23:23:00 +00:00
|
|
|
{
|
2008-12-04 20:57:47 +00:00
|
|
|
int len;
|
2019-06-10 09:04:58 +00:00
|
|
|
int fd = -1;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(char *) xml = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2019-06-10 09:04:58 +00:00
|
|
|
xml = virDomainDefFormat(def, driver->caps, VIR_DOMAIN_DEF_FORMAT_SECURE);
|
2009-03-16 17:14:34 +00:00
|
|
|
|
2008-01-30 19:52:16 +00:00
|
|
|
if (xml == NULL) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("saving domain '%s' failed to allocate space for metadata"),
|
2019-06-10 09:04:58 +00:00
|
|
|
def->name);
|
|
|
|
goto error;
|
2008-01-30 19:52:16 +00:00
|
|
|
}
|
2007-07-27 23:23:00 +00:00
|
|
|
|
|
|
|
if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("saving domain '%s' to '%s': open failed"),
|
2019-06-10 09:04:58 +00:00
|
|
|
def->name, path);
|
|
|
|
goto error;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2019-06-10 09:04:58 +00:00
|
|
|
|
Use safewrite in place of write, in many cases.
Also add "make syntax-check" rules to ensure no new uses sneak in.
There are many uses of write like this:
if (write (fd, xml, towrite) != towrite)
return -1;
The problem is that the syscall can succeed, yet write less than
the requested number of bytes, so the caller should retry
rather than simply failing.
This patch changes most of them to use util.c's safewrite wrapper,
which encapsulates the process. Also, there were a few cases in
which the retry loop was open-coded, and I replaced those, too.
* Makefile.maint (sc_avoid_write): New rule, to avoid recurrence.
* .x-sc_avoid_write: New file. Record two legitimate exemptions.
* qemud/qemud.c (sig_handler, qemudClientWriteBuf): Use safewrite, not write.
* src/conf.c (__virConfWriteFile): Likewise.
* src/qemu_conf.c (qemudSaveConfig, qemudSaveNetworkConfig): Likewise.
* src/qemu_driver.c (qemudWaitForMonitor, qemudStartVMDaemon)
(qemudVMData, PROC_IP_FORWARD): Likewise.
* proxy/libvirt_proxy.c: Include "util.h".
(proxyWriteClientSocket): Use safewrite.
* src/test.c (testDomainSave, testDomainCoreDump): Likewise.
* src/proxy_internal.c (virProxyWriteClientSocket): Likewise.
* src/virsh.c: Include "util-lib.h".
(vshOutputLogFile): Use safewrite.
* src/console.c: Include "util-lib.h".
(vshRunConsole): Use safewrite.
2008-02-22 15:55:04 +00:00
|
|
|
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("saving domain '%s' to '%s': write failed"),
|
2019-06-10 09:04:58 +00:00
|
|
|
def->name, path);
|
|
|
|
goto error;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2019-06-10 09:04:58 +00:00
|
|
|
|
|
|
|
len = strlen(xml);
|
Use safewrite in place of write, in many cases.
Also add "make syntax-check" rules to ensure no new uses sneak in.
There are many uses of write like this:
if (write (fd, xml, towrite) != towrite)
return -1;
The problem is that the syscall can succeed, yet write less than
the requested number of bytes, so the caller should retry
rather than simply failing.
This patch changes most of them to use util.c's safewrite wrapper,
which encapsulates the process. Also, there were a few cases in
which the retry loop was open-coded, and I replaced those, too.
* Makefile.maint (sc_avoid_write): New rule, to avoid recurrence.
* .x-sc_avoid_write: New file. Record two legitimate exemptions.
* qemud/qemud.c (sig_handler, qemudClientWriteBuf): Use safewrite, not write.
* src/conf.c (__virConfWriteFile): Likewise.
* src/qemu_conf.c (qemudSaveConfig, qemudSaveNetworkConfig): Likewise.
* src/qemu_driver.c (qemudWaitForMonitor, qemudStartVMDaemon)
(qemudVMData, PROC_IP_FORWARD): Likewise.
* proxy/libvirt_proxy.c: Include "util.h".
(proxyWriteClientSocket): Use safewrite.
* src/test.c (testDomainSave, testDomainCoreDump): Likewise.
* src/proxy_internal.c (virProxyWriteClientSocket): Likewise.
* src/virsh.c: Include "util-lib.h".
(vshOutputLogFile): Use safewrite.
* src/console.c: Include "util-lib.h".
(vshRunConsole): Use safewrite.
2008-02-22 15:55:04 +00:00
|
|
|
if (safewrite(fd, (char*)&len, sizeof(len)) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("saving domain '%s' to '%s': write failed"),
|
2019-06-10 09:04:58 +00:00
|
|
|
def->name, path);
|
|
|
|
goto error;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2019-06-10 09:04:58 +00:00
|
|
|
|
Use safewrite in place of write, in many cases.
Also add "make syntax-check" rules to ensure no new uses sneak in.
There are many uses of write like this:
if (write (fd, xml, towrite) != towrite)
return -1;
The problem is that the syscall can succeed, yet write less than
the requested number of bytes, so the caller should retry
rather than simply failing.
This patch changes most of them to use util.c's safewrite wrapper,
which encapsulates the process. Also, there were a few cases in
which the retry loop was open-coded, and I replaced those, too.
* Makefile.maint (sc_avoid_write): New rule, to avoid recurrence.
* .x-sc_avoid_write: New file. Record two legitimate exemptions.
* qemud/qemud.c (sig_handler, qemudClientWriteBuf): Use safewrite, not write.
* src/conf.c (__virConfWriteFile): Likewise.
* src/qemu_conf.c (qemudSaveConfig, qemudSaveNetworkConfig): Likewise.
* src/qemu_driver.c (qemudWaitForMonitor, qemudStartVMDaemon)
(qemudVMData, PROC_IP_FORWARD): Likewise.
* proxy/libvirt_proxy.c: Include "util.h".
(proxyWriteClientSocket): Use safewrite.
* src/test.c (testDomainSave, testDomainCoreDump): Likewise.
* src/proxy_internal.c (virProxyWriteClientSocket): Likewise.
* src/virsh.c: Include "util-lib.h".
(vshOutputLogFile): Use safewrite.
* src/console.c: Include "util-lib.h".
(vshRunConsole): Use safewrite.
2008-02-22 15:55:04 +00:00
|
|
|
if (safewrite(fd, xml, len) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("saving domain '%s' to '%s': write failed"),
|
2019-06-10 09:04:58 +00:00
|
|
|
def->name, path);
|
|
|
|
goto error;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2010-11-09 20:48:48 +00:00
|
|
|
if (VIR_CLOSE(fd) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("saving domain '%s' to '%s': write failed"),
|
2019-06-10 09:04:58 +00:00
|
|
|
def->name, path);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Don't report failure in close or unlink, because
|
|
|
|
* in either case we're already in a failure scenario
|
|
|
|
* and have reported an earlier error */
|
|
|
|
VIR_FORCE_CLOSE(fd);
|
|
|
|
unlink(path);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-10 09:04:59 +00:00
|
|
|
/**
|
|
|
|
* testDomainSaveImageOpen:
|
|
|
|
* @driver: test driver data
|
|
|
|
* @path: path of the saved image
|
|
|
|
* @ret_def: returns domain definition created from the XML stored in the image
|
|
|
|
*
|
|
|
|
* Returns the opened fd of the save image file and fills ret_def on success.
|
|
|
|
* Returns -1, on error.
|
|
|
|
*/
|
|
|
|
static int ATTRIBUTE_NONNULL(3)
|
|
|
|
testDomainSaveImageOpen(testDriverPtr driver,
|
|
|
|
const char *path,
|
|
|
|
virDomainDefPtr *ret_def)
|
|
|
|
{
|
|
|
|
char magic[15];
|
|
|
|
int fd = -1;
|
|
|
|
int len;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
VIR_AUTOFREE(char *) xml = NULL;
|
|
|
|
|
|
|
|
if ((fd = open(path, O_RDONLY)) < 0) {
|
|
|
|
virReportSystemError(errno, _("cannot read domain image '%s'"), path);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (saferead(fd, magic, sizeof(magic)) != sizeof(magic)) {
|
|
|
|
virReportSystemError(errno, _("incomplete save header in '%s'"), path);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(magic, TEST_SAVE_MAGIC, sizeof(magic))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("mismatched header magic"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (saferead(fd, (char*)&len, sizeof(len)) != sizeof(len)) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("failed to read metadata length in '%s'"),
|
|
|
|
path);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len < 1 || len > 8192) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("length of metadata out of range"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(xml, len+1) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (saferead(fd, xml, len) != len) {
|
|
|
|
virReportSystemError(errno, _("incomplete metadata in '%s'"), path);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
xml[len] = '\0';
|
|
|
|
|
|
|
|
if (!(def = virDomainDefParseString(xml, driver->caps, driver->xmlopt, NULL,
|
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE |
|
|
|
|
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
VIR_STEAL_PTR(*ret_def, def);
|
|
|
|
return fd;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virDomainDefFree(def);
|
|
|
|
VIR_FORCE_CLOSE(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-10 09:04:58 +00:00
|
|
|
static int
|
|
|
|
testDomainSaveFlags(virDomainPtr domain, const char *path,
|
|
|
|
const char *dxml, unsigned int flags)
|
|
|
|
{
|
|
|
|
testDriverPtr privconn = domain->conn->privateData;
|
|
|
|
virDomainObjPtr privdom;
|
|
|
|
virObjectEventPtr event = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (dxml) {
|
|
|
|
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
|
|
|
|
_("xml modification unsupported"));
|
|
|
|
return -1;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2019-06-10 09:04:58 +00:00
|
|
|
|
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainObjCheckActive(privdom) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!testDomainSaveImageWrite(privconn, path, privdom->def))
|
|
|
|
goto cleanup;
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
testDomainShutdownState(domain, privdom, VIR_DOMAIN_SHUTOFF_SAVED);
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(privdom,
|
2009-01-20 20:23:53 +00:00
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_SAVED);
|
2009-11-03 17:06:00 +00:00
|
|
|
|
2018-04-23 14:40:48 +00:00
|
|
|
if (!privdom->persistent)
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjListRemove(privconn->domains, privdom);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2009-11-03 17:06:00 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
save: wire up trivial save/restore flags implementations
For all hypervisors that support save and restore, the new API
now performs the same functions as the old.
VBox is excluded from this list, because its existing domainsave
is broken (there is no corresponding domainrestore, and there
is no control over the filename used in the save). A later
patch should change vbox to use its implementation for
managedsave, and teach start to use managedsave results.
* src/libxl/libxl_driver.c (libxlDomainSave): Move guts...
(libxlDomainSaveFlags): ...to new function.
(libxlDomainRestore): Move guts...
(libxlDomainRestoreFlags): ...to new function.
* src/test/test_driver.c (testDomainSave, testDomainSaveFlags)
(testDomainRestore, testDomainRestoreFlags): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSave)
(xenUnifiedDomainSaveFlags, xenUnifiedDomainRestore)
(xenUnifiedDomainRestoreFlags): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSave, qemudDomainRestore):
Rename and move guts.
(qemuDomainSave, qemuDomainSaveFlags, qemuDomainRestore)
(qemuDomainRestoreFlags): ...here.
(qemudDomainSaveFlag): Rename...
(qemuDomainSaveInternal): ...to this, and update callers.
2011-07-09 02:55:29 +00:00
|
|
|
static int
|
|
|
|
testDomainSave(virDomainPtr domain,
|
|
|
|
const char *path)
|
|
|
|
{
|
|
|
|
return testDomainSaveFlags(domain, path, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainRestoreFlags(virConnectPtr conn,
|
|
|
|
const char *path,
|
|
|
|
const char *dxml,
|
|
|
|
unsigned int flags)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2008-12-04 20:57:47 +00:00
|
|
|
int fd = -1;
|
|
|
|
virDomainDefPtr def = NULL;
|
2008-12-04 20:59:06 +00:00
|
|
|
virDomainObjPtr dom = NULL;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
save: wire up trivial save/restore flags implementations
For all hypervisors that support save and restore, the new API
now performs the same functions as the old.
VBox is excluded from this list, because its existing domainsave
is broken (there is no corresponding domainrestore, and there
is no control over the filename used in the save). A later
patch should change vbox to use its implementation for
managedsave, and teach start to use managedsave results.
* src/libxl/libxl_driver.c (libxlDomainSave): Move guts...
(libxlDomainSaveFlags): ...to new function.
(libxlDomainRestore): Move guts...
(libxlDomainRestoreFlags): ...to new function.
* src/test/test_driver.c (testDomainSave, testDomainSaveFlags)
(testDomainRestore, testDomainRestoreFlags): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSave)
(xenUnifiedDomainSaveFlags, xenUnifiedDomainRestore)
(xenUnifiedDomainRestoreFlags): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSave, qemudDomainRestore):
Rename and move guts.
(qemuDomainSave, qemuDomainSaveFlags, qemuDomainRestore)
(qemuDomainRestoreFlags): ...here.
(qemudDomainSaveFlag): Rename...
(qemuDomainSaveInternal): ...to this, and update callers.
2011-07-09 02:55:29 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
if (dxml) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
|
|
|
|
_("xml modification unsupported"));
|
save: wire up trivial save/restore flags implementations
For all hypervisors that support save and restore, the new API
now performs the same functions as the old.
VBox is excluded from this list, because its existing domainsave
is broken (there is no corresponding domainrestore, and there
is no control over the filename used in the save). A later
patch should change vbox to use its implementation for
managedsave, and teach start to use managedsave results.
* src/libxl/libxl_driver.c (libxlDomainSave): Move guts...
(libxlDomainSaveFlags): ...to new function.
(libxlDomainRestore): Move guts...
(libxlDomainRestoreFlags): ...to new function.
* src/test/test_driver.c (testDomainSave, testDomainSaveFlags)
(testDomainRestore, testDomainRestoreFlags): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSave)
(xenUnifiedDomainSaveFlags, xenUnifiedDomainRestore)
(xenUnifiedDomainRestoreFlags): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSave, qemudDomainRestore):
Rename and move guts.
(qemuDomainSave, qemuDomainSaveFlags, qemuDomainRestore)
(qemuDomainRestoreFlags): ...here.
(qemudDomainSaveFlag): Rename...
(qemuDomainSaveInternal): ...to this, and update callers.
2011-07-09 02:55:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-06-10 09:04:59 +00:00
|
|
|
if ((fd = testDomainSaveImageOpen(privconn, path, &def)) < 0)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-07-11 16:41:27 +00:00
|
|
|
|
2010-04-02 21:56:10 +00:00
|
|
|
if (testDomainGenerateIfnames(def) < 0)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2013-01-11 16:04:47 +00:00
|
|
|
if (!(dom = virDomainObjListAdd(privconn->domains,
|
Merge virDomainObjListIsDuplicate into virDomainObjListAdd
The duplicate VM checking should be done atomically with
virDomainObjListAdd, so shoud not be a separate function.
Instead just use flags to indicate what kind of checks are
required.
This pair, used in virDomainCreateXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainRestoreFlags:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, true)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainDefineXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 0) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
0, NULL)))
goto cleanup;
2013-01-14 14:46:58 +00:00
|
|
|
def,
|
2013-03-28 13:55:55 +00:00
|
|
|
privconn->xmlopt,
|
Merge virDomainObjListIsDuplicate into virDomainObjListAdd
The duplicate VM checking should be done atomically with
virDomainObjListAdd, so shoud not be a separate function.
Instead just use flags to indicate what kind of checks are
required.
This pair, used in virDomainCreateXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainRestoreFlags:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, true)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainDefineXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 0) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
0, NULL)))
goto cleanup;
2013-01-14 14:46:58 +00:00
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
|
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
|
|
|
|
NULL)))
|
2009-09-02 13:02:06 +00:00
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2015-09-23 12:13:53 +00:00
|
|
|
if (testDomainStartState(privconn, dom, VIR_DOMAIN_RUNNING_RESTORED) < 0) {
|
2018-04-23 14:40:48 +00:00
|
|
|
if (!dom->persistent)
|
2015-09-23 12:13:53 +00:00
|
|
|
virDomainObjListRemove(privconn->domains, dom);
|
2009-10-27 17:15:44 +00:00
|
|
|
goto cleanup;
|
2015-09-23 12:13:53 +00:00
|
|
|
}
|
2009-10-27 17:15:44 +00:00
|
|
|
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(dom,
|
2009-01-20 20:23:53 +00:00
|
|
|
VIR_DOMAIN_EVENT_STARTED,
|
|
|
|
VIR_DOMAIN_EVENT_STARTED_RESTORED);
|
2009-04-03 14:14:05 +00:00
|
|
|
ret = 0;
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2008-12-04 20:57:47 +00:00
|
|
|
virDomainDefFree(def);
|
2010-11-09 20:48:48 +00:00
|
|
|
VIR_FORCE_CLOSE(fd);
|
2018-04-23 14:40:48 +00:00
|
|
|
virDomainObjEndAPI(&dom);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2006-08-16 16:36:39 +00:00
|
|
|
}
|
|
|
|
|
save: wire up trivial save/restore flags implementations
For all hypervisors that support save and restore, the new API
now performs the same functions as the old.
VBox is excluded from this list, because its existing domainsave
is broken (there is no corresponding domainrestore, and there
is no control over the filename used in the save). A later
patch should change vbox to use its implementation for
managedsave, and teach start to use managedsave results.
* src/libxl/libxl_driver.c (libxlDomainSave): Move guts...
(libxlDomainSaveFlags): ...to new function.
(libxlDomainRestore): Move guts...
(libxlDomainRestoreFlags): ...to new function.
* src/test/test_driver.c (testDomainSave, testDomainSaveFlags)
(testDomainRestore, testDomainRestoreFlags): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSave)
(xenUnifiedDomainSaveFlags, xenUnifiedDomainRestore)
(xenUnifiedDomainRestoreFlags): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSave, qemudDomainRestore):
Rename and move guts.
(qemuDomainSave, qemuDomainSaveFlags, qemuDomainRestore)
(qemuDomainRestoreFlags): ...here.
(qemudDomainSaveFlag): Rename...
(qemuDomainSaveInternal): ...to this, and update callers.
2011-07-09 02:55:29 +00:00
|
|
|
static int
|
|
|
|
testDomainRestore(virConnectPtr conn,
|
|
|
|
const char *path)
|
|
|
|
{
|
|
|
|
return testDomainRestoreFlags(conn, path, NULL, 0);
|
|
|
|
}
|
|
|
|
|
2019-06-10 09:05:00 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSaveImageDefineXML(virConnectPtr conn,
|
|
|
|
const char *path,
|
|
|
|
const char *dxml,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int fd = -1;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
virDomainDefPtr newdef = NULL;
|
|
|
|
testDriverPtr privconn = conn->privateData;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SAVE_RUNNING |
|
|
|
|
VIR_DOMAIN_SAVE_PAUSED, -1);
|
|
|
|
|
|
|
|
if ((fd = testDomainSaveImageOpen(privconn, path, &def)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
VIR_FORCE_CLOSE(fd);
|
|
|
|
|
|
|
|
if ((newdef = virDomainDefParseString(dxml, privconn->caps, privconn->xmlopt, NULL,
|
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE)) == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!testDomainSaveImageWrite(privconn, path, newdef))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainDefFree(def);
|
|
|
|
virDomainDefFree(newdef);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-10 09:05:01 +00:00
|
|
|
static char *
|
|
|
|
testDomainSaveImageGetXMLDesc(virConnectPtr conn,
|
|
|
|
const char *path,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int fd = -1;
|
|
|
|
char *ret = NULL;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
testDriverPtr privconn = conn->privateData;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SAVE_IMAGE_XML_SECURE, NULL);
|
|
|
|
|
|
|
|
if ((fd = testDomainSaveImageOpen(privconn, path, &def)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = virDomainDefFormat(def, privconn->caps, VIR_DOMAIN_DEF_FORMAT_SECURE);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainDefFree(def);
|
|
|
|
VIR_FORCE_CLOSE(fd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-23 03:51:12 +00:00
|
|
|
static int testDomainCoreDumpWithFormat(virDomainPtr domain,
|
|
|
|
const char *to,
|
|
|
|
unsigned int dumpformat,
|
|
|
|
unsigned int flags)
|
2006-08-16 16:36:39 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = domain->conn->privateData;
|
2008-12-04 20:57:47 +00:00
|
|
|
int fd = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(VIR_DUMP_CRASH, -1);
|
|
|
|
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2018-04-17 22:13:28 +00:00
|
|
|
if (virDomainObjCheckActive(privdom) < 0)
|
2016-11-08 08:49:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
if ((fd = open(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("domain '%s' coredump: failed to open %s"),
|
|
|
|
domain->name, to);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
Use safewrite in place of write, in many cases.
Also add "make syntax-check" rules to ensure no new uses sneak in.
There are many uses of write like this:
if (write (fd, xml, towrite) != towrite)
return -1;
The problem is that the syscall can succeed, yet write less than
the requested number of bytes, so the caller should retry
rather than simply failing.
This patch changes most of them to use util.c's safewrite wrapper,
which encapsulates the process. Also, there were a few cases in
which the retry loop was open-coded, and I replaced those, too.
* Makefile.maint (sc_avoid_write): New rule, to avoid recurrence.
* .x-sc_avoid_write: New file. Record two legitimate exemptions.
* qemud/qemud.c (sig_handler, qemudClientWriteBuf): Use safewrite, not write.
* src/conf.c (__virConfWriteFile): Likewise.
* src/qemu_conf.c (qemudSaveConfig, qemudSaveNetworkConfig): Likewise.
* src/qemu_driver.c (qemudWaitForMonitor, qemudStartVMDaemon)
(qemudVMData, PROC_IP_FORWARD): Likewise.
* proxy/libvirt_proxy.c: Include "util.h".
(proxyWriteClientSocket): Use safewrite.
* src/test.c (testDomainSave, testDomainCoreDump): Likewise.
* src/proxy_internal.c (virProxyWriteClientSocket): Likewise.
* src/virsh.c: Include "util-lib.h".
(vshOutputLogFile): Use safewrite.
* src/console.c: Include "util-lib.h".
(vshRunConsole): Use safewrite.
2008-02-22 15:55:04 +00:00
|
|
|
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("domain '%s' coredump: failed to write header to %s"),
|
|
|
|
domain->name, to);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2010-11-09 20:48:48 +00:00
|
|
|
if (VIR_CLOSE(fd) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("domain '%s' coredump: write failed: %s"),
|
|
|
|
domain->name, to);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2009-11-03 17:06:00 +00:00
|
|
|
|
2014-03-23 03:51:12 +00:00
|
|
|
/* we don't support non-raw formats in test driver */
|
|
|
|
if (dumpformat != VIR_DOMAIN_CORE_DUMP_FORMAT_RAW) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("kdump-compressed format is not supported here"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-12-14 10:59:27 +00:00
|
|
|
if (flags & VIR_DUMP_CRASH) {
|
2011-05-04 09:07:01 +00:00
|
|
|
testDomainShutdownState(domain, privdom, VIR_DOMAIN_SHUTOFF_CRASHED);
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(privdom,
|
2009-12-14 10:59:27 +00:00
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_CRASHED);
|
2018-04-23 14:40:48 +00:00
|
|
|
if (!privdom->persistent)
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjListRemove(privconn->domains, privdom);
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2009-11-03 17:06:00 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2010-11-09 20:48:48 +00:00
|
|
|
VIR_FORCE_CLOSE(fd);
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 03:51:12 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainCoreDump(virDomainPtr domain,
|
|
|
|
const char *to,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
return testDomainCoreDumpWithFormat(domain, to,
|
|
|
|
VIR_DOMAIN_CORE_DUMP_FORMAT_RAW, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
testDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2013-05-03 12:49:30 +00:00
|
|
|
char *ret;
|
|
|
|
|
|
|
|
ignore_value(VIR_STRDUP(ret, "linux"));
|
2008-07-11 16:41:27 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 03:51:12 +00:00
|
|
|
|
2019-06-11 11:07:26 +00:00
|
|
|
static int
|
|
|
|
testDomainGetLaunchSecurityInfo(virDomainPtr domain ATTRIBUTE_UNUSED,
|
|
|
|
virTypedParameterPtr *params ATTRIBUTE_UNUSED,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
*nparams = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-23 03:51:12 +00:00
|
|
|
static unsigned long long
|
|
|
|
testDomainGetMaxMemory(virDomainPtr domain)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
xml: use long long internally, to centralize overflow checks
On 64-bit platforms, unsigned long and unsigned long long are
identical, so we don't have to worry about overflow checks.
On 32-bit platforms, anywhere we narrow unsigned long long back
to unsigned long, we have to worry about overflow; it's easier
to do this in one place by having most of the code use the same
or wider types, and only doing the narrowing at the last minute.
Therefore, the memory set commands remain unsigned long, and
the memory get command now centralizes the overflow check into
libvirt.c, so that drivers don't have to repeat the work.
This also fixes a bug where xen returned the wrong value on
failure (most APIs return -1 on failure, but getMaxMemory
must return 0 on failure).
* src/driver.h (virDrvDomainGetMaxMemory): Use long long.
* src/libvirt.c (virDomainGetMaxMemory): Raise overflow.
* src/test/test_driver.c (testGetMaxMemory): Fix driver.
* src/rpc/gendispatch.pl (name_to_ProcName): Likewise.
* src/xen/xen_hypervisor.c (xenHypervisorGetMaxMemory): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainGetMaxMemory): Likewise.
* src/xen/xend_internal.c (xenDaemonDomainGetMaxMemory):
Likewise.
* src/xen/xend_internal.h (xenDaemonDomainGetMaxMemory):
Likewise.
* src/xen/xm_internal.c (xenXMDomainGetMaxMemory): Likewise.
* src/xen/xm_internal.h (xenXMDomainGetMaxMemory): Likewise.
* src/xen/xs_internal.c (xenStoreDomainGetMaxMemory): Likewise.
* src/xen/xs_internal.h (xenStoreDomainGetMaxMemory): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainGetMaxMemory):
Likewise.
* src/esx/esx_driver.c (esxDomainGetMaxMemory): Likewise.
* src/libxl/libxl_driver.c (libxlDomainGetMaxMemory): Likewise.
* src/qemu/qemu_driver.c (qemudDomainGetMaxMemory): Likewise.
* src/lxc/lxc_driver.c (lxcDomainGetMaxMemory): Likewise.
* src/uml/uml_driver.c (umlDomainGetMaxMemory): Likewise.
2012-03-03 00:47:16 +00:00
|
|
|
unsigned long long ret = 0;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return 0;
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2016-06-15 13:34:04 +00:00
|
|
|
ret = virDomainDefGetMemoryTotal(privdom->def);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testDomainSetMaxMemory(virDomainPtr domain,
|
|
|
|
unsigned long memory)
|
2007-07-27 23:23:00 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
|
|
|
/* XXX validate not over host memory wrt to other domains */
|
2015-09-16 12:25:42 +00:00
|
|
|
virDomainDefSetMemoryTotal(privdom->def, memory);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2015-06-16 16:18:03 +00:00
|
|
|
return 0;
|
2006-08-16 16:36:39 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testDomainSetMemory(virDomainPtr domain,
|
|
|
|
unsigned long memory)
|
2007-07-27 23:23:00 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2016-06-15 13:34:04 +00:00
|
|
|
if (memory > virDomainDefGetMemoryTotal(privdom->def)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2010-10-12 14:43:39 +00:00
|
|
|
privdom->def->mem.cur_balloon = memory;
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
static int
|
|
|
|
testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
|
2009-10-27 22:00:02 +00:00
|
|
|
{
|
2010-10-04 23:01:12 +00:00
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainDefPtr def;
|
|
|
|
int ret = -1;
|
|
|
|
|
2011-06-08 06:33:33 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
|
|
|
VIR_DOMAIN_AFFECT_CONFIG |
|
2010-10-04 23:01:12 +00:00
|
|
|
VIR_DOMAIN_VCPU_MAXIMUM, -1);
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2010-10-04 23:01:12 +00:00
|
|
|
|
2015-06-16 08:10:59 +00:00
|
|
|
if (!(def = virDomainObjGetOneDef(vm, flags)))
|
2011-12-12 05:16:49 +00:00
|
|
|
goto cleanup;
|
2011-07-15 23:35:47 +00:00
|
|
|
|
2015-10-19 17:21:24 +00:00
|
|
|
if (flags & VIR_DOMAIN_VCPU_MAXIMUM)
|
|
|
|
ret = virDomainDefGetVcpusMax(def);
|
|
|
|
else
|
2015-10-22 12:59:03 +00:00
|
|
|
ret = virDomainDefGetVcpus(def);
|
2010-10-04 23:01:12 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-06-16 16:18:03 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2010-10-04 23:01:12 +00:00
|
|
|
return ret;
|
2009-10-27 22:00:02 +00:00
|
|
|
}
|
|
|
|
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
static int
|
|
|
|
testDomainGetMaxVcpus(virDomainPtr domain)
|
|
|
|
{
|
2011-06-08 06:33:33 +00:00
|
|
|
return testDomainGetVcpusFlags(domain, (VIR_DOMAIN_AFFECT_LIVE |
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
VIR_DOMAIN_VCPU_MAXIMUM));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2016-06-29 12:55:24 +00:00
|
|
|
testDriverPtr driver = domain->conn->privateData;
|
2009-11-16 16:31:35 +00:00
|
|
|
virDomainObjPtr privdom = NULL;
|
2015-06-16 17:15:27 +00:00
|
|
|
virDomainDefPtr def;
|
2010-11-19 19:51:46 +00:00
|
|
|
virDomainDefPtr persistentDef;
|
2009-10-27 22:00:02 +00:00
|
|
|
int ret = -1, maxvcpus;
|
|
|
|
|
2011-06-08 06:33:33 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
|
|
|
VIR_DOMAIN_AFFECT_CONFIG |
|
2010-10-04 23:01:12 +00:00
|
|
|
VIR_DOMAIN_VCPU_MAXIMUM, -1);
|
|
|
|
|
2015-06-16 17:15:27 +00:00
|
|
|
if ((maxvcpus = testConnectGetMaxVcpus(domain->conn, NULL)) < 0)
|
2010-10-04 23:01:12 +00:00
|
|
|
return -1;
|
2015-06-16 17:15:27 +00:00
|
|
|
|
|
|
|
if (nrCpus > maxvcpus) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
2015-06-16 17:15:27 +00:00
|
|
|
_("requested cpu amount exceeds maximum supported amount "
|
|
|
|
"(%d > %d)"), nrCpus, maxvcpus);
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2015-06-16 17:15:27 +00:00
|
|
|
if (virDomainObjGetDefs(privdom, flags, &def, &persistentDef) < 0)
|
2009-10-27 22:00:02 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-10-19 17:21:24 +00:00
|
|
|
if (def && virDomainDefGetVcpusMax(def) < nrCpus) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("requested cpu amount exceeds maximum (%d > %d)"),
|
2015-10-19 17:21:24 +00:00
|
|
|
nrCpus, virDomainDefGetVcpusMax(def));
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2015-06-16 17:15:27 +00:00
|
|
|
if (persistentDef &&
|
|
|
|
!(flags & VIR_DOMAIN_VCPU_MAXIMUM) &&
|
2015-10-19 17:21:24 +00:00
|
|
|
virDomainDefGetVcpusMax(persistentDef) < nrCpus) {
|
2015-06-16 17:15:27 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("requested cpu amount exceeds maximum (%d > %d)"),
|
2015-10-19 17:21:24 +00:00
|
|
|
nrCpus, virDomainDefGetVcpusMax(persistentDef));
|
2010-11-19 19:51:46 +00:00
|
|
|
goto cleanup;
|
2015-06-16 17:15:27 +00:00
|
|
|
}
|
2010-11-19 19:51:46 +00:00
|
|
|
|
2015-10-22 08:52:05 +00:00
|
|
|
if (def &&
|
|
|
|
virDomainDefSetVcpus(def, nrCpus) < 0)
|
|
|
|
goto cleanup;
|
2010-10-04 23:01:12 +00:00
|
|
|
|
2015-06-16 17:15:27 +00:00
|
|
|
if (persistentDef) {
|
|
|
|
if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
|
2016-06-29 12:55:24 +00:00
|
|
|
if (virDomainDefSetVcpusMax(persistentDef, nrCpus,
|
|
|
|
driver->xmlopt) < 0)
|
2015-10-16 14:10:27 +00:00
|
|
|
goto cleanup;
|
2015-06-16 17:15:27 +00:00
|
|
|
} else {
|
2015-10-22 08:52:05 +00:00
|
|
|
if (virDomainDefSetVcpus(persistentDef, nrCpus) < 0)
|
|
|
|
goto cleanup;
|
2015-06-16 17:15:27 +00:00
|
|
|
}
|
2010-10-04 23:01:12 +00:00
|
|
|
}
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2015-06-16 17:15:27 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-06-16 16:18:03 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2006-08-16 16:36:39 +00:00
|
|
|
}
|
|
|
|
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testDomainSetVcpus(virDomainPtr domain, unsigned int nrCpus)
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
{
|
2011-06-08 06:33:33 +00:00
|
|
|
return testDomainSetVcpusFlags(domain, nrCpus, VIR_DOMAIN_AFFECT_LIVE);
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
}
|
|
|
|
|
2009-10-21 19:04:14 +00:00
|
|
|
static int testDomainGetVcpus(virDomainPtr domain,
|
|
|
|
virVcpuInfoPtr info,
|
|
|
|
int maxinfo,
|
|
|
|
unsigned char *cpumaps,
|
|
|
|
int maplen)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = domain->conn->privateData;
|
2009-10-21 19:04:14 +00:00
|
|
|
virDomainObjPtr privdom;
|
2015-06-17 09:05:21 +00:00
|
|
|
virDomainDefPtr def;
|
Convert 'int i' to 'size_t i' in src/test/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2017-04-13 02:16:07 +00:00
|
|
|
int hostcpus;
|
2009-10-21 19:04:14 +00:00
|
|
|
int ret = -1;
|
|
|
|
struct timeval tv;
|
|
|
|
unsigned long long statbase;
|
2015-06-17 09:05:21 +00:00
|
|
|
virBitmapPtr allcpumap = NULL;
|
2009-10-21 19:04:14 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2009-10-21 19:04:14 +00:00
|
|
|
|
|
|
|
if (!virDomainObjIsActive(privdom)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2013-11-19 23:04:25 +00:00
|
|
|
"%s", _("cannot list vcpus for an inactive domain"));
|
2009-10-21 19:04:14 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-06-17 09:05:21 +00:00
|
|
|
def = privdom->def;
|
2009-10-21 19:04:14 +00:00
|
|
|
|
|
|
|
if (gettimeofday(&tv, NULL) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-10-21 19:04:14 +00:00
|
|
|
"%s", _("getting time of day"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
statbase = (tv.tv_sec * 1000UL * 1000UL) + tv.tv_usec;
|
|
|
|
|
|
|
|
hostcpus = VIR_NODEINFO_MAXCPUS(privconn->nodeInfo);
|
2015-06-17 09:05:21 +00:00
|
|
|
if (!(allcpumap = virBitmapNew(hostcpus)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
virBitmapSetAll(allcpumap);
|
|
|
|
|
2009-10-21 19:04:14 +00:00
|
|
|
/* Clamp to actual number of vcpus */
|
2015-10-22 12:59:03 +00:00
|
|
|
if (maxinfo > virDomainDefGetVcpus(privdom->def))
|
|
|
|
maxinfo = virDomainDefGetVcpus(privdom->def);
|
2009-10-21 19:04:14 +00:00
|
|
|
|
2015-06-17 09:05:21 +00:00
|
|
|
memset(info, 0, sizeof(*info) * maxinfo);
|
|
|
|
memset(cpumaps, 0, maxinfo * maplen);
|
2009-10-21 19:04:14 +00:00
|
|
|
|
2015-06-17 09:05:21 +00:00
|
|
|
for (i = 0; i < maxinfo; i++) {
|
2016-06-29 11:16:22 +00:00
|
|
|
virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(def, i);
|
2015-06-17 09:05:21 +00:00
|
|
|
virBitmapPtr bitmap = NULL;
|
2009-10-21 19:04:14 +00:00
|
|
|
|
2016-01-29 09:20:44 +00:00
|
|
|
if (!vcpu->online)
|
|
|
|
continue;
|
2009-10-21 19:04:14 +00:00
|
|
|
|
2016-01-29 09:20:44 +00:00
|
|
|
if (vcpu->cpumask)
|
|
|
|
bitmap = vcpu->cpumask;
|
2015-06-17 09:05:21 +00:00
|
|
|
else if (def->cpumask)
|
|
|
|
bitmap = def->cpumask;
|
|
|
|
else
|
|
|
|
bitmap = allcpumap;
|
2009-10-21 19:04:14 +00:00
|
|
|
|
2015-06-17 09:05:21 +00:00
|
|
|
if (cpumaps)
|
|
|
|
virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, i), maplen);
|
2009-10-21 19:04:14 +00:00
|
|
|
|
2015-06-17 09:05:21 +00:00
|
|
|
info[i].number = i;
|
|
|
|
info[i].state = VIR_VCPU_RUNNING;
|
|
|
|
info[i].cpu = virBitmapLastSetBit(bitmap);
|
2009-10-21 19:04:14 +00:00
|
|
|
|
2015-06-17 09:05:21 +00:00
|
|
|
/* Fake an increasing cpu time value */
|
|
|
|
info[i].cpuTime = statbase / 10;
|
2009-10-21 19:04:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = maxinfo;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-06-17 09:05:21 +00:00
|
|
|
virBitmapFree(allcpumap);
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2009-10-21 19:04:14 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-27 22:25:38 +00:00
|
|
|
static int testDomainPinVcpu(virDomainPtr domain,
|
|
|
|
unsigned int vcpu,
|
|
|
|
unsigned char *cpumap,
|
|
|
|
int maplen)
|
|
|
|
{
|
2016-06-29 11:16:22 +00:00
|
|
|
virDomainVcpuDefPtr vcpuinfo;
|
2009-10-27 22:25:38 +00:00
|
|
|
virDomainObjPtr privdom;
|
2015-06-17 09:05:21 +00:00
|
|
|
virDomainDefPtr def;
|
2009-10-27 22:25:38 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2009-10-27 22:25:38 +00:00
|
|
|
|
2015-06-17 09:05:21 +00:00
|
|
|
def = privdom->def;
|
|
|
|
|
2009-10-27 22:25:38 +00:00
|
|
|
if (!virDomainObjIsActive(privdom)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2013-11-19 23:04:25 +00:00
|
|
|
"%s", _("cannot pin vcpus on an inactive domain"));
|
2009-10-27 22:25:38 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-01-29 09:20:44 +00:00
|
|
|
if (!(vcpuinfo = virDomainDefGetVcpu(def, vcpu)) ||
|
|
|
|
!vcpuinfo->online) {
|
2016-01-04 18:46:31 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("requested vcpu '%d' is not present in the domain"),
|
|
|
|
vcpu);
|
2009-10-27 22:25:38 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-01-29 09:20:44 +00:00
|
|
|
virBitmapFree(vcpuinfo->cpumask);
|
|
|
|
|
|
|
|
if (!(vcpuinfo->cpumask = virBitmapNewData(cpumap, maplen)))
|
2015-06-17 09:05:21 +00:00
|
|
|
goto cleanup;
|
2009-10-27 22:25:38 +00:00
|
|
|
|
|
|
|
ret = 0;
|
2016-01-29 09:20:44 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2009-10-27 22:25:38 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-07-14 13:10:50 +00:00
|
|
|
static int
|
|
|
|
testDomainGetVcpuPinInfo(virDomainPtr dom,
|
|
|
|
int ncpumaps,
|
|
|
|
unsigned char *cpumaps,
|
|
|
|
int maplen,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2016-02-22 14:29:25 +00:00
|
|
|
testDriverPtr driver = dom->conn->privateData;
|
2015-07-14 13:10:50 +00:00
|
|
|
virDomainObjPtr privdom;
|
|
|
|
virDomainDefPtr def;
|
2016-02-22 14:29:25 +00:00
|
|
|
int ret = -1;
|
2015-07-14 13:10:50 +00:00
|
|
|
|
|
|
|
if (!(privdom = testDomObjFromDomain(dom)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!(def = virDomainObjGetOneDef(privdom, flags)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-02-22 14:29:25 +00:00
|
|
|
ret = virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumaps,
|
|
|
|
VIR_NODEINFO_MAXCPUS(driver->nodeInfo),
|
|
|
|
NULL);
|
2015-07-14 13:10:50 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainObjEndAPI(&privdom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-01-15 19:18:08 +00:00
|
|
|
static int
|
|
|
|
testDomainRenameCallback(virDomainObjPtr privdom,
|
|
|
|
const char *new_name,
|
|
|
|
unsigned int flags,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
testDriverPtr driver = opaque;
|
|
|
|
virObjectEventPtr event_new = NULL;
|
|
|
|
virObjectEventPtr event_old = NULL;
|
|
|
|
int ret = -1;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(char *) new_dom_name = NULL;
|
2018-01-15 19:18:08 +00:00
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2018-05-01 15:56:09 +00:00
|
|
|
if (strchr(new_name, '/')) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("name %s cannot contain '/'"), new_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-01-15 19:18:08 +00:00
|
|
|
if (VIR_STRDUP(new_dom_name, new_name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
event_old = virDomainEventLifecycleNewFromObj(privdom,
|
|
|
|
VIR_DOMAIN_EVENT_UNDEFINED,
|
|
|
|
VIR_DOMAIN_EVENT_UNDEFINED_RENAMED);
|
|
|
|
|
|
|
|
/* Switch name in domain definition. */
|
2019-02-07 13:11:03 +00:00
|
|
|
VIR_FREE(privdom->def->name);
|
|
|
|
VIR_STEAL_PTR(privdom->def->name, new_dom_name);
|
2018-01-15 19:18:08 +00:00
|
|
|
|
|
|
|
event_new = virDomainEventLifecycleNewFromObj(privdom,
|
|
|
|
VIR_DOMAIN_EVENT_DEFINED,
|
|
|
|
VIR_DOMAIN_EVENT_DEFINED_RENAMED);
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(driver->eventState, event_old);
|
|
|
|
virObjectEventStateQueue(driver->eventState, event_new);
|
2018-01-15 19:18:08 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainRename(virDomainPtr dom,
|
|
|
|
const char *new_name,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
testDriverPtr driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr privdom = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, ret);
|
|
|
|
|
|
|
|
if (!(privdom = testDomObjFromDomain(dom)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainObjIsActive(privdom)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("cannot rename active domain"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!privdom->persistent) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("cannot rename a transient domain"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainObjGetState(privdom, NULL) != VIR_DOMAIN_SHUTOFF) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
"%s", _("domain has to be shutoff before renaming"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainObjListRename(driver->domains, privdom, new_name, flags,
|
|
|
|
testDomainRenameCallback, driver) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Success, domain has been renamed. */
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainObjEndAPI(&privdom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-06 20:40:19 +00:00
|
|
|
static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
|
2006-08-16 16:36:39 +00:00
|
|
|
{
|
2016-02-03 21:40:35 +00:00
|
|
|
testDriverPtr privconn = domain->conn->privateData;
|
2008-07-11 16:41:27 +00:00
|
|
|
virDomainDefPtr def;
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
2008-12-04 20:57:47 +00:00
|
|
|
char *ret = NULL;
|
|
|
|
|
2019-02-14 20:25:01 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL);
|
2011-07-13 22:24:38 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return NULL;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
def = (flags & VIR_DOMAIN_XML_INACTIVE) &&
|
|
|
|
privdom->newDef ? privdom->newDef : privdom->def;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2016-02-03 21:40:35 +00:00
|
|
|
ret = virDomainDefFormat(def, privconn->caps,
|
|
|
|
virDomainDefFormatConvertXMLFlags(flags));
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2019-07-02 13:49:42 +00:00
|
|
|
|
|
|
|
#define TEST_SET_PARAM(index, name, type, value) \
|
|
|
|
if (index < *nparams && \
|
|
|
|
virTypedParameterAssign(¶ms[index], name, type, value) < 0) \
|
|
|
|
goto cleanup
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainGetMemoryParameters(virDomainPtr dom,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
|
|
|
VIR_DOMAIN_AFFECT_CONFIG |
|
|
|
|
VIR_TYPED_PARAM_STRING_OKAY, -1);
|
|
|
|
|
|
|
|
if ((*nparams) == 0) {
|
|
|
|
*nparams = 3;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(dom)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(def = virDomainObjGetOneDef(vm, flags)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
TEST_SET_PARAM(0, VIR_DOMAIN_MEMORY_HARD_LIMIT, VIR_TYPED_PARAM_ULLONG, def->mem.hard_limit);
|
|
|
|
TEST_SET_PARAM(1, VIR_DOMAIN_MEMORY_SOFT_LIMIT, VIR_TYPED_PARAM_ULLONG, def->mem.soft_limit);
|
|
|
|
TEST_SET_PARAM(2, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT, VIR_TYPED_PARAM_ULLONG, def->mem.swap_hard_limit);
|
|
|
|
|
|
|
|
if (*nparams > 3)
|
|
|
|
*nparams = 3;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
virDomainObjEndAPI(&vm);
|
|
|
|
return ret;
|
|
|
|
}
|
2019-07-02 13:49:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainGetNumaParameters(virDomainPtr dom,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
virDomainNumatuneMemMode mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT;
|
|
|
|
VIR_AUTOFREE(char *) nodeset = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
|
|
|
VIR_DOMAIN_AFFECT_CONFIG |
|
|
|
|
VIR_TYPED_PARAM_STRING_OKAY, -1);
|
|
|
|
|
|
|
|
if ((*nparams) == 0) {
|
|
|
|
*nparams = 2;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(dom)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(def = virDomainObjGetOneDef(vm, flags)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ignore_value(virDomainNumatuneGetMode(def->numa, -1, &mode));
|
|
|
|
nodeset = virDomainNumatuneFormatNodeset(def->numa, NULL, -1);
|
|
|
|
|
|
|
|
TEST_SET_PARAM(0, VIR_DOMAIN_NUMA_MODE, VIR_TYPED_PARAM_INT, mode);
|
|
|
|
TEST_SET_PARAM(1, VIR_DOMAIN_NUMA_NODESET, VIR_TYPED_PARAM_STRING, nodeset);
|
|
|
|
|
|
|
|
nodeset = NULL;
|
|
|
|
|
|
|
|
if (*nparams > 2)
|
|
|
|
*nparams = 2;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
virDomainObjEndAPI(&vm);
|
|
|
|
return ret;
|
|
|
|
}
|
2019-07-02 13:49:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainGetInterfaceParameters(virDomainPtr dom,
|
|
|
|
const char *device,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virNetDevBandwidthRate in = {0};
|
|
|
|
virNetDevBandwidthRate out = {0};
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
virDomainNetDefPtr net = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
|
|
|
VIR_DOMAIN_AFFECT_CONFIG |
|
|
|
|
VIR_TYPED_PARAM_STRING_OKAY, -1);
|
|
|
|
|
|
|
|
if ((*nparams) == 0) {
|
|
|
|
*nparams = 7;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(dom)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!(def = virDomainObjGetOneDef(vm, flags)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(net = virDomainNetFind(def, device)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (net->bandwidth) {
|
|
|
|
if (net->bandwidth->in)
|
|
|
|
in = *net->bandwidth->in;
|
|
|
|
if (net->bandwidth->out)
|
|
|
|
out = *net->bandwidth->out;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_SET_PARAM(0, VIR_DOMAIN_BANDWIDTH_IN_AVERAGE, VIR_TYPED_PARAM_UINT, in.average);
|
|
|
|
TEST_SET_PARAM(1, VIR_DOMAIN_BANDWIDTH_IN_PEAK, VIR_TYPED_PARAM_UINT, in.peak);
|
|
|
|
TEST_SET_PARAM(2, VIR_DOMAIN_BANDWIDTH_IN_BURST, VIR_TYPED_PARAM_UINT, in.burst);
|
|
|
|
TEST_SET_PARAM(3, VIR_DOMAIN_BANDWIDTH_IN_FLOOR, VIR_TYPED_PARAM_UINT, in.floor);
|
|
|
|
TEST_SET_PARAM(4, VIR_DOMAIN_BANDWIDTH_OUT_AVERAGE, VIR_TYPED_PARAM_UINT, out.average);
|
|
|
|
TEST_SET_PARAM(5, VIR_DOMAIN_BANDWIDTH_OUT_PEAK, VIR_TYPED_PARAM_UINT, out.peak);
|
|
|
|
TEST_SET_PARAM(6, VIR_DOMAIN_BANDWIDTH_OUT_BURST, VIR_TYPED_PARAM_UINT, out.burst);
|
|
|
|
|
|
|
|
if (*nparams > 7)
|
|
|
|
*nparams = 7;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
virDomainObjEndAPI(&vm);
|
|
|
|
return ret;
|
|
|
|
}
|
2019-07-02 13:49:42 +00:00
|
|
|
#undef TEST_SET_PARAM
|
|
|
|
|
|
|
|
|
2014-03-18 08:17:30 +00:00
|
|
|
static int testConnectNumOfDefinedDomains(virConnectPtr conn)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2008-10-10 14:20:37 +00:00
|
|
|
|
2015-06-22 12:33:23 +00:00
|
|
|
return virDomainObjListNumOfDomains(privconn->domains, false, NULL, NULL);
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectListDefinedDomains(virConnectPtr conn,
|
|
|
|
char **const names,
|
2014-03-18 08:17:30 +00:00
|
|
|
int maxnames)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2008-07-11 16:41:27 +00:00
|
|
|
|
|
|
|
memset(names, 0, sizeof(*names)*maxnames);
|
2015-06-22 12:33:23 +00:00
|
|
|
return virDomainObjListGetInactiveNames(privconn->domains, names, maxnames,
|
|
|
|
NULL, NULL);
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
|
|
|
|
2014-11-18 14:19:38 +00:00
|
|
|
static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn,
|
|
|
|
const char *xml,
|
|
|
|
unsigned int flags)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2008-12-04 20:57:47 +00:00
|
|
|
virDomainPtr ret = NULL;
|
2008-07-11 16:41:27 +00:00
|
|
|
virDomainDefPtr def;
|
2008-12-04 20:59:06 +00:00
|
|
|
virDomainObjPtr dom = NULL;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
Merge virDomainObjListIsDuplicate into virDomainObjListAdd
The duplicate VM checking should be done atomically with
virDomainObjListAdd, so shoud not be a separate function.
Instead just use flags to indicate what kind of checks are
required.
This pair, used in virDomainCreateXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainRestoreFlags:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, true)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainDefineXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 0) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
0, NULL)))
goto cleanup;
2013-01-14 14:46:58 +00:00
|
|
|
virDomainDefPtr oldDef = NULL;
|
2014-11-18 17:34:42 +00:00
|
|
|
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL);
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2014-11-18 17:34:42 +00:00
|
|
|
if (flags & VIR_DOMAIN_DEFINE_VALIDATE)
|
2016-05-24 15:20:20 +00:00
|
|
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA;
|
2014-11-18 14:19:38 +00:00
|
|
|
|
2013-03-28 13:55:55 +00:00
|
|
|
if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt,
|
2016-09-22 15:14:17 +00:00
|
|
|
NULL, parse_flags)) == NULL)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2016-11-11 09:17:37 +00:00
|
|
|
if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2010-04-02 21:56:10 +00:00
|
|
|
if (testDomainGenerateIfnames(def) < 0)
|
2009-09-02 13:02:06 +00:00
|
|
|
goto cleanup;
|
2013-01-11 16:04:47 +00:00
|
|
|
if (!(dom = virDomainObjListAdd(privconn->domains,
|
Merge virDomainObjListIsDuplicate into virDomainObjListAdd
The duplicate VM checking should be done atomically with
virDomainObjListAdd, so shoud not be a separate function.
Instead just use flags to indicate what kind of checks are
required.
This pair, used in virDomainCreateXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainRestoreFlags:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, true)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainDefineXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 0) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
0, NULL)))
goto cleanup;
2013-01-14 14:46:58 +00:00
|
|
|
def,
|
2013-03-28 13:55:55 +00:00
|
|
|
privconn->xmlopt,
|
Merge virDomainObjListIsDuplicate into virDomainObjListAdd
The duplicate VM checking should be done atomically with
virDomainObjListAdd, so shoud not be a separate function.
Instead just use flags to indicate what kind of checks are
required.
This pair, used in virDomainCreateXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainRestoreFlags:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, true)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainDefineXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 0) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
0, NULL)))
goto cleanup;
2013-01-14 14:46:58 +00:00
|
|
|
0,
|
|
|
|
&oldDef)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2009-06-22 16:29:40 +00:00
|
|
|
def = NULL;
|
2008-07-11 16:41:27 +00:00
|
|
|
dom->persistent = 1;
|
2009-06-22 16:29:40 +00:00
|
|
|
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(dom,
|
2009-01-20 20:23:53 +00:00
|
|
|
VIR_DOMAIN_EVENT_DEFINED,
|
Merge virDomainObjListIsDuplicate into virDomainObjListAdd
The duplicate VM checking should be done atomically with
virDomainObjListAdd, so shoud not be a separate function.
Instead just use flags to indicate what kind of checks are
required.
This pair, used in virDomainCreateXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainRestoreFlags:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, true)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainDefineXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 0) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
0, NULL)))
goto cleanup;
2013-01-14 14:46:58 +00:00
|
|
|
!oldDef ?
|
2009-11-02 18:37:38 +00:00
|
|
|
VIR_DOMAIN_EVENT_DEFINED_ADDED :
|
|
|
|
VIR_DOMAIN_EVENT_DEFINED_UPDATED);
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
ret = virGetDomain(conn, dom->def->name, dom->def->uuid, dom->def->id);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2008-12-04 20:57:47 +00:00
|
|
|
virDomainDefFree(def);
|
Merge virDomainObjListIsDuplicate into virDomainObjListAdd
The duplicate VM checking should be done atomically with
virDomainObjListAdd, so shoud not be a separate function.
Instead just use flags to indicate what kind of checks are
required.
This pair, used in virDomainCreateXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainRestoreFlags:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, true)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainDefineXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 0) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
0, NULL)))
goto cleanup;
2013-01-14 14:46:58 +00:00
|
|
|
virDomainDefFree(oldDef);
|
2018-04-23 14:40:48 +00:00
|
|
|
virDomainObjEndAPI(&dom);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2008-07-11 16:41:27 +00:00
|
|
|
return ret;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
|
|
|
|
2014-11-18 14:19:38 +00:00
|
|
|
static virDomainPtr
|
|
|
|
testDomainDefineXML(virConnectPtr conn, const char *xml)
|
|
|
|
{
|
|
|
|
return testDomainDefineXMLFlags(conn, xml, 0);
|
|
|
|
}
|
|
|
|
|
2013-09-09 16:02:59 +00:00
|
|
|
static char *testDomainGetMetadata(virDomainPtr dom,
|
|
|
|
int type,
|
|
|
|
const char *uri,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr privdom;
|
2015-06-16 16:18:03 +00:00
|
|
|
char *ret;
|
2013-09-09 16:02:59 +00:00
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
|
|
|
VIR_DOMAIN_AFFECT_CONFIG, NULL);
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(dom)))
|
|
|
|
return NULL;
|
2013-09-09 16:02:59 +00:00
|
|
|
|
2016-07-01 14:19:58 +00:00
|
|
|
ret = virDomainObjGetMetadata(privdom, type, uri, flags);
|
2013-09-09 16:02:59 +00:00
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2013-09-09 16:02:59 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testDomainSetMetadata(virDomainPtr dom,
|
|
|
|
int type,
|
|
|
|
const char *metadata,
|
|
|
|
const char *key,
|
|
|
|
const char *uri,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = dom->conn->privateData;
|
2013-09-09 16:02:59 +00:00
|
|
|
virDomainObjPtr privdom;
|
2015-06-16 16:18:03 +00:00
|
|
|
int ret;
|
2013-09-09 16:02:59 +00:00
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
|
|
|
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(dom)))
|
|
|
|
return -1;
|
2013-09-09 16:02:59 +00:00
|
|
|
|
|
|
|
ret = virDomainObjSetMetadata(privdom, type, metadata, key, uri,
|
|
|
|
privconn->caps, privconn->xmlopt,
|
2014-07-22 15:41:05 +00:00
|
|
|
NULL, NULL, flags);
|
2013-09-09 16:02:59 +00:00
|
|
|
|
2016-12-22 14:41:30 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
virObjectEventPtr ev = NULL;
|
|
|
|
ev = virDomainEventMetadataChangeNewFromObj(privdom, type, uri);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, ev);
|
2016-12-22 14:41:30 +00:00
|
|
|
}
|
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2013-09-09 16:02:59 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-04 13:17:43 +00:00
|
|
|
static int
|
|
|
|
testDomainSendProcessSignal(virDomainPtr dom,
|
|
|
|
long long pid_value,
|
|
|
|
unsigned int signum,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (pid_value != 1) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("only sending a signal to pid 1 is supported"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (signum >= VIR_DOMAIN_PROCESS_SIGNAL_LAST) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("signum value %d is out of range"),
|
|
|
|
signum);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(dom)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* do nothing */
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainObjEndAPI(&vm);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-09-09 16:02:59 +00:00
|
|
|
|
2008-04-04 07:31:24 +00:00
|
|
|
static int testNodeGetCellsFreeMemory(virConnectPtr conn,
|
|
|
|
unsigned long long *freemems,
|
2014-03-18 08:17:30 +00:00
|
|
|
int startCell, int maxCells)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
Convert 'int i' to 'size_t i' in src/test/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int cell;
|
|
|
|
size_t i;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-04-04 07:31:24 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2016-09-15 15:42:36 +00:00
|
|
|
if (startCell >= privconn->numCells) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
"%s", _("Range exceeds available cells"));
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-04-04 07:31:24 +00:00
|
|
|
}
|
|
|
|
|
Convert 'int i' to 'size_t i' in src/test/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
for (cell = startCell, i = 0;
|
|
|
|
(cell < privconn->numCells && i < maxCells);
|
|
|
|
++cell, ++i) {
|
|
|
|
freemems[i] = privconn->cells[cell].mem;
|
2008-04-04 07:31:24 +00:00
|
|
|
}
|
Convert 'int i' to 'size_t i' in src/test/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
ret = i;
|
2008-04-04 07:31:24 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-04-04 07:31:24 +00:00
|
|
|
}
|
|
|
|
|
2016-09-15 08:27:06 +00:00
|
|
|
#define TEST_NB_CPU_STATS 4
|
|
|
|
|
|
|
|
static int
|
|
|
|
testNodeGetCPUStats(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
int cpuNum ATTRIBUTE_UNUSED,
|
|
|
|
virNodeCPUStatsPtr params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (params == NULL) {
|
|
|
|
*nparams = TEST_NB_CPU_STATS;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < *nparams && i < 4; i++) {
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
if (virHostCPUStatsAssign(¶ms[i],
|
|
|
|
VIR_NODE_CPU_STATS_USER, 9797400000) < 0)
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (virHostCPUStatsAssign(¶ms[i],
|
|
|
|
VIR_NODE_CPU_STATS_KERNEL, 34678723400000) < 0)
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (virHostCPUStatsAssign(¶ms[i],
|
|
|
|
VIR_NODE_CPU_STATS_IDLE, 87264900000) < 0)
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (virHostCPUStatsAssign(¶ms[i],
|
|
|
|
VIR_NODE_CPU_STATS_IOWAIT, 763600000) < 0)
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*nparams = i;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-04-04 07:31:24 +00:00
|
|
|
|
2016-09-15 08:27:07 +00:00
|
|
|
static unsigned long long
|
|
|
|
testNodeGetFreeMemory(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
testDriverPtr privconn = conn->privateData;
|
|
|
|
unsigned int freeMem = 0;
|
|
|
|
size_t i;
|
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2016-09-15 08:27:07 +00:00
|
|
|
|
|
|
|
for (i = 0; i < privconn->numCells; i++)
|
|
|
|
freeMem += privconn->cells[i].freeMem;
|
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2016-09-15 08:27:07 +00:00
|
|
|
return freeMem;
|
|
|
|
}
|
|
|
|
|
2016-09-15 08:27:09 +00:00
|
|
|
static int
|
|
|
|
testNodeGetFreePages(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int npages,
|
|
|
|
unsigned int *pages ATTRIBUTE_UNUSED,
|
|
|
|
int startCell ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int cellCount,
|
|
|
|
unsigned long long *counts,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
size_t i = 0, j = 0;
|
|
|
|
int x = 6;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
for (i = 0; i < cellCount; i++) {
|
|
|
|
for (j = 0; j < npages; j++) {
|
|
|
|
x = x * 2 + 7;
|
|
|
|
counts[(i * npages) + j] = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-18 08:17:30 +00:00
|
|
|
static int testDomainCreateWithFlags(virDomainPtr domain, unsigned int flags)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = domain->conn->privateData;
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2010-06-10 15:55:36 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
if (virDomainObjGetState(privdom, NULL) != VIR_DOMAIN_SHUTOFF) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Domain '%s' is already running"), domain->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 18:59:45 +00:00
|
|
|
if (testDomainStartState(privconn, privdom,
|
2011-05-04 09:07:01 +00:00
|
|
|
VIR_DOMAIN_RUNNING_BOOTED) < 0)
|
2009-10-27 17:15:44 +00:00
|
|
|
goto cleanup;
|
|
|
|
domain->id = privdom->def->id;
|
|
|
|
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(privdom,
|
2009-01-20 20:23:53 +00:00
|
|
|
VIR_DOMAIN_EVENT_STARTED,
|
|
|
|
VIR_DOMAIN_EVENT_STARTED_BOOTED);
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-18 08:17:30 +00:00
|
|
|
static int testDomainCreate(virDomainPtr domain)
|
|
|
|
{
|
2010-06-10 15:55:36 +00:00
|
|
|
return testDomainCreateWithFlags(domain, 0);
|
|
|
|
}
|
|
|
|
|
2011-07-20 03:08:21 +00:00
|
|
|
static int testDomainUndefineFlags(virDomainPtr domain,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = domain->conn->privateData;
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2013-08-07 17:40:46 +00:00
|
|
|
int nsnapshots;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2013-08-07 17:40:46 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE |
|
|
|
|
VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, -1);
|
2011-07-20 03:08:21 +00:00
|
|
|
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2013-08-06 23:33:25 +00:00
|
|
|
if (privdom->hasManagedSave &&
|
|
|
|
!(flags & VIR_DOMAIN_UNDEFINE_MANAGED_SAVE)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Refusing to undefine while domain managed "
|
|
|
|
"save image exists"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-08-07 17:40:46 +00:00
|
|
|
/* Requiring an inactive VM is part of the documented API for
|
|
|
|
* UNDEFINE_SNAPSHOTS_METADATA
|
|
|
|
*/
|
|
|
|
if (!virDomainObjIsActive(privdom) &&
|
|
|
|
(nsnapshots = virDomainSnapshotObjListNum(privdom->snapshots,
|
|
|
|
NULL, 0))) {
|
|
|
|
if (!(flags & VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("cannot delete inactive domain with %d "
|
|
|
|
"snapshots"),
|
|
|
|
nsnapshots);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There isn't actually anything to do, we are just emulating qemu
|
|
|
|
* behavior here. */
|
|
|
|
}
|
|
|
|
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(privdom,
|
2009-01-20 20:23:53 +00:00
|
|
|
VIR_DOMAIN_EVENT_UNDEFINED,
|
|
|
|
VIR_DOMAIN_EVENT_UNDEFINED_REMOVED);
|
2013-08-06 23:33:25 +00:00
|
|
|
privdom->hasManagedSave = false;
|
|
|
|
|
2018-04-23 14:40:48 +00:00
|
|
|
if (virDomainObjIsActive(privdom))
|
2011-08-19 14:14:58 +00:00
|
|
|
privdom->persistent = 0;
|
2018-04-23 14:40:48 +00:00
|
|
|
else
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjListRemove(privconn->domains, privdom);
|
2011-08-19 13:50:49 +00:00
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
|
|
|
|
2011-07-20 03:08:21 +00:00
|
|
|
static int testDomainUndefine(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
return testDomainUndefineFlags(domain, 0);
|
|
|
|
}
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
static int testDomainGetAutostart(virDomainPtr domain,
|
|
|
|
int *autostart)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
*autostart = privdom->autostart;
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2015-06-16 16:18:03 +00:00
|
|
|
return 0;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int testDomainSetAutostart(virDomainPtr domain,
|
|
|
|
int autostart)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
privdom->autostart = autostart ? 1 : 0;
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2015-06-16 16:18:03 +00:00
|
|
|
return 0;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2019-05-12 23:26:14 +00:00
|
|
|
static int testDomainGetDiskErrors(virDomainPtr dom,
|
|
|
|
virDomainDiskErrorPtr errors,
|
|
|
|
unsigned int maxerrors,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
2019-07-04 13:20:35 +00:00
|
|
|
size_t nerrors = 0;
|
2019-05-12 23:26:14 +00:00
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(dom)))
|
2019-05-14 15:05:45 +00:00
|
|
|
return -1;
|
2019-05-12 23:26:14 +00:00
|
|
|
|
|
|
|
if (virDomainObjCheckActive(vm) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2019-07-04 11:31:34 +00:00
|
|
|
nerrors = MIN(vm->def->ndisks, maxerrors);
|
|
|
|
|
2019-05-12 23:26:14 +00:00
|
|
|
if (errors) {
|
2019-07-04 11:31:34 +00:00
|
|
|
/* sanitize input */
|
|
|
|
memset(errors, 0, sizeof(virDomainDiskError) * nerrors);
|
|
|
|
|
|
|
|
for (i = 0; i < nerrors; i++) {
|
2019-05-12 23:26:14 +00:00
|
|
|
if (VIR_STRDUP(errors[i].disk, vm->def->disks[i]->dst) < 0)
|
|
|
|
goto cleanup;
|
2019-05-14 15:09:19 +00:00
|
|
|
errors[i].error = (i % (VIR_DOMAIN_DISK_ERROR_LAST - 1)) + 1;
|
2019-05-12 23:26:14 +00:00
|
|
|
}
|
|
|
|
ret = i;
|
|
|
|
} else {
|
|
|
|
ret = vm->def->ndisks;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (ret < 0) {
|
2019-07-04 11:31:34 +00:00
|
|
|
for (i = 0; i < nerrors; i++)
|
2019-05-12 23:26:14 +00:00
|
|
|
VIR_FREE(errors[i].disk);
|
|
|
|
}
|
2019-05-14 15:05:45 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2019-05-12 23:26:14 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-25 21:58:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainGetFSInfo(virDomainPtr dom,
|
|
|
|
virDomainFSInfoPtr **info,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainFSInfoPtr *info_ret = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(dom)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virDomainObjCheckActive(vm) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
*info = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < vm->def->ndisks; i++) {
|
|
|
|
if (vm->def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
|
|
|
|
char *name = vm->def->disks[i]->dst;
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(info_ret, 2) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(info_ret[0]) < 0 ||
|
|
|
|
VIR_ALLOC(info_ret[0]->devAlias) < 0 ||
|
|
|
|
VIR_STRDUP(info_ret[0]->mountpoint, "/") < 0 ||
|
|
|
|
VIR_STRDUP(info_ret[0]->fstype, "ext4") < 0 ||
|
|
|
|
VIR_STRDUP(info_ret[0]->devAlias[0], name) < 0 ||
|
|
|
|
virAsprintf(&info_ret[0]->name, "%s1", name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(info_ret[1]) < 0 ||
|
|
|
|
VIR_ALLOC(info_ret[1]->devAlias) < 0 ||
|
|
|
|
VIR_STRDUP(info_ret[1]->mountpoint, "/boot") < 0 ||
|
|
|
|
VIR_STRDUP(info_ret[1]->fstype, "ext4") < 0 ||
|
|
|
|
VIR_STRDUP(info_ret[1]->devAlias[0], name) < 0 ||
|
|
|
|
virAsprintf(&info_ret[1]->name, "%s2", name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
info_ret[0]->ndevAlias = info_ret[1]->ndevAlias = 1;
|
|
|
|
|
|
|
|
VIR_STEAL_PTR(*info, info_ret);
|
|
|
|
|
|
|
|
ret = 2;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (info_ret) {
|
|
|
|
virDomainFSInfoFree(info_ret[0]);
|
|
|
|
virDomainFSInfoFree(info_ret[1]);
|
|
|
|
VIR_FREE(info_ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
virDomainObjEndAPI(&vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-03 11:54:18 +00:00
|
|
|
static int
|
|
|
|
testDomainSetPerfEvents(virDomainPtr dom,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
size_t i;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
|
|
|
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
|
|
|
|
|
|
|
if (virTypedParamsValidate(params, nparams,
|
|
|
|
VIR_PERF_PARAM_CMT, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_MBMT, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_MBML, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_CPU_CYCLES, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_INSTRUCTIONS, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_CACHE_REFERENCES, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_CACHE_MISSES, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_BRANCH_INSTRUCTIONS, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_BRANCH_MISSES, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_BUS_CYCLES, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_STALLED_CYCLES_FRONTEND, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_STALLED_CYCLES_BACKEND, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_REF_CPU_CYCLES, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_CPU_CLOCK, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_TASK_CLOCK, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_PAGE_FAULTS, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_CONTEXT_SWITCHES, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_CPU_MIGRATIONS, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_PAGE_FAULTS_MIN, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_PAGE_FAULTS_MAJ, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_ALIGNMENT_FAULTS, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
VIR_PERF_PARAM_EMULATION_FAULTS, VIR_TYPED_PARAM_BOOLEAN,
|
|
|
|
NULL) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(dom)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!(def = virDomainObjGetOneDef(vm, flags)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < nparams; i++) {
|
|
|
|
virTypedParameterPtr param = ¶ms[i];
|
|
|
|
virPerfEventType type = virPerfEventTypeFromString(param->field);
|
|
|
|
|
|
|
|
if (param->value.b)
|
|
|
|
def->perf.events[type] = VIR_TRISTATE_BOOL_YES;
|
|
|
|
else
|
|
|
|
def->perf.events[type] = VIR_TRISTATE_BOOL_NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
virDomainObjEndAPI(&vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-28 16:15:01 +00:00
|
|
|
static int
|
|
|
|
testDomainGetPerfEvents(virDomainPtr dom,
|
|
|
|
virTypedParameterPtr *params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
virTypedParameterPtr par = NULL;
|
|
|
|
size_t i;
|
|
|
|
int maxpar = 0;
|
|
|
|
int npar = 0;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
|
|
|
VIR_DOMAIN_AFFECT_CONFIG |
|
|
|
|
VIR_TYPED_PARAM_STRING_OKAY, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(dom)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(def = virDomainObjGetOneDef(vm, flags)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < VIR_PERF_EVENT_LAST; i++) {
|
|
|
|
if (virTypedParamsAddBoolean(&par, &npar, &maxpar,
|
|
|
|
virPerfEventTypeToString(i),
|
|
|
|
def->perf.events[i] == VIR_TRISTATE_BOOL_YES) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_STEAL_PTR(*params, par);
|
|
|
|
*nparams = npar;
|
|
|
|
npar = 0;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
virDomainObjEndAPI(&vm);
|
|
|
|
virTypedParamsFree(par, npar);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-04 18:19:08 +00:00
|
|
|
static char *testDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED,
|
2007-07-27 23:23:00 +00:00
|
|
|
int *nparams)
|
|
|
|
{
|
2008-12-04 20:57:47 +00:00
|
|
|
char *type = NULL;
|
|
|
|
|
2011-05-18 07:55:32 +00:00
|
|
|
if (nparams)
|
|
|
|
*nparams = 1;
|
|
|
|
|
2013-05-03 12:49:30 +00:00
|
|
|
ignore_value(VIR_STRDUP(type, "fair"));
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2011-05-17 22:33:53 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testDomainGetSchedulerParametersFlags(virDomainPtr domain,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
2007-07-27 23:23:00 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2011-05-17 22:33:53 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2012-01-07 12:47:43 +00:00
|
|
|
if (virTypedParameterAssign(params, VIR_DOMAIN_SCHEDULER_WEIGHT,
|
|
|
|
VIR_TYPED_PARAM_UINT, 50) < 0)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-07-11 16:41:27 +00:00
|
|
|
/* XXX */
|
|
|
|
/*params[0].value.ui = privdom->weight;*/
|
2011-05-18 08:52:57 +00:00
|
|
|
|
|
|
|
*nparams = 1;
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2011-05-17 22:33:53 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testDomainGetSchedulerParameters(virDomainPtr domain,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int *nparams)
|
2011-05-17 22:33:53 +00:00
|
|
|
{
|
2013-04-23 12:50:18 +00:00
|
|
|
return testDomainGetSchedulerParametersFlags(domain, params, nparams, 0);
|
2011-05-17 22:33:53 +00:00
|
|
|
}
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2011-05-17 22:33:53 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testDomainSetSchedulerParametersFlags(virDomainPtr domain,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
|
|
|
unsigned int flags)
|
2007-07-27 23:23:00 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
virDomainObjPtr privdom;
|
Convert 'int i' to 'size_t i' in src/test/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2011-05-17 22:33:53 +00:00
|
|
|
virCheckFlags(0, -1);
|
2013-05-03 13:34:10 +00:00
|
|
|
if (virTypedParamsValidate(params, nparams,
|
|
|
|
VIR_DOMAIN_SCHEDULER_WEIGHT,
|
|
|
|
VIR_TYPED_PARAM_UINT,
|
|
|
|
NULL) < 0)
|
2012-01-07 12:47:43 +00:00
|
|
|
return -1;
|
2011-05-17 22:33:53 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2011-05-18 09:04:12 +00:00
|
|
|
for (i = 0; i < nparams; i++) {
|
2012-01-07 12:47:43 +00:00
|
|
|
if (STREQ(params[i].field, VIR_DOMAIN_SCHEDULER_WEIGHT)) {
|
|
|
|
/* XXX */
|
|
|
|
/*privdom->weight = params[i].value.ui;*/
|
2011-05-18 09:04:12 +00:00
|
|
|
}
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2011-05-18 09:04:12 +00:00
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2011-05-17 22:33:53 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testDomainSetSchedulerParameters(virDomainPtr domain,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams)
|
2011-05-17 22:33:53 +00:00
|
|
|
{
|
2013-04-23 12:50:18 +00:00
|
|
|
return testDomainSetSchedulerParametersFlags(domain, params, nparams, 0);
|
2011-05-17 22:33:53 +00:00
|
|
|
}
|
|
|
|
|
2009-07-24 15:05:30 +00:00
|
|
|
static int testDomainBlockStats(virDomainPtr domain,
|
|
|
|
const char *path,
|
2014-09-16 13:19:46 +00:00
|
|
|
virDomainBlockStatsPtr stats)
|
2009-07-24 15:05:30 +00:00
|
|
|
{
|
|
|
|
virDomainObjPtr privdom;
|
|
|
|
struct timeval tv;
|
|
|
|
unsigned long long statbase;
|
2011-11-22 22:55:30 +00:00
|
|
|
int ret = -1;
|
2009-07-24 15:05:30 +00:00
|
|
|
|
2014-02-28 08:50:01 +00:00
|
|
|
if (!*path) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("summary statistics are not supported yet"));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return ret;
|
2009-07-24 15:05:30 +00:00
|
|
|
|
2018-04-17 22:13:28 +00:00
|
|
|
if (virDomainObjCheckActive(privdom) < 0)
|
2016-11-08 08:49:22 +00:00
|
|
|
goto error;
|
|
|
|
|
2011-11-22 22:55:30 +00:00
|
|
|
if (virDomainDiskIndexByName(privdom->def, path, false) < 0) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("invalid path: %s"), path);
|
2009-07-24 15:05:30 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gettimeofday(&tv, NULL) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-07-24 15:05:30 +00:00
|
|
|
"%s", _("getting time of day"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No significance to these numbers, just enough to mix it up*/
|
|
|
|
statbase = (tv.tv_sec * 1000UL * 1000UL) + tv.tv_usec;
|
|
|
|
stats->rd_req = statbase / 10;
|
|
|
|
stats->rd_bytes = statbase / 20;
|
|
|
|
stats->wr_req = statbase / 30;
|
|
|
|
stats->wr_bytes = statbase / 40;
|
|
|
|
stats->errs = tv.tv_sec / 2;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2009-07-24 15:05:30 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-19 16:45:30 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainInterfaceAddressFromNet(testDriverPtr driver,
|
|
|
|
const virDomainNetDef *net,
|
|
|
|
size_t addr_offset,
|
|
|
|
virDomainInterfacePtr iface)
|
|
|
|
{
|
|
|
|
virSocketAddr addr;
|
|
|
|
virNetworkObjPtr net_obj = NULL;
|
|
|
|
virNetworkDefPtr net_def = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(net_obj = testNetworkObjFindByName(driver, net->data.network.name)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
net_def = virNetworkObjGetDef(net_obj);
|
|
|
|
|
|
|
|
iface->addrs[0].prefix = virSocketAddrGetIPPrefix(&net_def->ips->address,
|
|
|
|
&net_def->ips->netmask,
|
|
|
|
net_def->ips->prefix);
|
|
|
|
|
|
|
|
if (net_def->ips->nranges > 0)
|
|
|
|
addr = net_def->ips->ranges[0].start;
|
|
|
|
else
|
|
|
|
addr = net_def->ips->address;
|
|
|
|
|
|
|
|
if (net_def->ips->family && STREQ(net_def->ips->family, "ipv6")) {
|
|
|
|
iface->addrs[0].type = VIR_IP_ADDR_TYPE_IPV6;
|
|
|
|
addr.data.inet6.sin6_addr.s6_addr[15] += addr_offset;
|
|
|
|
} else {
|
|
|
|
iface->addrs[0].type = VIR_IP_ADDR_TYPE_IPV4;
|
|
|
|
addr.data.inet4.sin_addr.s_addr = \
|
|
|
|
htonl(ntohl(addr.data.inet4.sin_addr.s_addr) + addr_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(iface->addrs[0].addr = virSocketAddrFormat(&addr)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
virNetworkObjEndAPI(&net_obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-23 12:50:00 +00:00
|
|
|
static int
|
|
|
|
testDomainInterfaceAddresses(virDomainPtr dom,
|
|
|
|
virDomainInterfacePtr **ifaces,
|
2019-06-19 11:18:15 +00:00
|
|
|
unsigned int source,
|
2019-05-23 12:50:00 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
size_t ifaces_count = 0;
|
|
|
|
int ret = -1;
|
|
|
|
char macaddr[VIR_MAC_STRING_BUFLEN];
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainInterfacePtr iface = NULL;
|
|
|
|
virDomainInterfacePtr *ifaces_ret = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2019-06-19 11:18:15 +00:00
|
|
|
if (source >= VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LAST) {
|
|
|
|
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
|
|
|
|
_("Unknown IP address data source %d"),
|
|
|
|
source);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-05-23 12:50:00 +00:00
|
|
|
if (!(vm = testDomObjFromDomain(dom)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainObjCheckActive(vm) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(ifaces_ret, vm->def->nnets) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < vm->def->nnets; i++) {
|
2019-06-19 16:45:30 +00:00
|
|
|
const virDomainNetDef *net = vm->def->nets[i];
|
|
|
|
|
2019-05-23 12:50:00 +00:00
|
|
|
if (VIR_ALLOC(iface) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2019-06-19 16:45:30 +00:00
|
|
|
if (VIR_STRDUP(iface->name, net->ifname) < 0)
|
2019-05-23 12:50:00 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2019-06-19 16:45:30 +00:00
|
|
|
virMacAddrFormat(&net->mac, macaddr);
|
2019-05-23 12:50:00 +00:00
|
|
|
if (VIR_STRDUP(iface->hwaddr, macaddr) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(iface->addrs) < 0)
|
|
|
|
goto cleanup;
|
2019-06-19 16:45:30 +00:00
|
|
|
iface->naddrs = 1;
|
2019-05-23 12:50:00 +00:00
|
|
|
|
2019-06-19 16:45:30 +00:00
|
|
|
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
|
|
|
/* try using different addresses per different inf and domain */
|
|
|
|
const size_t addr_offset = 20 * (vm->def->id - 1) + i + 1;
|
2019-05-23 12:50:00 +00:00
|
|
|
|
2019-06-19 16:45:30 +00:00
|
|
|
if (testDomainInterfaceAddressFromNet(dom->conn->privateData,
|
|
|
|
net, addr_offset, iface) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
iface->addrs[0].type = VIR_IP_ADDR_TYPE_IPV4;
|
|
|
|
iface->addrs[0].prefix = 24;
|
|
|
|
if (virAsprintf(&iface->addrs[0].addr, "192.168.0.%zu", 1 + i) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
}
|
2019-05-23 12:50:00 +00:00
|
|
|
|
|
|
|
VIR_APPEND_ELEMENT_INPLACE(ifaces_ret, ifaces_count, iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_STEAL_PTR(*ifaces, ifaces_ret);
|
|
|
|
ret = ifaces_count;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainObjEndAPI(&vm);
|
|
|
|
|
|
|
|
if (ifaces_ret) {
|
|
|
|
for (i = 0; i < ifaces_count; i++)
|
|
|
|
virDomainInterfaceFree(ifaces_ret[i]);
|
|
|
|
}
|
|
|
|
virDomainInterfaceFree(iface);
|
|
|
|
|
|
|
|
VIR_FREE(ifaces_ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-10-13 20:25:42 +00:00
|
|
|
static int
|
|
|
|
testDomainInterfaceStats(virDomainPtr domain,
|
|
|
|
const char *device,
|
|
|
|
virDomainInterfaceStatsPtr stats)
|
2009-07-24 15:05:30 +00:00
|
|
|
{
|
|
|
|
virDomainObjPtr privdom;
|
|
|
|
struct timeval tv;
|
|
|
|
unsigned long long statbase;
|
2017-10-02 13:24:39 +00:00
|
|
|
virDomainNetDefPtr net = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
2009-07-24 15:05:30 +00:00
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(privdom = testDomObjFromDomain(domain)))
|
|
|
|
return -1;
|
2009-07-24 15:05:30 +00:00
|
|
|
|
2018-04-17 22:13:28 +00:00
|
|
|
if (virDomainObjCheckActive(privdom) < 0)
|
2016-11-08 08:49:22 +00:00
|
|
|
goto error;
|
|
|
|
|
2017-10-13 20:25:42 +00:00
|
|
|
if (!(net = virDomainNetFind(privdom->def, device)))
|
2009-07-24 15:05:30 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (gettimeofday(&tv, NULL) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-07-24 15:05:30 +00:00
|
|
|
"%s", _("getting time of day"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No significance to these numbers, just enough to mix it up*/
|
|
|
|
statbase = (tv.tv_sec * 1000UL * 1000UL) + tv.tv_usec;
|
|
|
|
stats->rx_bytes = statbase / 10;
|
|
|
|
stats->rx_packets = statbase / 100;
|
|
|
|
stats->rx_errs = tv.tv_sec / 1;
|
|
|
|
stats->rx_drop = tv.tv_sec / 2;
|
|
|
|
stats->tx_bytes = statbase / 20;
|
|
|
|
stats->tx_packets = statbase / 110;
|
|
|
|
stats->tx_errs = tv.tv_sec / 3;
|
|
|
|
stats->tx_drop = tv.tv_sec / 4;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2009-07-24 15:05:30 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2017-03-04 14:48:11 +00:00
|
|
|
static virNetworkObjPtr
|
|
|
|
testNetworkObjFindByUUID(testDriverPtr privconn,
|
|
|
|
const unsigned char *uuid)
|
|
|
|
{
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjPtr obj;
|
2017-03-04 14:48:11 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
if (!(obj = virNetworkObjFindByUUID(privconn->networks, uuid))) {
|
2017-03-04 14:48:11 +00:00
|
|
|
virUUIDFormat(uuid, uuidstr);
|
|
|
|
virReportError(VIR_ERR_NO_NETWORK,
|
|
|
|
_("no network with matching uuid '%s'"),
|
|
|
|
uuidstr);
|
|
|
|
}
|
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
return obj;
|
2017-03-04 14:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
static virNetworkPtr
|
|
|
|
testNetworkLookupByUUID(virConnectPtr conn,
|
|
|
|
const unsigned char *uuid)
|
2007-07-27 23:23:00 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjPtr obj;
|
2017-05-09 22:38:58 +00:00
|
|
|
virNetworkDefPtr def;
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkPtr net = NULL;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
if (!(obj = testNetworkObjFindByUUID(privconn, uuid)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2017-05-09 22:38:58 +00:00
|
|
|
def = virNetworkObjGetDef(obj);
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2017-05-09 22:38:58 +00:00
|
|
|
net = virGetNetwork(conn, def->name, def->uuid);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
|
|
|
return net;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2017-03-04 14:34:53 +00:00
|
|
|
|
|
|
|
static virNetworkObjPtr
|
|
|
|
testNetworkObjFindByName(testDriverPtr privconn,
|
|
|
|
const char *name)
|
|
|
|
{
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjPtr obj;
|
2017-03-04 14:34:53 +00:00
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
if (!(obj = virNetworkObjFindByName(privconn->networks, name)))
|
2017-03-04 14:34:53 +00:00
|
|
|
virReportError(VIR_ERR_NO_NETWORK,
|
|
|
|
_("no network with matching name '%s'"),
|
|
|
|
name);
|
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
return obj;
|
2017-03-04 14:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
static virNetworkPtr
|
|
|
|
testNetworkLookupByName(virConnectPtr conn,
|
|
|
|
const char *name)
|
2007-07-27 23:23:00 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjPtr obj;
|
2017-05-09 22:38:58 +00:00
|
|
|
virNetworkDefPtr def;
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkPtr net = NULL;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
if (!(obj = testNetworkObjFindByName(privconn, name)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2017-05-09 22:38:58 +00:00
|
|
|
def = virNetworkObjGetDef(obj);
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2017-05-09 22:38:58 +00:00
|
|
|
net = virGetNetwork(conn, def->name, def->uuid);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
|
|
|
return net;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
static int
|
|
|
|
testConnectNumOfNetworks(virConnectPtr conn)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2015-02-24 10:32:52 +00:00
|
|
|
int numActive;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2015-02-24 10:32:52 +00:00
|
|
|
numActive = virNetworkObjListNumOfNetworks(privconn->networks,
|
|
|
|
true, NULL, conn);
|
2008-07-11 16:39:08 +00:00
|
|
|
return numActive;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testConnectListNetworks(virConnectPtr conn,
|
|
|
|
char **const names,
|
2017-07-26 14:18:39 +00:00
|
|
|
int maxnames)
|
2017-05-12 11:45:37 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2015-02-24 10:32:52 +00:00
|
|
|
int n;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2015-02-24 10:32:52 +00:00
|
|
|
n = virNetworkObjListGetNames(privconn->networks,
|
2017-07-26 14:18:39 +00:00
|
|
|
true, names, maxnames, NULL, conn);
|
2008-07-11 16:39:08 +00:00
|
|
|
return n;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testConnectNumOfDefinedNetworks(virConnectPtr conn)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2015-02-24 10:32:52 +00:00
|
|
|
int numInactive;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2015-02-24 10:32:52 +00:00
|
|
|
numInactive = virNetworkObjListNumOfNetworks(privconn->networks,
|
|
|
|
false, NULL, conn);
|
2008-07-11 16:39:08 +00:00
|
|
|
return numInactive;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testConnectListDefinedNetworks(virConnectPtr conn,
|
|
|
|
char **const names,
|
2017-07-26 14:18:39 +00:00
|
|
|
int maxnames)
|
2017-05-12 11:45:37 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2015-02-24 10:32:52 +00:00
|
|
|
int n;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2015-02-24 10:32:52 +00:00
|
|
|
n = virNetworkObjListGetNames(privconn->networks,
|
2017-07-26 14:18:39 +00:00
|
|
|
false, names, maxnames, NULL, conn);
|
2008-07-11 16:39:08 +00:00
|
|
|
return n;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
2012-09-04 15:55:19 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testConnectListAllNetworks(virConnectPtr conn,
|
2012-09-04 15:55:19 +00:00
|
|
|
virNetworkPtr **nets,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2012-09-04 15:55:19 +00:00
|
|
|
|
|
|
|
virCheckFlags(VIR_CONNECT_LIST_NETWORKS_FILTERS_ALL, -1);
|
|
|
|
|
2015-02-26 13:25:54 +00:00
|
|
|
return virNetworkObjListExport(conn, privconn->networks, nets, NULL, flags);
|
2012-09-04 15:55:19 +00:00
|
|
|
}
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testNetworkIsActive(virNetworkPtr net)
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = net->conn->privateData;
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
virNetworkObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
2017-03-04 14:48:11 +00:00
|
|
|
if (!(obj = testNetworkObjFindByUUID(privconn, net->uuid)))
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
goto cleanup;
|
2017-03-04 14:48:11 +00:00
|
|
|
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
ret = virNetworkObjIsActive(obj);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-02-25 16:38:54 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testNetworkIsPersistent(virNetworkPtr net)
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = net->conn->privateData;
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
virNetworkObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
2017-03-04 14:48:11 +00:00
|
|
|
if (!(obj = testNetworkObjFindByUUID(privconn, net->uuid)))
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
goto cleanup;
|
2017-03-04 14:48:11 +00:00
|
|
|
|
2017-05-10 11:29:57 +00:00
|
|
|
ret = virNetworkObjIsPersistent(obj);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-02-25 16:38:54 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
static virNetworkPtr
|
|
|
|
testNetworkCreateXML(virConnectPtr conn, const char *xml)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-05-09 22:38:58 +00:00
|
|
|
virNetworkDefPtr newDef;
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjPtr obj = NULL;
|
2017-05-09 22:38:58 +00:00
|
|
|
virNetworkDefPtr def;
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkPtr net = NULL;
|
2013-12-11 10:37:59 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2017-05-09 22:38:58 +00:00
|
|
|
if ((newDef = virNetworkDefParseString(xml)) == NULL)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2017-05-09 22:38:58 +00:00
|
|
|
if (!(obj = virNetworkObjAssignDef(privconn->networks, newDef,
|
2017-03-08 16:41:18 +00:00
|
|
|
VIR_NETWORK_OBJ_LIST_ADD_LIVE |
|
|
|
|
VIR_NETWORK_OBJ_LIST_ADD_CHECK_LIVE)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2017-05-09 22:38:58 +00:00
|
|
|
newDef = NULL;
|
|
|
|
def = virNetworkObjGetDef(obj);
|
2017-05-10 11:22:15 +00:00
|
|
|
virNetworkObjSetActive(obj, true);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2017-05-09 22:38:58 +00:00
|
|
|
event = virNetworkEventLifecycleNew(def->name, def->uuid,
|
2013-12-11 13:40:41 +00:00
|
|
|
VIR_NETWORK_EVENT_STARTED,
|
|
|
|
0);
|
2013-12-11 10:37:59 +00:00
|
|
|
|
2017-05-09 22:38:58 +00:00
|
|
|
net = virGetNetwork(conn, def->name, def->uuid);
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-05-09 22:38:58 +00:00
|
|
|
virNetworkDefFree(newDef);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
|
|
|
return net;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
|
|
|
static virNetworkPtr
|
|
|
|
testNetworkDefineXML(virConnectPtr conn,
|
|
|
|
const char *xml)
|
2012-08-20 05:01:53 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-05-09 22:38:58 +00:00
|
|
|
virNetworkDefPtr newDef;
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjPtr obj = NULL;
|
2017-05-09 22:38:58 +00:00
|
|
|
virNetworkDefPtr def;
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkPtr net = NULL;
|
2013-12-11 10:37:59 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2017-05-09 22:38:58 +00:00
|
|
|
if ((newDef = virNetworkDefParseString(xml)) == NULL)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2017-05-09 22:38:58 +00:00
|
|
|
if (!(obj = virNetworkObjAssignDef(privconn->networks, newDef, 0)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2017-05-09 22:38:58 +00:00
|
|
|
newDef = NULL;
|
|
|
|
def = virNetworkObjGetDef(obj);
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2017-05-09 22:38:58 +00:00
|
|
|
event = virNetworkEventLifecycleNew(def->name, def->uuid,
|
2013-12-11 13:40:41 +00:00
|
|
|
VIR_NETWORK_EVENT_DEFINED,
|
|
|
|
0);
|
2013-12-11 10:37:59 +00:00
|
|
|
|
2017-05-09 22:38:58 +00:00
|
|
|
net = virGetNetwork(conn, def->name, def->uuid);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-05-09 22:38:58 +00:00
|
|
|
virNetworkDefFree(newDef);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
|
|
|
return net;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
|
|
|
static int
|
2017-05-12 11:57:12 +00:00
|
|
|
testNetworkUndefine(virNetworkPtr net)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2017-05-12 11:57:12 +00:00
|
|
|
testDriverPtr privconn = net->conn->privateData;
|
|
|
|
virNetworkObjPtr obj;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2013-12-11 10:37:59 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
if (!(obj = testNetworkObjFindByName(privconn, net->name)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
if (virNetworkObjIsActive(obj)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2017-05-12 11:57:12 +00:00
|
|
|
_("Network '%s' is still running"), net->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
event = virNetworkEventLifecycleNew(net->name, net->uuid,
|
2013-12-11 13:40:41 +00:00
|
|
|
VIR_NETWORK_EVENT_UNDEFINED,
|
|
|
|
0);
|
2013-12-11 10:37:59 +00:00
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjRemoveInactive(privconn->networks, obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
2012-08-20 05:01:53 +00:00
|
|
|
static int
|
|
|
|
testNetworkUpdate(virNetworkPtr net,
|
|
|
|
unsigned int command,
|
|
|
|
unsigned int section,
|
|
|
|
int parentIndex,
|
|
|
|
const char *xml,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = net->conn->privateData;
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjPtr obj = NULL;
|
2012-08-20 05:01:53 +00:00
|
|
|
int isActive, ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_NETWORK_UPDATE_AFFECT_LIVE |
|
|
|
|
VIR_NETWORK_UPDATE_AFFECT_CONFIG,
|
|
|
|
-1);
|
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
if (!(obj = testNetworkObjFindByUUID(privconn, net->uuid)))
|
2012-08-20 05:01:53 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* VIR_NETWORK_UPDATE_AFFECT_CURRENT means "change LIVE if network
|
|
|
|
* is active, else change CONFIG
|
|
|
|
*/
|
2017-05-12 11:57:12 +00:00
|
|
|
isActive = virNetworkObjIsActive(obj);
|
2012-08-20 05:01:53 +00:00
|
|
|
if ((flags & (VIR_NETWORK_UPDATE_AFFECT_LIVE
|
|
|
|
| VIR_NETWORK_UPDATE_AFFECT_CONFIG)) ==
|
|
|
|
VIR_NETWORK_UPDATE_AFFECT_CURRENT) {
|
|
|
|
if (isActive)
|
|
|
|
flags |= VIR_NETWORK_UPDATE_AFFECT_LIVE;
|
|
|
|
else
|
|
|
|
flags |= VIR_NETWORK_UPDATE_AFFECT_CONFIG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update the network config in memory/on disk */
|
2017-05-12 11:57:12 +00:00
|
|
|
if (virNetworkObjUpdate(obj, command, section, parentIndex, xml, flags) < 0)
|
2012-08-20 05:01:53 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
2012-08-20 05:01:53 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
|
|
|
static int
|
2017-05-12 11:57:12 +00:00
|
|
|
testNetworkCreate(virNetworkPtr net)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2017-05-12 11:57:12 +00:00
|
|
|
testDriverPtr privconn = net->conn->privateData;
|
|
|
|
virNetworkObjPtr obj;
|
2017-05-09 22:38:58 +00:00
|
|
|
virNetworkDefPtr def;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2013-12-11 10:37:59 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
if (!(obj = testNetworkObjFindByName(privconn, net->name)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2017-05-09 22:38:58 +00:00
|
|
|
def = virNetworkObjGetDef(obj);
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
if (virNetworkObjIsActive(obj)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2017-05-12 11:57:12 +00:00
|
|
|
_("Network '%s' is already running"), net->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-10 11:22:15 +00:00
|
|
|
virNetworkObjSetActive(obj, true);
|
2017-05-09 22:38:58 +00:00
|
|
|
event = virNetworkEventLifecycleNew(def->name, def->uuid,
|
2013-12-11 13:40:41 +00:00
|
|
|
VIR_NETWORK_EVENT_STARTED,
|
|
|
|
0);
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
|
|
|
static int
|
2017-05-12 11:57:12 +00:00
|
|
|
testNetworkDestroy(virNetworkPtr net)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2017-05-12 11:57:12 +00:00
|
|
|
testDriverPtr privconn = net->conn->privateData;
|
|
|
|
virNetworkObjPtr obj;
|
2017-05-09 22:38:58 +00:00
|
|
|
virNetworkDefPtr def;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2013-12-11 10:37:59 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
if (!(obj = testNetworkObjFindByName(privconn, net->name)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2017-05-09 22:38:58 +00:00
|
|
|
def = virNetworkObjGetDef(obj);
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2017-05-10 11:22:15 +00:00
|
|
|
virNetworkObjSetActive(obj, false);
|
2017-05-09 22:38:58 +00:00
|
|
|
event = virNetworkEventLifecycleNew(def->name, def->uuid,
|
2013-12-11 13:40:41 +00:00
|
|
|
VIR_NETWORK_EVENT_STOPPED,
|
|
|
|
0);
|
2017-05-10 11:29:57 +00:00
|
|
|
if (!virNetworkObjIsPersistent(obj))
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjRemoveInactive(privconn->networks, obj);
|
2015-02-26 12:45:05 +00:00
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
|
|
|
static char *
|
2017-05-12 11:57:12 +00:00
|
|
|
testNetworkGetXMLDesc(virNetworkPtr net,
|
2017-05-12 11:45:37 +00:00
|
|
|
unsigned int flags)
|
2011-07-06 20:40:19 +00:00
|
|
|
{
|
2017-05-12 11:57:12 +00:00
|
|
|
testDriverPtr privconn = net->conn->privateData;
|
|
|
|
virNetworkObjPtr obj;
|
2008-12-04 20:57:47 +00:00
|
|
|
char *ret = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
if (!(obj = testNetworkObjFindByName(privconn, net->name)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2017-05-09 22:38:58 +00:00
|
|
|
ret = virNetworkDefFormat(virNetworkObjGetDef(obj), flags);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
|
|
|
static char *
|
2017-05-12 11:57:12 +00:00
|
|
|
testNetworkGetBridgeName(virNetworkPtr net)
|
2017-05-12 11:45:37 +00:00
|
|
|
{
|
2017-05-12 11:57:12 +00:00
|
|
|
testDriverPtr privconn = net->conn->privateData;
|
2008-07-11 16:39:08 +00:00
|
|
|
char *bridge = NULL;
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjPtr obj;
|
2017-05-09 22:38:58 +00:00
|
|
|
virNetworkDefPtr def;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
if (!(obj = testNetworkObjFindByName(privconn, net->name)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2017-05-09 22:38:58 +00:00
|
|
|
def = virNetworkObjGetDef(obj);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-09 22:38:58 +00:00
|
|
|
if (!(def->bridge)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("network '%s' does not have a bridge name."),
|
2017-05-09 22:38:58 +00:00
|
|
|
def->name);
|
2009-09-23 15:54:48 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-05-09 22:38:58 +00:00
|
|
|
ignore_value(VIR_STRDUP(bridge, def->bridge));
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
2007-07-27 23:23:00 +00:00
|
|
|
return bridge;
|
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
|
|
|
static int
|
2017-05-12 11:57:12 +00:00
|
|
|
testNetworkGetAutostart(virNetworkPtr net,
|
2017-05-12 11:45:37 +00:00
|
|
|
int *autostart)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2017-05-12 11:57:12 +00:00
|
|
|
testDriverPtr privconn = net->conn->privateData;
|
|
|
|
virNetworkObjPtr obj;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
if (!(obj = testNetworkObjFindByName(privconn, net->name)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-10 11:12:27 +00:00
|
|
|
*autostart = virNetworkObjIsAutostart(obj) ? 1 : 0;
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 11:45:37 +00:00
|
|
|
|
|
|
|
static int
|
2017-05-12 11:57:12 +00:00
|
|
|
testNetworkSetAutostart(virNetworkPtr net,
|
2017-05-12 11:45:37 +00:00
|
|
|
int autostart)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2017-05-12 11:57:12 +00:00
|
|
|
testDriverPtr privconn = net->conn->privateData;
|
|
|
|
virNetworkObjPtr obj;
|
2017-05-10 11:12:27 +00:00
|
|
|
bool new_autostart = (autostart != 0);
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-12 11:57:12 +00:00
|
|
|
if (!(obj = testNetworkObjFindByName(privconn, net->name)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-10 11:12:27 +00:00
|
|
|
virNetworkObjSetAutostart(obj, new_autostart);
|
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-05-12 11:57:12 +00:00
|
|
|
virNetworkObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2009-07-21 13:45:55 +00:00
|
|
|
/*
|
|
|
|
* Physical host interface routines
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2017-03-04 14:16:33 +00:00
|
|
|
static virInterfaceObjPtr
|
|
|
|
testInterfaceObjFindByName(testDriverPtr privconn,
|
|
|
|
const char *name)
|
|
|
|
{
|
2017-04-19 02:29:44 +00:00
|
|
|
virInterfaceObjPtr obj;
|
2017-03-04 14:16:33 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-04-14 20:49:48 +00:00
|
|
|
obj = virInterfaceObjListFindByName(privconn->ifaces, name);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2017-03-04 14:16:33 +00:00
|
|
|
|
2017-04-19 02:29:44 +00:00
|
|
|
if (!obj)
|
2017-03-04 14:16:33 +00:00
|
|
|
virReportError(VIR_ERR_NO_INTERFACE,
|
|
|
|
_("no interface with matching name '%s'"),
|
|
|
|
name);
|
|
|
|
|
2017-04-19 02:29:44 +00:00
|
|
|
return obj;
|
2017-03-04 14:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
static int
|
|
|
|
testConnectNumOfInterfaces(virConnectPtr conn)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-04-06 13:23:17 +00:00
|
|
|
int ninterfaces;
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-04-14 20:49:48 +00:00
|
|
|
ninterfaces = virInterfaceObjListNumOfInterfaces(privconn->ifaces, true);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2017-04-06 13:23:17 +00:00
|
|
|
return ninterfaces;
|
2009-07-21 13:45:55 +00:00
|
|
|
}
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testConnectListInterfaces(virConnectPtr conn,
|
|
|
|
char **const names,
|
|
|
|
int maxnames)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-04-06 13:37:57 +00:00
|
|
|
int nnames;
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-04-14 20:49:48 +00:00
|
|
|
nnames = virInterfaceObjListGetNames(privconn->ifaces, true,
|
|
|
|
names, maxnames);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2017-04-06 13:37:57 +00:00
|
|
|
return nnames;
|
2009-07-21 13:45:55 +00:00
|
|
|
}
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testConnectNumOfDefinedInterfaces(virConnectPtr conn)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-04-06 13:23:17 +00:00
|
|
|
int ninterfaces;
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-04-14 20:49:48 +00:00
|
|
|
ninterfaces = virInterfaceObjListNumOfInterfaces(privconn->ifaces, false);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2017-04-06 13:23:17 +00:00
|
|
|
return ninterfaces;
|
2009-07-21 13:45:55 +00:00
|
|
|
}
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testConnectListDefinedInterfaces(virConnectPtr conn,
|
|
|
|
char **const names,
|
|
|
|
int maxnames)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-04-06 13:37:57 +00:00
|
|
|
int nnames;
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-04-14 20:49:48 +00:00
|
|
|
nnames = virInterfaceObjListGetNames(privconn->ifaces, false,
|
|
|
|
names, maxnames);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2017-04-06 13:37:57 +00:00
|
|
|
return nnames;
|
2009-07-21 13:45:55 +00:00
|
|
|
}
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
|
2018-07-10 19:01:45 +00:00
|
|
|
static int
|
|
|
|
testConnectListAllInterfaces(virConnectPtr conn,
|
|
|
|
virInterfacePtr **ifaces,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
testDriverPtr privconn = conn->privateData;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE, -1);
|
|
|
|
|
|
|
|
return virInterfaceObjListExport(conn, privconn->ifaces, ifaces,
|
|
|
|
NULL, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
static virInterfacePtr
|
|
|
|
testInterfaceLookupByName(virConnectPtr conn,
|
|
|
|
const char *name)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-04-19 02:29:44 +00:00
|
|
|
virInterfaceObjPtr obj;
|
2017-04-19 02:32:17 +00:00
|
|
|
virInterfaceDefPtr def;
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfacePtr ret = NULL;
|
|
|
|
|
2017-04-19 02:29:44 +00:00
|
|
|
if (!(obj = testInterfaceObjFindByName(privconn, name)))
|
2017-04-14 13:05:21 +00:00
|
|
|
return NULL;
|
2017-04-25 21:45:02 +00:00
|
|
|
def = virInterfaceObjGetDef(obj);
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2017-04-19 02:32:17 +00:00
|
|
|
ret = virGetInterface(conn, def->name, def->mac);
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2017-05-15 18:31:44 +00:00
|
|
|
virInterfaceObjEndAPI(&obj);
|
2009-07-21 13:45:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
|
|
|
|
static virInterfacePtr
|
|
|
|
testInterfaceLookupByMACString(virConnectPtr conn,
|
|
|
|
const char *mac)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2009-07-21 13:45:55 +00:00
|
|
|
int ifacect;
|
2017-04-15 11:08:01 +00:00
|
|
|
char *ifacenames[] = { NULL, NULL };
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfacePtr ret = NULL;
|
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-04-15 11:08:01 +00:00
|
|
|
ifacect = virInterfaceObjListFindByMACString(privconn->ifaces, mac,
|
|
|
|
ifacenames, 2);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2009-07-21 13:45:55 +00:00
|
|
|
|
|
|
|
if (ifacect == 0) {
|
2017-04-15 11:08:01 +00:00
|
|
|
virReportError(VIR_ERR_NO_INTERFACE,
|
|
|
|
_("no interface with matching mac '%s'"), mac);
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ifacect > 1) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_MULTIPLE_INTERFACES, NULL);
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-04-15 11:08:01 +00:00
|
|
|
ret = virGetInterface(conn, ifacenames[0], mac);
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-04-15 11:08:01 +00:00
|
|
|
VIR_FREE(ifacenames[0]);
|
|
|
|
VIR_FREE(ifacenames[1]);
|
2009-07-21 13:45:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testInterfaceIsActive(virInterfacePtr iface)
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = iface->conn->privateData;
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
virInterfaceObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
2017-03-04 14:16:33 +00:00
|
|
|
if (!(obj = testInterfaceObjFindByName(privconn, iface->name)))
|
2017-04-14 13:05:21 +00:00
|
|
|
return -1;
|
2017-03-04 14:16:33 +00:00
|
|
|
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
ret = virInterfaceObjIsActive(obj);
|
|
|
|
|
2017-05-15 18:31:44 +00:00
|
|
|
virInterfaceObjEndAPI(&obj);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testInterfaceChangeBegin(virConnectPtr conn,
|
|
|
|
unsigned int flags)
|
2011-05-09 19:17:26 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2011-05-09 19:17:26 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2011-05-09 19:17:26 +00:00
|
|
|
if (privconn->transaction_running) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
2012-07-18 12:12:06 +00:00
|
|
|
_("there is another transaction running."));
|
2011-05-09 19:17:26 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
privconn->transaction_running = true;
|
|
|
|
|
2017-04-14 19:45:27 +00:00
|
|
|
if (!(privconn->backupIfaces = virInterfaceObjListClone(privconn->ifaces)))
|
2011-05-09 19:17:26 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2011-05-09 19:17:26 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testInterfaceChangeCommit(virConnectPtr conn,
|
|
|
|
unsigned int flags)
|
2011-05-09 19:17:26 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2011-05-09 19:17:26 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2011-05-09 19:17:26 +00:00
|
|
|
|
|
|
|
if (!privconn->transaction_running) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
2012-07-18 12:12:06 +00:00
|
|
|
_("no transaction running, "
|
|
|
|
"nothing to be committed."));
|
2011-05-09 19:17:26 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-10-19 15:51:22 +00:00
|
|
|
virObjectUnref(privconn->backupIfaces);
|
2011-05-09 19:17:26 +00:00
|
|
|
privconn->transaction_running = false;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2011-05-09 19:17:26 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testInterfaceChangeRollback(virConnectPtr conn,
|
|
|
|
unsigned int flags)
|
2011-05-09 19:17:26 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2011-05-09 19:17:26 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2011-05-09 19:17:26 +00:00
|
|
|
|
|
|
|
if (!privconn->transaction_running) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
2012-07-18 12:12:06 +00:00
|
|
|
_("no transaction running, "
|
|
|
|
"nothing to rollback."));
|
2011-05-09 19:17:26 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-10-19 15:51:22 +00:00
|
|
|
virObjectUnref(privconn->ifaces);
|
2017-04-14 19:45:27 +00:00
|
|
|
privconn->ifaces = privconn->backupIfaces;
|
|
|
|
privconn->backupIfaces = NULL;
|
2011-05-09 19:17:26 +00:00
|
|
|
|
|
|
|
privconn->transaction_running = false;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2011-05-09 19:17:26 +00:00
|
|
|
return ret;
|
|
|
|
}
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
|
|
|
|
static char *
|
|
|
|
testInterfaceGetXMLDesc(virInterfacePtr iface,
|
|
|
|
unsigned int flags)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = iface->conn->privateData;
|
2017-04-19 02:29:44 +00:00
|
|
|
virInterfaceObjPtr obj;
|
2017-04-25 21:45:02 +00:00
|
|
|
virInterfaceDefPtr def;
|
2009-07-21 13:45:55 +00:00
|
|
|
char *ret = NULL;
|
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2017-04-19 02:29:44 +00:00
|
|
|
if (!(obj = testInterfaceObjFindByName(privconn, iface->name)))
|
2017-04-14 13:05:21 +00:00
|
|
|
return NULL;
|
2017-04-25 21:45:02 +00:00
|
|
|
def = virInterfaceObjGetDef(obj);
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2017-04-25 21:45:02 +00:00
|
|
|
ret = virInterfaceDefFormat(def);
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2017-05-15 18:31:44 +00:00
|
|
|
virInterfaceObjEndAPI(&obj);
|
2009-07-21 13:45:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
static virInterfacePtr
|
|
|
|
testInterfaceDefineXML(virConnectPtr conn,
|
|
|
|
const char *xmlStr,
|
|
|
|
unsigned int flags)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceDefPtr def;
|
2017-04-19 02:29:44 +00:00
|
|
|
virInterfaceObjPtr obj = NULL;
|
2017-04-19 02:32:17 +00:00
|
|
|
virInterfaceDefPtr objdef;
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfacePtr ret = NULL;
|
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2010-02-10 12:28:05 +00:00
|
|
|
if ((def = virInterfaceDefParseString(xmlStr)) == NULL)
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-04-14 20:49:48 +00:00
|
|
|
if ((obj = virInterfaceObjListAssignDef(privconn->ifaces, def)) == NULL)
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
2017-04-25 21:45:02 +00:00
|
|
|
objdef = virInterfaceObjGetDef(obj);
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2017-04-19 02:32:17 +00:00
|
|
|
ret = virGetInterface(conn, objdef->name, objdef->mac);
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceDefFree(def);
|
2017-05-15 18:31:44 +00:00
|
|
|
virInterfaceObjEndAPI(&obj);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2009-07-21 13:45:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testInterfaceUndefine(virInterfacePtr iface)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = iface->conn->privateData;
|
2017-04-19 02:29:44 +00:00
|
|
|
virInterfaceObjPtr obj;
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2017-04-19 02:29:44 +00:00
|
|
|
if (!(obj = testInterfaceObjFindByName(privconn, iface->name)))
|
2017-04-14 13:05:21 +00:00
|
|
|
return -1;
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2017-04-14 20:49:48 +00:00
|
|
|
virInterfaceObjListRemove(privconn->ifaces, obj);
|
2017-05-15 18:31:44 +00:00
|
|
|
virObjectUnref(obj);
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2017-04-14 13:05:21 +00:00
|
|
|
return 0;
|
2009-07-21 13:45:55 +00:00
|
|
|
}
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testInterfaceCreate(virInterfacePtr iface,
|
|
|
|
unsigned int flags)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = iface->conn->privateData;
|
2017-04-19 02:29:44 +00:00
|
|
|
virInterfaceObjPtr obj;
|
2009-07-21 13:45:55 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2017-04-19 02:29:44 +00:00
|
|
|
if (!(obj = testInterfaceObjFindByName(privconn, iface->name)))
|
2017-04-14 13:05:21 +00:00
|
|
|
return -1;
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2017-04-25 21:45:02 +00:00
|
|
|
if (virInterfaceObjIsActive(obj)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, NULL);
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-04-25 21:45:02 +00:00
|
|
|
virInterfaceObjSetActive(obj, true);
|
2009-07-21 13:45:55 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-05-15 18:31:44 +00:00
|
|
|
virInterfaceObjEndAPI(&obj);
|
2009-07-21 13:45:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-06 13:46:43 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testInterfaceDestroy(virInterfacePtr iface,
|
|
|
|
unsigned int flags)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = iface->conn->privateData;
|
2017-04-19 02:29:44 +00:00
|
|
|
virInterfaceObjPtr obj;
|
2009-07-21 13:45:55 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2017-04-19 02:29:44 +00:00
|
|
|
if (!(obj = testInterfaceObjFindByName(privconn, iface->name)))
|
2017-04-14 13:05:21 +00:00
|
|
|
return -1;
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2017-04-25 21:45:02 +00:00
|
|
|
if (!virInterfaceObjIsActive(obj)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, NULL);
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-04-25 21:45:02 +00:00
|
|
|
virInterfaceObjSetActive(obj, false);
|
2009-07-21 13:45:55 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-05-15 18:31:44 +00:00
|
|
|
virInterfaceObjEndAPI(&obj);
|
2009-07-21 13:45:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
/*
|
|
|
|
* Storage Driver routines
|
|
|
|
*/
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
static int
|
2017-05-05 19:31:40 +00:00
|
|
|
testStoragePoolObjSetDefaults(virStoragePoolObjPtr obj)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2017-07-26 15:56:31 +00:00
|
|
|
char *configFile;
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
def->capacity = defaultPoolCap;
|
|
|
|
def->allocation = defaultPoolAlloc;
|
|
|
|
def->available = defaultPoolCap - defaultPoolAlloc;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-07-26 15:56:31 +00:00
|
|
|
if (VIR_STRDUP(configFile, "") < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
virStoragePoolObjSetConfigFile(obj, configFile);
|
|
|
|
return 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
|
2017-03-04 14:16:33 +00:00
|
|
|
static virStoragePoolObjPtr
|
|
|
|
testStoragePoolObjFindByName(testDriverPtr privconn,
|
|
|
|
const char *name)
|
|
|
|
{
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-03-04 14:16:33 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-10-07 11:24:24 +00:00
|
|
|
obj = virStoragePoolObjFindByName(privconn->pools, name);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2017-03-04 14:16:33 +00:00
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
if (!obj)
|
2017-03-04 14:16:33 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
|
|
_("no storage pool with matching name '%s'"),
|
|
|
|
name);
|
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
return obj;
|
2017-03-04 14:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
static virStoragePoolObjPtr
|
|
|
|
testStoragePoolObjFindActiveByName(testDriverPtr privconn,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
virStoragePoolObjPtr obj;
|
|
|
|
|
|
|
|
if (!(obj = testStoragePoolObjFindByName(privconn, name)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(obj)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), name);
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2017-05-05 21:02:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virStoragePoolObjPtr
|
|
|
|
testStoragePoolObjFindInactiveByName(testDriverPtr privconn,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
virStoragePoolObjPtr obj;
|
|
|
|
|
|
|
|
if (!(obj = testStoragePoolObjFindByName(privconn, name)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (virStoragePoolObjIsActive(obj)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is active"), name);
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2017-05-05 21:02:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-04 14:48:11 +00:00
|
|
|
static virStoragePoolObjPtr
|
|
|
|
testStoragePoolObjFindByUUID(testDriverPtr privconn,
|
|
|
|
const unsigned char *uuid)
|
|
|
|
{
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-03-04 14:48:11 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-10-07 11:24:24 +00:00
|
|
|
obj = virStoragePoolObjFindByUUID(privconn->pools, uuid);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2017-03-04 14:48:11 +00:00
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
if (!obj) {
|
2017-03-04 14:48:11 +00:00
|
|
|
virUUIDFormat(uuid, uuidstr);
|
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
|
|
_("no storage pool with matching uuid '%s'"),
|
|
|
|
uuidstr);
|
|
|
|
}
|
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
return obj;
|
2017-03-04 14:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static virStoragePoolPtr
|
|
|
|
testStoragePoolLookupByUUID(virConnectPtr conn,
|
2014-03-18 08:17:30 +00:00
|
|
|
const unsigned char *uuid)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolPtr pool = NULL;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindByUUID(privconn, uuid)))
|
2017-05-05 21:31:36 +00:00
|
|
|
return NULL;
|
2017-05-08 12:21:52 +00:00
|
|
|
def = virStoragePoolObjGetDef(obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2017-05-05 19:31:40 +00:00
|
|
|
return pool;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static virStoragePoolPtr
|
|
|
|
testStoragePoolLookupByName(virConnectPtr conn,
|
2014-03-18 08:17:30 +00:00
|
|
|
const char *name)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolPtr pool = NULL;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindByName(privconn, name)))
|
2017-05-05 21:31:36 +00:00
|
|
|
return NULL;
|
2017-05-08 12:21:52 +00:00
|
|
|
def = virStoragePoolObjGetDef(obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2017-05-05 19:31:40 +00:00
|
|
|
return pool;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static virStoragePoolPtr
|
2014-03-18 08:17:30 +00:00
|
|
|
testStoragePoolLookupByVolume(virStorageVolPtr vol)
|
|
|
|
{
|
2008-10-30 17:40:57 +00:00
|
|
|
return testStoragePoolLookupByName(vol->conn, vol->pool);
|
|
|
|
}
|
|
|
|
|
2017-03-21 10:30:46 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static int
|
2014-03-18 08:17:30 +00:00
|
|
|
testConnectNumOfStoragePools(virConnectPtr conn)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
Convert 'int i' to 'size_t i' in src/test/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int numActive = 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-10-07 11:24:24 +00:00
|
|
|
numActive = virStoragePoolObjNumOfStoragePools(privconn->pools, conn,
|
2017-03-21 10:30:46 +00:00
|
|
|
true, NULL);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
|
|
|
return numActive;
|
|
|
|
}
|
|
|
|
|
2017-03-21 13:15:18 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testConnectListStoragePools(virConnectPtr conn,
|
|
|
|
char **const names,
|
2017-03-21 13:15:18 +00:00
|
|
|
int maxnames)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
Convert 'int i' to 'size_t i' in src/test/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int n = 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-10-07 11:24:24 +00:00
|
|
|
n = virStoragePoolObjGetNames(privconn->pools, conn, true, NULL,
|
2017-03-21 13:15:18 +00:00
|
|
|
names, maxnames);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2017-03-21 10:30:46 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static int
|
2014-03-18 08:17:30 +00:00
|
|
|
testConnectNumOfDefinedStoragePools(virConnectPtr conn)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
Convert 'int i' to 'size_t i' in src/test/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int numInactive = 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-10-07 11:24:24 +00:00
|
|
|
numInactive = virStoragePoolObjNumOfStoragePools(privconn->pools, conn,
|
2017-03-21 10:30:46 +00:00
|
|
|
false, NULL);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
|
|
|
return numInactive;
|
|
|
|
}
|
|
|
|
|
2017-03-21 13:15:18 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testConnectListDefinedStoragePools(virConnectPtr conn,
|
|
|
|
char **const names,
|
2017-03-21 13:15:18 +00:00
|
|
|
int maxnames)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
Convert 'int i' to 'size_t i' in src/test/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int n = 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-10-07 11:24:24 +00:00
|
|
|
n = virStoragePoolObjGetNames(privconn->pools, conn, false, NULL,
|
2017-03-21 13:15:18 +00:00
|
|
|
names, maxnames);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2012-09-04 15:16:28 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testConnectListAllStoragePools(virConnectPtr conn,
|
|
|
|
virStoragePoolPtr **pools,
|
|
|
|
unsigned int flags)
|
2012-09-04 15:16:28 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2012-09-04 15:16:28 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ALL, -1);
|
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-10-07 11:24:24 +00:00
|
|
|
ret = virStoragePoolObjListExport(conn, privconn->pools, pools,
|
2013-06-26 17:47:48 +00:00
|
|
|
NULL, flags);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2012-09-04 15:16:28 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testStoragePoolIsActive(virStoragePoolPtr pool)
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
2017-03-04 14:48:11 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindByUUID(privconn, pool->uuid)))
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
goto cleanup;
|
2017-03-04 14:48:11 +00:00
|
|
|
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
ret = virStoragePoolObjIsActive(obj);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
if (obj)
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testStoragePoolIsPersistent(virStoragePoolPtr pool)
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
2017-03-04 14:48:11 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindByUUID(privconn, pool->uuid)))
|
2017-05-05 21:31:36 +00:00
|
|
|
return -1;
|
2017-03-04 14:48:11 +00:00
|
|
|
|
2017-07-26 15:56:31 +00:00
|
|
|
ret = virStoragePoolObjGetConfigFile(obj) ? 1 : 0;
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testStoragePoolCreate(virStoragePoolPtr pool,
|
|
|
|
unsigned int flags)
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2016-06-15 18:15:39 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindInactiveByName(privconn, pool->name)))
|
|
|
|
return -1;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-07-26 16:15:42 +00:00
|
|
|
virStoragePoolObjSetActive(obj, true);
|
2016-06-15 18:15:39 +00:00
|
|
|
|
|
|
|
event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid,
|
|
|
|
VIR_STORAGE_POOL_EVENT_STARTED,
|
|
|
|
0);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2017-05-05 21:02:01 +00:00
|
|
|
return 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static char *
|
2013-04-23 12:50:18 +00:00
|
|
|
testConnectFindStoragePoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
const char *type,
|
|
|
|
const char *srcSpec,
|
|
|
|
unsigned int flags)
|
2008-10-30 17:40:57 +00:00
|
|
|
{
|
2009-10-16 08:35:05 +00:00
|
|
|
int pool_type;
|
|
|
|
char *ret = NULL;
|
2019-01-31 13:48:11 +00:00
|
|
|
VIR_AUTOPTR(virStoragePoolSource) source = NULL;
|
2009-10-16 08:35:05 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2009-10-16 08:35:05 +00:00
|
|
|
pool_type = virStoragePoolTypeFromString(type);
|
|
|
|
if (!pool_type) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unknown storage pool type %s"), type);
|
2019-01-31 13:48:11 +00:00
|
|
|
return NULL;
|
2009-10-16 08:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (srcSpec) {
|
2010-02-10 11:42:56 +00:00
|
|
|
source = virStoragePoolDefParseSourceString(srcSpec, pool_type);
|
2009-10-16 08:35:05 +00:00
|
|
|
if (!source)
|
2019-01-31 13:48:11 +00:00
|
|
|
return NULL;
|
2009-10-16 08:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (pool_type) {
|
|
|
|
|
|
|
|
case VIR_STORAGE_POOL_LOGICAL:
|
2013-05-03 12:49:30 +00:00
|
|
|
ignore_value(VIR_STRDUP(ret, defaultPoolSourcesLogicalXML));
|
2019-01-31 13:48:11 +00:00
|
|
|
return ret;
|
2009-10-16 08:35:05 +00:00
|
|
|
|
|
|
|
case VIR_STORAGE_POOL_NETFS:
|
2012-04-25 10:43:09 +00:00
|
|
|
if (!source || !source->hosts[0].name) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
"%s", _("hostname must be specified for netfs sources"));
|
2019-01-31 13:48:11 +00:00
|
|
|
return NULL;
|
2009-10-16 08:35:05 +00:00
|
|
|
}
|
|
|
|
|
2013-07-04 10:16:47 +00:00
|
|
|
ignore_value(virAsprintf(&ret, defaultPoolSourcesNetFSXML,
|
|
|
|
source->hosts[0].name));
|
2019-01-31 13:48:11 +00:00
|
|
|
return ret;
|
2009-10-16 08:35:05 +00:00
|
|
|
|
|
|
|
default:
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_SUPPORT,
|
|
|
|
_("pool type '%s' does not support source discovery"), type);
|
2009-10-16 08:35:05 +00:00
|
|
|
}
|
|
|
|
|
2019-01-31 13:48:11 +00:00
|
|
|
return NULL;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-29 16:12:48 +00:00
|
|
|
static virNodeDeviceObjPtr
|
|
|
|
testNodeDeviceMockCreateVport(testDriverPtr driver,
|
|
|
|
const char *wwnn,
|
|
|
|
const char *wwpn);
|
|
|
|
static int
|
|
|
|
testCreateVport(testDriverPtr driver,
|
|
|
|
const char *wwnn,
|
|
|
|
const char *wwpn)
|
|
|
|
{
|
|
|
|
virNodeDeviceObjPtr obj = NULL;
|
|
|
|
/* The storage_backend_scsi createVport() will use the input adapter
|
|
|
|
* fields parent name, parent_wwnn/parent_wwpn, or parent_fabric_wwn
|
|
|
|
* in order to determine whether the provided parent can be used to
|
|
|
|
* create a vHBA or will find "an available vport capable" to create
|
|
|
|
* a vHBA. In order to do this, it uses the virVHBA* API's which traverse
|
|
|
|
* the sysfs looking at various fields (rather than going via nodedev).
|
|
|
|
*
|
|
|
|
* Since the test environ doesn't have the sysfs for the storage pool
|
|
|
|
* test, at least for now use the node device test infrastructure to
|
|
|
|
* create the vHBA. In the long run the result is the same. */
|
|
|
|
if (!(obj = testNodeDeviceMockCreateVport(driver, wwnn, wwpn)))
|
|
|
|
return -1;
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
2017-01-29 16:12:48 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static virStoragePoolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
testStoragePoolCreateXML(virConnectPtr conn,
|
|
|
|
const char *xml,
|
|
|
|
unsigned int flags)
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj = NULL;
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolPtr pool = NULL;
|
2016-06-15 18:15:39 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2019-01-31 15:21:47 +00:00
|
|
|
VIR_AUTOPTR(virStoragePoolDef) newDef = NULL;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-05-08 12:21:52 +00:00
|
|
|
if (!(newDef = virStoragePoolDefParseString(xml)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2018-08-17 10:30:08 +00:00
|
|
|
if (!(obj = virStoragePoolObjAssignDef(privconn->pools, newDef, true)))
|
2008-12-04 20:59:06 +00:00
|
|
|
goto cleanup;
|
2017-05-08 12:21:52 +00:00
|
|
|
newDef = NULL;
|
|
|
|
def = virStoragePoolObjGetDef(obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
|
2017-01-29 16:12:48 +00:00
|
|
|
/* In the real code, we'd call virVHBAManageVport followed by
|
|
|
|
* find_new_device, but we cannot do that here since we're not
|
|
|
|
* mocking udev. The mock routine will copy an existing vHBA and
|
|
|
|
* rename a few fields to mock that. */
|
|
|
|
if (testCreateVport(privconn,
|
2017-05-08 12:21:52 +00:00
|
|
|
def->source.adapter.data.fchost.wwnn,
|
|
|
|
def->source.adapter.data.fchost.wwpn) < 0) {
|
2017-10-07 11:24:24 +00:00
|
|
|
virStoragePoolObjRemove(privconn->pools, obj);
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectUnref(obj);
|
2017-05-05 19:31:40 +00:00
|
|
|
obj = NULL;
|
2017-01-29 16:12:48 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
if (testStoragePoolObjSetDefaults(obj) == -1) {
|
2017-10-07 11:24:24 +00:00
|
|
|
virStoragePoolObjRemove(privconn->pools, obj);
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectUnref(obj);
|
2017-05-05 19:31:40 +00:00
|
|
|
obj = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
2017-03-15 19:09:35 +00:00
|
|
|
|
|
|
|
/* *SetDefaults fills this in for the persistent pools, but this
|
|
|
|
* would be a transient pool so remove it; otherwise, the Destroy
|
|
|
|
* code will not Remove the pool */
|
2017-07-26 15:56:31 +00:00
|
|
|
virStoragePoolObjSetConfigFile(obj, NULL);
|
2017-03-15 19:09:35 +00:00
|
|
|
|
2017-07-26 16:15:42 +00:00
|
|
|
virStoragePoolObjSetActive(obj, true);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
event = virStoragePoolEventLifecycleNew(def->name, def->uuid,
|
2016-06-15 18:15:39 +00:00
|
|
|
VIR_STORAGE_POOL_EVENT_STARTED,
|
|
|
|
0);
|
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2017-05-05 19:31:40 +00:00
|
|
|
return pool;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static virStoragePoolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
testStoragePoolDefineXML(virConnectPtr conn,
|
|
|
|
const char *xml,
|
|
|
|
unsigned int flags)
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj = NULL;
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolPtr pool = NULL;
|
2016-06-15 18:15:39 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2019-01-31 15:21:47 +00:00
|
|
|
VIR_AUTOPTR(virStoragePoolDef) newDef = NULL;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-05-08 12:21:52 +00:00
|
|
|
if (!(newDef = virStoragePoolDefParseString(xml)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
newDef->capacity = defaultPoolCap;
|
|
|
|
newDef->allocation = defaultPoolAlloc;
|
|
|
|
newDef->available = defaultPoolCap - defaultPoolAlloc;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2018-08-17 10:30:08 +00:00
|
|
|
if (!(obj = virStoragePoolObjAssignDef(privconn->pools, newDef, false)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2017-05-08 12:21:52 +00:00
|
|
|
newDef = NULL;
|
|
|
|
def = virStoragePoolObjGetDef(obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
event = virStoragePoolEventLifecycleNew(def->name, def->uuid,
|
2016-06-15 18:15:39 +00:00
|
|
|
VIR_STORAGE_POOL_EVENT_DEFINED,
|
|
|
|
0);
|
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
if (testStoragePoolObjSetDefaults(obj) == -1) {
|
2017-10-07 11:24:24 +00:00
|
|
|
virStoragePoolObjRemove(privconn->pools, obj);
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectUnref(obj);
|
2017-05-05 19:31:40 +00:00
|
|
|
obj = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2017-05-05 19:31:40 +00:00
|
|
|
return pool;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static int
|
2014-03-18 08:17:30 +00:00
|
|
|
testStoragePoolUndefine(virStoragePoolPtr pool)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2016-06-15 18:15:39 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindInactiveByName(privconn, pool->name)))
|
|
|
|
return -1;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2016-06-15 18:15:39 +00:00
|
|
|
event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid,
|
|
|
|
VIR_STORAGE_POOL_EVENT_UNDEFINED,
|
|
|
|
0);
|
|
|
|
|
2017-10-07 11:24:24 +00:00
|
|
|
virStoragePoolObjRemove(privconn->pools, obj);
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectUnref(obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2017-05-05 21:02:01 +00:00
|
|
|
return 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static int
|
2008-12-04 20:56:10 +00:00
|
|
|
testStoragePoolBuild(virStoragePoolPtr pool,
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-09-09 15:09:49 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindInactiveByName(privconn, pool->name)))
|
|
|
|
return -1;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-09-09 15:09:49 +00:00
|
|
|
event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid,
|
|
|
|
VIR_STORAGE_POOL_EVENT_CREATED,
|
|
|
|
0);
|
|
|
|
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2017-09-09 15:09:49 +00:00
|
|
|
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2017-05-05 21:02:01 +00:00
|
|
|
return 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-29 16:12:48 +00:00
|
|
|
static int
|
|
|
|
testDestroyVport(testDriverPtr privconn,
|
|
|
|
const char *wwnn ATTRIBUTE_UNUSED,
|
|
|
|
const char *wwpn ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
virNodeDeviceObjPtr obj = NULL;
|
|
|
|
virObjectEventPtr event = NULL;
|
|
|
|
|
|
|
|
/* NB: Cannot use virVHBAGetHostByWWN (yet) like the storage_backend_scsi
|
|
|
|
* deleteVport() helper since that traverses the file system looking for
|
|
|
|
* the wwnn/wwpn. So our choice short term is to cheat and use the name
|
|
|
|
* (scsi_host12) we know was created.
|
|
|
|
*
|
|
|
|
* Reaching across the boundaries of space and time into the
|
|
|
|
* Node Device in order to remove */
|
2017-05-12 18:47:17 +00:00
|
|
|
if (!(obj = virNodeDeviceObjListFindByName(privconn->devs,
|
|
|
|
"scsi_host12"))) {
|
2017-01-29 16:12:48 +00:00
|
|
|
virReportError(VIR_ERR_NO_NODE_DEVICE, "%s",
|
|
|
|
_("no node device with matching name 'scsi_host12'"));
|
2017-05-12 15:08:57 +00:00
|
|
|
return -1;
|
2017-01-29 16:12:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
event = virNodeDeviceEventLifecycleNew("scsi_host12",
|
|
|
|
VIR_NODE_DEVICE_EVENT_DELETED,
|
|
|
|
0);
|
|
|
|
|
2017-05-12 18:47:17 +00:00
|
|
|
virNodeDeviceObjListRemove(privconn->devs, obj);
|
2017-05-15 15:00:59 +00:00
|
|
|
virObjectUnref(obj);
|
2017-01-29 16:12:48 +00:00
|
|
|
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2017-05-12 15:08:57 +00:00
|
|
|
return 0;
|
2017-01-29 16:12:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static int
|
2014-03-18 08:17:30 +00:00
|
|
|
testStoragePoolDestroy(virStoragePoolPtr pool)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2016-06-15 18:15:39 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
|
2017-05-12 15:08:57 +00:00
|
|
|
return -1;
|
2017-05-08 12:21:52 +00:00
|
|
|
def = virStoragePoolObjGetDef(obj);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-07-26 16:15:42 +00:00
|
|
|
virStoragePoolObjSetActive(obj, false);
|
2017-01-29 16:12:48 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
|
2017-01-29 16:12:48 +00:00
|
|
|
if (testDestroyVport(privconn,
|
2017-05-08 12:21:52 +00:00
|
|
|
def->source.adapter.data.fchost.wwnn,
|
|
|
|
def->source.adapter.data.fchost.wwpn) < 0)
|
2017-01-29 16:12:48 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
event = virStoragePoolEventLifecycleNew(def->name,
|
|
|
|
def->uuid,
|
2016-06-15 18:15:39 +00:00
|
|
|
VIR_STORAGE_POOL_EVENT_STOPPED,
|
|
|
|
0);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-07-26 15:56:31 +00:00
|
|
|
if (!(virStoragePoolObjGetConfigFile(obj))) {
|
2017-10-07 11:24:24 +00:00
|
|
|
virStoragePoolObjRemove(privconn->pools, obj);
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectUnref(obj);
|
2017-05-05 19:31:40 +00:00
|
|
|
obj = NULL;
|
2008-12-04 20:59:06 +00:00
|
|
|
}
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2008-12-04 20:56:10 +00:00
|
|
|
testStoragePoolDelete(virStoragePoolPtr pool,
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-09-09 15:09:49 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindInactiveByName(privconn, pool->name)))
|
|
|
|
return -1;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-09-09 15:09:49 +00:00
|
|
|
event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid,
|
|
|
|
VIR_STORAGE_POOL_EVENT_DELETED,
|
|
|
|
0);
|
|
|
|
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2017-09-09 15:09:49 +00:00
|
|
|
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2017-05-05 21:02:01 +00:00
|
|
|
return 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2008-12-04 20:56:10 +00:00
|
|
|
testStoragePoolRefresh(virStoragePoolPtr pool,
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2016-06-15 18:15:39 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
|
|
|
|
return -1;
|
2016-06-15 18:15:39 +00:00
|
|
|
|
2016-06-24 16:35:51 +00:00
|
|
|
event = virStoragePoolEventRefreshNew(pool->name, pool->uuid);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2017-05-05 21:02:01 +00:00
|
|
|
return 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2008-12-04 20:56:10 +00:00
|
|
|
testStoragePoolGetInfo(virStoragePoolPtr pool,
|
2014-03-18 08:17:30 +00:00
|
|
|
virStoragePoolInfoPtr info)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
|
2017-05-05 21:31:36 +00:00
|
|
|
return -1;
|
2017-05-08 12:21:52 +00:00
|
|
|
def = virStoragePoolObjGetDef(obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
|
|
|
memset(info, 0, sizeof(virStoragePoolInfo));
|
2017-07-26 16:15:42 +00:00
|
|
|
if (virStoragePoolObjIsActive(obj))
|
2008-10-30 17:40:57 +00:00
|
|
|
info->state = VIR_STORAGE_POOL_RUNNING;
|
|
|
|
else
|
|
|
|
info->state = VIR_STORAGE_POOL_INACTIVE;
|
2017-05-08 12:21:52 +00:00
|
|
|
info->capacity = def->capacity;
|
|
|
|
info->allocation = def->allocation;
|
|
|
|
info->available = def->available;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2017-05-05 21:31:36 +00:00
|
|
|
return 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static char *
|
2011-05-06 19:53:10 +00:00
|
|
|
testStoragePoolGetXMLDesc(virStoragePoolPtr pool,
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2008-12-04 20:57:47 +00:00
|
|
|
char *ret = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
|
2017-05-05 21:31:36 +00:00
|
|
|
return NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
ret = virStoragePoolDefFormat(virStoragePoolObjGetDef(obj));
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static int
|
2008-12-04 20:56:10 +00:00
|
|
|
testStoragePoolGetAutostart(virStoragePoolPtr pool,
|
2014-03-18 08:17:30 +00:00
|
|
|
int *autostart)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
|
2017-05-05 21:31:36 +00:00
|
|
|
return -1;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-07-26 15:56:31 +00:00
|
|
|
if (!virStoragePoolObjGetConfigFile(obj))
|
2008-10-30 17:40:57 +00:00
|
|
|
*autostart = 0;
|
2017-07-26 15:56:31 +00:00
|
|
|
else
|
2017-07-26 16:23:11 +00:00
|
|
|
*autostart = virStoragePoolObjIsAutostart(obj) ? 1 : 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2017-05-05 21:31:36 +00:00
|
|
|
return 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static int
|
2008-12-04 20:56:10 +00:00
|
|
|
testStoragePoolSetAutostart(virStoragePoolPtr pool,
|
2014-03-18 08:17:30 +00:00
|
|
|
int autostart)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-08-19 12:16:18 +00:00
|
|
|
bool new_autostart = (autostart != 0);
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
|
2017-05-05 21:31:36 +00:00
|
|
|
return -1;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-07-26 15:56:31 +00:00
|
|
|
if (!virStoragePoolObjGetConfigFile(obj)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
"%s", _("pool has no config file"));
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-08-19 12:16:18 +00:00
|
|
|
virStoragePoolObjSetAutostart(obj, new_autostart);
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2014-03-18 08:17:30 +00:00
|
|
|
testStoragePoolNumOfVolumes(virStoragePoolPtr pool)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
|
|
|
|
return -1;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-09 11:00:41 +00:00
|
|
|
ret = virStoragePoolObjNumOfVolumes(obj, pool->conn, NULL);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 16:16:26 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static int
|
2008-12-04 20:56:10 +00:00
|
|
|
testStoragePoolListVolumes(virStoragePoolPtr pool,
|
2008-10-30 17:40:57 +00:00
|
|
|
char **const names,
|
2014-03-18 08:17:30 +00:00
|
|
|
int maxnames)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-03-20 16:16:26 +00:00
|
|
|
int n = -1;
|
2008-12-04 20:59:06 +00:00
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
|
2017-03-20 16:16:26 +00:00
|
|
|
return -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-09 11:00:41 +00:00
|
|
|
n = virStoragePoolObjVolumeGetNames(obj, pool->conn, NULL, names, maxnames);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2017-03-20 16:16:26 +00:00
|
|
|
|
2012-09-04 15:32:56 +00:00
|
|
|
static int
|
2017-05-05 19:31:40 +00:00
|
|
|
testStoragePoolListAllVolumes(virStoragePoolPtr pool,
|
2012-09-04 15:32:56 +00:00
|
|
|
virStorageVolPtr **vols,
|
2014-03-18 08:17:30 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2017-05-05 19:31:40 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr obj;
|
2012-09-04 15:32:56 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindByUUID(privconn, pool->uuid)))
|
2017-03-20 17:48:47 +00:00
|
|
|
return -1;
|
2012-09-04 15:32:56 +00:00
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
if (!virStoragePoolObjIsActive(obj)) {
|
2012-09-04 15:32:56 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("storage pool is not active"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-05-09 11:00:41 +00:00
|
|
|
ret = virStoragePoolObjVolumeListExport(pool->conn, obj, vols, NULL);
|
2012-09-04 15:32:56 +00:00
|
|
|
|
|
|
|
cleanup:
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2012-09-04 15:32:56 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2017-05-05 21:21:50 +00:00
|
|
|
static virStorageVolDefPtr
|
|
|
|
testStorageVolDefFindByName(virStoragePoolObjPtr obj,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
virStorageVolDefPtr privvol;
|
|
|
|
|
|
|
|
if (!(privvol = virStorageVolDefFindByName(obj, name))) {
|
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return privvol;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
testStorageVolLookupByName(virStoragePoolPtr pool,
|
2017-05-05 21:21:50 +00:00
|
|
|
const char *name)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2008-12-04 20:56:10 +00:00
|
|
|
virStorageVolDefPtr privvol;
|
2008-12-04 20:57:47 +00:00
|
|
|
virStorageVolPtr ret = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
|
|
|
|
return NULL;
|
2017-05-08 12:21:52 +00:00
|
|
|
def = virStoragePoolObjGetDef(obj);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 21:21:50 +00:00
|
|
|
if (!(privvol = testStorageVolDefFindByName(obj, name)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
ret = virGetStorageVol(pool->conn, def->name,
|
2012-11-10 07:18:07 +00:00
|
|
|
privvol->name, privvol->key,
|
|
|
|
NULL, NULL);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-08 12:44:31 +00:00
|
|
|
struct storageVolLookupData {
|
|
|
|
const char *key;
|
|
|
|
const char *path;
|
|
|
|
virStorageVolDefPtr voldef;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
testStorageVolLookupByKeyCallback(virStoragePoolObjPtr obj,
|
|
|
|
const void *opaque)
|
|
|
|
{
|
2018-04-25 12:42:34 +00:00
|
|
|
struct storageVolLookupData *data = (struct storageVolLookupData *)opaque;
|
2017-10-08 12:44:31 +00:00
|
|
|
|
|
|
|
if (virStoragePoolObjIsActive(obj))
|
|
|
|
data->voldef = virStorageVolDefFindByKey(obj, data->key);
|
|
|
|
|
|
|
|
return !!data->voldef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
testStorageVolLookupByKey(virConnectPtr conn,
|
2014-03-18 08:17:30 +00:00
|
|
|
const char *key)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-07-26 17:38:45 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2017-10-08 12:44:31 +00:00
|
|
|
struct storageVolLookupData data = {
|
2018-04-06 12:01:02 +00:00
|
|
|
.key = key, .voldef = NULL };
|
2017-10-08 12:44:31 +00:00
|
|
|
virStorageVolPtr vol = NULL;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-10-07 11:24:24 +00:00
|
|
|
if ((obj = virStoragePoolObjListSearch(privconn->pools,
|
2017-10-08 12:44:31 +00:00
|
|
|
testStorageVolLookupByKeyCallback,
|
|
|
|
&data)) && data.voldef) {
|
2017-05-08 12:21:52 +00:00
|
|
|
def = virStoragePoolObjGetDef(obj);
|
2017-10-08 12:44:31 +00:00
|
|
|
vol = virGetStorageVol(conn, def->name,
|
|
|
|
data.voldef->name, data.voldef->key,
|
|
|
|
NULL, NULL);
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-10-08 12:44:31 +00:00
|
|
|
if (!vol)
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching key '%s'"), key);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2017-10-08 12:44:31 +00:00
|
|
|
return vol;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
testStorageVolLookupByPathCallback(virStoragePoolObjPtr obj,
|
|
|
|
const void *opaque)
|
|
|
|
{
|
2018-04-25 12:42:34 +00:00
|
|
|
struct storageVolLookupData *data = (struct storageVolLookupData *)opaque;
|
2017-10-08 12:44:31 +00:00
|
|
|
|
|
|
|
if (virStoragePoolObjIsActive(obj))
|
|
|
|
data->voldef = virStorageVolDefFindByPath(obj, data->path);
|
|
|
|
|
|
|
|
return !!data->voldef;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
testStorageVolLookupByPath(virConnectPtr conn,
|
2014-03-18 08:17:30 +00:00
|
|
|
const char *path)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2017-07-26 17:38:45 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2017-10-08 12:44:31 +00:00
|
|
|
struct storageVolLookupData data = {
|
2018-04-06 12:01:02 +00:00
|
|
|
.path = path, .voldef = NULL };
|
2017-10-08 12:44:31 +00:00
|
|
|
virStorageVolPtr vol = NULL;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectLock(privconn);
|
2017-10-07 11:24:24 +00:00
|
|
|
if ((obj = virStoragePoolObjListSearch(privconn->pools,
|
2017-10-08 12:44:31 +00:00
|
|
|
testStorageVolLookupByPathCallback,
|
|
|
|
&data)) && data.voldef) {
|
2017-05-08 12:21:52 +00:00
|
|
|
def = virStoragePoolObjGetDef(obj);
|
2017-10-08 12:44:31 +00:00
|
|
|
vol = virGetStorageVol(conn, def->name,
|
|
|
|
data.voldef->name, data.voldef->key,
|
|
|
|
NULL, NULL);
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
2018-11-20 13:54:16 +00:00
|
|
|
virObjectUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-10-08 12:44:31 +00:00
|
|
|
if (!vol)
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching path '%s'"), path);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2017-10-08 12:44:31 +00:00
|
|
|
return vol;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
testStorageVolCreateXML(virStoragePoolPtr pool,
|
|
|
|
const char *xmldesc,
|
|
|
|
unsigned int flags)
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2008-12-04 20:57:47 +00:00
|
|
|
virStorageVolPtr ret = NULL;
|
2019-01-31 14:44:54 +00:00
|
|
|
VIR_AUTOPTR(virStorageVolDef) privvol = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
|
|
|
|
return NULL;
|
2017-05-08 12:21:52 +00:00
|
|
|
def = virStoragePoolObjGetDef(obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
privvol = virStorageVolDefParseString(def, xmldesc, 0);
|
2008-12-04 20:56:10 +00:00
|
|
|
if (privvol == NULL)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
if (virStorageVolDefFindByName(obj, privvol->name)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
"%s", _("storage vol already exists"));
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure enough space */
|
2017-05-08 12:21:52 +00:00
|
|
|
if ((def->allocation + privvol->target.allocation) >
|
|
|
|
def->capacity) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Not enough free space in pool for volume '%s'"),
|
|
|
|
privvol->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2009-05-19 13:15:50 +00:00
|
|
|
if (virAsprintf(&privvol->target.path, "%s/%s",
|
2017-05-08 12:21:52 +00:00
|
|
|
def->target.path, privvol->name) < 0)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2014-03-07 08:33:31 +00:00
|
|
|
if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 ||
|
2017-05-09 12:05:16 +00:00
|
|
|
virStoragePoolObjAddVol(obj, privvol) < 0)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
def->allocation += privvol->target.allocation;
|
|
|
|
def->available = (def->capacity - def->allocation);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
ret = virGetStorageVol(pool->conn, def->name,
|
2012-11-10 07:18:07 +00:00
|
|
|
privvol->name, privvol->key,
|
|
|
|
NULL, NULL);
|
2008-12-07 20:45:28 +00:00
|
|
|
privvol = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2009-05-12 20:15:56 +00:00
|
|
|
static virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
|
|
|
|
const char *xmldesc,
|
|
|
|
virStorageVolPtr clonevol,
|
|
|
|
unsigned int flags)
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = pool->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2019-01-31 14:44:54 +00:00
|
|
|
virStorageVolDefPtr origvol = NULL;
|
2009-05-12 20:15:56 +00:00
|
|
|
virStorageVolPtr ret = NULL;
|
2019-01-31 14:44:54 +00:00
|
|
|
VIR_AUTOPTR(virStorageVolDef) privvol = NULL;
|
2009-05-12 20:15:56 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
|
|
|
|
return NULL;
|
2017-05-08 12:21:52 +00:00
|
|
|
def = virStoragePoolObjGetDef(obj);
|
2009-05-12 20:15:56 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
privvol = virStorageVolDefParseString(def, xmldesc, 0);
|
2009-05-12 20:15:56 +00:00
|
|
|
if (privvol == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
if (virStorageVolDefFindByName(obj, privvol->name)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
"%s", _("storage vol already exists"));
|
2009-05-12 20:15:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-05-05 19:31:40 +00:00
|
|
|
origvol = virStorageVolDefFindByName(obj, clonevol->name);
|
2009-05-12 20:15:56 +00:00
|
|
|
if (!origvol) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
clonevol->name);
|
2009-05-12 20:15:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure enough space */
|
2017-05-08 12:21:52 +00:00
|
|
|
if ((def->allocation + privvol->target.allocation) > def->capacity) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Not enough free space in pool for volume '%s'"),
|
|
|
|
privvol->name);
|
2009-05-12 20:15:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2017-05-08 12:21:52 +00:00
|
|
|
def->available = (def->capacity - def->allocation);
|
2009-05-12 20:15:56 +00:00
|
|
|
|
2009-05-19 13:15:50 +00:00
|
|
|
if (virAsprintf(&privvol->target.path, "%s/%s",
|
2017-05-08 12:21:52 +00:00
|
|
|
def->target.path, privvol->name) < 0)
|
2009-05-12 20:15:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-03-07 08:33:31 +00:00
|
|
|
if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 ||
|
2017-05-09 12:05:16 +00:00
|
|
|
virStoragePoolObjAddVol(obj, privvol) < 0)
|
2009-05-12 20:15:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
def->allocation += privvol->target.allocation;
|
|
|
|
def->available = (def->capacity - def->allocation);
|
2009-05-12 20:15:56 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
ret = virGetStorageVol(pool->conn, def->name,
|
2012-11-10 07:18:07 +00:00
|
|
|
privvol->name, privvol->key,
|
|
|
|
NULL, NULL);
|
2009-05-12 20:15:56 +00:00
|
|
|
privvol = NULL;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2009-05-12 20:15:56 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testStorageVolDelete(virStorageVolPtr vol,
|
|
|
|
unsigned int flags)
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = vol->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2008-12-04 20:56:10 +00:00
|
|
|
virStorageVolDefPtr privvol;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool)))
|
|
|
|
return -1;
|
2017-05-08 12:21:52 +00:00
|
|
|
def = virStoragePoolObjGetDef(obj);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 21:21:50 +00:00
|
|
|
if (!(privvol = testStorageVolDefFindByName(obj, vol->name)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
def->allocation -= privvol->target.allocation;
|
|
|
|
def->available = (def->capacity - def->allocation);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-09 12:05:16 +00:00
|
|
|
virStoragePoolObjRemoveVol(obj, privvol);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
static int
|
|
|
|
testStorageVolumeTypeForPool(int pooltype)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2019-02-07 16:29:24 +00:00
|
|
|
switch ((virStoragePoolType) pooltype) {
|
|
|
|
case VIR_STORAGE_POOL_DIR:
|
|
|
|
case VIR_STORAGE_POOL_FS:
|
|
|
|
case VIR_STORAGE_POOL_NETFS:
|
|
|
|
case VIR_STORAGE_POOL_VSTORAGE:
|
|
|
|
return VIR_STORAGE_VOL_FILE;
|
|
|
|
case VIR_STORAGE_POOL_SHEEPDOG:
|
|
|
|
case VIR_STORAGE_POOL_ISCSI_DIRECT:
|
|
|
|
case VIR_STORAGE_POOL_GLUSTER:
|
|
|
|
case VIR_STORAGE_POOL_RBD:
|
|
|
|
return VIR_STORAGE_VOL_NETWORK;
|
|
|
|
case VIR_STORAGE_POOL_LOGICAL:
|
|
|
|
case VIR_STORAGE_POOL_DISK:
|
|
|
|
case VIR_STORAGE_POOL_MPATH:
|
|
|
|
case VIR_STORAGE_POOL_ISCSI:
|
|
|
|
case VIR_STORAGE_POOL_SCSI:
|
|
|
|
case VIR_STORAGE_POOL_ZFS:
|
|
|
|
return VIR_STORAGE_VOL_BLOCK;
|
|
|
|
case VIR_STORAGE_POOL_LAST:
|
|
|
|
default:
|
|
|
|
virReportEnumRangeError(virStoragePoolType, pooltype);
|
|
|
|
return -1;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testStorageVolGetInfo(virStorageVolPtr vol,
|
2014-03-18 08:17:30 +00:00
|
|
|
virStorageVolInfoPtr info)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = vol->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-05-08 12:21:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2008-12-04 20:56:10 +00:00
|
|
|
virStorageVolDefPtr privvol;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool)))
|
|
|
|
return -1;
|
2017-05-08 12:21:52 +00:00
|
|
|
def = virStoragePoolObjGetDef(obj);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 21:21:50 +00:00
|
|
|
if (!(privvol = testStorageVolDefFindByName(obj, vol->name)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
memset(info, 0, sizeof(*info));
|
2019-02-07 16:29:24 +00:00
|
|
|
if ((info->type = testStorageVolumeTypeForPool(def->type)) < 0)
|
|
|
|
goto cleanup;
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
info->capacity = privvol->target.capacity;
|
|
|
|
info->allocation = privvol->target.allocation;
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static char *
|
2013-04-23 12:50:18 +00:00
|
|
|
testStorageVolGetXMLDesc(virStorageVolPtr vol,
|
|
|
|
unsigned int flags)
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = vol->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2008-12-04 20:56:10 +00:00
|
|
|
virStorageVolDefPtr privvol;
|
2008-12-04 20:57:47 +00:00
|
|
|
char *ret = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool)))
|
|
|
|
return NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 21:21:50 +00:00
|
|
|
if (!(privvol = testStorageVolDefFindByName(obj, vol->name)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2017-05-08 12:21:52 +00:00
|
|
|
ret = virStorageVolDefFormat(virStoragePoolObjGetDef(obj), privvol);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:57:37 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static char *
|
2014-03-18 08:17:30 +00:00
|
|
|
testStorageVolGetPath(virStorageVolPtr vol)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = vol->conn->privateData;
|
2017-05-05 19:31:40 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2008-12-04 20:56:10 +00:00
|
|
|
virStorageVolDefPtr privvol;
|
2008-12-04 20:57:47 +00:00
|
|
|
char *ret = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 21:02:01 +00:00
|
|
|
if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool)))
|
|
|
|
return NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2017-05-05 21:21:50 +00:00
|
|
|
if (!(privvol = testStorageVolDefFindByName(obj, vol->name)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2013-05-03 12:49:30 +00:00
|
|
|
ignore_value(VIR_STRDUP(ret, privvol->target.path));
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-10-08 13:09:09 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2009-10-01 18:54:36 +00:00
|
|
|
/* Node device implementations */
|
2008-12-04 21:00:50 +00:00
|
|
|
|
2017-03-04 14:16:33 +00:00
|
|
|
static virNodeDeviceObjPtr
|
|
|
|
testNodeDeviceObjFindByName(testDriverPtr driver,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
virNodeDeviceObjPtr obj;
|
|
|
|
|
2017-06-29 20:51:54 +00:00
|
|
|
if (!(obj = virNodeDeviceObjListFindByName(driver->devs, name)))
|
2017-03-04 14:16:33 +00:00
|
|
|
virReportError(VIR_ERR_NO_NODE_DEVICE,
|
|
|
|
_("no node device with matching name '%s'"),
|
|
|
|
name);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-01 18:54:36 +00:00
|
|
|
static int
|
|
|
|
testNodeNumOfDevices(virConnectPtr conn,
|
|
|
|
const char *cap,
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
unsigned int flags)
|
2009-10-01 18:54:36 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = conn->privateData;
|
2009-10-01 18:54:36 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2017-06-29 20:51:54 +00:00
|
|
|
return virNodeDeviceObjListNumOfDevices(driver->devs, conn, cap, NULL);
|
2009-10-01 18:54:36 +00:00
|
|
|
}
|
|
|
|
|
2017-03-19 19:51:03 +00:00
|
|
|
|
2009-10-01 18:54:36 +00:00
|
|
|
static int
|
|
|
|
testNodeListDevices(virConnectPtr conn,
|
|
|
|
const char *cap,
|
|
|
|
char **const names,
|
|
|
|
int maxnames,
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
unsigned int flags)
|
2009-10-01 18:54:36 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = conn->privateData;
|
2009-10-01 18:54:36 +00:00
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2017-06-29 20:51:54 +00:00
|
|
|
return virNodeDeviceObjListGetNames(driver->devs, conn, NULL,
|
|
|
|
cap, names, maxnames);
|
2009-10-01 18:54:36 +00:00
|
|
|
}
|
|
|
|
|
2018-02-23 20:08:46 +00:00
|
|
|
static int
|
|
|
|
testConnectListAllNodeDevices(virConnectPtr conn,
|
|
|
|
virNodeDevicePtr **devices,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
testDriverPtr driver = conn->privateData;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP, -1);
|
|
|
|
|
|
|
|
return virNodeDeviceObjListExport(conn, driver->devs, devices,
|
|
|
|
NULL, flags);
|
|
|
|
}
|
2017-03-19 19:51:03 +00:00
|
|
|
|
2009-10-01 18:54:36 +00:00
|
|
|
static virNodeDevicePtr
|
|
|
|
testNodeDeviceLookupByName(virConnectPtr conn, const char *name)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = conn->privateData;
|
2009-10-01 18:54:36 +00:00
|
|
|
virNodeDeviceObjPtr obj;
|
2017-06-03 11:36:01 +00:00
|
|
|
virNodeDeviceDefPtr def;
|
2009-10-01 18:54:36 +00:00
|
|
|
virNodeDevicePtr ret = NULL;
|
|
|
|
|
2017-03-04 14:16:33 +00:00
|
|
|
if (!(obj = testNodeDeviceObjFindByName(driver, name)))
|
2017-05-12 15:08:57 +00:00
|
|
|
return NULL;
|
2017-06-03 11:36:01 +00:00
|
|
|
def = virNodeDeviceObjGetDef(obj);
|
2009-10-01 18:54:36 +00:00
|
|
|
|
2017-02-07 18:04:08 +00:00
|
|
|
if ((ret = virGetNodeDevice(conn, name))) {
|
2018-04-13 11:42:16 +00:00
|
|
|
if (VIR_STRDUP(ret->parentName, def->parent) < 0) {
|
2017-02-07 18:04:08 +00:00
|
|
|
virObjectUnref(ret);
|
2017-05-26 10:57:43 +00:00
|
|
|
ret = NULL;
|
|
|
|
}
|
2017-02-07 18:04:08 +00:00
|
|
|
}
|
2009-10-01 18:54:36 +00:00
|
|
|
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
2009-10-01 18:54:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2011-05-06 19:53:10 +00:00
|
|
|
testNodeDeviceGetXMLDesc(virNodeDevicePtr dev,
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
unsigned int flags)
|
2009-10-01 18:54:36 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = dev->conn->privateData;
|
2009-10-01 18:54:36 +00:00
|
|
|
virNodeDeviceObjPtr obj;
|
|
|
|
char *ret = NULL;
|
|
|
|
|
test: reject unknown flags
* src/test/test_driver.c (testOpen, testDomainCoreDump)
(testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface)
(testInterfaceChangeBegin, testInterfaceChangeCommit)
(testInterfaceChangeRollback, testInterfaceGetXMLDesc)
(testInterfaceDefineXML, testInterfaceCreate)
(testInterfaceDestroy, testStorageOpen, testStoragePoolStart)
(testStorageFindPoolSources, testStoragePoolCreate)
(testStoragePoolDefine, testStoragePoolBuild)
(testStoragePoolDelete, testStoragePoolRefresh)
(testStoragePoolGetXMLDesc, testStorageVolumeCreateXML)
(testStorageVolumeCreateXMLFrom, testStorageVolumeDelete)
(testStorageVolumeGetXMLDesc, testDevMonOpen)
(testNodeNumOfDevices, testNodeListDevices)
(testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML)
(testSecretOpen, testNWFilterOpen): Reject unknown flags.
2011-07-06 23:00:08 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2017-03-04 14:16:33 +00:00
|
|
|
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
|
2017-05-12 15:08:57 +00:00
|
|
|
return NULL;
|
2009-10-01 18:54:36 +00:00
|
|
|
|
2017-06-03 11:36:01 +00:00
|
|
|
ret = virNodeDeviceDefFormat(virNodeDeviceObjGetDef(obj));
|
2009-10-01 18:54:36 +00:00
|
|
|
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
2009-10-01 18:54:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
testNodeDeviceGetParent(virNodeDevicePtr dev)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = dev->conn->privateData;
|
2009-10-01 18:54:36 +00:00
|
|
|
virNodeDeviceObjPtr obj;
|
2017-06-03 11:36:01 +00:00
|
|
|
virNodeDeviceDefPtr def;
|
2009-10-01 18:54:36 +00:00
|
|
|
char *ret = NULL;
|
|
|
|
|
2017-03-04 14:16:33 +00:00
|
|
|
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
|
2017-05-12 15:08:57 +00:00
|
|
|
return NULL;
|
2017-06-03 11:36:01 +00:00
|
|
|
def = virNodeDeviceObjGetDef(obj);
|
2009-10-01 18:54:36 +00:00
|
|
|
|
2017-06-03 11:36:01 +00:00
|
|
|
if (def->parent) {
|
|
|
|
ignore_value(VIR_STRDUP(ret, def->parent));
|
2009-10-01 18:54:36 +00:00
|
|
|
} else {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("no parent for this device"));
|
2009-10-01 18:54:36 +00:00
|
|
|
}
|
|
|
|
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
2009-10-01 18:54:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:00:50 +00:00
|
|
|
|
2009-10-01 18:54:36 +00:00
|
|
|
static int
|
|
|
|
testNodeDeviceNumOfCaps(virNodeDevicePtr dev)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = dev->conn->privateData;
|
2009-10-01 18:54:36 +00:00
|
|
|
virNodeDeviceObjPtr obj;
|
2017-06-03 11:36:01 +00:00
|
|
|
virNodeDeviceDefPtr def;
|
2009-10-01 18:54:36 +00:00
|
|
|
virNodeDevCapsDefPtr caps;
|
|
|
|
int ncaps = 0;
|
|
|
|
|
2017-03-04 14:16:33 +00:00
|
|
|
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
|
2017-05-12 15:08:57 +00:00
|
|
|
return -1;
|
2017-06-03 11:36:01 +00:00
|
|
|
def = virNodeDeviceObjGetDef(obj);
|
2009-10-01 18:54:36 +00:00
|
|
|
|
2017-06-03 11:36:01 +00:00
|
|
|
for (caps = def->caps; caps; caps = caps->next)
|
2009-10-01 18:54:36 +00:00
|
|
|
++ncaps;
|
|
|
|
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
2017-05-12 15:08:57 +00:00
|
|
|
return ncaps;
|
2009-10-01 18:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = dev->conn->privateData;
|
2009-10-01 18:54:36 +00:00
|
|
|
virNodeDeviceObjPtr obj;
|
2017-06-03 11:36:01 +00:00
|
|
|
virNodeDeviceDefPtr def;
|
2009-10-01 18:54:36 +00:00
|
|
|
virNodeDevCapsDefPtr caps;
|
|
|
|
int ncaps = 0;
|
|
|
|
|
2017-03-04 14:16:33 +00:00
|
|
|
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
|
2017-05-12 15:08:57 +00:00
|
|
|
return -1;
|
2017-06-03 11:36:01 +00:00
|
|
|
def = virNodeDeviceObjGetDef(obj);
|
2009-10-01 18:54:36 +00:00
|
|
|
|
2017-06-03 11:36:01 +00:00
|
|
|
for (caps = def->caps; caps && ncaps < maxnames; caps = caps->next) {
|
2017-05-12 15:08:57 +00:00
|
|
|
if (VIR_STRDUP(names[ncaps],
|
|
|
|
virNodeDevCapTypeToString(caps->data.type)) < 0)
|
|
|
|
goto error;
|
|
|
|
ncaps++;
|
2009-10-01 18:54:36 +00:00
|
|
|
}
|
|
|
|
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
2017-05-12 15:08:57 +00:00
|
|
|
return ncaps;
|
|
|
|
|
|
|
|
error:
|
|
|
|
while (--ncaps >= 0)
|
|
|
|
VIR_FREE(names[ncaps]);
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
2017-05-12 15:08:57 +00:00
|
|
|
return -1;
|
2009-10-01 18:54:36 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 12:48:36 +00:00
|
|
|
|
2017-02-28 09:48:05 +00:00
|
|
|
static virNodeDeviceObjPtr
|
|
|
|
testNodeDeviceMockCreateVport(testDriverPtr driver,
|
2017-01-24 01:52:24 +00:00
|
|
|
const char *wwnn,
|
2017-01-24 12:48:36 +00:00
|
|
|
const char *wwpn)
|
2009-10-14 20:16:10 +00:00
|
|
|
{
|
2017-01-24 01:52:24 +00:00
|
|
|
virNodeDeviceDefPtr def = NULL;
|
2009-10-14 20:16:10 +00:00
|
|
|
virNodeDevCapsDefPtr caps;
|
2017-02-28 09:48:05 +00:00
|
|
|
virNodeDeviceObjPtr obj = NULL, objcopy = NULL;
|
2017-06-03 11:36:01 +00:00
|
|
|
virNodeDeviceDefPtr objdef;
|
2016-07-28 12:02:52 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(char *) xml = NULL;
|
2009-10-14 20:16:10 +00:00
|
|
|
|
2017-01-24 01:52:24 +00:00
|
|
|
/* In the real code, we'd call virVHBAManageVport which would take the
|
|
|
|
* wwnn/wwpn from the input XML in order to call the "vport_create"
|
|
|
|
* function for the parent. That in turn would set off a sequence of
|
|
|
|
* events resulting in the creation of a vHBA scsi_hostN in the
|
|
|
|
* node device objects list using the "next" host number with the
|
|
|
|
* wwnn/wwpn from the input XML. The following will mock this by
|
|
|
|
* using the scsi_host11 definition, changing the name and the
|
|
|
|
* scsi_host capability fields before calling virNodeDeviceAssignDef
|
|
|
|
* to add the def to the node device objects list. */
|
2017-05-12 18:47:17 +00:00
|
|
|
if (!(objcopy = virNodeDeviceObjListFindByName(driver->devs,
|
|
|
|
"scsi_host11")))
|
2017-02-28 09:48:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-06-03 11:36:01 +00:00
|
|
|
xml = virNodeDeviceDefFormat(virNodeDeviceObjGetDef(objcopy));
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&objcopy);
|
2017-02-28 09:48:05 +00:00
|
|
|
if (!xml)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL)))
|
2017-01-24 01:52:24 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2009-10-14 20:16:10 +00:00
|
|
|
VIR_FREE(def->name);
|
2017-01-24 01:52:24 +00:00
|
|
|
if (VIR_STRDUP(def->name, "scsi_host12") < 0)
|
2009-10-14 20:16:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-01-24 01:52:24 +00:00
|
|
|
/* Find the 'scsi_host' cap and alter the host # and unique_id and
|
|
|
|
* then for the 'fc_host' capability modify the wwnn/wwpn to be that
|
|
|
|
* of the input XML. */
|
2009-10-14 20:16:10 +00:00
|
|
|
caps = def->caps;
|
|
|
|
while (caps) {
|
2015-05-08 16:55:00 +00:00
|
|
|
if (caps->data.type != VIR_NODE_DEV_CAP_SCSI_HOST)
|
2009-10-14 20:16:10 +00:00
|
|
|
continue;
|
|
|
|
|
2017-01-24 01:52:24 +00:00
|
|
|
/* For the "fc_host" cap - change the wwnn/wwpn to match the input */
|
|
|
|
if (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
|
|
|
|
VIR_FREE(caps->data.scsi_host.wwnn);
|
|
|
|
VIR_FREE(caps->data.scsi_host.wwpn);
|
|
|
|
if (VIR_STRDUP(caps->data.scsi_host.wwnn, wwnn) < 0 ||
|
|
|
|
VIR_STRDUP(caps->data.scsi_host.wwpn, wwpn) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
/* For the "scsi_host" cap, increment our host and unique_id to
|
|
|
|
* give the appearance that something new was created - then add
|
|
|
|
* that to the node device driver */
|
|
|
|
caps->data.scsi_host.host++;
|
|
|
|
caps->data.scsi_host.unique_id++;
|
|
|
|
}
|
2009-10-14 20:16:10 +00:00
|
|
|
caps = caps->next;
|
|
|
|
}
|
|
|
|
|
2017-05-12 18:47:17 +00:00
|
|
|
if (!(obj = virNodeDeviceObjListAssignDef(driver->devs, def)))
|
2009-10-14 20:16:10 +00:00
|
|
|
goto cleanup;
|
2018-02-23 23:09:20 +00:00
|
|
|
virNodeDeviceObjSetSkipUpdateCaps(obj, true);
|
2017-02-28 09:48:05 +00:00
|
|
|
def = NULL;
|
2017-06-03 11:36:01 +00:00
|
|
|
objdef = virNodeDeviceObjGetDef(obj);
|
2009-10-14 20:16:10 +00:00
|
|
|
|
2017-06-03 11:36:01 +00:00
|
|
|
event = virNodeDeviceEventLifecycleNew(objdef->name,
|
2016-07-28 12:02:52 +00:00
|
|
|
VIR_NODE_DEVICE_EVENT_CREATED,
|
|
|
|
0);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(driver->eventState, event);
|
2017-01-24 12:48:36 +00:00
|
|
|
|
|
|
|
cleanup:
|
2017-02-28 09:48:05 +00:00
|
|
|
virNodeDeviceDefFree(def);
|
|
|
|
return obj;
|
2017-01-24 12:48:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virNodeDevicePtr
|
|
|
|
testNodeDeviceCreateXML(virConnectPtr conn,
|
|
|
|
const char *xmlDesc,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
testDriverPtr driver = conn->privateData;
|
|
|
|
virNodeDeviceDefPtr def = NULL;
|
2017-02-28 09:48:05 +00:00
|
|
|
virNodeDevicePtr dev = NULL, ret = NULL;
|
|
|
|
virNodeDeviceObjPtr obj = NULL;
|
2017-06-03 11:36:01 +00:00
|
|
|
virNodeDeviceDefPtr objdef;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(char *) wwnn = NULL;
|
|
|
|
VIR_AUTOFREE(char *) wwpn = NULL;
|
2017-01-24 12:48:36 +00:00
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
if (!(def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, NULL)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-01-24 17:21:26 +00:00
|
|
|
/* We run this simply for validation - it essentially validates that
|
|
|
|
* the input XML either has a wwnn/wwpn or virNodeDevCapSCSIHostParseXML
|
|
|
|
* generated a wwnn/wwpn */
|
2017-01-24 12:48:36 +00:00
|
|
|
if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-01-24 17:21:26 +00:00
|
|
|
/* Unlike the "real" code we don't need the parent_host in order to
|
|
|
|
* call virVHBAManageVport, but still let's make sure the code finds
|
|
|
|
* something valid and no one messed up the mock environment. */
|
2017-07-20 13:17:22 +00:00
|
|
|
if (virNodeDeviceObjListGetParentHost(driver->devs, def) < 0)
|
2017-01-24 12:48:36 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* In the real code, we'd call virVHBAManageVport followed by
|
|
|
|
* find_new_device, but we cannot do that here since we're not
|
2017-01-24 01:52:24 +00:00
|
|
|
* mocking udev. The mock routine will copy an existing vHBA and
|
|
|
|
* rename a few fields to mock that. So in order to allow that to
|
|
|
|
* work properly, we need to drop our lock */
|
2017-02-28 09:48:05 +00:00
|
|
|
if (!(obj = testNodeDeviceMockCreateVport(driver, wwnn, wwpn)))
|
|
|
|
goto cleanup;
|
2017-06-03 11:36:01 +00:00
|
|
|
objdef = virNodeDeviceObjGetDef(obj);
|
2017-02-28 09:48:05 +00:00
|
|
|
|
2017-06-03 11:36:01 +00:00
|
|
|
if (!(dev = virGetNodeDevice(conn, objdef->name)))
|
2017-02-28 09:48:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2018-04-13 11:42:16 +00:00
|
|
|
VIR_FREE(dev->parentName);
|
|
|
|
if (VIR_STRDUP(dev->parentName, def->parent) < 0)
|
2017-02-28 09:48:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2019-01-28 13:41:37 +00:00
|
|
|
VIR_STEAL_PTR(ret, dev);
|
2016-07-28 12:02:52 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
2010-05-17 20:38:59 +00:00
|
|
|
virNodeDeviceDefFree(def);
|
2017-02-28 09:48:05 +00:00
|
|
|
virObjectUnref(dev);
|
|
|
|
return ret;
|
2009-10-14 20:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testNodeDeviceDestroy(virNodeDevicePtr dev)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = dev->conn->privateData;
|
2009-10-14 20:16:10 +00:00
|
|
|
virNodeDeviceObjPtr obj = NULL;
|
2017-07-20 13:07:52 +00:00
|
|
|
virNodeDeviceObjPtr parentobj = NULL;
|
2017-06-03 11:36:01 +00:00
|
|
|
virNodeDeviceDefPtr def;
|
2016-07-28 12:02:52 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2019-02-01 13:54:56 +00:00
|
|
|
VIR_AUTOFREE(char *) wwnn = NULL;
|
|
|
|
VIR_AUTOFREE(char *) wwpn = NULL;
|
2009-10-14 20:16:10 +00:00
|
|
|
|
2017-03-04 14:16:33 +00:00
|
|
|
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
|
2017-05-12 15:08:57 +00:00
|
|
|
return -1;
|
2017-06-03 11:36:01 +00:00
|
|
|
def = virNodeDeviceObjGetDef(obj);
|
2009-10-14 20:16:10 +00:00
|
|
|
|
2017-06-03 11:36:01 +00:00
|
|
|
if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1)
|
2017-05-12 15:08:57 +00:00
|
|
|
goto cleanup;
|
2009-10-14 20:16:10 +00:00
|
|
|
|
2017-07-20 13:07:52 +00:00
|
|
|
/* Unlike the real code we cannot run into the udevAddOneDevice race
|
|
|
|
* which would replace obj->def, so no need to save off the parent,
|
|
|
|
* but do need to drop the @obj lock so that the FindByName code doesn't
|
|
|
|
* deadlock on ourselves */
|
2017-05-15 15:00:59 +00:00
|
|
|
virObjectUnlock(obj);
|
2009-10-14 20:16:10 +00:00
|
|
|
|
2017-07-20 13:07:52 +00:00
|
|
|
/* We do this just for basic validation and throw away the parentobj
|
|
|
|
* since there's no vport_delete to be run */
|
|
|
|
if (!(parentobj = virNodeDeviceObjListFindByName(driver->devs,
|
|
|
|
def->parent))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot find parent '%s' definition"), def->parent);
|
2017-05-15 15:00:59 +00:00
|
|
|
virObjectLock(obj);
|
2017-05-12 15:08:57 +00:00
|
|
|
goto cleanup;
|
2009-10-14 20:16:10 +00:00
|
|
|
}
|
2017-07-20 13:07:52 +00:00
|
|
|
virNodeDeviceObjEndAPI(&parentobj);
|
2009-10-14 20:16:10 +00:00
|
|
|
|
2016-07-28 12:02:52 +00:00
|
|
|
event = virNodeDeviceEventLifecycleNew(dev->name,
|
|
|
|
VIR_NODE_DEVICE_EVENT_DELETED,
|
|
|
|
0);
|
|
|
|
|
2017-05-15 15:00:59 +00:00
|
|
|
virObjectLock(obj);
|
2017-05-12 18:47:17 +00:00
|
|
|
virNodeDeviceObjListRemove(driver->devs, obj);
|
2017-05-15 15:00:59 +00:00
|
|
|
virObjectUnref(obj);
|
2017-06-02 13:04:29 +00:00
|
|
|
obj = NULL;
|
2009-10-14 20:16:10 +00:00
|
|
|
|
2017-05-12 15:08:57 +00:00
|
|
|
cleanup:
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(driver->eventState, event);
|
2009-10-14 20:16:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-01 18:54:36 +00:00
|
|
|
|
|
|
|
/* Domain event implementations */
|
2009-01-20 20:23:53 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testConnectDomainEventRegister(virConnectPtr conn,
|
|
|
|
virConnectDomainEventCallback callback,
|
|
|
|
void *opaque,
|
|
|
|
virFreeCallback freecb)
|
2009-01-20 20:23:53 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = conn->privateData;
|
event: make deregister return value match docs
Ever since their introduction (commit 1509b80 in v0.5.0 for
virConnectDomainEventRegister, commit 4445723 in v0.8.0 for
virConnectDomainEventDeregisterAny), the event deregistration
functions have been documented as returning 0 on success;
likewise for older registration (only the newer RegisterAny
must return a non-zero callbackID). And now that we are
adding virConnectNetworkEventDeregisterAny for v1.2.1, it
should have the same semantics.
Fortunately, all of the stateful drivers have been obeying
the docs and returning 0, thanks to the way the remote_driver
tracks things (in fact, the RPC wire protocol is unable to
send a return value for DomainEventRegisterAny, at least not
without adding a new RPC number). Well, except for vbox,
which was always failing deregistration, due to failure to
set the return value to anything besides its initial -1.
But for local drivers, such as test:///default, we've been
returning non-zero numbers; worse, the non-zero numbers have
differed over time. For example, in Fedora 12 (libvirt 0.8.2),
calling Register twice would return 0 and 1 [the callbackID
generated under the hood]; while in Fedora 20 (libvirt 1.1.3),
it returns 1 and 2 [the number of callbacks registered for
that event type]. Since we have changed the behavior over
time, and since it differs by local vs. remote, we can safely
argue that no one could have been reasonably relying on any
particular behavior, so we might as well obey the docs, as well
as prepare callers that might deal with older clients to not be
surprised if the docs are not strictly followed.
For consistency, this patch fixes the code for all drivers,
even though it only makes an impact for vbox and for local
drivers. By fixing all drivers, future copy and paste from
a remote driver to a local driver is less likely to
reintroduce the bug.
Finally, update the testsuite to gain some coverage of the
issue for local drivers, including the first test of old-style
domain event registration via function pointer instead of
event id.
* src/libvirt.c (virConnectDomainEventRegister)
(virConnectDomainEventDeregister)
(virConnectDomainEventDeregisterAny): Clarify docs.
* src/libxl/libxl_driver.c (libxlConnectDomainEventRegister)
(libxlConnectDomainEventDeregister)
(libxlConnectDomainEventDeregisterAny): Match documentation.
* src/lxc/lxc_driver.c (lxcConnectDomainEventRegister)
(lxcConnectDomainEventDeregister)
(lxcConnectDomainEventDeregisterAny): Likewise.
* src/test/test_driver.c (testConnectDomainEventRegister)
(testConnectDomainEventDeregister)
(testConnectDomainEventDeregisterAny)
(testConnectNetworkEventDeregisterAny): Likewise.
* src/uml/uml_driver.c (umlConnectDomainEventRegister)
(umlConnectDomainEventDeregister)
(umlConnectDomainEventDeregisterAny): Likewise.
* src/vbox/vbox_tmpl.c (vboxConnectDomainEventRegister)
(vboxConnectDomainEventDeregister)
(vboxConnectDomainEventDeregisterAny): Likewise.
* src/xen/xen_driver.c (xenUnifiedConnectDomainEventRegister)
(xenUnifiedConnectDomainEventDeregister)
(xenUnifiedConnectDomainEventDeregisterAny): Likewise.
* src/network/bridge_driver.c
(networkConnectNetworkEventDeregisterAny): Likewise.
* tests/objecteventtest.c (testDomainCreateXMLOld): New test.
(mymain): Run it.
(testDomainCreateXML): Check return values.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-03 21:21:17 +00:00
|
|
|
int ret = 0;
|
2009-01-20 20:23:53 +00:00
|
|
|
|
event: move event filtering to daemon (regression fix)
https://bugzilla.redhat.com/show_bug.cgi?id=1058839
Commit f9f56340 for CVE-2014-0028 almost had the right idea - we
need to check the ACL rules to filter which events to send. But
it overlooked one thing: the event dispatch queue is running in
the main loop thread, and therefore does not normally have a
current virIdentityPtr. But filter checks can be based on current
identity, so when libvirtd.conf contains access_drivers=["polkit"],
we ended up rejecting access for EVERY event due to failure to
look up the current identity, even if it should have been allowed.
Furthermore, even for events that are triggered by API calls, it
is important to remember that the point of events is that they can
be copied across multiple connections, which may have separate
identities and permissions. So even if events were dispatched
from a context where we have an identity, we must change to the
correct identity of the connection that will be receiving the
event, rather than basing a decision on the context that triggered
the event, when deciding whether to filter an event to a
particular connection.
If there were an easy way to get from virConnectPtr to the
appropriate virIdentityPtr, then object_event.c could adjust the
identity prior to checking whether to dispatch an event. But
setting up that back-reference is a bit invasive. Instead, it
is easier to delay the filtering check until lower down the
stack, at the point where we have direct access to the RPC
client object that owns an identity. As such, this patch ends
up reverting a large portion of the framework of commit f9f56340.
We also have to teach 'make check' to special-case the fact that
the event registration filtering is done at the point of dispatch,
rather than the point of registration. Note that even though we
don't actually use virConnectDomainEventRegisterCheckACL (because
the RegisterAny variant is sufficient), we still generate the
function for the purposes of documenting that the filtering
takes place.
Also note that I did not entirely delete the notion of a filter
from object_event.c; I still plan on using that for my upcoming
patch series for qemu monitor events in libvirt-qemu.so. In
other words, while this patch changes ACL filtering to live in
remote.c and therefore we have no current client of the filtering
in object_event.c, the notion of filtering in object_event.c is
still useful down the road.
* src/check-aclrules.pl: Exempt event registration from having to
pass checkACL filter down call stack.
* daemon/remote.c (remoteRelayDomainEventCheckACL)
(remoteRelayNetworkEventCheckACL): New functions.
(remoteRelay*Event*): Use new functions.
* src/conf/domain_event.h (virDomainEventStateRegister)
(virDomainEventStateRegisterID): Drop unused parameter.
* src/conf/network_event.h (virNetworkEventStateRegisterID):
Likewise.
* src/conf/domain_event.c (virDomainEventFilter): Delete unused
function.
* src/conf/network_event.c (virNetworkEventFilter): Likewise.
* src/libxl/libxl_driver.c: Adjust caller.
* src/lxc/lxc_driver.c: Likewise.
* src/network/bridge_driver.c: Likewise.
* src/qemu/qemu_driver.c: Likewise.
* src/remote/remote_driver.c: Likewise.
* src/test/test_driver.c: Likewise.
* src/uml/uml_driver.c: Likewise.
* src/vbox/vbox_tmpl.c: Likewise.
* src/xen/xen_driver.c: Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-28 21:50:02 +00:00
|
|
|
if (virDomainEventStateRegister(conn, driver->eventState,
|
event: make deregister return value match docs
Ever since their introduction (commit 1509b80 in v0.5.0 for
virConnectDomainEventRegister, commit 4445723 in v0.8.0 for
virConnectDomainEventDeregisterAny), the event deregistration
functions have been documented as returning 0 on success;
likewise for older registration (only the newer RegisterAny
must return a non-zero callbackID). And now that we are
adding virConnectNetworkEventDeregisterAny for v1.2.1, it
should have the same semantics.
Fortunately, all of the stateful drivers have been obeying
the docs and returning 0, thanks to the way the remote_driver
tracks things (in fact, the RPC wire protocol is unable to
send a return value for DomainEventRegisterAny, at least not
without adding a new RPC number). Well, except for vbox,
which was always failing deregistration, due to failure to
set the return value to anything besides its initial -1.
But for local drivers, such as test:///default, we've been
returning non-zero numbers; worse, the non-zero numbers have
differed over time. For example, in Fedora 12 (libvirt 0.8.2),
calling Register twice would return 0 and 1 [the callbackID
generated under the hood]; while in Fedora 20 (libvirt 1.1.3),
it returns 1 and 2 [the number of callbacks registered for
that event type]. Since we have changed the behavior over
time, and since it differs by local vs. remote, we can safely
argue that no one could have been reasonably relying on any
particular behavior, so we might as well obey the docs, as well
as prepare callers that might deal with older clients to not be
surprised if the docs are not strictly followed.
For consistency, this patch fixes the code for all drivers,
even though it only makes an impact for vbox and for local
drivers. By fixing all drivers, future copy and paste from
a remote driver to a local driver is less likely to
reintroduce the bug.
Finally, update the testsuite to gain some coverage of the
issue for local drivers, including the first test of old-style
domain event registration via function pointer instead of
event id.
* src/libvirt.c (virConnectDomainEventRegister)
(virConnectDomainEventDeregister)
(virConnectDomainEventDeregisterAny): Clarify docs.
* src/libxl/libxl_driver.c (libxlConnectDomainEventRegister)
(libxlConnectDomainEventDeregister)
(libxlConnectDomainEventDeregisterAny): Match documentation.
* src/lxc/lxc_driver.c (lxcConnectDomainEventRegister)
(lxcConnectDomainEventDeregister)
(lxcConnectDomainEventDeregisterAny): Likewise.
* src/test/test_driver.c (testConnectDomainEventRegister)
(testConnectDomainEventDeregister)
(testConnectDomainEventDeregisterAny)
(testConnectNetworkEventDeregisterAny): Likewise.
* src/uml/uml_driver.c (umlConnectDomainEventRegister)
(umlConnectDomainEventDeregister)
(umlConnectDomainEventDeregisterAny): Likewise.
* src/vbox/vbox_tmpl.c (vboxConnectDomainEventRegister)
(vboxConnectDomainEventDeregister)
(vboxConnectDomainEventDeregisterAny): Likewise.
* src/xen/xen_driver.c (xenUnifiedConnectDomainEventRegister)
(xenUnifiedConnectDomainEventDeregister)
(xenUnifiedConnectDomainEventDeregisterAny): Likewise.
* src/network/bridge_driver.c
(networkConnectNetworkEventDeregisterAny): Likewise.
* tests/objecteventtest.c (testDomainCreateXMLOld): New test.
(mymain): Run it.
(testDomainCreateXML): Check return values.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-03 21:21:17 +00:00
|
|
|
callback, opaque, freecb) < 0)
|
|
|
|
ret = -1;
|
2009-01-20 20:23:53 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-18 14:47:07 +00:00
|
|
|
|
2009-01-20 20:23:53 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testConnectDomainEventDeregister(virConnectPtr conn,
|
|
|
|
virConnectDomainEventCallback callback)
|
2009-01-20 20:23:53 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = conn->privateData;
|
event: make deregister return value match docs
Ever since their introduction (commit 1509b80 in v0.5.0 for
virConnectDomainEventRegister, commit 4445723 in v0.8.0 for
virConnectDomainEventDeregisterAny), the event deregistration
functions have been documented as returning 0 on success;
likewise for older registration (only the newer RegisterAny
must return a non-zero callbackID). And now that we are
adding virConnectNetworkEventDeregisterAny for v1.2.1, it
should have the same semantics.
Fortunately, all of the stateful drivers have been obeying
the docs and returning 0, thanks to the way the remote_driver
tracks things (in fact, the RPC wire protocol is unable to
send a return value for DomainEventRegisterAny, at least not
without adding a new RPC number). Well, except for vbox,
which was always failing deregistration, due to failure to
set the return value to anything besides its initial -1.
But for local drivers, such as test:///default, we've been
returning non-zero numbers; worse, the non-zero numbers have
differed over time. For example, in Fedora 12 (libvirt 0.8.2),
calling Register twice would return 0 and 1 [the callbackID
generated under the hood]; while in Fedora 20 (libvirt 1.1.3),
it returns 1 and 2 [the number of callbacks registered for
that event type]. Since we have changed the behavior over
time, and since it differs by local vs. remote, we can safely
argue that no one could have been reasonably relying on any
particular behavior, so we might as well obey the docs, as well
as prepare callers that might deal with older clients to not be
surprised if the docs are not strictly followed.
For consistency, this patch fixes the code for all drivers,
even though it only makes an impact for vbox and for local
drivers. By fixing all drivers, future copy and paste from
a remote driver to a local driver is less likely to
reintroduce the bug.
Finally, update the testsuite to gain some coverage of the
issue for local drivers, including the first test of old-style
domain event registration via function pointer instead of
event id.
* src/libvirt.c (virConnectDomainEventRegister)
(virConnectDomainEventDeregister)
(virConnectDomainEventDeregisterAny): Clarify docs.
* src/libxl/libxl_driver.c (libxlConnectDomainEventRegister)
(libxlConnectDomainEventDeregister)
(libxlConnectDomainEventDeregisterAny): Match documentation.
* src/lxc/lxc_driver.c (lxcConnectDomainEventRegister)
(lxcConnectDomainEventDeregister)
(lxcConnectDomainEventDeregisterAny): Likewise.
* src/test/test_driver.c (testConnectDomainEventRegister)
(testConnectDomainEventDeregister)
(testConnectDomainEventDeregisterAny)
(testConnectNetworkEventDeregisterAny): Likewise.
* src/uml/uml_driver.c (umlConnectDomainEventRegister)
(umlConnectDomainEventDeregister)
(umlConnectDomainEventDeregisterAny): Likewise.
* src/vbox/vbox_tmpl.c (vboxConnectDomainEventRegister)
(vboxConnectDomainEventDeregister)
(vboxConnectDomainEventDeregisterAny): Likewise.
* src/xen/xen_driver.c (xenUnifiedConnectDomainEventRegister)
(xenUnifiedConnectDomainEventDeregister)
(xenUnifiedConnectDomainEventDeregisterAny): Likewise.
* src/network/bridge_driver.c
(networkConnectNetworkEventDeregisterAny): Likewise.
* tests/objecteventtest.c (testDomainCreateXMLOld): New test.
(mymain): Run it.
(testDomainCreateXML): Check return values.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-03 21:21:17 +00:00
|
|
|
int ret = 0;
|
2009-01-20 20:23:53 +00:00
|
|
|
|
2014-01-04 13:14:33 +00:00
|
|
|
if (virDomainEventStateDeregister(conn, driver->eventState,
|
event: make deregister return value match docs
Ever since their introduction (commit 1509b80 in v0.5.0 for
virConnectDomainEventRegister, commit 4445723 in v0.8.0 for
virConnectDomainEventDeregisterAny), the event deregistration
functions have been documented as returning 0 on success;
likewise for older registration (only the newer RegisterAny
must return a non-zero callbackID). And now that we are
adding virConnectNetworkEventDeregisterAny for v1.2.1, it
should have the same semantics.
Fortunately, all of the stateful drivers have been obeying
the docs and returning 0, thanks to the way the remote_driver
tracks things (in fact, the RPC wire protocol is unable to
send a return value for DomainEventRegisterAny, at least not
without adding a new RPC number). Well, except for vbox,
which was always failing deregistration, due to failure to
set the return value to anything besides its initial -1.
But for local drivers, such as test:///default, we've been
returning non-zero numbers; worse, the non-zero numbers have
differed over time. For example, in Fedora 12 (libvirt 0.8.2),
calling Register twice would return 0 and 1 [the callbackID
generated under the hood]; while in Fedora 20 (libvirt 1.1.3),
it returns 1 and 2 [the number of callbacks registered for
that event type]. Since we have changed the behavior over
time, and since it differs by local vs. remote, we can safely
argue that no one could have been reasonably relying on any
particular behavior, so we might as well obey the docs, as well
as prepare callers that might deal with older clients to not be
surprised if the docs are not strictly followed.
For consistency, this patch fixes the code for all drivers,
even though it only makes an impact for vbox and for local
drivers. By fixing all drivers, future copy and paste from
a remote driver to a local driver is less likely to
reintroduce the bug.
Finally, update the testsuite to gain some coverage of the
issue for local drivers, including the first test of old-style
domain event registration via function pointer instead of
event id.
* src/libvirt.c (virConnectDomainEventRegister)
(virConnectDomainEventDeregister)
(virConnectDomainEventDeregisterAny): Clarify docs.
* src/libxl/libxl_driver.c (libxlConnectDomainEventRegister)
(libxlConnectDomainEventDeregister)
(libxlConnectDomainEventDeregisterAny): Match documentation.
* src/lxc/lxc_driver.c (lxcConnectDomainEventRegister)
(lxcConnectDomainEventDeregister)
(lxcConnectDomainEventDeregisterAny): Likewise.
* src/test/test_driver.c (testConnectDomainEventRegister)
(testConnectDomainEventDeregister)
(testConnectDomainEventDeregisterAny)
(testConnectNetworkEventDeregisterAny): Likewise.
* src/uml/uml_driver.c (umlConnectDomainEventRegister)
(umlConnectDomainEventDeregister)
(umlConnectDomainEventDeregisterAny): Likewise.
* src/vbox/vbox_tmpl.c (vboxConnectDomainEventRegister)
(vboxConnectDomainEventDeregister)
(vboxConnectDomainEventDeregisterAny): Likewise.
* src/xen/xen_driver.c (xenUnifiedConnectDomainEventRegister)
(xenUnifiedConnectDomainEventDeregister)
(xenUnifiedConnectDomainEventDeregisterAny): Likewise.
* src/network/bridge_driver.c
(networkConnectNetworkEventDeregisterAny): Likewise.
* tests/objecteventtest.c (testDomainCreateXMLOld): New test.
(mymain): Run it.
(testDomainCreateXML): Check return values.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-03 21:21:17 +00:00
|
|
|
callback) < 0)
|
|
|
|
ret = -1;
|
2009-01-20 20:23:53 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-18 14:47:07 +00:00
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testConnectDomainEventRegisterAny(virConnectPtr conn,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int eventID,
|
|
|
|
virConnectDomainEventGenericCallback callback,
|
|
|
|
void *opaque,
|
|
|
|
virFreeCallback freecb)
|
2010-03-18 14:47:07 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = conn->privateData;
|
2010-03-18 14:47:07 +00:00
|
|
|
int ret;
|
|
|
|
|
event: move event filtering to daemon (regression fix)
https://bugzilla.redhat.com/show_bug.cgi?id=1058839
Commit f9f56340 for CVE-2014-0028 almost had the right idea - we
need to check the ACL rules to filter which events to send. But
it overlooked one thing: the event dispatch queue is running in
the main loop thread, and therefore does not normally have a
current virIdentityPtr. But filter checks can be based on current
identity, so when libvirtd.conf contains access_drivers=["polkit"],
we ended up rejecting access for EVERY event due to failure to
look up the current identity, even if it should have been allowed.
Furthermore, even for events that are triggered by API calls, it
is important to remember that the point of events is that they can
be copied across multiple connections, which may have separate
identities and permissions. So even if events were dispatched
from a context where we have an identity, we must change to the
correct identity of the connection that will be receiving the
event, rather than basing a decision on the context that triggered
the event, when deciding whether to filter an event to a
particular connection.
If there were an easy way to get from virConnectPtr to the
appropriate virIdentityPtr, then object_event.c could adjust the
identity prior to checking whether to dispatch an event. But
setting up that back-reference is a bit invasive. Instead, it
is easier to delay the filtering check until lower down the
stack, at the point where we have direct access to the RPC
client object that owns an identity. As such, this patch ends
up reverting a large portion of the framework of commit f9f56340.
We also have to teach 'make check' to special-case the fact that
the event registration filtering is done at the point of dispatch,
rather than the point of registration. Note that even though we
don't actually use virConnectDomainEventRegisterCheckACL (because
the RegisterAny variant is sufficient), we still generate the
function for the purposes of documenting that the filtering
takes place.
Also note that I did not entirely delete the notion of a filter
from object_event.c; I still plan on using that for my upcoming
patch series for qemu monitor events in libvirt-qemu.so. In
other words, while this patch changes ACL filtering to live in
remote.c and therefore we have no current client of the filtering
in object_event.c, the notion of filtering in object_event.c is
still useful down the road.
* src/check-aclrules.pl: Exempt event registration from having to
pass checkACL filter down call stack.
* daemon/remote.c (remoteRelayDomainEventCheckACL)
(remoteRelayNetworkEventCheckACL): New functions.
(remoteRelay*Event*): Use new functions.
* src/conf/domain_event.h (virDomainEventStateRegister)
(virDomainEventStateRegisterID): Drop unused parameter.
* src/conf/network_event.h (virNetworkEventStateRegisterID):
Likewise.
* src/conf/domain_event.c (virDomainEventFilter): Delete unused
function.
* src/conf/network_event.c (virNetworkEventFilter): Likewise.
* src/libxl/libxl_driver.c: Adjust caller.
* src/lxc/lxc_driver.c: Likewise.
* src/network/bridge_driver.c: Likewise.
* src/qemu/qemu_driver.c: Likewise.
* src/remote/remote_driver.c: Likewise.
* src/test/test_driver.c: Likewise.
* src/uml/uml_driver.c: Likewise.
* src/vbox/vbox_tmpl.c: Likewise.
* src/xen/xen_driver.c: Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-28 21:50:02 +00:00
|
|
|
if (virDomainEventStateRegisterID(conn, driver->eventState,
|
2011-12-13 11:14:46 +00:00
|
|
|
dom, eventID,
|
|
|
|
callback, opaque, freecb, &ret) < 0)
|
Return count of callbacks when registering callbacks
When registering a callback for a particular event some callers
need to know how many callbacks already exist for that event.
While it is possible to ask for a count, this is not free from
race conditions when threaded. Thus the API for registering
callbacks should return the count of callbacks. Also rename
virDomainEventStateDeregisterAny to virDomainEventStateDeregisterID
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Return count of callbacks when
registering callbacks
* src/libxl/libxl_driver.c, src/libxl/libxl_driver.c,
src/qemu/qemu_driver.c, src/remote/remote_driver.c,
src/remote/remote_driver.c, src/uml/uml_driver.c,
src/vbox/vbox_tmpl.c, src/xen/xen_driver.c: Update
for change in APIs
2011-12-13 23:38:54 +00:00
|
|
|
ret = -1;
|
2010-03-18 14:47:07 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testConnectDomainEventDeregisterAny(virConnectPtr conn,
|
|
|
|
int callbackID)
|
2010-03-18 14:47:07 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = conn->privateData;
|
event: make deregister return value match docs
Ever since their introduction (commit 1509b80 in v0.5.0 for
virConnectDomainEventRegister, commit 4445723 in v0.8.0 for
virConnectDomainEventDeregisterAny), the event deregistration
functions have been documented as returning 0 on success;
likewise for older registration (only the newer RegisterAny
must return a non-zero callbackID). And now that we are
adding virConnectNetworkEventDeregisterAny for v1.2.1, it
should have the same semantics.
Fortunately, all of the stateful drivers have been obeying
the docs and returning 0, thanks to the way the remote_driver
tracks things (in fact, the RPC wire protocol is unable to
send a return value for DomainEventRegisterAny, at least not
without adding a new RPC number). Well, except for vbox,
which was always failing deregistration, due to failure to
set the return value to anything besides its initial -1.
But for local drivers, such as test:///default, we've been
returning non-zero numbers; worse, the non-zero numbers have
differed over time. For example, in Fedora 12 (libvirt 0.8.2),
calling Register twice would return 0 and 1 [the callbackID
generated under the hood]; while in Fedora 20 (libvirt 1.1.3),
it returns 1 and 2 [the number of callbacks registered for
that event type]. Since we have changed the behavior over
time, and since it differs by local vs. remote, we can safely
argue that no one could have been reasonably relying on any
particular behavior, so we might as well obey the docs, as well
as prepare callers that might deal with older clients to not be
surprised if the docs are not strictly followed.
For consistency, this patch fixes the code for all drivers,
even though it only makes an impact for vbox and for local
drivers. By fixing all drivers, future copy and paste from
a remote driver to a local driver is less likely to
reintroduce the bug.
Finally, update the testsuite to gain some coverage of the
issue for local drivers, including the first test of old-style
domain event registration via function pointer instead of
event id.
* src/libvirt.c (virConnectDomainEventRegister)
(virConnectDomainEventDeregister)
(virConnectDomainEventDeregisterAny): Clarify docs.
* src/libxl/libxl_driver.c (libxlConnectDomainEventRegister)
(libxlConnectDomainEventDeregister)
(libxlConnectDomainEventDeregisterAny): Match documentation.
* src/lxc/lxc_driver.c (lxcConnectDomainEventRegister)
(lxcConnectDomainEventDeregister)
(lxcConnectDomainEventDeregisterAny): Likewise.
* src/test/test_driver.c (testConnectDomainEventRegister)
(testConnectDomainEventDeregister)
(testConnectDomainEventDeregisterAny)
(testConnectNetworkEventDeregisterAny): Likewise.
* src/uml/uml_driver.c (umlConnectDomainEventRegister)
(umlConnectDomainEventDeregister)
(umlConnectDomainEventDeregisterAny): Likewise.
* src/vbox/vbox_tmpl.c (vboxConnectDomainEventRegister)
(vboxConnectDomainEventDeregister)
(vboxConnectDomainEventDeregisterAny): Likewise.
* src/xen/xen_driver.c (xenUnifiedConnectDomainEventRegister)
(xenUnifiedConnectDomainEventDeregister)
(xenUnifiedConnectDomainEventDeregisterAny): Likewise.
* src/network/bridge_driver.c
(networkConnectNetworkEventDeregisterAny): Likewise.
* tests/objecteventtest.c (testDomainCreateXMLOld): New test.
(mymain): Run it.
(testDomainCreateXML): Check return values.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-03 21:21:17 +00:00
|
|
|
int ret = 0;
|
2010-03-18 14:47:07 +00:00
|
|
|
|
2014-01-04 13:14:33 +00:00
|
|
|
if (virObjectEventStateDeregisterID(conn, driver->eventState,
|
2017-06-14 11:32:15 +00:00
|
|
|
callbackID, true) < 0)
|
event: make deregister return value match docs
Ever since their introduction (commit 1509b80 in v0.5.0 for
virConnectDomainEventRegister, commit 4445723 in v0.8.0 for
virConnectDomainEventDeregisterAny), the event deregistration
functions have been documented as returning 0 on success;
likewise for older registration (only the newer RegisterAny
must return a non-zero callbackID). And now that we are
adding virConnectNetworkEventDeregisterAny for v1.2.1, it
should have the same semantics.
Fortunately, all of the stateful drivers have been obeying
the docs and returning 0, thanks to the way the remote_driver
tracks things (in fact, the RPC wire protocol is unable to
send a return value for DomainEventRegisterAny, at least not
without adding a new RPC number). Well, except for vbox,
which was always failing deregistration, due to failure to
set the return value to anything besides its initial -1.
But for local drivers, such as test:///default, we've been
returning non-zero numbers; worse, the non-zero numbers have
differed over time. For example, in Fedora 12 (libvirt 0.8.2),
calling Register twice would return 0 and 1 [the callbackID
generated under the hood]; while in Fedora 20 (libvirt 1.1.3),
it returns 1 and 2 [the number of callbacks registered for
that event type]. Since we have changed the behavior over
time, and since it differs by local vs. remote, we can safely
argue that no one could have been reasonably relying on any
particular behavior, so we might as well obey the docs, as well
as prepare callers that might deal with older clients to not be
surprised if the docs are not strictly followed.
For consistency, this patch fixes the code for all drivers,
even though it only makes an impact for vbox and for local
drivers. By fixing all drivers, future copy and paste from
a remote driver to a local driver is less likely to
reintroduce the bug.
Finally, update the testsuite to gain some coverage of the
issue for local drivers, including the first test of old-style
domain event registration via function pointer instead of
event id.
* src/libvirt.c (virConnectDomainEventRegister)
(virConnectDomainEventDeregister)
(virConnectDomainEventDeregisterAny): Clarify docs.
* src/libxl/libxl_driver.c (libxlConnectDomainEventRegister)
(libxlConnectDomainEventDeregister)
(libxlConnectDomainEventDeregisterAny): Match documentation.
* src/lxc/lxc_driver.c (lxcConnectDomainEventRegister)
(lxcConnectDomainEventDeregister)
(lxcConnectDomainEventDeregisterAny): Likewise.
* src/test/test_driver.c (testConnectDomainEventRegister)
(testConnectDomainEventDeregister)
(testConnectDomainEventDeregisterAny)
(testConnectNetworkEventDeregisterAny): Likewise.
* src/uml/uml_driver.c (umlConnectDomainEventRegister)
(umlConnectDomainEventDeregister)
(umlConnectDomainEventDeregisterAny): Likewise.
* src/vbox/vbox_tmpl.c (vboxConnectDomainEventRegister)
(vboxConnectDomainEventDeregister)
(vboxConnectDomainEventDeregisterAny): Likewise.
* src/xen/xen_driver.c (xenUnifiedConnectDomainEventRegister)
(xenUnifiedConnectDomainEventDeregister)
(xenUnifiedConnectDomainEventDeregisterAny): Likewise.
* src/network/bridge_driver.c
(networkConnectNetworkEventDeregisterAny): Likewise.
* tests/objecteventtest.c (testDomainCreateXMLOld): New test.
(mymain): Run it.
(testDomainCreateXML): Check return values.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-03 21:21:17 +00:00
|
|
|
ret = -1;
|
2010-03-18 14:47:07 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-11 10:37:59 +00:00
|
|
|
static int
|
|
|
|
testConnectNetworkEventRegisterAny(virConnectPtr conn,
|
|
|
|
virNetworkPtr net,
|
|
|
|
int eventID,
|
|
|
|
virConnectNetworkEventGenericCallback callback,
|
|
|
|
void *opaque,
|
|
|
|
virFreeCallback freecb)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = conn->privateData;
|
2013-12-11 10:37:59 +00:00
|
|
|
int ret;
|
|
|
|
|
event: move event filtering to daemon (regression fix)
https://bugzilla.redhat.com/show_bug.cgi?id=1058839
Commit f9f56340 for CVE-2014-0028 almost had the right idea - we
need to check the ACL rules to filter which events to send. But
it overlooked one thing: the event dispatch queue is running in
the main loop thread, and therefore does not normally have a
current virIdentityPtr. But filter checks can be based on current
identity, so when libvirtd.conf contains access_drivers=["polkit"],
we ended up rejecting access for EVERY event due to failure to
look up the current identity, even if it should have been allowed.
Furthermore, even for events that are triggered by API calls, it
is important to remember that the point of events is that they can
be copied across multiple connections, which may have separate
identities and permissions. So even if events were dispatched
from a context where we have an identity, we must change to the
correct identity of the connection that will be receiving the
event, rather than basing a decision on the context that triggered
the event, when deciding whether to filter an event to a
particular connection.
If there were an easy way to get from virConnectPtr to the
appropriate virIdentityPtr, then object_event.c could adjust the
identity prior to checking whether to dispatch an event. But
setting up that back-reference is a bit invasive. Instead, it
is easier to delay the filtering check until lower down the
stack, at the point where we have direct access to the RPC
client object that owns an identity. As such, this patch ends
up reverting a large portion of the framework of commit f9f56340.
We also have to teach 'make check' to special-case the fact that
the event registration filtering is done at the point of dispatch,
rather than the point of registration. Note that even though we
don't actually use virConnectDomainEventRegisterCheckACL (because
the RegisterAny variant is sufficient), we still generate the
function for the purposes of documenting that the filtering
takes place.
Also note that I did not entirely delete the notion of a filter
from object_event.c; I still plan on using that for my upcoming
patch series for qemu monitor events in libvirt-qemu.so. In
other words, while this patch changes ACL filtering to live in
remote.c and therefore we have no current client of the filtering
in object_event.c, the notion of filtering in object_event.c is
still useful down the road.
* src/check-aclrules.pl: Exempt event registration from having to
pass checkACL filter down call stack.
* daemon/remote.c (remoteRelayDomainEventCheckACL)
(remoteRelayNetworkEventCheckACL): New functions.
(remoteRelay*Event*): Use new functions.
* src/conf/domain_event.h (virDomainEventStateRegister)
(virDomainEventStateRegisterID): Drop unused parameter.
* src/conf/network_event.h (virNetworkEventStateRegisterID):
Likewise.
* src/conf/domain_event.c (virDomainEventFilter): Delete unused
function.
* src/conf/network_event.c (virNetworkEventFilter): Likewise.
* src/libxl/libxl_driver.c: Adjust caller.
* src/lxc/lxc_driver.c: Likewise.
* src/network/bridge_driver.c: Likewise.
* src/qemu/qemu_driver.c: Likewise.
* src/remote/remote_driver.c: Likewise.
* src/test/test_driver.c: Likewise.
* src/uml/uml_driver.c: Likewise.
* src/vbox/vbox_tmpl.c: Likewise.
* src/xen/xen_driver.c: Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-28 21:50:02 +00:00
|
|
|
if (virNetworkEventStateRegisterID(conn, driver->eventState,
|
2014-01-04 22:12:34 +00:00
|
|
|
net, eventID, callback,
|
2013-12-11 10:37:59 +00:00
|
|
|
opaque, freecb, &ret) < 0)
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testConnectNetworkEventDeregisterAny(virConnectPtr conn,
|
|
|
|
int callbackID)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr driver = conn->privateData;
|
event: make deregister return value match docs
Ever since their introduction (commit 1509b80 in v0.5.0 for
virConnectDomainEventRegister, commit 4445723 in v0.8.0 for
virConnectDomainEventDeregisterAny), the event deregistration
functions have been documented as returning 0 on success;
likewise for older registration (only the newer RegisterAny
must return a non-zero callbackID). And now that we are
adding virConnectNetworkEventDeregisterAny for v1.2.1, it
should have the same semantics.
Fortunately, all of the stateful drivers have been obeying
the docs and returning 0, thanks to the way the remote_driver
tracks things (in fact, the RPC wire protocol is unable to
send a return value for DomainEventRegisterAny, at least not
without adding a new RPC number). Well, except for vbox,
which was always failing deregistration, due to failure to
set the return value to anything besides its initial -1.
But for local drivers, such as test:///default, we've been
returning non-zero numbers; worse, the non-zero numbers have
differed over time. For example, in Fedora 12 (libvirt 0.8.2),
calling Register twice would return 0 and 1 [the callbackID
generated under the hood]; while in Fedora 20 (libvirt 1.1.3),
it returns 1 and 2 [the number of callbacks registered for
that event type]. Since we have changed the behavior over
time, and since it differs by local vs. remote, we can safely
argue that no one could have been reasonably relying on any
particular behavior, so we might as well obey the docs, as well
as prepare callers that might deal with older clients to not be
surprised if the docs are not strictly followed.
For consistency, this patch fixes the code for all drivers,
even though it only makes an impact for vbox and for local
drivers. By fixing all drivers, future copy and paste from
a remote driver to a local driver is less likely to
reintroduce the bug.
Finally, update the testsuite to gain some coverage of the
issue for local drivers, including the first test of old-style
domain event registration via function pointer instead of
event id.
* src/libvirt.c (virConnectDomainEventRegister)
(virConnectDomainEventDeregister)
(virConnectDomainEventDeregisterAny): Clarify docs.
* src/libxl/libxl_driver.c (libxlConnectDomainEventRegister)
(libxlConnectDomainEventDeregister)
(libxlConnectDomainEventDeregisterAny): Match documentation.
* src/lxc/lxc_driver.c (lxcConnectDomainEventRegister)
(lxcConnectDomainEventDeregister)
(lxcConnectDomainEventDeregisterAny): Likewise.
* src/test/test_driver.c (testConnectDomainEventRegister)
(testConnectDomainEventDeregister)
(testConnectDomainEventDeregisterAny)
(testConnectNetworkEventDeregisterAny): Likewise.
* src/uml/uml_driver.c (umlConnectDomainEventRegister)
(umlConnectDomainEventDeregister)
(umlConnectDomainEventDeregisterAny): Likewise.
* src/vbox/vbox_tmpl.c (vboxConnectDomainEventRegister)
(vboxConnectDomainEventDeregister)
(vboxConnectDomainEventDeregisterAny): Likewise.
* src/xen/xen_driver.c (xenUnifiedConnectDomainEventRegister)
(xenUnifiedConnectDomainEventDeregister)
(xenUnifiedConnectDomainEventDeregisterAny): Likewise.
* src/network/bridge_driver.c
(networkConnectNetworkEventDeregisterAny): Likewise.
* tests/objecteventtest.c (testDomainCreateXMLOld): New test.
(mymain): Run it.
(testDomainCreateXML): Check return values.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-03 21:21:17 +00:00
|
|
|
int ret = 0;
|
2013-12-11 10:37:59 +00:00
|
|
|
|
2014-01-04 13:14:33 +00:00
|
|
|
if (virObjectEventStateDeregisterID(conn, driver->eventState,
|
2017-06-14 11:32:15 +00:00
|
|
|
callbackID, true) < 0)
|
event: make deregister return value match docs
Ever since their introduction (commit 1509b80 in v0.5.0 for
virConnectDomainEventRegister, commit 4445723 in v0.8.0 for
virConnectDomainEventDeregisterAny), the event deregistration
functions have been documented as returning 0 on success;
likewise for older registration (only the newer RegisterAny
must return a non-zero callbackID). And now that we are
adding virConnectNetworkEventDeregisterAny for v1.2.1, it
should have the same semantics.
Fortunately, all of the stateful drivers have been obeying
the docs and returning 0, thanks to the way the remote_driver
tracks things (in fact, the RPC wire protocol is unable to
send a return value for DomainEventRegisterAny, at least not
without adding a new RPC number). Well, except for vbox,
which was always failing deregistration, due to failure to
set the return value to anything besides its initial -1.
But for local drivers, such as test:///default, we've been
returning non-zero numbers; worse, the non-zero numbers have
differed over time. For example, in Fedora 12 (libvirt 0.8.2),
calling Register twice would return 0 and 1 [the callbackID
generated under the hood]; while in Fedora 20 (libvirt 1.1.3),
it returns 1 and 2 [the number of callbacks registered for
that event type]. Since we have changed the behavior over
time, and since it differs by local vs. remote, we can safely
argue that no one could have been reasonably relying on any
particular behavior, so we might as well obey the docs, as well
as prepare callers that might deal with older clients to not be
surprised if the docs are not strictly followed.
For consistency, this patch fixes the code for all drivers,
even though it only makes an impact for vbox and for local
drivers. By fixing all drivers, future copy and paste from
a remote driver to a local driver is less likely to
reintroduce the bug.
Finally, update the testsuite to gain some coverage of the
issue for local drivers, including the first test of old-style
domain event registration via function pointer instead of
event id.
* src/libvirt.c (virConnectDomainEventRegister)
(virConnectDomainEventDeregister)
(virConnectDomainEventDeregisterAny): Clarify docs.
* src/libxl/libxl_driver.c (libxlConnectDomainEventRegister)
(libxlConnectDomainEventDeregister)
(libxlConnectDomainEventDeregisterAny): Match documentation.
* src/lxc/lxc_driver.c (lxcConnectDomainEventRegister)
(lxcConnectDomainEventDeregister)
(lxcConnectDomainEventDeregisterAny): Likewise.
* src/test/test_driver.c (testConnectDomainEventRegister)
(testConnectDomainEventDeregister)
(testConnectDomainEventDeregisterAny)
(testConnectNetworkEventDeregisterAny): Likewise.
* src/uml/uml_driver.c (umlConnectDomainEventRegister)
(umlConnectDomainEventDeregister)
(umlConnectDomainEventDeregisterAny): Likewise.
* src/vbox/vbox_tmpl.c (vboxConnectDomainEventRegister)
(vboxConnectDomainEventDeregister)
(vboxConnectDomainEventDeregisterAny): Likewise.
* src/xen/xen_driver.c (xenUnifiedConnectDomainEventRegister)
(xenUnifiedConnectDomainEventDeregister)
(xenUnifiedConnectDomainEventDeregisterAny): Likewise.
* src/network/bridge_driver.c
(networkConnectNetworkEventDeregisterAny): Likewise.
* tests/objecteventtest.c (testDomainCreateXMLOld): New test.
(mymain): Run it.
(testDomainCreateXML): Check return values.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-03 21:21:17 +00:00
|
|
|
ret = -1;
|
2013-12-11 10:37:59 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-15 18:15:39 +00:00
|
|
|
static int
|
|
|
|
testConnectStoragePoolEventRegisterAny(virConnectPtr conn,
|
|
|
|
virStoragePoolPtr pool,
|
|
|
|
int eventID,
|
|
|
|
virConnectStoragePoolEventGenericCallback callback,
|
|
|
|
void *opaque,
|
|
|
|
virFreeCallback freecb)
|
|
|
|
{
|
|
|
|
testDriverPtr driver = conn->privateData;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (virStoragePoolEventStateRegisterID(conn, driver->eventState,
|
|
|
|
pool, eventID, callback,
|
|
|
|
opaque, freecb, &ret) < 0)
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testConnectStoragePoolEventDeregisterAny(virConnectPtr conn,
|
|
|
|
int callbackID)
|
|
|
|
{
|
|
|
|
testDriverPtr driver = conn->privateData;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (virObjectEventStateDeregisterID(conn, driver->eventState,
|
2017-06-14 11:32:15 +00:00
|
|
|
callbackID, true) < 0)
|
2016-06-15 18:15:39 +00:00
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-07-28 12:02:52 +00:00
|
|
|
static int
|
|
|
|
testConnectNodeDeviceEventRegisterAny(virConnectPtr conn,
|
|
|
|
virNodeDevicePtr dev,
|
|
|
|
int eventID,
|
|
|
|
virConnectNodeDeviceEventGenericCallback callback,
|
|
|
|
void *opaque,
|
|
|
|
virFreeCallback freecb)
|
|
|
|
{
|
|
|
|
testDriverPtr driver = conn->privateData;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (virNodeDeviceEventStateRegisterID(conn, driver->eventState,
|
|
|
|
dev, eventID, callback,
|
|
|
|
opaque, freecb, &ret) < 0)
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testConnectNodeDeviceEventDeregisterAny(virConnectPtr conn,
|
|
|
|
int callbackID)
|
|
|
|
{
|
|
|
|
testDriverPtr driver = conn->privateData;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (virObjectEventStateDeregisterID(conn, driver->eventState,
|
2017-06-14 11:32:15 +00:00
|
|
|
callbackID, true) < 0)
|
2016-07-28 12:02:52 +00:00
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectListAllDomains(virConnectPtr conn,
|
|
|
|
virDomainPtr **domains,
|
|
|
|
unsigned int flags)
|
2012-06-11 09:04:57 +00:00
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = conn->privateData;
|
2012-06-11 09:04:57 +00:00
|
|
|
|
2012-08-03 15:48:05 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
|
2012-06-11 09:04:57 +00:00
|
|
|
|
2015-06-22 12:33:23 +00:00
|
|
|
return virDomainObjListExport(privconn->domains, conn, domains,
|
|
|
|
NULL, flags);
|
2012-06-11 09:04:57 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 14:05:15 +00:00
|
|
|
static int
|
2015-06-22 14:10:49 +00:00
|
|
|
testNodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2012-10-16 14:05:15 +00:00
|
|
|
unsigned char **cpumap,
|
|
|
|
unsigned int *online,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (cpumap) {
|
2013-07-04 10:16:47 +00:00
|
|
|
if (VIR_ALLOC_N(*cpumap, 1) < 0)
|
2015-06-22 14:10:49 +00:00
|
|
|
return -1;
|
2012-10-16 14:05:15 +00:00
|
|
|
*cpumap[0] = 0x15;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (online)
|
|
|
|
*online = 3;
|
|
|
|
|
2015-06-22 14:10:49 +00:00
|
|
|
return 8;
|
2012-10-16 14:05:15 +00:00
|
|
|
}
|
|
|
|
|
2013-03-29 21:25:13 +00:00
|
|
|
static char *
|
|
|
|
testDomainScreenshot(virDomainPtr dom ATTRIBUTE_UNUSED,
|
|
|
|
virStreamPtr st,
|
|
|
|
unsigned int screen ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2013-05-03 12:49:30 +00:00
|
|
|
if (VIR_STRDUP(ret, "image/png") < 0)
|
2013-03-29 21:25:13 +00:00
|
|
|
return NULL;
|
|
|
|
|
2016-12-06 12:45:18 +00:00
|
|
|
if (virFDStreamOpenFile(st, PKGDATADIR "/test-screenshot.png", 0, 0, O_RDONLY) < 0)
|
2013-03-29 21:25:13 +00:00
|
|
|
VIR_FREE(ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-01 12:46:56 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSendKey(virDomainPtr domain,
|
|
|
|
unsigned int codeset,
|
|
|
|
unsigned int holdtime ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int *keycodes,
|
|
|
|
int nkeycodes,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainObjCheckActive(vm) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < nkeycodes; i++) {
|
|
|
|
if (virKeycodeValueTranslate(codeset, codeset, keycodes[i]) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("invalid keycode %u of %s codeset"),
|
|
|
|
keycodes[i],
|
|
|
|
virKeycodeSetTypeToString(codeset));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainObjEndAPI(&vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-23 09:46:02 +00:00
|
|
|
static int
|
|
|
|
testConnectGetCPUModelNames(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2016-04-29 08:38:03 +00:00
|
|
|
const char *archName,
|
2013-09-23 09:46:02 +00:00
|
|
|
char ***models,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2016-04-29 08:38:03 +00:00
|
|
|
virArch arch;
|
|
|
|
|
2013-09-23 09:46:02 +00:00
|
|
|
virCheckFlags(0, -1);
|
2016-04-29 08:38:03 +00:00
|
|
|
|
|
|
|
if (!(arch = virArchFromString(archName))) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("cannot find architecture %s"),
|
|
|
|
archName);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-11-04 13:20:39 +00:00
|
|
|
return virCPUGetModels(arch, models);
|
2013-09-23 09:46:02 +00:00
|
|
|
}
|
2012-06-11 09:04:57 +00:00
|
|
|
|
2013-08-06 23:33:25 +00:00
|
|
|
static int
|
|
|
|
testDomainManagedSave(virDomainPtr dom, unsigned int flags)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = dom->conn->privateData;
|
2013-08-06 23:33:25 +00:00
|
|
|
virDomainObjPtr vm = NULL;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2013-08-06 23:33:25 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE |
|
|
|
|
VIR_DOMAIN_SAVE_RUNNING |
|
|
|
|
VIR_DOMAIN_SAVE_PAUSED, -1);
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(vm = testDomObjFromDomain(dom)))
|
|
|
|
return -1;
|
2013-08-06 23:33:25 +00:00
|
|
|
|
2018-04-17 22:13:28 +00:00
|
|
|
if (virDomainObjCheckActive(vm) < 0)
|
2013-08-06 23:33:25 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!vm->persistent) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("cannot do managed save for transient domain"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
testDomainShutdownState(dom, vm, VIR_DOMAIN_SHUTOFF_SAVED);
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
2013-08-06 23:33:25 +00:00
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_SAVED);
|
|
|
|
vm->hasManagedSave = true;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2013-08-06 23:33:25 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
2015-06-16 16:18:03 +00:00
|
|
|
int ret;
|
2013-08-06 23:33:25 +00:00
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(vm = testDomObjFromDomain(dom)))
|
|
|
|
return -1;
|
2013-08-06 23:33:25 +00:00
|
|
|
|
|
|
|
ret = vm->hasManagedSave;
|
2015-06-16 16:18:03 +00:00
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 23:33:25 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2015-06-16 16:18:03 +00:00
|
|
|
if (!(vm = testDomObjFromDomain(dom)))
|
|
|
|
return -1;
|
2013-08-06 23:33:25 +00:00
|
|
|
|
|
|
|
vm->hasManagedSave = false;
|
2015-06-16 16:18:03 +00:00
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2015-06-16 16:18:03 +00:00
|
|
|
return 0;
|
2013-08-06 23:33:25 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 11:37:01 +00:00
|
|
|
static int
|
|
|
|
testDomainMemoryPeek(virDomainPtr dom,
|
|
|
|
unsigned long long start,
|
|
|
|
size_t size,
|
|
|
|
void *buffer,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
|
|
|
unsigned char b = start;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_MEMORY_VIRTUAL | VIR_MEMORY_PHYSICAL, -1);
|
|
|
|
|
|
|
|
if (flags != VIR_MEMORY_VIRTUAL && flags != VIR_MEMORY_PHYSICAL) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
"%s", _("flags parameter must be VIR_MEMORY_VIRTUAL or VIR_MEMORY_PHYSICAL"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(dom)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainObjCheckActive(vm) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
((unsigned char *) buffer)[i] = b++;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainObjEndAPI(&vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-08-06 23:33:25 +00:00
|
|
|
|
2013-08-06 15:20:37 +00:00
|
|
|
/*
|
|
|
|
* Snapshot APIs
|
|
|
|
*/
|
|
|
|
|
2019-03-22 04:45:25 +00:00
|
|
|
static virDomainMomentObjPtr
|
2013-08-06 15:20:37 +00:00
|
|
|
testSnapObjFromName(virDomainObjPtr vm,
|
|
|
|
const char *name)
|
|
|
|
{
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr snap = NULL;
|
2013-08-06 15:20:37 +00:00
|
|
|
snap = virDomainSnapshotFindByName(vm->snapshots, name);
|
|
|
|
if (!snap)
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
|
|
|
|
_("no domain snapshot with matching name '%s'"),
|
|
|
|
name);
|
|
|
|
return snap;
|
|
|
|
}
|
|
|
|
|
2019-03-22 04:45:25 +00:00
|
|
|
static virDomainMomentObjPtr
|
2013-08-06 15:20:37 +00:00
|
|
|
testSnapObjFromSnapshot(virDomainObjPtr vm,
|
|
|
|
virDomainSnapshotPtr snapshot)
|
|
|
|
{
|
|
|
|
return testSnapObjFromName(vm, snapshot->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainObjPtr
|
|
|
|
testDomObjFromSnapshot(virDomainSnapshotPtr snapshot)
|
|
|
|
{
|
|
|
|
return testDomObjFromDomain(snapshot->domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotNum(virDomainPtr domain, unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
2015-06-16 12:05:18 +00:00
|
|
|
int n;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
|
2019-03-08 04:29:55 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL |
|
2013-08-06 15:20:37 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
2015-06-16 12:05:18 +00:00
|
|
|
return -1;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
n = virDomainSnapshotObjListNum(vm->snapshots, NULL, flags);
|
|
|
|
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 15:20:37 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotListNames(virDomainPtr domain,
|
|
|
|
char **names,
|
|
|
|
int nameslen,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
2015-06-16 12:05:18 +00:00
|
|
|
int n;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
|
2019-03-08 04:29:55 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL |
|
2013-08-06 15:20:37 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
2015-06-16 12:05:18 +00:00
|
|
|
return -1;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
n = virDomainSnapshotObjListGetNames(vm->snapshots, NULL, names, nameslen,
|
|
|
|
flags);
|
|
|
|
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 15:20:37 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainListAllSnapshots(virDomainPtr domain,
|
|
|
|
virDomainSnapshotPtr **snaps,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
2015-06-16 12:05:18 +00:00
|
|
|
int n;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
|
2019-03-08 04:29:55 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL |
|
2013-08-06 15:20:37 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
2015-06-16 12:05:18 +00:00
|
|
|
return -1;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
n = virDomainListSnapshots(vm->snapshots, NULL, domain, snaps, flags);
|
|
|
|
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 15:20:37 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot,
|
|
|
|
char **names,
|
|
|
|
int nameslen,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr snap = NULL;
|
2013-08-06 15:20:37 +00:00
|
|
|
int n = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS |
|
2019-03-08 04:29:55 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL |
|
2013-08-06 15:20:37 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
2015-06-16 12:05:18 +00:00
|
|
|
return -1;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
n = virDomainSnapshotObjListGetNames(vm->snapshots, snap, names, nameslen,
|
|
|
|
flags);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 15:20:37 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr snap = NULL;
|
2013-08-06 15:20:37 +00:00
|
|
|
int n = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS |
|
2019-03-08 04:29:55 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL |
|
2013-08-06 15:20:37 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
2015-06-16 12:05:18 +00:00
|
|
|
return -1;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
n = virDomainSnapshotObjListNum(vm->snapshots, snap, flags);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 15:20:37 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotListAllChildren(virDomainSnapshotPtr snapshot,
|
|
|
|
virDomainSnapshotPtr **snaps,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr snap = NULL;
|
2013-08-06 15:20:37 +00:00
|
|
|
int n = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS |
|
2019-03-08 04:29:55 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL |
|
2013-08-06 15:20:37 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
2015-06-16 12:05:18 +00:00
|
|
|
return -1;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
n = virDomainListSnapshots(vm->snapshots, snap, snapshot->domain, snaps,
|
|
|
|
flags);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 15:20:37 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainSnapshotPtr
|
|
|
|
testDomainSnapshotLookupByName(virDomainPtr domain,
|
|
|
|
const char *name,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr snap = NULL;
|
2013-08-06 15:20:37 +00:00
|
|
|
virDomainSnapshotPtr snapshot = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
2015-06-16 12:05:18 +00:00
|
|
|
return NULL;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
if (!(snap = testSnapObjFromName(vm, name)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2019-03-22 04:44:33 +00:00
|
|
|
snapshot = virGetDomainSnapshot(domain, snap->def->name);
|
2013-08-06 15:20:37 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 15:20:37 +00:00
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainHasCurrentSnapshot(virDomainPtr domain,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
2015-06-16 12:05:18 +00:00
|
|
|
int ret;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
2015-06-16 12:05:18 +00:00
|
|
|
return -1;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
2019-03-21 20:00:08 +00:00
|
|
|
ret = (virDomainSnapshotGetCurrent(vm->snapshots) != NULL);
|
2013-08-06 15:20:37 +00:00
|
|
|
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 15:20:37 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainSnapshotPtr
|
|
|
|
testDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr snap = NULL;
|
2013-08-06 15:20:37 +00:00
|
|
|
virDomainSnapshotPtr parent = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
2015-06-16 12:05:18 +00:00
|
|
|
return NULL;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2019-05-08 16:39:13 +00:00
|
|
|
if (!snap->def->parent_name) {
|
2013-08-06 15:20:37 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
|
|
|
|
_("snapshot '%s' does not have a parent"),
|
2019-03-22 04:44:33 +00:00
|
|
|
snap->def->name);
|
2013-08-06 15:20:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2019-05-08 16:39:13 +00:00
|
|
|
parent = virGetDomainSnapshot(snapshot->domain, snap->def->parent_name);
|
2013-08-06 15:20:37 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 15:20:37 +00:00
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainSnapshotPtr
|
|
|
|
testDomainSnapshotCurrent(virDomainPtr domain,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainSnapshotPtr snapshot = NULL;
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr current;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
2015-06-16 12:05:18 +00:00
|
|
|
return NULL;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
2019-03-21 20:00:08 +00:00
|
|
|
current = virDomainSnapshotGetCurrent(vm->snapshots);
|
|
|
|
if (!current) {
|
2013-08-06 15:20:37 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT, "%s",
|
|
|
|
_("the domain does not have a current snapshot"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2019-03-22 04:44:33 +00:00
|
|
|
snapshot = virGetDomainSnapshot(domain, current->def->name);
|
2013-08-06 15:20:37 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 15:20:37 +00:00
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
testDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
char *xml = NULL;
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr snap = NULL;
|
2013-08-06 15:20:37 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2016-02-04 22:55:05 +00:00
|
|
|
testDriverPtr privconn = snapshot->domain->conn->privateData;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
snapshot: Define explicit flags for snapshot xml
Commit f609cb85 (0.9.5) introduced virDomainSnapshotGetXMLDesc()'s use
of @flags as a subset of virDomainXMLFlags, documenting that 2 of the
3 flags defined at the time would never be valid. Later, commit
28f8dfdc (1.0.0) introduced a new flag, VIR_DOMAIN_XML_MIGRATABLE, but
did not adjust the snapshot documentation to declare it as invalid.
However, since the flag is not accepted as valid by any of the
drivers (remote is just passthrough; esx and vbox don't support flags;
qemu, test, and vz only support VIR_DOMAIN_XML_SECURE), and it is
unlikely that the domain state saved off during a snapshot creation
needs to be migration-friendly (as the snapshot is not the source of
a migration), it is easier to just define an explicit set of supported
flags directly related to the snapshot API rather than trying to
borrow from domain API, and risking confusion if even more domain
flags are added later (in fact, I have an upcoming patch that plans to
add a new flag to virDomainGetXMLDesc that makes no sense for
snapshots).
There is no API or ABI impact (since we purposefully used unsigned int
rather than an enum type in public API, and since the new flag name
carries the same value as the reused name).
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-02-13 21:09:05 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_XML_SECURE, NULL);
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
2015-06-16 12:05:18 +00:00
|
|
|
return NULL;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
virUUIDFormat(snapshot->domain->uuid, uuidstr);
|
|
|
|
|
2019-03-22 04:44:33 +00:00
|
|
|
xml = virDomainSnapshotDefFormat(uuidstr, virDomainSnapshotObjGetDef(snap),
|
|
|
|
privconn->caps, privconn->xmlopt,
|
2019-02-15 20:43:43 +00:00
|
|
|
virDomainSnapshotFormatConvertXMLFlags(flags));
|
2013-08-06 15:20:37 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 15:20:37 +00:00
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
2019-03-27 08:17:46 +00:00
|
|
|
int ret = -1;
|
|
|
|
virDomainMomentObjPtr snap = NULL;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
2015-06-16 12:05:18 +00:00
|
|
|
return -1;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
2019-03-27 08:17:46 +00:00
|
|
|
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = snap == virDomainSnapshotGetCurrent(vm->snapshots);
|
2013-08-06 15:20:37 +00:00
|
|
|
|
2019-03-27 08:17:46 +00:00
|
|
|
cleanup:
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 15:20:37 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
2015-06-16 12:05:18 +00:00
|
|
|
return -1;
|
2013-08-06 15:20:37 +00:00
|
|
|
|
2013-10-04 12:48:39 +00:00
|
|
|
if (!testSnapObjFromSnapshot(vm, snapshot))
|
2013-08-06 15:20:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 15:20:37 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-08-07 17:40:46 +00:00
|
|
|
static int
|
|
|
|
testDomainSnapshotAlignDisks(virDomainObjPtr vm,
|
|
|
|
virDomainSnapshotDefPtr def,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
|
2014-11-17 23:39:48 +00:00
|
|
|
bool align_match = true;
|
2013-08-07 17:40:46 +00:00
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) {
|
|
|
|
align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
|
|
|
|
align_match = false;
|
|
|
|
if (virDomainObjIsActive(vm))
|
2019-02-26 20:14:36 +00:00
|
|
|
def->state = VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT;
|
2013-08-07 17:40:46 +00:00
|
|
|
else
|
2019-02-26 20:14:36 +00:00
|
|
|
def->state = VIR_DOMAIN_SNAPSHOT_SHUTOFF;
|
2013-08-07 17:40:46 +00:00
|
|
|
def->memory = VIR_DOMAIN_SNAPSHOT_LOCATION_NONE;
|
|
|
|
} else if (def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
|
|
|
|
def->state = virDomainObjGetState(vm, NULL);
|
|
|
|
align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
|
|
|
|
align_match = false;
|
|
|
|
} else {
|
|
|
|
def->state = virDomainObjGetState(vm, NULL);
|
2019-02-26 20:14:36 +00:00
|
|
|
def->memory = def->state == VIR_DOMAIN_SNAPSHOT_SHUTOFF ?
|
2013-08-07 17:40:46 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_LOCATION_NONE :
|
|
|
|
VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return virDomainSnapshotAlignDisks(def, align_location, align_match);
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainSnapshotPtr
|
|
|
|
testDomainSnapshotCreateXML(virDomainPtr domain,
|
|
|
|
const char *xmlDesc,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = domain->conn->privateData;
|
2013-08-07 17:40:46 +00:00
|
|
|
virDomainObjPtr vm = NULL;
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr snap = NULL;
|
2013-08-07 17:40:46 +00:00
|
|
|
virDomainSnapshotPtr snapshot = NULL;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2013-08-21 20:54:17 +00:00
|
|
|
bool update_current = true;
|
|
|
|
bool redefine = flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE;
|
2013-08-07 17:40:46 +00:00
|
|
|
unsigned int parse_flags = VIR_DOMAIN_SNAPSHOT_PARSE_DISKS;
|
2019-05-09 14:59:06 +00:00
|
|
|
VIR_AUTOUNREF(virDomainSnapshotDefPtr) def = NULL;
|
2013-08-07 17:40:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DISK_ONLY: Not implemented yet
|
|
|
|
* REUSE_EXT: Not implemented yet
|
|
|
|
*
|
|
|
|
* NO_METADATA: Explicitly not implemented
|
|
|
|
*
|
2013-08-21 20:54:17 +00:00
|
|
|
* REDEFINE + CURRENT: Implemented
|
2013-08-07 17:40:46 +00:00
|
|
|
* HALT: Implemented
|
|
|
|
* QUIESCE: Nothing to do
|
|
|
|
* ATOMIC: Nothing to do
|
|
|
|
* LIVE: Nothing to do
|
|
|
|
*/
|
|
|
|
virCheckFlags(
|
2013-08-21 20:54:17 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT |
|
2013-08-07 17:40:46 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_CREATE_HALT |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_CREATE_LIVE, NULL);
|
|
|
|
|
2013-08-21 20:54:17 +00:00
|
|
|
if ((redefine && !(flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)))
|
|
|
|
update_current = false;
|
|
|
|
if (redefine)
|
|
|
|
parse_flags |= VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE;
|
|
|
|
|
2013-08-07 17:40:46 +00:00
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!vm->persistent && (flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("cannot halt after transient domain snapshot"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(def = virDomainSnapshotDefParseString(xmlDesc,
|
|
|
|
privconn->caps,
|
|
|
|
privconn->xmlopt,
|
snapshot: Drop virDomainSnapshotDef.current
The only use for the 'current' member of virDomainSnapshotDef was with
the PARSE/FORMAT_INTERNAL flag for controlling an internal-use
<active> element marking whether a particular snapshot definition was
current, and even then, only by the qemu driver on output, and by qemu
and test driver on input. But this duplicates vm->snapshot_current,
and gets in the way of potential simplifications to have qemu store a
single file for all snapshots rather than one file per snapshot. Get
rid of the member by adding a bool* parameter during parse (ignored if
the PARSE_INTERNAL flag is not set), and by adding a new flag during
format (if FORMAT_INTERNAL is set, the value printed in <active>
depends on the new FORMAT_CURRENT).
Then update the qemu driver accordingly, which involves hoisting
assignments to vm->current_snapshot to occur prior to any point where
a snapshot XML file is written (although qemu kept
vm->current_snapshot and snapshot->def_current in sync by the end of
the function, they were not always identical in the middle of
functions, so the shuffling gets a bit interesting). Later patches
will clean up some of that confusing churn to vm->current_snapshot.
Note: even if later patches refactor qemu to no longer use
FORMAT_INTERNAL for output (by storing bulk snapshot XML instead), we
will always need PARSE_INTERNAL for input (because on upgrade, a new
libvirt still has to parse XML left from a previous libvirt).
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-03-19 03:56:19 +00:00
|
|
|
NULL,
|
2013-08-07 17:40:46 +00:00
|
|
|
parse_flags)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-08-21 20:54:17 +00:00
|
|
|
if (redefine) {
|
2013-10-04 12:48:39 +00:00
|
|
|
if (virDomainSnapshotRedefinePrep(domain, vm, &def, &snap,
|
2017-05-19 13:07:15 +00:00
|
|
|
privconn->xmlopt,
|
2013-10-04 12:48:39 +00:00
|
|
|
&update_current, flags) < 0)
|
2013-08-21 20:54:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
} else {
|
2019-05-08 22:10:58 +00:00
|
|
|
if (!(def->parent.dom = virDomainDefCopy(vm->def,
|
2019-03-22 02:02:19 +00:00
|
|
|
privconn->caps,
|
|
|
|
privconn->xmlopt,
|
|
|
|
NULL,
|
|
|
|
true)))
|
2013-08-21 20:54:17 +00:00
|
|
|
goto cleanup;
|
2013-08-07 17:40:46 +00:00
|
|
|
|
2013-08-21 20:54:17 +00:00
|
|
|
if (testDomainSnapshotAlignDisks(vm, def, flags) < 0)
|
2013-08-07 17:40:46 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-08-21 20:54:17 +00:00
|
|
|
if (!snap) {
|
|
|
|
if (!(snap = virDomainSnapshotAssignDef(vm->snapshots, def)))
|
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
2013-08-07 17:40:46 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 20:54:17 +00:00
|
|
|
if (!redefine) {
|
2019-05-08 16:39:13 +00:00
|
|
|
if (VIR_STRDUP(snap->def->parent_name,
|
2019-03-21 20:00:08 +00:00
|
|
|
virDomainSnapshotGetCurrentName(vm->snapshots)) < 0)
|
2013-08-21 20:54:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT) &&
|
|
|
|
virDomainObjIsActive(vm)) {
|
|
|
|
testDomainShutdownState(domain, vm,
|
|
|
|
VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT);
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
|
2013-08-21 20:54:17 +00:00
|
|
|
VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT);
|
|
|
|
}
|
|
|
|
}
|
2013-08-07 17:40:46 +00:00
|
|
|
|
2019-03-22 04:44:33 +00:00
|
|
|
snapshot = virGetDomainSnapshot(domain, snap->def->name);
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-07 17:40:46 +00:00
|
|
|
if (vm) {
|
|
|
|
if (snapshot) {
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr other;
|
2013-08-21 20:54:17 +00:00
|
|
|
if (update_current)
|
2019-03-21 20:00:08 +00:00
|
|
|
virDomainSnapshotSetCurrent(vm->snapshots, snap);
|
2013-08-07 17:40:46 +00:00
|
|
|
other = virDomainSnapshotFindByName(vm->snapshots,
|
2019-05-08 16:39:13 +00:00
|
|
|
snap->def->parent_name);
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentSetParent(snap, other);
|
2013-08-07 17:40:46 +00:00
|
|
|
}
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-07 17:40:46 +00:00
|
|
|
}
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2013-08-07 17:40:46 +00:00
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _testSnapRemoveData testSnapRemoveData;
|
|
|
|
typedef testSnapRemoveData *testSnapRemoveDataPtr;
|
|
|
|
struct _testSnapRemoveData {
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
bool current;
|
|
|
|
};
|
|
|
|
|
2016-02-12 09:03:50 +00:00
|
|
|
static int
|
2013-08-07 17:40:46 +00:00
|
|
|
testDomainSnapshotDiscardAll(void *payload,
|
2016-02-12 09:03:50 +00:00
|
|
|
const void *name ATTRIBUTE_UNUSED,
|
|
|
|
void *data)
|
2013-08-07 17:40:46 +00:00
|
|
|
{
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr snap = payload;
|
2013-08-07 17:40:46 +00:00
|
|
|
testSnapRemoveDataPtr curr = data;
|
|
|
|
|
2019-03-21 20:00:08 +00:00
|
|
|
curr->current |= virDomainSnapshotObjListRemove(curr->vm->snapshots, snap);
|
2016-02-12 09:03:50 +00:00
|
|
|
return 0;
|
2013-08-07 17:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct _testSnapReparentData testSnapReparentData;
|
|
|
|
typedef testSnapReparentData *testSnapReparentDataPtr;
|
|
|
|
struct _testSnapReparentData {
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr parent;
|
2013-08-07 17:40:46 +00:00
|
|
|
virDomainObjPtr vm;
|
|
|
|
int err;
|
|
|
|
};
|
|
|
|
|
2016-02-12 09:03:50 +00:00
|
|
|
static int
|
2013-08-07 17:40:46 +00:00
|
|
|
testDomainSnapshotReparentChildren(void *payload,
|
|
|
|
const void *name ATTRIBUTE_UNUSED,
|
|
|
|
void *data)
|
|
|
|
{
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr snap = payload;
|
2013-08-07 17:40:46 +00:00
|
|
|
testSnapReparentDataPtr rep = data;
|
|
|
|
|
2014-11-13 14:24:39 +00:00
|
|
|
if (rep->err < 0)
|
2016-02-12 09:03:50 +00:00
|
|
|
return 0;
|
2013-08-07 17:40:46 +00:00
|
|
|
|
2019-05-08 16:39:13 +00:00
|
|
|
VIR_FREE(snap->def->parent_name);
|
2013-08-07 17:40:46 +00:00
|
|
|
|
|
|
|
if (rep->parent->def &&
|
2019-05-08 16:39:13 +00:00
|
|
|
VIR_STRDUP(snap->def->parent_name, rep->parent->def->name) < 0) {
|
2013-08-07 17:40:46 +00:00
|
|
|
rep->err = -1;
|
2016-02-12 09:03:50 +00:00
|
|
|
return 0;
|
2013-08-07 17:40:46 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 09:03:50 +00:00
|
|
|
return 0;
|
2013-08-07 17:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr snap = NULL;
|
|
|
|
virDomainMomentObjPtr parentsnap = NULL;
|
2013-08-07 17:40:46 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) {
|
|
|
|
testSnapRemoveData rem;
|
|
|
|
rem.vm = vm;
|
|
|
|
rem.current = false;
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentForEachDescendant(snap,
|
|
|
|
testDomainSnapshotDiscardAll,
|
|
|
|
&rem);
|
test: Avoid use-after-free on virDomainSnapshotDelete
The following virsh command was triggering a use-after-free:
$ virsh -c test:///default '
snapshot-create-as test s1
snapshot-create-as test s2
snapshot-delete --children-only test s1
snapshot-current --name test'
Domain snapshot s1 created
Domain snapshot s2 created
Domain snapshot s1 children deleted
error: name in virGetDomainSnapshot must not be NULL
I got lucky on that run - although the error message is quite
unexpected. On other runs, I was able to get a core dump, and
valgrind confirms there is a definitive problem.
The culprit? We were inconsistent about whether we set
vm->current_snapshot, snap->def->current, or both when updating how
the current snapshot was being tracked. As a result, deletion did not
see that snapshot s2 was previously current, and failed to update
vm->current_snapshot, so that the next API using the current snapshot
failed because it referenced stale memory for the now-gone s2 (instead
of the intended s1).
The test driver code was copied from the qemu code (which DOES track
both pieces of state everywhere), but was purposefully simplified
because the test driver does not have to write persistent snapshot
state to the file system. But when you realize that the only reason
snap->def->current needs to exist is when writing out one file per
snapshot for qemu, it's just as easy to state that the test driver
never has to mess with the field (rather than chasing down which
places forgot to set the field), and have vm->current_snapshot be the
sole source of truth in the test driver.
Ideally, I'd get rid of the 'current' member in virDomainSnapshotDef,
as well as the 'current_snapshot' member in virDomainDef, and instead
track the current member in virDomainSnapshotObjList, coupled with
writing ALL snapshot state for qemu in a single file (where I can use
<snapshots current='...'> as a wrapper, rather than
VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL to output <current>1</current> XML
on a per-snapshot file basis). But that's a bigger change, so for now
I'm just patching things to avoid the test driver segfault.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-03-17 03:57:45 +00:00
|
|
|
if (rem.current)
|
2019-03-21 20:00:08 +00:00
|
|
|
virDomainSnapshotSetCurrent(vm->snapshots, snap);
|
2013-08-07 17:40:46 +00:00
|
|
|
} else if (snap->nchildren) {
|
|
|
|
testSnapReparentData rep;
|
|
|
|
rep.parent = snap->parent;
|
|
|
|
rep.vm = vm;
|
|
|
|
rep.err = 0;
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentForEachChild(snap,
|
|
|
|
testDomainSnapshotReparentChildren,
|
|
|
|
&rep);
|
2013-08-07 17:40:46 +00:00
|
|
|
if (rep.err < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentMoveChildren(snap, snap->parent);
|
2013-08-07 17:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) {
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentDropChildren(snap);
|
2013-08-07 17:40:46 +00:00
|
|
|
} else {
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentDropParent(snap);
|
2019-03-21 20:00:08 +00:00
|
|
|
if (snap == virDomainSnapshotGetCurrent(vm->snapshots)) {
|
2019-05-08 16:39:13 +00:00
|
|
|
if (snap->def->parent_name) {
|
2013-08-07 17:40:46 +00:00
|
|
|
parentsnap = virDomainSnapshotFindByName(vm->snapshots,
|
2019-05-08 16:39:13 +00:00
|
|
|
snap->def->parent_name);
|
test: Avoid use-after-free on virDomainSnapshotDelete
The following virsh command was triggering a use-after-free:
$ virsh -c test:///default '
snapshot-create-as test s1
snapshot-create-as test s2
snapshot-delete --children-only test s1
snapshot-current --name test'
Domain snapshot s1 created
Domain snapshot s2 created
Domain snapshot s1 children deleted
error: name in virGetDomainSnapshot must not be NULL
I got lucky on that run - although the error message is quite
unexpected. On other runs, I was able to get a core dump, and
valgrind confirms there is a definitive problem.
The culprit? We were inconsistent about whether we set
vm->current_snapshot, snap->def->current, or both when updating how
the current snapshot was being tracked. As a result, deletion did not
see that snapshot s2 was previously current, and failed to update
vm->current_snapshot, so that the next API using the current snapshot
failed because it referenced stale memory for the now-gone s2 (instead
of the intended s1).
The test driver code was copied from the qemu code (which DOES track
both pieces of state everywhere), but was purposefully simplified
because the test driver does not have to write persistent snapshot
state to the file system. But when you realize that the only reason
snap->def->current needs to exist is when writing out one file per
snapshot for qemu, it's just as easy to state that the test driver
never has to mess with the field (rather than chasing down which
places forgot to set the field), and have vm->current_snapshot be the
sole source of truth in the test driver.
Ideally, I'd get rid of the 'current' member in virDomainSnapshotDef,
as well as the 'current_snapshot' member in virDomainDef, and instead
track the current member in virDomainSnapshotObjList, coupled with
writing ALL snapshot state for qemu in a single file (where I can use
<snapshots current='...'> as a wrapper, rather than
VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL to output <current>1</current> XML
on a per-snapshot file basis). But that's a bigger change, so for now
I'm just patching things to avoid the test driver segfault.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-03-17 03:57:45 +00:00
|
|
|
if (!parentsnap)
|
2013-08-07 17:40:46 +00:00
|
|
|
VIR_WARN("missing parent snapshot matching name '%s'",
|
2019-05-08 16:39:13 +00:00
|
|
|
snap->def->parent_name);
|
2013-08-07 17:40:46 +00:00
|
|
|
}
|
2019-03-21 20:00:08 +00:00
|
|
|
virDomainSnapshotSetCurrent(vm->snapshots, parentsnap);
|
2013-08-07 17:40:46 +00:00
|
|
|
}
|
|
|
|
virDomainSnapshotObjListRemove(vm->snapshots, snap);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-07 17:40:46 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2015-06-22 14:25:16 +00:00
|
|
|
testDriverPtr privconn = snapshot->domain->conn->privateData;
|
2013-08-07 17:40:46 +00:00
|
|
|
virDomainObjPtr vm = NULL;
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr snap = NULL;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
|
|
|
virObjectEventPtr event2 = NULL;
|
2013-08-07 17:40:46 +00:00
|
|
|
virDomainDefPtr config = NULL;
|
2019-03-22 04:44:33 +00:00
|
|
|
virDomainSnapshotDefPtr snapdef;
|
2013-08-07 17:40:46 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_REVERT_FORCE, -1);
|
|
|
|
|
|
|
|
/* We have the following transitions, which create the following events:
|
|
|
|
* 1. inactive -> inactive: none
|
|
|
|
* 2. inactive -> running: EVENT_STARTED
|
|
|
|
* 3. inactive -> paused: EVENT_STARTED, EVENT_PAUSED
|
|
|
|
* 4. running -> inactive: EVENT_STOPPED
|
|
|
|
* 5. running -> running: none
|
|
|
|
* 6. running -> paused: EVENT_PAUSED
|
|
|
|
* 7. paused -> inactive: EVENT_STOPPED
|
|
|
|
* 8. paused -> running: EVENT_RESUMED
|
|
|
|
* 9. paused -> paused: none
|
|
|
|
* Also, several transitions occur even if we fail partway through,
|
|
|
|
* and use of FORCE can cause multiple transitions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
|
|
|
goto cleanup;
|
2019-03-22 04:44:33 +00:00
|
|
|
snapdef = virDomainSnapshotObjGetDef(snap);
|
2013-08-07 17:40:46 +00:00
|
|
|
|
|
|
|
if (!vm->persistent &&
|
2019-03-22 04:44:33 +00:00
|
|
|
snapdef->state != VIR_DOMAIN_SNAPSHOT_RUNNING &&
|
|
|
|
snapdef->state != VIR_DOMAIN_SNAPSHOT_PAUSED &&
|
2013-08-07 17:40:46 +00:00
|
|
|
(flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) == 0) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("transient domain needs to request run or pause "
|
|
|
|
"to revert to inactive snapshot"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)) {
|
2019-03-22 04:44:33 +00:00
|
|
|
if (!snap->def->dom) {
|
2013-08-07 17:40:46 +00:00
|
|
|
virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY,
|
|
|
|
_("snapshot '%s' lacks domain '%s' rollback info"),
|
2019-03-22 04:44:33 +00:00
|
|
|
snap->def->name, vm->def->name);
|
2013-08-07 17:40:46 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virDomainObjIsActive(vm) &&
|
2019-03-22 04:44:33 +00:00
|
|
|
!(snapdef->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
|
|
|
|
snapdef->state == VIR_DOMAIN_SNAPSHOT_PAUSED) &&
|
2013-08-07 17:40:46 +00:00
|
|
|
(flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED))) {
|
|
|
|
virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, "%s",
|
|
|
|
_("must respawn guest to start inactive snapshot"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-21 20:00:08 +00:00
|
|
|
virDomainSnapshotSetCurrent(vm->snapshots, NULL);
|
2013-08-07 17:40:46 +00:00
|
|
|
|
2019-03-22 04:44:33 +00:00
|
|
|
config = virDomainDefCopy(snap->def->dom, privconn->caps,
|
2016-09-22 15:23:03 +00:00
|
|
|
privconn->xmlopt, NULL, true);
|
2013-08-07 17:40:46 +00:00
|
|
|
if (!config)
|
|
|
|
goto cleanup;
|
|
|
|
|
2019-03-22 04:44:33 +00:00
|
|
|
if (snapdef->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
|
|
|
|
snapdef->state == VIR_DOMAIN_SNAPSHOT_PAUSED) {
|
2013-08-07 17:40:46 +00:00
|
|
|
/* Transitions 2, 3, 5, 6, 8, 9 */
|
|
|
|
bool was_running = false;
|
|
|
|
bool was_stopped = false;
|
|
|
|
|
|
|
|
if (virDomainObjIsActive(vm)) {
|
|
|
|
/* Transitions 5, 6, 8, 9 */
|
|
|
|
/* Check for ABI compatibility. */
|
2017-05-19 13:07:15 +00:00
|
|
|
if (!virDomainDefCheckABIStability(vm->def, config,
|
|
|
|
privconn->xmlopt)) {
|
2013-08-07 17:40:46 +00:00
|
|
|
virErrorPtr err = virGetLastError();
|
|
|
|
|
|
|
|
if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)) {
|
|
|
|
/* Re-spawn error using correct category. */
|
|
|
|
if (err->code == VIR_ERR_CONFIG_UNSUPPORTED)
|
|
|
|
virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, "%s",
|
|
|
|
err->str2);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
virResetError(err);
|
|
|
|
testDomainShutdownState(snapshot->domain, vm,
|
|
|
|
VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT);
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
2013-08-07 17:40:46 +00:00
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT);
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2013-08-07 17:40:46 +00:00
|
|
|
goto load;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
|
|
|
|
/* Transitions 5, 6 */
|
|
|
|
was_running = true;
|
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
|
|
|
|
VIR_DOMAIN_PAUSED_FROM_SNAPSHOT);
|
|
|
|
/* Create an event now in case the restore fails, so
|
|
|
|
* that user will be alerted that they are now paused.
|
|
|
|
* If restore later succeeds, we might replace this. */
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
2013-08-07 17:40:46 +00:00
|
|
|
VIR_DOMAIN_EVENT_SUSPENDED,
|
|
|
|
VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT);
|
|
|
|
}
|
|
|
|
virDomainObjAssignDef(vm, config, false, NULL);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* Transitions 2, 3 */
|
|
|
|
load:
|
|
|
|
was_stopped = true;
|
|
|
|
virDomainObjAssignDef(vm, config, false, NULL);
|
|
|
|
if (testDomainStartState(privconn, vm,
|
|
|
|
VIR_DOMAIN_RUNNING_FROM_SNAPSHOT) < 0)
|
|
|
|
goto cleanup;
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
2013-08-07 17:40:46 +00:00
|
|
|
VIR_DOMAIN_EVENT_STARTED,
|
|
|
|
VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Touch up domain state. */
|
|
|
|
if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING) &&
|
2019-03-22 04:44:33 +00:00
|
|
|
(snapdef->state == VIR_DOMAIN_SNAPSHOT_PAUSED ||
|
2013-08-07 17:40:46 +00:00
|
|
|
(flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED))) {
|
|
|
|
/* Transitions 3, 6, 9 */
|
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
|
|
|
|
VIR_DOMAIN_PAUSED_FROM_SNAPSHOT);
|
|
|
|
if (was_stopped) {
|
|
|
|
/* Transition 3, use event as-is and add event2 */
|
2013-11-21 17:03:26 +00:00
|
|
|
event2 = virDomainEventLifecycleNewFromObj(vm,
|
2013-08-07 17:40:46 +00:00
|
|
|
VIR_DOMAIN_EVENT_SUSPENDED,
|
|
|
|
VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT);
|
|
|
|
} /* else transition 6 and 9 use event as-is */
|
|
|
|
} else {
|
|
|
|
/* Transitions 2, 5, 8 */
|
2013-11-21 16:04:33 +00:00
|
|
|
virObjectUnref(event);
|
2013-08-07 17:40:46 +00:00
|
|
|
event = NULL;
|
|
|
|
|
|
|
|
if (was_stopped) {
|
|
|
|
/* Transition 2 */
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
2013-08-07 17:40:46 +00:00
|
|
|
VIR_DOMAIN_EVENT_STARTED,
|
|
|
|
VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT);
|
|
|
|
} else if (was_running) {
|
|
|
|
/* Transition 8 */
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
2013-08-07 17:40:46 +00:00
|
|
|
VIR_DOMAIN_EVENT_RESUMED,
|
|
|
|
VIR_DOMAIN_EVENT_RESUMED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Transitions 1, 4, 7 */
|
|
|
|
virDomainObjAssignDef(vm, config, false, NULL);
|
|
|
|
|
|
|
|
if (virDomainObjIsActive(vm)) {
|
|
|
|
/* Transitions 4, 7 */
|
|
|
|
testDomainShutdownState(snapshot->domain, vm,
|
|
|
|
VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT);
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
2013-08-07 17:40:46 +00:00
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) {
|
|
|
|
/* Flush first event, now do transition 2 or 3 */
|
|
|
|
bool paused = (flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED) != 0;
|
|
|
|
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNewFromObj(vm,
|
2013-08-07 17:40:46 +00:00
|
|
|
VIR_DOMAIN_EVENT_STARTED,
|
|
|
|
VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT);
|
|
|
|
if (paused) {
|
2013-11-21 17:03:26 +00:00
|
|
|
event2 = virDomainEventLifecycleNewFromObj(vm,
|
2013-08-07 17:40:46 +00:00
|
|
|
VIR_DOMAIN_EVENT_SUSPENDED,
|
|
|
|
VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-21 20:00:08 +00:00
|
|
|
virDomainSnapshotSetCurrent(vm->snapshots, snap);
|
2013-08-07 17:40:46 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-07 17:40:46 +00:00
|
|
|
if (event) {
|
2018-06-12 17:33:00 +00:00
|
|
|
virObjectEventStateQueue(privconn->eventState, event);
|
|
|
|
virObjectEventStateQueue(privconn->eventState, event2);
|
2013-10-04 12:48:39 +00:00
|
|
|
} else {
|
2013-11-21 16:04:33 +00:00
|
|
|
virObjectUnref(event2);
|
2013-08-07 17:40:46 +00:00
|
|
|
}
|
2015-06-16 12:05:18 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-07 17:40:46 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-20 16:16:26 +00:00
|
|
|
static virHypervisorDriver testHypervisorDriver = {
|
Convert all driver struct intializers to C99 style
Change all the driver struct initializers to use the
C99 style, leaving out unused fields. This will make
it possible to add new APIs without changing every
driver. eg change:
qemudDomainResume, /* domainResume */
qemudDomainShutdown, /* domainShutdown */
NULL, /* domainReboot */
qemudDomainDestroy, /* domainDestroy */
to
.domainResume = qemudDomainResume,
.domainShutdown = qemudDomainShutdown,
.domainDestroy = qemudDomainDestroy,
And get rid of any existing C99 style initializersr which
set NULL, eg change
.listPools = vboxStorageListPools,
.numOfDefinedPools = NULL,
.listDefinedPools = NULL,
.findPoolSources = NULL,
.poolLookupByName = vboxStoragePoolLookupByName,
to
.listPools = vboxStorageListPools,
.poolLookupByName = vboxStoragePoolLookupByName,
2011-05-13 10:16:31 +00:00
|
|
|
.name = "Test",
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectOpen = testConnectOpen, /* 0.1.1 */
|
|
|
|
.connectClose = testConnectClose, /* 0.1.1 */
|
|
|
|
.connectGetVersion = testConnectGetVersion, /* 0.1.1 */
|
2013-04-26 16:39:11 +00:00
|
|
|
.connectGetHostname = testConnectGetHostname, /* 0.6.3 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectGetMaxVcpus = testConnectGetMaxVcpus, /* 0.3.2 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.nodeGetInfo = testNodeGetInfo, /* 0.1.1 */
|
2016-09-15 08:27:06 +00:00
|
|
|
.nodeGetCPUStats = testNodeGetCPUStats, /* 2.3.0 */
|
2016-09-15 08:27:07 +00:00
|
|
|
.nodeGetFreeMemory = testNodeGetFreeMemory, /* 2.3.0 */
|
2016-09-15 08:27:09 +00:00
|
|
|
.nodeGetFreePages = testNodeGetFreePages, /* 2.3.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectGetCapabilities = testConnectGetCapabilities, /* 0.2.1 */
|
2016-09-15 08:27:04 +00:00
|
|
|
.connectGetSysinfo = testConnectGetSysinfo, /* 2.3.0 */
|
2016-09-15 08:27:05 +00:00
|
|
|
.connectGetType = testConnectGetType, /* 2.3.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectListDomains = testConnectListDomains, /* 0.1.1 */
|
|
|
|
.connectNumOfDomains = testConnectNumOfDomains, /* 0.1.1 */
|
|
|
|
.connectListAllDomains = testConnectListAllDomains, /* 0.9.13 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainCreateXML = testDomainCreateXML, /* 0.1.4 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.domainLookupByID = testDomainLookupByID, /* 0.1.1 */
|
|
|
|
.domainLookupByUUID = testDomainLookupByUUID, /* 0.1.1 */
|
|
|
|
.domainLookupByName = testDomainLookupByName, /* 0.1.1 */
|
|
|
|
.domainSuspend = testDomainSuspend, /* 0.1.1 */
|
|
|
|
.domainResume = testDomainResume, /* 0.1.1 */
|
|
|
|
.domainShutdown = testDomainShutdown, /* 0.1.1 */
|
|
|
|
.domainShutdownFlags = testDomainShutdownFlags, /* 0.9.10 */
|
|
|
|
.domainReboot = testDomainReboot, /* 0.1.1 */
|
|
|
|
.domainDestroy = testDomainDestroy, /* 0.1.1 */
|
2018-03-22 18:42:27 +00:00
|
|
|
.domainDestroyFlags = testDomainDestroyFlags, /* 4.2.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.domainGetOSType = testDomainGetOSType, /* 0.1.9 */
|
2019-06-11 11:07:26 +00:00
|
|
|
.domainGetLaunchSecurityInfo = testDomainGetLaunchSecurityInfo, /* 5.5.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.domainGetMaxMemory = testDomainGetMaxMemory, /* 0.1.4 */
|
|
|
|
.domainSetMaxMemory = testDomainSetMaxMemory, /* 0.1.1 */
|
|
|
|
.domainSetMemory = testDomainSetMemory, /* 0.1.4 */
|
2019-05-31 14:31:35 +00:00
|
|
|
.domainGetHostname = testDomainGetHostname, /* 5.5.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.domainGetInfo = testDomainGetInfo, /* 0.1.1 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainGetState = testDomainGetState, /* 0.9.2 */
|
2019-04-24 16:57:57 +00:00
|
|
|
.domainGetTime = testDomainGetTime, /* 5.4.0 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainSave = testDomainSave, /* 0.3.2 */
|
save: wire up trivial save/restore flags implementations
For all hypervisors that support save and restore, the new API
now performs the same functions as the old.
VBox is excluded from this list, because its existing domainsave
is broken (there is no corresponding domainrestore, and there
is no control over the filename used in the save). A later
patch should change vbox to use its implementation for
managedsave, and teach start to use managedsave results.
* src/libxl/libxl_driver.c (libxlDomainSave): Move guts...
(libxlDomainSaveFlags): ...to new function.
(libxlDomainRestore): Move guts...
(libxlDomainRestoreFlags): ...to new function.
* src/test/test_driver.c (testDomainSave, testDomainSaveFlags)
(testDomainRestore, testDomainRestoreFlags): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSave)
(xenUnifiedDomainSaveFlags, xenUnifiedDomainRestore)
(xenUnifiedDomainRestoreFlags): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSave, qemudDomainRestore):
Rename and move guts.
(qemuDomainSave, qemuDomainSaveFlags, qemuDomainRestore)
(qemuDomainRestoreFlags): ...here.
(qemudDomainSaveFlag): Rename...
(qemuDomainSaveInternal): ...to this, and update callers.
2011-07-09 02:55:29 +00:00
|
|
|
.domainSaveFlags = testDomainSaveFlags, /* 0.9.4 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainRestore = testDomainRestore, /* 0.3.2 */
|
save: wire up trivial save/restore flags implementations
For all hypervisors that support save and restore, the new API
now performs the same functions as the old.
VBox is excluded from this list, because its existing domainsave
is broken (there is no corresponding domainrestore, and there
is no control over the filename used in the save). A later
patch should change vbox to use its implementation for
managedsave, and teach start to use managedsave results.
* src/libxl/libxl_driver.c (libxlDomainSave): Move guts...
(libxlDomainSaveFlags): ...to new function.
(libxlDomainRestore): Move guts...
(libxlDomainRestoreFlags): ...to new function.
* src/test/test_driver.c (testDomainSave, testDomainSaveFlags)
(testDomainRestore, testDomainRestoreFlags): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSave)
(xenUnifiedDomainSaveFlags, xenUnifiedDomainRestore)
(xenUnifiedDomainRestoreFlags): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSave, qemudDomainRestore):
Rename and move guts.
(qemuDomainSave, qemuDomainSaveFlags, qemuDomainRestore)
(qemuDomainRestoreFlags): ...here.
(qemudDomainSaveFlag): Rename...
(qemuDomainSaveInternal): ...to this, and update callers.
2011-07-09 02:55:29 +00:00
|
|
|
.domainRestoreFlags = testDomainRestoreFlags, /* 0.9.4 */
|
2019-06-10 09:05:00 +00:00
|
|
|
.domainSaveImageDefineXML = testDomainSaveImageDefineXML, /* 5.5.0 */
|
2019-06-10 09:05:01 +00:00
|
|
|
.domainSaveImageGetXMLDesc = testDomainSaveImageGetXMLDesc, /* 5.5.0 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainCoreDump = testDomainCoreDump, /* 0.3.2 */
|
2014-03-23 03:51:12 +00:00
|
|
|
.domainCoreDumpWithFormat = testDomainCoreDumpWithFormat, /* 1.2.3 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.domainSetVcpus = testDomainSetVcpus, /* 0.1.4 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainSetVcpusFlags = testDomainSetVcpusFlags, /* 0.8.5 */
|
|
|
|
.domainGetVcpusFlags = testDomainGetVcpusFlags, /* 0.8.5 */
|
|
|
|
.domainPinVcpu = testDomainPinVcpu, /* 0.7.3 */
|
|
|
|
.domainGetVcpus = testDomainGetVcpus, /* 0.7.3 */
|
2015-07-14 13:10:50 +00:00
|
|
|
.domainGetVcpuPinInfo = testDomainGetVcpuPinInfo, /* 1.2.18 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainGetMaxVcpus = testDomainGetMaxVcpus, /* 0.7.3 */
|
|
|
|
.domainGetXMLDesc = testDomainGetXMLDesc, /* 0.1.4 */
|
2019-07-02 13:49:42 +00:00
|
|
|
.domainGetMemoryParameters = testDomainGetMemoryParameters, /* 5.6.0 */
|
2019-07-02 13:49:43 +00:00
|
|
|
.domainGetNumaParameters = testDomainGetNumaParameters, /* 5.6.0 */
|
2019-07-02 13:49:44 +00:00
|
|
|
.domainGetInterfaceParameters = testDomainGetInterfaceParameters, /* 5.6.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectListDefinedDomains = testConnectListDefinedDomains, /* 0.1.11 */
|
|
|
|
.connectNumOfDefinedDomains = testConnectNumOfDefinedDomains, /* 0.1.11 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainCreate = testDomainCreate, /* 0.1.11 */
|
|
|
|
.domainCreateWithFlags = testDomainCreateWithFlags, /* 0.8.2 */
|
|
|
|
.domainDefineXML = testDomainDefineXML, /* 0.1.11 */
|
2014-11-18 14:19:38 +00:00
|
|
|
.domainDefineXMLFlags = testDomainDefineXMLFlags, /* 1.2.12 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainUndefine = testDomainUndefine, /* 0.1.11 */
|
2011-07-20 03:08:21 +00:00
|
|
|
.domainUndefineFlags = testDomainUndefineFlags, /* 0.9.4 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainGetAutostart = testDomainGetAutostart, /* 0.3.2 */
|
|
|
|
.domainSetAutostart = testDomainSetAutostart, /* 0.3.2 */
|
2019-05-12 23:26:14 +00:00
|
|
|
.domainGetDiskErrors = testDomainGetDiskErrors, /* 5.4.0 */
|
2019-06-25 21:58:07 +00:00
|
|
|
.domainGetFSInfo = testDomainGetFSInfo, /* 5.6.0 */
|
2019-07-03 11:54:18 +00:00
|
|
|
.domainSetPerfEvents = testDomainSetPerfEvents, /* 5.6.0 */
|
2019-06-28 16:15:01 +00:00
|
|
|
.domainGetPerfEvents = testDomainGetPerfEvents, /* 5.6.0 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainGetSchedulerType = testDomainGetSchedulerType, /* 0.3.2 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.domainGetSchedulerParameters = testDomainGetSchedulerParameters, /* 0.3.2 */
|
|
|
|
.domainGetSchedulerParametersFlags = testDomainGetSchedulerParametersFlags, /* 0.9.2 */
|
|
|
|
.domainSetSchedulerParameters = testDomainSetSchedulerParameters, /* 0.3.2 */
|
|
|
|
.domainSetSchedulerParametersFlags = testDomainSetSchedulerParametersFlags, /* 0.9.2 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainBlockStats = testDomainBlockStats, /* 0.7.0 */
|
2019-05-23 12:50:00 +00:00
|
|
|
.domainInterfaceAddresses = testDomainInterfaceAddresses, /* 5.4.0 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainInterfaceStats = testDomainInterfaceStats, /* 0.7.0 */
|
|
|
|
.nodeGetCellsFreeMemory = testNodeGetCellsFreeMemory, /* 0.4.2 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectDomainEventRegister = testConnectDomainEventRegister, /* 0.6.0 */
|
|
|
|
.connectDomainEventDeregister = testConnectDomainEventDeregister, /* 0.6.0 */
|
|
|
|
.connectIsEncrypted = testConnectIsEncrypted, /* 0.7.3 */
|
|
|
|
.connectIsSecure = testConnectIsSecure, /* 0.7.3 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainIsActive = testDomainIsActive, /* 0.7.3 */
|
|
|
|
.domainIsPersistent = testDomainIsPersistent, /* 0.7.3 */
|
|
|
|
.domainIsUpdated = testDomainIsUpdated, /* 0.8.6 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectDomainEventRegisterAny = testConnectDomainEventRegisterAny, /* 0.8.0 */
|
|
|
|
.connectDomainEventDeregisterAny = testConnectDomainEventDeregisterAny, /* 0.8.0 */
|
|
|
|
.connectIsAlive = testConnectIsAlive, /* 0.9.8 */
|
2012-10-16 14:05:15 +00:00
|
|
|
.nodeGetCPUMap = testNodeGetCPUMap, /* 1.0.0 */
|
2018-01-15 19:18:08 +00:00
|
|
|
.domainRename = testDomainRename, /* 4.1.0 */
|
2013-03-29 21:25:13 +00:00
|
|
|
.domainScreenshot = testDomainScreenshot, /* 1.0.5 */
|
2019-06-01 12:46:56 +00:00
|
|
|
.domainSendKey = testDomainSendKey, /* 5.5.0 */
|
2013-09-09 16:02:59 +00:00
|
|
|
.domainGetMetadata = testDomainGetMetadata, /* 1.1.3 */
|
|
|
|
.domainSetMetadata = testDomainSetMetadata, /* 1.1.3 */
|
2019-06-04 13:17:43 +00:00
|
|
|
.domainSendProcessSignal = testDomainSendProcessSignal, /* 5.5.0 */
|
2013-09-23 09:46:02 +00:00
|
|
|
.connectGetCPUModelNames = testConnectGetCPUModelNames, /* 1.1.3 */
|
2013-08-06 15:20:37 +00:00
|
|
|
.domainManagedSave = testDomainManagedSave, /* 1.1.4 */
|
|
|
|
.domainHasManagedSaveImage = testDomainHasManagedSaveImage, /* 1.1.4 */
|
|
|
|
.domainManagedSaveRemove = testDomainManagedSaveRemove, /* 1.1.4 */
|
2019-05-23 11:37:01 +00:00
|
|
|
.domainMemoryPeek = testDomainMemoryPeek, /* 5.4.0 */
|
2013-08-06 15:20:37 +00:00
|
|
|
|
|
|
|
.domainSnapshotNum = testDomainSnapshotNum, /* 1.1.4 */
|
|
|
|
.domainSnapshotListNames = testDomainSnapshotListNames, /* 1.1.4 */
|
|
|
|
.domainListAllSnapshots = testDomainListAllSnapshots, /* 1.1.4 */
|
|
|
|
.domainSnapshotGetXMLDesc = testDomainSnapshotGetXMLDesc, /* 1.1.4 */
|
|
|
|
.domainSnapshotNumChildren = testDomainSnapshotNumChildren, /* 1.1.4 */
|
|
|
|
.domainSnapshotListChildrenNames = testDomainSnapshotListChildrenNames, /* 1.1.4 */
|
|
|
|
.domainSnapshotListAllChildren = testDomainSnapshotListAllChildren, /* 1.1.4 */
|
|
|
|
.domainSnapshotLookupByName = testDomainSnapshotLookupByName, /* 1.1.4 */
|
|
|
|
.domainHasCurrentSnapshot = testDomainHasCurrentSnapshot, /* 1.1.4 */
|
|
|
|
.domainSnapshotGetParent = testDomainSnapshotGetParent, /* 1.1.4 */
|
|
|
|
.domainSnapshotCurrent = testDomainSnapshotCurrent, /* 1.1.4 */
|
|
|
|
.domainSnapshotIsCurrent = testDomainSnapshotIsCurrent, /* 1.1.4 */
|
|
|
|
.domainSnapshotHasMetadata = testDomainSnapshotHasMetadata, /* 1.1.4 */
|
2013-08-07 17:40:46 +00:00
|
|
|
.domainSnapshotCreateXML = testDomainSnapshotCreateXML, /* 1.1.4 */
|
|
|
|
.domainRevertToSnapshot = testDomainRevertToSnapshot, /* 1.1.4 */
|
|
|
|
.domainSnapshotDelete = testDomainSnapshotDelete, /* 1.1.4 */
|
2013-11-06 18:27:30 +00:00
|
|
|
|
2013-11-25 14:31:08 +00:00
|
|
|
.connectBaselineCPU = testConnectBaselineCPU, /* 1.2.0 */
|
2007-07-27 23:23:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static virNetworkDriver testNetworkDriver = {
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectNumOfNetworks = testConnectNumOfNetworks, /* 0.3.2 */
|
|
|
|
.connectListNetworks = testConnectListNetworks, /* 0.3.2 */
|
|
|
|
.connectNumOfDefinedNetworks = testConnectNumOfDefinedNetworks, /* 0.3.2 */
|
|
|
|
.connectListDefinedNetworks = testConnectListDefinedNetworks, /* 0.3.2 */
|
|
|
|
.connectListAllNetworks = testConnectListAllNetworks, /* 0.10.2 */
|
2013-12-11 10:37:59 +00:00
|
|
|
.connectNetworkEventRegisterAny = testConnectNetworkEventRegisterAny, /* 1.2.1 */
|
|
|
|
.connectNetworkEventDeregisterAny = testConnectNetworkEventDeregisterAny, /* 1.2.1 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.networkLookupByUUID = testNetworkLookupByUUID, /* 0.3.2 */
|
|
|
|
.networkLookupByName = testNetworkLookupByName, /* 0.3.2 */
|
|
|
|
.networkCreateXML = testNetworkCreateXML, /* 0.3.2 */
|
|
|
|
.networkDefineXML = testNetworkDefineXML, /* 0.3.2 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.networkUndefine = testNetworkUndefine, /* 0.3.2 */
|
2012-08-20 05:01:53 +00:00
|
|
|
.networkUpdate = testNetworkUpdate, /* 0.10.2 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.networkCreate = testNetworkCreate, /* 0.3.2 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.networkDestroy = testNetworkDestroy, /* 0.3.2 */
|
|
|
|
.networkGetXMLDesc = testNetworkGetXMLDesc, /* 0.3.2 */
|
|
|
|
.networkGetBridgeName = testNetworkGetBridgeName, /* 0.3.2 */
|
|
|
|
.networkGetAutostart = testNetworkGetAutostart, /* 0.3.2 */
|
|
|
|
.networkSetAutostart = testNetworkSetAutostart, /* 0.3.2 */
|
|
|
|
.networkIsActive = testNetworkIsActive, /* 0.7.3 */
|
|
|
|
.networkIsPersistent = testNetworkIsPersistent, /* 0.7.3 */
|
2007-07-27 23:23:00 +00:00
|
|
|
};
|
|
|
|
|
2009-07-21 13:45:55 +00:00
|
|
|
static virInterfaceDriver testInterfaceDriver = {
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectNumOfInterfaces = testConnectNumOfInterfaces, /* 0.7.0 */
|
|
|
|
.connectListInterfaces = testConnectListInterfaces, /* 0.7.0 */
|
|
|
|
.connectNumOfDefinedInterfaces = testConnectNumOfDefinedInterfaces, /* 0.7.0 */
|
|
|
|
.connectListDefinedInterfaces = testConnectListDefinedInterfaces, /* 0.7.0 */
|
2018-07-10 19:01:45 +00:00
|
|
|
.connectListAllInterfaces = testConnectListAllInterfaces, /* 4.6.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.interfaceLookupByName = testInterfaceLookupByName, /* 0.7.0 */
|
|
|
|
.interfaceLookupByMACString = testInterfaceLookupByMACString, /* 0.7.0 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.interfaceGetXMLDesc = testInterfaceGetXMLDesc, /* 0.7.0 */
|
|
|
|
.interfaceDefineXML = testInterfaceDefineXML, /* 0.7.0 */
|
|
|
|
.interfaceUndefine = testInterfaceUndefine, /* 0.7.0 */
|
|
|
|
.interfaceCreate = testInterfaceCreate, /* 0.7.0 */
|
|
|
|
.interfaceDestroy = testInterfaceDestroy, /* 0.7.0 */
|
|
|
|
.interfaceIsActive = testInterfaceIsActive, /* 0.7.3 */
|
2011-05-09 19:17:26 +00:00
|
|
|
.interfaceChangeBegin = testInterfaceChangeBegin, /* 0.9.2 */
|
|
|
|
.interfaceChangeCommit = testInterfaceChangeCommit, /* 0.9.2 */
|
|
|
|
.interfaceChangeRollback = testInterfaceChangeRollback, /* 0.9.2 */
|
2009-07-21 13:45:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-02-20 15:53:34 +00:00
|
|
|
static virStorageDriver testStorageDriver = {
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectNumOfStoragePools = testConnectNumOfStoragePools, /* 0.5.0 */
|
|
|
|
.connectListStoragePools = testConnectListStoragePools, /* 0.5.0 */
|
|
|
|
.connectNumOfDefinedStoragePools = testConnectNumOfDefinedStoragePools, /* 0.5.0 */
|
|
|
|
.connectListDefinedStoragePools = testConnectListDefinedStoragePools, /* 0.5.0 */
|
|
|
|
.connectListAllStoragePools = testConnectListAllStoragePools, /* 0.10.2 */
|
|
|
|
.connectFindStoragePoolSources = testConnectFindStoragePoolSources, /* 0.5.0 */
|
2016-06-15 18:15:39 +00:00
|
|
|
.connectStoragePoolEventRegisterAny = testConnectStoragePoolEventRegisterAny, /* 2.0.0 */
|
|
|
|
.connectStoragePoolEventDeregisterAny = testConnectStoragePoolEventDeregisterAny, /* 2.0.0 */
|
2013-04-22 17:26:01 +00:00
|
|
|
.storagePoolLookupByName = testStoragePoolLookupByName, /* 0.5.0 */
|
|
|
|
.storagePoolLookupByUUID = testStoragePoolLookupByUUID, /* 0.5.0 */
|
|
|
|
.storagePoolLookupByVolume = testStoragePoolLookupByVolume, /* 0.5.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.storagePoolCreateXML = testStoragePoolCreateXML, /* 0.5.0 */
|
|
|
|
.storagePoolDefineXML = testStoragePoolDefineXML, /* 0.5.0 */
|
2013-04-22 17:26:01 +00:00
|
|
|
.storagePoolBuild = testStoragePoolBuild, /* 0.5.0 */
|
|
|
|
.storagePoolUndefine = testStoragePoolUndefine, /* 0.5.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.storagePoolCreate = testStoragePoolCreate, /* 0.5.0 */
|
2013-04-22 17:26:01 +00:00
|
|
|
.storagePoolDestroy = testStoragePoolDestroy, /* 0.5.0 */
|
|
|
|
.storagePoolDelete = testStoragePoolDelete, /* 0.5.0 */
|
|
|
|
.storagePoolRefresh = testStoragePoolRefresh, /* 0.5.0 */
|
|
|
|
.storagePoolGetInfo = testStoragePoolGetInfo, /* 0.5.0 */
|
|
|
|
.storagePoolGetXMLDesc = testStoragePoolGetXMLDesc, /* 0.5.0 */
|
|
|
|
.storagePoolGetAutostart = testStoragePoolGetAutostart, /* 0.5.0 */
|
|
|
|
.storagePoolSetAutostart = testStoragePoolSetAutostart, /* 0.5.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.storagePoolNumOfVolumes = testStoragePoolNumOfVolumes, /* 0.5.0 */
|
2013-04-22 17:26:01 +00:00
|
|
|
.storagePoolListVolumes = testStoragePoolListVolumes, /* 0.5.0 */
|
|
|
|
.storagePoolListAllVolumes = testStoragePoolListAllVolumes, /* 0.10.2 */
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
.storageVolLookupByName = testStorageVolLookupByName, /* 0.5.0 */
|
|
|
|
.storageVolLookupByKey = testStorageVolLookupByKey, /* 0.5.0 */
|
|
|
|
.storageVolLookupByPath = testStorageVolLookupByPath, /* 0.5.0 */
|
|
|
|
.storageVolCreateXML = testStorageVolCreateXML, /* 0.5.0 */
|
|
|
|
.storageVolCreateXMLFrom = testStorageVolCreateXMLFrom, /* 0.6.4 */
|
|
|
|
.storageVolDelete = testStorageVolDelete, /* 0.5.0 */
|
|
|
|
.storageVolGetInfo = testStorageVolGetInfo, /* 0.5.0 */
|
|
|
|
.storageVolGetXMLDesc = testStorageVolGetXMLDesc, /* 0.5.0 */
|
|
|
|
.storageVolGetPath = testStorageVolGetPath, /* 0.5.0 */
|
2013-04-22 17:26:01 +00:00
|
|
|
.storagePoolIsActive = testStoragePoolIsActive, /* 0.7.3 */
|
|
|
|
.storagePoolIsPersistent = testStoragePoolIsPersistent, /* 0.7.3 */
|
2008-02-20 15:53:34 +00:00
|
|
|
};
|
|
|
|
|
2013-04-23 10:15:48 +00:00
|
|
|
static virNodeDeviceDriver testNodeDeviceDriver = {
|
2018-02-23 20:08:46 +00:00
|
|
|
.connectListAllNodeDevices = testConnectListAllNodeDevices, /* 4.1.0 */
|
2016-07-28 12:02:52 +00:00
|
|
|
.connectNodeDeviceEventRegisterAny = testConnectNodeDeviceEventRegisterAny, /* 2.2.0 */
|
|
|
|
.connectNodeDeviceEventDeregisterAny = testConnectNodeDeviceEventDeregisterAny, /* 2.2.0 */
|
2013-04-22 17:26:01 +00:00
|
|
|
.nodeNumOfDevices = testNodeNumOfDevices, /* 0.7.2 */
|
|
|
|
.nodeListDevices = testNodeListDevices, /* 0.7.2 */
|
|
|
|
.nodeDeviceLookupByName = testNodeDeviceLookupByName, /* 0.7.2 */
|
|
|
|
.nodeDeviceGetXMLDesc = testNodeDeviceGetXMLDesc, /* 0.7.2 */
|
|
|
|
.nodeDeviceGetParent = testNodeDeviceGetParent, /* 0.7.2 */
|
|
|
|
.nodeDeviceNumOfCaps = testNodeDeviceNumOfCaps, /* 0.7.2 */
|
|
|
|
.nodeDeviceListCaps = testNodeDeviceListCaps, /* 0.7.2 */
|
|
|
|
.nodeDeviceCreateXML = testNodeDeviceCreateXML, /* 0.7.3 */
|
|
|
|
.nodeDeviceDestroy = testNodeDeviceDestroy, /* 0.7.3 */
|
2008-12-04 21:00:50 +00:00
|
|
|
};
|
|
|
|
|
2015-01-20 16:16:26 +00:00
|
|
|
static virConnectDriver testConnectDriver = {
|
2018-03-28 09:53:31 +00:00
|
|
|
.localOnly = true,
|
2018-03-27 14:51:45 +00:00
|
|
|
.uriSchemes = (const char *[]){ "test", NULL },
|
2015-01-20 16:16:26 +00:00
|
|
|
.hypervisorDriver = &testHypervisorDriver,
|
|
|
|
.interfaceDriver = &testInterfaceDriver,
|
|
|
|
.networkDriver = &testNetworkDriver,
|
|
|
|
.nodeDeviceDriver = &testNodeDeviceDriver,
|
|
|
|
.nwfilterDriver = NULL,
|
|
|
|
.secretDriver = NULL,
|
|
|
|
.storageDriver = &testStorageDriver,
|
2010-03-29 21:09:20 +00:00
|
|
|
};
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
/**
|
|
|
|
* testRegister:
|
|
|
|
*
|
|
|
|
* Registers the test driver
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
testRegister(void)
|
|
|
|
{
|
2015-01-20 16:16:26 +00:00
|
|
|
return virRegisterConnectDriver(&testConnectDriver,
|
|
|
|
false);
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|