[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 01/12] shutdown: Define new public API virDomainShutdownFlags



This introduces new API virDomainShutdownFlags to allow
domain destroying with flags, as the existing API virDomainShutdown
misses flags.

The set of flags is defined in virDomainShutdownFlagsValues enum,
which is currently commented, because it is empty.

Calling this API with no flags set (@flags == 0) is equivalent calling
virDomainShutdown.
---
 include/libvirt/libvirt.h.in |    6 ++++
 src/driver.h                 |    4 +++
 src/libvirt.c                |   54 ++++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms      |    1 +
 4 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 0b7e35f..8785761 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -920,6 +920,10 @@ virConnectPtr           virDomainGetConnect     (virDomainPtr domain);
  * typedef enum {
  * } virDomainDestroyFlagsValues;
  */
+/*
+ * typedef enum{
+ * } virDomainShutdownFlagsValues;
+ */
 virDomainPtr            virDomainCreateXML      (virConnectPtr conn,
                                                  const char *xmlDesc,
                                                  unsigned int flags);
@@ -933,6 +937,8 @@ virDomainPtr            virDomainLookupByUUIDString     (virConnectPtr conn,
                                                         const char *uuid);
 
 int                     virDomainShutdown       (virDomainPtr domain);
+int                     virDomainShutdownFlags  (virDomainPtr domain,
+                                                 unsigned int flags);
 int                     virDomainReboot         (virDomainPtr domain,
                                                  unsigned int flags);
 int                     virDomainDestroy        (virDomainPtr domain);
diff --git a/src/driver.h b/src/driver.h
index 4df5496..e6b057c 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -120,6 +120,9 @@ typedef int
 typedef int
         (*virDrvDomainShutdown)		(virDomainPtr domain);
 typedef int
+        (*virDrvDomainShutdownFlags)    (virDomainPtr domain,
+                                         unsigned int flags);
+typedef int
         (*virDrvDomainReboot)		(virDomainPtr domain,
                                          unsigned int flags);
 typedef int
@@ -712,6 +715,7 @@ struct _virDriver {
     virDrvDomainSuspend		domainSuspend;
     virDrvDomainResume		domainResume;
     virDrvDomainShutdown		domainShutdown;
+    virDrvDomainShutdownFlags   domainShutdownFlags;
     virDrvDomainReboot		domainReboot;
     virDrvDomainDestroy		domainDestroy;
     virDrvDomainDestroyFlags    domainDestroyFlags;
diff --git a/src/libvirt.c b/src/libvirt.c
index 7fb1bc1..a826c7b 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -2756,6 +2756,60 @@ error:
 }
 
 /**
+ * virDomainShutdownFlags:
+ * @domain: a domain object
+ * @flags: an OR'ed set of virDomainShutdownFlagsValues
+ *
+ * Shutdown a domain, the domain object is still usable there after but
+ * the domain OS is being stopped. Note that the guest OS may ignore the
+ * request.
+ *
+ * TODO: should we add an option for reboot, knowing it may not be doable
+ *       in the general case ?
+ *
+ * Calling this function with no @flags set (equal to zero)
+ * is equivalent to calling virDomainShutdown.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virDomainShutdownFlags(virDomainPtr domain,
+                       unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+    if (domain->conn->flags & VIR_CONNECT_RO) {
+        virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        goto error;
+    }
+
+    conn = domain->conn;
+
+    if (conn->driver->domainShutdownFlags) {
+        int ret;
+        ret = conn->driver->domainShutdownFlags(domain, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(domain->conn);
+    return -1;
+}
+
+/**
  * virDomainReboot:
  * @domain: a domain object
  * @flags: extra flags for the reboot operation, not used yet
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 9336df4..a8447d9 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -472,6 +472,7 @@ LIBVIRT_0.9.4 {
         virDomainSaveFlags;
         virDomainUndefineFlags;
         virDomainDestroyFlags;
+        virDomainShutdownFlags;
 } LIBVIRT_0.9.3;
 
 # .... define new API here using predicted next version number ....
-- 
1.7.5.rc3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]