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);
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;
}
}
+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)
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 */
*/
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
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
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)
sizeof(virStoragePoolEventLifecycle),
virStoragePoolEventLifecycleDispose)))
return -1;
+ if (!(virStoragePoolEventRefreshClass =
+ virClassNew(virStoragePoolEventClass,
+ "virStoragePoolEventRefresh",
+ sizeof(virStoragePoolEventRefresh),
+ virStoragePoolEventRefreshDispose)))
+ return -1;
return 0;
}
}
+static void
+virStoragePoolEventRefreshDispose(void *obj)
+{
+ virStoragePoolEventRefreshPtr event = obj;
+ VIR_DEBUG("obj=%p", event);
+}
+
+
static void
virStoragePoolEventDispatchDefaultFunc(virConnectPtr conn,
virObjectEventPtr event,
goto cleanup;
}
+ case VIR_STORAGE_POOL_EVENT_ID_REFRESH:
+ {
+ ((virConnectStoragePoolEventGenericCallback)cb)(conn, pool,
+ cbopaque);
+ goto cleanup;
+ }
+
case VIR_STORAGE_POOL_EVENT_ID_LAST:
break;
}
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;
+}
int type,
int detail);
+virObjectEventPtr
+virStoragePoolEventRefreshNew(const char *name,
+ const unsigned char *uuid);
+
#endif
# conf/storage_event.h
virStoragePoolEventLifecycleNew;
+virStoragePoolEventRefreshNew;
virStoragePoolEventStateRegisterID;
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,
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
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,
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 **) */
* @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
};
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 {
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,
};
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:
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)
goto cleanup;
}
- event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid,
- VIR_STORAGE_POOL_EVENT_REFRESHED,
- 0);
+ event = virStoragePoolEventRefreshNew(pool->name, pool->uuid);
ret = 0;
cleanup:
int defineEvents;
int undefineEvents;
int unexpectedEvents;
- int refreshEvents;
} lifecycleEventCounter;
static void
counter->defineEvents = 0;
counter->undefineEvents = 0;
counter->unexpectedEvents = 0;
- counter->refreshEvents = 0;
}
typedef struct {
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
{
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);
}
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;
}
N_("Defined"),
N_("Undefined"),
N_("Started"),
- N_("Stopped"),
- N_("Refreshed"))
+ N_("Stopped"))
static const char *
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,
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")
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;
}
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;
}
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;
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)) {