|
Pablo Greco |
40546a |
From d7a8cd2fdafd168eb1672e7ecde1700463792518 Mon Sep 17 00:00:00 2001
|
|
Pablo Greco |
40546a |
Message-Id: <d7a8cd2fdafd168eb1672e7ecde1700463792518@dist-git>
|
|
Pablo Greco |
40546a |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Date: Mon, 1 Jul 2019 17:05:50 +0200
|
|
Pablo Greco |
40546a |
Subject: [PATCH] vircgroup: Extract file link resolving into separate 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 00a0085aa17677003e89cdafceb6a0260af43fb8)
|
|
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: <6d3c5594a53824ceac258a0f54162ec8af5aef37.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 | 85 +++++++++++++++++++++++++-------------------
|
|
Pablo Greco |
40546a |
1 file changed, 48 insertions(+), 37 deletions(-)
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
|
|
Pablo Greco |
40546a |
index 5144b33d43..8ddedbfe7c 100644
|
|
Pablo Greco |
40546a |
--- a/src/util/vircgroup.c
|
|
Pablo Greco |
40546a |
+++ b/src/util/vircgroup.c
|
|
Pablo Greco |
40546a |
@@ -356,6 +356,51 @@ virCgroupCopyMounts(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
+static int
|
|
Pablo Greco |
40546a |
+virCgroupResolveMountLink(char *mntDir,
|
|
Pablo Greco |
40546a |
+ const char *typeStr,
|
|
Pablo Greco |
40546a |
+ virCgroupControllerPtr controller)
|
|
Pablo Greco |
40546a |
+{
|
|
Pablo Greco |
40546a |
+ VIR_AUTOFREE(char *) linkSrc = NULL;
|
|
Pablo Greco |
40546a |
+ char *dirName;
|
|
Pablo Greco |
40546a |
+ struct stat sb;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ dirName = strrchr(mntDir, '/');
|
|
Pablo Greco |
40546a |
+ if (!dirName) {
|
|
Pablo Greco |
40546a |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
Pablo Greco |
40546a |
+ _("Missing '/' separator in cgroup mount '%s'"), mntDir);
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (!strchr(dirName + 1, ','))
|
|
Pablo Greco |
40546a |
+ return 0;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ *dirName = '\0';
|
|
Pablo Greco |
40546a |
+ if (virAsprintf(&linkSrc, "%s/%s", mntDir, typeStr) < 0)
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ *dirName = '/';
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (lstat(linkSrc, &sb) < 0) {
|
|
Pablo Greco |
40546a |
+ if (errno == ENOENT) {
|
|
Pablo Greco |
40546a |
+ VIR_WARN("Controller %s co-mounted at %s is missing symlink at %s",
|
|
Pablo Greco |
40546a |
+ typeStr, mntDir, linkSrc);
|
|
Pablo Greco |
40546a |
+ } else {
|
|
Pablo Greco |
40546a |
+ virReportSystemError(errno, _("Cannot stat %s"), linkSrc);
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+ } else {
|
|
Pablo Greco |
40546a |
+ if (!S_ISLNK(sb.st_mode)) {
|
|
Pablo Greco |
40546a |
+ VIR_WARN("Expecting a symlink at %s for controller %s",
|
|
Pablo Greco |
40546a |
+ linkSrc, typeStr);
|
|
Pablo Greco |
40546a |
+ } else {
|
|
Pablo Greco |
40546a |
+ VIR_STEAL_PTR(controller->linkPoint, linkSrc);
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ return 0;
|
|
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 |
@@ -397,8 +442,6 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
if (typelen == len && STREQLEN(typestr, tmp, len)) {
|
|
Pablo Greco |
40546a |
- struct stat sb;
|
|
Pablo Greco |
40546a |
- char *tmp2;
|
|
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 |
@@ -412,44 +455,12 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
if (VIR_STRDUP(controller->mountPoint, entry.mnt_dir) < 0)
|
|
Pablo Greco |
40546a |
goto cleanup;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- tmp2 = strrchr(entry.mnt_dir, '/');
|
|
Pablo Greco |
40546a |
- if (!tmp2) {
|
|
Pablo Greco |
40546a |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
Pablo Greco |
40546a |
- _("Missing '/' separator in cgroup mount '%s'"),
|
|
Pablo Greco |
40546a |
- entry.mnt_dir);
|
|
Pablo Greco |
40546a |
- goto cleanup;
|
|
Pablo Greco |
40546a |
- }
|
|
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 && strchr(tmp2 + 1, ',')) {
|
|
Pablo Greco |
40546a |
- VIR_AUTOFREE(char *) linksrc = NULL;
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- *tmp2 = '\0';
|
|
Pablo Greco |
40546a |
- if (virAsprintf(&linksrc, "%s/%s",
|
|
Pablo Greco |
40546a |
- entry.mnt_dir, typestr) < 0)
|
|
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 |
- *tmp2 = '/';
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- if (lstat(linksrc, &sb) < 0) {
|
|
Pablo Greco |
40546a |
- if (errno == ENOENT) {
|
|
Pablo Greco |
40546a |
- VIR_WARN("Controller %s co-mounted at %s is missing symlink at %s",
|
|
Pablo Greco |
40546a |
- typestr, entry.mnt_dir, linksrc);
|
|
Pablo Greco |
40546a |
- } else {
|
|
Pablo Greco |
40546a |
- virReportSystemError(errno,
|
|
Pablo Greco |
40546a |
- _("Cannot stat %s"),
|
|
Pablo Greco |
40546a |
- linksrc);
|
|
Pablo Greco |
40546a |
- goto cleanup;
|
|
Pablo Greco |
40546a |
- }
|
|
Pablo Greco |
40546a |
- } else {
|
|
Pablo Greco |
40546a |
- if (!S_ISLNK(sb.st_mode)) {
|
|
Pablo Greco |
40546a |
- VIR_WARN("Expecting a symlink at %s for controller %s",
|
|
Pablo Greco |
40546a |
- linksrc, typestr);
|
|
Pablo Greco |
40546a |
- } else {
|
|
Pablo Greco |
40546a |
- controller->linkPoint = linksrc;
|
|
Pablo Greco |
40546a |
- linksrc = NULL;
|
|
Pablo Greco |
40546a |
- }
|
|
Pablo Greco |
40546a |
- }
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
tmp = next;
|
|
Pablo Greco |
40546a |
--
|
|
Pablo Greco |
40546a |
2.22.0
|
|
Pablo Greco |
40546a |
|