2007-07-17 13:27:26 +00:00
|
|
|
/*
|
|
|
|
* openvz_driver.c: core driver methods for managing OpenVZ VEs
|
|
|
|
*
|
2014-02-20 00:32:19 +00:00
|
|
|
* Copyright (C) 2010-2014 Red Hat, Inc.
|
2007-07-17 13:27:26 +00:00
|
|
|
* Copyright (C) 2006, 2007 Binary Karma
|
|
|
|
* Copyright (C) 2006 Shuveb Hussain
|
2007-09-03 15:37:07 +00:00
|
|
|
* Copyright (C) 2007 Anoop Joe Cyriac
|
2007-07-17 13:27:26 +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/>.
|
2007-07-17 13:27:26 +00:00
|
|
|
*
|
2008-02-05 19:27:37 +00:00
|
|
|
* Authors:
|
2007-09-03 15:37:07 +00:00
|
|
|
* Shuveb Hussain <shuveb@binarykarma.com>
|
|
|
|
* Anoop Joe Cyriac <anoop@binarykarma.com>
|
|
|
|
*
|
2007-07-17 13:27:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <paths.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2008-11-04 23:22:06 +00:00
|
|
|
#include "datatypes.h"
|
2007-09-03 15:37:07 +00:00
|
|
|
#include "openvz_driver.h"
|
2012-05-07 21:00:28 +00:00
|
|
|
#include "openvz_util.h"
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2007-07-17 13:27:26 +00:00
|
|
|
#include "openvz_conf.h"
|
2007-07-25 23:16:30 +00:00
|
|
|
#include "nodeinfo.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2012-04-25 19:18:16 +00:00
|
|
|
#include "virtypedparam.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2012-12-12 16:27:01 +00:00
|
|
|
#include "vircommand.h"
|
2012-02-24 18:48:55 +00:00
|
|
|
#include "viruri.h"
|
2014-07-05 15:34:39 +00:00
|
|
|
#include "virstats.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2009-01-29 12:10:32 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_OPENVZ
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("openvz.openvz_driver");
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
#define OPENVZ_MAX_ARG 28
|
|
|
|
#define CMDBUF_LEN 1488
|
|
|
|
#define CMDOP_LEN 288
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2012-04-25 19:18:16 +00:00
|
|
|
#define OPENVZ_NB_MEM_PARAM 3
|
|
|
|
|
2008-07-21 08:08:25 +00:00
|
|
|
static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid);
|
2013-04-23 12:50:18 +00:00
|
|
|
static int openvzConnectGetMaxVcpus(virConnectPtr conn, const char *type);
|
2008-08-20 13:44:03 +00:00
|
|
|
static int openvzDomainGetMaxVcpus(virDomainPtr dom);
|
2010-04-03 14:23:45 +00:00
|
|
|
static int openvzDomainSetVcpusInternal(virDomainObjPtr vm,
|
2009-11-02 16:39:46 +00:00
|
|
|
unsigned int nvcpus);
|
2010-04-03 14:23:45 +00:00
|
|
|
static int openvzDomainSetMemoryInternal(virDomainObjPtr vm,
|
2012-03-02 20:27:39 +00:00
|
|
|
unsigned long long memory);
|
2011-07-29 08:41:32 +00:00
|
|
|
static int openvzGetVEStatus(virDomainObjPtr vm, int *status, int *reason);
|
2008-07-21 08:08:25 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
static void openvzDriverLock(struct openvz_driver *driver)
|
|
|
|
{
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&driver->lock);
|
2008-12-04 21:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void openvzDriverUnlock(struct openvz_driver *driver)
|
|
|
|
{
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&driver->lock);
|
2008-12-04 21:44:55 +00:00
|
|
|
}
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
struct openvz_driver ovz_driver;
|
|
|
|
|
2013-03-06 14:48:06 +00:00
|
|
|
static int
|
|
|
|
openvzDomainDefPostParse(virDomainDefPtr def,
|
|
|
|
virCapsPtr caps ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
/* fill the init path */
|
2013-05-03 12:45:31 +00:00
|
|
|
if (STREQ(def->os.type, "exe") && !def->os.init)
|
|
|
|
return VIR_STRDUP(def->os.init, "/sbin/init") < 0 ? -1 : 0;
|
2013-03-06 14:48:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 20:39:34 +00:00
|
|
|
static int
|
|
|
|
openvzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
maint: avoid 'const fooPtr' in domain_conf
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up offenders in src/conf/domain_conf, and their fallout.
Several things to note: virObjectLock() requires a non-const
argument; if this were C++, we could treat the locking field
as 'mutable' and allow locking an otherwise 'const' object, but
that is a more invasive change, so I instead dropped attempts
to be const-correct on domain lookup. virXMLPropString and
friends require a non-const xmlNodePtr - this is because libxml2
is not a const-correct library. We could make the src/util/virxml
wrappers cast away const, but I figured it was easier to not
try to mark xmlNodePtr as const. Finally, virDomainDeviceDefCopy
was a rather hard conversion - it calls virDomainDeviceDefPostParse,
which in turn in the xen driver was actually modifying the domain
outside of the current device being visited. We should not be
adding a device on the first per-device callback, but waiting until
after all per-device callbacks are complete.
* src/conf/domain_conf.h (virDomainObjListFindByID)
(virDomainObjListFindByUUID, virDomainObjListFindByName)
(virDomainObjAssignDef, virDomainObjListAdd): Drop attempt at
const.
(virDomainDeviceDefCopy): Use intended type.
(virDomainDeviceDefParse, virDomainDeviceDefPostParseCallback)
(virDomainVideoDefaultType, virDomainVideoDefaultRAM)
(virDomainChrGetDomainPtrs): Make const-correct.
* src/conf/domain_conf.c (virDomainObjListFindByID)
(virDomainObjListFindByUUID, virDomainObjListFindByName)
(virDomainDeviceDefCopy, virDomainObjListAdd)
(virDomainObjAssignDef, virDomainHostdevSubsysUsbDefParseXML)
(virDomainHostdevSubsysPciOrigStatesDefParseXML)
(virDomainHostdevSubsysPciDefParseXML)
(virDomainHostdevSubsysScsiDefParseXML)
(virDomainControllerModelTypeFromString)
(virDomainTPMDefParseXML, virDomainTimerDefParseXML)
(virDomainSoundCodecDefParseXML, virDomainSoundDefParseXML)
(virDomainWatchdogDefParseXML, virDomainRNGDefParseXML)
(virDomainMemballoonDefParseXML, virDomainNVRAMDefParseXML)
(virSysinfoParseXML, virDomainVideoAccelDefParseXML)
(virDomainVideoDefParseXML, virDomainHostdevDefParseXML)
(virDomainRedirdevDefParseXML)
(virDomainRedirFilterUsbDevDefParseXML)
(virDomainRedirFilterDefParseXML, virDomainIdMapEntrySort)
(virDomainIdmapDefParseXML, virDomainVcpuPinDefParseXML)
(virDiskNameToBusDeviceIndex, virDomainDeviceDefCopy)
(virDomainVideoDefaultType, virDomainHostdevAssignAddress)
(virDomainDeviceDefPostParseInternal, virDomainDeviceDefPostParse)
(virDomainChrGetDomainPtrs, virDomainControllerSCSINextUnit)
(virDomainSCSIDriveAddressIsUsed)
(virDomainDriveAddressIsUsedByDisk)
(virDomainDriveAddressIsUsedByHostdev): Fix fallout.
* src/openvz/openvz_driver.c (openvzDomainDeviceDefPostParse):
Likewise.
* src/libxl/libxl_domain.c (libxlDomainDeviceDefPostParse):
Likewise.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainDefaultNetModel): Likewise.
* src/lxc/lxc_domain.c (virLXCDomainDeviceDefPostParse):
Likewise.
* src/uml/uml_driver.c (umlDomainDeviceDefPostParse): Likewise.
* src/xen/xen_driver.c (xenDomainDeviceDefPostParse): Split...
(xenDomainDefPostParse): ...since per-device callback is not the
time to be adding a device.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 15:08:25 +00:00
|
|
|
const virDomainDef *def ATTRIBUTE_UNUSED,
|
2013-03-13 20:39:34 +00:00
|
|
|
virCapsPtr caps ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
|
|
|
|
dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
|
|
|
|
dev->data.chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE)
|
|
|
|
dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_OPENVZ;
|
|
|
|
|
2014-06-25 06:45:59 +00:00
|
|
|
/* forbid capabilities mode hostdev in this kind of hypervisor */
|
|
|
|
if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
|
|
|
|
dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("hostdev mode 'capabilities' is not "
|
|
|
|
"supported in %s"),
|
|
|
|
virDomainVirtTypeToString(def->virtType));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-03-13 20:39:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-06 14:48:06 +00:00
|
|
|
virDomainDefParserConfig openvzDomainDefParserConfig = {
|
|
|
|
.domainPostParseCallback = openvzDomainDefPostParse,
|
2013-03-13 20:39:34 +00:00
|
|
|
.devicesPostParseCallback = openvzDomainDeviceDefPostParse,
|
2013-03-06 14:48:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-16 14:45:55 +00:00
|
|
|
/* generate arguments to create OpenVZ container
|
|
|
|
return -1 - error
|
|
|
|
0 - OK
|
2012-05-05 06:47:05 +00:00
|
|
|
Caller has to free the cmd
|
2008-07-16 14:45:55 +00:00
|
|
|
*/
|
2012-05-05 06:47:05 +00:00
|
|
|
static virCommandPtr
|
|
|
|
openvzDomainDefineCmd(virDomainDefPtr vmdef)
|
2008-07-16 14:45:55 +00:00
|
|
|
{
|
2012-05-05 06:47:05 +00:00
|
|
|
virCommandPtr cmd = virCommandNewArgList(VZCTL,
|
|
|
|
"--quiet",
|
|
|
|
"create",
|
|
|
|
NULL);
|
2008-07-16 14:45:55 +00:00
|
|
|
|
2009-09-22 10:19:09 +00:00
|
|
|
if (vmdef == NULL) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Container is not defined"));
|
2012-05-05 06:47:05 +00:00
|
|
|
virCommandFree(cmd);
|
|
|
|
return NULL;
|
2008-07-16 14:45:55 +00:00
|
|
|
}
|
2010-11-28 21:52:44 +00:00
|
|
|
|
2012-05-05 06:47:05 +00:00
|
|
|
virCommandAddArgList(cmd, vmdef->name, "--name", vmdef->name, NULL);
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2009-03-24 10:59:13 +00:00
|
|
|
if (vmdef->nfss == 1 &&
|
2009-09-22 10:19:09 +00:00
|
|
|
vmdef->fss[0]->type == VIR_DOMAIN_FS_TYPE_TEMPLATE) {
|
2012-05-05 06:47:05 +00:00
|
|
|
virCommandAddArgList(cmd, "--ostemplate", vmdef->fss[0]->src, NULL);
|
2008-07-16 14:45:55 +00:00
|
|
|
}
|
2009-09-22 10:19:09 +00:00
|
|
|
|
2012-05-05 06:47:05 +00:00
|
|
|
return cmd;
|
2008-07-16 14:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
static int openvzSetInitialConfig(virDomainDefPtr vmdef)
|
2009-03-24 10:59:13 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int vpsid;
|
|
|
|
char * confdir = NULL;
|
2012-05-05 06:47:05 +00:00
|
|
|
virCommandPtr cmd = NULL;
|
2009-03-24 10:59:13 +00:00
|
|
|
|
|
|
|
if (vmdef->nfss > 1) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("only one filesystem supported"));
|
2009-03-24 10:59:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vmdef->nfss == 1 &&
|
|
|
|
vmdef->fss[0]->type != VIR_DOMAIN_FS_TYPE_TEMPLATE &&
|
|
|
|
vmdef->fss[0]->type != VIR_DOMAIN_FS_TYPE_MOUNT)
|
|
|
|
{
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("filesystem is not of type 'template' or 'mount'"));
|
2009-03-24 10:59:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (vmdef->nfss == 1 &&
|
|
|
|
vmdef->fss[0]->type == VIR_DOMAIN_FS_TYPE_MOUNT)
|
|
|
|
{
|
|
|
|
|
2010-08-31 22:43:18 +00:00
|
|
|
if (virStrToLong_i(vmdef->name, NULL, 10, &vpsid) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not convert domain name to VEID"));
|
2009-03-24 10:59:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (openvzCopyDefaultConfig(vpsid) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not copy default config"));
|
2009-03-24 10:59:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (openvzWriteVPSConfigParam(vpsid, "VE_PRIVATE", vmdef->fss[0]->src) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set the source dir for the filesystem"));
|
2009-03-24 10:59:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-05-05 06:47:05 +00:00
|
|
|
} else {
|
|
|
|
cmd = openvzDomainDefineCmd(vmdef);
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2009-03-24 10:59:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2009-03-24 10:59:13 +00:00
|
|
|
VIR_FREE(confdir);
|
2012-05-05 06:47:05 +00:00
|
|
|
virCommandFree(cmd);
|
|
|
|
|
2009-03-24 10:59:13 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-05 06:52:23 +00:00
|
|
|
static int
|
|
|
|
openvzSetDiskQuota(virDomainDefPtr vmdef,
|
2012-05-25 17:48:33 +00:00
|
|
|
virDomainFSDefPtr fss,
|
|
|
|
bool persist)
|
2012-05-05 06:52:23 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
unsigned long long sl, hl;
|
|
|
|
virCommandPtr cmd = virCommandNewArgList(VZCTL,
|
|
|
|
"--quiet",
|
|
|
|
"set",
|
|
|
|
vmdef->name,
|
|
|
|
NULL);
|
2012-05-25 17:48:33 +00:00
|
|
|
if (persist)
|
|
|
|
virCommandAddArg(cmd, "--save");
|
2012-05-05 06:52:23 +00:00
|
|
|
|
|
|
|
if (fss->type == VIR_DOMAIN_FS_TYPE_TEMPLATE) {
|
|
|
|
if (fss->space_hard_limit) {
|
|
|
|
hl = VIR_DIV_UP(fss->space_hard_limit, 1024);
|
|
|
|
virCommandAddArg(cmd, "--diskspace");
|
|
|
|
|
|
|
|
if (fss->space_soft_limit) {
|
|
|
|
sl = VIR_DIV_UP(fss->space_soft_limit, 1024);
|
|
|
|
virCommandAddArgFormat(cmd, "%lld:%lld", sl, hl);
|
|
|
|
} else {
|
|
|
|
virCommandAddArgFormat(cmd, "%lld", hl);
|
|
|
|
}
|
|
|
|
} else if (fss->space_soft_limit) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Can't set soft limit without hard limit"));
|
2012-05-05 06:52:23 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2012-05-05 06:52:23 +00:00
|
|
|
virCommandFree(cmd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-10 11:58:44 +00:00
|
|
|
static char *
|
|
|
|
openvzDomainGetHostname(virDomainPtr dom, unsigned int flags)
|
|
|
|
{
|
|
|
|
char *hostname = NULL;
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2012-07-10 11:58:44 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
hostname = openvzVEGetStringParam(dom, "hostname");
|
|
|
|
if (hostname == NULL)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* vzlist prints an unset hostname as '-' */
|
|
|
|
if (STREQ(hostname, "-")) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Hostname of '%s' is unset"), vm->def->name);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2012-07-10 11:58:44 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2012-07-10 11:58:44 +00:00
|
|
|
return hostname;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
error:
|
2012-07-10 11:58:44 +00:00
|
|
|
VIR_FREE(hostname);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
static virDomainPtr openvzDomainLookupByID(virConnectPtr conn,
|
2014-03-18 08:16:47 +00:00
|
|
|
int id)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2008-09-05 14:10:58 +00:00
|
|
|
virDomainObjPtr vm;
|
2008-12-04 21:41:51 +00:00
|
|
|
virDomainPtr dom = NULL;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByID(driver->domains, id);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
2008-12-04 21:41:51 +00:00
|
|
|
if (dom)
|
|
|
|
dom->id = vm->def->id;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2007-07-17 13:27:26 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
2014-03-18 08:16:47 +00:00
|
|
|
static int openvzConnectGetVersion(virConnectPtr conn, unsigned long *version)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-10-24 11:32:48 +00:00
|
|
|
*version = driver->version;
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
2008-10-24 11:32:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-26 16:39:11 +00:00
|
|
|
|
|
|
|
static char *openvzConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return virGetHostname();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static char *openvzDomainGetOSType(virDomainPtr dom)
|
2007-07-17 13:27:26 +00:00
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
char *ret = NULL;
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-09-05 14:10:58 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 12:45:31 +00:00
|
|
|
ignore_value(VIR_STRDUP(ret, vm->def->os.type));
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2008-09-05 14:10:58 +00:00
|
|
|
return ret;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virDomainPtr openvzDomainLookupByUUID(virConnectPtr conn,
|
2014-03-18 08:16:47 +00:00
|
|
|
const unsigned char *uuid)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainPtr dom = NULL;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
2008-12-04 21:41:51 +00:00
|
|
|
if (dom)
|
|
|
|
dom->id = vm->def->id;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2007-07-17 13:27:26 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr openvzDomainLookupByName(virConnectPtr conn,
|
2014-03-18 08:16:47 +00:00
|
|
|
const char *name)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainPtr dom = NULL;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByName(driver->domains, name);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
2008-12-04 21:41:51 +00:00
|
|
|
if (dom)
|
|
|
|
dom->id = vm->def->id;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2007-07-17 13:27:26 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int openvzDomainGetInfo(virDomainPtr dom,
|
2014-03-18 08:16:47 +00:00
|
|
|
virDomainInfoPtr info)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
2011-07-29 08:41:32 +00:00
|
|
|
int state;
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2011-07-29 08:41:32 +00:00
|
|
|
if (openvzGetVEStatus(vm, &state, NULL) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
info->state = state;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2011-07-29 08:41:32 +00:00
|
|
|
if (info->state != VIR_DOMAIN_RUNNING) {
|
2008-07-21 08:08:25 +00:00
|
|
|
info->cpuTime = 0;
|
|
|
|
} else {
|
|
|
|
if (openvzGetProcessInfo(&(info->cpuTime), dom->id) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("cannot read cputime for domain %d"), dom->id);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-07-21 08:08:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 14:43:39 +00:00
|
|
|
info->maxMem = vm->def->mem.max_balloon;
|
|
|
|
info->memory = vm->def->mem.cur_balloon;
|
2008-09-05 14:10:58 +00:00
|
|
|
info->nrVirtCpu = vm->def->vcpus;
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-02 09:35:29 +00:00
|
|
|
static int
|
|
|
|
openvzDomainGetState(virDomainPtr dom,
|
|
|
|
int *state,
|
|
|
|
int *reason,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2011-05-02 09:35:29 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2011-05-02 09:35:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-07-29 08:41:32 +00:00
|
|
|
ret = openvzGetVEStatus(vm, state, reason);
|
2011-05-02 09:35:29 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2011-05-02 09:35:29 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2011-05-02 09:35:29 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
static int openvzDomainIsActive(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
obj = virDomainObjListFindByUUID(driver->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
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
if (!obj) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = virDomainObjIsActive(obj);
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
if (obj)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(obj);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int openvzDomainIsPersistent(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
obj = virDomainObjListFindByUUID(driver->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
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
if (!obj) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = obj->persistent;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
if (obj)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(obj);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-24 07:43:15 +00:00
|
|
|
static int openvzDomainIsUpdated(virDomainPtr dom ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2011-07-06 20:40:19 +00:00
|
|
|
static char *openvzDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
char *ret = NULL;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2011-07-13 22:24:38 +00:00
|
|
|
/* Flags checked by virDomainDefFormat */
|
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2014-11-18 16:44:00 +00:00
|
|
|
ret = virDomainDefFormat(vm->def,
|
|
|
|
virDomainDefFormatConvertXMLFlags(flags));
|
2008-12-04 21:41:51 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2008-09-05 14:10:58 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
/*
|
|
|
|
* Convenient helper to target a command line argv
|
|
|
|
* and fill in an empty slot with the supplied
|
|
|
|
* key value. This lets us declare the argv on the
|
|
|
|
* stack and just splice in the domain name after
|
|
|
|
*/
|
2013-07-30 16:49:53 +00:00
|
|
|
#define PROGRAM_SENTINEL ((char *)0x1)
|
2008-12-04 21:41:51 +00:00
|
|
|
static void openvzSetProgramSentinal(const char **prog, const char *key)
|
|
|
|
{
|
|
|
|
const char **tmp = prog;
|
|
|
|
while (tmp && *tmp) {
|
2013-07-30 16:49:53 +00:00
|
|
|
if (*tmp == PROGRAM_SENTINEL) {
|
2008-12-04 21:41:51 +00:00
|
|
|
*tmp = key;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tmp++;
|
|
|
|
}
|
|
|
|
}
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2014-03-18 08:16:47 +00:00
|
|
|
static int openvzDomainSuspend(virDomainPtr dom)
|
|
|
|
{
|
2010-08-04 12:00:07 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
2013-07-30 16:49:53 +00:00
|
|
|
const char *prog[] = {VZCTL, "--quiet", "chkpnt", PROGRAM_SENTINEL, "--suspend", NULL};
|
2010-08-04 12:00:07 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2010-08-04 12:00:07 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2010-08-04 12:00:07 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virDomainObjIsActive(vm)) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Domain is not running"));
|
2010-08-04 12:00:07 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) {
|
2010-08-04 12:00:07 +00:00
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2014-11-13 14:29:21 +00:00
|
|
|
if (virRun(prog, NULL) < 0)
|
2010-08-04 12:00:07 +00:00
|
|
|
goto cleanup;
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER);
|
2010-08-04 12:00:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2010-08-04 12:00:07 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-08-04 12:00:07 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-18 08:16:47 +00:00
|
|
|
static int openvzDomainResume(virDomainPtr dom)
|
|
|
|
{
|
2010-08-04 12:00:07 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
2013-07-30 16:49:53 +00:00
|
|
|
const char *prog[] = {VZCTL, "--quiet", "chkpnt", PROGRAM_SENTINEL, "--resume", NULL};
|
2010-08-04 12:00:07 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2010-08-04 12:00:07 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2010-08-04 12:00:07 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virDomainObjIsActive(vm)) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Domain is not running"));
|
2010-08-04 12:00:07 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
|
2010-08-04 12:00:07 +00:00
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2014-11-13 14:29:21 +00:00
|
|
|
if (virRun(prog, NULL) < 0)
|
2010-08-04 12:00:07 +00:00
|
|
|
goto cleanup;
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNPAUSED);
|
2010-08-04 12:00:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2010-08-04 12:00:07 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-08-04 12:00:07 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-21 07:49:02 +00:00
|
|
|
static int
|
|
|
|
openvzDomainShutdownFlags(virDomainPtr dom,
|
2014-03-18 08:16:47 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
2013-07-30 16:49:53 +00:00
|
|
|
const char *prog[] = {VZCTL, "--quiet", "stop", PROGRAM_SENTINEL, NULL};
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2011-07-29 08:41:32 +00:00
|
|
|
int status;
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2011-07-21 07:49:02 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2011-07-29 08:41:32 +00:00
|
|
|
if (openvzGetVEStatus(vm, &status, NULL) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2011-07-29 08:41:32 +00:00
|
|
|
if (status != VIR_DOMAIN_RUNNING) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("domain is not in running state"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(prog, NULL) < 0)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
vm->def->id = -1;
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
|
2010-07-30 17:50:12 +00:00
|
|
|
dom->id = -1;
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2011-07-21 07:49:02 +00:00
|
|
|
static int
|
|
|
|
openvzDomainShutdown(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
return openvzDomainShutdownFlags(dom, 0);
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int
|
|
|
|
openvzDomainDestroy(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
return openvzDomainShutdownFlags(dom, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainDestroyFlags(virDomainPtr dom, unsigned int flags)
|
|
|
|
{
|
|
|
|
return openvzDomainShutdownFlags(dom, flags);
|
|
|
|
}
|
|
|
|
|
2007-09-03 16:30:00 +00:00
|
|
|
static int openvzDomainReboot(virDomainPtr dom,
|
2011-07-06 22:34:58 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
2013-07-30 16:49:53 +00:00
|
|
|
const char *prog[] = {VZCTL, "--quiet", "restart", PROGRAM_SENTINEL, NULL};
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2011-07-29 08:41:32 +00:00
|
|
|
int status;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2011-07-06 22:34:58 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2011-07-29 08:41:32 +00:00
|
|
|
if (openvzGetVEStatus(vm, &status, NULL) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2011-07-29 08:41:32 +00:00
|
|
|
if (status != VIR_DOMAIN_RUNNING) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("domain is not in running state"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(prog, NULL) < 0)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
ret = 0;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-11-12 16:35:47 +00:00
|
|
|
static char *
|
|
|
|
openvzGenerateVethName(int veid, char *dev_name_ve)
|
|
|
|
{
|
|
|
|
int ifNo = 0;
|
2013-05-03 12:45:31 +00:00
|
|
|
char *ret;
|
2008-11-12 16:35:47 +00:00
|
|
|
|
|
|
|
if (sscanf(dev_name_ve, "%*[^0-9]%d", &ifNo) != 1)
|
|
|
|
return NULL;
|
2013-07-04 10:13:02 +00:00
|
|
|
ignore_value(virAsprintf(&ret, "veth%d.%d.", veid, ifNo));
|
2013-05-03 12:45:31 +00:00
|
|
|
return ret;
|
2008-11-12 16:35:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
openvzGenerateContainerVethName(int veid)
|
|
|
|
{
|
2011-04-03 09:21:26 +00:00
|
|
|
char *temp = NULL;
|
|
|
|
char *name = NULL;
|
2008-11-12 16:35:47 +00:00
|
|
|
|
|
|
|
/* try to get line "^NETIF=..." from config */
|
2011-04-03 09:21:26 +00:00
|
|
|
if (openvzReadVPSConfigParam(veid, "NETIF", &temp) <= 0) {
|
2013-05-03 12:45:31 +00:00
|
|
|
ignore_value(VIR_STRDUP(name, "eth0"));
|
2008-11-12 16:35:47 +00:00
|
|
|
} else {
|
2011-04-05 09:54:59 +00:00
|
|
|
char *saveptr = NULL;
|
2011-04-03 09:21:26 +00:00
|
|
|
char *s;
|
|
|
|
int max = 0;
|
2008-11-12 16:35:47 +00:00
|
|
|
|
|
|
|
/* get maximum interface number (actually, it is the last one) */
|
2014-01-20 11:27:29 +00:00
|
|
|
for (s = strtok_r(temp, ";", &saveptr); s; s = strtok_r(NULL, ";", &saveptr)) {
|
2008-11-12 16:35:47 +00:00
|
|
|
int x;
|
|
|
|
|
|
|
|
if (sscanf(s, "ifname=eth%d", &x) != 1) return NULL;
|
|
|
|
if (x > max) max = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set new name */
|
2013-07-04 10:13:02 +00:00
|
|
|
ignore_value(virAsprintf(&name, "eth%d", max + 1));
|
2008-11-12 16:35:47 +00:00
|
|
|
}
|
2011-04-03 09:21:26 +00:00
|
|
|
|
|
|
|
VIR_FREE(temp);
|
|
|
|
|
|
|
|
return name;
|
2008-11-12 16:35:47 +00:00
|
|
|
}
|
|
|
|
|
2008-07-28 14:06:54 +00:00
|
|
|
static int
|
|
|
|
openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
|
2008-11-12 16:35:47 +00:00
|
|
|
virDomainNetDefPtr net,
|
|
|
|
virBufferPtr configBuf)
|
2008-07-28 14:06:54 +00:00
|
|
|
{
|
2013-05-19 09:17:19 +00:00
|
|
|
int rc = -1;
|
2008-11-12 16:35:47 +00:00
|
|
|
char macaddr[VIR_MAC_STRING_BUFLEN];
|
2012-07-17 12:07:59 +00:00
|
|
|
virMacAddr host_mac;
|
2009-01-07 10:55:54 +00:00
|
|
|
char host_macaddr[VIR_MAC_STRING_BUFLEN];
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2013-05-19 09:17:19 +00:00
|
|
|
virCommandPtr cmd = NULL;
|
2013-06-04 07:44:32 +00:00
|
|
|
char *guest_ifname = NULL;
|
2008-07-28 14:06:54 +00:00
|
|
|
|
|
|
|
if (net == NULL)
|
|
|
|
return 0;
|
|
|
|
if (vpsid == NULL) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Container ID is not specified"));
|
2008-07-28 14:06:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-05-19 09:17:19 +00:00
|
|
|
if (net->type != VIR_DOMAIN_NET_TYPE_BRIDGE &&
|
|
|
|
net->type != VIR_DOMAIN_NET_TYPE_ETHERNET)
|
|
|
|
return 0;
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2013-05-19 09:17:19 +00:00
|
|
|
cmd = virCommandNewArgList(VZCTL, "--quiet", "set", vpsid, NULL);
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2012-07-17 12:07:59 +00:00
|
|
|
virMacAddrFormat(&net->mac, macaddr);
|
2013-03-15 14:44:12 +00:00
|
|
|
virDomainNetGenerateMAC(driver->xmlopt, &host_mac);
|
2012-07-17 12:07:59 +00:00
|
|
|
virMacAddrFormat(&host_mac, host_macaddr);
|
2008-11-12 16:35:47 +00:00
|
|
|
|
2010-08-18 15:05:02 +00:00
|
|
|
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
|
|
|
(net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
|
2014-07-22 09:09:48 +00:00
|
|
|
net->nips == 0)) {
|
2008-11-12 16:35:47 +00:00
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
2010-02-19 15:49:56 +00:00
|
|
|
int veid = openvzGetVEID(vpsid);
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2013-06-04 07:44:32 +00:00
|
|
|
/* if net is ethernet and the user has specified guest interface name,
|
|
|
|
* let's use it; otherwise generate a new one */
|
|
|
|
if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
|
|
|
|
net->data.ethernet.dev != NULL) {
|
|
|
|
if (VIR_STRDUP(guest_ifname, net->data.ethernet.dev) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
guest_ifname = openvzGenerateContainerVethName(veid);
|
|
|
|
if (guest_ifname == NULL) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not generate eth name for container"));
|
2013-05-19 09:17:19 +00:00
|
|
|
goto cleanup;
|
2010-08-18 15:05:02 +00:00
|
|
|
}
|
2008-11-12 16:35:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if user doesn't specified host interface name,
|
|
|
|
* than we need to generate it */
|
|
|
|
if (net->ifname == NULL) {
|
2013-06-06 07:53:54 +00:00
|
|
|
net->ifname = openvzGenerateVethName(veid, guest_ifname);
|
2008-11-12 16:35:47 +00:00
|
|
|
if (net->ifname == NULL) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not generate veth name"));
|
2013-05-19 09:17:19 +00:00
|
|
|
goto cleanup;
|
2008-11-12 16:35:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-04 07:44:32 +00:00
|
|
|
virBufferAdd(&buf, guest_ifname, -1); /* Guest dev */
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, ",%s", macaddr); /* Guest dev mac */
|
|
|
|
virBufferAsprintf(&buf, ",%s", net->ifname); /* Host dev */
|
|
|
|
virBufferAsprintf(&buf, ",%s", host_macaddr); /* Host dev mac */
|
2008-11-12 16:35:47 +00:00
|
|
|
|
2010-08-18 15:05:02 +00:00
|
|
|
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
|
|
|
if (driver->version >= VZCTL_BRIDGE_MIN_VERSION) {
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, ",%s", net->data.bridge.brname); /* Host bridge */
|
2010-08-18 15:05:02 +00:00
|
|
|
} else {
|
2013-06-04 07:44:32 +00:00
|
|
|
virBufferAsprintf(configBuf, "ifname=%s", guest_ifname);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(configBuf, ",mac=%s", macaddr); /* Guest dev mac */
|
|
|
|
virBufferAsprintf(configBuf, ",host_ifname=%s", net->ifname); /* Host dev */
|
|
|
|
virBufferAsprintf(configBuf, ",host_mac=%s", host_macaddr); /* Host dev mac */
|
|
|
|
virBufferAsprintf(configBuf, ",bridge=%s", net->data.bridge.brname); /* Host bridge */
|
2010-08-18 15:05:02 +00:00
|
|
|
}
|
2008-07-28 14:06:54 +00:00
|
|
|
}
|
2008-11-12 16:35:47 +00:00
|
|
|
|
2013-05-19 09:17:19 +00:00
|
|
|
/* --netif_add ifname[,mac,host_ifname,host_mac] */
|
|
|
|
virCommandAddArg(cmd, "--netif_add");
|
|
|
|
virCommandAddArgBuffer(cmd, &buf);
|
2008-11-12 16:35:47 +00:00
|
|
|
} else if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
|
2014-07-22 09:09:48 +00:00
|
|
|
net->nips > 0) {
|
2014-11-12 08:30:09 +00:00
|
|
|
size_t i;
|
|
|
|
|
2011-01-28 21:38:06 +00:00
|
|
|
/* --ipadd ip */
|
2014-11-12 08:30:09 +00:00
|
|
|
for (i = 0; i < net->nips; i++) {
|
|
|
|
char *ipStr = virSocketAddrFormat(&net->ips[i]->address);
|
2015-01-09 15:48:37 +00:00
|
|
|
if (!ipStr)
|
|
|
|
goto cleanup;
|
2014-11-12 08:30:09 +00:00
|
|
|
virCommandAddArgList(cmd, "--ipadd", ipStr, NULL);
|
2015-01-09 12:38:17 +00:00
|
|
|
VIR_FREE(ipStr);
|
2014-11-12 08:30:09 +00:00
|
|
|
}
|
2008-07-28 14:06:54 +00:00
|
|
|
}
|
|
|
|
|
2011-01-28 21:38:06 +00:00
|
|
|
/* TODO: processing NAT and physical device */
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2013-05-19 09:17:19 +00:00
|
|
|
virCommandAddArg(cmd, "--save");
|
|
|
|
rc = virCommandRun(cmd, NULL);
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2013-05-19 09:17:19 +00:00
|
|
|
cleanup:
|
|
|
|
virCommandFree(cmd);
|
2013-06-04 07:44:32 +00:00
|
|
|
VIR_FREE(guest_ifname);
|
2008-07-28 14:06:54 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-11-12 16:35:47 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainSetNetworkConfig(virConnectPtr conn,
|
|
|
|
virDomainDefPtr def)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/openvz/ 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-11-12 16:35:47 +00:00
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
char *param;
|
|
|
|
int first = 1;
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2008-11-12 16:35:47 +00:00
|
|
|
|
2013-05-21 07:21:19 +00:00
|
|
|
for (i = 0; i < def->nnets; i++) {
|
2008-11-12 16:35:47 +00:00
|
|
|
if (driver->version < VZCTL_BRIDGE_MIN_VERSION &&
|
|
|
|
def->nets[i]->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
|
|
|
if (first)
|
|
|
|
first = 0;
|
|
|
|
else
|
|
|
|
virBufferAddLit(&buf, ";");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (openvzDomainSetNetwork(conn, def->name, def->nets[i], &buf) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not configure network"));
|
2008-11-12 16:35:47 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (driver->version < VZCTL_BRIDGE_MIN_VERSION && def->nnets) {
|
|
|
|
param = virBufferContentAndReset(&buf);
|
|
|
|
if (param) {
|
2009-03-24 10:59:13 +00:00
|
|
|
if (openvzWriteVPSConfigParam(strtoI(def->name), "NETIF", param) < 0) {
|
2008-11-12 16:35:47 +00:00
|
|
|
VIR_FREE(param);
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("cannot replace NETIF config"));
|
2008-11-12 16:35:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
VIR_FREE(param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
exit:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buf);
|
2008-11-12 16:35:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
static virDomainPtr
|
2014-11-18 14:19:38 +00:00
|
|
|
openvzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
|
2007-09-03 15:37:07 +00:00
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2008-09-05 14:10:58 +00:00
|
|
|
virDomainDefPtr vmdef = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
2008-07-16 14:45:55 +00:00
|
|
|
virDomainPtr dom = NULL;
|
2014-11-18 17:34:42 +00:00
|
|
|
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2014-11-18 17:34:42 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL);
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_DEFINE_VALIDATE)
|
|
|
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE;
|
2014-11-18 14:19:38 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-03-28 13:55:55 +00:00
|
|
|
if ((vmdef = virDomainDefParseString(xml, driver->caps, driver->xmlopt,
|
|
|
|
1 << VIR_DOMAIN_VIRT_OPENVZ,
|
2014-11-18 17:34:42 +00:00
|
|
|
parse_flags)) == NULL)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByName(driver->domains, vmdef->name);
|
2007-09-03 15:37:07 +00:00
|
|
|
if (vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Already an OPENVZ VM active with the id '%s'"),
|
|
|
|
vmdef->name);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
2013-03-28 13:55:55 +00:00
|
|
|
if (!(vm = virDomainObjListAdd(driver->domains, vmdef,
|
2013-03-31 18:03:42 +00:00
|
|
|
driver->xmlopt,
|
2013-03-28 13:55:55 +00:00
|
|
|
0, NULL)))
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
vmdef = 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
|
|
|
vm->persistent = 1;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
if (openvzSetInitialConfig(vm->def) < 0) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_ERROR(_("Error creating initial configuration"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
|
|
|
|
2012-05-05 06:52:23 +00:00
|
|
|
if (vm->def->nfss == 1) {
|
2012-05-25 17:48:33 +00:00
|
|
|
if (openvzSetDiskQuota(vm->def, vm->def->fss[0], true) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set disk quota"));
|
2012-05-05 06:52:23 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
if (openvzSetDefinedUUID(strtoI(vm->def->name), vm->def->uuid) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set UUID"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-08-05 10:53:05 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
if (openvzDomainSetNetworkConfig(conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2010-09-29 16:20:07 +00:00
|
|
|
if (vm->def->vcpus != vm->def->maxvcpus) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("current vcpu count must equal maximum"));
|
2010-09-29 16:20:07 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (vm->def->maxvcpus > 0) {
|
|
|
|
if (openvzDomainSetVcpusInternal(vm, vm->def->maxvcpus) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2013-01-30 14:17:34 +00:00
|
|
|
_("Could not set number of vCPUs"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-08-20 13:44:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 14:43:39 +00:00
|
|
|
if (vm->def->mem.cur_balloon > 0) {
|
|
|
|
if (openvzDomainSetMemoryInternal(vm, vm->def->mem.cur_balloon) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set memory size"));
|
2009-11-02 16:39:46 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
|
|
|
if (dom)
|
|
|
|
dom->id = -1;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-12-04 21:41:51 +00:00
|
|
|
virDomainDefFree(vmdef);
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
2007-09-03 15:37:07 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
2014-11-18 14:19:38 +00:00
|
|
|
static virDomainPtr
|
|
|
|
openvzDomainDefineXML(virConnectPtr conn, const char *xml)
|
|
|
|
{
|
|
|
|
return openvzDomainDefineXMLFlags(conn, xml, 0);
|
|
|
|
}
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
static virDomainPtr
|
2008-10-10 09:32:27 +00:00
|
|
|
openvzDomainCreateXML(virConnectPtr conn, const char *xml,
|
2010-05-25 17:13:13 +00:00
|
|
|
unsigned int flags)
|
2007-09-03 15:37:07 +00:00
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2008-09-05 14:10:58 +00:00
|
|
|
virDomainDefPtr vmdef = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
2008-07-16 14:45:55 +00:00
|
|
|
virDomainPtr dom = NULL;
|
2013-07-30 16:49:53 +00:00
|
|
|
const char *progstart[] = {VZCTL, "--quiet", "start", PROGRAM_SENTINEL, NULL};
|
2014-11-18 17:34:42 +00:00
|
|
|
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2014-11-18 17:34:42 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_START_VALIDATE, NULL);
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_START_VALIDATE)
|
|
|
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE;
|
2010-05-25 17:13:13 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-03-28 13:55:55 +00:00
|
|
|
if ((vmdef = virDomainDefParseString(xml, driver->caps, driver->xmlopt,
|
|
|
|
1 << VIR_DOMAIN_VIRT_OPENVZ,
|
2014-11-18 17:34:42 +00:00
|
|
|
parse_flags)) == NULL)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByName(driver->domains, vmdef->name);
|
2007-09-03 15:37:07 +00:00
|
|
|
if (vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Already an OPENVZ VM defined with the id '%s'"),
|
|
|
|
vmdef->name);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
2013-01-11 16:04:47 +00:00
|
|
|
if (!(vm = virDomainObjListAdd(driver->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
|
|
|
vmdef,
|
2013-03-28 13:55:55 +00:00
|
|
|
driver->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)))
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
vmdef = 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
|
|
|
/* All OpenVZ domains seem to be persistent - this is a bit of a violation
|
|
|
|
* of this libvirt API which is intended for transient domain creation */
|
|
|
|
vm->persistent = 1;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
if (openvzSetInitialConfig(vm->def) < 0) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_ERROR(_("Error creating initial configuration"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2012-05-05 06:52:23 +00:00
|
|
|
if (vm->def->nfss == 1) {
|
2012-05-25 17:48:33 +00:00
|
|
|
if (openvzSetDiskQuota(vm->def, vm->def->fss[0], true) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set disk quota"));
|
2012-05-05 06:52:23 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
if (openvzSetDefinedUUID(strtoI(vm->def->name), vm->def->uuid) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set UUID"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-08-05 10:53:05 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
if (openvzDomainSetNetworkConfig(conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
openvzSetProgramSentinal(progstart, vm->def->name);
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2014-11-13 14:29:21 +00:00
|
|
|
if (virRun(progstart, NULL) < 0)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
vm->pid = strtoI(vm->def->name);
|
2008-09-05 14:10:58 +00:00
|
|
|
vm->def->id = vm->pid;
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2010-09-29 16:20:07 +00:00
|
|
|
if (vm->def->maxvcpus > 0) {
|
|
|
|
if (openvzDomainSetVcpusInternal(vm, vm->def->maxvcpus) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2013-01-30 14:17:34 +00:00
|
|
|
_("Could not set number of vCPUs"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-08-20 13:44:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
|
|
|
if (dom)
|
|
|
|
dom->id = vm->def->id;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-12-04 21:41:51 +00:00
|
|
|
virDomainDefFree(vmdef);
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
2007-09-03 15:37:07 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-06-10 15:55:36 +00:00
|
|
|
openvzDomainCreateWithFlags(virDomainPtr dom, unsigned int flags)
|
2007-09-03 15:37:07 +00:00
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
2013-07-30 16:49:53 +00:00
|
|
|
const char *prog[] = {VZCTL, "--quiet", "start", PROGRAM_SENTINEL, NULL };
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2011-07-29 08:41:32 +00:00
|
|
|
int status;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2010-06-10 15:55:36 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByName(driver->domains, dom->name);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching id"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2011-07-29 08:41:32 +00:00
|
|
|
if (openvzGetVEStatus(vm, &status, NULL) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (status != VIR_DOMAIN_SHUTOFF) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_DENIED, "%s",
|
|
|
|
_("domain is not in shutoff state"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2014-11-13 14:29:21 +00:00
|
|
|
if (virRun(prog, NULL) < 0)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
vm->pid = strtoI(vm->def->name);
|
|
|
|
vm->def->id = vm->pid;
|
2010-07-30 08:36:06 +00:00
|
|
|
dom->id = vm->pid;
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 15:55:36 +00:00
|
|
|
static int
|
|
|
|
openvzDomainCreate(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
return openvzDomainCreateWithFlags(dom, 0);
|
|
|
|
}
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
static int
|
2011-07-20 03:08:21 +00:00
|
|
|
openvzDomainUndefineFlags(virDomainPtr dom,
|
|
|
|
unsigned int flags)
|
2007-09-03 15:37:07 +00:00
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
2013-07-30 16:49:53 +00:00
|
|
|
const char *prog[] = { VZCTL, "--quiet", "destroy", PROGRAM_SENTINEL, NULL };
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2011-07-29 08:41:32 +00:00
|
|
|
int status;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2011-07-20 03:08:21 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2007-09-03 15:37:07 +00:00
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2011-07-29 08:41:32 +00:00
|
|
|
if (openvzGetVEStatus(vm, &status, NULL) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2014-11-13 14:29:21 +00:00
|
|
|
if (virRun(prog, NULL) < 0)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2011-08-19 13:48:47 +00:00
|
|
|
if (virDomainObjIsActive(vm)) {
|
|
|
|
vm->persistent = 0;
|
|
|
|
} else {
|
2013-01-11 16:04:47 +00:00
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
2011-08-19 13:48:47 +00:00
|
|
|
vm = NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2011-07-20 03:08:21 +00:00
|
|
|
static int
|
|
|
|
openvzDomainUndefine(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
return openvzDomainUndefineFlags(dom, 0);
|
|
|
|
}
|
2008-07-10 07:52:14 +00:00
|
|
|
static int
|
|
|
|
openvzDomainSetAutostart(virDomainPtr dom, int autostart)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
2013-07-30 16:49:53 +00:00
|
|
|
const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINEL,
|
2008-07-10 12:21:09 +00:00
|
|
|
"--onboot", autostart ? "yes" : "no",
|
2008-07-10 07:52:14 +00:00
|
|
|
"--save", NULL };
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2008-07-10 07:52:14 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2008-07-10 07:52:14 +00:00
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-07-10 07:52:14 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2014-11-13 14:29:21 +00:00
|
|
|
if (virRun(prog, NULL) < 0)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
ret = 0;
|
2008-07-10 07:52:14 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2008-07-10 07:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainGetAutostart(virDomainPtr dom, int *autostart)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
2011-04-03 09:21:26 +00:00
|
|
|
char *value = NULL;
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2008-07-10 07:52:14 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2008-07-10 07:52:14 +00:00
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-07-10 07:52:14 +00:00
|
|
|
}
|
|
|
|
|
2011-04-03 09:21:26 +00:00
|
|
|
if (openvzReadVPSConfigParam(strtoI(vm->def->name), "ONBOOT", &value) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not read container config"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-07-10 07:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*autostart = 0;
|
2013-11-19 23:04:25 +00:00
|
|
|
if (STREQ(value, "yes"))
|
2008-07-10 12:21:09 +00:00
|
|
|
*autostart = 1;
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
2008-07-10 07:52:14 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2011-04-03 09:21:26 +00:00
|
|
|
VIR_FREE(value);
|
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2008-07-10 07:52:14 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int openvzConnectGetMaxVcpus(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
const char *type)
|
2009-08-17 12:24:27 +00:00
|
|
|
{
|
|
|
|
if (type == NULL || STRCASEEQ(type, "openvz"))
|
|
|
|
return 1028; /* OpenVZ has no limitation */
|
2008-08-20 13:44:03 +00:00
|
|
|
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("unknown type '%s'"), type);
|
2008-08-20 13:44:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
openvzDomainGetVcpusFlags(virDomainPtr dom ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2011-06-08 06:33:33 +00:00
|
|
|
if (flags != (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_VCPU_MAXIMUM)) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("unsupported flags (0x%x)"), flags);
|
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-08-20 13:44:03 +00:00
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
return openvzConnectGetMaxVcpus(NULL, "openvz");
|
2008-08-20 13:44:03 +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 openvzDomainGetMaxVcpus(virDomainPtr dom)
|
|
|
|
{
|
2011-06-08 06:33:33 +00:00
|
|
|
return openvzDomainGetVcpusFlags(dom, (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));
|
|
|
|
}
|
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
static int openvzDomainSetVcpusInternal(virDomainObjPtr vm,
|
|
|
|
unsigned int nvcpus)
|
2008-12-17 21:13:19 +00:00
|
|
|
{
|
|
|
|
char str_vcpus[32];
|
2013-07-30 16:49:53 +00:00
|
|
|
const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINEL,
|
2008-08-20 13:44:03 +00:00
|
|
|
"--cpus", str_vcpus, "--save", NULL };
|
2008-11-24 19:34:21 +00:00
|
|
|
unsigned int pcpus;
|
2008-12-17 21:13:19 +00:00
|
|
|
pcpus = openvzGetNodeCPUs();
|
|
|
|
if (pcpus > 0 && pcpus < nvcpus)
|
|
|
|
nvcpus = pcpus;
|
|
|
|
|
|
|
|
snprintf(str_vcpus, 31, "%d", nvcpus);
|
|
|
|
str_vcpus[31] = '\0';
|
|
|
|
|
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2014-11-13 14:29:21 +00:00
|
|
|
if (virRun(prog, NULL) < 0)
|
2008-12-17 21:13:19 +00:00
|
|
|
return -1;
|
|
|
|
|
2010-09-29 16:20:07 +00:00
|
|
|
vm->def->maxvcpus = vm->def->vcpus = nvcpus;
|
2008-12-17 21:13:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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 openvzDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|
|
|
unsigned int flags)
|
2008-12-17 21:13:19 +00:00
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
int ret = -1;
|
2008-08-20 13:44:03 +00:00
|
|
|
|
2011-06-08 06:33:33 +00:00
|
|
|
if (flags != VIR_DOMAIN_AFFECT_LIVE) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("unsupported flags (0x%x)"), flags);
|
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 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2008-08-20 13:44:03 +00:00
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-08-20 13:44:03 +00:00
|
|
|
}
|
|
|
|
|
2008-09-08 12:15:33 +00:00
|
|
|
if (nvcpus <= 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2013-01-30 14:17:34 +00:00
|
|
|
_("Number of vCPUs should be >= 1"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (openvzDomainSetVcpusInternal(vm, nvcpus) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set number of vCPUs"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-09-08 12:15:33 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2008-08-20 13:44:03 +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
|
|
|
|
openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
|
|
|
|
{
|
2011-06-08 06:33:33 +00:00
|
|
|
return openvzDomainSetVcpusFlags(dom, nvcpus, 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
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags)
|
2007-12-26 05:41:05 +00:00
|
|
|
{
|
2008-09-05 14:10:58 +00:00
|
|
|
struct openvz_driver *driver;
|
2008-11-17 11:44:51 +00:00
|
|
|
|
2011-07-06 22:34:58 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
2008-11-17 11:44:51 +00:00
|
|
|
if (conn->uri == NULL) {
|
2009-06-12 12:06:15 +00:00
|
|
|
if (!virFileExists("/proc/vz"))
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
if (access("/proc/vz", W_OK) < 0)
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
Centralize error reporting for URI parsing/formatting problems
Move error reporting out of the callers, into virURIParse
and virURIFormat, to get consistency.
* include/libvirt/virterror.h, src/util/virterror.c: Add VIR_FROM_URI
* src/util/viruri.c, src/util/viruri.h: Add error reporting
* src/esx/esx_driver.c, src/libvirt.c, src/libxl/libxl_driver.c,
src/lxc/lxc_driver.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/qemu/qemu_migration.c,
src/remote/remote_driver.c, src/uml/uml_driver.c,
src/vbox/vbox_tmpl.c, src/vmx/vmx.c, src/xen/xen_driver.c,
src/xen/xend_internal.c, tests/viruritest.c: Remove error
reporting
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-03-20 12:16:54 +00:00
|
|
|
if (!(conn->uri = virURIParse("openvz:///system")))
|
2009-06-12 12:06:15 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
} else {
|
|
|
|
/* If scheme isn't 'openvz', then its for another driver */
|
|
|
|
if (conn->uri->scheme == NULL ||
|
2012-10-17 09:23:12 +00:00
|
|
|
STRNEQ(conn->uri->scheme, "openvz"))
|
2009-06-12 12:06:15 +00:00
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
/* If server name is given, its for remote driver */
|
|
|
|
if (conn->uri->server != NULL)
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
/* If path isn't /system, then they typoed, so tell them correct path */
|
|
|
|
if (conn->uri->path == NULL ||
|
2012-10-17 09:23:12 +00:00
|
|
|
STRNEQ(conn->uri->path, "/system")) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unexpected OpenVZ URI path '%s', try openvz:///system"),
|
|
|
|
conn->uri->path);
|
2009-06-12 12:06:15 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virFileExists("/proc/vz")) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("OpenVZ control file /proc/vz does not exist"));
|
2009-06-12 12:06:15 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (access("/proc/vz", W_OK) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("OpenVZ control file /proc/vz is not accessible"));
|
2008-11-17 11:44:51 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
2008-09-05 14:10:58 +00:00
|
|
|
}
|
|
|
|
|
2009-06-12 12:06:15 +00:00
|
|
|
/* We now know the URI is definitely for this driver, so beyond
|
|
|
|
* here, don't return DECLINED, always use ERROR */
|
|
|
|
|
2013-07-04 10:13:02 +00:00
|
|
|
if (VIR_ALLOC(driver) < 0)
|
2008-09-05 14:10:58 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
|
2013-01-11 16:04:47 +00:00
|
|
|
if (!(driver->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 cleanup;
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if (!(driver->caps = openvzCapsInit()))
|
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2013-03-06 14:48:06 +00:00
|
|
|
if (!(driver->xmlopt = virDomainXMLOptionNew(&openvzDomainDefParserConfig,
|
|
|
|
NULL, NULL)))
|
2013-03-05 15:17:24 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if (openvzLoadDomains(driver) < 0)
|
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
if (openvzExtractVersion(driver) < 0)
|
2008-10-24 11:32:48 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
conn->privateData = driver;
|
2008-08-27 11:19:45 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2008-09-05 14:10:58 +00:00
|
|
|
openvzFreeDriver(driver);
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
2007-12-26 05:41:05 +00:00
|
|
|
};
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2014-03-18 08:16:47 +00:00
|
|
|
static int openvzConnectClose(virConnectPtr conn)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
openvzFreeDriver(driver);
|
2007-07-17 13:27:26 +00:00
|
|
|
conn->privateData = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static const char *openvzConnectGetType(virConnectPtr conn ATTRIBUTE_UNUSED) {
|
2009-08-03 10:42:39 +00:00
|
|
|
return "OpenVZ";
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2014-03-18 08:16:47 +00:00
|
|
|
static int openvzConnectIsEncrypted(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
|
|
|
/* Encryption is not relevant / applicable to way we talk to openvz */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-18 08:16:47 +00:00
|
|
|
static int openvzConnectIsSecure(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
|
|
|
/* We run CLI tools directly so this is secure */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-09-23 06:56:13 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
openvzConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
|
2011-09-23 06:56:13 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static char *openvzConnectGetCapabilities(virConnectPtr conn) {
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
|
|
|
char *ret;
|
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = virCapabilitiesFormatXML(driver->caps);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2008-09-05 14:10:58 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int openvzConnectListDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2014-03-18 08:16:47 +00:00
|
|
|
int *ids, int nids)
|
|
|
|
{
|
2007-07-17 13:27:26 +00:00
|
|
|
int got = 0;
|
2008-12-18 11:58:28 +00:00
|
|
|
int veid;
|
2008-08-20 09:08:17 +00:00
|
|
|
int outfd = -1;
|
2011-05-06 20:21:58 +00:00
|
|
|
int rc = -1;
|
2007-07-19 16:22:40 +00:00
|
|
|
int ret;
|
|
|
|
char buf[32];
|
2008-07-21 13:34:19 +00:00
|
|
|
char *endptr;
|
2013-11-19 23:04:25 +00:00
|
|
|
virCommandPtr cmd = virCommandNewArgList(VZLIST, "-ovpsid", "-H", NULL);
|
2011-05-06 20:21:58 +00:00
|
|
|
|
|
|
|
virCommandSetOutputFD(cmd, &outfd);
|
|
|
|
if (virCommandRunAsync(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2010-08-31 22:43:18 +00:00
|
|
|
while (got < nids) {
|
2007-07-19 16:22:40 +00:00
|
|
|
ret = openvz_readline(outfd, buf, 32);
|
2010-08-31 22:43:18 +00:00
|
|
|
if (!ret)
|
|
|
|
break;
|
2008-07-21 13:34:19 +00:00
|
|
|
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not parse VPS ID %s"), buf);
|
2008-07-21 13:34:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-07-17 13:27:26 +00:00
|
|
|
ids[got] = veid;
|
|
|
|
got ++;
|
|
|
|
}
|
2011-05-06 20:21:58 +00:00
|
|
|
|
|
|
|
if (virCommandWait(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2010-12-01 16:43:46 +00:00
|
|
|
if (VIR_CLOSE(outfd) < 0) {
|
|
|
|
virReportSystemError(errno, "%s", _("failed to close file"));
|
2011-05-06 20:21:58 +00:00
|
|
|
goto cleanup;
|
2010-12-01 16:43:46 +00:00
|
|
|
}
|
2011-05-06 20:21:58 +00:00
|
|
|
|
|
|
|
rc = got;
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2011-05-06 20:21:58 +00:00
|
|
|
VIR_FORCE_CLOSE(outfd);
|
|
|
|
virCommandFree(cmd);
|
|
|
|
return rc;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2014-03-18 08:16:47 +00:00
|
|
|
static int openvzConnectNumOfDomains(virConnectPtr conn)
|
|
|
|
{
|
2008-09-05 14:10:58 +00:00
|
|
|
struct openvz_driver *driver = 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-10-10 14:20:37 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-06-24 16:49:47 +00:00
|
|
|
n = virDomainObjListNumOfDomains(driver->domains, true, NULL, NULL);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
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 n;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int openvzConnectListDefinedDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
char **const names, int nnames) {
|
2007-07-17 13:27:26 +00:00
|
|
|
int got = 0;
|
2010-12-01 16:43:46 +00:00
|
|
|
int veid, outfd = -1, ret;
|
2011-05-06 20:21:58 +00:00
|
|
|
int rc = -1;
|
2008-09-05 14:10:58 +00:00
|
|
|
char vpsname[32];
|
2007-07-19 16:22:40 +00:00
|
|
|
char buf[32];
|
2008-07-21 13:34:19 +00:00
|
|
|
char *endptr;
|
2011-05-06 20:21:58 +00:00
|
|
|
virCommandPtr cmd = virCommandNewArgList(VZLIST,
|
|
|
|
"-ovpsid", "-H", "-S", NULL);
|
2007-07-17 13:27:26 +00:00
|
|
|
|
|
|
|
/* the -S options lists only stopped domains */
|
2011-05-06 20:21:58 +00:00
|
|
|
virCommandSetOutputFD(cmd, &outfd);
|
|
|
|
if (virCommandRunAsync(cmd, NULL) < 0)
|
2010-12-01 16:43:46 +00:00
|
|
|
goto out;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2010-08-31 22:43:18 +00:00
|
|
|
while (got < nnames) {
|
2007-07-19 16:22:40 +00:00
|
|
|
ret = openvz_readline(outfd, buf, 32);
|
2010-08-31 22:43:18 +00:00
|
|
|
if (!ret)
|
|
|
|
break;
|
2008-07-21 13:34:19 +00:00
|
|
|
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not parse VPS ID %s"), buf);
|
2008-07-21 13:34:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-09-05 14:10:58 +00:00
|
|
|
snprintf(vpsname, sizeof(vpsname), "%d", veid);
|
2013-05-03 12:45:31 +00:00
|
|
|
if (VIR_STRDUP(names[got], vpsname) < 0)
|
2010-12-01 16:43:46 +00:00
|
|
|
goto out;
|
2007-07-17 13:27:26 +00:00
|
|
|
got ++;
|
|
|
|
}
|
2011-05-06 20:21:58 +00:00
|
|
|
|
|
|
|
if (virCommandWait(cmd, NULL) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-12-01 16:43:46 +00:00
|
|
|
if (VIR_CLOSE(outfd) < 0) {
|
|
|
|
virReportSystemError(errno, "%s", _("failed to close file"));
|
|
|
|
goto out;
|
|
|
|
}
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2011-05-06 20:21:58 +00:00
|
|
|
rc = got;
|
2014-03-25 06:57:22 +00:00
|
|
|
out:
|
2010-12-01 16:43:46 +00:00
|
|
|
VIR_FORCE_CLOSE(outfd);
|
2011-05-06 20:21:58 +00:00
|
|
|
virCommandFree(cmd);
|
2011-05-17 15:12:16 +00:00
|
|
|
if (rc < 0) {
|
2013-05-21 07:21:19 +00:00
|
|
|
for (; got >= 0; got--)
|
2011-05-06 20:21:58 +00:00
|
|
|
VIR_FREE(names[got]);
|
|
|
|
}
|
|
|
|
return rc;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2011-04-03 09:21:26 +00:00
|
|
|
static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char *line = NULL;
|
|
|
|
size_t line_size = 0;
|
2008-07-21 08:08:25 +00:00
|
|
|
unsigned long long usertime, systime, nicetime;
|
2010-04-14 07:09:57 +00:00
|
|
|
int readvps = vpsid + 1; /* ensure readvps is initially different */
|
2011-04-03 09:21:26 +00:00
|
|
|
ssize_t ret;
|
2011-05-27 15:13:58 +00:00
|
|
|
int err = 0;
|
2008-07-21 08:08:25 +00:00
|
|
|
|
|
|
|
/* read statistic from /proc/vz/vestat.
|
2014-03-25 06:57:22 +00:00
|
|
|
sample:
|
2008-07-21 08:08:25 +00:00
|
|
|
Version: 2.2
|
2010-04-14 07:09:57 +00:00
|
|
|
VEID user nice system uptime idle other..
|
|
|
|
33 78 0 1330 59454597 142650441835148 other..
|
|
|
|
55 178 0 5340 59424597 542650441835148 other..
|
2008-07-21 08:08:25 +00:00
|
|
|
*/
|
|
|
|
|
2011-04-03 09:21:26 +00:00
|
|
|
if ((fp = fopen("/proc/vz/vestat", "r")) == NULL)
|
2008-07-21 08:08:25 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/*search line with VEID=vpsid*/
|
2010-08-31 22:43:18 +00:00
|
|
|
while (1) {
|
2011-04-03 09:21:26 +00:00
|
|
|
ret = getline(&line, &line_size, fp);
|
2011-05-27 15:13:58 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
err = !feof(fp);
|
2008-07-21 08:08:25 +00:00
|
|
|
break;
|
2011-05-27 15:13:58 +00:00
|
|
|
}
|
2008-07-21 08:08:25 +00:00
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
if (sscanf(line, "%d %llu %llu %llu",
|
|
|
|
&readvps, &usertime, &nicetime, &systime) == 4
|
2010-04-14 07:09:57 +00:00
|
|
|
&& readvps == vpsid) { /*found vpsid*/
|
|
|
|
/* convert jiffies to nanoseconds */
|
|
|
|
*cpuTime = (1000ull * 1000ull * 1000ull
|
|
|
|
* (usertime + nicetime + systime)
|
|
|
|
/ (unsigned long long)sysconf(_SC_CLK_TCK));
|
|
|
|
break;
|
|
|
|
}
|
2008-07-21 08:08:25 +00:00
|
|
|
}
|
|
|
|
|
2011-04-03 09:21:26 +00:00
|
|
|
VIR_FREE(line);
|
|
|
|
VIR_FORCE_FCLOSE(fp);
|
2011-05-27 15:13:58 +00:00
|
|
|
if (err)
|
2008-07-21 08:08:25 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (readvps != vpsid) /*not found*/
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-18 08:16:47 +00:00
|
|
|
static int openvzConnectNumOfDefinedDomains(virConnectPtr conn)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = 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-10-10 14:20:37 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2013-06-24 16:49:47 +00:00
|
|
|
n = virDomainObjListNumOfDomains(driver->domains, false, NULL, NULL);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
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 n;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 16:39:46 +00:00
|
|
|
static int
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzDomainSetMemoryInternal(virDomainObjPtr vm,
|
2012-03-02 20:27:39 +00:00
|
|
|
unsigned long long mem)
|
2009-11-02 16:39:46 +00:00
|
|
|
{
|
|
|
|
char str_mem[16];
|
2013-07-30 16:49:53 +00:00
|
|
|
const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINEL,
|
2009-11-02 16:39:46 +00:00
|
|
|
"--kmemsize", str_mem, "--save", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* memory has to be changed its format from kbyte to byte */
|
2012-03-02 20:27:39 +00:00
|
|
|
snprintf(str_mem, sizeof(str_mem), "%llu", mem * 1024);
|
2009-11-02 16:39:46 +00:00
|
|
|
|
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2014-11-13 14:29:21 +00:00
|
|
|
if (virRun(prog, NULL) < 0)
|
2009-11-02 16:39:46 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2009-11-02 16:39:46 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-04-25 19:18:16 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainGetBarrierLimit(virDomainPtr domain,
|
|
|
|
const char *param,
|
|
|
|
unsigned long long *barrier,
|
|
|
|
unsigned long long *limit)
|
|
|
|
{
|
2014-02-20 00:32:19 +00:00
|
|
|
int ret = -1;
|
2012-04-25 19:18:16 +00:00
|
|
|
char *endp, *output = NULL;
|
|
|
|
const char *tmp;
|
|
|
|
virCommandPtr cmd = virCommandNewArgList(VZLIST, "--no-header", NULL);
|
|
|
|
|
|
|
|
virCommandSetOutputBuffer(cmd, &output);
|
|
|
|
virCommandAddArgFormat(cmd, "-o%s.b,%s.l", param, param);
|
|
|
|
virCommandAddArg(cmd, domain->name);
|
2014-02-20 00:32:19 +00:00
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2012-04-25 19:18:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
tmp = output;
|
|
|
|
virSkipSpaces(&tmp);
|
|
|
|
if (virStrToLong_ull(tmp, &endp, 10, barrier) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Can't parse limit from "VZLIST" output '%s'"), output);
|
2012-04-25 19:18:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
tmp = endp;
|
|
|
|
virSkipSpaces(&tmp);
|
|
|
|
if (virStrToLong_ull(tmp, &endp, 10, limit) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Can't parse barrier from "VZLIST" output '%s'"), output);
|
2012-04-25 19:18:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2012-04-25 19:18:16 +00:00
|
|
|
VIR_FREE(output);
|
|
|
|
virCommandFree(cmd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainSetBarrierLimit(virDomainPtr domain,
|
|
|
|
const char *param,
|
|
|
|
unsigned long long barrier,
|
|
|
|
unsigned long long limit)
|
|
|
|
{
|
2014-02-20 00:32:19 +00:00
|
|
|
int ret = -1;
|
2012-04-25 19:18:16 +00:00
|
|
|
virCommandPtr cmd = virCommandNewArgList(VZCTL, "--quiet", "set", NULL);
|
|
|
|
|
|
|
|
/* LONG_MAX indicates unlimited so reject larger values */
|
|
|
|
if (barrier > LONG_MAX || limit > LONG_MAX) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Failed to set %s for %s: value too large"), param,
|
|
|
|
domain->name);
|
2012-04-25 19:18:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
virCommandAddArg(cmd, domain->name);
|
|
|
|
virCommandAddArgFormat(cmd, "--%s", param);
|
|
|
|
virCommandAddArgFormat(cmd, "%llu:%llu", barrier, limit);
|
|
|
|
virCommandAddArg(cmd, "--save");
|
2014-02-20 00:32:19 +00:00
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2012-04-25 19:18:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2012-04-25 19:18:16 +00:00
|
|
|
virCommandFree(cmd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainGetMemoryParameters(virDomainPtr domain,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/openvz/ 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 result = -1;
|
2012-04-25 19:18:16 +00:00
|
|
|
const char *name;
|
|
|
|
long kb_per_pages;
|
|
|
|
unsigned long long barrier, limit, val;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2012-05-07 21:00:28 +00:00
|
|
|
kb_per_pages = openvzKBPerPages();
|
|
|
|
if (kb_per_pages < 0)
|
2012-04-25 19:18:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (*nparams == 0) {
|
|
|
|
*nparams = OPENVZ_NB_MEM_PARAM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i <= *nparams; i++) {
|
|
|
|
virMemoryParameterPtr param = ¶ms[i];
|
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
name = "privvmpages";
|
|
|
|
if (openvzDomainGetBarrierLimit(domain, name, &barrier, &limit) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
val = (limit == LONG_MAX) ? 0ull : limit * kb_per_pages;
|
|
|
|
if (virTypedParameterAssign(param, VIR_DOMAIN_MEMORY_HARD_LIMIT,
|
|
|
|
VIR_TYPED_PARAM_ULLONG, val) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
name = "privvmpages";
|
|
|
|
if (openvzDomainGetBarrierLimit(domain, name, &barrier, &limit) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
val = (barrier == LONG_MAX) ? 0ull : barrier * kb_per_pages;
|
|
|
|
if (virTypedParameterAssign(param, VIR_DOMAIN_MEMORY_SOFT_LIMIT,
|
|
|
|
VIR_TYPED_PARAM_ULLONG, val) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
name = "vmguarpages";
|
|
|
|
if (openvzDomainGetBarrierLimit(domain, name, &barrier, &limit) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
val = (barrier == LONG_MAX) ? 0ull : barrier * kb_per_pages;
|
|
|
|
if (virTypedParameterAssign(param, VIR_DOMAIN_MEMORY_MIN_GUARANTEE,
|
|
|
|
VIR_TYPED_PARAM_ULLONG, val) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*nparams > OPENVZ_NB_MEM_PARAM)
|
|
|
|
*nparams = OPENVZ_NB_MEM_PARAM;
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2012-04-25 19:18:16 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainSetMemoryParameters(virDomainPtr domain,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/openvz/ 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 result = -1;
|
2012-04-25 19:18:16 +00:00
|
|
|
long kb_per_pages;
|
|
|
|
|
2012-05-07 21:00:28 +00:00
|
|
|
kb_per_pages = openvzKBPerPages();
|
|
|
|
if (kb_per_pages < 0)
|
2012-04-25 19:18:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
2013-05-03 13:34:10 +00:00
|
|
|
if (virTypedParamsValidate(params, nparams,
|
|
|
|
VIR_DOMAIN_MEMORY_HARD_LIMIT,
|
|
|
|
VIR_TYPED_PARAM_ULLONG,
|
|
|
|
VIR_DOMAIN_MEMORY_SOFT_LIMIT,
|
|
|
|
VIR_TYPED_PARAM_ULLONG,
|
|
|
|
VIR_DOMAIN_MEMORY_MIN_GUARANTEE,
|
|
|
|
VIR_TYPED_PARAM_ULLONG,
|
|
|
|
NULL) < 0)
|
2012-04-25 19:18:16 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0; i < nparams; i++) {
|
|
|
|
virTypedParameterPtr param = ¶ms[i];
|
|
|
|
unsigned long long barrier, limit;
|
|
|
|
|
|
|
|
if (STREQ(param->field, VIR_DOMAIN_MEMORY_HARD_LIMIT)) {
|
|
|
|
if (openvzDomainGetBarrierLimit(domain, "privvmpages",
|
|
|
|
&barrier, &limit) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
limit = params[i].value.ul / kb_per_pages;
|
|
|
|
if (openvzDomainSetBarrierLimit(domain, "privvmpages",
|
|
|
|
barrier, limit) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
} else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT)) {
|
|
|
|
if (openvzDomainGetBarrierLimit(domain, "privvmpages",
|
|
|
|
&barrier, &limit) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
barrier = params[i].value.ul / kb_per_pages;
|
|
|
|
if (openvzDomainSetBarrierLimit(domain, "privvmpages",
|
|
|
|
barrier, limit) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
} else if (STREQ(param->field, VIR_DOMAIN_MEMORY_MIN_GUARANTEE)) {
|
|
|
|
barrier = params[i].value.ul / kb_per_pages;
|
|
|
|
if (openvzDomainSetBarrierLimit(domain, "vmguarpages",
|
|
|
|
barrier, LONG_MAX) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = 0;
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2012-04-25 19:18:16 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-29 08:41:32 +00:00
|
|
|
static int
|
|
|
|
openvzGetVEStatus(virDomainObjPtr vm, int *status, int *reason)
|
|
|
|
{
|
|
|
|
virCommandPtr cmd;
|
|
|
|
char *outbuf;
|
|
|
|
char *line;
|
|
|
|
int state;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
cmd = virCommandNewArgList(VZLIST, vm->def->name, "-ostatus", "-H", NULL);
|
|
|
|
virCommandSetOutputBuffer(cmd, &outbuf);
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((line = strchr(outbuf, '\n')) == NULL) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Failed to parse vzlist output"));
|
2011-07-29 08:41:32 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
*line++ = '\0';
|
|
|
|
|
|
|
|
state = virDomainObjGetState(vm, reason);
|
|
|
|
|
|
|
|
if (STREQ(outbuf, "running")) {
|
|
|
|
/* There is no way to detect whether a domain is paused or not
|
|
|
|
* with vzlist */
|
|
|
|
if (state == VIR_DOMAIN_PAUSED)
|
|
|
|
*status = state;
|
|
|
|
else
|
|
|
|
*status = VIR_DOMAIN_RUNNING;
|
|
|
|
} else {
|
|
|
|
*status = VIR_DOMAIN_SHUTOFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2011-07-29 08:41:32 +00:00
|
|
|
virCommandFree(cmd);
|
|
|
|
VIR_FREE(outbuf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:51:31 +00:00
|
|
|
static int
|
2012-10-17 09:23:12 +00:00
|
|
|
openvzDomainInterfaceStats(virDomainPtr dom,
|
|
|
|
const char *path,
|
2014-09-16 13:19:45 +00:00
|
|
|
virDomainInterfaceStatsPtr stats)
|
2012-04-19 21:51:31 +00:00
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
Convert 'int i' to 'size_t i' in src/openvz/ 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-04-19 21:51:31 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2012-04-19 21:51:31 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
virUUIDFormat(dom->uuid, uuidstr);
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("no domain with matching uuid '%s'"), uuidstr);
|
2012-04-19 21:51:31 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virDomainObjIsActive(vm)) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
"%s", _("domain is not running"));
|
2012-04-19 21:51:31 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the path is one of the domain's network interfaces. */
|
2013-05-21 07:21:19 +00:00
|
|
|
for (i = 0; i < vm->def->nnets; i++) {
|
2012-04-19 21:51:31 +00:00
|
|
|
if (vm->def->nets[i]->ifname &&
|
2012-10-17 09:23:12 +00:00
|
|
|
STREQ(vm->def->nets[i]->ifname, path)) {
|
2012-04-19 21:51:31 +00:00
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == 0)
|
2014-07-05 15:34:39 +00:00
|
|
|
ret = virNetInterfaceStats(path, stats);
|
2012-04-19 21:51:31 +00:00
|
|
|
else
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("invalid path, '%s' is not a known interface"), path);
|
2012-04-19 21:51:31 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2012-04-19 21:51:31 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2012-04-19 21:51:31 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-25 17:49:32 +00:00
|
|
|
static int
|
|
|
|
openvzUpdateDevice(virDomainDefPtr vmdef,
|
|
|
|
virDomainDeviceDefPtr dev,
|
|
|
|
bool persist)
|
|
|
|
{
|
|
|
|
virDomainFSDefPtr fs, cur;
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
if (dev->type == VIR_DOMAIN_DEVICE_FS) {
|
|
|
|
fs = dev->data.fs;
|
|
|
|
pos = virDomainFSIndexByName(vmdef, fs->dst);
|
|
|
|
|
|
|
|
if (pos < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("target %s doesn't exist."), fs->dst);
|
2012-05-25 17:49:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
cur = vmdef->fss[pos];
|
|
|
|
|
|
|
|
/* We only allow updating the quota */
|
|
|
|
if (!STREQ(cur->src, fs->src)
|
|
|
|
|| cur->type != fs->type
|
|
|
|
|| cur->accessmode != fs->accessmode
|
|
|
|
|| cur->wrpolicy != fs->wrpolicy
|
|
|
|
|| cur->readonly != fs->readonly) {
|
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_CONFIG_UNSUPPORTED, "%s",
|
2012-07-18 13:13:44 +00:00
|
|
|
_("Can only modify disk quota"));
|
2012-05-25 17:49:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:29:21 +00:00
|
|
|
if (openvzSetDiskQuota(vmdef, fs, persist) < 0)
|
2012-05-25 17:49:32 +00:00
|
|
|
return -1;
|
|
|
|
cur->space_hard_limit = fs->space_hard_limit;
|
|
|
|
cur->space_soft_limit = fs->space_soft_limit;
|
|
|
|
} else {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Can't modify device type '%s'"),
|
|
|
|
virDomainDeviceTypeToString(dev->type));
|
2012-05-25 17:49:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int veid;
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainDeviceDefPtr dev = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainDefPtr vmdef = NULL;
|
|
|
|
bool persist = false;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_LIVE |
|
|
|
|
VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1);
|
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2012-05-25 17:49:32 +00:00
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2012-05-25 17:49:32 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-01-15 18:35:38 +00:00
|
|
|
vmdef = vm->def;
|
2012-05-25 17:49:32 +00:00
|
|
|
|
|
|
|
if (virStrToLong_i(vmdef->name, NULL, 10, &veid) < 0) {
|
2012-07-18 13:13:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not convert domain name to VEID"));
|
2012-05-25 17:49:32 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainLiveConfigHelperMethod(driver->caps,
|
2013-03-31 18:03:42 +00:00
|
|
|
driver->xmlopt,
|
2012-05-25 17:49:32 +00:00
|
|
|
vm,
|
|
|
|
&flags,
|
|
|
|
&vmdef) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-03-28 13:55:55 +00:00
|
|
|
dev = virDomainDeviceDefParse(xml, vmdef, driver->caps, driver->xmlopt,
|
2014-11-18 16:44:00 +00:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE);
|
2012-05-25 17:49:32 +00:00
|
|
|
if (!dev)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_AFFECT_CONFIG)
|
|
|
|
persist = true;
|
|
|
|
|
|
|
|
if (openvzUpdateDevice(vmdef, dev, persist) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2012-05-25 17:49:32 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
virDomainDeviceDefFree(dev);
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2012-05-25 17:49:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-11 09:04:57 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
openvzConnectListAllDomains(virConnectPtr conn,
|
|
|
|
virDomainPtr **domains,
|
|
|
|
unsigned int flags)
|
2012-06-11 09:04:57 +00:00
|
|
|
{
|
|
|
|
struct openvz_driver *driver = conn->privateData;
|
|
|
|
int ret = -1;
|
|
|
|
|
2012-08-03 15:48:05 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
|
2012-06-11 09:04:57 +00:00
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
2013-06-24 16:49:47 +00:00
|
|
|
ret = virDomainObjListExport(driver->domains, conn, domains,
|
|
|
|
NULL, flags);
|
2012-06-11 09:04:57 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-05-25 17:49:32 +00:00
|
|
|
|
2013-04-26 17:21:58 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
openvzNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virNodeInfoPtr nodeinfo)
|
|
|
|
{
|
|
|
|
return nodeGetInfo(nodeinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzNodeGetCPUStats(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
int cpuNum,
|
|
|
|
virNodeCPUStatsPtr params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
return nodeGetCPUStats(cpuNum, params, nparams, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzNodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
int cellNum,
|
|
|
|
virNodeMemoryStatsPtr params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
return nodeGetMemoryStats(cellNum, params, nparams, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzNodeGetCellsFreeMemory(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
unsigned long long *freeMems,
|
|
|
|
int startCell,
|
|
|
|
int maxCells)
|
|
|
|
{
|
|
|
|
return nodeGetCellsFreeMemory(freeMems, startCell, maxCells);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned long long
|
|
|
|
openvzNodeGetFreeMemory(virConnectPtr conn ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2014-06-16 12:02:34 +00:00
|
|
|
unsigned long long freeMem;
|
|
|
|
if (nodeGetMemory(NULL, &freeMem) < 0)
|
|
|
|
return 0;
|
|
|
|
return freeMem;
|
2013-04-26 17:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzNodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
unsigned char **cpumap,
|
|
|
|
unsigned int *online,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
return nodeGetCPUMap(cpumap, online, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-05 02:25:06 +00:00
|
|
|
static int
|
|
|
|
openvzConnectSupportsFeature(virConnectPtr conn ATTRIBUTE_UNUSED, int feature)
|
|
|
|
{
|
|
|
|
switch (feature) {
|
|
|
|
case VIR_DRV_FEATURE_MIGRATION_PARAMS:
|
|
|
|
case VIR_DRV_FEATURE_MIGRATION_V3:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
openvzDomainMigrateBegin3Params(virDomainPtr domain,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
|
|
|
char **cookieout ATTRIBUTE_UNUSED,
|
|
|
|
int *cookieoutlen ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
struct openvz_driver *driver = domain->conn->privateData;
|
|
|
|
char *xml = NULL;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
virCheckFlags(OPENVZ_MIGRATION_FLAGS, NULL);
|
|
|
|
if (virTypedParamsValidate(params, nparams, OPENVZ_MIGRATION_PARAMETERS) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, domain->uuid);
|
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virDomainObjIsActive(vm)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
"%s", _("domain is not running"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (openvzGetVEStatus(vm, &status, NULL) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (status != VIR_DOMAIN_RUNNING) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("domain is not in running state"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-11-18 16:44:00 +00:00
|
|
|
xml = virDomainDefFormat(vm->def, VIR_DOMAIN_DEF_FORMAT_SECURE);
|
2014-09-05 02:25:06 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainMigratePrepare3Params(virConnectPtr dconn,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
|
|
|
const char *cookiein ATTRIBUTE_UNUSED,
|
|
|
|
int cookieinlen ATTRIBUTE_UNUSED,
|
|
|
|
char **cookieout ATTRIBUTE_UNUSED,
|
|
|
|
int *cookieoutlen ATTRIBUTE_UNUSED,
|
|
|
|
char **uri_out,
|
|
|
|
unsigned int fflags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dconn->privateData;
|
|
|
|
const char *dom_xml = NULL;
|
|
|
|
const char *uri_in = NULL;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
2014-09-16 02:22:48 +00:00
|
|
|
char *my_hostname = NULL;
|
|
|
|
const char *hostname = NULL;
|
2014-09-05 02:25:06 +00:00
|
|
|
virURIPtr uri = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (virTypedParamsValidate(params, nparams, OPENVZ_MIGRATION_PARAMETERS) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virTypedParamsGetString(params, nparams,
|
|
|
|
VIR_MIGRATE_PARAM_DEST_XML,
|
|
|
|
&dom_xml) < 0 ||
|
|
|
|
virTypedParamsGetString(params, nparams,
|
|
|
|
VIR_MIGRATE_PARAM_URI,
|
|
|
|
&uri_in) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!dom_xml) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("no domain XML passed"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(def = virDomainDefParseString(dom_xml, driver->caps, driver->xmlopt,
|
|
|
|
1 << VIR_DOMAIN_VIRT_OPENVZ,
|
2014-11-18 16:44:00 +00:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
|
2014-09-05 02:25:06 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(vm = virDomainObjListAdd(driver->domains, def,
|
|
|
|
driver->xmlopt,
|
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
|
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
|
|
|
|
NULL)))
|
|
|
|
goto error;
|
|
|
|
def = NULL;
|
|
|
|
|
|
|
|
if (!uri_in) {
|
2014-09-16 02:22:48 +00:00
|
|
|
if ((my_hostname = virGetHostname()) == NULL)
|
2014-09-05 02:25:06 +00:00
|
|
|
goto error;
|
|
|
|
|
2014-09-16 02:22:48 +00:00
|
|
|
if (STRPREFIX(my_hostname, "localhost")) {
|
2014-09-05 02:25:06 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("hostname on destination resolved to localhost,"
|
|
|
|
" but migration requires an FQDN"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
uri = virURIParse(uri_in);
|
|
|
|
|
|
|
|
if (uri == NULL) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("unable to parse URI: %s"),
|
|
|
|
uri_in);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uri->server == NULL) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("missing host in migration URI: %s"),
|
|
|
|
uri_in);
|
|
|
|
goto error;
|
|
|
|
} else {
|
|
|
|
hostname = uri->server;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virAsprintf(uri_out, "ssh://%s", hostname) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virDomainDefFree(def);
|
|
|
|
if (vm) {
|
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
|
|
|
vm = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2014-09-16 02:22:48 +00:00
|
|
|
VIR_FREE(my_hostname);
|
2014-09-05 02:25:06 +00:00
|
|
|
virURIFree(uri);
|
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainMigratePerform3Params(virDomainPtr domain,
|
|
|
|
const char *dconnuri ATTRIBUTE_UNUSED,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
|
|
|
const char *cookiein ATTRIBUTE_UNUSED,
|
|
|
|
int cookieinlen ATTRIBUTE_UNUSED,
|
|
|
|
char **cookieout ATTRIBUTE_UNUSED,
|
|
|
|
int *cookieoutlen ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = domain->conn->privateData;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
const char *uri_str = NULL;
|
|
|
|
virURIPtr uri = NULL;
|
2014-09-16 02:22:48 +00:00
|
|
|
virCommandPtr cmd = NULL;
|
2014-09-05 02:25:06 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(OPENVZ_MIGRATION_FLAGS, -1);
|
|
|
|
if (virTypedParamsValidate(params, nparams, OPENVZ_MIGRATION_PARAMETERS) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTypedParamsGetString(params, nparams,
|
|
|
|
VIR_MIGRATE_PARAM_URI,
|
|
|
|
&uri_str) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, domain->uuid);
|
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse dst host:port from uri */
|
|
|
|
uri = virURIParse(uri_str);
|
|
|
|
if (uri == NULL || uri->server == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-09-16 02:22:48 +00:00
|
|
|
cmd = virCommandNew(VZMIGRATE);
|
2014-09-05 02:25:06 +00:00
|
|
|
if (flags & VIR_MIGRATE_LIVE)
|
|
|
|
virCommandAddArg(cmd, "--live");
|
|
|
|
virCommandAddArg(cmd, uri->server);
|
|
|
|
virCommandAddArg(cmd, vm->def->name);
|
|
|
|
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virCommandFree(cmd);
|
|
|
|
virURIFree(uri);
|
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr
|
|
|
|
openvzDomainMigrateFinish3Params(virConnectPtr dconn,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
|
|
|
const char *cookiein ATTRIBUTE_UNUSED,
|
|
|
|
int cookieinlen ATTRIBUTE_UNUSED,
|
|
|
|
char **cookieout ATTRIBUTE_UNUSED,
|
|
|
|
int *cookieoutlen ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags,
|
|
|
|
int cancelled)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dconn->privateData;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
const char *dname = NULL;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (cancelled)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
virCheckFlags(OPENVZ_MIGRATION_FLAGS, NULL);
|
|
|
|
if (virTypedParamsValidate(params, nparams, OPENVZ_MIGRATION_PARAMETERS) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTypedParamsGetString(params, nparams,
|
|
|
|
VIR_MIGRATE_PARAM_DEST_NAME,
|
|
|
|
&dname) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!dname ||
|
|
|
|
!(vm = virDomainObjListFindByName(driver->domains, dname))) {
|
|
|
|
/* Migration obviously failed if the domain doesn't exist */
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Migration failed. No domain on destination host "
|
|
|
|
"with matching name '%s'"),
|
|
|
|
NULLSTR(dname));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (openvzGetVEStatus(vm, &status, NULL) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (status != VIR_DOMAIN_RUNNING) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("domain is not running on destination host"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vm->def->id = strtoI(vm->def->name);
|
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_MIGRATED);
|
|
|
|
|
|
|
|
dom = virGetDomain(dconn, vm->def->name, vm->def->uuid);
|
|
|
|
if (dom)
|
|
|
|
dom->id = vm->def->id;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainMigrateConfirm3Params(virDomainPtr domain,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
|
|
|
const char *cookiein ATTRIBUTE_UNUSED,
|
|
|
|
int cookieinlen ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags,
|
|
|
|
int cancelled)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = domain->conn->privateData;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
int status;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(OPENVZ_MIGRATION_FLAGS, -1);
|
|
|
|
if (virTypedParamsValidate(params, nparams, OPENVZ_MIGRATION_PARAMETERS) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, domain->uuid);
|
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cancelled) {
|
|
|
|
if (openvzGetVEStatus(vm, &status, NULL) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (status == VIR_DOMAIN_RUNNING) {
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
VIR_DEBUG("Domain '%s' does not recover after failed migration",
|
|
|
|
vm->def->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vm->def->id = -1;
|
|
|
|
|
|
|
|
VIR_DEBUG("Domain '%s' successfully migrated", vm->def->name);
|
|
|
|
|
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
|
|
|
vm = NULL;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
|
|
|
virObjectUnlock(vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-16 09:25:59 +00:00
|
|
|
static virHypervisorDriver openvzDriver = {
|
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_OPENVZ,
|
|
|
|
.name = "OPENVZ",
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectOpen = openvzConnectOpen, /* 0.3.1 */
|
|
|
|
.connectClose = openvzConnectClose, /* 0.3.1 */
|
|
|
|
.connectGetType = openvzConnectGetType, /* 0.3.1 */
|
|
|
|
.connectGetVersion = openvzConnectGetVersion, /* 0.5.0 */
|
2013-04-26 16:39:11 +00:00
|
|
|
.connectGetHostname = openvzConnectGetHostname, /* 0.9.12 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectGetMaxVcpus = openvzConnectGetMaxVcpus, /* 0.4.6 */
|
2013-04-26 17:21:58 +00:00
|
|
|
.nodeGetInfo = openvzNodeGetInfo, /* 0.3.2 */
|
|
|
|
.nodeGetCPUStats = openvzNodeGetCPUStats, /* 0.9.12 */
|
|
|
|
.nodeGetMemoryStats = openvzNodeGetMemoryStats, /* 0.9.12 */
|
|
|
|
.nodeGetCellsFreeMemory = openvzNodeGetCellsFreeMemory, /* 0.9.12 */
|
|
|
|
.nodeGetFreeMemory = openvzNodeGetFreeMemory, /* 0.9.12 */
|
|
|
|
.nodeGetCPUMap = openvzNodeGetCPUMap, /* 1.0.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectGetCapabilities = openvzConnectGetCapabilities, /* 0.4.6 */
|
|
|
|
.connectListDomains = openvzConnectListDomains, /* 0.3.1 */
|
|
|
|
.connectNumOfDomains = openvzConnectNumOfDomains, /* 0.3.1 */
|
|
|
|
.connectListAllDomains = openvzConnectListAllDomains, /* 0.9.13 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainCreateXML = openvzDomainCreateXML, /* 0.3.3 */
|
|
|
|
.domainLookupByID = openvzDomainLookupByID, /* 0.3.1 */
|
|
|
|
.domainLookupByUUID = openvzDomainLookupByUUID, /* 0.3.1 */
|
|
|
|
.domainLookupByName = openvzDomainLookupByName, /* 0.3.1 */
|
|
|
|
.domainSuspend = openvzDomainSuspend, /* 0.8.3 */
|
|
|
|
.domainResume = openvzDomainResume, /* 0.8.3 */
|
|
|
|
.domainShutdown = openvzDomainShutdown, /* 0.3.1 */
|
2011-10-05 17:31:55 +00:00
|
|
|
.domainShutdownFlags = openvzDomainShutdownFlags, /* 0.9.10 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainReboot = openvzDomainReboot, /* 0.3.1 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.domainDestroy = openvzDomainDestroy, /* 0.3.1 */
|
|
|
|
.domainDestroyFlags = openvzDomainDestroyFlags, /* 0.9.4 */
|
|
|
|
.domainGetOSType = openvzDomainGetOSType, /* 0.3.1 */
|
2012-04-25 19:18:16 +00:00
|
|
|
.domainGetMemoryParameters = openvzDomainGetMemoryParameters, /* 0.9.12 */
|
|
|
|
.domainSetMemoryParameters = openvzDomainSetMemoryParameters, /* 0.9.12 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainGetInfo = openvzDomainGetInfo, /* 0.3.1 */
|
|
|
|
.domainGetState = openvzDomainGetState, /* 0.9.2 */
|
|
|
|
.domainSetVcpus = openvzDomainSetVcpus, /* 0.4.6 */
|
|
|
|
.domainSetVcpusFlags = openvzDomainSetVcpusFlags, /* 0.8.5 */
|
|
|
|
.domainGetVcpusFlags = openvzDomainGetVcpusFlags, /* 0.8.5 */
|
|
|
|
.domainGetMaxVcpus = openvzDomainGetMaxVcpus, /* 0.4.6 */
|
|
|
|
.domainGetXMLDesc = openvzDomainGetXMLDesc, /* 0.4.6 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectListDefinedDomains = openvzConnectListDefinedDomains, /* 0.3.1 */
|
|
|
|
.connectNumOfDefinedDomains = openvzConnectNumOfDefinedDomains, /* 0.3.1 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainCreate = openvzDomainCreate, /* 0.3.1 */
|
|
|
|
.domainCreateWithFlags = openvzDomainCreateWithFlags, /* 0.8.2 */
|
|
|
|
.domainDefineXML = openvzDomainDefineXML, /* 0.3.3 */
|
2014-11-18 14:19:38 +00:00
|
|
|
.domainDefineXMLFlags = openvzDomainDefineXMLFlags, /* 1.2.12 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainUndefine = openvzDomainUndefine, /* 0.3.3 */
|
2011-07-20 03:08:21 +00:00
|
|
|
.domainUndefineFlags = openvzDomainUndefineFlags, /* 0.9.4 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainGetAutostart = openvzDomainGetAutostart, /* 0.4.6 */
|
|
|
|
.domainSetAutostart = openvzDomainSetAutostart, /* 0.4.6 */
|
2012-04-19 21:51:31 +00:00
|
|
|
.domainInterfaceStats = openvzDomainInterfaceStats, /* 0.9.12 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectIsEncrypted = openvzConnectIsEncrypted, /* 0.7.3 */
|
|
|
|
.connectIsSecure = openvzConnectIsSecure, /* 0.7.3 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainIsActive = openvzDomainIsActive, /* 0.7.3 */
|
|
|
|
.domainIsPersistent = openvzDomainIsPersistent, /* 0.7.3 */
|
|
|
|
.domainIsUpdated = openvzDomainIsUpdated, /* 0.8.6 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectIsAlive = openvzConnectIsAlive, /* 0.9.8 */
|
2012-05-25 17:49:32 +00:00
|
|
|
.domainUpdateDeviceFlags = openvzDomainUpdateDeviceFlags, /* 0.9.13 */
|
2012-08-01 17:00:35 +00:00
|
|
|
.domainGetHostname = openvzDomainGetHostname, /* 0.10.0 */
|
2014-09-05 02:25:06 +00:00
|
|
|
.connectSupportsFeature = openvzConnectSupportsFeature, /* 1.2.8 */
|
|
|
|
.domainMigrateBegin3Params = openvzDomainMigrateBegin3Params, /* 1.2.8 */
|
|
|
|
.domainMigratePrepare3Params = openvzDomainMigratePrepare3Params, /* 1.2.8 */
|
|
|
|
.domainMigratePerform3Params = openvzDomainMigratePerform3Params, /* 1.2.8 */
|
|
|
|
.domainMigrateFinish3Params = openvzDomainMigrateFinish3Params, /* 1.2.8 */
|
|
|
|
.domainMigrateConfirm3Params = openvzDomainMigrateConfirm3Params, /* 1.2.8 */
|
2007-07-17 13:27:26 +00:00
|
|
|
};
|
|
|
|
|
2014-03-18 08:16:47 +00:00
|
|
|
int openvzRegister(void)
|
|
|
|
{
|
2014-10-16 09:25:59 +00:00
|
|
|
if (virRegisterHypervisorDriver(&openvzDriver) < 0)
|
2014-03-14 10:26:40 +00:00
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|