Replace virDomainObjIsActive with virDomainObjCheckIsActive
which raises error if domain is not active
Signed-off-by: Sagar Ghuge <ghugesss(a)gmail.com>
---
...libxl-Implement-virDomainObjCheckIsActive.patch | 55 ++++
...omainObjIsActive-with-virDomainObjCheckIs.patch | 109 ++++++++
...e-virDomainObjIsActive-to-virDomainObjChe.patch | 298 +++++++++++++++++++++
patch1 | 52 ++++
src/libxl/libxl_driver.c | 102 ++-----
5 files changed, 537 insertions(+), 79 deletions(-)
create mode 100644 0001-libxl-Implement-virDomainObjCheckIsActive.patch
create mode 100644 0002-change-virDomainObjIsActive-with-virDomainObjCheckIs.patch
create mode 100644 0003-libxl-Change-virDomainObjIsActive-to-virDomainObjChe.patch
create mode 100644 patch1
diff --git a/0001-libxl-Implement-virDomainObjCheckIsActive.patch
b/0001-libxl-Implement-virDomainObjCheckIsActive.patch
new file mode 100644
index 0000000..161a59d
--- /dev/null
+++ b/0001-libxl-Implement-virDomainObjCheckIsActive.patch
@@ -0,0 +1,55 @@
+From 364fe0cec782a312a7c0fc3a6ebf7580053f4f9a Mon Sep 17 00:00:00 2001
+From: Sagar Ghuge <ghugesss(a)gmail.com>
+Date: Thu, 23 Feb 2017 19:47:26 -0800
+Subject: [PATCH 1/3] libxl: Implement virDomainObjCheckIsActive
+
+Add function which raises error if domain is
+not active
+
+Signed-off-by: Sagar Ghuge <ghugesss(a)gmail.com>
+---
+ src/conf/domain_conf.c | 15 +++++++++++++++
+ src/conf/domain_conf.h | 1 +
+ 2 files changed, 16 insertions(+)
+
+diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
+index 97d42fe..a44454c 100644
+--- a/src/conf/domain_conf.c
++++ b/src/conf/domain_conf.c
+@@ -2997,6 +2997,21 @@ virDomainObjWait(virDomainObjPtr vm)
+ }
+
+
++int
++virDomainObjCheckIsActive(virDomainObjPtr vm)
++{
++ if (!virDomainObjIsActive(vm)) {
++ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
++ _("domain is not running"));
++ return -1;
++ }
++
++ return 0;
++}
++
++
++
++
+ /**
+ * Waits for domain condition to be triggered for a specific period of time.
+ *
+diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
+index 1e53cc3..cfeb1ba 100644
+--- a/src/conf/domain_conf.h
++++ b/src/conf/domain_conf.h
+@@ -2559,6 +2559,7 @@ bool virDomainObjTaint(virDomainObjPtr obj,
+
+ void virDomainObjBroadcast(virDomainObjPtr vm);
+ int virDomainObjWait(virDomainObjPtr vm);
++int virDomainObjCheckIsActive(virDomainObjPtr vm);
+ int virDomainObjWaitUntil(virDomainObjPtr vm,
+ unsigned long long whenms);
+
+--
+2.9.3
+
diff --git a/0002-change-virDomainObjIsActive-with-virDomainObjCheckIs.patch
b/0002-change-virDomainObjIsActive-with-virDomainObjCheckIs.patch
new file mode 100644
index 0000000..fa82dce
--- /dev/null
+++ b/0002-change-virDomainObjIsActive-with-virDomainObjCheckIs.patch
@@ -0,0 +1,109 @@
+From 2656b5e6e8047e5f23563d6dff4347bba4483e2a Mon Sep 17 00:00:00 2001
+From: Sagar Ghuge <ghugesss(a)gmail.com>
+Date: Thu, 23 Feb 2017 20:40:08 -0800
+Subject: [PATCH 2/3] change virDomainObjIsActive with
+ virDomainObjCheckIsActive
+
+Signed-off-by: Sagar Ghuge <ghugesss(a)gmail.com>
+---
+ src/test/test_driver.c | 35 +++++++----------------------------
+ 1 file changed, 7 insertions(+), 28 deletions(-)
+
+diff --git a/src/test/test_driver.c b/src/test/test_driver.c
+index 5fef3f1..bbcaa44 100644
+--- a/src/test/test_driver.c
++++ b/src/test/test_driver.c
+@@ -1769,11 +1769,8 @@ static int testDomainDestroy(virDomainPtr domain)
+ if (!(privdom = testDomObjFromDomain(domain)))
+ goto cleanup;
+
+- if (!virDomainObjIsActive(privdom)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("domain is not running"));
++ if (virDomainObjCheckIsActive(privdom) < 0)
+ goto cleanup;
+- }
+
+ testDomainShutdownState(domain, privdom, VIR_DOMAIN_SHUTOFF_DESTROYED);
+ event = virDomainEventLifecycleNewFromObj(privdom,
+@@ -1902,11 +1899,8 @@ static int testDomainReboot(virDomainPtr domain,
+ if (!(privdom = testDomObjFromDomain(domain)))
+ goto cleanup;
+
+- if (!virDomainObjIsActive(privdom)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("domain is not running"));
++ if (virDomainObjCheckIsActive(privdom) < 0)
+ goto cleanup;
+- }
+
+ virDomainObjSetState(privdom, VIR_DOMAIN_SHUTDOWN,
+ VIR_DOMAIN_SHUTDOWN_USER);
+@@ -2028,11 +2022,8 @@ testDomainSaveFlags(virDomainPtr domain, const char *path,
+ if (!(privdom = testDomObjFromDomain(domain)))
+ goto cleanup;
+
+- if (!virDomainObjIsActive(privdom)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("domain is not running"));
++ if (virDomainObjCheckIsActive(privdom) < 0)
+ goto cleanup;
+- }
+
+ xml = virDomainDefFormat(privdom->def, privconn->caps,
+ VIR_DOMAIN_DEF_FORMAT_SECURE);
+@@ -2232,11 +2223,8 @@ static int testDomainCoreDumpWithFormat(virDomainPtr domain,
+ if (!(privdom = testDomObjFromDomain(domain)))
+ goto cleanup;
+
+- if (!virDomainObjIsActive(privdom)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("domain is not running"));
++ if (virDomainObjCheckIsActive(privdom) < 0)
+ goto cleanup;
+- }
+
+ if ((fd = open(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
+ virReportSystemError(errno,
+@@ -3126,11 +3114,8 @@ static int testDomainBlockStats(virDomainPtr domain,
+ if (!(privdom = testDomObjFromDomain(domain)))
+ return ret;
+
+- if (!virDomainObjIsActive(privdom)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("domain is not running"));
++ if (virDomainObjCheckIsActive(privdom) < 0)
+ goto error;
+- }
+
+ if (virDomainDiskIndexByName(privdom->def, path, false) < 0) {
+ virReportError(VIR_ERR_INVALID_ARG,
+@@ -3171,11 +3156,8 @@ static int testDomainInterfaceStats(virDomainPtr domain,
+ if (!(privdom = testDomObjFromDomain(domain)))
+ return -1;
+
+- if (!virDomainObjIsActive(privdom)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("domain is not running"));
++ if (virDomainObjCheckIsActive(privdom) < 0)
+ goto error;
+- }
+
+ for (i = 0; i < privdom->def->nnets; i++) {
+ if (privdom->def->nets[i]->ifname &&
+@@ -6065,11 +6047,8 @@ testDomainManagedSave(virDomainPtr dom, unsigned int flags)
+ if (!(vm = testDomObjFromDomain(dom)))
+ return -1;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("domain is not running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto cleanup;
+- }
+
+ if (!vm->persistent) {
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+--
+2.9.3
+
diff --git a/0003-libxl-Change-virDomainObjIsActive-to-virDomainObjChe.patch
b/0003-libxl-Change-virDomainObjIsActive-to-virDomainObjChe.patch
new file mode 100644
index 0000000..5ea8ca7
--- /dev/null
+++ b/0003-libxl-Change-virDomainObjIsActive-to-virDomainObjChe.patch
@@ -0,0 +1,298 @@
+From ff65287895d08018e30e76923011cc1c8668e214 Mon Sep 17 00:00:00 2001
+From: Sagar Ghuge <ghugesss(a)gmail.com>
+Date: Thu, 23 Feb 2017 20:55:35 -0800
+Subject: [PATCH 3/3] libxl: Change virDomainObjIsActive to
+ virDomainObjCheckIsActive
+
+Replace virDomainObjIsActive with virDomainObjCheckIsActive
+which raises error if domain is not active
+
+Signed-off-by: Sagar Ghuge <ghugesss(a)gmail.com>
+---
+ src/libxl/libxl_driver.c | 102 +++++++++++------------------------------------
+ 1 file changed, 23 insertions(+), 79 deletions(-)
+
+diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
+index e5b8f48..7a69215 100644
+--- a/src/libxl/libxl_driver.c
++++ b/src/libxl/libxl_driver.c
+@@ -1183,10 +1183,8 @@ libxlDomainSuspend(virDomainPtr dom)
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto endjob;
+- }
+
+ if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) {
+ if (libxl_domain_pause(cfg->ctx, vm->def->id) != 0) {
+@@ -1239,10 +1237,8 @@ libxlDomainResume(virDomainPtr dom)
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto endjob;
+- }
+
+ if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
+ if (libxl_domain_unpause(cfg->ctx, vm->def->id) != 0) {
+@@ -1297,11 +1293,8 @@ libxlDomainShutdownFlags(virDomainPtr dom, unsigned int flags)
+ if (virDomainShutdownFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("Domain is not running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto cleanup;
+- }
+
+ if (flags & VIR_DOMAIN_SHUTDOWN_PARAVIRT) {
+ ret = libxl_domain_shutdown(cfg->ctx, vm->def->id);
+@@ -1364,11 +1357,8 @@ libxlDomainReboot(virDomainPtr dom, unsigned int flags)
+ if (virDomainRebootEnsureACL(dom->conn, vm->def, flags) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("Domain is not running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto cleanup;
+- }
+
+ if (flags & VIR_DOMAIN_REBOOT_PARAVIRT) {
+ ret = libxl_domain_reboot(cfg->ctx, vm->def->id);
+@@ -1411,11 +1401,8 @@ libxlDomainDestroyFlags(virDomainPtr dom,
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("Domain is not running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto endjob;
+- }
+
+ if (libxlDomainDestroyInternal(driver, vm) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+@@ -1820,10 +1807,8 @@ libxlDomainSaveFlags(virDomainPtr dom, const char *to, const char
*dxml,
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto endjob;
+- }
+
+ if (libxlDoDomainSave(driver, vm, to) < 0)
+ goto endjob;
+@@ -1946,10 +1931,8 @@ libxlDomainCoreDump(virDomainPtr dom, const char *to, unsigned int
flags)
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto endjob;
+- }
+
+ if (!(flags & VIR_DUMP_LIVE) &&
+ virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
+@@ -2043,10 +2026,9 @@ libxlDomainManagedSave(virDomainPtr dom, unsigned int flags)
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto endjob;
+- }
++
+ if (!vm->persistent) {
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("cannot do managed save for transient domain"));
+@@ -2518,10 +2500,8 @@ libxlDomainGetVcpus(virDomainPtr dom, virVcpuInfoPtr info, int
maxinfo,
+ if (virDomainGetVcpusEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto cleanup;
+- }
+
+ if ((vcpuinfo = libxl_list_vcpu(cfg->ctx, vm->def->id, &maxcpu,
+ &hostcpus)) == NULL) {
+@@ -2755,11 +2735,8 @@ libxlDomainCreateWithFlags(virDomainPtr dom,
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
+ goto cleanup;
+
+- if (virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("Domain is already running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto endjob;
+- }
+
+ ret = libxlDomainStartNew(driver, vm,
+ (flags & VIR_DOMAIN_START_PAUSED) != 0);
+@@ -4498,10 +4475,8 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams)
+ if (virDomainGetSchedulerTypeEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto cleanup;
+- }
+
+ sched_id = libxl_get_scheduler(cfg->ctx);
+
+@@ -4562,11 +4537,8 @@ libxlDomainGetSchedulerParametersFlags(virDomainPtr dom,
+ if (virDomainGetSchedulerParametersFlagsEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+- _("Domain is not running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto cleanup;
+- }
+
+ sched_id = libxl_get_scheduler(cfg->ctx);
+
+@@ -4643,10 +4615,8 @@ libxlDomainSetSchedulerParametersFlags(virDomainPtr dom,
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto endjob;
+- }
+
+ sched_id = libxl_get_scheduler(cfg->ctx);
+
+@@ -4712,11 +4682,8 @@ libxlDomainOpenConsole(virDomainPtr dom,
+ if (virDomainOpenConsoleEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("domain is not running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto cleanup;
+- }
+
+ priv = vm->privateData;
+ if (dev_name) {
+@@ -4812,11 +4779,8 @@ libxlDomainGetNumaParameters(virDomainPtr dom,
+ if (virDomainGetNumaParametersEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+- _("Domain is not running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto cleanup;
+- }
+
+ if ((*nparams) == 0) {
+ *nparams = LIBXL_NUMA_NPARAM;
+@@ -4983,11 +4947,8 @@ libxlDomainInterfaceStats(virDomainPtr dom,
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_QUERY) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("domain is not running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto endjob;
+- }
+
+ /* Check the path is one of the domain's network interfaces. */
+ for (i = 0; i < vm->def->nnets; i++) {
+@@ -5111,11 +5072,8 @@ libxlDomainGetCPUStats(virDomainPtr dom,
+ if (virDomainGetCPUStatsEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("domain is not running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto cleanup;
+- }
+
+ if (start_cpu == -1)
+ ret = libxlDomainGetTotalCPUStats(driver, vm, params, nparams);
+@@ -5164,11 +5122,8 @@ libxlDomainMemoryStats(virDomainPtr dom,
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_QUERY) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("domain is not running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto endjob;
+- }
+
+ if (libxl_domain_info(cfg->ctx, &d_info, vm->def->id) != 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+@@ -5528,11 +5483,8 @@ libxlDomainBlockStats(virDomainPtr dom,
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_QUERY) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("domain is not running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto endjob;
+- }
+
+ memset(&blkstats, 0, sizeof(libxlBlockStats));
+ if ((ret = libxlDomainBlockStatsGather(vm, path, &blkstats)) < 0)
+@@ -5581,11 +5533,8 @@ libxlDomainBlockStatsFlags(virDomainPtr dom,
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_QUERY) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("domain is not running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto endjob;
+- }
+
+ /* return count of supported stats */
+ if (*nparams == 0) {
+@@ -5922,9 +5871,7 @@ libxlDomainMigrateBegin3Params(virDomainPtr domain,
+ return NULL;
+ }
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID,
+- "%s", _("domain is not running"));
++ if (virDomainObjCheckIsActive(vm) < 0) {
+ virObjectUnlock(vm);
+ return NULL;
+ }
+@@ -6330,11 +6277,8 @@ libxlDomainInterfaceAddresses(virDomainPtr dom,
+ if (virDomainInterfaceAddressesEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+- _("domain is not running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto cleanup;
+- }
+
+ switch (source) {
+ case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE:
+--
+2.9.3
+
diff --git a/patch1 b/patch1
new file mode 100644
index 0000000..e39c5cd
--- /dev/null
+++ b/patch1
@@ -0,0 +1,52 @@
+diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
+index 1bc72a4..10a69af 100644
+--- a/src/conf/domain_conf.c
++++ b/src/conf/domain_conf.c
+@@ -2995,6 +2995,19 @@ virDomainObjWait(virDomainObjPtr vm)
+ }
+
+
++int
++virDomainObjCheckIsActive(virDomainObjPtr vm)
++{
++ if (!virDomainObjIsActive(vm)) {
++ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
++ _("domain is not running"));
++ return -1;
++ }
++
++ return 0;
++}
++
++
+ /**
+ * Waits for domain condition to be triggered for a specific period of time.
+ *
+diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
+index dd79206..b6c7826 100644
+--- a/src/conf/domain_conf.h
++++ b/src/conf/domain_conf.h
+@@ -2559,6 +2559,7 @@ bool virDomainObjTaint(virDomainObjPtr obj,
+
+ void virDomainObjBroadcast(virDomainObjPtr vm);
+ int virDomainObjWait(virDomainObjPtr vm);
++int virDomainObjCheckIsActive(virDomainObjPtr vm);
+ int virDomainObjWaitUntil(virDomainObjPtr vm,
+ unsigned long long whenms);
+
+diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
+index 74cb05a..3a487ac 100644
+--- a/src/libxl/libxl_driver.c
++++ b/src/libxl/libxl_driver.c
+@@ -1183,10 +1183,8 @@ libxlDomainSuspend(virDomainPtr dom)
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
+ goto cleanup;
+
+- if (!virDomainObjIsActive(vm)) {
+- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
++ if (virDomainObjCheckIsActive(vm) < 0)
+ goto endjob;
+- }
+
+ if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) {
+ if (libxl_domain_pause(cfg->ctx, vm->def->id) != 0) {
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index e5b8f48..7a69215 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -1183,10 +1183,8 @@ libxlDomainSuspend(virDomainPtr dom)
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto endjob;
- }
if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) {
if (libxl_domain_pause(cfg->ctx, vm->def->id) != 0) {
@@ -1239,10 +1237,8 @@ libxlDomainResume(virDomainPtr dom)
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto endjob;
- }
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
if (libxl_domain_unpause(cfg->ctx, vm->def->id) != 0) {
@@ -1297,11 +1293,8 @@ libxlDomainShutdownFlags(virDomainPtr dom, unsigned int flags)
if (virDomainShutdownFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("Domain is not running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto cleanup;
- }
if (flags & VIR_DOMAIN_SHUTDOWN_PARAVIRT) {
ret = libxl_domain_shutdown(cfg->ctx, vm->def->id);
@@ -1364,11 +1357,8 @@ libxlDomainReboot(virDomainPtr dom, unsigned int flags)
if (virDomainRebootEnsureACL(dom->conn, vm->def, flags) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("Domain is not running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto cleanup;
- }
if (flags & VIR_DOMAIN_REBOOT_PARAVIRT) {
ret = libxl_domain_reboot(cfg->ctx, vm->def->id);
@@ -1411,11 +1401,8 @@ libxlDomainDestroyFlags(virDomainPtr dom,
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("Domain is not running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto endjob;
- }
if (libxlDomainDestroyInternal(driver, vm) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1820,10 +1807,8 @@ libxlDomainSaveFlags(virDomainPtr dom, const char *to, const char
*dxml,
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto endjob;
- }
if (libxlDoDomainSave(driver, vm, to) < 0)
goto endjob;
@@ -1946,10 +1931,8 @@ libxlDomainCoreDump(virDomainPtr dom, const char *to, unsigned int
flags)
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto endjob;
- }
if (!(flags & VIR_DUMP_LIVE) &&
virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
@@ -2043,10 +2026,9 @@ libxlDomainManagedSave(virDomainPtr dom, unsigned int flags)
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto endjob;
- }
+
if (!vm->persistent) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot do managed save for transient domain"));
@@ -2518,10 +2500,8 @@ libxlDomainGetVcpus(virDomainPtr dom, virVcpuInfoPtr info, int
maxinfo,
if (virDomainGetVcpusEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto cleanup;
- }
if ((vcpuinfo = libxl_list_vcpu(cfg->ctx, vm->def->id, &maxcpu,
&hostcpus)) == NULL) {
@@ -2755,11 +2735,8 @@ libxlDomainCreateWithFlags(virDomainPtr dom,
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
goto cleanup;
- if (virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("Domain is already running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto endjob;
- }
ret = libxlDomainStartNew(driver, vm,
(flags & VIR_DOMAIN_START_PAUSED) != 0);
@@ -4498,10 +4475,8 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams)
if (virDomainGetSchedulerTypeEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto cleanup;
- }
sched_id = libxl_get_scheduler(cfg->ctx);
@@ -4562,11 +4537,8 @@ libxlDomainGetSchedulerParametersFlags(virDomainPtr dom,
if (virDomainGetSchedulerParametersFlagsEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("Domain is not running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto cleanup;
- }
sched_id = libxl_get_scheduler(cfg->ctx);
@@ -4643,10 +4615,8 @@ libxlDomainSetSchedulerParametersFlags(virDomainPtr dom,
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not
running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto endjob;
- }
sched_id = libxl_get_scheduler(cfg->ctx);
@@ -4712,11 +4682,8 @@ libxlDomainOpenConsole(virDomainPtr dom,
if (virDomainOpenConsoleEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("domain is not running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto cleanup;
- }
priv = vm->privateData;
if (dev_name) {
@@ -4812,11 +4779,8 @@ libxlDomainGetNumaParameters(virDomainPtr dom,
if (virDomainGetNumaParametersEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("Domain is not running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto cleanup;
- }
if ((*nparams) == 0) {
*nparams = LIBXL_NUMA_NPARAM;
@@ -4983,11 +4947,8 @@ libxlDomainInterfaceStats(virDomainPtr dom,
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_QUERY) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("domain is not running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto endjob;
- }
/* Check the path is one of the domain's network interfaces. */
for (i = 0; i < vm->def->nnets; i++) {
@@ -5111,11 +5072,8 @@ libxlDomainGetCPUStats(virDomainPtr dom,
if (virDomainGetCPUStatsEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("domain is not running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto cleanup;
- }
if (start_cpu == -1)
ret = libxlDomainGetTotalCPUStats(driver, vm, params, nparams);
@@ -5164,11 +5122,8 @@ libxlDomainMemoryStats(virDomainPtr dom,
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_QUERY) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("domain is not running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto endjob;
- }
if (libxl_domain_info(cfg->ctx, &d_info, vm->def->id) != 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -5528,11 +5483,8 @@ libxlDomainBlockStats(virDomainPtr dom,
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_QUERY) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("domain is not running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto endjob;
- }
memset(&blkstats, 0, sizeof(libxlBlockStats));
if ((ret = libxlDomainBlockStatsGather(vm, path, &blkstats)) < 0)
@@ -5581,11 +5533,8 @@ libxlDomainBlockStatsFlags(virDomainPtr dom,
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_QUERY) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("domain is not running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto endjob;
- }
/* return count of supported stats */
if (*nparams == 0) {
@@ -5922,9 +5871,7 @@ libxlDomainMigrateBegin3Params(virDomainPtr domain,
return NULL;
}
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("domain is not running"));
+ if (virDomainObjCheckIsActive(vm) < 0) {
virObjectUnlock(vm);
return NULL;
}
@@ -6330,11 +6277,8 @@ libxlDomainInterfaceAddresses(virDomainPtr dom,
if (virDomainInterfaceAddressesEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
- if (!virDomainObjIsActive(vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("domain is not running"));
+ if (virDomainObjCheckIsActive(vm) < 0)
goto cleanup;
- }
switch (source) {
case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE:
--
2.9.3