From 2b1cd1f148062a901d7841035495ce70b3e21282 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Fri, 21 Dec 2012 14:22:31 +0000 Subject: [PATCH] Add implementation of virDomainLxcOpenNamespace to LXC driver 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 --- src/lxc/lxc_driver.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 8457ae985f..078dadd2dc 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, @@ -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 = {