<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 18, 2018 at 5:45 PM, Pavel Hrdina <span dir="ltr"><<a href="mailto:phrdina@redhat.com" target="_blank">phrdina@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Signed-off-by: Pavel Hrdina <<a href="mailto:phrdina@redhat.com" target="_blank">phrdina@redhat.com</a>><br>
---<br>
src/util/vircgroup.c | 54 +-----------------------------<br>
src/util/vircgroupbackend.h | 7 ++++<br>
src/util/vircgroupv1.c | 65 ++++++++++++++++++++++++++++++<wbr>+++++++<br>
3 files changed, 73 insertions(+), 53 deletions(-)<br>
<br>
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c<br>
index 29faf5fb2c..479a2bf664 100644<br>
--- a/src/util/vircgroup.c<br>
+++ b/src/util/vircgroup.c<br>
@@ -3284,59 +3284,7 @@ int virCgroupSetOwner(virCgroupPtr cgroup,<br>
gid_t gid,<br>
int controllers)<br>
{<br>
- int ret = -1;<br>
- size_t i;<br>
- DIR *dh = NULL;<br>
- int direrr;<br>
-<br>
- for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {<br>
- VIR_AUTOFREE(char *) base = NULL;<br>
- struct dirent *de;<br>
-<br>
- if (!((1 << i) & controllers))<br>
- continue;<br>
-<br>
- if (!cgroup->controllers[i].mount<wbr>Point)<br>
- continue;<br>
-<br>
- if (virAsprintf(&base, "%s%s", cgroup->controllers[i].mountPo<wbr>int,<br>
- cgroup->controllers[i].placeme<wbr>nt) < 0)<br>
- goto cleanup;<br>
-<br>
- if (virDirOpen(&dh, base) < 0)<br>
- goto cleanup;<br>
-<br>
- while ((direrr = virDirRead(dh, &de, base)) > 0) {<br>
- VIR_AUTOFREE(char *) entry = NULL;<br>
-<br>
- if (virAsprintf(&entry, "%s/%s", base, de->d_name) < 0)<br>
- goto cleanup;<br>
-<br>
- if (chown(entry, uid, gid) < 0) {<br>
- virReportSystemError(errno,<br>
- _("cannot chown '%s' to (%u, %u)"),<br>
- entry, uid, gid);<br>
- goto cleanup;<br>
- }<br>
- }<br>
- if (direrr < 0)<br>
- goto cleanup;<br>
-<br>
- if (chown(base, uid, gid) < 0) {<br>
- virReportSystemError(errno,<br>
- _("cannot chown '%s' to (%u, %u)"),<br>
- base, uid, gid);<br>
- goto cleanup;<br>
- }<br>
-<br>
- VIR_DIR_CLOSE(dh);<br>
- }<br>
-<br>
- ret = 0;<br>
-<br>
- cleanup:<br>
- VIR_DIR_CLOSE(dh);<br>
- return ret;<br>
+ return cgroup->backend->setOwner(cgro<wbr>up, uid, gid, controllers);<br>
}<br>
<br>
<br>
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h<br>
index 70deb47461..4538654068 100644<br>
--- a/src/util/vircgroupbackend.h<br>
+++ b/src/util/vircgroupbackend.h<br>
@@ -123,6 +123,12 @@ typedef int<br>
const char *oldroot,<br>
const char *mountopts);<br>
<br>
+typedef int<br>
+(*virCgroupSetOwnerCB)(virCgr<wbr>oupPtr cgroup,<br>
+ uid_t uid,<br>
+ gid_t gid,<br>
+ int controllers);<br>
+<br>
struct _virCgroupBackend {<br>
virCgroupBackendType type;<br>
<br>
@@ -144,6 +150,7 @@ struct _virCgroupBackend {<br>
virCgroupAddTaskCB addTask;<br>
virCgroupHasEmptyTasksCB hasEmptyTasks;<br>
virCgroupBindMountCB bindMount;<br>
+ virCgroupSetOwnerCB setOwner;<br>
};<br>
typedef struct _virCgroupBackend virCgroupBackend;<br>
typedef virCgroupBackend *virCgroupBackendPtr;<br>
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c<br>
index 0514ba392d..d74fc8ff96 100644<br>
--- a/src/util/vircgroupv1.c<br>
+++ b/src/util/vircgroupv1.c<br>
@@ -866,6 +866,70 @@ virCgroupV1BindMount(virCgroup<wbr>Ptr group,<br>
}<br>
<br>
<br>
+static int<br>
+virCgroupV1SetOwner(virCgroup<wbr>Ptr cgroup,<br>
+ uid_t uid,<br>
+ gid_t gid,<br>
+ int controllers)<br>
+{<br>
+ int ret = -1;<br>
+ size_t i;<br>
+ VIR_AUTOFREE(char *) base = NULL;<br>
+ VIR_AUTOFREE(char *) entry = NULL;<br></blockquote><div><br></div><div>I would avoid these changes here in order to keep the diff as minimal as possible.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ DIR *dh = NULL;<br>
+ int direrr;<br>
+<br>
+ for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {<br>
+ struct dirent *de;<br>
+<br>
+ if (!((1 << i) & controllers))<br>
+ continue;<br>
+<br>
+ if (!cgroup->controllers[i].mount<wbr>Point)<br>
+ continue;<br>
+<br>
+ if (virAsprintf(&base, "%s%s", cgroup->controllers[i].mountPo<wbr>int,<br>
+ cgroup->controllers[i].placeme<wbr>nt) < 0)<br>
+ goto cleanup;<br>
+<br>
+ if (virDirOpen(&dh, base) < 0)<br>
+ goto cleanup;<br>
+<br>
+ while ((direrr = virDirRead(dh, &de, base)) > 0) {<br>
+ if (virAsprintf(&entry, "%s/%s", base, de->d_name) < 0)<br>
+ goto cleanup;<br>
+<br>
+ if (chown(entry, uid, gid) < 0) {<br>
+ virReportSystemError(errno,<br>
+ _("cannot chown '%s' to (%u, %u)"),<br>
+ entry, uid, gid);<br>
+ goto cleanup;<br>
+ }<br>
+<br>
+ VIR_FREE(entry);<br>
+ }<br>
+ if (direrr < 0)<br>
+ goto cleanup;<br>
+<br>
+ if (chown(base, uid, gid) < 0) {<br>
+ virReportSystemError(errno,<br>
+ _("cannot chown '%s' to (%u, %u)"),<br>
+ base, uid, gid);<br>
+ goto cleanup;<br>
+ }<br>
+<br>
+ VIR_FREE(base);<br>
+ VIR_DIR_CLOSE(dh);<br>
+ }<br>
+<br>
+ ret = 0;<br>
+<br>
+ cleanup:<br>
+ VIR_DIR_CLOSE(dh);<br>
+ return ret;<br>
+}<br>
+<br>
+<br>
virCgroupBackend virCgroupV1Backend = {<br>
.type = VIR_CGROUP_BACKEND_TYPE_V1,<br>
<br>
@@ -886,6 +950,7 @@ virCgroupBackend virCgroupV1Backend = {<br>
.addTask = virCgroupV1AddTask,<br>
.hasEmptyTasks = virCgroupV1HasEmptyTasks,<br>
.bindMount = virCgroupV1BindMount,<br>
+ .setOwner = virCgroupV1SetOwner,<br>
};<br>
<span class="m_-4177670804153872850HOEnZb"><font color="#888888"> <br>
<br>
-- <br>
2.17.1<br>
<br>
--<br>
libvir-list mailing list<br>
<a href="mailto:libvir-list@redhat.com" target="_blank">libvir-list@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/libvir-list" rel="noreferrer" target="_blank">https://www.redhat.com/mailman<wbr>/listinfo/libvir-list</a><br>
</font></span></blockquote></div><br></div></div>