vz_utils.h 4.6 KB
Newer Older
1
/*
2
 * vz_utils.h: core driver functions for managing
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * Parallels Cloud Server hosts
 *
 * Copyright (C) 2012 Parallels, Inc.
 *
 * 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
 * License along with this library; If not, see
 * <http://www.gnu.org/licenses/>.
 *
 */

23 24
#ifndef LIBVIRT_VZ_UTILS_H
# define LIBVIRT_VZ_UTILS_H
25

26 27
# include <Parallels.h>

D
Dmitry Guryanov 已提交
28 29
# include "driver.h"
# include "conf/domain_conf.h"
30
# include "conf/snapshot_conf.h"
31
# include "conf/virdomainsnapshotobjlist.h"
32
# include "conf/virdomainobjlist.h"
D
Dmitry Guryanov 已提交
33
# include "conf/domain_event.h"
34
# include "virthread.h"
35
# include "datatypes.h"
D
Dmitry Guryanov 已提交
36

37 38
# define vzParseError() \
    virReportErrorHelper(VIR_FROM_TEST, VIR_ERR_OPERATION_FAILED, __FILE__, \
M
Michal Privoznik 已提交
39
                         __FUNCTION__, __LINE__, _("Can't parse prlctl output"))
40

M
Maxim Nestratov 已提交
41
# define IS_CT(def)  (def->os.type == VIR_DOMAIN_OSTYPE_EXE)
42

43 44 45 46 47
# define vzDomNotFoundError(domain) \
    do { \
        char uuidstr[VIR_UUID_STRING_BUFLEN]; \
        virUUIDFormat(domain->uuid, uuidstr); \
        virReportError(VIR_ERR_NO_DOMAIN, \
48 49 50
                       _("no domain with matching uuid '%s'"), uuidstr); \
    } while (0)

51
# define PARALLELS_DOMAIN_ROUTED_NETWORK_NAME   "host-routed"
52
# define VIRTUOZZO_VER_7 ((unsigned long)7000000)
53 54 55 56 57

struct _vzCapabilities {
    virStorageFileFormat vmDiskFormat;
    virStorageFileFormat ctDiskFormat;
    virDomainDiskBus *diskBuses;
58 59
    virDomainControllerType *controllerTypes;
    virDomainControllerModelSCSI scsiControllerModel;
60 61 62
};
typedef struct _vzCapabilities vzCapabilities;
typedef struct _vzCapabilities *vzCapabilitiesPtr;
63

64 65 66
/* +2 to keep enclosing { and } */
# define VIR_UUID_STRING_BRACED_BUFLEN (VIR_UUID_STRING_BUFLEN + 2)

67 68
struct _vzDriver {
    virObjectLockable parent;
69 70

    /* Immutable pointer, self-locking APIs */
71
    virDomainObjListPtr domains;
72
    unsigned char session_uuid[VIR_UUID_BUFLEN];
73
    PRL_HANDLE server;
D
Dmitry Guryanov 已提交
74
    virCapsPtr caps;
75
    virDomainXMLOptionPtr xmlopt;
76
    virObjectEventStatePtr domainEventState;
77
    virSysinfoDefPtr hostsysinfo;
78
    unsigned long vzVersion;
79
    vzCapabilities vzCaps;
D
Dmitry Guryanov 已提交
80 81
};

82 83 84 85 86 87 88 89 90 91 92
typedef struct _vzDriver vzDriver;
typedef struct _vzDriver *vzDriverPtr;

struct _vzConn {
    struct _vzConn* next;

    vzDriverPtr driver;
    /* Immutable pointer, self-locking APIs */
    virConnectCloseCallbackDataPtr closeCallback;
};

93 94
typedef struct _vzConn vzConn;
typedef struct _vzConn *vzConnPtr;
D
Dmitry Guryanov 已提交
95

96 97 98 99 100 101 102 103
struct _vzDomainJobObj {
    virCond cond;
    bool active;
    /* when the job started, zeroed on time discontinuities */
    unsigned long long started;
    unsigned long long elapsed;
    bool hasProgress;
    int progress; /* percents */
104 105
    PRL_HANDLE sdkJob;
    bool cancelled;
106 107 108 109
};

typedef struct _vzDomainJobObj vzDomainJobObj;
typedef struct _vzDomainJobObj *vzDomainJobObjPtr;
110

111
struct vzDomObj {
D
Dmitry Guryanov 已提交
112
    int id;
113
    PRL_HANDLE sdkdom;
114
    PRL_HANDLE stats;
115
    vzDomainJobObj job;
D
Dmitry Guryanov 已提交
116 117
};

118
typedef struct vzDomObj *vzDomObjPtr;
D
Dmitry Guryanov 已提交
119

N
Nikolay Shirokovskiy 已提交
120
void* vzDomObjAlloc(void *opaque);
121 122
void vzDomObjFree(void *p);

123
virDomainObjPtr vzDomObjFromDomain(virDomainPtr domain);
124

125
char * vzGetOutput(const char *binary, ...)
126
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL;
127 128 129 130 131 132 133

vzDriverPtr
vzGetDriverConnection(void);

void
vzDestroyDriverConnection(void);

134
int
135
vzInitVersion(vzDriverPtr driver);
136
int
137 138 139
vzCheckUnsupportedDisk(const virDomainDef *def,
                       virDomainDiskDefPtr disk,
                       vzCapabilitiesPtr vzCaps);
140
int
141
vzCheckUnsupportedControllers(const virDomainDef *def,
142
                              vzCapabilitiesPtr vzCaps);
M
Mikhail Feoktistov 已提交
143
int
144
vzGetDefaultSCSIModel(vzDriverPtr driver,
M
Mikhail Feoktistov 已提交
145
                      PRL_CLUSTERED_DEVICE_SUBTYPE *scsiModel);
146

147 148
int vzCheckUnsupportedGraphics(virDomainGraphicsDefPtr gr);

149 150 151 152
# define PARALLELS_BLOCK_STATS_FOREACH(OP) \
    OP(rd_req, VIR_DOMAIN_BLOCK_STATS_READ_REQ, "read_requests") \
    OP(rd_bytes, VIR_DOMAIN_BLOCK_STATS_READ_BYTES, "read_total") \
    OP(wr_req, VIR_DOMAIN_BLOCK_STATS_WRITE_REQ, "write_requests") \
M
Michal Privoznik 已提交
153
    OP(wr_bytes, VIR_DOMAIN_BLOCK_STATS_WRITE_BYTES, "write_total")
154

155 156 157 158
int
vzDomainObjBeginJob(virDomainObjPtr dom);
void
vzDomainObjEndJob(virDomainObjPtr dom);
159 160
int
vzDomainJobUpdateTime(vzDomainJobObjPtr job);
161

162
#endif /* LIBVIRT_VZ_UTILS_H */