naccyde / rpms / systemd

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