struct openvz_driver ovz_driver;
+
+static virDomainObjPtr
+openvzDomObjFromDomainLocked(struct openvz_driver *driver,
+ const unsigned char *uuid)
+{
+ virDomainObjPtr vm;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+ if (!(vm = virDomainObjListFindByUUID(driver->domains, uuid))) {
+ virUUIDFormat(uuid, uuidstr);
+
+ virReportError(VIR_ERR_NO_DOMAIN,
+ _("no domain with matching uuid '%s'"), uuidstr);
+ return NULL;
+ }
+
+ return vm;
+}
+
+
+static virDomainObjPtr
+openvzDomObjFromDomain(struct openvz_driver *driver,
+ const unsigned char *uuid)
+{
+ virDomainObjPtr vm;
+
+ openvzDriverLock(driver);
+ vm = openvzDomObjFromDomainLocked(driver, uuid);
+ openvzDriverUnlock(driver);
+ return vm;
+}
+
+
static int
openvzDomainDefPostParse(virDomainDefPtr def,
virCapsPtr caps ATTRIBUTE_UNUSED,
virDomainObjPtr vm;
virCheckFlags(0, NULL);
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
+ return NULL;
hostname = openvzVEGetStringParam(dom, "hostname");
if (hostname == NULL)
virDomainObjPtr vm;
char *ret = NULL;
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, NULL);
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
+ return NULL;
ignore_value(VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type)));
- cleanup:
if (vm)
virObjectUnlock(vm);
return ret;
virDomainObjPtr vm;
virDomainPtr dom = NULL;
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, NULL);
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, uuid)))
+ return NULL;
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
- cleanup:
if (vm)
virObjectUnlock(vm);
return dom;
int state;
int ret = -1;
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
+ return -1;
if (openvzGetVEStatus(vm, &state, NULL) == -1)
goto cleanup;
virCheckFlags(0, -1);
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
+ return -1;
ret = openvzGetVEStatus(vm, state, reason);
- cleanup:
if (vm)
virObjectUnlock(vm);
return ret;
virDomainObjPtr obj;
int ret = -1;
- openvzDriverLock(driver);
- obj = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
- if (!obj) {
- virReportError(VIR_ERR_NO_DOMAIN, NULL);
- goto cleanup;
- }
+ if (!(obj = openvzDomObjFromDomain(driver, dom->uuid)))
+ return -1;
+
ret = virDomainObjIsActive(obj);
- cleanup:
if (obj)
virObjectUnlock(obj);
return ret;
virDomainObjPtr obj;
int ret = -1;
- openvzDriverLock(driver);
- obj = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
- if (!obj) {
- virReportError(VIR_ERR_NO_DOMAIN, NULL);
- goto cleanup;
- }
+ if (!(obj = openvzDomObjFromDomain(driver, dom->uuid)))
+ return -1;
+
ret = obj->persistent;
- cleanup:
if (obj)
virObjectUnlock(obj);
return ret;
/* Flags checked by virDomainDefFormat */
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
+ return NULL;
ret = virDomainDefFormat(vm->def, driver->caps,
virDomainDefFormatConvertXMLFlags(flags));
- cleanup:
if (vm)
virObjectUnlock(vm);
return ret;
const char *prog[] = {VZCTL, "--quiet", "chkpnt", PROGRAM_SENTINEL, "--suspend", NULL};
int ret = -1;
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
+ return -1;
if (!virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
const char *prog[] = {VZCTL, "--quiet", "chkpnt", PROGRAM_SENTINEL, "--resume", NULL};
int ret = -1;
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
+ return -1;
if (!virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
virCheckFlags(0, -1);
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
+ return -1;
if (openvzGetVEStatus(vm, &status, NULL) == -1)
goto cleanup;
virCheckFlags(0, -1);
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
+ return -1;
if (openvzGetVEStatus(vm, &status, NULL) == -1)
goto cleanup;
virCheckFlags(0, -1);
openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
+ if (!(vm = openvzDomObjFromDomainLocked(driver, dom->uuid)))
goto cleanup;
- }
if (openvzGetVEStatus(vm, &status, NULL) == -1)
goto cleanup;
"--save", NULL };
int ret = -1;
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
+ return -1;
openvzSetProgramSentinal(prog, vm->def->name);
if (virRun(prog, NULL) < 0)
char *value = NULL;
int ret = -1;
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
+ return -1;
if (openvzReadVPSConfigParam(strtoI(vm->def->name), "ONBOOT", &value) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
return -1;
}
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
+ return -1;
if (nvcpus <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
virDomainNetDefPtr net = NULL;
int ret = -1;
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- char uuidstr[VIR_UUID_STRING_BUFLEN];
- virUUIDFormat(dom->uuid, uuidstr);
- virReportError(VIR_ERR_NO_DOMAIN,
- _("no domain with matching uuid '%s'"), uuidstr);
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, dom->uuid)))
+ return -1;
if (!virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_OPERATION_INVALID,
VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1);
openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
+ if (!(vm = openvzDomObjFromDomainLocked(driver, dom->uuid)))
goto cleanup;
- }
if (virStrToLong_i(vm->def->name, NULL, 10, &veid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
if (virTypedParamsValidate(params, nparams, OPENVZ_MIGRATION_PARAMETERS) < 0)
return NULL;
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, domain->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
- goto cleanup;
- }
+ if (!(vm = openvzDomObjFromDomain(driver, domain->uuid)))
+ return NULL;
if (!virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_OPERATION_INVALID,
&uri_str) < 0)
goto cleanup;
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, domain->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
+ if (!(vm = openvzDomObjFromDomain(driver, domain->uuid)))
goto cleanup;
- }
/* parse dst host:port from uri */
uri = virURIParse(uri_str);
if (virTypedParamsValidate(params, nparams, OPENVZ_MIGRATION_PARAMETERS) < 0)
goto cleanup;
- openvzDriverLock(driver);
- vm = virDomainObjListFindByUUID(driver->domains, domain->uuid);
- openvzDriverUnlock(driver);
-
- if (!vm) {
- virReportError(VIR_ERR_NO_DOMAIN, "%s",
- _("no domain with matching uuid"));
+ if (!(vm = openvzDomObjFromDomain(driver, domain->uuid)))
goto cleanup;
- }
if (cancelled) {
if (openvzGetVEStatus(vm, &status, NULL) == -1)
virCheckFlags(0, -1);
- openvzDriverLock(driver);
- obj = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- openvzDriverUnlock(driver);
- if (!obj) {
- virReportError(VIR_ERR_NO_DOMAIN, NULL);
- goto cleanup;
- }
+ if (!(obj = openvzDomObjFromDomain(driver, dom->uuid)))
+ return -1;
+
ret = 0;
- cleanup:
if (obj)
virObjectUnlock(obj);
return ret;