[libvirt] [PATCH 12/13] destroy: Implement internal API for xen driver

Michal Privoznik mprivozn at redhat.com
Thu Jul 21 09:28:39 UTC 2011


---
 src/xen/xen_driver.c     |   28 ++++++++++++++++++++++++++++
 src/xen/xen_driver.h     |    1 +
 src/xen/xen_hypervisor.c |   24 ++++++++++++++++++++++--
 src/xen/xen_hypervisor.h |    3 +++
 src/xen/xen_inotify.c    |    1 +
 src/xen/xend_internal.c  |   24 ++++++++++++++++++++++--
 src/xen/xm_internal.c    |    1 +
 src/xen/xs_internal.c    |    1 +
 8 files changed, 79 insertions(+), 4 deletions(-)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 3b5df46..ce29fc4 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -925,6 +925,33 @@ xenUnifiedDomainDestroy (virDomainPtr dom)
     return -1;
 }
 
+static int
+xenUnifiedDomainDestroyWithFlags(virDomainPtr dom,
+                                 unsigned int flags)
+{
+    GET_PRIVATE(dom->conn);
+    int i;
+
+    virCheckFlags(0, -1);
+
+    /* Try non-hypervisor methods first, then hypervisor direct method
+     * as a last resort.
+     */
+    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
+        if (i != XEN_UNIFIED_HYPERVISOR_OFFSET &&
+            priv->opened[i] &&
+            drivers[i]->domainDestroyWithFlags &&
+            drivers[i]->domainDestroyWithFlags(dom) == 0)
+            return 0;
+
+    if (priv->opened[XEN_UNIFIED_HYPERVISOR_OFFSET] &&
+        drivers[XEN_UNIFIED_HYPERVISOR_OFFSET]->domainDestroyWithFlags&&
+        drivers[XEN_UNIFIED_HYPERVISOR_OFFSET]->domainDestroyWithFlags(dom) == 0)
+        return 0;
+
+    return -1;
+}
+
 static char *
 xenUnifiedDomainGetOSType (virDomainPtr dom)
 {
@@ -2205,6 +2232,7 @@ static virDriver xenUnifiedDriver = {
     .domainShutdown = xenUnifiedDomainShutdown, /* 0.0.3 */
     .domainReboot = xenUnifiedDomainReboot, /* 0.1.0 */
     .domainDestroy = xenUnifiedDomainDestroy, /* 0.0.3 */
+    .domainDestroyWithFlags = xenUnifiedDomainDestroyWithFlags, /* 0.9.4 */
     .domainGetOSType = xenUnifiedDomainGetOSType, /* 0.0.3 */
     .domainGetMaxMemory = xenUnifiedDomainGetMaxMemory, /* 0.0.3 */
     .domainSetMaxMemory = xenUnifiedDomainSetMaxMemory, /* 0.0.3 */
diff --git a/src/xen/xen_driver.h b/src/xen/xen_driver.h
index a6fe475..1f9c17a 100644
--- a/src/xen/xen_driver.h
+++ b/src/xen/xen_driver.h
@@ -95,6 +95,7 @@ struct xenUnifiedDriver {
         virDrvDomainShutdown		domainShutdown;
         virDrvDomainReboot		domainReboot;
         virDrvDomainDestroy		domainDestroy;
+        virDrvDomainDestroyWithFlags domainDestroyWithFlags;
         virDrvDomainGetOSType		domainGetOSType;
         virDrvDomainGetMaxMemory	domainGetMaxMemory;
         virDrvDomainSetMaxMemory	domainSetMaxMemory;
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index 543dfb1..e9920d2 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -816,6 +816,7 @@ struct xenUnifiedDriver xenHypervisorDriver = {
     NULL, /* domainShutdown */
     NULL, /* domainReboot */
     xenHypervisorDestroyDomain, /* domainDestroy */
+    xenHypervisorDestroyDomainWithFlags, /* domainDestroyWithFlags */
     xenHypervisorDomainGetOSType, /* domainGetOSType */
     xenHypervisorGetMaxMemory, /* domainGetMaxMemory */
     xenHypervisorSetMaxMemory, /* domainSetMaxMemory */
@@ -3433,19 +3434,26 @@ xenHypervisorResumeDomain(virDomainPtr domain)
 }
 
 /**
- * xenHypervisorDestroyDomain:
+ * xenHypervisorDestroyDomainWithFlags:
  * @domain: pointer to the domain block
+ * @flags: an OR'ed set of virDomainDestroyFlags
  *
  * Do an hypervisor call to destroy the given domain
  *
+ * Calling this function with no @flags set (equal zero
+ * is equivalent calling xenHypervisorDestroyDomain.
+ *
  * Returns 0 in case of success, -1 in case of error.
  */
 int
-xenHypervisorDestroyDomain(virDomainPtr domain)
+xenHypervisorDestroyDomainWithFlags(virDomainPtr domain,
+                                    unsigned int flags)
 {
     int ret;
     xenUnifiedPrivatePtr priv;
 
+    virCheckFlags(0, -1);
+
     if (domain->conn == NULL)
         return -1;
 
@@ -3460,6 +3468,18 @@ xenHypervisorDestroyDomain(virDomainPtr domain)
 }
 
 /**
+ * xenHypervisorDestroyDomain:
+ * @domain: pointer to the domain block
+ *
+ * See xenHypervisorDestroyDomainWithFlags
+ */
+int
+xenHypervisorDestroyDomain(virDomainPtr domain)
+{
+    return xenHypervisorDestroyDomainWithFlags(domain, 0);
+}
+
+/**
  * xenHypervisorSetMaxMemory:
  * @domain: pointer to the domain block
  * @memory: the max memory size in kilobytes.
diff --git a/src/xen/xen_hypervisor.h b/src/xen/xen_hypervisor.h
index d522d5b..d838ae8 100644
--- a/src/xen/xen_hypervisor.h
+++ b/src/xen/xen_hypervisor.h
@@ -59,6 +59,9 @@ int     xenHypervisorGetMaxVcpus        (virConnectPtr conn,
                                          const char *type);
 int     xenHypervisorDestroyDomain      (virDomainPtr domain)
           ATTRIBUTE_NONNULL (1);
+int     xenHypervisorDestroyDomainWithFlags(virDomainPtr domain,
+                                            unsigned int flags)
+          ATTRIBUTE_NONNULL (1);
 int     xenHypervisorResumeDomain       (virDomainPtr domain)
           ATTRIBUTE_NONNULL (1);
 int     xenHypervisorPauseDomain        (virDomainPtr domain)
diff --git a/src/xen/xen_inotify.c b/src/xen/xen_inotify.c
index 241dbc7..98f3081 100644
--- a/src/xen/xen_inotify.c
+++ b/src/xen/xen_inotify.c
@@ -63,6 +63,7 @@ struct xenUnifiedDriver xenInotifyDriver = {
     NULL, /* domainShutdown */
     NULL, /* domainReboot */
     NULL, /* domainDestroy */
+    NULL, /* domainDestroyWithFlags */
     NULL, /* domainGetOSType */
     NULL, /* domainGetMaxMemory */
     NULL, /* domainSetMaxMemory */
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index dec8484..b295035 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -1509,8 +1509,9 @@ xenDaemonDomainReboot(virDomainPtr domain, unsigned int flags)
 }
 
 /**
- * xenDaemonDomainDestroy:
+ * xenDaemonDomainDestroyWithFlags:
  * @domain: pointer to the Domain block
+ * @flags: an OR'ed set of virDomainDestroyFlags
  *
  * Abruptly halt the domain, the OS is not properly shutdown and the
  * resources allocated for the domain are immediately freed, mounted
@@ -1519,11 +1520,17 @@ xenDaemonDomainReboot(virDomainPtr domain, unsigned int flags)
  * dying and will go away completely once all of the resources have been
  * unmapped (usually from the backend devices).
  *
+ * Calling this function with no @flags set (equal zero)
+ * is equivalent calling xenDaemonDomainDestroy.
+ *
  * Returns 0 in case of success, -1 (with errno) in case of error.
  */
 int
-xenDaemonDomainDestroy(virDomainPtr domain)
+xenDaemonDomainDestroyWithFlags(virDomainPtr domain,
+                                unsigned int flags)
 {
+    virCheckFlags(0, -1);
+
     if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
         virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return(-1);
@@ -1539,6 +1546,18 @@ xenDaemonDomainDestroy(virDomainPtr domain)
 }
 
 /**
+ * xenDaemonDomainDestroy:
+ * @domain: pointer to the Domain block
+ *
+ * See xenDaemonDomainDestroyWithFlags
+ */
+int
+xenDaemonDomainDestroy(virDomainPtr dom)
+{
+    return xenDaemonDomainDestroyWithFlags(dom, 0);
+}
+
+/**
  * xenDaemonDomainGetOSType:
  * @domain: a domain object
  *
@@ -3941,6 +3960,7 @@ struct xenUnifiedDriver xenDaemonDriver = {
     xenDaemonDomainShutdown,     /* domainShutdown */
     xenDaemonDomainReboot,       /* domainReboot */
     xenDaemonDomainDestroy,      /* domainDestroy */
+    xenDaemonDomainDestroyWithFlags,  /* domainDestroyWithFlags */
     xenDaemonDomainGetOSType,    /* domainGetOSType */
     xenDaemonDomainGetMaxMemory, /* domainGetMaxMemory */
     xenDaemonDomainSetMaxMemory, /* domainSetMaxMemory */
diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index 6ec295e..b907ade 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -95,6 +95,7 @@ struct xenUnifiedDriver xenXMDriver = {
     NULL, /* domainShutdown */
     NULL, /* domainReboot */
     NULL, /* domainDestroy */
+    NULL, /* domainDestroyWithFlags */
     NULL, /* domainGetOSType */
     xenXMDomainGetMaxMemory, /* domainGetMaxMemory */
     xenXMDomainSetMaxMemory, /* domainSetMaxMemory */
diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c
index f62d716..ddd51fa 100644
--- a/src/xen/xs_internal.c
+++ b/src/xen/xs_internal.c
@@ -56,6 +56,7 @@ struct xenUnifiedDriver xenStoreDriver = {
     xenStoreDomainShutdown, /* domainShutdown */
     xenStoreDomainReboot, /* domainReboot */
     NULL, /* domainDestroy */
+    NULL, /* domainDestroyWithFlags */
     xenStoreDomainGetOSType, /* domainGetOSType */
     xenStoreDomainGetMaxMemory, /* domainGetMaxMemory */
     NULL, /* domainSetMaxMemory */
-- 
1.7.5.rc3




More information about the libvir-list mailing list