lxc_conf.c 3.1 KB
Newer Older
D
Daniel Veillard 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Copyright IBM Corp. 2008
 *
 * lxc_conf.c: config functions for managing linux containers
 *
 * Authors:
 *  David L. Leskovec <dlesko at linux.vnet.ibm.com>
 *
 * 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
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 */

/* includes */
#include <config.h>

28
#include <sys/utsname.h>
D
Daniel Veillard 已提交
29 30

#include "lxc_conf.h"
31 32
#include "nodeinfo.h"
#include "virterror_internal.h"
33 34
#include "logging.h"

D
Daniel Veillard 已提交
35

36 37
#define VIR_FROM_THIS VIR_FROM_LXC

D
Daniel Veillard 已提交
38
/* Functions */
39
virCapsPtr lxcCapsInit(void)
D
Daniel Veillard 已提交
40
{
41 42 43
    struct utsname utsname;
    virCapsPtr caps;
    virCapsGuestPtr guest;
44

45
    uname(&utsname);
46

47 48 49
    if ((caps = virCapabilitiesNew(utsname.machine,
                                   0, 0)) == NULL)
        goto no_memory;
D
Daniel Veillard 已提交
50

51 52 53 54 55 56 57 58
    /* Some machines have problematic NUMA toplogy causing
     * unexpected failures. We don't want to break the QEMU
     * driver in this scenario, so log errors & carry on
     */
    if (nodeCapsInitNUMA(caps) < 0) {
        virCapabilitiesFreeNUMAInfo(caps);
        VIR_WARN0("Failed to query host NUMA topology, disabling NUMA capabilities");
    }
59

60 61 62
    /* XXX shouldn't 'borrow' KVM's prefix */
    virCapabilitiesSetMacPrefix(caps, (unsigned char []){ 0x52, 0x54, 0x00 });

63 64 65 66
    if ((guest = virCapabilitiesAddGuest(caps,
                                         "exe",
                                         utsname.machine,
                                         sizeof(int) == 4 ? 32 : 8,
67
                                         BINDIR "/libvirt_lxc",
68 69 70 71
                                         NULL,
                                         0,
                                         NULL)) == NULL)
        goto no_memory;
D
Daniel Veillard 已提交
72

73 74 75 76 77 78 79
    if (virCapabilitiesAddGuestDomain(guest,
                                      "lxc",
                                      NULL,
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto no_memory;
80 81 82 83

    /* LXC Requires an emulator in the XML */
    virCapabilitiesSetEmulatorRequired(caps);

84
    return caps;
D
Daniel Veillard 已提交
85

86 87
no_memory:
    virCapabilitiesFree(caps);
D
Daniel Veillard 已提交
88 89 90
    return NULL;
}

91
int lxcLoadDriverConfig(lxc_driver_t *driver)
D
Daniel Veillard 已提交
92 93
{
    /* Set the container configuration directory */
94
    if ((driver->configDir = strdup(LXC_CONFIG_DIR)) == NULL)
95
        goto no_memory;
96
    if ((driver->stateDir = strdup(LXC_STATE_DIR)) == NULL)
97
        goto no_memory;
98
    if ((driver->logDir = strdup(LXC_LOG_DIR)) == NULL)
99
        goto no_memory;
100

D
Daniel Veillard 已提交
101
    return 0;
102 103

no_memory:
104
    virReportOOMError(NULL);
105
    return -1;
D
Daniel Veillard 已提交
106
}