storage_backend.h 9.8 KB
Newer Older
1 2 3
/*
 * storage_backend.h: internal storage driver backend contract
 *
4
 * Copyright (C) 2007-2010, 2012-2014 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17
 * Copyright (C) 2007-2008 Daniel P. Berrange
 *
 * 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
18
 * License along with this library.  If not, see
O
Osier Yang 已提交
19
 * <http://www.gnu.org/licenses/>.
20 21 22 23 24
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

#ifndef __VIR_STORAGE_BACKEND_H__
25
# define __VIR_STORAGE_BACKEND_H__
26

E
Eric Blake 已提交
27 28
# include <sys/stat.h>

29 30
# include "internal.h"
# include "storage_conf.h"
31
# include "vircommand.h"
32
# include "storage_driver.h"
33

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
typedef char * (*virStorageBackendFindPoolSources)(virConnectPtr conn,
                                                   const char *srcSpec,
                                                   unsigned int flags);
typedef int (*virStorageBackendCheckPool)(virConnectPtr conn,
                                          virStoragePoolObjPtr pool,
                                          bool *active);
typedef int (*virStorageBackendStartPool)(virConnectPtr conn,
                                          virStoragePoolObjPtr pool);
typedef int (*virStorageBackendBuildPool)(virConnectPtr conn,
                                          virStoragePoolObjPtr pool,
                                          unsigned int flags);
typedef int (*virStorageBackendRefreshPool)(virConnectPtr conn,
                                            virStoragePoolObjPtr pool);
typedef int (*virStorageBackendStopPool)(virConnectPtr conn,
                                         virStoragePoolObjPtr pool);
typedef int (*virStorageBackendDeletePool)(virConnectPtr conn,
                                           virStoragePoolObjPtr pool,
                                           unsigned int flags);
52
typedef int (*virStorageBackendBuildVol)(virConnectPtr conn,
53 54
                                         virStoragePoolObjPtr pool,
                                         virStorageVolDefPtr vol,
55
                                         unsigned int flags);
56 57 58 59 60 61 62 63 64 65 66 67 68 69
typedef int (*virStorageBackendCreateVol)(virConnectPtr conn,
                                          virStoragePoolObjPtr pool,
                                          virStorageVolDefPtr vol);
typedef int (*virStorageBackendRefreshVol)(virConnectPtr conn,
                                           virStoragePoolObjPtr pool,
                                           virStorageVolDefPtr vol);
typedef int (*virStorageBackendDeleteVol)(virConnectPtr conn,
                                          virStoragePoolObjPtr pool,
                                          virStorageVolDefPtr vol,
                                          unsigned int flags);
typedef int (*virStorageBackendBuildVolFrom)(virConnectPtr conn,
                                             virStoragePoolObjPtr pool,
                                             virStorageVolDefPtr origvol,
                                             virStorageVolDefPtr newvol,
70
                                             unsigned int flags);
71 72 73 74 75
typedef int (*virStorageBackendVolumeResize)(virConnectPtr conn,
                                             virStoragePoolObjPtr pool,
                                             virStorageVolDefPtr vol,
                                             unsigned long long capacity,
                                             unsigned int flags);
76

77 78
/* File creation/cloning functions used for cloning between backends */
int virStorageBackendCreateRaw(virConnectPtr conn,
79
                               virStoragePoolObjPtr pool,
80
                               virStorageVolDefPtr vol,
81 82 83
                               virStorageVolDefPtr inputvol,
                               unsigned int flags);
virStorageBackendBuildVolFrom
84
virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
85 86
                                         virStorageVolDefPtr inputvol);
int virStorageBackendFindFSImageTool(char **tool);
87
virStorageBackendBuildVolFrom
88
virStorageBackendFSImageToolTypeToFunc(int tool_type);
89

90 91 92 93
int virStorageBackendFindGlusterPoolSources(const char *host,
                                            int pooltype,
                                            virStoragePoolSourceListPtr list);

94 95 96 97

typedef struct _virStorageBackend virStorageBackend;
typedef virStorageBackend *virStorageBackendPtr;

98 99
/* Callbacks are optional unless documented otherwise; but adding more
 * callbacks provides better pool support.  */
100 101 102
struct _virStorageBackend {
    int type;

103
    virStorageBackendFindPoolSources findPoolSources;
104
    virStorageBackendCheckPool checkPool;
105 106
    virStorageBackendStartPool startPool;
    virStorageBackendBuildPool buildPool;
107
    virStorageBackendRefreshPool refreshPool; /* Must be non-NULL */
108 109 110
    virStorageBackendStopPool stopPool;
    virStorageBackendDeletePool deletePool;

111
    virStorageBackendBuildVol buildVol;
112
    virStorageBackendBuildVolFrom buildVolFrom;
113 114 115
    virStorageBackendCreateVol createVol;
    virStorageBackendRefreshVol refreshVol;
    virStorageBackendDeleteVol deleteVol;
116
    virStorageBackendVolumeResize resizeVol;
117 118 119
};

virStorageBackendPtr virStorageBackendForType(int type);
120

121 122
/* VolOpenCheckMode flags */
enum {
123 124 125 126 127 128
    VIR_STORAGE_VOL_OPEN_NOERROR = 1 << 0, /* don't error if unexpected type
                                            * encountered, just warn */
    VIR_STORAGE_VOL_OPEN_REG     = 1 << 1, /* regular files okay */
    VIR_STORAGE_VOL_OPEN_BLOCK   = 1 << 2, /* block files okay */
    VIR_STORAGE_VOL_OPEN_CHAR    = 1 << 3, /* char files okay */
    VIR_STORAGE_VOL_OPEN_DIR     = 1 << 4, /* directories okay */
129 130
};

131
# define VIR_STORAGE_VOL_OPEN_DEFAULT (VIR_STORAGE_VOL_OPEN_REG      |\
132
                                       VIR_STORAGE_VOL_OPEN_BLOCK)
133

134 135
int virStorageBackendVolOpen(const char *path, struct stat *sb,
                             unsigned int flags)
E
Eric Blake 已提交
136 137
    ATTRIBUTE_RETURN_CHECK
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
138

139
int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
140
                                   bool updateCapacity,
141
                                   bool withBlockVolFormat,
142
                                   unsigned int openflags);
143
int virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
144
                                         bool updateCapacity,
145
                                         bool withBlockVolFormat,
146
                                         unsigned int openflags);
147
int virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target,
148
                                           int fd,
149 150
                                           struct stat *sb,
                                           bool updateCapacity);
151

152
char *virStorageBackendStablePath(virStoragePoolObjPtr pool,
153
                                  const char *devpath,
154
                                  bool loop);
155

156 157 158 159 160 161 162 163
virCommandPtr
virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
                                  virStoragePoolObjPtr pool,
                                  virStorageVolDefPtr vol,
                                  virStorageVolDefPtr inputvol,
                                  unsigned int flags,
                                  const char *create_tool,
                                  int imgformat);
164

165
/* ------- virStorageFile backends ------------ */
166 167 168 169 170 171
typedef struct _virStorageFileBackend virStorageFileBackend;
typedef virStorageFileBackend *virStorageFileBackendPtr;

struct _virStorageDriverData {
    virStorageFileBackendPtr backend;
    void *priv;
172 173 174

    uid_t uid;
    gid_t gid;
175 176
};

177
typedef int
178
(*virStorageFileBackendInit)(virStorageSourcePtr src);
179 180

typedef void
181
(*virStorageFileBackendDeinit)(virStorageSourcePtr src);
182 183

typedef int
184
(*virStorageFileBackendCreate)(virStorageSourcePtr src);
185 186

typedef int
187
(*virStorageFileBackendUnlink)(virStorageSourcePtr src);
188 189

typedef int
190
(*virStorageFileBackendStat)(virStorageSourcePtr src,
191 192
                             struct stat *st);

193 194 195 196 197
typedef ssize_t
(*virStorageFileBackendReadHeader)(virStorageSourcePtr src,
                                   ssize_t max_len,
                                   char **buf);

198 199
typedef const char *
(*virStorageFileBackendGetUniqueIdentifier)(virStorageSourcePtr src);
200

201 202 203 204
typedef int
(*virStorageFileBackendAccess)(virStorageSourcePtr src,
                               int mode);

205
virStorageFileBackendPtr virStorageFileBackendForType(int type, int protocol);
206 207 208
virStorageFileBackendPtr virStorageFileBackendForTypeInternal(int type,
                                                              int protocol,
                                                              bool report);
209 210


211 212 213 214 215 216 217 218 219 220
struct _virStorageFileBackend {
    int type;
    int protocol;

    /* All storage file callbacks may be omitted if not implemented */

    /* The following group of callbacks is expected to set a libvirt
     * error on failure. */
    virStorageFileBackendInit backendInit;
    virStorageFileBackendDeinit backendDeinit;
221
    virStorageFileBackendReadHeader storageFileReadHeader;
222
    virStorageFileBackendGetUniqueIdentifier storageFileGetUniqueIdentifier;
223 224 225 226 227 228

    /* The following group of callbacks is expected to set errno
     * and return -1 on error. No libvirt error shall be reported */
    virStorageFileBackendCreate storageFileCreate;
    virStorageFileBackendUnlink storageFileUnlink;
    virStorageFileBackendStat   storageFileStat;
229
    virStorageFileBackendAccess storageFileAccess;
230 231
};

232
#endif /* __VIR_STORAGE_BACKEND_H__ */