]> xenbits.xensource.com Git - libvirt.git/commitdiff
Add implementation of virDomainLxcOpenNamespace to LXC driver
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 21 Dec 2012 14:22:31 +0000 (14:22 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 15 Jan 2013 18:16:54 +0000 (18:16 +0000)
The virDomainLxcOpenNamespace method needs to open every file
in /proc/$INITPID/ns and return the open file descriptor to the
client application.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/lxc/lxc_driver.c

index 8457ae985fb20a581e836a80a0387d24988b2ce7..078dadd2dc56830625a71ea9dee3618ba6f5ea8b 100644 (file)
@@ -63,6 +63,7 @@
 #include "virnetdev.h"
 #include "virnetdevtap.h"
 #include "virnodesuspend.h"
+#include "virprocess.h"
 #include "virtime.h"
 #include "virtypedparam.h"
 #include "viruri.h"
@@ -4467,6 +4468,53 @@ static int lxcDomainDetachDevice(virDomainPtr dom,
 }
 
 
+static int lxcDomainOpenNamespace(virDomainPtr dom,
+                                  int **fdlist,
+                                  unsigned int flags)
+{
+    virLXCDriverPtr driver = dom->conn->privateData;
+    virDomainObjPtr vm;
+    virLXCDomainObjPrivatePtr priv;
+    int ret = -1;
+    size_t nfds = 0;
+
+    *fdlist = NULL;
+    virCheckFlags(0, -1);
+
+    lxcDriverLock(driver);
+    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
+    lxcDriverUnlock(driver);
+    if (!vm) {
+        char uuidstr[VIR_UUID_STRING_BUFLEN];
+        virUUIDFormat(dom->uuid, uuidstr);
+        virReportError(VIR_ERR_NO_DOMAIN,
+                       _("no domain with matching uuid '%s'"), uuidstr);
+        goto cleanup;
+    }
+    priv = vm->privateData;
+
+    if (!virDomainObjIsActive(vm)) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       "%s", _("Domain is not running"));
+        goto cleanup;
+    }
+
+    if (!priv->initpid) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("Init pid is not yet available"));
+        goto cleanup;
+    }
+
+    if (virProcessGetNamespaces(priv->initpid, &nfds, fdlist) < 0)
+        goto cleanup;
+
+    ret = nfds;
+cleanup:
+    virDomainObjUnlock(vm);
+    return ret;
+}
+
+
 /* Function Tables */
 static virDriver lxcDriver = {
     .no = VIR_DRV_LXC,
@@ -4544,6 +4592,7 @@ static virDriver lxcDriver = {
     .domainShutdown = lxcDomainShutdown, /* 1.0.1 */
     .domainShutdownFlags = lxcDomainShutdownFlags, /* 1.0.1 */
     .domainReboot = lxcDomainReboot, /* 1.0.1 */
+    .domainLxcOpenNamespace = lxcDomainOpenNamespace, /* 1.0.2 */
 };
 
 static virStateDriver lxcStateDriver = {