blob: 3d9cb6d0187463fd6e5936f03885068aa99eb050 [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001From bda7c937ba544182a5cae2a9cf0c173e0ba268c9 Mon Sep 17 00:00:00 2001
2From: Hongxu Jia <hongxu.jia@windriver.com>
3Date: Thu, 27 Jul 2017 09:47:23 +0800
4Subject: [PATCH 3/3] remove dmraid while compiling with --with-dm
5
6Fix the following failure:
7
8...
9Perhaps you should add the directory containing `dmraid.pc'
10to the PKG_CONFIG_PATH environment variable
11No package 'dmraid' found
12...
13
14...
15../../../git/src/plugins/dm.c:24:10: fatal error: dmraid/dmraid.h: No
16such file or directory
17 #include <dmraid/dmraid.h>
18 ^~~~~~~~~~~~~~~~~
19...
20
21Upstream-Status: Inappropriate [oe specific]
22
23Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
24---
25 src/lib/plugin_apis/dm.api | 41 -----
26 src/plugins/Makefile.am | 2 +-
27 src/plugins/dm.c | 318 ------------------------------------
28 src/plugins/dm.h | 5 -
29 src/python/gi/overrides/BlockDev.py | 6 -
30 5 files changed, 1 insertion(+), 371 deletions(-)
31
32diff --git a/src/lib/plugin_apis/dm.api b/src/lib/plugin_apis/dm.api
33index a885bba..ec86b80 100644
34--- a/src/lib/plugin_apis/dm.api
35+++ b/src/lib/plugin_apis/dm.api
36@@ -68,44 +68,3 @@ gchar* bd_dm_node_from_name (const gchar *map_name, GError **error);
37 */
38 gboolean bd_dm_map_exists (const gchar *map_name, gboolean live_only, gboolean active_only, GError **error);
39
40-/**
41- * bd_dm_get_member_raid_sets:
42- * @name: (allow-none): name of the member
43- * @uuid: (allow-none): uuid of the member
44- * @major: major number of the device or -1 if not specified
45- * @minor: minor number of the device or -1 if not specified
46- * @error: (out): variable to store error (if any)
47- *
48- * Returns: (transfer full) (array zero-terminated=1): list of names of the RAID sets related to
49- * the member or %NULL in case of error
50- *
51- * One of @name, @uuid or @major:@minor has to be given.
52- */
53-gchar** bd_dm_get_member_raid_sets (const gchar *name, const gchar *uuid, gint major, gint minor, GError **error);
54-
55-/**
56- * bd_dm_activate_raid_set:
57- * @name: name of the DM RAID set to activate
58- * @error: (out): variable to store error (if any)
59- *
60- * Returns: whether the RAID set @name was successfully activate or not
61- */
62-gboolean bd_dm_activate_raid_set (const gchar *name, GError **error);
63-
64-/**
65- * bd_dm_deactivate_raid_set:
66- * @name: name of the DM RAID set to deactivate
67- * @error: (out): variable to store error (if any)
68- *
69- * Returns: whether the RAID set @name was successfully deactivate or not
70- */
71-gboolean bd_dm_deactivate_raid_set (const gchar *name, GError **error);
72-
73-/**
74- * bd_dm_get_raid_set_type:
75- * @name: name of the DM RAID set to get the type of
76- * @error: (out): variable to store error (if any)
77- *
78- * Returns: string representation of the @name RAID set's type
79- */
80-gchar* bd_dm_get_raid_set_type (const gchar *name, GError **error);
81diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
82index 6c4038f..59dc5e3 100644
83--- a/src/plugins/Makefile.am
84+++ b/src/plugins/Makefile.am
85@@ -76,7 +76,7 @@ endif
86
87 if WITH_DM
88 libbd_dm_la_CFLAGS = $(GLIB_CFLAGS) $(DEVMAPPER_CFLAGS) $(UDEV_CFLAGS) -Wall -Wextra -Werror
89-libbd_dm_la_LIBADD = $(GLIB_LIBS) $(DEVMAPPER_LIBS) $(UDEV_LIBS) -ldmraid ${builddir}/../utils/libbd_utils.la
90+libbd_dm_la_LIBADD = $(GLIB_LIBS) $(DEVMAPPER_LIBS) $(UDEV_LIBS) ${builddir}/../utils/libbd_utils.la
91 libbd_dm_la_LDFLAGS = -L${srcdir}/../utils/ -version-info 2:0:0 -Wl,--no-undefined
92 # Dear author of libdmdraid, VERSION really is not a good name for an enum member!
93 libbd_dm_la_CPPFLAGS = -I${builddir}/../../include/ -UVERSION
94diff --git a/src/plugins/dm.c b/src/plugins/dm.c
95index 9cee742..fd7c7ba 100644
96--- a/src/plugins/dm.c
97+++ b/src/plugins/dm.c
98@@ -21,16 +21,10 @@
99 #include <unistd.h>
100 #include <blockdev/utils.h>
101 #include <libdevmapper.h>
102-#include <dmraid/dmraid.h>
103 #include <libudev.h>
104
105 #include "dm.h"
106
107-/* macros taken from the pyblock/dmraid.h file plus one more*/
108-#define for_each_raidset(_c, _n) list_for_each_entry(_n, LC_RS(_c), list)
109-#define for_each_subset(_rs, _n) list_for_each_entry(_n, &(_rs)->sets, list)
110-#define for_each_device(_rs, _d) list_for_each_entry(_d, &(_rs)->devs, devs)
111-
112 /**
113 * SECTION: dm
114 * @short_description: plugin for basic operations with device mapper
115@@ -286,315 +280,3 @@ gboolean bd_dm_map_exists (const gchar *map_name, gboolean live_only, gboolean a
116 return ret;
117 }
118
119-/**
120- * init_dmraid_stack: (skip)
121- *
122- * Initializes the dmraid stack by creating the library context, discovering
123- * devices, raid sets, etc.
124- */
125-static struct lib_context* init_dmraid_stack (GError **error) {
126- gint rc = 0;
127- gchar *argv[] = {"blockdev.dmraid", NULL};
128- struct lib_context *lc;
129-
130- /* the code for this function was cherry-picked from the pyblock code */
131- /* XXX: do this all just once, store global lc and provide a reinit
132- * function? */
133-
134- /* initialize dmraid library context */
135- lc = libdmraid_init (1, (gchar **)argv);
136-
137- rc = discover_devices (lc, NULL);
138- if (!rc) {
139- g_set_error (error, BD_DM_ERROR, BD_DM_ERROR_RAID_FAIL,
140- "Failed to discover devices");
141- libdmraid_exit (lc);
142- return NULL;
143- }
144- discover_raid_devices (lc, NULL);
145-
146- if (!count_devices (lc, RAID)) {
147- g_set_error (error, BD_DM_ERROR, BD_DM_ERROR_RAID_NO_DEVS,
148- "No RAIDs discovered");
149- libdmraid_exit (lc);
150- return NULL;
151- }
152-
153- argv[0] = NULL;
154- if (!group_set (lc, argv)) {
155- g_set_error (error, BD_DM_ERROR, BD_DM_ERROR_RAID_FAIL,
156- "Failed to group_set");
157- libdmraid_exit (lc);
158- return NULL;
159- }
160-
161- return lc;
162-}
163-
164-/**
165- * raid_dev_matches_spec: (skip)
166- *
167- * Returns: whether the device specified by @sysname matches the spec given by @name,
168- * @uuid, @major and @minor
169- */
170-static gboolean raid_dev_matches_spec (struct raid_dev *raid_dev, const gchar *name, const gchar *uuid, gint major, gint minor) {
171- gchar const *dev_name = NULL;
172- gchar const *dev_uuid;
173- gchar const *major_str;
174- gchar const *minor_str;
175- struct udev *context;
176- struct udev_device *device;
177- gboolean ret = TRUE;
178-
179- /* find the second '/' to get name (the rest of the string) */
180- dev_name = strchr (raid_dev->di->path, '/');
181- if (dev_name && strlen (dev_name) > 1) {
182- dev_name++;
183- dev_name = strchr (dev_name, '/');
184- }
185- if (dev_name && strlen (dev_name) > 1) {
186- dev_name++;
187- }
188- else
189- dev_name = NULL;
190-
191- /* if we don't have the name, we cannot check any match */
192- g_return_val_if_fail (dev_name, FALSE);
193-
194- if (name && strcmp (dev_name, name) != 0) {
195- return FALSE;
196- }
197-
198- context = udev_new ();
199- device = udev_device_new_from_subsystem_sysname (context, "block", dev_name);
200- dev_uuid = udev_device_get_property_value (device, "UUID");
201- major_str = udev_device_get_property_value (device, "MAJOR");
202- minor_str = udev_device_get_property_value (device, "MINOR");
203-
204- if (uuid && (g_strcmp0 (uuid, "") != 0) && (g_strcmp0 (uuid, dev_uuid) != 0))
205- ret = FALSE;
206-
207- if (major >= 0 && (atoi (major_str) != major))
208- ret = FALSE;
209-
210- if (minor >= 0 && (atoi (minor_str) != minor))
211- ret = FALSE;
212-
213- udev_device_unref (device);
214- udev_unref (context);
215-
216- return ret;
217-}
218-
219-/**
220- * find_raid_sets_for_dev: (skip)
221- */
222-static void find_raid_sets_for_dev (const gchar *name, const gchar *uuid, gint major, gint minor, struct lib_context *lc, struct raid_set *rs, GPtrArray *ret_sets) {
223- struct raid_set *subset;
224- struct raid_dev *dev;
225-
226- if (T_GROUP(rs) || !list_empty(&(rs->sets))) {
227- for_each_subset (rs, subset)
228- find_raid_sets_for_dev (name, uuid, major, minor, lc, subset, ret_sets);
229- } else {
230- for_each_device (rs, dev) {
231- if (raid_dev_matches_spec (dev, name, uuid, major, minor))
232- g_ptr_array_add (ret_sets, g_strdup (rs->name));
233- }
234- }
235-}
236-
237-/**
238- * bd_dm_get_member_raid_sets:
239- * @name: (allow-none): name of the member
240- * @uuid: (allow-none): uuid of the member
241- * @major: major number of the device or -1 if not specified
242- * @minor: minor number of the device or -1 if not specified
243- * @error: (out): variable to store error (if any)
244- *
245- * Returns: (transfer full) (array zero-terminated=1): list of names of the RAID sets related to
246- * the member or %NULL in case of error
247- *
248- * One of @name, @uuid or @major:@minor has to be given.
249- */
250-gchar** bd_dm_get_member_raid_sets (const gchar *name, const gchar *uuid, gint major, gint minor, GError **error) {
251- guint64 i = 0;
252- struct lib_context *lc = NULL;
253- struct raid_set *rs = NULL;
254- GPtrArray *ret_sets = g_ptr_array_new ();
255- gchar **ret = NULL;
256-
257- lc = init_dmraid_stack (error);
258- if (!lc)
259- /* error is already populated */
260- return NULL;
261-
262- for_each_raidset (lc, rs) {
263- find_raid_sets_for_dev (name, uuid, major, minor, lc, rs, ret_sets);
264- }
265-
266- /* now create the return value -- NULL-terminated array of strings */
267- ret = g_new0 (gchar*, ret_sets->len + 1);
268- for (i=0; i < ret_sets->len; i++)
269- ret[i] = (gchar*) g_ptr_array_index (ret_sets, i);
270- ret[i] = NULL;
271-
272- g_ptr_array_free (ret_sets, FALSE);
273-
274- libdmraid_exit (lc);
275- return ret;
276-}
277-
278-/**
279- * find_in_raid_sets: (skip)
280- *
281- * Runs @eval_fn with @data on each set (traversing recursively) and returns the
282- * first RAID set that @eval_fn returns. Thus the @eval_fn should return %NULL
283- * on all RAID sets that don't fulfill the search criteria.
284- */
285-static struct raid_set* find_in_raid_sets (struct raid_set *rs, RSEvalFunc eval_fn, gpointer data) {
286- struct raid_set *subset = NULL;
287- struct raid_set *ret = NULL;
288-
289- ret = eval_fn (rs, data);
290- if (ret)
291- return ret;
292-
293- if (T_GROUP(rs) || !list_empty(&(rs->sets))) {
294- for_each_subset (rs, subset) {
295- ret = find_in_raid_sets (subset, eval_fn, data);
296- if (ret)
297- return ret;
298- }
299- }
300-
301- return ret;
302-}
303-
304-static struct raid_set* rs_matches_name (struct raid_set *rs, gpointer *name_data) {
305- gchar *name = (gchar*) name_data;
306-
307- if (g_strcmp0 (rs->name, name) == 0)
308- return rs;
309- else
310- return NULL;
311-}
312-
313-static gboolean change_set_by_name (const gchar *name, enum activate_type action, GError **error) {
314- gint rc = 0;
315- struct lib_context *lc;
316- struct raid_set *iter_rs;
317- struct raid_set *match_rs = NULL;
318-
319- lc = init_dmraid_stack (error);
320- if (!lc)
321- /* error is already populated */
322- return FALSE;
323-
324- for_each_raidset (lc, iter_rs) {
325- match_rs = find_in_raid_sets (iter_rs, (RSEvalFunc)rs_matches_name, (gchar *)name);
326- if (match_rs)
327- break;
328- }
329-
330- if (!match_rs) {
331- g_set_error (error, BD_DM_ERROR, BD_DM_ERROR_RAID_NO_EXIST,
332- "RAID set %s doesn't exist", name);
333- libdmraid_exit (lc);
334- return FALSE;
335- }
336-
337- rc = change_set (lc, action, match_rs);
338- if (!rc) {
339- g_set_error (error, BD_DM_ERROR, BD_DM_ERROR_RAID_FAIL,
340- "Failed to activate the RAID set '%s'", name);
341- libdmraid_exit (lc);
342- return FALSE;
343- }
344-
345- libdmraid_exit (lc);
346- return TRUE;
347-}
348-
349-/**
350- * bd_dm_activate_raid_set:
351- * @name: name of the DM RAID set to activate
352- * @error: (out): variable to store error (if any)
353- *
354- * Returns: whether the RAID set @name was successfully activate or not
355- */
356-gboolean bd_dm_activate_raid_set (const gchar *name, GError **error) {
357- guint64 progress_id = 0;
358- gchar *msg = NULL;
359- gboolean ret = FALSE;
360-
361- msg = g_strdup_printf ("Activating DM RAID set '%s'", name);
362- progress_id = bd_utils_report_started (msg);
363- g_free (msg);
364- ret = change_set_by_name (name, A_ACTIVATE, error);
365- bd_utils_report_finished (progress_id, "Completed");
366- return ret;
367-}
368-
369-/**
370- * bd_dm_deactivate_raid_set:
371- * @name: name of the DM RAID set to deactivate
372- * @error: (out): variable to store error (if any)
373- *
374- * Returns: whether the RAID set @name was successfully deactivate or not
375- */
376-gboolean bd_dm_deactivate_raid_set (const gchar *name, GError **error) {
377- guint64 progress_id = 0;
378- gchar *msg = NULL;
379- gboolean ret = FALSE;
380-
381- msg = g_strdup_printf ("Deactivating DM RAID set '%s'", name);
382- progress_id = bd_utils_report_started (msg);
383- g_free (msg);
384- ret = change_set_by_name (name, A_DEACTIVATE, error);
385- bd_utils_report_finished (progress_id, "Completed");
386- return ret;
387-}
388-
389-/**
390- * bd_dm_get_raid_set_type:
391- * @name: name of the DM RAID set to get the type of
392- * @error: (out): variable to store error (if any)
393- *
394- * Returns: string representation of the @name RAID set's type
395- */
396-gchar* bd_dm_get_raid_set_type (const gchar *name, GError **error) {
397- struct lib_context *lc;
398- struct raid_set *iter_rs;
399- struct raid_set *match_rs = NULL;
400- const gchar *type = NULL;
401-
402- lc = init_dmraid_stack (error);
403- if (!lc)
404- /* error is already populated */
405- return NULL;
406-
407- for_each_raidset (lc, iter_rs) {
408- match_rs = find_in_raid_sets (iter_rs, (RSEvalFunc)rs_matches_name, (gchar *)name);
409- if (match_rs)
410- break;
411- }
412-
413- if (!match_rs) {
414- g_set_error (error, BD_DM_ERROR, BD_DM_ERROR_RAID_NO_EXIST,
415- "RAID set %s doesn't exist", name);
416- libdmraid_exit (lc);
417- return NULL;
418- }
419-
420- type = get_set_type (lc, match_rs);
421- if (!type) {
422- g_set_error (error, BD_DM_ERROR, BD_DM_ERROR_RAID_FAIL,
423- "Failed to get RAID set's type");
424- libdmraid_exit (lc);
425- return NULL;
426- }
427-
428- libdmraid_exit (lc);
429- return g_strdup (type);
430-}
431diff --git a/src/plugins/dm.h b/src/plugins/dm.h
432index 859fb80..80acd49 100644
433--- a/src/plugins/dm.h
434+++ b/src/plugins/dm.h
435@@ -1,5 +1,4 @@
436 #include <glib.h>
437-#include <dmraid/dmraid.h>
438
439 #ifndef BD_DM
440 #define BD_DM
441@@ -35,9 +34,5 @@ gboolean bd_dm_remove (const gchar *map_name, GError **error);
442 gchar* bd_dm_name_from_node (const gchar *dm_node, GError **error);
443 gchar* bd_dm_node_from_name (const gchar *map_name, GError **error);
444 gboolean bd_dm_map_exists (const gchar *map_name, gboolean live_only, gboolean active_only, GError **error);
445-gchar** bd_dm_get_member_raid_sets (const gchar *name, const gchar *uuid, gint major, gint minor, GError **error);
446-gboolean bd_dm_activate_raid_set (const gchar *name, GError **error);
447-gboolean bd_dm_deactivate_raid_set (const gchar *name, GError **error);
448-gchar* bd_dm_get_raid_set_type (const gchar *name, GError **error);
449
450 #endif /* BD_DM */
451diff --git a/src/python/gi/overrides/BlockDev.py b/src/python/gi/overrides/BlockDev.py
452index fb3ffb4..eed0a38 100644
453--- a/src/python/gi/overrides/BlockDev.py
454+++ b/src/python/gi/overrides/BlockDev.py
455@@ -233,12 +233,6 @@ def dm_create_linear(map_name, device, length, uuid=None):
456 return _dm_create_linear(map_name, device, length, uuid)
457 __all__.append("dm_create_linear")
458
459-_dm_get_member_raid_sets = BlockDev.dm_get_member_raid_sets
460-@override(BlockDev.dm_get_member_raid_sets)
461-def dm_get_member_raid_sets(name=None, uuid=None, major=-1, minor=-1):
462- return _dm_get_member_raid_sets(name, uuid, major, minor)
463-__all__.append("dm_get_member_raid_sets")
464-
465
466 _loop_setup = BlockDev.loop_setup
467 @override(BlockDev.loop_setup)
468--
4691.8.3.1
470