Skip to contentSkip to conversation

master - Remove locking infrastructure from activation paths

PATCH Joe Thornber 1 participant 1 message Jun 7, 2018

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=da30b4a7865b82c05cd2be1a8eb3bca42c39abb3
Commit:        da30b4a7865b82c05cd2be1a8eb3bca42c39abb3
Parent:        616eeba6f2b33640534e26dea43661724edf3a14
Author:        David Teigland <[email protected]>
AuthorDate:    Tue Jun 5 16:47:24 2018 -0500
Committer:     Joe Thornber <[email protected]>
CommitterDate: Thu Jun 7 16:17:04 2018 +0100

Remove locking infrastructure from activation paths

Basic LV functions:

activate_lv(), deactivate_lv(),
suspend_lv(), resume_lv()

were routed through the locking infrastruture on the way to:

lv_activate_with_filter(), lv_deactivate(),
lv_suspend_if_active(), lv_resume_if_active()

This commit removes the locking infrastructure from the middle and calls the later functions directly from the former.

There were a couple of ancillary steps that the locking infrastructure added along the way which are still included:

- critical section inc/dec during suspend/resume
- checking for active component LVs during activate

The "activation" file lock (serializing activation) has not been kept because activation commands have been changed to take the VG file lock exclusively which makes the activation lock unused and unnecessary.

---
 lib/activate/activate.c    |  103 ++++++++++++++++++++++++++++++++++++++++----
 lib/activate/activate.h    |    8 +++
 lib/locking/file_locking.c |   48 --------------------
 lib/locking/locking.c      |   65 ++-------------------------
 lib/locking/locking.h      |   76 --------------------------------
 5 files changed, 107 insertions(+), 193 deletions(-)
lib/activate/activate.c +94 -9
index c9ead42..a7e5fe3 100644
@@ -2424,15 +2424,6 @@ static int _lv_activate(struct cmd_context *cmd, const char *lvid_s,
 	if (!activation())
 		return 1;
 
-	if (!laopts->exclusive &&
-	    (lv_is_origin(lv) ||
-	     seg_only_exclusive(first_seg(lv))))  {
-		log_error(INTERNAL_ERROR "Trying non-exlusive activation of %s with "
-			  "a volume type %s requiring exclusive activation.",
-			  display_lvname(lv), lvseg_name(first_seg(lv)));
-		return 0;
-	}
-
 	if (filter && !_passes_activation_filter(cmd, lv)) {
 		log_verbose("Not activating %s since it does not pass "
 			    "activation filter.", display_lvname(lv));
@@ -2765,3 +2756,97 @@ int deactivate_lv_with_sub_lv(const struct logical_volume *lv)
 
 	return 1;
 }
+
+int activate_lv(struct cmd_context *cmd, const struct logical_volume *lv)
+{
+	const struct logical_volume *active_lv;
+	int ret;
+
+	/*
+	 * When trying activating component LV, make sure none of sub component
+	 * LV or LVs that are using it are active.
+	 */
+	if (!lv_is_visible(lv))
+		active_lv = lv_holder_is_active(lv);
+	else
+		active_lv = lv_component_is_active(lv);
+
+	if (active_lv) {
+		log_error("Activation of logical volume %s is prohibited while logical volume %s is active.",
+			  display_lvname(lv), display_lvname(active_lv));
+		ret = 0;
+		goto out;
+	}
+
+	ret = lv_activate_with_filter(cmd, NULL, 0,
+				      (lv->status & LV_NOSCAN) ? 1 : 0,
+				      (lv->status & LV_TEMPORARY) ? 1 : 0,
+				      lv_committed(lv));
+out:
+	return ret;
+}
+
+int deactivate_lv(struct cmd_context *cmd, const struct logical_volume *lv)
+{
+	int ret;
+
+	ret = lv_deactivate(cmd, NULL, lv_committed(lv));
+
+	return ret;
+}
+
+int suspend_lv(struct cmd_context *cmd, const struct logical_volume *lv)
+{
+	int ret;
+
+	critical_section_inc(cmd, "locking for suspend");
+
+	ret = lv_suspend_if_active(cmd, NULL, 0, 0, lv_committed(lv), lv);
+
+	return ret;
+}
+
+int suspend_lv_origin(struct cmd_context *cmd, const struct logical_volume *lv)
+{
+	int ret;
+
+	critical_section_inc(cmd, "locking for suspend");
+
+	ret = lv_suspend_if_active(cmd, NULL, 1, 0, lv_committed(lv), lv);
+
+	return ret;
+}
+
+int resume_lv(struct cmd_context *cmd, const struct logical_volume *lv)
+{
+	int ret;
+
+	ret = lv_resume_if_active(cmd, NULL, 0, 0, 0, lv_committed(lv));
+
+	critical_section_dec(cmd, "unlocking on resume");
+
+	return ret;
+}
+
+int resume_lv_origin(struct cmd_context *cmd, const struct logical_volume *lv)
+{
+	int ret;
+
+	ret = lv_resume_if_active(cmd, NULL, 1, 0, 0, lv_committed(lv));
+
+	critical_section_dec(cmd, "unlocking on resume");
+
+	return ret;
+}
+
+int revert_lv(struct cmd_context *cmd, const struct logical_volume *lv)
+{
+	int ret;
+
+	ret = lv_resume_if_active(cmd, NULL, 0, 0, 1, lv_committed(lv));
+
+	critical_section_dec(cmd, "unlocking on resume");
+
+	return ret;
+}
+
lib/activate/activate.h +8 -0
index 8b6c4ad..2f0b0a0 100644
@@ -126,6 +126,14 @@ int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv);
 
 int lv_deactivate_any_missing_subdevs(const struct logical_volume *lv);
 
+int activate_lv(struct cmd_context *cmd, const struct logical_volume *lv);
+int deactivate_lv(struct cmd_context *cmd, const struct logical_volume *lv);
+int suspend_lv(struct cmd_context *cmd, const struct logical_volume *lv);
+int suspend_lv_origin(struct cmd_context *cmd, const struct logical_volume *lv);
+int resume_lv(struct cmd_context *cmd, const struct logical_volume *lv);
+int resume_lv_origin(struct cmd_context *cmd, const struct logical_volume *lv);
+int revert_lv(struct cmd_context *cmd, const struct logical_volume *lv);
+
 /*
  * Returns 1 if info structure has been populated, else 0 on failure.
  * When lvinfo* is NULL, it returns 1 if the device is locally active, 0 otherwise.
lib/locking/file_locking.c +0 -48

62 lines not on this page · raw message

lib/locking/locking.c +5 -60

136 lines not on this page · raw message

lib/locking/locking.h +0 -76

102 lines not on this page · raw message