storage_backend.h 12.2 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
typedef char * (*virStorageBackendFindPoolSources)(virConnectPtr conn,
                                                   const char *srcSpec,
                                                   unsigned int flags);
37
typedef int (*virStorageBackendCheckPool)(virStoragePoolObjPtr pool,
38 39 40 41 42 43 44 45 46 47 48 49 50
                                          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);
51
typedef int (*virStorageBackendBuildVol)(virConnectPtr conn,
52 53
                                         virStoragePoolObjPtr pool,
                                         virStorageVolDefPtr vol,
54
                                         unsigned int flags);
55 56 57 58 59 60 61 62 63 64 65 66 67 68
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,
69
                                             unsigned int flags);
70 71 72 73 74
typedef int (*virStorageBackendVolumeResize)(virConnectPtr conn,
                                             virStoragePoolObjPtr pool,
                                             virStorageVolDefPtr vol,
                                             unsigned long long capacity,
                                             unsigned int flags);
75 76 77 78 79 80 81 82 83 84 85 86 87 88
typedef int (*virStorageBackendVolumeDownload)(virConnectPtr conn,
                                               virStoragePoolObjPtr obj,
                                               virStorageVolDefPtr vol,
                                               virStreamPtr stream,
                                               unsigned long long offset,
                                               unsigned long long length,
                                               unsigned int flags);
typedef int (*virStorageBackendVolumeUpload)(virConnectPtr conn,
                                             virStoragePoolObjPtr obj,
                                             virStorageVolDefPtr vol,
                                             virStreamPtr stream,
                                             unsigned long long offset,
                                             unsigned long long len,
                                             unsigned int flags);
89 90 91 92 93
typedef int (*virStorageBackendVolumeWipe)(virConnectPtr conn,
                                           virStoragePoolObjPtr pool,
                                           virStorageVolDefPtr vol,
                                           unsigned int algorithm,
                                           unsigned int flags);
94

95 96
/* File creation/cloning functions used for cloning between backends */
int virStorageBackendCreateRaw(virConnectPtr conn,
97
                               virStoragePoolObjPtr pool,
98
                               virStorageVolDefPtr vol,
99 100 101
                               virStorageVolDefPtr inputvol,
                               unsigned int flags);
virStorageBackendBuildVolFrom
102
virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
103 104
                                         virStorageVolDefPtr inputvol);
int virStorageBackendFindFSImageTool(char **tool);
105
virStorageBackendBuildVolFrom
106
virStorageBackendFSImageToolTypeToFunc(int tool_type);
107

108 109 110 111
int virStorageBackendFindGlusterPoolSources(const char *host,
                                            int pooltype,
                                            virStoragePoolSourceListPtr list);

112 113 114 115 116 117 118 119 120 121 122 123 124 125
int virStorageBackendVolUploadLocal(virConnectPtr conn,
                                    virStoragePoolObjPtr pool,
                                    virStorageVolDefPtr vol,
                                    virStreamPtr stream,
                                    unsigned long long offset,
                                    unsigned long long len,
                                    unsigned int flags);
int virStorageBackendVolDownloadLocal(virConnectPtr conn,
                                      virStoragePoolObjPtr pool,
                                      virStorageVolDefPtr vol,
                                      virStreamPtr stream,
                                      unsigned long long offset,
                                      unsigned long long len,
                                      unsigned int flags);
126

127 128 129 130 131 132
int virStorageBackendVolWipeLocal(virConnectPtr conn,
                                  virStoragePoolObjPtr pool,
                                  virStorageVolDefPtr vol,
                                  unsigned int algorithm,
                                  unsigned int flags);

133 134 135
typedef struct _virStorageBackend virStorageBackend;
typedef virStorageBackend *virStorageBackendPtr;

136 137
/* Callbacks are optional unless documented otherwise; but adding more
 * callbacks provides better pool support.  */
138 139 140
struct _virStorageBackend {
    int type;

141
    virStorageBackendFindPoolSources findPoolSources;
142
    virStorageBackendCheckPool checkPool;
143 144
    virStorageBackendStartPool startPool;
    virStorageBackendBuildPool buildPool;
145
    virStorageBackendRefreshPool refreshPool; /* Must be non-NULL */
146 147 148
    virStorageBackendStopPool stopPool;
    virStorageBackendDeletePool deletePool;

149
    virStorageBackendBuildVol buildVol;
150
    virStorageBackendBuildVolFrom buildVolFrom;
151 152 153
    virStorageBackendCreateVol createVol;
    virStorageBackendRefreshVol refreshVol;
    virStorageBackendDeleteVol deleteVol;
154
    virStorageBackendVolumeResize resizeVol;
155 156
    virStorageBackendVolumeUpload uploadVol;
    virStorageBackendVolumeDownload downloadVol;
157
    virStorageBackendVolumeWipe wipeVol;
158 159 160
};

virStorageBackendPtr virStorageBackendForType(int type);
161

162 163
/* VolOpenCheckMode flags */
enum {
164 165 166 167 168 169
    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 */
170 171
};

172
# define VIR_STORAGE_VOL_OPEN_DEFAULT (VIR_STORAGE_VOL_OPEN_REG      |\
173
                                       VIR_STORAGE_VOL_OPEN_BLOCK)
174

175 176
int virStorageBackendVolOpen(const char *path, struct stat *sb,
                             unsigned int flags)
E
Eric Blake 已提交
177 178
    ATTRIBUTE_RETURN_CHECK
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
179

180
int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
181
                                   bool withBlockVolFormat,
182
                                   unsigned int openflags);
183
int virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
184
                                         bool withBlockVolFormat,
185
                                         unsigned int openflags);
186
int virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target,
187
                                           int fd,
188
                                           struct stat *sb);
189

190
char *virStorageBackendStablePath(virStoragePoolObjPtr pool,
191
                                  const char *devpath,
192
                                  bool loop);
193

194 195 196 197 198 199 200 201
virCommandPtr
virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
                                  virStoragePoolObjPtr pool,
                                  virStorageVolDefPtr vol,
                                  virStorageVolDefPtr inputvol,
                                  unsigned int flags,
                                  const char *create_tool,
                                  int imgformat);
202

203
/* ------- virStorageFile backends ------------ */
204 205 206 207 208 209
typedef struct _virStorageFileBackend virStorageFileBackend;
typedef virStorageFileBackend *virStorageFileBackendPtr;

struct _virStorageDriverData {
    virStorageFileBackendPtr backend;
    void *priv;
210 211 212

    uid_t uid;
    gid_t gid;
213 214
};

215
typedef int
216
(*virStorageFileBackendInit)(virStorageSourcePtr src);
217 218

typedef void
219
(*virStorageFileBackendDeinit)(virStorageSourcePtr src);
220 221

typedef int
222
(*virStorageFileBackendCreate)(virStorageSourcePtr src);
223 224

typedef int
225
(*virStorageFileBackendUnlink)(virStorageSourcePtr src);
226 227

typedef int
228
(*virStorageFileBackendStat)(virStorageSourcePtr src,
229 230
                             struct stat *st);

231 232 233 234 235
typedef ssize_t
(*virStorageFileBackendReadHeader)(virStorageSourcePtr src,
                                   ssize_t max_len,
                                   char **buf);

236 237
typedef const char *
(*virStorageFileBackendGetUniqueIdentifier)(virStorageSourcePtr src);
238

239 240 241 242
typedef int
(*virStorageFileBackendAccess)(virStorageSourcePtr src,
                               int mode);

243 244 245 246 247
typedef int
(*virStorageFileBackendChown)(virStorageSourcePtr src,
                              uid_t uid,
                              gid_t gid);

248
virStorageFileBackendPtr virStorageFileBackendForType(int type, int protocol);
249 250 251
virStorageFileBackendPtr virStorageFileBackendForTypeInternal(int type,
                                                              int protocol,
                                                              bool report);
252 253


254 255 256 257 258 259 260 261 262 263
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;
264
    virStorageFileBackendReadHeader storageFileReadHeader;
265
    virStorageFileBackendGetUniqueIdentifier storageFileGetUniqueIdentifier;
266 267 268 269 270 271

    /* 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;
272
    virStorageFileBackendAccess storageFileAccess;
273
    virStorageFileBackendChown  storageFileChown;
274 275
};

276
#endif /* __VIR_STORAGE_BACKEND_H__ */