2 * storage_backend.h: internal storage driver backend contract
4 * Copyright (C) 2007-2010, 2012-2014 Red Hat, Inc.
5 * Copyright (C) 2007-2008 Daniel P. Berrange
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library. If not, see
19 * <http://www.gnu.org/licenses/>.
21 * Author: Daniel P. Berrange <berrange@redhat.com>
24 #ifndef __VIR_STORAGE_BACKEND_H__
25 # define __VIR_STORAGE_BACKEND_H__
27 # include <sys/stat.h>
29 # include "internal.h"
30 # include "storage_conf.h"
31 # include "vircommand.h"
32 # include "storage_driver.h"
34 typedef char * (*virStorageBackendFindPoolSources)(virConnectPtr conn,
37 typedef int (*virStorageBackendCheckPool)(virConnectPtr conn,
38 virStoragePoolObjPtr pool,
40 typedef int (*virStorageBackendStartPool)(virConnectPtr conn,
41 virStoragePoolObjPtr pool);
42 typedef int (*virStorageBackendBuildPool)(virConnectPtr conn,
43 virStoragePoolObjPtr pool,
45 typedef int (*virStorageBackendRefreshPool)(virConnectPtr conn,
46 virStoragePoolObjPtr pool);
47 typedef int (*virStorageBackendStopPool)(virConnectPtr conn,
48 virStoragePoolObjPtr pool);
49 typedef int (*virStorageBackendDeletePool)(virConnectPtr conn,
50 virStoragePoolObjPtr pool,
52 typedef int (*virStorageBackendBuildVol)(virConnectPtr conn,
53 virStoragePoolObjPtr pool,
54 virStorageVolDefPtr vol,
56 typedef int (*virStorageBackendCreateVol)(virConnectPtr conn,
57 virStoragePoolObjPtr pool,
58 virStorageVolDefPtr vol);
59 typedef int (*virStorageBackendRefreshVol)(virConnectPtr conn,
60 virStoragePoolObjPtr pool,
61 virStorageVolDefPtr vol);
62 typedef int (*virStorageBackendDeleteVol)(virConnectPtr conn,
63 virStoragePoolObjPtr pool,
64 virStorageVolDefPtr vol,
66 typedef int (*virStorageBackendBuildVolFrom)(virConnectPtr conn,
67 virStoragePoolObjPtr pool,
68 virStorageVolDefPtr origvol,
69 virStorageVolDefPtr newvol,
71 typedef int (*virStorageBackendVolumeResize)(virConnectPtr conn,
72 virStoragePoolObjPtr pool,
73 virStorageVolDefPtr vol,
74 unsigned long long capacity,
77 /* File creation/cloning functions used for cloning between backends */
78 int virStorageBackendCreateRaw(virConnectPtr conn,
79 virStoragePoolObjPtr pool,
80 virStorageVolDefPtr vol,
81 virStorageVolDefPtr inputvol,
83 virStorageBackendBuildVolFrom
84 virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
85 virStorageVolDefPtr inputvol);
86 int virStorageBackendFindFSImageTool(char **tool);
87 virStorageBackendBuildVolFrom
88 virStorageBackendFSImageToolTypeToFunc(int tool_type);
90 int virStorageBackendFindGlusterPoolSources(const char *host,
92 virStoragePoolSourceListPtr list);
95 typedef struct _virStorageBackend virStorageBackend;
96 typedef virStorageBackend *virStorageBackendPtr;
98 /* Callbacks are optional unless documented otherwise; but adding more
99 * callbacks provides better pool support. */
100 struct _virStorageBackend {
103 virStorageBackendFindPoolSources findPoolSources;
104 virStorageBackendCheckPool checkPool;
105 virStorageBackendStartPool startPool;
106 virStorageBackendBuildPool buildPool;
107 virStorageBackendRefreshPool refreshPool; /* Must be non-NULL */
108 virStorageBackendStopPool stopPool;
109 virStorageBackendDeletePool deletePool;
111 virStorageBackendBuildVol buildVol;
112 virStorageBackendBuildVolFrom buildVolFrom;
113 virStorageBackendCreateVol createVol;
114 virStorageBackendRefreshVol refreshVol;
115 virStorageBackendDeleteVol deleteVol;
116 virStorageBackendVolumeResize resizeVol;
119 virStorageBackendPtr virStorageBackendForType(int type);
121 /* VolOpenCheckMode flags */
123 VIR_STORAGE_VOL_OPEN_NOERROR = 1 << 0, /* don't error if unexpected type
124 * encountered, just warn */
125 VIR_STORAGE_VOL_OPEN_REG = 1 << 1, /* regular files okay */
126 VIR_STORAGE_VOL_OPEN_BLOCK = 1 << 2, /* block files okay */
127 VIR_STORAGE_VOL_OPEN_CHAR = 1 << 3, /* char files okay */
128 VIR_STORAGE_VOL_OPEN_DIR = 1 << 4, /* directories okay */
131 # define VIR_STORAGE_VOL_OPEN_DEFAULT (VIR_STORAGE_VOL_OPEN_REG |\
132 VIR_STORAGE_VOL_OPEN_BLOCK)
134 int virStorageBackendVolOpen(const char *path, struct stat *sb,
136 ATTRIBUTE_RETURN_CHECK
137 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
139 int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
141 bool withBlockVolFormat,
142 unsigned int openflags);
143 int virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
145 bool withBlockVolFormat,
146 unsigned int openflags);
147 int virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target,
150 bool updateCapacity);
152 char *virStorageBackendStablePath(virStoragePoolObjPtr pool,
157 virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
158 virStoragePoolObjPtr pool,
159 virStorageVolDefPtr vol,
160 virStorageVolDefPtr inputvol,
162 const char *create_tool,
165 /* ------- virStorageFile backends ------------ */
166 typedef struct _virStorageFileBackend virStorageFileBackend;
167 typedef virStorageFileBackend *virStorageFileBackendPtr;
169 struct _virStorageDriverData {
170 virStorageFileBackendPtr backend;
178 (*virStorageFileBackendInit)(virStorageSourcePtr src);
181 (*virStorageFileBackendDeinit)(virStorageSourcePtr src);
184 (*virStorageFileBackendCreate)(virStorageSourcePtr src);
187 (*virStorageFileBackendUnlink)(virStorageSourcePtr src);
190 (*virStorageFileBackendStat)(virStorageSourcePtr src,
194 (*virStorageFileBackendReadHeader)(virStorageSourcePtr src,
199 virStorageFileBackendPtr virStorageFileBackendForType(int type, int protocol);
203 struct _virStorageFileBackend {
207 /* All storage file callbacks may be omitted if not implemented */
209 /* The following group of callbacks is expected to set a libvirt
210 * error on failure. */
211 virStorageFileBackendInit backendInit;
212 virStorageFileBackendDeinit backendDeinit;
213 virStorageFileBackendReadHeader storageFileReadHeader;
215 /* The following group of callbacks is expected to set errno
216 * and return -1 on error. No libvirt error shall be reported */
217 virStorageFileBackendCreate storageFileCreate;
218 virStorageFileBackendUnlink storageFileUnlink;
219 virStorageFileBackendStat storageFileStat;
222 #endif /* __VIR_STORAGE_BACKEND_H__ */