storage_backend.h 9.1 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

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
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);
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
/* File creation/cloning functions used for cloning between backends */
int virStorageBackendCreateRaw(virConnectPtr conn,
78
                               virStoragePoolObjPtr pool,
79
                               virStorageVolDefPtr vol,
80 81 82
                               virStorageVolDefPtr inputvol,
                               unsigned int flags);
virStorageBackendBuildVolFrom
83
virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
84 85
                                         virStorageVolDefPtr inputvol);
int virStorageBackendFindFSImageTool(char **tool);
86
virStorageBackendBuildVolFrom
87
virStorageBackendFSImageToolTypeToFunc(int tool_type);
88

89 90 91 92

typedef struct _virStorageBackend virStorageBackend;
typedef virStorageBackend *virStorageBackendPtr;

93 94
/* Callbacks are optional unless documented otherwise; but adding more
 * callbacks provides better pool support.  */
95 96 97
struct _virStorageBackend {
    int type;

98
    virStorageBackendFindPoolSources findPoolSources;
99
    virStorageBackendCheckPool checkPool;
100 101
    virStorageBackendStartPool startPool;
    virStorageBackendBuildPool buildPool;
102
    virStorageBackendRefreshPool refreshPool; /* Must be non-NULL */
103 104 105
    virStorageBackendStopPool stopPool;
    virStorageBackendDeletePool deletePool;

106
    virStorageBackendBuildVol buildVol;
107
    virStorageBackendBuildVolFrom buildVolFrom;
108 109 110
    virStorageBackendCreateVol createVol;
    virStorageBackendRefreshVol refreshVol;
    virStorageBackendDeleteVol deleteVol;
111
    virStorageBackendVolumeResize resizeVol;
112 113 114
};

virStorageBackendPtr virStorageBackendForType(int type);
115

116 117 118 119 120 121 122 123 124 125 126
int virStorageBackendVolOpen(const char *path)
ATTRIBUTE_RETURN_CHECK
ATTRIBUTE_NONNULL(1);

/* VolOpenCheckMode flags */
enum {
    VIR_STORAGE_VOL_OPEN_ERROR  = 1 << 0, /* warn if unexpected type
                                           * encountered */
    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 */
127
    VIR_STORAGE_VOL_OPEN_DIR    = 1 << 4, /* directories okay */
128 129
};

130 131 132 133
# define VIR_STORAGE_VOL_OPEN_DEFAULT (VIR_STORAGE_VOL_OPEN_ERROR    |\
                                       VIR_STORAGE_VOL_OPEN_REG      |\
                                       VIR_STORAGE_VOL_OPEN_CHAR     |\
                                       VIR_STORAGE_VOL_OPEN_BLOCK)
134

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

140
int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
141
                                   int withCapacity);
142 143 144
int virStorageBackendUpdateVolInfoFlags(virStorageVolDefPtr vol,
                                        int withCapacity,
                                        unsigned int openflags);
145
int virStorageBackendUpdateVolTargetInfo(virStorageVolTargetPtr target,
146
                                         unsigned long long *allocation,
147 148
                                         unsigned long long *capacity,
                                         unsigned int openflags);
149
int virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
150
                                           int fd,
E
Eric Blake 已提交
151
                                           struct stat *sb,
152 153
                                           unsigned long long *allocation,
                                           unsigned long long *capacity);
154 155
int virStorageBackendDetectBlockVolFormatFD(virStorageVolTargetPtr target,
                                            int fd);
156

157
char *virStorageBackendStablePath(virStoragePoolObjPtr pool,
158
                                  const char *devpath,
159
                                  bool loop);
160

161
typedef int (*virStorageBackendListVolRegexFunc)(virStoragePoolObjPtr pool,
162 163
                                                 char **const groups,
                                                 void *data);
164
typedef int (*virStorageBackendListVolNulFunc)(virStoragePoolObjPtr pool,
165 166 167 168
                                               size_t n_tokens,
                                               char **const groups,
                                               void *data);

169
int virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
170
                                  virCommandPtr cmd,
171 172 173 174
                                  int nregex,
                                  const char **regex,
                                  int *nvars,
                                  virStorageBackendListVolRegexFunc func,
175
                                  void *data, const char *cmd_to_ignore);
176

177
int virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
178
                                virCommandPtr cmd,
179 180 181
                                size_t n_columns,
                                virStorageBackendListVolNulFunc func,
                                void *data);
182

183 184 185 186 187 188 189 190
virCommandPtr
virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
                                  virStoragePoolObjPtr pool,
                                  virStorageVolDefPtr vol,
                                  virStorageVolDefPtr inputvol,
                                  unsigned int flags,
                                  const char *create_tool,
                                  int imgformat);
191

192
#endif /* __VIR_STORAGE_BACKEND_H__ */