]> xenbits.xensource.com Git - libvirt.git/commitdiff
destroy: Implement internal API for xen driver
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 21 Jul 2011 08:19:59 +0000 (10:19 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 21 Jul 2011 18:41:27 +0000 (20:41 +0200)
src/xen/xen_driver.c
src/xen/xen_driver.h
src/xen/xen_hypervisor.c
src/xen/xen_hypervisor.h
src/xen/xen_inotify.c
src/xen/xend_internal.c
src/xen/xm_internal.c
src/xen/xs_internal.c

index 7e3ef775823d84c010a9e794c99e9d1835c5820a..2a2a94e67d1041766c7a3c25cc1e1d6da901cbc5 100644 (file)
@@ -925,6 +925,33 @@ xenUnifiedDomainDestroy (virDomainPtr dom)
     return -1;
 }
 
+static int
+xenUnifiedDomainDestroyFlags(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]->domainDestroyFlags &&
+            drivers[i]->domainDestroyFlags(dom) == 0)
+            return 0;
+
+    if (priv->opened[XEN_UNIFIED_HYPERVISOR_OFFSET] &&
+        drivers[XEN_UNIFIED_HYPERVISOR_OFFSET]->domainDestroyFlags&&
+        drivers[XEN_UNIFIED_HYPERVISOR_OFFSET]->domainDestroyFlags(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 */
+    .domainDestroyFlags = xenUnifiedDomainDestroyFlags, /* 0.9.4 */
     .domainGetOSType = xenUnifiedDomainGetOSType, /* 0.0.3 */
     .domainGetMaxMemory = xenUnifiedDomainGetMaxMemory, /* 0.0.3 */
     .domainSetMaxMemory = xenUnifiedDomainSetMaxMemory, /* 0.0.3 */
index a6fe4753567611e37be6d6622f13b7147e491abe..21514276ab67fb387f8eb330b9f702cf5dc9ef0d 100644 (file)
@@ -95,6 +95,7 @@ struct xenUnifiedDriver {
         virDrvDomainShutdown           domainShutdown;
         virDrvDomainReboot             domainReboot;
         virDrvDomainDestroy            domainDestroy;
+        virDrvDomainDestroyFlags    domainDestroyFlags;
         virDrvDomainGetOSType          domainGetOSType;
         virDrvDomainGetMaxMemory       domainGetMaxMemory;
         virDrvDomainSetMaxMemory       domainSetMaxMemory;
index 9700471b2d6600f7ae82e95ff82947e3e1ff7e67..9312b0edd39862c90887e54b09b6953ed4a13572 100644 (file)
@@ -816,6 +816,7 @@ struct xenUnifiedDriver xenHypervisorDriver = {
     NULL, /* domainShutdown */
     NULL, /* domainReboot */
     xenHypervisorDestroyDomain, /* domainDestroy */
+    xenHypervisorDestroyDomainFlags, /* domainDestroyFlags */
     xenHypervisorDomainGetOSType, /* domainGetOSType */
     xenHypervisorGetMaxMemory, /* domainGetMaxMemory */
     xenHypervisorSetMaxMemory, /* domainSetMaxMemory */
@@ -3433,19 +3434,26 @@ xenHypervisorResumeDomain(virDomainPtr domain)
 }
 
 /**
- * xenHypervisorDestroyDomain:
+ * xenHypervisorDestroyDomainFlags:
  * @domain: pointer to the domain block
+ * @flags: an OR'ed set of virDomainDestroyFlagsValues
  *
  * Do an hypervisor call to destroy the given domain
  *
+ * Calling this function with no @flags set (equal to zero)
+ * is equivalent to calling xenHypervisorDestroyDomain.
+ *
  * Returns 0 in case of success, -1 in case of error.
  */
 int
-xenHypervisorDestroyDomain(virDomainPtr domain)
+xenHypervisorDestroyDomainFlags(virDomainPtr domain,
+                                unsigned int flags)
 {
     int ret;
     xenUnifiedPrivatePtr priv;
 
+    virCheckFlags(0, -1);
+
     if (domain->conn == NULL)
         return -1;
 
@@ -3459,6 +3467,18 @@ xenHypervisorDestroyDomain(virDomainPtr domain)
     return (0);
 }
 
+/**
+ * xenHypervisorDestroyDomain:
+ * @domain: pointer to the domain block
+ *
+ * See xenHypervisorDestroyDomainFlags
+ */
+int
+xenHypervisorDestroyDomain(virDomainPtr domain)
+{
+    return xenHypervisorDestroyDomainFlags(domain, 0);
+}
+
 /**
  * xenHypervisorSetMaxMemory:
  * @domain: pointer to the domain block
index d522d5bc6290ec19a94998a92689a5cf53a4470c..efdb81bd8b1f281fc59de499c2fc4cbb8cafcafa 100644 (file)
@@ -59,6 +59,9 @@ int     xenHypervisorGetMaxVcpus        (virConnectPtr conn,
                                          const char *type);
 int     xenHypervisorDestroyDomain      (virDomainPtr domain)
           ATTRIBUTE_NONNULL (1);
+int     xenHypervisorDestroyDomainFlags (virDomainPtr domain,
+                                         unsigned int flags)
+          ATTRIBUTE_NONNULL (1);
 int     xenHypervisorResumeDomain       (virDomainPtr domain)
           ATTRIBUTE_NONNULL (1);
 int     xenHypervisorPauseDomain        (virDomainPtr domain)
index 20e54eaf156d0777005bc9405698e9dc7487484a..5c5c56c091734626bbe2526e76e709fcb40baccf 100644 (file)
@@ -63,6 +63,7 @@ struct xenUnifiedDriver xenInotifyDriver = {
     NULL, /* domainShutdown */
     NULL, /* domainReboot */
     NULL, /* domainDestroy */
+    NULL, /* domainDestroyFlags */
     NULL, /* domainGetOSType */
     NULL, /* domainGetMaxMemory */
     NULL, /* domainSetMaxMemory */
index b0e5cb1712519d659890f7d426c9db6a8e2bdf34..7cd6868cf6c0fef7deb947031c6de52b3ff6a927 100644 (file)
@@ -1509,8 +1509,9 @@ xenDaemonDomainReboot(virDomainPtr domain, unsigned int flags)
 }
 
 /**
- * xenDaemonDomainDestroy:
+ * xenDaemonDomainDestroyFlags:
  * @domain: pointer to the Domain block
+ * @flags: an OR'ed set of virDomainDestroyFlagsValues
  *
  * 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 to zero)
+ * is equivalent to calling xenDaemonDomainDestroy.
+ *
  * Returns 0 in case of success, -1 (with errno) in case of error.
  */
 int
-xenDaemonDomainDestroy(virDomainPtr domain)
+xenDaemonDomainDestroyFlags(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);
@@ -1538,6 +1545,18 @@ xenDaemonDomainDestroy(virDomainPtr domain)
     return xend_op(domain->conn, domain->name, "op", "destroy", NULL);
 }
 
+/**
+ * xenDaemonDomainDestroy:
+ * @domain: pointer to the Domain block
+ *
+ * See xenDaemonDomainDestroyFlags
+ */
+int
+xenDaemonDomainDestroy(virDomainPtr dom)
+{
+    return xenDaemonDomainDestroyFlags(dom, 0);
+}
+
 /**
  * xenDaemonDomainGetOSType:
  * @domain: a domain object
@@ -3941,6 +3960,7 @@ struct xenUnifiedDriver xenDaemonDriver = {
     xenDaemonDomainShutdown,     /* domainShutdown */
     xenDaemonDomainReboot,       /* domainReboot */
     xenDaemonDomainDestroy,      /* domainDestroy */
+    xenDaemonDomainDestroyFlags, /* domainDestroyFlags */
     xenDaemonDomainGetOSType,    /* domainGetOSType */
     xenDaemonDomainGetMaxMemory, /* domainGetMaxMemory */
     xenDaemonDomainSetMaxMemory, /* domainSetMaxMemory */
index 6ec295e3b0ac695991206f28ce8c802a27f4445b..7929393b02c8fcb2f6d5bfadb986662d20e4fb87 100644 (file)
@@ -95,6 +95,7 @@ struct xenUnifiedDriver xenXMDriver = {
     NULL, /* domainShutdown */
     NULL, /* domainReboot */
     NULL, /* domainDestroy */
+    NULL, /* domainDestroyFlags */
     NULL, /* domainGetOSType */
     xenXMDomainGetMaxMemory, /* domainGetMaxMemory */
     xenXMDomainSetMaxMemory, /* domainSetMaxMemory */
index f62d7161bf2c98e37739b4f559510ee04f51b7f1..a08187d5940594a0cc7a70d0f77229a7c9c3fd74 100644 (file)
@@ -56,6 +56,7 @@ struct xenUnifiedDriver xenStoreDriver = {
     xenStoreDomainShutdown, /* domainShutdown */
     xenStoreDomainReboot, /* domainReboot */
     NULL, /* domainDestroy */
+    NULL, /* domainDestroyFlags */
     xenStoreDomainGetOSType, /* domainGetOSType */
     xenStoreDomainGetMaxMemory, /* domainGetMaxMemory */
     NULL, /* domainSetMaxMemory */