]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Add new events for *PoolBuild() and *PoolDelete().
authorJulio Faracco <jcfaracco@gmail.com>
Sat, 9 Sep 2017 15:09:49 +0000 (12:09 -0300)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 20 Sep 2017 09:52:56 +0000 (11:52 +0200)
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@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
examples/object-events/event-test.c
include/libvirt/libvirt-storage.h
src/storage/storage_driver.c
src/test/test_driver.c
tests/objecteventtest.c
tools/virsh-pool.c

index 78d200806601dac0eb7e594ed054347fe685ba62..a1446388799e4abca8118938546c04e697bc6c1b 100644 (file)
@@ -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;
     }
index 4517f713c36e73d087ca7edceb7ca8447f30c734..736e2e3b80bde0eb6341be2c4f86b67a243dbb22 100644 (file)
@@ -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
index 7db1f546376f16680bae1814d756d5353c0af434..4096d29701d04f96e568f455a70869ff7d06018a 100644 (file)
@@ -956,6 +956,7 @@ storagePoolBuild(virStoragePoolPtr pool,
 {
     virStoragePoolObjPtr obj;
     virStorageBackendPtr backend;
+    virObjectEventPtr event = NULL;
     int ret = -1;
 
     if (!(obj = virStoragePoolObjFromStoragePool(pool)))
@@ -977,9 +978,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;
 }
@@ -1059,6 +1068,7 @@ storagePoolDelete(virStoragePoolPtr pool,
 {
     virStoragePoolObjPtr obj;
     virStorageBackendPtr backend;
+    virObjectEventPtr event = NULL;
     char *stateFile = NULL;
     int ret = -1;
 
@@ -1103,9 +1113,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;
 }
index aacb513d680c5e70d72d0c789d9a2645ce0324c7..660626406e94c623e7e792380896acc9a5f723e3 100644 (file)
@@ -4584,13 +4584,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;
 }
 
@@ -4675,12 +4682,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;
 }
index 77a48a14957a1f3317fe5be825be868f028e0e03..4b12572eb45b00d350a7a351824bee707dae83ae 100644 (file)
@@ -167,6 +167,10 @@ storagePoolLifecycleCb(virConnectPtr conn ATTRIBUTE_UNUSED,
         counter->defineEvents++;
     else if (event == VIR_STORAGE_POOL_EVENT_UNDEFINED)
         counter->undefineEvents++;
+    else if (event == VIR_STORAGE_POOL_EVENT_CREATED)
+        counter->createdEvents++;
+    else if (event == VIR_STORAGE_POOL_EVENT_DELETED)
+        counter->deletedEvents++;
 }
 
 static void
@@ -722,6 +726,69 @@ testStoragePoolStartStopEvent(const void *data)
     return ret;
 }
 
+static int
+testStoragePoolBuild(const void *data)
+{
+    const objecteventTest *test = data;
+    lifecycleEventCounter counter;
+    int id;
+    int ret = 0;
+
+    lifecycleEventCounter_reset(&counter);
+
+    id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
+                      VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
+                      VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolLifecycleCb),
+                      &counter, NULL);
+
+    virStoragePoolBuild(test->pool, 0);
+
+    if (virEventRunDefaultImpl() < 0) {
+        ret = -1;
+        goto cleanup;
+    }
+
+    if (counter.createdEvents != 1) {
+        ret = -1;
+        goto cleanup;
+    }
+
+ cleanup:
+    virConnectStoragePoolEventDeregisterAny(test->conn, id);
+    return ret;
+}
+
+static int
+testStoragePoolDelete(const void *data)
+{
+    const objecteventTest *test = data;
+    lifecycleEventCounter counter;
+    int id;
+    int ret = 0;
+
+    lifecycleEventCounter_reset(&counter);
+
+    id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
+                      VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
+                      VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolLifecycleCb),
+                      &counter, NULL);
+
+    virStoragePoolDelete(test->pool, 0);
+
+    if (virEventRunDefaultImpl() < 0) {
+        ret = -1;
+        goto cleanup;
+    }
+
+    if (counter.deletedEvents != 1) {
+        ret = -1;
+        goto cleanup;
+    }
+
+ cleanup:
+    virConnectStoragePoolEventDeregisterAny(test->conn, id);
+    return ret;
+}
 static int
 testNodeDeviceCreateXML(const void *data)
 {
@@ -831,6 +898,13 @@ mymain(void)
     if (virTestRun("Storage pool start stop events ",
                    testStoragePoolStartStopEvent, &test) < 0)
         ret = EXIT_FAILURE;
+    /* Storage pool build and delete events */
+    if (virTestRun("Storage pool build event ",
+                   testStoragePoolBuild, &test) < 0)
+        ret = EXIT_FAILURE;
+    if (virTestRun("Storage pool delete event ",
+                   testStoragePoolDelete, &test) < 0)
+        ret = EXIT_FAILURE;
 
     /* Node device event tests */
     if (virTestRun("Node device createXML add event ",
index ba9281fbb914e4648bc8b5481214a7877326d174..558461b3dc440d4320cf3154899aeb9142c6de7d 100644 (file)
@@ -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)