xen_driver.h 5.8 KB
Newer Older
1
/*
2
 * xen_driver.h: Unified Xen driver.
3
 *
E
Eric Blake 已提交
4
 * Copyright (C) 2007, 2010-2011 Red Hat, Inc.
5
 *
O
Osier Yang 已提交
6 7 8 9 10 11 12 13 14 15 16
 * 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
17
 * License along with this library.  If not, see
O
Osier Yang 已提交
18
 * <http://www.gnu.org/licenses/>.
19 20 21 22 23
 *
 * Richard W.M. Jones <rjones@redhat.com>
 */

#ifndef __VIR_XEN_UNIFIED_H__
24 25 26 27 28 29 30 31 32 33 34
# define __VIR_XEN_UNIFIED_H__

# include "internal.h"
# include "capabilities.h"
# include "driver.h"
# include "domain_conf.h"
# include "xs_internal.h"
# if WITH_XEN_INOTIFY
#  include "xen_inotify.h"
# endif
# include "domain_event.h"
35
# include "virhash.h"
36 37 38 39 40 41 42

# ifndef HAVE_WINSOCK2_H
#  include <sys/un.h>
#  include <netinet/in.h>
# else
#  include <winsock2.h>
# endif
43

E
Eric Blake 已提交
44 45
# include <xen/xen.h>

46 47 48 49 50 51 52 53
/* xen-unstable changeset 19788 removed MAX_VIRT_CPUS from public
 * headers.  Its semantic was retained with XEN_LEGACY_MAX_VCPUS.
 * Ensure MAX_VIRT_CPUS is defined accordingly.
 */
# if !defined(MAX_VIRT_CPUS) && defined(XEN_LEGACY_MAX_VCPUS)
#  define MAX_VIRT_CPUS XEN_LEGACY_MAX_VCPUS
# endif

54
int xenRegister (void);
55

56
# define XEN_UNIFIED_HYPERVISOR_OFFSET 0
57 58 59
# define XEN_UNIFIED_XEND_OFFSET 1
# define XEN_UNIFIED_XS_OFFSET 2
# define XEN_UNIFIED_XM_OFFSET 3
60

61
# if WITH_XEN_INOTIFY
62
#  define XEN_UNIFIED_INOTIFY_OFFSET 4
63
#  define XEN_UNIFIED_NR_DRIVERS 5
64 65
# else
#  define XEN_UNIFIED_NR_DRIVERS 4
66
# endif
67

68
# define MIN_XEN_GUEST_SIZE 64  /* 64 megabytes */
69

70
# define XEND_DOMAINS_DIR "/var/lib/xend/domains"
71

72 73 74
# define XEN_SCHED_SEDF_NPARAM   6
# define XEN_SCHED_CRED_NPARAM   2

E
Eric Blake 已提交
75 76 77 78 79 80 81
/* The set of migration flags explicitly supported by xen.  */
# define XEN_MIGRATION_FLAGS                    \
    (VIR_MIGRATE_LIVE |                         \
     VIR_MIGRATE_UNDEFINE_SOURCE |              \
     VIR_MIGRATE_PAUSED |                       \
     VIR_MIGRATE_PERSIST_DEST)

82

83 84 85
typedef struct xenXMConfCache *xenXMConfCachePtr;
typedef struct xenXMConfCache {
    time_t refreshedAt;
E
Eric Blake 已提交
86
    char *filename;
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    virDomainDefPtr def;
} xenXMConfCache;

/* xenUnifiedDomainInfoPtr:
 * The minimal state we have about active domains
 * This is the minmal info necessary to still get a
 * virDomainPtr when the domain goes away
 */
struct _xenUnifiedDomainInfo {
    int  id;
    char *name;
    unsigned char uuid[VIR_UUID_BUFLEN];
};
typedef struct _xenUnifiedDomainInfo xenUnifiedDomainInfo;
typedef xenUnifiedDomainInfo *xenUnifiedDomainInfoPtr;

struct _xenUnifiedDomainInfoList {
104
    size_t count;
105 106 107 108 109
    xenUnifiedDomainInfoPtr *doms;
};
typedef struct _xenUnifiedDomainInfoList xenUnifiedDomainInfoList;
typedef xenUnifiedDomainInfoList *xenUnifiedDomainInfoListPtr;

110 111 112 113 114 115
/* xenUnifiedPrivatePtr:
 *
 * Per-connection private data, stored in conn->privateData.  All Xen
 * low-level drivers access parts of this structure.
 */
struct _xenUnifiedPrivate {
D
Daniel P. Berrange 已提交
116 117 118 119 120 121
    virMutex lock;

    /* These initial vars are initialized in Open method
     * and readonly thereafter, so can be used without
     * holding the lock
     */
122
    virCapsPtr caps;
123
    virDomainXMLOptionPtr xmlopt;
124 125 126
    int handle;			/* Xen hypervisor handle */

    /* connection to xend */
127 128 129 130
    struct sockaddr_storage addr;
    socklen_t addrlen;
    int addrfamily;
    int addrprotocol;
131

132 133 134 135 136
    /* Keep track of the drivers which opened.  We keep a yes/no flag
     * here for each driver, corresponding to the array drivers in
     * xen_unified.c.
     */
    int opened[XEN_UNIFIED_NR_DRIVERS];
137

D
Daniel P. Berrange 已提交
138 139 140 141 142 143 144 145 146

    /*
     * Everything from this point onwards must be protected
     * by the lock when used
     */

    struct xs_handle *xshandle; /* handle to talk to the xenstore */


147 148 149
    /* A list of xenstore watches */
    xenStoreWatchListPtr xsWatchList;
    int xsWatch;
150 151 152
    /* A list of active domain name/uuids */
    xenUnifiedDomainInfoListPtr activeDomainList;

D
Daniel P. Berrange 已提交
153 154 155
    /* NUMA topology info cache */
    int nbNodeCells;
    int nbNodeCpus;
156

157
    virObjectEventStatePtr domainEvents;
158

159 160 161
    /* Location of config files, either /etc
     * or /var/lib/xen */
    const char *configDir;
162 163
    /* Location of managed save dir, default /var/lib/libvirt/xen/save */
    char *saveDir;
164

165
# if WITH_XEN_INOTIFY
166 167 168
    /* The inotify fd */
    int inotifyFD;
    int inotifyWatch;
169

170
    int  useXenConfigCache;
171
    xenUnifiedDomainInfoListPtr configInfoList;
172
# endif
173 174 175 176 177 178 179 180

    /* For the 'xm' driver */
    /* Primary config file name -> virDomainDef map */
    virHashTablePtr configCache;
    /* Domain name to config file name */
    virHashTablePtr nameConfigMap;
    /* So we don't refresh too often */
    time_t lastRefresh;
181 182 183 184
};

typedef struct _xenUnifiedPrivate *xenUnifiedPrivatePtr;

185
char *xenDomainUsedCpus(virDomainPtr dom, virDomainDefPtr def);
186

187 188
virDomainXMLOptionPtr xenDomainXMLConfInit(void);

189 190 191 192 193 194 195 196
void xenUnifiedDomainInfoListFree(xenUnifiedDomainInfoListPtr info);
int  xenUnifiedAddDomainInfo(xenUnifiedDomainInfoListPtr info,
                             int id, char *name,
                             unsigned char *uuid);
int  xenUnifiedRemoveDomainInfo(xenUnifiedDomainInfoListPtr info,
                                int id, char *name,
                                unsigned char *uuid);
void xenUnifiedDomainEventDispatch (xenUnifiedPrivatePtr priv,
197
                                    virObjectEventPtr event);
198
unsigned long xenUnifiedVersion(void);
199
int xenUnifiedConnectGetMaxVcpus(virConnectPtr conn, const char *type);
200

D
Daniel P. Berrange 已提交
201 202 203
void xenUnifiedLock(xenUnifiedPrivatePtr priv);
void xenUnifiedUnlock(xenUnifiedPrivatePtr priv);

204
#endif /* __VIR_XEN_UNIFIED_H__ */