|
|
c480ed |
From 955ac573d3291bfb069664e2df9f4edb0ed09313 Mon Sep 17 00:00:00 2001
|
|
|
c480ed |
Message-Id: <955ac573d3291bfb069664e2df9f4edb0ed09313@dist-git>
|
|
|
c480ed |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
Date: Mon, 1 Jul 2019 17:06:40 +0200
|
|
|
c480ed |
Subject: [PATCH] vircgroup: extract virCgroupV1SetOwner
|
|
|
c480ed |
MIME-Version: 1.0
|
|
|
c480ed |
Content-Type: text/plain; charset=UTF-8
|
|
|
c480ed |
Content-Transfer-Encoding: 8bit
|
|
|
c480ed |
|
|
|
c480ed |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c480ed |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
(cherry picked from commit dad061101d34a8e4b76ec3c03253ed3e83b50b2a)
|
|
|
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: <644b2434def24cbb7834a7950595c110d5438166.1561993100.git.phrdina@redhat.com>
|
|
|
c480ed |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c480ed |
---
|
|
|
c480ed |
src/util/vircgroup.c | 54 +------------------------------
|
|
|
c480ed |
src/util/vircgroupbackend.h | 7 +++++
|
|
|
c480ed |
src/util/vircgroupv1.c | 63 +++++++++++++++++++++++++++++++++++++
|
|
|
c480ed |
3 files changed, 71 insertions(+), 53 deletions(-)
|
|
|
c480ed |
|
|
|
c480ed |
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
|
|
|
c480ed |
index 7789966472..e57aecb08a 100644
|
|
|
c480ed |
--- a/src/util/vircgroup.c
|
|
|
c480ed |
+++ b/src/util/vircgroup.c
|
|
|
c480ed |
@@ -3282,59 +3282,7 @@ int virCgroupSetOwner(virCgroupPtr cgroup,
|
|
|
c480ed |
gid_t gid,
|
|
|
c480ed |
int controllers)
|
|
|
c480ed |
{
|
|
|
c480ed |
- int ret = -1;
|
|
|
c480ed |
- size_t i;
|
|
|
c480ed |
- DIR *dh = NULL;
|
|
|
c480ed |
- int direrr;
|
|
|
c480ed |
-
|
|
|
c480ed |
- for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
|
|
|
c480ed |
- VIR_AUTOFREE(char *) base = NULL;
|
|
|
c480ed |
- struct dirent *de;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (!((1 << i) & controllers))
|
|
|
c480ed |
- continue;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (!cgroup->controllers[i].mountPoint)
|
|
|
c480ed |
- continue;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virAsprintf(&base, "%s%s", cgroup->controllers[i].mountPoint,
|
|
|
c480ed |
- cgroup->controllers[i].placement) < 0)
|
|
|
c480ed |
- goto cleanup;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virDirOpen(&dh, base) < 0)
|
|
|
c480ed |
- goto cleanup;
|
|
|
c480ed |
-
|
|
|
c480ed |
- while ((direrr = virDirRead(dh, &de, base)) > 0) {
|
|
|
c480ed |
- VIR_AUTOFREE(char *) entry = NULL;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virAsprintf(&entry, "%s/%s", base, de->d_name) < 0)
|
|
|
c480ed |
- goto cleanup;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (chown(entry, uid, gid) < 0) {
|
|
|
c480ed |
- virReportSystemError(errno,
|
|
|
c480ed |
- _("cannot chown '%s' to (%u, %u)"),
|
|
|
c480ed |
- entry, uid, gid);
|
|
|
c480ed |
- goto cleanup;
|
|
|
c480ed |
- }
|
|
|
c480ed |
- }
|
|
|
c480ed |
- if (direrr < 0)
|
|
|
c480ed |
- goto cleanup;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (chown(base, uid, gid) < 0) {
|
|
|
c480ed |
- virReportSystemError(errno,
|
|
|
c480ed |
- _("cannot chown '%s' to (%u, %u)"),
|
|
|
c480ed |
- base, uid, gid);
|
|
|
c480ed |
- goto cleanup;
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- VIR_DIR_CLOSE(dh);
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- ret = 0;
|
|
|
c480ed |
-
|
|
|
c480ed |
- cleanup:
|
|
|
c480ed |
- VIR_DIR_CLOSE(dh);
|
|
|
c480ed |
- return ret;
|
|
|
c480ed |
+ return cgroup->backend->setOwner(cgroup, uid, gid, controllers);
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
|
|
|
c480ed |
index caeec3de60..74af796c2f 100644
|
|
|
c480ed |
--- a/src/util/vircgroupbackend.h
|
|
|
c480ed |
+++ b/src/util/vircgroupbackend.h
|
|
|
c480ed |
@@ -131,6 +131,12 @@ typedef int
|
|
|
c480ed |
const char *oldroot,
|
|
|
c480ed |
const char *mountopts);
|
|
|
c480ed |
|
|
|
c480ed |
+typedef int
|
|
|
c480ed |
+(*virCgroupSetOwnerCB)(virCgroupPtr cgroup,
|
|
|
c480ed |
+ uid_t uid,
|
|
|
c480ed |
+ gid_t gid,
|
|
|
c480ed |
+ int controllers);
|
|
|
c480ed |
+
|
|
|
c480ed |
struct _virCgroupBackend {
|
|
|
c480ed |
virCgroupBackendType type;
|
|
|
c480ed |
|
|
|
c480ed |
@@ -152,6 +158,7 @@ struct _virCgroupBackend {
|
|
|
c480ed |
virCgroupAddTaskCB addTask;
|
|
|
c480ed |
virCgroupHasEmptyTasksCB hasEmptyTasks;
|
|
|
c480ed |
virCgroupBindMountCB bindMount;
|
|
|
c480ed |
+ virCgroupSetOwnerCB setOwner;
|
|
|
c480ed |
};
|
|
|
c480ed |
typedef struct _virCgroupBackend virCgroupBackend;
|
|
|
c480ed |
typedef virCgroupBackend *virCgroupBackendPtr;
|
|
|
c480ed |
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
|
|
|
c480ed |
index d63525dfb0..c1e2583912 100644
|
|
|
c480ed |
--- a/src/util/vircgroupv1.c
|
|
|
c480ed |
+++ b/src/util/vircgroupv1.c
|
|
|
c480ed |
@@ -867,6 +867,68 @@ virCgroupV1BindMount(virCgroupPtr group,
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
+static int
|
|
|
c480ed |
+virCgroupV1SetOwner(virCgroupPtr cgroup,
|
|
|
c480ed |
+ uid_t uid,
|
|
|
c480ed |
+ gid_t gid,
|
|
|
c480ed |
+ int controllers)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ int ret = -1;
|
|
|
c480ed |
+ size_t i;
|
|
|
c480ed |
+ DIR *dh = NULL;
|
|
|
c480ed |
+ int direrr;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
|
|
|
c480ed |
+ VIR_AUTOFREE(char *) base = NULL;
|
|
|
c480ed |
+ struct dirent *de;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (!((1 << i) & controllers))
|
|
|
c480ed |
+ continue;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (!cgroup->controllers[i].mountPoint)
|
|
|
c480ed |
+ continue;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virAsprintf(&base, "%s%s", cgroup->controllers[i].mountPoint,
|
|
|
c480ed |
+ cgroup->controllers[i].placement) < 0)
|
|
|
c480ed |
+ goto cleanup;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virDirOpen(&dh, base) < 0)
|
|
|
c480ed |
+ goto cleanup;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ while ((direrr = virDirRead(dh, &de, base)) > 0) {
|
|
|
c480ed |
+ VIR_AUTOFREE(char *) entry = NULL;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virAsprintf(&entry, "%s/%s", base, de->d_name) < 0)
|
|
|
c480ed |
+ goto cleanup;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (chown(entry, uid, gid) < 0) {
|
|
|
c480ed |
+ virReportSystemError(errno,
|
|
|
c480ed |
+ _("cannot chown '%s' to (%u, %u)"),
|
|
|
c480ed |
+ entry, uid, gid);
|
|
|
c480ed |
+ goto cleanup;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+ if (direrr < 0)
|
|
|
c480ed |
+ goto cleanup;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (chown(base, uid, gid) < 0) {
|
|
|
c480ed |
+ virReportSystemError(errno,
|
|
|
c480ed |
+ _("cannot chown '%s' to (%u, %u)"),
|
|
|
c480ed |
+ base, uid, gid);
|
|
|
c480ed |
+ goto cleanup;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ VIR_DIR_CLOSE(dh);
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ ret = 0;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ cleanup:
|
|
|
c480ed |
+ VIR_DIR_CLOSE(dh);
|
|
|
c480ed |
+ return ret;
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+
|
|
|
c480ed |
virCgroupBackend virCgroupV1Backend = {
|
|
|
c480ed |
.type = VIR_CGROUP_BACKEND_TYPE_V1,
|
|
|
c480ed |
|
|
|
c480ed |
@@ -887,6 +949,7 @@ virCgroupBackend virCgroupV1Backend = {
|
|
|
c480ed |
.addTask = virCgroupV1AddTask,
|
|
|
c480ed |
.hasEmptyTasks = virCgroupV1HasEmptyTasks,
|
|
|
c480ed |
.bindMount = virCgroupV1BindMount,
|
|
|
c480ed |
+ .setOwner = virCgroupV1SetOwner,
|
|
|
c480ed |
};
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
--
|
|
|
c480ed |
2.22.0
|
|
|
c480ed |
|