2007-07-17 13:27:26 +00:00
|
|
|
/*
|
|
|
|
* openvz_driver.c: core driver methods for managing OpenVZ VEs
|
|
|
|
*
|
2016-06-07 11:39:34 -04:00
|
|
|
* Copyright (C) 2010-2016 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 16:30:55 -06:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 18:06:23 +08:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2007-07-17 13:27:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2022-03-03 13:16:35 +01:00
|
|
|
#include <poll.h>
|
2007-07-17 13:27:26 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <pwd.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 23:00:28 +02: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"
|
2016-04-13 18:53:02 +01:00
|
|
|
#include "virhostcpu.h"
|
2016-04-13 18:53:02 +01:00
|
|
|
#include "virhostmem.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2011-07-19 12:32:58 -06:00
|
|
|
#include "virfile.h"
|
2012-04-25 21:18:16 +02: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 19:48:55 +01:00
|
|
|
#include "viruri.h"
|
2016-11-18 23:51:15 +01:00
|
|
|
#include "virnetdevtap.h"
|
2013-04-03 12:36:23 +02:00
|
|
|
#include "virstring.h"
|
2020-02-16 22:59:28 +01:00
|
|
|
#include "virutil.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");
|
|
|
|
|
2012-04-25 21:18:16 +02: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 13:50:18 +01:00
|
|
|
static int openvzConnectGetMaxVcpus(virConnectPtr conn, const char *type);
|
2008-08-20 13:44:03 +00:00
|
|
|
static int openvzDomainGetMaxVcpus(virDomainPtr dom);
|
2021-03-11 08:16:13 +01:00
|
|
|
static int openvzDomainSetVcpusInternal(virDomainObj *vm,
|
2016-06-29 14:55:24 +02:00
|
|
|
unsigned int nvcpus,
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainXMLOption *xmlopt);
|
|
|
|
static int openvzDomainSetMemoryInternal(virDomainObj *vm,
|
2012-03-02 13:27:39 -07:00
|
|
|
unsigned long long memory);
|
2021-03-11 08:16:13 +01:00
|
|
|
static int openvzGetVEStatus(virDomainObj *vm, int *status, int *reason);
|
2008-07-21 08:08:25 +00:00
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
struct openvz_driver ovz_driver;
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
static virDomainObj *
|
2018-03-09 11:48:02 -05:00
|
|
|
openvzDomObjFromDomainLocked(struct openvz_driver *driver,
|
|
|
|
const unsigned char *uuid)
|
|
|
|
{
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
2018-03-09 11:48:02 -05:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
2018-03-09 10:47:46 -05:00
|
|
|
if (!(vm = virDomainObjListFindByUUID(driver->domains, uuid))) {
|
2018-03-09 11:48:02 -05:00
|
|
|
virUUIDFormat(uuid, uuidstr);
|
|
|
|
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("no domain with matching uuid '%s'"), uuidstr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
static virDomainObj *
|
2018-03-09 11:48:02 -05:00
|
|
|
openvzDomObjFromDomain(struct openvz_driver *driver,
|
|
|
|
const unsigned char *uuid)
|
|
|
|
{
|
2022-02-11 13:54:11 +01:00
|
|
|
VIR_LOCK_GUARD lock = virLockGuardLock(&driver->lock);
|
2018-03-09 11:48:02 -05:00
|
|
|
|
2022-02-11 13:54:11 +01:00
|
|
|
return openvzDomObjFromDomainLocked(driver, uuid);
|
2018-03-09 11:48:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-16 14:45:55 +00:00
|
|
|
/* generate arguments to create OpenVZ container
|
|
|
|
return -1 - error
|
|
|
|
0 - OK
|
2012-05-05 08:47:05 +02:00
|
|
|
Caller has to free the cmd
|
2008-07-16 14:45:55 +00:00
|
|
|
*/
|
2021-03-11 08:16:13 +01:00
|
|
|
static virCommand *
|
|
|
|
openvzDomainDefineCmd(virDomainDef *vmdef)
|
2008-07-16 14:45:55 +00:00
|
|
|
{
|
2021-12-10 17:11:07 +01:00
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZCTL,
|
|
|
|
"--quiet",
|
|
|
|
"create",
|
|
|
|
NULL);
|
2008-07-16 14:45:55 +00:00
|
|
|
|
2009-09-22 12:19:09 +02:00
|
|
|
if (vmdef == NULL) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Container is not defined"));
|
2012-05-05 08:47:05 +02:00
|
|
|
return NULL;
|
2008-07-16 14:45:55 +00:00
|
|
|
}
|
2010-11-28 22:52:44 +01:00
|
|
|
|
2012-05-05 08:47:05 +02: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 12:19:09 +02:00
|
|
|
vmdef->fss[0]->type == VIR_DOMAIN_FS_TYPE_TEMPLATE) {
|
2012-05-05 08:47:05 +02:00
|
|
|
virCommandAddArgList(cmd, "--ostemplate", vmdef->fss[0]->src, NULL);
|
2008-07-16 14:45:55 +00:00
|
|
|
}
|
2009-09-22 12:19:09 +02:00
|
|
|
|
2021-12-10 17:11:07 +01:00
|
|
|
return g_steal_pointer(&cmd);
|
2008-07-16 14:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
static int openvzSetInitialConfig(virDomainDef *vmdef)
|
2009-03-24 10:59:13 +00:00
|
|
|
{
|
|
|
|
int vpsid;
|
|
|
|
|
|
|
|
if (vmdef->nfss > 1) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("only one filesystem supported"));
|
2021-12-13 19:00:53 +01:00
|
|
|
return -1;
|
2009-03-24 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("filesystem is not of type 'template' or 'mount'"));
|
2021-12-13 19:00:53 +01:00
|
|
|
return -1;
|
2009-03-24 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (vmdef->nfss == 1 &&
|
|
|
|
vmdef->fss[0]->type == VIR_DOMAIN_FS_TYPE_MOUNT)
|
|
|
|
{
|
|
|
|
|
2010-08-31 16:43:18 -06:00
|
|
|
if (virStrToLong_i(vmdef->name, NULL, 10, &vpsid) < 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not convert domain name to VEID"));
|
2021-12-13 19:00:53 +01:00
|
|
|
return -1;
|
2009-03-24 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (openvzCopyDefaultConfig(vpsid) < 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not copy default config"));
|
2021-12-13 19:00:53 +01:00
|
|
|
return -1;
|
2009-03-24 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 16:52:38 +03:00
|
|
|
if (openvzWriteVPSConfigParam(vpsid, "VE_PRIVATE", vmdef->fss[0]->src->path) < 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set the source dir for the filesystem"));
|
2021-12-13 19:00:53 +01:00
|
|
|
return -1;
|
2009-03-24 10:59:13 +00:00
|
|
|
}
|
2012-05-05 08:47:05 +02:00
|
|
|
} else {
|
2021-12-13 19:00:53 +01:00
|
|
|
g_autoptr(virCommand) cmd = openvzDomainDefineCmd(vmdef);
|
2012-05-05 08:47:05 +02:00
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2021-12-13 19:00:53 +01:00
|
|
|
return -1;
|
2009-03-24 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2021-12-13 19:00:53 +01:00
|
|
|
return 0;
|
2009-03-24 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-05 08:52:23 +02:00
|
|
|
static int
|
2021-03-11 08:16:13 +01:00
|
|
|
openvzSetDiskQuota(virDomainDef *vmdef,
|
|
|
|
virDomainFSDef *fss,
|
2012-05-25 19:48:33 +02:00
|
|
|
bool persist)
|
2012-05-05 08:52:23 +02:00
|
|
|
{
|
|
|
|
unsigned long long sl, hl;
|
2021-12-13 19:06:11 +01:00
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZCTL,
|
|
|
|
"--quiet",
|
|
|
|
"set",
|
|
|
|
vmdef->name,
|
|
|
|
NULL);
|
2012-05-25 19:48:33 +02:00
|
|
|
if (persist)
|
|
|
|
virCommandAddArg(cmd, "--save");
|
2012-05-05 08:52:23 +02: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 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Can't set soft limit without hard limit"));
|
2021-12-13 19:06:11 +01:00
|
|
|
return -1;
|
2012-05-05 08:52:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2021-12-13 19:06:11 +01:00
|
|
|
return -1;
|
2012-05-05 08:52:23 +02:00
|
|
|
}
|
|
|
|
|
2021-12-13 19:06:11 +01:00
|
|
|
return 0;
|
2012-05-05 08:52:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-10 13:58:44 +02:00
|
|
|
static char *
|
|
|
|
openvzDomainGetHostname(virDomainPtr dom, unsigned int flags)
|
|
|
|
{
|
|
|
|
char *hostname = NULL;
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
2012-07-10 13:58:44 +02:00
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return NULL;
|
2012-07-10 13:58:44 +02:00
|
|
|
|
|
|
|
hostname = openvzVEGetStringParam(dom, "hostname");
|
|
|
|
if (hostname == NULL)
|
2018-03-30 10:04:54 -04:00
|
|
|
goto cleanup;
|
2012-07-10 13:58:44 +02:00
|
|
|
|
|
|
|
/* vzlist prints an unset hostname as '-' */
|
|
|
|
if (STREQ(hostname, "-")) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Hostname of '%s' is unset"), vm->def->name);
|
2018-03-30 10:04:54 -04:00
|
|
|
VIR_FREE(hostname);
|
2012-07-10 13:58:44 +02:00
|
|
|
}
|
|
|
|
|
2014-03-25 07:57:22 +01:00
|
|
|
cleanup:
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2012-07-10 13:58:44 +02:00
|
|
|
return hostname;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
static virDomainPtr openvzDomainLookupByID(virConnectPtr conn,
|
2014-03-18 09:16:47 +01:00
|
|
|
int id)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2022-02-11 13:54:11 +01:00
|
|
|
virDomainObj *vm = NULL;
|
2008-12-04 21:41:51 +00:00
|
|
|
virDomainPtr dom = NULL;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2022-02-11 13:54:11 +01:00
|
|
|
VIR_WITH_MUTEX_LOCK_GUARD(&driver->lock) {
|
|
|
|
vm = virDomainObjListFindByID(driver->domains, id);
|
|
|
|
}
|
2008-12-04 21:44:55 +00:00
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2018-03-09 11:48:03 -05:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("no domain with matching id '%d'"), id);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-28 17:08:03 +02:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2014-03-25 07:57:22 +01:00
|
|
|
cleanup:
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2007-07-17 13:27:26 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
2014-03-18 09:16:47 +01:00
|
|
|
static int openvzConnectGetVersion(virConnectPtr conn, unsigned long *version)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2022-02-11 13:54:11 +01:00
|
|
|
VIR_LOCK_GUARD lock = virLockGuardLock(&driver->lock);
|
|
|
|
|
2008-10-24 11:32:48 +00:00
|
|
|
*version = driver->version;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-26 17:39:11 +01:00
|
|
|
|
2019-10-14 14:45:33 +02:00
|
|
|
static char *openvzConnectGetHostname(virConnectPtr conn G_GNUC_UNUSED)
|
2013-04-26 17:39:11 +01:00
|
|
|
{
|
|
|
|
return virGetHostname();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-23 13:50:18 +01: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;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
2008-12-04 21:41:51 +00:00
|
|
|
char *ret = NULL;
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return NULL;
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2019-10-18 13:27:03 +02:00
|
|
|
ret = g_strdup(virDomainOSTypeToString(vm->def->os.type));
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&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 09:16:47 +01:00
|
|
|
const unsigned char *uuid)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
2008-12-04 21:41:51 +00:00
|
|
|
virDomainPtr dom = NULL;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, uuid)))
|
|
|
|
return NULL;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2017-03-28 17:08:03 +02:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2007-07-17 13:27:26 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr openvzDomainLookupByName(virConnectPtr conn,
|
2014-03-18 09:16:47 +01:00
|
|
|
const char *name)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2022-02-11 13:54:11 +01:00
|
|
|
virDomainObj *vm = NULL;
|
2008-12-04 21:41:51 +00:00
|
|
|
virDomainPtr dom = NULL;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2022-02-11 13:54:11 +01:00
|
|
|
VIR_WITH_MUTEX_LOCK_GUARD(&driver->lock) {
|
|
|
|
vm = virDomainObjListFindByName(driver->domains, name);
|
|
|
|
}
|
2008-12-04 21:44:55 +00:00
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2018-03-09 11:48:03 -05:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("no domain with matching name '%s'"), name);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-28 17:08:03 +02:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2014-03-25 07:57:22 +01:00
|
|
|
cleanup:
|
2015-04-23 18:00:01 +02:00
|
|
|
virDomainObjEndAPI(&vm);
|
2007-07-17 13:27:26 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int openvzDomainGetInfo(virDomainPtr dom,
|
2014-03-18 09:16:47 +01:00
|
|
|
virDomainInfoPtr info)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
2011-07-29 10:41:32 +02:00
|
|
|
int state;
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2011-07-29 10:41:32 +02:00
|
|
|
if (openvzGetVEStatus(vm, &state, NULL) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
info->state = state;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2011-07-29 10:41:32 +02: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 14:13:44 +01: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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 15:34:04 +02:00
|
|
|
info->maxMem = virDomainDefGetMemoryTotal(vm->def);
|
2010-10-12 16:43:39 +02:00
|
|
|
info->memory = vm->def->mem.cur_balloon;
|
2015-10-22 14:59:03 +02:00
|
|
|
info->nrVirtCpu = virDomainDefGetVcpus(vm->def);
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 07:57:22 +01:00
|
|
|
cleanup:
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-02 11:35:29 +02:00
|
|
|
static int
|
|
|
|
openvzDomainGetState(virDomainPtr dom,
|
|
|
|
int *state,
|
|
|
|
int *reason,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
2011-05-02 11:35:29 +02:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
2011-05-02 11:35:29 +02:00
|
|
|
|
2011-07-29 10:41:32 +02:00
|
|
|
ret = openvzGetVEStatus(vm, state, reason);
|
2011-05-02 11:35:29 +02:00
|
|
|
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2011-05-02 11:35:29 +02: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 15:12:03 +01:00
|
|
|
static int openvzDomainIsActive(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *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 15:12:03 +01:00
|
|
|
int ret = -1;
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(obj = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
|
|
|
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 15:12:03 +01:00
|
|
|
ret = virDomainObjIsActive(obj);
|
|
|
|
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&obj);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 15:12:03 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int openvzDomainIsPersistent(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *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 15:12:03 +01:00
|
|
|
int ret = -1;
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(obj = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
|
|
|
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 15:12:03 +01:00
|
|
|
ret = obj->persistent;
|
|
|
|
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&obj);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 15:12:03 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-10-14 14:45:33 +02:00
|
|
|
static int openvzDomainIsUpdated(virDomainPtr dom G_GNUC_UNUSED)
|
2010-11-24 15:43:15 +08:00
|
|
|
{
|
|
|
|
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 15:12:03 +01:00
|
|
|
|
2011-07-06 14:40:19 -06:00
|
|
|
static char *openvzDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
2008-12-04 21:41:51 +00:00
|
|
|
char *ret = NULL;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2019-02-14 14:25:01 -06:00
|
|
|
virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL);
|
2011-07-13 16:24:38 -06:00
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return NULL;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2019-11-27 11:57:34 +00:00
|
|
|
ret = virDomainDefFormat(vm->def, driver->xmlopt,
|
2014-11-18 16:44:00 +00:00
|
|
|
virDomainDefFormatConvertXMLFlags(flags));
|
2008-12-04 21:41:51 +00:00
|
|
|
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&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
|
|
|
|
2014-03-18 09:16:47 +01:00
|
|
|
static int openvzDomainSuspend(virDomainPtr dom)
|
|
|
|
{
|
2020-04-22 16:25:19 +02:00
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZCTL, "--quiet", "chkpnt", NULL);
|
2010-08-04 14:00:07 +02:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
2010-08-04 14:00:07 +02:00
|
|
|
int ret = -1;
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
2010-08-04 14:00:07 +02:00
|
|
|
|
2018-04-17 22:13:32 +00:00
|
|
|
if (virDomainObjCheckActive(vm) < 0)
|
2010-08-04 14:00:07 +02:00
|
|
|
goto cleanup;
|
|
|
|
|
2011-05-04 11:07:01 +02:00
|
|
|
if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) {
|
2020-04-22 16:25:19 +02:00
|
|
|
virCommandAddArgList(cmd, vm->def->name, "--suspend", NULL);
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2010-08-04 14:00:07 +02:00
|
|
|
goto cleanup;
|
2011-05-04 11:07:01 +02:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER);
|
2010-08-04 14:00:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 07:57:22 +01:00
|
|
|
cleanup:
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2010-08-04 14:00:07 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-18 09:16:47 +01:00
|
|
|
static int openvzDomainResume(virDomainPtr dom)
|
|
|
|
{
|
2020-04-22 16:25:19 +02:00
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZCTL, "--quiet", "chkpnt", NULL);
|
2017-10-23 12:04:43 -04:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
2017-10-23 12:04:43 -04:00
|
|
|
int ret = -1;
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
2017-10-23 12:04:43 -04:00
|
|
|
|
2018-04-17 22:13:32 +00:00
|
|
|
if (virDomainObjCheckActive(vm) < 0)
|
2017-10-23 12:04:43 -04:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
|
2020-04-22 16:25:19 +02:00
|
|
|
virCommandAddArgList(cmd, vm->def->name, "--resume", NULL);
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2017-10-23 12:04:43 -04:00
|
|
|
goto cleanup;
|
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNPAUSED);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2010-08-04 14:00:07 +02:00
|
|
|
|
2014-03-25 07:57:22 +01:00
|
|
|
cleanup:
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2017-10-23 12:04:43 -04:00
|
|
|
return ret;
|
2010-08-04 14:00:07 +02:00
|
|
|
}
|
|
|
|
|
2011-07-21 09:49:02 +02:00
|
|
|
static int
|
|
|
|
openvzDomainShutdownFlags(virDomainPtr dom,
|
2014-03-18 09:16:47 +01:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2020-04-22 16:25:19 +02:00
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZCTL, "--quiet", "stop", NULL);
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2011-07-29 10:41:32 +02:00
|
|
|
int status;
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2011-07-21 09:49:02 +02:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2011-07-29 10:41:32 +02:00
|
|
|
if (openvzGetVEStatus(vm, &status, NULL) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (status != VIR_DOMAIN_RUNNING) {
|
2012-07-18 14:13:44 +01: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
|
|
|
|
2020-04-22 16:25:19 +02:00
|
|
|
virCommandAddArg(cmd, vm->def->name);
|
|
|
|
|
|
|
|
if (virCommandRun(cmd, 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 11:07:01 +02:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
|
2010-07-30 19:50:12 +02: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 07:57:22 +01:00
|
|
|
cleanup:
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2011-07-21 09:49:02 +02:00
|
|
|
static int
|
|
|
|
openvzDomainShutdown(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
return openvzDomainShutdownFlags(dom, 0);
|
|
|
|
}
|
|
|
|
|
2013-04-23 13:50:18 +01: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 16:34:58 -06:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2020-04-22 16:25:19 +02:00
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZCTL, "--quiet", "restart", NULL);
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2011-07-29 10:41:32 +02:00
|
|
|
int status;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2011-07-06 16:34:58 -06:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2011-07-29 10:41:32 +02:00
|
|
|
if (openvzGetVEStatus(vm, &status, NULL) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (status != VIR_DOMAIN_RUNNING) {
|
2012-07-18 14:13:44 +01: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
|
|
|
|
2020-04-22 16:25:19 +02:00
|
|
|
virCommandAddArg(cmd, vm->def->name);
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2020-04-22 16:25:19 +02:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2011-05-04 11:07:01 +02:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
|
|
|
|
|
2014-03-25 07:57:22 +01:00
|
|
|
cleanup:
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&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 14:45:31 +02:00
|
|
|
char *ret;
|
2008-11-12 16:35:47 +00:00
|
|
|
|
|
|
|
if (sscanf(dev_name_ve, "%*[^0-9]%d", &ifNo) != 1)
|
|
|
|
return NULL;
|
2019-10-22 15:26:14 +02:00
|
|
|
ret = g_strdup_printf("veth%d.%d.", veid, ifNo);
|
2013-05-03 14:45:31 +02:00
|
|
|
return ret;
|
2008-11-12 16:35:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
openvzGenerateContainerVethName(int veid)
|
|
|
|
{
|
2011-04-03 11:21:26 +02: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 11:21:26 +02:00
|
|
|
if (openvzReadVPSConfigParam(veid, "NETIF", &temp) <= 0) {
|
2019-10-18 13:27:03 +02:00
|
|
|
name = g_strdup("eth0");
|
2008-11-12 16:35:47 +00:00
|
|
|
} else {
|
2011-04-05 10:54:59 +01:00
|
|
|
char *saveptr = NULL;
|
2011-04-03 11:21:26 +02: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 12:27:29 +01: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 */
|
2019-10-22 15:26:14 +02:00
|
|
|
name = g_strdup_printf("eth%d", max + 1);
|
2008-11-12 16:35:47 +00:00
|
|
|
}
|
2011-04-03 11:21:26 +02: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,
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainNetDef *net,
|
|
|
|
virBuffer *configBuf)
|
2008-07-28 14:06:54 +00:00
|
|
|
{
|
2008-11-12 16:35:47 +00:00
|
|
|
char macaddr[VIR_MAC_STRING_BUFLEN];
|
2012-07-17 08:07:59 -04: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;
|
2021-12-13 19:08:49 +01:00
|
|
|
g_autoptr(virCommand) cmd = NULL;
|
|
|
|
g_autofree char *guest_ifname = NULL;
|
2008-07-28 14:06:54 +00:00
|
|
|
|
|
|
|
if (net == NULL)
|
2017-10-23 12:04:43 -04:00
|
|
|
return 0;
|
|
|
|
|
2008-07-28 14:06:54 +00:00
|
|
|
if (vpsid == NULL) {
|
2012-07-18 14:13:44 +01: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 11:17:19 +02: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 11:17:19 +02:00
|
|
|
cmd = virCommandNewArgList(VZCTL, "--quiet", "set", vpsid, NULL);
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2012-07-17 08:07:59 -04:00
|
|
|
virMacAddrFormat(&net->mac, macaddr);
|
2013-03-15 15:44:12 +01:00
|
|
|
virDomainNetGenerateMAC(driver->xmlopt, &host_mac);
|
2012-07-17 08:07:59 -04:00
|
|
|
virMacAddrFormat(&host_mac, host_macaddr);
|
2008-11-12 16:35:47 +00:00
|
|
|
|
2010-08-18 17:05:02 +02:00
|
|
|
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
|
|
|
(net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
|
2016-06-07 11:39:34 -04:00
|
|
|
net->guestIP.nips == 0)) {
|
2020-07-02 22:42:16 -04:00
|
|
|
g_auto(virBuffer)buf = VIR_BUFFER_INITIALIZER;
|
2010-02-19 16:49:56 +01:00
|
|
|
int veid = openvzGetVEID(vpsid);
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2013-06-04 09:44:32 +02:00
|
|
|
/* if net is ethernet and the user has specified guest interface name,
|
|
|
|
* let's use it; otherwise generate a new one */
|
conf/openvz: eliminate incorrect/undocumented use of <source dev='blah'/>
When support for <interface type='ethernet'> was added in commit
9a4b705f back in 2010, it erroneously looked at <source dev='blah'/>
for a user-specified guest-side interface name. This was never
documented though. (that attribute already existed at the time in the
data.ethernet union member of virDomainNetDef, but apparently had no
practical use - it was only used as a storage place for a NetDef's
bridge name during qemuDomainXMLToNative(), but even then that was
never used for anything).
When support for similar guest-side device naming was added to the lxc
driver several years later, it was put in a new subelement <guest
dev='blah'/>.
In the intervening years, since there was no validation that
ethernet.dev was NULL in the other drivers that didn't actually use
it, innocent souls who were adding other features assuming they needed
to account for non-NULL ethernet.dev when really they didn't, so
little bits of the usual pointless cargo-cult code showed up.
This patch not only switches the openvz driver to use the documented
<guest dev='blah'/> notation for naming the guest-side device (just in
case anyone is still using the openvz driver), and logs an error if
anyone tries to set <source dev='blah'/> for a type='ethernet'
interface, it also removes the cargo-cult uses of ethernet.dev and
<source dev='blah'/>, and eliminates if from the RNG and from
virDomainNetDef.
NB: I decided on this course of action after mentioning the
inconsistency here:
https://www.redhat.com/archives/libvir-list/2016-May/msg02038.html
and getting encouragement do eliminate it in a later IRC discussion
with danpb.
2016-06-21 15:20:57 -04:00
|
|
|
if (net->ifname_guest) {
|
2019-10-20 13:49:46 +02:00
|
|
|
guest_ifname = g_strdup(net->ifname_guest);
|
2013-06-04 09:44:32 +02:00
|
|
|
} else {
|
|
|
|
guest_ifname = openvzGenerateContainerVethName(veid);
|
|
|
|
if (guest_ifname == NULL) {
|
2017-10-23 12:04:43 -04:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not generate eth name for container"));
|
2021-12-13 19:08:49 +01:00
|
|
|
return -1;
|
2010-08-18 17:05:02 +02: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 09:53:54 +02:00
|
|
|
net->ifname = openvzGenerateVethName(veid, guest_ifname);
|
2008-11-12 16:35:47 +00:00
|
|
|
if (net->ifname == NULL) {
|
2017-10-23 12:04:43 -04:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not generate veth name"));
|
2021-12-13 19:08:49 +01:00
|
|
|
return -1;
|
2008-11-12 16:35:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-04 09:44:32 +02:00
|
|
|
virBufferAdd(&buf, guest_ifname, -1); /* Guest dev */
|
2011-04-30 10:34:49 -06: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 17:05:02 +02:00
|
|
|
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
|
|
|
if (driver->version >= VZCTL_BRIDGE_MIN_VERSION) {
|
2011-04-30 10:34:49 -06:00
|
|
|
virBufferAsprintf(&buf, ",%s", net->data.bridge.brname); /* Host bridge */
|
2010-08-18 17:05:02 +02:00
|
|
|
} else {
|
2013-06-04 09:44:32 +02:00
|
|
|
virBufferAsprintf(configBuf, "ifname=%s", guest_ifname);
|
2011-04-30 10:34:49 -06: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 17:05:02 +02:00
|
|
|
}
|
2008-07-28 14:06:54 +00:00
|
|
|
}
|
2008-11-12 16:35:47 +00:00
|
|
|
|
2013-05-19 11:17:19 +02: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 &&
|
2017-10-23 12:04:43 -04:00
|
|
|
net->guestIP.nips > 0) {
|
2014-11-12 09:30:09 +01:00
|
|
|
size_t i;
|
|
|
|
|
2011-01-28 22:38:06 +01:00
|
|
|
/* --ipadd ip */
|
2016-06-07 11:39:34 -04:00
|
|
|
for (i = 0; i < net->guestIP.nips; i++) {
|
2021-12-13 19:08:49 +01:00
|
|
|
g_autofree char *ipStr = virSocketAddrFormat(&net->guestIP.ips[i]->address);
|
2015-01-09 10:48:37 -05:00
|
|
|
if (!ipStr)
|
2021-12-13 19:08:49 +01:00
|
|
|
return -1;
|
2014-11-12 09:30:09 +01:00
|
|
|
virCommandAddArgList(cmd, "--ipadd", ipStr, NULL);
|
|
|
|
}
|
2008-07-28 14:06:54 +00:00
|
|
|
}
|
|
|
|
|
2011-01-28 22:38:06 +01:00
|
|
|
/* TODO: processing NAT and physical device */
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2013-05-19 11:17:19 +02:00
|
|
|
virCommandAddArg(cmd, "--save");
|
2021-12-13 19:08:49 +01:00
|
|
|
return virCommandRun(cmd, NULL);
|
2008-07-28 14:06:54 +00:00
|
|
|
}
|
|
|
|
|
2008-11-12 16:35:47 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainSetNetworkConfig(virConnectPtr conn,
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainDef *def)
|
2008-11-12 16:35:47 +00:00
|
|
|
{
|
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 15:09:33 +01:00
|
|
|
size_t i;
|
2020-07-02 22:42:16 -04:00
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
2008-11-12 16:35:47 +00:00
|
|
|
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 15:21:19 +08: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 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not configure network"));
|
2021-11-04 15:26:07 +01:00
|
|
|
return -1;
|
2008-11-12 16:35:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 14:13:44 +01: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2021-11-29 09:07:44 +01:00
|
|
|
g_autoptr(virDomainDef) vmdef = NULL;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *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;
|
2022-02-11 13:54:11 +01:00
|
|
|
VIR_LOCK_GUARD lock = virLockGuardLock(&driver->lock);
|
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)
|
2016-05-24 17:20:20 +02:00
|
|
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA;
|
2014-11-18 14:19:38 +00:00
|
|
|
|
2019-11-27 12:29:21 +00:00
|
|
|
if ((vmdef = virDomainDefParseString(xml, driver->xmlopt,
|
2016-09-22 17:14:17 +02:00
|
|
|
NULL, parse_flags)) == NULL)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2016-11-11 10:17:37 +01:00
|
|
|
if (virXMLCheckIllegalChars("name", vmdef->name, "\n") < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2021-11-02 12:19:50 +01:00
|
|
|
if (!(vm = virDomainObjListAdd(driver->domains, &vmdef,
|
2013-03-31 20:03:42 +02:00
|
|
|
driver->xmlopt,
|
2013-03-28 14:55:55 +01:00
|
|
|
0, NULL)))
|
2008-12-04 21:41:51 +00:00
|
|
|
goto 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 15:12:03 +01:00
|
|
|
vm->persistent = 1;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2010-04-03 16:23:45 +02:00
|
|
|
if (openvzSetInitialConfig(vm->def) < 0) {
|
2011-05-09 17:24:09 +08: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 08:52:23 +02:00
|
|
|
if (vm->def->nfss == 1) {
|
2012-05-25 19:48:33 +02:00
|
|
|
if (openvzSetDiskQuota(vm->def, vm->def->fss[0], true) < 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set disk quota"));
|
2012-05-05 08:52:23 +02: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 14:13:44 +01: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
|
|
|
|
2015-10-19 18:23:23 +02:00
|
|
|
if (virDomainDefHasVcpusOffline(vm->def)) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("current vcpu count must equal maximum"));
|
2010-09-29 10:20:07 -06:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2015-10-19 19:21:24 +02:00
|
|
|
if (virDomainDefGetVcpusMax(vm->def)) {
|
2016-06-29 14:55:24 +02:00
|
|
|
if (openvzDomainSetVcpusInternal(vm, virDomainDefGetVcpusMax(vm->def),
|
|
|
|
driver->xmlopt) < 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2013-01-30 09:17:34 -05:00
|
|
|
_("Could not set number of vCPUs"));
|
2017-10-23 12:04:43 -04:00
|
|
|
goto cleanup;
|
2008-08-20 13:44:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 16:43:39 +02:00
|
|
|
if (vm->def->mem.cur_balloon > 0) {
|
|
|
|
if (openvzDomainSetMemoryInternal(vm, vm->def->mem.cur_balloon) < 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set memory size"));
|
2017-10-23 12:04:43 -04:00
|
|
|
goto cleanup;
|
2009-11-02 17:39:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-28 17:08:03 +02:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, -1);
|
2008-12-04 21:41:51 +00:00
|
|
|
|
2014-03-25 07:57:22 +01:00
|
|
|
cleanup:
|
2018-04-23 10:40:48 -04:00
|
|
|
virDomainObjEndAPI(&vm);
|
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 11:13:13 -06:00
|
|
|
unsigned int flags)
|
2007-09-03 15:37:07 +00:00
|
|
|
{
|
2020-04-22 16:25:19 +02:00
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZCTL, "--quiet", "start", NULL);
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2021-11-29 09:07:44 +01:00
|
|
|
g_autoptr(virDomainDef) vmdef = NULL;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *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;
|
2022-02-11 13:54:11 +01:00
|
|
|
VIR_LOCK_GUARD lock = virLockGuardLock(&driver->lock);
|
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)
|
2016-05-24 17:20:20 +02:00
|
|
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA;
|
2010-05-25 11:13:13 -06:00
|
|
|
|
2019-11-27 12:29:21 +00:00
|
|
|
if ((vmdef = virDomainDefParseString(xml, driver->xmlopt,
|
2016-09-22 17:14:17 +02:00
|
|
|
NULL, 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
|
|
|
if (!(vm = virDomainObjListAdd(driver->domains,
|
2021-11-02 12:19:50 +01:00
|
|
|
&vmdef,
|
2013-03-28 14:55:55 +01:00
|
|
|
driver->xmlopt,
|
2015-09-22 16:57:52 +02:00
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
|
Merge virDomainObjListIsDuplicate into virDomainObjListAdd
The duplicate VM checking should be done atomically with
virDomainObjListAdd, so shoud not be a separate function.
Instead just use flags to indicate what kind of checks are
required.
This pair, used in virDomainCreateXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainRestoreFlags:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, true)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainDefineXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 0) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
0, NULL)))
goto cleanup;
2013-01-14 14:46:58 +00:00
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
|
|
|
|
NULL)))
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2021-11-02 12:19:50 +01:00
|
|
|
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 15:12:03 +01: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 16:23:45 +02:00
|
|
|
if (openvzSetInitialConfig(vm->def) < 0) {
|
2011-05-09 17:24:09 +08: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 08:52:23 +02:00
|
|
|
if (vm->def->nfss == 1) {
|
2012-05-25 19:48:33 +02:00
|
|
|
if (openvzSetDiskQuota(vm->def, vm->def->fss[0], true) < 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set disk quota"));
|
2012-05-05 08:52:23 +02:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
if (openvzSetDefinedUUID(strtoI(vm->def->name), vm->def->uuid) < 0) {
|
2012-07-18 14:13:44 +01: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
|
|
|
|
2020-04-22 16:25:19 +02:00
|
|
|
virCommandAddArg(cmd, vm->def->name);
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2020-04-22 16:25:19 +02:00
|
|
|
if (virCommandRun(cmd, 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 11:07:01 +02:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2015-10-19 19:21:24 +02:00
|
|
|
if (virDomainDefGetVcpusMax(vm->def) > 0) {
|
2016-06-29 14:55:24 +02:00
|
|
|
if (openvzDomainSetVcpusInternal(vm, virDomainDefGetVcpusMax(vm->def),
|
|
|
|
driver->xmlopt) < 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2013-01-30 09:17:34 -05: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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-28 17:08:03 +02:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
|
2008-12-04 21:41:51 +00:00
|
|
|
|
2014-03-25 07:57:22 +01:00
|
|
|
cleanup:
|
2018-04-23 10:40:48 -04:00
|
|
|
virDomainObjEndAPI(&vm);
|
2007-09-03 15:37:07 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-06-10 09:55:36 -06:00
|
|
|
openvzDomainCreateWithFlags(virDomainPtr dom, unsigned int flags)
|
2007-09-03 15:37:07 +00:00
|
|
|
{
|
2020-04-22 16:25:19 +02:00
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZCTL, "--quiet", "start", NULL);
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2022-02-11 13:54:11 +01:00
|
|
|
virDomainObj *vm = NULL;
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2011-07-29 10:41:32 +02:00
|
|
|
int status;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2010-06-10 09:55:36 -06:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2022-02-11 13:54:11 +01:00
|
|
|
VIR_WITH_MUTEX_LOCK_GUARD(&driver->lock) {
|
|
|
|
vm = virDomainObjListFindByName(driver->domains, dom->name);
|
|
|
|
}
|
2008-12-04 21:44:55 +00:00
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2018-03-09 11:48:03 -05:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("no domain with matching name '%s'"), dom->name);
|
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 10:41:32 +02:00
|
|
|
if (openvzGetVEStatus(vm, &status, NULL) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (status != VIR_DOMAIN_SHUTOFF) {
|
2012-07-18 14:13:44 +01: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
|
|
|
}
|
|
|
|
|
2020-04-22 16:25:19 +02:00
|
|
|
virCommandAddArg(cmd, vm->def->name);
|
|
|
|
|
|
|
|
if (virCommandRun(cmd, 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 10:36:06 +02:00
|
|
|
dom->id = vm->pid;
|
2011-05-04 11:07:01 +02: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 07:57:22 +01:00
|
|
|
cleanup:
|
2015-04-23 18:00:01 +02:00
|
|
|
virDomainObjEndAPI(&vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 09:55:36 -06:00
|
|
|
static int
|
|
|
|
openvzDomainCreate(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
return openvzDomainCreateWithFlags(dom, 0);
|
|
|
|
}
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
static int
|
2011-07-20 11:08:21 +08:00
|
|
|
openvzDomainUndefineFlags(virDomainPtr dom,
|
|
|
|
unsigned int flags)
|
2007-09-03 15:37:07 +00:00
|
|
|
{
|
2020-04-22 16:25:19 +02:00
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZCTL, "--quiet", "start", "destroy", NULL);
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2011-07-29 10:41:32 +02:00
|
|
|
int status;
|
2022-02-11 13:54:11 +01:00
|
|
|
VIR_LOCK_GUARD lock = virLockGuardLock(&driver->lock);
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2011-07-20 11:08:21 +08:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomainLocked(driver, dom->uuid)))
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2011-07-29 10:41:32 +02:00
|
|
|
if (openvzGetVEStatus(vm, &status, NULL) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
2020-04-22 16:25:19 +02:00
|
|
|
virCommandAddArg(cmd, vm->def->name);
|
|
|
|
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2018-04-23 10:40:48 -04:00
|
|
|
if (virDomainObjIsActive(vm))
|
2011-08-19 21:48:47 +08:00
|
|
|
vm->persistent = 0;
|
2018-04-23 10:40:48 -04:00
|
|
|
else
|
2013-01-11 16:04:47 +00:00
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
2011-08-19 21:48:47 +08:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2014-03-25 07:57:22 +01:00
|
|
|
cleanup:
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2011-07-20 11:08:21 +08: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;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
2020-04-22 16:25:19 +02:00
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZCTL, "--quiet", NULL);
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2008-07-10 07:52:14 +00:00
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
2008-07-10 07:52:14 +00:00
|
|
|
|
2020-04-22 16:25:19 +02:00
|
|
|
virCommandAddArgList(cmd, "set", vm->def->name,
|
|
|
|
"--onboot", autostart ? "yes" : "no",
|
|
|
|
"--save", NULL);
|
|
|
|
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2020-04-22 16:25:19 +02:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
2008-07-10 07:52:14 +00:00
|
|
|
|
2014-03-25 07:57:22 +01:00
|
|
|
cleanup:
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&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;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
2011-04-03 11:21:26 +02:00
|
|
|
char *value = NULL;
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2008-07-10 07:52:14 +00:00
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
2008-07-10 07:52:14 +00:00
|
|
|
|
2011-04-03 11:21:26 +02:00
|
|
|
if (openvzReadVPSConfigParam(strtoI(vm->def->name), "ONBOOT", &value) < 0) {
|
2012-07-18 14:13:44 +01: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 16:04:25 -07: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 07:57:22 +01:00
|
|
|
cleanup:
|
2011-04-03 11:21:26 +02:00
|
|
|
VIR_FREE(value);
|
|
|
|
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2008-07-10 07:52:14 +00:00
|
|
|
}
|
|
|
|
|
2019-10-14 14:45:33 +02:00
|
|
|
static int openvzConnectGetMaxVcpus(virConnectPtr conn G_GNUC_UNUSED,
|
2013-04-23 13:50:18 +01:00
|
|
|
const char *type)
|
2009-08-17 14:24:27 +02:00
|
|
|
{
|
|
|
|
if (type == NULL || STRCASEEQ(type, "openvz"))
|
|
|
|
return 1028; /* OpenVZ has no limitation */
|
2008-08-20 13:44:03 +00:00
|
|
|
|
2012-07-18 14:13:44 +01: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 16:37:53 -06:00
|
|
|
static int
|
2019-10-14 14:45:33 +02:00
|
|
|
openvzDomainGetVcpusFlags(virDomainPtr dom G_GNUC_UNUSED,
|
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 16:37:53 -06:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2011-06-08 14:33:33 +08:00
|
|
|
if (flags != (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_VCPU_MAXIMUM)) {
|
2012-07-18 14:13:44 +01: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 16:37:53 -06:00
|
|
|
return -1;
|
|
|
|
}
|
2008-08-20 13:44:03 +00:00
|
|
|
|
2013-04-23 13:50:18 +01: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 16:37:53 -06:00
|
|
|
static int openvzDomainGetMaxVcpus(virDomainPtr dom)
|
|
|
|
{
|
2011-06-08 14:33:33 +08: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 16:37:53 -06:00
|
|
|
VIR_DOMAIN_VCPU_MAXIMUM));
|
|
|
|
}
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
static int openvzDomainSetVcpusInternal(virDomainObj *vm,
|
2016-06-29 14:55:24 +02:00
|
|
|
unsigned int nvcpus,
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainXMLOption *xmlopt)
|
2008-12-17 21:13:19 +00:00
|
|
|
{
|
2020-04-22 16:25:19 +02:00
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZCTL, "--quiet", NULL);
|
2008-12-17 21:13:19 +00:00
|
|
|
char str_vcpus[32];
|
2008-11-24 19:34:21 +00:00
|
|
|
unsigned int pcpus;
|
2017-03-11 16:14:17 +01:00
|
|
|
pcpus = virHostCPUGetCount();
|
2008-12-17 21:13:19 +00:00
|
|
|
if (pcpus > 0 && pcpus < nvcpus)
|
|
|
|
nvcpus = pcpus;
|
|
|
|
|
2019-11-13 14:53:42 +01:00
|
|
|
g_snprintf(str_vcpus, sizeof(str_vcpus), "%d", nvcpus);
|
2008-12-17 21:13:19 +00:00
|
|
|
|
2020-04-22 16:25:19 +02:00
|
|
|
virCommandAddArgList(cmd, "set", vm->def->name,
|
|
|
|
"--cpus", str_vcpus, "--save", NULL);
|
|
|
|
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2008-12-17 21:13:19 +00:00
|
|
|
return -1;
|
|
|
|
|
2016-06-29 14:55:24 +02:00
|
|
|
if (virDomainDefSetVcpusMax(vm->def, nvcpus, xmlopt) < 0)
|
2015-10-16 16:10:27 +02:00
|
|
|
return -1;
|
|
|
|
|
2015-10-22 10:52:05 +02:00
|
|
|
if (virDomainDefSetVcpus(vm->def, nvcpus) < 0)
|
|
|
|
return -1;
|
|
|
|
|
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 16:37:53 -06:00
|
|
|
static int openvzDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|
|
|
unsigned int flags)
|
2008-12-17 21:13:19 +00:00
|
|
|
{
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj * vm;
|
2008-12-17 21:13:19 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
int ret = -1;
|
2008-08-20 13:44:03 +00:00
|
|
|
|
2011-06-08 14:33:33 +08:00
|
|
|
if (flags != VIR_DOMAIN_AFFECT_LIVE) {
|
2012-07-18 14:13:44 +01: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 16:37:53 -06:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
2008-08-20 13:44:03 +00:00
|
|
|
|
2020-09-22 22:27:55 +02:00
|
|
|
if (nvcpus == 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2013-01-30 09:17:34 -05:00
|
|
|
_("Number of vCPUs should be >= 1"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-06-29 14:55:24 +02:00
|
|
|
if (openvzDomainSetVcpusInternal(vm, nvcpus, driver->xmlopt) < 0) {
|
2013-01-30 09:17:34 -05:00
|
|
|
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 07:57:22 +01:00
|
|
|
cleanup:
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&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 16:37:53 -06:00
|
|
|
static int
|
|
|
|
openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
|
|
|
|
{
|
2011-06-08 14:33:33 +08: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 16:37:53 -06:00
|
|
|
}
|
|
|
|
|
2018-03-27 17:24:44 +01:00
|
|
|
|
|
|
|
static int
|
|
|
|
openvzConnectURIProbe(char **uri)
|
|
|
|
{
|
|
|
|
if (!virFileExists("/proc/vz"))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (access("/proc/vz", W_OK) < 0)
|
|
|
|
return 0;
|
|
|
|
|
2019-10-20 12:41:35 +02:00
|
|
|
*uri = g_strdup("openvz:///system");
|
|
|
|
return 1;
|
2018-03-27 17:24:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-23 13:50:18 +01:00
|
|
|
static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn,
|
2019-10-14 14:45:33 +02:00
|
|
|
virConnectAuthPtr auth G_GNUC_UNUSED,
|
2021-03-11 08:16:13 +01:00
|
|
|
virConf *conf G_GNUC_UNUSED,
|
2013-04-23 13:50:18 +01:00
|
|
|
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 16:34:58 -06:00
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
2018-03-28 12:49:29 +01:00
|
|
|
/* If path isn't /system, then they typoed, so tell them correct path */
|
2018-03-28 14:25:23 +01:00
|
|
|
if (STRNEQ(conn->uri->path, "/system")) {
|
2018-03-28 12:49:29 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unexpected OpenVZ URI path '%s', try openvz:///system"),
|
|
|
|
conn->uri->path);
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
2009-06-12 12:06:15 +00:00
|
|
|
|
2018-03-28 12:49:29 +01:00
|
|
|
if (!virFileExists("/proc/vz")) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("OpenVZ control file /proc/vz does not exist"));
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
2009-06-12 12:06:15 +00:00
|
|
|
|
2018-03-28 12:49:29 +01:00
|
|
|
if (access("/proc/vz", W_OK) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("OpenVZ control file /proc/vz is not accessible"));
|
|
|
|
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 */
|
|
|
|
|
2020-09-23 22:04:55 +02:00
|
|
|
driver = g_new0(struct openvz_driver, 1);
|
2008-09-05 14:10:58 +00:00
|
|
|
|
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 12:33:51 +01: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
|
|
|
|
2019-12-03 10:49:49 +00:00
|
|
|
if (!(driver->xmlopt = openvzXMLOption(driver)))
|
2013-03-05 16:17:24 +01: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 16:23:45 +02: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 07:57:22 +01: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 09:16:47 +01: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;
|
|
|
|
}
|
|
|
|
|
2019-10-14 14:45:33 +02:00
|
|
|
static const char *openvzConnectGetType(virConnectPtr conn G_GNUC_UNUSED) {
|
2009-08-03 11:42:39 +01:00
|
|
|
return "OpenVZ";
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-14 14:45:33 +02:00
|
|
|
static int openvzConnectIsEncrypted(virConnectPtr conn G_GNUC_UNUSED)
|
2014-03-18 09:16:47 +01:00
|
|
|
{
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 15:12:03 +01:00
|
|
|
/* Encryption is not relevant / applicable to way we talk to openvz */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-14 14:45:33 +02:00
|
|
|
static int openvzConnectIsSecure(virConnectPtr conn G_GNUC_UNUSED)
|
2014-03-18 09:16:47 +01:00
|
|
|
{
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 15:12:03 +01:00
|
|
|
/* We run CLI tools directly so this is secure */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-09-23 08:56:13 +02:00
|
|
|
static int
|
2019-10-14 14:45:33 +02:00
|
|
|
openvzConnectIsAlive(virConnectPtr conn G_GNUC_UNUSED)
|
2011-09-23 08:56:13 +02:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-04-23 13:50:18 +01:00
|
|
|
static char *openvzConnectGetCapabilities(virConnectPtr conn) {
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2022-02-11 13:54:11 +01:00
|
|
|
VIR_LOCK_GUARD lock = virLockGuardLock(&driver->lock);
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2022-02-11 13:54:11 +01:00
|
|
|
return virCapabilitiesFormatXML(driver->caps);
|
2008-09-05 14:10:58 +00:00
|
|
|
}
|
|
|
|
|
2019-10-14 14:45:33 +02:00
|
|
|
static int openvzConnectListDomains(virConnectPtr conn G_GNUC_UNUSED,
|
2014-03-18 09:16:47 +01:00
|
|
|
int *ids, int nids)
|
|
|
|
{
|
2007-07-17 13:27:26 +00:00
|
|
|
int got = 0;
|
2021-12-13 19:13:24 +01:00
|
|
|
VIR_AUTOCLOSE outfd = -1;
|
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZLIST, "-ovpsid", "-H", NULL);
|
2011-05-06 16:21:58 -04:00
|
|
|
|
|
|
|
virCommandSetOutputFD(cmd, &outfd);
|
|
|
|
if (virCommandRunAsync(cmd, NULL) < 0)
|
2021-12-13 19:13:24 +01:00
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2010-08-31 16:43:18 -06:00
|
|
|
while (got < nids) {
|
2021-12-13 19:13:24 +01:00
|
|
|
char *endptr;
|
|
|
|
char buf[32];
|
|
|
|
int veid;
|
|
|
|
|
|
|
|
if (openvz_readline(outfd, buf, 32) == 0)
|
2010-08-31 16:43:18 -06:00
|
|
|
break;
|
2008-07-21 13:34:19 +00:00
|
|
|
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not parse VPS ID %s"), buf);
|
2008-07-21 13:34:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-12-13 19:13:24 +01:00
|
|
|
ids[got++] = veid;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2011-05-06 16:21:58 -04:00
|
|
|
|
|
|
|
if (virCommandWait(cmd, NULL) < 0)
|
2021-12-13 19:13:24 +01:00
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2010-12-01 17:43:46 +01:00
|
|
|
if (VIR_CLOSE(outfd) < 0) {
|
|
|
|
virReportSystemError(errno, "%s", _("failed to close file"));
|
2021-12-13 19:13:24 +01:00
|
|
|
return -1;
|
2010-12-01 17:43:46 +01:00
|
|
|
}
|
2011-05-06 16:21:58 -04:00
|
|
|
|
2021-12-13 19:13:24 +01:00
|
|
|
return got;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2014-03-18 09:16:47 +01:00
|
|
|
static int openvzConnectNumOfDomains(virConnectPtr conn)
|
|
|
|
{
|
2008-09-05 14:10:58 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2022-02-11 13:54:11 +01:00
|
|
|
VIR_LOCK_GUARD lock = virLockGuardLock(&driver->lock);
|
2008-10-10 14:20:37 +00:00
|
|
|
|
2022-02-11 13:54:11 +01:00
|
|
|
return virDomainObjListNumOfDomains(driver->domains, true, NULL, NULL);
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-14 14:45:33 +02:00
|
|
|
static int openvzConnectListDefinedDomains(virConnectPtr conn G_GNUC_UNUSED,
|
2013-04-23 13:50:18 +01:00
|
|
|
char **const names, int nnames) {
|
2007-07-17 13:27:26 +00:00
|
|
|
int got = 0;
|
2021-12-13 19:22:28 +01:00
|
|
|
VIR_AUTOCLOSE outfd = -1;
|
|
|
|
int ret = -1;
|
|
|
|
g_autoptr(virCommand) 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 16:21:58 -04:00
|
|
|
virCommandSetOutputFD(cmd, &outfd);
|
|
|
|
if (virCommandRunAsync(cmd, NULL) < 0)
|
2021-12-13 19:22:28 +01:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2010-08-31 16:43:18 -06:00
|
|
|
while (got < nnames) {
|
2021-12-13 19:22:28 +01:00
|
|
|
char vpsname[32];
|
|
|
|
char buf[32];
|
|
|
|
char *endptr;
|
|
|
|
int veid;
|
|
|
|
|
|
|
|
if (openvz_readline(outfd, buf, 32) == 0)
|
2010-08-31 16:43:18 -06:00
|
|
|
break;
|
2008-07-21 13:34:19 +00:00
|
|
|
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not parse VPS ID %s"), buf);
|
2008-07-21 13:34:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-11-13 14:53:42 +01:00
|
|
|
g_snprintf(vpsname, sizeof(vpsname), "%d", veid);
|
2021-12-13 19:22:28 +01:00
|
|
|
names[got++] = g_strdup(vpsname);
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2011-05-06 16:21:58 -04:00
|
|
|
|
|
|
|
if (virCommandWait(cmd, NULL) < 0)
|
2021-12-13 19:22:28 +01:00
|
|
|
goto cleanup;
|
2011-05-06 16:21:58 -04:00
|
|
|
|
2010-12-01 17:43:46 +01:00
|
|
|
if (VIR_CLOSE(outfd) < 0) {
|
|
|
|
virReportSystemError(errno, "%s", _("failed to close file"));
|
2021-12-13 19:22:28 +01:00
|
|
|
goto cleanup;
|
2010-12-01 17:43:46 +01:00
|
|
|
}
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2021-12-13 19:22:28 +01:00
|
|
|
ret = got;
|
|
|
|
cleanup:
|
|
|
|
if (ret < 0) {
|
2013-05-21 15:21:19 +08:00
|
|
|
for (; got >= 0; got--)
|
2011-05-06 16:21:58 -04:00
|
|
|
VIR_FREE(names[got]);
|
|
|
|
}
|
2021-12-13 19:22:28 +01:00
|
|
|
return ret;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2011-04-03 11:21:26 +02: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 09:09:57 +02:00
|
|
|
int readvps = vpsid + 1; /* ensure readvps is initially different */
|
2011-04-03 11:21:26 +02:00
|
|
|
ssize_t ret;
|
2011-05-27 17:13:58 +02:00
|
|
|
int err = 0;
|
2008-07-21 08:08:25 +00:00
|
|
|
|
|
|
|
/* read statistic from /proc/vz/vestat.
|
2014-03-25 07:57:22 +01:00
|
|
|
sample:
|
2008-07-21 08:08:25 +00:00
|
|
|
Version: 2.2
|
2010-04-14 09:09:57 +02: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 11:21:26 +02:00
|
|
|
if ((fp = fopen("/proc/vz/vestat", "r")) == NULL)
|
2008-07-21 08:08:25 +00:00
|
|
|
return -1;
|
|
|
|
|
2020-01-24 21:30:04 +01:00
|
|
|
/* search line with VEID=vpsid */
|
2010-08-31 16:43:18 -06:00
|
|
|
while (1) {
|
2011-04-03 11:21:26 +02:00
|
|
|
ret = getline(&line, &line_size, fp);
|
2011-05-27 17:13:58 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
err = !feof(fp);
|
2008-07-21 08:08:25 +00:00
|
|
|
break;
|
2011-05-27 17:13:58 +02:00
|
|
|
}
|
2008-07-21 08:08:25 +00:00
|
|
|
|
2012-10-17 10:23:12 +01:00
|
|
|
if (sscanf(line, "%d %llu %llu %llu",
|
|
|
|
&readvps, &usertime, &nicetime, &systime) == 4
|
2020-01-24 21:30:04 +01:00
|
|
|
&& readvps == vpsid) { /* found vpsid */
|
2010-04-14 09:09:57 +02:00
|
|
|
/* 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 11:21:26 +02:00
|
|
|
VIR_FREE(line);
|
|
|
|
VIR_FORCE_FCLOSE(fp);
|
2011-05-27 17:13:58 +02: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 09:16:47 +01:00
|
|
|
static int openvzConnectNumOfDefinedDomains(virConnectPtr conn)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2022-02-11 13:54:11 +01:00
|
|
|
VIR_LOCK_GUARD lock = virLockGuardLock(&driver->lock);
|
2008-10-10 14:20:37 +00:00
|
|
|
|
2022-02-11 13:54:11 +01:00
|
|
|
return virDomainObjListNumOfDomains(driver->domains, false, NULL, NULL);
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 17:39:46 +01:00
|
|
|
static int
|
2021-03-11 08:16:13 +01:00
|
|
|
openvzDomainSetMemoryInternal(virDomainObj *vm,
|
2012-03-02 13:27:39 -07:00
|
|
|
unsigned long long mem)
|
2009-11-02 17:39:46 +01:00
|
|
|
{
|
2020-04-22 16:25:19 +02:00
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZCTL, "--quiet", NULL);
|
2009-11-02 17:39:46 +01:00
|
|
|
char str_mem[16];
|
|
|
|
|
|
|
|
/* memory has to be changed its format from kbyte to byte */
|
2019-11-13 14:53:42 +01:00
|
|
|
g_snprintf(str_mem, sizeof(str_mem), "%llu", mem * 1024);
|
2009-11-02 17:39:46 +01:00
|
|
|
|
2020-04-22 16:25:19 +02:00
|
|
|
virCommandAddArgList(cmd, "set", vm->def->name,
|
|
|
|
"--kmemsize", str_mem, "--save", NULL);
|
|
|
|
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2020-01-06 18:57:39 -03:00
|
|
|
return -1;
|
2009-11-02 17:39:46 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-25 21:18:16 +02:00
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainGetBarrierLimit(virDomainPtr domain,
|
|
|
|
const char *param,
|
|
|
|
unsigned long long *barrier,
|
|
|
|
unsigned long long *limit)
|
|
|
|
{
|
2021-12-13 19:24:07 +01:00
|
|
|
char *endp;
|
|
|
|
g_autofree char *output = NULL;
|
2012-04-25 21:18:16 +02:00
|
|
|
const char *tmp;
|
2021-12-13 19:24:07 +01:00
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZLIST, "--no-header", NULL);
|
2012-04-25 21:18:16 +02:00
|
|
|
|
|
|
|
virCommandSetOutputBuffer(cmd, &output);
|
|
|
|
virCommandAddArgFormat(cmd, "-o%s.b,%s.l", param, param);
|
|
|
|
virCommandAddArg(cmd, domain->name);
|
2014-02-19 17:32:19 -07:00
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2021-12-13 19:24:07 +01:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
|
|
|
|
tmp = output;
|
|
|
|
virSkipSpaces(&tmp);
|
|
|
|
if (virStrToLong_ull(tmp, &endp, 10, barrier) < 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2019-01-08 15:24:07 +01:00
|
|
|
_("Can't parse limit from vzlist output '%s'"), output);
|
2021-12-13 19:24:07 +01:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
}
|
|
|
|
tmp = endp;
|
|
|
|
virSkipSpaces(&tmp);
|
|
|
|
if (virStrToLong_ull(tmp, &endp, 10, limit) < 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2019-01-08 15:24:07 +01:00
|
|
|
_("Can't parse barrier from vzlist output '%s'"), output);
|
2021-12-13 19:24:07 +01:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
}
|
|
|
|
|
2021-12-13 19:24:07 +01:00
|
|
|
return 0;
|
2012-04-25 21:18:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainSetBarrierLimit(virDomainPtr domain,
|
|
|
|
const char *param,
|
|
|
|
unsigned long long barrier,
|
|
|
|
unsigned long long limit)
|
|
|
|
{
|
2021-12-13 19:24:34 +01:00
|
|
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZCTL, "--quiet", "set", NULL);
|
2012-04-25 21:18:16 +02:00
|
|
|
|
|
|
|
/* LONG_MAX indicates unlimited so reject larger values */
|
|
|
|
if (barrier > LONG_MAX || limit > LONG_MAX) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Failed to set %s for %s: value too large"), param,
|
|
|
|
domain->name);
|
2021-12-13 19:24:34 +01:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virCommandAddArg(cmd, domain->name);
|
|
|
|
virCommandAddArgFormat(cmd, "--%s", param);
|
|
|
|
virCommandAddArgFormat(cmd, "%llu:%llu", barrier, limit);
|
|
|
|
virCommandAddArg(cmd, "--save");
|
|
|
|
|
2021-12-13 19:24:34 +01:00
|
|
|
return virCommandRun(cmd, NULL);
|
2012-04-25 21:18:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 15:09:33 +01:00
|
|
|
size_t i;
|
2012-04-25 21:18:16 +02:00
|
|
|
const char *name;
|
|
|
|
long kb_per_pages;
|
|
|
|
unsigned long long barrier, limit, val;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2012-05-07 23:00:28 +02:00
|
|
|
kb_per_pages = openvzKBPerPages();
|
|
|
|
if (kb_per_pages < 0)
|
2020-01-06 18:57:39 -03:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
|
|
|
|
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)
|
2020-01-06 18:57:39 -03:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
|
2015-03-02 20:04:12 +01:00
|
|
|
val = (limit == LONG_MAX) ? VIR_DOMAIN_MEMORY_PARAM_UNLIMITED : limit * kb_per_pages;
|
2012-04-25 21:18:16 +02:00
|
|
|
if (virTypedParameterAssign(param, VIR_DOMAIN_MEMORY_HARD_LIMIT,
|
|
|
|
VIR_TYPED_PARAM_ULLONG, val) < 0)
|
2020-01-06 18:57:39 -03:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
name = "privvmpages";
|
|
|
|
if (openvzDomainGetBarrierLimit(domain, name, &barrier, &limit) < 0)
|
2020-01-06 18:57:39 -03:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
|
2015-03-02 20:04:12 +01:00
|
|
|
val = (barrier == LONG_MAX) ? VIR_DOMAIN_MEMORY_PARAM_UNLIMITED : barrier * kb_per_pages;
|
2012-04-25 21:18:16 +02:00
|
|
|
if (virTypedParameterAssign(param, VIR_DOMAIN_MEMORY_SOFT_LIMIT,
|
|
|
|
VIR_TYPED_PARAM_ULLONG, val) < 0)
|
2020-01-06 18:57:39 -03:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
name = "vmguarpages";
|
|
|
|
if (openvzDomainGetBarrierLimit(domain, name, &barrier, &limit) < 0)
|
2020-01-06 18:57:39 -03:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
|
|
|
|
val = (barrier == LONG_MAX) ? 0ull : barrier * kb_per_pages;
|
|
|
|
if (virTypedParameterAssign(param, VIR_DOMAIN_MEMORY_MIN_GUARANTEE,
|
|
|
|
VIR_TYPED_PARAM_ULLONG, val) < 0)
|
2020-01-06 18:57:39 -03:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*nparams > OPENVZ_NB_MEM_PARAM)
|
|
|
|
*nparams = OPENVZ_NB_MEM_PARAM;
|
|
|
|
|
2020-01-06 18:57:39 -03:00
|
|
|
return 0;
|
2012-04-25 21:18:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 15:09:33 +01:00
|
|
|
size_t i;
|
2012-04-25 21:18:16 +02:00
|
|
|
long kb_per_pages;
|
|
|
|
|
2012-05-07 23:00:28 +02:00
|
|
|
kb_per_pages = openvzKBPerPages();
|
|
|
|
if (kb_per_pages < 0)
|
2020-01-06 18:57:39 -03:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
2013-05-03 15:34:10 +02: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 21:18:16 +02: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)
|
2020-01-06 18:57:39 -03:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
limit = params[i].value.ul / kb_per_pages;
|
|
|
|
if (openvzDomainSetBarrierLimit(domain, "privvmpages",
|
|
|
|
barrier, limit) < 0)
|
2020-01-06 18:57:39 -03:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
} else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT)) {
|
|
|
|
if (openvzDomainGetBarrierLimit(domain, "privvmpages",
|
|
|
|
&barrier, &limit) < 0)
|
2020-01-06 18:57:39 -03:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
barrier = params[i].value.ul / kb_per_pages;
|
|
|
|
if (openvzDomainSetBarrierLimit(domain, "privvmpages",
|
|
|
|
barrier, limit) < 0)
|
2020-01-06 18:57:39 -03:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
} 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)
|
2020-01-06 18:57:39 -03:00
|
|
|
return -1;
|
2012-04-25 21:18:16 +02:00
|
|
|
}
|
|
|
|
}
|
2020-01-06 18:57:39 -03:00
|
|
|
|
|
|
|
return 0;
|
2012-04-25 21:18:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-29 10:41:32 +02:00
|
|
|
static int
|
2021-03-11 08:16:13 +01:00
|
|
|
openvzGetVEStatus(virDomainObj *vm, int *status, int *reason)
|
2011-07-29 10:41:32 +02:00
|
|
|
{
|
2021-12-13 19:26:06 +01:00
|
|
|
g_autoptr(virCommand) cmd = NULL;
|
|
|
|
g_autofree char *outbuf = NULL;
|
2011-07-29 10:41:32 +02:00
|
|
|
char *line;
|
|
|
|
int state;
|
|
|
|
|
|
|
|
cmd = virCommandNewArgList(VZLIST, vm->def->name, "-ostatus", "-H", NULL);
|
|
|
|
virCommandSetOutputBuffer(cmd, &outbuf);
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2021-12-13 19:26:06 +01:00
|
|
|
return -1;
|
2011-07-29 10:41:32 +02:00
|
|
|
|
|
|
|
if ((line = strchr(outbuf, '\n')) == NULL) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Failed to parse vzlist output"));
|
2021-12-13 19:26:06 +01:00
|
|
|
return -1;
|
2011-07-29 10:41:32 +02:00
|
|
|
}
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:26:06 +01:00
|
|
|
return 0;
|
2011-07-29 10:41:32 +02:00
|
|
|
}
|
|
|
|
|
2012-04-19 23:51:31 +02:00
|
|
|
static int
|
2012-10-17 10:23:12 +01:00
|
|
|
openvzDomainInterfaceStats(virDomainPtr dom,
|
2017-10-13 13:25:42 -07:00
|
|
|
const char *device,
|
2014-09-16 21:19:45 +08:00
|
|
|
virDomainInterfaceStatsPtr stats)
|
2012-04-19 23:51:31 +02:00
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm;
|
|
|
|
virDomainNetDef *net = NULL;
|
2012-04-19 23:51:31 +02:00
|
|
|
int ret = -1;
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
2012-04-19 23:51:31 +02:00
|
|
|
|
2018-04-17 22:13:32 +00:00
|
|
|
if (virDomainObjCheckActive(vm) < 0)
|
2012-04-19 23:51:31 +02:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-10-13 13:25:42 -07:00
|
|
|
if (!(net = virDomainNetFind(vm->def, device)))
|
2017-10-02 15:24:39 +02:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-10-13 16:29:36 -07:00
|
|
|
if (virNetDevTapInterfaceStats(net->ifname, stats,
|
2017-10-02 13:36:56 +02:00
|
|
|
!virDomainNetTypeSharesHostView(net)) < 0)
|
2017-10-02 15:24:39 +02:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2012-04-19 23:51:31 +02:00
|
|
|
|
2014-03-25 07:57:22 +01:00
|
|
|
cleanup:
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2012-04-19 23:51:31 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-25 19:49:32 +02:00
|
|
|
static int
|
2021-03-11 08:16:13 +01:00
|
|
|
openvzUpdateDevice(virDomainDef *vmdef,
|
|
|
|
virDomainDeviceDef *dev,
|
2012-05-25 19:49:32 +02:00
|
|
|
bool persist)
|
|
|
|
{
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainFSDef *fs;
|
|
|
|
virDomainFSDef *cur;
|
2012-05-25 19:49:32 +02:00
|
|
|
int pos;
|
|
|
|
|
|
|
|
if (dev->type == VIR_DOMAIN_DEVICE_FS) {
|
|
|
|
fs = dev->data.fs;
|
|
|
|
pos = virDomainFSIndexByName(vmdef, fs->dst);
|
|
|
|
|
|
|
|
if (pos < 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("target %s doesn't exist."), fs->dst);
|
2012-05-25 19:49:32 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
cur = vmdef->fss[pos];
|
|
|
|
|
|
|
|
/* We only allow updating the quota */
|
2016-07-14 16:52:38 +03:00
|
|
|
if (STRNEQ(cur->src->path, fs->src->path)
|
2012-05-25 19:49:32 +02:00
|
|
|
|| 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 14:33:08 -06:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
2012-07-18 14:13:44 +01:00
|
|
|
_("Can only modify disk quota"));
|
2012-05-25 19:49:32 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-13 15:29:21 +01:00
|
|
|
if (openvzSetDiskQuota(vmdef, fs, persist) < 0)
|
2012-05-25 19:49:32 +02:00
|
|
|
return -1;
|
|
|
|
cur->space_hard_limit = fs->space_hard_limit;
|
|
|
|
cur->space_soft_limit = fs->space_soft_limit;
|
|
|
|
} else {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Can't modify device type '%s'"),
|
|
|
|
virDomainDeviceTypeToString(dev->type));
|
2012-05-25 19:49:32 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
|
2017-10-23 12:04:43 -04:00
|
|
|
unsigned int flags)
|
2012-05-25 19:49:32 +02:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int veid;
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainDeviceDef *dev = NULL;
|
|
|
|
virDomainObj *vm = NULL;
|
|
|
|
virDomainDef *def = NULL;
|
2012-05-25 19:49:32 +02:00
|
|
|
bool persist = false;
|
2022-02-11 13:54:11 +01:00
|
|
|
VIR_LOCK_GUARD lock = virLockGuardLock(&driver->lock);
|
2012-05-25 19:49:32 +02:00
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_LIVE |
|
|
|
|
VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1);
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomainLocked(driver, dom->uuid)))
|
2012-05-25 19:49:32 +02:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-07-01 16:07:51 +02:00
|
|
|
if (virStrToLong_i(vm->def->name, NULL, 10, &veid) < 0) {
|
2012-07-18 14:13:44 +01:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not convert domain name to VEID"));
|
2012-05-25 19:49:32 +02:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-07-01 16:07:51 +02:00
|
|
|
if (!(def = virDomainObjGetOneDef(vm, flags)))
|
2012-05-25 19:49:32 +02:00
|
|
|
goto cleanup;
|
|
|
|
|
2019-11-27 12:29:21 +00:00
|
|
|
dev = virDomainDeviceDefParse(xml, def, driver->xmlopt, NULL,
|
2014-11-18 16:44:00 +00:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE);
|
2012-05-25 19:49:32 +02:00
|
|
|
if (!dev)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_AFFECT_CONFIG)
|
|
|
|
persist = true;
|
|
|
|
|
2016-07-01 16:07:51 +02:00
|
|
|
if (openvzUpdateDevice(def, dev, persist) < 0)
|
2012-05-25 19:49:32 +02:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 07:57:22 +01:00
|
|
|
cleanup:
|
2012-05-25 19:49:32 +02:00
|
|
|
virDomainDeviceDefFree(dev);
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2012-05-25 19:49:32 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-11 11:04:57 +02:00
|
|
|
static int
|
2013-04-23 13:50:18 +01:00
|
|
|
openvzConnectListAllDomains(virConnectPtr conn,
|
|
|
|
virDomainPtr **domains,
|
|
|
|
unsigned int flags)
|
2012-06-11 11:04:57 +02:00
|
|
|
{
|
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2022-02-11 13:54:11 +01:00
|
|
|
VIR_LOCK_GUARD lock = virLockGuardLock(&driver->lock);
|
2012-06-11 11:04:57 +02:00
|
|
|
|
2012-08-03 23:48:05 +08:00
|
|
|
virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
|
2022-02-11 13:54:11 +01:00
|
|
|
return virDomainObjListExport(driver->domains, conn, domains, NULL, flags);
|
2012-06-11 11:04:57 +02:00
|
|
|
}
|
|
|
|
|
2012-05-25 19:49:32 +02:00
|
|
|
|
2013-04-26 18:21:58 +01:00
|
|
|
|
|
|
|
static int
|
2019-10-14 14:45:33 +02:00
|
|
|
openvzNodeGetInfo(virConnectPtr conn G_GNUC_UNUSED,
|
2013-04-26 18:21:58 +01:00
|
|
|
virNodeInfoPtr nodeinfo)
|
|
|
|
{
|
2017-03-07 10:40:15 +01:00
|
|
|
return virCapabilitiesGetNodeInfo(nodeinfo);
|
2013-04-26 18:21:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2019-10-14 14:45:33 +02:00
|
|
|
openvzNodeGetCPUStats(virConnectPtr conn G_GNUC_UNUSED,
|
2013-04-26 18:21:58 +01:00
|
|
|
int cpuNum,
|
|
|
|
virNodeCPUStatsPtr params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2016-04-13 18:16:16 +01:00
|
|
|
return virHostCPUGetStats(cpuNum, params, nparams, flags);
|
2013-04-26 18:21:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2019-10-14 14:45:33 +02:00
|
|
|
openvzNodeGetMemoryStats(virConnectPtr conn G_GNUC_UNUSED,
|
2013-04-26 18:21:58 +01:00
|
|
|
int cellNum,
|
|
|
|
virNodeMemoryStatsPtr params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2016-04-13 18:16:16 +01:00
|
|
|
return virHostMemGetStats(cellNum, params, nparams, flags);
|
2013-04-26 18:21:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2019-10-14 14:45:33 +02:00
|
|
|
openvzNodeGetCellsFreeMemory(virConnectPtr conn G_GNUC_UNUSED,
|
2013-04-26 18:21:58 +01:00
|
|
|
unsigned long long *freeMems,
|
|
|
|
int startCell,
|
|
|
|
int maxCells)
|
|
|
|
{
|
2016-04-13 18:16:16 +01:00
|
|
|
return virHostMemGetCellsFree(freeMems, startCell, maxCells);
|
2013-04-26 18:21:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned long long
|
2019-10-14 14:45:33 +02:00
|
|
|
openvzNodeGetFreeMemory(virConnectPtr conn G_GNUC_UNUSED)
|
2013-04-26 18:21:58 +01:00
|
|
|
{
|
2014-06-16 14:02:34 +02:00
|
|
|
unsigned long long freeMem;
|
2016-04-13 18:16:16 +01:00
|
|
|
if (virHostMemGetInfo(NULL, &freeMem) < 0)
|
2014-06-16 14:02:34 +02:00
|
|
|
return 0;
|
|
|
|
return freeMem;
|
2013-04-26 18:21:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2019-10-14 14:45:33 +02:00
|
|
|
openvzNodeGetCPUMap(virConnectPtr conn G_GNUC_UNUSED,
|
2013-04-26 18:21:58 +01:00
|
|
|
unsigned char **cpumap,
|
|
|
|
unsigned int *online,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2016-04-13 18:16:16 +01:00
|
|
|
return virHostCPUGetMap(cpumap, online, flags);
|
2013-04-26 18:21:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-04 22:25:06 -04:00
|
|
|
static int
|
2019-10-14 14:45:33 +02:00
|
|
|
openvzConnectSupportsFeature(virConnectPtr conn G_GNUC_UNUSED, int feature)
|
2014-09-04 22:25:06 -04:00
|
|
|
{
|
2022-02-16 13:01:39 +01:00
|
|
|
int supported;
|
|
|
|
|
|
|
|
if (virDriverFeatureIsGlobal(feature, &supported))
|
|
|
|
return supported;
|
|
|
|
|
2018-03-08 13:20:24 +01:00
|
|
|
switch ((virDrvFeature) feature) {
|
2022-02-16 18:50:42 +01:00
|
|
|
case VIR_DRV_FEATURE_REMOTE:
|
|
|
|
case VIR_DRV_FEATURE_PROGRAM_KEEPALIVE:
|
|
|
|
case VIR_DRV_FEATURE_REMOTE_CLOSE_CALLBACK:
|
|
|
|
case VIR_DRV_FEATURE_REMOTE_EVENT_CALLBACK:
|
|
|
|
case VIR_DRV_FEATURE_TYPED_PARAM_STRING:
|
|
|
|
case VIR_DRV_FEATURE_NETWORK_UPDATE_HAS_CORRECT_ORDER:
|
|
|
|
case VIR_DRV_FEATURE_FD_PASSING:
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Global feature %d should have already been handled"),
|
|
|
|
feature);
|
|
|
|
return -1;
|
2014-09-04 22:25:06 -04:00
|
|
|
case VIR_DRV_FEATURE_MIGRATION_PARAMS:
|
|
|
|
case VIR_DRV_FEATURE_MIGRATION_V3:
|
|
|
|
return 1;
|
2018-03-08 13:20:24 +01:00
|
|
|
case VIR_DRV_FEATURE_MIGRATE_CHANGE_PROTECTION:
|
|
|
|
case VIR_DRV_FEATURE_MIGRATION_DIRECT:
|
|
|
|
case VIR_DRV_FEATURE_MIGRATION_OFFLINE:
|
|
|
|
case VIR_DRV_FEATURE_MIGRATION_P2P:
|
|
|
|
case VIR_DRV_FEATURE_MIGRATION_V1:
|
|
|
|
case VIR_DRV_FEATURE_MIGRATION_V2:
|
|
|
|
case VIR_DRV_FEATURE_XML_MIGRATABLE:
|
2014-09-04 22:25:06 -04:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
openvzDomainMigrateBegin3Params(virDomainPtr domain,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
2019-10-14 14:45:33 +02:00
|
|
|
char **cookieout G_GNUC_UNUSED,
|
|
|
|
int *cookieoutlen G_GNUC_UNUSED,
|
2014-09-04 22:25:06 -04:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm = NULL;
|
2014-09-04 22:25:06 -04:00
|
|
|
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;
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, domain->uuid)))
|
|
|
|
return NULL;
|
2014-09-04 22:25:06 -04:00
|
|
|
|
2018-04-17 22:13:32 +00:00
|
|
|
if (virDomainObjCheckActive(vm) < 0)
|
2014-09-04 22:25:06 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-11-27 11:57:34 +00:00
|
|
|
xml = virDomainDefFormat(vm->def, driver->xmlopt,
|
2016-02-03 21:40:35 +00:00
|
|
|
VIR_DOMAIN_DEF_FORMAT_SECURE);
|
2014-09-04 22:25:06 -04:00
|
|
|
|
|
|
|
cleanup:
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-09-04 22:25:06 -04:00
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainMigratePrepare3Params(virConnectPtr dconn,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
2019-10-14 14:45:33 +02:00
|
|
|
const char *cookiein G_GNUC_UNUSED,
|
|
|
|
int cookieinlen G_GNUC_UNUSED,
|
|
|
|
char **cookieout G_GNUC_UNUSED,
|
|
|
|
int *cookieoutlen G_GNUC_UNUSED,
|
2014-09-04 22:25:06 -04:00
|
|
|
char **uri_out,
|
2019-10-14 14:45:33 +02:00
|
|
|
unsigned int fflags G_GNUC_UNUSED)
|
2014-09-04 22:25:06 -04:00
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dconn->privateData;
|
|
|
|
const char *dom_xml = NULL;
|
|
|
|
const char *uri_in = NULL;
|
2021-11-29 09:07:44 +01:00
|
|
|
g_autoptr(virDomainDef) def = NULL;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm = NULL;
|
2020-11-19 11:09:43 +01:00
|
|
|
g_autofree char *my_hostname = NULL;
|
2014-09-15 22:22:48 -04:00
|
|
|
const char *hostname = NULL;
|
2020-11-19 11:09:43 +01:00
|
|
|
g_autoptr(virURI) uri = NULL;
|
2014-09-04 22:25:06 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-11-27 12:29:21 +00:00
|
|
|
if (!(def = virDomainDefParseString(dom_xml, driver->xmlopt,
|
2016-09-22 17:14:17 +02:00
|
|
|
NULL,
|
2016-05-26 15:58:53 +02:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE |
|
|
|
|
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)))
|
2014-09-04 22:25:06 -04:00
|
|
|
goto error;
|
|
|
|
|
2021-11-02 12:19:50 +01:00
|
|
|
if (!(vm = virDomainObjListAdd(driver->domains, &def,
|
2014-09-04 22:25:06 -04:00
|
|
|
driver->xmlopt,
|
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
|
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
|
|
|
|
NULL)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!uri_in) {
|
2014-09-15 22:22:48 -04:00
|
|
|
if ((my_hostname = virGetHostname()) == NULL)
|
2014-09-04 22:25:06 -04:00
|
|
|
goto error;
|
|
|
|
|
2014-09-15 22:22:48 -04:00
|
|
|
if (STRPREFIX(my_hostname, "localhost")) {
|
2014-09-04 22:25:06 -04:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("hostname on destination resolved to localhost,"
|
|
|
|
" but migration requires an FQDN"));
|
|
|
|
goto error;
|
|
|
|
}
|
2020-11-19 10:58:09 +01:00
|
|
|
|
|
|
|
hostname = my_hostname;
|
2014-09-04 22:25:06 -04:00
|
|
|
} 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;
|
|
|
|
}
|
2020-11-19 11:06:56 +01:00
|
|
|
|
|
|
|
hostname = uri->server;
|
2014-09-04 22:25:06 -04:00
|
|
|
}
|
|
|
|
|
2019-10-22 15:26:14 +02:00
|
|
|
*uri_out = g_strdup_printf("ssh://%s", hostname);
|
2014-09-04 22:25:06 -04:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
error:
|
2018-04-23 10:40:48 -04:00
|
|
|
if (vm)
|
2014-09-04 22:25:06 -04:00
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
|
|
|
|
|
|
|
done:
|
2018-04-23 10:40:48 -04:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-09-04 22:25:06 -04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainMigratePerform3Params(virDomainPtr domain,
|
2019-10-14 14:45:33 +02:00
|
|
|
const char *dconnuri G_GNUC_UNUSED,
|
2014-09-04 22:25:06 -04:00
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
2019-10-14 14:45:33 +02:00
|
|
|
const char *cookiein G_GNUC_UNUSED,
|
|
|
|
int cookieinlen G_GNUC_UNUSED,
|
|
|
|
char **cookieout G_GNUC_UNUSED,
|
|
|
|
int *cookieoutlen G_GNUC_UNUSED,
|
2014-09-04 22:25:06 -04:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = domain->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm = NULL;
|
2014-09-04 22:25:06 -04:00
|
|
|
const char *uri_str = NULL;
|
2021-12-13 19:27:02 +01:00
|
|
|
g_autoptr(virURI) uri = NULL;
|
|
|
|
g_autoptr(virCommand) cmd = NULL;
|
2014-09-04 22:25:06 -04: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;
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, domain->uuid)))
|
2014-09-04 22:25:06 -04:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* parse dst host:port from uri */
|
|
|
|
uri = virURIParse(uri_str);
|
|
|
|
if (uri == NULL || uri->server == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-09-15 22:22:48 -04:00
|
|
|
cmd = virCommandNew(VZMIGRATE);
|
2014-09-04 22:25:06 -04: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:
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-09-04 22:25:06 -04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr
|
|
|
|
openvzDomainMigrateFinish3Params(virConnectPtr dconn,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
2019-10-14 14:45:33 +02:00
|
|
|
const char *cookiein G_GNUC_UNUSED,
|
|
|
|
int cookieinlen G_GNUC_UNUSED,
|
|
|
|
char **cookieout G_GNUC_UNUSED,
|
|
|
|
int *cookieoutlen G_GNUC_UNUSED,
|
2014-09-04 22:25:06 -04:00
|
|
|
unsigned int flags,
|
|
|
|
int cancelled)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dconn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm = NULL;
|
2014-09-04 22:25:06 -04:00
|
|
|
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);
|
|
|
|
|
2017-03-28 17:08:03 +02:00
|
|
|
dom = virGetDomain(dconn, vm->def->name, vm->def->uuid, vm->def->id);
|
2014-09-04 22:25:06 -04:00
|
|
|
|
|
|
|
cleanup:
|
2015-04-23 18:00:01 +02:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-09-04 22:25:06 -04:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainMigrateConfirm3Params(virDomainPtr domain,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
2019-10-14 14:45:33 +02:00
|
|
|
const char *cookiein G_GNUC_UNUSED,
|
|
|
|
int cookieinlen G_GNUC_UNUSED,
|
2014-09-04 22:25:06 -04:00
|
|
|
unsigned int flags,
|
|
|
|
int cancelled)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = domain->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *vm = NULL;
|
2014-09-04 22:25:06 -04:00
|
|
|
int status;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(OPENVZ_MIGRATION_FLAGS, -1);
|
|
|
|
if (virTypedParamsValidate(params, nparams, OPENVZ_MIGRATION_PARAMETERS) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(vm = openvzDomObjFromDomain(driver, domain->uuid)))
|
2014-09-04 22:25:06 -04:00
|
|
|
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);
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&vm);
|
2014-09-04 22:25:06 -04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-01-15 15:02:44 +01:00
|
|
|
static int
|
|
|
|
openvzDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
2021-03-11 08:16:13 +01:00
|
|
|
virDomainObj *obj;
|
2015-01-15 15:02:44 +01:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2018-03-09 11:48:02 -05:00
|
|
|
if (!(obj = openvzDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
|
|
|
|
2015-01-15 15:02:44 +01:00
|
|
|
ret = 0;
|
|
|
|
|
2018-03-09 11:48:04 -05:00
|
|
|
virDomainObjEndAPI(&obj);
|
2015-01-15 15:02:44 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-04 22:25:06 -04:00
|
|
|
|
2015-01-20 16:16:26 +00:00
|
|
|
static virHypervisorDriver openvzHypervisorDriver = {
|
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 11:16:31 +01:00
|
|
|
.name = "OPENVZ",
|
2018-03-27 17:24:44 +01:00
|
|
|
.connectURIProbe = openvzConnectURIProbe,
|
2013-04-23 13:50:18 +01:00
|
|
|
.connectOpen = openvzConnectOpen, /* 0.3.1 */
|
|
|
|
.connectClose = openvzConnectClose, /* 0.3.1 */
|
|
|
|
.connectGetType = openvzConnectGetType, /* 0.3.1 */
|
|
|
|
.connectGetVersion = openvzConnectGetVersion, /* 0.5.0 */
|
2013-04-26 17:39:11 +01:00
|
|
|
.connectGetHostname = openvzConnectGetHostname, /* 0.9.12 */
|
2013-04-23 13:50:18 +01:00
|
|
|
.connectGetMaxVcpus = openvzConnectGetMaxVcpus, /* 0.4.6 */
|
2013-04-26 18:21:58 +01: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 13:50:18 +01:00
|
|
|
.connectGetCapabilities = openvzConnectGetCapabilities, /* 0.4.6 */
|
|
|
|
.connectListDomains = openvzConnectListDomains, /* 0.3.1 */
|
|
|
|
.connectNumOfDomains = openvzConnectNumOfDomains, /* 0.3.1 */
|
|
|
|
.connectListAllDomains = openvzConnectListAllDomains, /* 0.9.13 */
|
2011-05-13 14:35:01 +01: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 18:31:55 +01:00
|
|
|
.domainShutdownFlags = openvzDomainShutdownFlags, /* 0.9.10 */
|
2011-05-13 14:35:01 +01:00
|
|
|
.domainReboot = openvzDomainReboot, /* 0.3.1 */
|
2013-04-23 13:50:18 +01:00
|
|
|
.domainDestroy = openvzDomainDestroy, /* 0.3.1 */
|
|
|
|
.domainDestroyFlags = openvzDomainDestroyFlags, /* 0.9.4 */
|
|
|
|
.domainGetOSType = openvzDomainGetOSType, /* 0.3.1 */
|
2012-04-25 21:18:16 +02:00
|
|
|
.domainGetMemoryParameters = openvzDomainGetMemoryParameters, /* 0.9.12 */
|
|
|
|
.domainSetMemoryParameters = openvzDomainSetMemoryParameters, /* 0.9.12 */
|
2011-05-13 14:35:01 +01: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 13:50:18 +01:00
|
|
|
.connectListDefinedDomains = openvzConnectListDefinedDomains, /* 0.3.1 */
|
|
|
|
.connectNumOfDefinedDomains = openvzConnectNumOfDefinedDomains, /* 0.3.1 */
|
2011-05-13 14:35:01 +01: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 14:35:01 +01:00
|
|
|
.domainUndefine = openvzDomainUndefine, /* 0.3.3 */
|
2011-07-20 11:08:21 +08:00
|
|
|
.domainUndefineFlags = openvzDomainUndefineFlags, /* 0.9.4 */
|
2011-05-13 14:35:01 +01:00
|
|
|
.domainGetAutostart = openvzDomainGetAutostart, /* 0.4.6 */
|
|
|
|
.domainSetAutostart = openvzDomainSetAutostart, /* 0.4.6 */
|
2012-04-19 23:51:31 +02:00
|
|
|
.domainInterfaceStats = openvzDomainInterfaceStats, /* 0.9.12 */
|
2013-04-23 13:50:18 +01:00
|
|
|
.connectIsEncrypted = openvzConnectIsEncrypted, /* 0.7.3 */
|
|
|
|
.connectIsSecure = openvzConnectIsSecure, /* 0.7.3 */
|
2011-05-13 14:35:01 +01:00
|
|
|
.domainIsActive = openvzDomainIsActive, /* 0.7.3 */
|
|
|
|
.domainIsPersistent = openvzDomainIsPersistent, /* 0.7.3 */
|
|
|
|
.domainIsUpdated = openvzDomainIsUpdated, /* 0.8.6 */
|
2013-04-23 13:50:18 +01:00
|
|
|
.connectIsAlive = openvzConnectIsAlive, /* 0.9.8 */
|
2012-05-25 19:49:32 +02:00
|
|
|
.domainUpdateDeviceFlags = openvzDomainUpdateDeviceFlags, /* 0.9.13 */
|
2012-08-01 11:00:35 -06:00
|
|
|
.domainGetHostname = openvzDomainGetHostname, /* 0.10.0 */
|
2014-09-04 22:25:06 -04: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 */
|
2015-01-15 15:02:44 +01:00
|
|
|
.domainHasManagedSaveImage = openvzDomainHasManagedSaveImage, /* 1.2.13 */
|
2007-07-17 13:27:26 +00:00
|
|
|
};
|
|
|
|
|
2015-01-20 16:16:26 +00:00
|
|
|
static virConnectDriver openvzConnectDriver = {
|
2018-03-28 10:53:31 +01:00
|
|
|
.localOnly = true,
|
2018-03-27 15:51:45 +01:00
|
|
|
.uriSchemes = (const char *[]){ "openvz", NULL },
|
2015-01-20 16:16:26 +00:00
|
|
|
.hypervisorDriver = &openvzHypervisorDriver,
|
|
|
|
};
|
|
|
|
|
2014-03-18 09:16:47 +01:00
|
|
|
int openvzRegister(void)
|
|
|
|
{
|
2015-01-20 16:16:26 +00:00
|
|
|
return virRegisterConnectDriver(&openvzConnectDriver,
|
|
|
|
false);
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|