lvm2/bug-1095960_dev_io-no-discard-in-testmode.patch
Gang He d837fba6c1 Accepting request 623585 from home:ganghe:branches:openSUSE:Factory
- Fix issuing discard in test mode (bsc#1095960)
  + bug-1095960_dev_io-no-discard-in-testmode.patch
- Fix issuing discard in test mode (bsc#1095960)
  + bug-1095960_dev_io-no-discard-in-testmode.patch
- Fix issuing discard in test mode (bsc#1095960)
  + bug-1095960_dev_io-no-discard-in-testmode.patch

OBS-URL: https://build.opensuse.org/request/show/623585
OBS-URL: https://build.opensuse.org/package/show/Base:System/lvm2?expand=0&rev=225
2018-07-18 08:52:01 +00:00

35 lines
1.4 KiB
Diff

From b8a7f6ba3de6aed38c2969693b6064a943ea8799 Mon Sep 17 00:00:00 2001
From: Zdenek Kabelac <zkabelac@redhat.com>
Date: Sun, 8 Jul 2018 21:11:01 +0200
Subject: [PATCH] dev_io: no discard in testmode
When lvm2 command is executed in test mode, discard ioctl is skipped.
This may cause even data-loose in case, issuing discard for released
areas was enabled and user 'tested' lvreduce.
---
lib/device/dev-io.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index 145093f17..2a4967fc1 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -411,9 +411,11 @@ static int _dev_discard_blocks(struct device *dev, uint64_t offset_bytes, uint64
discard_range[0] = offset_bytes;
discard_range[1] = size_bytes;
- log_debug_devs("Discarding %" PRIu64 " bytes offset %" PRIu64 " bytes on %s.",
- size_bytes, offset_bytes, dev_name(dev));
- if (ioctl(dev->fd, BLKDISCARD, &discard_range) < 0) {
+ log_debug_devs("Discarding %" PRIu64 " bytes offset %" PRIu64 " bytes on %s. %s",
+ size_bytes, offset_bytes, dev_name(dev),
+ test_mode() ? " (test mode - suppressed)" : "");
+
+ if (!test_mode() && ioctl(dev->fd, BLKDISCARD, &discard_range) < 0) {
log_error("%s: BLKDISCARD ioctl at offset %" PRIu64 " size %" PRIu64 " failed: %s.",
dev_name(dev), offset_bytes, size_bytes, strerror(errno));
if (!dev_close(dev))
--
2.12.3