[libvirt] [PATCH 8/9] Add implementation of virDomainLxcOpenNamespace to LXC driver

Daniel P. Berrange berrange at redhat.com
Fri Dec 21 17:08:31 UTC 2012


From: "Daniel P. Berrange" <berrange at redhat.com>

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 at redhat.com>
---
 src/lxc/lxc_driver.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 025c35f..185b08f 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -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,
-- 
1.7.11.7




More information about the libvir-list mailing list