From ea92a34d1d7d681d9f25dc3348513889b28cbfb5 Mon Sep 17 00:00:00 2001
From: Osier Yang <jyang@redhat.com>
Date: Fri, 19 Aug 2011 21:48:47 +0800
Subject: [PATCH] openvz: Allow to undefine a running domain

---
 src/openvz/openvz_driver.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index b9dc712056..69ff44436e 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -1132,19 +1132,18 @@ openvzDomainUndefineFlags(virDomainPtr dom,
     if (openvzGetVEStatus(vm, &status, NULL) == -1)
         goto cleanup;
 
-    if (status != VIR_DOMAIN_SHUTOFF) {
-        openvzError(VIR_ERR_OPERATION_INVALID, "%s",
-                    _("cannot delete active domain"));
-        goto cleanup;
-    }
-
     openvzSetProgramSentinal(prog, vm->def->name);
     if (virRun(prog, NULL) < 0) {
         goto cleanup;
     }
 
-    virDomainRemoveInactive(&driver->domains, vm);
-    vm = NULL;
+    if (virDomainObjIsActive(vm)) {
+        vm->persistent = 0;
+    } else {
+        virDomainRemoveInactive(&driver->domains, vm);
+        vm = NULL;
+    }
+
     ret = 0;
 
 cleanup: