dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

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

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