mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-05 22:05:47 +00:00
conf: add secret event handling
Add helper APIs / objects for managing secret events Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
34fd3caabf
commit
df740caf54
@ -354,6 +354,9 @@ STORAGE_EVENT_SOURCES = \
|
|||||||
NODE_DEVICE_EVENT_SOURCES = \
|
NODE_DEVICE_EVENT_SOURCES = \
|
||||||
conf/node_device_event.c conf/node_device_event.h
|
conf/node_device_event.c conf/node_device_event.h
|
||||||
|
|
||||||
|
SECRET_EVENT_SOURCES = \
|
||||||
|
conf/secret_event.c conf/secret_event.h
|
||||||
|
|
||||||
# Network driver generic impl APIs
|
# Network driver generic impl APIs
|
||||||
NETWORK_CONF_SOURCES = \
|
NETWORK_CONF_SOURCES = \
|
||||||
conf/network_conf.c conf/network_conf.h \
|
conf/network_conf.c conf/network_conf.h \
|
||||||
@ -406,6 +409,7 @@ CONF_SOURCES = \
|
|||||||
$(NETWORK_EVENT_SOURCES) \
|
$(NETWORK_EVENT_SOURCES) \
|
||||||
$(STORAGE_EVENT_SOURCES) \
|
$(STORAGE_EVENT_SOURCES) \
|
||||||
$(NODE_DEVICE_EVENT_SOURCES) \
|
$(NODE_DEVICE_EVENT_SOURCES) \
|
||||||
|
$(SECRET_EVENT_SOURCES) \
|
||||||
$(NETWORK_CONF_SOURCES) \
|
$(NETWORK_CONF_SOURCES) \
|
||||||
$(NWFILTER_CONF_SOURCES) \
|
$(NWFILTER_CONF_SOURCES) \
|
||||||
$(NODE_DEVICE_CONF_SOURCES) \
|
$(NODE_DEVICE_CONF_SOURCES) \
|
||||||
@ -2390,6 +2394,7 @@ libvirt_setuid_rpc_client_la_SOURCES = \
|
|||||||
conf/object_event.c \
|
conf/object_event.c \
|
||||||
conf/storage_event.c \
|
conf/storage_event.c \
|
||||||
conf/node_device_event.c \
|
conf/node_device_event.c \
|
||||||
|
conf/secret_event.c \
|
||||||
rpc/virnetsocket.c \
|
rpc/virnetsocket.c \
|
||||||
rpc/virnetsocket.h \
|
rpc/virnetsocket.h \
|
||||||
rpc/virnetmessage.h \
|
rpc/virnetmessage.h \
|
||||||
|
252
src/conf/secret_event.c
Normal file
252
src/conf/secret_event.c
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
/*
|
||||||
|
* secret_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 "secret_event.h"
|
||||||
|
#include "object_event.h"
|
||||||
|
#include "object_event_private.h"
|
||||||
|
#include "datatypes.h"
|
||||||
|
#include "virlog.h"
|
||||||
|
|
||||||
|
VIR_LOG_INIT("conf.secret_event");
|
||||||
|
|
||||||
|
struct _virSecretEvent {
|
||||||
|
virObjectEvent parent;
|
||||||
|
|
||||||
|
/* Unused attribute to allow for subclass creation */
|
||||||
|
bool dummy;
|
||||||
|
};
|
||||||
|
typedef struct _virSecretEvent virSecretEvent;
|
||||||
|
typedef virSecretEvent *virSecretEventPtr;
|
||||||
|
|
||||||
|
struct _virSecretEventLifecycle {
|
||||||
|
virSecretEvent parent;
|
||||||
|
|
||||||
|
int type;
|
||||||
|
int detail;
|
||||||
|
};
|
||||||
|
typedef struct _virSecretEventLifecycle virSecretEventLifecycle;
|
||||||
|
typedef virSecretEventLifecycle *virSecretEventLifecyclePtr;
|
||||||
|
|
||||||
|
static virClassPtr virSecretEventClass;
|
||||||
|
static virClassPtr virSecretEventLifecycleClass;
|
||||||
|
static void virSecretEventDispose(void *obj);
|
||||||
|
static void virSecretEventLifecycleDispose(void *obj);
|
||||||
|
|
||||||
|
static int
|
||||||
|
virSecretEventsOnceInit(void)
|
||||||
|
{
|
||||||
|
if (!(virSecretEventClass =
|
||||||
|
virClassNew(virClassForObjectEvent(),
|
||||||
|
"virSecretEvent",
|
||||||
|
sizeof(virSecretEvent),
|
||||||
|
virSecretEventDispose)))
|
||||||
|
return -1;
|
||||||
|
if (!(virSecretEventLifecycleClass =
|
||||||
|
virClassNew(virSecretEventClass,
|
||||||
|
"virSecretEventLifecycle",
|
||||||
|
sizeof(virSecretEventLifecycle),
|
||||||
|
virSecretEventLifecycleDispose)))
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
VIR_ONCE_GLOBAL_INIT(virSecretEvents)
|
||||||
|
|
||||||
|
static void
|
||||||
|
virSecretEventDispose(void *obj)
|
||||||
|
{
|
||||||
|
virSecretEventPtr event = obj;
|
||||||
|
VIR_DEBUG("obj=%p", event);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
virSecretEventLifecycleDispose(void *obj)
|
||||||
|
{
|
||||||
|
virSecretEventLifecyclePtr event = obj;
|
||||||
|
VIR_DEBUG("obj=%p", event);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
virSecretEventDispatchDefaultFunc(virConnectPtr conn,
|
||||||
|
virObjectEventPtr event,
|
||||||
|
virConnectObjectEventGenericCallback cb,
|
||||||
|
void *cbopaque)
|
||||||
|
{
|
||||||
|
virSecretPtr secret = virGetSecret(conn,
|
||||||
|
event->meta.uuid,
|
||||||
|
event->meta.id,
|
||||||
|
event->meta.name);
|
||||||
|
|
||||||
|
if (!secret)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch ((virSecretEventID)event->eventID) {
|
||||||
|
case VIR_SECRET_EVENT_ID_LIFECYCLE:
|
||||||
|
{
|
||||||
|
virSecretEventLifecyclePtr secretLifecycleEvent;
|
||||||
|
|
||||||
|
secretLifecycleEvent = (virSecretEventLifecyclePtr)event;
|
||||||
|
((virConnectSecretEventLifecycleCallback)cb)(conn, secret,
|
||||||
|
secretLifecycleEvent->type,
|
||||||
|
secretLifecycleEvent->detail,
|
||||||
|
cbopaque);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
case VIR_SECRET_EVENT_ID_LAST:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
VIR_WARN("Unexpected event ID %d", event->eventID);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virObjectUnref(secret);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virSecretEventStateRegisterID:
|
||||||
|
* @conn: connection to associate with callback
|
||||||
|
* @state: object event state
|
||||||
|
* @secret: secret to filter on or NULL for all node secrets
|
||||||
|
* @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
|
||||||
|
virSecretEventStateRegisterID(virConnectPtr conn,
|
||||||
|
virObjectEventStatePtr state,
|
||||||
|
virSecretPtr secret,
|
||||||
|
int eventID,
|
||||||
|
virConnectSecretEventGenericCallback cb,
|
||||||
|
void *opaque,
|
||||||
|
virFreeCallback freecb,
|
||||||
|
int *callbackID)
|
||||||
|
{
|
||||||
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
|
|
||||||
|
if (virSecretEventsInitialize() < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (secret)
|
||||||
|
virUUIDFormat(secret->uuid, uuidstr);
|
||||||
|
return virObjectEventStateRegisterID(conn, state, secret ? uuidstr : NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
virSecretEventClass, eventID,
|
||||||
|
VIR_OBJECT_EVENT_CALLBACK(cb),
|
||||||
|
opaque, freecb,
|
||||||
|
false, callbackID, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virSecretEventStateRegisterClient:
|
||||||
|
* @conn: connection to associate with callback
|
||||||
|
* @state: object event state
|
||||||
|
* @secret: secret to filter on or NULL for all node secrets
|
||||||
|
* @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
|
||||||
|
virSecretEventStateRegisterClient(virConnectPtr conn,
|
||||||
|
virObjectEventStatePtr state,
|
||||||
|
virSecretPtr secret,
|
||||||
|
int eventID,
|
||||||
|
virConnectSecretEventGenericCallback cb,
|
||||||
|
void *opaque,
|
||||||
|
virFreeCallback freecb,
|
||||||
|
int *callbackID)
|
||||||
|
{
|
||||||
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
|
|
||||||
|
if (virSecretEventsInitialize() < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (secret)
|
||||||
|
virUUIDFormat(secret->uuid, uuidstr);
|
||||||
|
|
||||||
|
return virObjectEventStateRegisterID(conn, state, secret ? uuidstr : NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
virSecretEventClass, eventID,
|
||||||
|
VIR_OBJECT_EVENT_CALLBACK(cb),
|
||||||
|
opaque, freecb,
|
||||||
|
false, callbackID, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virSecretEventLifecycleNew:
|
||||||
|
* @uuid: UUID of the secret object the event describes
|
||||||
|
* @usage_type: type of usage for the secret
|
||||||
|
* @usage_id: usage specific identifier for the secret
|
||||||
|
* @type: type of lifecycle event
|
||||||
|
* @detail: more details about @type
|
||||||
|
*
|
||||||
|
* Create a new secret lifecycle event.
|
||||||
|
*/
|
||||||
|
virObjectEventPtr
|
||||||
|
virSecretEventLifecycleNew(const unsigned char *uuid,
|
||||||
|
int usage_type,
|
||||||
|
const char *usage_id,
|
||||||
|
int type,
|
||||||
|
int detail)
|
||||||
|
{
|
||||||
|
virSecretEventLifecyclePtr event;
|
||||||
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
|
|
||||||
|
if (virSecretEventsInitialize() < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
virUUIDFormat(uuid, uuidstr);
|
||||||
|
VIR_DEBUG("Event %s %d %s %d %d", uuidstr, usage_type, usage_id, type, detail);
|
||||||
|
if (!(event = virObjectEventNew(virSecretEventLifecycleClass,
|
||||||
|
virSecretEventDispatchDefaultFunc,
|
||||||
|
VIR_SECRET_EVENT_ID_LIFECYCLE,
|
||||||
|
usage_type, usage_id, uuid, uuidstr)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
event->type = type;
|
||||||
|
event->detail = detail;
|
||||||
|
|
||||||
|
return (virObjectEventPtr)event;
|
||||||
|
}
|
61
src/conf/secret_event.h
Normal file
61
src/conf/secret_event.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* secret_event.h: secret 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 __SECRET_EVENT_H__
|
||||||
|
# define __SECRET_EVENT_H__
|
||||||
|
|
||||||
|
int
|
||||||
|
virSecretEventStateRegisterID(virConnectPtr conn,
|
||||||
|
virObjectEventStatePtr state,
|
||||||
|
virSecretPtr secret,
|
||||||
|
int eventID,
|
||||||
|
virConnectSecretEventGenericCallback cb,
|
||||||
|
void *opaque,
|
||||||
|
virFreeCallback freecb,
|
||||||
|
int *callbackID)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5)
|
||||||
|
ATTRIBUTE_NONNULL(8);
|
||||||
|
|
||||||
|
int
|
||||||
|
virSecretEventStateRegisterClient(virConnectPtr conn,
|
||||||
|
virObjectEventStatePtr state,
|
||||||
|
virSecretPtr secret,
|
||||||
|
int eventID,
|
||||||
|
virConnectSecretEventGenericCallback cb,
|
||||||
|
void *opaque,
|
||||||
|
virFreeCallback freecb,
|
||||||
|
int *callbackID)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5)
|
||||||
|
ATTRIBUTE_NONNULL(8);
|
||||||
|
|
||||||
|
virObjectEventPtr
|
||||||
|
virSecretEventLifecycleNew(const unsigned char *uuid,
|
||||||
|
int usage_type,
|
||||||
|
const char *usage_id,
|
||||||
|
int type,
|
||||||
|
int detail);
|
||||||
|
|
||||||
|
#endif
|
@ -843,6 +843,11 @@ virSecretUsageTypeFromString;
|
|||||||
virSecretUsageTypeToString;
|
virSecretUsageTypeToString;
|
||||||
|
|
||||||
|
|
||||||
|
# conf/secret_event.h
|
||||||
|
virSecretEventLifecycleNew;
|
||||||
|
virSecretEventStateRegisterID;
|
||||||
|
|
||||||
|
|
||||||
# conf/snapshot_conf.h
|
# conf/snapshot_conf.h
|
||||||
virDomainListSnapshots;
|
virDomainListSnapshots;
|
||||||
virDomainSnapshotAlignDisks;
|
virDomainSnapshotAlignDisks;
|
||||||
|
Loading…
Reference in New Issue
Block a user