[libvirt] [PATCH 9/9] secret: add support for value change events

Daniel P. Berrange berrange at redhat.com
Fri Jan 6 15:11:24 UTC 2017


On Fri, Jan 06, 2017 at 04:02:45PM +0100, Michal Privoznik wrote:
> On 01/05/2017 02:59 PM, Daniel P. Berrange wrote:
> > Emit an event whenever a secret value changes
> > 
> > Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
> > ---
> >  daemon/remote.c                  | 29 ++++++++++++++++++++
> >  include/libvirt/libvirt-secret.h |  1 +
> >  src/conf/secret_event.c          | 59 ++++++++++++++++++++++++++++++++++++++++
> >  src/conf/secret_event.h          |  4 +++
> >  src/libvirt_private.syms         |  1 +
> >  src/remote/remote_driver.c       | 30 ++++++++++++++++++++
> >  src/remote/remote_protocol.x     | 13 ++++++++-
> >  src/secret/secret_driver.c       |  6 ++++
> >  tools/virsh-secret.c             | 35 ++++++++++++++++++++++++
> >  9 files changed, 177 insertions(+), 1 deletion(-)


> > +
> >  static vshEventCallback vshEventCallbacks[] = {
> >      { "lifecycle",
> >        VIR_SECRET_EVENT_CALLBACK(vshEventLifecyclePrint), },
> > +    { "value-changed", vshEventGenericPrint, },
> 
> We advise users to wrap their callbacks with VIR_SECRET_EVENT_CALLBACK() macro. We should follow our own advices.

The macro casts to virConnectSecretGenericCallback, and vshEventGenericPrint
already has that type, so no cast is required here.

> >  };
> >  
> >  static const vshCmdInfo info_secret_event[] = {
> > 
> 
> Also, looks like there's something missing:
> 
> object-events/event-test.c:1094:1: note: in expansion of macro 'verify'
>  verify(ARRAY_CARDINALITY(secretEvents) == VIR_SECRET_EVENT_ID_LAST);
>  ^

Opps, yes, I guess I didn't test the examples

> Perhaps this?
> 
> diff --git i/examples/object-events/event-test.c w/examples/object-events/event-test.c
> index cf8c1bca2..55c004f93 100644
> --- i/examples/object-events/event-test.c
> +++ w/examples/object-events/event-test.c
> @@ -763,6 +763,18 @@ mySecretEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
>  }
>  
>  
> +static int
> +mySecretEventValueChanged(virConnectPtr conn ATTRIBUTE_UNUSED,
> +                          virSecretPtr secret,
> +                          void *opaque ATTRIBUTE_UNUSED)
> +{
> +    char uuid[VIR_UUID_STRING_BUFLEN];
> +    virSecretGetUUIDString(secret, uuid);
> +    printf("%s EVENT: Secret %s\n", __func__, uuid);
> +    return 0;
> +}
> +
> +
>  static void
>  eventTypedParamsPrint(virTypedParameterPtr params,
>                        int nparams)
> @@ -1085,6 +1097,7 @@ struct secretEventData {
>  
>  struct secretEventData secretEvents[] = {
>      SECRET_EVENT(VIR_SECRET_EVENT_ID_LIFECYCLE, mySecretEventCallback),
> +    SECRET_EVENT(VIR_SECRET_EVENT_ID_VALUE_CHANGED, mySecretEventValueChanged),
>  };
>  
>  /* make sure that the events are kept in sync */

Yep, that looks sane.


Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|




More information about the libvir-list mailing list