Blame SOURCES/0060-Add-support-for-Tebibytes.patch

8e8941
From 42e641abeb312a91b841f1b1ea73661e4bd5a31c Mon Sep 17 00:00:00 2001
8e8941
From: Kinga Tanska <kinga.tanska@intel.com>
8e8941
Date: Tue, 21 Jan 2020 10:38:52 +0100
8e8941
Subject: [RHEL8.2 PATCH 60/61] Add support for Tebibytes
8e8941
8e8941
Adding support for Tebibytes enables display size of
8e8941
volumes in Tebibytes and Terabytes when they are
8e8941
bigger than 2048 GiB (or GB).
8e8941
8e8941
Signed-off-by: Kinga Tanska <kinga.tanska@intel.com>
8e8941
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
8e8941
---
8e8941
 mdadm.8.in | 20 ++++++++++----------
8e8941
 util.c     | 47 +++++++++++++++++++++++++++++++++--------------
8e8941
 2 files changed, 43 insertions(+), 24 deletions(-)
8e8941
8e8941
diff --git a/mdadm.8.in b/mdadm.8.in
8e8941
index ca02a33..5d00faf 100644
8e8941
--- a/mdadm.8.in
8e8941
+++ b/mdadm.8.in
8e8941
@@ -467,8 +467,8 @@ If this is not specified
8e8941
 size, though if there is a variance among the drives of greater than 1%, a warning is
8e8941
 issued.
8e8941
 
8e8941
-A suffix of 'K', 'M' or 'G' can be given to indicate Kilobytes, Megabytes or
8e8941
-Gigabytes respectively.
8e8941
+A suffix of 'K', 'M', 'G' or 'T' can be given to indicate Kilobytes,
8e8941
+Megabytes, Gigabytes or Terabytes respectively.
8e8941
 
8e8941
 Sometimes a replacement drive can be a little smaller than the
8e8941
 original drives though this should be minimised by IDEMA standards.
8e8941
@@ -532,8 +532,8 @@ problems the array can be made bigger again with no loss with another
8e8941
 .B "\-\-grow \-\-array\-size="
8e8941
 command.
8e8941
 
8e8941
-A suffix of 'K', 'M' or 'G' can be given to indicate Kilobytes, Megabytes or
8e8941
-Gigabytes respectively.
8e8941
+A suffix of 'K', 'M', 'G' or 'T' can be given to indicate Kilobytes,
8e8941
+Megabytes, Gigabytes or Terabytes respectively.
8e8941
 A value of
8e8941
 .B max
8e8941
 restores the apparent size of the array to be whatever the real
8e8941
@@ -551,8 +551,8 @@ This is only meaningful for RAID0, RAID4, RAID5, RAID6, and RAID10.
8e8941
 RAID4, RAID5, RAID6, and RAID10 require the chunk size to be a power
8e8941
 of 2.  In any case it must be a multiple of 4KB.
8e8941
 
8e8941
-A suffix of 'K', 'M' or 'G' can be given to indicate Kilobytes, Megabytes or
8e8941
-Gigabytes respectively.
8e8941
+A suffix of 'K', 'M', 'G' or 'T' can be given to indicate Kilobytes,
8e8941
+Megabytes, Gigabytes or Terabytes respectively.
8e8941
 
8e8941
 .TP
8e8941
 .BR \-\-rounding=
8e8941
@@ -767,8 +767,8 @@ When using an
8e8941
 bitmap, the chunksize defaults to 64Meg, or larger if necessary to
8e8941
 fit the bitmap into the available space.
8e8941
 
8e8941
-A suffix of 'K', 'M' or 'G' can be given to indicate Kilobytes, Megabytes or
8e8941
-Gigabytes respectively.
8e8941
+A suffix of 'K', 'M', 'G' or 'T' can be given to indicate Kilobytes,
8e8941
+Megabytes, Gigabytes or Terabytes respectively.
8e8941
 
8e8941
 .TP
8e8941
 .BR \-W ", " \-\-write\-mostly
8e8941
@@ -857,8 +857,8 @@ an array which was originally created using a different version of
8e8941
 which computed a different offset.
8e8941
 
8e8941
 Setting the offset explicitly over-rides the default.  The value given
8e8941
-is in Kilobytes unless a suffix of 'K', 'M' or 'G' is used to explicitly
8e8941
-indicate Kilobytes, Megabytes or Gigabytes respectively.
8e8941
+is in Kilobytes unless a suffix of 'K', 'M', 'G' or 'T' is used to explicitly
8e8941
+indicate Kilobytes, Megabytes, Gigabytes or Terabytes respectively.
8e8941
 
8e8941
 Since Linux 3.4,
8e8941
 .B \-\-data\-offset
8e8941
diff --git a/util.c b/util.c
8e8941
index 64dd409..07f9dc3 100644
8e8941
--- a/util.c
8e8941
+++ b/util.c
8e8941
@@ -389,7 +389,7 @@ int mdadm_version(char *version)
8e8941
 unsigned long long parse_size(char *size)
8e8941
 {
8e8941
 	/* parse 'size' which should be a number optionally
8e8941
-	 * followed by 'K', 'M', or 'G'.
8e8941
+	 * followed by 'K', 'M'. 'G' or 'T'.
8e8941
 	 * Without a suffix, K is assumed.
8e8941
 	 * Number returned is in sectors (half-K)
8e8941
 	 * INVALID_SECTORS returned on error.
8e8941
@@ -411,6 +411,10 @@ unsigned long long parse_size(char *size)
8e8941
 			c++;
8e8941
 			s *= 1024 * 1024 * 2;
8e8941
 			break;
8e8941
+		case 'T':
8e8941
+			c++;
8e8941
+			s *= 1024 * 1024 * 1024 * 2LL;
8e8941
+			break;
8e8941
 		case 's': /* sectors */
8e8941
 			c++;
8e8941
 			break;
8e8941
@@ -893,13 +897,14 @@ char *human_size(long long bytes)
8e8941
 {
8e8941
 	static char buf[47];
8e8941
 
8e8941
-	/* We convert bytes to either centi-M{ega,ibi}bytes or
8e8941
-	 * centi-G{igi,ibi}bytes, with appropriate rounding,
8e8941
-	 * and then print 1/100th of those as a decimal.
8e8941
+	/* We convert bytes to either centi-M{ega,ibi}bytes,
8e8941
+	 * centi-G{igi,ibi}bytes or centi-T{era,ebi}bytes
8e8941
+	 * with appropriate rounding, and then print
8e8941
+	 * 1/100th of those as a decimal.
8e8941
 	 * We allow upto 2048Megabytes before converting to
8e8941
-	 * gigabytes, as that shows more precision and isn't
8e8941
+	 * gigabytes and 2048Gigabytes before converting to
8e8941
+	 * terabytes, as that shows more precision and isn't
8e8941
 	 * too large a number.
8e8941
-	 * Terabytes are not yet handled.
8e8941
 	 */
8e8941
 
8e8941
 	if (bytes < 5000*1024)
8e8941
@@ -909,11 +914,16 @@ char *human_size(long long bytes)
8e8941
 		long cMB  = (bytes / ( 1000000LL / 200LL ) +1) /2;
8e8941
 		snprintf(buf, sizeof(buf), " (%ld.%02ld MiB %ld.%02ld MB)",
8e8941
 			cMiB/100, cMiB % 100, cMB/100, cMB % 100);
8e8941
-	} else {
8e8941
+	} else if (bytes < 2*1024LL*1024LL*1024LL*1024LL) {
8e8941
 		long cGiB = (bytes * 200LL / (1LL<<30) +1) / 2;
8e8941
 		long cGB  = (bytes / (1000000000LL/200LL ) +1) /2;
8e8941
 		snprintf(buf, sizeof(buf), " (%ld.%02ld GiB %ld.%02ld GB)",
8e8941
 			cGiB/100, cGiB % 100, cGB/100, cGB % 100);
8e8941
+	} else {
8e8941
+		long cTiB = (bytes * 200LL / (1LL<<40) + 1) / 2;
8e8941
+		long cTB  = (bytes / (1000000000000LL / 200LL) + 1) / 2;
8e8941
+		snprintf(buf, sizeof(buf), " (%ld.%02ld TiB %ld.%02ld TB)",
8e8941
+			cTiB/100, cTiB % 100, cTB/100, cTB % 100);
8e8941
 	}
8e8941
 	return buf;
8e8941
 }
8e8941
@@ -922,13 +932,14 @@ char *human_size_brief(long long bytes, int prefix)
8e8941
 {
8e8941
 	static char buf[30];
8e8941
 
8e8941
-	/* We convert bytes to either centi-M{ega,ibi}bytes or
8e8941
-	 * centi-G{igi,ibi}bytes, with appropriate rounding,
8e8941
-	 * and then print 1/100th of those as a decimal.
8e8941
+	/* We convert bytes to either centi-M{ega,ibi}bytes,
8e8941
+	 * centi-G{igi,ibi}bytes or centi-T{era,ebi}bytes
8e8941
+	 * with appropriate rounding, and then print
8e8941
+	 * 1/100th of those as a decimal.
8e8941
 	 * We allow upto 2048Megabytes before converting to
8e8941
-	 * gigabytes, as that shows more precision and isn't
8e8941
+	 * gigabytes and 2048Gigabytes before converting to
8e8941
+	 * terabytes, as that shows more precision and isn't
8e8941
 	 * too large a number.
8e8941
-	 * Terabytes are not yet handled.
8e8941
 	 *
8e8941
 	 * If prefix == IEC, we mean prefixes like kibi,mebi,gibi etc.
8e8941
 	 * If prefix == JEDEC, we mean prefixes like kilo,mega,giga etc.
8e8941
@@ -941,10 +952,14 @@ char *human_size_brief(long long bytes, int prefix)
8e8941
 			long cMiB = (bytes * 200LL / (1LL<<20) +1) /2;
8e8941
 			snprintf(buf, sizeof(buf), "%ld.%02ldMiB",
8e8941
 				 cMiB/100, cMiB % 100);
8e8941
-		} else {
8e8941
+		} else if (bytes < 2*1024LL*1024LL*1024LL*1024LL) {
8e8941
 			long cGiB = (bytes * 200LL / (1LL<<30) +1) /2;
8e8941
 			snprintf(buf, sizeof(buf), "%ld.%02ldGiB",
8e8941
 				 cGiB/100, cGiB % 100);
8e8941
+		} else {
8e8941
+			long cTiB = (bytes * 200LL / (1LL<<40) + 1) / 2;
8e8941
+			snprintf(buf, sizeof(buf), "%ld.%02ldTiB",
8e8941
+				 cTiB/100, cTiB % 100);
8e8941
 		}
8e8941
 	}
8e8941
 	else if (prefix == JEDEC) {
8e8941
@@ -952,10 +967,14 @@ char *human_size_brief(long long bytes, int prefix)
8e8941
 			long cMB  = (bytes / ( 1000000LL / 200LL ) +1) /2;
8e8941
 			snprintf(buf, sizeof(buf), "%ld.%02ldMB",
8e8941
 				 cMB/100, cMB % 100);
8e8941
-		} else {
8e8941
+		} else if (bytes < 2*1024LL*1024LL*1024LL*1024LL) {
8e8941
 			long cGB  = (bytes / (1000000000LL/200LL ) +1) /2;
8e8941
 			snprintf(buf, sizeof(buf), "%ld.%02ldGB",
8e8941
 				 cGB/100, cGB % 100);
8e8941
+		} else {
8e8941
+			long cTB  = (bytes / (1000000000000LL / 200LL) + 1) / 2;
8e8941
+			snprintf(buf, sizeof(buf), "%ld.%02ldTB",
8e8941
+				 cTB/100, cTB % 100);
8e8941
 		}
8e8941
 	}
8e8941
 	else
8e8941
-- 
8e8941
2.7.5
8e8941