Re: [PATCH v2 05/10] admin: Introduce virAdmConnectGetLoggingFilters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 11/25/2016 08:12 AM, Erik Skultety wrote:
> Enable libvirt users to query logging filter settings.
> 
> Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
> ---
>  daemon/admin.c                  | 47 +++++++++++++++++++++++++++++++++++++++++
>  include/libvirt/libvirt-admin.h |  4 ++++
>  src/admin/admin_protocol.x      | 16 +++++++++++++-
>  src/admin/admin_remote.c        | 35 ++++++++++++++++++++++++++++++
>  src/admin_protocol-structs      |  8 +++++++
>  src/libvirt-admin.c             | 41 +++++++++++++++++++++++++++++++++++
>  src/libvirt_admin_private.syms  |  2 ++
>  src/libvirt_admin_public.syms   |  1 +
>  8 files changed, 153 insertions(+), 1 deletion(-)
> 
> diff --git a/daemon/admin.c b/daemon/admin.c
> index 4fa3851..f3bc1de 100644
> --- a/daemon/admin.c
> +++ b/daemon/admin.c
> @@ -399,6 +399,22 @@ adminConnectGetLoggingOutputs(char **outputs, unsigned int flags)
>      return virLogGetNbOutputs();
>  }
>  
> +/* Returns the number of defined filters or -1 in case of an error */
> +static int
> +adminConnectGetLoggingFilters(char **filters, unsigned int flags)
> +{
> +    char *tmp = NULL;
> +    int ret = 0;
> +
> +    virCheckFlags(0, -1);
> +
> +    if ((ret = virLogGetNbFilters()) > 0 && !(tmp = virLogGetFilters()))
> +        return -1;
> +
> +    *filters = tmp;
> +    return ret;
> +}
> +
>  static int
>  adminDispatchConnectGetLoggingOutputs(virNetServerPtr server ATTRIBUTE_UNUSED,
>                                        virNetServerClientPtr client ATTRIBUTE_UNUSED,
> @@ -420,4 +436,35 @@ adminDispatchConnectGetLoggingOutputs(virNetServerPtr server ATTRIBUTE_UNUSED,
>  
>      return 0;
>  }
> +
> +static int
> +adminDispatchConnectGetLoggingFilters(virNetServerPtr server ATTRIBUTE_UNUSED,
> +                                      virNetServerClientPtr client ATTRIBUTE_UNUSED,
> +                                      virNetMessagePtr msg ATTRIBUTE_UNUSED,
> +                                      virNetMessageErrorPtr rerr,
> +                                      admin_connect_get_logging_filters_args *args,
> +                                      admin_connect_get_logging_filters_ret *ret)
> +{
> +    char *filters = NULL;
> +    int nfilters = 0;
> +
> +    if ((nfilters = adminConnectGetLoggingFilters(&filters, args->flags)) < 0) {
> +        virNetMessageSaveError(rerr);
> +        return -1;
> +    }
> +
> +    if (nfilters == 0) {
> +        ret->filters = NULL;
> +    } else {
> +        char **ret_filters = NULL;
> +        if (VIR_ALLOC(ret_filters) < 0)
> +            return -1;
> +
> +        *ret_filters = filters;
> +        ret->filters = ret_filters;

So while this works - why the extra effort to allocate an array of 1
item to stuff the returned filter into it?

While I understand outputs has a default and thus doesn't return NULL -
the adminConnectGetLoggingFilters will return :

-1 on failure
0 w/ NULL filters
# w/ non-NULL filters

So I believe you could still just VIR_STEAL_PTR(ret->filters, filters)
as it doesn't distinguish if 'b' is NULL or not - it just assigns it.

> +    }
> +    ret->nfilters = nfilters;
> +
> +    return 0;
> +}
>  #include "admin_dispatch.h"
> diff --git a/include/libvirt/libvirt-admin.h b/include/libvirt/libvirt-admin.h
> index 46d2155..d76ac20 100644
> --- a/include/libvirt/libvirt-admin.h
> +++ b/include/libvirt/libvirt-admin.h
> @@ -408,6 +408,10 @@ int virAdmConnectGetLoggingOutputs(virAdmConnectPtr conn,
>                                     char **outputs,
>                                     unsigned int flags);
>  
> +int virAdmConnectGetLoggingFilters(virAdmConnectPtr conn,
> +                                   char **filters,
> +                                   unsigned int flags);
> +
>  # ifdef __cplusplus
>  }
>  # endif
> diff --git a/src/admin/admin_protocol.x b/src/admin/admin_protocol.x
> index 237632a..8316bc4 100644
> --- a/src/admin/admin_protocol.x
> +++ b/src/admin/admin_protocol.x
> @@ -192,6 +192,15 @@ struct admin_connect_get_logging_outputs_ret {
>      unsigned int noutputs;
>  };
>  
> +struct admin_connect_get_logging_filters_args {
> +    unsigned int flags;
> +};
> +
> +struct admin_connect_get_logging_filters_ret {
> +    admin_string filters;
> +    unsigned int nfilters;
> +};
> +
>  /* Define the program number, protocol version and procedure numbers here. */
>  const ADMIN_PROGRAM = 0x06900690;
>  const ADMIN_PROTOCOL_VERSION = 1;
> @@ -282,5 +291,10 @@ enum admin_procedure {
>      /**
>       * @generate: none
>       */
> -    ADMIN_PROC_CONNECT_GET_LOGGING_OUTPUTS = 14
> +    ADMIN_PROC_CONNECT_GET_LOGGING_OUTPUTS = 14,
> +
> +    /**
> +     * @generate: none
> +     */
> +    ADMIN_PROC_CONNECT_GET_LOGGING_FILTERS = 15
>  };
> diff --git a/src/admin/admin_remote.c b/src/admin/admin_remote.c
> index e472484..b29d109 100644
> --- a/src/admin/admin_remote.c
> +++ b/src/admin/admin_remote.c
> @@ -460,3 +460,38 @@ remoteAdminConnectGetLoggingOutputs(virAdmConnectPtr conn,
>      virObjectUnlock(priv);
>      return rv;
>  }
> +
> +static int
> +remoteAdminConnectGetLoggingFilters(virAdmConnectPtr conn,
> +                                    char **filters,
> +                                    unsigned int flags)
> +{
> +    int rv = -1;
> +    remoteAdminPrivPtr priv = conn->privateData;
> +    admin_connect_get_logging_filters_args args;
> +    admin_connect_get_logging_filters_ret ret;
> +
> +    args.flags = flags;
> +
> +    memset(&ret, 0, sizeof(ret));
> +    virObjectLock(priv);
> +
> +    if (call(conn,
> +             0,
> +             ADMIN_PROC_CONNECT_GET_LOGGING_FILTERS,
> +             (xdrproc_t) xdr_admin_connect_get_logging_filters_args,
> +             (char *) &args,
> +             (xdrproc_t) xdr_admin_connect_get_logging_filters_ret,
> +             (char *) &ret) == -1)
> +        goto done;
> +
> +    if (filters)
> +        *filters = ret.filters ? *ret.filters : NULL;

Thus when you get back here you can just still *filters and not care
that ret.filters is an array of 1 item.
> +
> +    rv = ret.nfilters;
> +    VIR_FREE(ret.filters);
> +
> + done:
> +    virObjectUnlock(priv);
> +    return rv;
> +}
> diff --git a/src/admin_protocol-structs b/src/admin_protocol-structs
> index 096bf5a..c172557 100644
> --- a/src/admin_protocol-structs
> +++ b/src/admin_protocol-structs
> @@ -134,6 +134,13 @@ struct admin_connect_get_logging_outputs_ret {
>          admin_nonnull_string       outputs;
>          u_int                      noutputs;
>  };
> +struct admin_connect_get_logging_filters_args {
> +        u_int                      flags;
> +};
> +struct admin_connect_get_logging_filters_ret {
> +        admin_string               filters;
> +        u_int                      nfilters;
> +};
>  enum admin_procedure {
>          ADMIN_PROC_CONNECT_OPEN = 1,
>          ADMIN_PROC_CONNECT_CLOSE = 2,
> @@ -149,4 +156,5 @@ enum admin_procedure {
>          ADMIN_PROC_SERVER_GET_CLIENT_LIMITS = 12,
>          ADMIN_PROC_SERVER_SET_CLIENT_LIMITS = 13,
>          ADMIN_PROC_CONNECT_GET_LOGGING_OUTPUTS = 14,
> +        ADMIN_PROC_CONNECT_GET_LOGGING_FILTERS = 15,
>  };
> diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c
> index 13cba1d..29754a8 100644
> --- a/src/libvirt-admin.c
> +++ b/src/libvirt-admin.c
> @@ -1124,3 +1124,44 @@ virAdmConnectGetLoggingOutputs(virAdmConnectPtr conn,
>      virDispatchError(NULL);
>      return -1;
>  }
> +
> +/**
> + * virAdmConnectGetLoggingFilters:
> + * @conn: pointer to an active admin connection
> + * @filters: pointer to a variable to store a string containing all currently
> + *           defined logging filters on daemon (allocated automatically) or
> + *           NULL if just the number of defined outputs is required

s/outputs/filters

Since you seem to be allowing the or NULL....

> + * @flags: extra flags; not used yet, so callers should always pass 0
> + *
> + * Retrieves a list of currently installed logging filters. Filters returned
> + * are contained within an automatically allocated string and delimited by
> + * spaces. The format of each filter conforms to the format described in
> + * daemon's configuration file (e.g. libvirtd.conf).
> + *
> + * To retrieve individual filters, additional parsing needs to be done by the
> + * caller. Caller is also responsible for freeing @filters correctly.
> + *
> + * Returns the number of filters returned in @filters, or -1 in case of
> + * an error.
> + */
> +int
> +virAdmConnectGetLoggingFilters(virAdmConnectPtr conn,
> +                               char **filters,
> +                               unsigned int flags)
> +{
> +    int ret = -1;
> +
> +    VIR_DEBUG("conn=%p, flags=%x", conn, flags);
> +
> +    virResetLastError();
> +    virCheckAdmConnectReturn(conn, -1);
> +
> +    if ((ret = remoteAdminConnectGetLoggingFilters(conn, filters,
> +                                                   flags)) < 0)
> +        goto error;
> +
> +    return ret;
> + error:
> +    virDispatchError(NULL);
> +    return -1;
> +}
> diff --git a/src/libvirt_admin_private.syms b/src/libvirt_admin_private.syms
> index 7160af6..f2e03d1 100644
> --- a/src/libvirt_admin_private.syms
> +++ b/src/libvirt_admin_private.syms
> @@ -10,6 +10,8 @@ xdr_admin_client_close_args;
>  xdr_admin_client_get_info_args;
>  xdr_admin_client_get_info_ret;
>  xdr_admin_connect_get_lib_version_ret;
> +xdr_admin_connect_get_logging_filters_args;
> +xdr_admin_connect_get_logging_filters_ret;
>  xdr_admin_connect_get_logging_outputs_args;
>  xdr_admin_connect_get_logging_outputs_ret;
>  xdr_admin_connect_list_servers_args;
> diff --git a/src/libvirt_admin_public.syms b/src/libvirt_admin_public.syms
> index 9343a4f..234c50e 100644
> --- a/src/libvirt_admin_public.syms
> +++ b/src/libvirt_admin_public.syms
> @@ -43,4 +43,5 @@ LIBVIRT_ADMIN_2.0.0 {
>  LIBVIRT_ADMIN_2.5.0 {
>      global:
>          virAdmConnectGetLoggingOutputs;
> +        virAdmConnectGetLoggingFilters;
>  } LIBVIRT_ADMIN_2.0.0;
> 
s/2.5.0/3.0.0

ACK w/ adjustments

John

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux