qemu_block.h 7.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * qemu_block.h: helper functions for QEMU block subsystem
 *
 * 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/>.
 */

19
#pragma once
20

21
#include "internal.h"
22

23 24
#include "qemu_conf.h"
#include "qemu_domain.h"
25

26 27 28
#include "virhash.h"
#include "virjson.h"
#include "viruri.h"
29 30 31 32 33 34 35 36

typedef struct qemuBlockNodeNameBackingChainData qemuBlockNodeNameBackingChainData;
typedef qemuBlockNodeNameBackingChainData *qemuBlockNodeNameBackingChainDataPtr;
struct qemuBlockNodeNameBackingChainData {
    char *qemufilename; /* name of the image from qemu */
    char *nodeformat;   /* node name of the format layer */
    char *nodestorage;  /* node name of the storage backing the format node */

37
    qemuBlockNodeNameBackingChainDataPtr backing;
38 39 40 41

    /* for testing purposes */
    char *drvformat;
    char *drvstorage;
42 43 44
};

virHashTablePtr
45 46
qemuBlockNodeNameGetBackingChain(virJSONValuePtr namednodesdata,
                                 virJSONValuePtr blockstats);
47

48 49
int
qemuBlockNodeNamesDetect(virQEMUDriverPtr driver,
50 51
                         virDomainObjPtr vm,
                         qemuDomainAsyncJob asyncJob);
52

53 54 55
virHashTablePtr
qemuBlockGetNodeData(virJSONValuePtr data);

56 57 58
bool
qemuBlockStorageSourceSupportsConcurrentAccess(virStorageSourcePtr src);

59
virJSONValuePtr
60
qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
61
                                      bool legacy,
62 63
                                      bool onlytarget,
                                      bool autoreadonly);
64

65 66 67
virURIPtr
qemuBlockStorageSourceGetURI(virStorageSourcePtr src);

68
virJSONValuePtr
69 70
qemuBlockStorageSourceGetBlockdevProps(virStorageSourcePtr src,
                                       virStorageSourcePtr backingStore);
71

72 73
virJSONValuePtr
qemuBlockStorageGetCopyOnReadProps(virDomainDiskDefPtr disk);
74 75 76 77

typedef struct qemuBlockStorageSourceAttachData qemuBlockStorageSourceAttachData;
typedef qemuBlockStorageSourceAttachData *qemuBlockStorageSourceAttachDataPtr;
struct qemuBlockStorageSourceAttachData {
78 79 80
    virJSONValuePtr prmgrProps;
    char *prmgrAlias;

81 82 83 84 85 86 87
    virJSONValuePtr storageProps;
    const char *storageNodeName;
    bool storageAttached;

    virJSONValuePtr formatProps;
    const char *formatNodeName;
    bool formatAttached;
88 89 90 91

    char *driveCmd;
    char *driveAlias;
    bool driveAdded;
92 93 94 95 96 97

    virJSONValuePtr authsecretProps;
    char *authsecretAlias;

    virJSONValuePtr encryptsecretProps;
    char *encryptsecretAlias;
98 99 100

    virJSONValuePtr tlsProps;
    char *tlsAlias;
101 102 103 104 105 106
};


void
qemuBlockStorageSourceAttachDataFree(qemuBlockStorageSourceAttachDataPtr data);

107
G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuBlockStorageSourceAttachData,
108 109
                        qemuBlockStorageSourceAttachDataFree);

110
qemuBlockStorageSourceAttachDataPtr
111
qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src,
112
                                            virStorageSourcePtr backingStore,
113
                                            bool autoreadonly);
114

115 116 117 118
qemuBlockStorageSourceAttachDataPtr
qemuBlockStorageSourceDetachPrepare(virStorageSourcePtr src,
                                    char *driveAlias);

119 120 121 122 123 124 125 126 127 128 129 130 131 132
int
qemuBlockStorageSourceAttachApply(qemuMonitorPtr mon,
                                  qemuBlockStorageSourceAttachDataPtr data);

void
qemuBlockStorageSourceAttachRollback(qemuMonitorPtr mon,
                                     qemuBlockStorageSourceAttachDataPtr data);

int
qemuBlockStorageSourceDetachOneBlockdev(virQEMUDriverPtr driver,
                                        virDomainObjPtr vm,
                                        qemuDomainAsyncJob asyncJob,
                                        virStorageSourcePtr src);

133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
struct _qemuBlockStorageSourceChainData {
    qemuBlockStorageSourceAttachDataPtr *srcdata;
    size_t nsrcdata;
};

typedef struct _qemuBlockStorageSourceChainData qemuBlockStorageSourceChainData;
typedef qemuBlockStorageSourceChainData *qemuBlockStorageSourceChainDataPtr;

void
qemuBlockStorageSourceChainDataFree(qemuBlockStorageSourceChainDataPtr data);

qemuBlockStorageSourceChainDataPtr
qemuBlockStorageSourceChainDetachPrepareBlockdev(virStorageSourcePtr src);
qemuBlockStorageSourceChainDataPtr
qemuBlockStorageSourceChainDetachPrepareDrive(virStorageSourcePtr src,
                                              char *driveAlias);

int
qemuBlockStorageSourceChainAttach(qemuMonitorPtr mon,
                                  qemuBlockStorageSourceChainDataPtr data);

void
qemuBlockStorageSourceChainDetach(qemuMonitorPtr mon,
                                  qemuBlockStorageSourceChainDataPtr data);


159
G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuBlockStorageSourceChainData,
160 161
                        qemuBlockStorageSourceChainDataFree);

162 163 164 165 166
int
qemuBlockSnapshotAddLegacy(virJSONValuePtr actions,
                           virDomainDiskDefPtr disk,
                           virStorageSourcePtr newsrc,
                           bool reuse);
167

168 169 170 171 172
int
qemuBlockSnapshotAddBlockdev(virJSONValuePtr actions,
                             virDomainDiskDefPtr disk,
                             virStorageSourcePtr newsrc);

173 174 175 176
char *
qemuBlockGetBackingStoreString(virStorageSourcePtr src)
    ATTRIBUTE_NONNULL(1);

177 178 179 180
int
qemuBlockStorageSourceCreateGetFormatProps(virStorageSourcePtr src,
                                           virStorageSourcePtr backing,
                                           virJSONValuePtr *props)
181
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3) G_GNUC_WARN_UNUSED_RESULT;
182 183 184 185

int
qemuBlockStorageSourceCreateGetStorageProps(virStorageSourcePtr src,
                                            virJSONValuePtr *props)
186
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
187 188 189 190 191 192 193 194 195 196

int
qemuBlockStorageSourceCreate(virDomainObjPtr vm,
                             virStorageSourcePtr src,
                             virStorageSourcePtr backingStore,
                             virStorageSourcePtr chain,
                             qemuBlockStorageSourceAttachDataPtr data,
                             qemuDomainAsyncJob asyncJob);

int
197
qemuBlockStorageSourceCreateDetectSize(virHashTablePtr blockNamedNodeData,
198
                                       virStorageSourcePtr src,
199
                                       virStorageSourcePtr templ);
200 201 202 203 204 205

int
qemuBlockRemoveImageMetadata(virQEMUDriverPtr driver,
                             virDomainObjPtr vm,
                             const char *diskTarget,
                             virStorageSourcePtr src);
206 207 208 209 210

qemuBlockNamedNodeDataBitmapPtr
qemuBlockNamedNodeDataGetBitmapByName(virHashTablePtr blockNamedNodeData,
                                      virStorageSourcePtr src,
                                      const char *bitmap);
211 212 213 214

virHashTablePtr
qemuBlockGetNamedNodeData(virDomainObjPtr vm,
                          qemuDomainAsyncJob asyncJob);
215 216 217 218 219

bool
qemuBlockBitmapChainIsValid(virStorageSourcePtr src,
                            const char *bitmapname,
                            virHashTablePtr blockNamedNodeData);