c480ed
From 75f8c320bb6a09f111db513c52c71bbb5b3b7b9f Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <75f8c320bb6a09f111db513c52c71bbb5b3b7b9f@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:05:56 +0200
c480ed
Subject: [PATCH] vircgroup: Extract mount options matching into function
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit 6d5b91f0f5527ed79b39f1f1a375a35869e75356)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <6c5aa678b08ceb1efd6d1bda2350a979ca59035b.1561993099.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c | 84 ++++++++++++++++++++++++++------------------
c480ed
 1 file changed, 49 insertions(+), 35 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index 9032bcbb63..ec9994780a 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -399,6 +399,33 @@ virCgroupResolveMountLink(char *mntDir,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static bool
c480ed
+virCgroupMountOptsMatchController(const char *mntOpts,
c480ed
+                                  const char *typeStr)
c480ed
+{
c480ed
+    const char *tmp = mntOpts;
c480ed
+    int typeLen = strlen(typeStr);
c480ed
+
c480ed
+    while (tmp) {
c480ed
+        const char *next = strchr(tmp, ',');
c480ed
+        int len;
c480ed
+        if (next) {
c480ed
+            len = next - tmp;
c480ed
+            next++;
c480ed
+        } else {
c480ed
+            len = strlen(tmp);
c480ed
+        }
c480ed
+
c480ed
+        if (typeLen == len && STREQLEN(typeStr, tmp, len))
c480ed
+            return true;
c480ed
+
c480ed
+        tmp = next;
c480ed
+    }
c480ed
+
c480ed
+    return false;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 /*
c480ed
  * Process /proc/mounts figuring out what controllers are
c480ed
  * mounted and where
c480ed
@@ -426,42 +453,29 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
c480ed
 
c480ed
         for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
c480ed
             const char *typestr = virCgroupControllerTypeToString(i);
c480ed
-            int typelen = strlen(typestr);
c480ed
-            char *tmp = entry.mnt_opts;
c480ed
-            virCgroupControllerPtr controller = &group->controllers[i];
c480ed
-            while (tmp) {
c480ed
-                char *next = strchr(tmp, ',');
c480ed
-                int len;
c480ed
-                if (next) {
c480ed
-                    len = next-tmp;
c480ed
-                    next++;
c480ed
-                } else {
c480ed
-                    len = strlen(tmp);
c480ed
+
c480ed
+            if (virCgroupMountOptsMatchController(entry.mnt_opts, typestr)) {
c480ed
+                /* Note that the lines in /proc/mounts have the same
c480ed
+                 * order than the mount operations, and that there may
c480ed
+                 * be duplicates due to bind mounts. This means
c480ed
+                 * that the same mount point may be processed more than
c480ed
+                 * once. We need to save the results of the last one,
c480ed
+                 * and we need to be careful to release the memory used
c480ed
+                 * by previous processing. */
c480ed
+                virCgroupControllerPtr controller = &group->controllers[i];
c480ed
+
c480ed
+                VIR_FREE(controller->mountPoint);
c480ed
+                VIR_FREE(controller->linkPoint);
c480ed
+                if (VIR_STRDUP(controller->mountPoint, entry.mnt_dir) < 0)
c480ed
+                    goto cleanup;
c480ed
+
c480ed
+                /* If it is a co-mount it has a filename like "cpu,cpuacct"
c480ed
+                 * and we must identify the symlink path */
c480ed
+                if (checkLinks &&
c480ed
+                    virCgroupResolveMountLink(entry.mnt_dir, typestr,
c480ed
+                                              controller) < 0) {
c480ed
+                    goto cleanup;
c480ed
                 }
c480ed
-
c480ed
-                if (typelen == len && STREQLEN(typestr, tmp, len)) {
c480ed
-
c480ed
-                    /* Note that the lines in /proc/mounts have the same
c480ed
-                     * order than the mount operations, and that there may
c480ed
-                     * be duplicates due to bind mounts. This means
c480ed
-                     * that the same mount point may be processed more than
c480ed
-                     * once. We need to save the results of the last one,
c480ed
-                     * and we need to be careful to release the memory used
c480ed
-                     * by previous processing. */
c480ed
-                    VIR_FREE(controller->mountPoint);
c480ed
-                    VIR_FREE(controller->linkPoint);
c480ed
-                    if (VIR_STRDUP(controller->mountPoint, entry.mnt_dir) < 0)
c480ed
-                        goto cleanup;
c480ed
-
c480ed
-                    /* If it is a co-mount it has a filename like "cpu,cpuacct"
c480ed
-                     * and we must identify the symlink path */
c480ed
-                    if (checkLinks &&
c480ed
-                        virCgroupResolveMountLink(entry.mnt_dir, typestr,
c480ed
-                                                  controller) < 0) {
c480ed
-                            goto cleanup;
c480ed
-                    }
c480ed
-                }
c480ed
-                tmp = next;
c480ed
             }
c480ed
         }
c480ed
     }
c480ed
-- 
c480ed
2.22.0
c480ed