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
|
|
|
*
|
2015-05-08 16:55:00 +00:00
|
|
|
* Copyright (C) 2006-2015 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
|
|
|
*
|
|
|
|
* Daniel Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
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 <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#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"
|
2008-07-11 16:39:08 +00:00
|
|
|
#include "network_conf.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"
|
2013-03-29 21:25:13 +00:00
|
|
|
#include "fdstream.h"
|
2008-10-30 17:40:57 +00:00
|
|
|
#include "storage_conf.h"
|
2009-10-01 18:54:36 +00:00
|
|
|
#include "node_device_conf.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"
|
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
|
|
|
/* Driver specific info to carry with a domain */
|
|
|
|
struct _testDomainObjPrivate {
|
|
|
|
virVcpuInfoPtr vcpu_infos;
|
|
|
|
|
|
|
|
unsigned char *cpumaps;
|
|
|
|
};
|
|
|
|
typedef struct _testDomainObjPrivate testDomainObjPrivate;
|
|
|
|
typedef struct _testDomainObjPrivate *testDomainObjPrivatePtr;
|
|
|
|
|
2008-04-04 07:31:24 +00:00
|
|
|
#define MAX_CPUS 128
|
|
|
|
|
|
|
|
struct _testCell {
|
|
|
|
unsigned long mem;
|
|
|
|
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;
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
struct _testConn {
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutex lock;
|
2008-12-04 20:59:06 +00:00
|
|
|
|
2011-06-22 20:03:30 +00:00
|
|
|
char *path;
|
2007-07-27 23:23:00 +00:00
|
|
|
int nextDomID;
|
2008-07-11 16:41:27 +00:00
|
|
|
virCapsPtr caps;
|
2013-03-31 18:03:42 +00:00
|
|
|
virDomainXMLOptionPtr xmlopt;
|
2007-01-18 21:08:21 +00:00
|
|
|
virNodeInfo nodeInfo;
|
2013-01-11 16:04:47 +00:00
|
|
|
virDomainObjListPtr domains;
|
2015-02-23 14:54:54 +00:00
|
|
|
virNetworkObjListPtr networks;
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceObjList ifaces;
|
2011-05-09 19:17:26 +00:00
|
|
|
bool transaction_running;
|
|
|
|
virInterfaceObjList backupIfaces;
|
2008-10-30 17:40:57 +00:00
|
|
|
virStoragePoolObjList pools;
|
2009-10-01 18:54:36 +00:00
|
|
|
virNodeDeviceObjList 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
|
|
|
|
2014-01-04 13:14:33 +00:00
|
|
|
virObjectEventStatePtr eventState;
|
2007-07-27 23:23:00 +00:00
|
|
|
};
|
|
|
|
typedef struct _testConn testConn;
|
2015-02-23 14:54:54 +00:00
|
|
|
typedef testConn *testConnPtr;
|
2006-06-06 03:32:51 +00:00
|
|
|
|
2014-01-01 16:30:12 +00:00
|
|
|
static testConn defaultConn;
|
|
|
|
static int defaultConnections;
|
2014-03-25 14:54:44 +00:00
|
|
|
static virMutex defaultLock = VIR_MUTEX_INITIALIZER;
|
2014-01-01 16:30:12 +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
|
|
|
};
|
|
|
|
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectClose(virConnectPtr conn);
|
2013-11-25 13:16:02 +00:00
|
|
|
static void testObjectEventQueue(testConnPtr driver,
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event);
|
2009-01-20 20:23:53 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
static void testDriverLock(testConnPtr driver)
|
|
|
|
{
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&driver->lock);
|
2008-12-04 20:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void testDriverUnlock(testConnPtr driver)
|
|
|
|
{
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&driver->lock);
|
2008-12-04 20:59:06 +00:00
|
|
|
}
|
|
|
|
|
2009-10-27 18:06:30 +00:00
|
|
|
static void *testDomainObjPrivateAlloc(void)
|
|
|
|
{
|
|
|
|
testDomainObjPrivatePtr priv;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(priv) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return priv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testDomainObjPrivateFree(void *data)
|
|
|
|
{
|
|
|
|
testDomainObjPrivatePtr priv = data;
|
|
|
|
|
2009-11-24 11:44:49 +00:00
|
|
|
VIR_FREE(priv->vcpu_infos);
|
2009-10-27 18:06:30 +00:00
|
|
|
VIR_FREE(priv->cpumaps);
|
|
|
|
VIR_FREE(priv);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
int tmp, n;
|
|
|
|
size_t i;
|
2013-08-06 21:42:16 +00:00
|
|
|
unsigned int tmpuint;
|
|
|
|
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
VIR_FREE(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-07 14:57:55 +00:00
|
|
|
VIR_FREE(nodes);
|
2013-08-06 21:42:16 +00:00
|
|
|
testDomainDefNamespaceFree(nsdata);
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-27 18:06:30 +00:00
|
|
|
|
2013-03-31 18:03:42 +00:00
|
|
|
static virDomainXMLOptionPtr
|
2013-03-05 15:17:24 +00:00
|
|
|
testBuildXMLConfig(void)
|
|
|
|
{
|
2013-08-06 21:42:16 +00:00
|
|
|
virDomainXMLPrivateDataCallbacks priv = {
|
|
|
|
.alloc = testDomainObjPrivateAlloc,
|
|
|
|
.free = testDomainObjPrivateFree
|
|
|
|
};
|
|
|
|
|
|
|
|
/* All our XML extensions are input only, so we only need to parse */
|
|
|
|
virDomainXMLNamespace ns = {
|
|
|
|
.parse = testDomainDefNamespaceParse,
|
|
|
|
.free = testDomainDefNamespaceFree,
|
|
|
|
};
|
|
|
|
|
|
|
|
return virDomainXMLOptionNew(NULL, &priv, &ns);
|
2013-03-05 15:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
static virCapsPtr
|
2014-03-18 08:17:30 +00:00
|
|
|
testBuildCapabilities(virConnectPtr conn)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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 };
|
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;
|
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
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(cpu_cells, privconn->cells[i].numCpus) < 0)
|
2013-07-04 10:16:47 +00:00
|
|
|
goto error;
|
2013-01-22 17:42:08 +00:00
|
|
|
|
|
|
|
memcpy(cpu_cells, privconn->cells[i].cpus,
|
|
|
|
sizeof(*cpu_cells) * privconn->cells[i].numCpus);
|
|
|
|
|
|
|
|
|
2014-06-03 13:18:27 +00:00
|
|
|
if (virCapabilitiesAddHostNUMACell(caps, i, 0,
|
|
|
|
privconn->cells[i].numCpus,
|
2014-06-06 16:12:51 +00:00
|
|
|
cpu_cells, 0, NULL, 0, NULL) < 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
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
static const char *defaultDomainXML =
|
|
|
|
"<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>"
|
|
|
|
"</domain>";
|
2007-07-27 23:23:00 +00:00
|
|
|
|
|
|
|
|
2008-07-11 16:39:08 +00:00
|
|
|
static const char *defaultNetworkXML =
|
|
|
|
"<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>"
|
|
|
|
"</network>";
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2009-07-21 13:45:55 +00:00
|
|
|
static const char *defaultInterfaceXML =
|
|
|
|
"<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>"
|
|
|
|
"</interface>";
|
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static const char *defaultPoolXML =
|
|
|
|
"<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>"
|
|
|
|
"</pool>";
|
|
|
|
|
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";
|
|
|
|
|
2009-10-01 18:54:36 +00:00
|
|
|
static const char *defaultNodeXML =
|
|
|
|
"<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>";
|
|
|
|
|
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
|
|
|
|
2010-02-04 18:19:08 +00:00
|
|
|
static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool);
|
2009-10-27 18:06:30 +00:00
|
|
|
static int testNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2013-08-06 15:20:37 +00:00
|
|
|
static virDomainObjPtr
|
|
|
|
testDomObjFromDomain(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
testConnPtr driver = domain->conn->privateData;
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
|
|
|
testDriverLock(driver);
|
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, domain->uuid);
|
|
|
|
if (!vm) {
|
|
|
|
virUUIDFormat(domain->uuid, uuidstr);
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("no domain with matching uuid '%s' (%s)"),
|
|
|
|
uuidstr, domain->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
testDriverUnlock(driver);
|
|
|
|
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;
|
|
|
|
size_t i;
|
2009-07-24 15:05:29 +00:00
|
|
|
|
|
|
|
for (ifctr = 0; ifctr < maxif; ++ifctr) {
|
|
|
|
char *ifname;
|
|
|
|
int found = 0;
|
|
|
|
|
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 */
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < domdef->nnets; i++) {
|
2009-07-24 15:05:29 +00:00
|
|
|
if (domdef->nets[i]->ifname &&
|
2012-10-17 09:23:12 +00:00
|
|
|
STREQ(domdef->nets[i]->ifname, ifname)) {
|
2009-07-24 15:05:29 +00:00
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
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
|
|
|
/* Helper to update info for a single VCPU */
|
|
|
|
static int
|
2013-08-06 18:59:45 +00:00
|
|
|
testDomainUpdateVCPU(virDomainObjPtr dom,
|
2009-10-27 18:06:30 +00:00
|
|
|
int vcpu,
|
|
|
|
int maplen,
|
|
|
|
int maxcpu)
|
|
|
|
{
|
|
|
|
testDomainObjPrivatePtr privdata = dom->privateData;
|
|
|
|
virVcpuInfoPtr info = &privdata->vcpu_infos[vcpu];
|
|
|
|
unsigned char *cpumap = VIR_GET_CPUMAP(privdata->cpumaps, maplen, vcpu);
|
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 j;
|
2012-09-14 07:47:01 +00:00
|
|
|
bool cpu;
|
2009-10-27 18:06:30 +00:00
|
|
|
|
|
|
|
memset(info, 0, sizeof(virVcpuInfo));
|
|
|
|
memset(cpumap, 0, maplen);
|
|
|
|
|
|
|
|
info->number = vcpu;
|
|
|
|
info->state = VIR_VCPU_RUNNING;
|
|
|
|
info->cpuTime = 5000000;
|
|
|
|
info->cpu = 0;
|
|
|
|
|
|
|
|
if (dom->def->cpumask) {
|
|
|
|
for (j = 0; j < maxcpu && j < VIR_DOMAIN_CPUMASK_LEN; ++j) {
|
2012-09-14 07:47:01 +00:00
|
|
|
if (virBitmapGetBit(dom->def->cpumask, j, &cpu) < 0)
|
|
|
|
return -1;
|
|
|
|
if (cpu) {
|
2009-10-27 18:06:30 +00:00
|
|
|
VIR_USE_CPU(cpumap, j);
|
|
|
|
info->cpu = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (j = 0; j < maxcpu; ++j) {
|
|
|
|
if ((j % 3) == 0) {
|
|
|
|
/* Mark of every third CPU as usable */
|
|
|
|
VIR_USE_CPU(cpumap, j);
|
|
|
|
info->cpu = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update domain VCPU amount and info
|
|
|
|
*
|
|
|
|
* @conn: virConnectPtr
|
|
|
|
* @dom : domain needing updates
|
|
|
|
* @nvcpus: New amount of vcpus for the domain
|
|
|
|
* @clear_all: If true, rebuild info for ALL vcpus, not just newly added vcpus
|
|
|
|
*/
|
|
|
|
static int
|
2013-08-06 18:59:45 +00:00
|
|
|
testDomainUpdateVCPUs(testConnPtr privconn,
|
2009-10-27 18:06:30 +00:00
|
|
|
virDomainObjPtr dom,
|
|
|
|
int nvcpus,
|
|
|
|
unsigned int clear_all)
|
|
|
|
{
|
|
|
|
testDomainObjPrivatePtr privdata = dom->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
|
|
|
size_t i;
|
|
|
|
int ret = -1;
|
2009-10-27 18:06:30 +00:00
|
|
|
int cpumaplen, maxcpu;
|
|
|
|
|
|
|
|
maxcpu = VIR_NODEINFO_MAXCPUS(privconn->nodeInfo);
|
|
|
|
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
|
|
|
|
|
2013-07-04 10:16:47 +00:00
|
|
|
if (VIR_REALLOC_N(privdata->vcpu_infos, nvcpus) < 0)
|
2009-10-27 18:06:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-04 10:16:47 +00:00
|
|
|
if (VIR_REALLOC_N(privdata->cpumaps, nvcpus * cpumaplen) < 0)
|
2009-10-27 18:06:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Set running VCPU and cpumap state */
|
|
|
|
if (clear_all) {
|
|
|
|
for (i = 0; i < nvcpus; ++i)
|
2013-08-06 18:59:45 +00:00
|
|
|
if (testDomainUpdateVCPU(dom, i, cpumaplen, maxcpu) < 0)
|
2009-10-27 18:06:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
} else if (nvcpus > dom->def->vcpus) {
|
|
|
|
/* VCPU amount has grown, populate info for the new vcpus */
|
|
|
|
for (i = dom->def->vcpus; i < nvcpus; ++i)
|
2013-08-06 18:59:45 +00:00
|
|
|
if (testDomainUpdateVCPU(dom, i, cpumaplen, maxcpu) < 0)
|
2009-10-27 18:06:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-10-04 23:01:12 +00:00
|
|
|
dom->def->vcpus = nvcpus;
|
2009-10-27 18:06:30 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-10-27 18:06:30 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (privdom->newDef) {
|
|
|
|
virDomainDefFree(privdom->def);
|
|
|
|
privdom->def = privdom->newDef;
|
|
|
|
privdom->newDef = NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(privdom, VIR_DOMAIN_SHUTOFF, reason);
|
2010-11-19 18:36:29 +00:00
|
|
|
privdom->def->id = -1;
|
|
|
|
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
|
2013-08-06 18:59:45 +00:00
|
|
|
testDomainStartState(testConnPtr 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
|
|
|
|
2013-08-06 18:59:45 +00:00
|
|
|
if (testDomainUpdateVCPUs(privconn, dom, dom->def->vcpus, 1) < 0)
|
2009-10-27 18:06:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(dom, VIR_DOMAIN_RUNNING, reason);
|
2009-10-27 17:15:44 +00:00
|
|
|
dom->def->id = privconn->nextDomID++;
|
|
|
|
|
2013-03-05 15:17:24 +00:00
|
|
|
if (virDomainObjSetDefTransient(privconn->caps,
|
2013-03-31 18:03:42 +00:00
|
|
|
privconn->xmlopt,
|
2013-03-05 15:17:24 +00:00
|
|
|
dom, false) < 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
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
2007-01-18 21:08:21 +00:00
|
|
|
int u;
|
2014-01-01 16:30:12 +00:00
|
|
|
testConnPtr privconn = &defaultConn;
|
2008-07-11 16:41:27 +00:00
|
|
|
virDomainDefPtr domdef = NULL;
|
|
|
|
virDomainObjPtr domobj = NULL;
|
|
|
|
virNetworkDefPtr netdef = NULL;
|
|
|
|
virNetworkObjPtr netobj = NULL;
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceDefPtr interfacedef = NULL;
|
|
|
|
virInterfaceObjPtr interfaceobj = NULL;
|
2008-10-30 17:40:57 +00:00
|
|
|
virStoragePoolDefPtr pooldef = NULL;
|
|
|
|
virStoragePoolObjPtr poolobj = NULL;
|
2009-10-01 18:54:36 +00:00
|
|
|
virNodeDeviceDefPtr nodedef = NULL;
|
|
|
|
virNodeDeviceObjPtr nodeobj = NULL;
|
2008-07-11 16:39:08 +00:00
|
|
|
|
2014-01-01 16:30:12 +00:00
|
|
|
virMutexLock(&defaultLock);
|
|
|
|
if (defaultConnections++) {
|
|
|
|
conn->privateData = &defaultConn;
|
|
|
|
virMutexUnlock(&defaultLock);
|
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
if (virMutexInit(&privconn->lock) < 0) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("cannot initialize mutex"));
|
2014-01-01 16:30:12 +00:00
|
|
|
defaultConnections--;
|
|
|
|
virMutexUnlock(&defaultLock);
|
2009-01-15 19:56:05 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
conn->privateData = privconn;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2014-01-04 13:14:33 +00:00
|
|
|
if (!(privconn->eventState = virObjectEventStateNew()))
|
2014-01-01 16:30:12 +00:00
|
|
|
goto error;
|
|
|
|
|
2015-02-23 14:54:54 +00:00
|
|
|
if (!(privconn->domains = virDomainObjListNew()) ||
|
2015-02-24 12:45:45 +00:00
|
|
|
!(privconn->networks = virNetworkObjListNew()))
|
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
|
|
|
goto error;
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2011-01-28 21:38:06 +00:00
|
|
|
/* Numa setup */
|
2008-04-04 07:31:24 +00:00
|
|
|
privconn->numCells = 2;
|
|
|
|
for (u = 0; u < 2; ++u) {
|
|
|
|
privconn->cells[u].numCpus = 8;
|
|
|
|
privconn->cells[u].mem = (u + 1) * 2048 * 1024;
|
|
|
|
}
|
2013-05-21 07:21:18 +00:00
|
|
|
for (u = 0; u < 16; u++) {
|
2013-01-22 21:18:19 +00:00
|
|
|
virBitmapPtr siblings = virBitmapNew(16);
|
2013-07-04 10:16:47 +00:00
|
|
|
if (!siblings)
|
2013-01-22 21:18:19 +00:00
|
|
|
goto error;
|
|
|
|
ignore_value(virBitmapSetBit(siblings, u));
|
|
|
|
privconn->cells[u / 8].cpus[(u % 8)].id = u;
|
|
|
|
privconn->cells[u / 8].cpus[(u % 8)].socket_id = u / 8;
|
|
|
|
privconn->cells[u / 8].cpus[(u % 8)].core_id = u % 8;
|
|
|
|
privconn->cells[u / 8].cpus[(u % 8)].siblings = siblings;
|
2008-04-04 07:31:24 +00:00
|
|
|
}
|
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
if (!(privconn->caps = testBuildCapabilities(conn)))
|
|
|
|
goto error;
|
|
|
|
|
2013-03-31 18:03:42 +00:00
|
|
|
if (!(privconn->xmlopt = testBuildXMLConfig()))
|
2013-03-05 15:17:24 +00:00
|
|
|
goto error;
|
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
privconn->nextDomID = 1;
|
|
|
|
|
2013-03-28 13:55:55 +00:00
|
|
|
if (!(domdef = virDomainDefParseString(defaultDomainXML,
|
|
|
|
privconn->caps,
|
2013-03-31 18:03:42 +00:00
|
|
|
privconn->xmlopt,
|
2014-11-18 16:44:00 +00:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
|
2008-07-11 16:41:27 +00:00
|
|
|
goto error;
|
2011-07-11 17:29:09 +00:00
|
|
|
|
2010-04-02 21:56:10 +00:00
|
|
|
if (testDomainGenerateIfnames(domdef) < 0)
|
2008-07-11 16:41:27 +00:00
|
|
|
goto error;
|
2013-01-11 16:04:47 +00:00
|
|
|
if (!(domobj = virDomainObjListAdd(privconn->domains,
|
2013-03-28 13:55:55 +00:00
|
|
|
domdef,
|
2013-03-31 18:03:42 +00:00
|
|
|
privconn->xmlopt,
|
2013-03-28 13:55:55 +00:00
|
|
|
0, NULL)))
|
2009-09-02 13:02:06 +00:00
|
|
|
goto error;
|
|
|
|
domdef = NULL;
|
2009-10-27 17:15:44 +00:00
|
|
|
|
2010-11-19 18:36:29 +00:00
|
|
|
domobj->persistent = 1;
|
2013-08-06 18:59:45 +00:00
|
|
|
if (testDomainStartState(privconn, domobj,
|
|
|
|
VIR_DOMAIN_RUNNING_BOOTED) < 0) {
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(domobj);
|
2009-10-27 17:15:44 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(domobj);
|
2008-07-11 16:41:27 +00:00
|
|
|
|
2010-02-10 10:22:52 +00:00
|
|
|
if (!(netdef = virNetworkDefParseString(defaultNetworkXML)))
|
2008-07-11 16:41:27 +00:00
|
|
|
goto error;
|
network_conf: Drop virNetworkObjIsDuplicate
This function does not make any sense now, that network driver is
(almost) dropped. I mean, previously, when threads were
serialized, this function was there to check, if no other network
with the same name or UUID exists. However, nowadays that threads
can run more in parallel, this function is useless, in fact it
gives misleading return values. Consider the following scenario.
Two threads, both trying to define networks with same name but
different UUID (e.g. because it was generated during XML parsing
phase, whatever). Lets assume that both threads are about to call
networkValidate() which immediately calls
virNetworkObjIsDuplicate().
T1: calls virNetworkObjIsDuplicate() and since no network with
given name or UUID exist, success is returned.
T2: calls virNetworkObjIsDuplicate() and since no network with
given name or UUID exist, success is returned.
T1: calls virNetworkAssignDef() and successfully places its
network into the virNetworkObjList.
T2: calls virNetworkAssignDef() and since network with the same
name exists, the network definition is replaced.
Okay, this is mainly because virNetworkAssignDef() does not check
whether name and UUID matches. Well, lets make it so! And drop
useless function too.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-14 10:18:21 +00:00
|
|
|
if (!(netobj = virNetworkAssignDef(privconn->networks, netdef, 0))) {
|
2008-07-11 16:41:27 +00:00
|
|
|
virNetworkDefFree(netdef);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
netobj->active = 1;
|
2015-02-26 12:45:05 +00:00
|
|
|
virNetworkObjEndAPI(&netobj);
|
2008-07-11 16:41:27 +00:00
|
|
|
|
2010-02-10 12:28:05 +00:00
|
|
|
if (!(interfacedef = virInterfaceDefParseString(defaultInterfaceXML)))
|
2009-07-21 13:45:55 +00:00
|
|
|
goto error;
|
2010-02-10 12:28:05 +00:00
|
|
|
if (!(interfaceobj = virInterfaceAssignDef(&privconn->ifaces, interfacedef))) {
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceDefFree(interfacedef);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
interfaceobj->active = 1;
|
|
|
|
virInterfaceObjUnlock(interfaceobj);
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(pooldef = virStoragePoolDefParseString(defaultPoolXML)))
|
2008-10-30 17:40:57 +00:00
|
|
|
goto error;
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(poolobj = virStoragePoolObjAssignDef(&privconn->pools,
|
2008-10-30 17:40:57 +00:00
|
|
|
pooldef))) {
|
|
|
|
virStoragePoolDefFree(pooldef);
|
|
|
|
goto error;
|
|
|
|
}
|
2008-12-04 20:59:06 +00:00
|
|
|
|
2010-02-04 18:19:08 +00:00
|
|
|
if (testStoragePoolObjSetDefaults(poolobj) == -1) {
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjUnlock(poolobj);
|
2008-10-30 17:40:57 +00:00
|
|
|
goto error;
|
2008-12-04 20:59:06 +00:00
|
|
|
}
|
2008-10-30 17:40:57 +00:00
|
|
|
poolobj->active = 1;
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjUnlock(poolobj);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2009-10-01 18:54:36 +00:00
|
|
|
/* Init default node device */
|
2012-02-10 04:51:47 +00:00
|
|
|
if (!(nodedef = virNodeDeviceDefParseString(defaultNodeXML, 0, NULL)))
|
2009-10-01 18:54:36 +00:00
|
|
|
goto error;
|
2010-02-10 10:40:18 +00:00
|
|
|
if (!(nodeobj = virNodeDeviceAssignDef(&privconn->devs,
|
2009-10-01 18:54:36 +00:00
|
|
|
nodedef))) {
|
|
|
|
virNodeDeviceDefFree(nodedef);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
virNodeDeviceObjUnlock(nodeobj);
|
|
|
|
|
2014-01-01 16:30:12 +00:00
|
|
|
virMutexUnlock(&defaultLock);
|
2009-01-15 19:56:05 +00:00
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-01-11 13:54:15 +00:00
|
|
|
virObjectUnref(privconn->domains);
|
2015-02-24 12:45:45 +00:00
|
|
|
virObjectUnref(privconn->networks);
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceObjListFree(&privconn->ifaces);
|
2008-10-30 17:40:57 +00:00
|
|
|
virStoragePoolObjListFree(&privconn->pools);
|
2009-10-01 18:54:36 +00:00
|
|
|
virNodeDeviceObjListFree(&privconn->devs);
|
2013-02-01 12:26:18 +00:00
|
|
|
virObjectUnref(privconn->caps);
|
2014-01-04 13:14:33 +00:00
|
|
|
virObjectEventStateFree(privconn->eventState);
|
2014-01-01 16:30:12 +00:00
|
|
|
virMutexDestroy(&privconn->lock);
|
2009-01-15 19:56:05 +00:00
|
|
|
conn->privateData = NULL;
|
2009-09-02 13:02:06 +00:00
|
|
|
virDomainDefFree(domdef);
|
2014-01-01 16:30:12 +00:00
|
|
|
defaultConnections--;
|
|
|
|
virMutexUnlock(&defaultLock);
|
2008-07-11 16:41:27 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
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;
|
2009-08-03 12:37:44 +00:00
|
|
|
if (virStrncpy(absFile, relativeTo, baseLen, totalLen) == NULL) {
|
|
|
|
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;
|
|
|
|
char *relFile = virXMLPropString(node, "file");
|
|
|
|
|
|
|
|
if (relFile != NULL) {
|
|
|
|
absFile = testBuildFilename(file, relFile);
|
|
|
|
VIR_FREE(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);
|
|
|
|
VIR_FREE(absFile);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
static int
|
|
|
|
testParseNodeInfo(virNodeInfoPtr nodeInfo, xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2007-04-06 15:34:09 +00:00
|
|
|
char *str;
|
2013-08-06 18:45:02 +00:00
|
|
|
long l;
|
|
|
|
int ret;
|
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) {
|
2009-08-03 12:37:44 +00:00
|
|
|
if (virStrcpyStatic(nodeInfo->model, str) == NULL) {
|
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
|
|
|
VIR_FREE(str);
|
|
|
|
goto error;
|
|
|
|
}
|
2008-05-29 19:20:22 +00:00
|
|
|
VIR_FREE(str);
|
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
|
|
|
|
testParseDomainSnapshots(testConnPtr privconn,
|
|
|
|
virDomainObjPtr domobj,
|
|
|
|
const char *file,
|
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
int ret = -1;
|
|
|
|
testDomainNamespaceDefPtr nsdata = domobj->def->namespaceData;
|
|
|
|
xmlNodePtr *nodes = nsdata->snap_nodes;
|
|
|
|
|
|
|
|
for (i = 0; i < nsdata->num_snap_nodes; i++) {
|
|
|
|
virDomainSnapshotObjPtr snap;
|
|
|
|
virDomainSnapshotDefPtr def;
|
|
|
|
xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file,
|
|
|
|
"domainsnapshot");
|
|
|
|
if (!node)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
def = virDomainSnapshotDefParseNode(ctxt->doc, node,
|
|
|
|
privconn->caps,
|
|
|
|
privconn->xmlopt,
|
|
|
|
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))) {
|
|
|
|
virDomainSnapshotDefFree(def);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (def->current) {
|
|
|
|
if (domobj->current_snapshot) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("more than one snapshot claims to be active"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
domobj->current_snapshot = snap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2013-08-06 20:56:50 +00:00
|
|
|
testParseDomains(testConnPtr privconn,
|
|
|
|
const char *file,
|
|
|
|
xmlXPathContextPtr ctxt)
|
2013-08-06 18:45:02 +00:00
|
|
|
{
|
|
|
|
int num, ret = -1;
|
|
|
|
size_t i;
|
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
virDomainObjPtr obj;
|
|
|
|
|
|
|
|
num = virXPathNodeSet("/node/domain", ctxt, &nodes);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (num < 0)
|
2007-01-18 21:08:21 +00:00
|
|
|
goto error;
|
|
|
|
|
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,
|
|
|
|
privconn->caps, privconn->xmlopt,
|
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
|
|
|
|
2013-08-07 14:57:55 +00:00
|
|
|
if (testParseDomainSnapshots(privconn, obj, file, ctxt) < 0) {
|
|
|
|
virObjectUnlock(obj);
|
|
|
|
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,
|
|
|
|
VIR_DOMAIN_RUNNING_BOOTED) < 0) {
|
|
|
|
virObjectUnlock(obj);
|
|
|
|
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
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
virObjectUnlock(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:
|
2013-08-06 18:45:02 +00:00
|
|
|
VIR_FREE(nodes);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-08-06 20:56:50 +00:00
|
|
|
testParseNetworks(testConnPtr privconn,
|
|
|
|
const char *file,
|
|
|
|
xmlXPathContextPtr ctxt)
|
2013-08-06 18:45:02 +00:00
|
|
|
{
|
|
|
|
int num, ret = -1;
|
|
|
|
size_t i;
|
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
virNetworkObjPtr obj;
|
|
|
|
|
|
|
|
num = virXPathNodeSet("/node/network", ctxt, &nodes);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (num < 0)
|
2008-07-11 16:39:08 +00:00
|
|
|
goto error;
|
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)
|
|
|
|
goto error;
|
2008-07-11 16:39:08 +00:00
|
|
|
|
2013-08-06 20:56:50 +00:00
|
|
|
def = virNetworkDefParseNode(ctxt->doc, node);
|
|
|
|
if (!def)
|
|
|
|
goto error;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
network_conf: Drop virNetworkObjIsDuplicate
This function does not make any sense now, that network driver is
(almost) dropped. I mean, previously, when threads were
serialized, this function was there to check, if no other network
with the same name or UUID exists. However, nowadays that threads
can run more in parallel, this function is useless, in fact it
gives misleading return values. Consider the following scenario.
Two threads, both trying to define networks with same name but
different UUID (e.g. because it was generated during XML parsing
phase, whatever). Lets assume that both threads are about to call
networkValidate() which immediately calls
virNetworkObjIsDuplicate().
T1: calls virNetworkObjIsDuplicate() and since no network with
given name or UUID exist, success is returned.
T2: calls virNetworkObjIsDuplicate() and since no network with
given name or UUID exist, success is returned.
T1: calls virNetworkAssignDef() and successfully places its
network into the virNetworkObjList.
T2: calls virNetworkAssignDef() and since network with the same
name exists, the network definition is replaced.
Okay, this is mainly because virNetworkAssignDef() does not check
whether name and UUID matches. Well, lets make it so! And drop
useless function too.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-14 10:18:21 +00:00
|
|
|
if (!(obj = virNetworkAssignDef(privconn->networks, def, 0))) {
|
2008-07-11 16:39:08 +00:00
|
|
|
virNetworkDefFree(def);
|
|
|
|
goto error;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
obj->active = 1;
|
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
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-08-06 18:45:02 +00:00
|
|
|
VIR_FREE(nodes);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-08-06 20:56:50 +00:00
|
|
|
testParseInterfaces(testConnPtr privconn,
|
|
|
|
const char *file,
|
|
|
|
xmlXPathContextPtr ctxt)
|
2013-08-06 18:45:02 +00:00
|
|
|
{
|
|
|
|
int num, ret = -1;
|
|
|
|
size_t i;
|
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
virInterfaceObjPtr obj;
|
|
|
|
|
|
|
|
num = virXPathNodeSet("/node/interface", ctxt, &nodes);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (num < 0)
|
2009-07-21 13:45:55 +00:00
|
|
|
goto error;
|
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)
|
|
|
|
goto error;
|
2009-07-21 13:45:55 +00:00
|
|
|
|
2013-08-06 20:56:50 +00:00
|
|
|
def = virInterfaceDefParseNode(ctxt->doc, node);
|
|
|
|
if (!def)
|
|
|
|
goto error;
|
2009-10-07 14:44:05 +00:00
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
if (!(obj = virInterfaceAssignDef(&privconn->ifaces, def))) {
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceDefFree(def);
|
|
|
|
goto error;
|
|
|
|
}
|
2009-10-07 14:44:05 +00:00
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
obj->active = 1;
|
|
|
|
virInterfaceObjUnlock(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-08-06 18:45:02 +00:00
|
|
|
VIR_FREE(nodes);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-08-06 20:56:50 +00:00
|
|
|
testOpenVolumesForPool(const char *file,
|
2013-08-06 18:45:02 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
int poolidx)
|
|
|
|
{
|
|
|
|
char *vol_xpath;
|
|
|
|
size_t i;
|
|
|
|
int num, ret = -1;
|
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
virStorageVolDefPtr def = NULL;
|
|
|
|
|
|
|
|
/* Find storage volumes */
|
|
|
|
if (virAsprintf(&vol_xpath, "/node/pool[%d]/volume", poolidx) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
num = virXPathNodeSet(vol_xpath, ctxt, &nodes);
|
|
|
|
VIR_FREE(vol_xpath);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (num < 0)
|
2013-08-06 18:45:02 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
2013-08-06 20:56:50 +00:00
|
|
|
xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file,
|
|
|
|
"volume");
|
|
|
|
if (!node)
|
|
|
|
goto error;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
2015-02-05 15:20:17 +00:00
|
|
|
def = virStorageVolDefParseNode(pool->def, ctxt->doc, node, 0);
|
2013-08-06 20:56:50 +00:00
|
|
|
if (!def)
|
|
|
|
goto error;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
if (def->target.path == NULL) {
|
|
|
|
if (virAsprintf(&def->target.path, "%s/%s",
|
|
|
|
pool->def->target.path,
|
|
|
|
def->name) == -1)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!def->key && VIR_STRDUP(def->key, def->target.path) < 0)
|
|
|
|
goto error;
|
2014-03-07 08:33:31 +00:00
|
|
|
if (VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, pool->volumes.count, def) < 0)
|
|
|
|
goto error;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
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
|
|
|
pool->def->allocation += def->target.allocation;
|
2013-08-06 18:45:02 +00:00
|
|
|
pool->def->available = (pool->def->capacity -
|
|
|
|
pool->def->allocation);
|
|
|
|
def = NULL;
|
2009-07-21 13:45:55 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-08-06 18:45:02 +00:00
|
|
|
virStorageVolDefFree(def);
|
|
|
|
VIR_FREE(nodes);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-08-06 20:56:50 +00:00
|
|
|
testParseStorage(testConnPtr privconn,
|
|
|
|
const char *file,
|
|
|
|
xmlXPathContextPtr ctxt)
|
2013-08-06 18:45:02 +00:00
|
|
|
{
|
|
|
|
int num, ret = -1;
|
|
|
|
size_t i;
|
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
virStoragePoolObjPtr obj;
|
|
|
|
|
|
|
|
num = virXPathNodeSet("/node/pool", ctxt, &nodes);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (num < 0)
|
2008-10-30 17:40:57 +00:00
|
|
|
goto error;
|
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)
|
|
|
|
goto error;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2013-08-06 20:56:50 +00:00
|
|
|
def = virStoragePoolDefParseNode(ctxt->doc, node);
|
|
|
|
if (!def)
|
|
|
|
goto error;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
if (!(obj = virStoragePoolObjAssignDef(&privconn->pools,
|
2008-10-30 17:40:57 +00:00
|
|
|
def))) {
|
|
|
|
virStoragePoolDefFree(def);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
if (testStoragePoolObjSetDefaults(obj) == -1) {
|
|
|
|
virStoragePoolObjUnlock(obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
goto error;
|
2008-12-04 20:59:06 +00:00
|
|
|
}
|
2013-08-06 18:45:02 +00:00
|
|
|
obj->active = 1;
|
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) {
|
2013-08-06 18:45:02 +00:00
|
|
|
virStoragePoolObjUnlock(obj);
|
2009-06-22 17:19:30 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
virStoragePoolObjUnlock(obj);
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-08-06 18:45:02 +00:00
|
|
|
VIR_FREE(nodes);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-08-06 20:56:50 +00:00
|
|
|
testParseNodedevs(testConnPtr privconn,
|
|
|
|
const char *file,
|
|
|
|
xmlXPathContextPtr ctxt)
|
2013-08-06 18:45:02 +00:00
|
|
|
{
|
|
|
|
int num, ret = -1;
|
|
|
|
size_t i;
|
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
virNodeDeviceObjPtr obj;
|
|
|
|
|
|
|
|
num = virXPathNodeSet("/node/device", ctxt, &nodes);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (num < 0)
|
2009-10-02 14:05:17 +00:00
|
|
|
goto error;
|
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)
|
|
|
|
goto error;
|
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)
|
|
|
|
goto error;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
if (!(obj = virNodeDeviceAssignDef(&privconn->devs, def))) {
|
2009-10-02 14:05:17 +00:00
|
|
|
virNodeDeviceDefFree(def);
|
|
|
|
goto error;
|
|
|
|
}
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
virNodeDeviceObjUnlock(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-08-06 18:45:02 +00:00
|
|
|
VIR_FREE(nodes);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-01-08 18:32:48 +00:00
|
|
|
static int
|
|
|
|
testParseAuthUsers(testConnPtr privconn,
|
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
|
|
|
int num, ret = -1;
|
|
|
|
size_t i;
|
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
|
|
|
|
num = virXPathNodeSet("/node/auth/user", ctxt, &nodes);
|
|
|
|
if (num < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
privconn->numAuths = num;
|
|
|
|
if (num && VIR_ALLOC_N(privconn->auths, num) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
char *username, *password;
|
|
|
|
|
|
|
|
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"));
|
|
|
|
VIR_FREE(username);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
/* This field is optional. */
|
|
|
|
password = virXMLPropString(nodes[i], "password");
|
|
|
|
|
|
|
|
privconn->auths[i].username = username;
|
|
|
|
privconn->auths[i].password = password;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2014-01-08 18:32:48 +00:00
|
|
|
VIR_FREE(nodes);
|
|
|
|
return ret;
|
|
|
|
}
|
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;
|
|
|
|
testConnPtr privconn;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(privconn) < 0)
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
if (virMutexInit(&privconn->lock) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("cannot initialize mutex"));
|
|
|
|
VIR_FREE(privconn);
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
2009-10-02 14:05:17 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
testDriverLock(privconn);
|
|
|
|
conn->privateData = privconn;
|
|
|
|
|
2015-02-23 14:54:54 +00:00
|
|
|
if (!(privconn->domains = virDomainObjListNew()) ||
|
2015-02-24 12:45:45 +00:00
|
|
|
!(privconn->networks = virNetworkObjListNew()))
|
2013-08-06 18:45:02 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(privconn->caps = testBuildCapabilities(conn)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(privconn->xmlopt = testBuildXMLConfig()))
|
|
|
|
goto error;
|
|
|
|
|
2014-01-04 13:14:33 +00:00
|
|
|
if (!(privconn->eventState = virObjectEventStateNew()))
|
2014-01-01 16:30:12 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
if (!xmlStrEqual(ctxt->node->name, BAD_CAST "node")) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Root element is not 'node'"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
privconn->nextDomID = 1;
|
|
|
|
privconn->numCells = 0;
|
|
|
|
if (VIR_STRDUP(privconn->path, file) < 0)
|
|
|
|
goto error;
|
|
|
|
memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
|
|
|
|
|
|
|
|
if (testParseNodeInfo(&privconn->nodeInfo, ctxt) < 0)
|
|
|
|
goto error;
|
2013-08-06 20:56:50 +00:00
|
|
|
if (testParseDomains(privconn, file, ctxt) < 0)
|
2013-08-06 18:45:02 +00:00
|
|
|
goto error;
|
2013-08-06 20:56:50 +00:00
|
|
|
if (testParseNetworks(privconn, file, ctxt) < 0)
|
2013-08-06 18:45:02 +00:00
|
|
|
goto error;
|
2013-08-06 20:56:50 +00:00
|
|
|
if (testParseInterfaces(privconn, file, ctxt) < 0)
|
2013-08-06 18:45:02 +00:00
|
|
|
goto error;
|
2013-08-06 20:56:50 +00:00
|
|
|
if (testParseStorage(privconn, file, ctxt) < 0)
|
2013-08-06 18:45:02 +00:00
|
|
|
goto error;
|
2013-08-06 20:56:50 +00:00
|
|
|
if (testParseNodedevs(privconn, file, ctxt) < 0)
|
2013-08-06 18:45:02 +00:00
|
|
|
goto error;
|
2014-01-08 18:32:48 +00:00
|
|
|
if (testParseAuthUsers(privconn, ctxt) < 0)
|
|
|
|
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);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
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);
|
2013-01-11 13:54:15 +00:00
|
|
|
virObjectUnref(privconn->domains);
|
2015-02-24 12:45:45 +00:00
|
|
|
virObjectUnref(privconn->networks);
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceObjListFree(&privconn->ifaces);
|
2008-10-30 17:40:57 +00:00
|
|
|
virStoragePoolObjListFree(&privconn->pools);
|
2011-06-22 20:03:30 +00:00
|
|
|
VIR_FREE(privconn->path);
|
2014-01-04 13:14:33 +00:00
|
|
|
virObjectEventStateFree(privconn->eventState);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-05-29 19:20:22 +00:00
|
|
|
VIR_FREE(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
|
|
|
}
|
|
|
|
|
2014-01-08 18:32:48 +00:00
|
|
|
static int
|
|
|
|
testConnectAuthenticate(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = conn->privateData;
|
|
|
|
int ret = -1;
|
|
|
|
ssize_t i;
|
|
|
|
char *username = NULL, *password = NULL;
|
|
|
|
|
|
|
|
if (privconn->numAuths == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Authentication is required because the test XML contains a
|
|
|
|
* non-empty <auth/> section. First we must ask for a username.
|
|
|
|
*/
|
|
|
|
username = virAuthGetUsername(conn, auth, "test", NULL, "localhost"/*?*/);
|
|
|
|
if (!username) {
|
|
|
|
virReportError(VIR_ERR_AUTH_FAILED, "%s",
|
|
|
|
_("authentication failed when asking for username"));
|
|
|
|
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) {
|
|
|
|
password = virAuthGetPassword(conn, auth, "test",
|
|
|
|
username, "localhost");
|
|
|
|
if (password == NULL) {
|
|
|
|
virReportError(VIR_ERR_AUTH_FAILED, "%s",
|
|
|
|
_("authentication failed when asking for password"));
|
|
|
|
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:
|
2014-01-08 18:32:48 +00:00
|
|
|
VIR_FREE(username);
|
|
|
|
VIR_FREE(password);
|
|
|
|
return ret;
|
|
|
|
}
|
2006-06-06 03:32:51 +00:00
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static virDrvOpenStatus testConnectOpen(virConnectPtr conn,
|
2014-01-08 18:32:48 +00:00
|
|
|
virConnectAuthPtr auth,
|
2013-04-23 12:50:18 +00:00
|
|
|
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);
|
|
|
|
|
2008-11-17 11:44:51 +00:00
|
|
|
if (!conn->uri)
|
2007-04-04 14:19:49 +00:00
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
2006-06-06 03:32:51 +00:00
|
|
|
|
2008-11-17 11:44:51 +00:00
|
|
|
if (!conn->uri->scheme || STRNEQ(conn->uri->scheme, "test"))
|
2007-04-04 14:19:49 +00:00
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
2006-06-06 03:32:51 +00:00
|
|
|
|
2007-06-20 10:01:14 +00:00
|
|
|
/* Remote driver should handle these. */
|
2008-11-17 11:44:51 +00:00
|
|
|
if (conn->uri->server)
|
2007-06-20 10:01:14 +00:00
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
2007-04-18 10:14:07 +00:00
|
|
|
/* From this point on, the connection is for us. */
|
2008-11-17 11:44:51 +00:00
|
|
|
if (!conn->uri->path
|
|
|
|
|| 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. */
|
|
|
|
if (testConnectAuthenticate(conn, auth) < 0)
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
|
2011-05-12 12:58:44 +00:00
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectClose(virConnectPtr conn)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = conn->privateData;
|
2014-01-01 16:30:12 +00:00
|
|
|
|
|
|
|
if (privconn == &defaultConn) {
|
|
|
|
virMutexLock(&defaultLock);
|
|
|
|
if (--defaultConnections) {
|
|
|
|
virMutexUnlock(&defaultLock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-02-01 12:26:18 +00:00
|
|
|
virObjectUnref(privconn->caps);
|
2013-03-31 18:03:42 +00:00
|
|
|
virObjectUnref(privconn->xmlopt);
|
2013-01-11 13:54:15 +00:00
|
|
|
virObjectUnref(privconn->domains);
|
2009-11-24 11:44:49 +00:00
|
|
|
virNodeDeviceObjListFree(&privconn->devs);
|
2015-02-24 12:45:45 +00:00
|
|
|
virObjectUnref(privconn->networks);
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceObjListFree(&privconn->ifaces);
|
2008-10-30 17:40:57 +00:00
|
|
|
virStoragePoolObjListFree(&privconn->pools);
|
2014-01-04 13:14:33 +00:00
|
|
|
virObjectEventStateFree(privconn->eventState);
|
2011-06-22 20:03:30 +00:00
|
|
|
VIR_FREE(privconn->path);
|
2009-01-20 20:23:53 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexDestroy(&privconn->lock);
|
2008-10-10 14:50:26 +00:00
|
|
|
|
2014-01-01 16:30:12 +00:00
|
|
|
if (privconn == &defaultConn)
|
|
|
|
virMutexUnlock(&defaultLock);
|
|
|
|
else
|
|
|
|
VIR_FREE(privconn);
|
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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
char *cpu;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, NULL);
|
|
|
|
|
|
|
|
cpu = cpuBaselineXML(xmlCPUs, ncpus, NULL, 0, flags);
|
|
|
|
|
|
|
|
return cpu;
|
|
|
|
}
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
static int testNodeGetInfo(virConnectPtr conn,
|
|
|
|
virNodeInfoPtr info)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = conn->privateData;
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2007-07-27 23:23:00 +00:00
|
|
|
memcpy(info, &privconn->nodeInfo, sizeof(virNodeInfo));
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = conn->privateData;
|
2008-02-27 04:35:08 +00:00
|
|
|
char *xml;
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2014-06-27 07:55:44 +00:00
|
|
|
xml = virCapabilitiesFormatXML(privconn->caps);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-02-27 04:35:08 +00:00
|
|
|
return xml;
|
2007-03-15 17:24:56 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectNumOfDomains(virConnectPtr conn)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-06-24 16:49:47 +00:00
|
|
|
count = virDomainObjListNumOfDomains(privconn->domains, true, NULL, NULL);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(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)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = dom->conn->privateData;
|
|
|
|
virDomainObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
obj = virDomainObjListFindByUUID(privconn->domains, dom->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
|
|
|
testDriverUnlock(privconn);
|
|
|
|
if (!obj) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
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;
|
|
|
|
}
|
|
|
|
ret = virDomainObjIsActive(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)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(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)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = dom->conn->privateData;
|
|
|
|
virDomainObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
obj = virDomainObjListFindByUUID(privconn->domains, dom->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
|
|
|
testDriverUnlock(privconn);
|
|
|
|
if (!obj) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
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;
|
|
|
|
}
|
|
|
|
ret = obj->persistent;
|
|
|
|
|
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)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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)
|
|
|
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE;
|
2010-05-25 17:13:13 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-11-19 23:04:25 +00:00
|
|
|
if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt,
|
2014-11-18 17:34:42 +00:00
|
|
|
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,
|
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
|
|
|
|
2013-08-06 18:59:45 +00:00
|
|
|
if (testDomainStartState(privconn, dom, VIR_DOMAIN_RUNNING_BOOTED) < 0)
|
2009-10-27 17:15:44 +00:00
|
|
|
goto cleanup;
|
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);
|
|
|
|
|
2009-09-02 13:02:06 +00:00
|
|
|
ret = virGetDomain(conn, dom->def->name, dom->def->uuid);
|
2008-12-04 20:57:47 +00:00
|
|
|
if (ret)
|
2009-09-02 13:02:06 +00:00
|
|
|
ret->id = dom->def->id;
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (dom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(dom);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2010-03-25 20:53:29 +00:00
|
|
|
virDomainDefFree(def);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = conn->privateData;
|
2008-12-04 20:57:47 +00:00
|
|
|
virDomainPtr ret = NULL;
|
|
|
|
virDomainObjPtr dom;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
dom = virDomainObjListFindByID(privconn->domains, id);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (dom == NULL) {
|
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
|
|
|
}
|
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
ret = virGetDomain(conn, dom->def->name, dom->def->uuid);
|
2008-12-04 20:57:47 +00:00
|
|
|
if (ret)
|
|
|
|
ret->id = dom->def->id;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (dom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
dom = virDomainObjListFindByUUID(privconn->domains, uuid);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (dom == NULL) {
|
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
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
ret = virGetDomain(conn, dom->def->name, dom->def->uuid);
|
2008-12-04 20:57:47 +00:00
|
|
|
if (ret)
|
|
|
|
ret->id = dom->def->id;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (dom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = conn->privateData;
|
2008-12-04 20:57:47 +00:00
|
|
|
virDomainPtr ret = NULL;
|
|
|
|
virDomainObjPtr dom;
|
2007-07-06 14:56:15 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
dom = virDomainObjListFindByName(privconn->domains, name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (dom == NULL) {
|
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
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
ret = virGetDomain(conn, dom->def->name, dom->def->uuid);
|
2008-12-04 20:57:47 +00:00
|
|
|
if (ret)
|
|
|
|
ret->id = dom->def->id;
|
|
|
|
|
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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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 n;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-06-24 16:49:47 +00:00
|
|
|
n = virDomainObjListGetActiveIDs(privconn->domains, ids, maxids, NULL, NULL);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-10-10 14:20:37 +00:00
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
return n;
|
2006-06-06 03:32:51 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testDomainDestroy(virDomainPtr domain)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
2007-01-18 21:08:21 +00:00
|
|
|
|
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
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
if (!privdom->persistent)
|
|
|
|
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);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
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 testDomainResume(virDomainPtr domain)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
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);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event) {
|
|
|
|
testDriverLock(privconn);
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2009-01-20 20:23:53 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
}
|
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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
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);
|
2009-01-20 20:23:53 +00:00
|
|
|
|
|
|
|
if (event) {
|
|
|
|
testDriverLock(privconn);
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2009-01-20 20:23:53 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
}
|
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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
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:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
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
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
if (!privdom->persistent)
|
|
|
|
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);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
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,
|
2012-10-17 09:23:12 +00:00
|
|
|
unsigned int action ATTRIBUTE_UNUSED)
|
2006-06-14 23:58:34 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
2007-01-18 21:08:21 +00:00
|
|
|
|
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) {
|
|
|
|
case VIR_DOMAIN_LIFECYCLE_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;
|
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
case VIR_DOMAIN_LIFECYCLE_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;
|
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
case VIR_DOMAIN_LIFECYCLE_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;
|
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
case VIR_DOMAIN_LIFECYCLE_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
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
if (!privdom->persistent)
|
|
|
|
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);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
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 testDomainGetInfo(virDomainPtr domain,
|
2012-10-17 09:23:12 +00:00
|
|
|
virDomainInfoPtr info)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
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;
|
2015-02-17 17:01:09 +00:00
|
|
|
info->maxMem = virDomainDefGetMemoryActual(privdom->def);
|
2008-07-11 16:41:27 +00:00
|
|
|
info->nrVirtCpu = privdom->def->vcpus;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
virDomainObjPtr privdom;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2011-05-02 09:35:29 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2011-05-02 09:35:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
*state = virDomainObjGetState(privdom, reason);
|
2011-05-02 09:35:29 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2011-05-02 09:35:29 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
#define TEST_SAVE_MAGIC "TestGuestMagic"
|
|
|
|
|
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
|
|
|
|
testDomainSaveFlags(virDomainPtr domain, const char *path,
|
|
|
|
const char *dxml, unsigned int flags)
|
2007-07-27 23:23:00 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
2008-12-04 20:57:47 +00:00
|
|
|
char *xml = NULL;
|
|
|
|
int fd = -1;
|
|
|
|
int len;
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2010-02-09 18:58:01 +00:00
|
|
|
xml = virDomainDefFormat(privdom->def,
|
2014-11-18 16:44:00 +00:00
|
|
|
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"),
|
|
|
|
domain->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
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"),
|
|
|
|
domain->name, path);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2007-07-27 23:23:00 +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, 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"),
|
|
|
|
domain->name, path);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +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, (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"),
|
|
|
|
domain->name, path);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +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"),
|
|
|
|
domain->name, path);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
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"),
|
|
|
|
domain->name, path);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2008-12-04 20:57:47 +00:00
|
|
|
fd = -1;
|
|
|
|
|
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
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
if (!privdom->persistent)
|
|
|
|
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:
|
2008-12-04 20:57:47 +00:00
|
|
|
VIR_FREE(xml);
|
|
|
|
|
|
|
|
/* Don't report failure in close or unlink, because
|
|
|
|
* in either case we're already in a failure scenario
|
|
|
|
* and have reported a earlier error */
|
|
|
|
if (ret != 0) {
|
2010-11-09 20:48:48 +00:00
|
|
|
VIR_FORCE_CLOSE(fd);
|
2008-12-04 20:57:47 +00:00
|
|
|
unlink(path);
|
|
|
|
}
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = conn->privateData;
|
2008-12-04 20:57:47 +00:00
|
|
|
char *xml = NULL;
|
2007-07-27 23:23:00 +00:00
|
|
|
char magic[15];
|
2008-12-04 20:57:47 +00:00
|
|
|
int fd = -1;
|
|
|
|
int len;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-12-07 18:52:01 +00:00
|
|
|
testDriverLock(privconn);
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
if ((fd = open(path, O_RDONLY)) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("cannot read domain image '%s'"),
|
|
|
|
path);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2009-01-20 17:13:33 +00:00
|
|
|
if (saferead(fd, magic, sizeof(magic)) != sizeof(magic)) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("incomplete save header in '%s'"),
|
|
|
|
path);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
}
|
2007-07-27 23:23:00 +00:00
|
|
|
if (memcmp(magic, TEST_SAVE_MAGIC, sizeof(magic))) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("mismatched header magic"));
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2009-01-20 17:13:33 +00:00
|
|
|
if (saferead(fd, (char*)&len, sizeof(len)) != sizeof(len)) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("failed to read metadata length in '%s'"),
|
|
|
|
path);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
if (len < 1 || len > 8192) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("length of metadata out of range"));
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2013-07-04 10:16:47 +00:00
|
|
|
if (VIR_ALLOC_N(xml, len+1) < 0)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2009-01-20 17:13:33 +00:00
|
|
|
if (saferead(fd, xml, len) != len) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2013-09-10 18:10:55 +00:00
|
|
|
_("incomplete metadata in '%s'"), path);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
xml[len] = '\0';
|
2008-07-11 16:41:27 +00:00
|
|
|
|
2013-03-28 13:55:55 +00:00
|
|
|
def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt,
|
2014-11-18 16:44:00 +00:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE);
|
2008-07-11 16:41:27 +00:00
|
|
|
if (!def)
|
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
|
|
|
|
2013-08-06 18:59:45 +00:00
|
|
|
if (testDomainStartState(privconn, dom, VIR_DOMAIN_RUNNING_RESTORED) < 0)
|
2009-10-27 17:15:44 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
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);
|
|
|
|
VIR_FREE(xml);
|
2010-11-09 20:48:48 +00:00
|
|
|
VIR_FORCE_CLOSE(fd);
|
2008-12-04 20:59:06 +00:00
|
|
|
if (dom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(dom);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
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);
|
2015-04-23 16:00:01 +00:00
|
|
|
if (!privdom->persistent)
|
|
|
|
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);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
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
|
|
|
|
|
|
|
static unsigned long long
|
|
|
|
testDomainGetMaxMemory(virDomainPtr domain)
|
2014-03-18 08:17:30 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2015-02-17 17:01:09 +00:00
|
|
|
ret = virDomainDefGetMemoryActual(privdom->def);
|
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(&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
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
virDomainObjPtr privdom;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
2007-07-27 23:23:00 +00:00
|
|
|
|
|
|
|
/* XXX validate not over host memory wrt to other domains */
|
2015-02-17 17:01:09 +00:00
|
|
|
virDomainDefSetMemoryInitial(privdom->def, 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;
|
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
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
virDomainObjPtr privdom;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2015-02-17 17:01:09 +00:00
|
|
|
if (memory > virDomainDefGetMemoryActual(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
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
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);
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
|
2010-10-04 23:01:12 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (!vm) {
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
virUUIDFormat(domain->uuid, uuidstr);
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("no domain with matching uuid '%s'"), uuidstr);
|
2010-10-04 23:01:12 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-03-31 18:03:42 +00:00
|
|
|
if (virDomainLiveConfigHelperMethod(privconn->caps, privconn->xmlopt,
|
2013-03-05 15:17:24 +00:00
|
|
|
vm, &flags, &def) < 0)
|
2011-12-12 05:16:49 +00:00
|
|
|
goto cleanup;
|
2011-07-15 23:35:47 +00:00
|
|
|
|
2011-12-12 05:16:49 +00:00
|
|
|
if (flags & VIR_DOMAIN_AFFECT_LIVE)
|
2010-10-04 23:01:12 +00:00
|
|
|
def = vm->def;
|
|
|
|
|
|
|
|
ret = (flags & VIR_DOMAIN_VCPU_MAXIMUM) ? def->maxvcpus : def->vcpus;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2010-10-04 23:01:12 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(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)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
2009-11-16 16:31:35 +00:00
|
|
|
virDomainObjPtr privdom = NULL;
|
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);
|
|
|
|
|
|
|
|
/* At least one of LIVE or CONFIG must be set. MAXIMUM cannot be
|
|
|
|
* mixed with LIVE. */
|
2011-06-08 06:33:33 +00:00
|
|
|
if ((flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG)) == 0 ||
|
|
|
|
(flags & (VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_AFFECT_LIVE)) ==
|
|
|
|
(VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_AFFECT_LIVE)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("invalid flag combination: (0x%x)"), flags);
|
2010-10-04 23:01:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2013-04-23 12:50:18 +00:00
|
|
|
if (!nrCpus || (maxvcpus = testConnectGetMaxVcpus(domain->conn, NULL)) < nrCpus) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("argument out of range: %d"), 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
|
|
|
return -1;
|
|
|
|
}
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2011-06-08 06:33:33 +00:00
|
|
|
if (!virDomainObjIsActive(privdom) && (flags & VIR_DOMAIN_AFFECT_LIVE)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
"%s", _("cannot hotplug vcpus for an inactive domain"));
|
2009-10-27 22:00:02 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-10-04 23:01:12 +00:00
|
|
|
/* We allow more cpus in guest than host, but not more than the
|
|
|
|
* domain's starting limit. */
|
2010-11-22 18:55:58 +00:00
|
|
|
if (!(flags & (VIR_DOMAIN_VCPU_MAXIMUM)) &&
|
|
|
|
privdom->def->maxvcpus < maxvcpus)
|
2010-10-04 23:01:12 +00:00
|
|
|
maxvcpus = privdom->def->maxvcpus;
|
2010-11-22 18:55:58 +00:00
|
|
|
|
2009-10-27 22:00:02 +00:00
|
|
|
if (nrCpus > maxvcpus) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("requested cpu amount exceeds maximum (%d > %d)"),
|
|
|
|
nrCpus, maxvcpus);
|
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-11-19 19:51:46 +00:00
|
|
|
if (!(persistentDef = virDomainObjGetPersistentDef(privconn->caps,
|
2013-03-31 18:03:42 +00:00
|
|
|
privconn->xmlopt,
|
2010-11-19 19:51:46 +00:00
|
|
|
privdom)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2010-10-04 23:01:12 +00:00
|
|
|
switch (flags) {
|
2011-06-08 06:33:33 +00:00
|
|
|
case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_AFFECT_CONFIG:
|
2010-11-19 19:51:46 +00:00
|
|
|
persistentDef->maxvcpus = nrCpus;
|
|
|
|
if (nrCpus < persistentDef->vcpus)
|
|
|
|
persistentDef->vcpus = nrCpus;
|
2010-10-04 23:01:12 +00:00
|
|
|
ret = 0;
|
|
|
|
break;
|
2009-10-27 22:02:14 +00:00
|
|
|
|
2011-06-08 06:33:33 +00:00
|
|
|
case VIR_DOMAIN_AFFECT_CONFIG:
|
2010-11-19 19:51:46 +00:00
|
|
|
persistentDef->vcpus = nrCpus;
|
2010-10-04 23:01:12 +00:00
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
2011-06-08 06:33:33 +00:00
|
|
|
case VIR_DOMAIN_AFFECT_LIVE:
|
2013-08-06 18:59:45 +00:00
|
|
|
ret = testDomainUpdateVCPUs(privconn, privdom, nrCpus, 0);
|
2010-10-04 23:01:12 +00:00
|
|
|
break;
|
|
|
|
|
2011-06-08 06:33:33 +00:00
|
|
|
case VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG:
|
2013-08-06 18:59:45 +00:00
|
|
|
ret = testDomainUpdateVCPUs(privconn, privdom, nrCpus, 0);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (ret == 0)
|
2010-11-19 19:51:46 +00:00
|
|
|
persistentDef->vcpus = nrCpus;
|
2010-10-04 23:01:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(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)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
testDomainObjPrivatePtr privdomdata;
|
|
|
|
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
|
|
|
size_t i;
|
|
|
|
int v, maxcpu, hostcpus;
|
2009-10-21 19:04:14 +00:00
|
|
|
int ret = -1;
|
|
|
|
struct timeval tv;
|
|
|
|
unsigned long long statbase;
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains, domain->name);
|
2009-10-21 19:04:14 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-10-21 19:04:14 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
privdomdata = privdom->privateData;
|
|
|
|
|
|
|
|
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);
|
|
|
|
maxcpu = maplen * 8;
|
|
|
|
if (maxcpu > hostcpus)
|
|
|
|
maxcpu = hostcpus;
|
|
|
|
|
|
|
|
/* Clamp to actual number of vcpus */
|
|
|
|
if (maxinfo > privdom->def->vcpus)
|
|
|
|
maxinfo = privdom->def->vcpus;
|
|
|
|
|
|
|
|
/* Populate virVcpuInfo structures */
|
|
|
|
if (info != NULL) {
|
|
|
|
memset(info, 0, sizeof(*info) * maxinfo);
|
|
|
|
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < maxinfo; i++) {
|
2009-10-21 19:04:14 +00:00
|
|
|
virVcpuInfo privinfo = privdomdata->vcpu_infos[i];
|
|
|
|
|
|
|
|
info[i].number = privinfo.number;
|
|
|
|
info[i].state = privinfo.state;
|
|
|
|
info[i].cpu = privinfo.cpu;
|
|
|
|
|
|
|
|
/* Fake an increasing cpu time value */
|
|
|
|
info[i].cpuTime = statbase / 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Populate cpumaps */
|
|
|
|
if (cpumaps != NULL) {
|
|
|
|
int privmaplen = VIR_CPU_MAPLEN(hostcpus);
|
|
|
|
memset(cpumaps, 0, maplen * maxinfo);
|
|
|
|
|
2013-05-21 07:21:18 +00:00
|
|
|
for (v = 0; v < maxinfo; v++) {
|
2009-10-21 19:04:14 +00:00
|
|
|
unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v);
|
|
|
|
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < maxcpu; i++) {
|
2014-11-13 14:24:39 +00:00
|
|
|
if (VIR_CPU_USABLE(privdomdata->cpumaps, privmaplen, v, i))
|
2009-10-21 19:04:14 +00:00
|
|
|
VIR_USE_CPU(cpumap, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = maxinfo;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
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)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
testDomainObjPrivatePtr privdomdata;
|
|
|
|
virDomainObjPtr privdom;
|
|
|
|
unsigned char *privcpumap;
|
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;
|
|
|
|
int maxcpu, hostcpus, privmaplen;
|
2009-10-27 22:25:38 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains, domain->name);
|
2009-10-27 22:25:38 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-10-27 22:25:38 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vcpu > privdom->def->vcpus) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("requested vcpu is higher than allocated vcpus"));
|
2009-10-27 22:25:38 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
privdomdata = privdom->privateData;
|
|
|
|
hostcpus = VIR_NODEINFO_MAXCPUS(privconn->nodeInfo);
|
|
|
|
privmaplen = VIR_CPU_MAPLEN(hostcpus);
|
|
|
|
|
|
|
|
maxcpu = maplen * 8;
|
|
|
|
if (maxcpu > hostcpus)
|
|
|
|
maxcpu = hostcpus;
|
|
|
|
|
|
|
|
privcpumap = VIR_GET_CPUMAP(privdomdata->cpumaps, privmaplen, vcpu);
|
|
|
|
memset(privcpumap, 0, privmaplen);
|
|
|
|
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < maxcpu; i++) {
|
2014-11-13 14:24:39 +00:00
|
|
|
if (VIR_CPU_USABLE(cpumap, maplen, 0, i))
|
2009-10-27 22:25:38 +00:00
|
|
|
VIR_USE_CPU(privcpumap, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
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;
|
|
|
|
}
|
|
|
|
|
2011-07-06 20:40:19 +00:00
|
|
|
static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
|
2006-08-16 16:36:39 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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;
|
|
|
|
|
2011-07-13 22:24:38 +00:00
|
|
|
/* Flags checked by virDomainDefFormat */
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
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
|
|
|
|
2010-02-09 18:58:01 +00:00
|
|
|
ret = virDomainDefFormat(def,
|
2014-11-18 16:44:00 +00:00
|
|
|
virDomainDefFormatConvertXMLFlags(flags));
|
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(&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
|
|
|
|
2014-03-18 08:17:30 +00:00
|
|
|
static int testConnectNumOfDefinedDomains(virConnectPtr conn)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-06-24 16:49:47 +00:00
|
|
|
count = virDomainObjListNumOfDomains(privconn->domains, false, NULL, NULL);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(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;
|
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)
|
|
|
|
{
|
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
|
|
|
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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 n;
|
2008-07-11 16:41:27 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-07-11 16:41:27 +00:00
|
|
|
memset(names, 0, sizeof(*names)*maxnames);
|
2013-06-24 16:49:47 +00:00
|
|
|
n = virDomainObjListGetInactiveNames(privconn->domains, names, maxnames,
|
|
|
|
NULL, NULL);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-10-10 14:20:37 +00:00
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
return n;
|
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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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)
|
|
|
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE;
|
2014-11-18 14:19:38 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-03-28 13:55:55 +00:00
|
|
|
if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt,
|
2014-11-18 17:34:42 +00:00
|
|
|
parse_flags)) == NULL)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
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
|
|
|
|
2009-06-22 16:29:40 +00:00
|
|
|
ret = virGetDomain(conn, dom->def->name, dom->def->uuid);
|
2008-12-04 20:57:47 +00:00
|
|
|
if (ret)
|
2009-06-22 16:29:40 +00:00
|
|
|
ret->id = 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);
|
2008-12-04 20:59:06 +00:00
|
|
|
if (dom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(dom);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
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)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = dom->conn->privateData;
|
|
|
|
virDomainObjPtr privdom;
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
|
|
|
VIR_DOMAIN_AFFECT_CONFIG, NULL);
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
dom->name);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (privdom == NULL) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = virDomainObjGetMetadata(privdom, type, uri, privconn->caps,
|
|
|
|
privconn->xmlopt, flags);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
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)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = dom->conn->privateData;
|
|
|
|
virDomainObjPtr privdom;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
|
|
|
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
dom->name);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (privdom == NULL) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&privdom);
|
2013-09-09 16:02:59 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-04-04 07:31:24 +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:
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-04-04 07:31:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-18 08:17:30 +00:00
|
|
|
static int testDomainCreateWithFlags(virDomainPtr domain, unsigned int flags)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
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);
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
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);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(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)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
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:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
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;
|
|
|
|
|
2015-04-23 16:00:01 +00:00
|
|
|
if (virDomainObjIsActive(privdom))
|
2011-08-19 14:14:58 +00:00
|
|
|
privdom->persistent = 0;
|
2015-04-23 16:00:01 +00:00
|
|
|
else
|
|
|
|
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);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
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
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
virDomainObjPtr privdom;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
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
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int testDomainSetAutostart(virDomainPtr domain,
|
|
|
|
int autostart)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
virDomainObjPtr privdom;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
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
|
|
|
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-04-04 14:19:49 +00:00
|
|
|
|
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
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
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);
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
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
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
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;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-07-24 15:05:30 +00:00
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2009-07-24 15:05:30 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-07-24 15:05:30 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testDomainInterfaceStats(virDomainPtr domain,
|
|
|
|
const char *path,
|
2014-09-16 13:19:45 +00:00
|
|
|
virDomainInterfaceStatsPtr stats)
|
2009-07-24 15:05:30 +00:00
|
|
|
{
|
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
virDomainObjPtr privdom;
|
|
|
|
struct timeval tv;
|
|
|
|
unsigned long long statbase;
|
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;
|
|
|
|
int found = 0, ret = -1;
|
2009-07-24 15:05:30 +00:00
|
|
|
|
|
|
|
testDriverLock(privconn);
|
2013-01-11 16:04:47 +00:00
|
|
|
privdom = virDomainObjListFindByName(privconn->domains,
|
|
|
|
domain->name);
|
2009-07-24 15:05:30 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (privdom == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-07-24 15:05:30 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < privdom->def->nnets; i++) {
|
2009-07-24 15:05:30 +00:00
|
|
|
if (privdom->def->nets[i]->ifname &&
|
2012-10-17 09:23:12 +00:00
|
|
|
STREQ(privdom->def->nets[i]->ifname, path)) {
|
2009-07-24 15:05:30 +00:00
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("invalid path, '%s' is not a known interface"), 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->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
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static virNetworkPtr testNetworkLookupByUUID(virConnectPtr conn,
|
|
|
|
const unsigned char *uuid)
|
2007-07-27 23:23:00 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = conn->privateData;
|
|
|
|
virNetworkObjPtr net;
|
2008-12-04 20:57:47 +00:00
|
|
|
virNetworkPtr ret = NULL;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2015-02-23 15:57:29 +00:00
|
|
|
net = virNetworkObjFindByUUID(privconn->networks, uuid);
|
2008-12-04 20:59:06 +00:00
|
|
|
if (net == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_NETWORK, NULL);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = virGetNetwork(conn, net->def->name, net->def->uuid);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-02-25 16:38:54 +00:00
|
|
|
virNetworkObjEndAPI(&net);
|
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
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static virNetworkPtr testNetworkLookupByName(virConnectPtr conn,
|
2008-07-11 16:39:08 +00:00
|
|
|
const char *name)
|
2007-07-27 23:23:00 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = conn->privateData;
|
2008-12-04 20:57:47 +00:00
|
|
|
virNetworkObjPtr net;
|
|
|
|
virNetworkPtr ret = NULL;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2015-02-23 16:05:52 +00:00
|
|
|
net = virNetworkObjFindByName(privconn->networks, name);
|
2008-12-04 20:59:06 +00:00
|
|
|
if (net == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_NETWORK, NULL);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = virGetNetwork(conn, net->def->name, net->def->uuid);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-02-25 16:38:54 +00:00
|
|
|
virNetworkObjEndAPI(&net);
|
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 testConnectNumOfNetworks(virConnectPtr conn)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectListNetworks(virConnectPtr conn, char **const names, int nnames) {
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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,
|
|
|
|
true, names, nnames, NULL, conn);
|
2008-07-11 16:39:08 +00:00
|
|
|
return n;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-18 08:17:30 +00:00
|
|
|
static int testConnectNumOfDefinedNetworks(virConnectPtr conn)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames) {
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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,
|
|
|
|
false, names, nnames, NULL, conn);
|
2008-07-11 16:39:08 +00:00
|
|
|
return n;
|
2007-07-27 23:23:00 +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)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = conn->privateData;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
static int testNetworkIsActive(virNetworkPtr net)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = net->conn->privateData;
|
|
|
|
virNetworkObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
2015-02-23 15:57:29 +00:00
|
|
|
obj = virNetworkObjFindByUUID(privconn->networks, 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
|
|
|
if (!obj) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_NETWORK, NULL);
|
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;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testNetworkIsPersistent(virNetworkPtr net)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = net->conn->privateData;
|
|
|
|
virNetworkObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
2015-02-23 15:57:29 +00:00
|
|
|
obj = virNetworkObjFindByUUID(privconn->networks, 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
|
|
|
if (!obj) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_NETWORK, NULL);
|
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;
|
|
|
|
}
|
|
|
|
ret = obj->persistent;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-18 08:17:30 +00:00
|
|
|
static virNetworkPtr testNetworkCreateXML(virConnectPtr conn, const char *xml)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = conn->privateData;
|
2008-07-11 16:39:08 +00:00
|
|
|
virNetworkDefPtr def;
|
2008-12-04 20:59:06 +00:00
|
|
|
virNetworkObjPtr net = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
virNetworkPtr ret = NULL;
|
2013-12-11 10:37:59 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2010-02-10 10:22:52 +00:00
|
|
|
if ((def = virNetworkDefParseString(xml)) == NULL)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
network_conf: Drop virNetworkObjIsDuplicate
This function does not make any sense now, that network driver is
(almost) dropped. I mean, previously, when threads were
serialized, this function was there to check, if no other network
with the same name or UUID exists. However, nowadays that threads
can run more in parallel, this function is useless, in fact it
gives misleading return values. Consider the following scenario.
Two threads, both trying to define networks with same name but
different UUID (e.g. because it was generated during XML parsing
phase, whatever). Lets assume that both threads are about to call
networkValidate() which immediately calls
virNetworkObjIsDuplicate().
T1: calls virNetworkObjIsDuplicate() and since no network with
given name or UUID exist, success is returned.
T2: calls virNetworkObjIsDuplicate() and since no network with
given name or UUID exist, success is returned.
T1: calls virNetworkAssignDef() and successfully places its
network into the virNetworkObjList.
T2: calls virNetworkAssignDef() and since network with the same
name exists, the network definition is replaced.
Okay, this is mainly because virNetworkAssignDef() does not check
whether name and UUID matches. Well, lets make it so! And drop
useless function too.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-14 10:18:21 +00:00
|
|
|
if (!(net = virNetworkAssignDef(privconn->networks, def,
|
|
|
|
VIR_NETWORK_OBJ_LIST_ADD_LIVE |
|
|
|
|
VIR_NETWORK_OBJ_LIST_ADD_CHECK_LIVE)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
2009-02-13 18:11:03 +00:00
|
|
|
net->active = 1;
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2013-12-11 10:37:59 +00:00
|
|
|
event = virNetworkEventLifecycleNew(net->def->name, net->def->uuid,
|
2013-12-11 13:40:41 +00:00
|
|
|
VIR_NETWORK_EVENT_STARTED,
|
|
|
|
0);
|
2013-12-11 10:37:59 +00:00
|
|
|
|
2009-02-13 18:11:03 +00:00
|
|
|
ret = virGetNetwork(conn, net->def->name, net->def->uuid);
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2008-12-04 20:57:47 +00:00
|
|
|
virNetworkDefFree(def);
|
2013-12-11 10:37:59 +00:00
|
|
|
if (event)
|
|
|
|
testObjectEventQueue(privconn, event);
|
2015-02-25 16:38:54 +00:00
|
|
|
virNetworkObjEndAPI(&net);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2012-08-20 05:01:53 +00:00
|
|
|
static
|
2013-04-23 12:50:18 +00:00
|
|
|
virNetworkPtr testNetworkDefineXML(virConnectPtr conn, const char *xml)
|
2012-08-20 05:01:53 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = conn->privateData;
|
2008-07-11 16:39:08 +00:00
|
|
|
virNetworkDefPtr def;
|
2008-12-04 20:59:06 +00:00
|
|
|
virNetworkObjPtr net = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
virNetworkPtr ret = NULL;
|
2013-12-11 10:37:59 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2010-02-10 10:22:52 +00:00
|
|
|
if ((def = virNetworkDefParseString(xml)) == NULL)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
network_conf: Drop virNetworkObjIsDuplicate
This function does not make any sense now, that network driver is
(almost) dropped. I mean, previously, when threads were
serialized, this function was there to check, if no other network
with the same name or UUID exists. However, nowadays that threads
can run more in parallel, this function is useless, in fact it
gives misleading return values. Consider the following scenario.
Two threads, both trying to define networks with same name but
different UUID (e.g. because it was generated during XML parsing
phase, whatever). Lets assume that both threads are about to call
networkValidate() which immediately calls
virNetworkObjIsDuplicate().
T1: calls virNetworkObjIsDuplicate() and since no network with
given name or UUID exist, success is returned.
T2: calls virNetworkObjIsDuplicate() and since no network with
given name or UUID exist, success is returned.
T1: calls virNetworkAssignDef() and successfully places its
network into the virNetworkObjList.
T2: calls virNetworkAssignDef() and since network with the same
name exists, the network definition is replaced.
Okay, this is mainly because virNetworkAssignDef() does not check
whether name and UUID matches. Well, lets make it so! And drop
useless function too.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-14 10:18:21 +00:00
|
|
|
if (!(net = virNetworkAssignDef(privconn->networks, def, 0)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2013-12-11 10:37:59 +00:00
|
|
|
event = virNetworkEventLifecycleNew(net->def->name, net->def->uuid,
|
2013-12-11 13:40:41 +00:00
|
|
|
VIR_NETWORK_EVENT_DEFINED,
|
|
|
|
0);
|
2013-12-11 10:37:59 +00:00
|
|
|
|
2009-02-13 18:11:03 +00:00
|
|
|
ret = virGetNetwork(conn, net->def->name, net->def->uuid);
|
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
|
|
|
virNetworkDefFree(def);
|
2013-12-11 10:37:59 +00:00
|
|
|
if (event)
|
|
|
|
testObjectEventQueue(privconn, event);
|
2015-02-25 16:38:54 +00:00
|
|
|
virNetworkObjEndAPI(&net);
|
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 testNetworkUndefine(virNetworkPtr network)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = network->conn->privateData;
|
|
|
|
virNetworkObjPtr privnet;
|
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
|
|
|
|
2015-02-23 16:05:52 +00:00
|
|
|
privnet = virNetworkObjFindByName(privconn->networks, network->name);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privnet == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
2007-07-27 23:23:00 +00:00
|
|
|
|
Rename internal APis
Rename virDomainIsActive to virDomainObjIsActive, and
virInterfaceIsActive to virInterfaceObjIsActive and finally
virNetworkIsActive to virNetworkObjIsActive.
* src/conf/domain_conf.c, src/conf/domain_conf.h,
src/conf/interface_conf.h, src/conf/network_conf.c,
src/conf/network_conf.h, src/lxc/lxc_driver.c,
src/network/bridge_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_driver.c, src/qemu/qemu_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c: Update for
renamed APIs.
2009-10-20 14:51:03 +00:00
|
|
|
if (virNetworkObjIsActive(privnet)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("Network '%s' is still running"), network->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2013-12-11 10:37:59 +00:00
|
|
|
event = virNetworkEventLifecycleNew(network->name, network->uuid,
|
2013-12-11 13:40:41 +00:00
|
|
|
VIR_NETWORK_EVENT_UNDEFINED,
|
|
|
|
0);
|
2013-12-11 10:37:59 +00:00
|
|
|
|
2015-02-23 14:54:54 +00:00
|
|
|
virNetworkRemoveInactive(privconn->networks, privnet);
|
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:
|
2013-12-11 10:37:59 +00:00
|
|
|
if (event)
|
|
|
|
testObjectEventQueue(privconn, event);
|
2015-02-25 16:38:54 +00:00
|
|
|
virNetworkObjEndAPI(&privnet);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +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)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = net->conn->privateData;
|
|
|
|
virNetworkObjPtr network = NULL;
|
|
|
|
int isActive, ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_NETWORK_UPDATE_AFFECT_LIVE |
|
|
|
|
VIR_NETWORK_UPDATE_AFFECT_CONFIG,
|
|
|
|
-1);
|
|
|
|
|
2015-02-23 15:57:29 +00:00
|
|
|
network = virNetworkObjFindByUUID(privconn->networks, net->uuid);
|
2012-08-20 05:01:53 +00:00
|
|
|
if (!network) {
|
|
|
|
virReportError(VIR_ERR_NO_NETWORK,
|
|
|
|
"%s", _("no network with matching uuid"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* VIR_NETWORK_UPDATE_AFFECT_CURRENT means "change LIVE if network
|
|
|
|
* is active, else change CONFIG
|
|
|
|
*/
|
|
|
|
isActive = virNetworkObjIsActive(network);
|
|
|
|
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 */
|
|
|
|
if (virNetworkObjUpdate(network, command, section, parentIndex, xml, flags) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-02-25 16:38:54 +00:00
|
|
|
virNetworkObjEndAPI(&network);
|
2012-08-20 05:01:53 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-18 08:17:30 +00:00
|
|
|
static int testNetworkCreate(virNetworkPtr network)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = network->conn->privateData;
|
|
|
|
virNetworkObjPtr privnet;
|
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
|
|
|
|
2015-02-23 16:05:52 +00:00
|
|
|
privnet = virNetworkObjFindByName(privconn->networks, network->name);
|
2008-12-04 20:56:10 +00:00
|
|
|
if (privnet == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
2007-07-27 23:23:00 +00:00
|
|
|
|
Rename internal APis
Rename virDomainIsActive to virDomainObjIsActive, and
virInterfaceIsActive to virInterfaceObjIsActive and finally
virNetworkIsActive to virNetworkObjIsActive.
* src/conf/domain_conf.c, src/conf/domain_conf.h,
src/conf/interface_conf.h, src/conf/network_conf.c,
src/conf/network_conf.h, src/lxc/lxc_driver.c,
src/network/bridge_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_driver.c, src/qemu/qemu_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c: Update for
renamed APIs.
2009-10-20 14:51:03 +00:00
|
|
|
if (virNetworkObjIsActive(privnet)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("Network '%s' is already running"), network->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2008-07-11 16:39:08 +00:00
|
|
|
privnet->active = 1;
|
2013-12-11 10:37:59 +00:00
|
|
|
event = virNetworkEventLifecycleNew(privnet->def->name, privnet->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:
|
2013-12-11 10:37:59 +00:00
|
|
|
if (event)
|
|
|
|
testObjectEventQueue(privconn, event);
|
2015-02-25 16:38:54 +00:00
|
|
|
virNetworkObjEndAPI(&privnet);
|
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 testNetworkDestroy(virNetworkPtr network)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = network->conn->privateData;
|
|
|
|
virNetworkObjPtr privnet;
|
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
|
|
|
|
2015-02-23 16:05:52 +00:00
|
|
|
privnet = virNetworkObjFindByName(privconn->networks, network->name);
|
2008-12-04 20:56:10 +00:00
|
|
|
if (privnet == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2008-07-11 16:39:08 +00:00
|
|
|
privnet->active = 0;
|
2013-12-11 10:37:59 +00:00
|
|
|
event = virNetworkEventLifecycleNew(privnet->def->name, privnet->def->uuid,
|
2013-12-11 13:40:41 +00:00
|
|
|
VIR_NETWORK_EVENT_STOPPED,
|
|
|
|
0);
|
2015-02-26 12:45:05 +00:00
|
|
|
if (!privnet->persistent)
|
2015-02-23 14:54:54 +00:00
|
|
|
virNetworkRemoveInactive(privconn->networks, privnet);
|
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:
|
2013-12-11 10:37:59 +00:00
|
|
|
if (event)
|
|
|
|
testObjectEventQueue(privconn, event);
|
2015-02-25 16:38:54 +00:00
|
|
|
virNetworkObjEndAPI(&privnet);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 20:40:19 +00:00
|
|
|
static char *testNetworkGetXMLDesc(virNetworkPtr network,
|
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)
|
2011-07-06 20:40:19 +00:00
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = network->conn->privateData;
|
|
|
|
virNetworkObjPtr privnet;
|
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);
|
|
|
|
|
2015-02-23 16:05:52 +00:00
|
|
|
privnet = virNetworkObjFindByName(privconn->networks, network->name);
|
2008-12-04 20:56:10 +00:00
|
|
|
if (privnet == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2011-12-14 10:50:40 +00:00
|
|
|
ret = virNetworkDefFormat(privnet->def, flags);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-02-25 16:38:54 +00:00
|
|
|
virNetworkObjEndAPI(&privnet);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *testNetworkGetBridgeName(virNetworkPtr network) {
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = network->conn->privateData;
|
2008-07-11 16:39:08 +00:00
|
|
|
char *bridge = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
virNetworkObjPtr privnet;
|
|
|
|
|
2015-02-23 16:05:52 +00:00
|
|
|
privnet = virNetworkObjFindByName(privconn->networks, network->name);
|
2008-12-04 20:56:10 +00:00
|
|
|
if (privnet == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
2009-09-23 15:54:48 +00:00
|
|
|
if (!(privnet->def->bridge)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("network '%s' does not have a bridge name."),
|
|
|
|
privnet->def->name);
|
2009-09-23 15:54:48 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-05-03 12:49:30 +00:00
|
|
|
ignore_value(VIR_STRDUP(bridge, privnet->def->bridge));
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-02-25 16:38:54 +00:00
|
|
|
virNetworkObjEndAPI(&privnet);
|
2007-07-27 23:23:00 +00:00
|
|
|
return bridge;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testNetworkGetAutostart(virNetworkPtr network,
|
2014-03-18 08:17:30 +00:00
|
|
|
int *autostart)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = network->conn->privateData;
|
|
|
|
virNetworkObjPtr privnet;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2015-02-23 16:05:52 +00:00
|
|
|
privnet = virNetworkObjFindByName(privconn->networks, network->name);
|
2008-12-04 20:56:10 +00:00
|
|
|
if (privnet == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
*autostart = privnet->autostart;
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-02-25 16:38:54 +00:00
|
|
|
virNetworkObjEndAPI(&privnet);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int testNetworkSetAutostart(virNetworkPtr network,
|
2014-03-18 08:17:30 +00:00
|
|
|
int autostart)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = network->conn->privateData;
|
|
|
|
virNetworkObjPtr privnet;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2015-02-23 16:05:52 +00:00
|
|
|
privnet = virNetworkObjFindByName(privconn->networks, network->name);
|
2008-12-04 20:56:10 +00:00
|
|
|
if (privnet == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
privnet->autostart = autostart ? 1 : 0;
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-02-25 16:38:54 +00:00
|
|
|
virNetworkObjEndAPI(&privnet);
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectNumOfInterfaces(virConnectPtr conn)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
|
|
|
testConnPtr 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
|
|
|
size_t i;
|
|
|
|
int count = 0;
|
2009-07-21 13:45:55 +00:00
|
|
|
|
|
|
|
testDriverLock(privconn);
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; (i < privconn->ifaces.count); i++) {
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceObjLock(privconn->ifaces.objs[i]);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (virInterfaceObjIsActive(privconn->ifaces.objs[i]))
|
2009-07-21 13:45:55 +00:00
|
|
|
count++;
|
|
|
|
virInterfaceObjUnlock(privconn->ifaces.objs[i]);
|
|
|
|
}
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectListInterfaces(virConnectPtr conn, char **const names, int nnames)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
|
|
|
testConnPtr 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;
|
|
|
|
size_t i;
|
2009-07-21 13:45:55 +00:00
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
memset(names, 0, sizeof(*names)*nnames);
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; (i < privconn->ifaces.count) && (n < nnames); i++) {
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceObjLock(privconn->ifaces.objs[i]);
|
Rename internal APis
Rename virDomainIsActive to virDomainObjIsActive, and
virInterfaceIsActive to virInterfaceObjIsActive and finally
virNetworkIsActive to virNetworkObjIsActive.
* src/conf/domain_conf.c, src/conf/domain_conf.h,
src/conf/interface_conf.h, src/conf/network_conf.c,
src/conf/network_conf.h, src/lxc/lxc_driver.c,
src/network/bridge_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_driver.c, src/qemu/qemu_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c: Update for
renamed APIs.
2009-10-20 14:51:03 +00:00
|
|
|
if (virInterfaceObjIsActive(privconn->ifaces.objs[i])) {
|
2013-05-03 12:49:30 +00:00
|
|
|
if (VIR_STRDUP(names[n++], privconn->ifaces.objs[i]->def->name) < 0) {
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceObjUnlock(privconn->ifaces.objs[i]);
|
2013-05-03 12:49:30 +00:00
|
|
|
goto error;
|
2009-07-21 13:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
virInterfaceObjUnlock(privconn->ifaces.objs[i]);
|
|
|
|
}
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-05-21 07:21:18 +00:00
|
|
|
for (n = 0; n < nnames; n++)
|
2009-07-21 13:45:55 +00:00
|
|
|
VIR_FREE(names[n]);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectNumOfDefinedInterfaces(virConnectPtr conn)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
|
|
|
testConnPtr 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
|
|
|
size_t i;
|
|
|
|
int count = 0;
|
2009-07-21 13:45:55 +00:00
|
|
|
|
|
|
|
testDriverLock(privconn);
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < privconn->ifaces.count; i++) {
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceObjLock(privconn->ifaces.objs[i]);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (!virInterfaceObjIsActive(privconn->ifaces.objs[i]))
|
2009-07-21 13:45:55 +00:00
|
|
|
count++;
|
|
|
|
virInterfaceObjUnlock(privconn->ifaces.objs[i]);
|
|
|
|
}
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const names, int nnames)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
|
|
|
testConnPtr 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;
|
|
|
|
size_t i;
|
2009-07-21 13:45:55 +00:00
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
memset(names, 0, sizeof(*names)*nnames);
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; (i < privconn->ifaces.count) && (n < nnames); i++) {
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceObjLock(privconn->ifaces.objs[i]);
|
Rename internal APis
Rename virDomainIsActive to virDomainObjIsActive, and
virInterfaceIsActive to virInterfaceObjIsActive and finally
virNetworkIsActive to virNetworkObjIsActive.
* src/conf/domain_conf.c, src/conf/domain_conf.h,
src/conf/interface_conf.h, src/conf/network_conf.c,
src/conf/network_conf.h, src/lxc/lxc_driver.c,
src/network/bridge_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_driver.c, src/qemu/qemu_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c: Update for
renamed APIs.
2009-10-20 14:51:03 +00:00
|
|
|
if (!virInterfaceObjIsActive(privconn->ifaces.objs[i])) {
|
2013-05-03 12:49:30 +00:00
|
|
|
if (VIR_STRDUP(names[n++], privconn->ifaces.objs[i]->def->name) < 0) {
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceObjUnlock(privconn->ifaces.objs[i]);
|
2013-05-03 12:49:30 +00:00
|
|
|
goto error;
|
2009-07-21 13:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
virInterfaceObjUnlock(privconn->ifaces.objs[i]);
|
|
|
|
}
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-05-21 07:21:18 +00:00
|
|
|
for (n = 0; n < nnames; n++)
|
2009-07-21 13:45:55 +00:00
|
|
|
VIR_FREE(names[n]);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static virInterfacePtr testInterfaceLookupByName(virConnectPtr conn,
|
2009-07-21 13:45:55 +00:00
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = conn->privateData;
|
|
|
|
virInterfaceObjPtr iface;
|
|
|
|
virInterfacePtr ret = NULL;
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
iface = virInterfaceFindByName(&privconn->ifaces, name);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (iface == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_INTERFACE, NULL);
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = virGetInterface(conn, iface->def->name, iface->def->mac);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-07-21 13:45:55 +00:00
|
|
|
if (iface)
|
|
|
|
virInterfaceObjUnlock(iface);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static virInterfacePtr testInterfaceLookupByMACString(virConnectPtr conn,
|
2009-07-21 13:45:55 +00:00
|
|
|
const char *mac)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = conn->privateData;
|
|
|
|
virInterfaceObjPtr iface;
|
|
|
|
int ifacect;
|
|
|
|
virInterfacePtr ret = NULL;
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
ifacect = virInterfaceFindByMACString(&privconn->ifaces, mac, &iface, 1);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (ifacect == 0) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_INTERFACE, NULL);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = virGetInterface(conn, iface->def->name, iface->def->mac);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-07-21 13:45:55 +00:00
|
|
|
if (iface)
|
|
|
|
virInterfaceObjUnlock(iface);
|
|
|
|
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
|
|
|
static int testInterfaceIsActive(virInterfacePtr iface)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = iface->conn->privateData;
|
|
|
|
virInterfaceObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
obj = virInterfaceFindByName(&privconn->ifaces, iface->name);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
if (!obj) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_INTERFACE, NULL);
|
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;
|
|
|
|
}
|
|
|
|
ret = virInterfaceObjIsActive(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)
|
|
|
|
virInterfaceObjUnlock(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-09 19:17:26 +00:00
|
|
|
static int testInterfaceChangeBegin(virConnectPtr conn,
|
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)
|
2011-05-09 19:17:26 +00:00
|
|
|
{
|
|
|
|
testConnPtr privconn = conn->privateData;
|
|
|
|
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);
|
|
|
|
|
2011-05-09 19:17:26 +00:00
|
|
|
testDriverLock(privconn);
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (virInterfaceObjListClone(&privconn->ifaces,
|
|
|
|
&privconn->backupIfaces) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2011-05-09 19:17:26 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testInterfaceChangeCommit(virConnectPtr conn,
|
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)
|
2011-05-09 19:17:26 +00:00
|
|
|
{
|
|
|
|
testConnPtr privconn = conn->privateData;
|
|
|
|
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);
|
|
|
|
|
2011-05-09 19:17:26 +00:00
|
|
|
testDriverLock(privconn);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
virInterfaceObjListFree(&privconn->backupIfaces);
|
|
|
|
privconn->transaction_running = false;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2011-05-09 19:17:26 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testInterfaceChangeRollback(virConnectPtr conn,
|
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)
|
2011-05-09 19:17:26 +00:00
|
|
|
{
|
|
|
|
testConnPtr privconn = conn->privateData;
|
|
|
|
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);
|
|
|
|
|
2011-05-09 19:17:26 +00:00
|
|
|
testDriverLock(privconn);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
virInterfaceObjListFree(&privconn->ifaces);
|
|
|
|
privconn->ifaces.count = privconn->backupIfaces.count;
|
|
|
|
privconn->ifaces.objs = privconn->backupIfaces.objs;
|
|
|
|
privconn->backupIfaces.count = 0;
|
|
|
|
privconn->backupIfaces.objs = NULL;
|
|
|
|
|
|
|
|
privconn->transaction_running = false;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2011-05-09 19:17:26 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
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
|
|
|
|
2009-07-21 13:45:55 +00:00
|
|
|
static char *testInterfaceGetXMLDesc(virInterfacePtr iface,
|
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-07-21 13:45:55 +00:00
|
|
|
{
|
|
|
|
testConnPtr privconn = iface->conn->privateData;
|
|
|
|
virInterfaceObjPtr privinterface;
|
|
|
|
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);
|
|
|
|
|
2009-07-21 13:45:55 +00:00
|
|
|
testDriverLock(privconn);
|
|
|
|
privinterface = virInterfaceFindByName(&privconn->ifaces,
|
|
|
|
iface->name);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (privinterface == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_INTERFACE, __FUNCTION__);
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-02-10 12:28:05 +00:00
|
|
|
ret = virInterfaceDefFormat(privinterface->def);
|
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
|
|
|
if (privinterface)
|
|
|
|
virInterfaceObjUnlock(privinterface);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virInterfacePtr testInterfaceDefineXML(virConnectPtr conn, const char *xmlStr,
|
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-07-21 13:45:55 +00:00
|
|
|
{
|
|
|
|
testConnPtr privconn = conn->privateData;
|
|
|
|
virInterfaceDefPtr def;
|
|
|
|
virInterfaceObjPtr iface = NULL;
|
|
|
|
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);
|
|
|
|
|
2009-07-21 13:45:55 +00:00
|
|
|
testDriverLock(privconn);
|
2010-02-10 12:28:05 +00:00
|
|
|
if ((def = virInterfaceDefParseString(xmlStr)) == NULL)
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2010-02-10 12:28:05 +00:00
|
|
|
if ((iface = virInterfaceAssignDef(&privconn->ifaces, def)) == NULL)
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
|
|
|
|
|
|
|
ret = virGetInterface(conn, iface->def->name, iface->def->mac);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-07-21 13:45:55 +00:00
|
|
|
virInterfaceDefFree(def);
|
|
|
|
if (iface)
|
|
|
|
virInterfaceObjUnlock(iface);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testInterfaceUndefine(virInterfacePtr iface)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = iface->conn->privateData;
|
|
|
|
virInterfaceObjPtr privinterface;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
privinterface = virInterfaceFindByName(&privconn->ifaces,
|
|
|
|
iface->name);
|
|
|
|
|
|
|
|
if (privinterface == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_INTERFACE, NULL);
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
virInterfaceRemove(&privconn->ifaces,
|
|
|
|
privinterface);
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-07-21 13:45:55 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testInterfaceCreate(virInterfacePtr iface,
|
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-07-21 13:45:55 +00:00
|
|
|
{
|
|
|
|
testConnPtr privconn = iface->conn->privateData;
|
|
|
|
virInterfaceObjPtr privinterface;
|
|
|
|
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);
|
|
|
|
|
2009-07-21 13:45:55 +00:00
|
|
|
testDriverLock(privconn);
|
|
|
|
privinterface = virInterfaceFindByName(&privconn->ifaces,
|
|
|
|
iface->name);
|
|
|
|
|
|
|
|
if (privinterface == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_INTERFACE, NULL);
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (privinterface->active != 0) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, NULL);
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
privinterface->active = 1;
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-07-21 13:45:55 +00:00
|
|
|
if (privinterface)
|
|
|
|
virInterfaceObjUnlock(privinterface);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testInterfaceDestroy(virInterfacePtr iface,
|
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-07-21 13:45:55 +00:00
|
|
|
{
|
|
|
|
testConnPtr privconn = iface->conn->privateData;
|
|
|
|
virInterfaceObjPtr privinterface;
|
|
|
|
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);
|
|
|
|
|
2009-07-21 13:45:55 +00:00
|
|
|
testDriverLock(privconn);
|
|
|
|
privinterface = virInterfaceFindByName(&privconn->ifaces,
|
|
|
|
iface->name);
|
|
|
|
|
|
|
|
if (privinterface == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_INTERFACE, NULL);
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (privinterface->active == 0) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, NULL);
|
2009-07-21 13:45:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
privinterface->active = 0;
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-07-21 13:45:55 +00:00
|
|
|
if (privinterface)
|
|
|
|
virInterfaceObjUnlock(privinterface);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
/*
|
|
|
|
* Storage Driver routines
|
|
|
|
*/
|
|
|
|
|
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-18 08:17:30 +00:00
|
|
|
static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool)
|
|
|
|
{
|
2008-10-30 17:40:57 +00:00
|
|
|
|
|
|
|
pool->def->capacity = defaultPoolCap;
|
|
|
|
pool->def->allocation = defaultPoolAlloc;
|
|
|
|
pool->def->available = defaultPoolCap - defaultPoolAlloc;
|
|
|
|
|
2013-05-03 12:49:30 +00:00
|
|
|
return VIR_STRDUP(pool->configFile, "");
|
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
|
|
|
|
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)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = conn->privateData;
|
2008-12-04 20:57:47 +00:00
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
virStoragePoolPtr ret = NULL;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&privconn->pools, uuid);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (pool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL, NULL);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid,
|
|
|
|
NULL, NULL);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static virStoragePoolPtr
|
|
|
|
testStoragePoolLookupByName(virConnectPtr conn,
|
2014-03-18 08:17:30 +00:00
|
|
|
const char *name)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = conn->privateData;
|
2008-12-04 20:57:47 +00:00
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
virStoragePoolPtr ret = NULL;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
pool = virStoragePoolObjFindByName(&privconn->pools, name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (pool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL, NULL);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid,
|
|
|
|
NULL, NULL);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-18 08:17:30 +00:00
|
|
|
testConnectNumOfStoragePools(virConnectPtr conn)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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;
|
|
|
|
size_t i;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < privconn->pools.count; i++)
|
2008-10-30 17:40:57 +00:00
|
|
|
if (virStoragePoolObjIsActive(privconn->pools.objs[i]))
|
|
|
|
numActive++;
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
|
|
|
return numActive;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testConnectListStoragePools(virConnectPtr conn,
|
|
|
|
char **const names,
|
2014-03-18 08:17:30 +00:00
|
|
|
int nnames)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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;
|
|
|
|
size_t i;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
memset(names, 0, sizeof(*names)*nnames);
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < privconn->pools.count && n < nnames; i++) {
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjLock(privconn->pools.objs[i]);
|
2008-10-30 17:40:57 +00:00
|
|
|
if (virStoragePoolObjIsActive(privconn->pools.objs[i]) &&
|
2013-05-03 12:49:30 +00:00
|
|
|
VIR_STRDUP(names[n++], privconn->pools.objs[i]->def->name) < 0) {
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjUnlock(privconn->pools.objs[i]);
|
2013-05-03 12:49:30 +00:00
|
|
|
goto error;
|
2008-12-04 20:59:06 +00:00
|
|
|
}
|
|
|
|
virStoragePoolObjUnlock(privconn->pools.objs[i]);
|
|
|
|
}
|
|
|
|
testDriverUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
|
|
|
return n;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-05-21 07:21:18 +00:00
|
|
|
for (n = 0; n < nnames; n++)
|
2008-10-30 17:40:57 +00:00
|
|
|
VIR_FREE(names[n]);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:57:47 +00:00
|
|
|
return -1;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-18 08:17:30 +00:00
|
|
|
testConnectNumOfDefinedStoragePools(virConnectPtr conn)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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;
|
|
|
|
size_t i;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < privconn->pools.count; i++) {
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjLock(privconn->pools.objs[i]);
|
2008-10-30 17:40:57 +00:00
|
|
|
if (!virStoragePoolObjIsActive(privconn->pools.objs[i]))
|
|
|
|
numInactive++;
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjUnlock(privconn->pools.objs[i]);
|
|
|
|
}
|
|
|
|
testDriverUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
|
|
|
return numInactive;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testConnectListDefinedStoragePools(virConnectPtr conn,
|
|
|
|
char **const names,
|
2014-03-18 08:17:30 +00:00
|
|
|
int nnames)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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;
|
|
|
|
size_t i;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
memset(names, 0, sizeof(*names)*nnames);
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < privconn->pools.count && n < nnames; i++) {
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjLock(privconn->pools.objs[i]);
|
2008-10-30 17:40:57 +00:00
|
|
|
if (!virStoragePoolObjIsActive(privconn->pools.objs[i]) &&
|
2013-05-03 12:49:30 +00:00
|
|
|
VIR_STRDUP(names[n++], privconn->pools.objs[i]->def->name) < 0) {
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjUnlock(privconn->pools.objs[i]);
|
2013-05-03 12:49:30 +00:00
|
|
|
goto error;
|
2008-12-04 20:59:06 +00:00
|
|
|
}
|
|
|
|
virStoragePoolObjUnlock(privconn->pools.objs[i]);
|
|
|
|
}
|
|
|
|
testDriverUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
|
|
|
return n;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
error:
|
2013-05-21 07:21:18 +00:00
|
|
|
for (n = 0; n < nnames; n++)
|
2008-10-30 17:40:57 +00:00
|
|
|
VIR_FREE(names[n]);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:57:47 +00:00
|
|
|
return -1;
|
2008-10-30 17:40:57 +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
|
|
|
{
|
|
|
|
testConnPtr privconn = conn->privateData;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
2013-06-26 17:47:48 +00:00
|
|
|
ret = virStoragePoolObjListExport(conn, privconn->pools, pools,
|
|
|
|
NULL, flags);
|
2012-09-04 15:16:28 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
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
|
|
|
static int testStoragePoolIsActive(virStoragePoolPtr pool)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
obj = virStoragePoolObjFindByUUID(&privconn->pools, pool->uuid);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
if (!obj) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL, NULL);
|
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;
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
virStoragePoolObjUnlock(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testStoragePoolIsPersistent(virStoragePoolPtr pool)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
obj = virStoragePoolObjFindByUUID(&privconn->pools, pool->uuid);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
if (!obj) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL, NULL);
|
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;
|
|
|
|
}
|
|
|
|
ret = obj->configFile ? 1 : 0;
|
|
|
|
|
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)
|
|
|
|
virStoragePoolObjUnlock(obj);
|
|
|
|
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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
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(0, -1);
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
if (virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is already active"), pool->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-10-30 17:40:57 +00:00
|
|
|
|
|
|
|
privpool->active = 1;
|
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:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
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
|
|
|
virStoragePoolSourcePtr source = NULL;
|
|
|
|
int pool_type;
|
|
|
|
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);
|
|
|
|
|
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);
|
2009-10-16 08:35:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (pool_type) {
|
|
|
|
|
|
|
|
case VIR_STORAGE_POOL_LOGICAL:
|
2013-05-03 12:49:30 +00:00
|
|
|
ignore_value(VIR_STRDUP(ret, defaultPoolSourcesLogicalXML));
|
2009-10-16 08:35:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
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"));
|
2009-10-16 08:35:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-07-04 10:16:47 +00:00
|
|
|
ignore_value(virAsprintf(&ret, defaultPoolSourcesNetFSXML,
|
|
|
|
source->hosts[0].name));
|
2009-10-16 08:35:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-10-16 08:35:05 +00:00
|
|
|
virStoragePoolSourceFree(source);
|
|
|
|
return ret;
|
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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = conn->privateData;
|
2008-10-30 17:40:57 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjPtr pool = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
virStoragePoolPtr ret = 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);
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(def = virStoragePoolDefParseString(xml)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&privconn->pools, def->uuid);
|
|
|
|
if (!pool)
|
|
|
|
pool = virStoragePoolObjFindByName(&privconn->pools, def->name);
|
|
|
|
if (pool) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("storage pool already exists"));
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(pool = virStoragePoolObjAssignDef(&privconn->pools, def)))
|
2008-12-04 20:59:06 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:57:47 +00:00
|
|
|
def = NULL;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2010-02-04 18:19:08 +00:00
|
|
|
if (testStoragePoolObjSetDefaults(pool) == -1) {
|
2008-10-30 17:40:57 +00:00
|
|
|
virStoragePoolObjRemove(&privconn->pools, pool);
|
2008-12-04 20:57:47 +00:00
|
|
|
pool = NULL;
|
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
pool->active = 1;
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid,
|
|
|
|
NULL, NULL);
|
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
|
|
|
virStoragePoolDefFree(def);
|
2008-12-04 20:59:06 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = conn->privateData;
|
2008-10-30 17:40:57 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjPtr pool = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
virStoragePoolPtr ret = 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);
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(def = virStoragePoolDefParseString(xml)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
|
|
|
def->capacity = defaultPoolCap;
|
|
|
|
def->allocation = defaultPoolAlloc;
|
|
|
|
def->available = defaultPoolCap - defaultPoolAlloc;
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(pool = virStoragePoolObjAssignDef(&privconn->pools, def)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2010-02-04 18:19:08 +00:00
|
|
|
if (testStoragePoolObjSetDefaults(pool) == -1) {
|
2008-10-30 17:40:57 +00:00
|
|
|
virStoragePoolObjRemove(&privconn->pools, pool);
|
2008-12-04 20:57:47 +00:00
|
|
|
pool = NULL;
|
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid,
|
|
|
|
NULL, NULL);
|
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
|
|
|
virStoragePoolDefFree(def);
|
2008-12-04 20:59:06 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
testDriverUnlock(privconn);
|
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
|
|
|
testStoragePoolUndefine(virStoragePoolPtr pool)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
if (virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is already active"), pool->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-10-30 17:40:57 +00:00
|
|
|
|
|
|
|
virStoragePoolObjRemove(&privconn->pools, privpool);
|
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:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
|
|
|
testDriverUnlock(privconn);
|
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
|
|
|
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)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
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(0, -1);
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
if (virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is already active"), pool->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-12-07 14:08:37 +00:00
|
|
|
ret = 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
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
|
|
|
testStoragePoolDestroy(virStoragePoolPtr pool)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), pool->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
|
|
|
|
|
|
|
privpool->active = 0;
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool->configFile == NULL) {
|
2008-10-30 17:40:57 +00:00
|
|
|
virStoragePoolObjRemove(&privconn->pools, privpool);
|
2008-12-04 20:59:06 +00:00
|
|
|
privpool = NULL;
|
|
|
|
}
|
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:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
|
|
|
testDriverUnlock(privconn);
|
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)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
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(0, -1);
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is already active"), pool->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +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:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
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
|
|
|
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)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
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(0, -1);
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), pool->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +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:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
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
|
|
|
testStoragePoolGetInfo(virStoragePoolPtr pool,
|
2014-03-18 08:17:30 +00:00
|
|
|
virStoragePoolInfoPtr info)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
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(virStoragePoolInfo));
|
|
|
|
if (privpool->active)
|
|
|
|
info->state = VIR_STORAGE_POOL_RUNNING;
|
|
|
|
else
|
|
|
|
info->state = VIR_STORAGE_POOL_INACTIVE;
|
|
|
|
info->capacity = privpool->def->capacity;
|
|
|
|
info->allocation = privpool->def->allocation;
|
|
|
|
info->available = privpool->def->available;
|
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:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
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)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
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);
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:56:10 +00:00
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
ret = virStoragePoolDefFormat(privpool->def);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
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
|
|
|
testStoragePoolGetAutostart(virStoragePoolPtr pool,
|
2014-03-18 08:17:30 +00:00
|
|
|
int *autostart)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
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
|
|
|
|
|
|
|
if (!privpool->configFile) {
|
|
|
|
*autostart = 0;
|
|
|
|
} else {
|
|
|
|
*autostart = privpool->autostart;
|
|
|
|
}
|
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:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
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
|
|
|
testStoragePoolSetAutostart(virStoragePoolPtr pool,
|
2014-03-18 08:17:30 +00:00
|
|
|
int autostart)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
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
|
|
|
|
|
|
|
if (!privpool->configFile) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
autostart = (autostart != 0);
|
|
|
|
privpool->autostart = autostart;
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
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)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), pool->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
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = privpool->volumes.count;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
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
|
|
|
testStoragePoolListVolumes(virStoragePoolPtr pool,
|
2008-10-30 17:40:57 +00:00
|
|
|
char **const names,
|
2014-03-18 08:17:30 +00:00
|
|
|
int maxnames)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
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;
|
|
|
|
int n = 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
memset(names, 0, maxnames * sizeof(*names));
|
2008-12-04 20:59:06 +00:00
|
|
|
|
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), pool->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < privpool->volumes.count && n < maxnames; i++) {
|
2013-05-03 12:49:30 +00:00
|
|
|
if (VIR_STRDUP(names[n++], privpool->volumes.objs[i]->name) < 0)
|
2008-10-30 17:40:57 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjUnlock(privpool);
|
2008-10-30 17:40:57 +00:00
|
|
|
return n;
|
|
|
|
|
|
|
|
cleanup:
|
2013-05-21 07:21:18 +00:00
|
|
|
for (n = 0; n < maxnames; n++)
|
2008-10-30 17:40:57 +00:00
|
|
|
VIR_FREE(names[i]);
|
|
|
|
|
2008-12-02 15:59:14 +00:00
|
|
|
memset(names, 0, maxnames * sizeof(*names));
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
2008-10-30 17:40:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-09-04 15:32:56 +00:00
|
|
|
static int
|
|
|
|
testStoragePoolListAllVolumes(virStoragePoolPtr obj,
|
|
|
|
virStorageVolPtr **vols,
|
2014-03-18 08:17:30 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2012-09-04 15:32:56 +00:00
|
|
|
testConnPtr privconn = obj->conn->privateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
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;
|
2012-09-04 15:32:56 +00:00
|
|
|
virStorageVolPtr *tmp_vols = NULL;
|
|
|
|
virStorageVolPtr vol = NULL;
|
|
|
|
int nvols = 0;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
pool = virStoragePoolObjFindByUUID(&privconn->pools, obj->uuid);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (!pool) {
|
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL, "%s",
|
|
|
|
_("no storage pool with matching uuid"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("storage pool is not active"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Just returns the volumes count */
|
|
|
|
if (!vols) {
|
|
|
|
ret = pool->volumes.count;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-07-04 10:16:47 +00:00
|
|
|
if (VIR_ALLOC_N(tmp_vols, pool->volumes.count + 1) < 0)
|
2012-09-04 15:32:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < pool->volumes.count; i++) {
|
2012-09-04 15:32:56 +00:00
|
|
|
if (!(vol = virGetStorageVol(obj->conn, pool->def->name,
|
|
|
|
pool->volumes.objs[i]->name,
|
2012-11-10 07:18:07 +00:00
|
|
|
pool->volumes.objs[i]->key,
|
|
|
|
NULL, NULL)))
|
2012-09-04 15:32:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
tmp_vols[nvols++] = vol;
|
|
|
|
}
|
|
|
|
|
|
|
|
*vols = tmp_vols;
|
|
|
|
tmp_vols = NULL;
|
|
|
|
ret = nvols;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (tmp_vols) {
|
|
|
|
for (i = 0; i < nvols; i++) {
|
|
|
|
if (tmp_vols[i])
|
|
|
|
virStorageVolFree(tmp_vols[i]);
|
|
|
|
}
|
2013-01-09 14:54:14 +00:00
|
|
|
VIR_FREE(tmp_vols);
|
2012-09-04 15:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2008-10-30 17:40:57 +00:00
|
|
|
|
|
|
|
static virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
testStorageVolLookupByName(virStoragePoolPtr pool,
|
2014-03-18 08:17:30 +00:00
|
|
|
const char *name ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
|
|
|
virStorageVolDefPtr privvol;
|
2008-12-04 20:57:47 +00:00
|
|
|
virStorageVolPtr ret = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:56:10 +00:00
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), pool->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
privvol = virStorageVolDefFindByName(privpool, name);
|
|
|
|
|
|
|
|
if (!privvol) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"), name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = virGetStorageVol(pool->conn, privpool->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:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
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)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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
|
|
|
size_t i;
|
2008-12-04 20:57:47 +00:00
|
|
|
virStorageVolPtr ret = NULL;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < privconn->pools.count; i++) {
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjLock(privconn->pools.objs[i]);
|
2008-10-30 17:40:57 +00:00
|
|
|
if (virStoragePoolObjIsActive(privconn->pools.objs[i])) {
|
2008-12-04 20:56:10 +00:00
|
|
|
virStorageVolDefPtr privvol =
|
2008-10-30 17:40:57 +00:00
|
|
|
virStorageVolDefFindByKey(privconn->pools.objs[i], key);
|
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
if (privvol) {
|
|
|
|
ret = virGetStorageVol(conn,
|
|
|
|
privconn->pools.objs[i]->def->name,
|
|
|
|
privvol->name,
|
2012-11-10 07:18:07 +00:00
|
|
|
privvol->key,
|
|
|
|
NULL, NULL);
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjUnlock(privconn->pools.objs[i]);
|
2008-12-04 20:57:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjUnlock(privconn->pools.objs[i]);
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
if (!ret)
|
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
|
|
|
|
|
|
|
return ret;
|
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)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr 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
|
|
|
size_t i;
|
2008-12-04 20:57:47 +00:00
|
|
|
virStorageVolPtr ret = NULL;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < privconn->pools.count; i++) {
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjLock(privconn->pools.objs[i]);
|
2008-10-30 17:40:57 +00:00
|
|
|
if (virStoragePoolObjIsActive(privconn->pools.objs[i])) {
|
2008-12-04 20:56:10 +00:00
|
|
|
virStorageVolDefPtr privvol =
|
2008-10-30 17:40:57 +00:00
|
|
|
virStorageVolDefFindByPath(privconn->pools.objs[i], path);
|
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
if (privvol) {
|
|
|
|
ret = virGetStorageVol(conn,
|
|
|
|
privconn->pools.objs[i]->def->name,
|
|
|
|
privvol->name,
|
2012-11-10 07:18:07 +00:00
|
|
|
privvol->key,
|
|
|
|
NULL, NULL);
|
2008-12-04 20:59:06 +00:00
|
|
|
virStoragePoolObjUnlock(privconn->pools.objs[i]);
|
2008-12-04 20:57:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
2008-12-11 15:04:09 +00:00
|
|
|
virStoragePoolObjUnlock(privconn->pools.objs[i]);
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
if (!ret)
|
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
|
|
|
|
|
|
|
return ret;
|
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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
2008-12-04 20:57:47 +00:00
|
|
|
virStorageVolDefPtr privvol = NULL;
|
|
|
|
virStorageVolPtr 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);
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:56:10 +00:00
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), pool->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
|
|
|
|
2015-02-05 15:20:17 +00:00
|
|
|
privvol = virStorageVolDefParseString(privpool->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
|
|
|
|
|
|
|
if (virStorageVolDefFindByName(privpool, 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 */
|
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
|
|
|
if ((privpool->def->allocation + privvol->target.allocation) >
|
2008-10-30 17:40:57 +00:00
|
|
|
privpool->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",
|
|
|
|
privpool->def->target.path,
|
2013-07-04 10:16:47 +00:00
|
|
|
privvol->name) == -1)
|
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 ||
|
|
|
|
VIR_APPEND_ELEMENT_COPY(privpool->volumes.objs,
|
|
|
|
privpool->volumes.count, privvol) < 0)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
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
|
|
|
privpool->def->allocation += privvol->target.allocation;
|
2008-10-30 17:40:57 +00:00
|
|
|
privpool->def->available = (privpool->def->capacity -
|
|
|
|
privpool->def->allocation);
|
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = virGetStorageVol(pool->conn, privpool->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:
|
2008-12-04 20:57:47 +00:00
|
|
|
virStorageVolDefFree(privvol);
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-10-30 17:40:57 +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
|
|
|
{
|
2009-05-12 20:15:56 +00:00
|
|
|
testConnPtr privconn = pool->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
|
|
|
virStorageVolDefPtr privvol = NULL, origvol = NULL;
|
|
|
|
virStorageVolPtr 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);
|
|
|
|
|
2009-05-12 20:15:56 +00:00
|
|
|
testDriverLock(privconn);
|
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
pool->name);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-05-12 20:15:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), pool->name);
|
2009-05-12 20:15:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-02-05 15:20:17 +00:00
|
|
|
privvol = virStorageVolDefParseString(privpool->def, xmldesc, 0);
|
2009-05-12 20:15:56 +00:00
|
|
|
if (privvol == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virStorageVolDefFindByName(privpool, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
origvol = virStorageVolDefFindByName(privpool, clonevol->name);
|
|
|
|
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 */
|
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
|
|
|
if ((privpool->def->allocation + privvol->target.allocation) >
|
2009-05-12 20:15:56 +00:00
|
|
|
privpool->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;
|
|
|
|
}
|
|
|
|
privpool->def->available = (privpool->def->capacity -
|
|
|
|
privpool->def->allocation);
|
|
|
|
|
2009-05-19 13:15:50 +00:00
|
|
|
if (virAsprintf(&privvol->target.path, "%s/%s",
|
|
|
|
privpool->def->target.path,
|
2013-07-04 10:16:47 +00:00
|
|
|
privvol->name) == -1)
|
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 ||
|
|
|
|
VIR_APPEND_ELEMENT_COPY(privpool->volumes.objs,
|
|
|
|
privpool->volumes.count, privvol) < 0)
|
2009-05-12 20:15:56 +00:00
|
|
|
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
|
|
|
privpool->def->allocation += privvol->target.allocation;
|
2009-05-12 20:15:56 +00:00
|
|
|
privpool->def->available = (privpool->def->capacity -
|
|
|
|
privpool->def->allocation);
|
|
|
|
|
|
|
|
ret = virGetStorageVol(pool->conn, privpool->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:
|
2009-05-12 20:15:56 +00:00
|
|
|
virStorageVolDefFree(privvol);
|
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = vol->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
|
|
|
virStorageVolDefPtr privvol;
|
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;
|
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);
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
vol->pool);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
privvol = virStorageVolDefFindByName(privpool, vol->name);
|
|
|
|
|
|
|
|
if (privvol == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
vol->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), vol->pool);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
privpool->def->allocation -= privvol->target.allocation;
|
2008-10-30 17:40:57 +00:00
|
|
|
privpool->def->available = (privpool->def->capacity -
|
|
|
|
privpool->def->allocation);
|
|
|
|
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < privpool->volumes.count; i++) {
|
2008-10-30 17:40:57 +00:00
|
|
|
if (privpool->volumes.objs[i] == privvol) {
|
|
|
|
virStorageVolDefFree(privvol);
|
|
|
|
|
2014-03-07 08:33:31 +00:00
|
|
|
VIR_DELETE_ELEMENT(privpool->volumes.objs, i, privpool->volumes.count);
|
2008-10-30 17:40:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-18 08:17:30 +00:00
|
|
|
static int testStorageVolumeTypeForPool(int pooltype)
|
|
|
|
{
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
switch (pooltype) {
|
2008-10-30 17:40:57 +00:00
|
|
|
case VIR_STORAGE_POOL_DIR:
|
|
|
|
case VIR_STORAGE_POOL_FS:
|
|
|
|
case VIR_STORAGE_POOL_NETFS:
|
|
|
|
return VIR_STORAGE_VOL_FILE;
|
|
|
|
default:
|
|
|
|
return VIR_STORAGE_VOL_BLOCK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
testStorageVolGetInfo(virStorageVolPtr vol,
|
2014-03-18 08:17:30 +00:00
|
|
|
virStorageVolInfoPtr info)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = vol->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
|
|
|
virStorageVolDefPtr privvol;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
vol->pool);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
privvol = virStorageVolDefFindByName(privpool, vol->name);
|
|
|
|
|
|
|
|
if (privvol == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
vol->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), vol->pool);
|
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));
|
|
|
|
info->type = testStorageVolumeTypeForPool(privpool->def->type);
|
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:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
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
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = vol->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
|
|
|
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);
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
vol->pool);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
privvol = virStorageVolDefFindByName(privpool, vol->name);
|
|
|
|
|
|
|
|
if (privvol == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
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
|
|
|
|
2008-12-04 20:56:10 +00:00
|
|
|
if (!virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), vol->pool);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
ret = virStorageVolDefFormat(privpool->def, privvol);
|
2008-12-04 20:57:47 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2008-10-30 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2014-03-18 08:17:30 +00:00
|
|
|
testStorageVolGetPath(virStorageVolPtr vol)
|
|
|
|
{
|
2008-12-04 20:56:10 +00:00
|
|
|
testConnPtr privconn = vol->conn->privateData;
|
|
|
|
virStoragePoolObjPtr privpool;
|
|
|
|
virStorageVolDefPtr privvol;
|
2008-12-04 20:57:47 +00:00
|
|
|
char *ret = NULL;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool = virStoragePoolObjFindByName(&privconn->pools,
|
|
|
|
vol->pool);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
|
|
|
|
if (privpool == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
privvol = virStorageVolDefFindByName(privpool, vol->name);
|
|
|
|
|
|
|
|
if (privvol == NULL) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
vol->name);
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-12-04 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(privpool)) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), vol->pool);
|
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:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privpool)
|
|
|
|
virStoragePoolObjUnlock(privpool);
|
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
|
|
|
|
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
|
|
|
{
|
|
|
|
testConnPtr driver = conn->privateData;
|
|
|
|
int ndevs = 0;
|
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;
|
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);
|
|
|
|
|
2009-10-01 18:54:36 +00:00
|
|
|
testDriverLock(driver);
|
|
|
|
for (i = 0; i < driver->devs.count; i++)
|
|
|
|
if ((cap == NULL) ||
|
|
|
|
virNodeDeviceHasCap(driver->devs.objs[i], cap))
|
|
|
|
++ndevs;
|
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
return ndevs;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
testConnPtr driver = conn->privateData;
|
|
|
|
int ndevs = 0;
|
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;
|
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);
|
|
|
|
|
2009-10-01 18:54:36 +00:00
|
|
|
testDriverLock(driver);
|
|
|
|
for (i = 0; i < driver->devs.count && ndevs < maxnames; i++) {
|
|
|
|
virNodeDeviceObjLock(driver->devs.objs[i]);
|
|
|
|
if (cap == NULL ||
|
|
|
|
virNodeDeviceHasCap(driver->devs.objs[i], cap)) {
|
2013-05-03 12:49:30 +00:00
|
|
|
if (VIR_STRDUP(names[ndevs++], driver->devs.objs[i]->def->name) < 0) {
|
2009-10-01 18:54:36 +00:00
|
|
|
virNodeDeviceObjUnlock(driver->devs.objs[i]);
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virNodeDeviceObjUnlock(driver->devs.objs[i]);
|
|
|
|
}
|
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
return ndevs;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
testDriverUnlock(driver);
|
|
|
|
--ndevs;
|
|
|
|
while (--ndevs >= 0)
|
|
|
|
VIR_FREE(names[ndevs]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virNodeDevicePtr
|
|
|
|
testNodeDeviceLookupByName(virConnectPtr conn, const char *name)
|
|
|
|
{
|
|
|
|
testConnPtr driver = conn->privateData;
|
|
|
|
virNodeDeviceObjPtr obj;
|
|
|
|
virNodeDevicePtr ret = NULL;
|
|
|
|
|
|
|
|
testDriverLock(driver);
|
|
|
|
obj = virNodeDeviceFindByName(&driver->devs, name);
|
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!obj) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_NODE_DEVICE, NULL);
|
2009-10-01 18:54:36 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = virGetNodeDevice(conn, name);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-10-01 18:54:36 +00:00
|
|
|
if (obj)
|
|
|
|
virNodeDeviceObjUnlock(obj);
|
|
|
|
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
|
|
|
{
|
|
|
|
testConnPtr driver = dev->conn->privateData;
|
|
|
|
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);
|
|
|
|
|
2009-10-01 18:54:36 +00:00
|
|
|
testDriverLock(driver);
|
|
|
|
obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!obj) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_NODE_DEVICE,
|
|
|
|
_("no node device with matching name '%s'"),
|
|
|
|
dev->name);
|
2009-10-01 18:54:36 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
ret = virNodeDeviceDefFormat(obj->def);
|
2009-10-01 18:54:36 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-10-01 18:54:36 +00:00
|
|
|
if (obj)
|
|
|
|
virNodeDeviceObjUnlock(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
testNodeDeviceGetParent(virNodeDevicePtr dev)
|
|
|
|
{
|
|
|
|
testConnPtr driver = dev->conn->privateData;
|
|
|
|
virNodeDeviceObjPtr obj;
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
testDriverLock(driver);
|
|
|
|
obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!obj) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_NODE_DEVICE,
|
|
|
|
_("no node device with matching name '%s'"),
|
|
|
|
dev->name);
|
2009-10-01 18:54:36 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj->def->parent) {
|
2013-05-03 12:49:30 +00:00
|
|
|
ignore_value(VIR_STRDUP(ret, obj->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
|
|
|
}
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-10-01 18:54:36 +00:00
|
|
|
if (obj)
|
|
|
|
virNodeDeviceObjUnlock(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:00:50 +00:00
|
|
|
|
2009-10-01 18:54:36 +00:00
|
|
|
static int
|
|
|
|
testNodeDeviceNumOfCaps(virNodeDevicePtr dev)
|
|
|
|
{
|
|
|
|
testConnPtr driver = dev->conn->privateData;
|
|
|
|
virNodeDeviceObjPtr obj;
|
|
|
|
virNodeDevCapsDefPtr caps;
|
|
|
|
int ncaps = 0;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
testDriverLock(driver);
|
|
|
|
obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!obj) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_NODE_DEVICE,
|
|
|
|
_("no node device with matching name '%s'"),
|
|
|
|
dev->name);
|
2009-10-01 18:54:36 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (caps = obj->def->caps; caps; caps = caps->next)
|
|
|
|
++ncaps;
|
|
|
|
ret = ncaps;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-10-01 18:54:36 +00:00
|
|
|
if (obj)
|
|
|
|
virNodeDeviceObjUnlock(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames)
|
|
|
|
{
|
|
|
|
testConnPtr driver = dev->conn->privateData;
|
|
|
|
virNodeDeviceObjPtr obj;
|
|
|
|
virNodeDevCapsDefPtr caps;
|
|
|
|
int ncaps = 0;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
testDriverLock(driver);
|
|
|
|
obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!obj) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_NODE_DEVICE,
|
|
|
|
_("no node device with matching name '%s'"),
|
|
|
|
dev->name);
|
2009-10-01 18:54:36 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) {
|
2015-05-08 16:55:00 +00:00
|
|
|
if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->data.type)) < 0)
|
2009-10-01 18:54:36 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = ncaps;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-10-01 18:54:36 +00:00
|
|
|
if (obj)
|
|
|
|
virNodeDeviceObjUnlock(obj);
|
|
|
|
if (ret == -1) {
|
|
|
|
--ncaps;
|
|
|
|
while (--ncaps >= 0)
|
|
|
|
VIR_FREE(names[ncaps]);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-14 20:16:10 +00:00
|
|
|
static virNodeDevicePtr
|
|
|
|
testNodeDeviceCreateXML(virConnectPtr conn,
|
|
|
|
const char *xmlDesc,
|
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-14 20:16:10 +00:00
|
|
|
{
|
|
|
|
testConnPtr driver = conn->privateData;
|
|
|
|
virNodeDeviceDefPtr def = NULL;
|
|
|
|
virNodeDeviceObjPtr obj = NULL;
|
|
|
|
char *wwnn = NULL, *wwpn = NULL;
|
|
|
|
int parent_host = -1;
|
|
|
|
virNodeDevicePtr dev = NULL;
|
|
|
|
virNodeDevCapsDefPtr caps;
|
|
|
|
|
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-14 20:16:10 +00:00
|
|
|
testDriverLock(driver);
|
|
|
|
|
2012-02-10 04:51:47 +00:00
|
|
|
def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, NULL);
|
2014-11-13 14:24:39 +00:00
|
|
|
if (def == NULL)
|
2009-10-14 20:16:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* We run these next two simply for validation */
|
2014-11-13 14:24:39 +00:00
|
|
|
if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1)
|
2009-10-14 20:16:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDeviceGetParentHost(&driver->devs,
|
2009-10-14 20:16:10 +00:00
|
|
|
def->name,
|
|
|
|
def->parent,
|
|
|
|
&parent_host) == -1) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 'name' is supposed to be filled in by the node device backend, which
|
|
|
|
* we don't have. Use WWPN instead. */
|
|
|
|
VIR_FREE(def->name);
|
2013-05-03 12:49:30 +00:00
|
|
|
if (VIR_STRDUP(def->name, wwpn) < 0)
|
2009-10-14 20:16:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-06-05 17:17:05 +00:00
|
|
|
/* Fill in a random 'host' and 'unique_id' value,
|
|
|
|
* since this would also come from the backend */
|
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;
|
|
|
|
|
2012-01-25 15:17:46 +00:00
|
|
|
caps->data.scsi_host.host = virRandomBits(10);
|
2014-06-05 17:17:05 +00:00
|
|
|
caps->data.scsi_host.unique_id = 2;
|
2009-10-14 20:16:10 +00:00
|
|
|
caps = caps->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-13 14:24:39 +00:00
|
|
|
if (!(obj = virNodeDeviceAssignDef(&driver->devs, def)))
|
2009-10-14 20:16:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
virNodeDeviceObjUnlock(obj);
|
|
|
|
|
|
|
|
dev = virGetNodeDevice(conn, def->name);
|
|
|
|
def = NULL;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2009-10-14 20:16:10 +00:00
|
|
|
testDriverUnlock(driver);
|
2010-05-17 20:38:59 +00:00
|
|
|
virNodeDeviceDefFree(def);
|
2009-10-14 20:16:10 +00:00
|
|
|
VIR_FREE(wwnn);
|
|
|
|
VIR_FREE(wwpn);
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testNodeDeviceDestroy(virNodeDevicePtr dev)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
testConnPtr driver = dev->conn->privateData;
|
|
|
|
virNodeDeviceObjPtr obj = NULL;
|
|
|
|
char *parent_name = NULL, *wwnn = NULL, *wwpn = NULL;
|
|
|
|
int parent_host = -1;
|
|
|
|
|
|
|
|
testDriverLock(driver);
|
|
|
|
obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!obj) {
|
2012-07-18 12:12:06 +00:00
|
|
|
virReportError(VIR_ERR_NO_NODE_DEVICE, NULL);
|
2009-10-14 20:16:10 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:24:39 +00:00
|
|
|
if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) == -1)
|
2009-10-14 20:16:10 +00:00
|
|
|
goto out;
|
|
|
|
|
2013-05-03 12:49:30 +00:00
|
|
|
if (VIR_STRDUP(parent_name, obj->def->parent) < 0)
|
2009-10-14 20:16:10 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* virNodeDeviceGetParentHost will cause the device object's lock to be
|
|
|
|
* taken, so we have to dup the parent's name and drop the lock
|
|
|
|
* before calling it. We don't need the reference to the object
|
|
|
|
* any more once we have the parent's name. */
|
|
|
|
virNodeDeviceObjUnlock(obj);
|
|
|
|
|
|
|
|
/* We do this just for basic validation */
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDeviceGetParentHost(&driver->devs,
|
2009-10-14 20:16:10 +00:00
|
|
|
dev->name,
|
|
|
|
parent_name,
|
|
|
|
&parent_host) == -1) {
|
|
|
|
obj = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
virNodeDeviceObjLock(obj);
|
|
|
|
virNodeDeviceObjRemove(&driver->devs, obj);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
out:
|
2009-10-14 20:16:10 +00:00
|
|
|
if (obj)
|
|
|
|
virNodeDeviceObjUnlock(obj);
|
|
|
|
VIR_FREE(parent_name);
|
|
|
|
VIR_FREE(wwnn);
|
|
|
|
VIR_FREE(wwpn);
|
|
|
|
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
|
|
|
{
|
|
|
|
testConnPtr 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
|
|
|
|
|
|
|
testDriverLock(driver);
|
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
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
testConnPtr 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
|
|
|
|
|
|
|
testDriverLock(driver);
|
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
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
testConnPtr driver = conn->privateData;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
testDriverLock(driver);
|
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
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
testConnPtr 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
|
|
|
|
|
|
|
testDriverLock(driver);
|
2014-01-04 13:14:33 +00:00
|
|
|
if (virObjectEventStateDeregisterID(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
|
|
|
callbackID) < 0)
|
|
|
|
ret = -1;
|
2010-03-18 14:47:07 +00:00
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
testConnPtr driver = conn->privateData;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
testDriverLock(driver);
|
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;
|
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testConnectNetworkEventDeregisterAny(virConnectPtr conn,
|
|
|
|
int callbackID)
|
|
|
|
{
|
|
|
|
testConnPtr 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
|
|
|
|
|
|
|
testDriverLock(driver);
|
2014-01-04 13:14:33 +00:00
|
|
|
if (virObjectEventStateDeregisterID(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
|
|
|
callbackID) < 0)
|
|
|
|
ret = -1;
|
2013-12-11 10:37:59 +00:00
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-20 20:23:53 +00:00
|
|
|
/* driver must be locked before calling */
|
2013-11-25 13:16:02 +00:00
|
|
|
static void testObjectEventQueue(testConnPtr driver,
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event)
|
2009-01-20 20:23:53 +00:00
|
|
|
{
|
2014-01-04 13:14:33 +00:00
|
|
|
virObjectEventStateQueue(driver->eventState, event);
|
2009-01-20 20:23:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-24 16:49:47 +00:00
|
|
|
|
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
|
|
|
{
|
|
|
|
testConnPtr privconn = conn->privateData;
|
|
|
|
int ret;
|
|
|
|
|
2012-08-03 15:48:05 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
|
2012-06-11 09:04:57 +00:00
|
|
|
|
|
|
|
testDriverLock(privconn);
|
2013-06-24 16:49:47 +00:00
|
|
|
ret = virDomainObjListExport(privconn->domains, conn, domains,
|
|
|
|
NULL, flags);
|
2012-06-11 09:04:57 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-16 14:05:15 +00:00
|
|
|
static int
|
|
|
|
testNodeGetCPUMap(virConnectPtr conn,
|
|
|
|
unsigned char **cpumap,
|
|
|
|
unsigned int *online,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = conn->privateData;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
if (cpumap) {
|
2013-07-04 10:16:47 +00:00
|
|
|
if (VIR_ALLOC_N(*cpumap, 1) < 0)
|
2012-10-16 14:05:15 +00:00
|
|
|
goto cleanup;
|
|
|
|
*cpumap[0] = 0x15;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (online)
|
|
|
|
*online = 3;
|
|
|
|
|
|
|
|
ret = 8;
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2012-10-16 14:05:15 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2013-09-24 09:57:37 +00:00
|
|
|
if (virFDStreamOpenFile(st, PKGDATADIR "/libvirtLogo.png", 0, 0, O_RDONLY) < 0)
|
2013-03-29 21:25:13 +00:00
|
|
|
VIR_FREE(ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-09-23 09:46:02 +00:00
|
|
|
static int
|
|
|
|
testConnectGetCPUModelNames(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
const char *arch,
|
|
|
|
char ***models,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
return cpuGetModels(arch, models);
|
|
|
|
}
|
2012-06-11 09:04:57 +00:00
|
|
|
|
2013-08-06 23:33:25 +00:00
|
|
|
static int
|
|
|
|
testDomainManagedSave(virDomainPtr dom, unsigned int flags)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = dom->conn->privateData;
|
|
|
|
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);
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
vm = virDomainObjListFindByName(privconn->domains, dom->name);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
if (vm == NULL) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virDomainObjIsActive(vm)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
"%s", _("domain is not running"));
|
|
|
|
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);
|
2013-08-06 23:33:25 +00:00
|
|
|
if (event) {
|
|
|
|
testDriverLock(privconn);
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2013-08-06 23:33:25 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
|
|
|
|
vm = virDomainObjListFindByName(privconn->domains, dom->name);
|
|
|
|
if (vm == NULL) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = vm->hasManagedSave;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 23:33:25 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
|
|
|
|
vm = virDomainObjListFindByName(privconn->domains, dom->name);
|
|
|
|
if (vm == NULL) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vm->hasManagedSave = false;
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2015-04-23 16:00:01 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2013-08-06 23:33:25 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-06 15:20:37 +00:00
|
|
|
/*
|
|
|
|
* Snapshot APIs
|
|
|
|
*/
|
|
|
|
|
|
|
|
static virDomainSnapshotObjPtr
|
|
|
|
testSnapObjFromName(virDomainObjPtr vm,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
virDomainSnapshotObjPtr snap = NULL;
|
|
|
|
snap = virDomainSnapshotFindByName(vm->snapshots, name);
|
|
|
|
if (!snap)
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
|
|
|
|
_("no domain snapshot with matching name '%s'"),
|
|
|
|
name);
|
|
|
|
return snap;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainSnapshotObjPtr
|
|
|
|
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;
|
|
|
|
int n = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
n = virDomainSnapshotObjListNum(vm->snapshots, NULL, flags);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-06 15:20:37 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotListNames(virDomainPtr domain,
|
|
|
|
char **names,
|
|
|
|
int nameslen,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
int n = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
n = virDomainSnapshotObjListGetNames(vm->snapshots, NULL, names, nameslen,
|
|
|
|
flags);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-06 15:20:37 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainListAllSnapshots(virDomainPtr domain,
|
|
|
|
virDomainSnapshotPtr **snaps,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
int n = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
n = virDomainListSnapshots(vm->snapshots, NULL, domain, snaps, flags);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-06 15:20:37 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot,
|
|
|
|
char **names,
|
|
|
|
int nameslen,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainSnapshotObjPtr snap = NULL;
|
|
|
|
int n = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
n = virDomainSnapshotObjListGetNames(vm->snapshots, snap, names, nameslen,
|
|
|
|
flags);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-06 15:20:37 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainSnapshotObjPtr snap = NULL;
|
|
|
|
int n = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
n = virDomainSnapshotObjListNum(vm->snapshots, snap, flags);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-06 15:20:37 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotListAllChildren(virDomainSnapshotPtr snapshot,
|
|
|
|
virDomainSnapshotPtr **snaps,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainSnapshotObjPtr snap = NULL;
|
|
|
|
int n = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
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:
|
2013-08-06 15:20:37 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainSnapshotPtr
|
|
|
|
testDomainSnapshotLookupByName(virDomainPtr domain,
|
|
|
|
const char *name,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainSnapshotObjPtr snap = NULL;
|
|
|
|
virDomainSnapshotPtr snapshot = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(snap = testSnapObjFromName(vm, name)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
snapshot = virGetDomainSnapshot(domain, snap->def->name);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-06 15:20:37 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainHasCurrentSnapshot(virDomainPtr domain,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = (vm->current_snapshot != NULL);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-06 15:20:37 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainSnapshotPtr
|
|
|
|
testDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainSnapshotObjPtr snap = NULL;
|
|
|
|
virDomainSnapshotPtr parent = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!snap->def->parent) {
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
|
|
|
|
_("snapshot '%s' does not have a parent"),
|
|
|
|
snap->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = virGetDomainSnapshot(snapshot->domain, snap->def->parent);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-06 15:20:37 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainSnapshotPtr
|
|
|
|
testDomainSnapshotCurrent(virDomainPtr domain,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainSnapshotPtr snapshot = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromDomain(domain)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!vm->current_snapshot) {
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT, "%s",
|
|
|
|
_("the domain does not have a current snapshot"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot = virGetDomainSnapshot(domain, vm->current_snapshot->def->name);
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-06 15:20:37 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
testDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
char *xml = NULL;
|
|
|
|
virDomainSnapshotObjPtr snap = NULL;
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_XML_SECURE, NULL);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
virUUIDFormat(snapshot->domain->uuid, uuidstr);
|
|
|
|
|
2014-11-18 16:44:00 +00:00
|
|
|
xml = virDomainSnapshotDefFormat(uuidstr, snap->def,
|
|
|
|
virDomainDefFormatConvertXMLFlags(flags),
|
|
|
|
0);
|
2013-08-06 15:20:37 +00:00
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-06 15:20:37 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = (vm->current_snapshot &&
|
|
|
|
STREQ(snapshot->name, vm->current_snapshot->def->name));
|
|
|
|
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-06 15:20:37 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (!(vm = testDomObjFromSnapshot(snapshot)))
|
|
|
|
goto cleanup;
|
|
|
|
|
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:
|
2013-08-06 15:20:37 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
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))
|
|
|
|
def->state = VIR_DOMAIN_DISK_SNAPSHOT;
|
|
|
|
else
|
|
|
|
def->state = VIR_DOMAIN_SHUTOFF;
|
|
|
|
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);
|
|
|
|
def->memory = def->state == VIR_DOMAIN_SHUTOFF ?
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = domain->conn->privateData;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainSnapshotDefPtr def = NULL;
|
|
|
|
virDomainSnapshotObjPtr snap = NULL;
|
|
|
|
virDomainSnapshotPtr snapshot = NULL;
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event = NULL;
|
2013-08-07 17:40:46 +00:00
|
|
|
char *xml = 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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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,
|
|
|
|
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,
|
|
|
|
&update_current, flags) < 0)
|
2013-08-21 20:54:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
if (!(def->dom = virDomainDefCopy(vm->def,
|
|
|
|
privconn->caps,
|
|
|
|
privconn->xmlopt,
|
|
|
|
true)))
|
|
|
|
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) {
|
|
|
|
if (vm->current_snapshot &&
|
|
|
|
(VIR_STRDUP(snap->def->parent,
|
|
|
|
vm->current_snapshot->def->name) < 0))
|
|
|
|
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
|
|
|
|
|
|
|
snapshot = virGetDomainSnapshot(domain, snap->def->name);
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-07 17:40:46 +00:00
|
|
|
VIR_FREE(xml);
|
|
|
|
if (vm) {
|
|
|
|
if (snapshot) {
|
|
|
|
virDomainSnapshotObjPtr other;
|
2013-08-21 20:54:17 +00:00
|
|
|
if (update_current)
|
|
|
|
vm->current_snapshot = snap;
|
2013-08-07 17:40:46 +00:00
|
|
|
other = virDomainSnapshotFindByName(vm->snapshots,
|
|
|
|
snap->def->parent);
|
|
|
|
snap->parent = other;
|
|
|
|
other->nchildren++;
|
|
|
|
snap->sibling = other->first_child;
|
|
|
|
other->first_child = snap;
|
|
|
|
}
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
}
|
|
|
|
if (event) {
|
|
|
|
testDriverLock(privconn);
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2013-08-07 17:40:46 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
}
|
|
|
|
virDomainSnapshotDefFree(def);
|
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _testSnapRemoveData testSnapRemoveData;
|
|
|
|
typedef testSnapRemoveData *testSnapRemoveDataPtr;
|
|
|
|
struct _testSnapRemoveData {
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
bool current;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
testDomainSnapshotDiscardAll(void *payload,
|
|
|
|
const void *name ATTRIBUTE_UNUSED,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
virDomainSnapshotObjPtr snap = payload;
|
|
|
|
testSnapRemoveDataPtr curr = data;
|
|
|
|
|
|
|
|
if (snap->def->current)
|
|
|
|
curr->current = true;
|
|
|
|
virDomainSnapshotObjListRemove(curr->vm->snapshots, snap);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct _testSnapReparentData testSnapReparentData;
|
|
|
|
typedef testSnapReparentData *testSnapReparentDataPtr;
|
|
|
|
struct _testSnapReparentData {
|
|
|
|
virDomainSnapshotObjPtr parent;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int err;
|
|
|
|
virDomainSnapshotObjPtr last;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
testDomainSnapshotReparentChildren(void *payload,
|
|
|
|
const void *name ATTRIBUTE_UNUSED,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
virDomainSnapshotObjPtr snap = payload;
|
|
|
|
testSnapReparentDataPtr rep = data;
|
|
|
|
|
2014-11-13 14:24:39 +00:00
|
|
|
if (rep->err < 0)
|
2013-08-07 17:40:46 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
VIR_FREE(snap->def->parent);
|
|
|
|
snap->parent = rep->parent;
|
|
|
|
|
|
|
|
if (rep->parent->def &&
|
|
|
|
VIR_STRDUP(snap->def->parent, rep->parent->def->name) < 0) {
|
|
|
|
rep->err = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!snap->sibling)
|
|
|
|
rep->last = snap;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainSnapshotObjPtr snap = NULL;
|
|
|
|
virDomainSnapshotObjPtr parentsnap = NULL;
|
|
|
|
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;
|
|
|
|
virDomainSnapshotForEachDescendant(snap,
|
|
|
|
testDomainSnapshotDiscardAll,
|
|
|
|
&rem);
|
|
|
|
if (rem.current) {
|
2014-11-13 14:24:39 +00:00
|
|
|
if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)
|
2013-08-07 17:40:46 +00:00
|
|
|
snap->def->current = true;
|
|
|
|
vm->current_snapshot = snap;
|
|
|
|
}
|
|
|
|
} else if (snap->nchildren) {
|
|
|
|
testSnapReparentData rep;
|
|
|
|
rep.parent = snap->parent;
|
|
|
|
rep.vm = vm;
|
|
|
|
rep.err = 0;
|
|
|
|
rep.last = NULL;
|
|
|
|
virDomainSnapshotForEachChild(snap,
|
|
|
|
testDomainSnapshotReparentChildren,
|
|
|
|
&rep);
|
|
|
|
if (rep.err < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Can't modify siblings during ForEachChild, so do it now. */
|
|
|
|
snap->parent->nchildren += snap->nchildren;
|
|
|
|
rep.last->sibling = snap->parent->first_child;
|
|
|
|
snap->parent->first_child = snap->first_child;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) {
|
|
|
|
snap->nchildren = 0;
|
|
|
|
snap->first_child = NULL;
|
|
|
|
} else {
|
|
|
|
virDomainSnapshotDropParent(snap);
|
|
|
|
if (snap == vm->current_snapshot) {
|
|
|
|
if (snap->def->parent) {
|
|
|
|
parentsnap = virDomainSnapshotFindByName(vm->snapshots,
|
|
|
|
snap->def->parent);
|
|
|
|
if (!parentsnap) {
|
|
|
|
VIR_WARN("missing parent snapshot matching name '%s'",
|
|
|
|
snap->def->parent);
|
|
|
|
} else {
|
|
|
|
parentsnap->def->current = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vm->current_snapshot = parentsnap;
|
|
|
|
}
|
|
|
|
virDomainSnapshotObjListRemove(vm->snapshots, snap);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-07 17:40:46 +00:00
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = snapshot->domain->conn->privateData;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainSnapshotObjPtr 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;
|
|
|
|
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;
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
|
|
|
|
if (!vm->persistent &&
|
|
|
|
snap->def->state != VIR_DOMAIN_RUNNING &&
|
|
|
|
snap->def->state != VIR_DOMAIN_PAUSED &&
|
|
|
|
(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)) {
|
|
|
|
if (!snap->def->dom) {
|
|
|
|
virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY,
|
|
|
|
_("snapshot '%s' lacks domain '%s' rollback info"),
|
|
|
|
snap->def->name, vm->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virDomainObjIsActive(vm) &&
|
|
|
|
!(snap->def->state == VIR_DOMAIN_RUNNING
|
|
|
|
|| snap->def->state == VIR_DOMAIN_PAUSED) &&
|
|
|
|
(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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (vm->current_snapshot) {
|
|
|
|
vm->current_snapshot->def->current = false;
|
|
|
|
vm->current_snapshot = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
snap->def->current = true;
|
|
|
|
config = virDomainDefCopy(snap->def->dom,
|
|
|
|
privconn->caps, privconn->xmlopt, true);
|
|
|
|
if (!config)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (snap->def->state == VIR_DOMAIN_RUNNING ||
|
|
|
|
snap->def->state == VIR_DOMAIN_PAUSED) {
|
|
|
|
/* 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. */
|
|
|
|
if (!virDomainDefCheckABIStability(vm->def, config)) {
|
|
|
|
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);
|
|
|
|
if (event)
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, 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) &&
|
|
|
|
(snap->def->state == VIR_DOMAIN_PAUSED ||
|
|
|
|
(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;
|
|
|
|
|
|
|
|
if (event)
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vm->current_snapshot = snap;
|
|
|
|
ret = 0;
|
2014-03-25 06:52:53 +00:00
|
|
|
cleanup:
|
2013-08-07 17:40:46 +00:00
|
|
|
if (event) {
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, event);
|
2013-08-07 17:40:46 +00:00
|
|
|
if (event2)
|
2013-11-25 13:16:02 +00:00
|
|
|
testObjectEventQueue(privconn, 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
|
|
|
}
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-06 15:20:37 +00:00
|
|
|
|
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 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectGetCapabilities = testConnectGetCapabilities, /* 0.2.1 */
|
|
|
|
.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 */
|
|
|
|
.domainGetOSType = testDomainGetOSType, /* 0.1.9 */
|
|
|
|
.domainGetMaxMemory = testDomainGetMaxMemory, /* 0.1.4 */
|
|
|
|
.domainSetMaxMemory = testDomainSetMaxMemory, /* 0.1.1 */
|
|
|
|
.domainSetMemory = testDomainSetMemory, /* 0.1.4 */
|
|
|
|
.domainGetInfo = testDomainGetInfo, /* 0.1.1 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainGetState = testDomainGetState, /* 0.9.2 */
|
|
|
|
.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 */
|
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 */
|
|
|
|
.domainGetMaxVcpus = testDomainGetMaxVcpus, /* 0.7.3 */
|
|
|
|
.domainGetXMLDesc = testDomainGetXMLDesc, /* 0.1.4 */
|
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 */
|
|
|
|
.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 */
|
|
|
|
.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 */
|
2013-03-29 21:25:13 +00:00
|
|
|
.domainScreenshot = testDomainScreenshot, /* 1.0.5 */
|
2013-09-09 16:02:59 +00:00
|
|
|
.domainGetMetadata = testDomainGetMetadata, /* 1.1.3 */
|
|
|
|
.domainSetMetadata = testDomainSetMetadata, /* 1.1.3 */
|
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 */
|
|
|
|
|
|
|
|
.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 */
|
|
|
|
.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 */
|
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 = {
|
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 = {
|
|
|
|
.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
|
|
|
}
|