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

Re: [libvirt] [PATCH 5/7] virnetserverclient: Add an internal method to retrieve client's identity



On 29.04.2016 15:45, Erik Skultety wrote:
> This method just aggregates various client object attributes, like socket
> address, connection type (RO/RW), and some TCP/TLS/UNIX identity in an atomic
> manner.
> 
> Signed-off-by: Erik Skultety <eskultet redhat com>
> ---
>  src/rpc/virnetserverclient.c | 26 ++++++++++++++++++++++++++
>  src/rpc/virnetserverclient.h |  3 +++
>  2 files changed, 29 insertions(+)
> 
> diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
> index 396b0cc..ef1b568 100644
> --- a/src/rpc/virnetserverclient.c
> +++ b/src/rpc/virnetserverclient.c
> @@ -1612,3 +1612,29 @@ virNetServerClientGetTransport(virNetServerClientPtr client)
>  
>      return ret;
>  }
> +
> +int
> +virNetServerClientGetInfo(virNetServerClientPtr client,
> +                          bool *readonly, const char **sock_addr,
> +                          virIdentityPtr *identity)
> +{
> +    int ret = -1;
> +
> +    virObjectLock(client);
> +    *readonly = client->readonly;
> +
> +    if (!(*sock_addr = virNetServerClientRemoteAddrString(client))) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                       _("No network socket associated with client"));
> +        goto cleanup;
> +    }
> +
> +    *identity = NULL;
> +    if (client->identity)
> +        *identity = virObjectRef(client->identity);

Should we drop this if() and therefore set *identity to NULL if there's
none? I guess it's better to be safe than sorry. Moreover, if we don't
do that and return 0 it's hard for callers of this function to determine
if this argument has been updated or not. In general I think that
function should either update all args or none.

> +
> +    ret = 0;
> + cleanup:
> +    virObjectUnlock(client);
> +    return ret;
> +}
> diff --git a/src/rpc/virnetserverclient.h b/src/rpc/virnetserverclient.h
> index b576fde..2fbf60c 100644
> --- a/src/rpc/virnetserverclient.h
> +++ b/src/rpc/virnetserverclient.h
> @@ -148,5 +148,8 @@ int virNetServerClientSendMessage(virNetServerClientPtr client,
>  
>  bool virNetServerClientNeedAuth(virNetServerClientPtr client);
>  int virNetServerClientGetTransport(virNetServerClientPtr client);
> +int virNetServerClientGetInfo(virNetServerClientPtr client,
> +                              bool *readonly, const char **sock_addr,
> +                              virIdentityPtr *identity);
>  
>  #endif /* __VIR_NET_SERVER_CLIENT_H__ */
> 

Don't forget to export this symbol in src/libvirt_remote.syms too.

Michal


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