mirror of https://gitee.com/openkylin/libvirt.git
libvirt-lxc: add virDomainLxcEnterCGroup API
Add the virDomainLxcEnterCGroup API to the libvirt-lxc.so file. This method moves the calling process into the cgroups associated with the container. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
235620463c
commit
57e62ee00a
|
@ -32,6 +32,7 @@
|
|||
# undef HAVE_LIBSASL2
|
||||
# undef WITH_CAPNG
|
||||
# undef WITH_CURL
|
||||
# undef WITH_DBUS
|
||||
# undef WITH_DTRACE_PROBES
|
||||
# undef WITH_GNUTLS
|
||||
# undef WITH_GNUTLS_GCRYPT
|
||||
|
@ -39,6 +40,7 @@
|
|||
# undef WITH_NUMACTL
|
||||
# undef WITH_SASL
|
||||
# undef WITH_SSH2
|
||||
# undef WITH_SYSTEMD_DAEMON
|
||||
# undef WITH_VIRTUALPORT
|
||||
# undef WITH_YAJL
|
||||
# undef WITH_YAJL2
|
||||
|
|
|
@ -46,6 +46,8 @@ int virDomainLxcEnterSecurityLabel(virSecurityModelPtr model,
|
|||
virSecurityLabelPtr label,
|
||||
virSecurityLabelPtr oldlabel,
|
||||
unsigned int flags);
|
||||
int virDomainLxcEnterCGroup(virDomainPtr domain,
|
||||
unsigned int flags);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -2327,8 +2327,10 @@ libvirt_setuid_rpc_client_la_SOURCES = \
|
|||
util/viratomic.h \
|
||||
util/virbitmap.c \
|
||||
util/virbuffer.c \
|
||||
util/vircgroup.c \
|
||||
util/vircommand.c \
|
||||
util/virconf.c \
|
||||
util/virdbus.c \
|
||||
util/virerror.c \
|
||||
util/virevent.c \
|
||||
util/vireventpoll.c \
|
||||
|
@ -2336,6 +2338,7 @@ libvirt_setuid_rpc_client_la_SOURCES = \
|
|||
util/virgettext.c \
|
||||
util/virhash.c \
|
||||
util/virhashcode.c \
|
||||
util/virhostcpu.c \
|
||||
util/virjson.c \
|
||||
util/virlog.c \
|
||||
util/virobject.c \
|
||||
|
@ -2344,6 +2347,7 @@ libvirt_setuid_rpc_client_la_SOURCES = \
|
|||
util/virrandom.c \
|
||||
util/virsocketaddr.c \
|
||||
util/virstring.c \
|
||||
util/virsystemd.c \
|
||||
util/virtime.c \
|
||||
util/virthread.c \
|
||||
util/virthreadjob.c \
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#ifdef WITH_APPARMOR
|
||||
# include <sys/apparmor.h>
|
||||
#endif
|
||||
#include "vircgroup.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||
|
||||
|
@ -269,3 +270,49 @@ virDomainLxcEnterSecurityLabel(virSecurityModelPtr model,
|
|||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virDomainLxcEnterCGroup:
|
||||
* @domain: a domain object
|
||||
* @flags: currently unused, pass 0
|
||||
*
|
||||
* This API is LXC specific, so it will only work with hypervisor
|
||||
* connections to the LXC driver.
|
||||
*
|
||||
* Attaches the process to the control cgroups associated
|
||||
* with the container @domain.
|
||||
*
|
||||
* Returns 0 on success, -1 on error
|
||||
*/
|
||||
int virDomainLxcEnterCGroup(virDomainPtr domain,
|
||||
unsigned int flags)
|
||||
{
|
||||
virConnectPtr conn;
|
||||
virCgroupPtr cgroup = NULL;
|
||||
|
||||
VIR_DOMAIN_DEBUG(domain, "flags=%x", flags);
|
||||
|
||||
virResetLastError();
|
||||
|
||||
virCheckDomainReturn(domain, -1);
|
||||
conn = domain->conn;
|
||||
|
||||
virCheckReadOnlyGoto(conn->flags, error);
|
||||
virCheckFlagsGoto(0, error);
|
||||
|
||||
if (virCgroupNewDetect(domain->id, -1, &cgroup) < 0)
|
||||
goto error;
|
||||
|
||||
if (virCgroupAddTask(cgroup, getpid()) < 0)
|
||||
goto error;
|
||||
|
||||
virCgroupFree(&cgroup);
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
virDispatchError(NULL);
|
||||
virCgroupFree(&cgroup);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -20,3 +20,8 @@ LIBVIRT_LXC_1.0.4 {
|
|||
global:
|
||||
virDomainLxcEnterSecurityLabel;
|
||||
} LIBVIRT_LXC_1.0.2;
|
||||
|
||||
LIBVIRT_LXC_1.3.6 {
|
||||
global:
|
||||
virDomainLxcEnterCGroup;
|
||||
} LIBVIRT_LXC_1.0.4;
|
||||
|
|
Loading…
Reference in New Issue