render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 75f8c320bb6a09f111db513c52c71bbb5b3b7b9f Mon Sep 17 00:00:00 2001
Message-Id: <75f8c320bb6a09f111db513c52c71bbb5b3b7b9f@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:05:56 +0200
Subject: [PATCH] vircgroup: Extract mount options matching into function
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 6d5b91f0f5527ed79b39f1f1a375a35869e75356)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <6c5aa678b08ceb1efd6d1bda2350a979ca59035b.1561993099.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroup.c | 84 ++++++++++++++++++++++++++------------------
 1 file changed, 49 insertions(+), 35 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 9032bcbb63..ec9994780a 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -399,6 +399,33 @@ virCgroupResolveMountLink(char *mntDir,
 }
 
 
+static bool
+virCgroupMountOptsMatchController(const char *mntOpts,
+                                  const char *typeStr)
+{
+    const char *tmp = mntOpts;
+    int typeLen = strlen(typeStr);
+
+    while (tmp) {
+        const char *next = strchr(tmp, ',');
+        int len;
+        if (next) {
+            len = next - tmp;
+            next++;
+        } else {
+            len = strlen(tmp);
+        }
+
+        if (typeLen == len && STREQLEN(typeStr, tmp, len))
+            return true;
+
+        tmp = next;
+    }
+
+    return false;
+}
+
+
 /*
  * Process /proc/mounts figuring out what controllers are
  * mounted and where
@@ -426,42 +453,29 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
 
         for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
             const char *typestr = virCgroupControllerTypeToString(i);
-            int typelen = strlen(typestr);
-            char *tmp = entry.mnt_opts;
-            virCgroupControllerPtr controller = &group->controllers[i];
-            while (tmp) {
-                char *next = strchr(tmp, ',');
-                int len;
-                if (next) {
-                    len = next-tmp;
-                    next++;
-                } else {
-                    len = strlen(tmp);
+
+            if (virCgroupMountOptsMatchController(entry.mnt_opts, typestr)) {
+                /* Note that the lines in /proc/mounts have the same
+                 * order than the mount operations, and that there may
+                 * be duplicates due to bind mounts. This means
+                 * that the same mount point may be processed more than
+                 * once. We need to save the results of the last one,
+                 * and we need to be careful to release the memory used
+                 * by previous processing. */
+                virCgroupControllerPtr controller = &group->controllers[i];
+
+                VIR_FREE(controller->mountPoint);
+                VIR_FREE(controller->linkPoint);
+                if (VIR_STRDUP(controller->mountPoint, entry.mnt_dir) < 0)
+                    goto cleanup;
+
+                /* 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,
+                                              controller) < 0) {
+                    goto cleanup;
                 }
-
-                if (typelen == len && STREQLEN(typestr, tmp, len)) {
-
-                    /* Note that the lines in /proc/mounts have the same
-                     * order than the mount operations, and that there may
-                     * be duplicates due to bind mounts. This means
-                     * that the same mount point may be processed more than
-                     * once. We need to save the results of the last one,
-                     * and we need to be careful to release the memory used
-                     * by previous processing. */
-                    VIR_FREE(controller->mountPoint);
-                    VIR_FREE(controller->linkPoint);
-                    if (VIR_STRDUP(controller->mountPoint, entry.mnt_dir) < 0)
-                        goto cleanup;
-
-                    /* 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,
-                                                  controller) < 0) {
-                            goto cleanup;
-                    }
-                }
-                tmp = next;
             }
         }
     }
-- 
2.22.0