lxc_domain.c 2.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (C) 2010-2012 Red Hat, Inc.
 * Copyright IBM Corp. 2008
 *
 * lxc_domain.h: LXC domain helpers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library.  If not, see
O
Osier Yang 已提交
19
 * <http://www.gnu.org/licenses/>.
20 21 22 23 24 25
 */

#include <config.h>

#include "lxc_domain.h"

26
#include "viralloc.h"
27
#include "virlog.h"
28
#include "virerror.h"
29 30

#define VIR_FROM_THIS VIR_FROM_LXC
31

32
static void *virLXCDomainObjPrivateAlloc(void)
33
{
34
    virLXCDomainObjPrivatePtr priv;
35 36 37 38 39 40 41

    if (VIR_ALLOC(priv) < 0)
        return NULL;

    return priv;
}

42
static void virLXCDomainObjPrivateFree(void *data)
43
{
44
    virLXCDomainObjPrivatePtr priv = data;
45 46 47 48 49

    VIR_FREE(priv);
}


50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
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;
}

76 77 78 79 80 81
virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks = {
    .alloc = virLXCDomainObjPrivateAlloc,
    .free = virLXCDomainObjPrivateFree,
    .format = virLXCDomainObjPrivateXMLFormat,
    .parse  = virLXCDomainObjPrivateXMLParse,
};