On Mon, May 09, 2011 at 09:28:53PM +0200, Michal Privoznik wrote:
---
src/test/test_driver.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 113 insertions(+), 3 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 83dcf1a..9ae6e7a 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -85,6 +85,8 @@ struct _testConn {
virDomainObjList domains;
virNetworkObjList networks;
virInterfaceObjList ifaces;
+ int transaction_running:1;
Or a 'bool'
+ virInterfaceObjList backupIfaces;
virStoragePoolObjList pools;
virNodeDeviceObjList devs;
int numCells;
@@ -3433,6 +3435,114 @@ cleanup:
return ret;
}
+static int testInterfaceChangeStart(virConnectPtr conn,
+ unsigned int flags ATTRIBUTE_UNUSED)
+{
+ testConnPtr privconn = conn->privateData;
+ int ret = -1;
+ unsigned int i, cnt;
+
+ testDriverLock(privconn);
+ if (privconn->transaction_running) {
+ testError(VIR_ERR_OPERATION_INVALID, _("there is another change "
+ "running."));
+ goto cleanup;
+ }
I think we should refer to it as 'transaction' not 'change'.
+
+ privconn->transaction_running = 1;
+
+ cnt = privconn->ifaces.count;
+ for (i = 0; i < cnt; i++) {
+ virInterfaceDefPtr def = privconn->ifaces.objs[i]->def;
+ virInterfaceDefPtr backup;
+ virInterfaceObjPtr iface;
+ char *xml = virInterfaceDefFormat(def);
+
+ if (!xml) {
+ virReportOOMError();
+ goto no_memory;
+ }
+
+ if ((backup = virInterfaceDefParseString(xml)) == NULL) {
+ VIR_FREE(xml);
+ goto cleanup;
+ }
+
+ if ((iface =
+ virInterfaceAssignDef(&privconn->backupIfaces, backup)) == NULL) {
+ VIR_FREE(xml);
+ goto cleanup;
+ }
+
+ virInterfaceObjUnlock(iface);
+
+ conn->refs++;
+
+ VIR_FREE(xml);
+ }
Perhaps in src/conf/interface_conf.c add a method
virInterfaceObjListClone()
to contain this code.
+
+ ret = 0;
+cleanup:
+ testDriverUnlock(privconn);
+ return ret;
+no_memory:
+ virInterfaceObjListFree(&privconn->backupIfaces);
+ goto cleanup;
+}
+
+static int testInterfaceChangeCommit(virConnectPtr conn,
+ unsigned int flags ATTRIBUTE_UNUSED)
+{
+ testConnPtr privconn = conn->privateData;
+ int ret = -1;
+
+ testDriverLock(privconn);
+
+ if (!privconn->transaction_running) {
+ testError(VIR_ERR_OPERATION_INVALID, _("no transaction running, "
+ "nothing to be commited."));
+ goto cleanup;
+ }
+
+ virInterfaceObjListFree(&privconn->backupIfaces);
+ privconn->transaction_running = 0;
+
+ ret = 0;
+
+cleanup:
+ testDriverUnlock(privconn);
+
+ return ret;
+}
+
+static int testInterfaceChangeRollback(virConnectPtr conn,
+ unsigned int flags ATTRIBUTE_UNUSED)
+{
+ testConnPtr privconn = conn->privateData;
+ int ret = -1;
+
+ testDriverLock(privconn);
+
+ if (!privconn->transaction_running) {
+ testError(VIR_ERR_OPERATION_INVALID, _("no transaction running, "
+ "nothing to rollback."));
+ goto cleanup;
+ }
+
+ virInterfaceObjListFree(&privconn->ifaces);
+ privconn->ifaces.count = privconn->backupIfaces.count;
+ privconn->ifaces.objs = privconn->backupIfaces.objs;
+ privconn->backupIfaces.count = 0;
+ privconn->backupIfaces.objs = NULL;
+
+ privconn->transaction_running = 0;
+
+ ret = 0;
+
+cleanup:
+ testDriverUnlock(privconn);
+ return ret;
+}
static char *testInterfaceGetXMLDesc(virInterfacePtr iface,
unsigned int flags ATTRIBUTE_UNUSED)
@@ -5488,9 +5598,9 @@ static virInterfaceDriver testInterfaceDriver = {
testInterfaceCreate, /* interfaceCreate */
testInterfaceDestroy, /* interfaceDestroy */
testInterfaceIsActive, /* interfaceIsActive */
- NULL, /* interfaceChangeStart */
- NULL, /* interfaceChangeCommit */
- NULL, /* interfaceChangeRollback */
+ testInterfaceChangeStart, /* interfaceChangeStart */
+ testInterfaceChangeCommit, /* interfaceChangeCommit */
+ testInterfaceChangeRollback, /* interfaceChangeRollback */
};
Daniel
--
|:
http://berrange.com -o-
http://www.flickr.com/photos/dberrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|:
http://entangle-photo.org -o-
http://live.gnome.org/gtk-vnc :|