[libvirt] [PATCH 3/8] virDomainGetState public API implementation

Jiri Denemark jdenemar at redhat.com
Wed May 4 14:45:04 UTC 2011


---
 src/libvirt.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index e74e977..5cd20ce 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -3173,6 +3173,53 @@ error:
 }
 
 /**
+ * virDomainGetState:
+ * @domain: a domain object
+ * @state: returned state of the domain (one of virDomainState)
+ * @reason: returned reason which led to @state (one of virDomain*Reason
+ * corresponding to the current state); it is allowed to be NULL
+ *
+ * Extract domain state. Each state can be accompanied with a reason (if known)
+ * which led to the state.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virDomainGetState(virDomainPtr domain, int *state, int *reason)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain, "state=%p, reason=%p", state, reason);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+    if (!state) {
+        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto error;
+    }
+
+    conn = domain->conn;
+    if (conn->driver->domainGetState) {
+        int ret;
+        ret = conn->driver->domainGetState(domain, state, reason);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(domain->conn);
+    return -1;
+}
+
+/**
  * virDomainGetXMLDesc:
  * @domain: a domain object
  * @flags: an OR'ed set of virDomainXMLFlags
-- 
1.7.5.rc3




More information about the libvir-list mailing list