]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: respect --discard=no also for block devices
authorLuca Boccassi <bluca@debian.org>
Tue, 22 Nov 2022 16:24:54 +0000 (16:24 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 23 Nov 2022 00:33:26 +0000 (01:33 +0100)
It's only used to avoid BLKDISCARD on individual partitions at the moment.
It can take a lot of time to run on very slow devices, so avoid it for
them too.

src/partition/repart.c

index 5beba69f3fca361c186714275e9d87b3f0fa8ca6..e23a0c335092fe335506727ff6a2888f212ecda2 100644 (file)
@@ -4618,13 +4618,15 @@ static int context_write_partition_table(
 
                 log_info("Wiped block device.");
 
-                r = context_discard_range(context, 0, context->total);
-                if (r == -EOPNOTSUPP)
-                        log_info("Storage does not support discard, not discarding entire block device data.");
-                else if (r < 0)
-                        return log_error_errno(r, "Failed to discard entire block device: %m");
-                else if (r > 0)
-                        log_info("Discarded entire block device.");
+                if (arg_discard) {
+                        r = context_discard_range(context, 0, context->total);
+                        if (r == -EOPNOTSUPP)
+                                log_info("Storage does not support discard, not discarding entire block device data.");
+                        else if (r < 0)
+                                return log_error_errno(r, "Failed to discard entire block device: %m");
+                        else if (r > 0)
+                                log_info("Discarded entire block device.");
+                }
         }
 
         r = fdisk_get_partitions(context->fdisk_context, &original_table);