1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
/*
* storage_backend.c: internal storage driver backend contract
*
* Copyright (C) 2007-2016 Red Hat, Inc.
* 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
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <sys/stat.h>
#include "virerror.h"
#include "internal.h"
#include "storage_backend.h"
#include "virlog.h"
#include "virmodule.h"
#include "virfile.h"
#include "configmake.h"
#if WITH_STORAGE_LVM
# include "storage_backend_logical.h"
#endif
#if WITH_STORAGE_ISCSI
# include "storage_backend_iscsi.h"
#endif
#if WITH_STORAGE_ISCSI_DIRECT
# include "storage_backend_iscsi_direct.h"
#endif
#if WITH_STORAGE_SCSI
# include "storage_backend_scsi.h"
#endif
#if WITH_STORAGE_MPATH
# include "storage_backend_mpath.h"
#endif
#if WITH_STORAGE_DISK
# include "storage_backend_disk.h"
#endif
#if WITH_STORAGE_DIR
# include "storage_backend_fs.h"
#endif
#if WITH_STORAGE_RBD
# include "storage_backend_rbd.h"
#endif
#if WITH_STORAGE_GLUSTER
# include "storage_backend_gluster.h"
#endif
#if WITH_STORAGE_ZFS
# include "storage_backend_zfs.h"
#endif
#if WITH_STORAGE_VSTORAGE
# include "storage_backend_vstorage.h"
#endif
#define VIR_FROM_THIS VIR_FROM_STORAGE
VIR_LOG_INIT("storage.storage_backend");
#define VIR_STORAGE_BACKENDS_MAX 20
static virStorageBackend *virStorageBackends[VIR_STORAGE_BACKENDS_MAX];
static size_t virStorageBackendsCount;
#define STORAGE_BACKEND_MODULE_DIR LIBDIR "/libvirt/storage-backend"
static int
virStorageDriverLoadBackendModule(const char *name,
const char *regfunc,
bool forceload)
{
g_autofree char *modfile = NULL;
if (!(modfile = virFileFindResourceFull(name,
"libvirt_storage_backend_",
VIR_FILE_MODULE_EXT,
abs_top_builddir "/src",
STORAGE_BACKEND_MODULE_DIR,
"LIBVIRT_STORAGE_BACKEND_DIR")))
return -1;
return virModuleLoad(modfile, regfunc, forceload);
}
#define VIR_STORAGE_BACKEND_REGISTER(func, module) \
if (virStorageDriverLoadBackendModule(module, #func, allbackends) < 0) \
return -1
int
virStorageBackendDriversRegister(bool allbackends G_GNUC_UNUSED)
{
#if WITH_STORAGE_DIR || WITH_STORAGE_FS
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendFsRegister, "fs");
#endif
#if WITH_STORAGE_LVM
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendLogicalRegister, "logical");
#endif
#if WITH_STORAGE_ISCSI
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendISCSIRegister, "iscsi");
#endif
#if WITH_STORAGE_ISCSI_DIRECT
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendISCSIDirectRegister, "iscsi-direct");
#endif
#if WITH_STORAGE_SCSI
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendSCSIRegister, "scsi");
#endif
#if WITH_STORAGE_MPATH
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendMpathRegister, "mpath");
#endif
#if WITH_STORAGE_DISK
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendDiskRegister, "disk");
#endif
#if WITH_STORAGE_RBD
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendRBDRegister, "rbd");
#endif
#if WITH_STORAGE_GLUSTER
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendGlusterRegister, "gluster");
#endif
#if WITH_STORAGE_ZFS
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendZFSRegister, "zfs");
#endif
#if WITH_STORAGE_VSTORAGE
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendVstorageRegister, "vstorage");
#endif
return 0;
}
#undef VIR_STORAGE_BACKEND_REGISTER
int
virStorageBackendRegister(virStorageBackend *backend)
{
VIR_DEBUG("Registering storage backend '%s'",
virStoragePoolTypeToString(backend->type));
if (virStorageBackendsCount >= VIR_STORAGE_BACKENDS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Too many drivers, cannot register storage backend '%1$s'"),
virStoragePoolTypeToString(backend->type));
return -1;
}
virStorageBackends[virStorageBackendsCount] = backend;
virStorageBackendsCount++;
return 0;
}
virStorageBackend *
virStorageBackendForType(int type)
{
size_t i;
for (i = 0; i < virStorageBackendsCount; i++)
if (virStorageBackends[i]->type == type)
return virStorageBackends[i];
virReportError(VIR_ERR_INTERNAL_ERROR,
_("missing backend for pool type %1$d (%2$s)"),
type, NULLSTR(virStoragePoolTypeToString(type)));
return NULL;
}
virCaps *
virStorageBackendGetCapabilities(void)
{
virCaps *caps;
size_t i;
if (!(caps = virCapabilitiesNew(VIR_ARCH_NONE, false, false)))
return NULL;
for (i = 0; i < virStorageBackendsCount; i++)
virCapabilitiesAddStoragePool(caps, virStorageBackends[i]->type);
return caps;
}
|