Re: [PATCH v2 6/9] admin: Add URI support and introduce virAdmGetDefaultURI

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

 




On 10/16/2015 02:12 PM, Erik Skultety wrote:
> Since virt-admin should be able to connect to various admin servers
> on hosted different daemons, we need to provide URI support to
> libvirt-admin.
> ---
>  include/libvirt/libvirt-admin.h |   2 +
>  src/datatypes.c                 |   2 +
>  src/datatypes.h                 |   1 +
>  src/libvirt-admin.c             | 132 +++++++++++++++++++++++++++++++---------
>  src/libvirt_admin_public.syms   |   1 +
>  tools/virt-admin.c              |  39 ++++++++++++
>  6 files changed, 147 insertions(+), 30 deletions(-)
> 

Ran the series through the Coverity checks...

[...]

>  /**
>   * virAdmConnectOpen:
>   * @name: uri of the daemon to connect to, NULL for default
> @@ -170,6 +199,7 @@ virAdmConnectOpen(const char *name, unsigned int flags)
>  {
>      char *sock_path = NULL;
>      virAdmConnectPtr conn = NULL;
> +    virConfPtr conf = NULL;
>  
>      if (virAdmInitialize() < 0)
>          goto error;
> @@ -180,7 +210,18 @@ virAdmConnectOpen(const char *name, unsigned int flags)
>      if (!(conn = virAdmConnectNew()))
>          goto error;
>  
> -    if (!(sock_path = getSocketPath(name)))
> +    if (virGetLibvirtConfigFile(&conf) < 0)
> +        goto error;
> +

conf is allocated now and will need to be free'd/cleaned appropriately
via virConfFree() @ error:

John

> +    if (!name) {
> +        if (virAdmGetDefaultURI(conf, &conn->uri) < 0)
> +            goto error;
> +    } else {
> +        if (!(conn->uri = virURIParse(name)))
> +            goto error;
> +    }
> +
> +    if (!(sock_path = getSocketPath(conn->uri)))
>          goto error;
>  
>      if (!(conn->privateData = remoteAdminPrivNew(sock_path)))
> @@ -304,3 +345,34 @@ virAdmConnectIsAlive(virAdmConnectPtr conn)
>      else
>          return 0;
>  }
> +
> +/**
> + * virAdmConnectGetURI:
> + * @conn: pointer to an admin connection
> + *
> + * String returned by this method is normally the same as the string passed
> + * to the virAdmConnectOpen. Even if NULL was passed to virAdmConnectOpen,
> + * this method returns a non-null URI string.
> + *
> + * Returns an URI string related to the connection or NULL in case of an error.
> + * Caller is responsible for freeing the string.
> + */
> +char *
> +virAdmConnectGetURI(virAdmConnectPtr conn)
> +{
> +    char *uri = NULL;
> +    VIR_DEBUG("conn=%p", conn);
> +
> +    virResetLastError();
> +
> +    virCheckAdmConnectReturn(conn, NULL);
> +
> +    if (!(uri = virURIFormat(conn->uri)))
> +        goto error;
> +
> +    return uri;
> +
> + error:
> +    virDispatchError(NULL);
> +    return uri;
> +}

[...]

--
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]