2007-07-17 13:27:26 +00:00
|
|
|
/*
|
|
|
|
* openvz_driver.c: core driver methods for managing OpenVZ VEs
|
|
|
|
*
|
2010-05-03 21:00:43 +00:00
|
|
|
* Copyright (C) 2010 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
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
2008-02-05 19:27:37 +00:00
|
|
|
* Authors:
|
2007-09-03 15:37:07 +00:00
|
|
|
* Shuveb Hussain <shuveb@binarykarma.com>
|
|
|
|
* Anoop Joe Cyriac <anoop@binarykarma.com>
|
|
|
|
*
|
2007-07-17 13:27:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <paths.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
#include "virterror_internal.h"
|
2008-11-04 23:22:06 +00:00
|
|
|
#include "datatypes.h"
|
2007-09-03 15:37:07 +00:00
|
|
|
#include "openvz_driver.h"
|
2007-07-17 13:27:26 +00:00
|
|
|
#include "event.h"
|
|
|
|
#include "buf.h"
|
2007-07-19 16:22:40 +00:00
|
|
|
#include "util.h"
|
2007-07-17 13:27:26 +00:00
|
|
|
#include "openvz_conf.h"
|
2007-07-25 23:16:30 +00:00
|
|
|
#include "nodeinfo.h"
|
2008-07-16 14:45:55 +00:00
|
|
|
#include "memory.h"
|
2008-11-12 16:35:47 +00:00
|
|
|
#include "bridge.h"
|
2010-11-09 20:48:48 +00:00
|
|
|
#include "files.h"
|
2010-11-29 09:23:15 +00:00
|
|
|
#include "logging.h"
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2009-01-29 12:10:32 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_OPENVZ
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
#define OPENVZ_MAX_ARG 28
|
|
|
|
#define CMDBUF_LEN 1488
|
|
|
|
#define CMDOP_LEN 288
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-07-21 08:08:25 +00:00
|
|
|
static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid);
|
2008-08-20 13:44:03 +00:00
|
|
|
static int openvzGetMaxVCPUs(virConnectPtr conn, const char *type);
|
|
|
|
static int openvzDomainGetMaxVcpus(virDomainPtr dom);
|
2010-04-03 14:23:45 +00:00
|
|
|
static int openvzDomainSetVcpusInternal(virDomainObjPtr vm,
|
2009-11-02 16:39:46 +00:00
|
|
|
unsigned int nvcpus);
|
2010-04-03 14:23:45 +00:00
|
|
|
static int openvzDomainSetMemoryInternal(virDomainObjPtr vm,
|
2009-11-02 16:39:46 +00:00
|
|
|
unsigned long memory);
|
2008-07-21 08:08:25 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
static void openvzDriverLock(struct openvz_driver *driver)
|
|
|
|
{
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&driver->lock);
|
2008-12-04 21:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void openvzDriverUnlock(struct openvz_driver *driver)
|
|
|
|
{
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&driver->lock);
|
2008-12-04 21:44:55 +00:00
|
|
|
}
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
struct openvz_driver ovz_driver;
|
|
|
|
|
2008-08-08 15:43:38 +00:00
|
|
|
static void cmdExecFree(const char *cmdExec[])
|
2007-09-03 15:37:07 +00:00
|
|
|
{
|
|
|
|
int i=-1;
|
2010-08-31 22:43:18 +00:00
|
|
|
while (cmdExec[++i]) {
|
2008-07-16 14:45:55 +00:00
|
|
|
VIR_FREE(cmdExec[i]);
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-16 14:45:55 +00:00
|
|
|
/* generate arguments to create OpenVZ container
|
|
|
|
return -1 - error
|
|
|
|
0 - OK
|
|
|
|
*/
|
2009-09-22 10:19:09 +00:00
|
|
|
static int
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzDomainDefineCmd(const char *args[],
|
2009-09-22 10:19:09 +00:00
|
|
|
int maxarg, virDomainDefPtr vmdef)
|
2008-07-16 14:45:55 +00:00
|
|
|
{
|
|
|
|
int narg;
|
|
|
|
|
|
|
|
for (narg = 0; narg < maxarg; narg++)
|
|
|
|
args[narg] = NULL;
|
|
|
|
|
2009-09-22 10:19:09 +00:00
|
|
|
if (vmdef == NULL) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Container is not defined"));
|
2008-07-16 14:45:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-11-28 21:52:44 +00:00
|
|
|
|
2008-07-16 14:45:55 +00:00
|
|
|
#define ADD_ARG(thisarg) \
|
|
|
|
do { \
|
|
|
|
if (narg >= maxarg) \
|
|
|
|
goto no_memory; \
|
|
|
|
args[narg++] = thisarg; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ADD_ARG_LIT(thisarg) \
|
|
|
|
do { \
|
|
|
|
if (narg >= maxarg) \
|
|
|
|
goto no_memory; \
|
|
|
|
if ((args[narg++] = strdup(thisarg)) == NULL) \
|
|
|
|
goto no_memory; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
narg = 0;
|
|
|
|
ADD_ARG_LIT(VZCTL);
|
|
|
|
ADD_ARG_LIT("--quiet");
|
|
|
|
ADD_ARG_LIT("create");
|
2009-09-22 10:19:09 +00:00
|
|
|
|
2010-11-28 21:52:44 +00:00
|
|
|
ADD_ARG_LIT(vmdef->name);
|
2009-09-22 10:19:09 +00:00
|
|
|
ADD_ARG_LIT("--name");
|
2008-07-16 14:45:55 +00:00
|
|
|
ADD_ARG_LIT(vmdef->name);
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2009-03-24 10:59:13 +00:00
|
|
|
if (vmdef->nfss == 1 &&
|
2009-09-22 10:19:09 +00:00
|
|
|
vmdef->fss[0]->type == VIR_DOMAIN_FS_TYPE_TEMPLATE) {
|
2008-07-16 14:45:55 +00:00
|
|
|
ADD_ARG_LIT("--ostemplate");
|
2008-10-10 16:08:01 +00:00
|
|
|
ADD_ARG_LIT(vmdef->fss[0]->src);
|
2008-07-16 14:45:55 +00:00
|
|
|
}
|
2008-09-05 14:10:58 +00:00
|
|
|
#if 0
|
2008-07-16 14:45:55 +00:00
|
|
|
if ((vmdef->profile && *(vmdef->profile))) {
|
|
|
|
ADD_ARG_LIT("--config");
|
|
|
|
ADD_ARG_LIT(vmdef->profile);
|
|
|
|
}
|
2008-09-05 14:10:58 +00:00
|
|
|
#endif
|
2008-07-16 14:45:55 +00:00
|
|
|
|
|
|
|
ADD_ARG(NULL);
|
|
|
|
return 0;
|
2009-09-22 10:19:09 +00:00
|
|
|
|
|
|
|
no_memory:
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
2008-07-16 14:45:55 +00:00
|
|
|
_("Could not put argument to %s"), VZCTL);
|
|
|
|
return -1;
|
2009-09-22 10:19:09 +00:00
|
|
|
|
2008-07-16 14:45:55 +00:00
|
|
|
#undef ADD_ARG
|
|
|
|
#undef ADD_ARG_LIT
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
static int openvzSetInitialConfig(virDomainDefPtr vmdef)
|
2009-03-24 10:59:13 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int vpsid;
|
|
|
|
char * confdir = NULL;
|
|
|
|
const char *prog[OPENVZ_MAX_ARG];
|
|
|
|
prog[0] = NULL;
|
|
|
|
|
|
|
|
if (vmdef->nfss > 1) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("only one filesystem supported"));
|
2009-03-24 10:59:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vmdef->nfss == 1 &&
|
|
|
|
vmdef->fss[0]->type != VIR_DOMAIN_FS_TYPE_TEMPLATE &&
|
|
|
|
vmdef->fss[0]->type != VIR_DOMAIN_FS_TYPE_MOUNT)
|
|
|
|
{
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("filesystem is not of type 'template' or 'mount'"));
|
2009-03-24 10:59:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (vmdef->nfss == 1 &&
|
|
|
|
vmdef->fss[0]->type == VIR_DOMAIN_FS_TYPE_MOUNT)
|
|
|
|
{
|
|
|
|
|
2010-08-31 22:43:18 +00:00
|
|
|
if (virStrToLong_i(vmdef->name, NULL, 10, &vpsid) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not convert domain name to VEID"));
|
2009-03-24 10:59:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (openvzCopyDefaultConfig(vpsid) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not copy default config"));
|
2009-03-24 10:59:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (openvzWriteVPSConfigParam(vpsid, "VE_PRIVATE", vmdef->fss[0]->src) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set the source dir for the filesystem"));
|
2009-03-24 10:59:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-03 14:23:45 +00:00
|
|
|
if (openvzDomainDefineCmd(prog, OPENVZ_MAX_ARG, vmdef) < 0) {
|
2010-11-29 09:23:15 +00:00
|
|
|
VIR_ERROR0(_("Error creating command for container"));
|
2009-03-24 10:59:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(prog, NULL) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not exec %s"), VZCTL);
|
2009-03-24 10:59:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(confdir);
|
|
|
|
cmdExecFree(prog);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
static virDomainPtr openvzDomainLookupByID(virConnectPtr conn,
|
2008-09-05 14:10:58 +00:00
|
|
|
int id) {
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2008-09-05 14:10:58 +00:00
|
|
|
virDomainObjPtr vm;
|
2008-12-04 21:41:51 +00:00
|
|
|
virDomainPtr dom = NULL;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-10-10 14:20:37 +00:00
|
|
|
vm = virDomainFindByID(&driver->domains, id);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, NULL);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
2008-12-04 21:41:51 +00:00
|
|
|
if (dom)
|
|
|
|
dom->id = vm->def->id;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2007-07-17 13:27:26 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
2008-10-24 11:32:48 +00:00
|
|
|
static int openvzGetVersion(virConnectPtr conn, unsigned long *version) {
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-10-24 11:32:48 +00:00
|
|
|
*version = driver->version;
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
2008-10-24 11:32:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
static char *openvzGetOSType(virDomainPtr dom)
|
2007-07-17 13:27:26 +00:00
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
char *ret = NULL;
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if (!vm) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, NULL);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-09-05 14:10:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(ret = strdup(vm->def->os.type)))
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-09-05 14:10:58 +00:00
|
|
|
return ret;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virDomainPtr openvzDomainLookupByUUID(virConnectPtr conn,
|
2008-09-05 14:10:58 +00:00
|
|
|
const unsigned char *uuid) {
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainPtr dom = NULL;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, NULL);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
2008-12-04 21:41:51 +00:00
|
|
|
if (dom)
|
|
|
|
dom->id = vm->def->id;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2007-07-17 13:27:26 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr openvzDomainLookupByName(virConnectPtr conn,
|
2008-12-04 21:41:51 +00:00
|
|
|
const char *name) {
|
|
|
|
struct openvz_driver *driver = conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainPtr dom = NULL;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
vm = virDomainFindByName(&driver->domains, name);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, NULL);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
2008-12-04 21:41:51 +00:00
|
|
|
if (dom)
|
|
|
|
dom->id = vm->def->id;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2007-07-17 13:27:26 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int openvzDomainGetInfo(virDomainPtr dom,
|
2008-09-05 14:10:58 +00:00
|
|
|
virDomainInfoPtr info) {
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2010-12-23 22:21:27 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, "%s",
|
2010-04-03 14:23:45 +00:00
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
info->state = vm->state;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
Rename internal APis
Rename virDomainIsActive to virDomainObjIsActive, and
virInterfaceIsActive to virInterfaceObjIsActive and finally
virNetworkIsActive to virNetworkObjIsActive.
* src/conf/domain_conf.c, src/conf/domain_conf.h,
src/conf/interface_conf.h, src/conf/network_conf.c,
src/conf/network_conf.h, src/lxc/lxc_driver.c,
src/network/bridge_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_driver.c, src/qemu/qemu_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c: Update for
renamed APIs.
2009-10-20 14:51:03 +00:00
|
|
|
if (!virDomainObjIsActive(vm)) {
|
2008-07-21 08:08:25 +00:00
|
|
|
info->cpuTime = 0;
|
|
|
|
} else {
|
|
|
|
if (openvzGetProcessInfo(&(info->cpuTime), dom->id) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_OPERATION_FAILED,
|
2008-09-05 14:10:58 +00:00
|
|
|
_("cannot read cputime for domain %d"), dom->id);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-07-21 08:08:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 14:43:39 +00:00
|
|
|
info->maxMem = vm->def->mem.max_balloon;
|
|
|
|
info->memory = vm->def->mem.cur_balloon;
|
2008-09-05 14:10:58 +00:00
|
|
|
info->nrVirtCpu = vm->def->vcpus;
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
static int openvzDomainIsActive(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
|
|
|
obj = virDomainFindByUUID(&driver->domains, dom->uuid);
|
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
if (!obj) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, NULL);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = virDomainObjIsActive(obj);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (obj)
|
|
|
|
virDomainObjUnlock(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int openvzDomainIsPersistent(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
|
|
|
obj = virDomainFindByUUID(&driver->domains, dom->uuid);
|
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
if (!obj) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, NULL);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = obj->persistent;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (obj)
|
|
|
|
virDomainObjUnlock(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-24 07:43:15 +00:00
|
|
|
static int openvzDomainIsUpdated(virDomainPtr dom ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
static char *openvzDomainDumpXML(virDomainPtr dom, int flags) {
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
char *ret = NULL;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2010-12-23 22:21:27 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, "%s",
|
2010-04-03 14:23:45 +00:00
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2010-02-09 18:58:01 +00:00
|
|
|
ret = virDomainDefFormat(vm->def, flags);
|
2008-12-04 21:41:51 +00:00
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2008-09-05 14:10:58 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
/*
|
|
|
|
* Convenient helper to target a command line argv
|
|
|
|
* and fill in an empty slot with the supplied
|
|
|
|
* key value. This lets us declare the argv on the
|
|
|
|
* stack and just splice in the domain name after
|
|
|
|
*/
|
|
|
|
#define PROGRAM_SENTINAL ((char *)0x1)
|
|
|
|
static void openvzSetProgramSentinal(const char **prog, const char *key)
|
|
|
|
{
|
|
|
|
const char **tmp = prog;
|
|
|
|
while (tmp && *tmp) {
|
|
|
|
if (*tmp == PROGRAM_SENTINAL) {
|
|
|
|
*tmp = key;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tmp++;
|
|
|
|
}
|
|
|
|
}
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2010-08-04 12:00:07 +00:00
|
|
|
static int openvzDomainSuspend(virDomainPtr dom) {
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
const char *prog[] = {VZCTL, "--quiet", "chkpnt", PROGRAM_SENTINAL, "--suspend", NULL};
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2010-12-23 22:21:27 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, "%s",
|
2010-08-04 12:00:07 +00:00
|
|
|
_("no domain with matching uuid"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virDomainObjIsActive(vm)) {
|
|
|
|
openvzError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Domain is not running"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vm->state != VIR_DOMAIN_PAUSED) {
|
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
|
|
|
if (virRun(prog, NULL) < 0) {
|
|
|
|
openvzError(VIR_ERR_OPERATION_FAILED, "%s",
|
|
|
|
_("Suspend operation failed"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
vm->state = VIR_DOMAIN_PAUSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int openvzDomainResume(virDomainPtr dom) {
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
const char *prog[] = {VZCTL, "--quiet", "chkpnt", PROGRAM_SENTINAL, "--resume", NULL};
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
openvzDriverLock(driver);
|
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2010-12-23 22:21:27 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, "%s",
|
2010-08-04 12:00:07 +00:00
|
|
|
_("no domain with matching uuid"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virDomainObjIsActive(vm)) {
|
|
|
|
openvzError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Domain is not running"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vm->state == VIR_DOMAIN_PAUSED) {
|
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
|
|
|
if (virRun(prog, NULL) < 0) {
|
|
|
|
openvzError(VIR_ERR_OPERATION_FAILED, "%s",
|
|
|
|
_("Resume operation failed"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
vm->state = VIR_DOMAIN_RUNNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
static int openvzDomainShutdown(virDomainPtr dom) {
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
const char *prog[] = {VZCTL, "--quiet", "stop", PROGRAM_SENTINAL, NULL};
|
|
|
|
int ret = -1;
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if (!vm) {
|
2010-12-23 22:21:27 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, "%s",
|
2010-04-03 14:23:45 +00:00
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2008-09-05 14:10:58 +00:00
|
|
|
if (vm->state != VIR_DOMAIN_RUNNING) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("domain is not in running state"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(prog, NULL) < 0)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
vm->def->id = -1;
|
|
|
|
vm->state = VIR_DOMAIN_SHUTOFF;
|
2010-07-30 17:50:12 +00:00
|
|
|
dom->id = -1;
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2007-09-03 16:30:00 +00:00
|
|
|
static int openvzDomainReboot(virDomainPtr dom,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED) {
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
const char *prog[] = {VZCTL, "--quiet", "restart", PROGRAM_SENTINAL, NULL};
|
|
|
|
int ret = -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2010-12-23 22:21:27 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, "%s",
|
2010-04-03 14:23:45 +00:00
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2008-09-05 14:10:58 +00:00
|
|
|
if (vm->state != VIR_DOMAIN_RUNNING) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("domain is not in running state"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(prog, NULL) < 0)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
ret = 0;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(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)
|
|
|
|
{
|
|
|
|
char dev_name[32];
|
|
|
|
int ifNo = 0;
|
|
|
|
|
|
|
|
if (sscanf(dev_name_ve, "%*[^0-9]%d", &ifNo) != 1)
|
|
|
|
return NULL;
|
|
|
|
if (snprintf(dev_name, sizeof(dev_name), "veth%d.%d", veid, ifNo) < 7)
|
|
|
|
return NULL;
|
|
|
|
return strdup(dev_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
openvzGenerateContainerVethName(int veid)
|
|
|
|
{
|
|
|
|
char temp[1024];
|
|
|
|
|
|
|
|
/* try to get line "^NETIF=..." from config */
|
2009-09-04 17:11:31 +00:00
|
|
|
if (openvzReadVPSConfigParam(veid, "NETIF", temp, sizeof(temp)) <= 0) {
|
2008-11-12 16:35:47 +00:00
|
|
|
snprintf(temp, sizeof(temp), "eth0");
|
|
|
|
} else {
|
2009-01-22 19:41:48 +00:00
|
|
|
char *saveptr;
|
2008-11-12 16:35:47 +00:00
|
|
|
char *s;
|
|
|
|
int max = 0;
|
|
|
|
|
|
|
|
/* get maximum interface number (actually, it is the last one) */
|
2009-01-22 19:41:48 +00:00
|
|
|
for (s=strtok_r(temp, ";", &saveptr); s; s=strtok_r(NULL, ";", &saveptr)) {
|
2008-11-12 16:35:47 +00:00
|
|
|
int x;
|
|
|
|
|
|
|
|
if (sscanf(s, "ifname=eth%d", &x) != 1) return NULL;
|
|
|
|
if (x > max) max = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set new name */
|
|
|
|
snprintf(temp, sizeof(temp), "eth%d", max+1);
|
|
|
|
}
|
|
|
|
return strdup(temp);
|
|
|
|
}
|
|
|
|
|
2008-07-28 14:06:54 +00:00
|
|
|
static int
|
|
|
|
openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
|
2008-11-12 16:35:47 +00:00
|
|
|
virDomainNetDefPtr net,
|
|
|
|
virBufferPtr configBuf)
|
2008-07-28 14:06:54 +00:00
|
|
|
{
|
|
|
|
int rc = 0, narg;
|
2008-08-08 15:43:38 +00:00
|
|
|
const char *prog[OPENVZ_MAX_ARG];
|
2008-11-12 16:35:47 +00:00
|
|
|
char macaddr[VIR_MAC_STRING_BUFLEN];
|
2009-01-07 10:55:54 +00:00
|
|
|
unsigned char host_mac[VIR_MAC_BUFLEN];
|
|
|
|
char host_macaddr[VIR_MAC_STRING_BUFLEN];
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2008-11-12 16:35:47 +00:00
|
|
|
char *opt = NULL;
|
2008-07-28 14:06:54 +00:00
|
|
|
|
|
|
|
#define ADD_ARG_LIT(thisarg) \
|
|
|
|
do { \
|
|
|
|
if (narg >= OPENVZ_MAX_ARG) \
|
|
|
|
goto no_memory; \
|
|
|
|
if ((prog[narg++] = strdup(thisarg)) == NULL) \
|
|
|
|
goto no_memory; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
|
|
if (net == NULL)
|
|
|
|
return 0;
|
|
|
|
if (vpsid == NULL) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Container ID is not specified"));
|
2008-07-28 14:06:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (narg = 0; narg < OPENVZ_MAX_ARG; narg++)
|
|
|
|
prog[narg] = NULL;
|
|
|
|
|
|
|
|
narg = 0;
|
|
|
|
|
|
|
|
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
|
|
|
net->type == VIR_DOMAIN_NET_TYPE_ETHERNET) {
|
|
|
|
ADD_ARG_LIT(VZCTL);
|
|
|
|
ADD_ARG_LIT("--quiet");
|
|
|
|
ADD_ARG_LIT("set");
|
|
|
|
ADD_ARG_LIT(vpsid);
|
|
|
|
}
|
|
|
|
|
2008-11-12 16:35:47 +00:00
|
|
|
virFormatMacAddr(net->mac, macaddr);
|
2009-01-07 10:55:54 +00:00
|
|
|
virCapabilitiesGenerateMac(driver->caps, host_mac);
|
|
|
|
virFormatMacAddr(host_mac, host_macaddr);
|
2008-11-12 16:35:47 +00:00
|
|
|
|
2010-08-18 15:05:02 +00:00
|
|
|
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
|
|
|
(net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
|
|
|
|
net->data.ethernet.ipaddr == NULL)) {
|
2008-11-12 16:35:47 +00:00
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
2010-02-19 15:49:56 +00:00
|
|
|
int veid = openvzGetVEID(vpsid);
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2011-01-28 21:38:06 +00:00
|
|
|
/* --netif_add ifname[,mac,host_ifname,host_mac] */
|
2008-07-28 14:06:54 +00:00
|
|
|
ADD_ARG_LIT("--netif_add") ;
|
2008-11-12 16:35:47 +00:00
|
|
|
|
2010-08-18 15:05:02 +00:00
|
|
|
/* if user doesn't specify guest interface name,
|
|
|
|
* then we need to generate it */
|
|
|
|
if (net->data.ethernet.dev == NULL) {
|
|
|
|
net->data.ethernet.dev = openvzGenerateContainerVethName(veid);
|
|
|
|
if (net->data.ethernet.dev == NULL) {
|
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not generate eth name for container"));
|
|
|
|
rc = -1;
|
|
|
|
goto exit;
|
|
|
|
}
|
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) {
|
2010-08-18 15:05:02 +00:00
|
|
|
net->ifname = openvzGenerateVethName(veid, net->data.ethernet.dev);
|
2008-11-12 16:35:47 +00:00
|
|
|
if (net->ifname == NULL) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not generate veth name"));
|
2008-11-12 16:35:47 +00:00
|
|
|
rc = -1;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-18 15:05:02 +00:00
|
|
|
virBufferAdd(&buf, net->data.ethernet.dev, -1); /* Guest dev */
|
2008-11-12 16:35:47 +00:00
|
|
|
virBufferVSprintf(&buf, ",%s", macaddr); /* Guest dev mac */
|
|
|
|
virBufferVSprintf(&buf, ",%s", net->ifname); /* Host dev */
|
2009-01-07 10:55:54 +00:00
|
|
|
virBufferVSprintf(&buf, ",%s", host_macaddr); /* Host dev mac */
|
2008-11-12 16:35:47 +00:00
|
|
|
|
2010-08-18 15:05:02 +00:00
|
|
|
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
|
|
|
if (driver->version >= VZCTL_BRIDGE_MIN_VERSION) {
|
|
|
|
virBufferVSprintf(&buf, ",%s", net->data.bridge.brname); /* Host bridge */
|
|
|
|
} else {
|
|
|
|
virBufferVSprintf(configBuf, "ifname=%s", net->data.ethernet.dev);
|
|
|
|
virBufferVSprintf(configBuf, ",mac=%s", macaddr); /* Guest dev mac */
|
|
|
|
virBufferVSprintf(configBuf, ",host_ifname=%s", net->ifname); /* Host dev */
|
|
|
|
virBufferVSprintf(configBuf, ",host_mac=%s", host_macaddr); /* Host dev mac */
|
|
|
|
virBufferVSprintf(configBuf, ",bridge=%s", net->data.bridge.brname); /* Host bridge */
|
|
|
|
}
|
2008-07-28 14:06:54 +00:00
|
|
|
}
|
2008-11-12 16:35:47 +00:00
|
|
|
|
|
|
|
if (!(opt = virBufferContentAndReset(&buf)))
|
|
|
|
goto no_memory;
|
|
|
|
|
2008-07-28 14:06:54 +00:00
|
|
|
ADD_ARG_LIT(opt) ;
|
2008-11-12 16:35:47 +00:00
|
|
|
VIR_FREE(opt);
|
|
|
|
} else if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
|
2008-07-28 14:06:54 +00:00
|
|
|
net->data.ethernet.ipaddr != NULL) {
|
2011-01-28 21:38:06 +00:00
|
|
|
/* --ipadd ip */
|
2008-07-28 14:06:54 +00:00
|
|
|
ADD_ARG_LIT("--ipadd") ;
|
|
|
|
ADD_ARG_LIT(net->data.ethernet.ipaddr) ;
|
|
|
|
}
|
|
|
|
|
2011-01-28 21:38:06 +00:00
|
|
|
/* TODO: processing NAT and physical device */
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2010-08-31 22:43:18 +00:00
|
|
|
if (prog[0] != NULL) {
|
2008-07-28 14:06:54 +00:00
|
|
|
ADD_ARG_LIT("--save");
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(prog, NULL) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not exec %s"), VZCTL);
|
2008-07-28 14:06:54 +00:00
|
|
|
rc = -1;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
cmdExecFree(prog);
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
no_memory:
|
2008-11-12 16:35:47 +00:00
|
|
|
VIR_FREE(opt);
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
2008-07-28 14:06:54 +00:00
|
|
|
_("Could not put argument to %s"), VZCTL);
|
|
|
|
cmdExecFree(prog);
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
#undef ADD_ARG_LIT
|
|
|
|
}
|
|
|
|
|
2008-11-12 16:35:47 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainSetNetworkConfig(virConnectPtr conn,
|
|
|
|
virDomainDefPtr def)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
char *param;
|
|
|
|
int first = 1;
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2008-11-12 16:35:47 +00:00
|
|
|
|
|
|
|
for (i = 0 ; i < def->nnets ; i++) {
|
|
|
|
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) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not configure network"));
|
2008-11-12 16:35:47 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (driver->version < VZCTL_BRIDGE_MIN_VERSION && def->nnets) {
|
|
|
|
param = virBufferContentAndReset(&buf);
|
|
|
|
if (param) {
|
2009-03-24 10:59:13 +00:00
|
|
|
if (openvzWriteVPSConfigParam(strtoI(def->name), "NETIF", param) < 0) {
|
2008-11-12 16:35:47 +00:00
|
|
|
VIR_FREE(param);
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("cannot replace NETIF config"));
|
2008-11-12 16:35:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
VIR_FREE(param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
exit:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buf);
|
2008-11-12 16:35:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
static virDomainPtr
|
|
|
|
openvzDomainDefineXML(virConnectPtr conn, const char *xml)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2008-09-05 14:10:58 +00:00
|
|
|
virDomainDefPtr vmdef = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
2008-07-16 14:45:55 +00:00
|
|
|
virDomainPtr dom = NULL;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2010-02-09 18:58:01 +00:00
|
|
|
if ((vmdef = virDomainDefParseString(driver->caps, xml,
|
2009-01-08 13:54:20 +00:00
|
|
|
VIR_DOMAIN_XML_INACTIVE)) == NULL)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2009-11-08 21:08:54 +00:00
|
|
|
if (vmdef->os.init == NULL) {
|
|
|
|
if (!(vmdef->os.init = strdup("/sbin/init"))) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-11-08 21:08:54 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-09-05 14:10:58 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 14:20:37 +00:00
|
|
|
vm = virDomainFindByName(&driver->domains, vmdef->name);
|
2007-09-03 15:37:07 +00:00
|
|
|
if (vm) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Already an OPENVZ VM active with the id '%s'"),
|
|
|
|
vmdef->name);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
2010-02-09 18:58:01 +00:00
|
|
|
if (!(vm = virDomainAssignDef(driver->caps,
|
2010-03-24 14:31:21 +00:00
|
|
|
&driver->domains, vmdef, false)))
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
vmdef = NULL;
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
vm->persistent = 1;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
if (openvzSetInitialConfig(vm->def) < 0) {
|
2010-11-29 09:23:15 +00:00
|
|
|
VIR_ERROR0(_("Error creating initial configuration"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
|
|
|
|
2011-01-28 21:38:06 +00:00
|
|
|
/* TODO: set quota */
|
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) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set UUID"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-08-05 10:53:05 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
if (openvzDomainSetNetworkConfig(conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2010-09-29 16:20:07 +00:00
|
|
|
if (vm->def->vcpus != vm->def->maxvcpus) {
|
|
|
|
openvzError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("current vcpu count must equal maximum"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (vm->def->maxvcpus > 0) {
|
|
|
|
if (openvzDomainSetVcpusInternal(vm, vm->def->maxvcpus) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set number of virtual cpu"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-08-20 13:44:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 14:43:39 +00:00
|
|
|
if (vm->def->mem.cur_balloon > 0) {
|
|
|
|
if (openvzDomainSetMemoryInternal(vm, vm->def->mem.cur_balloon) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set memory size"));
|
2009-11-02 16:39:46 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
|
|
|
if (dom)
|
|
|
|
dom->id = -1;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainDefFree(vmdef);
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
|
|
|
openvzDriverUnlock(driver);
|
2007-09-03 15:37:07 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr
|
2008-10-10 09:32:27 +00:00
|
|
|
openvzDomainCreateXML(virConnectPtr conn, const char *xml,
|
2010-05-25 17:13:13 +00:00
|
|
|
unsigned int flags)
|
2007-09-03 15:37:07 +00:00
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
2008-09-05 14:10:58 +00:00
|
|
|
virDomainDefPtr vmdef = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
2008-07-16 14:45:55 +00:00
|
|
|
virDomainPtr dom = NULL;
|
2008-12-04 21:41:51 +00:00
|
|
|
const char *progstart[] = {VZCTL, "--quiet", "start", PROGRAM_SENTINAL, NULL};
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2010-05-25 17:13:13 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2010-02-09 18:58:01 +00:00
|
|
|
if ((vmdef = virDomainDefParseString(driver->caps, xml,
|
2009-01-08 13:54:20 +00:00
|
|
|
VIR_DOMAIN_XML_INACTIVE)) == NULL)
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2009-11-08 21:08:54 +00:00
|
|
|
if (vmdef->os.init == NULL) {
|
|
|
|
if (!(vmdef->os.init = strdup("/sbin/init"))) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-11-08 21:08:54 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2008-10-10 14:20:37 +00:00
|
|
|
vm = virDomainFindByName(&driver->domains, vmdef->name);
|
2007-09-03 15:37:07 +00:00
|
|
|
if (vm) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Already an OPENVZ VM defined with the id '%s'"),
|
|
|
|
vmdef->name);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
2010-02-09 18:58:01 +00:00
|
|
|
if (!(vm = virDomainAssignDef(driver->caps,
|
2010-03-24 14:31:21 +00:00
|
|
|
&driver->domains, vmdef, false)))
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
vmdef = NULL;
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
/* All OpenVZ domains seem to be persistent - this is a bit of a violation
|
|
|
|
* of this libvirt API which is intended for transient domain creation */
|
|
|
|
vm->persistent = 1;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
if (openvzSetInitialConfig(vm->def) < 0) {
|
2010-11-29 09:23:15 +00:00
|
|
|
VIR_ERROR0(_("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
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
if (openvzSetDefinedUUID(strtoI(vm->def->name), vm->def->uuid) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set UUID"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-08-05 10:53:05 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
if (openvzDomainSetNetworkConfig(conn, vm->def) < 0)
|
|
|
|
goto cleanup;
|
2008-07-28 14:06:54 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
openvzSetProgramSentinal(progstart, vm->def->name);
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(progstart, NULL) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not exec %s"), VZCTL);
|
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
|
|
|
|
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;
|
|
|
|
vm->state = VIR_DOMAIN_RUNNING;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2010-09-29 16:20:07 +00:00
|
|
|
if (vm->def->maxvcpus > 0) {
|
|
|
|
if (openvzDomainSetVcpusInternal(vm, vm->def->maxvcpus) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not set number of virtual cpu"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-08-20 13:44:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
|
|
|
if (dom)
|
|
|
|
dom->id = vm->def->id;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainDefFree(vmdef);
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
|
|
|
openvzDriverUnlock(driver);
|
2007-09-03 15:37:07 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-06-10 15:55:36 +00:00
|
|
|
openvzDomainCreateWithFlags(virDomainPtr dom, unsigned int flags)
|
2007-09-03 15:37:07 +00:00
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
const char *prog[] = {VZCTL, "--quiet", "start", PROGRAM_SENTINAL, NULL };
|
|
|
|
int ret = -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2010-06-10 15:55:36 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
vm = virDomainFindByName(&driver->domains, dom->name);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!vm) {
|
2010-12-23 22:21:27 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, "%s",
|
2010-04-03 14:23:45 +00:00
|
|
|
_("no domain with matching id"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if (vm->state != VIR_DOMAIN_SHUTOFF) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_OPERATION_DENIED, "%s",
|
|
|
|
_("domain is not in shutoff state"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(prog, NULL) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
2008-12-04 21:41:51 +00:00
|
|
|
_("Could not exec %s"), VZCTL);
|
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
vm->pid = strtoI(vm->def->name);
|
|
|
|
vm->def->id = vm->pid;
|
2010-07-30 08:36:06 +00:00
|
|
|
dom->id = vm->pid;
|
2008-09-05 14:10:58 +00:00
|
|
|
vm->state = VIR_DOMAIN_RUNNING;
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 15:55:36 +00:00
|
|
|
static int
|
|
|
|
openvzDomainCreate(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
return openvzDomainCreateWithFlags(dom, 0);
|
|
|
|
}
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
static int
|
|
|
|
openvzDomainUndefine(virDomainPtr dom)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
const char *prog[] = { VZCTL, "--quiet", "destroy", PROGRAM_SENTINAL, NULL };
|
|
|
|
int ret = -1;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
2007-09-03 15:37:07 +00:00
|
|
|
if (!vm) {
|
2010-12-23 22:21:27 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, "%s",
|
2010-04-03 14:23:45 +00:00
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
2007-07-17 13:27:26 +00:00
|
|
|
|
Rename internal APis
Rename virDomainIsActive to virDomainObjIsActive, and
virInterfaceIsActive to virInterfaceObjIsActive and finally
virNetworkIsActive to virNetworkObjIsActive.
* src/conf/domain_conf.c, src/conf/domain_conf.h,
src/conf/interface_conf.h, src/conf/network_conf.c,
src/conf/network_conf.h, src/lxc/lxc_driver.c,
src/network/bridge_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_driver.c, src/qemu/qemu_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c: Update for
renamed APIs.
2009-10-20 14:51:03 +00:00
|
|
|
if (virDomainObjIsActive(vm)) {
|
2011-01-15 15:57:33 +00:00
|
|
|
openvzError(VIR_ERR_OPERATION_INVALID, "%s",
|
2010-04-03 14:23:45 +00:00
|
|
|
_("cannot delete active domain"));
|
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
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(prog, NULL) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
2008-12-04 21:41:51 +00:00
|
|
|
_("Could not exec %s"), VZCTL);
|
|
|
|
goto cleanup;
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
virDomainRemoveInactive(&driver->domains, vm);
|
2008-12-04 21:44:55 +00:00
|
|
|
vm = NULL;
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
|
|
|
openvzDriverUnlock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-07-10 07:52:14 +00:00
|
|
|
static int
|
|
|
|
openvzDomainSetAutostart(virDomainPtr dom, int autostart)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINAL,
|
2008-07-10 12:21:09 +00:00
|
|
|
"--onboot", autostart ? "yes" : "no",
|
2008-07-10 07:52:14 +00:00
|
|
|
"--save", NULL };
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2008-07-10 07:52:14 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2008-07-10 07:52:14 +00:00
|
|
|
if (!vm) {
|
2010-12-23 22:21:27 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, "%s",
|
2010-04-03 14:23:45 +00:00
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-07-10 07:52:14 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(prog, NULL) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not exec %s"), VZCTL);
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-07-10 07:52:14 +00:00
|
|
|
}
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
2008-07-10 07:52:14 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2008-07-10 07:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzDomainGetAutostart(virDomainPtr dom, int *autostart)
|
|
|
|
{
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
2008-07-10 07:52:14 +00:00
|
|
|
char value[1024];
|
2008-12-04 21:41:51 +00:00
|
|
|
int ret = -1;
|
2008-07-10 07:52:14 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2008-07-10 07:52:14 +00:00
|
|
|
if (!vm) {
|
2010-12-23 22:21:27 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, "%s",
|
2010-04-03 14:23:45 +00:00
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-07-10 07:52:14 +00:00
|
|
|
}
|
|
|
|
|
2009-03-24 10:59:13 +00:00
|
|
|
if (openvzReadVPSConfigParam(strtoI(vm->def->name), "ONBOOT", value, sizeof(value)) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(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;
|
|
|
|
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
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2008-07-10 07:52:14 +00:00
|
|
|
}
|
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
static int openvzGetMaxVCPUs(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
const char *type)
|
2009-08-17 12:24:27 +00:00
|
|
|
{
|
|
|
|
if (type == NULL || STRCASEEQ(type, "openvz"))
|
|
|
|
return 1028; /* OpenVZ has no limitation */
|
2008-08-20 13:44:03 +00:00
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("unknown type '%s'"), type);
|
2008-08-20 13:44:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
static int
|
|
|
|
openvzDomainGetVcpusFlags(virDomainPtr dom ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
if (flags != (VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_MAXIMUM)) {
|
|
|
|
openvzError(VIR_ERR_INVALID_ARG, _("unsupported flags (0x%x)"), flags);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-08-20 13:44:03 +00:00
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
return openvzGetMaxVCPUs(NULL, "openvz");
|
2008-08-20 13:44:03 +00:00
|
|
|
}
|
|
|
|
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
static int openvzDomainGetMaxVcpus(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
return openvzDomainGetVcpusFlags(dom, (VIR_DOMAIN_VCPU_LIVE |
|
|
|
|
VIR_DOMAIN_VCPU_MAXIMUM));
|
|
|
|
}
|
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
static int openvzDomainSetVcpusInternal(virDomainObjPtr vm,
|
|
|
|
unsigned int nvcpus)
|
2008-12-17 21:13:19 +00:00
|
|
|
{
|
|
|
|
char str_vcpus[32];
|
2008-12-04 21:41:51 +00:00
|
|
|
const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINAL,
|
2008-08-20 13:44:03 +00:00
|
|
|
"--cpus", str_vcpus, "--save", NULL };
|
2008-11-24 19:34:21 +00:00
|
|
|
unsigned int pcpus;
|
2008-12-17 21:13:19 +00:00
|
|
|
pcpus = openvzGetNodeCPUs();
|
|
|
|
if (pcpus > 0 && pcpus < nvcpus)
|
|
|
|
nvcpus = pcpus;
|
|
|
|
|
|
|
|
snprintf(str_vcpus, 31, "%d", nvcpus);
|
|
|
|
str_vcpus[31] = '\0';
|
|
|
|
|
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(prog, NULL) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not exec %s"), VZCTL);
|
2008-12-17 21:13:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-09-29 16:20:07 +00:00
|
|
|
vm->def->maxvcpus = vm->def->vcpus = nvcpus;
|
2008-12-17 21:13:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
static int openvzDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|
|
|
unsigned int flags)
|
2008-12-17 21:13:19 +00:00
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
struct openvz_driver *driver = dom->conn->privateData;
|
|
|
|
int ret = -1;
|
2008-08-20 13:44:03 +00:00
|
|
|
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
if (flags != VIR_DOMAIN_VCPU_LIVE) {
|
|
|
|
openvzError(VIR_ERR_INVALID_ARG, _("unsupported flags (0x%x)"), flags);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
|
|
|
|
2008-08-20 13:44:03 +00:00
|
|
|
if (!vm) {
|
2010-12-23 22:21:27 +00:00
|
|
|
openvzError(VIR_ERR_NO_DOMAIN, "%s",
|
2010-04-03 14:23:45 +00:00
|
|
|
_("no domain with matching uuid"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-08-20 13:44:03 +00:00
|
|
|
}
|
|
|
|
|
2008-09-08 12:15:33 +00:00
|
|
|
if (nvcpus <= 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("VCPUs should be >= 1"));
|
2008-12-04 21:41:51 +00:00
|
|
|
goto cleanup;
|
2008-09-08 12:15:33 +00:00
|
|
|
}
|
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzDomainSetVcpusInternal(vm, nvcpus);
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:44:55 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2008-08-20 13:44:03 +00:00
|
|
|
}
|
|
|
|
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
static int
|
|
|
|
openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
|
|
|
|
{
|
|
|
|
return openvzDomainSetVcpusFlags(dom, nvcpus, VIR_DOMAIN_VCPU_LIVE);
|
|
|
|
}
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
static virDrvOpenStatus openvzOpen(virConnectPtr conn,
|
2008-11-17 11:44:51 +00:00
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
|
|
|
int flags ATTRIBUTE_UNUSED)
|
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
|
|
|
|
|
|
|
if (conn->uri == NULL) {
|
2009-06-12 12:06:15 +00:00
|
|
|
if (!virFileExists("/proc/vz"))
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
if (access("/proc/vz", W_OK) < 0)
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
2008-11-17 11:44:51 +00:00
|
|
|
conn->uri = xmlParseURI("openvz:///system");
|
|
|
|
if (conn->uri == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-06-12 12:06:15 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* If scheme isn't 'openvz', then its for another driver */
|
|
|
|
if (conn->uri->scheme == NULL ||
|
|
|
|
STRNEQ (conn->uri->scheme, "openvz"))
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
/* If server name is given, its for remote driver */
|
|
|
|
if (conn->uri->server != NULL)
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
/* If path isn't /system, then they typoed, so tell them correct path */
|
|
|
|
if (conn->uri->path == NULL ||
|
|
|
|
STRNEQ (conn->uri->path, "/system")) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
2009-06-12 12:06:15 +00:00
|
|
|
_("unexpected OpenVZ URI path '%s', try openvz:///system"),
|
|
|
|
conn->uri->path);
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virFileExists("/proc/vz")) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2009-06-12 12:06:15 +00:00
|
|
|
_("OpenVZ control file /proc/vz does not exist"));
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (access("/proc/vz", W_OK) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2009-06-12 12:06:15 +00:00
|
|
|
_("OpenVZ control file /proc/vz is not accessible"));
|
2008-11-17 11:44:51 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
2008-09-05 14:10:58 +00:00
|
|
|
}
|
|
|
|
|
2009-06-12 12:06:15 +00:00
|
|
|
/* We now know the URI is definitely for this driver, so beyond
|
|
|
|
* here, don't return DECLINED, always use ERROR */
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if (VIR_ALLOC(driver) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-09-05 14:10:58 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
Convert virDomainObjListPtr to use a hash of domain objects
The current virDomainObjListPtr object stores domain objects in
an array. This means that to find a particular objects requires
O(n) time, and more critically acquiring O(n) mutex locks.
The new impl replaces the array with a virHashTable, keyed off
UUID. Finding a object based on UUID is now O(1) time, and only
requires a single mutex lock. Finding by name/id is unchanged
in complexity.
In changing this, all code which iterates over the array had
to be updated to use a hash table iterator function callback.
Several of the functions which were identically duplicating
across all drivers were pulled into domain_conf.c
* src/conf/domain_conf.h, src/conf/domain_conf.c: Change
virDomainObjListPtr to use virHashTable. Add a initializer
method virDomainObjListInit, and rename virDomainObjListFree
to virDomainObjListDeinit, since its not actually freeing
the container, only its contents. Also add some convenient
methods virDomainObjListGetInactiveNames,
virDomainObjListGetActiveIDs and virDomainObjListNumOfDomains
which can be used to implement the correspondingly named
public API entry points in drivers
* src/libvirt_private.syms: Export new methods from domain_conf.h
* src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_conf.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/test/test_driver.c,
src/uml/uml_driver.c, src/vbox/vbox_tmpl.c: Update all code
to deal with hash tables instead of arrays for domains
2009-10-09 11:33:51 +00:00
|
|
|
if (virDomainObjListInit(&driver->domains) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if (!(driver->caps = openvzCapsInit()))
|
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if (openvzLoadDomains(driver) < 0)
|
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
if (openvzExtractVersion(driver) < 0)
|
2008-10-24 11:32:48 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
conn->privateData = driver;
|
2008-08-27 11:19:45 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
cleanup:
|
|
|
|
openvzFreeDriver(driver);
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
2007-12-26 05:41:05 +00:00
|
|
|
};
|
2007-07-17 13:27:26 +00:00
|
|
|
|
|
|
|
static int openvzClose(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *openvzGetType(virConnectPtr conn ATTRIBUTE_UNUSED) {
|
2009-08-03 10:42:39 +00:00
|
|
|
return "OpenVZ";
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
static int openvzIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) {
|
|
|
|
/* Encryption is not relevant / applicable to way we talk to openvz */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int openvzIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) {
|
|
|
|
/* We run CLI tools directly so this is secure */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
static char *openvzGetCapabilities(virConnectPtr conn) {
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
|
|
|
char *ret;
|
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
2008-12-04 21:41:51 +00:00
|
|
|
ret = virCapabilitiesFormatXML(driver->caps);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2008-12-04 21:41:51 +00:00
|
|
|
return ret;
|
2008-09-05 14:10:58 +00:00
|
|
|
}
|
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
static int openvzListDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
int *ids, int nids) {
|
2007-07-17 13:27:26 +00:00
|
|
|
int got = 0;
|
2008-12-18 11:58:28 +00:00
|
|
|
int veid;
|
|
|
|
pid_t pid;
|
2008-08-20 09:08:17 +00:00
|
|
|
int outfd = -1;
|
2007-07-19 16:22:40 +00:00
|
|
|
int ret;
|
|
|
|
char buf[32];
|
2008-07-21 13:34:19 +00:00
|
|
|
char *endptr;
|
2007-07-19 16:22:40 +00:00
|
|
|
const char *cmd[] = {VZLIST, "-ovpsid", "-H" , NULL};
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2010-02-04 22:41:52 +00:00
|
|
|
ret = virExec(cmd, NULL, NULL,
|
2010-12-01 16:43:46 +00:00
|
|
|
&pid, -1, &outfd, NULL, VIR_EXEC_NONE);
|
2010-08-31 22:43:18 +00:00
|
|
|
if (ret == -1) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not exec %s"), VZLIST);
|
2010-12-01 16:43:46 +00:00
|
|
|
VIR_FORCE_CLOSE(outfd);
|
2008-07-07 11:48:40 +00:00
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2010-08-31 22:43:18 +00:00
|
|
|
while (got < nids) {
|
2007-07-19 16:22:40 +00:00
|
|
|
ret = openvz_readline(outfd, buf, 32);
|
2010-08-31 22:43:18 +00:00
|
|
|
if (!ret)
|
|
|
|
break;
|
2008-07-21 13:34:19 +00:00
|
|
|
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not parse VPS ID %s"), buf);
|
2008-07-21 13:34:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-07-17 13:27:26 +00:00
|
|
|
ids[got] = veid;
|
|
|
|
got ++;
|
|
|
|
}
|
2007-07-19 16:22:40 +00:00
|
|
|
waitpid(pid, NULL, 0);
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2010-12-01 16:43:46 +00:00
|
|
|
if (VIR_CLOSE(outfd) < 0) {
|
|
|
|
virReportSystemError(errno, "%s", _("failed to close file"));
|
|
|
|
return -1;
|
|
|
|
}
|
2007-07-17 13:27:26 +00:00
|
|
|
return got;
|
|
|
|
}
|
|
|
|
|
2008-10-10 14:20:37 +00:00
|
|
|
static int openvzNumDomains(virConnectPtr conn) {
|
2008-09-05 14:10:58 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
Convert virDomainObjListPtr to use a hash of domain objects
The current virDomainObjListPtr object stores domain objects in
an array. This means that to find a particular objects requires
O(n) time, and more critically acquiring O(n) mutex locks.
The new impl replaces the array with a virHashTable, keyed off
UUID. Finding a object based on UUID is now O(1) time, and only
requires a single mutex lock. Finding by name/id is unchanged
in complexity.
In changing this, all code which iterates over the array had
to be updated to use a hash table iterator function callback.
Several of the functions which were identically duplicating
across all drivers were pulled into domain_conf.c
* src/conf/domain_conf.h, src/conf/domain_conf.c: Change
virDomainObjListPtr to use virHashTable. Add a initializer
method virDomainObjListInit, and rename virDomainObjListFree
to virDomainObjListDeinit, since its not actually freeing
the container, only its contents. Also add some convenient
methods virDomainObjListGetInactiveNames,
virDomainObjListGetActiveIDs and virDomainObjListNumOfDomains
which can be used to implement the correspondingly named
public API entry points in drivers
* src/libvirt_private.syms: Export new methods from domain_conf.h
* src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_conf.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/test/test_driver.c,
src/uml/uml_driver.c, src/vbox/vbox_tmpl.c: Update all code
to deal with hash tables instead of arrays for domains
2009-10-09 11:33:51 +00:00
|
|
|
int n;
|
2008-10-10 14:20:37 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
Convert virDomainObjListPtr to use a hash of domain objects
The current virDomainObjListPtr object stores domain objects in
an array. This means that to find a particular objects requires
O(n) time, and more critically acquiring O(n) mutex locks.
The new impl replaces the array with a virHashTable, keyed off
UUID. Finding a object based on UUID is now O(1) time, and only
requires a single mutex lock. Finding by name/id is unchanged
in complexity.
In changing this, all code which iterates over the array had
to be updated to use a hash table iterator function callback.
Several of the functions which were identically duplicating
across all drivers were pulled into domain_conf.c
* src/conf/domain_conf.h, src/conf/domain_conf.c: Change
virDomainObjListPtr to use virHashTable. Add a initializer
method virDomainObjListInit, and rename virDomainObjListFree
to virDomainObjListDeinit, since its not actually freeing
the container, only its contents. Also add some convenient
methods virDomainObjListGetInactiveNames,
virDomainObjListGetActiveIDs and virDomainObjListNumOfDomains
which can be used to implement the correspondingly named
public API entry points in drivers
* src/libvirt_private.syms: Export new methods from domain_conf.h
* src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_conf.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/test/test_driver.c,
src/uml/uml_driver.c, src/vbox/vbox_tmpl.c: Update all code
to deal with hash tables instead of arrays for domains
2009-10-09 11:33:51 +00:00
|
|
|
n = virDomainObjListNumOfDomains(&driver->domains, 1);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
2008-10-10 14:20:37 +00:00
|
|
|
|
Convert virDomainObjListPtr to use a hash of domain objects
The current virDomainObjListPtr object stores domain objects in
an array. This means that to find a particular objects requires
O(n) time, and more critically acquiring O(n) mutex locks.
The new impl replaces the array with a virHashTable, keyed off
UUID. Finding a object based on UUID is now O(1) time, and only
requires a single mutex lock. Finding by name/id is unchanged
in complexity.
In changing this, all code which iterates over the array had
to be updated to use a hash table iterator function callback.
Several of the functions which were identically duplicating
across all drivers were pulled into domain_conf.c
* src/conf/domain_conf.h, src/conf/domain_conf.c: Change
virDomainObjListPtr to use virHashTable. Add a initializer
method virDomainObjListInit, and rename virDomainObjListFree
to virDomainObjListDeinit, since its not actually freeing
the container, only its contents. Also add some convenient
methods virDomainObjListGetInactiveNames,
virDomainObjListGetActiveIDs and virDomainObjListNumOfDomains
which can be used to implement the correspondingly named
public API entry points in drivers
* src/libvirt_private.syms: Export new methods from domain_conf.h
* src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_conf.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/test/test_driver.c,
src/uml/uml_driver.c, src/vbox/vbox_tmpl.c: Update all code
to deal with hash tables instead of arrays for domains
2009-10-09 11:33:51 +00:00
|
|
|
return n;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2010-04-03 14:23:45 +00:00
|
|
|
static int openvzListDefinedDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2008-09-05 14:10:58 +00:00
|
|
|
char **const names, int nnames) {
|
2007-07-17 13:27:26 +00:00
|
|
|
int got = 0;
|
2010-12-01 16:43:46 +00:00
|
|
|
int veid, outfd = -1, ret;
|
2008-12-18 11:58:28 +00:00
|
|
|
pid_t pid;
|
2008-09-05 14:10:58 +00:00
|
|
|
char vpsname[32];
|
2007-07-19 16:22:40 +00:00
|
|
|
char buf[32];
|
2008-07-21 13:34:19 +00:00
|
|
|
char *endptr;
|
2007-09-03 15:37:07 +00:00
|
|
|
const char *cmd[] = {VZLIST, "-ovpsid", "-H", "-S", NULL};
|
2007-07-17 13:27:26 +00:00
|
|
|
|
|
|
|
/* the -S options lists only stopped domains */
|
2010-02-04 22:41:52 +00:00
|
|
|
ret = virExec(cmd, NULL, NULL,
|
2010-12-01 16:43:46 +00:00
|
|
|
&pid, -1, &outfd, NULL, VIR_EXEC_NONE);
|
2010-08-31 22:43:18 +00:00
|
|
|
if (ret == -1) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not exec %s"), VZLIST);
|
2010-12-01 16:43:46 +00:00
|
|
|
goto out;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2010-08-31 22:43:18 +00:00
|
|
|
while (got < nnames) {
|
2007-07-19 16:22:40 +00:00
|
|
|
ret = openvz_readline(outfd, buf, 32);
|
2010-08-31 22:43:18 +00:00
|
|
|
if (!ret)
|
|
|
|
break;
|
2008-07-21 13:34:19 +00:00
|
|
|
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not parse VPS ID %s"), buf);
|
2008-07-21 13:34:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-09-05 14:10:58 +00:00
|
|
|
snprintf(vpsname, sizeof(vpsname), "%d", veid);
|
|
|
|
if (!(names[got] = strdup(vpsname)))
|
2010-12-01 16:43:46 +00:00
|
|
|
virReportOOMError();
|
|
|
|
goto out;
|
2007-07-17 13:27:26 +00:00
|
|
|
got ++;
|
|
|
|
}
|
2007-07-19 16:22:40 +00:00
|
|
|
waitpid(pid, NULL, 0);
|
2010-12-01 16:43:46 +00:00
|
|
|
if (VIR_CLOSE(outfd) < 0) {
|
|
|
|
virReportSystemError(errno, "%s", _("failed to close file"));
|
|
|
|
goto out;
|
|
|
|
}
|
2007-07-17 13:27:26 +00:00
|
|
|
return got;
|
2008-09-05 14:10:58 +00:00
|
|
|
|
2010-12-01 16:43:46 +00:00
|
|
|
out:
|
|
|
|
VIR_FORCE_CLOSE(outfd);
|
2008-09-05 14:10:58 +00:00
|
|
|
for ( ; got >= 0 ; got--)
|
|
|
|
VIR_FREE(names[got]);
|
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-07-21 08:08:25 +00:00
|
|
|
static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid) {
|
|
|
|
int fd;
|
|
|
|
char line[1024] ;
|
|
|
|
unsigned long long usertime, systime, nicetime;
|
2010-04-14 07:09:57 +00:00
|
|
|
int readvps = vpsid + 1; /* ensure readvps is initially different */
|
|
|
|
int ret;
|
2008-07-21 08:08:25 +00:00
|
|
|
|
|
|
|
/* read statistic from /proc/vz/vestat.
|
|
|
|
sample:
|
|
|
|
Version: 2.2
|
2010-04-14 07:09:57 +00:00
|
|
|
VEID user nice system uptime idle other..
|
|
|
|
33 78 0 1330 59454597 142650441835148 other..
|
|
|
|
55 178 0 5340 59424597 542650441835148 other..
|
2008-07-21 08:08:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
if ((fd = open("/proc/vz/vestat", O_RDONLY)) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/*search line with VEID=vpsid*/
|
2010-08-31 22:43:18 +00:00
|
|
|
while (1) {
|
2008-07-21 08:08:25 +00:00
|
|
|
ret = openvz_readline(fd, line, sizeof(line));
|
2010-04-14 07:09:57 +00:00
|
|
|
if (ret <= 0)
|
2008-07-21 08:08:25 +00:00
|
|
|
break;
|
|
|
|
|
2010-04-14 07:09:57 +00:00
|
|
|
if (sscanf (line, "%d %llu %llu %llu",
|
|
|
|
&readvps, &usertime, &nicetime, &systime) == 4
|
|
|
|
&& readvps == vpsid) { /*found vpsid*/
|
|
|
|
/* convert jiffies to nanoseconds */
|
|
|
|
*cpuTime = (1000ull * 1000ull * 1000ull
|
|
|
|
* (usertime + nicetime + systime)
|
|
|
|
/ (unsigned long long)sysconf(_SC_CLK_TCK));
|
|
|
|
break;
|
|
|
|
}
|
2008-07-21 08:08:25 +00:00
|
|
|
}
|
|
|
|
|
2010-11-09 20:48:48 +00:00
|
|
|
VIR_FORCE_CLOSE(fd);
|
2008-07-21 08:08:25 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (readvps != vpsid) /*not found*/
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
static int openvzNumDefinedDomains(virConnectPtr conn) {
|
2008-12-04 21:41:51 +00:00
|
|
|
struct openvz_driver *driver = conn->privateData;
|
Convert virDomainObjListPtr to use a hash of domain objects
The current virDomainObjListPtr object stores domain objects in
an array. This means that to find a particular objects requires
O(n) time, and more critically acquiring O(n) mutex locks.
The new impl replaces the array with a virHashTable, keyed off
UUID. Finding a object based on UUID is now O(1) time, and only
requires a single mutex lock. Finding by name/id is unchanged
in complexity.
In changing this, all code which iterates over the array had
to be updated to use a hash table iterator function callback.
Several of the functions which were identically duplicating
across all drivers were pulled into domain_conf.c
* src/conf/domain_conf.h, src/conf/domain_conf.c: Change
virDomainObjListPtr to use virHashTable. Add a initializer
method virDomainObjListInit, and rename virDomainObjListFree
to virDomainObjListDeinit, since its not actually freeing
the container, only its contents. Also add some convenient
methods virDomainObjListGetInactiveNames,
virDomainObjListGetActiveIDs and virDomainObjListNumOfDomains
which can be used to implement the correspondingly named
public API entry points in drivers
* src/libvirt_private.syms: Export new methods from domain_conf.h
* src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_conf.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/test/test_driver.c,
src/uml/uml_driver.c, src/vbox/vbox_tmpl.c: Update all code
to deal with hash tables instead of arrays for domains
2009-10-09 11:33:51 +00:00
|
|
|
int n;
|
2008-10-10 14:20:37 +00:00
|
|
|
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverLock(driver);
|
Convert virDomainObjListPtr to use a hash of domain objects
The current virDomainObjListPtr object stores domain objects in
an array. This means that to find a particular objects requires
O(n) time, and more critically acquiring O(n) mutex locks.
The new impl replaces the array with a virHashTable, keyed off
UUID. Finding a object based on UUID is now O(1) time, and only
requires a single mutex lock. Finding by name/id is unchanged
in complexity.
In changing this, all code which iterates over the array had
to be updated to use a hash table iterator function callback.
Several of the functions which were identically duplicating
across all drivers were pulled into domain_conf.c
* src/conf/domain_conf.h, src/conf/domain_conf.c: Change
virDomainObjListPtr to use virHashTable. Add a initializer
method virDomainObjListInit, and rename virDomainObjListFree
to virDomainObjListDeinit, since its not actually freeing
the container, only its contents. Also add some convenient
methods virDomainObjListGetInactiveNames,
virDomainObjListGetActiveIDs and virDomainObjListNumOfDomains
which can be used to implement the correspondingly named
public API entry points in drivers
* src/libvirt_private.syms: Export new methods from domain_conf.h
* src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_conf.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/test/test_driver.c,
src/uml/uml_driver.c, src/vbox/vbox_tmpl.c: Update all code
to deal with hash tables instead of arrays for domains
2009-10-09 11:33:51 +00:00
|
|
|
n = virDomainObjListNumOfDomains(&driver->domains, 0);
|
2008-12-04 21:44:55 +00:00
|
|
|
openvzDriverUnlock(driver);
|
2008-10-10 14:20:37 +00:00
|
|
|
|
Convert virDomainObjListPtr to use a hash of domain objects
The current virDomainObjListPtr object stores domain objects in
an array. This means that to find a particular objects requires
O(n) time, and more critically acquiring O(n) mutex locks.
The new impl replaces the array with a virHashTable, keyed off
UUID. Finding a object based on UUID is now O(1) time, and only
requires a single mutex lock. Finding by name/id is unchanged
in complexity.
In changing this, all code which iterates over the array had
to be updated to use a hash table iterator function callback.
Several of the functions which were identically duplicating
across all drivers were pulled into domain_conf.c
* src/conf/domain_conf.h, src/conf/domain_conf.c: Change
virDomainObjListPtr to use virHashTable. Add a initializer
method virDomainObjListInit, and rename virDomainObjListFree
to virDomainObjListDeinit, since its not actually freeing
the container, only its contents. Also add some convenient
methods virDomainObjListGetInactiveNames,
virDomainObjListGetActiveIDs and virDomainObjListNumOfDomains
which can be used to implement the correspondingly named
public API entry points in drivers
* src/libvirt_private.syms: Export new methods from domain_conf.h
* src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_conf.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/test/test_driver.c,
src/uml/uml_driver.c, src/vbox/vbox_tmpl.c: Update all code
to deal with hash tables instead of arrays for domains
2009-10-09 11:33:51 +00:00
|
|
|
return n;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 16:39:46 +00:00
|
|
|
static int
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzDomainSetMemoryInternal(virDomainObjPtr vm,
|
2009-11-02 16:39:46 +00:00
|
|
|
unsigned long mem)
|
|
|
|
{
|
|
|
|
char str_mem[16];
|
|
|
|
const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINAL,
|
|
|
|
"--kmemsize", str_mem, "--save", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* memory has to be changed its format from kbyte to byte */
|
|
|
|
snprintf(str_mem, sizeof(str_mem), "%lu", mem * 1024);
|
|
|
|
|
|
|
|
openvzSetProgramSentinal(prog, vm->def->name);
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(prog, NULL) < 0) {
|
2010-04-03 14:23:45 +00:00
|
|
|
openvzError(VIR_ERR_INTERNAL_ERROR,
|
2009-11-02 16:39:46 +00:00
|
|
|
_("Could not exec %s"), VZCTL);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
static virDriver openvzDriver = {
|
|
|
|
VIR_DRV_OPENVZ,
|
|
|
|
"OPENVZ",
|
|
|
|
openvzOpen, /* open */
|
|
|
|
openvzClose, /* close */
|
2007-09-03 15:37:07 +00:00
|
|
|
NULL, /* supports_feature */
|
2007-07-17 13:27:26 +00:00
|
|
|
openvzGetType, /* type */
|
2008-10-24 11:32:48 +00:00
|
|
|
openvzGetVersion, /* version */
|
2009-11-12 15:53:26 +00:00
|
|
|
NULL, /* libvirtVersion (impl. in libvirt.c) */
|
2009-03-31 15:47:16 +00:00
|
|
|
NULL, /* getHostname */
|
2008-08-20 13:44:03 +00:00
|
|
|
openvzGetMaxVCPUs, /* getMaxVcpus */
|
2009-06-03 13:28:02 +00:00
|
|
|
nodeGetInfo, /* nodeGetInfo */
|
2008-09-05 14:10:58 +00:00
|
|
|
openvzGetCapabilities, /* getCapabilities */
|
2007-07-17 13:27:26 +00:00
|
|
|
openvzListDomains, /* listDomains */
|
|
|
|
openvzNumDomains, /* numOfDomains */
|
2008-10-10 09:32:27 +00:00
|
|
|
openvzDomainCreateXML, /* domainCreateXML */
|
2007-07-17 13:27:26 +00:00
|
|
|
openvzDomainLookupByID, /* domainLookupByID */
|
|
|
|
openvzDomainLookupByUUID, /* domainLookupByUUID */
|
|
|
|
openvzDomainLookupByName, /* domainLookupByName */
|
2010-08-04 12:00:07 +00:00
|
|
|
openvzDomainSuspend, /* domainSuspend */
|
|
|
|
openvzDomainResume, /* domainResume */
|
2007-07-17 13:27:26 +00:00
|
|
|
openvzDomainShutdown, /* domainShutdown */
|
|
|
|
openvzDomainReboot, /* domainReboot */
|
|
|
|
openvzDomainShutdown, /* domainDestroy */
|
|
|
|
openvzGetOSType, /* domainGetOSType */
|
|
|
|
NULL, /* domainGetMaxMemory */
|
|
|
|
NULL, /* domainSetMaxMemory */
|
|
|
|
NULL, /* domainSetMemory */
|
|
|
|
openvzDomainGetInfo, /* domainGetInfo */
|
|
|
|
NULL, /* domainSave */
|
|
|
|
NULL, /* domainRestore */
|
|
|
|
NULL, /* domainCoreDump */
|
2008-08-20 13:44:03 +00:00
|
|
|
openvzDomainSetVcpus, /* domainSetVcpus */
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
openvzDomainSetVcpusFlags, /* domainSetVcpusFlags */
|
|
|
|
openvzDomainGetVcpusFlags, /* domainGetVcpusFlags */
|
2007-07-17 13:27:26 +00:00
|
|
|
NULL, /* domainPinVcpu */
|
|
|
|
NULL, /* domainGetVcpus */
|
2008-08-20 13:44:03 +00:00
|
|
|
openvzDomainGetMaxVcpus, /* domainGetMaxVcpus */
|
2009-03-03 09:14:28 +00:00
|
|
|
NULL, /* domainGetSecurityLabel */
|
|
|
|
NULL, /* nodeGetSecurityModel */
|
2008-09-05 14:10:58 +00:00
|
|
|
openvzDomainDumpXML, /* domainDumpXML */
|
2009-05-21 13:46:35 +00:00
|
|
|
NULL, /* domainXmlFromNative */
|
|
|
|
NULL, /* domainXmlToNative */
|
2009-03-31 15:47:16 +00:00
|
|
|
openvzListDefinedDomains, /* listDefinedDomains */
|
|
|
|
openvzNumDefinedDomains, /* numOfDefinedDomains */
|
2007-07-17 13:27:26 +00:00
|
|
|
openvzDomainCreate, /* domainCreate */
|
2010-06-10 15:55:36 +00:00
|
|
|
openvzDomainCreateWithFlags, /* domainCreateWithFlags */
|
2007-09-03 15:37:07 +00:00
|
|
|
openvzDomainDefineXML, /* domainDefineXML */
|
|
|
|
openvzDomainUndefine, /* domainUndefine */
|
2007-07-17 13:27:26 +00:00
|
|
|
NULL, /* domainAttachDevice */
|
2010-01-14 01:44:26 +00:00
|
|
|
NULL, /* domainAttachDeviceFlags */
|
2007-07-17 13:27:26 +00:00
|
|
|
NULL, /* domainDetachDevice */
|
2010-01-14 01:44:26 +00:00
|
|
|
NULL, /* domainDetachDeviceFlags */
|
Introduce a new virDomainUpdateDeviceFlags public API
The current virDomainAttachDevice API can be (ab)used to change
the media of an existing CDROM/Floppy device. Going forward there
will be more devices that can be configured on the fly and overloading
virDomainAttachDevice for this is not too pleasant. This patch adds
a new virDomainUpdateDeviceFlags() explicitly just for modifying
existing devices.
* include/libvirt/libvirt.h.in: Add virDomainUpdateDeviceFlags
* src/driver.h: Internal API for virDomainUpdateDeviceFlags
* src/libvirt.c, src/libvirt_public.syms: Glue public API to
driver API
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c, src/qemu/qemu_driver.c,
src/remote/remote_driver.c, src/test/test_driver.c, src/uml/uml_driver.c,
src/vbox/vbox_tmpl.c, src/xen/xen_driver.c, src/xenapi/xenapi_driver.c: Add
stubs for new driver entry point
2010-03-22 12:23:41 +00:00
|
|
|
NULL, /* domainUpdateDeviceFlags */
|
2008-07-10 07:52:14 +00:00
|
|
|
openvzDomainGetAutostart, /* domainGetAutostart */
|
|
|
|
openvzDomainSetAutostart, /* domainSetAutostart */
|
2007-07-17 13:27:26 +00:00
|
|
|
NULL, /* domainGetSchedulerType */
|
|
|
|
NULL, /* domainGetSchedulerParameters */
|
|
|
|
NULL, /* domainSetSchedulerParameters */
|
2007-09-03 16:30:00 +00:00
|
|
|
NULL, /* domainMigratePrepare */
|
|
|
|
NULL, /* domainMigratePerform */
|
|
|
|
NULL, /* domainMigrateFinish */
|
|
|
|
NULL, /* domainBlockStats */
|
|
|
|
NULL, /* domainInterfaceStats */
|
2009-12-20 12:28:42 +00:00
|
|
|
NULL, /* domainMemoryStats */
|
2008-06-12 13:48:29 +00:00
|
|
|
NULL, /* domainBlockPeek */
|
|
|
|
NULL, /* domainMemoryPeek */
|
Internal driver API infrastructure for virDomainGetBlockInfo
This defines the internal driver API and stubs out each driver
* src/driver.h: Define virDrvDomainGetBlockInfo signature
* src/libvirt.c, src/libvirt_public.syms: Glue public API to drivers
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xenapi/xenapi_driver.c: Stub out driver
2010-04-27 19:27:34 +00:00
|
|
|
NULL, /* domainGetBlockInfo */
|
2007-09-28 14:28:12 +00:00
|
|
|
NULL, /* nodeGetCellsFreeMemory */
|
2009-03-31 15:47:16 +00:00
|
|
|
NULL, /* getFreeMemory */
|
2008-10-23 13:18:18 +00:00
|
|
|
NULL, /* domainEventRegister */
|
|
|
|
NULL, /* domainEventDeregister */
|
2008-11-14 08:42:47 +00:00
|
|
|
NULL, /* domainMigratePrepare2 */
|
|
|
|
NULL, /* domainMigrateFinish2 */
|
2009-03-31 15:47:16 +00:00
|
|
|
NULL, /* nodeDeviceDettach */
|
2009-03-02 16:25:13 +00:00
|
|
|
NULL, /* nodeDeviceReAttach */
|
|
|
|
NULL, /* nodeDeviceReset */
|
2009-09-30 10:51:54 +00:00
|
|
|
NULL, /* domainMigratePrepareTunnel */
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
openvzIsEncrypted,
|
|
|
|
openvzIsSecure,
|
|
|
|
openvzDomainIsActive,
|
|
|
|
openvzDomainIsPersistent,
|
2010-11-24 07:43:15 +00:00
|
|
|
openvzDomainIsUpdated, /* domainIsUpdated */
|
2009-12-18 13:59:39 +00:00
|
|
|
NULL, /* cpuCompare */
|
2010-02-02 11:34:01 +00:00
|
|
|
NULL, /* cpuBaseline */
|
Stub out internal driver entry points for job processing
The internal glue layer for the new pubic API
* src/driver.h: Define internal driver API contract
* src/libvirt.c, src/libvirt_public.syms: Wire up public
API to internal driver API
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/qemu/qemu_driver.c, src/remote/remote_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c: Stub new entry point
2010-02-03 11:32:24 +00:00
|
|
|
NULL, /* domainGetJobInfo */
|
Wire up internal entry points for virDomainAbortJob API
This provides the internal glue for the driver API
* src/driver.h: Internal API contract
* src/libvirt.c, src/libvirt_public.syms: Connect public API
to driver API
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/qemu/qemu_driver.c, src/remote/remote_driver.c,
src/test/test_driver.c src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c: Stub out entry points
2010-02-04 16:16:35 +00:00
|
|
|
NULL, /* domainAbortJob */
|
2010-03-12 13:55:08 +00:00
|
|
|
NULL, /* domainMigrateSetMaxDowntime */
|
Introduce a new public API for domain events
The current API for domain events has a number of problems
- Only allows for domain lifecycle change events
- Does not allow the same callback to be registered multiple times
- Does not allow filtering of events to a specific domain
This introduces a new more general purpose domain events API
typedef enum {
VIR_DOMAIN_EVENT_ID_LIFECYCLE = 0, /* virConnectDomainEventCallback */
...more events later..
}
int virConnectDomainEventRegisterAny(virConnectPtr conn,
virDomainPtr dom, /* Optional, to filter */
int eventID,
virConnectDomainEventGenericCallback cb,
void *opaque,
virFreeCallback freecb);
int virConnectDomainEventDeregisterAny(virConnectPtr conn,
int callbackID);
Since different event types can received different data in the callback,
the API is defined with a generic callback. Specific events will each
have a custom signature for their callback. Thus when registering an
event it is neccessary to cast the callback to the generic signature
eg
int myDomainEventCallback(virConnectPtr conn,
virDomainPtr dom,
int event,
int detail,
void *opaque)
{
...
}
virConnectDomainEventRegisterAny(conn, NULL,
VIR_DOMAIN_EVENT_ID_LIFECYCLE,
VIR_DOMAIN_EVENT_CALLBACK(myDomainEventCallback)
NULL, NULL);
The VIR_DOMAIN_EVENT_CALLBACK() macro simply does a "bad" cast
to the generic signature
* include/libvirt/libvirt.h.in: Define new APIs for registering
domain events
* src/driver.h: Internal driver entry points for new events APIs
* src/libvirt.c: Wire up public API to driver API for events APIs
* src/libvirt_public.syms: Export new APIs
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/qemu/qemu_driver.c, src/remote/remote_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c,
src/vbox/vbox_tmpl.c, src/xen/xen_driver.c,
src/xenapi/xenapi_driver.c: Stub out new API entries
2010-03-18 13:01:48 +00:00
|
|
|
NULL, /* domainEventRegisterAny */
|
|
|
|
NULL, /* domainEventDeregisterAny */
|
2010-04-01 08:46:28 +00:00
|
|
|
NULL, /* domainManagedSave */
|
|
|
|
NULL, /* domainHasManagedSaveImage */
|
|
|
|
NULL, /* domainManagedSaveRemove */
|
2010-03-31 20:33:13 +00:00
|
|
|
NULL, /* domainSnapshotCreateXML */
|
|
|
|
NULL, /* domainSnapshotDumpXML */
|
|
|
|
NULL, /* domainSnapshotNum */
|
|
|
|
NULL, /* domainSnapshotListNames */
|
|
|
|
NULL, /* domainSnapshotLookupByName */
|
|
|
|
NULL, /* domainHasCurrentSnapshot */
|
|
|
|
NULL, /* domainSnapshotCurrent */
|
|
|
|
NULL, /* domainRevertToSnapshot */
|
|
|
|
NULL, /* domainSnapshotDelete */
|
2010-04-13 18:02:46 +00:00
|
|
|
NULL, /* qemuDomainMonitorCommand */
|
2010-10-12 14:03:24 +00:00
|
|
|
NULL, /* domainSetMemoryParameters */
|
|
|
|
NULL, /* domainGetMemoryParameters */
|
Introduce a virDomainOpenConsole API
To enable virsh console (or equivalent) to be used remotely
it is necessary to provide remote access to the /dev/pts/XXX
pseudo-TTY associated with the console/serial/parallel device
in the guest. The virStream API provide a bi-directional I/O
stream capability that can be used for this purpose. This
patch thus introduces a virDomainOpenConsole API that uses
the stream APIs.
* src/libvirt.c, src/libvirt_public.syms,
include/libvirt/libvirt.h.in, src/driver.h: Define the
new virDomainOpenConsole API
* src/esx/esx_driver.c, src/lxc/lxc_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_driver.c,
src/phyp/phyp_driver.c, src/qemu/qemu_driver.c,
src/remote/remote_driver.c, src/test/test_driver.c,
src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xenapi/xenapi_driver.c: Stub
API entry point
2010-07-23 12:34:31 +00:00
|
|
|
NULL, /* domainOpenConsole */
|
2007-07-17 13:27:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int openvzRegister(void) {
|
|
|
|
virRegisterDriver(&openvzDriver);
|
|
|
|
return 0;
|
|
|
|
}
|