mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
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.
This commit is contained in:
parent
a33d8fceee
commit
ea2fec86dd
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user