|
|
a19a3f |
From 5bcb348b17935328a2344d811ddba9847ab3c846 Mon Sep 17 00:00:00 2001
|
|
|
a19a3f |
From: Vojtech Trefny <vtrefny@redhat.com>
|
|
|
a19a3f |
Date: Mon, 16 Oct 2017 12:33:14 +0200
|
|
|
a19a3f |
Subject: [PATCH 1/5] Move some useful mdraid functions to a helper file
|
|
|
a19a3f |
|
|
|
a19a3f |
Related: rhbz#1400056
|
|
|
a19a3f |
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
|
|
|
a19a3f |
---
|
|
|
a19a3f |
src/Makefile.am | 1 +
|
|
|
a19a3f |
src/udiskslinuxmdraid.c | 83 ++------------------------------
|
|
|
a19a3f |
src/udiskslinuxmdraidhelpers.c | 104 +++++++++++++++++++++++++++++++++++++++++
|
|
|
a19a3f |
src/udiskslinuxmdraidhelpers.h | 41 ++++++++++++++++
|
|
|
a19a3f |
4 files changed, 149 insertions(+), 80 deletions(-)
|
|
|
a19a3f |
create mode 100644 src/udiskslinuxmdraidhelpers.c
|
|
|
a19a3f |
create mode 100644 src/udiskslinuxmdraidhelpers.h
|
|
|
a19a3f |
|
|
|
a19a3f |
diff --git a/src/Makefile.am b/src/Makefile.am
|
|
|
a19a3f |
index 396ab4e..9cca8cd 100644
|
|
|
a19a3f |
--- a/src/Makefile.am
|
|
|
a19a3f |
+++ b/src/Makefile.am
|
|
|
a19a3f |
@@ -66,6 +66,7 @@ libudisks_daemon_la_SOURCES = \
|
|
|
a19a3f |
udiskslinuxdrive.h udiskslinuxdrive.c \
|
|
|
a19a3f |
udiskslinuxdriveata.h udiskslinuxdriveata.c \
|
|
|
a19a3f |
udiskslinuxmdraidobject.h udiskslinuxmdraidobject.c \
|
|
|
a19a3f |
+ udiskslinuxmdraidhelpers.h udiskslinuxmdraidhelpers.c \
|
|
|
a19a3f |
udiskslinuxmdraid.h udiskslinuxmdraid.c \
|
|
|
a19a3f |
udiskslinuxmanager.h udiskslinuxmanager.c \
|
|
|
a19a3f |
udiskslinuxfsinfo.h udiskslinuxfsinfo.c \
|
|
|
a19a3f |
diff --git a/src/udiskslinuxmdraid.c b/src/udiskslinuxmdraid.c
|
|
|
a19a3f |
index 9bf6ae9..2dcf0ff 100644
|
|
|
a19a3f |
--- a/src/udiskslinuxmdraid.c
|
|
|
a19a3f |
+++ b/src/udiskslinuxmdraid.c
|
|
|
a19a3f |
@@ -38,6 +38,7 @@
|
|
|
a19a3f |
#include "udiskslinuxprovider.h"
|
|
|
a19a3f |
#include "udiskslinuxmdraidobject.h"
|
|
|
a19a3f |
#include "udiskslinuxmdraid.h"
|
|
|
a19a3f |
+#include "udiskslinuxmdraidhelpers.h"
|
|
|
a19a3f |
#include "udiskslinuxblockobject.h"
|
|
|
a19a3f |
#include "udisksdaemon.h"
|
|
|
a19a3f |
#include "udisksstate.h"
|
|
|
a19a3f |
@@ -128,68 +129,6 @@ udisks_linux_mdraid_new (void)
|
|
|
a19a3f |
|
|
|
a19a3f |
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
a19a3f |
|
|
|
a19a3f |
-static gchar *
|
|
|
a19a3f |
-read_sysfs_attr (GUdevDevice *device,
|
|
|
a19a3f |
- const gchar *attr)
|
|
|
a19a3f |
-{
|
|
|
a19a3f |
- gchar *ret = NULL;
|
|
|
a19a3f |
- gchar *path = NULL;
|
|
|
a19a3f |
- GError *error = NULL;
|
|
|
a19a3f |
-
|
|
|
a19a3f |
- g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
|
|
|
a19a3f |
-
|
|
|
a19a3f |
- path = g_strdup_printf ("%s/%s", g_udev_device_get_sysfs_path (device), attr);
|
|
|
a19a3f |
- if (!g_file_get_contents (path, &ret, NULL /* size */, &error))
|
|
|
a19a3f |
- {
|
|
|
a19a3f |
- udisks_warning ("Error reading sysfs attr `%s': %s (%s, %d)",
|
|
|
a19a3f |
- path, error->message, g_quark_to_string (error->domain), error->code);
|
|
|
a19a3f |
- g_clear_error (&error);
|
|
|
a19a3f |
- goto out;
|
|
|
a19a3f |
- }
|
|
|
a19a3f |
-
|
|
|
a19a3f |
- out:
|
|
|
a19a3f |
- g_free (path);
|
|
|
a19a3f |
- return ret;
|
|
|
a19a3f |
-}
|
|
|
a19a3f |
-
|
|
|
a19a3f |
-static gint
|
|
|
a19a3f |
-read_sysfs_attr_as_int (GUdevDevice *device,
|
|
|
a19a3f |
- const gchar *attr)
|
|
|
a19a3f |
-{
|
|
|
a19a3f |
- gint ret = 0;
|
|
|
a19a3f |
- gchar *str = NULL;
|
|
|
a19a3f |
-
|
|
|
a19a3f |
- str = read_sysfs_attr (device, attr);
|
|
|
a19a3f |
- if (str == NULL)
|
|
|
a19a3f |
- goto out;
|
|
|
a19a3f |
-
|
|
|
a19a3f |
- ret = atoi (str);
|
|
|
a19a3f |
- g_free (str);
|
|
|
a19a3f |
-
|
|
|
a19a3f |
- out:
|
|
|
a19a3f |
- return ret;
|
|
|
a19a3f |
-}
|
|
|
a19a3f |
-
|
|
|
a19a3f |
-static guint64
|
|
|
a19a3f |
-read_sysfs_attr_as_uint64 (GUdevDevice *device,
|
|
|
a19a3f |
- const gchar *attr)
|
|
|
a19a3f |
-{
|
|
|
a19a3f |
- guint64 ret = 0;
|
|
|
a19a3f |
- gchar *str = NULL;
|
|
|
a19a3f |
-
|
|
|
a19a3f |
- str = read_sysfs_attr (device, attr);
|
|
|
a19a3f |
- if (str == NULL)
|
|
|
a19a3f |
- goto out;
|
|
|
a19a3f |
-
|
|
|
a19a3f |
- ret = atoll (str);
|
|
|
a19a3f |
- g_free (str);
|
|
|
a19a3f |
-
|
|
|
a19a3f |
- out:
|
|
|
a19a3f |
- return ret;
|
|
|
a19a3f |
-}
|
|
|
a19a3f |
-
|
|
|
a19a3f |
-/* ---------------------------------------------------------------------------------------------------- */
|
|
|
a19a3f |
-
|
|
|
a19a3f |
static gboolean
|
|
|
a19a3f |
on_polling_timout (gpointer user_data)
|
|
|
a19a3f |
{
|
|
|
a19a3f |
@@ -306,8 +245,6 @@ udisks_linux_mdraid_update (UDisksLinuxMDRaid *mdraid,
|
|
|
a19a3f |
guint64 sync_remaining_time = 0;
|
|
|
a19a3f |
GVariantBuilder builder;
|
|
|
a19a3f |
UDisksDaemon *daemon = NULL;
|
|
|
a19a3f |
- gboolean has_redundancy = FALSE;
|
|
|
a19a3f |
- gboolean has_stripes = FALSE;
|
|
|
a19a3f |
UDisksBaseJob *job = NULL;
|
|
|
a19a3f |
|
|
|
a19a3f |
daemon = udisks_linux_mdraid_object_get_daemon (object);
|
|
|
a19a3f |
@@ -377,23 +314,9 @@ udisks_linux_mdraid_update (UDisksLinuxMDRaid *mdraid,
|
|
|
a19a3f |
|
|
|
a19a3f |
udisks_mdraid_set_running (iface, raid_device != NULL);
|
|
|
a19a3f |
|
|
|
a19a3f |
- if (g_strcmp0 (level, "raid1") == 0 ||
|
|
|
a19a3f |
- g_strcmp0 (level, "raid4") == 0 ||
|
|
|
a19a3f |
- g_strcmp0 (level, "raid5") == 0 ||
|
|
|
a19a3f |
- g_strcmp0 (level, "raid6") == 0 ||
|
|
|
a19a3f |
- g_strcmp0 (level, "raid10") == 0)
|
|
|
a19a3f |
- has_redundancy = TRUE;
|
|
|
a19a3f |
-
|
|
|
a19a3f |
- if (g_strcmp0 (level, "raid0") == 0 ||
|
|
|
a19a3f |
- g_strcmp0 (level, "raid4") == 0 ||
|
|
|
a19a3f |
- g_strcmp0 (level, "raid5") == 0 ||
|
|
|
a19a3f |
- g_strcmp0 (level, "raid6") == 0 ||
|
|
|
a19a3f |
- g_strcmp0 (level, "raid10") == 0)
|
|
|
a19a3f |
- has_stripes = TRUE;
|
|
|
a19a3f |
-
|
|
|
a19a3f |
if (raid_device != NULL)
|
|
|
a19a3f |
{
|
|
|
a19a3f |
- if (has_redundancy)
|
|
|
a19a3f |
+ if (mdraid_has_redundancy (level))
|
|
|
a19a3f |
{
|
|
|
a19a3f |
/* Can't use GUdevDevice methods as they cache the result and these variables vary */
|
|
|
a19a3f |
degraded = read_sysfs_attr_as_int (raid_device->udev_device, "md/degraded");
|
|
|
a19a3f |
@@ -408,7 +331,7 @@ udisks_linux_mdraid_update (UDisksLinuxMDRaid *mdraid,
|
|
|
a19a3f |
g_strstrip (bitmap_location);
|
|
|
a19a3f |
}
|
|
|
a19a3f |
|
|
|
a19a3f |
- if (has_stripes)
|
|
|
a19a3f |
+ if (mdraid_has_stripes (level))
|
|
|
a19a3f |
{
|
|
|
a19a3f |
chunk_size = read_sysfs_attr_as_uint64 (raid_device->udev_device, "md/chunk_size");
|
|
|
a19a3f |
}
|
|
|
a19a3f |
diff --git a/src/udiskslinuxmdraidhelpers.c b/src/udiskslinuxmdraidhelpers.c
|
|
|
a19a3f |
new file mode 100644
|
|
|
a19a3f |
index 0000000..dafdddf
|
|
|
a19a3f |
--- /dev/null
|
|
|
a19a3f |
+++ b/src/udiskslinuxmdraidhelpers.c
|
|
|
a19a3f |
@@ -0,0 +1,104 @@
|
|
|
a19a3f |
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
|
a19a3f |
+ *
|
|
|
a19a3f |
+ * Copyright (C) 2017 Red Hat, Inc.
|
|
|
a19a3f |
+ *
|
|
|
a19a3f |
+ * This program is free software; you can redistribute it and/or modify
|
|
|
a19a3f |
+ * it under the terms of the GNU General Public License as published by
|
|
|
a19a3f |
+ * the Free Software Foundation; either version 2 of the License, or
|
|
|
a19a3f |
+ * (at your option) any later version.
|
|
|
a19a3f |
+ *
|
|
|
a19a3f |
+ * This program is distributed in the hope that it will be useful,
|
|
|
a19a3f |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
a19a3f |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
a19a3f |
+ * GNU General Public License for more details.
|
|
|
a19a3f |
+ *
|
|
|
a19a3f |
+ * You should have received a copy of the GNU General Public License
|
|
|
a19a3f |
+ * along with this program; if not, write to the Free Software
|
|
|
a19a3f |
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
a19a3f |
+ *
|
|
|
a19a3f |
+ * Author: Vojtech Trefny <vtrefny@redhat.com>
|
|
|
a19a3f |
+ *
|
|
|
a19a3f |
+ */
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+#include <glib.h>
|
|
|
a19a3f |
+#include <gudev/gudev.h>
|
|
|
a19a3f |
+#include <stdlib.h>
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+#include "udiskslinuxmdraidhelpers.h"
|
|
|
a19a3f |
+#include "udiskslogging.h"
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+gboolean
|
|
|
a19a3f |
+mdraid_has_redundancy (const gchar *raid_level)
|
|
|
a19a3f |
+{
|
|
|
a19a3f |
+ return raid_level != NULL &&
|
|
|
a19a3f |
+ g_str_has_prefix (raid_level, "raid") &&
|
|
|
a19a3f |
+ g_strcmp0 (raid_level, "raid0") != 0;
|
|
|
a19a3f |
+}
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+gboolean
|
|
|
a19a3f |
+mdraid_has_stripes (const gchar *raid_level)
|
|
|
a19a3f |
+{
|
|
|
a19a3f |
+ return raid_level != NULL &&
|
|
|
a19a3f |
+ g_str_has_prefix (raid_level, "raid") &&
|
|
|
a19a3f |
+ g_strcmp0 (raid_level, "raid1") != 0;
|
|
|
a19a3f |
+}
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+gchar *
|
|
|
a19a3f |
+read_sysfs_attr (GUdevDevice *device,
|
|
|
a19a3f |
+ const gchar *attr)
|
|
|
a19a3f |
+{
|
|
|
a19a3f |
+ gchar *ret = NULL;
|
|
|
a19a3f |
+ gchar *path = NULL;
|
|
|
a19a3f |
+ GError *error = NULL;
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+ g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+ path = g_strdup_printf ("%s/%s", g_udev_device_get_sysfs_path (device), attr);
|
|
|
a19a3f |
+ if (!g_file_get_contents (path, &ret, NULL /* size */, &error))
|
|
|
a19a3f |
+ {
|
|
|
a19a3f |
+ udisks_warning ("Error reading sysfs attr `%s': %s (%s, %d)",
|
|
|
a19a3f |
+ path, error->message, g_quark_to_string (error->domain), error->code);
|
|
|
a19a3f |
+ g_clear_error (&error);
|
|
|
a19a3f |
+ goto out;
|
|
|
a19a3f |
+ }
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+ out:
|
|
|
a19a3f |
+ g_free (path);
|
|
|
a19a3f |
+ return ret;
|
|
|
a19a3f |
+}
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+gint
|
|
|
a19a3f |
+read_sysfs_attr_as_int (GUdevDevice *device,
|
|
|
a19a3f |
+ const gchar *attr)
|
|
|
a19a3f |
+{
|
|
|
a19a3f |
+ gint ret = 0;
|
|
|
a19a3f |
+ gchar *str = NULL;
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+ str = read_sysfs_attr (device, attr);
|
|
|
a19a3f |
+ if (str == NULL)
|
|
|
a19a3f |
+ goto out;
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+ ret = atoi (str);
|
|
|
a19a3f |
+ g_free (str);
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+ out:
|
|
|
a19a3f |
+ return ret;
|
|
|
a19a3f |
+}
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+guint64
|
|
|
a19a3f |
+read_sysfs_attr_as_uint64 (GUdevDevice *device,
|
|
|
a19a3f |
+ const gchar *attr)
|
|
|
a19a3f |
+{
|
|
|
a19a3f |
+ guint64 ret = 0;
|
|
|
a19a3f |
+ gchar *str = NULL;
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+ str = read_sysfs_attr (device, attr);
|
|
|
a19a3f |
+ if (str == NULL)
|
|
|
a19a3f |
+ goto out;
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+ ret = atoll (str);
|
|
|
a19a3f |
+ g_free (str);
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+ out:
|
|
|
a19a3f |
+ return ret;
|
|
|
a19a3f |
+}
|
|
|
a19a3f |
diff --git a/src/udiskslinuxmdraidhelpers.h b/src/udiskslinuxmdraidhelpers.h
|
|
|
a19a3f |
new file mode 100644
|
|
|
a19a3f |
index 0000000..6d2b714
|
|
|
a19a3f |
--- /dev/null
|
|
|
a19a3f |
+++ b/src/udiskslinuxmdraidhelpers.h
|
|
|
a19a3f |
@@ -0,0 +1,41 @@
|
|
|
a19a3f |
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
|
a19a3f |
+ *
|
|
|
a19a3f |
+ * Copyright (C) 2017 Red Hat, Inc.
|
|
|
a19a3f |
+ *
|
|
|
a19a3f |
+ * This program is free software; you can redistribute it and/or modify
|
|
|
a19a3f |
+ * it under the terms of the GNU General Public License as published by
|
|
|
a19a3f |
+ * the Free Software Foundation; either version 2 of the License, or
|
|
|
a19a3f |
+ * (at your option) any later version.
|
|
|
a19a3f |
+ *
|
|
|
a19a3f |
+ * This program is distributed in the hope that it will be useful,
|
|
|
a19a3f |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
a19a3f |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
a19a3f |
+ * GNU General Public License for more details.
|
|
|
a19a3f |
+ *
|
|
|
a19a3f |
+ * You should have received a copy of the GNU General Public License
|
|
|
a19a3f |
+ * along with this program; if not, write to the Free Software
|
|
|
a19a3f |
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
a19a3f |
+ *
|
|
|
a19a3f |
+ * Author: Vojtech Trefny <vtrefny@redhat.com>
|
|
|
a19a3f |
+ *
|
|
|
a19a3f |
+ */
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+#ifndef __UDISKS_LINUX_MDRAID_HELPERS_H__
|
|
|
a19a3f |
+#define __UDISKS_LINUX_MDRAID_HEPLERS_H__
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+#include <glib.h>
|
|
|
a19a3f |
+#include <gudev/gudev.h>
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+G_BEGIN_DECLS
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+gboolean mdraid_has_redundancy (const gchar *raid_level);
|
|
|
a19a3f |
+gboolean mdraid_has_stripes (const gchar *raid_level);
|
|
|
a19a3f |
+gchar *read_sysfs_attr (GUdevDevice *device, const gchar *attr);
|
|
|
a19a3f |
+gint read_sysfs_attr_as_int (GUdevDevice *device, const gchar *attr);
|
|
|
a19a3f |
+guint64 read_sysfs_attr_as_uint64 (GUdevDevice *device, const gchar *attr);
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+G_END_DECLS
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+#endif /* __UDISKS_LINUX_MDRAID_HEPLERS_H__ */
|
|
|
a19a3f |
--
|
|
|
a19a3f |
2.9.5
|
|
|
a19a3f |
|
|
|
a19a3f |
From 61ff342139f21663958bcc2972a3efa37cf7bc83 Mon Sep 17 00:00:00 2001
|
|
|
a19a3f |
From: Vojtech Trefny <vtrefny@redhat.com>
|
|
|
a19a3f |
Date: Mon, 16 Oct 2017 12:41:22 +0200
|
|
|
a19a3f |
Subject: [PATCH 2/5] Remove leading/trailing white space in 'read_sysfs_attr'
|
|
|
a19a3f |
|
|
|
a19a3f |
So we don't have to call 'g_strstrip' after using it.
|
|
|
a19a3f |
|
|
|
a19a3f |
Related: rhbz#1400056
|
|
|
a19a3f |
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
|
|
|
a19a3f |
---
|
|
|
a19a3f |
src/udiskslinuxmdraid.c | 8 --------
|
|
|
a19a3f |
src/udiskslinuxmdraidhelpers.c | 4 ++++
|
|
|
a19a3f |
2 files changed, 4 insertions(+), 8 deletions(-)
|
|
|
a19a3f |
|
|
|
a19a3f |
diff --git a/src/udiskslinuxmdraid.c b/src/udiskslinuxmdraid.c
|
|
|
a19a3f |
index 2dcf0ff..22b4ee4 100644
|
|
|
a19a3f |
--- a/src/udiskslinuxmdraid.c
|
|
|
a19a3f |
+++ b/src/udiskslinuxmdraid.c
|
|
|
a19a3f |
@@ -321,14 +321,8 @@ udisks_linux_mdraid_update (UDisksLinuxMDRaid *mdraid,
|
|
|
a19a3f |
/* Can't use GUdevDevice methods as they cache the result and these variables vary */
|
|
|
a19a3f |
degraded = read_sysfs_attr_as_int (raid_device->udev_device, "md/degraded");
|
|
|
a19a3f |
sync_action = read_sysfs_attr (raid_device->udev_device, "md/sync_action");
|
|
|
a19a3f |
- if (sync_action != NULL)
|
|
|
a19a3f |
- g_strstrip (sync_action);
|
|
|
a19a3f |
sync_completed = read_sysfs_attr (raid_device->udev_device, "md/sync_completed");
|
|
|
a19a3f |
- if (sync_completed != NULL)
|
|
|
a19a3f |
- g_strstrip (sync_completed);
|
|
|
a19a3f |
bitmap_location = read_sysfs_attr (raid_device->udev_device, "md/bitmap/location");
|
|
|
a19a3f |
- if (bitmap_location != NULL)
|
|
|
a19a3f |
- g_strstrip (bitmap_location);
|
|
|
a19a3f |
}
|
|
|
a19a3f |
|
|
|
a19a3f |
if (mdraid_has_stripes (level))
|
|
|
a19a3f |
@@ -472,7 +466,6 @@ udisks_linux_mdraid_update (UDisksLinuxMDRaid *mdraid,
|
|
|
a19a3f |
member_state = read_sysfs_attr (raid_device->udev_device, buf);
|
|
|
a19a3f |
if (member_state != NULL)
|
|
|
a19a3f |
{
|
|
|
a19a3f |
- g_strstrip (member_state);
|
|
|
a19a3f |
member_state_elements = g_strsplit (member_state, ",", 0);
|
|
|
a19a3f |
}
|
|
|
a19a3f |
else
|
|
|
a19a3f |
@@ -486,7 +479,6 @@ udisks_linux_mdraid_update (UDisksLinuxMDRaid *mdraid,
|
|
|
a19a3f |
member_slot = read_sysfs_attr (raid_device->udev_device, buf);
|
|
|
a19a3f |
if (member_slot != NULL)
|
|
|
a19a3f |
{
|
|
|
a19a3f |
- g_strstrip (member_slot);
|
|
|
a19a3f |
if (g_strcmp0 (member_slot, "none") != 0)
|
|
|
a19a3f |
member_slot_as_int = atoi (member_slot);
|
|
|
a19a3f |
}
|
|
|
a19a3f |
diff --git a/src/udiskslinuxmdraidhelpers.c b/src/udiskslinuxmdraidhelpers.c
|
|
|
a19a3f |
index dafdddf..297b1fa 100644
|
|
|
a19a3f |
--- a/src/udiskslinuxmdraidhelpers.c
|
|
|
a19a3f |
+++ b/src/udiskslinuxmdraidhelpers.c
|
|
|
a19a3f |
@@ -62,6 +62,10 @@ read_sysfs_attr (GUdevDevice *device,
|
|
|
a19a3f |
goto out;
|
|
|
a19a3f |
}
|
|
|
a19a3f |
|
|
|
a19a3f |
+ /* remove newline from the attribute */
|
|
|
a19a3f |
+ if (ret != NULL)
|
|
|
a19a3f |
+ g_strstrip (ret);
|
|
|
a19a3f |
+
|
|
|
a19a3f |
out:
|
|
|
a19a3f |
g_free (path);
|
|
|
a19a3f |
return ret;
|
|
|
a19a3f |
--
|
|
|
a19a3f |
2.9.5
|
|
|
a19a3f |
|
|
|
a19a3f |
From 756571efc1b0d602bca2dd4ff761dca686dc08bd Mon Sep 17 00:00:00 2001
|
|
|
a19a3f |
From: Vojtech Trefny <vtrefny@redhat.com>
|
|
|
a19a3f |
Date: Mon, 16 Oct 2017 12:42:42 +0200
|
|
|
a19a3f |
Subject: [PATCH 3/5] Do not try to create file watchers for RAIDs without
|
|
|
a19a3f |
redundancy
|
|
|
a19a3f |
|
|
|
a19a3f |
We are trying to watch 'md/degraded' and 'md/sync_action' sysfs
|
|
|
a19a3f |
files for all RAIDs but these files exist only for RAIDs with
|
|
|
a19a3f |
redundancy -- we shouldn't do this for raid0, containers and linear
|
|
|
a19a3f |
RAIDs.
|
|
|
a19a3f |
|
|
|
a19a3f |
Resolves: rhbz#1400056
|
|
|
a19a3f |
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
|
|
|
a19a3f |
---
|
|
|
a19a3f |
src/udiskslinuxmdraidobject.c | 19 +++++++++++++++++++
|
|
|
a19a3f |
1 file changed, 19 insertions(+)
|
|
|
a19a3f |
|
|
|
a19a3f |
diff --git a/src/udiskslinuxmdraidobject.c b/src/udiskslinuxmdraidobject.c
|
|
|
a19a3f |
index 493145e..1d2f07a 100644
|
|
|
a19a3f |
--- a/src/udiskslinuxmdraidobject.c
|
|
|
a19a3f |
+++ b/src/udiskslinuxmdraidobject.c
|
|
|
a19a3f |
@@ -30,6 +30,7 @@
|
|
|
a19a3f |
#include "udisksdaemonutil.h"
|
|
|
a19a3f |
#include "udiskslinuxprovider.h"
|
|
|
a19a3f |
#include "udiskslinuxmdraidobject.h"
|
|
|
a19a3f |
+#include "udiskslinuxmdraidhelpers.h"
|
|
|
a19a3f |
#include "udiskslinuxmdraid.h"
|
|
|
a19a3f |
#include "udiskslinuxblockobject.h"
|
|
|
a19a3f |
#include "udiskslinuxdevice.h"
|
|
|
a19a3f |
@@ -552,9 +553,18 @@ static void
|
|
|
a19a3f |
raid_device_added (UDisksLinuxMDRaidObject *object,
|
|
|
a19a3f |
UDisksLinuxDevice *device)
|
|
|
a19a3f |
{
|
|
|
a19a3f |
+ gchar *level = NULL;
|
|
|
a19a3f |
+
|
|
|
a19a3f |
g_assert (object->sync_action_source == NULL);
|
|
|
a19a3f |
g_assert (object->degraded_source == NULL);
|
|
|
a19a3f |
|
|
|
a19a3f |
+ if (!UDISKS_IS_LINUX_DEVICE (device))
|
|
|
a19a3f |
+ goto out;
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+ level = read_sysfs_attr (device->udev_device, "md/level");
|
|
|
a19a3f |
+ if (level == NULL || !mdraid_has_redundancy (level))
|
|
|
a19a3f |
+ goto out;
|
|
|
a19a3f |
+
|
|
|
a19a3f |
/* udisks_debug ("start watching %s", g_udev_device_get_sysfs_path (device->udev_device)); */
|
|
|
a19a3f |
object->sync_action_source = watch_attr (device,
|
|
|
a19a3f |
"md/sync_action",
|
|
|
a19a3f |
@@ -564,6 +574,9 @@ raid_device_added (UDisksLinuxMDRaidObject *object,
|
|
|
a19a3f |
"md/degraded",
|
|
|
a19a3f |
(GSourceFunc) attr_changed,
|
|
|
a19a3f |
object);
|
|
|
a19a3f |
+
|
|
|
a19a3f |
+ out:
|
|
|
a19a3f |
+ g_free (level);
|
|
|
a19a3f |
}
|
|
|
a19a3f |
|
|
|
a19a3f |
static void
|
|
|
a19a3f |
@@ -684,6 +697,12 @@ udisks_linux_mdraid_object_uevent (UDisksLinuxMDRaidObject *object,
|
|
|
a19a3f |
object->raid_device = g_object_ref (device);
|
|
|
a19a3f |
raid_device_added (object, object->raid_device);
|
|
|
a19a3f |
}
|
|
|
a19a3f |
+ else if (object->sync_action_source == NULL && object->degraded_source == NULL)
|
|
|
a19a3f |
+ {
|
|
|
a19a3f |
+ /* we don't have file watchers, adding them may failed because
|
|
|
a19a3f |
+ we were unable to get raid level, let's try again */
|
|
|
a19a3f |
+ raid_device_added (object, object->raid_device);
|
|
|
a19a3f |
+ }
|
|
|
a19a3f |
}
|
|
|
a19a3f |
}
|
|
|
a19a3f |
}
|
|
|
a19a3f |
--
|
|
|
a19a3f |
2.9.5
|
|
|
a19a3f |
|
|
|
a19a3f |
From ab6ee79abac6a75eddd0ecfba7fc5111663bc50f Mon Sep 17 00:00:00 2001
|
|
|
a19a3f |
From: Vojtech Trefny <vtrefny@redhat.com>
|
|
|
a19a3f |
Date: Mon, 16 Oct 2017 15:26:16 +0200
|
|
|
a19a3f |
Subject: [PATCH 5/5] Try to use libblockdev to get RAID array size
|
|
|
a19a3f |
|
|
|
a19a3f |
If reading size from sysfs fails, try to use libblockdev to read
|
|
|
a19a3f |
it from mdadm --examine data.
|
|
|
a19a3f |
|
|
|
a19a3f |
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
|
|
|
a19a3f |
---
|
|
|
a19a3f |
src/udiskslinuxmdraid.c | 15 ++++++++++++++-
|
|
|
a19a3f |
1 file changed, 14 insertions(+), 1 deletion(-)
|
|
|
a19a3f |
|
|
|
a19a3f |
diff --git a/src/udiskslinuxmdraid.c b/src/udiskslinuxmdraid.c
|
|
|
a19a3f |
index 22b4ee4..6c94a2b 100644
|
|
|
a19a3f |
--- a/src/udiskslinuxmdraid.c
|
|
|
a19a3f |
+++ b/src/udiskslinuxmdraid.c
|
|
|
a19a3f |
@@ -246,6 +246,8 @@ udisks_linux_mdraid_update (UDisksLinuxMDRaid *mdraid,
|
|
|
a19a3f |
GVariantBuilder builder;
|
|
|
a19a3f |
UDisksDaemon *daemon = NULL;
|
|
|
a19a3f |
UDisksBaseJob *job = NULL;
|
|
|
a19a3f |
+ GError *error = NULL;
|
|
|
a19a3f |
+ BDMDExamineData *raid_data = NULL;
|
|
|
a19a3f |
|
|
|
a19a3f |
daemon = udisks_linux_mdraid_object_get_daemon (object);
|
|
|
a19a3f |
|
|
|
a19a3f |
@@ -303,7 +305,15 @@ udisks_linux_mdraid_update (UDisksLinuxMDRaid *mdraid,
|
|
|
a19a3f |
}
|
|
|
a19a3f |
else
|
|
|
a19a3f |
{
|
|
|
a19a3f |
- /* TODO: need MD_ARRAY_SIZE, see https://bugs.freedesktop.org/show_bug.cgi?id=53239#c5 */
|
|
|
a19a3f |
+ raid_data = bd_md_examine (g_udev_device_get_device_file (device->udev_device),
|
|
|
a19a3f |
+ &error);
|
|
|
a19a3f |
+ if (raid_data == NULL)
|
|
|
a19a3f |
+ {
|
|
|
a19a3f |
+ udisks_debug ("Failed to read array size: %s", error->message);
|
|
|
a19a3f |
+ g_clear_error (&error);
|
|
|
a19a3f |
+ }
|
|
|
a19a3f |
+ else
|
|
|
a19a3f |
+ size = raid_data->size;
|
|
|
a19a3f |
}
|
|
|
a19a3f |
|
|
|
a19a3f |
udisks_mdraid_set_uuid (iface, uuid);
|
|
|
a19a3f |
@@ -523,11 +533,14 @@ udisks_linux_mdraid_update (UDisksLinuxMDRaid *mdraid,
|
|
|
a19a3f |
uuid));
|
|
|
a19a3f |
|
|
|
a19a3f |
out:
|
|
|
a19a3f |
+ if (raid_data)
|
|
|
a19a3f |
+ bd_md_examine_data_free (raid_data);
|
|
|
a19a3f |
g_free (sync_completed);
|
|
|
a19a3f |
g_free (sync_action);
|
|
|
a19a3f |
g_free (bitmap_location);
|
|
|
a19a3f |
g_list_free_full (member_devices, g_object_unref);
|
|
|
a19a3f |
g_clear_object (&raid_device);
|
|
|
a19a3f |
+ g_clear_error (&error);
|
|
|
a19a3f |
return ret;
|
|
|
a19a3f |
}
|
|
|
a19a3f |
|
|
|
a19a3f |
--
|
|
|
a19a3f |
2.9.5
|
|
|
a19a3f |
|