[libvirt] [PATCH 8/9] vircgrouptest: call virCgroupDetectMounts directly

Fabiano Fidêncio fidencio at redhat.com
Wed Sep 19 11:36:56 UTC 2018


On Tue, Sep 18, 2018 at 2:18 PM, Pavel Hrdina <phrdina at redhat.com> wrote:

> Because we can set which files to return for cgroup tests there
> is no need to have special function tailored to run tests.
>
> Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
> ---
>  src/libvirt_private.syms |  2 +-
>  src/util/vircgroup.c     | 21 +++++----------------
>  src/util/vircgrouppriv.h |  4 +---
>  tests/vircgrouptest.c    | 16 ++++++++--------
>  4 files changed, 15 insertions(+), 28 deletions(-)
>
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index ad7ce57b65..7f3b5738c4 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -1513,7 +1513,7 @@ virCgroupDelThread;
>  virCgroupDenyAllDevices;
>  virCgroupDenyDevice;
>  virCgroupDenyDevicePath;
> -virCgroupDetectMountsFromFile;
> +virCgroupDetectMounts;
>  virCgroupFree;
>  virCgroupGetBlkioDeviceReadBps;
>  virCgroupGetBlkioDeviceReadIops;
> diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
> index 3211f63cb1..f8ef76136b 100644
> --- a/src/util/vircgroup.c
> +++ b/src/util/vircgroup.c
> @@ -430,9 +430,7 @@ virCgroupMountOptsMatchController(const char *mntOpts,
>   * mounted and where
>   */
>  int
> -virCgroupDetectMountsFromFile(virCgroupPtr group,
> -                              const char *path,
> -                              bool checkLinks)
> +virCgroupDetectMounts(virCgroupPtr group)
>  {
>      size_t i;
>      FILE *mounts = NULL;
> @@ -440,9 +438,9 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
>      char buf[CGROUP_MAX_VAL];
>      int ret = -1;
>
> -    mounts = fopen(path, "r");
> +    mounts = fopen("/proc/mounts", "r");
>      if (mounts == NULL) {
> -        virReportSystemError(errno, _("Unable to open %s"), path);
> +        virReportSystemError(errno, "%s", _("Unable to open
> /proc/mounts"));
>          return -1;
>      }
>
> @@ -470,8 +468,7 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
>
>                  /* If it is a co-mount it has a filename like
> "cpu,cpuacct"
>                   * and we must identify the symlink path */
> -                if (checkLinks &&
> -                    virCgroupResolveMountLink(entry.mnt_dir, typestr,
> +                if (virCgroupResolveMountLink(entry.mnt_dir, typestr,
>                                                controller) < 0) {
>                      goto cleanup;
>                  }
> @@ -485,12 +482,6 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
>      return ret;
>  }
>
> -static int
> -virCgroupDetectMounts(virCgroupPtr group)
> -{
> -    return virCgroupDetectMountsFromFile(group, "/proc/mounts", true);
> -}
> -
>
>  static int
>  virCgroupCopyPlacement(virCgroupPtr group,
> @@ -4082,9 +4073,7 @@ virCgroupAvailable(void)
>
>
>  int
> -virCgroupDetectMountsFromFile(virCgroupPtr group ATTRIBUTE_UNUSED,
> -                              const char *path ATTRIBUTE_UNUSED,
> -                              bool checkLinks ATTRIBUTE_UNUSED)
> +virCgroupDetectMounts(virCgroupPtr group ATTRIBUTE_UNUSED)
>  {
>      virReportSystemError(ENXIO, "%s",
>                           _("Control groups not supported on this
> platform"));
> diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
> index a0034f3889..f78fe8bb9c 100644
> --- a/src/util/vircgrouppriv.h
> +++ b/src/util/vircgrouppriv.h
> @@ -50,9 +50,7 @@ struct _virCgroup {
>      virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST];
>  };
>
> -int virCgroupDetectMountsFromFile(virCgroupPtr group,
> -                                  const char *path,
> -                                  bool checkLinks);
> +int virCgroupDetectMounts(virCgroupPtr group);
>
>  int virCgroupNewPartition(const char *path,
>                            bool create,
> diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
> index 7968903cad..6a38091a86 100644
> --- a/tests/vircgrouptest.c
> +++ b/tests/vircgrouptest.c
> @@ -164,21 +164,21 @@ testCgroupDetectMounts(const void *args)
>  {
>      int result = -1;
>      const char *file = args;
> -    char *mounts = NULL;
>      char *parsed = NULL;
>      const char *actual;
>      virCgroupPtr group = NULL;
>      virBuffer buf = VIR_BUFFER_INITIALIZER;
>      size_t i;
>
> -    if (virAsprintf(&mounts, "%s/vircgroupdata/%s.mounts",
> -                    abs_srcdir, file) < 0 ||
> -        virAsprintf(&parsed, "%s/vircgroupdata/%s.parsed",
> -                    abs_srcdir, file) < 0 ||
> -        VIR_ALLOC(group) < 0)
> +    setenv("VIR_CGROUP_MOCK_FILENAME", file, 1);
> +
> +    if (virAsprintf(&parsed, "%s/vircgroupdata/%s.parsed", abs_srcdir,
> file) < 0)
> +        goto cleanup;
> +
> +    if (VIR_ALLOC(group) < 0)
>

Just a comment ... although there was no need to split this in two
different checks, I do believe it's cleaner to read.


>          goto cleanup;
>
> -    if (virCgroupDetectMountsFromFile(group, mounts, false) < 0)
> +    if (virCgroupDetectMounts(group) < 0)
>          goto cleanup;
>
>      for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
> @@ -196,7 +196,7 @@ testCgroupDetectMounts(const void *args)
>      result = 0;
>
>   cleanup:
> -    VIR_FREE(mounts);
> +    unsetenv("VIR_CGROUP_MOCK_FILENAME");
>      VIR_FREE(parsed);
>      virCgroupFree(&group);
>      virBufferFreeAndReset(&buf);
> --
> 2.17.1
>
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
>

Reviewed-by: Fabiano Fidêncio <fidencio at redhat.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180919/db84a14f/attachment-0001.htm>


More information about the libvir-list mailing list