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: Gao feng <gaofeng@cn.fujitsu.com>
This commit is contained in:
Gao feng 2013-07-16 10:00:02 +08:00 committed by Eric Blake
parent ae4e916f04
commit 14a0c4084d
3 changed files with 29 additions and 27 deletions

View File

@ -2122,3 +2122,24 @@ int lxcContainerAvailable(int features)
VIR_DEBUG("container support is enabled"); VIR_DEBUG("container support is enabled");
return 0; 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;
}

View File

@ -67,4 +67,6 @@ int lxcContainerSetupHostdevCapsMakePath(const char *dev);
virArch lxcContainerGetAlt32bitArch(virArch arch); virArch lxcContainerGetAlt32bitArch(virArch arch);
int lxcContainerChown(virDomainDefPtr def, const char *path);
#endif /* LXC_CONTAINER_H */ #endif /* LXC_CONTAINER_H */

View File

@ -1113,27 +1113,6 @@ cleanup2:
return rc; 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 static int
virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr map, virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr map,
@ -1248,7 +1227,7 @@ static int virLXCControllerSetupDev(virLXCControllerPtr ctrl)
goto cleanup; goto cleanup;
} }
if (virLXCControllerChown(ctrl, dev) < 0) if (lxcContainerChown(ctrl->def, dev) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
@ -1296,7 +1275,7 @@ static int virLXCControllerPopulateDevices(virLXCControllerPtr ctrl)
goto cleanup; goto cleanup;
} }
if (virLXCControllerChown(ctrl, path) < 0) if (lxcContainerChown(ctrl->def, path) < 0)
goto cleanup; goto cleanup;
VIR_FREE(path); VIR_FREE(path);
@ -1369,7 +1348,7 @@ static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl,
goto cleanup; goto cleanup;
} }
if (virLXCControllerChown(ctrl, dst) < 0) if (lxcContainerChown(ctrl->def, dst) < 0)
goto cleanup; goto cleanup;
/* Labelling normally operates on src, but we need /* Labelling normally operates on src, but we need
@ -1627,8 +1606,8 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl)
goto cleanup; goto cleanup;
} }
if ((virLXCControllerChown(ctrl, ctrl->devptmx) < 0) || if ((lxcContainerChown(ctrl->def, ctrl->devptmx) < 0) ||
(virLXCControllerChown(ctrl, devpts) < 0)) (lxcContainerChown(ctrl->def, devpts) < 0))
goto cleanup; goto cleanup;
ret = 0; ret = 0;
@ -1666,7 +1645,7 @@ virLXCControllerSetupConsoles(virLXCControllerPtr ctrl,
} }
/* Change the owner of tty device to the root user of container */ /* 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; goto cleanup;
VIR_FREE(ttyHostPath); VIR_FREE(ttyHostPath);