]> xenbits.xensource.com Git - libvirt.git/commitdiff
Promote storage pool refresh lifecycle event to top level event
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 24 Jun 2016 16:35:51 +0000 (17:35 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 24 Jun 2016 17:26:11 +0000 (18:26 +0100)
The VIR_STORAGE_POOL_EVENT_REFRESHED constant does not
reflect any change in the lifecycle of the storage pool.

It should thus not be part of the storage pool lifecycle
event set, but rather be a top level event in its own
right. Thus we introduce VIR_STORAGE_POOL_EVENT_ID_REFRESH
to replace it.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 files changed:
daemon/remote.c
examples/object-events/event-test.c
include/libvirt/libvirt-storage.h
src/conf/storage_event.c
src/conf/storage_event.h
src/libvirt_private.syms
src/remote/remote_driver.c
src/remote/remote_protocol.x
src/remote_protocol-structs
src/storage/storage_driver.c
src/test/test_driver.c
tests/objecteventtest.c
tools/virsh-pool.c

index 5ee82bb30e144835abc4a8e8a8dfb1bdf69b9db7..4aa43c22395e1ccc7f8d70d2d118d1496876adc5 100644 (file)
@@ -1294,8 +1294,37 @@ remoteRelayStoragePoolEventLifecycle(virConnectPtr conn,
     return 0;
 }
 
+static int
+remoteRelayStoragePoolEventRefresh(virConnectPtr conn,
+                                   virStoragePoolPtr pool,
+                                   void *opaque)
+{
+    daemonClientEventCallbackPtr callback = opaque;
+    remote_storage_pool_event_refresh_msg data;
+
+    if (callback->callbackID < 0 ||
+        !remoteRelayStoragePoolEventCheckACL(callback->client, conn, pool))
+        return -1;
+
+    VIR_DEBUG("Relaying storage pool refresh event callback %d",
+              callback->callbackID);
+
+    /* build return data */
+    memset(&data, 0, sizeof(data));
+    make_nonnull_storage_pool(&data.pool, pool);
+    data.callbackID = callback->callbackID;
+
+    remoteDispatchObjectEventSend(callback->client, remoteProgram,
+                                  REMOTE_PROC_STORAGE_POOL_EVENT_REFRESH,
+                                  (xdrproc_t)xdr_remote_storage_pool_event_refresh_msg,
+                                  &data);
+
+    return 0;
+}
+
 static virConnectStoragePoolEventGenericCallback storageEventCallbacks[] = {
     VIR_STORAGE_POOL_EVENT_CALLBACK(remoteRelayStoragePoolEventLifecycle),
+    VIR_STORAGE_POOL_EVENT_CALLBACK(remoteRelayStoragePoolEventRefresh),
 };
 
 verify(ARRAY_CARDINALITY(storageEventCallbacks) == VIR_STORAGE_POOL_EVENT_ID_LAST);
index 215e02625305ce22f862053c082a9eeec8c62c41..f2f71cc32c052e5248b1be7bbe763db4cf91ba18 100644 (file)
@@ -349,8 +349,6 @@ storagePoolEventToString(int event)
             return "Started";
         case VIR_STORAGE_POOL_EVENT_STOPPED:
             return "Stopped";
-        case VIR_STORAGE_POOL_EVENT_REFRESHED:
-            return "Refreshed";
         case VIR_STORAGE_POOL_EVENT_LAST:
             break;
     }
@@ -679,6 +677,17 @@ myStoragePoolEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
 }
 
 
+static int
+myStoragePoolEventRefreshCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+                                  virStoragePoolPtr pool,
+                                  void *opaque ATTRIBUTE_UNUSED)
+{
+    printf("%s EVENT: Storage pool %s refresh\n", __func__,
+           virStoragePoolGetName(pool));
+    return 0;
+}
+
+
 static void
 eventTypedParamsPrint(virTypedParameterPtr params,
                       int nparams)
@@ -936,6 +945,7 @@ struct storagePoolEventData {
 
 struct storagePoolEventData storagePoolEvents[] = {
     STORAGE_POOL_EVENT(VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE, myStoragePoolEventCallback),
+    STORAGE_POOL_EVENT(VIR_STORAGE_POOL_EVENT_ID_REFRESH, myStoragePoolEventRefreshCallback),
 };
 
 /* make sure that the events are kept in sync */
index a67a97f3f3f4248268a8ff2af886f0c48f840d59..0974f6ed2951c68d8ae8b65504919250dfefdb84 100644 (file)
@@ -394,6 +394,7 @@ int virStoragePoolIsPersistent(virStoragePoolPtr pool);
  */
 typedef enum {
     VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE = 0, /* virConnectStoragePoolEventLifecycleCallback */
+    VIR_STORAGE_POOL_EVENT_ID_REFRESH = 1, /* virConnectStoragePoolEventGenericCallback */
 
 # ifdef VIR_ENUM_SENTINELS
     VIR_STORAGE_POOL_EVENT_ID_LAST
@@ -443,7 +444,6 @@ typedef enum {
     VIR_STORAGE_POOL_EVENT_UNDEFINED = 1,
     VIR_STORAGE_POOL_EVENT_STARTED = 2,
     VIR_STORAGE_POOL_EVENT_STOPPED = 3,
-    VIR_STORAGE_POOL_EVENT_REFRESHED = 4,
 
 # ifdef VIR_ENUM_SENTINELS
     VIR_STORAGE_POOL_EVENT_LAST
index c5688be3ad0e646b8dd253cd30b5a37d6b987a22..5768bab6afdee5f3ad93406d20c00cf9d2b8add7 100644 (file)
@@ -48,10 +48,20 @@ struct _virStoragePoolEventLifecycle {
 typedef struct _virStoragePoolEventLifecycle virStoragePoolEventLifecycle;
 typedef virStoragePoolEventLifecycle *virStoragePoolEventLifecyclePtr;
 
+struct _virStoragePoolEventRefresh {
+    virStoragePoolEvent parent;
+
+    bool dummy;
+};
+typedef struct _virStoragePoolEventRefresh virStoragePoolEventRefresh;
+typedef virStoragePoolEventRefresh *virStoragePoolEventRefreshPtr;
+
 static virClassPtr virStoragePoolEventClass;
 static virClassPtr virStoragePoolEventLifecycleClass;
+static virClassPtr virStoragePoolEventRefreshClass;
 static void virStoragePoolEventDispose(void *obj);
 static void virStoragePoolEventLifecycleDispose(void *obj);
+static void virStoragePoolEventRefreshDispose(void *obj);
 
 static int
 virStoragePoolEventsOnceInit(void)
@@ -68,6 +78,12 @@ virStoragePoolEventsOnceInit(void)
                       sizeof(virStoragePoolEventLifecycle),
                       virStoragePoolEventLifecycleDispose)))
         return -1;
+    if (!(virStoragePoolEventRefreshClass =
+          virClassNew(virStoragePoolEventClass,
+                      "virStoragePoolEventRefresh",
+                      sizeof(virStoragePoolEventRefresh),
+                      virStoragePoolEventRefreshDispose)))
+        return -1;
     return 0;
 }
 
@@ -89,6 +105,14 @@ virStoragePoolEventLifecycleDispose(void *obj)
 }
 
 
+static void
+virStoragePoolEventRefreshDispose(void *obj)
+{
+    virStoragePoolEventRefreshPtr event = obj;
+    VIR_DEBUG("obj=%p", event);
+}
+
+
 static void
 virStoragePoolEventDispatchDefaultFunc(virConnectPtr conn,
                                        virObjectEventPtr event,
@@ -115,6 +139,13 @@ virStoragePoolEventDispatchDefaultFunc(virConnectPtr conn,
             goto cleanup;
         }
 
+    case VIR_STORAGE_POOL_EVENT_ID_REFRESH:
+        {
+            ((virConnectStoragePoolEventGenericCallback)cb)(conn, pool,
+                                                            cbopaque);
+            goto cleanup;
+        }
+
     case VIR_STORAGE_POOL_EVENT_ID_LAST:
         break;
     }
@@ -235,3 +266,29 @@ virStoragePoolEventLifecycleNew(const char *name,
 
     return (virObjectEventPtr)event;
 }
+
+
+/**
+ * virStoragePoolEventRefreshNew:
+ * @name: name of the storage pool object the event describes
+ * @uuid: uuid of the storage pool object the event describes
+ *
+ * Create a new storage pool refresh event.
+ */
+virObjectEventPtr
+virStoragePoolEventRefreshNew(const char *name,
+                              const unsigned char *uuid)
+{
+    virStoragePoolEventRefreshPtr event;
+
+    if (virStoragePoolEventsInitialize() < 0)
+        return NULL;
+
+    if (!(event = virObjectEventNew(virStoragePoolEventRefreshClass,
+                                    virStoragePoolEventDispatchDefaultFunc,
+                                    VIR_STORAGE_POOL_EVENT_ID_REFRESH,
+                                    0, name, uuid)))
+        return NULL;
+
+    return (virObjectEventPtr)event;
+}
index 7c8ccb78b354b437c151b2a98de0ed3a61203946..ea726911fa33d33cf4b508ad0c0137c972e682f4 100644 (file)
@@ -57,4 +57,8 @@ virStoragePoolEventLifecycleNew(const char *name,
                                 int type,
                                 int detail);
 
+virObjectEventPtr
+virStoragePoolEventRefreshNew(const char *name,
+                              const unsigned char *uuid);
+
 #endif
index a9eda05113edce43a59c96440ad19628cfcf6b46..9ac033d3ab7ddfb038eb08924b25c55c85b72e33 100644 (file)
@@ -881,6 +881,7 @@ virStorageVolTypeToString;
 
 # conf/storage_event.h
 virStoragePoolEventLifecycleNew;
+virStoragePoolEventRefreshNew;
 virStoragePoolEventStateRegisterID;
 
 
index 1f81f03b9e30f77094a2722e40ab70f9c0b815e3..e9904f8cd1c0214590b2e269afc562f6244d925e 100644 (file)
@@ -361,6 +361,11 @@ remoteStoragePoolBuildEventLifecycle(virNetClientProgramPtr prog ATTRIBUTE_UNUSE
                                      virNetClientPtr client ATTRIBUTE_UNUSED,
                                      void *evdata, void *opaque);
 
+static void
+remoteStoragePoolBuildEventRefresh(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
+                                   virNetClientPtr client ATTRIBUTE_UNUSED,
+                                   void *evdata, void *opaque);
+
 static void
 remoteConnectNotifyEventConnectionClosed(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                                          virNetClientPtr client ATTRIBUTE_UNUSED,
@@ -544,6 +549,10 @@ static virNetClientProgramEvent remoteEvents[] = {
       remoteStoragePoolBuildEventLifecycle,
       sizeof(remote_storage_pool_event_lifecycle_msg),
       (xdrproc_t)xdr_remote_storage_pool_event_lifecycle_msg },
+    { REMOTE_PROC_STORAGE_POOL_EVENT_REFRESH,
+      remoteStoragePoolBuildEventRefresh,
+      sizeof(remote_storage_pool_event_refresh_msg),
+      (xdrproc_t)xdr_remote_storage_pool_event_refresh_msg },
 };
 
 static void
@@ -5133,6 +5142,27 @@ remoteStoragePoolBuildEventLifecycle(virNetClientProgramPtr prog ATTRIBUTE_UNUSE
     remoteEventQueue(priv, event, msg->callbackID);
 }
 
+static void
+remoteStoragePoolBuildEventRefresh(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
+                                   virNetClientPtr client ATTRIBUTE_UNUSED,
+                                   void *evdata, void *opaque)
+{
+    virConnectPtr conn = opaque;
+    struct private_data *priv = conn->privateData;
+    remote_storage_pool_event_refresh_msg *msg = evdata;
+    virStoragePoolPtr pool;
+    virObjectEventPtr event = NULL;
+
+    pool = get_nonnull_storage_pool(conn, msg->pool);
+    if (!pool)
+        return;
+
+    event = virStoragePoolEventRefreshNew(pool->name, pool->uuid);
+    virObjectUnref(pool);
+
+    remoteEventQueue(priv, event, msg->callbackID);
+}
+
 static void
 remoteDomainBuildQemuMonitorEvent(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                                   virNetClientPtr client ATTRIBUTE_UNUSED,
index d11bfdf69912c10a08e7fc483dd605fcbecd6980..4403714cef70ee94b78df75e0bc21157fa4be1c7 100644 (file)
@@ -3126,6 +3126,11 @@ struct remote_storage_pool_event_lifecycle_msg {
     int detail;
 };
 
+struct remote_storage_pool_event_refresh_msg {
+    int callbackID;
+    remote_nonnull_storage_pool pool;
+};
+
 struct remote_domain_fsfreeze_args {
     remote_nonnull_domain dom;
     remote_nonnull_string mountpoints<REMOTE_DOMAIN_FSFREEZE_MOUNTPOINTS_MAX>; /* (const char **) */
@@ -5871,5 +5876,11 @@ enum remote_procedure {
      * @generate: both
      * @acl: domain:write
      */
-    REMOTE_PROC_DOMAIN_SET_GUEST_VCPUS = 372
+    REMOTE_PROC_DOMAIN_SET_GUEST_VCPUS = 372,
+
+    /**
+     * @generate: both
+     * @acl: none
+     */
+    REMOTE_PROC_STORAGE_POOL_EVENT_REFRESH = 373
 };
index 0d89b15c213a68d45351e1f7af064ed263e700dd..46e798b64f5e008ace7f3625e7c3dd1e482632e8 100644 (file)
@@ -2567,6 +2567,10 @@ struct remote_storage_pool_event_lifecycle_msg {
         int                        event;
         int                        detail;
 };
+struct remote_storage_pool_event_refresh_msg {
+        int                        callbackID;
+        remote_nonnull_storage_pool pool;
+};
 struct remote_domain_fsfreeze_args {
         remote_nonnull_domain      dom;
         struct {
@@ -3140,4 +3144,5 @@ enum remote_procedure {
         REMOTE_PROC_STORAGE_POOL_EVENT_LIFECYCLE = 370,
         REMOTE_PROC_DOMAIN_GET_GUEST_VCPUS = 371,
         REMOTE_PROC_DOMAIN_SET_GUEST_VCPUS = 372,
+        REMOTE_PROC_STORAGE_POOL_EVENT_REFRESH = 373,
 };
index d75c5aa1b78a2164ac94776f40fc87a2cc869008..cef21249dabf1f2e2c3492f4bf5b48bd606b9631 100644 (file)
@@ -1206,10 +1206,8 @@ storagePoolRefresh(virStoragePoolPtr obj,
         goto cleanup;
     }
 
-    event = virStoragePoolEventLifecycleNew(pool->def->name,
-                                            pool->def->uuid,
-                                            VIR_STORAGE_POOL_EVENT_REFRESHED,
-                                            0);
+    event = virStoragePoolEventRefreshNew(pool->def->name,
+                                          pool->def->uuid);
     ret = 0;
 
  cleanup:
@@ -2342,10 +2340,8 @@ virStorageVolPoolRefreshThread(void *opaque)
     if (backend->refreshPool(NULL, pool) < 0)
         VIR_DEBUG("Failed to refresh storage pool");
 
-    event = virStoragePoolEventLifecycleNew(pool->def->name,
-                                            pool->def->uuid,
-                                            VIR_STORAGE_POOL_EVENT_REFRESHED,
-                                            0);
+    event = virStoragePoolEventRefreshNew(pool->def->name,
+                                          pool->def->uuid);
 
  cleanup:
     if (event)
index 2622335a5f0b1899993a98284b1f9aabcc905d43..baff0856069bba72074a2fce0316f4002b41a9bf 100644 (file)
@@ -4480,9 +4480,7 @@ testStoragePoolRefresh(virStoragePoolPtr pool,
         goto cleanup;
     }
 
-    event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid,
-                                            VIR_STORAGE_POOL_EVENT_REFRESHED,
-                                            0);
+    event = virStoragePoolEventRefreshNew(pool->name, pool->uuid);
     ret = 0;
 
  cleanup:
index ac8cce3ed1b71288013b4d862211125b0ce707b6..5e8087bc08f628bfe0ee288d0221d9f133f6a934 100644 (file)
@@ -67,7 +67,6 @@ typedef struct {
     int defineEvents;
     int undefineEvents;
     int unexpectedEvents;
-    int refreshEvents;
 } lifecycleEventCounter;
 
 static void
@@ -78,7 +77,6 @@ lifecycleEventCounter_reset(lifecycleEventCounter *counter)
     counter->defineEvents = 0;
     counter->undefineEvents = 0;
     counter->unexpectedEvents = 0;
-    counter->refreshEvents = 0;
 }
 
 typedef struct {
@@ -153,8 +151,16 @@ storagePoolLifecycleCb(virConnectPtr conn ATTRIBUTE_UNUSED,
         counter->defineEvents++;
     else if (event == VIR_STORAGE_POOL_EVENT_UNDEFINED)
         counter->undefineEvents++;
-    else if (event == VIR_STORAGE_POOL_EVENT_REFRESHED)
-        counter->refreshEvents++;
+}
+
+static void
+storagePoolRefreshCb(virConnectPtr conn ATTRIBUTE_UNUSED,
+                     virStoragePoolPtr pool ATTRIBUTE_UNUSED,
+                     void* opaque)
+{
+    int *counter = opaque;
+
+    (*counter)++;
 }
 
 static int
@@ -646,18 +652,24 @@ testStoragePoolStartStopEvent(const void *data)
 {
     const objecteventTest *test = data;
     lifecycleEventCounter counter;
-    int id;
+    int refreshCounter;
+    int id1, id2;
     int ret = 0;
 
     if (!test->pool)
         return -1;
 
     lifecycleEventCounter_reset(&counter);
+    refreshCounter = 0;
 
-    id = virConnectStoragePoolEventRegisterAny(test->conn, test->pool,
+    id1 = virConnectStoragePoolEventRegisterAny(test->conn, test->pool,
                       VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
                       VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolLifecycleCb),
                       &counter, NULL);
+    id2 = virConnectStoragePoolEventRegisterAny(test->conn, test->pool,
+                      VIR_STORAGE_POOL_EVENT_ID_REFRESH,
+                      VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolRefreshCb),
+                      &refreshCounter, NULL);
     virStoragePoolCreate(test->pool, 0);
     virStoragePoolRefresh(test->pool, 0);
     virStoragePoolDestroy(test->pool);
@@ -668,13 +680,14 @@ testStoragePoolStartStopEvent(const void *data)
     }
 
     if (counter.startEvents != 1 || counter.stopEvents != 1 ||
-        counter.refreshEvents != 1 || counter.unexpectedEvents > 0) {
+        refreshCounter != 1 || counter.unexpectedEvents > 0) {
         ret = -1;
         goto cleanup;
     }
 
  cleanup:
-    virConnectStoragePoolEventDeregisterAny(test->conn, id);
+    virConnectStoragePoolEventDeregisterAny(test->conn, id1);
+    virConnectStoragePoolEventDeregisterAny(test->conn, id2);
     return ret;
 }
 
index 18e218cabde5c0c6e0ef19fb513cf59517742dea..60453310df64f63c3361b3e51ab500c3366c0b69 100644 (file)
@@ -1899,8 +1899,7 @@ VIR_ENUM_IMPL(virshPoolEvent,
               N_("Defined"),
               N_("Undefined"),
               N_("Started"),
-              N_("Stopped"),
-              N_("Refreshed"))
+              N_("Stopped"))
 
 static const char *
 virshPoolEventToString(int event)
@@ -1909,18 +1908,21 @@ virshPoolEventToString(int event)
     return str ? _(str) : _("unknown");
 }
 
+struct vshEventCallback {
+    const char *name;
+    virConnectStoragePoolEventGenericCallback cb;
+};
+typedef struct vshEventCallback vshEventCallback;
+
 struct virshPoolEventData {
     vshControl *ctl;
     bool loop;
     bool timestamp;
     int count;
+    vshEventCallback *cb;
 };
 typedef struct virshPoolEventData virshPoolEventData;
 
-VIR_ENUM_DECL(virshPoolEventId)
-VIR_ENUM_IMPL(virshPoolEventId,
-              VIR_STORAGE_POOL_EVENT_ID_LAST,
-              "lifecycle")
 
 static void
 vshEventLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
@@ -1955,6 +1957,45 @@ vshEventLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
         vshEventDone(data->ctl);
 }
 
+static void
+vshEventGenericPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+                     virStoragePoolPtr pool,
+                     void *opaque)
+{
+    virshPoolEventData *data = opaque;
+
+    if (!data->loop && data->count)
+        return;
+
+    if (data->timestamp) {
+        char timestamp[VIR_TIME_STRING_BUFLEN];
+
+        if (virTimeStringNowRaw(timestamp) < 0)
+            timestamp[0] = '\0';
+
+        vshPrint(data->ctl, _("%s: event '%s'' for storage pool %s\n"),
+                 timestamp,
+                 data->cb->name,
+                 virStoragePoolGetName(pool));
+    } else {
+        vshPrint(data->ctl, _("event '%s' for storage pool %s\n"),
+                 data->cb->name,
+                 virStoragePoolGetName(pool));
+    }
+
+    data->count++;
+    if (!data->loop)
+        vshEventDone(data->ctl);
+}
+
+static vshEventCallback vshEventCallbacks[] = {
+    { "lifecycle",
+      VIR_STORAGE_POOL_EVENT_CALLBACK(vshEventLifecyclePrint), },
+    { "refresh", vshEventGenericPrint, }
+};
+verify(VIR_STORAGE_POOL_EVENT_ID_LAST == ARRAY_CARDINALITY(vshEventCallbacks));
+
+
 static const vshCmdInfo info_pool_event[] = {
     {.name = "help",
      .data = N_("Storage Pool Events")
@@ -2009,7 +2050,7 @@ cmdPoolEvent(vshControl *ctl, const vshCmd *cmd)
         size_t i;
 
         for (i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++)
-            vshPrint(ctl, "%s\n", virshPoolEventIdTypeToString(i));
+            vshPrint(ctl, "%s\n", vshEventCallbacks[i].name);
         return true;
     }
 
@@ -2019,7 +2060,11 @@ cmdPoolEvent(vshControl *ctl, const vshCmd *cmd)
         vshError(ctl, "%s", _("either --list or event type is required"));
         return false;
     }
-    if ((event = virshPoolEventIdTypeFromString(eventName)) < 0) {
+
+    for (event = 0; event < VIR_STORAGE_POOL_EVENT_ID_LAST; event++)
+        if (STREQ(eventName, vshEventCallbacks[event].name))
+            break;
+    if (event == VIR_STORAGE_POOL_EVENT_ID_LAST) {
         vshError(ctl, _("unknown event type %s"), eventName);
         return false;
     }
@@ -2028,6 +2073,7 @@ cmdPoolEvent(vshControl *ctl, const vshCmd *cmd)
     data.loop = vshCommandOptBool(cmd, "loop");
     data.timestamp = vshCommandOptBool(cmd, "timestamp");
     data.count = 0;
+    data.cb = &vshEventCallbacks[event];
     if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
         return false;
 
@@ -2037,7 +2083,7 @@ cmdPoolEvent(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
 
     if ((eventId = virConnectStoragePoolEventRegisterAny(priv->conn, pool, event,
-                                                         VIR_STORAGE_POOL_EVENT_CALLBACK(vshEventLifecyclePrint),
+                                                         data.cb->cb,
                                                          &data, NULL)) < 0)
         goto cleanup;
     switch (vshEventWait(ctl)) {