Re: [dbus PATCH v2 16/22] Implement GetMemoryParameters method for Domain Interface

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

 



On Thu, Apr 12, 2018 at 04:32:55PM +0200, Katerina Koukiou wrote:
> Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx>
> ---
>  data/org.libvirt.Domain.xml |  6 ++++++
>  src/domain.c                | 37 +++++++++++++++++++++++++++++++++++++
>  2 files changed, 43 insertions(+)
> 
> diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml
> index 7f58cbd..db9a93e 100644
> --- a/data/org.libvirt.Domain.xml
> +++ b/data/org.libvirt.Domain.xml
> @@ -71,6 +71,12 @@
>          value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetJobInfo"/>
>        <arg name="jobInfo" type="(sttttttttttt)" direction="out"/>
>      </method>
> +    <method name="GetMemoryParameters">
> +      <annotation name="org.gtk.GDBus.DocString"
> +        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetMemoryParameters"/>
> +      <arg name="flags" type="u" direction="in"/>
> +      <arg name="memoryParameters" type="a{sv}" direction="out"/>
> +    </method>
>      <method name="GetStats">
>        <annotation name="org.gtk.GDBus.DocString"
>          value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainListGetStats"/>
> diff --git a/src/domain.c b/src/domain.c
> index 1896590..1f907e0 100644
> --- a/src/domain.c
> +++ b/src/domain.c
> @@ -450,6 +450,42 @@ virtDBusDomainGetJobInfo(GVariant *inArgs G_GNUC_UNUSED,
>                               jobInfo->fileRemaining);
>  }
>  
> +static void
> +virtDBusDomainGetMemoryParameters(GVariant *inArgs,
> +                                  GUnixFDList *inFDs G_GNUC_UNUSED,
> +                                  const gchar *objectPath,
> +                                  gpointer userData,
> +                                  GVariant **outArgs,
> +                                  GUnixFDList **outFDs G_GNUC_UNUSED,
> +                                  GError **error)
> +{
> +    virtDBusConnect *connect = userData;
> +    g_autoptr(virDomain) domain = NULL;
> +    g_autofree virTypedParameterPtr params = NULL;
> +    gint nparams = 0;
> +    guint flags;
> +    GVariant *grecords;
> +
> +    g_variant_get(inArgs, "(u)", &flags);
> +
> +    domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
> +    if (!domain)
> +        return;
> +
> +    if (virDomainGetMemoryParameters(domain, NULL, &nparams, flags) == 0 &&
> +        nparams != 0) {

Using temporary 'ret' variable for virDomainGetMemoryParameters will
make the code nicer:

    ret = virDomainGetMemoryParameters(domain, NULL, &nparams, flags);
    if (ret == 0 && nparams != 0) {
        ...
    }

> +        if ((params = g_new0(virTypedParameter, nparams)) == NULL)
> +            return;

There is no need to check 'params == NULL', g_new0 aborts a program if
the allocation fails.

> +        if (virDomainGetMemoryParameters(domain, params, &nparams, flags))

Explicit check for return value ' < 0' is preferred.

> +            return virtDBusUtilSetLastVirtError(error);
> +    }
> +
> +    grecords = virtDBusUtilTypedParamsToGVariant(params,
> +                                                 nparams);

This can be on a single line.

Pavel

Attachment: signature.asc
Description: PGP signature

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