dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

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

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