lxc_conf.h 4.6 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 28 29 30 31 32 33 34 35 36 37 38
/*
 * Copyright IBM Corp. 2008
 *
 * lxc_conf.h: header file for linux container config functions
 *
 * 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
 */

#ifndef LXC_CONF_H
#define LXC_CONF_H

#include <config.h>

#ifdef WITH_LXC

#include "internal.h"

/* Defines */
#define LXC_MAX_TTY_NAME 32
#define LXC_MAX_XML_LENGTH 16384
#define LXC_MAX_ERROR_LEN 1024
#define LXC_DOMAIN_TYPE "lxc"

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/* types of networks for containers */
enum lxc_net_type {
    LXC_NET_NETWORK,
    LXC_NET_BRIDGE
};

typedef struct __lxc_net_def lxc_net_def_t;
struct __lxc_net_def {
    int type;
    char *parentVeth;       /* veth device in parent namespace */
    char *containerVeth;    /* veth device in container namespace */
    char *txName;           /* bridge or network name */

    lxc_net_def_t *next;
};

D
Daniel Veillard 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
typedef struct __lxc_mount lxc_mount_t;
struct __lxc_mount {
    char source[PATH_MAX]; /* user's directory */
    char target[PATH_MAX];

    lxc_mount_t *next;
};

typedef struct __lxc_vm_def lxc_vm_def_t;
struct __lxc_vm_def {
    unsigned char uuid[VIR_UUID_BUFLEN];
    char* name;
    int id;

    /* init command string */
70
    char *init;
D
Daniel Veillard 已提交
71 72 73 74 75 76 77 78

    int maxMemory;

    /* mounts - list of mount structs */
    int nmounts;
    lxc_mount_t *mounts;

    /* tty device */
79
    char *tty;
80 81 82 83

    /* network devices */
    int numNets;
    lxc_net_def_t *nets;
D
Daniel Veillard 已提交
84 85 86 87 88 89 90 91 92 93
};

typedef struct __lxc_vm lxc_vm_t;
struct __lxc_vm {
    int pid;
    int state;

    char configFile[PATH_MAX];
    char configFileBase[PATH_MAX];

94 95
    char ttyPidFile[PATH_MAX];

D
Daniel Veillard 已提交
96 97 98 99 100 101 102 103 104 105 106
    lxc_vm_def_t *def;

    lxc_vm_t *next;
};

typedef struct __lxc_driver lxc_driver_t;
struct __lxc_driver {
    lxc_vm_t *vms;
    int nactivevms;
    int ninactivevms;
    char* configDir;
107
    char* stateDir;
108
    int have_netns;
D
Daniel Veillard 已提交
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
};

/* Types and structs */

/* Inline Functions */
static inline int lxcIsActiveVM(lxc_vm_t *vm)
{
    return vm->def->id != -1;
}

/* Function declarations */
lxc_vm_def_t * lxcParseVMDef(virConnectPtr conn,
                             const char* xmlString,
                             const char* fileName);
int lxcSaveVMDef(virConnectPtr conn,
                 lxc_driver_t *driver,
                 lxc_vm_t *vm,
                 lxc_vm_def_t *def);
127
int lxcLoadDriverConfig(lxc_driver_t *driver);
D
Daniel Veillard 已提交
128 129 130 131
int lxcSaveConfig(virConnectPtr conn,
                  lxc_driver_t *driver,
                  lxc_vm_t *vm,
                  lxc_vm_def_t *def);
132
int lxcLoadContainerInfo(lxc_driver_t *driver);
D
Daniel Veillard 已提交
133 134 135 136 137 138 139 140 141 142 143 144 145 146
int lxcLoadContainerConfigFile(lxc_driver_t *driver,
                               const char *file);
lxc_vm_t * lxcAssignVMDef(virConnectPtr conn,
                          lxc_driver_t *driver,
                          lxc_vm_def_t *def);
char *lxcGenerateXML(virConnectPtr conn,
                     lxc_driver_t *driver,
                     lxc_vm_t *vm,
                     lxc_vm_def_t *def);
lxc_vm_t *lxcFindVMByID(const lxc_driver_t *driver, int id);
lxc_vm_t *lxcFindVMByUUID(const lxc_driver_t *driver,
                          const unsigned char *uuid);
lxc_vm_t *lxcFindVMByName(const lxc_driver_t *driver,
                          const char *name);
147
int lxcCheckContainerProcess(lxc_vm_def_t *vm);
D
Daniel Veillard 已提交
148 149 150 151 152 153 154 155 156
void lxcRemoveInactiveVM(lxc_driver_t *driver,
                         lxc_vm_t *vm);
void lxcFreeVMs(lxc_vm_t *vms);
void lxcFreeVM(lxc_vm_t *vm);
void lxcFreeVMDef(lxc_vm_def_t *vmdef);
int lxcDeleteConfig(virConnectPtr conn,
                    lxc_driver_t *driver,
                    const char *configFile,
                    const char *name);
157 158 159
int lxcStoreTtyPid(const lxc_driver_t *driver, lxc_vm_t *vm);
int lxcLoadTtyPid(const lxc_driver_t *driver, lxc_vm_t *vm);
int lxcDeleteTtyPidFile(const lxc_vm_t *vm);
D
Daniel Veillard 已提交
160 161 162 163 164 165 166 167 168

void lxcError(virConnectPtr conn,
              virDomainPtr dom,
              int code, const char *fmt, ...)
    ATTRIBUTE_FORMAT(printf,4,5);

#endif /* WITH_LXC */
#endif /* LXC_CONF_H */