qemu_block.h 5.9 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 69 70
virJSONValuePtr
qemuBlockStorageSourceGetBlockdevProps(virStorageSourcePtr src);

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

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

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

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

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

    virJSONValuePtr authsecretProps;
    char *authsecretAlias;

    virJSONValuePtr encryptsecretProps;
    char *encryptsecretAlias;
97 98 99

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


void
qemuBlockStorageSourceAttachDataFree(qemuBlockStorageSourceAttachDataPtr data);

106 107 108
VIR_DEFINE_AUTOPTR_FUNC(qemuBlockStorageSourceAttachData,
                        qemuBlockStorageSourceAttachDataFree);

109
qemuBlockStorageSourceAttachDataPtr
110 111
qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src,
                                            bool autoreadonly);
112

113 114 115 116
qemuBlockStorageSourceAttachDataPtr
qemuBlockStorageSourceDetachPrepare(virStorageSourcePtr src,
                                    char *driveAlias);

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

void
qemuBlockStorageSourceAttachRollback(qemuMonitorPtr mon,
                                     qemuBlockStorageSourceAttachDataPtr data);

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

131 132 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 159
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);


VIR_DEFINE_AUTOPTR_FUNC(qemuBlockStorageSourceChainData,
                        qemuBlockStorageSourceChainDataFree);

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

166 167 168 169 170
int
qemuBlockSnapshotAddBlockdev(virJSONValuePtr actions,
                             virDomainDiskDefPtr disk,
                             virStorageSourcePtr newsrc);

171 172 173 174 175
int
qemuBlockStorageSourceCreateGetFormatProps(virStorageSourcePtr src,
                                           virStorageSourcePtr backing,
                                           virJSONValuePtr *props)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;
176 177 178 179 180

int
qemuBlockStorageSourceCreateGetStorageProps(virStorageSourcePtr src,
                                            virJSONValuePtr *props)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;