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

[libvirt] [PATCH 04/10] linkstate: Implementation of the public API



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

diff --git a/src/libvirt.c b/src/libvirt.c
index c8af3e1..53b7a11 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -6421,6 +6421,128 @@ error:
 }

 /**
+ * virDomainInterfaceLinkSetState:
+ * @dom: pointer to the domain object
+ * @path: interface identification (MAC Address)
+ * @state: state of the link to be set (one of virInterfaceLinkStates)
+ * @flags: bitwise OR of virDomainModificationImpact
+ *
+ * This function sets a new link state for the interface.
+ * This function requires privileged access to the hypervisor.
+ *
+ * The path parameter is the name of the network interface.
+ *
+ * @flags may include VIR_DOMAIN_AFFECT_LIVE or VIR_DOMAIN_AFFECT_CONFIG.
+ * Both flags may be set. If VIR_DOMAIN_AFFECT_LIVE is set, the change
+ * affects a running domain and will fail if domain is not active.
+ * If VIR_DOMAIN_AFFECT_CONFIG is set, the change affects persistent state,
+ * and will fail for transient domains.
+ * If neither flag is specified (that is, @flags is VIR_DOMAIN_AFFECT_CURRENT),
+ * then an inactive domain modifies persistent setup, while an active domain is
+ * hypervisor-dependent on whether just live or both live and persistent state
+ * is changed.
+ *
+ * Returns: 0 in case of success or -1 in case of failure.
+ */
+int
+virDomainInterfaceLinkSetState(virDomainPtr dom, const char *path,
+                               unsigned int state, unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(dom, "path=%s, state=%u flags=%X",
+                     path, state, flags);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECTED_DOMAIN (dom)) {
+        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+    if (!path ||
+        !(state == VIR_LINK_STATE_UP || state == VIR_LINK_STATE_DOWN)) {
+        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto error;
+    }
+    if (dom->conn->flags & VIR_CONNECT_RO) {
+        virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        goto error;
+    }
+
+    conn = dom->conn;
+
+    if (conn->driver->domainInterfaceLinkSetState) {
+        if (conn->driver->domainInterfaceLinkSetState (dom, path, state, flags) == -1)
+            goto error;
+
+        return 0;
+    }
+
+    virLibDomainError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(dom->conn);
+    return -1;
+}
+
+/**
+ * virDomainInterfaceLinkGetState:
+ * @dom: pointer to the domain object
+ * @path: interface identification (MAC Address)
+ * @flags: one of virDomainModificationImpact
+ *
+ * This function gets link state for the interface. Current state for a running
+ * domain and persistent state for a inactive domain.
+ *
+ * If @flags includes VIR_DOMAIN_AFFECT_LIVE, this will query a
+ * running domain (which will fail if domain is not active);
+ * if it includes VIR_DOMAIN_AFFECT_CONFIG, this will query
+ * the XML description of the domain. It is an error to set
+ * both flags. If neither flag is set (that is, VIR_DOMAIN_AFFECT_CURRENT),
+ * then the configuration queried depends on whether the domain
+ * is currently running.
+ *
+ * Returns: One of virInterfaceLinkStates on success or -1 in case of failure.
+ */
+int
+virDomainInterfaceLinkGetState(virDomainPtr dom, const char *path,
+                               unsigned int flags)
+{
+    virConnectPtr conn;
+    int ret = -1;
+
+    VIR_DOMAIN_DEBUG(dom, "path=%s, flags=%X",
+                     path, flags);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECTED_DOMAIN (dom)) {
+        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+    if (!path) {
+        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto error;
+    }
+    conn = dom->conn;
+
+    if (conn->driver->domainInterfaceLinkGetState) {
+        if ((ret=conn->driver->domainInterfaceLinkGetState (dom, path, flags)) == -1)
+            goto error;
+
+        return ret;
+    }
+
+    virLibDomainError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(dom->conn);
+    return ret;
+}
+
+/**
  * virDomainMemoryStats:
  * @dom: pointer to the domain object
  * @stats: nr_stats-sized array of stat structures (returned)
-- 
1.7.6


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