]> xenbits.xensource.com Git - libvirt.git/commitdiff
libvirt-lxc: add virDomainLxcEnterCGroup API
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 14 Apr 2016 14:16:22 +0000 (15:16 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 10 Jun 2016 10:02:53 +0000 (11:02 +0100)
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>
config-post.h
include/libvirt/libvirt-lxc.h
src/Makefile.am
src/libvirt-lxc.c
src/libvirt_lxc.syms

index 2398d3d9ced576ad9751ae0925cd16d169b11de0..f43521bd34890bbdd579464c2c0a7dff1452bde8 100644 (file)
@@ -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
index 1901fce4f8d372d611316a7c4a8d6a67a655a3d9..0d16a5c44d753e1c682f7ac299a28d9fae5363b7 100644 (file)
@@ -46,6 +46,8 @@ int virDomainLxcEnterSecurityLabel(virSecurityModelPtr model,
                                    virSecurityLabelPtr label,
                                    virSecurityLabelPtr oldlabel,
                                    unsigned int flags);
+int virDomainLxcEnterCGroup(virDomainPtr domain,
+                            unsigned int flags);
 
 # ifdef __cplusplus
 }
index 04ef9a506cc6262b0b410c0d6bb83538fdca9d27..ee4a7bf941ca00d1790a7ac63127dbc99c942aba 100644 (file)
@@ -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             \
index 8553570c6a3a36a47bdb9e91ff426ff3819d96b4..16e08e9db8a9f130d4b74bf8dc520acef5614d77 100644 (file)
@@ -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;
+}
index ccf1be98973aced2fa5d65edbc562178118016cc..56c24c00f771b9e475270ce3c6542788dd6ae268 100644 (file)
@@ -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;