libxl_conf.h 6.3 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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#pragma once

#include <libxl.h>

#include "internal.h"
#include "libvirt_internal.h"
#include "virdomainobjlist.h"
#include "domain_event.h"
#include "capabilities.h"
#include "configmake.h"
#include "virportallocator.h"
#include "virobject.h"
#include "virchrdev.h"
#include "virhostdev.h"
#include "locking/lock_manager.h"
#include "virfirmware.h"
#include "libxl_capabilities.h"
#include "libxl_logger.h"

#define LIBXL_DRIVER_NAME "xenlight"
#define LIBXL_VNC_PORT_MIN  5900
#define LIBXL_VNC_PORT_MAX  65535

#define LIBXL_MIGRATION_PORT_MIN  49152
#define LIBXL_MIGRATION_PORT_MAX  49216

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

59

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

typedef struct _libxlDriverConfig libxlDriverConfig;
typedef libxlDriverConfig *libxlDriverConfigPtr;

struct _libxlDriverConfig {
    virObject parent;

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

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

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

81 82
    char *lockManagerName;

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

86 87
    bool nested_hvm;

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

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

    virFirmwarePtr *firmwares;
    size_t nfirmwares;
103 104
};

105 106
G_DEFINE_AUTOPTR_CLEANUP_FUNC(libxlDriverConfig, virObjectUnref);

107 108 109 110

struct _libxlDriverPrivate {
    virMutex lock;

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

116 117 118
    /* pid file FD, ensures two copies of the driver can't use the same root */
    int lockFD;

119
    /* Atomic inc/dec only */
120
    unsigned int nactive;
121

122
    /* Immutable pointers. Caller must provide locking */
123 124 125
    virStateInhibitCallback inhibitCallback;
    void *inhibitOpaque;

126
    /* Immutable pointer, self-locking APIs */
127
    virDomainObjListPtr domains;
J
Jim Fehlig 已提交
128

129
    /* Immutable pointer, immutable object */
130 131
    virDomainXMLOptionPtr xmlopt;

132
    /* Immutable pointer, self-locking APIs */
133
    virObjectEventStatePtr domainEventState;
134

135
    /* Immutable pointer, immutable object */
136
    virPortAllocatorRangePtr reservedGraphicsPorts;
137

138
    /* Immutable pointer, immutable object */
139
    virPortAllocatorRangePtr migrationPorts;
J
Jim Fehlig 已提交
140

J
Ján Tomko 已提交
141
    /* Immutable pointer, lockless APIs */
142
    virSysinfoDefPtr hostsysinfo;
143 144 145

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

148 149 150 151 152 153
#define LIBXL_SAVE_MAGIC "libvirt-xml\n \0 \r"
#ifdef LIBXL_HAVE_SRM_V2
# define LIBXL_SAVE_VERSION 2
#else
# define LIBXL_SAVE_VERSION 1
#endif
154 155 156 157 158 159 160 161 162 163

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 已提交
164

165 166
libxlDriverConfigPtr
libxlDriverConfigNew(void);
167 168
int
libxlDriverConfigInit(libxlDriverConfigPtr cfg);
169 170 171

libxlDriverConfigPtr
libxlDriverConfigGet(libxlDriverPrivatePtr driver);
172

173 174 175 176
int
libxlDriverNodeGetInfo(libxlDriverPrivatePtr driver,
                       virNodeInfoPtr info);

177 178 179
int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
                              const char *filename);

180 181 182 183
int
libxlDriverGetDom0MaxmemConf(libxlDriverConfigPtr cfg,
                             unsigned long long *maxmem);

184
int
J
Jim Fehlig 已提交
185
libxlMakeDisk(virDomainDiskDefPtr l_dev, libxl_device_disk *x_dev);
186 187 188 189

void
libxlUpdateDiskDef(virDomainDiskDefPtr l_dev, libxl_device_disk *x_dev);

190
int
191 192
libxlMakeNic(virDomainDefPtr def,
             virDomainNetDefPtr l_nic,
193 194
             libxl_device_nic *x_nic,
             bool attach);
195
int
196
libxlMakeVfb(virPortAllocatorRangePtr graphicsports,
197
             virDomainGraphicsDefPtr l_vfb, libxl_device_vfb *x_vfb);
198

199
int
200
libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci *pcidev);
201

202
#ifdef LIBXL_HAVE_PVUSB
203 204 205 206
int
libxlMakeUSBController(virDomainControllerDefPtr controller,
                       libxl_device_usbctrl *usbctrl);

207 208
int
libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev);
209
#endif
210

211
virDomainXMLOptionPtr
212
libxlCreateXMLConf(libxlDriverPrivatePtr driver);
213

214 215 216
#ifdef LIBXL_HAVE_DEVICE_CHANNEL
# define LIBXL_ATTR_UNUSED
#else
J
Ján Tomko 已提交
217
# define LIBXL_ATTR_UNUSED G_GNUC_UNUSED
218
#endif
J
Jim Fehlig 已提交
219
int
220
libxlBuildDomainConfig(virPortAllocatorRangePtr graphicsports,
221
                       virDomainDefPtr def,
222
                       libxlDriverConfigPtr cfg,
223
                       libxl_domain_config *d_config);
J
Jim Fehlig 已提交
224

225 226 227 228 229 230 231 232 233 234 235
static inline void
libxlDriverLock(libxlDriverPrivatePtr driver)
{
    virMutexLock(&driver->lock);
}

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