libxl_conf.h 6.5 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/>.
M
Markus Groß 已提交
20 21 22
 *
 * Authors:
 *     Jim Fehlig <jfehlig@novell.com>
23
 *     Markus Groß <gross@univention.de>
J
Jim Fehlig 已提交
24 25 26 27 28 29 30 31
 */

#ifndef LIBXL_CONF_H
# define LIBXL_CONF_H

# include <libxl.h>

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

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

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

J
Joao Martins 已提交
50 51 52 53
/* Used for prefix of ifname of any network name generated dynamically
 * by libvirt for Xen, and cannot be used for a persistent network name.  */
# define LIBXL_GENERATED_PREFIX_XEN "vif"

54
# define LIBXL_CONFIG_BASE_DIR SYSCONFDIR "/libvirt"
J
Jim Fehlig 已提交
55 56 57 58 59 60
# 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"
61
# define LIBXL_DUMP_DIR LIBXL_LIB_DIR "/dump"
62
# define LIBXL_BOOTLOADER_PATH "pygrub"
J
Jim Fehlig 已提交
63

64 65 66 67 68 69 70 71
# ifndef LIBXL_FIRMWARE_DIR
#  define LIBXL_FIRMWARE_DIR "/usr/lib/xen/boot"
# endif
# ifndef LIBXL_EXECBIN_DIR
#  define LIBXL_EXECBIN_DIR "/usr/lib/xen/bin"
# endif


72 73 74 75 76 77 78 79 80 81 82
/* libxl interface for setting VCPU affinity changed in 4.5. In fact, a new
 * parameter has been added, representative of 'VCPU soft affinity'. If one
 * does not care about it (and that's libvirt case), passing NULL is the
 * right thing to do. To mark that change, LIBXL_HAVE_VCPUINFO_SOFT_AFFINITY
 * is defined. */
# ifdef LIBXL_HAVE_VCPUINFO_SOFT_AFFINITY
#  define libxl_set_vcpuaffinity(ctx, domid, vcpuid, map) \
    libxl_set_vcpuaffinity((ctx), (domid), (vcpuid), (map), NULL)
#  define libxl_set_vcpuaffinity_all(ctx, domid, max_vcpus, map) \
    libxl_set_vcpuaffinity_all((ctx), (domid), (max_vcpus), (map), NULL)
# endif
J
Jim Fehlig 已提交
83 84 85

typedef struct _libxlDriverPrivate libxlDriverPrivate;
typedef libxlDriverPrivate *libxlDriverPrivatePtr;
86 87 88 89 90 91 92

typedef struct _libxlDriverConfig libxlDriverConfig;
typedef libxlDriverConfig *libxlDriverConfigPtr;

struct _libxlDriverConfig {
    virObject parent;

93
    const libxl_version_info *verInfo;
J
Jim Fehlig 已提交
94 95
    unsigned int version;

J
Jim Fehlig 已提交
96 97 98
    /* log stream for driver-wide libxl ctx */
    FILE *logger_file;
    xentoollog_logger *logger;
J
Jim Fehlig 已提交
99
    /* libxl ctx for driver wide ops; getVersion, getNodeInfo, ... */
J
Jim Fehlig 已提交
100
    libxl_ctx *ctx;
J
Jim Fehlig 已提交
101

102 103 104 105
    /* Controls automatic ballooning of domain0. If true, attempt to get
     * memory for new domains from domain0. */
    bool autoballoon;

106 107
    char *lockManagerName;

J
Joao Martins 已提交
108 109 110
    int keepAliveInterval;
    unsigned int keepAliveCount;

111 112 113
    /* Once created, caps are immutable */
    virCapsPtr caps;

114
    char *configBaseDir;
115 116 117 118 119 120
    char *configDir;
    char *autostartDir;
    char *logDir;
    char *stateDir;
    char *libDir;
    char *saveDir;
121
    char *autoDumpDir;
122 123 124 125 126 127
};


struct _libxlDriverPrivate {
    virMutex lock;

128
    virHostdevManagerPtr hostdevMgr;
129 130 131 132
    /* Require lock to get reference on 'config',
     * then lockless thereafter */
    libxlDriverConfigPtr config;

133
    /* Atomic inc/dec only */
134
    unsigned int nactive;
135

136
    /* Immutable pointers. Caller must provide locking */
137 138 139
    virStateInhibitCallback inhibitCallback;
    void *inhibitOpaque;

140
    /* Immutable pointer, self-locking APIs */
141
    virDomainObjListPtr domains;
J
Jim Fehlig 已提交
142

143
    /* Immutable pointer, immutable object */
144 145
    virDomainXMLOptionPtr xmlopt;

146
    /* Immutable pointer, self-locking APIs */
147
    virObjectEventStatePtr domainEventState;
148

149
    /* Immutable pointer, self-locking APIs */
150
    virPortAllocatorPtr reservedGraphicsPorts;
151

J
Jim Fehlig 已提交
152 153 154
    /* Immutable pointer, self-locking APIs */
    virPortAllocatorPtr migrationPorts;

155
    /* Immutable pointer, lockless APIs*/
156
    virSysinfoDefPtr hostsysinfo;
157 158 159

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

162 163 164 165 166 167 168 169 170 171 172 173
# define LIBXL_SAVE_MAGIC "libvirt-xml\n \0 \r"
# define LIBXL_SAVE_VERSION 1

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

175 176 177 178 179
libxlDriverConfigPtr
libxlDriverConfigNew(void);

libxlDriverConfigPtr
libxlDriverConfigGet(libxlDriverPrivatePtr driver);
180

181 182 183 184
int
libxlDriverNodeGetInfo(libxlDriverPrivatePtr driver,
                       virNodeInfoPtr info);

185 186 187
int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
                              const char *filename);

J
Jim Fehlig 已提交
188 189 190
virCapsPtr
libxlMakeCapabilities(libxl_ctx *ctx);

191 192 193
int
libxlDomainGetEmulatorType(const virDomainDef *def);

194
int
J
Jim Fehlig 已提交
195
libxlMakeDisk(virDomainDiskDefPtr l_dev, libxl_device_disk *x_dev);
196
int
197 198 199
libxlMakeNic(virDomainDefPtr def,
             virDomainNetDefPtr l_nic,
             libxl_device_nic *x_nic);
200
int
201
libxlMakeVfb(virPortAllocatorPtr graphicsports,
202
             virDomainGraphicsDefPtr l_vfb, libxl_device_vfb *x_vfb);
203

204
int
205
libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci *pcidev);
206

207 208 209
virDomainXMLOptionPtr
libxlCreateXMLConf(void);

J
Jim Fehlig 已提交
210
int
211
libxlBuildDomainConfig(virPortAllocatorPtr graphicsports,
212 213 214
                       virDomainDefPtr def,
                       libxl_ctx *ctx,
                       libxl_domain_config *d_config);
J
Jim Fehlig 已提交
215

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

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

J
Jim Fehlig 已提交
228
#endif /* LIBXL_CONF_H */