libxl_conf.h 6.2 KB
Newer Older
1 2 3
/*
 * libxl_conf.h: libxl configuration management
 *
4
 * Copyright (C) 2011-2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
5
 * Copyright (C) 2011 Univention GmbH.
J
Jim Fehlig 已提交
6 7 8 9 10 11 12 13 14 15 16 17
 *
 * 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/>.
J
Jim Fehlig 已提交
20 21
 */

22 23
#ifndef LIBVIRT_LIBXL_CONF_H
# define LIBVIRT_LIBXL_CONF_H
J
Jim Fehlig 已提交
24 25 26 27

# include <libxl.h>

# include "internal.h"
28
# include "libvirt_internal.h"
29
# include "virdomainobjlist.h"
30
# include "domain_event.h"
J
Jim Fehlig 已提交
31 32
# include "capabilities.h"
# include "configmake.h"
33
# include "virportallocator.h"
34
# include "virobject.h"
B
Bamvor Jian Zhang 已提交
35
# include "virchrdev.h"
36
# include "virhostdev.h"
37
# include "locking/lock_manager.h"
38
# include "virfirmware.h"
39
# include "libxl_capabilities.h"
40
# include "libxl_logger.h"
J
Jim Fehlig 已提交
41

42
# define LIBXL_DRIVER_NAME "xenlight"
J
Jim Fehlig 已提交
43 44 45
# define LIBXL_VNC_PORT_MIN  5900
# define LIBXL_VNC_PORT_MAX  65535

J
Jim Fehlig 已提交
46 47 48
# define LIBXL_MIGRATION_PORT_MIN  49152
# define LIBXL_MIGRATION_PORT_MAX  49216

49
# define LIBXL_CONFIG_BASE_DIR SYSCONFDIR "/libvirt"
J
Jim Fehlig 已提交
50 51 52 53 54 55
# define LIBXL_CONFIG_DIR SYSCONFDIR "/libvirt/libxl"
# define LIBXL_AUTOSTART_DIR LIBXL_CONFIG_DIR "/autostart"
# define LIBXL_STATE_DIR LOCALSTATEDIR "/run/libvirt/libxl"
# define LIBXL_LOG_DIR LOCALSTATEDIR "/log/libvirt/libxl"
# define LIBXL_LIB_DIR LOCALSTATEDIR "/lib/libvirt/libxl"
# define LIBXL_SAVE_DIR LIBXL_LIB_DIR "/save"
56
# define LIBXL_DUMP_DIR LIBXL_LIB_DIR "/dump"
J
Joao Martins 已提交
57
# define LIBXL_CHANNEL_DIR LIBXL_LIB_DIR "/channel/target"
58
# define LIBXL_BOOTLOADER_PATH "pygrub"
J
Jim Fehlig 已提交
59

60

J
Jim Fehlig 已提交
61 62
typedef struct _libxlDriverPrivate libxlDriverPrivate;
typedef libxlDriverPrivate *libxlDriverPrivatePtr;
63 64 65 66 67 68 69

typedef struct _libxlDriverConfig libxlDriverConfig;
typedef libxlDriverConfig *libxlDriverConfigPtr;

struct _libxlDriverConfig {
    virObject parent;

70
    const libxl_version_info *verInfo;
J
Jim Fehlig 已提交
71 72
    unsigned int version;

J
Jim Fehlig 已提交
73
    /* log stream for driver-wide libxl ctx */
74
    libxlLoggerPtr logger;
J
Jim Fehlig 已提交
75
    /* libxl ctx for driver wide ops; getVersion, getNodeInfo, ... */
J
Jim Fehlig 已提交
76
    libxl_ctx *ctx;
J
Jim Fehlig 已提交
77

78 79 80 81
    /* Controls automatic ballooning of domain0. If true, attempt to get
     * memory for new domains from domain0. */
    bool autoballoon;

82 83
    char *lockManagerName;

J
Joao Martins 已提交
84 85 86
    int keepAliveInterval;
    unsigned int keepAliveCount;

87 88
    bool nested_hvm;

89 90 91
    /* Once created, caps are immutable */
    virCapsPtr caps;

92
    char *configBaseDir;
93 94 95 96 97 98
    char *configDir;
    char *autostartDir;
    char *logDir;
    char *stateDir;
    char *libDir;
    char *saveDir;
99
    char *autoDumpDir;
J
Joao Martins 已提交
100
    char *channelDir;
101 102 103

    virFirmwarePtr *firmwares;
    size_t nfirmwares;
104 105 106 107 108 109
};


struct _libxlDriverPrivate {
    virMutex lock;

110
    virHostdevManagerPtr hostdevMgr;
111 112 113 114
    /* Require lock to get reference on 'config',
     * then lockless thereafter */
    libxlDriverConfigPtr config;

115
    /* Atomic inc/dec only */
116
    unsigned int nactive;
117

118
    /* Immutable pointers. Caller must provide locking */
119 120 121
    virStateInhibitCallback inhibitCallback;
    void *inhibitOpaque;

122
    /* Immutable pointer, self-locking APIs */
123
    virDomainObjListPtr domains;
J
Jim Fehlig 已提交
124

125
    /* Immutable pointer, immutable object */
126 127
    virDomainXMLOptionPtr xmlopt;

128
    /* Immutable pointer, self-locking APIs */
129
    virObjectEventStatePtr domainEventState;
130

131
    /* Immutable pointer, immutable object */
132
    virPortAllocatorRangePtr reservedGraphicsPorts;
133

134
    /* Immutable pointer, immutable object */
135
    virPortAllocatorRangePtr migrationPorts;
J
Jim Fehlig 已提交
136

137
    /* Immutable pointer, lockless APIs*/
138
    virSysinfoDefPtr hostsysinfo;
139 140 141

    /* Immutable pointer. lockless access */
    virLockManagerPluginPtr lockManager;
J
Jim Fehlig 已提交
142 143
};

144
# define LIBXL_SAVE_MAGIC "libvirt-xml\n \0 \r"
145 146 147 148 149
# ifdef LIBXL_HAVE_SRM_V2
#  define LIBXL_SAVE_VERSION 2
# else
#  define LIBXL_SAVE_VERSION 1
# endif
150 151 152 153 154 155 156 157 158 159

typedef struct _libxlSavefileHeader libxlSavefileHeader;
typedef libxlSavefileHeader *libxlSavefileHeaderPtr;
struct _libxlSavefileHeader {
    char magic[sizeof(LIBXL_SAVE_MAGIC)-1];
    uint32_t version;
    uint32_t xmlLen;
    /* 24 bytes used, pad up to 64 bytes */
    uint32_t unused[10];
};
J
Jim Fehlig 已提交
160

161 162 163 164 165
libxlDriverConfigPtr
libxlDriverConfigNew(void);

libxlDriverConfigPtr
libxlDriverConfigGet(libxlDriverPrivatePtr driver);
166

167 168 169 170
int
libxlDriverNodeGetInfo(libxlDriverPrivatePtr driver,
                       virNodeInfoPtr info);

171 172 173
int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
                              const char *filename);

174 175 176 177
int
libxlDriverGetDom0MaxmemConf(libxlDriverConfigPtr cfg,
                             unsigned long long *maxmem);

178
int
J
Jim Fehlig 已提交
179
libxlMakeDisk(virDomainDiskDefPtr l_dev, libxl_device_disk *x_dev);
180 181 182 183

void
libxlUpdateDiskDef(virDomainDiskDefPtr l_dev, libxl_device_disk *x_dev);

184
int
185 186
libxlMakeNic(virDomainDefPtr def,
             virDomainNetDefPtr l_nic,
187 188
             libxl_device_nic *x_nic,
             bool attach);
189
int
190
libxlMakeVfb(virPortAllocatorRangePtr graphicsports,
191
             virDomainGraphicsDefPtr l_vfb, libxl_device_vfb *x_vfb);
192

193
int
194
libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci *pcidev);
195

196
# ifdef LIBXL_HAVE_PVUSB
197 198 199 200
int
libxlMakeUSBController(virDomainControllerDefPtr controller,
                       libxl_device_usbctrl *usbctrl);

201 202 203 204
int
libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev);
# endif

205 206 207
virDomainXMLOptionPtr
libxlCreateXMLConf(void);

J
Joao Martins 已提交
208 209 210 211 212
# ifdef LIBXL_HAVE_DEVICE_CHANNEL
#  define LIBXL_ATTR_UNUSED
# else
#  define LIBXL_ATTR_UNUSED ATTRIBUTE_UNUSED
# endif
J
Jim Fehlig 已提交
213
int
214
libxlBuildDomainConfig(virPortAllocatorRangePtr graphicsports,
215
                       virDomainDefPtr def,
216
                       libxlDriverConfigPtr cfg,
217
                       libxl_domain_config *d_config);
J
Jim Fehlig 已提交
218

219 220 221 222 223 224 225 226 227 228 229 230
static inline void
libxlDriverLock(libxlDriverPrivatePtr driver)
{
    virMutexLock(&driver->lock);
}

static inline void
libxlDriverUnlock(libxlDriverPrivatePtr driver)
{
    virMutexUnlock(&driver->lock);
}

231
#endif /* LIBVIRT_LIBXL_CONF_H */