xen_driver.h 6.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * xen_unified.c: Unified Xen driver.
 *
 * Copyright (C) 2007 Red Hat, Inc.
 *
 * See COPYING.LIB for the License of this software
 *
 * Richard W.M. Jones <rjones@redhat.com>
 */

#ifndef __VIR_XEN_UNIFIED_H__
#define __VIR_XEN_UNIFIED_H__

#include "internal.h"
15
#include "capabilities.h"
16
#include "driver.h"
17 18 19 20 21 22
#include "domain_conf.h"
#include "xs_internal.h"
#if WITH_XEN_INOTIFY
#include "xen_inotify.h"
#endif
#include "domain_event.h"
23
#include "hash.h"
24

25
#ifndef HAVE_WINSOCK2_H
26 27
#include <sys/un.h>
#include <netinet/in.h>
28 29 30
#else
#include <winsock2.h>
#endif
31

32
extern int xenRegister (void);
33

34 35 36 37 38
#define XEN_UNIFIED_HYPERVISOR_OFFSET 0
#define XEN_UNIFIED_PROXY_OFFSET 1
#define XEN_UNIFIED_XEND_OFFSET 2
#define XEN_UNIFIED_XS_OFFSET 3
#define XEN_UNIFIED_XM_OFFSET 4
39 40 41 42 43

#if WITH_XEN_INOTIFY
#define XEN_UNIFIED_INOTIFY_OFFSET 5
#define XEN_UNIFIED_NR_DRIVERS 6
#else
44
#define XEN_UNIFIED_NR_DRIVERS 5
45
#endif
46

47 48
#define MIN_XEN_GUEST_SIZE 64  /* 64 megabytes */

49 50 51
#define XEN_CONFIG_FORMAT_XM    "xen-xm"
#define XEN_CONFIG_FORMAT_SEXPR "xen-sxpr"

52 53
#define XEND_DOMAINS_DIR "/var/lib/xend/domains"

54 55 56 57 58 59 60 61 62 63 64
/* _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 {
65 66 67
        virDrvOpen			open;
        virDrvClose			close;
        virDrvGetVersion		version;
68
    virDrvGetHostname       getHostname;
69 70 71 72
        virDrvNodeGetInfo		nodeGetInfo;
        virDrvGetCapabilities		getCapabilities;
        virDrvListDomains		listDomains;
        virDrvNumOfDomains		numOfDomains;
73
        virDrvDomainCreateXML		domainCreateXML;
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
        virDrvDomainSuspend		domainSuspend;
        virDrvDomainResume		domainResume;
        virDrvDomainShutdown		domainShutdown;
        virDrvDomainReboot		domainReboot;
        virDrvDomainDestroy		domainDestroy;
        virDrvDomainGetOSType		domainGetOSType;
        virDrvDomainGetMaxMemory	domainGetMaxMemory;
        virDrvDomainSetMaxMemory	domainSetMaxMemory;
        virDrvDomainSetMemory		domainSetMemory;
        virDrvDomainGetInfo		domainGetInfo;
        virDrvDomainSave		domainSave;
        virDrvDomainRestore		domainRestore;
        virDrvDomainCoreDump		domainCoreDump;
        virDrvDomainSetVcpus		domainSetVcpus;
        virDrvDomainPinVcpu		domainPinVcpu;
        virDrvDomainGetVcpus		domainGetVcpus;
        virDrvDomainGetMaxVcpus		domainGetMaxVcpus;
        virDrvListDefinedDomains	listDefinedDomains;
        virDrvNumOfDefinedDomains	numOfDefinedDomains;
        virDrvDomainCreate		domainCreate;
        virDrvDomainDefineXML           domainDefineXML;
        virDrvDomainUndefine            domainUndefine;
        virDrvDomainAttachDevice	domainAttachDevice;
        virDrvDomainDetachDevice	domainDetachDevice;
        virDrvDomainGetAutostart	domainGetAutostart;
        virDrvDomainSetAutostart	domainSetAutostart;
        virDrvDomainGetSchedulerType	domainGetSchedulerType;
        virDrvDomainGetSchedulerParameters domainGetSchedulerParameters;
        virDrvDomainSetSchedulerParameters domainSetSchedulerParameters;
103 104
};

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
typedef struct xenXMConfCache *xenXMConfCachePtr;
typedef struct xenXMConfCache {
    time_t refreshedAt;
    char filename[PATH_MAX];
    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;

132 133 134 135 136 137
/* 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 已提交
138 139 140 141 142 143
    virMutex lock;

    /* These initial vars are initialized in Open method
     * and readonly thereafter, so can be used without
     * holding the lock
     */
144
    virCapsPtr caps;
145 146 147 148 149
    int handle;			/* Xen hypervisor handle */

    int xendConfigVersion;      /* XenD config version */

    /* connection to xend */
150 151 152 153
    struct sockaddr_storage addr;
    socklen_t addrlen;
    int addrfamily;
    int addrprotocol;
154

155 156 157 158 159
    /* 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];
160

D
Daniel P. Berrange 已提交
161 162 163 164 165 166 167 168 169 170 171

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

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

    int proxy;                  /* fd of proxy. */


172 173 174
    /* A list of xenstore watches */
    xenStoreWatchListPtr xsWatchList;
    int xsWatch;
175 176 177
    /* A list of active domain name/uuids */
    xenUnifiedDomainInfoListPtr activeDomainList;

D
Daniel P. Berrange 已提交
178 179 180
    /* NUMA topology info cache */
    int nbNodeCells;
    int nbNodeCpus;
181 182 183

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

186 187 188 189
    /* Location of config files, either /etc
     * or /var/lib/xen */
    const char *configDir;

190 191 192 193
#if WITH_XEN_INOTIFY
    /* The inotify fd */
    int inotifyFD;
    int inotifyWatch;
194 195 196

    int  useXenConfigCache ;
    xenUnifiedDomainInfoListPtr configInfoList;
197
#endif
198 199 200 201 202 203 204 205

    /* 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;
206 207 208 209
};

typedef struct _xenUnifiedPrivate *xenUnifiedPrivatePtr;

210
char *xenDomainUsedCpus(virDomainPtr dom);
211

212 213 214 215 216 217 218 219
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,
220
                                    virDomainEventPtr event);
221 222
unsigned long xenUnifiedVersion(void);

D
Daniel P. Berrange 已提交
223 224 225 226 227 228 229 230
#ifndef PROXY
void xenUnifiedLock(xenUnifiedPrivatePtr priv);
void xenUnifiedUnlock(xenUnifiedPrivatePtr priv);
#else
#define xenUnifiedLock(p) do {} while(0)
#define xenUnifiedUnlock(p) do {} while(0)
#endif

231
#endif /* __VIR_XEN_UNIFIED_H__ */