From d33d1dda277a78dcf63574c567ca24d7c3462f49 Mon Sep 17 00:00:00 2001
From: Marius Vollmer <mvollmer@redhat.com>
Date: Tue, 30 Apr 2024 14:39:13 +0300
Subject: [PATCH] mdraid: Expose "consistency_policy" sysfs value

---
 data/org.freedesktop.UDisks2.xml | 12 ++++++++++++
 src/udiskslinuxmdraid.c          |  4 ++++
 2 files changed, 16 insertions(+)

diff --git a/data/org.freedesktop.UDisks2.xml b/data/org.freedesktop.UDisks2.xml
index 53194c7..5d34901 100644
--- a/data/org.freedesktop.UDisks2.xml
+++ b/data/org.freedesktop.UDisks2.xml
@@ -3137,6 +3137,18 @@
     -->
     <property name="Degraded" type="u" access="read"/>
 
+    <!-- ConsistencyPolicy:
+         @since: 2.11.0
+         The consistency policy of the array.
+
+         If the RAID array does not support consistency policies (for
+         example RAID-0 arrays), this is empty.
+
+         This property corresponds to the
+         <literal>consistency_policy</literal> sysfs file.
+    -->
+    <property name="ConsistencyPolicy" type="s" access="read"/>
+
     <!-- BitmapLocation:
          The location of a write-intent bitmap (empty if the array is not running), if any.
 
diff --git a/src/udiskslinuxmdraid.c b/src/udiskslinuxmdraid.c
index 900cd65..46ee77e 100644
--- a/src/udiskslinuxmdraid.c
+++ b/src/udiskslinuxmdraid.c
@@ -237,6 +237,7 @@ udisks_linux_mdraid_update (UDisksLinuxMDRaid       *mdraid,
   const gchar *name = NULL;
   gchar *sync_action = NULL;
   gchar *sync_completed = NULL;
+  gchar *consistency_policy = NULL;
   gchar *bitmap_location = NULL;
   guint degraded = 0;
   guint64 chunk_size = 0;
@@ -316,6 +317,7 @@ udisks_linux_mdraid_update (UDisksLinuxMDRaid       *mdraid,
           degraded = udisks_linux_device_read_sysfs_attr_as_int (raid_device, "md/degraded", NULL);
           sync_action = udisks_linux_device_read_sysfs_attr (raid_device, "md/sync_action", NULL);
           sync_completed = udisks_linux_device_read_sysfs_attr (raid_device, "md/sync_completed", NULL);
+          consistency_policy = udisks_linux_device_read_sysfs_attr (raid_device, "md/consistency_policy", NULL);
           bitmap_location = udisks_linux_device_read_sysfs_attr (raid_device, "md/bitmap/location", NULL);
         }
 
@@ -326,6 +328,7 @@ udisks_linux_mdraid_update (UDisksLinuxMDRaid       *mdraid,
     }
   udisks_mdraid_set_degraded (iface, degraded);
   udisks_mdraid_set_sync_action (iface, sync_action);
+  udisks_mdraid_set_consistency_policy (iface, consistency_policy);
   udisks_mdraid_set_bitmap_location (iface, bitmap_location);
   udisks_mdraid_set_chunk_size (iface, chunk_size);
 
@@ -517,6 +520,7 @@ udisks_linux_mdraid_update (UDisksLinuxMDRaid       *mdraid,
       bd_md_examine_data_free (raid_data);
   g_free (sync_completed);
   g_free (sync_action);
+  g_free (consistency_policy);
   g_free (bitmap_location);
   g_list_free_full (member_devices, g_object_unref);
   g_clear_object (&raid_device);
-- 
2.33.0

