storage_backend.h 7.9 KB
Newer Older
1 2 3
/*
 * storage_backend.h: internal storage driver backend contract
 *
4
 * Copyright (C) 2007-2010, 2012 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

27 28
# include "internal.h"
# include "storage_conf.h"
29
# include "vircommand.h"
30 31

typedef char * (*virStorageBackendFindPoolSources)(virConnectPtr conn, const char *srcSpec, unsigned int flags);
32
typedef int (*virStorageBackendCheckPool)(virConnectPtr conn, virStoragePoolObjPtr pool, bool *active);
33 34 35 36 37 38
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);

39
typedef int (*virStorageBackendBuildVol)(virConnectPtr conn,
40 41
                                         virStoragePoolObjPtr pool, virStorageVolDefPtr vol,
                                         unsigned int flags);
42 43 44
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);
45 46 47
typedef int (*virStorageBackendBuildVolFrom)(virConnectPtr conn, virStoragePoolObjPtr pool,
                                             virStorageVolDefPtr origvol, virStorageVolDefPtr newvol,
                                             unsigned int flags);
48 49 50 51 52
typedef int (*virStorageBackendVolumeResize)(virConnectPtr conn,
                                             virStoragePoolObjPtr pool,
                                             virStorageVolDefPtr vol,
                                             unsigned long long capacity,
                                             unsigned int flags);
53

54 55
/* File creation/cloning functions used for cloning between backends */
int virStorageBackendCreateRaw(virConnectPtr conn,
56
                               virStoragePoolObjPtr pool,
57
                               virStorageVolDefPtr vol,
58 59 60
                               virStorageVolDefPtr inputvol,
                               unsigned int flags);
virStorageBackendBuildVolFrom
61
virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
62 63
                                         virStorageVolDefPtr inputvol);
int virStorageBackendFindFSImageTool(char **tool);
64
virStorageBackendBuildVolFrom
65
virStorageBackendFSImageToolTypeToFunc(int tool_type);
66

67 68 69 70 71 72 73

typedef struct _virStorageBackend virStorageBackend;
typedef virStorageBackend *virStorageBackendPtr;

struct _virStorageBackend {
    int type;

74
    virStorageBackendFindPoolSources findPoolSources;
75
    virStorageBackendCheckPool checkPool;
76 77 78 79 80 81
    virStorageBackendStartPool startPool;
    virStorageBackendBuildPool buildPool;
    virStorageBackendRefreshPool refreshPool;
    virStorageBackendStopPool stopPool;
    virStorageBackendDeletePool deletePool;

82
    virStorageBackendBuildVol buildVol;
83
    virStorageBackendBuildVolFrom buildVolFrom;
84 85 86
    virStorageBackendCreateVol createVol;
    virStorageBackendRefreshVol refreshVol;
    virStorageBackendDeleteVol deleteVol;
87
    virStorageBackendVolumeResize resizeVol;
88 89 90
};

virStorageBackendPtr virStorageBackendForType(int type);
91

92 93 94 95 96 97 98 99 100 101 102
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 */
103
    VIR_STORAGE_VOL_OPEN_DIR    = 1 << 4, /* directories okay */
104 105
};

106 107 108 109
# 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)
110 111 112 113

int virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags)
ATTRIBUTE_RETURN_CHECK
ATTRIBUTE_NONNULL(1);
114

115
int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
116 117
                                   int withCapacity);

118 119 120
int virStorageBackendUpdateVolInfoFlags(virStorageVolDefPtr vol,
                                        int withCapacity,
                                        unsigned int openflags);
121
int virStorageBackendUpdateVolTargetInfo(virStorageVolTargetPtr target,
122
                                         unsigned long long *allocation,
123 124
                                         unsigned long long *capacity,
                                         unsigned int openflags);
125
int virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
126 127 128
                                           int fd,
                                           unsigned long long *allocation,
                                           unsigned long long *capacity);
D
Dave Allan 已提交
129
int
130 131
virStorageBackendDetectBlockVolFormatFD(virStorageVolTargetPtr target,
                                        int fd);
132

133
char *virStorageBackendStablePath(virStoragePoolObjPtr pool,
134
                                  const char *devpath,
135
                                  bool loop);
136

137
typedef int (*virStorageBackendListVolRegexFunc)(virStoragePoolObjPtr pool,
138 139
                                                 char **const groups,
                                                 void *data);
140
typedef int (*virStorageBackendListVolNulFunc)(virStoragePoolObjPtr pool,
141 142 143 144
                                               size_t n_tokens,
                                               char **const groups,
                                               void *data);

145
int virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
146
                                  virCommandPtr cmd,
147 148 149 150
                                  int nregex,
                                  const char **regex,
                                  int *nvars,
                                  virStorageBackendListVolRegexFunc func,
151
                                  void *data, const char *cmd_to_ignore);
152

153
int virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
154
                                virCommandPtr cmd,
155 156 157
                                size_t n_columns,
                                virStorageBackendListVolNulFunc func,
                                void *data);
158

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

168
#endif /* __VIR_STORAGE_BACKEND_H__ */