vz_utils.h 4.4 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 30 31
# include "driver.h"
# include "conf/domain_conf.h"
# include "conf/storage_conf.h"
# include "conf/domain_event.h"
D
Dmitry Guryanov 已提交
32
# include "conf/network_conf.h"
33
# include "virthread.h"
34
# include "virjson.h"
D
Dmitry Guryanov 已提交
35

36
# define vzParseError()                                                 \
37 38 39
    virReportErrorHelper(VIR_FROM_TEST, VIR_ERR_OPERATION_FAILED, __FILE__,    \
                     __FUNCTION__, __LINE__, _("Can't parse prlctl output"))

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

42
# define vzDomNotFoundError(domain)                               \
43 44 45 46 47 48 49
    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)

50 51 52 53 54 55 56
# define PARALLELS_DOMAIN_ROUTED_NETWORK_NAME   "Routed"
# define PARALLELS_DOMAIN_BRIDGED_NETWORK_NAME  "Bridged"

# define PARALLELS_REQUIRED_HOSTONLY_NETWORK "Host-Only"
# define PARALLELS_HOSTONLY_NETWORK_TYPE "host-only"
# define PARALLELS_REQUIRED_BRIDGED_NETWORK  "Bridged"
# define PARALLELS_BRIDGED_NETWORK_TYPE  "bridged"
57

58
struct _vzConn {
D
Dmitry Guryanov 已提交
59
    virMutex lock;
60 61

    /* Immutable pointer, self-locking APIs */
62
    virDomainObjListPtr domains;
63

64
    PRL_HANDLE server;
D
Dmitry Guryanov 已提交
65
    virStoragePoolObjList pools;
66
    virNetworkObjListPtr networks;
D
Dmitry Guryanov 已提交
67
    virCapsPtr caps;
68
    virDomainXMLOptionPtr xmlopt;
69
    virObjectEventStatePtr domainEventState;
70
    virStorageDriverStatePtr storageState;
71
    const char *drivername;
D
Dmitry Guryanov 已提交
72 73
};

74 75
typedef struct _vzConn vzConn;
typedef struct _vzConn *vzConnPtr;
D
Dmitry Guryanov 已提交
76

77
struct _vzCountersCache {
78 79 80 81 82 83 84
    PRL_HANDLE stats;
    virCond cond;
    // -1 - unsubscribed
    // > -1 - subscribed
    int count;
};

85
typedef struct _vzCountersCache vzCountersCache;
86

87
struct vzDomObj {
D
Dmitry Guryanov 已提交
88 89
    int id;
    char *uuid;
90
    char *home;
91
    PRL_HANDLE sdkdom;
92
    vzCountersCache cache;
D
Dmitry Guryanov 已提交
93 94
};

95
typedef struct vzDomObj *vzDomObjPtr;
D
Dmitry Guryanov 已提交
96

97 98 99
virDrvOpenStatus vzStorageOpen(virConnectPtr conn, unsigned int flags);
int vzStorageClose(virConnectPtr conn);
extern virStorageDriver vzStorageDriver;
100

101 102 103
virDrvOpenStatus vzNetworkOpen(virConnectPtr conn, unsigned int flags);
int vzNetworkClose(virConnectPtr conn);
extern virNetworkDriver vzNetworkDriver;
D
Dmitry Guryanov 已提交
104

105 106
virDomainObjPtr vzDomObjFromDomain(virDomainPtr domain);
virDomainObjPtr vzDomObjFromDomainRef(virDomainPtr domain);
107

108
virJSONValuePtr vzParseOutput(const char *binary, ...)
109
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL;
110
char * vzGetOutput(const char *binary, ...)
111
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL;
112
int vzCmdRun(const char *binary, ...)
113
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL;
114 115 116 117
char * vzAddFileExt(const char *path, const char *ext);
void vzDriverLock(vzConnPtr driver);
void vzDriverUnlock(vzConnPtr driver);
virStorageVolPtr vzStorageVolLookupByPathLocked(virConnectPtr conn,
118
                                                       const char *path);
119
int vzStorageVolDefRemove(virStoragePoolObjPtr privpool,
120
                                 virStorageVolDefPtr privvol);
121

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