Re: [PATCH 03/36] qemu: convert virQEMUCaps to GObject

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

 



On Fri, 2020-04-03 at 17:15 +0200, Rafael Fonseca wrote:
> virFileCache had to also be changed to properly unref the QEMUCaps
> objects; in turn, virfilecachetest was also converted to GObject so
> it
> plays nicely with virFileCache.

There is still some documentation in virfilecache.h that says that the
virFileCacheNewDataPtr function must return an instance of virObject.

> 
> Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
> ---
>  src/qemu/qemu_capabilities.c | 119 +++++++++++++++----------------
> ----
>  src/qemu/qemu_capabilities.h |   9 ++-
>  src/qemu/qemu_domain.c       |   8 +--
>  src/qemu/qemu_process.c      |   3 +-
>  src/util/virfilecache.c      |  13 ++--
>  tests/cputest.c              |  14 ++---
>  tests/domaincapstest.c       |   3 +-
>  tests/qemublocktest.c        |   3 +-
>  tests/qemucapabilitiestest.c |   9 +--
>  tests/qemucaps2xmltest.c     |  16 ++---
>  tests/qemucapsprobe.c        |   4 +-
>  tests/qemumemlocktest.c      |   3 +-
>  tests/testutilsqemu.c        |  18 +++---
>  tests/virfilecachetest.c     |  53 +++++++---------
>  14 files changed, 118 insertions(+), 157 deletions(-)
> 
> diff --git a/src/qemu/qemu_capabilities.c
> b/src/qemu/qemu_capabilities.c
> index 4bbd14f7ad..36a8467f2c 100644
> --- a/src/qemu/qemu_capabilities.c
> +++ b/src/qemu/qemu_capabilities.c
> @@ -639,7 +639,7 @@ static void virQEMUDomainCapsCacheDispose(void
> *obj)
>   * And don't forget to update virQEMUCapsNewCopy.
>   */
>  struct _virQEMUCaps {
> -    virObject parent;
> +    GObject parent;
>  
>      bool kvmSupportsNesting;
>  
> @@ -677,14 +677,23 @@ struct virQEMUCapsSearchData {
>  };
>  
>  
> -static virClassPtr virQEMUCapsClass;
> -static void virQEMUCapsDispose(void *obj);
> +G_DEFINE_TYPE(virQEMUCaps, vir_qemu_caps, G_TYPE_OBJECT);
>  
> -static int virQEMUCapsOnceInit(void)
> +static void virQEMUCapsFinalize(GObject *obj);
> +
> +static void vir_qemu_caps_init(virQEMUCaps *caps G_GNUC_UNUSED)
>  {
> -    if (!VIR_CLASS_NEW(virQEMUCaps, virClassForObject()))
> -        return -1;
> +}
>  
> +static void vir_qemu_caps_class_init(virQEMUCapsClass *klass)
> +{
> +    GObjectClass *obj = G_OBJECT_CLASS(klass);
> +
> +    obj->finalize = virQEMUCapsFinalize;
> +}
> +
> +static int virQEMUCapsOnceInit(void)
> +{
>      if (!(VIR_CLASS_NEW(virQEMUDomainCapsCache,
> virClassForObjectLockable())))
>          return -1;
>  
> @@ -864,7 +873,7 @@ virQEMUCapsInitGuest(virCapsPtr caps,
>                       virArch guestarch)
>  {
>      char *binary = NULL;
> -    virQEMUCapsPtr qemuCaps = NULL;
> +    g_autoptr(virQEMUCaps) qemuCaps = NULL;
>      int ret = -1;
>  
>      binary = virQEMUCapsGetDefaultEmulator(hostarch, guestarch);
> @@ -882,7 +891,6 @@ virQEMUCapsInitGuest(virCapsPtr caps,
>                                           guestarch);
>  
>      VIR_FREE(binary);
> -    virObjectUnref(qemuCaps);
>  
>      return ret;
>  }
> @@ -1633,7 +1641,7 @@ int virQEMUCapsGetDefaultVersion(virCapsPtr
> caps,
>                                   virFileCachePtr capsCache,
>                                   unsigned int *version)
>  {
> -    virQEMUCapsPtr qemucaps;
> +    g_autoptr(virQEMUCaps) qemucaps = NULL;
>      virArch hostarch;
>      virCapsDomainDataPtr capsdata;
>  
> @@ -1656,7 +1664,6 @@ int virQEMUCapsGetDefaultVersion(virCapsPtr
> caps,
>          return -1;
>  
>      *version = virQEMUCapsGetVersion(qemucaps);
> -    virObjectUnref(qemucaps);
>      return 0;
>  }
>  
> @@ -1682,26 +1689,17 @@ virQEMUDomainCapsCacheNew(void)
>  virQEMUCapsPtr
>  virQEMUCapsNew(void)
>  {
> -    virQEMUCapsPtr qemuCaps;
> -
> -    if (virQEMUCapsInitialize() < 0)
> -        return NULL;
> -
> -    if (!(qemuCaps = virObjectNew(virQEMUCapsClass)))
> -        return NULL;
> +    g_autoptr(virQEMUCaps) qemuCaps =
> +        VIR_QEMU_CAPS(g_object_new(VIR_TYPE_QEMU_CAPS, NULL));
>  
>      qemuCaps->invalidation = true;
>      if (!(qemuCaps->flags = virBitmapNew(QEMU_CAPS_LAST)))
> -        goto error;
> +        return NULL;
>  
>      if (!(qemuCaps->domCapsCache = virQEMUDomainCapsCacheNew()))
> -        goto error;
> -
> -    return qemuCaps;
> +        return NULL;
>  
> - error:
> -    virObjectUnref(qemuCaps);
> -    return NULL;
> +    return g_steal_pointer(&qemuCaps);
>  }
>  
>  
> @@ -1709,6 +1707,8 @@ virQEMUCapsPtr
>  virQEMUCapsNewBinary(const char *binary)
>  {
>      virQEMUCapsPtr qemuCaps = virQEMUCapsNew();
> +    if (!qemuCaps)
> +        return NULL;
>  
>      if (qemuCaps)
>          qemuCaps->binary = g_strdup(binary);
> @@ -1818,7 +1818,7 @@ virQEMUCapsAccelCopy(virQEMUCapsAccelPtr dst,
>  
>  virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
>  {
> -    virQEMUCapsPtr ret = virQEMUCapsNewBinary(qemuCaps->binary);
> +    g_autoptr(virQEMUCaps) ret = virQEMUCapsNewBinary(qemuCaps-
> >binary);
>      size_t i;
>  
>      if (!ret)
> @@ -1842,10 +1842,10 @@ virQEMUCapsPtr
> virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
>  
>      if (virQEMUCapsAccelCopy(&ret->kvm, &qemuCaps->kvm) < 0 ||
>          virQEMUCapsAccelCopy(&ret->tcg, &qemuCaps->tcg) < 0)
> -        goto error;
> +        return NULL;
>  
>      if (VIR_ALLOC_N(ret->gicCapabilities, qemuCaps-
> >ngicCapabilities) < 0)
> -        goto error;
> +        return NULL;
>      ret->ngicCapabilities = qemuCaps->ngicCapabilities;
>      for (i = 0; i < qemuCaps->ngicCapabilities; i++)
>          ret->gicCapabilities[i] = qemuCaps->gicCapabilities[i];
> @@ -1853,13 +1853,9 @@ virQEMUCapsPtr
> virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
>      if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SEV_GUEST) &&
>          virQEMUCapsSEVInfoCopy(&ret->sevCapabilities,
>                                 qemuCaps->sevCapabilities) < 0)
> -        goto error;
> -
> -    return ret;
> +        return NULL;
>  
> - error:
> -    virObjectUnref(ret);
> -    return NULL;
> +    return g_steal_pointer(&ret);
>  }
>  
>  
> @@ -1880,9 +1876,9 @@ virQEMUCapsAccelClear(virQEMUCapsAccelPtr caps)
>  }
>  
>  
> -void virQEMUCapsDispose(void *obj)
> +void virQEMUCapsFinalize(GObject *obj)
>  {
> -    virQEMUCapsPtr qemuCaps = obj;
> +    virQEMUCapsPtr qemuCaps = VIR_QEMU_CAPS(obj);
>  
>      virObjectUnref(qemuCaps->domCapsCache);
>      virBitmapFree(qemuCaps->flags);
> @@ -1897,6 +1893,8 @@ void virQEMUCapsDispose(void *obj)
>  
>      virQEMUCapsAccelClear(&qemuCaps->kvm);
>      virQEMUCapsAccelClear(&qemuCaps->tcg);
> +
> +    G_OBJECT_CLASS(vir_qemu_caps_parent_class)->finalize(obj);
>  }
>  
>  void
> @@ -5142,18 +5140,18 @@ virQEMUCapsNewForBinaryInternal(virArch
> hostArch,
>                                  unsigned int microcodeVersion,
>                                  const char *kernelVersion)
>  {
> -    virQEMUCapsPtr qemuCaps;
> +    g_autoptr(virQEMUCaps) qemuCaps = NULL;
>      struct stat sb;
>  
>      if (!(qemuCaps = virQEMUCapsNewBinary(binary)))
> -        goto error;
> +        return NULL;
>  
>      /* We would also want to check faccessat if we cared about ACLs,
>       * but we don't.  */
>      if (stat(binary, &sb) < 0) {
>          virReportSystemError(errno, _("Cannot check QEMU binary
> %s"),
>                               binary);
> -        goto error;
> +        return NULL;
>      }
>      qemuCaps->ctime = sb.st_ctime;
>  
> @@ -5164,11 +5162,11 @@ virQEMUCapsNewForBinaryInternal(virArch
> hostArch,
>      if (!virFileIsExecutable(binary)) {
>          virReportSystemError(errno, _("QEMU binary %s is not
> executable"),
>                               binary);
> -        goto error;
> +        return NULL;
>      }
>  
>      if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid) < 0)
> -        goto error;
> +        return NULL;
>  
>      qemuCaps->libvirtCtime = virGetSelfLastChanged();
>      qemuCaps->libvirtVersion = LIBVIR_VERSION_NUMBER;
> @@ -5184,11 +5182,7 @@ virQEMUCapsNewForBinaryInternal(virArch
> hostArch,
>          qemuCaps->kvmSupportsNesting =
> virQEMUCapsKVMSupportsNesting();
>      }
>  
> -    return qemuCaps;
> -
> - error:
> -    virObjectUnref(qemuCaps);
> -    return NULL;
> +    return g_steal_pointer(&qemuCaps);
>  }
>  
>  static void *
> @@ -5212,20 +5206,16 @@ virQEMUCapsLoadFile(const char *filename,
>                      const char *binary,
>                      void *privData)
>  {
> -    virQEMUCapsPtr qemuCaps = virQEMUCapsNewBinary(binary);
> +    g_autoptr(virQEMUCaps) qemuCaps = virQEMUCapsNewBinary(binary);
>      virQEMUCapsCachePrivPtr priv = privData;
>  
>      if (!qemuCaps)
>          return NULL;
>  
>      if (virQEMUCapsLoadCache(priv->hostArch, qemuCaps, filename) <
> 0)
> -        goto error;
> -
> -    return qemuCaps;
> +        return NULL;
>  
> - error:
> -    virObjectUnref(qemuCaps);
> -    return NULL;
> +    return g_steal_pointer(&qemuCaps);
>  }
>  
>  
> @@ -5341,15 +5331,13 @@ virQEMUCapsCacheLookupCopy(virFileCachePtr
> cache,
>                             const char *binary,
>                             const char *machineType)
>  {
> -    virQEMUCapsPtr qemuCaps = virQEMUCapsCacheLookup(cache, binary);
> +    g_autoptr(virQEMUCaps) qemuCaps = virQEMUCapsCacheLookup(cache,
> binary);
>      virQEMUCapsPtr ret;
>  
>      if (!qemuCaps)
>          return NULL;
>  
>      ret = virQEMUCapsNewCopy(qemuCaps);
> -    virObjectUnref(qemuCaps);
> -
>      if (!ret)
>          return NULL;
>  
> @@ -5453,8 +5441,7 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr
> cache,
>      virArch hostarch = virArchFromHost();
>      virArch arch = hostarch;
>      virDomainVirtType capsType;
> -    virQEMUCapsPtr qemuCaps = NULL;
> -    virQEMUCapsPtr ret = NULL;
> +    g_autoptr(virQEMUCaps) qemuCaps = NULL;
>      virArch arch_from_caps;
>      g_autofree char *probedbinary = NULL;
>  
> @@ -5462,14 +5449,14 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr
> cache,
>          (virttype = virDomainVirtTypeFromString(virttypeStr)) < 0) {
>          virReportError(VIR_ERR_INVALID_ARG,
>                         _("unknown virttype: %s"), virttypeStr);
> -        goto cleanup;
> +        return NULL;
>      }
>  
>      if (archStr &&
>          (arch = virArchFromString(archStr)) == VIR_ARCH_NONE) {
>          virReportError(VIR_ERR_INVALID_ARG,
>                         _("unknown architecture: %s"), archStr);
> -        goto cleanup;
> +        return NULL;
>      }
>  
>      if (!binary) {
> @@ -5478,7 +5465,7 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr
> cache,
>      }
>  
>      if (!(qemuCaps = virQEMUCapsCacheLookup(cache, binary)))
> -        goto cleanup;
> +        return NULL;
>  
>      arch_from_caps = virQEMUCapsGetArch(qemuCaps);
>  
> @@ -5492,7 +5479,7 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr
> cache,
>                           "match given architecture '%s'"),
>                         virArchToString(arch_from_caps),
>                         virArchToString(arch));
> -        goto cleanup;
> +        return NULL;
>      }
>  
>      if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
> @@ -5507,7 +5494,7 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr
> cache,
>          virReportError(VIR_ERR_INVALID_ARG,
>                         _("KVM is not supported by '%s' on this
> host"),
>                         binary);
> -        goto cleanup;
> +        return NULL;
>      }
>  
>      if (machine) {
> @@ -5518,7 +5505,7 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr
> cache,
>              virReportError(VIR_ERR_INVALID_ARG,
>                             _("the machine '%s' is not supported by
> emulator '%s'"),
>                             machine, binary);
> -            goto cleanup;
> +            return NULL;
>          }
>      } else {
>          machine = virQEMUCapsGetPreferredMachine(qemuCaps,
> virttype);
> @@ -5531,11 +5518,7 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr
> cache,
>      if (retMachine)
>          *retMachine = machine;
>  
> -    ret = g_steal_pointer(&qemuCaps);
> -
> - cleanup:
> -    virObjectUnref(qemuCaps);
> -    return ret;
> +    return g_steal_pointer(&qemuCaps);
>  }
>  
>  bool
> diff --git a/src/qemu/qemu_capabilities.h
> b/src/qemu/qemu_capabilities.h
> index 51ec1a5165..0602c23b10 100644
> --- a/src/qemu/qemu_capabilities.h
> +++ b/src/qemu/qemu_capabilities.h
> @@ -21,7 +21,9 @@
>  
>  #pragma once
>  
> -#include "virobject.h"
> +#include "internal.h"
> +#include <glib-object.h>
> +
>  #include "capabilities.h"
>  #include "vircommand.h"
>  #include "qemu_monitor.h"
> @@ -553,10 +555,11 @@ typedef enum { /* virQEMUCapsFlags grouping
> marker for syntax-check */
>      QEMU_CAPS_LAST /* this must always be the last item */
>  } virQEMUCapsFlags;
>  
> -typedef struct _virQEMUCaps virQEMUCaps;
> +#define VIR_TYPE_QEMU_CAPS vir_qemu_caps_get_type()
> +G_DECLARE_FINAL_TYPE(virQEMUCaps, vir_qemu_caps, VIR, QEMU_CAPS,
> GObject);
> +
>  typedef virQEMUCaps *virQEMUCapsPtr;
>  
> -G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUCaps, virObjectUnref);
>  
>  virQEMUCapsPtr virQEMUCapsNew(void);
>  virQEMUCapsPtr virQEMUCapsNewBinary(const char *binary);
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index 0ae0547b86..32dd69892a 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -2249,8 +2249,8 @@
> qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv)
>  
>      VIR_FREE(priv->machineName);
>  
> -    virObjectUnref(priv->qemuCaps);
> -    priv->qemuCaps = NULL;
> +    if (priv->qemuCaps)
> +        g_clear_object(&priv->qemuCaps);
>  
>      VIR_FREE(priv->pidfile);
>  
> @@ -6024,7 +6024,7 @@ qemuDomainPostParseDataFree(void *parseOpaque)
>  {
>      virQEMUCapsPtr qemuCaps = parseOpaque;
>  
> -    virObjectUnref(qemuCaps);
> +    g_object_unref(qemuCaps);
>  }
>  
>  
> @@ -6867,7 +6867,7 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr
> driver,
>          g_autoptr(virQEMUCaps) qCaps = NULL;
>  
>          if (qemuCaps) {
> -            qCaps = virObjectRef(qemuCaps);
> +            qCaps = g_object_ref(qemuCaps);
>          } else {
>              if (!(qCaps = virQEMUCapsCacheLookupCopy(driver-
> >qemuCapsCache,
>                                                       def->virtType,
> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index 6b9f6fb860..3f28c5245c 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -5491,7 +5491,8 @@ qemuProcessPrepareQEMUCaps(virDomainObjPtr vm,
>      qemuDomainObjPrivatePtr priv = vm->privateData;
>      size_t i;
>  
> -    virObjectUnref(priv->qemuCaps);
> +    if (priv->qemuCaps)
> +        g_object_unref(priv->qemuCaps);
>      if (!(priv->qemuCaps = virQEMUCapsCacheLookupCopy(qemuCapsCache,
>                                                        vm->def-
> >virtType,
>                                                        vm->def-
> >emulator,
> diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c
> index aecabf173d..e9b4211861 100644
> --- a/src/util/virfilecache.c
> +++ b/src/util/virfilecache.c
> @@ -34,6 +34,7 @@
>  #include "virlog.h"
>  #include "virobject.h"
>  #include "virstring.h"
> +#include <glib-object.h>
>  
>  #include <sys/stat.h>
>  #include <sys/types.h>
> @@ -169,7 +170,8 @@ virFileCacheLoad(virFileCachePtr cache,
>      *data = g_steal_pointer(&loadData);
>  
>   cleanup:
> -    virObjectUnref(loadData);
> +    if (loadData)
> +        g_object_unref(loadData);
>      return ret;
>  }
>  
> @@ -206,7 +208,7 @@ virFileCacheNewData(virFileCachePtr cache,
>              return NULL;
>  
>          if (virFileCacheSave(cache, name, data) < 0) {
> -            virObjectUnref(data);
> +            g_object_unref(data);
>              data = NULL;
>          }
>      }
> @@ -275,8 +277,7 @@ virFileCacheValidate(virFileCachePtr cache,
>          if (*data) {
>              VIR_DEBUG("Caching data '%p' for '%s'", *data, name);
>              if (virHashAddEntry(cache->table, name, *data) < 0) {
> -                virObjectUnref(*data);
> -                *data = NULL;
> +                g_clear_object(data);
>              }
>          }
>      }
> @@ -306,7 +307,7 @@ virFileCacheLookup(virFileCachePtr cache,
>      data = virHashLookup(cache->table, name);
>      virFileCacheValidate(cache, name, &data);
>  
> -    virObjectRef(data);
> +    g_object_ref(data);
>      virObjectUnlock(cache);
>  
>      return data;
> @@ -337,7 +338,7 @@ virFileCacheLookupByFunc(virFileCachePtr cache,
>      data = virHashSearch(cache->table, iter, iterData, (void
> **)&name);
>      virFileCacheValidate(cache, name, &data);
>  
> -    virObjectRef(data);
> +    g_object_ref(data);
>      virObjectUnlock(cache);
>  
>      return data;
> diff --git a/tests/cputest.c b/tests/cputest.c
> index 1f59f0d3a9..4590bfacee 100644
> --- a/tests/cputest.c
> +++ b/tests/cputest.c
> @@ -519,8 +519,8 @@ cpuTestMakeQEMUCaps(const struct data *data)
>      return qemuCaps;
>  
>   error:
> -    virObjectUnref(qemuCaps);
> -    qemuCaps = NULL;
> +    if (qemuCaps)
> +        g_clear_object(&qemuCaps);
>      goto cleanup;
>  }
>  
> @@ -529,7 +529,7 @@ static int
>  cpuTestGetCPUModels(const struct data *data,
>                      virDomainCapsCPUModelsPtr *models)
>  {
> -    virQEMUCapsPtr qemuCaps;
> +    g_autoptr(virQEMUCaps) qemuCaps = NULL;
>  
>      *models = NULL;
>  
> @@ -542,8 +542,6 @@ cpuTestGetCPUModels(const struct data *data,
>  
>      *models = virQEMUCapsGetCPUModels(qemuCaps, VIR_DOMAIN_VIRT_KVM,
> NULL, NULL);
>  
> -    virObjectUnref(qemuCaps);
> -
>      return 0;
>  }
>  
> @@ -876,7 +874,7 @@ static int
>  cpuTestJSONCPUID(const void *arg)
>  {
>      const struct data *data = arg;
> -    virQEMUCapsPtr qemuCaps = NULL;
> +    g_autoptr(virQEMUCaps) qemuCaps = NULL;
>      virCPUDefPtr cpu = NULL;
>      char *result = NULL;
>      int ret = -1;
> @@ -898,7 +896,6 @@ cpuTestJSONCPUID(const void *arg)
>      ret = cpuTestCompareXML(data->arch, cpu, result);
>  
>   cleanup:
> -    virObjectUnref(qemuCaps);
>      virCPUDefFree(cpu);
>      VIR_FREE(result);
>      return ret;
> @@ -909,7 +906,7 @@ static int
>  cpuTestJSONSignature(const void *arg)
>  {
>      const struct data *data = arg;
> -    virQEMUCapsPtr qemuCaps = NULL;
> +    g_autoptr(virQEMUCaps) qemuCaps = NULL;
>      virCPUDataPtr hostData = NULL;
>      qemuMonitorCPUModelInfoPtr modelInfo;
>      int ret = -1;
> @@ -924,7 +921,6 @@ cpuTestJSONSignature(const void *arg)
>      ret = cpuTestCompareSignature(data, hostData);
>  
>   cleanup:
> -    virObjectUnref(qemuCaps);
>      virCPUDataFree(hostData);
>      return ret;
>  }
> diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
> index fb803eaa47..d6f0021665 100644
> --- a/tests/domaincapstest.c
> +++ b/tests/domaincapstest.c
> @@ -79,7 +79,7 @@ fillQemuCaps(virDomainCapsPtr domCaps,
>  {
>      int ret = -1;
>      char *path = NULL;
> -    virQEMUCapsPtr qemuCaps = NULL;
> +    g_autoptr(virQEMUCaps) qemuCaps = NULL;
>      virDomainCapsLoaderPtr loader = &domCaps->os.loader;
>      virDomainVirtType virtType;
>  
> @@ -131,7 +131,6 @@ fillQemuCaps(virDomainCapsPtr domCaps,
>  
>      ret = 0;
>   cleanup:
> -    virObjectUnref(qemuCaps);
>      VIR_FREE(path);
>      return ret;
>  }
> diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
> index f9fbfc98f2..ec97e399c8 100644
> --- a/tests/qemublocktest.c
> +++ b/tests/qemublocktest.c
> @@ -1450,7 +1450,8 @@ mymain(void)
>   cleanup:
>      qemuTestDriverFree(&driver);
>      VIR_FREE(capslatest_x86_64);
> -    virObjectUnref(caps_x86_64);
> +    if (caps_x86_64)
> +        g_object_unref(caps_x86_64);
>  
>      return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
>  }
> diff --git a/tests/qemucapabilitiestest.c
> b/tests/qemucapabilitiestest.c
> index 5b32ac1451..b7a93748d9 100644
> --- a/tests/qemucapabilitiestest.c
> +++ b/tests/qemucapabilitiestest.c
> @@ -74,7 +74,7 @@ testQemuCaps(const void *opaque)
>      char *repliesFile = NULL;
>      char *capsFile = NULL;
>      qemuMonitorTestPtr mon = NULL;
> -    virQEMUCapsPtr capsActual = NULL;
> +    g_autoptr(virQEMUCaps) capsActual = NULL;
>      char *binary = NULL;
>      char *actual = NULL;
>      unsigned int fakeMicrocodeVersion = 0;
> @@ -138,7 +138,6 @@ testQemuCaps(const void *opaque)
>      VIR_FREE(actual);
>      VIR_FREE(binary);
>      qemuMonitorTestFree(mon);
> -    virObjectUnref(capsActual);
>      return ret;
>  }
>  
> @@ -149,8 +148,8 @@ testQemuCapsCopy(const void *opaque)
>      int ret = -1;
>      const testQemuData *data = opaque;
>      char *capsFile = NULL;
> -    virQEMUCapsPtr orig = NULL;
> -    virQEMUCapsPtr copy = NULL;
> +    g_autoptr(virQEMUCaps) orig = NULL;
> +    g_autoptr(virQEMUCaps) copy = NULL;
>      char *actual = NULL;
>  
>      capsFile = g_strdup_printf("%s/%s_%s.%s.xml",
> @@ -174,8 +173,6 @@ testQemuCapsCopy(const void *opaque)
>  
>   cleanup:
>      VIR_FREE(capsFile);
> -    virObjectUnref(orig);
> -    virObjectUnref(copy);
>      VIR_FREE(actual);
>      return ret;
>  }
> diff --git a/tests/qemucaps2xmltest.c b/tests/qemucaps2xmltest.c
> index 349af0e431..6039895fd8 100644
> --- a/tests/qemucaps2xmltest.c
> +++ b/tests/qemucaps2xmltest.c
> @@ -51,7 +51,7 @@ testQemuDataInit(testQemuDataPtr data)
>  static virQEMUCapsPtr
>  testQemuGetCaps(char *caps)
>  {
> -    virQEMUCapsPtr qemuCaps = NULL;
> +    g_autoptr(virQEMUCaps) qemuCaps = NULL;
>      xmlDocPtr xml;
>      xmlXPathContextPtr ctxt = NULL;
>      ssize_t i, n;
> @@ -85,11 +85,10 @@ testQemuGetCaps(char *caps)
>      VIR_FREE(nodes);
>      xmlFreeDoc(xml);
>      xmlXPathFreeContext(ctxt);
> -    return qemuCaps;
> +    return g_steal_pointer(&qemuCaps);
>  
>   error:
>      VIR_FREE(nodes);
> -    virObjectUnref(qemuCaps);
>      xmlFreeDoc(xml);
>      xmlXPathFreeContext(ctxt);
>      return NULL;
> @@ -98,7 +97,7 @@ testQemuGetCaps(char *caps)
>  static virCapsPtr
>  testGetCaps(char *capsData, const testQemuData *data)
>  {
> -    virQEMUCapsPtr qemuCaps = NULL;
> +    g_autoptr(virQEMUCaps) qemuCaps = NULL;
>      g_autoptr(virCaps) caps = NULL;
>      virArch arch = virArchFromString(data->archName);
>      g_autofree char *binary = NULL;
> @@ -107,7 +106,7 @@ testGetCaps(char *capsData, const testQemuData
> *data)
>  
>      if ((qemuCaps = testQemuGetCaps(capsData)) == NULL) {
>          fprintf(stderr, "failed to parse qemu capabilities flags");
> -        goto error;
> +        return NULL;
>      }
>  
>      caps = virCapabilitiesNew(arch, false, false);
> @@ -117,15 +116,10 @@ testGetCaps(char *capsData, const testQemuData
> *data)
>                                         qemuCaps,
>                                         arch) < 0) {
>          fprintf(stderr, "failed to create the capabilities from
> qemu");
> -        goto error;
> +        return NULL;
>      }
>  
> -    virObjectUnref(qemuCaps);
>      return g_steal_pointer(&caps);
> -
> - error:
> -    virObjectUnref(qemuCaps);
> -    return NULL;
>  }
>  
>  static int
> diff --git a/tests/qemucapsprobe.c b/tests/qemucapsprobe.c
> index c7e8f3309d..f3705a1ed5 100644
> --- a/tests/qemucapsprobe.c
> +++ b/tests/qemucapsprobe.c
> @@ -45,7 +45,7 @@ int
>  main(int argc, char **argv)
>  {
>      virThread thread;
> -    virQEMUCapsPtr caps;
> +    g_autoptr(virQEMUCaps) caps = NULL;
>      const char *mock = VIR_TEST_MOCK("qemucapsprobe");
>  
>      if (!virFileIsExecutable(mock)) {
> @@ -78,7 +78,5 @@ main(int argc, char **argv)
>                                                   -1, -1, 0, NULL)))
>          return EXIT_FAILURE;
>  
> -    virObjectUnref(caps);
> -
>      return EXIT_SUCCESS;
>  }
> diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c
> index 3f18fed1c3..c1945f1f2b 100644
> --- a/tests/qemumemlocktest.c
> +++ b/tests/qemumemlocktest.c
> @@ -58,7 +58,7 @@ mymain(void)
>  {
>      int ret = 0;
>      char *fakerootdir;
> -    virQEMUCapsPtr qemuCaps = NULL;
> +    g_autoptr(virQEMUCaps) qemuCaps = NULL;
>  
>      fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
>  
> @@ -148,7 +148,6 @@ mymain(void)
>      DO_TEST("pseries-locked+hostdev",
> VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
>  
>   cleanup:
> -    virObjectUnref(qemuCaps);
>  
>      if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
>          virFileDeleteTree(fakerootdir);
> diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
> index 082467f58e..dd8143ff55 100644
> --- a/tests/testutilsqemu.c
> +++ b/tests/testutilsqemu.c
> @@ -286,20 +286,16 @@ virQEMUCapsPtr
>  qemuTestParseCapabilitiesArch(virArch arch,
>                                const char *capsFile)
>  {
> -    virQEMUCapsPtr qemuCaps = NULL;
> +    g_autoptr(virQEMUCaps) qemuCaps = NULL;
>      g_autofree char *binary = g_strdup_printf("/usr/bin/qemu-system-
> %s",
>                                                virArchToString(arch))
> ;
>  
>      if (!(qemuCaps = virQEMUCapsNewBinary(binary)) ||
>          virQEMUCapsLoadCache(arch, qemuCaps, capsFile) < 0)
> -        goto error;
> +        return NULL;
>  
>      virQEMUCapsSetInvalidation(qemuCaps, false);
> -    return qemuCaps;
> -
> - error:
> -    virObjectUnref(qemuCaps);
> -    return NULL;
> +    return g_steal_pointer(&qemuCaps);
>  }
>  
>  
> @@ -359,7 +355,7 @@ int qemuTestCapsCacheInsert(virFileCachePtr
> cache,
>          }
>  
>          if (virFileCacheInsertData(cache, qemu_emulators[i],
> tmpCaps) < 0) {
> -            virObjectUnref(tmpCaps);
> +            g_object_unref(tmpCaps);
>              return -1;
>          }
>      }
> @@ -663,7 +659,7 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
>  {
>      va_list argptr;
>      testQemuInfoArgName argname;
> -    virQEMUCapsPtr qemuCaps = NULL;
> +    g_autoptr(virQEMUCaps) qemuCaps = NULL;
>      int gic = GIC_NONE;
>      char *capsarch = NULL;
>      char *capsver = NULL;
> @@ -780,7 +776,6 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
>      ret = 0;
>  
>   cleanup:
> -    virObjectUnref(qemuCaps);
>      va_end(argptr);
>  
>      return ret;
> @@ -792,5 +787,6 @@ testQemuInfoClear(struct testQemuInfo *info)
>  {
>      VIR_FREE(info->infile);
>      VIR_FREE(info->outfile);
> -    virObjectUnref(info->qemuCaps);
> +    if (info->qemuCaps)
> +        g_object_unref(info->qemuCaps);
>  }
> diff --git a/tests/virfilecachetest.c b/tests/virfilecachetest.c
> index 6d280b3bec..2c4f4a94e5 100644
> --- a/tests/virfilecachetest.c
> +++ b/tests/virfilecachetest.c
> @@ -24,52 +24,50 @@
>  #include "virfile.h"
>  #include "virfilecache.h"
>  
> +#include <glib-object.h>
>  
>  #define VIR_FROM_THIS VIR_FROM_NONE
>  
>  
>  struct _testFileCacheObj {
> -    virObject parent;
> +    GObject parent;
>      char *data;
>  };
> -typedef struct _testFileCacheObj testFileCacheObj;
> +#define TYPE_TEST_FILE_CACHE_OBJ test_file_cache_obj_get_type()
> +G_DECLARE_FINAL_TYPE(testFileCacheObj, test_file_cache_obj, TEST,
> FILE_CACHE_OBJ, GObject);
>  typedef testFileCacheObj *testFileCacheObjPtr;
>  
>  
> -static virClassPtr testFileCacheObjClass;
> +G_DEFINE_TYPE(testFileCacheObj, test_file_cache_obj, G_TYPE_OBJECT);
>  
>  
>  static void
> -testFileCacheObjDispose(void *opaque)
> +testFileCacheObjFinalize(GObject *opaque)
>  {
> -    testFileCacheObjPtr obj = opaque;
> +    testFileCacheObjPtr obj = TEST_FILE_CACHE_OBJ(opaque);
>      VIR_FREE(obj->data);
> -}
>  
> +    G_OBJECT_CLASS(test_file_cache_obj_parent_class)-
> >finalize(opaque);
> +}
>  
> -static int
> -testFileCacheObjOnceInit(void)
> +static void
> +test_file_cache_obj_init(testFileCacheObj *obj G_GNUC_UNUSED)
>  {
> -    if (!VIR_CLASS_NEW(testFileCacheObj, virClassForObject()))
> -        return -1;
> -
> -    return 0;
>  }
>  
> +static void
> +test_file_cache_obj_class_init(testFileCacheObjClass *klass)
> +{
> +    GObjectClass *obj = G_OBJECT_CLASS(klass);
>  
> -VIR_ONCE_GLOBAL_INIT(testFileCacheObj);
> +    obj->finalize = testFileCacheObjFinalize;
> +}
>  
>  
>  static testFileCacheObjPtr
>  testFileCacheObjNew(const char *data)
>  {
> -    testFileCacheObjPtr obj;
> -
> -    if (testFileCacheObjInitialize() < 0)
> -        return NULL;
> -
> -    if (!(obj = virObjectNew(testFileCacheObjClass)))
> -        return NULL;
> +    testFileCacheObjPtr obj =
> TEST_FILE_CACHE_OBJ(g_object_new(TYPE_TEST_FILE_CACHE_OBJ, NULL));
>  
>      obj->data = g_strdup(data);
>  
> @@ -160,9 +158,8 @@ typedef testFileCacheData *testFileCacheDataPtr;
>  static int
>  testFileCache(const void *opaque)
>  {
> -    int ret = -1;
>      const testFileCacheData *data = opaque;
> -    testFileCacheObjPtr obj = NULL;
> +    g_autoptr(testFileCacheObj) obj = NULL;
>      testFileCachePrivPtr testPriv = virFileCacheGetPriv(data-
> >cache);
>  
>      testPriv->dataSaved = false;
> @@ -171,27 +168,23 @@ testFileCache(const void *opaque)
>  
>      if (!(obj = virFileCacheLookup(data->cache, data->name))) {
>          fprintf(stderr, "Getting cached data failed.\n");
> -        goto cleanup;
> +        return -1;
>      }
>  
>      if (!obj->data || STRNEQ(data->expectData, obj->data)) {
>          fprintf(stderr, "Expect data '%s', loaded data '%s'.\n",
>                  data->expectData, NULLSTR(obj->data));
> -        goto cleanup;
> +        return -1;
>      }
>  
>      if (data->expectSave != testPriv->dataSaved) {
>          fprintf(stderr, "Expect data to be saved '%s', data saved
> '%s'.\n",
>                  data->expectSave ? "yes" : "no",
>                  testPriv->dataSaved ? "yes" : "no");
> -        goto cleanup;
> +        return -1;
>      }
>  
> -    ret = 0;
> -
> - cleanup:
> -    virObjectUnref(obj);
> -    return ret;
> +    return 0;
>  }
>  
>  




[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