From: "Daniel P. Berrange" <berrange(a)redhat.com>
The initpid will be required long term to enable LXC to
implement various hotplug operations. Thus it needs to be
persisted in the domain status XML. LXC has not used the
domain status XML before, so this introduces use of the
helpers.
---
src/lxc/lxc_domain.c | 32 ++++++++++++++++++++++++++++++++
src/lxc/lxc_domain.h | 2 ++
src/lxc/lxc_process.c | 7 +++++++
3 files changed, 41 insertions(+)
diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c
index 17f1d0c..bd80d9f 100644
--- a/src/lxc/lxc_domain.c
+++ b/src/lxc/lxc_domain.c
@@ -24,6 +24,10 @@
#include "lxc_domain.h"
#include "memory.h"
+#include "logging.h"
+#include "virterror_internal.h"
+
+#define VIR_FROM_THIS VIR_FROM_LXC
static void *virLXCDomainObjPrivateAlloc(void)
{
@@ -43,8 +47,36 @@ static void virLXCDomainObjPrivateFree(void *data)
}
+static int virLXCDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)
+{
+ virLXCDomainObjPrivatePtr priv = data;
+
+ virBufferAsprintf(buf, " <init pid='%llu'/>\n",
+ (unsigned long long)priv->initpid);
+
+ return 0;
+}
+
+static int virLXCDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data)
+{
+ virLXCDomainObjPrivatePtr priv = data;
+ unsigned long long thepid;
+
+ if (virXPathULongLong("string(./init[1]/@pid)", ctxt, &thepid) < 0)
{
+ virErrorPtr err = virGetLastError();
+ VIR_WARN("Failed to load init pid from state %s", err ? err->message
: "null");
+ priv->initpid = 0;
+ } else {
+ priv->initpid = thepid;
+ }
+
+ return 0;
+}
+
void virLXCDomainSetPrivateDataHooks(virCapsPtr caps)
{
caps->privateDataAllocFunc = virLXCDomainObjPrivateAlloc;
caps->privateDataFreeFunc = virLXCDomainObjPrivateFree;
+ caps->privateDataXMLFormat = virLXCDomainObjPrivateXMLFormat;
+ caps->privateDataXMLParse = virLXCDomainObjPrivateXMLParse;
}
diff --git a/src/lxc/lxc_domain.h b/src/lxc/lxc_domain.h
index b1dd5d9..882f34a 100644
--- a/src/lxc/lxc_domain.h
+++ b/src/lxc/lxc_domain.h
@@ -34,6 +34,8 @@ struct _virLXCDomainObjPrivate {
bool doneStopEvent;
int stopReason;
bool wantReboot;
+
+ pid_t initpid;
};
void virLXCDomainSetPrivateDataHooks(virCapsPtr caps);
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 1bf4697..d489c04 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -637,11 +637,18 @@ static void virLXCProcessMonitorExitNotify(virLXCMonitorPtr mon
ATTRIBUTE_UNUSED
priv->stopReason, status);
}
+/* XXX a little evil */
+extern virLXCDriverPtr lxc_driver;
static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED,
pid_t initpid,
virDomainObjPtr vm)
{
+ virLXCDomainObjPrivatePtr priv = vm->privateData;
+ priv->initpid = initpid;
virDomainAuditInit(vm, initpid);
+
+ if (virDomainSaveStatus(lxc_driver->caps, lxc_driver->stateDir, vm) < 0)
+ VIR_WARN("Cannot update XML with PID for LXC %s",
vm->def->name);
}
static virLXCMonitorCallbacks monitorCallbacks = {
--
1.7.11.2