2006-06-06 03:32:51 +00:00
|
|
|
/*
|
|
|
|
* test.c: A "mock" hypervisor for use by application unit tests
|
|
|
|
*
|
2011-12-14 10:50:40 +00:00
|
|
|
* Copyright (C) 2006-2012 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>
|
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-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"
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_TEST
|
|
|
|
|
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
|
|
|
|
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;
|
2008-10-10 14:50:26 +00:00
|
|
|
virNetworkObjList 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];
|
2009-01-20 20:23:53 +00:00
|
|
|
|
2011-05-12 12:58:44 +00:00
|
|
|
virDomainEventStatePtr domainEventState;
|
2007-07-27 23:23:00 +00:00
|
|
|
};
|
|
|
|
typedef struct _testConn testConn;
|
|
|
|
typedef struct _testConn *testConnPtr;
|
2006-06-06 03:32:51 +00:00
|
|
|
|
2007-03-15 17:24:56 +00:00
|
|
|
#define TEST_MODEL "i686"
|
2008-02-27 04:35:08 +00:00
|
|
|
#define TEST_MODEL_WORDSIZE 32
|
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);
|
2009-01-20 20:23:53 +00:00
|
|
|
static void testDomainEventQueue(testConnPtr driver,
|
|
|
|
virDomainEventPtr event);
|
|
|
|
|
|
|
|
|
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-03-31 18:03:42 +00:00
|
|
|
static virDomainXMLOptionPtr
|
2013-03-05 15:17:24 +00:00
|
|
|
testBuildXMLConfig(void)
|
|
|
|
{
|
|
|
|
virDomainXMLPrivateDataCallbacks priv = { .alloc = testDomainObjPrivateAlloc,
|
|
|
|
.free = testDomainObjPrivateFree };
|
2013-02-19 16:29:39 +00:00
|
|
|
return virDomainXMLOptionNew(NULL, &priv, NULL);
|
2013-03-05 15:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
static virCapsPtr
|
|
|
|
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;
|
|
|
|
const char *const guest_types[] = { "hvm", "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
|
|
|
|
2012-12-10 22:28:09 +00:00
|
|
|
if ((caps = virCapabilitiesNew(VIR_ARCH_I686, 0, 0)) == 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;
|
2008-07-11 16:41:27 +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);
|
|
|
|
|
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
if (virCapabilitiesAddHostNUMACell(caps, i, privconn->cells[i].numCpus,
|
2013-03-07 16:03:36 +00:00
|
|
|
0, cpu_cells) < 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,
|
|
|
|
"test",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL) == NULL)
|
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
|
|
|
if (virCapabilitiesAddGuestFeature(guest, "pae", 1, 1) == NULL)
|
2013-07-04 10:16:47 +00:00
|
|
|
goto error;
|
2008-07-11 16:41:27 +00:00
|
|
|
if (virCapabilitiesAddGuestFeature(guest ,"nonpae", 1, 1) == 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
|
|
|
|
2013-05-03 12:49:30 +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);
|
2008-10-30 17:40:57 +00:00
|
|
|
static const unsigned long long defaultPoolAlloc = 0;
|
|
|
|
|
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
|
|
|
|
2009-07-24 15:05:29 +00:00
|
|
|
static char *
|
2010-04-02 21:56:10 +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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
cleanup:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-10-27 18:06:30 +00:00
|
|
|
ret = 0;
|
|
|
|
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
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
static int testOpenDefault(virConnectPtr conn) {
|
2007-01-18 21:08:21 +00:00
|
|
|
int u;
|
2008-05-29 19:20:22 +00:00
|
|
|
testConnPtr privconn;
|
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
|
|
|
|
2013-07-04 10:16:47 +00:00
|
|
|
if (VIR_ALLOC(privconn) < 0)
|
2007-07-27 23:23:00 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
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"));
|
2009-01-15 19:56:05 +00:00
|
|
|
VIR_FREE(privconn);
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2009-01-15 19:56:05 +00:00
|
|
|
conn->privateData = privconn;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2013-01-11 16:04:47 +00:00
|
|
|
if (!(privconn->domains = virDomainObjListNew()))
|
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,
|
2011-07-11 17:29:09 +00:00
|
|
|
1 << VIR_DOMAIN_VIRT_TEST,
|
2009-01-08 13:54:20 +00:00
|
|
|
VIR_DOMAIN_XML_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;
|
2012-09-14 15:35:35 +00:00
|
|
|
if (!(netobj = virNetworkAssignDef(&privconn->networks, netdef, false))) {
|
2008-07-11 16:41:27 +00:00
|
|
|
virNetworkDefFree(netdef);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
netobj->active = 1;
|
|
|
|
netobj->persistent = 1;
|
2008-12-04 20:59:06 +00:00
|
|
|
virNetworkObjUnlock(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);
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2009-01-15 19:56:05 +00:00
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
|
|
|
|
error:
|
2013-01-11 13:54:15 +00:00
|
|
|
virObjectUnref(privconn->domains);
|
2008-10-10 14:50:26 +00:00
|
|
|
virNetworkObjListFree(&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);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
2009-01-15 19:56:05 +00:00
|
|
|
conn->privateData = NULL;
|
2008-07-11 16:41:27 +00:00
|
|
|
VIR_FREE(privconn);
|
2009-09-02 13:02:06 +00:00
|
|
|
virDomainDefFree(domdef);
|
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,
|
2007-01-18 21:08:21 +00:00
|
|
|
const char *filename) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
error:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (num < 0) {
|
2007-01-18 21:08:21 +00:00
|
|
|
goto error;
|
2006-08-16 16:36:39 +00:00
|
|
|
}
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2008-07-11 16:41:27 +00:00
|
|
|
virDomainDefPtr def;
|
2013-08-06 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,
|
|
|
|
1 << VIR_DOMAIN_VIRT_TEST,
|
|
|
|
VIR_DOMAIN_XML_INACTIVE);
|
|
|
|
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-06 18:45:02 +00:00
|
|
|
obj->persistent = 1;
|
2013-08-06 18:59:45 +00:00
|
|
|
if (testDomainStartState(privconn, obj,
|
|
|
|
VIR_DOMAIN_RUNNING_BOOTED) < 0) {
|
2013-08-06 18:45:02 +00:00
|
|
|
virObjectUnlock(obj);
|
2009-10-27 17:15:44 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
error:
|
|
|
|
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);
|
|
|
|
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
|
|
|
|
|
|
|
if (!(obj = virNetworkAssignDef(&privconn->networks, def, false))) {
|
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->persistent = 1;
|
|
|
|
obj->active = 1;
|
|
|
|
virNetworkObjUnlock(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;
|
|
|
|
error:
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
error:
|
|
|
|
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);
|
|
|
|
if (num < 0) {
|
|
|
|
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
|
|
|
|
2013-08-06 20:56:50 +00:00
|
|
|
def = virStorageVolDefParseNode(pool->def, ctxt->doc, node);
|
|
|
|
if (!def)
|
|
|
|
goto error;
|
2013-08-06 18:45:02 +00:00
|
|
|
|
|
|
|
if (VIR_REALLOC_N(pool->volumes.objs,
|
|
|
|
pool->volumes.count+1) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
pool->def->allocation += def->allocation;
|
|
|
|
pool->def->available = (pool->def->capacity -
|
|
|
|
pool->def->allocation);
|
|
|
|
|
|
|
|
pool->volumes.objs[pool->volumes.count++] = def;
|
|
|
|
def = NULL;
|
2009-07-21 13:45:55 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 18:45:02 +00:00
|
|
|
ret = 0;
|
|
|
|
error:
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
error:
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
error:
|
|
|
|
VIR_FREE(nodes);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (!(privconn->domains = virDomainObjListNew()))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(privconn->caps = testBuildCapabilities(conn)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(privconn->xmlopt = testBuildXMLConfig()))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(doc = virXMLParseFileCtxt(file, &ctxt))) {
|
|
|
|
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;
|
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);
|
2008-10-10 14:50:26 +00:00
|
|
|
virNetworkObjListFree(&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);
|
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
|
|
|
}
|
|
|
|
|
2006-06-06 03:32:51 +00:00
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static virDrvOpenStatus testConnectOpen(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags)
|
2006-06-06 03:32:51 +00:00
|
|
|
{
|
2007-07-27 23:23:00 +00:00
|
|
|
int ret;
|
2011-05-12 12:58:44 +00:00
|
|
|
testConnPtr privconn;
|
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;
|
|
|
|
|
|
|
|
privconn = conn->privateData;
|
|
|
|
testDriverLock(privconn);
|
2009-01-20 20:23:53 +00:00
|
|
|
|
2011-12-14 00:25:58 +00:00
|
|
|
privconn->domainEventState = virDomainEventStateNew();
|
2011-05-12 12:58:44 +00:00
|
|
|
if (!privconn->domainEventState) {
|
2009-05-19 11:06:25 +00:00
|
|
|
testDriverUnlock(privconn);
|
2013-04-23 12:50:18 +00:00
|
|
|
testConnectClose(conn);
|
2011-05-12 12:58:44 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
2009-01-20 20:23:53 +00:00
|
|
|
}
|
|
|
|
|
2011-05-12 12:58:44 +00:00
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
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;
|
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);
|
2008-10-10 14:50:26 +00:00
|
|
|
virNetworkObjListFree(&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-05-12 12:58:44 +00:00
|
|
|
virDomainEventStateFree(privconn->domainEventState);
|
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
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2008-12-04 20:57:47 +00:00
|
|
|
if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL)
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
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);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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;
|
2009-01-20 20:23:53 +00:00
|
|
|
virDomainEventPtr event = NULL;
|
2006-08-16 16:36:39 +00:00
|
|
|
|
2010-05-25 17:13:13 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
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,
|
|
|
|
1 << VIR_DOMAIN_VIRT_TEST,
|
2009-01-08 13:54:20 +00:00
|
|
|
VIR_DOMAIN_XML_INACTIVE)) == 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
|
|
|
|
2009-01-20 20:23:53 +00:00
|
|
|
event = virDomainEventNewFromObj(dom,
|
|
|
|
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
|
|
|
|
|
|
|
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)
|
|
|
|
testDomainEventQueue(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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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 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;
|
2009-01-20 20:23:53 +00:00
|
|
|
virDomainEventPtr 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);
|
2009-01-20 20:23:53 +00:00
|
|
|
event = virDomainEventNewFromObj(privdom,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
|
2009-11-03 17:06:00 +00:00
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
if (!privdom->persistent) {
|
2013-01-11 16:04:47 +00:00
|
|
|
virDomainObjListRemove(privconn->domains,
|
|
|
|
privdom);
|
2008-12-04 20:59:06 +00:00
|
|
|
privdom = NULL;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2008-12-04 20:57:47 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(privdom);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
|
|
|
testDomainEventQueue(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;
|
2009-01-20 20:23:53 +00:00
|
|
|
virDomainEventPtr 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);
|
2009-01-20 20:23:53 +00:00
|
|
|
event = virDomainEventNewFromObj(privdom,
|
|
|
|
VIR_DOMAIN_EVENT_RESUMED,
|
|
|
|
VIR_DOMAIN_EVENT_RESUMED_UNPAUSED);
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(privdom);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event) {
|
|
|
|
testDriverLock(privconn);
|
|
|
|
testDomainEventQueue(privconn, event);
|
|
|
|
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;
|
2009-01-20 20:23:53 +00:00
|
|
|
virDomainEventPtr 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);
|
2009-01-20 20:23:53 +00:00
|
|
|
event = virDomainEventNewFromObj(privdom,
|
|
|
|
VIR_DOMAIN_EVENT_SUSPENDED,
|
|
|
|
VIR_DOMAIN_EVENT_SUSPENDED_PAUSED);
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(privdom);
|
2009-01-20 20:23:53 +00:00
|
|
|
|
|
|
|
if (event) {
|
|
|
|
testDriverLock(privconn);
|
|
|
|
testDomainEventQueue(privconn, event);
|
|
|
|
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;
|
2009-01-20 20:23:53 +00:00
|
|
|
virDomainEventPtr 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);
|
2009-01-20 20:23:53 +00:00
|
|
|
event = virDomainEventNewFromObj(privdom,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
|
2009-11-03 17:06:00 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
if (!privdom->persistent) {
|
2013-01-11 16:04:47 +00:00
|
|
|
virDomainObjListRemove(privconn->domains,
|
|
|
|
privdom);
|
2008-12-04 20:59:06 +00:00
|
|
|
privdom = NULL;
|
|
|
|
}
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2009-11-03 17:06:00 +00:00
|
|
|
ret = 0;
|
2008-12-04 20:57:47 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(privdom);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
|
|
|
testDomainEventQueue(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;
|
2009-01-20 20:23:53 +00:00
|
|
|
virDomainEventPtr 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);
|
2009-01-20 20:23:53 +00:00
|
|
|
event = virDomainEventNewFromObj(privdom,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
|
2009-11-03 17:06:00 +00:00
|
|
|
|
2009-01-20 20:23:53 +00:00
|
|
|
if (!privdom->persistent) {
|
2013-01-11 16:04:47 +00:00
|
|
|
virDomainObjListRemove(privconn->domains,
|
|
|
|
privdom);
|
2009-01-20 20:23:53 +00:00
|
|
|
privdom = NULL;
|
|
|
|
}
|
2008-12-04 20:59:06 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(privdom);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
|
|
|
testDomainEventQueue(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;
|
|
|
|
info->maxMem = privdom->def->mem.max_balloon;
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(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;
|
2009-01-20 20:23:53 +00:00
|
|
|
virDomainEventPtr 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,
|
2009-03-16 17:14:34 +00:00
|
|
|
VIR_DOMAIN_XML_SECURE);
|
|
|
|
|
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);
|
2009-01-20 20:23:53 +00:00
|
|
|
event = virDomainEventNewFromObj(privdom,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_SAVED);
|
2009-11-03 17:06:00 +00:00
|
|
|
|
2008-07-11 16:41:27 +00:00
|
|
|
if (!privdom->persistent) {
|
2013-01-11 16:04:47 +00:00
|
|
|
virDomainObjListRemove(privconn->domains,
|
|
|
|
privdom);
|
2008-12-04 20:59:06 +00:00
|
|
|
privdom = NULL;
|
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;
|
2008-12-04 20:57:47 +00:00
|
|
|
cleanup:
|
|
|
|
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);
|
|
|
|
}
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(privdom);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
|
|
|
testDomainEventQueue(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;
|
2009-01-20 20:23:53 +00:00
|
|
|
virDomainEventPtr 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,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("incomplete metdata 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,
|
|
|
|
1 << VIR_DOMAIN_VIRT_TEST,
|
2009-01-08 13:54:20 +00:00
|
|
|
VIR_DOMAIN_XML_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;
|
|
|
|
|
2009-01-20 20:23:53 +00:00
|
|
|
event = virDomainEventNewFromObj(dom,
|
|
|
|
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
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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)
|
|
|
|
testDomainEventQueue(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);
|
|
|
|
}
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
static int testDomainCoreDump(virDomainPtr domain,
|
|
|
|
const char *to,
|
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)
|
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;
|
2009-01-20 20:23:53 +00:00
|
|
|
virDomainEventPtr 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
|
|
|
|
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);
|
2009-12-14 10:59:27 +00:00
|
|
|
event = virDomainEventNewFromObj(privdom,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_CRASHED);
|
|
|
|
if (!privdom->persistent) {
|
2013-01-11 16:04:47 +00:00
|
|
|
virDomainObjListRemove(privconn->domains,
|
|
|
|
privdom);
|
2009-12-14 10:59:27 +00:00
|
|
|
privdom = NULL;
|
|
|
|
}
|
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;
|
2008-12-04 20:57:47 +00:00
|
|
|
cleanup:
|
2010-11-09 20:48:48 +00:00
|
|
|
VIR_FORCE_CLOSE(fd);
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(privdom);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
|
|
|
testDomainEventQueue(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
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static unsigned long long testDomainGetMaxMemory(virDomainPtr domain) {
|
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
|
|
|
|
2010-10-12 14:43:39 +00:00
|
|
|
ret = privdom->def->mem.max_balloon;
|
2008-12-04 20:57:47 +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;
|
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 */
|
2010-10-12 14:43:39 +00:00
|
|
|
privdom->def->mem.max_balloon = memory;
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2010-10-12 14:43:39 +00:00
|
|
|
if (memory > privdom->def->mem.max_balloon) {
|
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;
|
|
|
|
|
|
|
|
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;
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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);
|
2010-11-19 19:51:46 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
persistentDef->vcpus = nrCpus;
|
|
|
|
}
|
2010-10-04 23:01:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-04 20:57:47 +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,
|
|
|
|
"%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++) {
|
2009-10-21 19:04:14 +00:00
|
|
|
if (VIR_CPU_USABLE(privdomdata->cpumaps, privmaplen, v, i)) {
|
|
|
|
VIR_USE_CPU(cpumap, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = maxinfo;
|
|
|
|
cleanup:
|
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(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,
|
|
|
|
"%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++) {
|
2009-10-27 22:25:38 +00:00
|
|
|
if (VIR_CPU_USABLE(cpumap, maplen, 0, i)) {
|
|
|
|
VIR_USE_CPU(privcpumap, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(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,
|
2008-12-04 20:57:47 +00:00
|
|
|
flags);
|
|
|
|
|
|
|
|
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-06-06 03:32:51 +00:00
|
|
|
}
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2013-04-23 12:50:18 +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,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
static virDomainPtr testDomainDefineXML(virConnectPtr conn,
|
2008-07-11 16:41:27 +00:00
|
|
|
const char *xml) {
|
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;
|
2009-01-20 20:23:53 +00:00
|
|
|
virDomainEventPtr 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;
|
2007-01-18 21:08:21 +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,
|
|
|
|
1 << VIR_DOMAIN_VIRT_TEST,
|
2009-01-08 13:54:20 +00:00
|
|
|
VIR_DOMAIN_XML_INACTIVE)) == 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
|
|
|
|
2009-01-20 20:23:53 +00:00
|
|
|
event = virDomainEventNewFromObj(dom,
|
|
|
|
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
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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)
|
|
|
|
testDomainEventQueue(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
|
|
|
}
|
|
|
|
|
2008-04-04 07:31:24 +00:00
|
|
|
static int testNodeGetCellsFreeMemory(virConnectPtr conn,
|
|
|
|
unsigned long long *freemems,
|
|
|
|
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
|
|
|
|
2008-12-04 20:57:47 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-10 15:55:36 +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;
|
2009-01-20 20:23:53 +00:00
|
|
|
virDomainEventPtr 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;
|
|
|
|
|
2009-01-20 20:23:53 +00:00
|
|
|
event = virDomainEventNewFromObj(privdom,
|
|
|
|
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
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(privdom);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
|
|
|
testDomainEventQueue(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
|
|
|
}
|
|
|
|
|
2010-06-10 15:55:36 +00:00
|
|
|
static int testDomainCreate(virDomainPtr domain) {
|
|
|
|
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;
|
2009-01-20 20:23:53 +00:00
|
|
|
virDomainEventPtr event = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
int ret = -1;
|
2008-12-04 20:56:10 +00:00
|
|
|
|
2011-07-20 03:08:21 +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-07-27 23:23:00 +00:00
|
|
|
|
2009-01-20 20:23:53 +00:00
|
|
|
event = virDomainEventNewFromObj(privdom,
|
|
|
|
VIR_DOMAIN_EVENT_UNDEFINED,
|
|
|
|
VIR_DOMAIN_EVENT_UNDEFINED_REMOVED);
|
2011-08-19 14:14:58 +00:00
|
|
|
if (virDomainObjIsActive(privdom)) {
|
|
|
|
privdom->persistent = 0;
|
2011-08-19 13:50:49 +00:00
|
|
|
} else {
|
2013-01-11 16:04:47 +00:00
|
|
|
virDomainObjListRemove(privconn->domains,
|
|
|
|
privdom);
|
2011-08-19 13:50:49 +00:00
|
|
|
privdom = NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
2007-01-18 21:08:21 +00:00
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(privdom);
|
2009-01-20 20:23:53 +00:00
|
|
|
if (event)
|
|
|
|
testDomainEventQueue(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;
|
|
|
|
|
|
|
|
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;
|
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;
|
|
|
|
|
|
|
|
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;
|
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;
|
|
|
|
|
|
|
|
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;
|
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;
|
|
|
|
|
|
|
|
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;
|
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,
|
|
|
|
struct _virDomainBlockStats *stats)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
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;
|
|
|
|
error:
|
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(privdom);
|
2009-07-24 15:05:30 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testDomainInterfaceStats(virDomainPtr domain,
|
|
|
|
const char *path,
|
|
|
|
struct _virDomainInterfaceStats *stats)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
error:
|
|
|
|
if (privdom)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(privdom);
|
2009-07-24 15:05:30 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static virDrvOpenStatus testNetworkOpen(virConnectPtr conn,
|
2007-12-05 18:28:05 +00:00
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
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)
|
|
|
|
{
|
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
if (STRNEQ(conn->driver->name, "Test"))
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
conn->networkPrivateData = conn->privateData;
|
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testNetworkClose(virConnectPtr conn) {
|
2007-07-27 23:23:00 +00:00
|
|
|
conn->networkPrivateData = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
|
|
|
net = virNetworkFindByUUID(&privconn->networks, uuid);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (net)
|
|
|
|
virNetworkObjUnlock(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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
|
|
|
net = virNetworkFindByName(&privconn->networks, name);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (net)
|
|
|
|
virNetworkObjUnlock(net);
|
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 testConnectNumOfNetworks(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;
|
2007-07-27 23:23:00 +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->networks.count; i++) {
|
2008-12-04 20:59:06 +00:00
|
|
|
virNetworkObjLock(privconn->networks.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 (virNetworkObjIsActive(privconn->networks.objs[i]))
|
2008-07-11 16:39:08 +00:00
|
|
|
numActive++;
|
2008-12-04 20:59:06 +00:00
|
|
|
virNetworkObjUnlock(privconn->networks.objs[i]);
|
|
|
|
}
|
|
|
|
testDriverUnlock(privconn);
|
2008-10-10 14:50:26 +00:00
|
|
|
|
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;
|
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;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-07-11 16:39:08 +00:00
|
|
|
memset(names, 0, sizeof(*names)*nnames);
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < privconn->networks.count && n < nnames; i++) {
|
2008-12-04 20:59:06 +00:00
|
|
|
virNetworkObjLock(privconn->networks.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 (virNetworkObjIsActive(privconn->networks.objs[i]) &&
|
2013-05-03 12:49:30 +00:00
|
|
|
VIR_STRDUP(names[n++], privconn->networks.objs[i]->def->name) < 0) {
|
2008-12-04 20:59:06 +00:00
|
|
|
virNetworkObjUnlock(privconn->networks.objs[i]);
|
2013-05-03 12:49:30 +00:00
|
|
|
goto error;
|
2008-12-04 20:59:06 +00:00
|
|
|
}
|
|
|
|
virNetworkObjUnlock(privconn->networks.objs[i]);
|
|
|
|
}
|
|
|
|
testDriverUnlock(privconn);
|
2008-10-10 14:50:26 +00:00
|
|
|
|
2008-07-11 16:39:08 +00:00
|
|
|
return n;
|
|
|
|
|
2013-05-03 12:49:30 +00:00
|
|
|
error:
|
2013-05-21 07:21:18 +00:00
|
|
|
for (n = 0; n < nnames; n++)
|
2008-07-11 16:39:08 +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;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testConnectNumOfDefinedNetworks(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;
|
2007-07-27 23:23:00 +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->networks.count; i++) {
|
2008-12-04 20:59:06 +00:00
|
|
|
virNetworkObjLock(privconn->networks.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 (!virNetworkObjIsActive(privconn->networks.objs[i]))
|
2008-07-11 16:39:08 +00:00
|
|
|
numInactive++;
|
2008-12-04 20:59:06 +00:00
|
|
|
virNetworkObjUnlock(privconn->networks.objs[i]);
|
|
|
|
}
|
|
|
|
testDriverUnlock(privconn);
|
2008-10-10 14:50:26 +00:00
|
|
|
|
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;
|
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;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-07-11 16:39:08 +00:00
|
|
|
memset(names, 0, sizeof(*names)*nnames);
|
2013-05-21 07:21:18 +00:00
|
|
|
for (i = 0; i < privconn->networks.count && n < nnames; i++) {
|
2008-12-04 20:59:06 +00:00
|
|
|
virNetworkObjLock(privconn->networks.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 (!virNetworkObjIsActive(privconn->networks.objs[i]) &&
|
2013-05-03 12:49:30 +00:00
|
|
|
VIR_STRDUP(names[n++], privconn->networks.objs[i]->def->name) < 0) {
|
2008-12-04 20:59:06 +00:00
|
|
|
virNetworkObjUnlock(privconn->networks.objs[i]);
|
2013-05-03 12:49:30 +00:00
|
|
|
goto error;
|
2008-12-04 20:59:06 +00:00
|
|
|
}
|
|
|
|
virNetworkObjUnlock(privconn->networks.objs[i]);
|
|
|
|
}
|
|
|
|
testDriverUnlock(privconn);
|
2008-10-10 14:50:26 +00:00
|
|
|
|
2008-07-11 16:39:08 +00:00
|
|
|
return n;
|
|
|
|
|
2013-05-03 12:49:30 +00:00
|
|
|
error:
|
2013-05-21 07:21:18 +00:00
|
|
|
for (n = 0; n < nnames; n++)
|
2008-07-11 16:39:08 +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;
|
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;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_CONNECT_LIST_NETWORKS_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
2013-06-26 15:42:27 +00:00
|
|
|
ret = virNetworkObjListExport(conn, privconn->networks, nets, NULL, flags);
|
2012-09-04 15:55:19 +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
|
|
|
|
|
|
|
static int testNetworkIsActive(virNetworkPtr net)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = net->conn->privateData;
|
|
|
|
virNetworkObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
obj = virNetworkFindByUUID(&privconn->networks, net->uuid);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
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);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (obj)
|
|
|
|
virNetworkObjUnlock(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testNetworkIsPersistent(virNetworkPtr net)
|
|
|
|
{
|
|
|
|
testConnPtr privconn = net->conn->privateData;
|
|
|
|
virNetworkObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
obj = virNetworkFindByUUID(&privconn->networks, net->uuid);
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (obj)
|
|
|
|
virNetworkObjUnlock(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-23 12:50:18 +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;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
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
|
|
|
|
2012-09-14 15:35:35 +00:00
|
|
|
if (!(net = virNetworkAssignDef(&privconn->networks, def, false)))
|
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
|
|
|
|
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
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
cleanup:
|
|
|
|
virNetworkDefFree(def);
|
2008-12-04 20:59:06 +00:00
|
|
|
if (net)
|
|
|
|
virNetworkObjUnlock(net);
|
|
|
|
testDriverUnlock(privconn);
|
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;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
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
|
|
|
|
2012-09-14 15:35:35 +00:00
|
|
|
if (!(net = virNetworkAssignDef(&privconn->networks, def, false)))
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
2009-02-13 18:11:03 +00:00
|
|
|
net->persistent = 1;
|
2007-07-27 23:23:00 +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
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virNetworkDefFree(def);
|
2008-12-04 20:59:06 +00:00
|
|
|
if (net)
|
|
|
|
virNetworkObjUnlock(net);
|
|
|
|
testDriverUnlock(privconn);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +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;
|
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
|
|
|
privnet = virNetworkFindByName(&privconn->networks,
|
|
|
|
network->name);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-07-11 16:39:08 +00:00
|
|
|
virNetworkRemoveInactive(&privconn->networks,
|
|
|
|
privnet);
|
2008-12-04 20:59:06 +00:00
|
|
|
privnet = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privnet)
|
|
|
|
virNetworkObjUnlock(privnet);
|
|
|
|
testDriverUnlock(privconn);
|
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);
|
|
|
|
|
|
|
|
testDriverLock(privconn);
|
|
|
|
|
|
|
|
network = virNetworkFindByUUID(&privconn->networks, net->uuid);
|
|
|
|
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;
|
|
|
|
cleanup:
|
|
|
|
testDriverUnlock(privconn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +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;
|
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
|
|
|
privnet = virNetworkFindByName(&privconn->networks,
|
|
|
|
network->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
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;
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
2007-07-27 23:23:00 +00:00
|
|
|
|
2008-12-04 20:57:47 +00:00
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privnet)
|
|
|
|
virNetworkObjUnlock(privnet);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +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;
|
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
|
|
|
privnet = virNetworkFindByName(&privconn->networks,
|
|
|
|
network->name);
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (!privnet->persistent) {
|
|
|
|
virNetworkRemoveInactive(&privconn->networks,
|
|
|
|
privnet);
|
2008-12-04 20:59:06 +00:00
|
|
|
privnet = NULL;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privnet)
|
|
|
|
virNetworkObjUnlock(privnet);
|
|
|
|
testDriverUnlock(privconn);
|
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);
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privnet = virNetworkFindByName(&privconn->networks,
|
|
|
|
network->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
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
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privnet)
|
|
|
|
virNetworkObjUnlock(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;
|
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privnet = virNetworkFindByName(&privconn->networks,
|
|
|
|
network->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
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
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privnet)
|
|
|
|
virNetworkObjUnlock(privnet);
|
2007-07-27 23:23:00 +00:00
|
|
|
return bridge;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testNetworkGetAutostart(virNetworkPtr network,
|
|
|
|
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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privnet = virNetworkFindByName(&privconn->networks,
|
|
|
|
network->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privnet)
|
|
|
|
virNetworkObjUnlock(privnet);
|
2008-12-04 20:57:47 +00:00
|
|
|
return ret;
|
2007-07-27 23:23:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int testNetworkSetAutostart(virNetworkPtr network,
|
|
|
|
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
|
|
|
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverLock(privconn);
|
2008-12-04 20:56:10 +00:00
|
|
|
privnet = virNetworkFindByName(&privconn->networks,
|
|
|
|
network->name);
|
2008-12-04 20:59:06 +00:00
|
|
|
testDriverUnlock(privconn);
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 20:59:06 +00:00
|
|
|
if (privnet)
|
|
|
|
virNetworkObjUnlock(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 virDrvOpenStatus testInterfaceOpen(virConnectPtr conn,
|
2009-07-21 13:45:55 +00:00
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
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
|
|
|
{
|
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);
|
|
|
|
|
2009-07-21 13:45:55 +00:00
|
|
|
if (STRNEQ(conn->driver->name, "Test"))
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
conn->interfacePrivateData = conn->privateData;
|
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int testInterfaceClose(virConnectPtr conn)
|
2009-07-21 13:45:55 +00:00
|
|
|
{
|
|
|
|
conn->interfacePrivateData = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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]);
|
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])) {
|
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;
|
|
|
|
|
2013-05-03 12:49:30 +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]);
|
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])) {
|
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;
|
|
|
|
|
2013-05-03 12:49:30 +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);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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;
|
|
|
|
cleanup:
|
|
|
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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
|
|
|
|
2010-02-04 18:19:08 +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
|
|
|
}
|
|
|
|
|
2008-02-20 15:53:34 +00:00
|
|
|
static virDrvOpenStatus testStorageOpen(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
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)
|
|
|
|
{
|
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
2008-02-20 15:53:34 +00:00
|
|
|
if (STRNEQ(conn->driver->name, "Test"))
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
conn->storagePrivateData = conn->privateData;
|
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testStorageClose(virConnectPtr conn) {
|
|
|
|
conn->storagePrivateData = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
static virStoragePoolPtr
|
|
|
|
testStoragePoolLookupByUUID(virConnectPtr conn,
|
|
|
|
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
|
|
|
|
|
|
|
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,
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
testStoragePoolLookupByVolume(virStorageVolPtr vol) {
|
|
|
|
return testStoragePoolLookupByName(vol->conn, vol->pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +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,
|
|
|
|
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;
|
|
|
|
|
2013-05-03 12:49:30 +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
|
2013-04-23 12:50:18 +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,
|
|
|
|
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;
|
|
|
|
|
2013-05-03 12:49:30 +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);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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
|
|
|
|
2008-12-04 20:57:47 +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
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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
|
2008-12-04 20:56:10 +00:00
|
|
|
testStoragePoolUndefine(virStoragePoolPtr pool) {
|
|
|
|
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
|
|
|
|
2008-12-04 20:57:47 +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
|
|
|
|
2008-12-04 20:57:47 +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
|
|
|
testStoragePoolDestroy(virStoragePoolPtr pool) {
|
|
|
|
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
|
|
|
|
2008-12-04 20:57:47 +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
|
|
|
|
2008-12-04 20:57:47 +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
|
|
|
|
2008-12-04 20:57:47 +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,
|
2008-10-30 17:40:57 +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
|
|
|
|
2008-12-04 20:57:47 +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
|
|
|
|
|
|
|
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,
|
2008-10-30 17:40:57 +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
|
|
|
|
2008-12-04 20:57:47 +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,
|
2008-10-30 17:40:57 +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;
|
|
|
|
|
|
|
|
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
|
2013-04-23 12:50:18 +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;
|
|
|
|
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
unsigned int flags) {
|
|
|
|
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,
|
|
|
|
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
|
|
|
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
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
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
privvol = virStorageVolDefParseString(privpool->def, xmldesc);
|
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 */
|
2008-12-04 20:56:10 +00:00
|
|
|
if ((privpool->def->allocation + privvol->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
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_REALLOC_N(privpool->volumes.objs,
|
2013-07-04 10:16:47 +00:00
|
|
|
privpool->volumes.count+1) < 0)
|
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
|
|
|
|
2013-05-03 12:49:30 +00:00
|
|
|
if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
|
2008-12-04 20:57:47 +00:00
|
|
|
goto cleanup;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool->def->allocation += privvol->allocation;
|
2008-10-30 17:40:57 +00:00
|
|
|
privpool->def->available = (privpool->def->capacity -
|
|
|
|
privpool->def->allocation);
|
|
|
|
|
2008-12-04 20:56:10 +00:00
|
|
|
privpool->volumes.objs[privpool->volumes.count++] = privvol;
|
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-07 20:45:28 +00:00
|
|
|
privvol = NULL;
|
2008-12-04 20:57:47 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
privvol = virStorageVolDefParseString(privpool->def, xmldesc);
|
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 */
|
|
|
|
if ((privpool->def->allocation + privvol->allocation) >
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (VIR_REALLOC_N(privpool->volumes.objs,
|
2013-07-04 10:16:47 +00:00
|
|
|
privpool->volumes.count+1) < 0)
|
2009-05-12 20:15:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
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;
|
|
|
|
|
2013-05-03 12:49:30 +00:00
|
|
|
if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
|
2009-05-12 20:15:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
privpool->def->allocation += privvol->allocation;
|
|
|
|
privpool->def->available = (privpool->def->capacity -
|
|
|
|
privpool->def->allocation);
|
|
|
|
|
|
|
|
privpool->volumes.objs[privpool->volumes.count++] = privvol;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-30 17:40:57 +00:00
|
|
|
privpool->def->allocation -= privvol->allocation;
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (i < (privpool->volumes.count - 1))
|
|
|
|
memmove(privpool->volumes.objs + i,
|
|
|
|
privpool->volumes.objs + i + 1,
|
|
|
|
sizeof(*(privpool->volumes.objs)) *
|
|
|
|
(privpool->volumes.count - (i + 1)));
|
|
|
|
|
|
|
|
if (VIR_REALLOC_N(privpool->volumes.objs,
|
|
|
|
privpool->volumes.count - 1) < 0) {
|
|
|
|
; /* Failure to reduce memory allocation isn't fatal */
|
|
|
|
}
|
|
|
|
privpool->volumes.count--;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:57:47 +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 testStorageVolumeTypeForPool(int pooltype) {
|
|
|
|
|
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,
|
|
|
|
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);
|
|
|
|
info->capacity = privvol->capacity;
|
|
|
|
info->allocation = privvol->allocation;
|
2008-12-04 20:57:47 +00:00
|
|
|
ret = 0;
|
2008-10-30 17:40:57 +00:00
|
|
|
|
2008-12-04 20:57:47 +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
|
|
|
|
|
|
|
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
|
|
|
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
|
|
|
|
|
|
|
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 */
|
2013-04-23 10:15:48 +00:00
|
|
|
static virDrvOpenStatus testNodeDeviceOpen(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
|
|
|
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
|
|
|
{
|
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
2008-12-04 21:00:50 +00:00
|
|
|
if (STRNEQ(conn->driver->name, "Test"))
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
2013-04-23 10:15:48 +00:00
|
|
|
conn->nodeDevicePrivateData = conn->privateData;
|
2008-12-04 21:00:50 +00:00
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2013-04-23 10:15:48 +00:00
|
|
|
static int testNodeDeviceClose(virConnectPtr conn) {
|
|
|
|
conn->nodeDevicePrivateData = NULL;
|
2008-12-04 21:00:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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) {
|
2013-05-03 12:49:30 +00:00
|
|
|
if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->type)) < 0)
|
2009-10-01 18:54:36 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = ncaps;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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);
|
2009-10-14 20:16:10 +00:00
|
|
|
if (def == NULL) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We run these next two simply for validation */
|
2010-02-10 10:40:18 +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;
|
|
|
|
|
|
|
|
/* Fill in a random 'host' value, since this would also come from
|
|
|
|
* the backend */
|
|
|
|
caps = def->caps;
|
|
|
|
while (caps) {
|
|
|
|
if (caps->type != VIR_NODE_DEV_CAP_SCSI_HOST)
|
|
|
|
continue;
|
|
|
|
|
2012-01-25 15:17:46 +00:00
|
|
|
caps->data.scsi_host.host = virRandomBits(10);
|
2009-10-14 20:16:10 +00:00
|
|
|
caps = caps->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-10 10:40:18 +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;
|
|
|
|
cleanup:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-02-10 10:40:18 +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);
|
|
|
|
|
|
|
|
out:
|
|
|
|
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;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
testDriverLock(driver);
|
2011-12-13 11:14:46 +00:00
|
|
|
ret = virDomainEventStateRegister(conn,
|
|
|
|
driver->domainEventState,
|
|
|
|
callback, opaque, freecb);
|
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;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
testDriverLock(driver);
|
2011-05-12 12:58:44 +00:00
|
|
|
ret = virDomainEventStateDeregister(conn,
|
|
|
|
driver->domainEventState,
|
|
|
|
callback);
|
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);
|
2011-12-13 11:14:46 +00:00
|
|
|
if (virDomainEventStateRegisterID(conn,
|
|
|
|
driver->domainEventState,
|
|
|
|
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;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
testDriverLock(driver);
|
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 = virDomainEventStateDeregisterID(conn,
|
|
|
|
driver->domainEventState,
|
|
|
|
callbackID);
|
2010-03-18 14:47:07 +00:00
|
|
|
testDriverUnlock(driver);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-20 20:23:53 +00:00
|
|
|
/* driver must be locked before calling */
|
|
|
|
static void testDomainEventQueue(testConnPtr driver,
|
|
|
|
virDomainEventPtr event)
|
|
|
|
{
|
2011-05-12 12:58:44 +00:00
|
|
|
virDomainEventStateQueue(driver->domainEventState, event);
|
2009-01-20 20:23:53 +00:00
|
|
|
}
|
|
|
|
|
2009-09-01 20:37:42 +00:00
|
|
|
static virDrvOpenStatus testSecretOpen(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
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)
|
|
|
|
{
|
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
2009-09-01 20:37:42 +00:00
|
|
|
if (STRNEQ(conn->driver->name, "Test"))
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
2010-04-09 14:05:59 +00:00
|
|
|
conn->secretPrivateData = conn->privateData;
|
2009-09-01 20:37:42 +00:00
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testSecretClose(virConnectPtr conn) {
|
|
|
|
conn->secretPrivateData = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
2009-01-20 20:23:53 +00:00
|
|
|
|
2010-03-29 21:09:20 +00:00
|
|
|
|
|
|
|
static virDrvOpenStatus testNWFilterOpen(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
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)
|
|
|
|
{
|
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
2010-03-29 21:09:20 +00:00
|
|
|
if (STRNEQ(conn->driver->name, "Test"))
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
2010-04-09 13:53:47 +00:00
|
|
|
conn->nwfilterPrivateData = conn->privateData;
|
2010-03-29 21:09:20 +00:00
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testNWFilterClose(virConnectPtr conn) {
|
|
|
|
conn->nwfilterPrivateData = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (virFDStreamOpenFile(st, PKGDATADIR "/libvirtLogo.png", 0, 0, O_RDONLY < 0))
|
|
|
|
VIR_FREE(ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-11 09:04:57 +00:00
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
static virDriver testDriver = {
|
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
|
|
|
.no = VIR_DRV_TEST,
|
|
|
|
.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 */
|
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 */
|
|
|
|
.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 */
|
2007-07-27 23:23:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static virNetworkDriver testNetworkDriver = {
|
|
|
|
"Test",
|
2013-04-23 12:50:18 +00:00
|
|
|
.networkOpen = testNetworkOpen, /* 0.3.2 */
|
|
|
|
.networkClose = testNetworkClose, /* 0.3.2 */
|
|
|
|
.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 */
|
|
|
|
.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 = {
|
|
|
|
"Test", /* name */
|
2013-04-23 12:50:18 +00:00
|
|
|
.interfaceOpen = testInterfaceOpen, /* 0.7.0 */
|
|
|
|
.interfaceClose = testInterfaceClose, /* 0.7.0 */
|
|
|
|
.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 = {
|
|
|
|
.name = "Test",
|
2013-04-23 12:49:21 +00:00
|
|
|
.storageOpen = testStorageOpen, /* 0.4.1 */
|
|
|
|
.storageClose = testStorageClose, /* 0.4.1 */
|
2013-04-22 17:26:01 +00:00
|
|
|
|
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 = {
|
2008-12-04 21:00:50 +00:00
|
|
|
.name = "Test",
|
2013-04-23 12:49:21 +00:00
|
|
|
.nodeDeviceOpen = testNodeDeviceOpen, /* 0.6.0 */
|
|
|
|
.nodeDeviceClose = testNodeDeviceClose, /* 0.6.0 */
|
2013-04-22 17:26:01 +00:00
|
|
|
|
|
|
|
.nodeNumOfDevices = testNodeNumOfDevices, /* 0.7.2 */
|
|
|
|
.nodeListDevices = testNodeListDevices, /* 0.7.2 */
|
|
|
|
.nodeDeviceLookupByName = testNodeDeviceLookupByName, /* 0.7.2 */
|
|
|
|
.nodeDeviceGetXMLDesc = testNodeDeviceGetXMLDesc, /* 0.7.2 */
|
|
|
|
.nodeDeviceGetParent = testNodeDeviceGetParent, /* 0.7.2 */
|
|
|
|
.nodeDeviceNumOfCaps = testNodeDeviceNumOfCaps, /* 0.7.2 */
|
|
|
|
.nodeDeviceListCaps = testNodeDeviceListCaps, /* 0.7.2 */
|
|
|
|
.nodeDeviceCreateXML = testNodeDeviceCreateXML, /* 0.7.3 */
|
|
|
|
.nodeDeviceDestroy = testNodeDeviceDestroy, /* 0.7.3 */
|
2008-12-04 21:00:50 +00:00
|
|
|
};
|
|
|
|
|
2009-09-01 20:37:42 +00:00
|
|
|
static virSecretDriver testSecretDriver = {
|
|
|
|
.name = "Test",
|
2013-04-23 12:49:21 +00:00
|
|
|
.secretOpen = testSecretOpen, /* 0.7.1 */
|
|
|
|
.secretClose = testSecretClose, /* 0.7.1 */
|
2009-09-01 20:37:42 +00:00
|
|
|
};
|
2008-12-04 21:00:50 +00:00
|
|
|
|
|
|
|
|
2010-03-29 21:09:20 +00:00
|
|
|
static virNWFilterDriver testNWFilterDriver = {
|
|
|
|
.name = "Test",
|
2013-04-23 12:49:21 +00:00
|
|
|
.nwfilterOpen = testNWFilterOpen, /* 0.8.0 */
|
|
|
|
.nwfilterClose = testNWFilterClose, /* 0.8.0 */
|
2010-03-29 21:09:20 +00:00
|
|
|
};
|
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
/**
|
|
|
|
* testRegister:
|
|
|
|
*
|
|
|
|
* Registers the test driver
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
testRegister(void)
|
|
|
|
{
|
|
|
|
if (virRegisterDriver(&testDriver) < 0)
|
|
|
|
return -1;
|
|
|
|
if (virRegisterNetworkDriver(&testNetworkDriver) < 0)
|
|
|
|
return -1;
|
2009-07-21 13:45:55 +00:00
|
|
|
if (virRegisterInterfaceDriver(&testInterfaceDriver) < 0)
|
|
|
|
return -1;
|
2008-02-20 15:53:34 +00:00
|
|
|
if (virRegisterStorageDriver(&testStorageDriver) < 0)
|
|
|
|
return -1;
|
2013-04-23 10:15:48 +00:00
|
|
|
if (virRegisterNodeDeviceDriver(&testNodeDeviceDriver) < 0)
|
2008-12-04 21:00:50 +00:00
|
|
|
return -1;
|
2009-09-01 20:37:42 +00:00
|
|
|
if (virRegisterSecretDriver(&testSecretDriver) < 0)
|
|
|
|
return -1;
|
2010-03-29 21:09:20 +00:00
|
|
|
if (virRegisterNWFilterDriver(&testNWFilterDriver) < 0)
|
|
|
|
return -1;
|
2008-12-04 21:00:50 +00:00
|
|
|
|
2007-07-27 23:23:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|