提交 03308482 编写于 作者: D Daniel P. Berrange

Promote storage pool refresh lifecycle event to top level event

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: NDaniel P. Berrange <berrange@redhat.com>
上级 318ebb36
......@@ -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);
......
......@@ -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 */
......
......@@ -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
......
......@@ -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;
}
......@@ -57,4 +57,8 @@ virStoragePoolEventLifecycleNew(const char *name,
int type,
int detail);
virObjectEventPtr
virStoragePoolEventRefreshNew(const char *name,
const unsigned char *uuid);
#endif
......@@ -881,6 +881,7 @@ virStorageVolTypeToString;
# conf/storage_event.h
virStoragePoolEventLifecycleNew;
virStoragePoolEventRefreshNew;
virStoragePoolEventStateRegisterID;
......
......@@ -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,
......
......@@ -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
};
......@@ -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,
};
......@@ -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)
......
......@@ -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:
......
......@@ -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;
}
......
......@@ -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)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册