[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] master - discards: skip when removing LVs on missing PVs



Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b737ff01e4038d45798521448dc4ae4864d1b29a
Commit:        b737ff01e4038d45798521448dc4ae4864d1b29a
Parent:        2a6712ddefb6720d115d11c276223b57abf5dd94
Author:        Alasdair G Kergon <agk redhat com>
AuthorDate:    Wed Sep 19 12:48:56 2012 +0100
Committer:     Alasdair G Kergon <agk redhat com>
CommitterDate: Wed Sep 19 12:48:56 2012 +0100

discards: skip when removing LVs on missing PVs

Don't try to issue discards to a missing PV to avoid segfault.
Prevent lvremove from removing LVs that have any part missing.

https://bugzilla.redhat.com/857554
---
 WHATS_NEW               |    2 ++
 lib/metadata/pv_manip.c |   17 +++++++++++++++--
 tools/lvremove.c        |    6 ++++++
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/WHATS_NEW b/WHATS_NEW
index f2aa7ec..996f1a2 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,7 @@
 Version 2.02.98 -
 =================================
+  Don't try to issue discards to a missing PV to avoid segfault.
+  Prevent lvremove from removing LVs that have any part missing.
   Clear LV_NOSYNCED flag when a RAID1 LV is converted to a linear LV.
   Disallow RAID1 upconvert if the LV was created with --nosync.
   Depend on systemd-udev-settle in units generated by activation generator.
diff --git a/lib/metadata/pv_manip.c b/lib/metadata/pv_manip.c
index e85a2bc..d04ecab 100644
--- a/lib/metadata/pv_manip.c
+++ b/lib/metadata/pv_manip.c
@@ -191,6 +191,7 @@ int discard_pv_segment(struct pv_segment *peg, uint32_t discard_area_reduction)
 {
 	uint64_t discard_offset_sectors;
 	uint64_t pe_start = peg->pv->pe_start;
+	char uuid[64] __attribute__((aligned(8)));
 
 	if (!peg->lvseg) {
 		log_error("discard_pv_segment with unallocated segment: "
@@ -203,8 +204,20 @@ int discard_pv_segment(struct pv_segment *peg, uint32_t discard_area_reduction)
 	 * the device and kernel (>= 2.6.35) supports discards.
 	 */
 	if (!find_config_tree_bool(peg->pv->fmt->cmd,
-				   "devices/issue_discards", DEFAULT_ISSUE_DISCARDS) ||
-	    !dev_discard_max_bytes(peg->pv->fmt->cmd->sysfs_dir, peg->pv->dev) ||
+				   "devices/issue_discards", DEFAULT_ISSUE_DISCARDS))
+		return 1;
+ 
+	/* Missing PV? */
+	if (is_missing_pv(peg->pv) || !peg->pv->dev) {
+		if (!id_write_format(&peg->pv->id, uuid, sizeof(uuid)))
+			return_0;
+
+		log_verbose("Skipping discard on missing device with uuid %s.", uuid);
+
+		return 1;
+	}
+
+	if (!dev_discard_max_bytes(peg->pv->fmt->cmd->sysfs_dir, peg->pv->dev) ||
 	    !dev_discard_granularity(peg->pv->fmt->cmd->sysfs_dir, peg->pv->dev))
 		return 1;
 
diff --git a/tools/lvremove.c b/tools/lvremove.c
index 0252149..2c5b317 100644
--- a/tools/lvremove.c
+++ b/tools/lvremove.c
@@ -26,6 +26,12 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv,
         if (lv_is_cow(lv) && lv_is_virtual_origin(origin = origin_from_cow(lv)))
                 lv = origin;
 
+	if (lv->status & PARTIAL_LV) {
+		log_error("Not removing LV %s/%s because part or all of it is missing.",
+			  lv->vg->name, lv->name);
+		return ECMD_FAILED;
+	}
+
 	if (!lv_remove_with_dependencies(cmd, lv, arg_count(cmd, force_ARG), 0)) {
 		stack;
 		return ECMD_FAILED;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]