xen_driver.h 7.5 KB
Newer Older
1 2 3
/*
 * xen_unified.c: Unified Xen driver.
 *
E
Eric Blake 已提交
4
 * Copyright (C) 2007, 2010-2011 Red Hat, Inc.
5 6 7 8 9 10 11
 *
 * See COPYING.LIB for the License of this software
 *
 * Richard W.M. Jones <rjones@redhat.com>
 */

#ifndef __VIR_XEN_UNIFIED_H__
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# 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"
# include "hash.h"

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

E
Eric Blake 已提交
32 33
# include <xen/xen.h>

34 35 36 37 38 39 40 41
/* 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

42
extern int xenRegister (void);
43

44
# define XEN_UNIFIED_HYPERVISOR_OFFSET 0
45 46 47
# define XEN_UNIFIED_XEND_OFFSET 1
# define XEN_UNIFIED_XS_OFFSET 2
# define XEN_UNIFIED_XM_OFFSET 3
48

49
# if WITH_XEN_INOTIFY
50
#  define XEN_UNIFIED_INOTIFY_OFFSET 4
51
#  define XEN_UNIFIED_NR_DRIVERS 5
52 53
# else
#  define XEN_UNIFIED_NR_DRIVERS 4
54
# endif
55

56
# define MIN_XEN_GUEST_SIZE 64  /* 64 megabytes */
57

58 59
# define XEN_CONFIG_FORMAT_XM    "xen-xm"
# define XEN_CONFIG_FORMAT_SEXPR "xen-sxpr"
60

61
# define XEND_DOMAINS_DIR "/var/lib/xend/domains"
62

63 64 65
# define XEN_SCHED_SEDF_NPARAM   6
# define XEN_SCHED_CRED_NPARAM   2

E
Eric Blake 已提交
66 67 68 69 70 71 72
/* 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)

73 74 75 76 77 78 79 80 81 82 83
/* _xenUnifiedDriver:
 *
 * Entry points into the underlying Xen drivers.  This structure
 * will eventually go away and instead xen unified will make direct
 * calls to the underlying Xen drivers.
 *
 * To reiterate - the goal is to remove elements from this structure
 * until it is empty, replacing indirect calls through this
 * structure with direct calls in xen_unified.c.
 */
struct xenUnifiedDriver {
84 85 86
        virDrvOpen			open;
        virDrvClose			close;
        virDrvGetVersion		version;
87
    virDrvGetHostname       getHostname;
88 89 90 91
        virDrvNodeGetInfo		nodeGetInfo;
        virDrvGetCapabilities		getCapabilities;
        virDrvListDomains		listDomains;
        virDrvNumOfDomains		numOfDomains;
92
        virDrvDomainCreateXML		domainCreateXML;
93 94 95 96 97
        virDrvDomainSuspend		domainSuspend;
        virDrvDomainResume		domainResume;
        virDrvDomainShutdown		domainShutdown;
        virDrvDomainReboot		domainReboot;
        virDrvDomainDestroy		domainDestroy;
98
        virDrvDomainDestroyFlags    domainDestroyFlags;
99 100 101 102 103 104 105 106
        virDrvDomainGetOSType		domainGetOSType;
        virDrvDomainGetMaxMemory	domainGetMaxMemory;
        virDrvDomainSetMaxMemory	domainSetMaxMemory;
        virDrvDomainSetMemory		domainSetMemory;
        virDrvDomainGetInfo		domainGetInfo;
        virDrvDomainSave		domainSave;
        virDrvDomainRestore		domainRestore;
        virDrvDomainCoreDump		domainCoreDump;
107
        virDrvDomainScreenshot      domainScreenshot;
108 109 110 111 112 113 114
        virDrvDomainPinVcpu		domainPinVcpu;
        virDrvDomainGetVcpus		domainGetVcpus;
        virDrvListDefinedDomains	listDefinedDomains;
        virDrvNumOfDefinedDomains	numOfDefinedDomains;
        virDrvDomainCreate		domainCreate;
        virDrvDomainDefineXML           domainDefineXML;
        virDrvDomainUndefine            domainUndefine;
115 116
        virDrvDomainAttachDeviceFlags	domainAttachDeviceFlags;
        virDrvDomainDetachDeviceFlags	domainDetachDeviceFlags;
117
        virDrvDomainUpdateDeviceFlags	domainUpdateDeviceFlags;
118 119 120 121 122
        virDrvDomainGetAutostart	domainGetAutostart;
        virDrvDomainSetAutostart	domainSetAutostart;
        virDrvDomainGetSchedulerType	domainGetSchedulerType;
        virDrvDomainGetSchedulerParameters domainGetSchedulerParameters;
        virDrvDomainSetSchedulerParameters domainSetSchedulerParameters;
123 124
};

125 126 127
typedef struct xenXMConfCache *xenXMConfCachePtr;
typedef struct xenXMConfCache {
    time_t refreshedAt;
E
Eric Blake 已提交
128
    char *filename;
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
    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 {
    unsigned int count;
    xenUnifiedDomainInfoPtr *doms;
};
typedef struct _xenUnifiedDomainInfoList xenUnifiedDomainInfoList;
typedef xenUnifiedDomainInfoList *xenUnifiedDomainInfoListPtr;

152 153 154 155 156 157
/* 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 已提交
158 159 160 161 162 163
    virMutex lock;

    /* These initial vars are initialized in Open method
     * and readonly thereafter, so can be used without
     * holding the lock
     */
164
    virCapsPtr caps;
165 166 167 168 169
    int handle;			/* Xen hypervisor handle */

    int xendConfigVersion;      /* XenD config version */

    /* connection to xend */
170 171 172 173
    struct sockaddr_storage addr;
    socklen_t addrlen;
    int addrfamily;
    int addrprotocol;
174

175 176 177 178 179
    /* 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];
180

D
Daniel P. Berrange 已提交
181 182 183 184 185 186 187 188 189

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

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


190 191 192
    /* A list of xenstore watches */
    xenStoreWatchListPtr xsWatchList;
    int xsWatch;
193 194 195
    /* A list of active domain name/uuids */
    xenUnifiedDomainInfoListPtr activeDomainList;

D
Daniel P. Berrange 已提交
196 197 198
    /* NUMA topology info cache */
    int nbNodeCells;
    int nbNodeCpus;
199 200 201

    /* An list of callbacks */
    virDomainEventCallbackListPtr domainEventCallbacks;
D
Daniel P. Berrange 已提交
202
    int domainEventDispatching;
203

204 205 206 207
    /* Location of config files, either /etc
     * or /var/lib/xen */
    const char *configDir;

208
# if WITH_XEN_INOTIFY
209 210 211
    /* The inotify fd */
    int inotifyFD;
    int inotifyWatch;
212 213 214

    int  useXenConfigCache ;
    xenUnifiedDomainInfoListPtr configInfoList;
215
# endif
216 217 218 219 220 221 222 223

    /* 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;
224 225 226 227
};

typedef struct _xenUnifiedPrivate *xenUnifiedPrivatePtr;

228
char *xenDomainUsedCpus(virDomainPtr dom);
229

230 231 232 233 234 235 236 237
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,
238
                                    virDomainEventPtr event);
239
unsigned long xenUnifiedVersion(void);
240
int xenUnifiedGetMaxVcpus(virConnectPtr conn, const char *type);
241

D
Daniel P. Berrange 已提交
242 243 244
void xenUnifiedLock(xenUnifiedPrivatePtr priv);
void xenUnifiedUnlock(xenUnifiedPrivatePtr priv);

245
#endif /* __VIR_XEN_UNIFIED_H__ */