render / rpms / libvirt

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