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

[lvm-devel] [PATCH mirror 2/13] Add _apply_lv_change() to lib/metadata/mirror.c



This is a cosmetic change of moving idiomatic operations of
vg write/lv suspend/vg commit/lv resume to a new function.
No functional change.

Thanks,
-- 
Jun'ichi Nomura, NEC Corporation of America

When removing a part of mirrored LV (mimage, mlog),
we have to update the mirrored LV in kernel first,
then we can remove the unused mimage/mlog.

This procedure is common when _delete_lv() is used.

Index: LVM2.work/lib/metadata/mirror.c
===================================================================
--- LVM2.work.orig/lib/metadata/mirror.c
+++ LVM2.work/lib/metadata/mirror.c
@@ -80,6 +80,45 @@ static void _move_lv_segments(struct log
 
 
 /*
+ * Preparation for _delete_lv()
+ */
+static int _apply_lv_change(struct logical_volume *lv)
+{
+	/*
+	 * To successfully remove sub LVs used by this lv,
+	 * we need to release the sub LVs from the lv in kernel first.
+	 * So, write the new metadata, suspend the lv, commit the metadata
+	 * and resume with the new metadata.
+	 * Then, _delete_lv() can deactivate and remove the sub LVs fully.
+	 */
+
+	if (!vg_write(lv->vg)) {
+		log_error("intermediate VG write failed.");
+		return 0;
+	}
+
+	if (!suspend_lv(lv->vg->cmd, lv)) {
+		log_error("Failed to lock %s", lv->name);
+		vg_revert(lv->vg);
+		return 0;
+	}
+
+	if (!vg_commit(lv->vg)) {
+		resume_lv(lv->vg->cmd, lv);
+		return 0;
+	}
+
+	log_very_verbose("Updating \"%s\" in kernel", lv->name);
+
+	if (!resume_lv(lv->vg->cmd, lv)) {
+		log_error("Problem reactivating %s", lv->name);
+		return 0;
+	}
+
+	return 1;
+}
+
+/*
  * Delete independent/orphan LV, it must acquire lock.
  */
 static int _delete_lv(struct lv_segment *mirrored_seg, struct logical_volume *lv)
@@ -218,29 +257,8 @@ int remove_mirror_images(struct lv_segme
 	 * remove the LVs from the mirror set, commit that metadata
 	 * then deactivate and remove them fully.
 	 */
-
-	if (!vg_write(mirrored_seg->lv->vg)) {
-		log_error("intermediate VG write failed.");
-		return 0;
-	}
-
-	if (!suspend_lv(mirrored_seg->lv->vg->cmd, mirrored_seg->lv)) {
-		log_error("Failed to lock %s", mirrored_seg->lv->name);
-		vg_revert(mirrored_seg->lv->vg);
-		return 0;
-	}
-
-	if (!vg_commit(mirrored_seg->lv->vg)) {
-		resume_lv(mirrored_seg->lv->vg->cmd, mirrored_seg->lv);
-		return 0;
-	}
-
-	log_very_verbose("Updating \"%s\" in kernel", mirrored_seg->lv->name);
-
-	if (!resume_lv(mirrored_seg->lv->vg->cmd, mirrored_seg->lv)) {
-		log_error("Problem reactivating %s", mirrored_seg->lv->name);
-		return 0;
-	}
+	if (!_apply_lv_change(mirrored_seg->lv))
+		return_0;
 
 	/* Delete the 'orphan' LVs */
 	for (m = num_mirrors; m < old_area_count; m++)

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