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