This commit adds new events for two methods and operations: *PoolBuild() and
*PoolDelete(). Using the event-test and the commands set below we have the
following outputs:
$ sudo ./event-test
Registering event callbacks
myStoragePoolEventCallback EVENT: Storage pool test Defined 0
myStoragePoolEventCallback EVENT: Storage pool test Created 0
myStoragePoolEventCallback EVENT: Storage pool test Started 0
myStoragePoolEventCallback EVENT: Storage pool test Stopped 0
myStoragePoolEventCallback EVENT: Storage pool test Deleted 0
myStoragePoolEventCallback EVENT: Storage pool test Undefined 0
Another terminal:
$ sudo virsh pool-define test.xml
Pool test defined from test.xml
$ sudo virsh pool-build test
Pool test built
$ sudo virsh pool-start test
Pool test started
$ sudo virsh pool-destroy test
Pool test destroyed
$ sudo virsh pool-delete test
Pool test deleted
$ sudo virsh pool-undefine test
Pool test has been undefined
This commits can be a solution for RHBZ #1475227.
Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=1475227
Signed-off-by: Julio Faracco <jcfaracco(a)gmail.com>
---
examples/object-events/event-test.c | 4 ++++
include/libvirt/libvirt-storage.h | 2 ++
src/storage/storage_driver.c | 17 +++++++++++++++++
src/test/test_driver.c | 14 ++++++++++++++
tools/virsh-pool.c | 4 +++-
5 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/examples/object-events/event-test.c b/examples/object-events/event-test.c
index 78d2008..a144638 100644
--- a/examples/object-events/event-test.c
+++ b/examples/object-events/event-test.c
@@ -356,6 +356,10 @@ storagePoolEventToString(int event)
return "Started";
case VIR_STORAGE_POOL_EVENT_STOPPED:
return "Stopped";
+ case VIR_STORAGE_POOL_EVENT_CREATED:
+ return "Created";
+ case VIR_STORAGE_POOL_EVENT_DELETED:
+ return "Deleted";
case VIR_STORAGE_POOL_EVENT_LAST:
break;
}
diff --git a/include/libvirt/libvirt-storage.h b/include/libvirt/libvirt-storage.h
index 4517f71..736e2e3 100644
--- a/include/libvirt/libvirt-storage.h
+++ b/include/libvirt/libvirt-storage.h
@@ -465,6 +465,8 @@ typedef enum {
VIR_STORAGE_POOL_EVENT_UNDEFINED = 1,
VIR_STORAGE_POOL_EVENT_STARTED = 2,
VIR_STORAGE_POOL_EVENT_STOPPED = 3,
+ VIR_STORAGE_POOL_EVENT_CREATED = 4,
+ VIR_STORAGE_POOL_EVENT_DELETED = 5,
# ifdef VIR_ENUM_SENTINELS
VIR_STORAGE_POOL_EVENT_LAST
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 7cf5943..5e50415 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -959,6 +959,7 @@ storagePoolBuild(virStoragePoolPtr pool,
{
virStoragePoolObjPtr obj;
virStorageBackendPtr backend;
+ virObjectEventPtr event = NULL;
int ret = -1;
if (!(obj = virStoragePoolObjFromStoragePool(pool)))
@@ -980,9 +981,17 @@ storagePoolBuild(virStoragePoolPtr pool,
if (backend->buildPool &&
backend->buildPool(pool->conn, obj, flags) < 0)
goto cleanup;
+
+ event = virStoragePoolEventLifecycleNew(obj->def->name,
+ obj->def->uuid,
+ VIR_STORAGE_POOL_EVENT_CREATED,
+ 0);
+
ret = 0;
cleanup:
+ if (event)
+ virObjectEventStateQueue(driver->storageEventState, event);
virStoragePoolObjUnlock(obj);
return ret;
}
@@ -1062,6 +1071,7 @@ storagePoolDelete(virStoragePoolPtr pool,
{
virStoragePoolObjPtr obj;
virStorageBackendPtr backend;
+ virObjectEventPtr event = NULL;
char *stateFile = NULL;
int ret = -1;
@@ -1106,9 +1116,16 @@ storagePoolDelete(virStoragePoolPtr pool,
if (backend->deletePool(pool->conn, obj, flags) < 0)
goto cleanup;
+ event = virStoragePoolEventLifecycleNew(obj->def->name,
+ obj->def->uuid,
+ VIR_STORAGE_POOL_EVENT_DELETED,
+ 0);
+
ret = 0;
cleanup:
+ if (event)
+ virObjectEventStateQueue(driver->storageEventState, event);
virStoragePoolObjUnlock(obj);
return ret;
}
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index aa38f54..0a2cde7 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -4562,13 +4562,20 @@ testStoragePoolBuild(virStoragePoolPtr pool,
{
testDriverPtr privconn = pool->conn->privateData;
virStoragePoolObjPtr obj;
+ virObjectEventPtr event = NULL;
virCheckFlags(0, -1);
if (!(obj = testStoragePoolObjFindInactiveByName(privconn, pool->name)))
return -1;
+ event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid,
+ VIR_STORAGE_POOL_EVENT_CREATED,
+ 0);
+
virStoragePoolObjUnlock(obj);
+
+ testObjectEventQueue(privconn, event);
return 0;
}
@@ -4653,12 +4660,19 @@ testStoragePoolDelete(virStoragePoolPtr pool,
{
testDriverPtr privconn = pool->conn->privateData;
virStoragePoolObjPtr obj;
+ virObjectEventPtr event = NULL;
virCheckFlags(0, -1);
if (!(obj = testStoragePoolObjFindInactiveByName(privconn, pool->name)))
return -1;
+ event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid,
+ VIR_STORAGE_POOL_EVENT_DELETED,
+ 0);
+
+ testObjectEventQueue(privconn, event);
+
virStoragePoolObjUnlock(obj);
return 0;
}
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index ba9281f..558461b 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -1952,7 +1952,9 @@ VIR_ENUM_IMPL(virshPoolEvent,
N_("Defined"),
N_("Undefined"),
N_("Started"),
- N_("Stopped"))
+ N_("Stopped"),
+ N_("Created"),
+ N_("Deleted"))
static const char *
virshPoolEventToString(int event)
--
2.7.4