mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 19:11:16 +00:00
conf: add node_device_event handling
Add node device event handling infrastructure to node_device_event.[ch]
This commit is contained in:
parent
fcabc1ca53
commit
9806ae04dd
@ -348,6 +348,9 @@ NETWORK_EVENT_SOURCES = \
|
||||
STORAGE_EVENT_SOURCES = \
|
||||
conf/storage_event.c conf/storage_event.h
|
||||
|
||||
NODE_DEVICE_EVENT_SOURCES = \
|
||||
conf/node_device_event.c conf/node_device_event.h
|
||||
|
||||
# Network driver generic impl APIs
|
||||
NETWORK_CONF_SOURCES = \
|
||||
conf/network_conf.c conf/network_conf.h \
|
||||
@ -399,6 +402,7 @@ CONF_SOURCES = \
|
||||
$(DOMAIN_EVENT_SOURCES) \
|
||||
$(NETWORK_EVENT_SOURCES) \
|
||||
$(STORAGE_EVENT_SOURCES) \
|
||||
$(NODE_DEVICE_EVENT_SOURCES) \
|
||||
$(NETWORK_CONF_SOURCES) \
|
||||
$(NWFILTER_CONF_SOURCES) \
|
||||
$(NODE_DEVICE_CONF_SOURCES) \
|
||||
@ -2369,6 +2373,7 @@ libvirt_setuid_rpc_client_la_SOURCES = \
|
||||
conf/network_event.c \
|
||||
conf/object_event.c \
|
||||
conf/storage_event.c \
|
||||
conf/node_device_event.c \
|
||||
rpc/virnetsocket.c \
|
||||
rpc/virnetsocket.h \
|
||||
rpc/virnetmessage.h \
|
||||
|
234
src/conf/node_device_event.c
Normal file
234
src/conf/node_device_event.c
Normal file
@ -0,0 +1,234 @@
|
||||
/*
|
||||
* node_device_event.c: node device event queue processing helpers
|
||||
*
|
||||
* Copyright (C) 2010-2014 Red Hat, Inc.
|
||||
* Copyright (C) 2008 VirtualIron
|
||||
* Copyright (C) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "node_device_event.h"
|
||||
#include "object_event.h"
|
||||
#include "object_event_private.h"
|
||||
#include "datatypes.h"
|
||||
#include "virlog.h"
|
||||
|
||||
VIR_LOG_INIT("conf.node_device_event");
|
||||
|
||||
struct _virNodeDeviceEvent {
|
||||
virObjectEvent parent;
|
||||
|
||||
/* Unused attribute to allow for subclass creation */
|
||||
bool dummy;
|
||||
};
|
||||
typedef struct _virNodeDeviceEvent virNodeDeviceEvent;
|
||||
typedef virNodeDeviceEvent *virNodeDeviceEventPtr;
|
||||
|
||||
struct _virNodeDeviceEventLifecycle {
|
||||
virNodeDeviceEvent parent;
|
||||
|
||||
int type;
|
||||
int detail;
|
||||
};
|
||||
typedef struct _virNodeDeviceEventLifecycle virNodeDeviceEventLifecycle;
|
||||
typedef virNodeDeviceEventLifecycle *virNodeDeviceEventLifecyclePtr;
|
||||
|
||||
static virClassPtr virNodeDeviceEventClass;
|
||||
static virClassPtr virNodeDeviceEventLifecycleClass;
|
||||
static void virNodeDeviceEventDispose(void *obj);
|
||||
static void virNodeDeviceEventLifecycleDispose(void *obj);
|
||||
|
||||
static int
|
||||
virNodeDeviceEventsOnceInit(void)
|
||||
{
|
||||
if (!(virNodeDeviceEventClass =
|
||||
virClassNew(virClassForObjectEvent(),
|
||||
"virNodeDeviceEvent",
|
||||
sizeof(virNodeDeviceEvent),
|
||||
virNodeDeviceEventDispose)))
|
||||
return -1;
|
||||
if (!(virNodeDeviceEventLifecycleClass =
|
||||
virClassNew(virNodeDeviceEventClass,
|
||||
"virNodeDeviceEventLifecycle",
|
||||
sizeof(virNodeDeviceEventLifecycle),
|
||||
virNodeDeviceEventLifecycleDispose)))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
VIR_ONCE_GLOBAL_INIT(virNodeDeviceEvents)
|
||||
|
||||
static void
|
||||
virNodeDeviceEventDispose(void *obj)
|
||||
{
|
||||
virNodeDeviceEventPtr event = obj;
|
||||
VIR_DEBUG("obj=%p", event);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
virNodeDeviceEventLifecycleDispose(void *obj)
|
||||
{
|
||||
virNodeDeviceEventLifecyclePtr event = obj;
|
||||
VIR_DEBUG("obj=%p", event);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
virNodeDeviceEventDispatchDefaultFunc(virConnectPtr conn,
|
||||
virObjectEventPtr event,
|
||||
virConnectObjectEventGenericCallback cb,
|
||||
void *cbopaque)
|
||||
{
|
||||
virNodeDevicePtr dev = virGetNodeDevice(conn,
|
||||
event->meta.name);
|
||||
|
||||
if (!dev)
|
||||
return;
|
||||
|
||||
switch ((virNodeDeviceEventID)event->eventID) {
|
||||
case VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE:
|
||||
{
|
||||
virNodeDeviceEventLifecyclePtr nodeDeviceLifecycleEvent;
|
||||
|
||||
nodeDeviceLifecycleEvent = (virNodeDeviceEventLifecyclePtr)event;
|
||||
((virConnectNodeDeviceEventLifecycleCallback)cb)(conn, dev,
|
||||
nodeDeviceLifecycleEvent->type,
|
||||
nodeDeviceLifecycleEvent->detail,
|
||||
cbopaque);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
case VIR_NODE_DEVICE_EVENT_ID_LAST:
|
||||
break;
|
||||
}
|
||||
VIR_WARN("Unexpected event ID %d", event->eventID);
|
||||
|
||||
cleanup:
|
||||
virObjectUnref(dev);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virNodeDeviceEventStateRegisterID:
|
||||
* @conn: connection to associate with callback
|
||||
* @state: object event state
|
||||
* @dev: node device to filter on or NULL for all node devices
|
||||
* @eventID: ID of the event type to register for
|
||||
* @cb: function to invoke when event occurs
|
||||
* @opaque: data blob to pass to @callback
|
||||
* @freecb: callback to free @opaque
|
||||
* @callbackID: filled with callback ID
|
||||
*
|
||||
* Register the function @cb with connection @conn, from @state, for
|
||||
* events of type @eventID, and return the registration handle in
|
||||
* @callbackID.
|
||||
*
|
||||
* Returns: the number of callbacks now registered, or -1 on error
|
||||
*/
|
||||
int
|
||||
virNodeDeviceEventStateRegisterID(virConnectPtr conn,
|
||||
virObjectEventStatePtr state,
|
||||
virNodeDevicePtr dev,
|
||||
int eventID,
|
||||
virConnectNodeDeviceEventGenericCallback cb,
|
||||
void *opaque,
|
||||
virFreeCallback freecb,
|
||||
int *callbackID)
|
||||
{
|
||||
if (virNodeDeviceEventsInitialize() < 0)
|
||||
return -1;
|
||||
|
||||
return virObjectEventStateRegisterID(conn, state, dev ? dev->name : NULL,
|
||||
NULL, NULL,
|
||||
virNodeDeviceEventClass, eventID,
|
||||
VIR_OBJECT_EVENT_CALLBACK(cb),
|
||||
opaque, freecb,
|
||||
false, callbackID, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virNodeDeviceEventStateRegisterClient:
|
||||
* @conn: connection to associate with callback
|
||||
* @state: object event state
|
||||
* @dev: node device to filter on or NULL for all node devices
|
||||
* @eventID: ID of the event type to register for
|
||||
* @cb: function to invoke when event occurs
|
||||
* @opaque: data blob to pass to @callback
|
||||
* @freecb: callback to free @opaque
|
||||
* @callbackID: filled with callback ID
|
||||
*
|
||||
* Register the function @cb with connection @conn, from @state, for
|
||||
* events of type @eventID, and return the registration handle in
|
||||
* @callbackID. This version is intended for use on the client side
|
||||
* of RPC.
|
||||
*
|
||||
* Returns: the number of callbacks now registered, or -1 on error
|
||||
*/
|
||||
int
|
||||
virNodeDeviceEventStateRegisterClient(virConnectPtr conn,
|
||||
virObjectEventStatePtr state,
|
||||
virNodeDevicePtr dev,
|
||||
int eventID,
|
||||
virConnectNodeDeviceEventGenericCallback cb,
|
||||
void *opaque,
|
||||
virFreeCallback freecb,
|
||||
int *callbackID)
|
||||
{
|
||||
if (virNodeDeviceEventsInitialize() < 0)
|
||||
return -1;
|
||||
|
||||
return virObjectEventStateRegisterID(conn, state, dev ? dev->name : NULL,
|
||||
NULL, NULL,
|
||||
virNodeDeviceEventClass, eventID,
|
||||
VIR_OBJECT_EVENT_CALLBACK(cb),
|
||||
opaque, freecb,
|
||||
false, callbackID, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virNodeDeviceEventLifecycleNew:
|
||||
* @name: name of the node device object the event describes
|
||||
* @type: type of lifecycle event
|
||||
* @detail: more details about @type
|
||||
*
|
||||
* Create a new node device lifecycle event.
|
||||
*/
|
||||
virObjectEventPtr
|
||||
virNodeDeviceEventLifecycleNew(const char *name,
|
||||
int type,
|
||||
int detail)
|
||||
{
|
||||
virNodeDeviceEventLifecyclePtr event;
|
||||
|
||||
if (virNodeDeviceEventsInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
if (!(event = virObjectEventNew(virNodeDeviceEventLifecycleClass,
|
||||
virNodeDeviceEventDispatchDefaultFunc,
|
||||
VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE,
|
||||
0, name, NULL, name)))
|
||||
return NULL;
|
||||
|
||||
event->type = type;
|
||||
event->detail = detail;
|
||||
|
||||
return (virObjectEventPtr)event;
|
||||
}
|
59
src/conf/node_device_event.h
Normal file
59
src/conf/node_device_event.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* node_device_event.h: node device event queue processing helpers
|
||||
*
|
||||
* Copyright (C) 2010-2014 Red Hat, Inc.
|
||||
* Copyright (C) 2008 VirtualIron
|
||||
* Copyright (C) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "object_event.h"
|
||||
#include "object_event_private.h"
|
||||
|
||||
#ifndef __NODE_DEVICE_EVENT_H__
|
||||
# define __NODE_DEVICE_EVENT_H__
|
||||
|
||||
int
|
||||
virNodeDeviceEventStateRegisterID(virConnectPtr conn,
|
||||
virObjectEventStatePtr state,
|
||||
virNodeDevicePtr dev,
|
||||
int eventID,
|
||||
virConnectNodeDeviceEventGenericCallback cb,
|
||||
void *opaque,
|
||||
virFreeCallback freecb,
|
||||
int *callbackID)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5)
|
||||
ATTRIBUTE_NONNULL(8);
|
||||
|
||||
int
|
||||
virNodeDeviceEventStateRegisterClient(virConnectPtr conn,
|
||||
virObjectEventStatePtr state,
|
||||
virNodeDevicePtr dev,
|
||||
int eventID,
|
||||
virConnectNodeDeviceEventGenericCallback cb,
|
||||
void *opaque,
|
||||
virFreeCallback freecb,
|
||||
int *callbackID)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5)
|
||||
ATTRIBUTE_NONNULL(8);
|
||||
|
||||
virObjectEventPtr
|
||||
virNodeDeviceEventLifecycleNew(const char *name,
|
||||
int type,
|
||||
int detail);
|
||||
|
||||
#endif
|
@ -684,6 +684,11 @@ virNodeDeviceObjRemove;
|
||||
virNodeDeviceObjUnlock;
|
||||
|
||||
|
||||
# conf/node_device_event.h
|
||||
virNodeDeviceEventLifecycleNew;
|
||||
virNodeDeviceEventStateRegisterID;
|
||||
|
||||
|
||||
# conf/numa_conf.h
|
||||
virDomainNumaCheckABIStability;
|
||||
virDomainNumaEquals;
|
||||
|
Loading…
Reference in New Issue
Block a user