diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 4d65288046..bf6443cf39 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -2122,3 +2122,24 @@ int lxcContainerAvailable(int features) VIR_DEBUG("container support is enabled"); return 0; } + +int lxcContainerChown(virDomainDefPtr def, const char *path) +{ + uid_t uid; + gid_t gid; + + if (!def->idmap.uidmap) + return 0; + + uid = def->idmap.uidmap[0].target; + gid = def->idmap.gidmap[0].target; + + if (chown(path, uid, gid) < 0) { + virReportSystemError(errno, + _("Failed to change owner of %s to %u:%u"), + path, uid, gid); + return -1; + } + + return 0; +} diff --git a/src/lxc/lxc_container.h b/src/lxc/lxc_container.h index 6f270d7f7a..0e3b5918fc 100644 --- a/src/lxc/lxc_container.h +++ b/src/lxc/lxc_container.h @@ -67,4 +67,6 @@ int lxcContainerSetupHostdevCapsMakePath(const char *dev); virArch lxcContainerGetAlt32bitArch(virArch arch); +int lxcContainerChown(virDomainDefPtr def, const char *path); + #endif /* LXC_CONTAINER_H */ diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 38b632e355..4907af48b9 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1113,27 +1113,6 @@ cleanup2: return rc; } -static int -virLXCControllerChown(virLXCControllerPtr ctrl, char *path) -{ - uid_t uid; - gid_t gid; - - if (!ctrl->def->idmap.uidmap) - return 0; - - uid = ctrl->def->idmap.uidmap[0].target; - gid = ctrl->def->idmap.gidmap[0].target; - - if (chown(path, uid, gid) < 0) { - virReportSystemError(errno, - _("Failed to change owner of %s to %u:%u"), - path, uid, gid); - return -1; - } - - return 0; -} static int virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr map, @@ -1248,7 +1227,7 @@ static int virLXCControllerSetupDev(virLXCControllerPtr ctrl) goto cleanup; } - if (virLXCControllerChown(ctrl, dev) < 0) + if (lxcContainerChown(ctrl->def, dev) < 0) goto cleanup; ret = 0; @@ -1296,7 +1275,7 @@ static int virLXCControllerPopulateDevices(virLXCControllerPtr ctrl) goto cleanup; } - if (virLXCControllerChown(ctrl, path) < 0) + if (lxcContainerChown(ctrl->def, path) < 0) goto cleanup; VIR_FREE(path); @@ -1369,7 +1348,7 @@ static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl, goto cleanup; } - if (virLXCControllerChown(ctrl, dst) < 0) + if (lxcContainerChown(ctrl->def, dst) < 0) goto cleanup; /* Labelling normally operates on src, but we need @@ -1627,8 +1606,8 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl) goto cleanup; } - if ((virLXCControllerChown(ctrl, ctrl->devptmx) < 0) || - (virLXCControllerChown(ctrl, devpts) < 0)) + if ((lxcContainerChown(ctrl->def, ctrl->devptmx) < 0) || + (lxcContainerChown(ctrl->def, devpts) < 0)) goto cleanup; ret = 0; @@ -1666,7 +1645,7 @@ virLXCControllerSetupConsoles(virLXCControllerPtr ctrl, } /* Change the owner of tty device to the root user of container */ - if (virLXCControllerChown(ctrl, ttyHostPath) < 0) + if (lxcContainerChown(ctrl->def, ttyHostPath) < 0) goto cleanup; VIR_FREE(ttyHostPath);