提交 14a0c408 编写于 作者: G Gao feng 提交者: Eric Blake

LXC: Move virLXCControllerChown to lxc_container.c

lxc driver will use this function to change the owner
of hot added devices.

Move virLXCControllerChown to lxc_container.c and Rename
it to lxcContainerChown.
Signed-off-by: NGao feng <gaofeng@cn.fujitsu.com>
上级 ae4e916f
......@@ -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;
}
......@@ -67,4 +67,6 @@ int lxcContainerSetupHostdevCapsMakePath(const char *dev);
virArch lxcContainerGetAlt32bitArch(virArch arch);
int lxcContainerChown(virDomainDefPtr def, const char *path);
#endif /* LXC_CONTAINER_H */
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册