|
|
ac3a84 |
From 44843b307d9acbe4f17b7af710cf66932667533a Mon Sep 17 00:00:00 2001
|
|
|
ac3a84 |
From: Luca Boccassi <bluca@debian.org>
|
|
|
ac3a84 |
Date: Tue, 22 Nov 2022 16:24:54 +0000
|
|
|
ac3a84 |
Subject: [PATCH] repart: respect --discard=no also for block devices
|
|
|
ac3a84 |
|
|
|
ac3a84 |
It's only used to avoid BLKDISCARD on individual partitions at the moment.
|
|
|
ac3a84 |
It can take a lot of time to run on very slow devices, so avoid it for
|
|
|
ac3a84 |
them too.
|
|
|
ac3a84 |
|
|
|
ac3a84 |
(cherry picked from commit 0dce448bbc97c861520c287b01d632b887442925)
|
|
|
ac3a84 |
|
|
|
ac3a84 |
Related: #2138081
|
|
|
ac3a84 |
---
|
|
|
ac3a84 |
src/partition/repart.c | 16 +++++++++-------
|
|
|
ac3a84 |
1 file changed, 9 insertions(+), 7 deletions(-)
|
|
|
ac3a84 |
|
|
|
ac3a84 |
diff --git a/src/partition/repart.c b/src/partition/repart.c
|
|
|
ac3a84 |
index 8e3cfece89..c4ca9840c8 100644
|
|
|
ac3a84 |
--- a/src/partition/repart.c
|
|
|
ac3a84 |
+++ b/src/partition/repart.c
|
|
|
ac3a84 |
@@ -4387,13 +4387,15 @@ static int context_write_partition_table(
|
|
|
ac3a84 |
|
|
|
ac3a84 |
log_info("Wiped block device.");
|
|
|
ac3a84 |
|
|
|
ac3a84 |
- r = context_discard_range(context, 0, context->total);
|
|
|
ac3a84 |
- if (r == -EOPNOTSUPP)
|
|
|
ac3a84 |
- log_info("Storage does not support discard, not discarding entire block device data.");
|
|
|
ac3a84 |
- else if (r < 0)
|
|
|
ac3a84 |
- return log_error_errno(r, "Failed to discard entire block device: %m");
|
|
|
ac3a84 |
- else if (r > 0)
|
|
|
ac3a84 |
- log_info("Discarded entire block device.");
|
|
|
ac3a84 |
+ if (arg_discard) {
|
|
|
ac3a84 |
+ r = context_discard_range(context, 0, context->total);
|
|
|
ac3a84 |
+ if (r == -EOPNOTSUPP)
|
|
|
ac3a84 |
+ log_info("Storage does not support discard, not discarding entire block device data.");
|
|
|
ac3a84 |
+ else if (r < 0)
|
|
|
ac3a84 |
+ return log_error_errno(r, "Failed to discard entire block device: %m");
|
|
|
ac3a84 |
+ else if (r > 0)
|
|
|
ac3a84 |
+ log_info("Discarded entire block device.");
|
|
|
ac3a84 |
+ }
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
r = fdisk_get_partitions(context->fdisk_context, &original_table);
|