File linear.patch of Package libstorage-ng.31305

diff -ru libstorage-ng-4.4.94-orig/storage/Devices/Md.cc libstorage-ng-4.4.94/storage/Devices/Md.cc
--- libstorage-ng-4.4.94-orig/storage/Devices/Md.cc	2022-03-17 20:08:12.000000000 +0100
+++ libstorage-ng-4.4.94/storage/Devices/Md.cc	2023-09-11 11:46:39.238633941 +0200
@@ -198,6 +198,13 @@
     }
 
 
+    bool
+    Md::is_chunk_size_meaningful() const
+    {
+	return get_impl().is_chunk_size_meaningful();
+    }
+
+
     unsigned long
     Md::get_chunk_size() const
     {
Only in libstorage-ng-4.4.94/storage/Devices: Md.cc.orig
diff -ru libstorage-ng-4.4.94-orig/storage/Devices/Md.h libstorage-ng-4.4.94/storage/Devices/Md.h
--- libstorage-ng-4.4.94-orig/storage/Devices/Md.h	2022-03-17 20:08:12.000000000 +0100
+++ libstorage-ng-4.4.94/storage/Devices/Md.h	2023-09-11 11:46:39.238633941 +0200
@@ -40,7 +40,7 @@
      */
     enum class MdLevel
     {
-	UNKNOWN, RAID0, RAID1, RAID4, RAID5, RAID6, RAID10, CONTAINER
+	UNKNOWN, RAID0, RAID1, RAID4, RAID5, RAID6, RAID10, CONTAINER, LINEAR
     };
 
 
@@ -173,12 +173,21 @@
 	std::vector<MdParity> get_allowed_md_parities() const;
 
 	/**
-	 * Get the chunk size of the MD RAID. The chunk size is not meaningful for RAID1.
+	 * Is the chunk size meaningful for the RAID (so far only depends on RAID level)?
+	 */
+	bool is_chunk_size_meaningful() const;
+
+	/**
+	 * Get the chunk size of the MD RAID. The chunk size is not meaningful for LINEAR
+	 * nor RAID1.
+	 *
+	 * @see is_chunk_size_meaningful()
 	 */
 	unsigned long get_chunk_size() const;
 
 	/**
-	 * Set the chunk size of the MD RAID. The chunk size is not meaningful for RAID1.
+	 * Set the chunk size of the MD RAID. The chunk size is not meaningful for LINEAR
+	 * nor RAID1.
 	 *
 	 * The function does not make a complete check of the chunk size since that
 	 * depends on the RAID Level and the underlying devices. Use the
@@ -186,6 +195,8 @@
 	 *
 	 * Only for MD RAIDs not created on disk yet.
 	 *
+	 * @see is_chunk_size_meaningful()
+	 *
 	 * @throw InvalidChunkSize, Exception
 	 */
 	void set_chunk_size(unsigned long chunk_size);
diff -ru libstorage-ng-4.4.94-orig/storage/Devices/MdImpl.cc libstorage-ng-4.4.94/storage/Devices/MdImpl.cc
--- libstorage-ng-4.4.94-orig/storage/Devices/MdImpl.cc	2022-03-17 20:08:12.000000000 +0100
+++ libstorage-ng-4.4.94/storage/Devices/MdImpl.cc	2023-09-11 11:47:19.555553618 +0200
@@ -63,7 +63,7 @@
 
     // strings must match /proc/mdstat
     const vector<string> EnumTraits<MdLevel>::names({
-	"unknown", "RAID0", "RAID1", "RAID4", "RAID5", "RAID6", "RAID10", "CONTAINER"
+	"unknown", "RAID0", "RAID1", "RAID4", "RAID5", "RAID6", "RAID10", "CONTAINER", "LINEAR"
     });
 
 
@@ -173,6 +173,7 @@
 
 	switch (md_level)
 	{
+	    case MdLevel::LINEAR:
 	    case MdLevel::RAID0:
 		underlying_size = size / number_of_devices;
 		break;
@@ -302,6 +303,7 @@
 	    case MdLevel::UNKNOWN:
 		return { };
 
+	    case MdLevel::LINEAR:
 	    case MdLevel::RAID0:
 	    case MdLevel::RAID1:
 	    case MdLevel::RAID4:
@@ -333,6 +335,14 @@
     }
 
 
+    bool
+    Md::Impl::is_chunk_size_meaningful() const
+    {
+	return md_level == MdLevel::RAID0 || md_level == MdLevel::RAID4 || md_level == MdLevel::RAID5 ||
+	    md_level == MdLevel::RAID6 || md_level == MdLevel::RAID10;
+    }
+
+
     void
     Md::Impl::set_chunk_size(unsigned long chunk_size)
     {
@@ -821,6 +831,9 @@
     {
 	switch (md_level)
 	{
+	    case MdLevel::LINEAR:
+		return 2;
+
 	    case MdLevel::RAID0:
 		return 2;
 
@@ -855,6 +868,7 @@
     {
 	switch (md_level)
 	{
+	    case MdLevel::LINEAR:
 	    case MdLevel::RAID0:
 		return false;
 
@@ -876,6 +890,7 @@
     {
 	switch (md_level)
 	{
+	    case MdLevel::LINEAR:
 	    case MdLevel::RAID0:
 	    case MdLevel::RAID1:
 		return false;
@@ -996,6 +1011,14 @@
 
 	switch (md_level)
 	{
+	    case MdLevel::LINEAR:
+		if (number >= 2)
+		{
+		    size = sum;
+		    optimal_io_size = 0;
+		}
+		break;
+
 	    case MdLevel::RAID0:
 		if (number >= 2)
 		{
@@ -1115,7 +1138,8 @@
 	     md_level == MdLevel::RAID10) && journals.empty())
 	    cmd_line += " --bitmap=internal";
 
-	if (chunk_size > 0)
+	// mdadm 4.2 bails out if a chunk size is provided for RAID1 (bsc#1205172)
+	if (is_chunk_size_meaningful() && chunk_size > 0)
 	    cmd_line += " --chunk=" + to_string(chunk_size / KiB);
 
 	if (md_parity != MdParity::DEFAULT)
Only in libstorage-ng-4.4.94/storage/Devices: MdImpl.cc.orig
Only in libstorage-ng-4.4.94/storage/Devices: MdImpl.cc.rej
diff -ru libstorage-ng-4.4.94-orig/storage/Devices/MdImpl.h libstorage-ng-4.4.94/storage/Devices/MdImpl.h
--- libstorage-ng-4.4.94-orig/storage/Devices/MdImpl.h	2022-03-17 20:08:12.000000000 +0100
+++ libstorage-ng-4.4.94/storage/Devices/MdImpl.h	2023-09-11 11:46:39.238633941 +0200
@@ -92,6 +92,8 @@
 
 	vector<MdParity> get_allowed_md_parities() const;
 
+	bool is_chunk_size_meaningful() const;
+
 	unsigned long get_chunk_size() const { return chunk_size; }
 	void set_chunk_size(unsigned long chunk_size);
 
Only in libstorage-ng-4.4.94/storage/Devices: MdImpl.h.orig
diff -ru libstorage-ng-4.4.94-orig/storage/SystemInfo/ProcMdstat.cc libstorage-ng-4.4.94/storage/SystemInfo/ProcMdstat.cc
--- libstorage-ng-4.4.94-orig/storage/SystemInfo/ProcMdstat.cc	2022-03-17 20:08:12.000000000 +0100
+++ libstorage-ng-4.4.94/storage/SystemInfo/ProcMdstat.cc	2023-09-11 11:46:39.238633941 +0200
@@ -102,7 +102,7 @@
 	boost::trim_left(line, locale::classic());
 
 	tmp = extractNthWord( 0, line );
-	if (boost::starts_with(tmp, "raid"))
+	if (boost::starts_with(tmp, "raid") || tmp == "linear")
 	{
 	    entry.md_level = toValueWithFallback(boost::to_upper_copy(tmp, locale::classic()), MdLevel::UNKNOWN);
 	    if (entry.md_level == MdLevel::UNKNOWN)
openSUSE Build Service is sponsored by