Line data Source code
1 1 : GQuark bd_dm_error_quark (void) {
2 1 : return g_quark_from_static_string ("g-bd-dm-error-quark");
3 : }
4 :
5 0 : static gboolean bd_dm_is_tech_avail_stub (BDDMTech tech G_GNUC_UNUSED, guint64 mode G_GNUC_UNUSED, GError **error) {
6 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_dm_is_tech_avail' called, but not implemented!");
7 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
8 : "The function 'bd_dm_is_tech_avail' called, but not implemented!");
9 0 : return FALSE;
10 : }
11 :
12 : static gboolean (*_bd_dm_is_tech_avail) (BDDMTech tech, guint64 mode, GError **error) = bd_dm_is_tech_avail_stub;
13 :
14 : /**
15 : * bd_dm_is_tech_avail:
16 : * @tech: the queried tech
17 : * @mode: a bit mask of queried modes of operation (#BDDMTechMode) for @tech
18 : * @error: (out) (optional): place to store error (details about why the @tech-@mode combination is not available)
19 : *
20 : * Returns: whether the @tech-@mode combination is available -- supported by the
21 : * plugin implementation and having all the runtime dependencies available
22 : */
23 2 : gboolean bd_dm_is_tech_avail (BDDMTech tech, guint64 mode, GError **error) {
24 2 : return _bd_dm_is_tech_avail (tech, mode, error);
25 : }
26 :
27 :
28 0 : static gboolean bd_dm_create_linear_stub (const gchar *map_name G_GNUC_UNUSED, const gchar *device G_GNUC_UNUSED, guint64 length G_GNUC_UNUSED, const gchar *uuid G_GNUC_UNUSED, GError **error) {
29 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_dm_create_linear' called, but not implemented!");
30 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
31 : "The function 'bd_dm_create_linear' called, but not implemented!");
32 0 : return FALSE;
33 : }
34 :
35 : static gboolean (*_bd_dm_create_linear) (const gchar *map_name, const gchar *device, guint64 length, const gchar *uuid, GError **error) = bd_dm_create_linear_stub;
36 :
37 : /**
38 : * bd_dm_create_linear:
39 : * @map_name: name of the map
40 : * @device: device to create map for
41 : * @length: length of the mapping in sectors
42 : * @uuid: (nullable): UUID for the new dev mapper device or %NULL if not specified
43 : * @error: (out) (optional): place to store error (if any)
44 : *
45 : * Returns: whether the new linear mapping @map_name was successfully created
46 : * for the @device or not
47 : *
48 : * Tech category: %BD_DM_TECH_MAP-%BD_DM_TECH_MODE_CREATE_ACTIVATE
49 : */
50 5 : gboolean bd_dm_create_linear (const gchar *map_name, const gchar *device, guint64 length, const gchar *uuid, GError **error) {
51 5 : return _bd_dm_create_linear (map_name, device, length, uuid, error);
52 : }
53 :
54 :
55 0 : static gboolean bd_dm_remove_stub (const gchar *map_name G_GNUC_UNUSED, GError **error) {
56 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_dm_remove' called, but not implemented!");
57 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
58 : "The function 'bd_dm_remove' called, but not implemented!");
59 0 : return FALSE;
60 : }
61 :
62 : static gboolean (*_bd_dm_remove) (const gchar *map_name, GError **error) = bd_dm_remove_stub;
63 :
64 : /**
65 : * bd_dm_remove:
66 : * @map_name: name of the map to remove
67 : * @error: (out) (optional): place to store error (if any)
68 : *
69 : * Returns: whether the @map_name map was successfully removed or not
70 : *
71 : * Tech category: %BD_DM_TECH_MAP-%BD_DM_TECH_MODE_REMOVE_DEACTIVATE
72 : */
73 10 : gboolean bd_dm_remove (const gchar *map_name, GError **error) {
74 10 : return _bd_dm_remove (map_name, error);
75 : }
76 :
77 :
78 0 : static gchar* bd_dm_name_from_node_stub (const gchar *dm_node G_GNUC_UNUSED, GError **error) {
79 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_dm_name_from_node' called, but not implemented!");
80 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
81 : "The function 'bd_dm_name_from_node' called, but not implemented!");
82 0 : return NULL;
83 : }
84 :
85 : static gchar* (*_bd_dm_name_from_node) (const gchar *dm_node, GError **error) = bd_dm_name_from_node_stub;
86 :
87 : /**
88 : * bd_dm_name_from_node:
89 : * @dm_node: name of the DM node (e.g. "dm-0")
90 : * @error: (out) (optional): place to store error (if any)
91 : *
92 : * Returns: map name of the map providing the @dm_node device or %NULL
93 : * (@error) contains the error in such cases
94 : *
95 : * Tech category: %BD_DM_TECH_MAP-%BD_DM_TECH_MODE_QUERY
96 : */
97 1 : gchar* bd_dm_name_from_node (const gchar *dm_node, GError **error) {
98 1 : return _bd_dm_name_from_node (dm_node, error);
99 : }
100 :
101 :
102 0 : static gchar* bd_dm_node_from_name_stub (const gchar *map_name G_GNUC_UNUSED, GError **error) {
103 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_dm_node_from_name' called, but not implemented!");
104 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
105 : "The function 'bd_dm_node_from_name' called, but not implemented!");
106 0 : return NULL;
107 : }
108 :
109 : static gchar* (*_bd_dm_node_from_name) (const gchar *map_name, GError **error) = bd_dm_node_from_name_stub;
110 :
111 : /**
112 : * bd_dm_node_from_name:
113 : * @map_name: name of the queried DM map
114 : * @error: (out) (optional): place to store error (if any)
115 : *
116 : * Returns: DM node name for the @map_name map or %NULL (@error) contains
117 : * the error in such cases
118 : *
119 : * Tech category: %BD_DM_TECH_MAP-%BD_DM_TECH_MODE_QUERY
120 : */
121 1 : gchar* bd_dm_node_from_name (const gchar *map_name, GError **error) {
122 1 : return _bd_dm_node_from_name (map_name, error);
123 : }
124 :
125 :
126 0 : static gchar* bd_dm_get_subsystem_from_name_stub (const gchar *device_name G_GNUC_UNUSED, GError **error) {
127 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_dm_get_subsystem_from_name' called, but not implemented!");
128 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
129 : "The function 'bd_dm_get_subsystem_from_name' called, but not implemented!");
130 0 : return NULL;
131 : }
132 :
133 : static gchar* (*_bd_dm_get_subsystem_from_name) (const gchar *device_name, GError **error) = bd_dm_get_subsystem_from_name_stub;
134 :
135 : /**
136 : * bd_dm_get_subsystem_from_name:
137 : * @device_name: name of the device
138 : * @error: (out) (optional): place to store error (if any)
139 : *
140 : * Returns: subsystem of the given device
141 : *
142 : * Tech category: %BD_DM_TECH_MAP-%BD_DM_TECH_MODE_QUERY
143 : */
144 5 : gchar* bd_dm_get_subsystem_from_name (const gchar *device_name, GError **error) {
145 5 : return _bd_dm_get_subsystem_from_name (device_name, error);
146 : }
147 :
148 :
149 0 : static gboolean bd_dm_map_exists_stub (const gchar *map_name G_GNUC_UNUSED, gboolean live_only G_GNUC_UNUSED, gboolean active_only G_GNUC_UNUSED, GError **error) {
150 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_dm_map_exists' called, but not implemented!");
151 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
152 : "The function 'bd_dm_map_exists' called, but not implemented!");
153 0 : return FALSE;
154 : }
155 :
156 : static gboolean (*_bd_dm_map_exists) (const gchar *map_name, gboolean live_only, gboolean active_only, GError **error) = bd_dm_map_exists_stub;
157 :
158 : /**
159 : * bd_dm_map_exists:
160 : * @map_name: name of the queried map
161 : * @live_only: whether to go through the live maps only or not
162 : * @active_only: whether to ignore suspended maps or not
163 : * @error: (out) (optional): place to store error (if any)
164 : *
165 : * Returns: whether the given @map_name exists (and is live if @live_only is
166 : * %TRUE (and is active if @active_only is %TRUE)).
167 : *
168 : * Tech category: %BD_DM_TECH_MAP-%BD_DM_TECH_MODE_QUERY
169 : */
170 4 : gboolean bd_dm_map_exists (const gchar *map_name, gboolean live_only, gboolean active_only, GError **error) {
171 4 : return _bd_dm_map_exists (map_name, live_only, active_only, error);
172 : }
173 :
174 :
175 17 : static gpointer load_dm_from_plugin(const gchar *so_name) {
176 17 : void *handle = NULL;
177 17 : char *error = NULL;
178 17 : gboolean (*init_fn) (void) = NULL;
179 :
180 17 : handle = dlopen(so_name, RTLD_LAZY);
181 17 : if (!handle) {
182 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load module dm: %s", dlerror());
183 0 : return NULL;
184 : }
185 :
186 17 : dlerror();
187 17 : * (void**) (&init_fn) = dlsym(handle, "bd_dm_init");
188 17 : if ((error = dlerror()) != NULL)
189 0 : bd_utils_log_format (BD_UTILS_LOG_DEBUG, "failed to load the init() function for dm: %s", error);
190 : /* coverity[dead_error_condition] */
191 17 : if (init_fn && !init_fn()) {
192 0 : dlclose(handle);
193 0 : return NULL;
194 : }
195 17 : init_fn = NULL;
196 :
197 17 : dlerror();
198 17 : * (void**) (&_bd_dm_is_tech_avail) = dlsym(handle, "bd_dm_is_tech_avail");
199 17 : if ((error = dlerror()) != NULL)
200 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_dm_is_tech_avail: %s", error);
201 :
202 17 : dlerror();
203 17 : * (void**) (&_bd_dm_create_linear) = dlsym(handle, "bd_dm_create_linear");
204 17 : if ((error = dlerror()) != NULL)
205 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_dm_create_linear: %s", error);
206 :
207 17 : dlerror();
208 17 : * (void**) (&_bd_dm_remove) = dlsym(handle, "bd_dm_remove");
209 17 : if ((error = dlerror()) != NULL)
210 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_dm_remove: %s", error);
211 :
212 17 : dlerror();
213 17 : * (void**) (&_bd_dm_name_from_node) = dlsym(handle, "bd_dm_name_from_node");
214 17 : if ((error = dlerror()) != NULL)
215 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_dm_name_from_node: %s", error);
216 :
217 17 : dlerror();
218 17 : * (void**) (&_bd_dm_node_from_name) = dlsym(handle, "bd_dm_node_from_name");
219 17 : if ((error = dlerror()) != NULL)
220 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_dm_node_from_name: %s", error);
221 :
222 17 : dlerror();
223 17 : * (void**) (&_bd_dm_get_subsystem_from_name) = dlsym(handle, "bd_dm_get_subsystem_from_name");
224 17 : if ((error = dlerror()) != NULL)
225 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_dm_get_subsystem_from_name: %s", error);
226 :
227 17 : dlerror();
228 17 : * (void**) (&_bd_dm_map_exists) = dlsym(handle, "bd_dm_map_exists");
229 17 : if ((error = dlerror()) != NULL)
230 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_dm_map_exists: %s", error);
231 :
232 17 : return handle;
233 : }
234 :
235 17 : static gboolean unload_dm (gpointer handle) {
236 17 : char *error = NULL;
237 17 : gboolean (*close_fn) (void) = NULL;
238 :
239 17 : _bd_dm_is_tech_avail = bd_dm_is_tech_avail_stub;
240 17 : _bd_dm_create_linear = bd_dm_create_linear_stub;
241 17 : _bd_dm_remove = bd_dm_remove_stub;
242 17 : _bd_dm_name_from_node = bd_dm_name_from_node_stub;
243 17 : _bd_dm_node_from_name = bd_dm_node_from_name_stub;
244 17 : _bd_dm_get_subsystem_from_name = bd_dm_get_subsystem_from_name_stub;
245 17 : _bd_dm_map_exists = bd_dm_map_exists_stub;
246 :
247 17 : dlerror();
248 17 : * (void**) (&close_fn) = dlsym(handle, "bd_dm_close");
249 17 : if (((error = dlerror()) != NULL) || !close_fn)
250 0 : bd_utils_log_format (BD_UTILS_LOG_DEBUG, "failed to load the close_plugin() function for dm: %s", error);
251 : /* coverity[dead_error_condition] */
252 17 : if (close_fn) {
253 17 : close_fn();
254 : }
255 :
256 17 : return dlclose(handle) == 0;
257 : }
258 :
|