提交 ea2fec86 编写于 作者: D Daniel P. Berrange

Store initpid in the domain status XML for LXC

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.
上级 a33d8fce
......@@ -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;
}
......@@ -34,6 +34,8 @@ struct _virLXCDomainObjPrivate {
bool doneStopEvent;
int stopReason;
bool wantReboot;
pid_t initpid;
};
void virLXCDomainSetPrivateDataHooks(virCapsPtr caps);
......
......@@ -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 = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册