repart: respect --discard=no also for block devices

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.
This commit is contained in:
Luca Boccassi
2022-11-23 01:33:26 +01:00
committed by Luca Boccassi
parent da403fd38a
commit 0dce448bbc
+9 -7
View 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);