vz_utils.h 4.1 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 23 24 25
 * 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/>.
 *
 */

#ifndef PARALLELS_UTILS_H
# define PARALLELS_UTILS_H

26 27
# include <Parallels.h>

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

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

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

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

49 50
# define PARALLELS_DOMAIN_ROUTED_NETWORK_NAME   "Routed"
# define PARALLELS_DOMAIN_BRIDGED_NETWORK_NAME  "Bridged"
51 52 53 54 55 56
# define VIRTUOZZO_VER_7 ((unsigned long) 7000000)

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

63
struct _vzConn {
D
Dmitry Guryanov 已提交
64
    virMutex lock;
65 66

    /* Immutable pointer, self-locking APIs */
67
    virDomainObjListPtr domains;
68

69
    PRL_HANDLE server;
D
Dmitry Guryanov 已提交
70
    virCapsPtr caps;
71
    virDomainXMLOptionPtr xmlopt;
72
    virObjectEventStatePtr domainEventState;
73
    const char *drivername;
74 75
    /* Immutable pointer, self-locking APIs */
    virConnectCloseCallbackDataPtr closeCallback;
76
    unsigned long vzVersion;
77
    vzCapabilities vzCaps;
D
Dmitry Guryanov 已提交
78 79
};

80 81
typedef struct _vzConn vzConn;
typedef struct _vzConn *vzConnPtr;
D
Dmitry Guryanov 已提交
82

83
struct _vzCountersCache {
84 85
    PRL_HANDLE stats;
    virCond cond;
M
Michal Privoznik 已提交
86 87
    /* = -1 - unsubscribed
       > -1 - subscribed */
88 89 90
    int count;
};

91
typedef struct _vzCountersCache vzCountersCache;
92

93
struct vzDomObj {
D
Dmitry Guryanov 已提交
94
    int id;
95
    char *home;
96
    PRL_HANDLE sdkdom;
97
    vzCountersCache cache;
D
Dmitry Guryanov 已提交
98 99
};

100
typedef struct vzDomObj *vzDomObjPtr;
D
Dmitry Guryanov 已提交
101

102 103
virDomainObjPtr vzDomObjFromDomain(virDomainPtr domain);
virDomainObjPtr vzDomObjFromDomainRef(virDomainPtr domain);
104

105
char * vzGetOutput(const char *binary, ...)
106
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL;
107 108
void vzDriverLock(vzConnPtr driver);
void vzDriverUnlock(vzConnPtr driver);
109 110 111 112
virDomainObjPtr
vzNewDomain(vzConnPtr privconn,
            char *name,
            const unsigned char *uuid);
113 114
int
vzInitVersion(vzConnPtr privconn);
115 116 117
int
vzCheckUnsupportedDisks(virDomainDefPtr def,
                        vzCapabilitiesPtr vzCaps);
118 119 120
int
vzCheckUnsupportedControllers(virDomainDefPtr def,
                              vzCapabilitiesPtr vzCaps);
121

M
Michal Privoznik 已提交
122 123 124 125 126
# 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")      \
    OP(wr_bytes, VIR_DOMAIN_BLOCK_STATS_WRITE_BYTES, "write_total")
127

128
#endif