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

[libvirt] [RFC][PATCH 3/7] interface: implement the public APIs



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

diff --git a/src/libvirt.c b/src/libvirt.c
index abacf85..d9b659d 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -7481,6 +7481,135 @@ virInterfaceFree(virInterfacePtr iface)
     return 0;
 }
 
+/**
+ * virInterfaceChangeStart:
+ * @conn: pointer to hypervisor connection
+ * @flags: flags, not used yet
+ *
+ * This functions creates a restore point to which one can return
+ * later by calling virInterfaceChangeRollback. This function should
+ * be called before any transaction with interface configuration.
+ * Once knowing, new configuration works, it can be commited via
+ * virInterfaceChangeCommit, which frees restore point.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virInterfaceChangeStart(virConnectPtr conn, unsigned int flags)
+{
+    int ret = -1;
+
+    VIR_DEBUG("conn=%p, flags=%d", conn, flags);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        goto end;
+    }
+
+    if (conn->flags & VIR_CONNECT_RO) {
+        virLibInterfaceError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        virDispatchError(conn);
+        goto end;
+    }
+
+    if (conn->interfaceDriver && conn->interfaceDriver->interfaceChangeStart) {
+        ret = conn->interfaceDriver->interfaceChangeStart(conn, flags);
+    } else {
+        virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+    }
+
+end:
+    VIR_DEBUG("returning: %d", ret);
+    return ret;
+}
+
+/**
+ * virInterfaceChangeCommit:
+ * @conn: pointer to hypervisor connection
+ * @flags: flags, not used yet
+ *
+ * This commits the changes made to interfaces and frees restore point
+ * created by virInterfaceChangeStart.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virInterfaceChangeCommit(virConnectPtr conn, unsigned int flags)
+{
+    int ret = -1;
+
+    VIR_DEBUG("conn=%p, flags=%d", conn, flags);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        goto end;
+    }
+
+    if (conn->flags & VIR_CONNECT_RO) {
+        virLibInterfaceError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        virDispatchError(conn);
+        goto end;
+    }
+
+    if (conn->interfaceDriver && conn->interfaceDriver->interfaceChangeCommit) {
+        ret = conn->interfaceDriver->interfaceChangeCommit(conn, flags);
+    } else {
+        virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+    }
+
+end:
+    VIR_DEBUG("returning: %d", ret);
+    return ret;
+}
+
+/**
+ * virInterfaceChangeRollback:
+ * @conn: pointer to hypervisor connection
+ * @flags: flags, not used yet
+ *
+ * This cancels changes made to interfaces settings by restoring previous
+ * state created by virInterfaceChangeStart.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virInterfaceChangeRollback(virConnectPtr conn, unsigned int flags)
+{
+    int ret = -1;
+
+    VIR_DEBUG("conn=%p, flags=%d", conn, flags);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        goto end;
+    }
+
+    if (conn->flags & VIR_CONNECT_RO) {
+        virLibInterfaceError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        virDispatchError(conn);
+        goto end;
+    }
+
+    if (conn->interfaceDriver &&
+        conn->interfaceDriver->interfaceChangeRollback) {
+        ret = conn->interfaceDriver->interfaceChangeRollback(conn, flags);
+    } else {
+         virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+    }
+
+end:
+    VIR_DEBUG("returning: %d", ret);
+    return ret;
+}
 
 /**
  * virStoragePoolGetConnect:
-- 
1.7.5.rc3


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