mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-29 17:33:09 +00:00
Merge all return paths from openvz driver APIs
This commit is contained in:
parent
b6ee63d8bb
commit
e8c92c3b17
@ -1,3 +1,8 @@
|
|||||||
|
Thu Dec 4 21:41:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
* src/openvz_driver.c: Merge all return paths from openvz
|
||||||
|
driver APIs
|
||||||
|
|
||||||
Thu Dec 4 21:40:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
Thu Dec 4 21:40:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* src/storage_conf.h: Add driver lock
|
* src/storage_conf.h: Add driver lock
|
||||||
@ -5,8 +10,8 @@ Thu Dec 4 21:40:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
|||||||
|
|
||||||
Thu Dec 4 21:39:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
Thu Dec 4 21:39:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* src/storage_driver.c: Merge all return paths driver storage
|
* src/storage_driver.c: Merge all return paths from storage
|
||||||
APIs
|
driver APIs
|
||||||
|
|
||||||
Thu Dec 4 21:38:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
Thu Dec 4 21:38:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
@ -155,96 +155,101 @@ static int openvzDomainDefineCmd(virConnectPtr conn,
|
|||||||
|
|
||||||
static virDomainPtr openvzDomainLookupByID(virConnectPtr conn,
|
static virDomainPtr openvzDomainLookupByID(virConnectPtr conn,
|
||||||
int id) {
|
int id) {
|
||||||
struct openvz_driver *driver = (struct openvz_driver *)conn->privateData;
|
struct openvz_driver *driver = conn->privateData;
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
virDomainPtr dom;
|
virDomainPtr dom = NULL;
|
||||||
|
|
||||||
vm = virDomainFindByID(&driver->domains, id);
|
vm = virDomainFindByID(&driver->domains, id);
|
||||||
|
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
|
openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
||||||
if (!dom)
|
if (dom)
|
||||||
return NULL;
|
|
||||||
|
|
||||||
dom->id = vm->def->id;
|
dom->id = vm->def->id;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
return dom;
|
return dom;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int openvzGetVersion(virConnectPtr conn, unsigned long *version) {
|
static int openvzGetVersion(virConnectPtr conn, unsigned long *version) {
|
||||||
struct openvz_driver *driver = (struct openvz_driver *)conn->privateData;
|
struct openvz_driver *driver = conn->privateData;
|
||||||
*version = driver->version;
|
*version = driver->version;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *openvzGetOSType(virDomainPtr dom)
|
static char *openvzGetOSType(virDomainPtr dom)
|
||||||
{
|
{
|
||||||
struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData;
|
struct openvz_driver *driver = dom->conn->privateData;
|
||||||
virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
virDomainObjPtr vm;
|
||||||
char *ret;
|
char *ret = NULL;
|
||||||
|
|
||||||
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
openvzError(dom->conn, VIR_ERR_NO_DOMAIN, NULL);
|
openvzError(dom->conn, VIR_ERR_NO_DOMAIN, NULL);
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ret = strdup(vm->def->os.type)))
|
if (!(ret = strdup(vm->def->os.type)))
|
||||||
openvzError(dom->conn, VIR_ERR_NO_MEMORY, NULL);
|
openvzError(dom->conn, VIR_ERR_NO_MEMORY, NULL);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static virDomainPtr openvzDomainLookupByUUID(virConnectPtr conn,
|
static virDomainPtr openvzDomainLookupByUUID(virConnectPtr conn,
|
||||||
const unsigned char *uuid) {
|
const unsigned char *uuid) {
|
||||||
struct openvz_driver *driver = (struct openvz_driver *)conn->privateData;
|
struct openvz_driver *driver = conn->privateData;
|
||||||
virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, uuid);
|
virDomainObjPtr vm;
|
||||||
virDomainPtr dom;
|
virDomainPtr dom = NULL;
|
||||||
|
|
||||||
|
vm = virDomainFindByUUID(&driver->domains, uuid);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
|
openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
||||||
if (!dom)
|
if (dom)
|
||||||
return NULL;
|
|
||||||
|
|
||||||
dom->id = vm->def->id;
|
dom->id = vm->def->id;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
return dom;
|
return dom;
|
||||||
}
|
}
|
||||||
|
|
||||||
static virDomainPtr openvzDomainLookupByName(virConnectPtr conn,
|
static virDomainPtr openvzDomainLookupByName(virConnectPtr conn,
|
||||||
const char *name) {
|
const char *name) {
|
||||||
struct openvz_driver *driver = (struct openvz_driver *)conn->privateData;
|
struct openvz_driver *driver = conn->privateData;
|
||||||
virDomainObjPtr vm = virDomainFindByName(&driver->domains, name);
|
virDomainObjPtr vm;
|
||||||
virDomainPtr dom;
|
virDomainPtr dom = NULL;
|
||||||
|
|
||||||
|
vm = virDomainFindByName(&driver->domains, name);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
|
openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
||||||
if (!dom)
|
if (dom)
|
||||||
return NULL;
|
|
||||||
|
|
||||||
dom->id = vm->def->id;
|
dom->id = vm->def->id;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
return dom;
|
return dom;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int openvzDomainGetInfo(virDomainPtr dom,
|
static int openvzDomainGetInfo(virDomainPtr dom,
|
||||||
virDomainInfoPtr info) {
|
virDomainInfoPtr info) {
|
||||||
struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData;
|
struct openvz_driver *driver = dom->conn->privateData;
|
||||||
virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
virDomainObjPtr vm;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
|
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
|
||||||
"%s", _("no domain with matching uuid"));
|
"%s", _("no domain with matching uuid"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
info->state = vm->state;
|
info->state = vm->state;
|
||||||
@ -255,80 +260,116 @@ static int openvzDomainGetInfo(virDomainPtr dom,
|
|||||||
if (openvzGetProcessInfo(&(info->cpuTime), dom->id) < 0) {
|
if (openvzGetProcessInfo(&(info->cpuTime), dom->id) < 0) {
|
||||||
openvzError(dom->conn, VIR_ERR_OPERATION_FAILED,
|
openvzError(dom->conn, VIR_ERR_OPERATION_FAILED,
|
||||||
_("cannot read cputime for domain %d"), dom->id);
|
_("cannot read cputime for domain %d"), dom->id);
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info->maxMem = vm->def->maxmem;
|
info->maxMem = vm->def->maxmem;
|
||||||
info->memory = vm->def->memory;
|
info->memory = vm->def->memory;
|
||||||
info->nrVirtCpu = vm->def->vcpus;
|
info->nrVirtCpu = vm->def->vcpus;
|
||||||
return 0;
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *openvzDomainDumpXML(virDomainPtr dom, int flags) {
|
static char *openvzDomainDumpXML(virDomainPtr dom, int flags) {
|
||||||
struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData;
|
struct openvz_driver *driver = dom->conn->privateData;
|
||||||
virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
virDomainObjPtr vm;
|
||||||
|
char *ret = NULL;
|
||||||
|
|
||||||
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
|
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
|
||||||
"%s", _("no domain with matching uuid"));
|
"%s", _("no domain with matching uuid"));
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
return virDomainDefFormat(dom->conn, vm->def, flags);
|
ret = virDomainDefFormat(dom->conn, vm->def, flags);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int openvzDomainShutdown(virDomainPtr dom) {
|
static int openvzDomainShutdown(virDomainPtr dom) {
|
||||||
struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData;
|
struct openvz_driver *driver = dom->conn->privateData;
|
||||||
virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
virDomainObjPtr vm;
|
||||||
const char *prog[] = {VZCTL, "--quiet", "stop", vm ? vm->def->name : NULL, NULL};
|
const char *prog[] = {VZCTL, "--quiet", "stop", PROGRAM_SENTINAL, NULL};
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
|
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
|
||||||
"%s", _("no domain with matching uuid"));
|
"%s", _("no domain with matching uuid"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openvzSetProgramSentinal(prog, vm->def->name);
|
||||||
if (vm->state != VIR_DOMAIN_RUNNING) {
|
if (vm->state != VIR_DOMAIN_RUNNING) {
|
||||||
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
|
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("domain is not in running state"));
|
"%s", _("domain is not in running state"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virRun(dom->conn, prog, NULL) < 0)
|
if (virRun(dom->conn, prog, NULL) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
|
|
||||||
vm->def->id = -1;
|
vm->def->id = -1;
|
||||||
vm->state = VIR_DOMAIN_SHUTOFF;
|
vm->state = VIR_DOMAIN_SHUTOFF;
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
return 0;
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int openvzDomainReboot(virDomainPtr dom,
|
static int openvzDomainReboot(virDomainPtr dom,
|
||||||
unsigned int flags ATTRIBUTE_UNUSED) {
|
unsigned int flags ATTRIBUTE_UNUSED) {
|
||||||
struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData;
|
struct openvz_driver *driver = dom->conn->privateData;
|
||||||
virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
virDomainObjPtr vm;
|
||||||
const char *prog[] = {VZCTL, "--quiet", "restart", vm ? vm->def->name : NULL, NULL};
|
const char *prog[] = {VZCTL, "--quiet", "restart", PROGRAM_SENTINAL, NULL};
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
|
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
|
||||||
"%s", _("no domain with matching uuid"));
|
"%s", _("no domain with matching uuid"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openvzSetProgramSentinal(prog, vm->def->name);
|
||||||
if (vm->state != VIR_DOMAIN_RUNNING) {
|
if (vm->state != VIR_DOMAIN_RUNNING) {
|
||||||
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
|
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("domain is not in running state"));
|
"%s", _("domain is not in running state"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virRun(dom->conn, prog, NULL) < 0)
|
if (virRun(dom->conn, prog, NULL) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
return 0;
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
@ -379,7 +420,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
|
|||||||
int rc = 0, narg;
|
int rc = 0, narg;
|
||||||
const char *prog[OPENVZ_MAX_ARG];
|
const char *prog[OPENVZ_MAX_ARG];
|
||||||
char macaddr[VIR_MAC_STRING_BUFLEN];
|
char macaddr[VIR_MAC_STRING_BUFLEN];
|
||||||
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
|
struct openvz_driver *driver = conn->privateData;
|
||||||
char *opt = NULL;
|
char *opt = NULL;
|
||||||
|
|
||||||
#define ADD_ARG_LIT(thisarg) \
|
#define ADD_ARG_LIT(thisarg) \
|
||||||
@ -508,7 +549,7 @@ openvzDomainSetNetworkConfig(virConnectPtr conn,
|
|||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
char *param;
|
char *param;
|
||||||
int first = 1;
|
int first = 1;
|
||||||
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
|
struct openvz_driver *driver = conn->privateData;
|
||||||
|
|
||||||
for (i = 0 ; i < def->nnets ; i++) {
|
for (i = 0 ; i < def->nnets ; i++) {
|
||||||
if (driver->version < VZCTL_BRIDGE_MIN_VERSION &&
|
if (driver->version < VZCTL_BRIDGE_MIN_VERSION &&
|
||||||
@ -551,7 +592,7 @@ exit:
|
|||||||
static virDomainPtr
|
static virDomainPtr
|
||||||
openvzDomainDefineXML(virConnectPtr conn, const char *xml)
|
openvzDomainDefineXML(virConnectPtr conn, const char *xml)
|
||||||
{
|
{
|
||||||
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
|
struct openvz_driver *driver = conn->privateData;
|
||||||
virDomainDefPtr vmdef = NULL;
|
virDomainDefPtr vmdef = NULL;
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
@ -559,12 +600,11 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml)
|
|||||||
prog[0] = NULL;
|
prog[0] = NULL;
|
||||||
|
|
||||||
if ((vmdef = virDomainDefParseString(conn, driver->caps, xml)) == NULL)
|
if ((vmdef = virDomainDefParseString(conn, driver->caps, xml)) == NULL)
|
||||||
return NULL;
|
goto cleanup;
|
||||||
|
|
||||||
if (vmdef->os.init == NULL &&
|
if (vmdef->os.init == NULL &&
|
||||||
!(vmdef->os.init = strdup("/sbin/init"))) {
|
!(vmdef->os.init = strdup("/sbin/init"))) {
|
||||||
virDomainDefFree(vmdef);
|
goto cleanup;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vm = virDomainFindByName(&driver->domains, vmdef->name);
|
vm = virDomainFindByName(&driver->domains, vmdef->name);
|
||||||
@ -572,18 +612,16 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml)
|
|||||||
openvzError(conn, VIR_ERR_OPERATION_FAILED,
|
openvzError(conn, VIR_ERR_OPERATION_FAILED,
|
||||||
_("Already an OPENVZ VM active with the id '%s'"),
|
_("Already an OPENVZ VM active with the id '%s'"),
|
||||||
vmdef->name);
|
vmdef->name);
|
||||||
virDomainDefFree(vmdef);
|
goto cleanup;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (!(vm = virDomainAssignDef(conn, &driver->domains, vmdef))) {
|
|
||||||
virDomainDefFree(vmdef);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
if (!(vm = virDomainAssignDef(conn, &driver->domains, vmdef)))
|
||||||
|
goto cleanup;
|
||||||
|
vmdef = NULL;
|
||||||
|
|
||||||
if (openvzDomainDefineCmd(conn, prog, OPENVZ_MAX_ARG, vmdef) < 0) {
|
if (openvzDomainDefineCmd(conn, prog, OPENVZ_MAX_ARG, vm->def) < 0) {
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("Error creating command for container"));
|
"%s", _("Error creating command for container"));
|
||||||
goto exit;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: set quota
|
//TODO: set quota
|
||||||
@ -591,31 +629,32 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml)
|
|||||||
if (virRun(conn, prog, NULL) < 0) {
|
if (virRun(conn, prog, NULL) < 0) {
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Could not exec %s"), VZCTL);
|
_("Could not exec %s"), VZCTL);
|
||||||
goto exit;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (openvzSetDefinedUUID(strtoI(vmdef->name), vmdef->uuid) < 0) {
|
if (openvzSetDefinedUUID(strtoI(vm->def->name), vm->def->uuid) < 0) {
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("Could not set UUID"));
|
"%s", _("Could not set UUID"));
|
||||||
goto exit;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (openvzDomainSetNetworkConfig(conn, vmdef) < 0)
|
if (openvzDomainSetNetworkConfig(conn, vm->def) < 0)
|
||||||
goto exit;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (vm->def->vcpus > 0) {
|
||||||
|
if (openvzDomainSetVcpus(dom, vm->def->vcpus) < 0) {
|
||||||
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("Could not set number of virtual cpu"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
||||||
if (dom)
|
if (dom)
|
||||||
dom->id = -1;
|
dom->id = -1;
|
||||||
|
|
||||||
if (vmdef->vcpus > 0) {
|
cleanup:
|
||||||
if (openvzDomainSetVcpus(dom, vmdef->vcpus) < 0) {
|
virDomainDefFree(vmdef);
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
||||||
"%s", _("Could not set number of virtual cpu"));
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
|
||||||
cmdExecFree(prog);
|
cmdExecFree(prog);
|
||||||
return dom;
|
return dom;
|
||||||
}
|
}
|
||||||
@ -624,82 +663,79 @@ static virDomainPtr
|
|||||||
openvzDomainCreateXML(virConnectPtr conn, const char *xml,
|
openvzDomainCreateXML(virConnectPtr conn, const char *xml,
|
||||||
unsigned int flags ATTRIBUTE_UNUSED)
|
unsigned int flags ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
|
struct openvz_driver *driver = conn->privateData;
|
||||||
virDomainDefPtr vmdef = NULL;
|
virDomainDefPtr vmdef = NULL;
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
|
const char *progstart[] = {VZCTL, "--quiet", "start", PROGRAM_SENTINAL, NULL};
|
||||||
const char *progstart[] = {VZCTL, "--quiet", "start", NULL, NULL};
|
|
||||||
const char *progcreate[OPENVZ_MAX_ARG];
|
const char *progcreate[OPENVZ_MAX_ARG];
|
||||||
progcreate[0] = NULL;
|
progcreate[0] = NULL;
|
||||||
|
|
||||||
if ((vmdef = virDomainDefParseString(conn, driver->caps, xml)) == NULL)
|
if ((vmdef = virDomainDefParseString(conn, driver->caps, xml)) == NULL)
|
||||||
return NULL;
|
goto cleanup;
|
||||||
|
|
||||||
if (vmdef->os.init == NULL &&
|
if (vmdef->os.init == NULL &&
|
||||||
!(vmdef->os.init = strdup("/sbin/init"))) {
|
!(vmdef->os.init = strdup("/sbin/init")))
|
||||||
virDomainDefFree(vmdef);
|
goto cleanup;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
vm = virDomainFindByName(&driver->domains, vmdef->name);
|
vm = virDomainFindByName(&driver->domains, vmdef->name);
|
||||||
if (vm) {
|
if (vm) {
|
||||||
openvzError(conn, VIR_ERR_OPERATION_FAILED,
|
openvzError(conn, VIR_ERR_OPERATION_FAILED,
|
||||||
_("Already an OPENVZ VM defined with the id '%s'"),
|
_("Already an OPENVZ VM defined with the id '%s'"),
|
||||||
vmdef->name);
|
vmdef->name);
|
||||||
virDomainDefFree(vmdef);
|
goto cleanup;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (!(vm = virDomainAssignDef(conn, &driver->domains, vmdef))) {
|
|
||||||
virDomainDefFree(vmdef);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
if (!(vm = virDomainAssignDef(conn, &driver->domains, vmdef)))
|
||||||
|
goto cleanup;
|
||||||
|
vmdef = NULL;
|
||||||
|
|
||||||
if (openvzDomainDefineCmd(conn, progcreate, OPENVZ_MAX_ARG, vmdef) < 0) {
|
if (openvzDomainDefineCmd(conn, progcreate, OPENVZ_MAX_ARG, vm->def) < 0) {
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("Error creating command for container"));
|
"%s", _("Error creating command for container"));
|
||||||
goto exit;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virRun(conn, progcreate, NULL) < 0) {
|
if (virRun(conn, progcreate, NULL) < 0) {
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Could not exec %s"), VZCTL);
|
_("Could not exec %s"), VZCTL);
|
||||||
goto exit;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (openvzSetDefinedUUID(strtoI(vmdef->name), vmdef->uuid) < 0) {
|
if (openvzSetDefinedUUID(strtoI(vm->def->name), vm->def->uuid) < 0) {
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("Could not set UUID"));
|
"%s", _("Could not set UUID"));
|
||||||
goto exit;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (openvzDomainSetNetworkConfig(conn, vmdef) < 0)
|
if (openvzDomainSetNetworkConfig(conn, vm->def) < 0)
|
||||||
goto exit;
|
goto cleanup;
|
||||||
|
|
||||||
progstart[3] = vmdef->name;
|
openvzSetProgramSentinal(progstart, vm->def->name);
|
||||||
|
|
||||||
if (virRun(conn, progstart, NULL) < 0) {
|
if (virRun(conn, progstart, NULL) < 0) {
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Could not exec %s"), VZCTL);
|
_("Could not exec %s"), VZCTL);
|
||||||
goto exit;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
vm->pid = strtoI(vmdef->name);
|
vm->pid = strtoI(vm->def->name);
|
||||||
vm->def->id = vm->pid;
|
vm->def->id = vm->pid;
|
||||||
vm->state = VIR_DOMAIN_RUNNING;
|
vm->state = VIR_DOMAIN_RUNNING;
|
||||||
|
|
||||||
|
if (vm->def->vcpus > 0) {
|
||||||
|
if (openvzDomainSetVcpus(dom, vm->def->vcpus) < 0) {
|
||||||
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("Could not set number of virtual cpu"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
||||||
if (dom)
|
if (dom)
|
||||||
dom->id = vm->def->id;
|
dom->id = vm->def->id;
|
||||||
|
|
||||||
if (vmdef->vcpus > 0) {
|
cleanup:
|
||||||
if (openvzDomainSetVcpus(dom, vmdef->vcpus) < 0) {
|
virDomainDefFree(vmdef);
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
||||||
"%s", _("Could not set number of virtual cpu"));
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
|
||||||
cmdExecFree(progcreate);
|
cmdExecFree(progcreate);
|
||||||
return dom;
|
return dom;
|
||||||
}
|
}
|
||||||
@ -707,110 +743,128 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml,
|
|||||||
static int
|
static int
|
||||||
openvzDomainCreate(virDomainPtr dom)
|
openvzDomainCreate(virDomainPtr dom)
|
||||||
{
|
{
|
||||||
struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData;
|
struct openvz_driver *driver = dom->conn->privateData;
|
||||||
virDomainObjPtr vm = virDomainFindByName(&driver->domains, dom->name);
|
virDomainObjPtr vm;
|
||||||
const char *prog[] = {VZCTL, "--quiet", "start", vm ? vm->def->name : NULL, NULL };
|
const char *prog[] = {VZCTL, "--quiet", "start", PROGRAM_SENTINAL, NULL };
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
vm = virDomainFindByName(&driver->domains, dom->name);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
|
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
|
||||||
"%s", _("no domain with matching id"));
|
"%s", _("no domain with matching id"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm->state != VIR_DOMAIN_SHUTOFF) {
|
if (vm->state != VIR_DOMAIN_SHUTOFF) {
|
||||||
openvzError(dom->conn, VIR_ERR_OPERATION_DENIED,
|
openvzError(dom->conn, VIR_ERR_OPERATION_DENIED,
|
||||||
"%s", _("domain is not in shutoff state"));
|
"%s", _("domain is not in shutoff state"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openvzSetProgramSentinal(prog, vm->def->name);
|
||||||
if (virRun(dom->conn, prog, NULL) < 0) {
|
if (virRun(dom->conn, prog, NULL) < 0) {
|
||||||
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
|
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Could not exec %s"), VZCTL);
|
_("Could not exec %s"), VZCTL);
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
vm->pid = strtoI(vm->def->name);
|
vm->pid = strtoI(vm->def->name);
|
||||||
vm->def->id = vm->pid;
|
vm->def->id = vm->pid;
|
||||||
vm->state = VIR_DOMAIN_RUNNING;
|
vm->state = VIR_DOMAIN_RUNNING;
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
return 0;
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
openvzDomainUndefine(virDomainPtr dom)
|
openvzDomainUndefine(virDomainPtr dom)
|
||||||
{
|
{
|
||||||
virConnectPtr conn= dom->conn;
|
struct openvz_driver *driver = dom->conn->privateData;
|
||||||
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
|
virDomainObjPtr vm;
|
||||||
virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
const char *prog[] = { VZCTL, "--quiet", "destroy", PROGRAM_SENTINAL, NULL };
|
||||||
const char *prog[] = { VZCTL, "--quiet", "destroy", vm ? vm->def->name : NULL, NULL };
|
int ret = -1;
|
||||||
|
|
||||||
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
openvzError(conn, VIR_ERR_INVALID_DOMAIN, "%s", _("no domain with matching uuid"));
|
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN, "%s", _("no domain with matching uuid"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virDomainIsActive(vm)) {
|
if (virDomainIsActive(vm)) {
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR, "%s", _("cannot delete active domain"));
|
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR, "%s", _("cannot delete active domain"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virRun(conn, prog, NULL) < 0) {
|
openvzSetProgramSentinal(prog, vm->def->name);
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
if (virRun(dom->conn, prog, NULL) < 0) {
|
||||||
|
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Could not exec %s"), VZCTL);
|
_("Could not exec %s"), VZCTL);
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
virDomainRemoveInactive(&driver->domains, vm);
|
virDomainRemoveInactive(&driver->domains, vm);
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
return 0;
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
openvzDomainSetAutostart(virDomainPtr dom, int autostart)
|
openvzDomainSetAutostart(virDomainPtr dom, int autostart)
|
||||||
{
|
{
|
||||||
virConnectPtr conn= dom->conn;
|
struct openvz_driver *driver = dom->conn->privateData;
|
||||||
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
|
virDomainObjPtr vm;
|
||||||
virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINAL,
|
||||||
const char *prog[] = { VZCTL, "--quiet", "set", vm ? vm->def->name : NULL,
|
|
||||||
"--onboot", autostart ? "yes" : "no",
|
"--onboot", autostart ? "yes" : "no",
|
||||||
"--save", NULL };
|
"--save", NULL };
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
openvzError(conn, VIR_ERR_INVALID_DOMAIN, "%s", _("no domain with matching uuid"));
|
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN, "%s", _("no domain with matching uuid"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virRun(conn, prog, NULL) < 0) {
|
openvzSetProgramSentinal(prog, vm->def->name);
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR, _("Could not exec %s"), VZCTL);
|
if (virRun(dom->conn, prog, NULL) < 0) {
|
||||||
return -1;
|
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR, _("Could not exec %s"), VZCTL);
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
return 0;
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
openvzDomainGetAutostart(virDomainPtr dom, int *autostart)
|
openvzDomainGetAutostart(virDomainPtr dom, int *autostart)
|
||||||
{
|
{
|
||||||
virConnectPtr conn= dom->conn;
|
struct openvz_driver *driver = dom->conn->privateData;
|
||||||
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
|
virDomainObjPtr vm;
|
||||||
virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
|
||||||
char value[1024];
|
char value[1024];
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
openvzError(conn, VIR_ERR_INVALID_DOMAIN, "%s", _("no domain with matching uuid"));
|
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
|
||||||
return -1;
|
"%s", _("no domain with matching uuid"));
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (openvzReadConfigParam(strtoI(vm->def->name), "ONBOOT", value, sizeof(value)) < 0) {
|
if (openvzReadConfigParam(strtoI(vm->def->name), "ONBOOT", value, sizeof(value)) < 0) {
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR, "%s", _("Could not read container config"));
|
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
return -1;
|
"%s", _("Could not read container config"));
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
*autostart = 0;
|
*autostart = 0;
|
||||||
if (STREQ(value,"yes"))
|
if (STREQ(value,"yes"))
|
||||||
*autostart = 1;
|
*autostart = 1;
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
return 0;
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int openvzGetMaxVCPUs(virConnectPtr conn, const char *type) {
|
static int openvzGetMaxVCPUs(virConnectPtr conn, const char *type) {
|
||||||
@ -828,24 +882,25 @@ static int openvzDomainGetMaxVcpus(virDomainPtr dom) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) {
|
static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) {
|
||||||
virConnectPtr conn= dom->conn;
|
struct openvz_driver *driver = dom->conn->privateData;
|
||||||
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
|
virDomainObjPtr vm;
|
||||||
virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
|
||||||
char str_vcpus[32];
|
char str_vcpus[32];
|
||||||
const char *prog[] = { VZCTL, "--quiet", "set", vm ? vm->def->name : NULL,
|
const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINAL,
|
||||||
"--cpus", str_vcpus, "--save", NULL };
|
"--cpus", str_vcpus, "--save", NULL };
|
||||||
unsigned int pcpus;
|
unsigned int pcpus;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
openvzError(conn, VIR_ERR_INVALID_DOMAIN,
|
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
|
||||||
"%s", _("no domain with matching uuid"));
|
"%s", _("no domain with matching uuid"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nvcpus <= 0) {
|
if (nvcpus <= 0) {
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("VCPUs should be >= 1"));
|
"%s", _("VCPUs should be >= 1"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
pcpus = openvzGetNodeCPUs();
|
pcpus = openvzGetNodeCPUs();
|
||||||
@ -855,14 +910,18 @@ static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) {
|
|||||||
snprintf(str_vcpus, 31, "%d", nvcpus);
|
snprintf(str_vcpus, 31, "%d", nvcpus);
|
||||||
str_vcpus[31] = '\0';
|
str_vcpus[31] = '\0';
|
||||||
|
|
||||||
if (virRun(conn, prog, NULL) < 0) {
|
openvzSetProgramSentinal(prog, vm->def->name);
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
if (virRun(dom->conn, prog, NULL) < 0) {
|
||||||
|
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Could not exec %s"), VZCTL);
|
_("Could not exec %s"), VZCTL);
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
vm->def->vcpus = nvcpus;
|
vm->def->vcpus = nvcpus;
|
||||||
return 0;
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int openvzProbe(void)
|
static int openvzProbe(void)
|
||||||
@ -919,7 +978,7 @@ cleanup:
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int openvzClose(virConnectPtr conn) {
|
static int openvzClose(virConnectPtr conn) {
|
||||||
struct openvz_driver *driver = (struct openvz_driver *)conn->privateData;
|
struct openvz_driver *driver = conn->privateData;
|
||||||
|
|
||||||
openvzFreeDriver(driver);
|
openvzFreeDriver(driver);
|
||||||
conn->privateData = NULL;
|
conn->privateData = NULL;
|
||||||
@ -937,9 +996,12 @@ static int openvzGetNodeInfo(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char *openvzGetCapabilities(virConnectPtr conn) {
|
static char *openvzGetCapabilities(virConnectPtr conn) {
|
||||||
struct openvz_driver *driver = (struct openvz_driver *)conn->privateData;
|
struct openvz_driver *driver = conn->privateData;
|
||||||
|
char *ret;
|
||||||
|
|
||||||
return virCapabilitiesFormatXML(driver->caps);
|
ret = virCapabilitiesFormatXML(driver->caps);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int openvzListDomains(virConnectPtr conn, int *ids, int nids) {
|
static int openvzListDomains(virConnectPtr conn, int *ids, int nids) {
|
||||||
@ -1074,7 +1136,7 @@ Version: 2.2
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int openvzNumDefinedDomains(virConnectPtr conn) {
|
static int openvzNumDefinedDomains(virConnectPtr conn) {
|
||||||
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
|
struct openvz_driver *driver = conn->privateData;
|
||||||
int ninactive = 0, i;
|
int ninactive = 0, i;
|
||||||
|
|
||||||
for (i = 0 ; i < driver->domains.count ; i++)
|
for (i = 0 ; i < driver->domains.count ; i++)
|
||||||
|
Loading…
Reference in New Issue
Block a user